Skip to content

Commit

Permalink
Fix C identifier lists for functions returning pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jun 27, 2023
1 parent c5357db commit 7bc8383
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wpiformat/wpiformat/cidentlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def run_pipeline(self, config_file, name, lines):
#
# "def\\s+\w+" matches preprocessor directives "#ifdef" and "#ifndef" so
# their contents aren't used as a return type.
#
# "\w+\**\s+\w+\s*" matches a function return type with 0 or more
# trailing asterisks, spaces, a function name, then spaces before the
# open parenthesis
preproc_str = r"#else|#endif|"
comment_str = r"/\*|\*/|//|" + linesep + r"|"
string_str = r"\\\\|\\\"|\"|"
char_str = r"\\'|'|"
extern_str = r"(?P<ext_decl>extern \"C(\+\+)?\")\s+(?P<ext_brace>\{)?|"
braces_str = r"\{|\}|;|def\s+\w+|\w+\s+\w+\s*(?P<paren>\(\))"
braces_str = r"\{|\}|;|def\s+\w+|\w+\**\s+\w+\s*(?P<paren>\(\))"
postfix_str = r"(?=\s*(;|\{))"
token_regex = regex.compile(
preproc_str
Expand Down
10 changes: 10 additions & 0 deletions wpiformat/wpiformat/test/test_cidentlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,14 @@ def test_cidentlist():
)
test.add_latest_input_as_output(True)

# Ensure extern "C" function with pointer return type gets matched
test.add_input(
"./Test.cpp",
'extern "C" void* func() {}' + os.linesep,
)
test.add_output(
'extern "C" void* func(void) {}' + os.linesep,
True,
)

test.run(OutputType.FILE)

0 comments on commit 7bc8383

Please sign in to comment.