[llvm-pdbdump] Add regex-based filtering.
[oota-llvm.git] / tools / llvm-pdbdump / TypedefDumper.cpp
1 //===- TypedefDumper.cpp - PDBSymDumper impl for typedefs -------- * C++ *-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "TypedefDumper.h"
11
12 #include "BuiltinDumper.h"
13 #include "FunctionDumper.h"
14 #include "LinePrinter.h"
15 #include "llvm-pdbdump.h"
16
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDBExtras.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
24
25 using namespace llvm;
26
27 TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
28
29 void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
30                           int Indent) {
31   WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
32   uint32_t TargetId = Symbol.getTypeId();
33   if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
34     TypeSymbol->dump(OS, 0, *this);
35   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
36 }
37
38 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
39                          int Indent) {}
40
41 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
42                          int Indent) {
43   BuiltinDumper Dumper(Printer);
44   Dumper.start(Symbol, OS);
45 }
46
47 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
48                          int Indent) {
49   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
50   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
51 }
52
53 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
54                          int Indent) {
55   if (Symbol.isConstType())
56     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
57   if (Symbol.isVolatileType())
58     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
59   uint32_t PointeeId = Symbol.getTypeId();
60   auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
61   if (!PointeeType)
62     return;
63   if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
64     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
65     if (Symbol.isReference())
66       Pointer = FunctionDumper::PointerType::Reference;
67     FunctionDumper NestedDumper(Printer);
68     NestedDumper.start(*FuncSig, nullptr, Pointer, OS);
69   } else {
70     PointeeType->dump(OS, Indent, *this);
71     OS << ((Symbol.isReference()) ? "&" : "*");
72   }
73 }
74
75 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol,
76                          raw_ostream &OS, int Indent) {
77   FunctionDumper Dumper(Printer);
78   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS);
79 }
80
81 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
82                          int Indent) {
83   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
84   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
85 }