Skip to content

Commit 06afe80

Browse files
authored
Merge pull request #6220 from martin-cs/refactor/virtual_register_languages
Refactor/virtual register languages
2 parents e6f6970 + 021116b commit 06afe80

16 files changed

+84
-34
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ class optionst;
154154
class janalyzer_parse_optionst : public parse_options_baset
155155
{
156156
public:
157-
virtual int doit() override;
158-
virtual void help() override;
157+
int doit() override;
158+
void help() override;
159159

160160
janalyzer_parse_optionst(int argc, const char **argv);
161161

@@ -177,7 +177,7 @@ class janalyzer_parse_optionst : public parse_options_baset
177177
protected:
178178
std::unique_ptr<class_hierarchyt> class_hierarchy;
179179

180-
void register_languages();
180+
void register_languages() override;
181181

182182
void get_command_line_options(optionst &options);
183183

jbmc/src/jdiff/jdiff_parse_options.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class goto_modelt;
4242
class jdiff_parse_optionst : public parse_options_baset
4343
{
4444
public:
45-
virtual int doit();
46-
virtual void help();
45+
int doit() override;
46+
void help() override;
4747

4848
jdiff_parse_optionst(int argc, const char **argv);
4949

5050
protected:
51-
void register_languages();
51+
void register_languages() override;
5252

5353
void get_command_line_options(optionst &options);
5454

src/cbmc/cbmc_parse_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class cbmc_parse_optionst : public parse_options_baset
114114
protected:
115115
goto_modelt goto_model;
116116

117-
void register_languages();
117+
void register_languages() override;
118118
void get_command_line_options(optionst &);
119119
void preprocessing(const optionst &);
120120
bool set_properties();

src/goto-analyzer/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
SRC = goto_analyzer_main.cpp \
1+
SRC = goto_analyzer_languages.cpp \
2+
goto_analyzer_main.cpp \
23
goto_analyzer_parse_options.cpp \
34
taint_analysis.cpp \
45
taint_parser.cpp \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************\
2+
3+
Module: Language Registration
4+
5+
Author: Martin Brain, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Language Registration
11+
12+
#include "goto_analyzer_parse_options.h"
13+
14+
#include <langapi/mode.h>
15+
16+
#include <ansi-c/ansi_c_language.h>
17+
#include <cpp/cpp_language.h>
18+
19+
#ifdef HAVE_JSIL
20+
# include <jsil/jsil_language.h>
21+
#endif
22+
23+
void goto_analyzer_parse_optionst::register_languages()
24+
{
25+
register_language(new_ansi_c_language);
26+
register_language(new_cpp_language);
27+
28+
#ifdef HAVE_JSIL
29+
register_language(new_jsil_language);
30+
#endif
31+
}

src/goto-analyzer/goto_analyzer_parse_options.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ Author: Daniel Kroening, [email protected]
1616
#include <iostream>
1717
#include <memory>
1818

19-
#include <ansi-c/ansi_c_language.h>
2019
#include <ansi-c/cprover_library.h>
2120

2221
#include <assembler/remove_asm.h>
2322

24-
#include <cpp/cpp_language.h>
2523
#include <cpp/cprover_library.h>
2624

27-
#include <jsil/jsil_language.h>
28-
2925
#include <goto-programs/add_malloc_may_fail_variable_initializations.h>
3026
#include <goto-programs/initialize_goto_model.h>
3127
#include <goto-programs/link_to_library.h>
@@ -37,9 +33,6 @@ Author: Daniel Kroening, [email protected]
3733
#include <analyses/ai.h>
3834
#include <analyses/local_may_alias.h>
3935

40-
#include <langapi/mode.h>
41-
#include <langapi/language.h>
42-
4336
#include <util/config.h>
4437
#include <util/exception_utils.h>
4538
#include <util/exit_codes.h>
@@ -65,13 +58,6 @@ goto_analyzer_parse_optionst::goto_analyzer_parse_optionst(
6558
{
6659
}
6760

68-
void goto_analyzer_parse_optionst::register_languages()
69-
{
70-
register_language(new_ansi_c_language);
71-
register_language(new_cpp_language);
72-
register_language(new_jsil_language);
73-
}
74-
7561
void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
7662
{
7763
if(config.set(cmdline))

src/goto-analyzer/goto_analyzer_parse_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class goto_analyzer_parse_optionst: public parse_options_baset
183183
protected:
184184
goto_modelt goto_model;
185185

186-
virtual void register_languages();
186+
void register_languages() override;
187187

188188
virtual void get_command_line_options(optionst &options);
189189

src/goto-cc/goto_cc_languages.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ Author: CM Wintersteiger
1515

1616
#include <ansi-c/ansi_c_language.h>
1717
#include <cpp/cpp_language.h>
18-
#include <jsil/jsil_language.h>
18+
19+
#ifdef HAVE_JSIL
20+
# include <jsil/jsil_language.h>
21+
#endif
1922

2023
void goto_cc_modet::register_languages()
2124
{
2225
register_language(new_ansi_c_language);
2326
register_language(new_cpp_language);
27+
28+
#ifdef HAVE_JSIL
2429
register_language(new_jsil_language);
30+
#endif
2531
}

src/goto-diff/goto_diff_parse_options.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class optionst;
4343
class goto_diff_parse_optionst : public parse_options_baset
4444
{
4545
public:
46-
virtual int doit();
47-
virtual void help();
46+
int doit() override;
47+
void help() override;
4848

4949
goto_diff_parse_optionst(int argc, const char **argv);
5050

5151
protected:
52-
void register_languages();
52+
void register_languages() override;
5353

5454
void get_command_line_options(optionst &options);
5555

src/goto-harness/goto_harness_parse_options.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ int goto_harness_parse_optionst::doit()
108108
// This just sets up the defaults (and would interpret options such as --32).
109109
config.set(cmdline);
110110

111+
// Normally we would register language front-ends here but as goto-harness
112+
// only works on goto binaries, we don't need to
113+
111114
// Read goto binary into goto-model
112115
auto read_goto_binary_result =
113116
read_goto_binary(got_harness_config.in_file, ui_message_handler);

src/goto-instrument/goto_instrument_parse_options.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ Author: Daniel Kroening, [email protected]
129129
class goto_instrument_parse_optionst : public parse_options_baset
130130
{
131131
public:
132-
virtual int doit();
133-
virtual void help();
132+
int doit() override;
133+
void help() override;
134134

135135
goto_instrument_parse_optionst(int argc, const char **argv)
136136
: parse_options_baset(
@@ -145,7 +145,7 @@ class goto_instrument_parse_optionst : public parse_options_baset
145145
}
146146

147147
protected:
148-
void register_languages();
148+
void register_languages() override;
149149

150150
void get_goto_program();
151151
void instrument_goto_program();

src/memory-analyzer/memory_analyzer_parse_options.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ memory_analyzer_parse_optionst::memory_analyzer_parse_optionst(
4242
{
4343
}
4444

45+
void memory_analyzer_parse_optionst::register_languages()
46+
{
47+
// For now only C is supported due to the additional challenges of
48+
// mapping source code to debugging symbols in other languages.
49+
register_language(new_ansi_c_language);
50+
}
51+
4552
int memory_analyzer_parse_optionst::doit()
4653
{
4754
if(cmdline.isset("version"))
@@ -91,7 +98,7 @@ int memory_analyzer_parse_optionst::doit()
9198
"--symtab-snapshot");
9299
}
93100

94-
register_language(new_ansi_c_language);
101+
register_languages();
95102

96103
std::string binary = cmdline.args.front();
97104

src/memory-analyzer/memory_analyzer_parse_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class memory_analyzer_parse_optionst : public parse_options_baset
3737

3838
protected:
3939
messaget message;
40+
41+
void register_languages() override;
4042
};
4143

4244
#endif // CPROVER_MEMORY_ANALYZER_MEMORY_ANALYZER_PARSE_OPTIONS_H

src/symtab2gb/symtab2gb_parse_options.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ static void run_symtab2gb(
9696
}
9797
}
9898

99+
void symtab2gb_parse_optionst::register_languages()
100+
{
101+
// As this is a converter and linker it only really needs to support
102+
// the JSON symtab front-end.
103+
register_language(new_json_symtab_language);
104+
// Workaround to allow external front-ends to use "C" mode
105+
register_language(new_ansi_c_language);
106+
}
107+
99108
int symtab2gb_parse_optionst::doit()
100109
{
101110
if(cmdline.isset("version"))
@@ -114,9 +123,7 @@ int symtab2gb_parse_optionst::doit()
114123
{
115124
gb_filename = cmdline.get_value(SYMTAB2GB_OUT_FILE_OPT);
116125
}
117-
register_language(new_json_symtab_language);
118-
// Workaround to allow external front-ends to use "C" mode
119-
register_language(new_ansi_c_language);
126+
register_languages();
120127
config.set(cmdline);
121128
run_symtab2gb(symtab_filenames, gb_filename);
122129
return CPROVER_EXIT_SUCCESS;

src/symtab2gb/symtab2gb_parse_options.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class symtab2gb_parse_optionst : public parse_options_baset
2727
symtab2gb_parse_optionst(int argc, const char *argv[]);
2828
void help() override;
2929
int doit() override;
30+
31+
protected:
32+
void register_languages() override;
3033
};
3134

3235
#endif // CPROVER_SYMTAB2GB_SYMTAB2GB_PARSE_OPTIONS_H

src/util/parse_options.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class parse_options_baset
4545
ui_message_handlert ui_message_handler;
4646
messaget log;
4747

48+
virtual void register_languages()
49+
{
50+
}
51+
4852
private:
4953
void unknown_option_msg();
5054
};

0 commit comments

Comments
 (0)