Skip to content

Commit 0764f77

Browse files
authored
Merge pull request diffblue#2036 from romainbrenguier/id_array_list
Define ID and exprt for array-list
2 parents 690b606 + 47f4b35 commit 0764f77

File tree

12 files changed

+40
-17
lines changed

12 files changed

+40
-17
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3913,7 +3913,7 @@ std::string expr2ct::convert_with_precedence(
39133913
else if(src.id()==ID_array)
39143914
return convert_array(src, precedence);
39153915

3916-
else if(src.id()=="array-list")
3916+
else if(src.id() == ID_array_list)
39173917
return convert_array_list(src, precedence);
39183918

39193919
else if(src.id()==ID_typecast)

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ void interpretert::evaluate(
934934
return;
935935
}
936936
}
937-
else if(expr.op0().id()=="array-list")
937+
else if(expr.op0().id() == ID_array_list)
938938
{
939939
// This sort of construct comes from boolbv_get, but doesn't seem
940940
// to have an exprt yet. Its operands are a list of key-value pairs.

src/solvers/flattening/boolbv_get.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
375375

376376
if(size_mpint>100 || size.id()==ID_infinity)
377377
{
378-
result=exprt("array-list", type);
378+
result = array_list_exprt(to_array_type(type));
379379
result.type().set(ID_size, integer2string(size_mpint));
380380

381381
result.operands().reserve(values.size()*2);

src/solvers/refinement/string_refinement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ exprt substitute_array_lists(exprt expr, size_t string_max_length)
20502050
for(auto &operand : expr.operands())
20512051
operand = substitute_array_lists(operand, string_max_length);
20522052

2053-
if(expr.id()=="array-list")
2053+
if(expr.id() == ID_array_list)
20542054
{
20552055
DATA_INVARIANT(
20562056
expr.operands().size()>=2,

src/solvers/refinement/string_refinement_util.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,21 @@ interval_sparse_arrayt::interval_sparse_arrayt(
164164
}
165165
}
166166

167-
interval_sparse_arrayt interval_sparse_arrayt::of_array_list(
168-
const exprt &expr,
167+
interval_sparse_arrayt::interval_sparse_arrayt(
168+
const array_list_exprt &expr,
169169
const exprt &extra_value)
170+
: interval_sparse_arrayt(extra_value)
170171
{
171172
PRECONDITION(expr.operands().size() % 2 == 0);
172-
interval_sparse_arrayt sparse_array(extra_value);
173173
for(std::size_t i = 0; i < expr.operands().size(); i += 2)
174174
{
175175
const auto index = numeric_cast<std::size_t>(expr.operands()[i]);
176176
INVARIANT(
177177
expr.operands()[i + 1].type() == extra_value.type(),
178178
"all values in array should have the same type");
179179
if(index.has_value() && expr.operands()[i + 1].id() != ID_unknown)
180-
sparse_array.entries[*index] = expr.operands()[i + 1];
180+
entries[*index] = expr.operands()[i + 1];
181181
}
182-
return sparse_array;
183182
}
184183

185184
optionalt<interval_sparse_arrayt>
@@ -189,8 +188,8 @@ interval_sparse_arrayt::of_expr(const exprt &expr, const exprt &extra_value)
189188
return interval_sparse_arrayt(*array_expr, extra_value);
190189
if(const auto &with_expr = expr_try_dynamic_cast<with_exprt>(expr))
191190
return interval_sparse_arrayt(*with_expr);
192-
if(expr.id() == "array-list")
193-
return of_array_list(expr, extra_value);
191+
if(const auto &array_list = expr_try_dynamic_cast<array_list_exprt>(expr))
192+
return interval_sparse_arrayt(*array_list, extra_value);
194193
return {};
195194
}
196195

src/solvers/refinement/string_refinement_util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ class interval_sparse_arrayt final : public sparse_arrayt
131131
/// Initialize a sparse array from an array represented by a list of
132132
/// index-value pairs, and setting the default to `extra_value`.
133133
/// Indexes must be constant expressions, and negative indexes are ignored.
134-
static interval_sparse_arrayt
135-
of_array_list(const exprt &expr, const exprt &extra_value);
134+
interval_sparse_arrayt(
135+
const array_list_exprt &expr,
136+
const exprt &extra_value);
136137

137138
exprt to_if_expression(const exprt &index) const override;
138139

src/solvers/smt1/smt1_conv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ exprt smt1_convt::ce_value(
219219
if(index_expr.is_nil())
220220
return nil_exprt();
221221

222-
exprt array_list("array-list", type);
222+
array_list_exprt array_list(array_type);
223223
array_list.copy_to_operands(index_expr, value_expr);
224224

225225
return array_list;

src/solvers/smt1/smt1_conv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class smt1_convt:public prop_convt
158158
const std::string &value)
159159
{
160160
exprt tmp=ce_value(identifier.type, index, value, false);
161-
if(tmp.id()=="array-list" && identifier.value.id()=="array-list")
161+
if(tmp.id() == ID_array_list && identifier.value.id() == ID_array_list)
162162
{
163163
forall_operands(it, tmp)
164164
identifier.value.copy_to_operands(*it);

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ IREP_ID_ONE(array_of)
246246
IREP_ID_ONE(array_equal)
247247
IREP_ID_ONE(array_set)
248248
IREP_ID_ONE(array_copy)
249+
IREP_ID_ONE(array_list)
249250
IREP_ID_ONE(mod)
250251
IREP_ID_ONE(rem)
251252
IREP_ID_ONE(shr)

src/util/simplify_expr_array.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool simplify_exprt::simplify_index(exprt &expr)
167167
return false;
168168
}
169169
}
170-
else if(array.id()=="array-list")
170+
else if(array.id() == ID_array_list)
171171
{
172172
// These are index/value pairs, alternating.
173173
for(size_t i=0; i<array.operands().size()/2; i++)

src/util/std_expr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,27 @@ template<> inline bool can_cast_expr<array_exprt>(const exprt &base)
16491649
return base.id()==ID_array;
16501650
}
16511651

1652+
/// Array constructor from a list of index-element pairs
1653+
/// Operands are index/value pairs, alternating.
1654+
class array_list_exprt : public exprt
1655+
{
1656+
public:
1657+
explicit array_list_exprt(const array_typet &_type)
1658+
: exprt(ID_array_list, _type)
1659+
{
1660+
}
1661+
};
1662+
1663+
template <>
1664+
inline bool can_cast_expr<array_list_exprt>(const exprt &base)
1665+
{
1666+
return base.id() == ID_array_list;
1667+
}
1668+
1669+
inline void validate_expr(const array_list_exprt &value)
1670+
{
1671+
PRECONDITION(value.operands().size() % 2 == 0);
1672+
}
16521673

16531674
/*! \brief vector constructor from list of elements
16541675
*/

unit/solvers/refinement/string_refinement/substitute_array_list.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ SCENARIO("substitute_array_list",
2020
{
2121
const typet char_type=unsignedbv_typet(16);
2222
const typet int_type=signedbv_typet(32);
23-
exprt arr("array-list");
23+
const array_typet array_type(char_type, infinity_exprt(int_type));
24+
array_list_exprt arr(array_type);
2425
const exprt index0=from_integer(0, int_type);
2526
const exprt charx=from_integer('x', char_type);
2627
const exprt index1=from_integer(1, int_type);

0 commit comments

Comments
 (0)