|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Validate expressions |
| 4 | +
|
| 5 | +Author: Daniel Poetzl |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include "validate_expressions.h" |
| 10 | + |
| 11 | +#ifdef REPORT_UNIMPLEMENTED_EXPRESSION_CHECKS |
| 12 | +#include <iostream> |
| 13 | +#endif |
| 14 | + |
| 15 | +#include "expr.h" |
| 16 | +#include "namespace.h" |
| 17 | +#include "std_expr.h" |
| 18 | +#include "validate.h" |
| 19 | + |
| 20 | +#define CALL_ON_EXPR(expr_type) \ |
| 21 | + C<expr_type>()(expr, std::forward<Args>(args)...) |
| 22 | + |
| 23 | +template <template <typename> class C, typename... Args> |
| 24 | +void call_on_expr(const exprt &expr, Args &&... args) |
| 25 | +{ |
| 26 | + if(expr.id() == ID_equal) |
| 27 | + { |
| 28 | + CALL_ON_EXPR(equal_exprt); |
| 29 | + } |
| 30 | + else if(expr.id() == ID_plus) |
| 31 | + { |
| 32 | + CALL_ON_EXPR(plus_exprt); |
| 33 | + } |
| 34 | + else |
| 35 | + { |
| 36 | +#ifdef REPORT_UNIMPLEMENTED_EXPRESSION_CHECKS |
| 37 | + std::cerr << "Unimplemented well-formedness check for expression with id: " |
| 38 | + << expr.id_string() std::endl; |
| 39 | +#endif |
| 40 | + |
| 41 | + CALL_ON_EXPR(exprt); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +/// Check that the given expression is well-formed (shallow checks only, i.e., |
| 46 | +/// subexpressions and its type are not checked) |
| 47 | +/// |
| 48 | +/// The function casts the given expression to its concrete subtype (as |
| 49 | +/// determined by the id() field) and then calls its check() method. |
| 50 | +/// |
| 51 | +/// The validation mode indicates whether well-formedness check failures are |
| 52 | +/// reported via DATA_INVARIANT violations or exceptions. |
| 53 | +void check_expr_pick(const exprt &expr, const validation_modet vm) |
| 54 | +{ |
| 55 | + call_on_expr<call_checkt>(expr, vm); |
| 56 | +} |
| 57 | + |
| 58 | +/// Check that the given expression is well-formed, assuming that its |
| 59 | +/// subexpression and type have already been checked for well-formedness. |
| 60 | +/// |
| 61 | +/// The function casts the given expression to its concrete subtype (as |
| 62 | +/// determined by the id() field) and then calls its validate() method. |
| 63 | +/// |
| 64 | +/// The validation mode indicates whether well-formedness check failures are |
| 65 | +/// reported via DATA_INVARIANT violations or exceptions. |
| 66 | +void validate_expr_pick( |
| 67 | + const exprt &expr, |
| 68 | + const namespacet &ns, |
| 69 | + const validation_modet vm) |
| 70 | +{ |
| 71 | + call_on_expr<call_validatet>(expr, ns, vm); |
| 72 | +} |
| 73 | + |
| 74 | +/// Check that the given expression is well-formed (full check, including checks |
| 75 | +/// of all subexpressions and the type) |
| 76 | +/// |
| 77 | +/// The function casts the given expression to its concrete subtype (as |
| 78 | +/// determined by the id() field) and then calls its validate_full() method. |
| 79 | +/// |
| 80 | +/// The validation mode indicates whether well-formedness check failures are |
| 81 | +/// reported via DATA_INVARIANT violations or exceptions. |
| 82 | +void validate_expr_full_pick( |
| 83 | + const exprt &expr, |
| 84 | + const namespacet &ns, |
| 85 | + const validation_modet vm) |
| 86 | +{ |
| 87 | + call_on_expr<call_validate_fullt>(expr, ns, vm); |
| 88 | +} |
0 commit comments