LLVM  14.0.0git
NativeEnumTypes.cpp
Go to the documentation of this file.
1 //==- NativeEnumTypes.cpp - Native Type Enumerator impl ----------*- 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 
18 
19 using namespace llvm;
20 using namespace llvm::codeview;
21 using namespace llvm::pdb;
22 
23 NativeEnumTypes::NativeEnumTypes(NativeSession &PDBSession,
25  std::vector<codeview::TypeLeafKind> Kinds)
26  : Matches(), Index(0), Session(PDBSession) {
27  Optional<TypeIndex> TI = Types.getFirst();
28  while (TI) {
29  CVType CVT = Types.getType(*TI);
30  TypeLeafKind K = CVT.kind();
31  if (llvm::is_contained(Kinds, K)) {
32  // Don't add forward refs, we'll find those later while enumerating.
33  if (!isUdtForwardRef(CVT))
34  Matches.push_back(*TI);
35  } else if (K == TypeLeafKind::LF_MODIFIER) {
36  TypeIndex ModifiedTI = getModifiedType(CVT);
37  if (!ModifiedTI.isSimple()) {
38  CVType UnmodifiedCVT = Types.getType(ModifiedTI);
39  // LF_MODIFIERs point to forward refs, but don't worry about that
40  // here. We're pushing the TypeIndex of the LF_MODIFIER itself,
41  // so we'll worry about resolving forward refs later.
42  if (llvm::is_contained(Kinds, UnmodifiedCVT.kind()))
43  Matches.push_back(*TI);
44  }
45  }
46  TI = Types.getNext(*TI);
47  }
48 }
49 
51  std::vector<codeview::TypeIndex> Indices)
52  : Matches(std::move(Indices)), Index(0), Session(PDBSession) {}
53 
55  return static_cast<uint32_t>(Matches.size());
56 }
57 
58 std::unique_ptr<PDBSymbol> NativeEnumTypes::getChildAtIndex(uint32_t N) const {
59  if (N < Matches.size()) {
60  SymIndexId Id = Session.getSymbolCache().findSymbolByTypeIndex(Matches[N]);
61  return Session.getSymbolCache().getSymbolById(Id);
62  }
63  return nullptr;
64 }
65 
66 std::unique_ptr<PDBSymbol> NativeEnumTypes::getNext() {
67  return getChildAtIndex(Index++);
68 }
69 
70 void NativeEnumTypes::reset() { Index = 0; }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::pdb::NativeEnumTypes::reset
void reset() override
Definition: NativeEnumTypes.cpp:70
llvm::Optional
Definition: APInt.h:33
llvm::codeview::isUdtForwardRef
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
Definition: TypeRecordHelpers.cpp:27
llvm::pdb::NativeEnumTypes::NativeEnumTypes
NativeEnumTypes(NativeSession &Session, codeview::LazyRandomTypeCollection &TypeCollection, std::vector< codeview::TypeLeafKind > Kinds)
Definition: NativeEnumTypes.cpp:23
llvm::codeview::getModifiedType
TypeIndex getModifiedType(const CVType &CVT)
Given a CVType which is assumed to be an LF_MODIFIER, return the TypeIndex of the type that the LF_MO...
Definition: TypeRecordHelpers.cpp:47
llvm::pdb::NativeEnumTypes::getNext
std::unique_ptr< PDBSymbol > getNext() override
Definition: NativeEnumTypes.cpp:66
PDBSymbolTypeEnum.h
llvm::codeview::LazyRandomTypeCollection
Provides amortized O(1) random access to a CodeView type stream.
Definition: LazyRandomTypeCollection.h:49
PDBSymbol.h
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::SymbolCache::getSymbolById
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
Definition: SymbolCache.cpp:242
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::codeview::CVRecord::kind
Kind kind() const
Definition: CVRecord.h:43
llvm::pdb::NativeEnumTypes::getChildCount
uint32_t getChildCount() const override
Definition: NativeEnumTypes.cpp:54
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1614
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:109
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:1607
TypeRecordHelpers.h
NativeEnumTypes.h
llvm::codeview::CVRecord< TypeLeafKind >
uint32_t
llvm::codeview::LazyRandomTypeCollection::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: LazyRandomTypeCollection.cpp:213
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:153
std
Definition: BitVector.h:838
TypeDeserializer.h
llvm::pdb::NativeSession
Definition: NativeSession.h:28
NativeTypeEnum.h
llvm::codeview::TypeLeafKind
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:33
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition: TypeIndex.h:112
N
#define N
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:95
llvm::codeview::LazyRandomTypeCollection::getFirst
Optional< TypeIndex > getFirst() override
Definition: LazyRandomTypeCollection.cpp:204
llvm::codeview::LazyRandomTypeCollection::getType
CVType getType(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:90
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:228
llvm::pdb::NativeEnumTypes::getChildAtIndex
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
Definition: NativeEnumTypes.cpp:58
NativeSession.h