]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/llvm-pdbutil/PrettyTypedefDumper.cpp
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / 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 #include "PrettyTypeDumper.h"
16
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDBExtras.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
24
25 using namespace llvm;
26 using namespace llvm::pdb;
27
28 TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
29
30 void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol) {
31   WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
32   uint32_t TargetId = Symbol.getTypeId();
33   if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
34     TypeSymbol->dump(*this);
35   WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
36                                                       << Symbol.getName();
37 }
38
39 void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol) {
40   TypeDumper Dumper(Printer);
41   Dumper.dump(Symbol);
42 }
43
44 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
45   BuiltinDumper Dumper(Printer);
46   Dumper.start(Symbol);
47 }
48
49 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
50   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
51   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
52 }
53
54 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol) {
55   if (Symbol.isConstType())
56     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
57   if (Symbol.isVolatileType())
58     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
59   auto PointeeType = Symbol.getPointeeType();
60   if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
61     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
62     if (Symbol.isReference())
63       Pointer = FunctionDumper::PointerType::Reference;
64     FunctionDumper NestedDumper(Printer);
65     NestedDumper.start(*FuncSig, nullptr, Pointer);
66   } else {
67     PointeeType->dump(*this);
68     Printer << ((Symbol.isReference()) ? "&" : "*");
69   }
70
71   if (Symbol.getRawSymbol().isRestrictedType())
72     WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
73 }
74
75 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
76   FunctionDumper Dumper(Printer);
77   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None);
78 }
79
80 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
81   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
82   WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
83 }