1 //===- NativeTypeUDT.cpp - info about class/struct type ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/Native/NativeTypeUDT.h"
12 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
17 using namespace llvm::codeview;
18 using namespace llvm::pdb;
20 NativeTypeUDT::NativeTypeUDT(NativeSession &Session, SymIndexId Id,
21 codeview::TypeIndex TI, codeview::ClassRecord CR)
22 : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
23 Class(std::move(CR)), Tag(Class.getPointer()) {}
25 NativeTypeUDT::NativeTypeUDT(NativeSession &Session, SymIndexId Id,
26 codeview::TypeIndex TI, codeview::UnionRecord UR)
27 : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
28 Union(std::move(UR)), Tag(Union.getPointer()) {}
30 NativeTypeUDT::NativeTypeUDT(NativeSession &Session, SymIndexId Id,
31 NativeTypeUDT &UnmodifiedType,
32 codeview::ModifierRecord Modifier)
33 : NativeRawSymbol(Session, PDB_SymType::UDT, Id),
34 UnmodifiedType(&UnmodifiedType), Modifiers(std::move(Modifier)) {}
36 NativeTypeUDT::~NativeTypeUDT() {}
38 void NativeTypeUDT::dump(raw_ostream &OS, int Indent,
39 PdbSymbolIdField ShowIdFields,
40 PdbSymbolIdField RecurseIdFields) const {
42 NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
44 dumpSymbolField(OS, "name", getName(), Indent);
45 dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
46 PdbSymbolIdField::LexicalParent, ShowIdFields,
48 if (Modifiers.hasValue())
49 dumpSymbolIdField(OS, "unmodifiedTypeId", getUnmodifiedTypeId(), Indent,
50 Session, PdbSymbolIdField::UnmodifiedType, ShowIdFields,
52 if (getUdtKind() != PDB_UdtType::Union)
53 dumpSymbolField(OS, "virtualTableShapeId", getVirtualTableShapeId(),
55 dumpSymbolField(OS, "length", getLength(), Indent);
56 dumpSymbolField(OS, "udtKind", getUdtKind(), Indent);
57 dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
58 dumpSymbolField(OS, "constType", isConstType(), Indent);
59 dumpSymbolField(OS, "hasAssignmentOperator", hasAssignmentOperator(), Indent);
60 dumpSymbolField(OS, "hasCastOperator", hasCastOperator(), Indent);
61 dumpSymbolField(OS, "hasNestedTypes", hasNestedTypes(), Indent);
62 dumpSymbolField(OS, "overloadedOperator", hasOverloadedOperator(), Indent);
63 dumpSymbolField(OS, "isInterfaceUdt", isInterfaceUdt(), Indent);
64 dumpSymbolField(OS, "intrinsic", isIntrinsic(), Indent);
65 dumpSymbolField(OS, "nested", isNested(), Indent);
66 dumpSymbolField(OS, "packed", isPacked(), Indent);
67 dumpSymbolField(OS, "isRefUdt", isRefUdt(), Indent);
68 dumpSymbolField(OS, "scoped", isScoped(), Indent);
69 dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
70 dumpSymbolField(OS, "isValueUdt", isValueUdt(), Indent);
71 dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
74 std::string NativeTypeUDT::getName() const {
76 return UnmodifiedType->getName();
78 return Tag->getName();
81 SymIndexId NativeTypeUDT::getLexicalParentId() const { return 0; }
83 SymIndexId NativeTypeUDT::getUnmodifiedTypeId() const {
85 return UnmodifiedType->getSymIndexId();
90 SymIndexId NativeTypeUDT::getVirtualTableShapeId() const {
92 return UnmodifiedType->getVirtualTableShapeId();
95 return Session.getSymbolCache().findSymbolByTypeIndex(Class->VTableShape);
100 uint64_t NativeTypeUDT::getLength() const {
102 return UnmodifiedType->getLength();
105 return Class->getSize();
107 return Union->getSize();
110 PDB_UdtType NativeTypeUDT::getUdtKind() const {
112 return UnmodifiedType->getUdtKind();
115 case TypeRecordKind::Class:
116 return PDB_UdtType::Class;
117 case TypeRecordKind::Union:
118 return PDB_UdtType::Union;
119 case TypeRecordKind::Struct:
120 return PDB_UdtType::Struct;
121 case TypeRecordKind::Interface:
122 return PDB_UdtType::Interface;
124 llvm_unreachable("Unexected udt kind");
128 bool NativeTypeUDT::hasConstructor() const {
130 return UnmodifiedType->hasConstructor();
132 return (Tag->Options & ClassOptions::HasConstructorOrDestructor) !=
136 bool NativeTypeUDT::isConstType() const {
139 return (Modifiers->Modifiers & ModifierOptions::Const) !=
140 ModifierOptions::None;
143 bool NativeTypeUDT::hasAssignmentOperator() const {
145 return UnmodifiedType->hasAssignmentOperator();
147 return (Tag->Options & ClassOptions::HasOverloadedAssignmentOperator) !=
151 bool NativeTypeUDT::hasCastOperator() const {
153 return UnmodifiedType->hasCastOperator();
155 return (Tag->Options & ClassOptions::HasConversionOperator) !=
159 bool NativeTypeUDT::hasNestedTypes() const {
161 return UnmodifiedType->hasNestedTypes();
163 return (Tag->Options & ClassOptions::ContainsNestedClass) !=
167 bool NativeTypeUDT::hasOverloadedOperator() const {
169 return UnmodifiedType->hasOverloadedOperator();
171 return (Tag->Options & ClassOptions::HasOverloadedOperator) !=
175 bool NativeTypeUDT::isInterfaceUdt() const { return false; }
177 bool NativeTypeUDT::isIntrinsic() const {
179 return UnmodifiedType->isIntrinsic();
181 return (Tag->Options & ClassOptions::Intrinsic) != ClassOptions::None;
184 bool NativeTypeUDT::isNested() const {
186 return UnmodifiedType->isNested();
188 return (Tag->Options & ClassOptions::Nested) != ClassOptions::None;
191 bool NativeTypeUDT::isPacked() const {
193 return UnmodifiedType->isPacked();
195 return (Tag->Options & ClassOptions::Packed) != ClassOptions::None;
198 bool NativeTypeUDT::isRefUdt() const { return false; }
200 bool NativeTypeUDT::isScoped() const {
202 return UnmodifiedType->isScoped();
204 return (Tag->Options & ClassOptions::Scoped) != ClassOptions::None;
207 bool NativeTypeUDT::isValueUdt() const { return false; }
209 bool NativeTypeUDT::isUnalignedType() const {
212 return (Modifiers->Modifiers & ModifierOptions::Unaligned) !=
213 ModifierOptions::None;
216 bool NativeTypeUDT::isVolatileType() const {
219 return (Modifiers->Modifiers & ModifierOptions::Volatile) !=
220 ModifierOptions::None;