|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Syntactic GOTO-DIFF for Java |
| 4 | +
|
| 5 | +Author: Peter Schrammel |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// Syntactic GOTO-DIFF for Java |
| 11 | + |
| 12 | +#include "java_syntactic_diff.h" |
| 13 | + |
| 14 | +#include <goto-programs/goto_model.h> |
| 15 | + |
| 16 | +bool java_syntactic_difft::operator()() |
| 17 | +{ |
| 18 | + forall_goto_functions(it, goto_model1.goto_functions) |
| 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 | + } |
| 111 | + forall_goto_functions(it, goto_model2.goto_functions) |
| 112 | + { |
| 113 | + if(!it->second.body_available()) |
| 114 | + continue; |
| 115 | + |
| 116 | + total_functions_count++; |
| 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 | +} |
0 commit comments