LLVM  8.0.1
NativeEnumTypes.cpp
Go to the documentation of this file.
1 //==- NativeEnumTypes.cpp - Native Type Enumerator impl ----------*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 using namespace llvm::pdb;
23 
24 NativeEnumTypes::NativeEnumTypes(NativeSession &PDBSession,
26  std::vector<codeview::TypeLeafKind> Kinds)
27  : Matches(), Index(0), Session(PDBSession) {
28  Optional<TypeIndex> TI = Types.getFirst();
29  while (TI) {
30  CVType CVT = Types.getType(*TI);
31  TypeLeafKind K = CVT.kind();
32  if (llvm::is_contained(Kinds, K)) {
33  // Don't add forward refs, we'll find those later while enumerating.
34  if (!isUdtForwardRef(CVT))
35  Matches.push_back(*TI);
36  } else if (K == TypeLeafKind::LF_MODIFIER) {
37  TypeIndex ModifiedTI = getModifiedType(CVT);
38  if (!ModifiedTI.isSimple()) {
39  CVType UnmodifiedCVT = Types.getType(ModifiedTI);
40  // LF_MODIFIERs point to forward refs, but don't worry about that
41  // here. We're pushing the TypeIndex of the LF_MODIFIER itself,
42  // so we'll worry about resolving forward refs later.
43  if (llvm::is_contained(Kinds, UnmodifiedCVT.kind()))
44  Matches.push_back(*TI);
45  }
46  }
47  TI = Types.getNext(*TI);
48  }
49 }
50 
52  std::vector<codeview::TypeIndex> Indices)
53  : Matches(std::move(Indices)), Index(0), Session(PDBSession) {}
54 
56  return static_cast<uint32_t>(Matches.size());
57 }
58 
59 std::unique_ptr<PDBSymbol> NativeEnumTypes::getChildAtIndex(uint32_t N) const {
60  if (N < Matches.size()) {
61  SymIndexId Id = Session.getSymbolCache().findSymbolByTypeIndex(Matches[N]);
62  return Session.getSymbolCache().getSymbolById(Id);
63  }
64  return nullptr;
65 }
66 
67 std::unique_ptr<PDBSymbol> NativeEnumTypes::getNext() {
68  return getChildAtIndex(Index++);
69 }
70 
71 void NativeEnumTypes::reset() { Index = 0; }
Kind kind() const
Definition: CVRecord.h:37
This class represents lattice values for constants.
Definition: AllocatorList.h:24
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
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:938
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:96
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:1245