Skip to content

Commit 848dd95

Browse files
Add an interval_sparse_array::of_expr function
This initialize a sparse array from the array expression we know how to deal with.
1 parent 5f07bf0 commit 848dd95

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/solvers/refinement/string_refinement_util.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ interval_sparse_arrayt interval_sparse_arrayt::of_array_list(
176176
return sparse_array;
177177
}
178178

179+
optionalt<interval_sparse_arrayt>
180+
interval_sparse_arrayt::of_expr(const exprt &expr, const exprt &extra_value)
181+
{
182+
if(const auto &array_expr = expr_try_dynamic_cast<array_exprt>(expr))
183+
return interval_sparse_arrayt(*array_expr, extra_value);
184+
if(const auto &with_expr = expr_try_dynamic_cast<with_exprt>(expr))
185+
return interval_sparse_arrayt(*with_expr);
186+
if(expr.id() == "array-list")
187+
return of_array_list(expr, extra_value);
188+
return {};
189+
}
190+
179191
void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
180192
{
181193
equations_containing[expr].push_back(i);

src/solvers/refinement/string_refinement_util.h

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class interval_sparse_arrayt final : public sparse_arrayt
132132

133133
exprt to_if_expression(const exprt &index) const override;
134134

135+
/// If the expression is an array_exprt or a with_exprt uses the appropriate
136+
/// constructor, otherwise returns empty optional.
137+
static optionalt<interval_sparse_arrayt>
138+
of_expr(const exprt &expr, const exprt &extra_value);
139+
135140
private:
136141
explicit interval_sparse_arrayt(exprt default_value)
137142
: sparse_arrayt(default_value)

0 commit comments

Comments
 (0)