-
Notifications
You must be signed in to change notification settings - Fork 273
Merge in feature branch that adds gnat2goto compatibility #3112
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ set_target_properties( | |
goto-symex | ||
jsil | ||
json | ||
json-symtab-language | ||
langapi | ||
linking | ||
pointer-analysis | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ add_subdirectory(goto-programs) | |
add_subdirectory(goto-symex) | ||
add_subdirectory(jsil) | ||
add_subdirectory(json) | ||
add_subdirectory(json-symtab-language) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong commit. |
||
add_subdirectory(langapi) | ||
add_subdirectory(linking) | ||
add_subdirectory(pointer-analysis) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ target_link_libraries(cbmc-lib | |
goto-programs | ||
goto-symex | ||
json | ||
json-symtab-language | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong commit |
||
langapi | ||
linking | ||
pointer-analysis | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <ansi-c/ansi_c_language.h> | ||
#include <cpp/cpp_language.h> | ||
#include <json-symtab-language/json_symtab_language.h> | ||
|
||
#ifdef HAVE_JSIL | ||
#include <jsil/jsil_language.h> | ||
|
@@ -24,8 +25,9 @@ void cbmc_parse_optionst::register_languages() | |
{ | ||
register_language(new_ansi_c_language); | ||
register_language(new_cpp_language); | ||
register_language(new_json_symtab_language); | ||
|
||
#ifdef HAVE_JSIL | ||
#ifdef HAVE_JSIL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: Don't do this whitespace change, or if you have to, make sure you also adjust the matching |
||
register_language(new_jsil_language); | ||
#endif | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
file(GLOB_RECURSE sources "*.cpp" "*.h") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong commit. |
||
add_library(json-symtab-language ${sources}) | ||
|
||
generic_includes(json-symtab-language) | ||
|
||
target_link_libraries(json-symtab-language json util) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
SRC = json_symtab_language.cpp \ | ||
json_symbol_table.cpp \ | ||
json_symbol.cpp | ||
|
||
INCLUDES= -I .. | ||
|
||
include ../config.inc | ||
include ../common | ||
|
||
CLEANFILES = json-symtab-language$(LIBEXT) | ||
|
||
all: json-symtab-language$(LIBEXT) | ||
|
||
############################################################################### | ||
|
||
json-symtab-language$(LIBEXT): $(OBJ) | ||
$(LINKLIB) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/*******************************************************************\ | ||
|
||
Module: JSON symbol deserialization | ||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "json_symbol.h" | ||
|
||
#include <util/exception_utils.h> | ||
#include <util/expr.h> | ||
#include <util/json_irep.h> | ||
#include <util/source_location.h> | ||
#include <util/type.h> | ||
|
||
/// Return string value for a given key if present in the json object. | ||
/// \param in: The json object that is getting fetched as a string. | ||
/// \param key: The key for the json value to be fetched. | ||
/// \return: A string value for the corresponding key. | ||
static const std::string & | ||
try_get_string(const jsont &in, const std::string &key) | ||
{ | ||
if(!in.is_string()) | ||
throw deserialization_exceptiont( | ||
"symbol_from_json: expected string for key '" + key + "'"); | ||
return in.value; | ||
} | ||
|
||
/// Return boolean value for a given key if present in the json object. | ||
/// \param in: The json object that is getting fetched as a boolean. | ||
/// \param key: The key for the json value to be fetched. | ||
/// \return: A boolean value for the corresponding key. | ||
static bool try_get_bool(const jsont &in, const std::string &key) | ||
{ | ||
if(!(in.is_true() || in.is_false())) | ||
throw deserialization_exceptiont( | ||
"symbol_from_json: expected bool for key '" + key + "'"); | ||
return in.is_true(); | ||
} | ||
|
||
/// Deserialise a json object to a symbolt. | ||
/// \param in: The json object that is getting fetched as an object. | ||
/// \return: A symbolt representing the json object. | ||
symbolt symbol_from_json(const jsont &in) | ||
{ | ||
if(!in.is_object()) | ||
throw deserialization_exceptiont("symbol_from_json takes an object"); | ||
symbolt result; | ||
json_irept json2irep(true); | ||
for(const auto &kv : in.object) | ||
{ | ||
if(kv.first == "type") | ||
{ | ||
irept irep = json2irep.convert_from_json(kv.second); | ||
result.type = static_cast<typet &>(irep); | ||
} | ||
else if(kv.first == "value") | ||
{ | ||
irept irep = json2irep.convert_from_json(kv.second); | ||
result.value = static_cast<exprt &>(irep); | ||
} | ||
else if(kv.first == "location") | ||
{ | ||
irept irep = json2irep.convert_from_json(kv.second); | ||
result.location = static_cast<source_locationt &>(irep); | ||
} | ||
else if(kv.first == "name") | ||
result.name = try_get_string(kv.second, "name"); | ||
else if(kv.first == "module") | ||
result.module = try_get_string(kv.second, "module"); | ||
else if(kv.first == "base_name") | ||
result.base_name = try_get_string(kv.second, "base_name"); | ||
else if(kv.first == "mode") | ||
result.mode = try_get_string(kv.second, "mode"); | ||
else if(kv.first == "pretty_name") | ||
result.pretty_name = try_get_string(kv.second, "pretty_name"); | ||
else if(kv.first == "is_type") | ||
result.is_type = try_get_bool(kv.second, "is_type"); | ||
else if(kv.first == "is_macro") | ||
result.is_macro = try_get_bool(kv.second, "is_macro"); | ||
else if(kv.first == "is_exported") | ||
result.is_exported = try_get_bool(kv.second, "is_exported"); | ||
else if(kv.first == "is_input") | ||
result.is_input = try_get_bool(kv.second, "is_input"); | ||
else if(kv.first == "is_output") | ||
result.is_output = try_get_bool(kv.second, "is_output"); | ||
else if(kv.first == "is_state_var") | ||
result.is_state_var = try_get_bool(kv.second, "is_state_var"); | ||
else if(kv.first == "is_property") | ||
result.is_property = try_get_bool(kv.second, "is_property"); | ||
else if(kv.first == "is_static_lifetime") | ||
result.is_static_lifetime = try_get_bool(kv.second, "is_static_lifetime"); | ||
else if(kv.first == "is_thread_local") | ||
result.is_thread_local = try_get_bool(kv.second, "is_thread_local"); | ||
else if(kv.first == "is_lvalue") | ||
result.is_lvalue = try_get_bool(kv.second, "is_lvalue"); | ||
else if(kv.first == "is_file_local") | ||
result.is_file_local = try_get_bool(kv.second, "is_file_local"); | ||
else if(kv.first == "is_extern") | ||
result.is_extern = try_get_bool(kv.second, "is_extern"); | ||
else if(kv.first == "is_volatile") | ||
result.is_volatile = try_get_bool(kv.second, "is_volatile"); | ||
else if(kv.first == "is_parameter") | ||
result.is_parameter = try_get_bool(kv.second, "is_parameter"); | ||
else if(kv.first == "is_auxiliary") | ||
result.is_auxiliary = try_get_bool(kv.second, "is_auxiliary"); | ||
else if(kv.first == "is_weak") | ||
result.is_weak = try_get_bool(kv.second, "is_weak"); | ||
else | ||
throw deserialization_exceptiont( | ||
"symbol_from_json: unexpected key '" + kv.first + "'"); | ||
} | ||
|
||
return result; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*******************************************************************\ | ||
|
||
Module: JSON symbol deserialization | ||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_JSON_SYMTAB_LANGUAGE_JSON_SYMBOL_H | ||
#define CPROVER_JSON_SYMTAB_LANGUAGE_JSON_SYMBOL_H | ||
|
||
#include <util/json.h> | ||
#include <util/symbol.h> | ||
|
||
symbolt symbol_from_json(const jsont &); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*******************************************************************\ | ||
|
||
Module: JSON symbol table deserialization | ||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "json_symbol_table.h" | ||
#include "json_symbol.h" | ||
|
||
#include <util/exception_utils.h> | ||
#include <util/json.h> | ||
#include <util/symbol_table.h> | ||
|
||
void symbol_table_from_json(const jsont &in, symbol_tablet &symbol_table) | ||
{ | ||
if(!in.is_array()) | ||
throw deserialization_exceptiont( | ||
"symbol_table_from_json: JSON input must be an array"); | ||
for(const auto &js_symbol : in.array) | ||
{ | ||
symbolt deserialized = symbol_from_json(js_symbol); | ||
if(symbol_table.add(deserialized)) | ||
throw deserialization_exceptiont( | ||
"symbol_table_from_json: duplicate symbol name '" + | ||
id2string(deserialized.name) + "'"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*******************************************************************\ | ||
|
||
Module: JSON symbol table deserialization | ||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_JSON_SYMTAB_LANGUAGE_JSON_SYMBOL_TABLE_H | ||
#define CPROVER_JSON_SYMTAB_LANGUAGE_JSON_SYMBOL_TABLE_H | ||
|
||
class jsont; | ||
class symbol_tablet; | ||
|
||
void symbol_table_from_json(const jsont &, symbol_tablet &); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now have rvalues! Return that symbol_table! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you suggest to manually construct and populate the symbol table from within the function? That does make sense, but it's not very convenient, because the symbol table is constructed much earlier in the call stack, and it's in the interface of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the symbol table that gets passed to json_symtab_languaget::typecheck is expected to be empty; so you can simply overwrite. |
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*******************************************************************\ | ||
|
||
Module: JSON symbol table language. Accepts a JSON format symbol | ||
table that has been produced out-of-process, e.g. by using | ||
a compiler's front-end. | ||
|
||
Author: Chris Smowton, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "json_symtab_language.h" | ||
#include "json_symbol_table.h" | ||
#include <json/json_parser.h> | ||
#include <util/namespace.h> | ||
|
||
/// Parse a goto program in json form. | ||
/// \param instream: The input stream | ||
/// \param path: A file path | ||
/// \return: boolean signifying success or failure of the parsing | ||
bool json_symtab_languaget::parse( | ||
std::istream &instream, | ||
const std::string &path) | ||
{ | ||
return parse_json(instream, path, get_message_handler(), parsed_json_file); | ||
} | ||
|
||
/// Typecheck a goto program in json form. | ||
/// \param symbol_table: The symbol table containing symbols read from file. | ||
/// \param module: A useless parameter, there for interface consistency. | ||
/// \return: boolean signifying success or failure of the typechecking. | ||
bool json_symtab_languaget::typecheck( | ||
symbol_tablet &symbol_table, | ||
const std::string &module) | ||
{ | ||
try | ||
{ | ||
symbol_table_from_json(parsed_json_file, symbol_table); | ||
return false; | ||
} | ||
catch(const std::string &str) | ||
{ | ||
error() << "typecheck: " << str << eom; | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't announce the class where errors happen elsewhere, so I'd remove here for consistency. |
||
} | ||
} | ||
|
||
/// Output the result of the parsed json file to the output stream | ||
/// passed as a parameter to this function. | ||
/// \param out: The stream to use to output the parsed_json_file. | ||
void json_symtab_languaget::show_parse(std::ostream &out) | ||
{ | ||
parsed_json_file.output(out); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be in the wrong commit.