Change identifier regex to better support multiline declarations

Signed-off-by: Yuto Takano <yuto.takano@arm.com>
This commit is contained in:
Yuto Takano 2021-08-06 20:02:32 +01:00
parent 8f457cf222
commit cfc9e4a275

View file

@ -410,20 +410,21 @@ class NameCheck(object):
previous_line = None previous_line = None
continue continue
# Match "^something something$", with optional inline/static # If the line contains only space-separated alphanumeric
# This *might* be a function with its argument brackets on # characters (or underscore, asterisk, or, open bracket),
# the next line, or a struct declaration, so keep note of it # and nothing else, high chance it's a declaration that
if re.match( # continues on the next line
r"(inline +|static +|typedef +)*\w+ +\w+$", if re.match(r"^([\w\*\(]+\s+)+$", line):
line): if previous_line:
previous_line += " " + line
else:
previous_line = line previous_line = line
continue continue
# If previous line seemed to start an unfinished declaration # If previous line seemed to start an unfinished declaration
# (as above), and this line begins with a bracket, concat # (as above), concat and treat them as one.
# them and treat them as one line. if previous_line:
if previous_line and re.match(" *[\({]", line): line = previous_line.strip() + " " + line.strip()
line = previous_line.strip() + line.strip()
previous_line = None previous_line = None
# Skip parsing if line has a space in front = hueristic to # Skip parsing if line has a space in front = hueristic to
@ -433,9 +434,15 @@ class NameCheck(object):
continue continue
identifier = re.search( identifier = re.search(
# Match " something(" or " *something(". function calls. # Match " something(a" or " *something(a". Functions.
r".* \**(\w+)\(|" # Assumptions:
# Match (*something)( # - function definition from return type to one of its
# arguments is all on one line (enforced by the above
# previous_line concat)
# - function definition line only contains alphanumeric,
# asterisk, underscore, and open bracket
r".* \**(\w+) *\( *\w|"
# Match "(*something)(". Flexible with spaces.
r".*\( *\* *(\w+) *\) *\(|" r".*\( *\* *(\w+) *\) *\(|"
# Match names of named data structures # Match names of named data structures
r"(?:typedef +)?(?:struct|union|enum) +(\w+)(?: *{)?$|" r"(?:typedef +)?(?:struct|union|enum) +(\w+)(?: *{)?$|"