]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / PrettyTypedefDumper.cpp
1 //===- PrettyTypedefDumper.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 "PrettyTypedefDumper.h"
11
12 #include "LinePrinter.h"
13 #include "PrettyBuiltinDumper.h"
14 #include "PrettyFunctionDumper.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 using namespace llvm::pdb;
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::Identifier).get() << " "
35                                                       << Symbol.getName();
36 }
37
38 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol) {}
39
40 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
41   BuiltinDumper Dumper(Printer);
42   Dumper.start(Symbol);
43 }
44
45 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
46   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
47   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
48 }
49
50 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol) {
51   if (Symbol.isConstType())
52     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
53   if (Symbol.isVolatileType())
54     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
55   auto PointeeType = Symbol.getPointeeType();
56   if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
57     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
58     if (Symbol.isReference())
59       Pointer = FunctionDumper::PointerType::Reference;
60     FunctionDumper NestedDumper(Printer);
61     NestedDumper.start(*FuncSig, nullptr, Pointer);
62   } else {
63     PointeeType->dump(*this);
64     Printer << ((Symbol.isReference()) ? "&" : "*");
65   }
66
67   if (Symbol.getRawSymbol().isRestrictedType())
68     WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
69 }
70
71 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
72   FunctionDumper Dumper(Printer);
73   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None);
74 }
75
76 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
77   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
78   WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
79 }