CBMC
havoc_utils.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Utilities for building havoc code for expressions.
4 
5 Author: Saswat Padhi, saspadhi@amazon.com
6 
7 Date: July 2021
8 
9 \*******************************************************************/
10 
13 
14 #ifndef CPROVER_GOTO_INSTRUMENT_HAVOC_UTILS_H
15 #define CPROVER_GOTO_INSTRUMENT_HAVOC_UTILS_H
16 
17 #include <set>
18 
20 
21 #include <util/expr_util.h>
22 
23 typedef std::set<exprt> assignst;
24 
27 {
28 public:
29  explicit havoc_utils_is_constantt(const assignst &mod) : assigns(mod)
30  {
31  }
32 
33  bool is_constant(const exprt &expr) const override
34  {
35  // Besides the "usual" constants (checked in is_constantt::is_constant),
36  // we also treat unmodified symbols as constants
37  if(expr.id() == ID_symbol && assigns.find(expr) == assigns.end())
38  return true;
39 
40  return is_constantt::is_constant(expr);
41  }
42 
43 protected:
44  const assignst &assigns;
45 };
46 
48 {
49 public:
50  explicit havoc_utilst(const assignst &mod) : assigns(mod), is_constant(mod)
51  {
52  }
53 
62  const source_locationt location,
63  goto_programt &dest) const;
64 
76  virtual void append_havoc_code_for_expr(
77  const source_locationt location,
78  const exprt &expr,
79  goto_programt &dest) const;
80 
87  const source_locationt location,
88  const exprt &expr,
89  goto_programt &dest) const;
90 
97  const source_locationt location,
98  const exprt &expr,
99  goto_programt &dest) const;
100 
101 protected:
104 };
105 
106 #endif // CPROVER_GOTO_INSTRUMENT_HAVOC_UTILS_H
is_constantt
Determine whether an expression is constant.
Definition: expr_util.h:88
havoc_utils_is_constantt::assigns
const assignst & assigns
Definition: havoc_utils.h:44
havoc_utils_is_constantt
A class containing utility functions for havocing expressions.
Definition: havoc_utils.h:26
havoc_utilst
Definition: havoc_utils.h:47
havoc_utilst::append_scalar_havoc_code_for_expr
virtual void append_scalar_havoc_code_for_expr(const source_locationt location, const exprt &expr, goto_programt &dest) const
Append goto instructions to havoc the value of expr
Definition: havoc_utils.cpp:57
exprt
Base class for all expressions.
Definition: expr.h:55
havoc_utilst::is_constant
const havoc_utils_is_constantt is_constant
Definition: havoc_utils.h:103
havoc_utilst::append_havoc_code_for_expr
virtual void append_havoc_code_for_expr(const source_locationt location, const exprt &expr, goto_programt &dest) const
Append goto instructions to havoc a single expression expr
Definition: havoc_utils.cpp:29
havoc_utils_is_constantt::havoc_utils_is_constantt
havoc_utils_is_constantt(const assignst &mod)
Definition: havoc_utils.h:29
is_constantt::is_constant
virtual bool is_constant(const exprt &) const
This function determines what expressions are to be propagated as "constants".
Definition: expr_util.cpp:227
havoc_utilst::havoc_utilst
havoc_utilst(const assignst &mod)
Definition: havoc_utils.h:50
havoc_utils_is_constantt::is_constant
bool is_constant(const exprt &expr) const override
This function determines what expressions are to be propagated as "constants".
Definition: havoc_utils.h:33
havoc_utilst::append_object_havoc_code_for_expr
virtual void append_object_havoc_code_for_expr(const source_locationt location, const exprt &expr, goto_programt &dest) const
Append goto instructions to havoc the underlying object of expr
Definition: havoc_utils.cpp:46
havoc_utilst::append_full_havoc_code
void append_full_havoc_code(const source_locationt location, goto_programt &dest) const
Append goto instructions to havoc the full assigns set.
Definition: havoc_utils.cpp:21
irept::id
const irep_idt & id() const
Definition: irep.h:396
assignst
std::set< exprt > assignst
Definition: havoc_utils.h:23
havoc_utilst::assigns
const assignst & assigns
Definition: havoc_utils.h:102
goto_program.h
source_locationt
Definition: source_location.h:18
expr_util.h
Deprecated expression utility functions.
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:72