1 //==- NativeEnumTypes.cpp - Native Type Enumerator impl ----------*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
11 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
12 #include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
15 #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
20 using namespace llvm::codeview
;
21 using namespace llvm::pdb
;
23 NativeEnumTypes::NativeEnumTypes(NativeSession
&PDBSession
,
24 LazyRandomTypeCollection
&Types
,
25 std::vector
<codeview::TypeLeafKind
> Kinds
)
26 : Matches(), Index(0), Session(PDBSession
) {
27 Optional
<TypeIndex
> TI
= Types
.getFirst();
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
);
46 TI
= Types
.getNext(*TI
);
50 NativeEnumTypes::NativeEnumTypes(NativeSession
&PDBSession
,
51 std::vector
<codeview::TypeIndex
> Indices
)
52 : Matches(std::move(Indices
)), Index(0), Session(PDBSession
) {}
54 uint32_t NativeEnumTypes::getChildCount() const {
55 return static_cast<uint32_t>(Matches
.size());
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
);
66 std::unique_ptr
<PDBSymbol
> NativeEnumTypes::getNext() {
67 return getChildAtIndex(Index
++);
70 void NativeEnumTypes::reset() { Index
= 0; }