|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: GOTO-DIFF Base Class |
| 4 | +
|
| 5 | +Author: Peter Schrammel |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <util/i2string.h> |
| 10 | + |
| 11 | +#include "goto_diff.h" |
| 12 | + |
| 13 | +/*******************************************************************\ |
| 14 | +
|
| 15 | +Function: goto_difft::output_functions |
| 16 | +
|
| 17 | + Inputs: |
| 18 | +
|
| 19 | + Outputs: |
| 20 | +
|
| 21 | + Purpose: |
| 22 | +
|
| 23 | +\*******************************************************************/ |
| 24 | + |
| 25 | +std::ostream &goto_difft::output_functions(std::ostream &out) const |
| 26 | +{ |
| 27 | + switch(ui) |
| 28 | + { |
| 29 | + case ui_message_handlert::PLAIN: |
| 30 | + { |
| 31 | + out << "total number of functions: " << total_functions_count << "\n"; |
| 32 | + out << "new functions: \n"; |
| 33 | + for(irep_id_sett::const_iterator it=new_functions.begin(); |
| 34 | + it!=new_functions.end(); ++it) |
| 35 | + { |
| 36 | + const goto_programt &program= |
| 37 | + goto_model2.goto_functions.function_map.at(*it).body; |
| 38 | + out << " " |
| 39 | + << program.instructions.begin()->source_location.get_file() |
| 40 | + << ": " << *it << "\n"; |
| 41 | + } |
| 42 | + |
| 43 | + out << "modified functions: \n"; |
| 44 | + for(irep_id_sett::const_iterator it=modified_functions.begin(); |
| 45 | + it!=modified_functions.end(); ++it) |
| 46 | + { |
| 47 | + const goto_programt &program= |
| 48 | + goto_model2.goto_functions.function_map.at(*it).body; |
| 49 | + out << " " |
| 50 | + << program.instructions.begin()->source_location.get_file() |
| 51 | + << ": " << *it << "\n"; |
| 52 | + } |
| 53 | + |
| 54 | + out << "deleted functions: \n"; |
| 55 | + for(irep_id_sett::const_iterator it=deleted_functions.begin(); |
| 56 | + it!=deleted_functions.end(); ++it) |
| 57 | + { |
| 58 | + const goto_programt &program= |
| 59 | + goto_model2.goto_functions.function_map.at(*it).body; |
| 60 | + out << " " |
| 61 | + << program.instructions.begin()->source_location.get_file() |
| 62 | + << ": " << *it << "\n"; |
| 63 | + } |
| 64 | + break; |
| 65 | + } |
| 66 | + case ui_message_handlert::JSON_UI: |
| 67 | + { |
| 68 | + json_objectt json_result; |
| 69 | + json_result["totalNumberOfFunctions"]= |
| 70 | + json_stringt(i2string(total_functions_count)); |
| 71 | + convert_function_group |
| 72 | + (json_result["newFunctions"].make_array(), new_functions); |
| 73 | + convert_function_group( |
| 74 | + json_result["modifiedFunctions"].make_array(), modified_functions); |
| 75 | + convert_function_group( |
| 76 | + json_result["deletedFunctions"].make_array(), deleted_functions); |
| 77 | + out << ",\n" << json_result; |
| 78 | + break; |
| 79 | + } |
| 80 | + case ui_message_handlert::XML_UI: |
| 81 | + { |
| 82 | + out << "not supported yet"; |
| 83 | + } |
| 84 | + } |
| 85 | + return out; |
| 86 | +} |
| 87 | + |
| 88 | +/*******************************************************************\ |
| 89 | +
|
| 90 | +Function: goto_difft::convert_function_group |
| 91 | +
|
| 92 | + Inputs: |
| 93 | +
|
| 94 | + Outputs: |
| 95 | +
|
| 96 | + Purpose: |
| 97 | +
|
| 98 | +\*******************************************************************/ |
| 99 | + |
| 100 | +void goto_difft::convert_function_group( |
| 101 | + json_arrayt &result, |
| 102 | + const irep_id_sett &function_group) const |
| 103 | +{ |
| 104 | + for(irep_id_sett::const_iterator it=function_group.begin(); |
| 105 | + it!=function_group.end(); ++it) |
| 106 | + { |
| 107 | + convert_function(result.push_back(jsont()).make_object(), *it); |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +/*******************************************************************\ |
| 112 | +
|
| 113 | +Function: goto_difft::convert_functions |
| 114 | +
|
| 115 | + Inputs: |
| 116 | +
|
| 117 | + Outputs: |
| 118 | +
|
| 119 | + Purpose: |
| 120 | +
|
| 121 | +\*******************************************************************/ |
| 122 | + |
| 123 | +void goto_difft::convert_function( |
| 124 | + json_objectt &result, |
| 125 | + const irep_idt &function_name) const |
| 126 | +{ |
| 127 | + const goto_programt &program= |
| 128 | + goto_model2.goto_functions.function_map.at(function_name).body; |
| 129 | + result["file"]=json_stringt( |
| 130 | + id2string(program.instructions.begin()->source_location.get_file())); |
| 131 | + result["name"]=json_stringt(id2string(function_name)); |
| 132 | +} |
0 commit comments