Skip to content

Commit 30dafe2

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 6f06664 commit 30dafe2

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
@@ -1560,14 +1560,14 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
15601560
loc);
15611561

15621562
// > class1 = Class.forName(string1)
1563+
java_method_typet fun_type(
1564+
{java_method_typet::parametert(string_ptr_type)}, class_type);
15631565
code_function_callt fun_call(
15641566
class1,
15651567
symbol_exprt(
1566-
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;"),
1568+
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;",
1569+
std::move(fun_type)),
15671570
{string1});
1568-
const java_method_typet fun_type(
1569-
{java_method_typet::parametert(string_ptr_type)}, class_type);
1570-
fun_call.function().type()=fun_type;
15711571
code.add(fun_call, loc);
15721572

15731573
// > 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
@@ -1450,13 +1450,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14501450
throw 0;
14511451
}
14521452

1453-
symbol_exprt result;
1454-
result.add_source_location()=source_location;
1455-
result.set_identifier(identifier);
14561453
code_typet t(
14571454
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
14581455
t.make_ellipsis();
1459-
result.type()=t;
1456+
symbol_exprt result(identifier, t);
1457+
result.add_source_location() = source_location;
14601458
expr.swap(result);
14611459
return;
14621460
}
@@ -1483,14 +1481,12 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
14831481
throw 0;
14841482
}
14851483

1486-
symbol_exprt result;
1487-
result.add_source_location()=source_location;
1488-
result.set_identifier(identifier);
14891484
const code_typet t(
14901485
{code_typet::parametert(ptr_arg.type()),
14911486
code_typet::parametert(signed_int_type())},
14921487
ptr_arg.type().subtype());
1493-
result.type()=t;
1488+
symbol_exprt result(identifier, t);
1489+
result.add_source_location() = source_location;
14941490
expr.swap(result);
14951491
return;
14961492
}
@@ -1517,15 +1513,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15171513
throw 0;
15181514
}
15191515

1520-
symbol_exprt result;
1521-
result.add_source_location()=source_location;
1522-
result.set_identifier(identifier);
15231516
const code_typet t(
15241517
{code_typet::parametert(ptr_arg.type()),
15251518
code_typet::parametert(ptr_arg.type().subtype()),
15261519
code_typet::parametert(signed_int_type())},
15271520
empty_typet());
1528-
result.type()=t;
1521+
symbol_exprt result(identifier, t);
1522+
result.add_source_location() = source_location;
15291523
expr.swap(result);
15301524
return;
15311525
}
@@ -1552,15 +1546,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15521546
throw 0;
15531547
}
15541548

1555-
symbol_exprt result;
1556-
result.add_source_location()=source_location;
1557-
result.set_identifier(identifier);
15581549
const code_typet t(
15591550
{code_typet::parametert(ptr_arg.type()),
15601551
code_typet::parametert(ptr_arg.type().subtype()),
15611552
code_typet::parametert(signed_int_type())},
15621553
ptr_arg.type().subtype());
1563-
result.type()=t;
1554+
symbol_exprt result(identifier, t);
1555+
result.add_source_location() = source_location;
15641556
expr.swap(result);
15651557
return;
15661558
}
@@ -1595,15 +1587,13 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
15951587

15961588
const exprt &ptr_arg=fargs.operands.front();
15971589

1598-
symbol_exprt result;
1599-
result.add_source_location()=source_location;
1600-
result.set_identifier(identifier);
16011590
const code_typet t(
16021591
{code_typet::parametert(ptr_arg.type()),
16031592
code_typet::parametert(ptr_arg.type()),
16041593
code_typet::parametert(signed_int_type())},
16051594
empty_typet());
1606-
result.type()=t;
1595+
symbol_exprt result(identifier, t);
1596+
result.add_source_location() = source_location;
16071597
expr.swap(result);
16081598
return;
16091599
}
@@ -1644,16 +1634,14 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
16441634

16451635
const exprt &ptr_arg=fargs.operands.front();
16461636

1647-
symbol_exprt result;
1648-
result.add_source_location()=source_location;
1649-
result.set_identifier(identifier);
16501637
const code_typet t(
16511638
{code_typet::parametert(ptr_arg.type()),
16521639
code_typet::parametert(ptr_arg.type()),
16531640
code_typet::parametert(ptr_arg.type()),
16541641
code_typet::parametert(signed_int_type())},
16551642
empty_typet());
1656-
result.type()=t;
1643+
symbol_exprt result(identifier, t);
1644+
result.add_source_location() = source_location;
16571645
expr.swap(result);
16581646
return;
16591647
}
@@ -1699,9 +1687,6 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
16991687

17001688
const exprt &ptr_arg=fargs.operands.front();
17011689

1702-
symbol_exprt result;
1703-
result.add_source_location()=source_location;
1704-
result.set_identifier(identifier);
17051690
code_typet::parameterst parameters;
17061691
parameters.push_back(code_typet::parametert(ptr_arg.type()));
17071692
parameters.push_back(code_typet::parametert(ptr_arg.type()));
@@ -1715,7 +1700,8 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17151700
parameters.push_back(code_typet::parametert(signed_int_type()));
17161701
parameters.push_back(code_typet::parametert(signed_int_type()));
17171702
code_typet t(std::move(parameters), c_bool_type());
1718-
result.type()=t;
1703+
symbol_exprt result(identifier, t);
1704+
result.add_source_location() = source_location;
17191705
expr.swap(result);
17201706
return;
17211707
}
@@ -1744,13 +1730,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17441730
throw 0;
17451731
}
17461732

1747-
symbol_exprt result;
1748-
result.add_source_location()=source_location;
1749-
result.set_identifier(identifier);
17501733
code_typet t(
17511734
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
17521735
t.make_ellipsis();
1753-
result.type()=t;
1736+
symbol_exprt result(identifier, t);
1737+
result.add_source_location() = source_location;
17541738
expr.swap(result);
17551739
return;
17561740
}
@@ -1779,13 +1763,11 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
17791763
throw 0;
17801764
}
17811765

1782-
symbol_exprt result;
1783-
result.add_source_location()=source_location;
1784-
result.set_identifier(identifier);
17851766
code_typet t(
17861767
{code_typet::parametert(ptr_arg.type())}, ptr_arg.type().subtype());
17871768
t.make_ellipsis();
1788-
result.type()=t;
1769+
symbol_exprt result(identifier, t);
1770+
result.add_source_location() = source_location;
17891771
expr.swap(result);
17901772
return;
17911773
}

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)