@@ -41,7 +41,7 @@ def __init__(self, mh, stab, verify_checks, debug_vcg, cvc5_binary):
4141 self .abstract_extensions = {}
4242 self .checked_types = set ()
4343
44- def verify (self ):
44+ def perform_sanity_checks (self ):
4545 # lobster-exclude: Not safety relevant
4646 ok = True
4747 for package in self .stab .values (ast .Package ):
@@ -202,3 +202,35 @@ def verify_array_type(self, n_typ):
202202 "An array with 0 to 1 components should just\n "
203203 "be an optional %s instead." %
204204 n_typ .element_type .name )
205+
206+ def markup_ref (self , item , string_literals ):
207+ for string_literal in string_literals :
208+ for reference in string_literal .references :
209+ if reference .package .name == item .name :
210+ return string_literal
211+ return None
212+
213+ def verify_imports (self ):
214+ for file in self .mh .sm .all_files .values ():
215+ if not file .primary and not file .secondary :
216+ continue
217+ if not file .cu .imports :
218+ continue
219+ for item in file .cu .imports :
220+ import_tokens = [t for t in file .lexer .tokens
221+ if t .value == item .name ]
222+ markup = self .markup_ref (item ,
223+ (m .ast_link for m in
224+ file .lexer .tokens if
225+ isinstance (m .ast_link ,
226+ ast .String_Literal ) and
227+ m .ast_link .has_references ))
228+ if markup is not None :
229+ import_tokens .append (markup )
230+ if len (import_tokens ) == 1 :
231+ import_tk = import_tokens [0 ]
232+ self .mh .check (import_tk .location ,
233+ "unused import %s" % import_tk .value ,
234+ "unused_imports" ,
235+ "Consider deleting this import"
236+ " statement if not needed." )
0 commit comments