MISRA: Speed up analysis of .ctu_info files (#4666)
* Speed up analyses of .ctu_info files Use temporary dictionaries to eliminate duplicate typedefs, tags and macros * Consistency: use a cache key variable Ensures that the get and add use the same key. * CTU perf: use dict for macros, tags & types.
This commit is contained in:
parent
a0b59ff56a
commit
c0d9a76dd9
|
@ -4435,9 +4435,9 @@ class MisraChecker:
|
||||||
self.executeCheck(2210, self.misra_22_10, cfg)
|
self.executeCheck(2210, self.misra_22_10, cfg)
|
||||||
|
|
||||||
def analyse_ctu_info(self, ctu_info_files):
|
def analyse_ctu_info(self, ctu_info_files):
|
||||||
all_typedef_info = []
|
all_typedef_info = {}
|
||||||
all_tagname_info = []
|
all_tagname_info = {}
|
||||||
all_macro_info = []
|
all_macro_info = {}
|
||||||
all_external_identifiers_decl = {}
|
all_external_identifiers_decl = {}
|
||||||
all_external_identifiers_def = {}
|
all_external_identifiers_def = {}
|
||||||
all_internal_identifiers = {}
|
all_internal_identifiers = {}
|
||||||
|
@ -4461,47 +4461,38 @@ class MisraChecker:
|
||||||
|
|
||||||
if summary_type == 'MisraTypedefInfo':
|
if summary_type == 'MisraTypedefInfo':
|
||||||
for new_typedef_info in summary_data:
|
for new_typedef_info in summary_data:
|
||||||
found = False
|
key = new_typedef_info['name']
|
||||||
for old_typedef_info in all_typedef_info:
|
existing_typedef_info = all_typedef_info.get(key, None)
|
||||||
if old_typedef_info['name'] == new_typedef_info['name']:
|
if existing_typedef_info:
|
||||||
found = True
|
if is_different_location(existing_typedef_info, new_typedef_info):
|
||||||
if is_different_location(old_typedef_info, new_typedef_info):
|
self.reportError(Location(existing_typedef_info), 5, 6)
|
||||||
self.reportError(Location(old_typedef_info), 5, 6)
|
self.reportError(Location(new_typedef_info), 5, 6)
|
||||||
self.reportError(Location(new_typedef_info), 5, 6)
|
else:
|
||||||
else:
|
existing_typedef_info['used'] = existing_typedef_info['used'] or new_typedef_info['used']
|
||||||
if new_typedef_info['used']:
|
else:
|
||||||
old_typedef_info['used'] = True
|
all_typedef_info[key] = new_typedef_info
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
all_typedef_info.append(new_typedef_info)
|
|
||||||
|
|
||||||
if summary_type == 'MisraTagName':
|
if summary_type == 'MisraTagName':
|
||||||
for new_tagname_info in summary_data:
|
for new_tagname_info in summary_data:
|
||||||
found = False
|
key = new_tagname_info['name']
|
||||||
for old_tagname_info in all_tagname_info:
|
existing_tagname_info = all_tagname_info.get(key, None)
|
||||||
if old_tagname_info['name'] == new_tagname_info['name']:
|
if existing_tagname_info:
|
||||||
found = True
|
if is_different_location(existing_tagname_info, new_tagname_info):
|
||||||
if is_different_location(old_tagname_info, new_tagname_info):
|
self.reportError(Location(existing_tagname_info), 5, 7)
|
||||||
self.reportError(Location(old_tagname_info), 5, 7)
|
self.reportError(Location(new_tagname_info), 5, 7)
|
||||||
self.reportError(Location(new_tagname_info), 5, 7)
|
else:
|
||||||
else:
|
existing_tagname_info['used'] = existing_tagname_info['used'] or new_tagname_info['used']
|
||||||
if new_tagname_info['used']:
|
else:
|
||||||
old_tagname_info['used'] = True
|
all_tagname_info[key] = new_tagname_info
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
all_tagname_info.append(new_tagname_info)
|
|
||||||
|
|
||||||
if summary_type == 'MisraMacro':
|
if summary_type == 'MisraMacro':
|
||||||
for new_macro in summary_data:
|
for new_macro in summary_data:
|
||||||
found = False
|
key = new_macro['name']
|
||||||
for old_macro in all_macro_info:
|
existing_macro = all_macro_info.get(key, None)
|
||||||
if old_macro['name'] == new_macro['name']:
|
if existing_macro:
|
||||||
found = True
|
existing_macro['used'] = existing_macro['used'] or new_macro['used']
|
||||||
if new_macro['used']:
|
else:
|
||||||
old_macro['used'] = True
|
all_macro_info[key] = new_macro
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
all_macro_info.append(new_macro)
|
|
||||||
|
|
||||||
if summary_type == 'MisraExternalIdentifiers':
|
if summary_type == 'MisraExternalIdentifiers':
|
||||||
for s in summary_data:
|
for s in summary_data:
|
||||||
|
@ -4540,17 +4531,17 @@ class MisraChecker:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return
|
return
|
||||||
|
|
||||||
for ti in all_typedef_info:
|
unused_typedefs = [tdi for tdi in all_typedef_info.values() if not tdi['used']]
|
||||||
if not ti['used']:
|
for tdi in unused_typedefs:
|
||||||
self.reportError(Location(ti), 2, 3)
|
self.reportError(Location(tdi), 2, 3)
|
||||||
|
|
||||||
for ti in all_tagname_info:
|
unused_tags = [tag for tag in all_tagname_info.values() if not tag['used']]
|
||||||
if not ti['used']:
|
for tag in unused_tags:
|
||||||
self.reportError(Location(ti), 2, 4)
|
self.reportError(Location(tag), 2, 4)
|
||||||
|
|
||||||
for m in all_macro_info:
|
unused_macros = [m for m in all_macro_info.values() if not m['used']]
|
||||||
if not m['used']:
|
for m in unused_macros:
|
||||||
self.reportError(Location(m), 2, 5)
|
self.reportError(Location(m), 2, 5)
|
||||||
|
|
||||||
all_external_identifiers = all_external_identifiers_decl
|
all_external_identifiers = all_external_identifiers_decl
|
||||||
all_external_identifiers.update(all_external_identifiers_def)
|
all_external_identifiers.update(all_external_identifiers_def)
|
||||||
|
|
Loading…
Reference in New Issue