From ba8f2b1c0ff9e91e08796d582e4f64a03a9e3db4 Mon Sep 17 00:00:00 2001 From: MS Date: Mon, 19 Feb 2024 10:00:48 -0500 Subject: [PATCH] parser: Detect function declaration (#580) --- tools/isledecomp/isledecomp/parser/error.py | 5 +++++ tools/isledecomp/isledecomp/parser/parser.py | 3 +++ tools/isledecomp/tests/test_parser.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/tools/isledecomp/isledecomp/parser/error.py b/tools/isledecomp/isledecomp/parser/error.py index b838a394..9ced1498 100644 --- a/tools/isledecomp/isledecomp/parser/error.py +++ b/tools/isledecomp/isledecomp/parser/error.py @@ -78,6 +78,11 @@ class ParserError(Enum): # they annotate are different. WRONG_STRING = 205 + # ERROR: This lineref FUNCTION marker is next to a function declaration or + # forward reference. The correct place for the marker is where the function + # is implemented so we can match with the PDB. + NO_IMPLEMENTATION = 206 + @dataclass class ParserAlert: diff --git a/tools/isledecomp/isledecomp/parser/parser.py b/tools/isledecomp/isledecomp/parser/parser.py index c3c9cde3..2e5daf07 100644 --- a/tools/isledecomp/isledecomp/parser/parser.py +++ b/tools/isledecomp/isledecomp/parser/parser.py @@ -487,6 +487,9 @@ def read_line(self, line: str): ): self._function_starts_here() self._function_done() + elif self.function_sig.endswith(");"): + # Detect forward reference or declaration + self._syntax_error(ParserError.NO_IMPLEMENTATION) else: self.state = ReaderState.WANT_CURLY diff --git a/tools/isledecomp/tests/test_parser.py b/tools/isledecomp/tests/test_parser.py index 1abae670..772a39c4 100644 --- a/tools/isledecomp/tests/test_parser.py +++ b/tools/isledecomp/tests/test_parser.py @@ -695,3 +695,19 @@ def test_static_variable_incomplete_coverage(parser): # Failed for TEST module assert len(parser.alerts) == 1 assert parser.alerts[0].code == ParserError.ORPHANED_STATIC_VARIABLE + + +def test_header_function_declaration(parser): + """This is either a forward reference or a declaration in a header file. + Meaning: The implementation is not here. This is not the correct place + for the FUNCTION marker and it will probably not match anything.""" + + parser.read_lines( + [ + "// FUNCTION: HELLO 0x1234", + "void sample_function(int);", + ] + ) + + assert len(parser.alerts) == 1 + assert parser.alerts[0].code == ParserError.NO_IMPLEMENTATION