[llvm-pdbdump] Fix GCC build.
[oota-llvm.git] / tools / llvm-pdbdump / TypeDumper.cpp
1 //===- TypeDumper.cpp - PDBSymDumper implementation for types *----- 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 "TypeDumper.h"
11
12 #include "ClassDefinitionDumper.h"
13 #include "LinePrinter.h"
14 #include "llvm-pdbdump.h"
15 #include "TypedefDumper.h"
16
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
22
23 using namespace llvm;
24
25 TypeDumper::TypeDumper(LinePrinter &P, bool ClassDefs)
26     : PDBSymDumper(true), Printer(P), FullClassDefs(ClassDefs) {}
27
28 void TypeDumper::start(const PDBSymbolExe &Exe) {
29   auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
30   Printer.NewLine();
31   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
32   Printer << ": (" << Enums->getChildCount() << " items)";
33   Printer.Indent();
34   while (auto Enum = Enums->getNext())
35     Enum->dump(*this);
36   Printer.Unindent();
37
38   auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
39   Printer.NewLine();
40   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
41   Printer << ": (" << Typedefs->getChildCount() << " items)";
42   Printer.Indent();
43   while (auto Typedef = Typedefs->getNext())
44     Typedef->dump(*this);
45   Printer.Unindent();
46
47   auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
48   Printer.NewLine();
49   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
50   Printer << ": (" << Classes->getChildCount() << " items)";
51   Printer.Indent();
52   while (auto Class = Classes->getNext())
53     Class->dump(*this);
54   Printer.Unindent();
55 }
56
57 void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
58   if (Symbol.getUnmodifiedTypeId() != 0)
59     return;
60   if (Printer.IsTypeExcluded(Symbol.getName()))
61     return;
62   Printer.NewLine();
63
64   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
65   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
66 }
67
68 void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
69   if (Printer.IsTypeExcluded(Symbol.getName()))
70     return;
71
72   Printer.NewLine();
73   TypedefDumper Dumper(Printer);
74   Dumper.start(Symbol);
75 }
76
77 void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
78   if (Symbol.getUnmodifiedTypeId() != 0)
79     return;
80   if (Printer.IsTypeExcluded(Symbol.getName()))
81     return;
82
83   Printer.NewLine();
84
85   if (FullClassDefs) {
86     ClassDefinitionDumper Dumper(Printer);
87     Dumper.start(Symbol);
88   } else {
89     WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
90     WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
91   }
92 }