]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/PrettyEnumDumper.cpp
Merge llvm, clang, lld and lldb release_40 branch r292009. Also update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / PrettyEnumDumper.cpp
1 //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "PrettyEnumDumper.h"
11
12 #include "LinePrinter.h"
13 #include "PrettyBuiltinDumper.h"
14 #include "llvm-pdbdump.h"
15
16 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
19
20 using namespace llvm;
21 using namespace llvm::pdb;
22
23 EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
24
25 void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
26   WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
27   WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
28   if (!opts::pretty::NoEnumDefs) {
29     auto BuiltinType = Symbol.getUnderlyingType();
30     if (BuiltinType->getBuiltinType() != PDB_BuiltinType::Int ||
31         BuiltinType->getLength() != 4) {
32       Printer << " : ";
33       BuiltinDumper Dumper(Printer);
34       Dumper.start(*BuiltinType);
35     }
36     Printer << " {";
37     Printer.Indent();
38     auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
39     while (auto EnumValue = EnumValues->getNext()) {
40       if (EnumValue->getDataKind() != PDB_DataKind::Constant)
41         continue;
42       Printer.NewLine();
43       WithColor(Printer, PDB_ColorItem::Identifier).get()
44           << EnumValue->getName();
45       Printer << " = ";
46       WithColor(Printer, PDB_ColorItem::LiteralValue).get()
47           << EnumValue->getValue();
48     }
49     Printer.Unindent();
50     Printer.NewLine();
51     Printer << "}";
52   }
53 }