Skip to content

Commit eaf3a7d

Browse files
Get source location from symbol table
Source locations of instructions are not reliable.
1 parent 7c04b5c commit eaf3a7d

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/goto-diff/goto_diff_base.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Author: Peter Schrammel
1515

1616
std::ostream &goto_difft::output_functions(std::ostream &out) const
1717
{
18+
namespacet ns1(goto_model1.symbol_table);
19+
namespacet ns2(goto_model2.symbol_table);
1820
switch(ui)
1921
{
2022
case ui_message_handlert::uit::PLAIN:
@@ -24,33 +26,24 @@ std::ostream &goto_difft::output_functions(std::ostream &out) const
2426
for(irep_id_sett::const_iterator it=new_functions.begin();
2527
it!=new_functions.end(); ++it)
2628
{
27-
const goto_programt &program=
28-
goto_model2.goto_functions.function_map.at(*it).body;
29-
out << " "
30-
<< program.instructions.begin()->source_location.get_file()
31-
<< ": " << *it << "\n";
29+
const symbolt &symbol = ns2.lookup(*it);
30+
out << " " << symbol.location.get_file() << ": " << *it << "\n";
3231
}
3332

3433
out << "modified functions:\n";
3534
for(irep_id_sett::const_iterator it=modified_functions.begin();
3635
it!=modified_functions.end(); ++it)
3736
{
38-
const goto_programt &program=
39-
goto_model2.goto_functions.function_map.at(*it).body;
40-
out << " "
41-
<< program.instructions.begin()->source_location.get_file()
42-
<< ": " << *it << "\n";
37+
const symbolt &symbol = ns2.lookup(*it);
38+
out << " " << symbol.location.get_file() << ": " << *it << "\n";
4339
}
4440

4541
out << "deleted functions:\n";
4642
for(irep_id_sett::const_iterator it=deleted_functions.begin();
4743
it!=deleted_functions.end(); ++it)
4844
{
49-
const goto_programt &program=
50-
goto_model1.goto_functions.function_map.at(*it).body;
51-
out << " "
52-
<< program.instructions.begin()->source_location.get_file()
53-
<< ": " << *it << "\n";
45+
const symbolt &symbol = ns1.lookup(*it);
46+
out << " " << symbol.location.get_file() << ": " << *it << "\n";
5447
}
5548
break;
5649
}
@@ -91,12 +84,22 @@ void goto_difft::convert_function(
9184
json_objectt &result,
9285
const irep_idt &function_name) const
9386
{
94-
const goto_programt &program=
95-
goto_model2.goto_functions.function_map.at(function_name).body;
96-
if(!program.instructions.empty())
87+
// the function may be in goto_model1 or goto_model2
88+
if(
89+
goto_model1.goto_functions.function_map.find(function_name) !=
90+
goto_model1.goto_functions.function_map.end())
9791
{
98-
result["sourceLocation"]=
99-
json(program.instructions.begin()->source_location);
92+
const symbolt &symbol =
93+
namespacet(goto_model1.symbol_table).lookup(function_name);
94+
result["sourceLocation"] = json(symbol.location);
95+
}
96+
else if(
97+
goto_model2.goto_functions.function_map.find(function_name) !=
98+
goto_model2.goto_functions.function_map.end())
99+
{
100+
const symbolt &symbol =
101+
namespacet(goto_model2.symbol_table).lookup(function_name);
102+
result["sourceLocation"] = json(symbol.location);
100103
}
101104
result["name"]=json_stringt(id2string(function_name));
102105
}

0 commit comments

Comments
 (0)