1 //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "PrettyEnumDumper.h"
11 #include "LinePrinter.h"
12 #include "PrettyBuiltinDumper.h"
13 #include "llvm-pdbutil.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
20 using namespace llvm::pdb
;
22 EnumDumper::EnumDumper(LinePrinter
&P
) : PDBSymDumper(true), Printer(P
) {}
24 void EnumDumper::start(const PDBSymbolTypeEnum
&Symbol
) {
25 if (Symbol
.getUnmodifiedTypeId() != 0) {
26 if (Symbol
.isConstType())
27 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "const ";
28 if (Symbol
.isVolatileType())
29 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "volatile ";
30 if (Symbol
.isUnalignedType())
31 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "unaligned ";
32 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "enum ";
33 WithColor(Printer
, PDB_ColorItem::Type
).get() << Symbol
.getName();
37 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "enum ";
38 WithColor(Printer
, PDB_ColorItem::Type
).get() << Symbol
.getName();
39 if (!opts::pretty::NoEnumDefs
) {
40 auto UnderlyingType
= Symbol
.getUnderlyingType();
43 if (UnderlyingType
->getBuiltinType() != PDB_BuiltinType::Int
||
44 UnderlyingType
->getLength() != 4) {
46 BuiltinDumper
Dumper(Printer
);
47 Dumper
.start(*UnderlyingType
);
49 auto EnumValues
= Symbol
.findAllChildren
<PDBSymbolData
>();
52 if (EnumValues
&& EnumValues
->getChildCount() > 0) {
53 while (auto EnumValue
= EnumValues
->getNext()) {
54 if (EnumValue
->getDataKind() != PDB_DataKind::Constant
)
57 WithColor(Printer
, PDB_ColorItem::Identifier
).get()
58 << EnumValue
->getName();
60 WithColor(Printer
, PDB_ColorItem::LiteralValue
).get()
61 << EnumValue
->getValue();