[llvm-pdbdump] Fix dumping of function pointers and basic types.
[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 "llvm-pdbdump.h"
15
16 #include "llvm/DebugInfo/PDB/IPDBSession.h"
17 #include "llvm/DebugInfo/PDB/PDBExtras.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
23
24 using namespace llvm;
25
26 TypedefDumper::TypedefDumper() : PDBSymDumper(true) {}
27
28 void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
29                           int Indent) {
30   OS << "typedef ";
31   uint32_t TargetId = Symbol.getTypeId();
32   if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
33     TypeSymbol->dump(OS, 0, *this);
34   OS << " " << Symbol.getName();
35 }
36
37 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
38                          int Indent) {}
39
40 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
41                          int Indent) {
42   BuiltinDumper Dumper;
43   Dumper.start(Symbol, OS);
44 }
45
46 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
47                          int Indent) {
48   OS << "enum " << Symbol.getName();
49 }
50
51 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
52                          int Indent) {
53   if (Symbol.isConstType())
54     OS << "const ";
55   if (Symbol.isVolatileType())
56     OS << "volatile ";
57   uint32_t PointeeId = Symbol.getTypeId();
58   auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
59   if (!PointeeType)
60     return;
61   if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
62     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
63     if (Symbol.isReference())
64       Pointer = FunctionDumper::PointerType::Reference;
65     FunctionDumper NestedDumper;
66     NestedDumper.start(*FuncSig, nullptr, Pointer, OS);
67   } else {
68     PointeeType->dump(OS, Indent, *this);
69     OS << ((Symbol.isReference()) ? "&" : "*");
70   }
71 }
72
73 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol,
74                          raw_ostream &OS, int Indent) {
75   FunctionDumper Dumper;
76   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS);
77 }
78
79 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
80                          int Indent) {
81   OS << "class " << Symbol.getName();
82 }