1 //===- NativeSymbolEnumerator.cpp - info about enumerators ------*- 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 "llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h"
11 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12 #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
13 #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
16 using namespace llvm::codeview
;
17 using namespace llvm::pdb
;
19 NativeSymbolEnumerator::NativeSymbolEnumerator(
20 NativeSession
&Session
, SymIndexId Id
, const NativeTypeEnum
&Parent
,
21 codeview::EnumeratorRecord Record
)
22 : NativeRawSymbol(Session
, PDB_SymType::Data
, Id
), Parent(Parent
),
23 Record(std::move(Record
)) {}
25 NativeSymbolEnumerator::~NativeSymbolEnumerator() {}
27 void NativeSymbolEnumerator::dump(raw_ostream
&OS
, int Indent
,
28 PdbSymbolIdField ShowIdFields
,
29 PdbSymbolIdField RecurseIdFields
) const {
30 NativeRawSymbol::dump(OS
, Indent
, ShowIdFields
, RecurseIdFields
);
31 dumpSymbolIdField(OS
, "classParentId", getClassParentId(), Indent
, Session
,
32 PdbSymbolIdField::ClassParent
, ShowIdFields
,
34 dumpSymbolIdField(OS
, "lexicalParentId", getLexicalParentId(), Indent
,
35 Session
, PdbSymbolIdField::LexicalParent
, ShowIdFields
,
37 dumpSymbolField(OS
, "name", getName(), Indent
);
38 dumpSymbolIdField(OS
, "typeId", getTypeId(), Indent
, Session
,
39 PdbSymbolIdField::Type
, ShowIdFields
, RecurseIdFields
);
40 dumpSymbolField(OS
, "dataKind", getDataKind(), Indent
);
41 dumpSymbolField(OS
, "locationType", getLocationType(), Indent
);
42 dumpSymbolField(OS
, "constType", isConstType(), Indent
);
43 dumpSymbolField(OS
, "unalignedType", isUnalignedType(), Indent
);
44 dumpSymbolField(OS
, "volatileType", isVolatileType(), Indent
);
45 dumpSymbolField(OS
, "value", getValue(), Indent
);
48 SymIndexId
NativeSymbolEnumerator::getClassParentId() const {
49 return Parent
.getSymIndexId();
52 SymIndexId
NativeSymbolEnumerator::getLexicalParentId() const { return 0; }
54 std::string
NativeSymbolEnumerator::getName() const { return Record
.Name
; }
56 SymIndexId
NativeSymbolEnumerator::getTypeId() const {
57 return Parent
.getTypeId();
60 PDB_DataKind
NativeSymbolEnumerator::getDataKind() const {
61 return PDB_DataKind::Constant
;
64 PDB_LocType
NativeSymbolEnumerator::getLocationType() const {
65 return PDB_LocType::Constant
;
68 bool NativeSymbolEnumerator::isConstType() const { return false; }
70 bool NativeSymbolEnumerator::isVolatileType() const { return false; }
72 bool NativeSymbolEnumerator::isUnalignedType() const { return false; }
74 Variant
NativeSymbolEnumerator::getValue() const {
75 const NativeTypeBuiltin
&BT
= Parent
.getUnderlyingBuiltinType();
77 switch (BT
.getBuiltinType()) {
78 case PDB_BuiltinType::Int
:
79 case PDB_BuiltinType::Long
:
80 case PDB_BuiltinType::Char
: {
81 assert(Record
.Value
.isSignedIntN(BT
.getLength() * 8));
82 int64_t N
= Record
.Value
.getSExtValue();
83 switch (BT
.getLength()) {
85 return Variant
{static_cast<int8_t>(N
)};
87 return Variant
{static_cast<int16_t>(N
)};
89 return Variant
{static_cast<int32_t>(N
)};
91 return Variant
{static_cast<int64_t>(N
)};
95 case PDB_BuiltinType::UInt
:
96 case PDB_BuiltinType::ULong
: {
97 assert(Record
.Value
.isIntN(BT
.getLength() * 8));
98 uint64_t U
= Record
.Value
.getZExtValue();
99 switch (BT
.getLength()) {
101 return Variant
{static_cast<uint8_t>(U
)};
103 return Variant
{static_cast<uint16_t>(U
)};
105 return Variant
{static_cast<uint32_t>(U
)};
107 return Variant
{static_cast<uint64_t>(U
)};
111 case PDB_BuiltinType::Bool
: {
112 assert(Record
.Value
.isIntN(BT
.getLength() * 8));
113 uint64_t U
= Record
.Value
.getZExtValue();
114 return Variant
{static_cast<bool>(U
)};
117 assert(false && "Invalid enumeration type");
121 return Variant
{Record
.Value
.getSExtValue()};