[~] pyDia: prepare for c++ use

git-svn-id: https://pykd.svn.codeplex.com/svn@69945 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-09-22 07:33:53 +00:00 committed by Mikhail I. Izmestev
parent 03e052a418
commit c868fbfb28
2 changed files with 40 additions and 24 deletions

View File

@ -217,28 +217,33 @@ ULONG Symbol::getLocType()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Symbol::getValueImpl(VARIANT &vtValue)
python::object Symbol::getValue()
{ {
throwIfNull(__FUNCTION__); throwIfNull(__FUNCTION__);
VARIANT variant = { VT_EMPTY }; HRESULT hres = m_symbol->get_value(&vtValue);
HRESULT hres = m_symbol->get_value(&variant);
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaSymbol::get_value", hres); throw Exception("Call IDiaSymbol::get_value", hres);
}
switch (variant.vt) ////////////////////////////////////////////////////////////////////////////////
python::object Symbol::getValue()
{
VARIANT vtValue = { VT_EMPTY };
getValueImpl(vtValue);
switch (vtValue.vt)
{ {
case VT_I1: case VT_I1:
case VT_UI1: case VT_UI1:
return python::object( static_cast<ULONG>(variant.bVal) ); return python::object( static_cast<ULONG>(vtValue.bVal) );
case VT_BOOL: case VT_BOOL:
return python::object( static_cast<bool>(!!variant.iVal) ); return python::object( static_cast<bool>(!!vtValue.iVal) );
case VT_I2: case VT_I2:
case VT_UI2: case VT_UI2:
return python::object( static_cast<ULONG>(variant.iVal) ); return python::object( static_cast<ULONG>(vtValue.iVal) );
case VT_I4: case VT_I4:
case VT_UI4: case VT_UI4:
@ -246,20 +251,20 @@ python::object Symbol::getValue()
case VT_UINT: case VT_UINT:
case VT_ERROR: case VT_ERROR:
case VT_HRESULT: case VT_HRESULT:
return python::object( variant.lVal ); return python::object( vtValue.lVal );
case VT_I8: case VT_I8:
case VT_UI8: case VT_UI8:
return python::object( variant.llVal ); return python::object( vtValue.llVal );
case VT_R4: case VT_R4:
return python::object( variant.fltVal ); return python::object( vtValue.fltVal );
case VT_R8: case VT_R8:
return python::object( variant.dblVal ); return python::object( vtValue.dblVal );
case VT_BSTR: case VT_BSTR:
return python::object( autoBstr::asStr(variant.bstrVal).c_str() ); return python::object( autoBstr::asStr(vtValue.bstrVal).c_str() );
} }
throw Exception("Unknown value type"); throw Exception("Unknown value type");
@ -293,7 +298,7 @@ ULONG Symbol::getBitPosition()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
python::object Symbol::getChildByName(const std::string &_name) Symbol Symbol::getChildByName(const std::string &_name)
{ {
throwIfNull(__FUNCTION__); throwIfNull(__FUNCTION__);
@ -323,7 +328,7 @@ python::object Symbol::getChildByName(const std::string &_name)
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres); throw Exception("Call IDiaEnumSymbols::Item", hres);
return python::object( Symbol(child) ); return Symbol(child);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -352,7 +357,7 @@ ULONG Symbol::getChildCount()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
python::object Symbol::getChildByIndex(ULONG _index) Symbol Symbol::getChildByIndex(ULONG _index)
{ {
throwIfNull(__FUNCTION__); throwIfNull(__FUNCTION__);
@ -379,7 +384,7 @@ python::object Symbol::getChildByIndex(ULONG _index)
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres); throw Exception("Call IDiaEnumSymbols::Item", hres);
return python::object( Symbol(child) ); return Symbol(child);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -392,6 +397,7 @@ std::string Symbol::print()
DWORD dwValue; DWORD dwValue;
autoBstr bstrValue; autoBstr bstrValue;
VARIANT vtValue = { VT_EMPTY }; VARIANT vtValue = { VT_EMPTY };
bool bValue;
sstream << "symTag: "; sstream << "symTag: ";
HRESULT hres = m_symbol->get_symTag(&dwValue); HRESULT hres = m_symbol->get_symTag(&dwValue);
@ -421,8 +427,17 @@ std::string Symbol::print()
} }
} }
hres = m_symbol->get_value(&vtValue); bValue = false;
if (S_OK == hres) try
{
getValueImpl(vtValue);
bValue = true;
}
catch (const Exception &except)
{
DBG_UNREFERENCED_PARAMETER(except);
}
if (bValue)
{ {
switch (vtValue.vt) switch (vtValue.vt)
{ {
@ -507,7 +522,7 @@ GlobalScope::GlobalScope(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
python::object GlobalScope::openPdb(const std::string &filePath) GlobalScope GlobalScope::openPdb(const std::string &filePath)
{ {
DiaDataSourcePtr _scope; DiaDataSourcePtr _scope;
@ -530,7 +545,7 @@ python::object GlobalScope::openPdb(const std::string &filePath)
if ( S_OK != hres ) if ( S_OK != hres )
throw Exception("Call IDiaSymbol::get_globalScope", hres); throw Exception("Call IDiaSymbol::get_globalScope", hres);
return python::object(GlobalScope(_scope, _session, _globalScope)); return GlobalScope(_scope, _session, _globalScope);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -94,6 +94,7 @@ public:
ULONG getLocType(); ULONG getLocType();
void getValueImpl(VARIANT &vtValue);
python::object getValue(); python::object getValue();
bool isBasicType(); bool isBasicType();
@ -102,9 +103,9 @@ public:
ULONG getBitPosition(); ULONG getBitPosition();
python::object getChildByName(const std::string &_name); Symbol getChildByName(const std::string &_name);
ULONG getChildCount(); ULONG getChildCount();
python::object getChildByIndex(ULONG _index); Symbol getChildByIndex(ULONG _index);
std::string print(); std::string print();
@ -160,7 +161,7 @@ public:
GlobalScope() {} GlobalScope() {}
// create GlobalScope instance // create GlobalScope instance
static python::object openPdb(const std::string &filePath); static GlobalScope openPdb(const std::string &filePath);
private: private: