LLVM 19.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"
20
21using namespace llvm;
22using namespace llvm::codeview;
23using namespace llvm::pdb;
24
27 std::vector<codeview::TypeLeafKind> Kinds)
28 : Index(0), Session(PDBSession) {
29 std::optional<TypeIndex> TI = Types.getFirst();
30 while (TI) {
31 CVType CVT = Types.getType(*TI);
32 TypeLeafKind K = CVT.kind();
33 if (llvm::is_contained(Kinds, K)) {
34 // Don't add forward refs, we'll find those later while enumerating.
35 if (!isUdtForwardRef(CVT))
36 Matches.push_back(*TI);
37 } else if (K == TypeLeafKind::LF_MODIFIER) {
38 TypeIndex ModifiedTI = getModifiedType(CVT);
39 if (!ModifiedTI.isSimple()) {
40 CVType UnmodifiedCVT = Types.getType(ModifiedTI);
41 // LF_MODIFIERs point to forward refs, but don't worry about that
42 // here. We're pushing the TypeIndex of the LF_MODIFIER itself,
43 // so we'll worry about resolving forward refs later.
44 if (llvm::is_contained(Kinds, UnmodifiedCVT.kind()))
45 Matches.push_back(*TI);
46 }
47 }
48 TI = Types.getNext(*TI);
49 }
50}
51
53 std::vector<codeview::TypeIndex> Indices)
54 : Matches(std::move(Indices)), Index(0), Session(PDBSession) {}
55
57 return static_cast<uint32_t>(Matches.size());
58}
59
60std::unique_ptr<PDBSymbol> NativeEnumTypes::getChildAtIndex(uint32_t N) const {
61 if (N < Matches.size()) {
62 SymIndexId Id = Session.getSymbolCache().findSymbolByTypeIndex(Matches[N]);
63 return Session.getSymbolCache().getSymbolById(Id);
64 }
65 return nullptr;
66}
67
68std::unique_ptr<PDBSymbol> NativeEnumTypes::getNext() {
69 return getChildAtIndex(Index++);
70}
71
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:1858
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1888
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N