Fix legacy troublesome regex

Signed-off-by: Yuto Takano <yuto.takano@arm.com>
This commit is contained in:
Yuto Takano 2021-08-05 21:07:14 +01:00
parent fe02684049
commit 6f38ab3bca

View file

@ -237,7 +237,7 @@ class NameCheck(object):
A list of (identifier, containing filename) A list of (identifier, containing filename)
""" """
EXCLUDED_DECLARATIONS = ( EXCLUDED_DECLARATIONS = (
r"^(extern \"C\"|(typedef )?(struct|enum)( {)?$|};?$|$)" r"^(extern \"C\"|(typedef )?(struct|union|enum)( {)?$|};?$|$)"
) )
identifiers = [] identifiers = []
@ -258,19 +258,15 @@ class NameCheck(object):
# Skip parsing this line if it's a line comment, or if it # Skip parsing this line if it's a line comment, or if it
# begins with a preprocessor directive # begins with a preprocessor directive
if in_block_comment or re.match(r"(//|#)", line): if in_block_comment or re.match(r"^(//|#)", line):
continue continue
if re.match(EXCLUDED_DECLARATIONS, line): if re.match(EXCLUDED_DECLARATIONS, line):
continue continue
identifier = re.search( identifier = re.search(
# Matches: "mbedtls_aes_init(" # Matches: "mbedtls_aes_init("
r"([a-zA-Z_][a-zA-Z0-9_]*)\(|" r"([a-zA-Z_][a-zA-Z0-9_]*)\(",
# Matches: "(*f_rng)("
r"\(\*(.+)\)\(|"
# TODO: unknown purpose
r"(\w+)\W*$",
line line
) )
@ -281,7 +277,7 @@ class NameCheck(object):
header_file, header_file,
line, line,
(identifier.start(), identifier.end()), (identifier.start(), identifier.end()),
identifier.group(0))) identifier.group(1)))
return identifiers return identifiers