@@ -668,6 +668,65 @@ bool goto_programt::instructiont::equals(const instructiont &other) const
668668 // clang-format on
669669}
670670
671+ bool goto_programt::instructiont::check_internal_invariants (
672+ const symbol_tablet &table,
673+ messaget &msg) const
674+ {
675+ bool found_violation = false ;
676+ std::vector<std::string> id_collector;
677+ auto symbol_finder = [&](const exprt &e) {
678+ if (e.id () == ID_symbol)
679+ {
680+ auto symbol_expr = to_symbol_expr (e);
681+ if (!table.has_symbol (symbol_expr.get_identifier ()))
682+ id_collector.push_back (id2string (symbol_expr.get_identifier ()));
683+ }
684+ };
685+
686+ if (!table.has_symbol (function))
687+ id_collector.push_back (id2string (function));
688+
689+ switch (type)
690+ {
691+ case GOTO:
692+ case ASSUME:
693+ case ASSERT:
694+ guard.visit (symbol_finder);
695+ break ;
696+ case ASSIGN:
697+ case DECL:
698+ case DEAD:
699+ case FUNCTION_CALL:
700+ code.visit (symbol_finder);
701+ break ;
702+ case OTHER:
703+ case SKIP:
704+ case LOCATION:
705+ case END_FUNCTION:
706+ case START_THREAD:
707+ case END_THREAD:
708+ case ATOMIC_BEGIN:
709+ case ATOMIC_END:
710+ case RETURN:
711+ case THROW:
712+ case CATCH:
713+ case NO_INSTRUCTION_TYPE:
714+ case INCOMPLETE_GOTO:
715+ break ;
716+ }
717+
718+ if (!id_collector.empty ())
719+ {
720+ for (const auto &id : id_collector)
721+ {
722+ msg.error () << id << " not found (" << source_location << " )"
723+ << messaget::eom;
724+ }
725+ found_violation = true ;
726+ }
727+ return found_violation;
728+ }
729+
671730bool goto_programt::equals (const goto_programt &other) const
672731{
673732 if (instructions.size () != other.instructions .size ())
@@ -699,6 +758,19 @@ bool goto_programt::equals(const goto_programt &other) const
699758 return true ;
700759}
701760
761+ bool goto_programt::check_internal_invariants (
762+ const symbol_tablet &table,
763+ messaget &msg) const
764+ {
765+ bool found_violation = false ;
766+ forall_goto_program_instructions (it, (*this ))
767+ {
768+ found_violation =
769+ found_violation || it->check_internal_invariants (table, msg);
770+ }
771+ return found_violation;
772+ }
773+
702774// / Outputs a string representation of a `goto_program_instruction_typet`
703775std::ostream &operator <<(std::ostream &out, goto_program_instruction_typet t)
704776{
0 commit comments