[llvm-pdbdump] Colorize output.
[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 Inline, bool ClassDefs)
26     : PDBSymDumper(true), Printer(P), InlineDump(Inline),
27       FullClassDefs(ClassDefs) {}
28
29 void TypeDumper::start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent) {
30   auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
31   Printer.NewLine();
32   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
33   Printer << ": (" << Enums->getChildCount() << " items)";
34   Printer.Indent();
35   while (auto Enum = Enums->getNext())
36     Enum->dump(OS, Indent + 2, *this);
37   Printer.Unindent();
38
39   auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
40   Printer.NewLine();
41   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
42   Printer << ": (" << Typedefs->getChildCount() << " items)";
43   Printer.Indent();
44   while (auto Typedef = Typedefs->getNext())
45     Typedef->dump(OS, Indent + 2, *this);
46   Printer.Unindent();
47
48   auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
49   Printer.NewLine();
50   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
51   Printer << ": (" << Classes->getChildCount() << " items)";
52   Printer.Indent();
53   while (auto Class = Classes->getNext())
54     Class->dump(OS, Indent + 2, *this);
55   Printer.Unindent();
56 }
57
58 void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
59                       int Indent) {
60   if (Symbol.getUnmodifiedTypeId() != 0)
61     return;
62
63   if (!InlineDump)
64     Printer.NewLine();
65
66   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
67   WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
68 }
69
70 void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
71                       int Indent) {
72   if (!InlineDump)
73     Printer.NewLine();
74
75   TypedefDumper Dumper(Printer);
76   Dumper.start(Symbol, OS, Indent);
77 }
78
79 void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
80                       int Indent) {
81   if (Symbol.getUnmodifiedTypeId() != 0)
82     return;
83   if (!InlineDump)
84     Printer.NewLine();
85
86   if (FullClassDefs) {
87     ClassDefinitionDumper Dumper(Printer);
88     Dumper.start(Symbol, OS, Indent);
89   } else {
90     WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
91     WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
92   }
93 }