Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
m417z
kdlibcpp
Commits
c79f0797
Commit
c79f0797
authored
Jul 12, 2019
by
ussrhero
Browse files
added nullptr support for expression evaluator
parent
9ee1f620
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
18 deletions
+20
-18
kdlib/include/kdlib/dataaccessor.h
kdlib/include/kdlib/dataaccessor.h
+1
-1
kdlib/include/kdlib/typedvar.h
kdlib/include/kdlib/typedvar.h
+2
-0
kdlib/source/clang/evalexpr.cpp
kdlib/source/clang/evalexpr.cpp
+3
-5
kdlib/source/typedvar.cpp
kdlib/source/typedvar.cpp
+8
-0
kdlib/tests/kdlibtest/exprevaltest.cpp
kdlib/tests/kdlibtest/exprevaltest.cpp
+6
-12
No files found.
kdlib/include/kdlib/dataaccessor.h
View file @
c79f0797
...
...
@@ -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
);
...
...
kdlib/include/kdlib/typedvar.h
View file @
c79f0797
...
...
@@ -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
))
{}
...
...
kdlib/source/clang/evalexpr.cpp
View file @
c79f0797
...
...
@@ -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
();
}
...
...
kdlib/source/typedvar.cpp
View file @
c79f0797
...
...
@@ -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
)
);
...
...
kdlib/tests/kdlibtest/exprevaltest.cpp
View file @
c79f0797
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment