Skip to content

Commit cb43524

Browse files
committed
Remove language_uit dependency from jdiff
Parsing is encapsulated in initialize_goto_model.
1 parent 12e8e5a commit cb43524

File tree

4 files changed

+18
-134
lines changed

4 files changed

+18
-134
lines changed

jbmc/src/jdiff/jdiff_languages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Author: Peter Schrammel
99
/// \file
1010
/// Language Registration
1111

12-
#include "jdiff_languages.h"
12+
#include "jdiff_parse_options.h"
1313

1414
#include <langapi/mode.h>
1515

1616
#include <java_bytecode/java_bytecode_language.h>
1717

18-
void jdiff_languagest::register_languages()
18+
void jdiff_parse_optionst::register_languages()
1919
{
2020
register_language(new_java_bytecode_language);
2121
}

jbmc/src/jdiff/jdiff_languages.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Author: Peter Schrammel
2727
#include <goto-programs/adjust_float_expressions.h>
2828
#include <goto-programs/goto_convert_functions.h>
2929
#include <goto-programs/goto_inline.h>
30+
#include <goto-programs/initialize_goto_model.h>
3031
#include <goto-programs/instrument_preconditions.h>
3132
#include <goto-programs/link_to_library.h>
3233
#include <goto-programs/loop_ids.h>
@@ -60,28 +61,10 @@ Author: Peter Schrammel
6061
#include <goto-diff/goto_diff.h>
6162
#include <goto-diff/unified_diff.h>
6263

63-
// TODO: do not use language_uit for this; requires a refactoring of
64-
// initialize_goto_model to support parsing specific command line files
6564
jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
6665
: parse_options_baset(JDIFF_OPTIONS, argc, argv, ui_message_handler),
67-
jdiff_languagest(cmdline, ui_message_handler, &options),
68-
ui_message_handler(cmdline, std::string("JDIFF ") + CBMC_VERSION),
69-
languages2(cmdline, ui_message_handler, &options)
70-
{
71-
}
72-
73-
::jdiff_parse_optionst::jdiff_parse_optionst(
74-
int argc,
75-
const char **argv,
76-
const std::string &extra_options)
77-
: parse_options_baset(
78-
JDIFF_OPTIONS + extra_options,
79-
argc,
80-
argv,
81-
ui_message_handler),
82-
jdiff_languagest(cmdline, ui_message_handler, &options),
83-
ui_message_handler(cmdline, std::string("JDIFF ") + CBMC_VERSION),
84-
languages2(cmdline, ui_message_handler, &options)
66+
messaget(ui_message_handler),
67+
ui_message_handler(cmdline, std::string("JDIFF ") + CBMC_VERSION)
8568
{
8669
}
8770

@@ -219,19 +202,21 @@ int jdiff_parse_optionst::doit()
219202
return CPROVER_EXIT_INCORRECT_TASK;
220203
}
221204

222-
goto_modelt goto_model1, goto_model2;
205+
register_languages();
223206

224-
int get_goto_program_ret = get_goto_program(options, *this, goto_model1);
225-
if(get_goto_program_ret != -1)
226-
return get_goto_program_ret;
227-
get_goto_program_ret = get_goto_program(options, languages2, goto_model2);
228-
if(get_goto_program_ret != -1)
229-
return get_goto_program_ret;
207+
goto_modelt goto_model1 =
208+
initialize_goto_model({cmdline.args[0]}, ui_message_handler, options);
209+
if(process_goto_program(options, goto_model1))
210+
return CPROVER_EXIT_INTERNAL_ERROR;
211+
goto_modelt goto_model2 =
212+
initialize_goto_model({cmdline.args[1]}, ui_message_handler, options);
213+
if(process_goto_program(options, goto_model2))
214+
return CPROVER_EXIT_INTERNAL_ERROR;
230215

231216
if(cmdline.isset("show-loops"))
232217
{
233-
show_loop_ids(get_ui(), goto_model1);
234-
show_loop_ids(get_ui(), goto_model2);
218+
show_loop_ids(ui_message_handler.get_ui(), goto_model1);
219+
show_loop_ids(ui_message_handler.get_ui(), goto_model2);
235220
return CPROVER_EXIT_SUCCESS;
236221
}
237222

@@ -284,61 +269,6 @@ int jdiff_parse_optionst::doit()
284269
return CPROVER_EXIT_SUCCESS;
285270
}
286271

287-
int jdiff_parse_optionst::get_goto_program(
288-
const optionst &options,
289-
jdiff_languagest &languages,
290-
goto_modelt &goto_model)
291-
{
292-
status() << "Reading program from `" << cmdline.args[0] << "'" << eom;
293-
294-
if(is_goto_binary(cmdline.args[0]))
295-
{
296-
auto tmp_goto_model =
297-
read_goto_binary(cmdline.args[0], languages.get_message_handler());
298-
if(!tmp_goto_model.has_value())
299-
return CPROVER_EXIT_INCORRECT_TASK;
300-
301-
goto_model = std::move(*tmp_goto_model);
302-
303-
config.set(cmdline);
304-
305-
// This one is done.
306-
cmdline.args.erase(cmdline.args.begin());
307-
}
308-
else
309-
{
310-
// This is a a workaround to make parse() think that there is only
311-
// one source file.
312-
std::string arg2("");
313-
if(cmdline.args.size() == 2)
314-
{
315-
arg2 = cmdline.args[1];
316-
cmdline.args.erase(--cmdline.args.end());
317-
}
318-
319-
if(languages.parse() || languages.typecheck() || languages.final())
320-
return CPROVER_EXIT_INCORRECT_TASK;
321-
322-
// we no longer need any parse trees or language files
323-
languages.clear_parse();
324-
325-
status() << "Generating GOTO Program" << eom;
326-
327-
goto_model.symbol_table = languages.symbol_table;
328-
goto_convert(
329-
goto_model.symbol_table, goto_model.goto_functions, ui_message_handler);
330-
331-
if(process_goto_program(options, goto_model))
332-
return CPROVER_EXIT_INTERNAL_ERROR;
333-
334-
// if we had a second argument then we will handle it next
335-
if(arg2 != "")
336-
cmdline.args[0] = arg2;
337-
}
338-
339-
return -1; // no error, continue
340-
}
341-
342272
bool jdiff_parse_optionst::process_goto_program(
343273
const optionst &options,
344274
goto_modelt &goto_model)

jbmc/src/jdiff/jdiff_parse_options.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Author: Peter Schrammel
2323
#include <goto-programs/show_goto_functions.h>
2424
#include <goto-programs/show_properties.h>
2525

26-
#include "jdiff_languages.h"
27-
2826
class goto_modelt;
2927

3028
// clang-format off
@@ -42,30 +40,20 @@ class goto_modelt;
4240
"(compact-output)"
4341
// clang-format on
4442

45-
class jdiff_parse_optionst : public parse_options_baset, public jdiff_languagest
43+
class jdiff_parse_optionst : public parse_options_baset, public messaget
4644
{
4745
public:
4846
virtual int doit();
4947
virtual void help();
5048

5149
jdiff_parse_optionst(int argc, const char **argv);
52-
jdiff_parse_optionst(
53-
int argc,
54-
const char **argv,
55-
const std::string &extra_options);
5650

5751
protected:
58-
optionst options;
5952
ui_message_handlert ui_message_handler;
60-
jdiff_languagest languages2;
53+
void register_languages();
6154

6255
void get_command_line_options(optionst &options);
6356

64-
virtual int get_goto_program(
65-
const optionst &options,
66-
jdiff_languagest &languages,
67-
goto_modelt &goto_model);
68-
6957
bool process_goto_program(const optionst &options, goto_modelt &goto_model);
7058
};
7159

0 commit comments

Comments
 (0)