CBMC
validate_expressions.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Validate expressions
4 
5 Author: Daniel Poetzl
6 
7 \*******************************************************************/
8 
9 #include "validate_expressions.h"
10 #include "validate_helpers.h"
11 
12 #ifdef REPORT_UNIMPLEMENTED_EXPRESSION_CHECKS
13 #include <iostream>
14 #endif
15 
16 #include "bitvector_expr.h" // IWYU pragma: keep
17 #include "pointer_expr.h" // IWYU pragma: keep
18 #include "ssa_expr.h"
19 
20 #define CALL_ON_EXPR(expr_type) \
21  C<exprt, expr_type>()(expr, std::forward<Args>(args)...)
22 
23 template <template <typename, typename> class C, typename... Args>
24 void call_on_expr(const exprt &expr, Args &&... args)
25 {
26  if(expr.id() == ID_equal)
27  {
29  }
30  else if(expr.id() == ID_plus)
31  {
33  }
34  else if(is_ssa_expr(expr))
35  {
37  }
38  else if(expr.id() == ID_member)
39  {
41  }
42  else if(expr.id() == ID_dereference)
43  {
45  }
46  else if(expr.is_constant())
47  {
49  }
50  else if(expr.id() == ID_if)
51  {
53  }
54  else if(expr.id() == ID_update)
55  {
57  }
58  else if(expr.id() == ID_overflow_unary_minus)
59  {
61  }
62  else if(expr.id() == ID_count_leading_zeros)
63  {
65  }
66  else
67  {
68 #ifdef REPORT_UNIMPLEMENTED_EXPRESSION_CHECKS
69  std::cerr << "Unimplemented well-formedness check for expression with id: "
70  << expr.id_string() std::endl;
71 #endif
72 
74  }
75 }
76 
85 void check_expr(const exprt &expr, const validation_modet vm)
86 {
87  call_on_expr<call_checkt>(expr, vm);
88 }
89 
99  const exprt &expr,
100  const namespacet &ns,
101  const validation_modet vm)
102 {
103  call_on_expr<call_validatet>(expr, ns, vm);
104 }
105 
115  const exprt &expr,
116  const namespacet &ns,
117  const validation_modet vm)
118 {
119  call_on_expr<call_validate_fullt>(expr, ns, vm);
120 }
API to expression classes for bitvectors.
A constant literal expression.
Definition: std_expr.h:3000
The count leading zeros (counting the number of zero bits starting from the most-significant bit) exp...
Operator to dereference a pointer.
Definition: pointer_expr.h:834
Equality.
Definition: std_expr.h:1366
Base class for all expressions.
Definition: expr.h:56
bool is_constant() const
Return whether the expression is a constant.
Definition: expr.h:212
The trinary if-then-else operator.
Definition: std_expr.h:2380
const std::string & id_string() const
Definition: irep.h:391
const irep_idt & id() const
Definition: irep.h:388
Extract member of struct or union.
Definition: std_expr.h:2854
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The plus expression Associativity is not specified.
Definition: std_expr.h:1002
Expression providing an SSA-renamed symbol of expressions.
Definition: ssa_expr.h:17
A Boolean expression returning true, iff negation would result in an overflow when applied to the (si...
Operator to update elements in structs and arrays.
Definition: std_expr.h:2665
API to expression classes for Pointers.
bool is_ssa_expr(const exprt &expr)
Definition: ssa_expr.h:125
void check_expr(const exprt &expr, const validation_modet vm)
Check that the given expression is well-formed (shallow checks only, i.e., subexpressions and its typ...
void validate_full_expr(const exprt &expr, const namespacet &ns, const validation_modet vm)
Check that the given expression is well-formed (full check, including checks of all subexpressions an...
void validate_expr(const exprt &expr, const namespacet &ns, const validation_modet vm)
Check that the given expression is well-formed, assuming that its subexpression and type have already...
void call_on_expr(const exprt &expr, Args &&... args)
#define CALL_ON_EXPR(expr_type)
validation_modet