Skip to content

Commit

Permalink
autotest: Handle @LoggerEnum tags for #define sets
Browse files Browse the repository at this point in the history
  • Loading branch information
shancock884 committed Nov 8, 2024
1 parent 9941ce6 commit d76fb02
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Tools/autotest/logger_metadata/enum_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def match_enum_line(self, line):
if m is not None:
return (m.group(1), 1 << int(m.group(2)), m.group(3))

# Match: "#define FRED 1 // optional comment"
m = re.match(r"#define\s*([A-Z0-9_a-z]+)\s+(-?\d+) *(// *(.*) *)?$", line)
if m is not None:
return (m.group(1), m.group(2), m.group(4))

if m is None:
raise ValueError("Failed to match (%s)" % line)

Expand All @@ -116,7 +121,13 @@ def debug(x):
break
line = line.rstrip()
# print("state=%s line: %s" % (state, line))
if re.match(r"\s*//.*", line):
# Skip single-line comments - unless they contain LoggerEnum tags
if re.match(r"\s*//.*", line) and not "LoggerEnum" in line:
continue
# Skip multi-line comments
if re.match(r"\s*/\*.*", line):
while "*/" not in line:
line = f.readline()
continue
if state == "outside":
if re.match("class .*;", line) is not None:
Expand Down Expand Up @@ -154,6 +165,19 @@ def debug(x):
last_value = None
state = state_inside
skip_enumeration = False
continue

# // @LoggerEnum: NAME - can be used around for #define sets
m = re.match(r".*@LoggerEnum: *([\w]+)", line)
if m is not None:
enum_name = m.group(1)
debug("%s: %s" % (source_file, enum_name))
entries = []
last_value = None
state = state_inside
skip_enumeration = False
continue

continue
if state == "inside":
if re.match(r"\s*$", line):
Expand All @@ -164,7 +188,7 @@ def debug(x):
continue
if re.match(r"#else", line):
continue
if re.match(r".*}\s*\w*(\s*=\s*[\w:]+)?;", line):
if re.match(r".*}\s*\w*(\s*=\s*[\w:]+)?;", line) or "@LoggerEnumEnd" in line:
# potential end of enumeration
if not skip_enumeration:
if enum_name is None:
Expand Down

0 comments on commit d76fb02

Please sign in to comment.