Home | History | Annotate | Download | only in Native
      1 //===- NativeEnumSymbol.cpp - info about enum type --------------*- 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 "llvm/DebugInfo/PDB/Native/NativeEnumSymbol.h"
     11 
     12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
     13 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
     14 #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
     15 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
     16 
     17 #include <cassert>
     18 
     19 using namespace llvm;
     20 using namespace llvm::pdb;
     21 
     22 NativeEnumSymbol::NativeEnumSymbol(NativeSession &Session, SymIndexId Id,
     23                                    const codeview::CVType &CVT)
     24     : NativeRawSymbol(Session, Id), CV(CVT),
     25       Record(codeview::TypeRecordKind::Enum) {
     26   assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM);
     27   cantFail(visitTypeRecord(CV, *this));
     28 }
     29 
     30 NativeEnumSymbol::~NativeEnumSymbol() {}
     31 
     32 std::unique_ptr<NativeRawSymbol> NativeEnumSymbol::clone() const {
     33   return llvm::make_unique<NativeEnumSymbol>(Session, SymbolId, CV);
     34 }
     35 
     36 std::unique_ptr<IPDBEnumSymbols>
     37 NativeEnumSymbol::findChildren(PDB_SymType Type) const {
     38   switch (Type) {
     39   case PDB_SymType::Data: {
     40     // TODO(amccarth):  Provide an actual implementation.
     41     return nullptr;
     42   }
     43   default:
     44     return nullptr;
     45   }
     46 }
     47 
     48 Error NativeEnumSymbol::visitKnownRecord(codeview::CVType &CVR,
     49                                          codeview::EnumRecord &ER) {
     50   Record = ER;
     51   return Error::success();
     52 }
     53 
     54 Error NativeEnumSymbol::visitKnownMember(codeview::CVMemberRecord &CVM,
     55                                          codeview::EnumeratorRecord &R) {
     56   return Error::success();
     57 }
     58 
     59 PDB_SymType NativeEnumSymbol::getSymTag() const { return PDB_SymType::Enum; }
     60 
     61 uint32_t NativeEnumSymbol::getClassParentId() const { return 0xFFFFFFFF; }
     62 
     63 uint32_t NativeEnumSymbol::getUnmodifiedTypeId() const { return 0; }
     64 
     65 bool NativeEnumSymbol::hasConstructor() const {
     66   return bool(Record.getOptions() &
     67               codeview::ClassOptions::HasConstructorOrDestructor);
     68 }
     69 
     70 bool NativeEnumSymbol::hasAssignmentOperator() const {
     71   return bool(Record.getOptions() &
     72               codeview::ClassOptions::HasOverloadedAssignmentOperator);
     73 }
     74 
     75 bool NativeEnumSymbol::hasCastOperator() const {
     76   return bool(Record.getOptions() &
     77               codeview::ClassOptions::HasConversionOperator);
     78 }
     79 
     80 uint64_t NativeEnumSymbol::getLength() const {
     81   const auto Id = Session.findSymbolByTypeIndex(Record.getUnderlyingType());
     82   const auto UnderlyingType =
     83       Session.getConcreteSymbolById<PDBSymbolTypeBuiltin>(Id);
     84   return UnderlyingType ? UnderlyingType->getLength() : 0;
     85 }
     86 
     87 std::string NativeEnumSymbol::getName() const { return Record.getName(); }
     88 
     89 bool NativeEnumSymbol::isNested() const {
     90   return bool(Record.getOptions() & codeview::ClassOptions::Nested);
     91 }
     92 
     93 bool NativeEnumSymbol::hasOverloadedOperator() const {
     94   return bool(Record.getOptions() &
     95               codeview::ClassOptions::HasOverloadedOperator);
     96 }
     97 
     98 bool NativeEnumSymbol::isPacked() const {
     99   return bool(Record.getOptions() & codeview::ClassOptions::Packed);
    100 }
    101 
    102 bool NativeEnumSymbol::isScoped() const {
    103   return bool(Record.getOptions() & codeview::ClassOptions::Scoped);
    104 }
    105 
    106 uint32_t NativeEnumSymbol::getTypeId() const {
    107   return Session.findSymbolByTypeIndex(Record.getUnderlyingType());
    108 }
    109