Skip to content

Commit bafd7e7

Browse files
authored
Merge pull request #3771 from tautschnig/deprecation-array_exprt
Construct array_exprt in a non-deprecated way [blocks: #3768]
2 parents 6f06664 + 475a7b9 commit bafd7e7

File tree

17 files changed

+44
-42
lines changed

17 files changed

+44
-42
lines changed

jbmc/src/java_bytecode/character_refine_preprocess.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,13 +1187,13 @@ exprt character_refine_preprocesst::expr_of_to_chars(
11871187
{
11881188
array_typet array_type=to_array_type(type);
11891189
const typet &char_type=array_type.subtype();
1190-
array_exprt case1(array_type);
1191-
array_exprt case2(array_type);
11921190
exprt low_surrogate=expr_of_low_surrogate(chr, char_type);
1193-
case1.copy_to_operands(low_surrogate);
1194-
case2.add_to_operands(
1195-
std::move(low_surrogate), expr_of_high_surrogate(chr, char_type));
1196-
return if_exprt(expr_of_is_bmp_code_point(chr, type), case1, case2);
1191+
array_exprt case1({low_surrogate}, array_type);
1192+
exprt high_surrogate = expr_of_high_surrogate(chr, char_type);
1193+
array_exprt case2(
1194+
{std::move(low_surrogate), std::move(high_surrogate)}, array_type);
1195+
return if_exprt(
1196+
expr_of_is_bmp_code_point(chr, type), std::move(case1), std::move(case2));
11971197
}
11981198

11991199
/// Converts function call to an assignment of an expression corresponding to

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,13 +1614,14 @@ exprt java_bytecode_parsert::get_relement_value()
16141614

16151615
case '[':
16161616
{
1617-
array_exprt values;
16181617
u2 num_values=read_u2();
1618+
exprt::operandst values;
1619+
values.reserve(num_values);
16191620
for(std::size_t i=0; i<num_values; i++)
16201621
{
1621-
values.operands().push_back(get_relement_value());
1622+
values.push_back(get_relement_value());
16221623
}
1623-
return std::move(values);
1624+
return array_exprt(std::move(values), array_typet(typet(), exprt()));
16241625
}
16251626

16261627
case 's':

jbmc/src/java_bytecode/java_string_literals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static array_exprt utf16_to_array(const std::wstring &in)
4949
{
5050
const auto jchar=java_char_type();
5151
array_exprt ret(
52-
array_typet(jchar, from_integer(in.length(), java_int_type())));
52+
{}, array_typet(jchar, from_integer(in.length(), java_int_type())));
5353
for(const auto c : in)
5454
ret.copy_to_operands(from_integer(c, jchar));
5555
return ret;

jbmc/unit/solvers/refinement/string_constraint_instantiation/instantiate_not_contains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ constant_exprt from_integer(const mp_integer &i)
6161
array_string_exprt make_string_exprt(const std::string &str)
6262
{
6363
const constant_exprt length=from_integer(str.length(), t.length_type());
64-
array_exprt content(array_typet(t.char_type(), length));
64+
array_exprt content({}, array_typet(t.char_type(), length));
6565

6666
for(const char c : str)
6767
content.copy_to_operands(from_integer(c, t.char_type()));

src/goto-programs/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ exprt interpretert::get_value(
487487
else if(real_type.id()==ID_array)
488488
{
489489
// Get size of array
490-
array_exprt result(to_array_type(real_type));
490+
array_exprt result({}, to_array_type(real_type));
491491
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
492492
mp_integer subtype_size=get_size(type.subtype());
493493
mp_integer count;
@@ -551,7 +551,7 @@ exprt interpretert::get_value(
551551
}
552552
else if(real_type.id()==ID_array)
553553
{
554-
array_exprt result(to_array_type(real_type));
554+
array_exprt result({}, to_array_type(real_type));
555555
const exprt &size_expr=static_cast<const exprt &>(type.find(ID_size));
556556

557557
// Get size of array

src/goto-programs/remove_vector.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void remove_vector(exprt &expr)
9797
const typet subtype=array_type.subtype();
9898
// do component-wise:
9999
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
100-
array_exprt array_expr(array_type);
100+
array_exprt array_expr({}, array_type);
101101
array_expr.operands().resize(numeric_cast_v<std::size_t>(dimension));
102102

103103
for(std::size_t i=0; i<array_expr.operands().size(); i++)
@@ -124,7 +124,7 @@ static void remove_vector(exprt &expr)
124124
const typet subtype=array_type.subtype();
125125
// do component-wise:
126126
// -x -> vector(-x[0],-x[1],...)
127-
array_exprt array_expr(array_type);
127+
array_exprt array_expr({}, array_type);
128128
array_expr.operands().resize(numeric_cast_v<std::size_t>(dimension));
129129

130130
for(std::size_t i=0; i<array_expr.operands().size(); i++)
@@ -153,9 +153,7 @@ static void remove_vector(exprt &expr)
153153
const auto dimension = numeric_cast_v<std::size_t>(array_type.size());
154154
exprt casted_op =
155155
typecast_exprt::conditional_cast(op, array_type.subtype());
156-
array_exprt array_expr(array_type);
157-
array_expr.operands().resize(dimension, op);
158-
expr = array_expr;
156+
expr = array_exprt(exprt::operandst(dimension, casted_op), array_type);
159157
}
160158
}
161159
}

src/solvers/lowering/byte_operators.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static exprt unpack_rec(
3636
const namespacet &ns,
3737
bool unpack_byte_array=false)
3838
{
39-
array_exprt array(
39+
array_exprt array({},
4040
array_typet(unsignedbv_typet(8), from_integer(0, size_type())));
4141

4242
// endianness_mapt should be the point of reference for mapping out
@@ -240,7 +240,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
240240
element_width.has_value() && *element_width >= 1 &&
241241
*element_width % 8 == 0 && to_integer(array_type.size(), num_elements))
242242
{
243-
array_exprt array(array_type);
243+
array_exprt array({}, array_type);
244244

245245
for(mp_integer i=0; i<num_elements; ++i)
246246
{

src/solvers/refinement/string_builtin_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static array_string_exprt
102102
make_string(Iter begin, Iter end, const array_typet &array_type)
103103
{
104104
const typet &char_type = array_type.subtype();
105-
array_exprt array_expr(array_type);
105+
array_exprt array_expr({}, array_type);
106106
const auto &insert = std::back_inserter(array_expr.operands());
107107
std::transform(begin, end, insert, [&](const mp_integer &i) {
108108
return from_integer(i, char_type);

src/solvers/refinement/string_constraint_generator_float.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
422422
two_power_e_over_ten_power_d_table.size(),
423423
int_type);
424424
array_exprt conversion_factor_table(
425-
array_typet(float_type, conversion_factor_table_size));
425+
{}, array_typet(float_type, conversion_factor_table_size));
426426
for(const auto &negative : two_power_e_over_ten_power_d_table_negatives)
427427
conversion_factor_table.copy_to_operands(
428428
constant_float(negative, float_spec));

src/solvers/refinement/string_refinement_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ array_exprt interval_sparse_arrayt::concretize(
171171
{
172172
const array_typet array_type(
173173
default_value.type(), from_integer(size, index_type));
174-
array_exprt array(array_type);
174+
array_exprt array({}, array_type);
175175
array.operands().reserve(size);
176176

177177
auto it = entries.begin();

src/util/expr_initializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
122122
{
123123
// we initialize this with an empty array
124124

125-
array_exprt value(array_type);
125+
array_exprt value({}, array_type);
126126
value.type().id(ID_array);
127127
value.type().set(ID_size, from_integer(0, size_type()));
128128
value.add_source_location()=source_location;
@@ -157,7 +157,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
157157
if(*array_size < 0)
158158
return nil_exprt();
159159

160-
array_exprt value(array_type);
160+
array_exprt value({}, array_type);
161161
value.operands().resize(numeric_cast_v<std::size_t>(*array_size), tmpval);
162162
value.add_source_location()=source_location;
163163
return std::move(value);

src/util/simplify_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ exprt simplify_exprt::bits2expr(
15401540

15411541
const std::size_t el_size = numeric_cast_v<std::size_t>(*el_size_opt);
15421542

1543-
array_exprt result(array_type);
1543+
array_exprt result({}, array_type);
15441544
result.reserve_operands(n_el);
15451545

15461546
for(std::size_t i=0; i<n_el; ++i)

src/util/std_expr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,11 @@ class array_exprt : public multi_ary_exprt
17651765
: multi_ary_exprt(ID_array, _type)
17661766
{
17671767
}
1768+
1769+
array_exprt(operandst &&_operands, const array_typet &_type)
1770+
: multi_ary_exprt(ID_array, std::move(_operands), _type)
1771+
{
1772+
}
17681773
};
17691774

17701775
/// \brief Cast an exprt to an \ref array_exprt

src/util/string_constant.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ array_exprt string_constantt::to_array_expr() const
3535

3636
exprt size=from_integer(string_size, index_type());
3737

38-
array_exprt dest;
39-
dest.type()=array_typet(char_type, size);
38+
array_exprt dest({}, array_typet(char_type, size));
4039

4140
dest.operands().resize(string_size);
4241

unit/pointer-analysis/value_set.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ SCENARIO(
263263

264264
WHEN("We query { &i1, &i2 }[i3]")
265265
{
266-
array_exprt arr(array_typet(int32_ptr, from_integer(2, int32_type)));
267-
arr.copy_to_operands(address_of_exprt(i1.symbol_expr()));
268-
arr.copy_to_operands(address_of_exprt(i2.symbol_expr()));
266+
array_exprt arr(
267+
{address_of_exprt(i1.symbol_expr()),
268+
address_of_exprt(i2.symbol_expr())},
269+
array_typet(int32_ptr, from_integer(2, int32_type)));
269270

270271
index_exprt index_of_arr(arr, i3.symbol_expr());
271272

unit/solvers/refinement/array_pool/array_pool.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ SCENARIO(
4343
WHEN("Looking for the address of the first element of a constant array")
4444
{
4545
const array_typet array_type(char_type, from_integer(3, length_type));
46-
const exprt array = [array_type, char_type]{
47-
array_exprt a(array_type);
48-
a.operands().push_back(from_integer('f', char_type));
49-
a.operands().push_back(from_integer('o', char_type));
50-
a.operands().push_back(from_integer('o', char_type));
51-
return a;
52-
}();
53-
const exprt first_element =
54-
index_exprt(array, from_integer(0, length_type));
46+
const array_exprt array(
47+
{from_integer('f', char_type),
48+
from_integer('o', char_type),
49+
from_integer('o', char_type)},
50+
array_type);
51+
const exprt first_element =
52+
index_exprt(array, from_integer(0, length_type));
5553
const exprt pointer = address_of_exprt(first_element, pointer_type);
5654
const array_string_exprt associated_array =
5755
pool.find(pointer, array_type.size());

unit/solvers/refinement/string_refinement/concretize_array.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ SCENARIO("concretize_array_expression",
4848
const exprt concrete = sparse_array.concretize(7, int_type);
4949

5050
// Assert
51-
array_exprt expected(array_type);
5251
// The expected result is `{ 'x', 'x', 'y', 'y', 'y', 'z', 'z' }`
53-
expected.operands() = {charx, charx, chary, chary, chary, charz, charz};
52+
array_exprt expected(
53+
{charx, charx, chary, chary, chary, charz, charz}, array_type);
5454
to_array_type(expected.type()).size() = from_integer(7, int_type);
5555
REQUIRE(concrete==expected);
5656
}

0 commit comments

Comments
 (0)