Skip to content

Commit 4022dfb

Browse files
authored
Merge pull request #3775 from tautschnig/deprecation-struct_exprt
Construct struct_exprt in a non-deprecated way
2 parents 71a5cb4 + e1ff1fd commit 4022dfb

File tree

18 files changed

+80
-90
lines changed

18 files changed

+80
-90
lines changed

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,11 @@ codet java_string_library_preprocesst::code_assign_components_to_java_string(
836836
// A String has a field Object with @clsid = String
837837
const symbolt &jlo_symbol = *symbol_table.lookup("java::java.lang.Object");
838838
const struct_typet &jlo_struct = to_struct_type(jlo_symbol.type);
839-
struct_exprt jlo_init(jlo_struct);
839+
struct_exprt jlo_init({}, jlo_struct);
840840
irep_idt clsid = get_tag(lhs.type().subtype());
841841
java_root_class_init(jlo_init, jlo_struct, clsid);
842842

843-
struct_exprt struct_rhs(deref.type());
844-
struct_rhs.copy_to_operands(jlo_init);
845-
struct_rhs.copy_to_operands(rhs_length);
846-
struct_rhs.copy_to_operands(rhs_array);
843+
struct_exprt struct_rhs({jlo_init, rhs_length, rhs_array}, deref.type());
847844
return code_assignt(
848845
checked_dereference(lhs, lhs.type().subtype()), struct_rhs);
849846
}
@@ -1342,7 +1339,7 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13421339
{
13431340
// Declarations of the fields of arg_i_struct
13441341
// arg_i_struct is { arg_i_string_expr, tmp_int, tmp_char, ... }
1345-
struct_exprt arg_i_struct(structured_type);
1342+
struct_exprt arg_i_struct({}, structured_type);
13461343
std::list<exprt> field_exprs;
13471344
for(const auto & comp : structured_type.components())
13481345
{

jbmc/src/java_bytecode/java_string_literals.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ symbol_exprt get_or_create_string_literal_symbol(
9898
// the literal with @clsid = String
9999
struct_tag_typet jlo_symbol("java::java.lang.Object");
100100
const auto &jlo_struct = to_struct_type(ns.follow(jlo_symbol));
101-
struct_exprt jlo_init(jlo_symbol);
101+
struct_exprt jlo_init({}, jlo_symbol);
102102
const auto &jls_struct = to_struct_type(ns.follow(string_type));
103103
java_root_class_init(jlo_init, jlo_struct, "java::java.lang.String");
104104

@@ -109,7 +109,7 @@ symbol_exprt get_or_create_string_literal_symbol(
109109
const array_exprt data =
110110
utf16_to_array(utf8_to_utf16_native_endian(id2string(value)));
111111

112-
struct_exprt literal_init(new_symbol.type);
112+
struct_exprt literal_init({}, new_symbol.type);
113113
literal_init.operands().resize(jls_struct.components().size());
114114
const std::size_t jlo_nb = jls_struct.component_number("@java.lang.Object");
115115
literal_init.operands()[jlo_nb] = jlo_init;
@@ -183,8 +183,7 @@ symbol_exprt get_or_create_string_literal_symbol(
183183
// Case where something defined java.lang.String, so it has
184184
// a proper base class (always java.lang.Object in practical
185185
// JDKs seen so far)
186-
struct_exprt literal_init(new_symbol.type);
187-
literal_init.move_to_operands(jlo_init);
186+
struct_exprt literal_init({std::move(jlo_init)}, new_symbol.type);
188187
for(const auto &comp : jls_struct.components())
189188
{
190189
if(comp.get_name()=="@java.lang.Object")

jbmc/unit/solvers/refinement/string_refinement/dependency_graph.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ struct_exprt make_string_argument(std::string name)
3737

3838
const symbol_exprt length(name + "_length", length_type());
3939
const symbol_exprt content(name + "_content", pointer_type(java_char_type()));
40-
struct_exprt expr(type);
41-
expr.operands().push_back(length);
42-
expr.operands().push_back(content);
43-
return expr;
40+
return struct_exprt({length, content}, type);
4441
}
4542

4643
SCENARIO("dependency_graph", "[core][solvers][refinement][string_refinement]")

jbmc/unit/solvers/refinement/string_refinement/string_symbol_resolution.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ SCENARIO("string_identifiers_resolution_from_equations",
3939
struct_typet struct_type;
4040
struct_type.components().emplace_back("str1", string_typet());
4141
struct_type.components().emplace_back("str2", string_typet());
42-
struct_exprt struct_expr(struct_type);
43-
struct_expr.operands().push_back(a);
44-
struct_expr.operands().push_back(f);
42+
struct_exprt struct_expr({a, f}, struct_type);
4543
symbol_exprt symbol_struct("sym_struct", struct_type);
4644

4745
std::vector<equal_exprt> equations;

src/cpp/cpp_typecheck_virtual_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol)
8181
// do the values
8282
const struct_typet &vt_type=to_struct_type(vt_symb_type.type);
8383

84-
struct_exprt values(struct_tag_typet(vt_symb_type.name));
84+
struct_exprt values({}, struct_tag_typet(vt_symb_type.name));
8585

8686
for(const auto &compo : vt_type.components())
8787
{

src/goto-instrument/dump_c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ void dump_ct::cleanup_expr(exprt &expr)
12531253
{
12541254
if(u_type_f.get_component(u.get_component_name()).get_is_padding())
12551255
// we just use an empty struct to fake an empty union
1256-
expr=struct_exprt(struct_typet());
1256+
expr = struct_exprt({}, struct_typet());
12571257
}
12581258
// add a typecast for NULL
12591259
else if(u.op().id()==ID_constant &&

src/goto-programs/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ exprt interpretert::get_value(
465465
const typet real_type=ns.follow(type);
466466
if(real_type.id()==ID_struct)
467467
{
468-
struct_exprt result(real_type);
468+
struct_exprt result({}, real_type);
469469
const struct_typet &struct_type=to_struct_type(real_type);
470470
const struct_typet::componentst &components=struct_type.components();
471471

@@ -532,7 +532,7 @@ exprt interpretert::get_value(
532532

533533
if(real_type.id()==ID_struct)
534534
{
535-
struct_exprt result(real_type);
535+
struct_exprt result({}, real_type);
536536
const struct_typet &struct_type=to_struct_type(real_type);
537537
const struct_typet::componentst &components=struct_type.components();
538538

src/goto-programs/remove_complex.cpp

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,18 @@ static void remove_complex(exprt &expr)
136136
PRECONDITION(expr.operands().size() == 2);
137137
// do component-wise:
138138
// x+y -> complex(x.r+y.r,x.i+y.i)
139-
struct_exprt struct_expr(expr.type());
140-
struct_expr.operands().resize(2);
141-
142-
struct_expr.op0()=
143-
binary_exprt(complex_member(expr.op0(), ID_real), expr.id(),
144-
complex_member(expr.op1(), ID_real));
145-
146-
struct_expr.op0().add_source_location()=expr.source_location();
147-
148-
struct_expr.op1()=
149-
binary_exprt(complex_member(expr.op0(), ID_imag), expr.id(),
150-
complex_member(expr.op1(), ID_imag));
151-
139+
struct_exprt struct_expr(
140+
{binary_exprt(
141+
complex_member(expr.op0(), ID_real),
142+
expr.id(),
143+
complex_member(expr.op1(), ID_real)),
144+
binary_exprt(
145+
complex_member(expr.op0(), ID_imag),
146+
expr.id(),
147+
complex_member(expr.op1(), ID_imag))},
148+
expr.type());
149+
150+
struct_expr.op0().add_source_location() = expr.source_location();
152151
struct_expr.op1().add_source_location()=expr.source_location();
153152

154153
expr=struct_expr;
@@ -158,18 +157,14 @@ static void remove_complex(exprt &expr)
158157
auto const &unary_minus_expr = to_unary_minus_expr(expr);
159158
// do component-wise:
160159
// -x -> complex(-x.r,-x.i)
161-
struct_exprt struct_expr(unary_minus_expr.type());
162-
struct_expr.operands().resize(2);
163-
164-
struct_expr.op0() =
165-
unary_minus_exprt(complex_member(unary_minus_expr.op(), ID_real));
160+
struct_exprt struct_expr(
161+
{unary_minus_exprt(complex_member(unary_minus_expr.op(), ID_real)),
162+
unary_minus_exprt(complex_member(unary_minus_expr.op(), ID_imag))},
163+
unary_minus_expr.type());
166164

167165
struct_expr.op0().add_source_location() =
168166
unary_minus_expr.source_location();
169167

170-
struct_expr.op1() =
171-
unary_minus_exprt(complex_member(unary_minus_expr.op(), ID_imag));
172-
173168
struct_expr.op1().add_source_location() =
174169
unary_minus_expr.source_location();
175170

@@ -178,9 +173,9 @@ static void remove_complex(exprt &expr)
178173
else if(expr.id()==ID_complex)
179174
{
180175
auto const &complex_expr = to_complex_expr(expr);
181-
auto struct_expr = struct_exprt(complex_expr.type());
176+
auto struct_expr = struct_exprt(
177+
{complex_expr.real(), complex_expr.imag()}, complex_expr.type());
182178
struct_expr.add_source_location() = complex_expr.source_location();
183-
struct_expr.copy_to_operands(complex_expr.real(), complex_expr.imag());
184179
expr.swap(struct_expr);
185180
}
186181
else if(expr.id()==ID_typecast)
@@ -192,18 +187,15 @@ static void remove_complex(exprt &expr)
192187
{
193188
// complex to complex -- do typecast per component
194189

195-
struct_exprt struct_expr(typecast_expr.type());
196-
struct_expr.operands().resize(2);
197-
198-
struct_expr.op0() =
199-
typecast_exprt(complex_member(typecast_expr.op(), ID_real), subtype);
190+
struct_exprt struct_expr(
191+
{typecast_exprt(complex_member(typecast_expr.op(), ID_real), subtype),
192+
typecast_exprt(
193+
complex_member(typecast_expr.op(), ID_imag), subtype)},
194+
typecast_expr.type());
200195

201196
struct_expr.op0().add_source_location() =
202197
typecast_expr.source_location();
203198

204-
struct_expr.op1() =
205-
typecast_exprt(complex_member(typecast_expr.op(), ID_imag), subtype);
206-
207199
struct_expr.op1().add_source_location() =
208200
typecast_expr.source_location();
209201

@@ -212,11 +204,10 @@ static void remove_complex(exprt &expr)
212204
else
213205
{
214206
// non-complex to complex
215-
struct_exprt struct_expr(typecast_expr.type());
216-
struct_expr.operands().resize(2);
217-
218-
struct_expr.op0() = typecast_exprt(typecast_expr.op(), subtype);
219-
struct_expr.op1()=from_integer(0, subtype);
207+
struct_exprt struct_expr(
208+
{typecast_exprt(typecast_expr.op(), subtype),
209+
from_integer(0, subtype)},
210+
typecast_expr.type());
220211
struct_expr.add_source_location() = typecast_expr.source_location();
221212

222213
expr=struct_expr;

src/goto-programs/string_abstraction.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ symbol_exprt string_abstractiont::add_dummy_symbol_and_value(
429429
if(source_type.id()==ID_array && is_char_type(source_type.subtype()) &&
430430
type_eq(type, string_struct, ns))
431431
{
432-
new_symbol.value=struct_exprt(string_struct);
433-
new_symbol.value.operands().resize(3);
434-
new_symbol.value.op0()=build_unknown(whatt::IS_ZERO, false);
435-
new_symbol.value.op1()=build_unknown(whatt::LENGTH, false);
436-
new_symbol.value.op2()=to_array_type(source_type).size().id()==ID_infinity?
437-
build_unknown(whatt::SIZE, false):to_array_type(source_type).size();
432+
new_symbol.value = struct_exprt(
433+
{build_unknown(whatt::IS_ZERO, false),
434+
build_unknown(whatt::LENGTH, false),
435+
to_array_type(source_type).size().id() == ID_infinity
436+
? build_unknown(whatt::SIZE, false)
437+
: to_array_type(source_type).size()},
438+
string_struct);
438439
make_type(new_symbol.value.op2(), build_type(whatt::SIZE));
439440
}
440441
else
@@ -1032,12 +1033,11 @@ bool string_abstractiont::build_symbol_constant(
10321033
new_symbol.is_file_local=false;
10331034

10341035
{
1035-
struct_exprt value(string_struct);
1036-
value.operands().resize(3);
1037-
1038-
value.op0()=true_exprt();
1039-
value.op1()=from_integer(zero_length, build_type(whatt::LENGTH));
1040-
value.op2()=from_integer(buf_size, build_type(whatt::SIZE));
1036+
struct_exprt value(
1037+
{true_exprt(),
1038+
from_integer(zero_length, build_type(whatt::LENGTH)),
1039+
from_integer(buf_size, build_type(whatt::SIZE))},
1040+
string_struct);
10411041

10421042
// initialization
10431043
goto_programt::targett assignment1=initialization.add_instruction();

src/solvers/flattening/boolbv_get.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ exprt boolbvt::bv_get_rec(
152152
}
153153
}
154154

155-
struct_exprt dest(type);
156-
dest.operands().swap(op);
157-
return std::move(dest);
155+
return struct_exprt(std::move(op), type);
158156
}
159157
else if(type.id()==ID_union)
160158
{

src/solvers/lowering/byte_operators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
264264
const struct_typet::componentst &components=struct_type.components();
265265

266266
bool failed=false;
267-
struct_exprt s(src.type());
267+
struct_exprt s({}, src.type());
268268

269269
for(const auto &comp : components)
270270
{

src/solvers/refinement/string_constraint_generator_format.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,11 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
401401
if(fe.is_format_specifier())
402402
{
403403
const format_specifiert &fs=fe.get_format_specifier();
404-
struct_exprt arg;
405404
if(fs.conversion!=format_specifiert::PERCENT_SIGN &&
406405
fs.conversion!=format_specifiert::LINE_SEPARATOR)
407406
{
407+
exprt arg;
408+
408409
if(fs.index==-1)
409410
{
410411
INVARIANT(
@@ -421,11 +422,19 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
421422
// first argument `args[0]` corresponds to index 1
422423
arg=to_struct_expr(args[fs.index-1]);
423424
}
425+
426+
auto result = add_axioms_for_format_specifier(
427+
fresh_symbol,
428+
fs,
429+
to_struct_expr(arg),
430+
index_type,
431+
char_type,
432+
array_pool,
433+
message,
434+
ns);
435+
merge(constraints, std::move(result.second));
436+
intermediary_strings.push_back(result.first);
424437
}
425-
auto result = add_axioms_for_format_specifier(
426-
fresh_symbol, fs, arg, index_type, char_type, array_pool, message, ns);
427-
merge(constraints, std::move(result.second));
428-
intermediary_strings.push_back(result.first);
429438
}
430439
else
431440
{

src/solvers/smt2/smt2_conv.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ exprt smt2_convt::parse_struct(
393393
const struct_typet::componentst &components =
394394
type.components();
395395

396-
struct_exprt result(type);
397-
398-
result.operands().resize(components.size(), nil_exprt());
396+
struct_exprt result(exprt::operandst(components.size(), nil_exprt()), type);
399397

400398
if(components.empty())
401399
return std::move(result);

src/util/expr_initializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
188188
const struct_typet::componentst &components=
189189
to_struct_type(type).components();
190190

191-
struct_exprt value(type);
191+
struct_exprt value({}, type);
192192

193193
value.operands().reserve(components.size());
194194

src/util/simplify_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ exprt simplify_exprt::bits2expr(
14921492
const struct_typet::componentst &components=
14931493
struct_type.components();
14941494

1495-
struct_exprt result(type);
1495+
struct_exprt result({}, type);
14961496
result.reserve_operands(components.size());
14971497

14981498
mp_integer m_offset_bits=0;

src/util/std_expr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,11 @@ class struct_exprt : public multi_ary_exprt
19591959
{
19601960
}
19611961

1962+
struct_exprt(operandst &&_operands, const typet &_type)
1963+
: multi_ary_exprt(ID_struct, std::move(_operands), _type)
1964+
{
1965+
}
1966+
19621967
exprt &component(const irep_idt &name, const namespacet &ns);
19631968
const exprt &component(const irep_idt &name, const namespacet &ns) const;
19641969
};

src/util/string_expr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ class refined_string_exprt : public struct_exprt
123123
const exprt &_length,
124124
const exprt &_content,
125125
const typet &type)
126-
: struct_exprt(type)
126+
: struct_exprt({_length, _content}, type)
127127
{
128-
add_to_operands(_length, _content);
129128
}
130129

131130
refined_string_exprt(const exprt &_length, const exprt &_content)

unit/pointer-analysis/value_set.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ SCENARIO(
211211

212212
WHEN("We query what '{ .x = &a2, .y = &a3 }.x' points to")
213213
{
214-
struct_exprt struct_constant(struct_tag_typet(A_symbol.name));
215-
struct_constant.copy_to_operands(
216-
address_of_exprt(a2_symbol.symbol_expr()));
217-
struct_constant.copy_to_operands(
218-
address_of_exprt(a3_symbol.symbol_expr()));
214+
struct_exprt struct_constant(
215+
{address_of_exprt(a2_symbol.symbol_expr()),
216+
address_of_exprt(a3_symbol.symbol_expr())},
217+
struct_tag_typet(A_symbol.name));
219218

220219
member_exprt member_of_constant(struct_constant, A_x);
221220

0 commit comments

Comments
 (0)