LLVM 20.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
11#include "llvm/ADT/STLExtras.h"
19
20using namespace llvm;
21using namespace llvm::codeview;
22using namespace llvm::pdb;
23
26 std::vector<codeview::TypeLeafKind> Kinds)
27 : Index(0), Session(PDBSession) {
28 std::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
59std::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
67std::unique_ptr<PDBSymbol> NativeEnumTypes::getNext() {
68 return getChildAtIndex(Index++);
69}
70
71void NativeEnumTypes::reset() { Index = 0; }
This file contains some templates that are useful if you are working with the STL at all.
Kind kind() const
Definition: CVRecord.h:42
Provides amortized O(1) random access to a CodeView type stream.
A 32-bit type reference.
Definition: TypeIndex.h:96
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
NativeEnumTypes(NativeSession &Session, codeview::LazyRandomTypeCollection &TypeCollection, std::vector< codeview::TypeLeafKind > Kinds)
uint32_t getChildCount() const override
std::unique_ptr< PDBSymbol > getNext() override
SymbolCache & getSymbolCache()
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
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...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1873
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N