|
6 | 6 |
|
7 | 7 | import os, sys, re, argparse, glob
|
8 | 8 |
|
9 |
| -VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z]\S*\s+.*);', re.M) |
| 9 | +VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z][^ \n\t:]*\s+.*);', re.M) |
10 | 10 | EXTERNS_RE = re.compile(r'^extern\s+(.*);', re.M)
|
11 | 11 |
|
| 12 | +types = { } |
12 | 13 | sizes = { }
|
13 | 14 |
|
14 | 15 | def main():
|
@@ -68,19 +69,46 @@ def parse_vars(fn, lines):
|
68 | 69 | for line in lines:
|
69 | 70 | line = re.sub(r'\s*\{.*\}', '', line)
|
70 | 71 | line = re.sub(r'\s*\(.*\)', '', line)
|
71 |
| - for item in re.split(r'\s*,\s*', line): |
72 |
| - item = re.sub(r'\s*=.*', '', item) |
73 |
| - m = re.search(r'(?P<var>\w+)(?P<sz>\[.*?\])?$', item) |
| 72 | + line = re.sub(r'\s*=\s*[^,]*', '', line) |
| 73 | + m = re.search(r'^(?:(?:static|extern)\s+)?(?P<type>[^\[,]+?)(?P<vars>\w+([\[,].+)?)$', line) |
| 74 | + if not m: |
| 75 | + print(f"Bogus match? ({line})") |
| 76 | + continue |
| 77 | + items = m['vars'] |
| 78 | + main_type = m['type'].strip() |
| 79 | + mt_len = len(main_type) |
| 80 | + main_type = main_type.rstrip('*') |
| 81 | + first_stars = '*' * (mt_len - len(main_type)) |
| 82 | + if first_stars: |
| 83 | + main_type = main_type.rstrip() |
| 84 | + items = first_stars + items |
| 85 | + for item in re.split(r'\s*,\s*', items): |
| 86 | + m = re.search(r'(?P<stars>\*+\s*)?(?P<var>\w+)(?P<sz>\[.*?\])?$', item) |
74 | 87 | if not m:
|
75 | 88 | print(f"Bogus match? ({item})")
|
76 | 89 | continue
|
77 |
| - if m['sz']: |
78 |
| - if m['var'] in sizes: |
79 |
| - if sizes[m['var']] != m['sz']: |
| 90 | + typ = main_type |
| 91 | + if m['stars']: |
| 92 | + typ = typ + m['stars'].strip() |
| 93 | + chk = [ |
| 94 | + 'type', typ, types, |
| 95 | + 'size', m['sz'], sizes, |
| 96 | + ] |
| 97 | + while chk: |
| 98 | + label = chk.pop(0) |
| 99 | + new = chk.pop(0) |
| 100 | + lst = chk.pop(0) |
| 101 | + if not new: |
| 102 | + continue |
| 103 | + if label == 'type': |
| 104 | + new = ' '.join(new.split()).replace(' *', '*') |
| 105 | + if m['var'] in lst: |
| 106 | + old = lst[m['var']] |
| 107 | + if new != old: |
80 | 108 | var = m['var']
|
81 |
| - print(fn, f'has inconsistent size for "{var}":', m['sz'], 'vs', sizes[var]) |
| 109 | + print(fn, f'has inconsistent {label} for "{var}":', new, 'vs', old) |
82 | 110 | else:
|
83 |
| - sizes[m['var']] = m['sz'] |
| 111 | + lst[m['var']] = new |
84 | 112 | ret.append(m['var'])
|
85 | 113 | return ret
|
86 | 114 |
|
|
0 commit comments