1 //==- DIAEnumDebugStreams.cpp - DIA Debug Stream Enumerator impl -*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
11 #include "llvm/DebugInfo/PDB/DIA/DIADataStream.h"
12 #include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h"
13 
14 using namespace llvm;
15 
DIAEnumDebugStreams(CComPtr<IDiaEnumDebugStreams> DiaEnumerator)16 DIAEnumDebugStreams::DIAEnumDebugStreams(
17     CComPtr<IDiaEnumDebugStreams> DiaEnumerator)
18     : Enumerator(DiaEnumerator) {}
19 
getChildCount() const20 uint32_t DIAEnumDebugStreams::getChildCount() const {
21   LONG Count = 0;
22   return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
23 }
24 
25 std::unique_ptr<IPDBDataStream>
getChildAtIndex(uint32_t Index) const26 DIAEnumDebugStreams::getChildAtIndex(uint32_t Index) const {
27   CComPtr<IDiaEnumDebugStreamData> Item;
28   VARIANT VarIndex;
29   VarIndex.vt = VT_I4;
30   VarIndex.lVal = Index;
31   if (S_OK != Enumerator->Item(VarIndex, &Item))
32     return nullptr;
33 
34   return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item));
35 }
36 
getNext()37 std::unique_ptr<IPDBDataStream> DIAEnumDebugStreams::getNext() {
38   CComPtr<IDiaEnumDebugStreamData> Item;
39   ULONG NumFetched = 0;
40   if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
41     return nullptr;
42 
43   return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item));
44 }
45 
reset()46 void DIAEnumDebugStreams::reset() { Enumerator->Reset(); }
47 
clone() const48 DIAEnumDebugStreams *DIAEnumDebugStreams::clone() const {
49   CComPtr<IDiaEnumDebugStreams> EnumeratorClone;
50   if (S_OK != Enumerator->Clone(&EnumeratorClone))
51     return nullptr;
52   return new DIAEnumDebugStreams(EnumeratorClone);
53 }
54