]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / PrettyEnumDumper.cpp
1 //===- PrettyEnumDumper.cpp -------------------------------------*- 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 "PrettyEnumDumper.h"
10
11 #include "LinePrinter.h"
12 #include "PrettyBuiltinDumper.h"
13 #include "llvm-pdbutil.h"
14
15 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
18
19 using namespace llvm;
20 using namespace llvm::pdb;
21
22 EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
23
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();
34     return;
35   }
36
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();
41     if (!UnderlyingType)
42       return;
43     if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
44         UnderlyingType->getLength() != 4) {
45       Printer << " : ";
46       BuiltinDumper Dumper(Printer);
47       Dumper.start(*UnderlyingType);
48     }
49     auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
50     Printer << " {";
51     Printer.Indent();
52     if (EnumValues && EnumValues->getChildCount() > 0) {
53       while (auto EnumValue = EnumValues->getNext()) {
54         if (EnumValue->getDataKind() != PDB_DataKind::Constant)
55           continue;
56         Printer.NewLine();
57         WithColor(Printer, PDB_ColorItem::Identifier).get()
58             << EnumValue->getName();
59         Printer << " = ";
60         WithColor(Printer, PDB_ColorItem::LiteralValue).get()
61             << EnumValue->getValue();
62       }
63     }
64     Printer.Unindent();
65     Printer.NewLine();
66     Printer << "}";
67   }
68 }