Skip to content

Commit 028a80d

Browse files
committed
Replace all uses of deprecated symbol_exprt constructors
This helps type safety has it avoids constructing symbol_exprts that never get a proper type (or identifier).
1 parent 9129e09 commit 028a80d

38 files changed

+136
-151
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15361536
else if(statement=="getstatic")
15371537
{
15381538
PRECONDITION(op.empty() && results.size() == 1);
1539-
symbol_exprt symbol_expr(arg0.type());
15401539
const auto &field_name=arg0.get_string(ID_component_name);
15411540
const bool is_assertions_disabled_field=
15421541
field_name.find("$assertionsDisabled")!=std::string::npos;
15431542

1544-
symbol_expr.set_identifier(
1545-
get_static_field(arg0.get_string(ID_class), field_name));
1543+
const symbol_exprt symbol_expr(
1544+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15461545

15471546
INVARIANT(
15481547
symbol_table.has_symbol(symbol_expr.get_identifier()),
@@ -1559,10 +1558,10 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15591558
else if(statement=="putstatic")
15601559
{
15611560
PRECONDITION(op.size() == 1 && results.empty());
1562-
symbol_exprt symbol_expr(arg0.type());
15631561
const auto &field_name=arg0.get_string(ID_component_name);
1564-
symbol_expr.set_identifier(
1565-
get_static_field(arg0.get_string(ID_class), field_name));
1562+
1563+
const symbol_exprt symbol_expr(
1564+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15661565

15671566
INVARIANT(
15681567
symbol_table.has_symbol(symbol_expr.get_identifier()),

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class java_bytecode_convert_methodt:public messaget
119119
bool is_parameter;
120120
std::vector<holet> holes;
121121

122-
variablet() : symbol_expr(), start_pc(0), length(0), is_parameter(false)
122+
variablet()
123+
: symbol_expr("", typet()),
124+
start_pc(0),
125+
length(0),
126+
is_parameter(false)
123127
{
124128
}
125129
};

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ exprt java_bytecode_parsert::get_relement_value()
16001600
case 'c':
16011601
{
16021602
u2 class_info_index = read_u2();
1603-
return symbol_exprt(pool_entry(class_info_index).s);
1603+
return symbol_exprt(pool_entry(class_info_index).s, typet());
16041604
}
16051605

16061606
case '@':

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,14 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
15551555
loc);
15561556

15571557
// > class1 = Class.forName(string1)
1558+
java_method_typet fun_type(
1559+
{java_method_typet::parametert(string_ptr_type)}, class_type);
15581560
code_function_callt fun_call(
15591561
class1,
15601562
symbol_exprt(
1561-
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;"),
1563+
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;",
1564+
std::move(fun_type)),
15621565
{string1});
1563-
const java_method_typet fun_type(
1564-
{java_method_typet::parametert(string_ptr_type)}, class_type);
1565-
fun_call.function().type()=fun_type;
15661566
code.add(fun_call, loc);
15671567

15681568
// > return class1;

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ exprt make_function_application(
285285
declare_function(fun_name, type, symbol_table);
286286

287287
// Function application
288-
return function_application_exprt(symbol_exprt(fun_name), arguments, type);
288+
return function_application_exprt(
289+
symbol_exprt(fun_name, typet()), arguments, type);
289290
}
290291

291292
/// Strip java:: prefix from given identifier

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ SCENARIO("instantiate_not_contains",
185185
{
186186
// Creating "ab".lastIndexOf("b", 0)
187187
const function_application_exprt func(
188-
symbol_exprt(ID_cprover_string_last_index_of_func),
188+
symbol_exprt(ID_cprover_string_last_index_of_func, typet()),
189189
{ab, b, from_integer(2)},
190190
t.length_type());
191191

@@ -215,7 +215,7 @@ SCENARIO("instantiate_not_contains",
215215
simplify(sc.premise, empty_ns);
216216
simplify(sc.s0, empty_ns);
217217
simplify(sc.s1, empty_ns);
218-
witnesses[sc] = generator.fresh_symbol("w", t.witness_type());
218+
witnesses.emplace(sc, generator.fresh_symbol("w", t.witness_type()));
219219
nc_axioms.push_back(sc);
220220
return accu + to_string(sc) + "\n\n";
221221
});
@@ -287,7 +287,7 @@ SCENARIO("instantiate_not_contains",
287287
// Create witness for axiom
288288
string_constraint_generatort generator(empty_ns);
289289
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
290-
witnesses[vacuous] = generator.fresh_symbol("w", t.witness_type());
290+
witnesses.emplace(vacuous, generator.fresh_symbol("w", t.witness_type()));
291291

292292
INFO("Original axiom:\n");
293293
INFO(to_string(vacuous) + "\n\n");
@@ -337,7 +337,7 @@ SCENARIO("instantiate_not_contains",
337337
// Create witness for axiom
338338
string_constraint_generatort generator(empty_ns);
339339
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
340-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
340+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
341341

342342
INFO("Original axiom:\n");
343343
INFO(to_string(trivial) + "\n\n");
@@ -388,7 +388,7 @@ SCENARIO("instantiate_not_contains",
388388
// Create witness for axiom
389389
string_constraint_generatort generator(empty_ns);
390390
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
391-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
391+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
392392

393393
INFO("Original axiom:\n");
394394
INFO(to_string(trivial) + "\n\n");
@@ -441,7 +441,7 @@ SCENARIO("instantiate_not_contains",
441441
// Create witness for axiom
442442
string_constraint_generatort generator(empty_ns);
443443
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
444-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
444+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
445445

446446
INFO("Original axiom:\n");
447447
INFO(to_string(trivial) + "\n\n");
@@ -492,7 +492,7 @@ SCENARIO("instantiate_not_contains",
492492
// Create witness for axiom
493493
string_constraint_generatort generator(empty_ns);
494494
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
495-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
495+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
496496

497497
INFO("Original axiom:\n");
498498
INFO(to_string(trivial) + "\n\n");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ SCENARIO("dependency_graph", "[core][solvers][refinement][string_refinement]")
6565

6666
// fun1 is s3 = s1.concat(s2)
6767
const function_application_exprt fun1(
68-
symbol_exprt(ID_cprover_string_concat_func),
68+
symbol_exprt(ID_cprover_string_concat_func, typet()),
6969
{string3.op0(), string3.op1(), string1, string2},
7070
fun_type);
7171

7272
// fun2 is s5 = s3.concat(s4)
7373
const function_application_exprt fun2(
74-
symbol_exprt(ID_cprover_string_concat_func),
74+
symbol_exprt(ID_cprover_string_concat_func, typet()),
7575
{string5.op0(), string5.op1(), string3, string4},
7676
fun_type);
7777

7878
// fun3 is s6 = s5.concat(s2)
7979
const function_application_exprt fun3(
80-
symbol_exprt(ID_cprover_string_concat_func),
80+
symbol_exprt(ID_cprover_string_concat_func, typet()),
8181
{string6.op0(), string6.op1(), string5, string2},
8282
fun_type);
8383

src/analyses/constant_propagator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ bool constant_propagator_domaint::partial_evaluate(
649649
// if the current rounding mode is top we can
650650
// still get a non-top result by trying all rounding
651651
// modes and checking if the results are all the same
652-
if(!known_values.is_constant(symbol_exprt(ID_cprover_rounding_mode_str)))
652+
if(!known_values.is_constant(
653+
symbol_exprt(ID_cprover_rounding_mode_str, typet())))
653654
{
654655
return partial_evaluate_with_all_rounding_modes(known_values, expr, ns);
655656
}

src/analyses/locals.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ void localst::build(const goto_functiont &goto_function)
2121
if(it->is_decl())
2222
{
2323
const code_declt &code_decl=to_code_decl(it->code);
24-
locals_map[code_decl.get_identifier()] = code_decl.symbol();
24+
locals_map.emplace(code_decl.get_identifier(), code_decl.symbol());
2525
}
2626

2727
for(const auto &param : goto_function.type.parameters())
28-
locals_map[param.get_identifier()]=
29-
symbol_exprt(param.get_identifier(), param.type());
28+
locals_map.emplace(
29+
param.get_identifier(),
30+
symbol_exprt(param.get_identifier(), param.type()));
3031
}
3132

3233
void localst::output(std::ostream &out) const

src/ansi-c/c_typecheck_base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ void c_typecheck_baset::typecheck_declaration(
697697
// also cater for renaming/placement in sections
698698
const auto &renaming_entry = asm_label_map.find(full_spec.alias);
699699
if(renaming_entry == asm_label_map.end())
700-
symbol.value = symbol_exprt(full_spec.alias);
700+
symbol.value = symbol_exprt(full_spec.alias, typet());
701701
else
702-
symbol.value = symbol_exprt(renaming_entry->second);
702+
symbol.value = symbol_exprt(renaming_entry->second, typet());
703703
symbol.is_macro=true;
704704
}
705705

src/ansi-c/c_typecheck_type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,7 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
635635
symbol_table.add(new_symbol);
636636

637637
// produce the code that declares and initializes the symbol
638-
symbol_exprt symbol_expr;
639-
symbol_expr.set_identifier(temp_identifier);
640-
symbol_expr.type()=new_symbol.type;
638+
symbol_exprt symbol_expr(temp_identifier, new_symbol.type);
641639

642640
code_declt declaration(symbol_expr);
643641
declaration.add_source_location() = size_source_location;

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
743743
}
744744
else
745745
{
746-
symbol_exprt symexpr;
747-
symexpr.set_identifier(new_symbol->name);
746+
symbol_exprt symexpr(new_symbol->name, typet());
748747

749748
exprt::operandst ops;
750749
ops.push_back(value);

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,13 +1448,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14481448
throw 0;
14491449
}
14501450

1451-
symbol_exprt result;
1452-
result.add_source_location()=source_location;
1453-
result.set_identifier(identifier);
14541451
code_typet t(
14551452
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
14561453
t.make_ellipsis();
1457-
result.type()=t;
1454+
symbol_exprt result(identifier, t);
1455+
result.add_source_location() = source_location;
14581456
expr.swap(result);
14591457
return;
14601458
}
@@ -1481,14 +1479,12 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14811479
throw 0;
14821480
}
14831481

1484-
symbol_exprt result;
1485-
result.add_source_location()=source_location;
1486-
result.set_identifier(identifier);
14871482
const code_typet t(
14881483
{code_typet::parametert(ptr_arg.type()),
14891484
code_typet::parametert(signed_int_type())},
14901485
ptr_arg.type().subtype());
1491-
result.type()=t;
1486+
symbol_exprt result(identifier, t);
1487+
result.add_source_location() = source_location;
14921488
expr.swap(result);
14931489
return;
14941490
}
@@ -1515,15 +1511,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15151511
throw 0;
15161512
}
15171513

1518-
symbol_exprt result;
1519-
result.add_source_location()=source_location;
1520-
result.set_identifier(identifier);
15211514
const code_typet t(
15221515
{code_typet::parametert(ptr_arg.type()),
15231516
code_typet::parametert(ptr_arg.type().subtype()),
15241517
code_typet::parametert(signed_int_type())},
15251518
empty_typet());
1526-
result.type()=t;
1519+
symbol_exprt result(identifier, t);
1520+
result.add_source_location() = source_location;
15271521
expr.swap(result);
15281522
return;
15291523
}
@@ -1550,15 +1544,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15501544
throw 0;
15511545
}
15521546

1553-
symbol_exprt result;
1554-
result.add_source_location()=source_location;
1555-
result.set_identifier(identifier);
15561547
const code_typet t(
15571548
{code_typet::parametert(ptr_arg.type()),
15581549
code_typet::parametert(ptr_arg.type().subtype()),
15591550
code_typet::parametert(signed_int_type())},
15601551
ptr_arg.type().subtype());
1561-
result.type()=t;
1552+
symbol_exprt result(identifier, t);
1553+
result.add_source_location() = source_location;
15621554
expr.swap(result);
15631555
return;
15641556
}
@@ -1593,15 +1585,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15931585

15941586
const exprt &ptr_arg=fargs.operands.front();
15951587

1596-
symbol_exprt result;
1597-
result.add_source_location()=source_location;
1598-
result.set_identifier(identifier);
15991588
const code_typet t(
16001589
{code_typet::parametert(ptr_arg.type()),
16011590
code_typet::parametert(ptr_arg.type()),
16021591
code_typet::parametert(signed_int_type())},
16031592
empty_typet());
1604-
result.type()=t;
1593+
symbol_exprt result(identifier, t);
1594+
result.add_source_location() = source_location;
16051595
expr.swap(result);
16061596
return;
16071597
}
@@ -1642,16 +1632,14 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
16421632

16431633
const exprt &ptr_arg=fargs.operands.front();
16441634

1645-
symbol_exprt result;
1646-
result.add_source_location()=source_location;
1647-
result.set_identifier(identifier);
16481635
const code_typet t(
16491636
{code_typet::parametert(ptr_arg.type()),
16501637
code_typet::parametert(ptr_arg.type()),
16511638
code_typet::parametert(ptr_arg.type()),
16521639
code_typet::parametert(signed_int_type())},
16531640
empty_typet());
1654-
result.type()=t;
1641+
symbol_exprt result(identifier, t);
1642+
result.add_source_location() = source_location;
16551643
expr.swap(result);
16561644
return;
16571645
}
@@ -1697,9 +1685,6 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
16971685

16981686
const exprt &ptr_arg=fargs.operands.front();
16991687

1700-
symbol_exprt result;
1701-
result.add_source_location()=source_location;
1702-
result.set_identifier(identifier);
17031688
code_typet::parameterst parameters;
17041689
parameters.push_back(code_typet::parametert(ptr_arg.type()));
17051690
parameters.push_back(code_typet::parametert(ptr_arg.type()));
@@ -1713,7 +1698,8 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17131698
parameters.push_back(code_typet::parametert(signed_int_type()));
17141699
parameters.push_back(code_typet::parametert(signed_int_type()));
17151700
code_typet t(std::move(parameters), c_bool_type());
1716-
result.type()=t;
1701+
symbol_exprt result(identifier, t);
1702+
result.add_source_location() = source_location;
17171703
expr.swap(result);
17181704
return;
17191705
}
@@ -1742,13 +1728,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17421728
throw 0;
17431729
}
17441730

1745-
symbol_exprt result;
1746-
result.add_source_location()=source_location;
1747-
result.set_identifier(identifier);
17481731
code_typet t(
17491732
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
17501733
t.make_ellipsis();
1751-
result.type()=t;
1734+
symbol_exprt result(identifier, t);
1735+
result.add_source_location() = source_location;
17521736
expr.swap(result);
17531737
return;
17541738
}
@@ -1777,13 +1761,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17771761
throw 0;
17781762
}
17791763

1780-
symbol_exprt result;
1781-
result.add_source_location()=source_location;
1782-
result.set_identifier(identifier);
17831764
code_typet t(
17841765
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
17851766
t.make_ellipsis();
1786-
result.type()=t;
1767+
symbol_exprt result(identifier, t);
1768+
result.add_source_location() = source_location;
17871769
expr.swap(result);
17881770
return;
17891771
}

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ bool cpp_typecheck_resolvet::disambiguate_functions(
21332133
{
21342134
// it's a constructor
21352135
const typet &object_type=parameter.type().subtype();
2136-
symbol_exprt object(object_type);
2136+
symbol_exprt object("", object_type);
21372137
object.set(ID_C_lvalue, true);
21382138

21392139
cpp_typecheck_fargst new_fargs(fargs);

0 commit comments

Comments
 (0)