DxilDiaEnumTables.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilDiaEnumTables.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // DIA API implementation for DXIL modules. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "DxilDiaEnumTables.h"
  12. #include "DxilDia.h"
  13. #include "DxilDiaSession.h"
  14. #include "DxilDiaTable.h"
  15. STDMETHODIMP dxil_dia::EnumTables::get_Count(_Out_ LONG *pRetVal) {
  16. *pRetVal = ((unsigned)Table::LastKind - (unsigned)Table::FirstKind) + 1;
  17. return S_OK;
  18. }
  19. STDMETHODIMP dxil_dia::EnumTables::Item(
  20. /* [in] */ VARIANT index,
  21. /* [retval][out] */ IDiaTable **table) {
  22. // Avoid pulling in additional variant support (could have used VariantChangeType instead).
  23. DWORD indexVal;
  24. switch (index.vt) {
  25. case VT_UI4:
  26. indexVal = index.uintVal;
  27. break;
  28. case VT_I4:
  29. IFR(IntToDWord(index.intVal, &indexVal));
  30. break;
  31. default:
  32. return E_INVALIDARG;
  33. }
  34. if (indexVal > (unsigned)Table::LastKind) {
  35. return E_INVALIDARG;
  36. }
  37. HRESULT hr = S_OK;
  38. if (!m_tables[indexVal]) {
  39. DxcThreadMalloc TM(m_pMalloc);
  40. hr = Table::Create(m_pSession, (Table::Kind)indexVal, &m_tables[indexVal]);
  41. }
  42. m_tables[indexVal].p->AddRef();
  43. *table = m_tables[indexVal];
  44. return hr;
  45. }
  46. STDMETHODIMP dxil_dia::EnumTables::Next(
  47. ULONG celt,
  48. IDiaTable **rgelt,
  49. ULONG *pceltFetched) {
  50. DxcThreadMalloc TM(m_pMalloc);
  51. ULONG fetched = 0;
  52. while (fetched < celt && m_next <= (unsigned)Table::LastKind) {
  53. HRESULT hr = S_OK;
  54. if (!m_tables[m_next]) {
  55. DxcThreadMalloc TM(m_pMalloc);
  56. hr = Table::Create(m_pSession, (Table::Kind)m_next, &m_tables[m_next]);
  57. if (FAILED(hr)) {
  58. return hr; // TODO: this leaks prior tables.
  59. }
  60. }
  61. m_tables[m_next].p->AddRef();
  62. rgelt[fetched] = m_tables[m_next];
  63. ++m_next, ++fetched;
  64. }
  65. if (pceltFetched != nullptr)
  66. *pceltFetched = fetched;
  67. return (fetched == celt) ? S_OK : S_FALSE;
  68. }
  69. STDMETHODIMP dxil_dia::EnumTables::Reset() {
  70. m_next = 0;
  71. return S_OK;
  72. }
  73. HRESULT dxil_dia::EnumTables::Create(
  74. /* [in] */ dxil_dia::Session *pSession,
  75. /* [out] */ IDiaEnumTables **ppEnumTables) {
  76. *ppEnumTables = CreateOnMalloc<EnumTables>(pSession->GetMallocNoRef(), pSession);
  77. if (*ppEnumTables == nullptr)
  78. return E_OUTOFMEMORY;
  79. (*ppEnumTables)->AddRef();
  80. return S_OK;
  81. }