Skip to content

Commit 7c9aaff

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 adb3d7b commit 7c9aaff

21 files changed

+128
-132
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -481,21 +481,17 @@ void java_bytecode_convert_methodt::convert(
481481
// be rewritten below in the loop that iterates through the method
482482
// parameters; the only field that seem to be useful to write here is the
483483
// symbol_expr, others will be rewritten
484-
variables[v.index].push_back(variablet());
485-
auto &newv=variables[v.index].back();
486-
newv.symbol_expr=result;
487-
newv.start_pc=v.start_pc;
488-
newv.length=v.length;
484+
variables[v.index].emplace_back(result, v.start_pc, v.length);
489485
}
490486

491487
// The variables is a expanding_vectort, and the loop above may have expanded
492488
// the vector introducing gaps where the entries are empty vectors. We now
493489
// make sure that the vector of each LV slot contains exactly one variablet,
494-
// possibly default-initialized
490+
// which we will add below
495491
std::size_t param_index=0;
496492
for(const auto &param : parameters)
497493
{
498-
variables[param_index].resize(1);
494+
variables[param_index].clear();
499495
param_index+=java_local_variable_slots(param.type());
500496
}
501497
INVARIANT(
@@ -549,10 +545,11 @@ void java_bytecode_convert_methodt::convert(
549545
symbol_table.add(parameter_symbol);
550546

551547
// Add as a JVM local variable
552-
variables[param_index][0].symbol_expr=parameter_symbol.symbol_expr();
553-
variables[param_index][0].is_parameter=true;
554-
variables[param_index][0].start_pc=0;
555-
variables[param_index][0].length=std::numeric_limits<size_t>::max();
548+
variables[param_index].emplace_back(
549+
parameter_symbol.symbol_expr(),
550+
0,
551+
std::numeric_limits<size_t>::max(),
552+
true);
556553
param_index+=java_local_variable_slots(param.type());
557554
}
558555

@@ -921,17 +918,14 @@ static void gather_symbol_live_ranges(
921918
if(e.id()==ID_symbol)
922919
{
923920
const auto &symexpr=to_symbol_expr(e);
924-
auto findit = result.insert(
925-
{symexpr.get_identifier(), java_bytecode_convert_methodt::variablet()});
926-
auto &var=findit.first->second;
927-
if(findit.second)
928-
{
929-
var.symbol_expr=symexpr;
930-
var.start_pc=pc;
931-
var.length=1;
932-
}
933-
else
921+
auto findit = result.emplace(
922+
std::piecewise_construct,
923+
std::forward_as_tuple(symexpr.get_identifier()),
924+
std::forward_as_tuple(symexpr, pc, 1));
925+
if(!findit.second)
934926
{
927+
auto &var = findit.first->second;
928+
935929
if(pc<var.start_pc)
936930
{
937931
var.length+=(var.start_pc-pc);
@@ -1536,13 +1530,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15361530
else if(statement=="getstatic")
15371531
{
15381532
PRECONDITION(op.empty() && results.size() == 1);
1539-
symbol_exprt symbol_expr(arg0.type());
15401533
const auto &field_name=arg0.get_string(ID_component_name);
15411534
const bool is_assertions_disabled_field=
15421535
field_name.find("$assertionsDisabled")!=std::string::npos;
15431536

1544-
symbol_expr.set_identifier(
1545-
get_static_field(arg0.get_string(ID_class), field_name));
1537+
const symbol_exprt symbol_expr(
1538+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15461539

15471540
INVARIANT(
15481541
symbol_table.has_symbol(symbol_expr.get_identifier()),
@@ -1559,10 +1552,10 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15591552
else if(statement=="putstatic")
15601553
{
15611554
PRECONDITION(op.size() == 1 && results.empty());
1562-
symbol_exprt symbol_expr(arg0.type());
15631555
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));
1556+
1557+
const symbol_exprt symbol_expr(
1558+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15661559

15671560
INVARIANT(
15681561
symbol_table.has_symbol(symbol_expr.get_identifier()),

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,40 @@ class java_bytecode_convert_methodt:public messaget
116116
symbol_exprt symbol_expr;
117117
size_t start_pc;
118118
size_t length;
119-
bool is_parameter;
119+
bool is_parameter = false;
120120
std::vector<holet> holes;
121121

122-
variablet() : symbol_expr(), start_pc(0), length(0), is_parameter(false)
122+
variablet(
123+
const symbol_exprt &_symbol_expr,
124+
std::size_t _start_pc,
125+
std::size_t _length)
126+
: symbol_expr(_symbol_expr), start_pc(_start_pc), length(_length)
127+
{
128+
}
129+
130+
variablet(
131+
const symbol_exprt &_symbol_expr,
132+
std::size_t _start_pc,
133+
std::size_t _length,
134+
bool _is_parameter)
135+
: symbol_expr(_symbol_expr),
136+
start_pc(_start_pc),
137+
length(_length),
138+
is_parameter(_is_parameter)
139+
{
140+
}
141+
142+
variablet(
143+
const symbol_exprt &_symbol_expr,
144+
std::size_t _start_pc,
145+
std::size_t _length,
146+
bool _is_parameter,
147+
std::vector<holet> &&_holes)
148+
: symbol_expr(_symbol_expr),
149+
start_pc(_start_pc),
150+
length(_length),
151+
is_parameter(_is_parameter),
152+
holes(std::move(_holes))
123153
{
124154
}
125155
};

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ void java_bytecode_convert_methodt::setup_local_variables(
773773
// to calculate which variable to use, one uses the address of the instruction
774774
// that uses the variable, the size of the instruction and the start_pc /
775775
// length values in the local variable table
776-
for(const auto &v : vars_with_holes)
776+
for(auto &v : vars_with_holes)
777777
{
778778
if(v.is_parameter)
779779
continue;
@@ -807,12 +807,8 @@ void java_bytecode_convert_methodt::setup_local_variables(
807807
// Create a new local variable in the variables[] array, the result of
808808
// merging multiple local variables with equal name (parameters excluded)
809809
// into a single local variable with holes
810-
variables[v.var.index].push_back(variablet());
811-
auto &newv=variables[v.var.index].back();
812-
newv.symbol_expr=result;
813-
newv.start_pc=v.var.start_pc;
814-
newv.length=v.var.length;
815-
newv.holes=std::move(v.holes);
810+
variables[v.var.index].emplace_back(
811+
result, v.var.start_pc, v.var.length, false, std::move(v.holes));
816812

817813
// Register the local variable in the symbol table
818814
symbolt new_symbol;
@@ -862,9 +858,7 @@ java_bytecode_convert_methodt::find_variable_for_slot(
862858
// with scope from 0 to SIZE_T_MAX
863859
// as it is at the end of the vector, it will only be taken into account
864860
// if no other variable is valid
865-
size_t list_length=var_list.size();
866-
var_list.resize(list_length+1);
867-
var_list[list_length].start_pc=0;
868-
var_list[list_length].length=std::numeric_limits<size_t>::max();
869-
return var_list[list_length];
861+
var_list.emplace_back(
862+
symbol_exprt(irep_idt(), typet()), 0, std::numeric_limits<size_t>::max());
863+
return var_list.back();
870864
}

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

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

15611561
// > class1 = Class.forName(string1)
1562+
java_method_typet fun_type(
1563+
{java_method_typet::parametert(string_ptr_type)}, class_type);
15621564
code_function_callt fun_call(
15631565
class1,
15641566
symbol_exprt(
1565-
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;"),
1567+
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;",
1568+
std::move(fun_type)),
15661569
{string1});
1567-
const java_method_typet fun_type(
1568-
{java_method_typet::parametert(string_ptr_type)}, class_type);
1569-
fun_call.function().type()=fun_type;
15701570
code.add(fun_call, loc);
15711571

15721572
// > return class1;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ SCENARIO(
224224
simplify(sc.premise, empty_ns);
225225
simplify(sc.s0, empty_ns);
226226
simplify(sc.s1, empty_ns);
227-
witnesses[sc] = generator.fresh_symbol("w", t.witness_type());
227+
witnesses.emplace(sc, generator.fresh_symbol("w", t.witness_type()));
228228
nc_axioms.push_back(sc);
229229
return accu + to_string(sc) + "\n\n";
230230
});
@@ -296,7 +296,7 @@ SCENARIO(
296296
// Create witness for axiom
297297
string_constraint_generatort generator(empty_ns);
298298
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
299-
witnesses[vacuous] = generator.fresh_symbol("w", t.witness_type());
299+
witnesses.emplace(vacuous, generator.fresh_symbol("w", t.witness_type()));
300300

301301
INFO("Original axiom:\n");
302302
INFO(to_string(vacuous) + "\n\n");
@@ -346,7 +346,7 @@ SCENARIO(
346346
// Create witness for axiom
347347
string_constraint_generatort generator(empty_ns);
348348
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
349-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
349+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
350350

351351
INFO("Original axiom:\n");
352352
INFO(to_string(trivial) + "\n\n");
@@ -397,7 +397,7 @@ SCENARIO(
397397
// Create witness for axiom
398398
string_constraint_generatort generator(empty_ns);
399399
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
400-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
400+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
401401

402402
INFO("Original axiom:\n");
403403
INFO(to_string(trivial) + "\n\n");
@@ -450,7 +450,7 @@ SCENARIO(
450450
// Create witness for axiom
451451
string_constraint_generatort generator(empty_ns);
452452
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
453-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
453+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
454454

455455
INFO("Original axiom:\n");
456456
INFO(to_string(trivial) + "\n\n");
@@ -501,7 +501,7 @@ SCENARIO(
501501
// Create witness for axiom
502502
string_constraint_generatort generator(empty_ns);
503503
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
504-
witnesses[trivial] = generator.fresh_symbol("w", t.witness_type());
504+
witnesses.emplace(trivial, generator.fresh_symbol("w", t.witness_type()));
505505

506506
INFO("Original axiom:\n");
507507
INFO(to_string(trivial) + "\n\n");

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_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;

0 commit comments

Comments
 (0)