mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-23 00:14:22 +00:00
Match static function variables (#530)
* Match static function variables * IsleApp::Tick static variables
This commit is contained in:
@@ -419,8 +419,7 @@ def test_static_variable(parser):
|
||||
"""We can detect whether a variable is a static function variable
|
||||
based on the parser's state when we detect it.
|
||||
Checking for the word `static` alone is not a good test.
|
||||
Static class variables are filed as S_GDATA32, same as regular globals.
|
||||
Only function statics are filed as S_LDATA32."""
|
||||
Static class variables are filed as S_GDATA32, same as regular globals."""
|
||||
|
||||
parser.read_lines(
|
||||
[
|
||||
@@ -436,7 +435,7 @@ def test_static_variable(parser):
|
||||
"// FUNCTION: TEST 0x5555",
|
||||
"void test_function() {",
|
||||
"// GLOBAL: TEST 0x8888",
|
||||
"int g_internal = 0;",
|
||||
"static int g_internal = 0;",
|
||||
"}",
|
||||
]
|
||||
)
|
||||
@@ -629,3 +628,70 @@ def test_match_qualified_variable(parser):
|
||||
assert len(parser.variables) == 1
|
||||
assert parser.variables[0].name == "MxTest::g_count"
|
||||
assert len(parser.alerts) == 0
|
||||
|
||||
|
||||
def test_static_variable_parent(parser):
|
||||
"""Report the address of the parent function that contains a static variable."""
|
||||
|
||||
parser.read_lines(
|
||||
[
|
||||
"// FUNCTION: TEST 0x1234",
|
||||
"void test()",
|
||||
"{",
|
||||
" // GLOBAL: TEST 0x5555",
|
||||
" static int g_count = 0;",
|
||||
"}",
|
||||
]
|
||||
)
|
||||
|
||||
assert len(parser.variables) == 1
|
||||
assert parser.variables[0].is_static is True
|
||||
assert parser.variables[0].parent_function == 0x1234
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="""Without the FUNCTION marker we don't know that we are inside a function,
|
||||
so we do not identify this variable as static."""
|
||||
)
|
||||
def test_static_variable_no_parent(parser):
|
||||
"""If the function that contains a static variable is not marked, we
|
||||
cannot match it with cvdump so we should skip it and report an error."""
|
||||
|
||||
parser.read_lines(
|
||||
[
|
||||
"void test()",
|
||||
"{",
|
||||
" // GLOBAL: TEST 0x5555",
|
||||
" static int g_count = 0;",
|
||||
"}",
|
||||
]
|
||||
)
|
||||
|
||||
# No way to match this variable so don't report it
|
||||
assert len(parser.variables) == 0
|
||||
assert len(parser.alerts) == 1
|
||||
assert parser.alerts[0].code == ParserError.ORPHANED_STATIC_VARIABLE
|
||||
|
||||
|
||||
def test_static_variable_incomplete_coverage(parser):
|
||||
"""If the function that contains a static variable is marked, but
|
||||
not for each module used for the variable itself, this is an error."""
|
||||
|
||||
parser.read_lines(
|
||||
[
|
||||
"// FUNCTION: HELLO 0x1234",
|
||||
"void test()",
|
||||
"{",
|
||||
" // GLOBAL: HELLO 0x5555",
|
||||
" // GLOBAL: TEST 0x5555",
|
||||
" static int g_count = 0;",
|
||||
"}",
|
||||
]
|
||||
)
|
||||
|
||||
# Match for HELLO module
|
||||
assert len(parser.variables) == 1
|
||||
|
||||
# Failed for TEST module
|
||||
assert len(parser.alerts) == 1
|
||||
assert parser.alerts[0].code == ParserError.ORPHANED_STATIC_VARIABLE
|
||||
|
Reference in New Issue
Block a user