Skip to content

Refactor/virtual register languages #6220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jbmc/src/janalyzer/janalyzer_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class optionst;
class janalyzer_parse_optionst : public parse_options_baset
{
public:
virtual int doit() override;
virtual void help() override;
int doit() override;
void help() override;

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

Expand All @@ -177,7 +177,7 @@ class janalyzer_parse_optionst : public parse_options_baset
protected:
std::unique_ptr<class_hierarchyt> class_hierarchy;

void register_languages();
void register_languages() override;

void get_command_line_options(optionst &options);

Expand Down
6 changes: 3 additions & 3 deletions jbmc/src/jdiff/jdiff_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class goto_modelt;
class jdiff_parse_optionst : public parse_options_baset
{
public:
virtual int doit();
virtual void help();
int doit() override;
void help() override;

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

protected:
void register_languages();
void register_languages() override;

void get_command_line_options(optionst &options);

Expand Down
2 changes: 1 addition & 1 deletion src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class cbmc_parse_optionst : public parse_options_baset
protected:
goto_modelt goto_model;

void register_languages();
void register_languages() override;
void get_command_line_options(optionst &);
void preprocessing(const optionst &);
bool set_properties();
Expand Down
3 changes: 2 additions & 1 deletion src/goto-analyzer/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SRC = goto_analyzer_main.cpp \
SRC = goto_analyzer_languages.cpp \
goto_analyzer_main.cpp \
goto_analyzer_parse_options.cpp \
taint_analysis.cpp \
taint_parser.cpp \
Expand Down
31 changes: 31 additions & 0 deletions src/goto-analyzer/goto_analyzer_languages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************\

Module: Language Registration

Author: Martin Brain, [email protected]

\*******************************************************************/

/// \file
/// Language Registration

#include "goto_analyzer_parse_options.h"

#include <langapi/mode.h>

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

#ifdef HAVE_JSIL
# include <jsil/jsil_language.h>
#endif

void goto_analyzer_parse_optionst::register_languages()
{
register_language(new_ansi_c_language);
register_language(new_cpp_language);

#ifdef HAVE_JSIL
register_language(new_jsil_language);
#endif
}
14 changes: 0 additions & 14 deletions src/goto-analyzer/goto_analyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ Author: Daniel Kroening, [email protected]
#include <iostream>
#include <memory>

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

#include <assembler/remove_asm.h>

#include <cpp/cpp_language.h>
#include <cpp/cprover_library.h>

#include <jsil/jsil_language.h>

#include <goto-programs/add_malloc_may_fail_variable_initializations.h>
#include <goto-programs/initialize_goto_model.h>
#include <goto-programs/link_to_library.h>
Expand All @@ -37,9 +33,6 @@ Author: Daniel Kroening, [email protected]
#include <analyses/ai.h>
#include <analyses/local_may_alias.h>

#include <langapi/mode.h>
#include <langapi/language.h>

#include <util/config.h>
#include <util/exception_utils.h>
#include <util/exit_codes.h>
Expand All @@ -65,13 +58,6 @@ goto_analyzer_parse_optionst::goto_analyzer_parse_optionst(
{
}

void goto_analyzer_parse_optionst::register_languages()
{
register_language(new_ansi_c_language);
register_language(new_cpp_language);
register_language(new_jsil_language);
}

void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
{
if(config.set(cmdline))
Expand Down
2 changes: 1 addition & 1 deletion src/goto-analyzer/goto_analyzer_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class goto_analyzer_parse_optionst: public parse_options_baset
protected:
goto_modelt goto_model;

virtual void register_languages();
void register_languages() override;

virtual void get_command_line_options(optionst &options);

Expand Down
8 changes: 7 additions & 1 deletion src/goto-cc/goto_cc_languages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ Author: CM Wintersteiger

#include <ansi-c/ansi_c_language.h>
#include <cpp/cpp_language.h>
#include <jsil/jsil_language.h>

#ifdef HAVE_JSIL
# include <jsil/jsil_language.h>
#endif

void goto_cc_modet::register_languages()
{
register_language(new_ansi_c_language);
register_language(new_cpp_language);

#ifdef HAVE_JSIL
register_language(new_jsil_language);
#endif
}
6 changes: 3 additions & 3 deletions src/goto-diff/goto_diff_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class optionst;
class goto_diff_parse_optionst : public parse_options_baset
{
public:
virtual int doit();
virtual void help();
int doit() override;
void help() override;

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

protected:
void register_languages();
void register_languages() override;

void get_command_line_options(optionst &options);

Expand Down
3 changes: 3 additions & 0 deletions src/goto-harness/goto_harness_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ int goto_harness_parse_optionst::doit()
// This just sets up the defaults (and would interpret options such as --32).
config.set(cmdline);

// Normally we would register language front-ends here but as goto-harness
// only works on goto binaries, we don't need to

// Read goto binary into goto-model
auto read_goto_binary_result =
read_goto_binary(got_harness_config.in_file, ui_message_handler);
Expand Down
6 changes: 3 additions & 3 deletions src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ Author: Daniel Kroening, [email protected]
class goto_instrument_parse_optionst : public parse_options_baset
{
public:
virtual int doit();
virtual void help();
int doit() override;
void help() override;

goto_instrument_parse_optionst(int argc, const char **argv)
: parse_options_baset(
Expand All @@ -145,7 +145,7 @@ class goto_instrument_parse_optionst : public parse_options_baset
}

protected:
void register_languages();
void register_languages() override;

void get_goto_program();
void instrument_goto_program();
Expand Down
9 changes: 8 additions & 1 deletion src/memory-analyzer/memory_analyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ memory_analyzer_parse_optionst::memory_analyzer_parse_optionst(
{
}

void memory_analyzer_parse_optionst::register_languages()
{
// For now only C is supported due to the additional challenges of
// mapping source code to debugging symbols in other languages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a reference to a GitHub issue here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know there was one! I'll have a look...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not immediately finding one; if you had one in mind can you post a link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the chasing of the geese that are wild (positively livid...), I sort of half-assumed this was referring to the tickets discussing possible refactorings around languaget and modes - but I realise now I mis-read this comment.

register_language(new_ansi_c_language);
}

int memory_analyzer_parse_optionst::doit()
{
if(cmdline.isset("version"))
Expand Down Expand Up @@ -91,7 +98,7 @@ int memory_analyzer_parse_optionst::doit()
"--symtab-snapshot");
}

register_language(new_ansi_c_language);
register_languages();

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

Expand Down
2 changes: 2 additions & 0 deletions src/memory-analyzer/memory_analyzer_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class memory_analyzer_parse_optionst : public parse_options_baset

protected:
messaget message;

void register_languages() override;
};

#endif // CPROVER_MEMORY_ANALYZER_MEMORY_ANALYZER_PARSE_OPTIONS_H
13 changes: 10 additions & 3 deletions src/symtab2gb/symtab2gb_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ static void run_symtab2gb(
}
}

void symtab2gb_parse_optionst::register_languages()
{
// As this is a converter and linker it only really needs to support
// the JSON symtab front-end.
register_language(new_json_symtab_language);
// Workaround to allow external front-ends to use "C" mode
register_language(new_ansi_c_language);
}

int symtab2gb_parse_optionst::doit()
{
if(cmdline.isset("version"))
Expand All @@ -114,9 +123,7 @@ int symtab2gb_parse_optionst::doit()
{
gb_filename = cmdline.get_value(SYMTAB2GB_OUT_FILE_OPT);
}
register_language(new_json_symtab_language);
// Workaround to allow external front-ends to use "C" mode
register_language(new_ansi_c_language);
register_languages();
config.set(cmdline);
run_symtab2gb(symtab_filenames, gb_filename);
return CPROVER_EXIT_SUCCESS;
Expand Down
3 changes: 3 additions & 0 deletions src/symtab2gb/symtab2gb_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class symtab2gb_parse_optionst : public parse_options_baset
symtab2gb_parse_optionst(int argc, const char *argv[]);
void help() override;
int doit() override;

protected:
void register_languages() override;
};

#endif // CPROVER_SYMTAB2GB_SYMTAB2GB_PARSE_OPTIONS_H
4 changes: 4 additions & 0 deletions src/util/parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class parse_options_baset
ui_message_handlert ui_message_handler;
messaget log;

virtual void register_languages()
{
}

private:
void unknown_option_msg();
};
Expand Down