]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / PrettyTypedefDumper.cpp
1 //===- PrettyTypedefDumper.cpp - PDBSymDumper impl for typedefs -- * C++ *-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "PrettyTypedefDumper.h"
10
11 #include "LinePrinter.h"
12 #include "PrettyBuiltinDumper.h"
13 #include "PrettyFunctionDumper.h"
14 #include "PrettyTypeDumper.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   TypeDumper Dumper(Printer);
40   Dumper.dump(Symbol);
41 }
42
43 void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
44   BuiltinDumper Dumper(Printer);
45   Dumper.start(Symbol);
46 }
47
48 void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
49   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
50   WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
51 }
52
53 void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol) {
54   if (Symbol.isConstType())
55     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
56   if (Symbol.isVolatileType())
57     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
58   auto PointeeType = Symbol.getPointeeType();
59   if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
60     FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
61     if (Symbol.isReference())
62       Pointer = FunctionDumper::PointerType::Reference;
63     FunctionDumper NestedDumper(Printer);
64     NestedDumper.start(*FuncSig, nullptr, Pointer);
65   } else {
66     PointeeType->dump(*this);
67     Printer << ((Symbol.isReference()) ? "&" : "*");
68   }
69
70   if (Symbol.getRawSymbol().isRestrictedType())
71     WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
72 }
73
74 void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
75   FunctionDumper Dumper(Printer);
76   Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None);
77 }
78
79 void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
80   WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
81   WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
82 }