-
Notifications
You must be signed in to change notification settings - Fork 17
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
SMV: set pretty names for top-level identifiers #452
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,21 @@ Author: Daniel Kroening, [email protected] | |
|
||
\*******************************************************************/ | ||
|
||
#include <cstring> | ||
#include "expr2smv.h" | ||
|
||
#include <util/lispexpr.h> | ||
#include <util/lispirep.h> | ||
#include <util/namespace.h> | ||
#include <util/std_expr.h> | ||
|
||
#include "expr2smv.h" | ||
#include <util/symbol.h> | ||
|
||
class expr2smvt | ||
{ | ||
public: | ||
explicit expr2smvt(const namespacet &__ns) : ns(__ns) | ||
{ | ||
} | ||
|
||
bool convert_nondet_choice(const exprt &src, std::string &dest, unsigned precedence); | ||
|
||
bool convert_binary(const exprt &src, std::string &dest, const std::string &symbol, unsigned precedence); | ||
|
@@ -34,7 +38,8 @@ class expr2smvt | |
|
||
bool convert(const exprt &src, std::string &dest); | ||
|
||
bool convert_symbol(const exprt &src, std::string &dest, unsigned &precedence); | ||
bool | ||
convert_symbol(const symbol_exprt &, std::string &dest, unsigned &precedence); | ||
|
||
bool convert_next_symbol(const exprt &src, std::string &dest, unsigned &precedence); | ||
|
||
|
@@ -45,6 +50,9 @@ class expr2smvt | |
bool convert_norep(const exprt &src, std::string &dest, unsigned &precedence); | ||
|
||
bool convert(const typet &src, std::string &dest); | ||
|
||
protected: | ||
const namespacet &ns; | ||
}; | ||
|
||
/* | ||
|
@@ -312,15 +320,15 @@ Function: expr2smvt::convert_symbol | |
\*******************************************************************/ | ||
|
||
bool expr2smvt::convert_symbol( | ||
const exprt &src, | ||
const symbol_exprt &src, | ||
std::string &dest, | ||
unsigned &precedence) | ||
{ | ||
precedence=SMV_MAX_PRECEDENCE; | ||
dest=src.get_string(ID_identifier); | ||
|
||
if(strncmp(dest.c_str(), "smv::", 5)==0) | ||
dest.erase(0, 5); | ||
|
||
auto &symbol = ns.lookup(src); | ||
|
||
dest = id2string(symbol.display_name()); | ||
|
||
return false; | ||
} | ||
|
@@ -343,7 +351,8 @@ bool expr2smvt::convert_next_symbol( | |
unsigned &precedence) | ||
{ | ||
std::string tmp; | ||
convert_symbol(src, tmp, precedence); | ||
convert_symbol( | ||
symbol_exprt{src.get(ID_identifier), src.type()}, tmp, precedence); | ||
|
||
dest="next("+tmp+")"; | ||
|
||
|
@@ -468,7 +477,7 @@ bool expr2smvt::convert( | |
to_unary_expr(src), dest, src.id_string() + " ", precedence = 7); | ||
|
||
else if(src.id()==ID_symbol) | ||
return convert_symbol(src, dest, precedence); | ||
return convert_symbol(to_symbol_expr(src), dest, precedence); | ||
|
||
else if(src.id()==ID_next_symbol) | ||
return convert_next_symbol(src, dest, precedence); | ||
|
@@ -527,9 +536,9 @@ Function: expr2smv | |
|
||
\*******************************************************************/ | ||
|
||
bool expr2smv(const exprt &expr, std::string &code) | ||
bool expr2smv(const exprt &expr, std::string &code, const namespacet &ns) | ||
{ | ||
expr2smvt expr2smv; | ||
expr2smvt expr2smv(ns); | ||
return expr2smv.convert(expr, code); | ||
} | ||
|
||
|
@@ -545,14 +554,14 @@ Function: type2smv | |
|
||
\*******************************************************************/ | ||
|
||
bool type2smv(const typet &type, std::string &code) | ||
bool type2smv(const typet &type, std::string &code, const namespacet &ns) | ||
{ | ||
if(type.id()==ID_bool) | ||
code="boolean"; | ||
else if(type.id()==ID_array) | ||
{ | ||
std::string tmp; | ||
if(type2smv(to_array_type(type).element_type(), tmp)) | ||
if(type2smv(to_array_type(type).element_type(), tmp, ns)) | ||
return true; | ||
code="array "; | ||
code+=".."; | ||
|
@@ -587,7 +596,7 @@ bool type2smv(const typet &type, std::string &code) | |
{ | ||
if(first) first=false; else code+=", "; | ||
std::string tmp; | ||
expr2smv(*it, tmp); | ||
expr2smv(*it, tmp, ns); | ||
code+=tmp; | ||
} | ||
code+=')'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,5 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/expr.h> | ||
|
||
bool expr2smv(const exprt &expr, std::string &code); | ||
bool type2smv(const typet &type, std::string &code); | ||
|
||
bool expr2smv(const exprt &, std::string &code, const namespacet &); | ||
bool type2smv(const typet &, std::string &code, const namespacet &); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ Author: Daniel Kroening, [email protected] | |
\*******************************************************************/ | ||
|
||
#include "smv_language.h" | ||
#include "smv_typecheck.h" | ||
#include "smv_parser.h" | ||
#include "expr2smv.h" | ||
|
||
#include <util/namespace.h> | ||
#include <util/symbol_table.h> | ||
|
||
#include "expr2smv.h" | ||
#include "smv_parser.h" | ||
#include "smv_typecheck.h" | ||
|
||
/*******************************************************************\ | ||
|
||
Function: smv_languaget::parse | ||
|
@@ -153,7 +155,9 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &) | |
if(it->second.type.id()!="submodule") | ||
{ | ||
std::string msg; | ||
type2smv(it->second.type, msg); | ||
symbol_tablet symbol_table; | ||
namespacet ns(symbol_table); | ||
type2smv(it->second.type, msg, ns); | ||
out << " " << it->first << ": " | ||
<< msg << ";" << std::endl; | ||
} | ||
|
@@ -168,7 +172,9 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &) | |
if(it->second.type.id()=="submodule") | ||
{ | ||
std::string msg; | ||
type2smv(it->second.type, msg); | ||
symbol_tablet symbol_table; | ||
namespacet ns(symbol_table); | ||
Comment on lines
+175
to
+176
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 we really not have a symbol table or namespace available when invoking 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. Yes, this is pre typechecking. |
||
type2smv(it->second.type, msg, ns); | ||
out << " " << it->first << ": " | ||
<< msg << ";" << std::endl; | ||
} | ||
|
@@ -201,7 +207,7 @@ Function: smv_languaget::from_expr | |
bool smv_languaget::from_expr(const exprt &expr, std::string &code, | ||
const namespacet &ns) | ||
{ | ||
return expr2smv(expr, code); | ||
return expr2smv(expr, code, ns); | ||
} | ||
|
||
/*******************************************************************\ | ||
|
@@ -221,7 +227,7 @@ bool smv_languaget::from_type( | |
std::string &code, | ||
const namespacet &ns) | ||
{ | ||
return type2smv(type, code); | ||
return type2smv(type, code, ns); | ||
} | ||
|
||
/*******************************************************************\ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not for this PR, but rather asking about potential future work: Is
bool
really the appropriate return type? Shouldn't places thatreturn true
really be usingUNIMPLEMENTED
instead? Then the return type could instead bestd::string
.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.
Another option would be to send anything that that code doesn't know how to format to
format_expr
.