Commit c79f0797 authored by ussrhero's avatar ussrhero

added nullptr support for expression evaluator

parent 9ee1f620
......@@ -100,7 +100,7 @@ DataAccessorPtr getCacheAccessor(size_t bufferSize, const std::wstring& locatio
DataAccessorPtr getCacheAccessor(const void* rawBuffer, size_t bufferSize, const std::wstring& location=L"");
DataAccessorPtr getCacheAccessor(const NumVariant& var, const std::wstring& location=L"");
template<typename T>
template<typename T, typename std::enable_if< !std::is_integral<T>::value >::type* = nullptr >
DataAccessorPtr getCacheAccessor(const T& structType, const std::wstring& location=L"")
{
return getCacheAccessor(&structType, sizeof(structType), location);
......
......@@ -70,6 +70,7 @@ TypedVarPtr loadBoolVar( bool var );
TypedVarPtr loadFloatVar( float var );
TypedVarPtr loadDoubleVar( double var );
TypedVarPtr loadWCharVar( wchar_t var );
TypedVarPtr loadNullPtr();
class TypedVar : public NumConvertable, private boost::noncopyable {
......@@ -175,6 +176,7 @@ public:
TypedValue( double var ) : m_value( loadDoubleVar(var) ) {}
TypedValue( wchar_t var ) : m_value( loadWCharVar(var) ) {}
TypedValue( bool var ) : m_value( loadBoolVar(var) ) {}
TypedValue( nullptr_t ) : m_value(loadNullPtr() ) {}
template<typename T>
TypedValue(T* var) : m_value(loadULongLongVar((unsigned long long)var)) {}
......
......@@ -779,6 +779,9 @@ TypedValue ExprEval::getIdentifierValue()
if (fullName == "false")
return TypedValue(false);
if (fullName == "nullptr")
return TypedValue(nullptr);
TypedValue result;
std::wstring wname = strToWStr(fullName);
if (m_scope->find(wname, result))
......@@ -1993,11 +1996,6 @@ TypedValue TypeCastOperation::castToPtr(const TypedValue& val)
return TypedValue(val.getAddress()).castTo(m_type);
}
if (val.getType()->isUserDefined())
{
return TypedValue(val.getAddress()).castTo(m_type);
}
NOT_IMPLEMENTED();
}
......
......@@ -621,6 +621,14 @@ TypedVarPtr loadBoolVar(bool var)
///////////////////////////////////////////////////////////////////////////////
TypedVarPtr loadNullPtr()
{
DataAccessorPtr accessor = getCacheAccessor(8);
return loadType(L"Void*")->getVar(accessor);
}
///////////////////////////////////////////////////////////////////////////////
TypedVarPtr loadFloatVar( float var )
{
DataAccessorPtr accessor = getCacheAccessor( sizeof(float) );
......
......@@ -310,6 +310,12 @@ TEST(ExprEval, PointerArithm)
EXPECT_THROW(evalExpr("-(long*)10"), DbgException);
}
TEST(ExprEval, NullPtr)
{
EXPECT_EQ(0, evalExpr("(void*)0"));
EXPECT_EQ(0, evalExpr("(int**)nullptr"));
}
class ExprEvalTarget : public ProcessFixture
{
public:
......@@ -381,11 +387,6 @@ TEST_F(ExprEvalTarget, CastUdt)
EXPECT_THROW(evalExpr("(structTest)g_classChild", m_targetModule->getScope()), DbgException);
}
//
//TEST_F(ExprEvalTarget, CastUdt)
//{
// EXPECT_THROW(evalExpr("(int)g_classChild", m_targetModule->getScope()), DbgException);
TEST_F(ExprEvalTarget, EnumVal)
{
EXPECT_EQ(enumType::THREE, evalExpr("enumType::THREE", m_targetModule->getScope()));
......@@ -438,10 +439,3 @@ TEST_F(ExprEvalTarget, Eval1)
EXPECT_EQ( (g_testArray + 1)->m_field1 % 4, evalExpr("(g_testArray + 1)->m_field1 % 4", m_targetModule->getScope()));
}
TEST_F(ExprEvalTarget, StructAsPointer)
{
auto var = loadTypedVar(L"g_classChild");
auto scope = makeScope({ { L"this", var } });
EXPECT_EQ(var->getAddress(), evalExpr("(void*)this", scope));
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment