@@ -21,82 +21,6 @@ Author: Daniel Kroening
21
21
22
22
#include < langapi/language_util.h>
23
23
24
- // / Replaces in src, expressions of the form pointer_offset(constant) by that
25
- // / constant.
26
- // / \param src: an expression
27
- void remove_pointer_offsets (exprt &src)
28
- {
29
- if (src.id ()==ID_pointer_offset &&
30
- src.op0 ().id ()==ID_constant &&
31
- src.op0 ().type ().id ()==ID_pointer)
32
- {
33
- std::string binary_str=id2string (to_constant_expr (src.op0 ()).get_value ());
34
- // The constant address consists of OBJECT-ID || OFFSET.
35
- // Shift out the object-identifier bits, leaving only the offset:
36
- mp_integer offset=binary2integer (
37
- binary_str.substr (config.bv_encoding .object_bits ), false );
38
- src=from_integer (offset, src.type ());
39
- }
40
- else
41
- for (auto &op : src.operands ())
42
- remove_pointer_offsets (op);
43
- }
44
-
45
- // / Replaces in src, expressions of the form pointer_offset(array_symbol) by a
46
- // / constant value of 0. This is meant to simplify array expressions.
47
- // / \param src: an expression
48
- // / \param array_symbol: a symbol expression representing an array
49
- void remove_pointer_offsets (exprt &src, const symbol_exprt &array_symbol)
50
- {
51
- if (src.id ()==ID_pointer_offset &&
52
- src.op0 ().id ()==ID_constant &&
53
- src.op0 ().op0 ().id ()==ID_address_of &&
54
- src.op0 ().op0 ().op0 ().id ()==ID_index)
55
- {
56
- const index_exprt &idx=to_index_expr (src.op0 ().op0 ().op0 ());
57
- const irep_idt &array_id=to_symbol_expr (idx.array ()).get_identifier ();
58
- if (idx.array ().id ()==ID_symbol &&
59
- array_id==array_symbol.get_identifier () &&
60
- to_constant_expr (idx.index ()).value_is_zero_string ())
61
- src=from_integer (0 , src.type ());
62
- }
63
- else
64
- for (auto &op : src.operands ())
65
- remove_pointer_offsets (op, array_symbol);
66
- }
67
-
68
- // / Simplify an expression before putting it in the json format
69
- // / \param src: an expression potentialy containing array accesses (index_expr)
70
- // / \return an expression similar in meaning to src but where array accesses
71
- // / have been simplified
72
- exprt simplify_array_access (const exprt &src, const namespacet &ns)
73
- {
74
- if (src.id ()==ID_index && to_index_expr (src).array ().id ()==ID_symbol)
75
- {
76
- // Case where the array is a symbol.
77
- const symbol_exprt &array_symbol=to_symbol_expr (to_index_expr (src).array ());
78
- exprt simplified_index=to_index_expr (src).index ();
79
- // We remove potential appearances of `pointer_offset(array_symbol)`
80
- remove_pointer_offsets (simplified_index, array_symbol);
81
- simplified_index=simplify_expr (simplified_index, ns);
82
- return index_exprt (array_symbol, simplified_index);
83
- }
84
- else if (src.id ()==ID_index && to_index_expr (src).array ().id ()==ID_array)
85
- {
86
- // Case where the array is given by an array of expressions
87
- exprt index=to_index_expr (src).index ();
88
- remove_pointer_offsets (index);
89
-
90
- // We look for an actual integer value for the index
91
- index=simplify_expr (index, ns);
92
- unsigned i;
93
- if (index.id ()==ID_constant &&
94
- !to_unsigned_integer (to_constant_expr (index), i))
95
- return to_index_expr (src).array ().operands ()[i];
96
- }
97
- return src;
98
- }
99
-
100
24
// / Produce a json representation of a trace.
101
25
// / \param ns: a namespace
102
26
// / \param goto_trace: a trace in a goto program
@@ -169,7 +93,7 @@ void convert(
169
93
DATA_INVARIANT (
170
94
step.full_lhs .is_not_nil (),
171
95
" full_lhs in assignment must not be nil" );
172
- exprt simplified=simplify_array_access (step.full_lhs , ns);
96
+ exprt simplified=simplify_expr (step.full_lhs , ns);
173
97
full_lhs_string=from_expr (ns, identifier, simplified);
174
98
175
99
const symbolt *symbol;
@@ -183,7 +107,7 @@ void convert(
183
107
type_string=from_type (ns, identifier, symbol->type );
184
108
185
109
json_assignment[" mode" ]=json_stringt (id2string (symbol->mode ));
186
- exprt simplified=simplify_array_access (step.full_lhs_value , ns);
110
+ exprt simplified=simplify_expr (step.full_lhs_value , ns);
187
111
188
112
full_lhs_value=json (simplified, ns, symbol->mode );
189
113
}
0 commit comments