LLVM  10.0.0svn
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; }
Kind kind() const
Definition: CVRecord.h:43
This class represents lattice values for constants.
Definition: AllocatorList.h:23
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:33
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE, LF_UNION, or LF_ENUM with the forward ref class option.
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: BitVector.h:937
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...
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
std::unique_ptr< PDBSymbol > getNext() override
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
A 32-bit type reference.
Definition: TypeIndex.h:95
NativeEnumTypes(NativeSession &Session, codeview::LazyRandomTypeCollection &TypeCollection, std::vector< codeview::TypeLeafKind > Kinds)
uint32_t getChildCount() const override
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI)
#define N
SymbolCache & getSymbolCache()
Provides amortized O(1) random access to a CodeView type stream.
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:1224