@@ -669,57 +669,12 @@ bool goto_programt::instructiont::equals(const instructiont &other) const
669
669
}
670
670
671
671
void goto_programt::instructiont::validate (
672
- const symbol_tablet &table ,
672
+ const namespacet &ns ,
673
673
const validation_modet vm) const
674
674
{
675
- namespacet ns (table);
676
675
validate_code_full_pick (code, ns, vm);
677
676
validate_expr_full_pick (guard, ns, vm);
678
677
679
- auto evaluates_to_boolean = [](const exprt &e) -> bool {
680
- if (e.type ().id () != ID_bool)
681
- return false ;
682
-
683
- if (e.id () == ID_typecast)
684
- return e.type ().id () == ID_bool;
685
-
686
- // Boolean constants
687
- if (e.id () == ID_true || e.id () == ID_false)
688
- return true ;
689
- if (e.id () == ID_constant)
690
- return true ;
691
-
692
- // Symbols
693
- if (e.id () == ID_symbol)
694
- return true ;
695
-
696
- // arithmetic relations
697
- if (e.id () == ID_equal || e.id () == ID_notequal)
698
- return true ;
699
- if (e.id () == ID_ieee_float_equal || e.id () == ID_ieee_float_notequal)
700
- return true ;
701
- if (e.id () == ID_ge || e.id () == ID_gt)
702
- return true ;
703
- if (e.id () == ID_le || e.id () == ID_lt)
704
- return true ;
705
-
706
- // propositional operators
707
- if (
708
- e.id () == ID_not || e.id () == ID_and || e.id () == ID_or ||
709
- e.id () == ID_implies)
710
- return true ;
711
- if (e.id () == ID_exists || e.id () == ID_forall)
712
- return true ;
713
-
714
- // weird
715
- if (
716
- e.id () == ID_isfinite || e.id () == ID_isnormal || e.id () == ID_isinf ||
717
- e.id () == ID_isnan)
718
- return true ;
719
-
720
- return false ;
721
- };
722
-
723
678
switch (type)
724
679
{
725
680
case ASSIGN:
@@ -733,36 +688,22 @@ void goto_programt::instructiont::validate(
733
688
targets.empty (),
734
689
" assume instruction should not have a target" ,
735
690
source_location);
736
- DATA_CHECK_WITH_DIAGNOSTICS (
737
- evaluates_to_boolean (guard),
738
- " assuming non-boolean condition\n " + guard.pretty (),
739
- source_location);
740
691
break ;
741
692
case ASSERT:
742
693
DATA_CHECK_WITH_DIAGNOSTICS (
743
694
targets.empty (),
744
695
" assert instruction should not have a target" ,
745
696
source_location);
746
- DATA_CHECK_WITH_DIAGNOSTICS (
747
- evaluates_to_boolean (guard),
748
- " asserting non-boolean condition\n " + guard.pretty (),
749
- source_location);
750
697
break ;
751
698
case GOTO:
752
699
DATA_CHECK_WITH_DIAGNOSTICS (
753
700
has_target (),
754
701
" goto instruction expects at least one target" ,
755
702
source_location);
756
- for (const auto &t : targets)
757
- {
758
- DATA_CHECK_WITH_DIAGNOSTICS (
759
- t->is_target () && t->target_number != 0 ,
760
- " goto target has to be a target" ,
761
- source_location);
762
- }
703
+ // get_target checks that targets.size()==1
763
704
DATA_CHECK_WITH_DIAGNOSTICS (
764
- evaluates_to_boolean (guard) ,
765
- " goto with non-boolean condition \n " + guard. pretty () ,
705
+ get_target ()-> is_target () && get_target ()-> target_number != 0 ,
706
+ " goto target has to be a target " ,
766
707
source_location);
767
708
break ;
768
709
case FUNCTION_CALL:
@@ -782,22 +723,29 @@ void goto_programt::instructiont::validate(
782
723
code.get_statement () == ID_dead,
783
724
" dead instructions should contain a dead statement" ,
784
725
source_location);
785
- DATA_CHECK_WITH_DIAGNOSTICS (
786
- table.has_symbol (to_code_dead (code).get_identifier ()),
787
- " removing unknown symbol: " +
788
- id2string (to_code_dead (code).get_identifier ()) + " from scope" ,
789
- source_location);
726
+ {
727
+ const symbolt *symbol;
728
+ DATA_CHECK_WITH_DIAGNOSTICS (
729
+ !ns.lookup (to_code_dead (code).get_identifier (), symbol),
730
+ " removing unknown symbol: " +
731
+ id2string (to_code_dead (code).get_identifier ()) + " from scope" ,
732
+ source_location);
733
+ }
790
734
break ;
791
735
case DECL:
792
736
DATA_CHECK_WITH_DIAGNOSTICS (
793
737
code.get_statement () == ID_decl,
794
738
" declaration instructions should contain a declaration statement" ,
795
739
source_location);
796
- DATA_CHECK_WITH_DIAGNOSTICS (
797
- table.has_symbol (to_code_decl (code).get_identifier ()),
798
- " declaring unknown symbol: " +
799
- id2string (to_code_decl (code).get_identifier ()),
800
- source_location);
740
+ {
741
+ const symbolt *symbol;
742
+ DATA_CHECK_WITH_DIAGNOSTICS (
743
+ !ns.lookup (to_code_decl (code).get_identifier (), symbol),
744
+ " declaring unknown symbol: " +
745
+ id2string (to_code_decl (code).get_identifier ()),
746
+ source_location);
747
+ }
748
+ break ;
801
749
default :
802
750
break ;
803
751
}
0 commit comments