@@ -8,48 +8,26 @@ Author: Diffblue Ltd.
8
8
9
9
#include " nondet.h"
10
10
11
- #include < util/arith_tools.h>
12
- #include < util/c_types.h>
13
- #include < util/fresh_symbol.h>
14
- #include < util/symbol.h>
15
-
16
- // / Gets a fresh nondet choice in range (min_value, max_value). GOTO generated
17
- // / resembles:
18
- // / ```
19
- // / int_type name_prefix::nondet_int = NONDET(int_type)
20
- // / ASSUME(name_prefix::nondet_int >= min_value)
21
- // / ASSUME(name_prefix::nondet_int <= max_value)
22
- // / ```
23
- // / \param min_value: Minimum value (inclusive) of returned int.
24
- // / \param max_value: Maximum value (inclusive) of returned int.
25
- // / \param name_prefix: Prefix for the fresh symbol name generated (should be
26
- // / function id)
27
- // / \param int_type: The type of the int used to non-deterministically choose
28
- // / one of the switch cases.
29
- // / \param mode: Mode (language) of the symbol to be generated.
30
- // / \param source_location: The location to mark the generated int with.
31
- // / \param symbol_table: The global symbol table.
32
- // / \param [out] instructions: Output instructions are written to
33
- // / 'instructions'. These declare, nondet-initialise and range-constrain (with
34
- // / assume statements) a fresh integer.
35
- // / \return Returns a symbol expression for the resulting integer.
11
+ #include " allocate_objects.h"
12
+ #include " arith_tools.h"
13
+ #include " c_types.h"
14
+ #include " fresh_symbol.h"
15
+ #include " symbol.h"
16
+
36
17
symbol_exprt generate_nondet_int (
37
- const mp_integer &min_value,
38
- const mp_integer &max_value,
39
- const std::string &name_prefix,
40
- const typet &int_type,
41
- const irep_idt &mode,
18
+ const exprt &min_value_expr,
19
+ const exprt &max_value_expr,
20
+ const std::string &basename_prefix,
42
21
const source_locationt &source_location,
43
- symbol_table_baset &symbol_table ,
22
+ allocate_objectst &allocate_objects ,
44
23
code_blockt &instructions)
45
24
{
46
- PRECONDITION (min_value < max_value);
25
+ PRECONDITION (min_value_expr.type () == max_value_expr.type ());
26
+ const typet &int_type = min_value_expr.type ();
47
27
48
28
// Declare a symbol for the non deterministic integer.
49
29
const symbol_exprt &nondet_symbol =
50
- get_fresh_aux_symbol (
51
- int_type, name_prefix, " nondet_int" , source_location, mode, symbol_table)
52
- .symbol_expr ();
30
+ allocate_objects.allocate_automatic_local_object (int_type, basename_prefix);
53
31
instructions.add (code_declt (nondet_symbol));
54
32
55
33
// Assign the symbol any non deterministic integer value.
@@ -60,30 +38,35 @@ symbol_exprt generate_nondet_int(
60
38
// Constrain the non deterministic integer with a lower bound of `min_value`.
61
39
// ASSUME(name_prefix::nondet_int >= min_value)
62
40
instructions.add (
63
- code_assumet (
64
- binary_predicate_exprt (
65
- nondet_symbol, ID_ge, from_integer (min_value, int_type))));
41
+ code_assumet (binary_predicate_exprt (nondet_symbol, ID_ge, min_value_expr)));
66
42
67
43
// Constrain the non deterministic integer with an upper bound of `max_value`.
68
44
// ASSUME(name_prefix::nondet_int <= max_value)
69
45
instructions.add (
70
- code_assumet (
71
- binary_predicate_exprt (
72
- nondet_symbol, ID_le, from_integer (max_value, int_type))));
46
+ code_assumet (binary_predicate_exprt (nondet_symbol, ID_le, max_value_expr)));
73
47
74
48
return nondet_symbol;
75
49
}
76
50
77
- // / Pick nondeterministically between imperative actions 'switch_cases'.
78
- // / \param name_prefix: Name prefix for fresh symbols (should be function id)
79
- // / \param switch_cases: List of codet objects to execute in each switch case.
80
- // / \param int_type: The type of the int used to non-deterministically choose
81
- // / one of the switch cases.
82
- // / \param mode: Mode (language) of the symbol to be generated.
83
- // / \param source_location: The location to mark the generated int with.
84
- // / \param symbol_table: The global symbol table.
85
- // / \return Returns a nondet-switch choosing between switch_cases. The resulting
86
- // / switch block has no default case.
51
+ symbol_exprt generate_nondet_int (
52
+ const mp_integer &min_value,
53
+ const mp_integer &max_value,
54
+ const std::string &basename_prefix,
55
+ const typet &int_type,
56
+ const source_locationt &source_location,
57
+ allocate_objectst &allocate_objects,
58
+ code_blockt &instructions)
59
+ {
60
+ PRECONDITION (min_value <= max_value);
61
+ return generate_nondet_int (
62
+ from_integer (min_value, int_type),
63
+ from_integer (max_value, int_type),
64
+ basename_prefix,
65
+ source_location,
66
+ allocate_objects,
67
+ instructions);
68
+ }
69
+
87
70
code_blockt generate_nondet_switch (
88
71
const irep_idt &name_prefix,
89
72
const alternate_casest &switch_cases,
@@ -99,14 +82,16 @@ code_blockt generate_nondet_switch(
99
82
100
83
code_blockt result_block;
101
84
85
+ allocate_objectst allocate_objects{
86
+ mode, source_location, name_prefix, symbol_table};
87
+
102
88
const symbol_exprt &switch_value = generate_nondet_int (
103
89
0 ,
104
90
switch_cases.size () - 1 ,
105
- id2string (name_prefix) ,
91
+ " nondet_int " ,
106
92
int_type,
107
- mode,
108
93
source_location,
109
- symbol_table ,
94
+ allocate_objects ,
110
95
result_block);
111
96
112
97
code_blockt switch_block;
0 commit comments