Commit 9ee1f620 authored by ussrhero's avatar ussrhero
Browse files

fixed void type evaluate

parent 39da9f92
......@@ -801,6 +801,12 @@ TypeInfoPtr applyComplexModifierRecursive(const parser::ComplexMatcher& matcher,
{
TypeInfoPtr typeInfo = typeInfo_;
if (matcher.isReference())
{
if (typeInfo->isVoid() )
throw ExprException(L"error syntax");
}
if (matcher.isPointer())
{
for ( auto p : matcher.getPointerMatcher().getPointerMatchers() )
......@@ -1266,6 +1272,12 @@ std::string TypeEval::getBaseTypeName(const parser::BaseTypeMatcher& baseTypeMa
TypeInfoPtr TypeEval::getBaseType()
{
if (m_tokens->front().is(clang::tok::kw_void))
{
m_tokens->pop_front();
return loadType(L"Void");
}
std::unique_ptr<BaseTypeBuilder> baseTypeBuilder(new EmptyBaseTypeBuilder);
while (true)
......@@ -1637,7 +1649,8 @@ static const std::map< std::string, std::function<kdlib::TypeInfoPtr(void)> >
{ "size_t", []() { return kdlib::ptrSize() == 4 ? kdlib::loadType(L"UInt4B") : kdlib::loadType(L"UInt8B"); } },
{ "intptr_t", []() { return kdlib::ptrSize() == 4 ? kdlib::loadType(L"Int4B") : kdlib::loadType(L"Int8B"); } },
{ "uintptr_t", []() { return kdlib::ptrSize() == 4 ? kdlib::loadType(L"UInt4B") : kdlib::loadType(L"UInt8B"); } },
{ "bool", []() { return kdlib::loadType(L"Bool"); } }
{ "bool", []() { return kdlib::loadType(L"Bool"); } },
{ "void", []() { return kdlib::loadType(L"Void"); } }
};
bool isStandardIntType(const clang::Token& token)
......@@ -1980,6 +1993,11 @@ 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();
}
......
......@@ -179,6 +179,16 @@ public:
return arrayMatcher;
}
bool isReference() const
{
return refMatcher.getMatchResult().isMatched();
}
const RefMatcher& getRefMatcher() const
{
assert(isReference());
return refMatcher;
}
private:
......
......@@ -58,7 +58,7 @@ public:
throw TypeException(m_name, L"method has no offset");
if (m_constMember)
throw TypeException(m_name, L"constatnt has no offset");
throw TypeException(m_name, L"constant has no offset");
return m_offset;
}
......
......@@ -436,4 +436,12 @@ TEST_F(ExprEvalTarget, Eval1)
EXPECT_EQ(g_testArray[1].m_field1, evalExpr("g_testArray[1].m_field1", m_targetModule->getScope()));
EXPECT_EQ(g_structTest1.m_field4->m_field1 + 200, evalExpr("g_structTest1.m_field4->m_field1 + 200", m_targetModule->getScope()));
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
......@@ -442,3 +442,15 @@ TEST(TypeEvalTest, TemplateUnusedType)
EXPECT_NO_THROW(evalType("TestStruct<int,TestStruct<int,int>>", typeProvider));
}
TEST(TypeEvalTest, Void)
{
EXPECT_EQ(L"Void", evalType("void")->getName());
EXPECT_EQ(L"Void*", evalType("void *")->getName());
EXPECT_EQ(L"Void*[1]", evalType("void *[1]")->getName());
EXPECT_THROW(evalType("void&"), TypeException);
EXPECT_THROW(evalType("void&&"), TypeException);
EXPECT_THROW(evalType("void[5]"), TypeException);
}
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