Skip to content

Commit 1c9abbd

Browse files
committed
Redo variable naming using scope start addresses, per Peter's suggestion
1 parent 3bb4c60 commit 1c9abbd

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class java_bytecode_convert_methodt:public messaget
135135
if(var.symbol_expr.get_identifier().empty())
136136
{
137137
// an un-named local variable
138-
irep_idt base_name="__anonlocal"+id2string(number)+type_char;
138+
irep_idt base_name="anonlocal::"+id2string(number)+type_char;
139139
irep_idt identifier=id2string(current_method)+"::"+id2string(base_name);
140140

141141
symbol_exprt result(identifier, t);
@@ -295,8 +295,6 @@ void java_bytecode_convert_methodt::convert(
295295

296296
variables.clear();
297297

298-
std::set<std::string> unique_local_names;
299-
300298
// Do the parameters and locals in the variable table, which is available when
301299
// compiled with -g or for methods with many local variables in the latter
302300
// case, different variables can have the same index, depending on the
@@ -309,26 +307,11 @@ void java_bytecode_convert_methodt::convert(
309307
{
310308
typet t=java_type_from_string(v.signature);
311309
size_t unique_number=0;
312-
std::string unique_id;
313-
std::string infix;
314-
// Avoid clashing with anonymous locals:
315-
if(has_prefix(as_string(v.name),"__anonlocal"))
316-
infix="_";
317-
// Avoid clashing with other named locals with disjoint scopes
318-
// (no sub-function-block-scoping in GOTO programs afaik!)
319-
do {
320-
std::ostringstream id_oss;
321-
id_oss << infix << v.name;
322-
size_t this_suffix=unique_number++;
323-
if(this_suffix!=0)
324-
id_oss << this_suffix;
325-
unique_id=id_oss.str();
326-
} while(!unique_local_names.insert(unique_id).second);
327-
std::ostringstream scoped_name;
328-
scoped_name << method_identifier << "::" << unique_id;
329-
irep_idt identifier(scoped_name.str());
310+
std::ostringstream id_oss;
311+
id_oss << method_identifier << "::" << v.start_pc << "::" << v.name;
312+
irep_idt identifier(id_oss.str());
330313
symbol_exprt result(identifier, t);
331-
result.set(ID_C_base_name, irep_idt(unique_id));
314+
result.set(ID_C_base_name, v.name);
332315
size_t number_index_entries = variables[v.index].size();
333316
variables[v.index].resize(number_index_entries + 1);
334317
variables[v.index][number_index_entries].symbol_expr = result;

0 commit comments

Comments
 (0)