Skip to content

Commit c81bd2d

Browse files
committed
Add validate() methods to (components of) goto models
1 parent 1abaee0 commit c81bd2d

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

src/goto-programs/goto_function.h

+10
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ class goto_functiont
110110
parameter_identifiers = std::move(other.parameter_identifiers);
111111
return *this;
112112
}
113+
114+
/// Check that the goto function is well-formed
115+
///
116+
/// The validation mode indicates whether well-formedness check failures are
117+
/// reported via DATA_INVARIANT violations or exceptions.
118+
void validate(const namespacet &ns, const validation_modet vm) const
119+
{
120+
body.validate(ns, vm);
121+
validate_type_full_pick(type, ns, vm);
122+
}
113123
};
114124

115125
void get_local_identifiers(const goto_functiont &, std::set<irep_idt> &dest);

src/goto-programs/goto_functions.h

+13
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ class goto_functionst
118118
for(const auto &fun : other.function_map)
119119
function_map[fun.first].copy_from(fun.second);
120120
}
121+
122+
/// Check that the goto functions are well-formed
123+
///
124+
/// The validation mode indicates whether well-formedness check failures are
125+
/// reported via DATA_INVARIANT violations or exceptions.
126+
void validate(const namespacet &ns, const validation_modet vm) const
127+
{
128+
for(const auto &entry : function_map)
129+
{
130+
const goto_functiont &goto_function = entry.second;
131+
goto_function.validate(ns, vm);
132+
}
133+
}
121134
};
122135

123136
#define Forall_goto_functions(it, functions) \

src/goto-programs/goto_model.h

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ class goto_modelt : public abstract_goto_modelt
9595
return goto_functions.function_map.find(id) !=
9696
goto_functions.function_map.end();
9797
}
98+
99+
/// Check that the goto model is well-formed
100+
///
101+
/// The validation mode indicates whether well-formedness check failures are
102+
/// reported via DATA_INVARIANT violations or exceptions.
103+
void validate(const namespacet &ns, const validation_modet vm) const
104+
{
105+
goto_functions.validate(ns, vm);
106+
symbol_table.validate();
107+
}
98108
};
99109

100110
/// Class providing the abstract GOTO model interface onto an unrelated

src/goto-programs/goto_program.h

+22
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,16 @@ class goto_programt
398398
/// only be evaluated in the context of a goto_programt (see
399399
/// goto_programt::equals).
400400
bool equals(const instructiont &other) const;
401+
402+
/// Check that the instruction is well-formed
403+
///
404+
/// The validation mode indicates whether well-formedness check failures are
405+
/// reported via DATA_INVARIANT violations or exceptions.
406+
void validate(const namespacet &ns, const validation_modet vm) const
407+
{
408+
validate_code_full_pick(code, ns, vm);
409+
validate_expr_full_pick(guard, ns, vm);
410+
}
401411
};
402412

403413
// Never try to change this to vector-we mutate the list while iterating
@@ -677,6 +687,18 @@ class goto_programt
677687
/// the same number of instructions, each pair of instructions compares equal,
678688
/// and relative jumps have the same distance.
679689
bool equals(const goto_programt &other) const;
690+
691+
/// Check that the goto program is well-formed
692+
///
693+
/// The validation mode indicates whether well-formedness check failures are
694+
/// reported via DATA_INVARIANT violations or exceptions.
695+
void validate(const namespacet &ns, const validation_modet vm) const
696+
{
697+
for(const instructiont &ins : instructions)
698+
{
699+
ins.validate(ns, vm);
700+
}
701+
}
680702
};
681703

682704
/// Get control-flow successors of a given instruction. The instruction is

src/util/symbol_table.h

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class symbol_tablet : public symbol_table_baset
109109
{
110110
return iteratort(internal_symbols.end());
111111
}
112+
113+
void validate() const
114+
{
115+
}
112116
};
113117

114118
#endif // CPROVER_UTIL_SYMBOL_TABLE_H

0 commit comments

Comments
 (0)