autotest: Handle @LoggerEnum tags for #define sets

This commit is contained in:
Simon Hancock 2024-02-18 18:18:20 +00:00 committed by Peter Barker
parent df9c36fee3
commit 43272dd9ee
1 changed files with 26 additions and 2 deletions

View File

@ -92,6 +92,11 @@ class EnumDocco(object):
if m is not None: if m is not None:
return (m.group(1), 1 << int(m.group(2)), m.group(3)) 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: if m is None:
raise ValueError("Failed to match (%s)" % line) raise ValueError("Failed to match (%s)" % line)
@ -116,7 +121,13 @@ class EnumDocco(object):
break break
line = line.rstrip() line = line.rstrip()
# print("state=%s line: %s" % (state, line)) # 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 "LoggerEnum" not in line:
continue
# Skip multi-line comments
if re.match(r"\s*/\*.*", line):
while "*/" not in line:
line = f.readline()
continue continue
if state == "outside": if state == "outside":
if re.match("class .*;", line) is not None: if re.match("class .*;", line) is not None:
@ -154,6 +165,19 @@ class EnumDocco(object):
last_value = None last_value = None
state = state_inside state = state_inside
skip_enumeration = False 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 continue
if state == "inside": if state == "inside":
if re.match(r"\s*$", line): if re.match(r"\s*$", line):
@ -164,7 +188,7 @@ class EnumDocco(object):
continue continue
if re.match(r"#else", line): if re.match(r"#else", line):
continue 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 # potential end of enumeration
if not skip_enumeration: if not skip_enumeration:
if enum_name is None: if enum_name is None: