LLVM  15.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 
15 
16 using namespace llvm;
17 using namespace llvm::codeview;
18 using namespace llvm::pdb;
19 
20 NativeTypeUDT::NativeTypeUDT(NativeSession &Session, SymIndexId Id,
22  : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
23  Class(std::move(CR)), Tag(Class.getPointer()) {}
24 
27  : NativeRawSymbol(Session, PDB_SymType::UDT, Id), Index(TI),
28  Union(std::move(UR)), Tag(Union.getPointer()) {}
29 
31  NativeTypeUDT &UnmodifiedType,
32  codeview::ModifierRecord Modifier)
33  : NativeRawSymbol(Session, PDB_SymType::UDT, Id),
34  UnmodifiedType(&UnmodifiedType), Modifiers(std::move(Modifier)) {}
35 
37 
38 void NativeTypeUDT::dump(raw_ostream &OS, int Indent,
39  PdbSymbolIdField ShowIdFields,
40  PdbSymbolIdField RecurseIdFields) const {
41 
42  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
43 
44  dumpSymbolField(OS, "name", getName(), Indent);
45  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
46  PdbSymbolIdField::LexicalParent, ShowIdFields,
47  RecurseIdFields);
48  if (Modifiers.hasValue())
49  dumpSymbolIdField(OS, "unmodifiedTypeId", getUnmodifiedTypeId(), Indent,
51  RecurseIdFields);
53  dumpSymbolField(OS, "virtualTableShapeId", getVirtualTableShapeId(),
54  Indent);
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);
72 }
73 
74 std::string NativeTypeUDT::getName() const {
75  if (UnmodifiedType)
76  return UnmodifiedType->getName();
77 
78  return std::string(Tag->getName());
79 }
80 
82 
84  if (UnmodifiedType)
85  return UnmodifiedType->getSymIndexId();
86 
87  return 0;
88 }
89 
91  if (UnmodifiedType)
93 
94  if (Class)
95  return Session.getSymbolCache().findSymbolByTypeIndex(Class->VTableShape);
96 
97  return 0;
98 }
99 
101  if (UnmodifiedType)
102  return UnmodifiedType->getLength();
103 
104  if (Class)
105  return Class->getSize();
106 
107  return Union->getSize();
108 }
109 
111  if (UnmodifiedType)
112  return UnmodifiedType->getUdtKind();
113 
114  switch (Tag->Kind) {
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;
123  default:
124  llvm_unreachable("Unexpected udt kind");
125  }
126 }
127 
129  if (UnmodifiedType)
130  return UnmodifiedType->hasConstructor();
131 
132  return (Tag->Options & ClassOptions::HasConstructorOrDestructor) !=
134 }
135 
137  if (!Modifiers)
138  return false;
139  return (Modifiers->Modifiers & ModifierOptions::Const) !=
141 }
142 
144  if (UnmodifiedType)
146 
147  return (Tag->Options & ClassOptions::HasOverloadedAssignmentOperator) !=
149 }
150 
152  if (UnmodifiedType)
154 
155  return (Tag->Options & ClassOptions::HasConversionOperator) !=
157 }
158 
160  if (UnmodifiedType)
161  return UnmodifiedType->hasNestedTypes();
162 
163  return (Tag->Options & ClassOptions::ContainsNestedClass) !=
165 }
166 
168  if (UnmodifiedType)
170 
171  return (Tag->Options & ClassOptions::HasOverloadedOperator) !=
173 }
174 
175 bool NativeTypeUDT::isInterfaceUdt() const { return false; }
176 
178  if (UnmodifiedType)
179  return UnmodifiedType->isIntrinsic();
180 
181  return (Tag->Options & ClassOptions::Intrinsic) != ClassOptions::None;
182 }
183 
185  if (UnmodifiedType)
186  return UnmodifiedType->isNested();
187 
188  return (Tag->Options & ClassOptions::Nested) != ClassOptions::None;
189 }
190 
192  if (UnmodifiedType)
193  return UnmodifiedType->isPacked();
194 
195  return (Tag->Options & ClassOptions::Packed) != ClassOptions::None;
196 }
197 
198 bool NativeTypeUDT::isRefUdt() const { return false; }
199 
201  if (UnmodifiedType)
202  return UnmodifiedType->isScoped();
203 
204  return (Tag->Options & ClassOptions::Scoped) != ClassOptions::None;
205 }
206 
207 bool NativeTypeUDT::isValueUdt() const { return false; }
208 
210  if (!Modifiers)
211  return false;
212  return (Modifiers->Modifiers & ModifierOptions::Unaligned) !=
214 }
215 
217  if (!Modifiers)
218  return false;
219  return (Modifiers->Modifiers & ModifierOptions::Volatile) !=
221 }
llvm::pdb::PDB_UdtType::Interface
@ Interface
llvm::pdb::NativeTypeUDT::isRefUdt
bool isRefUdt() const override
Definition: NativeTypeUDT.cpp:198
llvm::pdb::PDB_UdtType::Struct
@ Struct
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::pdb::NativeTypeUDT::isPacked
bool isPacked() const override
Definition: NativeTypeUDT.cpp:191
llvm::pdb::NativeTypeUDT::hasOverloadedOperator
bool hasOverloadedOperator() const override
Definition: NativeTypeUDT.cpp:167
llvm::pdb::NativeTypeUDT
Definition: NativeTypeUDT.h:25
llvm::pdb::NativeTypeUDT::isConstType
bool isConstType() const override
Definition: NativeTypeUDT.cpp:136
llvm::pdb::NativeTypeUDT::isNested
bool isNested() const override
Definition: NativeTypeUDT.cpp:184
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:71
llvm::pdb::NativeTypeUDT::getName
std::string getName() const override
Definition: NativeTypeUDT.cpp:74
llvm::pdb::PdbSymbolIdField::UnmodifiedType
@ UnmodifiedType
llvm::pdb::NativeTypeUDT::isInterfaceUdt
bool isInterfaceUdt() const override
Definition: NativeTypeUDT.cpp:175
llvm::pdb::NativeTypeUDT::getUnmodifiedTypeId
SymIndexId getUnmodifiedTypeId() const override
Definition: NativeTypeUDT.cpp:83
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:100
llvm::pdb::NativeTypeUDT::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeTypeUDT.cpp:38
llvm::pdb::PdbSymbolIdField::LexicalParent
@ LexicalParent
llvm::pdb::NativeTypeUDT::getUdtKind
PDB_UdtType getUdtKind() const override
Definition: NativeTypeUDT.cpp:110
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::NativeTypeUDT::NativeTypeUDT
NativeTypeUDT(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ClassRecord Class)
Definition: NativeTypeUDT.cpp:20
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::codeview::ModifierRecord
Definition: TypeRecord.h:130
CodeView.h
llvm::None
const NoneType None
Definition: None.h:24
llvm::pdb::NativeTypeUDT::~NativeTypeUDT
~NativeTypeUDT() override
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::NativeTypeUDT::Class
Optional< codeview::ClassRecord > Class
Definition: NativeTypeUDT.h:67
llvm::codeview::TagRecord::getName
StringRef getName() const
Definition: TypeRecord.h:454
llvm::pdb::NativeTypeUDT::isVolatileType
bool isVolatileType() const override
Definition: NativeTypeUDT.cpp:216
uint64_t
llvm::pdb::NativeTypeUDT::hasAssignmentOperator
bool hasAssignmentOperator() const override
Definition: NativeTypeUDT.cpp:143
llvm::pdb::NativeTypeUDT::isScoped
bool isScoped() const override
Definition: NativeTypeUDT.cpp:200
llvm::pdb::NativeTypeUDT::Tag
codeview::TagRecord * Tag
Definition: NativeTypeUDT.h:70
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:458
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:126
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:113
IPDBEnumChildren.h
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:1665
llvm::pdb::PDB_UdtType::Class
@ Class
llvm::pdb::PDB_UdtType::Union
@ Union
llvm::pdb::NativeRawSymbol::getSymIndexId
SymIndexId getSymIndexId() const override
Definition: NativeRawSymbol.cpp:291
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
uint32_t
llvm::pdb::NativeTypeUDT::isIntrinsic
bool isIntrinsic() const override
Definition: NativeTypeUDT.cpp:177
llvm::pdb::NativeTypeUDT::getLexicalParentId
SymIndexId getLexicalParentId() const override
Definition: NativeTypeUDT.cpp:81
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:158
std
Definition: BitVector.h:851
NativeTypeUDT.h
llvm::pdb::NativeTypeUDT::hasConstructor
bool hasConstructor() const override
Definition: NativeTypeUDT.cpp:128
llvm::codeview::UnionRecord
Definition: TypeRecord.h:498
llvm::pdb::NativeTypeUDT::hasCastOperator
bool hasCastOperator() const override
Definition: NativeTypeUDT.cpp:151
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:21
llvm::pdb::NativeSession
Definition: NativeSession.h:32
llvm::tgtok::Class
@ Class
Definition: TGLexer.h:50
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
PDBExtras.h
SymbolCache.h
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::pdb::NativeTypeUDT::getVirtualTableShapeId
SymIndexId getVirtualTableShapeId() const override
Definition: NativeTypeUDT.cpp:90
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::codeview::ClassRecord
Definition: TypeRecord.h:465
llvm::pdb::NativeTypeUDT::isUnalignedType
bool isUnalignedType() const override
Definition: NativeTypeUDT.cpp:209
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:235
llvm::pdb::NativeTypeUDT::UnmodifiedType
NativeTypeUDT * UnmodifiedType
Definition: NativeTypeUDT.h:69
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
llvm::pdb::NativeTypeUDT::isValueUdt
bool isValueUdt() const override
Definition: NativeTypeUDT.cpp:207
llvm::pdb::NativeTypeUDT::Union
Optional< codeview::UnionRecord > Union
Definition: NativeTypeUDT.h:68
NativeSession.h
llvm::pdb::NativeTypeUDT::hasNestedTypes
bool hasNestedTypes() const override
Definition: NativeTypeUDT.cpp:159