-
Notifications
You must be signed in to change notification settings - Fork 285
Add string type support to SMT back-end
#8838
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
Open
tautschnig
wants to merge
2
commits into
diffblue:develop
Choose a base branch
from
tautschnig:smt-strings
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+32
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -2707,8 +2707,24 @@ void smt2_convt::convert_expr(const exprt &expr) | |
| else if(expr.id() == ID_function_application) | ||
| { | ||
| const auto &function_application_expr = to_function_application_expr(expr); | ||
|
|
||
| // Check for string operations by looking at the function symbol name | ||
| std::string fn_name; | ||
| if(function_application_expr.function().id() == ID_symbol) | ||
| fn_name = id2string( | ||
| to_symbol_expr(function_application_expr.function()).get_identifier()); | ||
|
|
||
| if(fn_name == "Str.Concat" && | ||
| function_application_expr.arguments().size() == 2) | ||
| { | ||
| out << "(str.++ "; | ||
| convert_expr(function_application_expr.arguments()[0]); | ||
| out << ' '; | ||
| convert_expr(function_application_expr.arguments()[1]); | ||
| out << ')'; | ||
| } | ||
| // do not use parentheses if there function is a constant | ||
| if(function_application_expr.arguments().empty()) | ||
| else if(function_application_expr.arguments().empty()) | ||
| { | ||
| convert_expr(function_application_expr.function()); | ||
| } | ||
|
|
@@ -3763,6 +3779,19 @@ void smt2_convt::convert_constant(const constant_exprt &expr) | |
| out << "(_ bv" << (value_int - range_type.get_from()) << " " << width | ||
| << ")"; | ||
| } | ||
| else if(expr_type.id()==ID_string) | ||
| { | ||
| const std::string &value = id2string(expr.get_value()); | ||
| out << "\""; | ||
| for(char c : value) | ||
| { | ||
| if(c == '"') | ||
| out << "\"\""; | ||
| else | ||
| out << c; | ||
| } | ||
| out << "\""; | ||
| } | ||
| else | ||
| UNEXPECTEDCASE("unknown constant: "+expr_type.id_string()); | ||
| } | ||
|
|
@@ -5991,6 +6020,8 @@ void smt2_convt::convert_type(const typet &type) | |
| UNEXPECTEDCASE("unsuppored range type"); | ||
| out << "(_ BitVec " << address_bits(size) << ")"; | ||
| } | ||
| else if(type.id()==ID_string) | ||
|
||
| out << "String"; | ||
| else | ||
| { | ||
| UNEXPECTEDCASE("unsupported type: "+type.id_string()); | ||
|
|
||
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.
The str.++ (string concatenation) operation in SMT-LIB 2 can take any number of arguments (including 0, 1, or more than 2), but this implementation only handles exactly 2 arguments. When there are != 2 arguments, it falls through to the else case which will output "Str.Concat" instead of "str.++". Consider removing the size check or handling variable numbers of arguments to ensure all Str.Concat calls are properly converted to str.++.