Skip to content

Commit 21ea31f

Browse files
authored
Merge pull request #1702 from peterschrammel/goto-diff-java
Various goto-diff fixes and a java regression test
2 parents c4bc953 + 2811363 commit 21ea31f

File tree

8 files changed

+83
-25
lines changed

8 files changed

+83
-25
lines changed
397 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Test {
2+
3+
public int run() {
4+
int x = 42;
5+
6+
return x;
7+
}
8+
9+
public void bar() {
10+
int y = 0;
11+
}
12+
13+
public void unchanged() {
14+
int z = 0;
15+
}
16+
}
396 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Test {
2+
3+
public int run() {
4+
int x = 0;
5+
6+
return x;
7+
}
8+
9+
public void unchanged() {
10+
int z = 0;
11+
}
12+
13+
public void foo() {
14+
int y = 0;
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
old.jar
3+
new.jar
4+
// Enable multi-line checking
5+
activate-multi-line-match
6+
EXIT=0
7+
SIGNAL=0
8+
new functions:\n Test\.java: java::Test\.foo:\(\)V\nmodified functions:\n Test\.java: java::Test\.run:\(\)I\ndeleted functions:\n Test\.java: java::Test\.bar:\(\)V
9+
--
10+
^warning: ignoring

src/goto-diff/goto_diff_base.cpp

Lines changed: 23 additions & 20 deletions
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
}

src/goto-diff/syntactic_diff.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,22 @@ bool syntactic_difft::operator()()
4242
i_it2!=f_it->second.body.instructions.end();
4343
++i_it1, ++i_it2)
4444
{
45-
if(i_it1->code != i_it2->code ||
46-
i_it1->function != i_it2->function ||
47-
i_it1->type != i_it2->type ||
48-
i_it1->guard != i_it2->guard ||
49-
i_it1->targets != i_it2->targets)
45+
long jump_difference1 = 0;
46+
if(!i_it1->targets.empty())
47+
{
48+
jump_difference1 =
49+
i_it1->get_target()->location_number - i_it1->location_number;
50+
}
51+
long jump_difference2 = 0;
52+
if(!i_it2->targets.empty())
53+
{
54+
jump_difference2 =
55+
i_it2->get_target()->location_number - i_it2->location_number;
56+
}
57+
if(
58+
i_it1->code != i_it2->code || i_it1->function != i_it2->function ||
59+
i_it1->type != i_it2->type || i_it1->guard != i_it2->guard ||
60+
jump_difference1 != jump_difference2)
5061
{
5162
modified_functions.insert(it->first);
5263
break;

src/goto-programs/goto_convert_functions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: June 2003
1616
#include <util/std_code.h>
1717
#include <util/symbol_table.h>
1818
#include <util/prefix.h>
19+
#include <util/fresh_symbol.h>
1920

2021
#include "goto_inline.h"
2122

@@ -145,6 +146,7 @@ void goto_convert_functionst::convert_function(
145146
// make tmp variables local to function
146147
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp::";
147148
temporary_counter=0;
149+
reset_temporary_counter();
148150

149151
f.type=to_code_type(symbol.type);
150152

0 commit comments

Comments
 (0)