@@ -4435,9 +4435,9 @@ def fillVerifyExpected(verify_expected, tok):
44354435 self .executeCheck (2210 , self .misra_22_10 , cfg )
44364436
44374437 def analyse_ctu_info (self , ctu_info_files ):
4438- all_typedef_info = []
4439- all_tagname_info = []
4440- all_macro_info = []
4438+ all_typedef_info = {}
4439+ all_tagname_info = {}
4440+ all_macro_info = {}
44414441 all_external_identifiers_decl = {}
44424442 all_external_identifiers_def = {}
44434443 all_internal_identifiers = {}
@@ -4461,47 +4461,38 @@ def is_different_location(loc1, loc2):
44614461
44624462 if summary_type == 'MisraTypedefInfo' :
44634463 for new_typedef_info in summary_data :
4464- found = False
4465- for old_typedef_info in all_typedef_info :
4466- if old_typedef_info ['name' ] == new_typedef_info ['name' ]:
4467- found = True
4468- if is_different_location (old_typedef_info , new_typedef_info ):
4469- self .reportError (Location (old_typedef_info ), 5 , 6 )
4470- self .reportError (Location (new_typedef_info ), 5 , 6 )
4471- else :
4472- if new_typedef_info ['used' ]:
4473- old_typedef_info ['used' ] = True
4474- break
4475- if not found :
4476- all_typedef_info .append (new_typedef_info )
4464+ key = new_typedef_info ['name' ]
4465+ existing_typedef_info = all_typedef_info .get (key , None )
4466+ if existing_typedef_info :
4467+ if is_different_location (existing_typedef_info , new_typedef_info ):
4468+ self .reportError (Location (existing_typedef_info ), 5 , 6 )
4469+ self .reportError (Location (new_typedef_info ), 5 , 6 )
4470+ else :
4471+ existing_typedef_info ['used' ] = existing_typedef_info ['used' ] or new_typedef_info ['used' ]
4472+ else :
4473+ all_typedef_info [key ] = new_typedef_info
44774474
44784475 if summary_type == 'MisraTagName' :
44794476 for new_tagname_info in summary_data :
4480- found = False
4481- for old_tagname_info in all_tagname_info :
4482- if old_tagname_info ['name' ] == new_tagname_info ['name' ]:
4483- found = True
4484- if is_different_location (old_tagname_info , new_tagname_info ):
4485- self .reportError (Location (old_tagname_info ), 5 , 7 )
4486- self .reportError (Location (new_tagname_info ), 5 , 7 )
4487- else :
4488- if new_tagname_info ['used' ]:
4489- old_tagname_info ['used' ] = True
4490- break
4491- if not found :
4492- all_tagname_info .append (new_tagname_info )
4477+ key = new_tagname_info ['name' ]
4478+ existing_tagname_info = all_tagname_info .get (key , None )
4479+ if existing_tagname_info :
4480+ if is_different_location (existing_tagname_info , new_tagname_info ):
4481+ self .reportError (Location (existing_tagname_info ), 5 , 7 )
4482+ self .reportError (Location (new_tagname_info ), 5 , 7 )
4483+ else :
4484+ existing_tagname_info ['used' ] = existing_tagname_info ['used' ] or new_tagname_info ['used' ]
4485+ else :
4486+ all_tagname_info [key ] = new_tagname_info
44934487
44944488 if summary_type == 'MisraMacro' :
44954489 for new_macro in summary_data :
4496- found = False
4497- for old_macro in all_macro_info :
4498- if old_macro ['name' ] == new_macro ['name' ]:
4499- found = True
4500- if new_macro ['used' ]:
4501- old_macro ['used' ] = True
4502- break
4503- if not found :
4504- all_macro_info .append (new_macro )
4490+ key = new_macro ['name' ]
4491+ existing_macro = all_macro_info .get (key , None )
4492+ if existing_macro :
4493+ existing_macro ['used' ] = existing_macro ['used' ] or new_macro ['used' ]
4494+ else :
4495+ all_macro_info [key ] = new_macro
45054496
45064497 if summary_type == 'MisraExternalIdentifiers' :
45074498 for s in summary_data :
@@ -4540,17 +4531,17 @@ def is_different_location(loc1, loc2):
45404531 except FileNotFoundError :
45414532 return
45424533
4543- for ti in all_typedef_info :
4544- if not ti [ 'used' ] :
4545- self .reportError (Location (ti ), 2 , 3 )
4534+ unused_typedefs = [ tdi for tdi in all_typedef_info . values () if not tdi [ 'used' ]]
4535+ for tdi in unused_typedefs :
4536+ self .reportError (Location (tdi ), 2 , 3 )
45464537
4547- for ti in all_tagname_info :
4548- if not ti [ 'used' ] :
4549- self .reportError (Location (ti ), 2 , 4 )
4538+ unused_tags = [ tag for tag in all_tagname_info . values () if not tag [ 'used' ]]
4539+ for tag in unused_tags :
4540+ self .reportError (Location (tag ), 2 , 4 )
45504541
4551- for m in all_macro_info :
4552- if not m [ 'used' ] :
4553- self .reportError (Location (m ), 2 , 5 )
4542+ unused_macros = [ m for m in all_macro_info . values () if not m [ 'used' ]]
4543+ for m in unused_macros :
4544+ self .reportError (Location (m ), 2 , 5 )
45544545
45554546 all_external_identifiers = all_external_identifiers_decl
45564547 all_external_identifiers .update (all_external_identifiers_def )
0 commit comments