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 "PrettyBuiltinDumper.h"
12#include "PrettyFunctionDumper.h"
13#include "PrettyTypeDumper.h"
14
15#include "llvm/DebugInfo/PDB/IPDBSession.h"
16#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
17#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.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
24using namespace llvm;
25using namespace llvm::pdb;
26
27TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
28
29void 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(SymbolId: TargetId))
33 TypeSymbol->dump(Dumper&: *this);
34 WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
35 << Symbol.getName();
36}
37
38void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol) {
39 TypeDumper Dumper(Printer);
40 Dumper.dump(Symbol);
41}
42
43void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
44 BuiltinDumper Dumper(Printer);
45 Dumper.start(Symbol);
46}
47
48void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
49 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
50 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
51}
52
53void 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>(Val&: PointeeType)) {
60 FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
61 if (Symbol.isReference())
62 Pointer = FunctionDumper::PointerType::Reference;
63 FunctionDumper NestedDumper(Printer);
64 NestedDumper.start(Symbol: *FuncSig, Name: nullptr, Pointer);
65 } else {
66 PointeeType->dump(Dumper&: *this);
67 Printer << ((Symbol.isReference()) ? "&" : "*");
68 }
69
70 if (Symbol.getRawSymbol().isRestrictedType())
71 WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
72}
73
74void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
75 FunctionDumper Dumper(Printer);
76 Dumper.start(Symbol, Name: nullptr, Pointer: FunctionDumper::PointerType::None);
77}
78
79void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
80 WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
81 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
82}
83