10b57cec5SDimitry Andric //===- NativeSymbolEnumerator.cpp - info about enumerators ------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h"
100b57cec5SDimitry Andric 
1181ad6265SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
120b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
130b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric using namespace llvm;
160b57cec5SDimitry Andric using namespace llvm::codeview;
170b57cec5SDimitry Andric using namespace llvm::pdb;
180b57cec5SDimitry Andric 
NativeSymbolEnumerator(NativeSession & Session,SymIndexId Id,const NativeTypeEnum & Parent,codeview::EnumeratorRecord Record)190b57cec5SDimitry Andric NativeSymbolEnumerator::NativeSymbolEnumerator(
200b57cec5SDimitry Andric     NativeSession &Session, SymIndexId Id, const NativeTypeEnum &Parent,
210b57cec5SDimitry Andric     codeview::EnumeratorRecord Record)
220b57cec5SDimitry Andric     : NativeRawSymbol(Session, PDB_SymType::Data, Id), Parent(Parent),
230b57cec5SDimitry Andric       Record(std::move(Record)) {}
240b57cec5SDimitry Andric 
2581ad6265SDimitry Andric NativeSymbolEnumerator::~NativeSymbolEnumerator() = default;
260b57cec5SDimitry Andric 
dump(raw_ostream & OS,int Indent,PdbSymbolIdField ShowIdFields,PdbSymbolIdField RecurseIdFields) const270b57cec5SDimitry Andric void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent,
280b57cec5SDimitry Andric                                   PdbSymbolIdField ShowIdFields,
290b57cec5SDimitry Andric                                   PdbSymbolIdField RecurseIdFields) const {
300b57cec5SDimitry Andric   NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
310b57cec5SDimitry Andric   dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
320b57cec5SDimitry Andric                     PdbSymbolIdField::ClassParent, ShowIdFields,
330b57cec5SDimitry Andric                     RecurseIdFields);
340b57cec5SDimitry Andric   dumpSymbolIdField(OS, "lexicalParentId", getLexicalParentId(), Indent,
350b57cec5SDimitry Andric                     Session, PdbSymbolIdField::LexicalParent, ShowIdFields,
360b57cec5SDimitry Andric                     RecurseIdFields);
370b57cec5SDimitry Andric   dumpSymbolField(OS, "name", getName(), Indent);
380b57cec5SDimitry Andric   dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
390b57cec5SDimitry Andric                     PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
400b57cec5SDimitry Andric   dumpSymbolField(OS, "dataKind", getDataKind(), Indent);
410b57cec5SDimitry Andric   dumpSymbolField(OS, "locationType", getLocationType(), Indent);
420b57cec5SDimitry Andric   dumpSymbolField(OS, "constType", isConstType(), Indent);
430b57cec5SDimitry Andric   dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
440b57cec5SDimitry Andric   dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
450b57cec5SDimitry Andric   dumpSymbolField(OS, "value", getValue(), Indent);
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric 
getClassParentId() const480b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getClassParentId() const {
490b57cec5SDimitry Andric   return Parent.getSymIndexId();
500b57cec5SDimitry Andric }
510b57cec5SDimitry Andric 
getLexicalParentId() const520b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getLexicalParentId() const { return 0; }
530b57cec5SDimitry Andric 
getName() const545ffd83dbSDimitry Andric std::string NativeSymbolEnumerator::getName() const {
555ffd83dbSDimitry Andric   return std::string(Record.Name);
565ffd83dbSDimitry Andric }
570b57cec5SDimitry Andric 
getTypeId() const580b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getTypeId() const {
590b57cec5SDimitry Andric   return Parent.getTypeId();
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric 
getDataKind() const620b57cec5SDimitry Andric PDB_DataKind NativeSymbolEnumerator::getDataKind() const {
630b57cec5SDimitry Andric   return PDB_DataKind::Constant;
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric 
getLocationType() const660b57cec5SDimitry Andric PDB_LocType NativeSymbolEnumerator::getLocationType() const {
670b57cec5SDimitry Andric   return PDB_LocType::Constant;
680b57cec5SDimitry Andric }
690b57cec5SDimitry Andric 
isConstType() const700b57cec5SDimitry Andric bool NativeSymbolEnumerator::isConstType() const { return false; }
710b57cec5SDimitry Andric 
isVolatileType() const720b57cec5SDimitry Andric bool NativeSymbolEnumerator::isVolatileType() const { return false; }
730b57cec5SDimitry Andric 
isUnalignedType() const740b57cec5SDimitry Andric bool NativeSymbolEnumerator::isUnalignedType() const { return false; }
750b57cec5SDimitry Andric 
getValue() const760b57cec5SDimitry Andric Variant NativeSymbolEnumerator::getValue() const {
770b57cec5SDimitry Andric   const NativeTypeBuiltin &BT = Parent.getUnderlyingBuiltinType();
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   switch (BT.getBuiltinType()) {
800b57cec5SDimitry Andric   case PDB_BuiltinType::Int:
810b57cec5SDimitry Andric   case PDB_BuiltinType::Long:
820b57cec5SDimitry Andric   case PDB_BuiltinType::Char: {
830b57cec5SDimitry Andric     assert(Record.Value.isSignedIntN(BT.getLength() * 8));
840b57cec5SDimitry Andric     int64_t N = Record.Value.getSExtValue();
850b57cec5SDimitry Andric     switch (BT.getLength()) {
860b57cec5SDimitry Andric     case 1:
870b57cec5SDimitry Andric       return Variant{static_cast<int8_t>(N)};
880b57cec5SDimitry Andric     case 2:
890b57cec5SDimitry Andric       return Variant{static_cast<int16_t>(N)};
900b57cec5SDimitry Andric     case 4:
910b57cec5SDimitry Andric       return Variant{static_cast<int32_t>(N)};
920b57cec5SDimitry Andric     case 8:
930b57cec5SDimitry Andric       return Variant{static_cast<int64_t>(N)};
940b57cec5SDimitry Andric     }
950b57cec5SDimitry Andric     break;
960b57cec5SDimitry Andric   }
970b57cec5SDimitry Andric   case PDB_BuiltinType::UInt:
980b57cec5SDimitry Andric   case PDB_BuiltinType::ULong: {
990b57cec5SDimitry Andric     assert(Record.Value.isIntN(BT.getLength() * 8));
1000b57cec5SDimitry Andric     uint64_t U = Record.Value.getZExtValue();
1010b57cec5SDimitry Andric     switch (BT.getLength()) {
1020b57cec5SDimitry Andric     case 1:
1030b57cec5SDimitry Andric       return Variant{static_cast<uint8_t>(U)};
1040b57cec5SDimitry Andric     case 2:
1050b57cec5SDimitry Andric       return Variant{static_cast<uint16_t>(U)};
1060b57cec5SDimitry Andric     case 4:
1070b57cec5SDimitry Andric       return Variant{static_cast<uint32_t>(U)};
1080b57cec5SDimitry Andric     case 8:
1090b57cec5SDimitry Andric       return Variant{static_cast<uint64_t>(U)};
1100b57cec5SDimitry Andric     }
1110b57cec5SDimitry Andric     break;
1120b57cec5SDimitry Andric   }
1130b57cec5SDimitry Andric   case PDB_BuiltinType::Bool: {
1140b57cec5SDimitry Andric     assert(Record.Value.isIntN(BT.getLength() * 8));
1150b57cec5SDimitry Andric     uint64_t U = Record.Value.getZExtValue();
1160b57cec5SDimitry Andric     return Variant{static_cast<bool>(U)};
1170b57cec5SDimitry Andric   }
1180b57cec5SDimitry Andric   default:
1190b57cec5SDimitry Andric     assert(false && "Invalid enumeration type");
1200b57cec5SDimitry Andric     break;
1210b57cec5SDimitry Andric   }
1220b57cec5SDimitry Andric 
1230b57cec5SDimitry Andric   return Variant{Record.Value.getSExtValue()};
1240b57cec5SDimitry Andric }
125