[llvm-pdbdump] Clean up method signatures.
[oota-llvm.git] / tools / llvm-pdbdump / ClassDefinitionDumper.cpp
1 //===- ClassDefinitionDumper.cpp --------------------------------*- 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 "ClassDefinitionDumper.h"
11 #include "FunctionDumper.h"
12 #include "LinePrinter.h"
13 #include "llvm-pdbdump.h"
14 #include "TypedefDumper.h"
15 #include "VariableDumper.h"
16
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDBExtras.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
27 #include "llvm/Support/Format.h"
28
29 using namespace llvm;
30
31 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
32     : PDBSymDumper(true), Printer(P) {}
33
34 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
35   std::string Name = Class.getName();
36   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
37   WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
38   Printer << " {";
39   auto Children = Class.findAllChildren();
40   if (Children->getChildCount() == 0) {
41     Printer << "}";
42     return;
43   }
44
45   // Try to dump symbols organized by member access level.  Public members
46   // first, then protected, then private.  This might be slow, so it's worth
47   // reconsidering the value of this if performance of large PDBs is a problem.
48   // NOTE: Access level of nested types is not recorded in the PDB, so we have
49   // a special case for them.
50   SymbolGroupByAccess Groups;
51   Groups.insert(std::make_pair(0, SymbolGroup()));
52   Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
53   Groups.insert(
54       std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
55   Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
56
57   while (auto Child = Children->getNext()) {
58     PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
59     if (isa<PDBSymbolTypeBaseClass>(*Child))
60       continue;
61
62     auto &AccessGroup = Groups.find((int)Access)->second;
63
64     if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
65       if (Func->isCompilerGenerated())
66         continue;
67       if (Func->getLength() == 0 && !Func->isPureVirtual())
68         continue;
69       Child.release();
70       AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
71     } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
72       Child.release();
73       AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
74     } else {
75       AccessGroup.Unknown.push_back(std::move(Child));
76     }
77   }
78
79   int Count = 0;
80   Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]);
81   Count += dumpAccessGroup(PDB_MemberAccess::Public,
82                            Groups[(int)PDB_MemberAccess::Public]);
83   Count += dumpAccessGroup(PDB_MemberAccess::Protected,
84                            Groups[(int)PDB_MemberAccess::Protected]);
85   Count += dumpAccessGroup(PDB_MemberAccess::Private,
86                            Groups[(int)PDB_MemberAccess::Private]);
87   if (Count > 0)
88     Printer.NewLine();
89   Printer << "}";
90 }
91
92 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
93                                            const SymbolGroup &Group) {
94   if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
95     return 0;
96
97   int Count = 0;
98   if (Access == PDB_MemberAccess::Private) {
99     Printer.NewLine();
100     WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
101     Printer << ":";
102   } else if (Access == PDB_MemberAccess::Protected) {
103     Printer.NewLine();
104     WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
105     Printer << ":";
106   } else if (Access == PDB_MemberAccess::Public) {
107     Printer.NewLine();
108     WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
109     Printer << ":";
110   }
111   Printer.Indent();
112   for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
113        iter != end; ++iter) {
114     ++Count;
115     (*iter)->dump(*this);
116   }
117   for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
118        ++iter) {
119     ++Count;
120     (*iter)->dump(*this);
121   }
122   for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
123        iter != end; ++iter) {
124     ++Count;
125     (*iter)->dump(*this);
126   }
127   Printer.Unindent();
128   return Count;
129 }
130
131 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
132
133 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
134   VariableDumper Dumper(Printer);
135   Dumper.start(Symbol);
136 }
137
138 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
139   if (Printer.IsSymbolExcluded(Symbol.getName()))
140     return;
141
142   Printer.NewLine();
143   FunctionDumper Dumper(Printer);
144   Dumper.start(Symbol, FunctionDumper::PointerType::None);
145 }
146
147 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {}
148
149 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
150   if (Printer.IsTypeExcluded(Symbol.getName()))
151     return;
152
153   Printer.NewLine();
154   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
155   WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
156 }
157
158 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
159   if (Printer.IsTypeExcluded(Symbol.getName()))
160     return;
161
162   Printer.NewLine();
163   TypedefDumper Dumper(Printer);
164   Dumper.start(Symbol);
165 }
166
167 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}