File tree 2 files changed +30
-0
lines changed 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,24 @@ interval_sparse_arrayt::interval_sparse_arrayt(
158
158
}
159
159
}
160
160
161
+ interval_sparse_arrayt interval_sparse_arrayt::of_array_list (
162
+ const exprt &expr,
163
+ const exprt &extra_value)
164
+ {
165
+ PRECONDITION (expr.operands ().size () % 2 == 0 );
166
+ interval_sparse_arrayt sparse_array (extra_value);
167
+ for (std::size_t i = 0 ; i < expr.operands ().size (); i += 2 )
168
+ {
169
+ const auto index = numeric_cast<std::size_t >(expr.operands ()[i]);
170
+ INVARIANT (
171
+ expr.operands ()[i + 1 ].type () == extra_value.type (),
172
+ " all values in array should have the same type" );
173
+ if (index .has_value () && expr.operands ()[i + 1 ].id () != ID_unknown)
174
+ sparse_array.entries [*index ] = expr.operands ()[i + 1 ];
175
+ }
176
+ return sparse_array;
177
+ }
178
+
161
179
void equation_symbol_mappingt::add (const std::size_t i, const exprt &expr)
162
180
{
163
181
equations_containing[expr].push_back (i);
Original file line number Diff line number Diff line change @@ -124,7 +124,19 @@ class interval_sparse_arrayt final : public sparse_arrayt
124
124
// / `extra_value`.
125
125
interval_sparse_arrayt (const array_exprt &expr, const exprt &extra_value);
126
126
127
+ // / Initialize a sparse array from an array represented by a list of
128
+ // / index-value pairs, and setting the default to `extra_value`.
129
+ // / Indexes must be constant expressions, and negative indexes are ignored.
130
+ static interval_sparse_arrayt
131
+ of_array_list (const exprt &expr, const exprt &extra_value);
132
+
127
133
exprt to_if_expression (const exprt &index) const override ;
134
+
135
+ private:
136
+ explicit interval_sparse_arrayt (exprt default_value)
137
+ : sparse_arrayt(default_value)
138
+ {
139
+ }
128
140
};
129
141
130
142
// / Maps equation to expressions contained in them and conversely expressions to
You can’t perform that action at this time.
0 commit comments