Skip to content

Replace all uses of deprecated symbol_exprt constructors [blocks: #3768] #3766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 33 additions & 40 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,19 @@ void java_bytecode_convert_methodt::convert(
// be rewritten below in the loop that iterates through the method
// parameters; the only field that seem to be useful to write here is the
// symbol_expr, others will be rewritten
variables[v.index].push_back(variablet());
auto &newv=variables[v.index].back();
newv.symbol_expr=result;
newv.start_pc=v.start_pc;
newv.length=v.length;
variables[v.index].emplace_back(result, v.start_pc, v.length);
}

// The variables is a expanding_vectort, and the loop above may have expanded
// the vector introducing gaps where the entries are empty vectors. We now
// make sure that the vector of each LV slot contains exactly one variablet,
// possibly default-initialized
// which we will add below
std::size_t param_index=0;
for(const auto &param : parameters)
{
variables[param_index].resize(1);
INVARIANT(
variables[param_index].size() <= 1,
"should have at most one entry per index");
param_index+=java_local_variable_slots(param.type());
}
INVARIANT(
Expand All @@ -522,23 +520,20 @@ void java_bytecode_convert_methodt::convert(
base_name = ID_this;
identifier=id2string(method_identifier)+"::"+id2string(base_name);
}
else
else if(!variables[param_index].empty())
{
// if already present in the LVT ...
base_name=variables[param_index][0].symbol_expr.get(ID_C_base_name);
identifier=variables[param_index][0].symbol_expr.get(ID_identifier);

// ... then base_name will not be empty
if(base_name.empty())
{
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
// variable slot where the parameter is stored and T is a character
// indicating the type
const typet &type=param.type();
char suffix=java_char_from_type(type);
base_name="arg"+std::to_string(param_index)+suffix;
identifier=id2string(method_identifier)+"::"+id2string(base_name);
}
}
else
{
// my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
// variable slot where the parameter is stored and T is a character
// indicating the type
char suffix = java_char_from_type(param.type());
base_name = "arg" + std::to_string(param_index) + suffix;
identifier = id2string(method_identifier) + "::" + id2string(base_name);
}
param.set_base_name(base_name);
param.set_identifier(identifier);
Expand All @@ -552,10 +547,12 @@ void java_bytecode_convert_methodt::convert(
symbol_table.add(parameter_symbol);

// Add as a JVM local variable
variables[param_index][0].symbol_expr=parameter_symbol.symbol_expr();
variables[param_index][0].is_parameter=true;
variables[param_index][0].start_pc=0;
variables[param_index][0].length=std::numeric_limits<size_t>::max();
variables[param_index].clear();
variables[param_index].emplace_back(
parameter_symbol.symbol_expr(),
0,
std::numeric_limits<size_t>::max(),
true);
param_index+=java_local_variable_slots(param.type());
}

Expand Down Expand Up @@ -952,17 +949,14 @@ static void gather_symbol_live_ranges(
if(e.id()==ID_symbol)
{
const auto &symexpr=to_symbol_expr(e);
auto findit = result.insert(
{symexpr.get_identifier(), java_bytecode_convert_methodt::variablet()});
auto &var=findit.first->second;
if(findit.second)
{
var.symbol_expr=symexpr;
var.start_pc=pc;
var.length=1;
}
else
auto findit = result.emplace(
std::piecewise_construct,
std::forward_as_tuple(symexpr.get_identifier()),
std::forward_as_tuple(symexpr, pc, 1));
if(!findit.second)
{
auto &var = findit.first->second;

if(pc<var.start_pc)
{
var.length+=(var.start_pc-pc);
Expand Down Expand Up @@ -1564,13 +1558,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
else if(statement=="getstatic")
{
PRECONDITION(op.empty() && results.size() == 1);
symbol_exprt symbol_expr(arg0.type());
const auto &field_name=arg0.get_string(ID_component_name);
const bool is_assertions_disabled_field=
field_name.find("$assertionsDisabled")!=std::string::npos;

symbol_expr.set_identifier(
get_static_field(arg0.get_string(ID_class), field_name));
const symbol_exprt symbol_expr(
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());

INVARIANT(
symbol_table.has_symbol(symbol_expr.get_identifier()),
Expand All @@ -1587,10 +1580,10 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
else if(statement=="putstatic")
{
PRECONDITION(op.size() == 1 && results.empty());
symbol_exprt symbol_expr(arg0.type());
const auto &field_name=arg0.get_string(ID_component_name);
symbol_expr.set_identifier(
get_static_field(arg0.get_string(ID_class), field_name));

const symbol_exprt symbol_expr(
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());

INVARIANT(
symbol_table.has_symbol(symbol_expr.get_identifier()),
Expand Down
34 changes: 32 additions & 2 deletions jbmc/src/java_bytecode/java_bytecode_convert_method_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,40 @@ class java_bytecode_convert_methodt:public messaget
symbol_exprt symbol_expr;
size_t start_pc;
size_t length;
bool is_parameter;
bool is_parameter = false;
std::vector<holet> holes;

variablet() : symbol_expr(), start_pc(0), length(0), is_parameter(false)
variablet(
const symbol_exprt &_symbol_expr,
std::size_t _start_pc,
std::size_t _length)
: symbol_expr(_symbol_expr), start_pc(_start_pc), length(_length)
{
}

variablet(
const symbol_exprt &_symbol_expr,
std::size_t _start_pc,
std::size_t _length,
bool _is_parameter)
: symbol_expr(_symbol_expr),
start_pc(_start_pc),
length(_length),
is_parameter(_is_parameter)
{
}

variablet(
const symbol_exprt &_symbol_expr,
std::size_t _start_pc,
std::size_t _length,
bool _is_parameter,
std::vector<holet> &&_holes)
: symbol_expr(_symbol_expr),
start_pc(_start_pc),
length(_length),
is_parameter(_is_parameter),
holes(std::move(_holes))
{
}
};
Expand Down
18 changes: 6 additions & 12 deletions jbmc/src/java_bytecode/java_local_variable_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void java_bytecode_convert_methodt::setup_local_variables(
// to calculate which variable to use, one uses the address of the instruction
// that uses the variable, the size of the instruction and the start_pc /
// length values in the local variable table
for(const auto &v : vars_with_holes)
for(auto &v : vars_with_holes)
{
if(v.is_parameter)
continue;
Expand Down Expand Up @@ -807,12 +807,8 @@ void java_bytecode_convert_methodt::setup_local_variables(
// Create a new local variable in the variables[] array, the result of
// merging multiple local variables with equal name (parameters excluded)
// into a single local variable with holes
variables[v.var.index].push_back(variablet());
auto &newv=variables[v.var.index].back();
newv.symbol_expr=result;
newv.start_pc=v.var.start_pc;
newv.length=v.var.length;
newv.holes=std::move(v.holes);
variables[v.var.index].emplace_back(
result, v.var.start_pc, v.var.length, false, std::move(v.holes));

// Register the local variable in the symbol table
symbolt new_symbol;
Expand Down Expand Up @@ -862,9 +858,7 @@ java_bytecode_convert_methodt::find_variable_for_slot(
// with scope from 0 to SIZE_T_MAX
// as it is at the end of the vector, it will only be taken into account
// if no other variable is valid
size_t list_length=var_list.size();
var_list.resize(list_length+1);
var_list[list_length].start_pc=0;
var_list[list_length].length=std::numeric_limits<size_t>::max();
return var_list[list_length];
var_list.emplace_back(
symbol_exprt(irep_idt(), typet()), 0, std::numeric_limits<size_t>::max());
return var_list.back();
}
8 changes: 4 additions & 4 deletions jbmc/src/java_bytecode/java_string_library_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,14 +1559,14 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
loc);

// > class1 = Class.forName(string1)
java_method_typet fun_type(
{java_method_typet::parametert(string_ptr_type)}, class_type);
code_function_callt fun_call(
class1,
symbol_exprt(
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;"),
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;",
std::move(fun_type)),
{string1});
const java_method_typet fun_type(
{java_method_typet::parametert(string_ptr_type)}, class_type);
fun_call.function().type()=fun_type;
code.add(fun_call, loc);

// > return class1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ SCENARIO(
simplify(sc.premise, empty_ns);
simplify(sc.s0, empty_ns);
simplify(sc.s1, empty_ns);
witnesses[sc] = generator.fresh_symbol("w", t.witness_type());
witnesses.emplace(sc, generator.fresh_symbol("w", t.witness_type()));
nc_axioms.push_back(sc);
return accu + to_string(sc) + "\n\n";
});
Expand Down Expand Up @@ -296,7 +296,7 @@ SCENARIO(
// Create witness for axiom
string_constraint_generatort generator(empty_ns);
std::unordered_map<string_not_contains_constraintt, symbol_exprt> witnesses;
witnesses[vacuous] = generator.fresh_symbol("w", t.witness_type());
witnesses.emplace(vacuous, generator.fresh_symbol("w", t.witness_type()));

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

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

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

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

INFO("Original axiom:\n");
INFO(to_string(trivial) + "\n\n");
Expand Down
7 changes: 4 additions & 3 deletions src/analyses/locals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ void localst::build(const goto_functiont &goto_function)
if(it->is_decl())
{
const code_declt &code_decl=to_code_decl(it->code);
locals_map[code_decl.get_identifier()] = code_decl.symbol();
locals_map.emplace(code_decl.get_identifier(), code_decl.symbol());
}

for(const auto &param : goto_function.type.parameters())
locals_map[param.get_identifier()]=
symbol_exprt(param.get_identifier(), param.type());
locals_map.emplace(
param.get_identifier(),
symbol_exprt(param.get_identifier(), param.type()));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


void localst::output(std::ostream &out) const
Expand Down
4 changes: 1 addition & 3 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,7 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
symbol_table.add(new_symbol);

// produce the code that declares and initializes the symbol
symbol_exprt symbol_expr;
symbol_expr.set_identifier(temp_identifier);
symbol_expr.type() = new_symbol.type;
symbol_exprt symbol_expr(temp_identifier, new_symbol.type);

code_declt declaration(symbol_expr);
declaration.add_source_location() = size_source_location;
Expand Down
Loading