LLVM  9.0.0svn
NativeEnumGlobals.cpp
Go to the documentation of this file.
1 //==- NativeEnumGlobals.cpp - Native Global 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 NativeEnumGlobals::NativeEnumGlobals(NativeSession &PDBSession,
24  std::vector<codeview::SymbolKind> Kinds)
25  : Index(0), Session(PDBSession) {
28  for (uint32_t Off : GS.getGlobalsTable()) {
29  CVSymbol S = SS.readRecord(Off);
30  if (!llvm::is_contained(Kinds, S.kind()))
31  continue;
32  MatchOffsets.push_back(Off);
33  }
34 }
35 
37  return static_cast<uint32_t>(MatchOffsets.size());
38 }
39 
40 std::unique_ptr<PDBSymbol>
42  if (N >= MatchOffsets.size())
43  return nullptr;
44 
45  SymIndexId Id =
46  Session.getSymbolCache().getOrCreateGlobalSymbolByOffset(MatchOffsets[N]);
47  return Session.getSymbolCache().getSymbolById(Id);
48 }
49 
50 std::unique_ptr<PDBSymbol> NativeEnumGlobals::getNext() {
51  return getChildAtIndex(Index++);
52 }
53 
54 void NativeEnumGlobals::reset() { Index = 0; }
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:703
Kind kind() const
Definition: CVRecord.h:43
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Expected< GlobalsStream & > getPDBGlobalsStream()
Definition: PDBFile.cpp:255
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
uint32_t getChildCount() const override
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
Expected< SymbolStream & > getPDBSymbolStream()
Definition: PDBFile.cpp:346
std::unique_ptr< PDBSymbol > getNext() override
SymIndexId getOrCreateGlobalSymbolByOffset(uint32_t Offset)
#define N
const GSIHashTable & getGlobalsTable() const
Definition: GlobalsStream.h:74
SymbolCache & getSymbolCache()
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:30
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:1251