Skip to content

Commit 2c7ce18

Browse files
committed
use ebmc_languaget API in ebmc_parse_optionst
This replaces the direct call to get_transition_system(...) by a call to an implementation of ebmc_languaget, which wraps get_transition_system.
1 parent 4e87354 commit 2c7ce18

File tree

4 files changed

+72
-50
lines changed

4 files changed

+72
-50
lines changed

src/ebmc/build_transition_system.cpp

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,29 @@ Author: Daniel Kroening, [email protected]
3030
#include <fstream>
3131
#include <iostream>
3232

33-
int preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
33+
void preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
3434
{
3535
messaget message(message_handler);
3636

3737
if(cmdline.args.size() != 1)
38-
{
39-
message.error() << "please give exactly one file to preprocess"
40-
<< messaget::eom;
41-
return 1;
42-
}
38+
throw ebmc_errort{}.with_exit_code(1)
39+
<< "please give exactly one file to preprocess";
4340

4441
const auto &filename = cmdline.args.front();
4542
std::ifstream infile(widen_if_needed(filename));
4643

4744
if(!infile)
48-
{
49-
message.error() << "failed to open input file `" << filename << "'"
50-
<< messaget::eom;
51-
return 1;
52-
}
45+
throw ebmc_errort{}.with_exit_code(1)
46+
<< "failed to open input file `" << filename << "'";
5347

5448
auto language = get_language_from_filename(filename);
5549

5650
if(language == nullptr)
5751
{
5852
source_locationt location;
5953
location.set_file(filename);
60-
message.error().source_location = location;
61-
message.error() << "failed to figure out type of file" << messaget::eom;
62-
return 1;
54+
throw ebmc_errort{}.with_location(location).with_exit_code(1)
55+
<< "failed to figure out type of file";
6356
}
6457

6558
optionst options;
@@ -77,12 +70,7 @@ int preprocess(const cmdlinet &cmdline, message_handlert &message_handler)
7770
language->set_language_options(options, message_handler);
7871

7972
if(language->preprocess(infile, filename, std::cout, message_handler))
80-
{
81-
message.error() << "PREPROCESSING FAILED" << messaget::eom;
82-
return 1;
83-
}
84-
85-
return 0;
73+
throw ebmc_errort{}.with_exit_code(1) << "PREPROCESSING FAILED";
8674
}
8775

8876
static bool parse(
@@ -211,9 +199,6 @@ int get_transition_system(
211199
{
212200
messaget message(message_handler);
213201

214-
if(cmdline.isset("preprocess"))
215-
return preprocess(cmdline, message_handler);
216-
217202
//
218203
// parsing
219204
//
@@ -349,3 +334,40 @@ int show_symbol_table(
349334
return get_transition_system(
350335
cmdline, message_handler, dummy_transition_system);
351336
}
337+
338+
std::optional<transition_systemt> ebmc_languagest::transition_system()
339+
{
340+
if(cmdline.isset("preprocess"))
341+
{
342+
preprocess(cmdline, message_handler);
343+
return {};
344+
}
345+
346+
if(cmdline.isset("show-parse"))
347+
{
348+
show_parse(cmdline, message_handler);
349+
return {};
350+
}
351+
352+
if(
353+
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
354+
cmdline.isset("json-modules"))
355+
{
356+
show_modules(cmdline, message_handler);
357+
return {};
358+
}
359+
360+
if(cmdline.isset("show-module-hierarchy"))
361+
{
362+
show_module_hierarchy(cmdline, message_handler);
363+
return {};
364+
}
365+
366+
if(cmdline.isset("show-symbol-table"))
367+
{
368+
show_symbol_table(cmdline, message_handler);
369+
return {};
370+
}
371+
372+
return get_transition_system(cmdline, message_handler);
373+
}

src/ebmc/build_transition_system.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,25 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H
1010
#define CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H
1111

12-
class cmdlinet;
13-
class message_handlert;
14-
class transition_systemt;
12+
#include "ebmc_language.h"
1513

1614
transition_systemt get_transition_system(const cmdlinet &, message_handlert &);
1715

18-
int preprocess(const cmdlinet &, message_handlert &);
16+
void preprocess(const cmdlinet &, message_handlert &);
1917
int show_parse(const cmdlinet &, message_handlert &);
2018
int show_modules(const cmdlinet &, message_handlert &);
2119
int show_module_hierarchy(const cmdlinet &, message_handlert &);
2220
int show_symbol_table(const cmdlinet &, message_handlert &);
2321

22+
class ebmc_languagest : public ebmc_languaget
23+
{
24+
public:
25+
ebmc_languagest(cmdlinet &_cmdline, message_handlert &_message_handler)
26+
: ebmc_languaget{_cmdline, _message_handler}
27+
{
28+
}
29+
30+
std::optional<transition_systemt> transition_system() override;
31+
};
32+
2433
#endif // CPROVER_EBMC_BUILD_TRANSITION_SYSTEM_H

src/ebmc/ebmc_language.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define EBMC_LANGUAGE_H
1414

1515
#include <iosfwd>
16+
#include <optional>
1617

1718
class cmdlinet;
1819
class message_handlert;
@@ -29,11 +30,9 @@ class ebmc_languaget
2930

3031
virtual ~ebmc_languaget();
3132

32-
/// produce diagnostic output as specified on the command line
33-
virtual void diagnostics() = 0;
34-
35-
/// produce the transition system, and return it
36-
virtual transition_systemt transition_system() = 0;
33+
/// Produce the transition system, and return it;
34+
/// returns {} when diagnostic output was produced instead.
35+
virtual std::optional<transition_systemt> transition_system() = 0;
3736

3837
protected:
3938
cmdlinet &cmdline;

src/ebmc/ebmc_parse_options.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919
#include "diatest.h"
2020
#include "ebmc_base.h"
2121
#include "ebmc_error.h"
22+
#include "ebmc_language.h"
2223
#include "ebmc_version.h"
2324
#include "format_hooks.h"
2425
#include "instrument_buechi.h"
@@ -108,23 +109,6 @@ int ebmc_parse_optionst::doit()
108109
return 0;
109110
}
110111

111-
if(cmdline.isset("preprocess"))
112-
return preprocess(cmdline, ui_message_handler);
113-
114-
if(cmdline.isset("show-parse"))
115-
return show_parse(cmdline, ui_message_handler);
116-
117-
if(
118-
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
119-
cmdline.isset("json-modules"))
120-
return show_modules(cmdline, ui_message_handler);
121-
122-
if(cmdline.isset("show-module-hierarchy"))
123-
return show_module_hierarchy(cmdline, ui_message_handler);
124-
125-
if(cmdline.isset("show-symbol-table"))
126-
return show_symbol_table(cmdline, ui_message_handler);
127-
128112
if(cmdline.isset("coverage"))
129113
{
130114
throw ebmc_errort() << "This option is currently disabled";
@@ -208,7 +192,15 @@ int ebmc_parse_optionst::doit()
208192
}
209193

210194
// get the transition system
211-
auto transition_system = get_transition_system(cmdline, ui_message_handler);
195+
ebmc_languagest ebmc_languages{cmdline, ui_message_handler};
196+
197+
auto transition_system_opt = ebmc_languages.transition_system();
198+
199+
// Did we produce diagnostics instead?
200+
if(!transition_system_opt.has_value())
201+
return 0;
202+
203+
auto &transition_system = transition_system_opt.value();
212204

213205
// get the properties
214206
auto properties = ebmc_propertiest::from_command_line(

0 commit comments

Comments
 (0)