Skip to content

Commit 12e8e5a

Browse files
committed
Remove language_uit dependency from goto-diff
Parsing is encapsulated in initialize_goto_model.
1 parent 750e2f3 commit 12e8e5a

File tree

4 files changed

+18
-138
lines changed

4 files changed

+18
-138
lines changed

src/goto-diff/goto_diff_languages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Author: Daniel Kroening, [email protected]
99
/// \file
1010
/// Language Registration
1111

12-
#include "goto_diff_languages.h"
12+
#include "goto_diff_parse_options.h"
1313

1414
#include <langapi/mode.h>
1515

1616
#include <ansi-c/ansi_c_language.h>
1717
#include <cpp/cpp_language.h>
1818

19-
void goto_diff_languagest::register_languages()
19+
void goto_diff_parse_optionst::register_languages()
2020
{
2121
register_language(new_ansi_c_language);
2222
register_language(new_cpp_language);

src/goto-diff/goto_diff_languages.h

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

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 14 additions & 88 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>
@@ -62,24 +63,8 @@ Author: Peter Schrammel
6263

6364
goto_diff_parse_optionst::goto_diff_parse_optionst(int argc, const char **argv)
6465
: parse_options_baset(GOTO_DIFF_OPTIONS, argc, argv, ui_message_handler),
65-
goto_diff_languagest(cmdline, ui_message_handler),
66-
ui_message_handler(cmdline, std::string("GOTO-DIFF ") + CBMC_VERSION),
67-
languages2(cmdline, ui_message_handler)
68-
{
69-
}
70-
71-
::goto_diff_parse_optionst::goto_diff_parse_optionst(
72-
int argc,
73-
const char **argv,
74-
const std::string &extra_options)
75-
: parse_options_baset(
76-
GOTO_DIFF_OPTIONS + extra_options,
77-
argc,
78-
argv,
79-
ui_message_handler),
80-
goto_diff_languagest(cmdline, ui_message_handler),
81-
ui_message_handler(cmdline, std::string("GOTO-DIFF ") + CBMC_VERSION),
82-
languages2(cmdline, ui_message_handler)
66+
messaget(ui_message_handler),
67+
ui_message_handler(cmdline, std::string("GOTO-DIFF ") + CBMC_VERSION)
8368
{
8469
}
8570

@@ -253,21 +238,21 @@ int goto_diff_parse_optionst::doit()
253238
return CPROVER_EXIT_INCORRECT_TASK;
254239
}
255240

256-
goto_modelt goto_model1, goto_model2;
241+
register_languages();
257242

258-
int get_goto_program_ret=
259-
get_goto_program(options, *this, goto_model1);
260-
if(get_goto_program_ret!=-1)
261-
return get_goto_program_ret;
262-
get_goto_program_ret=
263-
get_goto_program(options, languages2, goto_model2);
264-
if(get_goto_program_ret!=-1)
265-
return get_goto_program_ret;
243+
goto_modelt goto_model1 =
244+
initialize_goto_model({cmdline.args[0]}, ui_message_handler, options);
245+
if(process_goto_program(options, goto_model1))
246+
return CPROVER_EXIT_INTERNAL_ERROR;
247+
goto_modelt goto_model2 =
248+
initialize_goto_model({cmdline.args[1]}, ui_message_handler, options);
249+
if(process_goto_program(options, goto_model2))
250+
return CPROVER_EXIT_INTERNAL_ERROR;
266251

267252
if(cmdline.isset("show-loops"))
268253
{
269-
show_loop_ids(get_ui(), goto_model1);
270-
show_loop_ids(get_ui(), goto_model2);
254+
show_loop_ids(ui_message_handler.get_ui(), goto_model1);
255+
show_loop_ids(ui_message_handler.get_ui(), goto_model2);
271256
return CPROVER_EXIT_SUCCESS;
272257
}
273258

@@ -324,65 +309,6 @@ int goto_diff_parse_optionst::doit()
324309
return CPROVER_EXIT_SUCCESS;
325310
}
326311

327-
int goto_diff_parse_optionst::get_goto_program(
328-
const optionst &options,
329-
goto_diff_languagest &languages,
330-
goto_modelt &goto_model)
331-
{
332-
status() << "Reading program from `" << cmdline.args[0] << "'" << eom;
333-
334-
if(is_goto_binary(cmdline.args[0]))
335-
{
336-
auto tmp_goto_model =
337-
read_goto_binary(cmdline.args[0], languages.get_message_handler());
338-
if(!tmp_goto_model.has_value())
339-
return CPROVER_EXIT_INCORRECT_TASK;
340-
341-
goto_model = std::move(*tmp_goto_model);
342-
343-
config.set(cmdline);
344-
345-
// This one is done.
346-
cmdline.args.erase(cmdline.args.begin());
347-
}
348-
else
349-
{
350-
// This is a a workaround to make parse() think that there is only
351-
// one source file.
352-
std::string arg2("");
353-
if(cmdline.args.size()==2)
354-
{
355-
arg2 = cmdline.args[1];
356-
cmdline.args.erase(--cmdline.args.end());
357-
}
358-
359-
if(languages.parse() ||
360-
languages.typecheck() ||
361-
languages.final())
362-
return CPROVER_EXIT_INCORRECT_TASK;
363-
364-
// we no longer need any parse trees or language files
365-
languages.clear_parse();
366-
367-
status() << "Generating GOTO Program" << eom;
368-
369-
goto_model.symbol_table=languages.symbol_table;
370-
goto_convert(
371-
goto_model.symbol_table,
372-
goto_model.goto_functions,
373-
ui_message_handler);
374-
375-
if(process_goto_program(options, goto_model))
376-
return CPROVER_EXIT_INTERNAL_ERROR;
377-
378-
// if we had a second argument then we will handle it next
379-
if(arg2!="")
380-
cmdline.args[0]=arg2;
381-
}
382-
383-
return -1; // no error, continue
384-
}
385-
386312
bool goto_diff_parse_optionst::process_goto_program(
387313
const optionst &options,
388314
goto_modelt &goto_model)

src/goto-diff/goto_diff_parse_options.h

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

25-
#include "goto_diff_languages.h"
26-
2725
class goto_modelt;
2826
class optionst;
2927

@@ -41,31 +39,20 @@ class optionst;
4139
"(compact-output)"
4240
// clang-format on
4341

44-
class goto_diff_parse_optionst:
45-
public parse_options_baset,
46-
public goto_diff_languagest
42+
class goto_diff_parse_optionst : public parse_options_baset, public messaget
4743
{
4844
public:
4945
virtual int doit();
5046
virtual void help();
5147

5248
goto_diff_parse_optionst(int argc, const char **argv);
53-
goto_diff_parse_optionst(
54-
int argc,
55-
const char **argv,
56-
const std::string &extra_options);
5749

5850
protected:
5951
ui_message_handlert ui_message_handler;
60-
goto_diff_languagest languages2;
52+
void register_languages();
6153

6254
void get_command_line_options(optionst &options);
6355

64-
virtual int get_goto_program(
65-
const optionst &options,
66-
goto_diff_languagest &languages,
67-
goto_modelt &goto_model);
68-
6956
bool process_goto_program(const optionst &options, goto_modelt &goto_model);
7057
};
7158

0 commit comments

Comments
 (0)