@@ -11,95 +11,142 @@ Author: Peter Schrammel
11
11
12
12
#include " goto_diff.h"
13
13
14
+ #include < goto-programs/show_properties.h>
15
+
14
16
#include < util/json_expr.h>
17
+ #include < util/options.h>
15
18
16
- std::ostream &goto_difft::output_functions (std::ostream &out) const
19
+ // / Output diff result
20
+ void goto_difft::output_functions () const
17
21
{
18
- namespacet ns1 (goto_model1.symbol_table );
19
- namespacet ns2 (goto_model2.symbol_table );
20
22
switch (ui)
21
23
{
22
24
case ui_message_handlert::uit::PLAIN:
23
25
{
24
- out << " total number of functions: " << total_functions_count << " \n " ;
25
- out << " new functions:\n " ;
26
- for (irep_id_sett::const_iterator it=new_functions.begin ();
27
- it!=new_functions.end (); ++it)
28
- {
29
- const symbolt &symbol = ns2.lookup (*it);
30
- out << " " << symbol.location .get_file () << " : " << *it << " \n " ;
31
- }
32
-
33
- out << " modified functions:\n " ;
34
- for (irep_id_sett::const_iterator it=modified_functions.begin ();
35
- it!=modified_functions.end (); ++it)
36
- {
37
- const symbolt &symbol = ns2.lookup (*it);
38
- out << " " << symbol.location .get_file () << " : " << *it << " \n " ;
39
- }
40
-
41
- out << " deleted functions:\n " ;
42
- for (irep_id_sett::const_iterator it=deleted_functions.begin ();
43
- it!=deleted_functions.end (); ++it)
44
- {
45
- const symbolt &symbol = ns1.lookup (*it);
46
- out << " " << symbol.location .get_file () << " : " << *it << " \n " ;
47
- }
26
+ result () << " total number of functions: " << total_functions_count
27
+ << ' \n ' ;
28
+ output_function_group (" new functions" , new_functions, goto_model2);
29
+ output_function_group (
30
+ " modified functions" , modified_functions, goto_model2);
31
+ output_function_group (
32
+ " deleted functions" , deleted_functions, goto_model1);
33
+ result () << eom;
48
34
break ;
49
35
}
50
36
case ui_message_handlert::uit::JSON_UI:
51
37
{
52
38
json_objectt json_result;
53
39
json_result[" totalNumberOfFunctions" ]=
54
40
json_stringt (std::to_string (total_functions_count));
55
- convert_function_group
56
- (json_result[" newFunctions" ].make_array (), new_functions);
57
- convert_function_group (
58
- json_result[" modifiedFunctions" ].make_array (), modified_functions);
59
- convert_function_group (
60
- json_result[" deletedFunctions" ].make_array (), deleted_functions);
61
- out << " ,\n " << json_result;
41
+ convert_function_group_json (
42
+ json_result[" newFunctions" ].make_array (), new_functions, goto_model2);
43
+ convert_function_group_json (
44
+ json_result[" modifiedFunctions" ].make_array (),
45
+ modified_functions,
46
+ goto_model2);
47
+ convert_function_group_json (
48
+ json_result[" deletedFunctions" ].make_array (),
49
+ deleted_functions,
50
+ goto_model1);
51
+ result () << json_result;
62
52
break ;
63
53
}
64
54
case ui_message_handlert::uit::XML_UI:
65
55
{
66
- out << " not supported yet" ;
56
+ error () << " XML output not supported yet" << eom ;
67
57
}
68
58
}
69
- return out;
70
59
}
71
60
72
- void goto_difft::convert_function_group (
73
- json_arrayt &result,
74
- const irep_id_sett &function_group) const
61
+ // / Output group of functions in plain text format
62
+ // / \param group_name: the name of the group, e.g. "modified functions"
63
+ // / \param function_group: set of function ids in the group
64
+ // / \param goto_model: the goto model
65
+ void goto_difft::output_function_group (
66
+ const std::string &group_name,
67
+ const irep_id_sett &function_group,
68
+ const goto_modelt &goto_model) const
75
69
{
76
- for (irep_id_sett::const_iterator it=function_group. begin () ;
77
- it!= function_group. end (); ++it )
70
+ result () << group_name << " : \n " ;
71
+ for ( const auto &function_name : function_group)
78
72
{
79
- convert_function (result. push_back ( jsont ()). make_object (), *it );
73
+ output_function (function_name, goto_model );
80
74
}
81
75
}
82
76
83
- void goto_difft::convert_function (
84
- json_objectt &result,
85
- const irep_idt &function_name) const
77
+ // / Output function information in plain text format
78
+ // / \param function_name: the function id
79
+ // / \param goto_model: the goto model
80
+ void goto_difft::output_function (
81
+ const irep_idt &function_name,
82
+ const goto_modelt &goto_model) const
83
+ {
84
+ namespacet ns (goto_model.symbol_table );
85
+ const symbolt &symbol = ns.lookup (function_name);
86
+
87
+ result () << " " << symbol.location .get_file () << " : " << function_name
88
+ << ' \n ' ;
89
+
90
+ if (options.get_bool_option (" show-properties" ))
91
+ {
92
+ const auto goto_function_it =
93
+ goto_model.goto_functions .function_map .find (function_name);
94
+ CHECK_RETURN (
95
+ goto_function_it != goto_model.goto_functions .function_map .end ());
96
+ const goto_programt &goto_program = goto_function_it->second .body ;
97
+
98
+ for (const auto &ins : goto_program.instructions )
99
+ {
100
+ if (!ins.is_assert ())
101
+ continue ;
102
+
103
+ const source_locationt &source_location = ins.source_location ;
104
+ irep_idt property_id = source_location.get_property_id ();
105
+ result () << " " << property_id << ' \n ' ;
106
+ }
107
+ }
108
+ }
109
+
110
+ // / Convert a function group to JSON
111
+ // / \param result: the JSON array to be populated
112
+ // / \param function_group: set of function ids in the group
113
+ // / \param goto_model: the goto model
114
+ void goto_difft::convert_function_group_json (
115
+ json_arrayt &result,
116
+ const irep_id_sett &function_group,
117
+ const goto_modelt &goto_model) const
86
118
{
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 ())
119
+ for (const auto &function_name : function_group)
91
120
{
92
- const symbolt &symbol =
93
- namespacet (goto_model1.symbol_table ).lookup (function_name);
94
- result[" sourceLocation" ] = json (symbol.location );
121
+ convert_function_json (
122
+ result.push_back (jsont ()).make_object (), function_name, goto_model);
95
123
}
96
- else if (
97
- goto_model2.goto_functions .function_map .find (function_name) !=
98
- goto_model2.goto_functions .function_map .end ())
124
+ }
125
+
126
+ // / Convert function information to JSON
127
+ // / \param result: the JSON object to be populated
128
+ // / \param function_name: the function id
129
+ // / \param goto_model: the goto model
130
+ void goto_difft::convert_function_json (
131
+ json_objectt &result,
132
+ const irep_idt &function_name,
133
+ const goto_modelt &goto_model) const
134
+ {
135
+ namespacet ns (goto_model.symbol_table );
136
+ const symbolt &symbol = ns.lookup (function_name);
137
+
138
+ result[" name" ] = json_stringt (id2string (function_name));
139
+ result[" sourceLocation" ] = json (symbol.location );
140
+
141
+ if (options.get_bool_option (" show-properties" ))
99
142
{
100
- const symbolt &symbol =
101
- namespacet (goto_model2.symbol_table ).lookup (function_name);
102
- result[" sourceLocation" ] = json (symbol.location );
143
+ const auto goto_function_it =
144
+ goto_model.goto_functions .function_map .find (function_name);
145
+ CHECK_RETURN (
146
+ goto_function_it != goto_model.goto_functions .function_map .end ());
147
+ const goto_programt &goto_program = goto_function_it->second .body ;
148
+
149
+ convert_properties_json (
150
+ result[" properties" ].make_array (), ns, function_name, goto_program);
103
151
}
104
- result[" name" ]=json_stringt (id2string (function_name));
105
152
}
0 commit comments