Skip to content

Commit 5bb7d99

Browse files
committed
py: Modify makeqstrdata to recognise better the output of CPP.
1 parent 49f20b8 commit 5bb7d99

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

py/makeqstrdata.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,37 @@ def compute_hash(qstr):
2424
hash = (hash * 33) ^ ord(char)
2525
return hash & 0xffff
2626

27+
# given a list of (name,regex) pairs, find the first one that matches the given line
28+
def re_match(regexs, line):
29+
for name, regex in regexs:
30+
match = re.match(regex, line)
31+
if match:
32+
return name, match
33+
return None, None
34+
2735
def do_work(infiles):
2836
# read the qstrs in from the input files
2937
qstrs = {}
30-
cpp_header_blocks = 3
3138
for infile in infiles:
3239
with open(infile, 'rt') as f:
3340
line_number = 0
3441
for line in f:
3542
line_number += 1
3643
line = line.strip()
3744

38-
# ignore blank lines and comments
39-
if len(line) == 0 or line.startswith('//'):
45+
# ignore blank lines, comments and preprocessor directives
46+
if len(line) == 0 or line.startswith('//') or line.startswith('#'):
4047
continue
4148

42-
# We'll have 3 line-number lines for py/qstrdefs.h - initial, leaving it to
43-
# go into other headers, and returning to it.
44-
if line.startswith('# ') and 'py/qstrdefs.h' in line:
45-
cpp_header_blocks -= 1
46-
continue
47-
if cpp_header_blocks != 0:
48-
continue
49-
50-
# verify line is of the correct form
51-
match = re.match(r'Q\((.+)\)$', line)
52-
if not match:
49+
# work out what kind of line it is
50+
match_kind, match = re_match([('qstr', r'Q\((.+)\)$'), ('cdecl', r'(typedef|extern) [A-Za-z0-9_* ]+;$')], line)
51+
if match_kind is None:
52+
# unknown line format
5353
print('({}:{}) bad qstr format, got {}'.format(infile, line_number, line), file=sys.stderr)
5454
return False
55+
elif match_kind != 'qstr':
56+
# not a line with a qstr
57+
continue
5558

5659
# get the qstr value
5760
qstr = match.group(1)

0 commit comments

Comments
 (0)