Skip to content

Commit c2e3503

Browse files
authored
Merge pull request #3766 from tautschnig/remove-deprecated-symbol-exprt-constructors
Replace all uses of deprecated symbol_exprt constructors [blocks: #3768]
2 parents 81feeec + 267094c commit c2e3503

21 files changed

+143
-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
@@ -484,21 +484,19 @@ void java_bytecode_convert_methodt::convert(
484484
// be rewritten below in the loop that iterates through the method
485485
// parameters; the only field that seem to be useful to write here is the
486486
// symbol_expr, others will be rewritten
487-
variables[v.index].push_back(variablet());
488-
auto &newv=variables[v.index].back();
489-
newv.symbol_expr=result;
490-
newv.start_pc=v.start_pc;
491-
newv.length=v.length;
487+
variables[v.index].emplace_back(result, v.start_pc, v.length);
492488
}
493489

494490
// The variables is a expanding_vectort, and the loop above may have expanded
495491
// the vector introducing gaps where the entries are empty vectors. We now
496492
// make sure that the vector of each LV slot contains exactly one variablet,
497-
// possibly default-initialized
493+
// which we will add below
498494
std::size_t param_index=0;
499495
for(const auto &param : parameters)
500496
{
501-
variables[param_index].resize(1);
497+
INVARIANT(
498+
variables[param_index].size() <= 1,
499+
"should have at most one entry per index");
502500
param_index+=java_local_variable_slots(param.type());
503501
}
504502
INVARIANT(
@@ -522,23 +520,20 @@ void java_bytecode_convert_methodt::convert(
522520
base_name = ID_this;
523521
identifier=id2string(method_identifier)+"::"+id2string(base_name);
524522
}
525-
else
523+
else if(!variables[param_index].empty())
526524
{
527525
// if already present in the LVT ...
528526
base_name=variables[param_index][0].symbol_expr.get(ID_C_base_name);
529527
identifier=variables[param_index][0].symbol_expr.get(ID_identifier);
530-
531-
// ... then base_name will not be empty
532-
if(base_name.empty())
533-
{
534-
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
535-
// variable slot where the parameter is stored and T is a character
536-
// indicating the type
537-
const typet &type=param.type();
538-
char suffix=java_char_from_type(type);
539-
base_name="arg"+std::to_string(param_index)+suffix;
540-
identifier=id2string(method_identifier)+"::"+id2string(base_name);
541-
}
528+
}
529+
else
530+
{
531+
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
532+
// variable slot where the parameter is stored and T is a character
533+
// indicating the type
534+
char suffix = java_char_from_type(param.type());
535+
base_name = "arg" + std::to_string(param_index) + suffix;
536+
identifier = id2string(method_identifier) + "::" + id2string(base_name);
542537
}
543538
param.set_base_name(base_name);
544539
param.set_identifier(identifier);
@@ -552,10 +547,12 @@ void java_bytecode_convert_methodt::convert(
552547
symbol_table.add(parameter_symbol);
553548

554549
// Add as a JVM local variable
555-
variables[param_index][0].symbol_expr=parameter_symbol.symbol_expr();
556-
variables[param_index][0].is_parameter=true;
557-
variables[param_index][0].start_pc=0;
558-
variables[param_index][0].length=std::numeric_limits<size_t>::max();
550+
variables[param_index].clear();
551+
variables[param_index].emplace_back(
552+
parameter_symbol.symbol_expr(),
553+
0,
554+
std::numeric_limits<size_t>::max(),
555+
true);
559556
param_index+=java_local_variable_slots(param.type());
560557
}
561558

@@ -952,17 +949,14 @@ static void gather_symbol_live_ranges(
952949
if(e.id()==ID_symbol)
953950
{
954951
const auto &symexpr=to_symbol_expr(e);
955-
auto findit = result.insert(
956-
{symexpr.get_identifier(), java_bytecode_convert_methodt::variablet()});
957-
auto &var=findit.first->second;
958-
if(findit.second)
959-
{
960-
var.symbol_expr=symexpr;
961-
var.start_pc=pc;
962-
var.length=1;
963-
}
964-
else
952+
auto findit = result.emplace(
953+
std::piecewise_construct,
954+
std::forward_as_tuple(symexpr.get_identifier()),
955+
std::forward_as_tuple(symexpr, pc, 1));
956+
if(!findit.second)
965957
{
958+
auto &var = findit.first->second;
959+
966960
if(pc<var.start_pc)
967961
{
968962
var.length+=(var.start_pc-pc);
@@ -1565,13 +1559,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15651559
else if(statement=="getstatic")
15661560
{
15671561
PRECONDITION(op.empty() && results.size() == 1);
1568-
symbol_exprt symbol_expr(arg0.type());
15691562
const auto &field_name=arg0.get_string(ID_component_name);
15701563
const bool is_assertions_disabled_field=
15711564
field_name.find("$assertionsDisabled")!=std::string::npos;
15721565

1573-
symbol_expr.set_identifier(
1574-
get_static_field(arg0.get_string(ID_class), field_name));
1566+
const symbol_exprt symbol_expr(
1567+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15751568

15761569
INVARIANT(
15771570
symbol_table.has_symbol(symbol_expr.get_identifier()),
@@ -1588,10 +1581,10 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15881581
else if(statement=="putstatic")
15891582
{
15901583
PRECONDITION(op.size() == 1 && results.empty());
1591-
symbol_exprt symbol_expr(arg0.type());
15921584
const auto &field_name=arg0.get_string(ID_component_name);
1593-
symbol_expr.set_identifier(
1594-
get_static_field(arg0.get_string(ID_class), field_name));
1585+
1586+
const symbol_exprt symbol_expr(
1587+
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
15951588

15961589
INVARIANT(
15971590
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
@@ -118,10 +118,40 @@ class java_bytecode_convert_methodt:public messaget
118118
symbol_exprt symbol_expr;
119119
size_t start_pc;
120120
size_t length;
121-
bool is_parameter;
121+
bool is_parameter = false;
122122
std::vector<holet> holes;
123123

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

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)