xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- DIAEnumTables.cpp - DIA Table Enumerator Impl ------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIAEnumTables.h"
10*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIATable.h"
11*0b57cec5SDimitry Andric 
12*0b57cec5SDimitry Andric using namespace llvm;
13*0b57cec5SDimitry Andric using namespace llvm::pdb;
14*0b57cec5SDimitry Andric 
DIAEnumTables(CComPtr<IDiaEnumTables> DiaEnumerator)15*0b57cec5SDimitry Andric DIAEnumTables::DIAEnumTables(CComPtr<IDiaEnumTables> DiaEnumerator)
16*0b57cec5SDimitry Andric     : Enumerator(DiaEnumerator) {}
17*0b57cec5SDimitry Andric 
getChildCount() const18*0b57cec5SDimitry Andric uint32_t DIAEnumTables::getChildCount() const {
19*0b57cec5SDimitry Andric   LONG Count = 0;
20*0b57cec5SDimitry Andric   return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
21*0b57cec5SDimitry Andric }
22*0b57cec5SDimitry Andric 
23*0b57cec5SDimitry Andric std::unique_ptr<IPDBTable>
getChildAtIndex(uint32_t Index) const24*0b57cec5SDimitry Andric DIAEnumTables::getChildAtIndex(uint32_t Index) const {
25*0b57cec5SDimitry Andric   CComPtr<IDiaTable> Item;
26*0b57cec5SDimitry Andric   VARIANT Var;
27*0b57cec5SDimitry Andric   Var.vt = VT_UINT;
28*0b57cec5SDimitry Andric   Var.uintVal = Index;
29*0b57cec5SDimitry Andric   if (S_OK != Enumerator->Item(Var, &Item))
30*0b57cec5SDimitry Andric     return nullptr;
31*0b57cec5SDimitry Andric 
32*0b57cec5SDimitry Andric   return std::unique_ptr<IPDBTable>(new DIATable(Item));
33*0b57cec5SDimitry Andric }
34*0b57cec5SDimitry Andric 
getNext()35*0b57cec5SDimitry Andric std::unique_ptr<IPDBTable> DIAEnumTables::getNext() {
36*0b57cec5SDimitry Andric   CComPtr<IDiaTable> Item;
37*0b57cec5SDimitry Andric   ULONG CeltFetched = 0;
38*0b57cec5SDimitry Andric   if (S_OK != Enumerator->Next(1, &Item, &CeltFetched))
39*0b57cec5SDimitry Andric     return nullptr;
40*0b57cec5SDimitry Andric 
41*0b57cec5SDimitry Andric   return std::unique_ptr<IPDBTable>(new DIATable(Item));
42*0b57cec5SDimitry Andric }
43*0b57cec5SDimitry Andric 
reset()44*0b57cec5SDimitry Andric void DIAEnumTables::reset() { Enumerator->Reset(); }
45