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