LLVM  14.0.0git
NativeTypeUDT.cpp
Go to the documentation of this file.
1 //===- NativeTypeUDT.cpp - info about class/struct type ---------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
12 
13 #include <cassert>
14 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 using namespace llvm::pdb;
18 
19 NativeTypeUDT::NativeTypeUDT(NativeSession &Session, SymIndexId Id,
21  : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
22  Class(std::move(CR)), Tag(Class.getPointer()) {}
23 
26  : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
27  Union(std::move(UR)), Tag(Union.getPointer()) {}
28 
30  NativeTypeUDT &UnmodifiedType,
31  codeview::ModifierRecord Modifier)
32  : NativeRawSymbol(Session, PDB_SymType::UDT, Id),
33  UnmodifiedType(&UnmodifiedType), Modifiers(std::move(Modifier)) {}
34 
36 
37 void NativeTypeUDT::dump(raw_ostream &OS, int Indent,
38  PdbSymbolIdField ShowIdFields,
39  PdbSymbolIdField RecurseIdFields) const {
40 
41  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
42 
43  dumpSymbolField(OS, "name", getName(), Indent);
44  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
45  PdbSymbolIdField::LexicalParent, ShowIdFields,
46  RecurseIdFields);
47  if (Modifiers.hasValue())
48  dumpSymbolIdField(OS, "unmodifiedTypeId", getUnmodifiedTypeId(), Indent,
50  RecurseIdFields);
52  dumpSymbolField(OS, "virtualTableShapeId", getVirtualTableShapeId(),
53  Indent);
54  dumpSymbolField(OS, "length", getLength(), Indent);
55  dumpSymbolField(OS, "udtKind", getUdtKind(), Indent);
56  dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
57  dumpSymbolField(OS, "constType", isConstType(), Indent);
58  dumpSymbolField(OS, "hasAssignmentOperator", hasAssignmentOperator(), Indent);
59  dumpSymbolField(OS, "hasCastOperator", hasCastOperator(), Indent);
60  dumpSymbolField(OS, "hasNestedTypes", hasNestedTypes(), Indent);
61  dumpSymbolField(OS, "overloadedOperator", hasOverloadedOperator(), Indent);
62  dumpSymbolField(OS, "isInterfaceUdt", isInterfaceUdt(), Indent);
63  dumpSymbolField(OS, "intrinsic", isIntrinsic(), Indent);
64  dumpSymbolField(OS, "nested", isNested(), Indent);
65  dumpSymbolField(OS, "packed", isPacked(), Indent);
66  dumpSymbolField(OS, "isRefUdt", isRefUdt(), Indent);
67  dumpSymbolField(OS, "scoped", isScoped(), Indent);
68  dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
69  dumpSymbolField(OS, "isValueUdt", isValueUdt(), Indent);
70  dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
71 }
72 
73 std::string NativeTypeUDT::getName() const {
74  if (UnmodifiedType)
75  return UnmodifiedType->getName();
76 
77  return std::string(Tag->getName());
78 }
79 
81 
83  if (UnmodifiedType)
84  return UnmodifiedType->getSymIndexId();
85 
86  return 0;
87 }
88 
90  if (UnmodifiedType)
92 
93  if (Class)
94  return Session.getSymbolCache().findSymbolByTypeIndex(Class->VTableShape);
95 
96  return 0;
97 }
98 
100  if (UnmodifiedType)
101  return UnmodifiedType->getLength();
102 
103  if (Class)
104  return Class->getSize();
105 
106  return Union->getSize();
107 }
108 
110  if (UnmodifiedType)
111  return UnmodifiedType->getUdtKind();
112 
113  switch (Tag->Kind) {
115  return PDB_UdtType::Class;
116  case TypeRecordKind::Union:
117  return PDB_UdtType::Union;
118  case TypeRecordKind::Struct:
119  return PDB_UdtType::Struct;
120  case TypeRecordKind::Interface:
121  return PDB_UdtType::Interface;
122  default:
123  llvm_unreachable("Unexpected udt kind");
124  }
125 }
126 
128  if (UnmodifiedType)
129  return UnmodifiedType->hasConstructor();
130 
131  return (Tag->Options & ClassOptions::HasConstructorOrDestructor) !=
133 }
134 
136  if (!Modifiers)
137  return false;
138  return (Modifiers->Modifiers & ModifierOptions::Const) !=
140 }
141 
143  if (UnmodifiedType)
145 
146  return (Tag->Options & ClassOptions::HasOverloadedAssignmentOperator) !=
148 }
149 
151  if (UnmodifiedType)
153 
154  return (Tag->Options & ClassOptions::HasConversionOperator) !=
156 }
157 
159  if (UnmodifiedType)
160  return UnmodifiedType->hasNestedTypes();
161 
162  return (Tag->Options & ClassOptions::ContainsNestedClass) !=
164 }
165 
167  if (UnmodifiedType)
169 
170  return (Tag->Options & ClassOptions::HasOverloadedOperator) !=
172 }
173 
174 bool NativeTypeUDT::isInterfaceUdt() const { return false; }
175 
177  if (UnmodifiedType)
178  return UnmodifiedType->isIntrinsic();
179 
180  return (Tag->Options & ClassOptions::Intrinsic) != ClassOptions::None;
181 }
182 
184  if (UnmodifiedType)
185  return UnmodifiedType->isNested();
186 
187  return (Tag->Options & ClassOptions::Nested) != ClassOptions::None;
188 }
189 
191  if (UnmodifiedType)
192  return UnmodifiedType->isPacked();
193 
194  return (Tag->Options & ClassOptions::Packed) != ClassOptions::None;
195 }
196 
197 bool NativeTypeUDT::isRefUdt() const { return false; }
198 
200  if (UnmodifiedType)
201  return UnmodifiedType->isScoped();
202 
203  return (Tag->Options & ClassOptions::Scoped) != ClassOptions::None;
204 }
205 
206 bool NativeTypeUDT::isValueUdt() const { return false; }
207 
209  if (!Modifiers)
210  return false;
211  return (Modifiers->Modifiers & ModifierOptions::Unaligned) !=
213 }
214 
216  if (!Modifiers)
217  return false;
218  return (Modifiers->Modifiers & ModifierOptions::Volatile) !=
220 }
llvm::pdb::PDB_UdtType::Interface
@ Interface
llvm::pdb::NativeTypeUDT::isRefUdt
bool isRefUdt() const override
Definition: NativeTypeUDT.cpp:197
llvm::pdb::PDB_UdtType::Struct
@ Struct
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::pdb::NativeTypeUDT::isPacked
bool isPacked() const override
Definition: NativeTypeUDT.cpp:190
llvm::pdb::NativeTypeUDT::hasOverloadedOperator
bool hasOverloadedOperator() const override
Definition: NativeTypeUDT.cpp:166
llvm::pdb::NativeTypeUDT
Definition: NativeTypeUDT.h:21
llvm::pdb::NativeTypeUDT::isConstType
bool isConstType() const override
Definition: NativeTypeUDT.cpp:135
llvm::pdb::NativeTypeUDT::isNested
bool isNested() const override
Definition: NativeTypeUDT.cpp:183
llvm::pdb::PDB_UdtType
PDB_UdtType
These values correspond to the UdtKind enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:310
llvm::pdb::NativeTypeUDT::Modifiers
Optional< codeview::ModifierRecord > Modifiers
Definition: NativeTypeUDT.h:67
llvm::pdb::NativeTypeUDT::getName
std::string getName() const override
Definition: NativeTypeUDT.cpp:73
llvm::pdb::PdbSymbolIdField::UnmodifiedType
@ UnmodifiedType
llvm::pdb::NativeTypeUDT::isInterfaceUdt
bool isInterfaceUdt() const override
Definition: NativeTypeUDT.cpp:174
llvm::pdb::NativeTypeUDT::getUnmodifiedTypeId
SymIndexId getUnmodifiedTypeId() const override
Definition: NativeTypeUDT.cpp:82
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::NativeTypeUDT::getLength
uint64_t getLength() const override
Definition: NativeTypeUDT.cpp:99
llvm::pdb::NativeTypeUDT::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeTypeUDT.cpp:37
llvm::pdb::PdbSymbolIdField::LexicalParent
@ LexicalParent
llvm::pdb::NativeTypeUDT::getUdtKind
PDB_UdtType getUdtKind() const override
Definition: NativeTypeUDT.cpp:109
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::NativeTypeUDT::NativeTypeUDT
NativeTypeUDT(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ClassRecord Class)
Definition: NativeTypeUDT.cpp:19
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::codeview::ModifierRecord
Definition: TypeRecord.h:129
llvm::None
const NoneType None
Definition: None.h:23
llvm::pdb::NativeTypeUDT::~NativeTypeUDT
~NativeTypeUDT() override
Definition: NativeTypeUDT.cpp:35
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::NativeTypeUDT::Class
Optional< codeview::ClassRecord > Class
Definition: NativeTypeUDT.h:63
llvm::codeview::TagRecord::getName
StringRef getName() const
Definition: TypeRecord.h:453
llvm::pdb::NativeTypeUDT::isVolatileType
bool isVolatileType() const override
Definition: NativeTypeUDT.cpp:215
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::pdb::NativeTypeUDT::hasAssignmentOperator
bool hasAssignmentOperator() const override
Definition: NativeTypeUDT.cpp:142
llvm::pdb::NativeTypeUDT::isScoped
bool isScoped() const override
Definition: NativeTypeUDT.cpp:199
llvm::pdb::NativeTypeUDT::Tag
codeview::TagRecord * Tag
Definition: NativeTypeUDT.h:66
llvm::pdb::dumpSymbolField
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
llvm::codeview::TagRecord::Options
ClassOptions Options
Definition: TypeRecord.h:457
llvm::pdb::dumpSymbolIdField
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
llvm::codeview::TypeRecord::Kind
TypeRecordKind Kind
Definition: TypeRecord.h:125
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:109
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::pdb::PDB_UdtType::Class
@ Class
llvm::pdb::PDB_UdtType::Union
@ Union
llvm::pdb::NativeRawSymbol::getSymIndexId
SymIndexId getSymIndexId() const override
Definition: NativeRawSymbol.cpp:292
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
uint32_t
llvm::pdb::NativeTypeUDT::isIntrinsic
bool isIntrinsic() const override
Definition: NativeTypeUDT.cpp:176
llvm::pdb::NativeTypeUDT::getLexicalParentId
SymIndexId getLexicalParentId() const override
Definition: NativeTypeUDT.cpp:80
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:153
std
Definition: BitVector.h:838
NativeTypeUDT.h
TypeDeserializer.h
llvm::pdb::NativeTypeUDT::hasConstructor
bool hasConstructor() const override
Definition: NativeTypeUDT.cpp:127
llvm::codeview::UnionRecord
Definition: TypeRecord.h:497
llvm::pdb::NativeTypeUDT::hasCastOperator
bool hasCastOperator() const override
Definition: NativeTypeUDT.cpp:150
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:22
llvm::pdb::NativeSession
Definition: NativeSession.h:28
llvm::tgtok::Class
@ Class
Definition: TGLexer.h:50
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::pdb::NativeTypeUDT::getVirtualTableShapeId
SymIndexId getVirtualTableShapeId() const override
Definition: NativeTypeUDT.cpp:89
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::codeview::ClassRecord
Definition: TypeRecord.h:464
llvm::pdb::NativeTypeUDT::isUnalignedType
bool isUnalignedType() const override
Definition: NativeTypeUDT.cpp:208
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:231
llvm::pdb::NativeTypeUDT::UnmodifiedType
NativeTypeUDT * UnmodifiedType
Definition: NativeTypeUDT.h:65
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
llvm::pdb::NativeTypeUDT::isValueUdt
bool isValueUdt() const override
Definition: NativeTypeUDT.cpp:206
llvm::pdb::NativeTypeUDT::Union
Optional< codeview::UnionRecord > Union
Definition: NativeTypeUDT.h:64
llvm::pdb::NativeTypeUDT::hasNestedTypes
bool hasNestedTypes() const override
Definition: NativeTypeUDT.cpp:158