cprover
goto_diff_base.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: GOTO-DIFF Base Class
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "goto_diff.h"
13 
14 #include <util/json_expr.h>
15 
16 std::ostream &goto_difft::output_functions(std::ostream &out) const
17 {
18  switch(ui)
19  {
21  {
22  out << "total number of functions: " << total_functions_count << "\n";
23  out << "new functions:\n";
24  for(irep_id_sett::const_iterator it=new_functions.begin();
25  it!=new_functions.end(); ++it)
26  {
27  const goto_programt &program=
29  out << " "
30  << program.instructions.begin()->source_location.get_file()
31  << ": " << *it << "\n";
32  }
33 
34  out << "modified functions:\n";
35  for(irep_id_sett::const_iterator it=modified_functions.begin();
36  it!=modified_functions.end(); ++it)
37  {
38  const goto_programt &program=
40  out << " "
41  << program.instructions.begin()->source_location.get_file()
42  << ": " << *it << "\n";
43  }
44 
45  out << "deleted functions:\n";
46  for(irep_id_sett::const_iterator it=deleted_functions.begin();
47  it!=deleted_functions.end(); ++it)
48  {
49  const goto_programt &program=
51  out << " "
52  << program.instructions.begin()->source_location.get_file()
53  << ": " << *it << "\n";
54  }
55  break;
56  }
58  {
59  json_objectt json_result;
60  json_result["totalNumberOfFunctions"]=
61  json_stringt(std::to_string(total_functions_count));
63  (json_result["newFunctions"].make_array(), new_functions);
65  json_result["modifiedFunctions"].make_array(), modified_functions);
67  json_result["deletedFunctions"].make_array(), deleted_functions);
68  out << ",\n" << json_result;
69  break;
70  }
72  {
73  out << "not supported yet";
74  }
75  }
76  return out;
77 }
78 
81  const irep_id_sett &function_group) const
82 {
83  for(irep_id_sett::const_iterator it=function_group.begin();
84  it!=function_group.end(); ++it)
85  {
86  convert_function(result.push_back(jsont()).make_object(), *it);
87  }
88 }
89 
92  const irep_idt &function_name) const
93 {
94  const goto_programt &program=
95  goto_model2.goto_functions.function_map.at(function_name).body;
96  if(!program.instructions.empty())
97  {
98  result["sourceLocation"]=
99  json(program.instructions.begin()->source_location);
100  }
101  result["name"]=json_stringt(id2string(function_name));
102 }
virtual std::ostream & output_functions(std::ostream &out) const
mstreamt & result()
Definition: message.h:233
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
const goto_modelt & goto_model1
Definition: goto_diff.h:45
instructionst instructions
The list of instructions in the goto program.
Definition: json.h:21
const goto_modelt & goto_model2
Definition: goto_diff.h:46
void convert_function(json_objectt &result, const irep_idt &function_name) const
jsont & push_back(const jsont &json)
Definition: json.h:157
unsigned total_functions_count
Definition: goto_diff.h:49
irep_id_sett modified_functions
Definition: goto_diff.h:51
Expressions in JSON.
void convert_function_group(json_arrayt &result, const irep_id_sett &function_group) const
language_uit::uit ui
Definition: goto_diff.h:47
std::set< irep_idt > irep_id_sett
Definition: goto_diff.h:50
A specialization of goto_program_templatet over goto programs in which instructions have codet type...
Definition: goto_program.h:24
irep_id_sett new_functions
Definition: goto_diff.h:51
json_objectt & make_object()
Definition: json.h:234
irep_id_sett deleted_functions
Definition: goto_diff.h:51
goto_functionst goto_functions
Definition: goto_model.h:26
json_objectt json(const source_locationt &location)
Definition: json_expr.cpp:23
GOTO-DIFF Base Class.