CBMC
solver_types.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Solver
4 
5 Author: Daniel Kroening, dkr@amazon.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_CPROVER_SOLVER_TYPES_H
13 #define CPROVER_CPROVER_SOLVER_TYPES_H
14 
15 #include <util/mathematical_expr.h>
16 #include <util/std_expr.h>
17 
18 #include <chrono>
19 #include <unordered_map>
20 #include <unordered_set>
21 
23 {
24 public:
26  {
27  }
28  explicit frame_reft(std::size_t __index) : index(__index)
29  {
30  }
31  std::size_t index;
32  friend bool operator==(const frame_reft &a, const frame_reft &b)
33  {
34  return a.index == b.index;
35  }
36 };
37 
38 using frame_mapt = std::unordered_map<symbol_exprt, frame_reft, irep_hash>;
39 
40 class framet
41 {
42 public:
44  symbol_exprt __symbol,
45  source_locationt __source_location,
46  frame_reft __ref)
47  : symbol(std::move(__symbol)),
48  source_location(std::move(__source_location)),
49  ref(std::move(__ref))
50  {
51  }
52 
54 
55  // our current hypothesis invariant
56  std::vector<exprt> invariants;
57  std::unordered_set<exprt, irep_hash> invariants_set;
58 
59  // inferred obligations
60  std::vector<exprt> obligations;
61  std::unordered_set<exprt, irep_hash> obligations_set;
62 
63  // auxiliary facts
64  std::vector<exprt> auxiliaries;
65  std::unordered_set<exprt, irep_hash> auxiliaries_set;
66 
67  // formulas where this frame is on the rhs of ⇒
68  struct implicationt
69  {
71  : lhs(std::move(__lhs)), rhs(std::move(__rhs))
72  {
73  }
76 
78  {
79  return implies_exprt(lhs, rhs);
80  }
81  };
82 
83  std::vector<implicationt> implications;
84 
85  // tracking source code origin
87 
88  void add_auxiliary(exprt);
89  void add_invariant(exprt);
90  void add_obligation(exprt);
91 
92  void reset()
93  {
94  invariants.clear();
95  invariants_set.clear();
96  obligations.clear();
97  obligations_set.clear();
98  auxiliaries.clear();
99  auxiliaries_set.clear();
100  }
101 
103 };
104 
105 frame_mapt build_frame_map(const std::vector<framet> &frames);
106 
107 frame_reft find_frame(const frame_mapt &, const symbol_exprt &frame_symbol);
108 
109 void find_implications(
110  const std::vector<exprt> &constraints,
111  std::vector<framet> &);
112 
113 std::vector<framet> setup_frames(const std::vector<exprt> &constraints);
114 
116 {
117 public:
119  source_locationt __source_location,
120  frame_reft __frame,
121  exprt __condition)
122  : source_location(std::move(__source_location)),
123  frame(std::move(__frame)),
124  condition(std::move(__condition))
125  {
126  }
127 
129  {
131  }
132 
136 
137  using statust = enum { UNKNOWN, PASS, REFUTED, ERROR, DROPPED };
139  std::chrono::time_point<std::chrono::steady_clock> start, stop;
140 
141  // trace information when REFUTED
143  {
144  trace_updatet(exprt __address, exprt __value)
145  : address(std::move(__address)), value(std::move(__value))
146  {
147  }
149  };
150 
152  {
154  std::vector<trace_updatet> updates;
155  };
156 
157  using tracet = std::vector<trace_statet>;
159 };
160 
161 std::vector<propertyt> find_properties(
162  const std::vector<exprt> &constraints,
163  const std::vector<framet> &);
164 
165 struct workt
166 {
167  using patht = std::vector<frame_reft>;
168 
169  workt(frame_reft __frame, exprt __invariant, patht __path)
170  : frame(std::move(__frame)),
171  invariant(std::move(__invariant)),
172  path(std::move(__path))
173  {
174  }
175 
176  // The frame where the invariant is to be established.
179 
181 
182  std::size_t nondet_counter = 0;
183 };
184 
185 #endif // CPROVER_CPROVER_SOLVER_TYPES_H
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
friend bool operator==(const frame_reft &a, const frame_reft &b)
Definition: solver_types.h:32
frame_reft(std::size_t __index)
Definition: solver_types.h:28
std::size_t index
Definition: solver_types.h:31
Stack frames – these are used for function calls and for exceptions.
Definition: solver_types.h:41
std::unordered_set< exprt, irep_hash > invariants_set
Definition: solver_types.h:57
std::vector< exprt > obligations
Definition: solver_types.h:60
std::unordered_set< exprt, irep_hash > auxiliaries_set
Definition: solver_types.h:65
void add_invariant(exprt)
frame_reft ref
Definition: solver_types.h:102
void reset()
Definition: solver_types.h:92
void add_auxiliary(exprt)
framet(symbol_exprt __symbol, source_locationt __source_location, frame_reft __ref)
Definition: solver_types.h:43
std::unordered_set< exprt, irep_hash > obligations_set
Definition: solver_types.h:61
symbol_exprt symbol
Definition: solver_types.h:53
std::vector< exprt > auxiliaries
Definition: solver_types.h:64
source_locationt source_location
Definition: solver_types.h:86
void add_obligation(exprt)
std::vector< exprt > invariants
Definition: solver_types.h:56
std::vector< implicationt > implications
Definition: solver_types.h:83
Application of (mathematical) function.
Boolean implication.
Definition: std_expr.h:2183
std::vector< trace_statet > tracet
Definition: solver_types.h:157
exprt condition
Definition: solver_types.h:135
enum { UNKNOWN, PASS, REFUTED, ERROR, DROPPED } statust
Definition: solver_types.h:137
statust status
Definition: solver_types.h:138
frame_reft frame
Definition: solver_types.h:134
propertyt(source_locationt __source_location, frame_reft __frame, exprt __condition)
Definition: solver_types.h:118
tracet trace
Definition: solver_types.h:158
irep_idt property_id() const
Definition: solver_types.h:128
std::chrono::time_point< std::chrono::steady_clock > stop
Definition: solver_types.h:139
source_locationt source_location
Definition: solver_types.h:133
std::chrono::time_point< std::chrono::steady_clock > start
Definition: solver_types.h:139
const irep_idt & get_property_id() const
static const source_locationt & nil()
Expression to hold a symbol (variable)
Definition: std_expr.h:131
API to expression classes for 'mathematical' expressions.
@ PASS
The property was not violated.
frame_mapt build_frame_map(const std::vector< framet > &frames)
std::vector< framet > setup_frames(const std::vector< exprt > &constraints)
std::unordered_map< symbol_exprt, frame_reft, irep_hash > frame_mapt
Definition: solver_types.h:38
void find_implications(const std::vector< exprt > &constraints, std::vector< framet > &)
frame_reft find_frame(const frame_mapt &, const symbol_exprt &frame_symbol)
std::vector< propertyt > find_properties(const std::vector< exprt > &constraints, const std::vector< framet > &)
API to expression classes.
implies_exprt as_expr() const
Definition: solver_types.h:77
implicationt(exprt __lhs, function_application_exprt __rhs)
Definition: solver_types.h:70
function_application_exprt rhs
Definition: solver_types.h:75
std::vector< trace_updatet > updates
Definition: solver_types.h:154
trace_updatet(exprt __address, exprt __value)
Definition: solver_types.h:144
workt(frame_reft __frame, exprt __invariant, patht __path)
Definition: solver_types.h:169
exprt invariant
Definition: solver_types.h:178
patht path
Definition: solver_types.h:180
std::size_t nondet_counter
Definition: solver_types.h:182
std::vector< frame_reft > patht
Definition: solver_types.h:167
frame_reft frame
Definition: solver_types.h:177