5e4228c7c703a5ca9c0effe04cc12d00855ada96
[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) {
30   WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
31   uint32_t TargetId = Symbol.getTypeId();
32   if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
33     TypeSymbol->dump(*this);
34   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
35 }
36
37 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol) {}
38
39 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
40   BuiltinDumper Dumper(Printer);
41   Dumper.start(Symbol);
42 }
43
44 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
45   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
46   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
47 }
48
49 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol) {
50   if (Symbol.isConstType())
51     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
52   if (Symbol.isVolatileType())
53     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
54   uint32_t PointeeId = Symbol.getTypeId();
55   auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
56   if (!PointeeType)
57     return;
58   if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
59     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
60     if (Symbol.isReference())
61       Pointer = FunctionDumper::PointerType::Reference;
62     FunctionDumper NestedDumper(Printer);
63     NestedDumper.start(*FuncSig, nullptr, Pointer);
64   } else {
65     PointeeType->dump(*this);
66     Printer << ((Symbol.isReference()) ? "&" : "*");
67   }
68 }
69
70 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
71   FunctionDumper Dumper(Printer);
72   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None);
73 }
74
75 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
76   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
77   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
78 }