Skip to content

Commit bad06ab

Browse files
danpoePetr Bauch
authored and
Petr Bauch
committed
Add validate() methods to (components of) goto models
1 parent f9234d7 commit bad06ab

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

src/goto-programs/goto_function.h

Lines changed: 10 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ class goto_functionst
117117

118118
std::vector<function_mapt::const_iterator> sorted() const;
119119
std::vector<function_mapt::iterator> sorted();
120+
121+
/// Check that the goto functions are well-formed
122+
///
123+
/// The validation mode indicates whether well-formedness check failures are
124+
/// reported via DATA_INVARIANT violations or exceptions.
125+
void validate(const namespacet &ns, const validation_modet vm) const
126+
{
127+
for(const auto &entry : function_map)
128+
{
129+
const goto_functiont &goto_function = entry.second;
130+
goto_function.validate(ns, vm);
131+
}
132+
}
120133
};
121134

122135
#define Forall_goto_functions(it, functions) \

src/goto-programs/goto_model.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ class goto_modelt : public abstract_goto_modelt
8989
return goto_functions.function_map.find(id) !=
9090
goto_functions.function_map.end();
9191
}
92+
93+
/// Check that the goto model is well-formed
94+
///
95+
/// The validation mode indicates whether well-formedness check failures are
96+
/// reported via DATA_INVARIANT violations or exceptions.
97+
void validate(const namespacet &ns, const validation_modet vm) const
98+
{
99+
goto_functions.validate(ns, vm);
100+
symbol_table.validate();
101+
}
92102
};
93103

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

src/goto-programs/goto_program.h

Lines changed: 22 additions & 0 deletions
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/exception_utils.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
118118
Diagnostic &&diagnostic,
119119
Diagnostics &&... diagnostics)
120120
: message(std::move(message)),
121-
diagnostics(
122-
detail::assemble_diagnostics(
123-
std::forward(diagnostic),
124-
std::forward<Diagnostics>(diagnostics)...))
121+
diagnostics(detail::assemble_diagnostics(
122+
std::forward(diagnostic),
123+
std::forward<Diagnostics>(diagnostics)...))
125124
{
126125
}
127126

src/util/symbol_table.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class symbol_tablet : public symbol_table_baset
109109
{
110110
return iteratort(internal_symbols.end());
111111
}
112+
113+
/// Check that the symbol table is well-formed
114+
void validate() const
115+
{
116+
}
112117
};
113118

114119
#endif // CPROVER_UTIL_SYMBOL_TABLE_H

0 commit comments

Comments
 (0)