Skip to content

Commit 697a744

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 8300e2d commit 697a744

21 files changed

+141
-145
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

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

490486
// The variables is a expanding_vectort, and the loop above may have expanded
491487
// the vector introducing gaps where the entries are empty vectors. We now
492488
// make sure that the vector of each LV slot contains exactly one variablet,
493-
// possibly default-initialized
489+
// which we will add below
494490
std::size_t param_index=0;
495491
for(const auto &param : parameters)
496492
{
497-
variables[param_index].resize(1);
493+
INVARIANT(
494+
variables[param_index].size() <= 1,
495+
"should have at most one entry per index");
498496
param_index+=java_local_variable_slots(param.type());
499497
}
500498
INVARIANT(
@@ -518,23 +516,20 @@ void java_bytecode_convert_methodt::convert(
518516
base_name = ID_this;
519517
identifier=id2string(method_identifier)+"::"+id2string(base_name);
520518
}
521-
else
519+
else if(!variables[param_index].empty())
522520
{
523521
// if already present in the LVT ...
524522
base_name=variables[param_index][0].symbol_expr.get(ID_C_base_name);
525523
identifier=variables[param_index][0].symbol_expr.get(ID_identifier);
526-
527-
// ... then base_name will not be empty
528-
if(base_name.empty())
529-
{
530-
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
531-
// variable slot where the parameter is stored and T is a character
532-
// indicating the type
533-
const typet &type=param.type();
534-
char suffix=java_char_from_type(type);
535-
base_name="arg"+std::to_string(param_index)+suffix;
536-
identifier=id2string(method_identifier)+"::"+id2string(base_name);
537-
}
524+
}
525+
else
526+
{
527+
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
528+
// variable slot where the parameter is stored and T is a character
529+
// indicating the type
530+
char suffix = java_char_from_type(param.type());
531+
base_name = "arg" + std::to_string(param_index) + suffix;
532+
identifier = id2string(method_identifier) + "::" + id2string(base_name);
538533
}
539534
param.set_base_name(base_name);
540535
param.set_identifier(identifier);
@@ -548,10 +543,12 @@ void java_bytecode_convert_methodt::convert(
548543
symbol_table.add(parameter_symbol);
549544

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

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

1543-
symbol_expr.set_identifier(
1544-
get_static_field(arg0.get_string(ID_class), field_name));
1536+
const symbol_exprt symbol_expr(
1537+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15451538

15461539
INVARIANT(
15471540
symbol_table.has_symbol(symbol_expr.get_identifier()),
@@ -1558,10 +1551,10 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15581551
else if(statement=="putstatic")
15591552
{
15601553
PRECONDITION(op.size() == 1 && results.empty());
1561-
symbol_exprt symbol_expr(arg0.type());
15621554
const auto &field_name=arg0.get_string(ID_component_name);
1563-
symbol_expr.set_identifier(
1564-
get_static_field(arg0.get_string(ID_class), field_name));
1555+
1556+
const symbol_exprt symbol_expr(
1557+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15651558

15661559
INVARIANT(
15671560
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)