Skip to content

Commit 80a611c

Browse files
danpoePetr Bauch
authored and
Petr Bauch
committed
Add validation methods to exprt
1 parent 02a53f7 commit 80a611c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/util/expr.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Author: Daniel Kroening, [email protected]
1010
#define CPROVER_UTIL_EXPR_H
1111

1212
#include "type.h"
13+
#include "validate.h"
14+
#include "validate_expressions.h"
15+
#include "validate_types.h"
1316

1417
#include <functional>
1518
#include <list>
@@ -235,6 +238,59 @@ class exprt:public irept
235238
return static_cast<source_locationt &>(add(ID_C_source_location));
236239
}
237240

241+
/// Check that the expression is well-formed (shallow checks only, i.e.,
242+
/// subexpressions and its type are not checked).
243+
///
244+
/// Subclasses may override this method to provide specific well-formedness
245+
/// checks for the corresponding expressions.
246+
///
247+
/// The validation mode indicates whether well-formedness check failures are
248+
/// reported via DATA_INVARIANT violations or exceptions.
249+
void check(const validation_modet vm = validation_modet::INVARIANT) const
250+
{
251+
}
252+
253+
/// Check that the expression is well-formed, assuming that its subexpressions
254+
/// and type have all ready been checked for well-formedness.
255+
///
256+
/// Subclasses may override this method to provide specific well-formedness
257+
/// checks for the corresponding expressions.
258+
///
259+
/// The validation mode indicates whether well-formedness check failures are
260+
/// reported via DATA_INVARIANT violations or exceptions.
261+
void validate(
262+
const namespacet &ns,
263+
const validation_modet vm = validation_modet::INVARIANT) const
264+
{
265+
check_expr_pick(*this, vm);
266+
}
267+
268+
/// Check that the expression is well-formed (full check, including checks
269+
/// of all subexpressions and the type)
270+
///
271+
/// Subclasses may override this method, though in most cases the provided
272+
/// implementation should be sufficient.
273+
///
274+
/// The validation mode indicates whether well-formedness check failures are
275+
/// reported via DATA_INVARIANT violations or exceptions.
276+
void validate_full(
277+
const namespacet &ns,
278+
const validation_modet vm = validation_modet::INVARIANT) const
279+
{
280+
// first check operands (if any)
281+
for(const exprt &op : operands())
282+
{
283+
validate_expr_full_pick(op, ns, vm);
284+
}
285+
286+
// type may be nil
287+
const typet &t = type();
288+
289+
validate_type_full_pick(t, ns, vm);
290+
291+
validate_expr_pick(*this, ns, vm);
292+
}
293+
238294
protected:
239295
exprt &add_expr(const irep_idt &name)
240296
{

0 commit comments

Comments
 (0)