Skip to content

Commit a4d3dc3

Browse files
Show properties in goto-diff
Shows properties for each new/modified/deleted function. For now, for modified functions all properties are shown regardless of whether they are affected by the modification or not.
1 parent d3eb1f3 commit a4d3dc3

File tree

5 files changed

+149
-80
lines changed

5 files changed

+149
-80
lines changed

src/goto-diff/goto_diff.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,57 @@ Author: Peter Schrammel
1919

2020
#include <ostream>
2121

22+
class optionst;
23+
2224
class goto_difft:public messaget
2325
{
2426
public:
25-
explicit goto_difft(
27+
goto_difft(
2628
const goto_modelt &_goto_model1,
2729
const goto_modelt &_goto_model2,
28-
message_handlert &_message_handler
29-
)
30-
:
31-
messaget(_message_handler),
32-
goto_model1(_goto_model1),
33-
goto_model2(_goto_model2),
34-
ui(ui_message_handlert::uit::PLAIN),
35-
total_functions_count(0)
36-
{}
30+
const optionst &_options,
31+
message_handlert &_message_handler)
32+
: messaget(_message_handler),
33+
goto_model1(_goto_model1),
34+
goto_model2(_goto_model2),
35+
options(_options),
36+
ui(ui_message_handlert::uit::PLAIN),
37+
total_functions_count(0)
38+
{
39+
}
3740

3841
virtual bool operator()()=0;
3942

4043
void set_ui(ui_message_handlert::uit _ui) { ui=_ui; }
4144

42-
virtual std::ostream &output_functions(std::ostream &out) const;
45+
virtual void output_functions() const;
4346

4447
protected:
4548
const goto_modelt &goto_model1;
4649
const goto_modelt &goto_model2;
50+
const optionst &options;
4751
ui_message_handlert::uit ui;
4852

4953
unsigned total_functions_count;
5054
typedef std::set<irep_idt> irep_id_sett;
5155
irep_id_sett new_functions, modified_functions, deleted_functions;
5256

53-
void convert_function_group(
57+
void output_function_group(
58+
const std::string &group_name,
59+
const irep_id_sett &function_group,
60+
const goto_modelt &goto_model) const;
61+
void output_function(
62+
const irep_idt &function_name,
63+
const goto_modelt &goto_model) const;
64+
65+
void convert_function_group_json(
5466
json_arrayt &result,
55-
const irep_id_sett &function_group) const;
56-
void convert_function(
67+
const irep_id_sett &function_group,
68+
const goto_modelt &goto_model) const;
69+
void convert_function_json(
5770
json_objectt &result,
58-
const irep_idt &function_name) const;
71+
const irep_idt &function_name,
72+
const goto_modelt &goto_model) const;
5973
};
6074

6175
#endif // CPROVER_GOTO_DIFF_GOTO_DIFF_H

src/goto-diff/goto_diff_base.cpp

Lines changed: 106 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,142 @@ Author: Peter Schrammel
1111

1212
#include "goto_diff.h"
1313

14+
#include <goto-programs/show_properties.h>
15+
1416
#include <util/json_expr.h>
17+
#include <util/options.h>
1518

16-
std::ostream &goto_difft::output_functions(std::ostream &out) const
19+
/// Output diff result
20+
void goto_difft::output_functions() const
1721
{
18-
namespacet ns1(goto_model1.symbol_table);
19-
namespacet ns2(goto_model2.symbol_table);
2022
switch(ui)
2123
{
2224
case ui_message_handlert::uit::PLAIN:
2325
{
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;
4834
break;
4935
}
5036
case ui_message_handlert::uit::JSON_UI:
5137
{
5238
json_objectt json_result;
5339
json_result["totalNumberOfFunctions"]=
5440
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;
6252
break;
6353
}
6454
case ui_message_handlert::uit::XML_UI:
6555
{
66-
out << "not supported yet";
56+
error() << "XML output not supported yet" << eom;
6757
}
6858
}
69-
return out;
7059
}
7160

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
7569
{
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)
7872
{
79-
convert_function(result.push_back(jsont()).make_object(), *it);
73+
output_function(function_name, goto_model);
8074
}
8175
}
8276

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
86118
{
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)
91120
{
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);
95123
}
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"))
99142
{
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);
103151
}
104-
result["name"]=json_stringt(id2string(function_name));
105152
}

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Author: Peter Schrammel
5353

5454
#include <pointer-analysis/add_failed_symbols.h>
5555

56+
#include <java_bytecode/java_bytecode_language.h>
57+
5658
#include <langapi/mode.h>
5759

5860
#include <cbmc/version.h>
@@ -234,6 +236,8 @@ void goto_diff_parse_optionst::get_command_line_options(optionst &options)
234236
<< " must not be given together" << eom;
235237
exit(1);
236238
}
239+
240+
options.set_option("show-properties", cmdline.isset("show-properties"));
237241
}
238242

239243
/// invoke main modules
@@ -331,10 +335,10 @@ int goto_diff_parse_optionst::doit()
331335
return CPROVER_EXIT_SUCCESS;
332336
}
333337

334-
syntactic_difft sd(goto_model1, goto_model2, get_message_handler());
338+
syntactic_difft sd(goto_model1, goto_model2, options, get_message_handler());
335339
sd.set_ui(get_ui());
336340
sd();
337-
sd.output_functions(std::cout);
341+
sd.output_functions();
338342

339343
return CPROVER_EXIT_SUCCESS;
340344
}
@@ -516,6 +520,7 @@ void goto_diff_parse_optionst::help()
516520
"\n"
517521
"Diff options:\n"
518522
HELP_SHOW_GOTO_FUNCTIONS
523+
HELP_SHOW_PROPERTIES
519524
" --syntactic do syntactic diff (default)\n"
520525
" -u | --unified output unified diff\n"
521526
" --change-impact | \n"

src/goto-diff/goto_diff_parse_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Peter Schrammel
2020

2121
#include <goto-programs/goto_model.h>
2222
#include <goto-programs/show_goto_functions.h>
23+
#include <goto-programs/show_properties.h>
2324

2425
#include "goto_diff_languages.h"
2526

@@ -30,6 +31,7 @@ class optionst;
3031
#define GOTO_DIFF_OPTIONS \
3132
"(json-ui)" \
3233
OPT_SHOW_GOTO_FUNCTIONS \
34+
OPT_SHOW_PROPERTIES \
3335
OPT_GOTO_CHECK \
3436
"(cover):" \
3537
"(verbosity):(version)" \

src/goto-diff/syntactic_diff.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ Author: Peter Schrammel
1616

1717
class syntactic_difft:public goto_difft
1818
{
19-
public:
20-
explicit syntactic_difft(
19+
public:
20+
syntactic_difft(
2121
const goto_modelt &_goto_model1,
2222
const goto_modelt &_goto_model2,
23-
message_handlert &_message_handler):
24-
goto_difft(_goto_model1, _goto_model2, _message_handler)
23+
const optionst &_options,
24+
message_handlert &_message_handler)
25+
: goto_difft(_goto_model1, _goto_model2, _options, _message_handler)
2526
{
2627
}
2728

0 commit comments

Comments
 (0)