cprover
java_syntactic_diff.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Syntactic GOTO-DIFF for Java
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "java_syntactic_diff.h"
13 
15 
17 {
19  {
20  if(!it->second.body_available())
21  continue;
22 
23  goto_functionst::function_mapt::const_iterator f_it =
24  goto_model2.goto_functions.function_map.find(it->first);
25  if(
26  f_it == goto_model2.goto_functions.function_map.end() ||
27  !f_it->second.body_available())
28  {
29  deleted_functions.insert(it->first);
30  continue;
31  }
32 
33  // check access qualifiers
34  const symbolt *fun1 = goto_model1.symbol_table.lookup(it->first);
35  CHECK_RETURN(fun1 != nullptr);
36  const symbolt *fun2 = goto_model2.symbol_table.lookup(it->first);
37  CHECK_RETURN(fun2 != nullptr);
38  const irep_idt &class_name = fun1->type.get(ID_C_class);
39  bool function_access_changed =
40  fun1->type.get(ID_access) != fun2->type.get(ID_access);
41  bool class_access_changed = false;
42  bool field_access_changed = false;
43  if(!class_name.empty())
44  {
45  const symbolt *class1 = goto_model1.symbol_table.lookup(class_name);
46  CHECK_RETURN(class1 != nullptr);
47  const symbolt *class2 = goto_model2.symbol_table.lookup(class_name);
48  CHECK_RETURN(class2 != nullptr);
49  class_access_changed =
50  class1->type.get(ID_access) != class2->type.get(ID_access);
51  const class_typet &class_type1 = to_class_type(class1->type);
52  const class_typet &class_type2 = to_class_type(class2->type);
53  for(const auto &field1 : class_type1.components())
54  {
55  for(const auto &field2 : class_type2.components())
56  {
57  if(field1.get_name() == field2.get_name())
58  {
59  field_access_changed = field1.get_access() != field2.get_access();
60  break;
61  }
62  }
63  if(field_access_changed)
64  break;
65  }
66  }
67  if(function_access_changed || class_access_changed || field_access_changed)
68  {
69  modified_functions.insert(it->first);
70  continue;
71  }
72 
73  if(
74  it->second.body.instructions.size() !=
75  f_it->second.body.instructions.size())
76  {
77  modified_functions.insert(it->first);
78  continue;
79  }
80 
81  goto_programt::instructionst::const_iterator i_it1 =
82  it->second.body.instructions.begin();
83  for(goto_programt::instructionst::const_iterator
84  i_it2 = f_it->second.body.instructions.begin();
85  i_it1 != it->second.body.instructions.end() &&
86  i_it2 != f_it->second.body.instructions.end();
87  ++i_it1, ++i_it2)
88  {
89  long jump_difference1 = 0;
90  if(!i_it1->targets.empty())
91  {
92  jump_difference1 =
93  i_it1->get_target()->location_number - i_it1->location_number;
94  }
95  long jump_difference2 = 0;
96  if(!i_it2->targets.empty())
97  {
98  jump_difference2 =
99  i_it2->get_target()->location_number - i_it2->location_number;
100  }
101  if(
102  i_it1->code != i_it2->code || i_it1->function != i_it2->function ||
103  i_it1->type != i_it2->type || i_it1->guard != i_it2->guard ||
104  jump_difference1 != jump_difference2)
105  {
106  modified_functions.insert(it->first);
107  break;
108  }
109  }
110  }
112  {
113  if(!it->second.body_available())
114  continue;
115 
117 
118  goto_functionst::function_mapt::const_iterator f_it =
119  goto_model1.goto_functions.function_map.find(it->first);
120  if(
121  f_it == goto_model1.goto_functions.function_map.end() ||
122  !f_it->second.body_available())
123  new_functions.insert(it->first);
124  }
125 
126  return !(
127  new_functions.empty() && modified_functions.empty() &&
128  deleted_functions.empty());
129 }
const goto_modelt & goto_model1
Definition: goto_diff.h:49
const goto_modelt & goto_model2
Definition: goto_diff.h:50
const componentst & components() const
Definition: std_types.h:245
function_mapt function_map
const class_typet & to_class_type(const typet &type)
Cast a generic typet to a class_typet.
Definition: std_types.h:435
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:29
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:30
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:266
Syntactic GOTO-DIFF for Java.
Symbol Table + CFG.
unsigned total_functions_count
Definition: goto_diff.h:54
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
std::set< irep_idt > modified_functions
Definition: goto_diff.h:55
typet type
Type of symbol.
Definition: symbol.h:34
C++ class type.
Definition: std_types.h:341
#define forall_goto_functions(it, functions)
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool empty() const
Definition: dstring.h:73
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:32
std::set< irep_idt > deleted_functions
Definition: goto_diff.h:55
std::set< irep_idt > new_functions
Definition: goto_diff.h:55