CBMC
jdiff_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: JDIFF Command Line Option Processing
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "jdiff_parse_options.h"
13 
14 #include <util/config.h>
15 #include <util/exit_codes.h>
16 #include <util/options.h>
17 #include <util/version.h>
18 
23 #include <goto-programs/loop_ids.h>
24 #include <goto-programs/mm_io.h>
31 
33 #include <goto-diff/unified_diff.h>
34 #include <goto-instrument/cover.h>
38 
39 #include "java_syntactic_diff.h"
40 
41 #include <cstdlib> // exit()
42 #include <iostream>
43 
44 jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
47  argc,
48  argv,
49  std::string("JDIFF ") + CBMC_VERSION)
50 {
51 }
52 
54 {
55  if(config.set(cmdline))
56  {
57  usage_error();
58  exit(1);
59  }
60 
62 
63  // check assertions
64  if(cmdline.isset("no-assertions"))
65  options.set_option("assertions", false);
66  else
67  options.set_option("assertions", true);
68 
69  // use assumptions
70  if(cmdline.isset("no-assumptions"))
71  options.set_option("assumptions", false);
72  else
73  options.set_option("assumptions", true);
74 
75  if(cmdline.isset("cover"))
76  parse_cover_options(cmdline, options);
77 
78  options.set_option("show-properties", cmdline.isset("show-properties"));
79 }
80 
83 {
84  if(cmdline.isset("version"))
85  {
86  std::cout << CBMC_VERSION << '\n';
87  return CPROVER_EXIT_SUCCESS;
88  }
89 
90  //
91  // command line options
92  //
93 
94  optionst options;
95  get_command_line_options(options);
98 
100 
101  if(cmdline.args.size() != 2)
102  {
103  log.error() << "Please provide two programs to compare" << messaget::eom;
105  }
106 
108 
109  goto_modelt goto_model1 =
111  if(process_goto_program(options, goto_model1))
113  goto_modelt goto_model2 =
115  if(process_goto_program(options, goto_model2))
117 
118  if(cmdline.isset("show-loops"))
119  {
120  show_loop_ids(ui_message_handler.get_ui(), goto_model1);
121  show_loop_ids(ui_message_handler.get_ui(), goto_model2);
122  return CPROVER_EXIT_SUCCESS;
123  }
124 
125  if(
126  cmdline.isset("show-goto-functions") ||
127  cmdline.isset("list-goto-functions"))
128  {
130  goto_model1, ui_message_handler, cmdline.isset("list-goto-functions"));
132  goto_model2, ui_message_handler, cmdline.isset("list-goto-functions"));
133  return CPROVER_EXIT_SUCCESS;
134  }
135 
136  if(
137  cmdline.isset("change-impact") || cmdline.isset("forward-impact") ||
138  cmdline.isset("backward-impact"))
139  {
140  impact_modet impact_mode =
141  cmdline.isset("forward-impact")
143  : (cmdline.isset("backward-impact") ? impact_modet::BACKWARD
146  goto_model1, goto_model2, impact_mode, cmdline.isset("compact-output"));
147 
148  return CPROVER_EXIT_SUCCESS;
149  }
150 
151  if(cmdline.isset("unified") || cmdline.isset('u'))
152  {
153  unified_difft u(goto_model1, goto_model2);
154  u();
155  u.output(std::cout);
156 
157  return CPROVER_EXIT_SUCCESS;
158  }
159 
161  goto_model1, goto_model2, options, ui_message_handler);
162  sd();
163  sd.output_functions();
164 
165  return CPROVER_EXIT_SUCCESS;
166 }
167 
169  const optionst &options,
170  goto_modelt &goto_model)
171 {
172  // remove function pointers
173  log.status() << "Removing function pointers and virtual functions"
174  << messaget::eom;
175  remove_function_pointers(ui_message_handler, goto_model, false);
176 
177  // Java virtual functions -> explicit dispatch tables:
178  remove_virtual_functions(goto_model);
179 
180  // remove Java throw and catch
181  // This introduces instanceof, so order is important:
183 
184  // Java instanceof -> clsid comparison:
185  class_hierarchyt class_hierarchy(goto_model.symbol_table);
186  remove_instanceof(goto_model, class_hierarchy, ui_message_handler);
187 
188  mm_io(goto_model);
189 
190  // instrument library preconditions
191  instrument_preconditions(goto_model);
192 
193  // remove returns
194  remove_returns(goto_model);
195 
196  transform_assertions_assumptions(options, goto_model);
197 
198  // checks don't know about adjusted float expressions
199  adjust_float_expressions(goto_model);
200 
201  // recalculate numbers, etc.
202  goto_model.goto_functions.update();
203 
204  // instrument cover goals
205  if(cmdline.isset("cover"))
206  {
207  // remove skips such that trivial GOTOs are deleted and not considered for
208  // coverage annotation:
209  remove_skip(goto_model);
210 
211  const auto cover_config =
212  get_cover_config(options, goto_model.symbol_table, ui_message_handler);
213  if(instrument_cover_goals(cover_config, goto_model, ui_message_handler))
214  return true;
215  }
216 
217  // label the assertions
218  // This must be done after adding assertions and
219  // before using the argument of the "property" option.
220  // Do not re-label after using the property slicer because
221  // this would cause the property identifiers to change.
222  label_properties(goto_model);
223 
224  // remove any skips introduced since coverage instrumentation
225  remove_skip(goto_model);
226 
227  return false;
228 }
229 
232 {
233  // clang-format off
234  std::cout << '\n' << banner_string("JDIFF", CBMC_VERSION) << '\n'
235  << align_center_with_border("Copyright (C) 2016-2018") << '\n'
236  << align_center_with_border("Daniel Kroening, Peter Schrammel") << '\n' // NOLINT(*)
237  << align_center_with_border("kroening@kroening.com") << '\n'
238  <<
239  "\n"
240  "Usage: Purpose:\n"
241  "\n"
242  " jdiff [-?] [-h] [--help] show help\n"
243  " jdiff old new jars to be compared\n"
244  "\n"
245  "Diff options:\n"
248  " --show-loops show the loops in the programs\n"
249  " -u | --unified output unified diff\n"
250  " --change-impact | \n"
251  " --forward-impact |\n"
252  // NOLINTNEXTLINE(whitespace/line_length)
253  " --backward-impact output unified diff with forward&backward/forward/backward dependencies\n"
254  " --compact-output output dependencies in compact mode\n"
255  "\n"
256  "Program instrumentation options:\n"
257  " --no-assertions ignore user assertions\n"
258  " --no-assumptions ignore user assumptions\n"
259  HELP_COVER
260  "Other options:\n"
261  " --version show version and exit\n"
262  " --json-ui use JSON-formatted output\n"
263  " --verbosity # verbosity level\n"
265  "\n";
266  // clang-format on
267 }
cmdlinet::args
argst args
Definition: cmdline.h:145
mm_io
void mm_io(const exprt &mm_io_r, const exprt &mm_io_r_value, const exprt &mm_io_w, goto_functionst::goto_functiont &goto_function, const namespacet &ns)
Definition: mm_io.cpp:37
cover.h
HELP_SHOW_GOTO_FUNCTIONS
#define HELP_SHOW_GOTO_FUNCTIONS
Definition: show_goto_functions.h:25
impact_modet
impact_modet
Definition: change_impact.h:18
JDIFF_OPTIONS
#define JDIFF_OPTIONS
Definition: jdiff_parse_options.h:26
unified_difft::output
void output(std::ostream &os) const
Definition: unified_diff.cpp:375
jdiff_parse_optionst::get_command_line_options
void get_command_line_options(optionst &options)
Definition: jdiff_parse_options.cpp:53
class_hierarchyt
Non-graph-based representation of the class hierarchy.
Definition: class_hierarchy.h:42
parse_options_baset::ui_message_handler
ui_message_handlert ui_message_handler
Definition: parse_options.h:45
parse_options_baset
Definition: parse_options.h:19
java_bytecode_language.h
parse_java_language_options
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
Definition: java_bytecode_language.cpp:55
remove_exceptions_using_instanceof
void remove_exceptions_using_instanceof(symbol_table_baset &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
Definition: remove_exceptions.cpp:627
cmdlinet::isset
virtual bool isset(char option) const
Definition: cmdline.cpp:30
impact_modet::BACKWARD
@ BACKWARD
optionst
Definition: options.h:22
messaget::M_STATISTICS
@ M_STATISTICS
Definition: message.h:171
messaget::status
mstreamt & status() const
Definition: message.h:414
instrument_preconditions.h
remove_skip
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:87
remove_virtual_functions.h
remove_virtual_functions
void remove_virtual_functions(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Definition: remove_virtual_functions.cpp:728
change_impact
void change_impact(const goto_modelt &model_old, const goto_modelt &model_new, impact_modet impact_mode, bool compact_output)
Definition: change_impact.cpp:753
goto_modelt
Definition: goto_model.h:25
show_loop_ids
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition: loop_ids.cpp:21
HELP_COVER
#define HELP_COVER
Definition: cover.h:32
options.h
optionst::set_option
void set_option(const std::string &option, const bool value)
Definition: options.cpp:28
parse_options_baset::log_version_and_architecture
void log_version_and_architecture(const std::string &front_end)
Write version and system architecture to log.status().
Definition: parse_options.cpp:152
messaget::eom
static eomt eom
Definition: message.h:297
instrument_cover_goals
static void instrument_cover_goals(const irep_idt &function_id, goto_programt &goto_program, const cover_instrumenterst &instrumenters, const irep_idt &mode, message_handlert &message_handler, const cover_instrumenter_baset::assertion_factoryt &make_assertion)
Applies instrumenters to given goto program.
Definition: cover.cpp:37
impact_modet::BOTH
@ BOTH
version.h
unified_difft
Definition: unified_diff.h:29
label_properties
void label_properties(goto_modelt &goto_model)
Definition: set_properties.cpp:45
remove_instanceof
void remove_instanceof(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
Replace an instanceof in the expression or guard of the passed instruction of the given function body...
Definition: remove_instanceof.cpp:306
ui_message_handlert::get_ui
virtual uit get_ui() const
Definition: ui_message.h:33
parse_options_baset::usage_error
virtual void usage_error()
Definition: parse_options.cpp:49
unified_diff.h
set_properties.h
get_cover_config
cover_configt get_cover_config(const optionst &options, const symbol_tablet &symbol_table, message_handlert &message_handler)
Build data structures controlling coverage from command-line options.
Definition: cover.cpp:186
goto_difft::output_functions
virtual void output_functions() const
Output diff result.
Definition: goto_diff_base.cpp:21
CBMC_VERSION
const char * CBMC_VERSION
messaget::error
mstreamt & error() const
Definition: message.h:399
initialize_goto_model.h
banner_string
std::string banner_string(const std::string &front_end, const std::string &version)
Definition: parse_options.cpp:174
mm_io.h
instrument_preconditions
void instrument_preconditions(const goto_modelt &goto_model, goto_programt &goto_program)
Definition: instrument_preconditions.cpp:99
jdiff_parse_options.h
remove_function_pointers
void remove_function_pointers(message_handlert &_message_handler, goto_modelt &goto_model, bool only_remove_const_fps)
Definition: remove_function_pointers.cpp:533
show_properties.h
cmdlinet::get_value
std::string get_value(char option) const
Definition: cmdline.cpp:48
java_syntactic_diff.h
HELP_SHOW_PROPERTIES
#define HELP_SHOW_PROPERTIES
Definition: show_properties.h:30
show_goto_functions
void show_goto_functions(const namespacet &ns, ui_message_handlert &ui_message_handler, const goto_functionst &goto_functions, bool list_only)
Definition: show_goto_functions.cpp:20
transform_assertions_assumptions
static void transform_assertions_assumptions(goto_programt &goto_program, bool enable_assertions, bool enable_built_in_assertions, bool enable_assumptions)
Definition: goto_check.cpp:19
parse_cover_options
void parse_cover_options(const cmdlinet &cmdline, optionst &options)
Parses coverage-related command line options.
Definition: cover.cpp:148
goto_check.h
impact_modet::FORWARD
@ FORWARD
jdiff_parse_optionst::jdiff_parse_optionst
jdiff_parse_optionst(int argc, const char **argv)
Definition: jdiff_parse_options.cpp:44
CPROVER_EXIT_INCORRECT_TASK
#define CPROVER_EXIT_INCORRECT_TASK
The command line is correctly structured but cannot be carried out due to missing files,...
Definition: exit_codes.h:49
remove_returns.h
remove_exceptions.h
config
configt config
Definition: config.cpp:25
remove_instanceof.h
parse_options_baset::log
messaget log
Definition: parse_options.h:46
jdiff_parse_optionst::register_languages
void register_languages() override
Definition: jdiff_languages.cpp:18
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:33
configt::set
bool set(const cmdlinet &cmdline)
Definition: config.cpp:798
exit_codes.h
remove_returns
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
Definition: remove_returns.cpp:255
java_syntactic_difft
Definition: java_syntactic_diff.h:17
goto_functionst::update
void update()
Definition: goto_functions.h:83
jdiff_parse_optionst::process_goto_program
bool process_goto_program(const optionst &options, goto_modelt &goto_model)
Definition: jdiff_parse_options.cpp:168
change_impact.h
config.h
loop_ids.h
jdiff_parse_optionst::help
void help() override
display command line help
Definition: jdiff_parse_options.cpp:231
adjust_float_expressions
void adjust_float_expressions(exprt &expr, const exprt &rounding_mode)
Replaces arithmetic operations and typecasts involving floating point numbers with their equivalent f...
Definition: adjust_float_expressions.cpp:85
CPROVER_EXIT_INTERNAL_ERROR
#define CPROVER_EXIT_INTERNAL_ERROR
An error has been encountered during processing the requested analysis.
Definition: exit_codes.h:45
initialize_goto_model
goto_modelt initialize_goto_model(const std::vector< std::string > &files, message_handlert &message_handler, const optionst &options)
Definition: initialize_goto_model.cpp:178
CPROVER_EXIT_SUCCESS
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Definition: exit_codes.h:16
messaget::eval_verbosity
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
Definition: message.cpp:105
remove_skip.h
adjust_float_expressions.h
remove_function_pointers.h
parse_options_baset::cmdline
cmdlinet cmdline
Definition: parse_options.h:28
goto_modelt::symbol_table
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:30
align_center_with_border
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
Definition: parse_options.cpp:161
jdiff_parse_optionst::doit
int doit() override
invoke main modules
Definition: jdiff_parse_options.cpp:82
HELP_TIMESTAMP
#define HELP_TIMESTAMP
Definition: timestamper.h:14