diff options
author | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2021-07-07 10:00:45 +0100 |
---|---|---|
committer | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2021-07-07 10:00:45 +0100 |
commit | 3dd7ba03fa2bffc908a4e8cc363fe344a84cc361 (patch) | |
tree | c18491ee6bf922b610b743c917014b5ea1741abb /tools | |
parent | 8a630ad6d069c9c191f33732e479b83b0e8dd811 (diff) |
tools/check_typed_item_calls.py: Add extra mask checks
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/check_typed_item_calls.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/check_typed_item_calls.py b/tools/check_typed_item_calls.py index 25f52278a4..ea68aa80c4 100755 --- a/tools/check_typed_item_calls.py +++ b/tools/check_typed_item_calls.py @@ -220,6 +220,9 @@ class Item: if check_mask: if not mask in { 'NULL', '0x0', '0'}: self.check_contiguous_bits(mask) + self.check_mask_too_long(mask) + self.check_odd_num_digits(mask) + def set_mask_value(self): try: @@ -290,6 +293,23 @@ class Item: return n += 1 + def check_mask_too_long(self, mask): + if not self.mask_value: + return + if mask.startswith('0x00') or mask.endswith('00'): + # There may be good reasons for having a wider field/mask, e.g. if there are 32 flags, showing them + # all lined up as part of the same word may make it clearer. But some annoying cases have been found + # where the grouping does not seem to be natural.. + print('Warning: ', self.filename, 'filter=', self.filter, ' - mask seems to be wider than necessary', mask) + global issues_found + issues_found += 1 + + def check_odd_num_digits(self, mask): + if mask.startswith('0x') and len(mask) % 2: + print('Warning: ', self.filename, 'filter=', self.filter, ' - mask has odd number of digits', mask) + global issues_found + issues_found += 1 + # These are APIs in proto.c that check a set of types at runtime and can print '.. is not of type ..' to the console @@ -386,11 +406,11 @@ def find_items(filename, check_mask=False, check_label=False, check_consecutive= contents = f.read() # Remove comments so as not to trip up RE. contents = removeComments(contents) - matches = re.finditer(r'.*\{\s*\&(hf_.*),\s*{\s*\"(.+)\",\s*\"([a-zA-Z0-9_\-\.]+)\",\s*([A-Z0-9_]*),\s*.*,\s*([A-Za-z0-9x]*)\s*,', contents) + matches = re.finditer(r'.*\{\s*\&(hf_.*),\s*{\s*\"(.+)\",\s*\"([a-zA-Z0-9_\-\.]+)\",\s*([A-Z0-9_]*),\s*.*,\s*([A-Za-z0-9x_\(\)]*),\s*([a-z0-9x_]*),', contents) for m in matches: # Store this item. hf = m.group(1) - items[hf] = Item(filename, filter=m.group(3), label=m.group(2), item_type=m.group(4), mask=m.group(5), + items[hf] = Item(filename, filter=m.group(3), label=m.group(2), item_type=m.group(4), mask=m.group(6), check_mask=check_mask, check_label=check_label, check_consecutive=(not is_generated and check_consecutive)) |