Change identifier regex to better support multiline declarations
Signed-off-by: Yuto Takano <yuto.takano@arm.com>
This commit is contained in:
parent
8f457cf222
commit
cfc9e4a275
1 changed files with 21 additions and 14 deletions
|
@ -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+)(?: *{)?$|"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue