-
Notifications
You must be signed in to change notification settings - Fork 273
Cleaning dependencies of the string solver #549
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
Cleaning dependencies of the string solver #549
Conversation
The linter warnings appear to be genuine, would you mind addressing them? |
|
||
// Internal type used for string refinement | ||
class refined_string_typet: public struct_typet | ||
{ | ||
public: | ||
explicit refined_string_typet(typet char_type); | ||
explicit refined_string_typet(typet index_type, typet char_type); |
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.
It's safe to get rid of "explicit" now that this constructor takes 2 arguments.
{ } | ||
mode(ID_unknown) | ||
{ | ||
next_symbol_id=1; |
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.
I'm not entirely sure, but I think this would actually reset the counter. Place the initialisation with the declaration.
exprt constr2=character_equals_ignore_case( | ||
s1[qvar], s2[qvar], char_a, char_A, char_Z); | ||
string_constraintt a2(qvar, s1.length(), eq, constr2); | ||
axioms.push_back(a2); | ||
|
||
symbol_exprt witness=fresh_exist_index("witness_unequal_ignore_case"); | ||
exprt zero=from_integer(0, get_index_type()); | ||
// TODO: we should have to give the type of witness |
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.
Would you mind elaborating a bit more to enable others to pick up this TODO? Specifically, I don't know who "we" refers to, and what type that would be - it seems it's using index_type - is that not correct?
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.
sorry this shouldn't be there, the call the index_type has been added but the TODO wasn't removed
return string_exprt(length, content, type); | ||
} | ||
|
||
|
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.
Nit picking: one blank line will do
@@ -705,14 +707,14 @@ exprt string_refinementt::sum_over_map( | |||
switch(second) | |||
{ | |||
case -1: | |||
if(sum==from_integer(0, generator.get_index_type())) | |||
if(sum==nil_exprt()) |
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.
You might want to use if(sum.is_nil())
exprt index_const=from_integer(constants, generator.get_index_type()); | ||
return plus_exprt(sum, index_const); | ||
exprt index_const=from_integer(constants, index_type); | ||
if(sum!=nil_exprt()) |
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.
You could use if(sum.is_not_nil())
@tautschnig yes, sorry for these, this is now done |
Thanks a lot for the immediate cleanup - please see my comments for a few more changes to consider. |
@@ -229,8 +256,9 @@ string_exprt string_constraint_generatort::find_or_add_string_of_symbol( | |||
const symbol_exprt &sym) | |||
{ | |||
irep_idt id=sym.get_identifier(); | |||
auto entry=symbol_to_string.insert( | |||
std::make_pair(id, string_exprt(get_char_type()))); | |||
refined_string_typet ref_type=to_refined_string_type(sym.type()); |
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.
const &
@@ -403,15 +430,16 @@ string_exprt string_constraint_generatort::add_axioms_for_copy( | |||
const function_application_exprt &f) | |||
{ | |||
string_exprt s1=add_axioms_for_string_expr(args(f, 1)[0]); | |||
string_exprt res(get_char_type()); | |||
refined_string_typet ref_type=to_refined_string_type(s1.type()); |
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.
const & (and all other instances like this)
@@ -655,7 +638,8 @@ exprt string_constraint_generatort::add_axioms_for_char_at( | |||
const function_application_exprt &f) | |||
{ | |||
string_exprt str=add_axioms_for_string_expr(args(f, 2)[0]); | |||
symbol_exprt char_sym=string_exprt::fresh_symbol("char", get_char_type()); | |||
refined_string_typet ref_type=to_refined_string_type(str.type()); |
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.
const &
src/util/string_expr.h
Outdated
// Generate a new symbol of the given type with a prefix | ||
static symbol_exprt fresh_symbol( | ||
const irep_idt &prefix, const typet &type=bool_typet()); | ||
string_exprt(exprt _length, exprt _content, typet type): string_exprt(type) |
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.
const & (twice, and use copy_to_operands)
@@ -705,14 +707,14 @@ exprt string_refinementt::sum_over_map( | |||
switch(second) | |||
{ | |||
case -1: | |||
if(sum==from_integer(0, generator.get_index_type())) | |||
if(sum==nil_exprt()) |
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.
.is_nil() (several instances)
@tautschnig @peterschrammel thanks for the comment, I've now done the corresponding corrections |
0174939
to
6096c5f
Compare
6096c5f
to
0628812
Compare
exprt s0, | ||
exprt s1) : | ||
string_exprt s0, | ||
string_exprt s1) : |
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.
no space before :
@@ -73,9 +57,14 @@ class string_constraint_generatort | |||
return index_exprt(witness.at(c), univ_val); | |||
} | |||
|
|||
symbol_exprt fresh_exist_index(const irep_idt &prefix); | |||
symbol_exprt fresh_univ_index(const irep_idt &prefix); | |||
static unsigned next_symbol_id=1; |
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 initialisation should be in the cpp file.
src/util/string_expr.h
Outdated
static irep_idt extract_java_string(const symbol_exprt &s); | ||
|
||
static unsigned next_symbol_id; | ||
|
||
friend inline string_exprt &to_string_expr(exprt &expr); | ||
}; | ||
|
||
|
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.
remove one blank line
4aefd87
to
a04f840
Compare
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.
I would suggest to move the initialisation as indicated in the comment - otherwise this looks ok to me.
@@ -17,42 +17,48 @@ Author: Romain Brenguier, [email protected] | |||
#include <util/pointer_predicates.h> | |||
#include <util/ssa_expr.h> | |||
|
|||
unsigned string_constraint_generatort::next_symbol_id=1; | |||
|
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.
Why is this initialization not done right in the class declaration? I'd rather drop this one instead of the in-class one as you've done in one of your commits.
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.
Personally I don't have a preference, but Peter suggested that the initialisation should be in the cpp file.
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.
You can't initialise a non-const static member in the class definition.
|
||
// Internal type used for string refinement | ||
class refined_string_typet: public struct_typet | ||
{ | ||
public: | ||
explicit refined_string_typet(typet char_type); | ||
refined_string_typet(typet index_type, typet char_type); |
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.
const & (twice)
|
||
string_not_contains_constraintt( | ||
exprt univ_lower_bound, | ||
exprt univ_bound_sup, | ||
exprt premise, | ||
exprt exists_bound_inf, | ||
exprt exists_bound_sup, | ||
exprt s0, | ||
exprt s1) : | ||
string_exprt s0, |
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.
const & (twice)
@@ -22,11 +22,11 @@ Constructor: refined_string_typet::refined_string_typet | |||
|
|||
\*******************************************************************/ | |||
|
|||
refined_string_typet::refined_string_typet(typet char_type) | |||
refined_string_typet::refined_string_typet(typet index_type, typet char_type) |
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.
const & (twice)
boolean_symbols.push_back(b); | ||
return b; | ||
} | ||
|
||
|
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.
remove one blank line
@peterschrammel It seems all concerns have been addressed. I note that the linter is failing with an internal error rather than reporting any problems in the source files... |
@romainbrenguier can you please rebase, to have a fixed linter output? |
d9b5714
to
c29eed4
Compare
@forejtv done |
|
||
static symbol_exprt fresh_symbol( | ||
const irep_idt &prefix, const typet &type=bool_typet()); | ||
symbol_exprt fresh_exist_index(const irep_idt &prefix, typet type); |
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.
const typet &type (several occurrences)
f971285
to
0ad726d
Compare
@peterschrammel it's now done, should I squash the commits? |
Yes, the cleanup commits should be squashed |
`src/util` is a more appropriate place for the `string_exprt` class We changed the constructor with one type argument to be similar to other `exprt` constructors. This constructor was used to generate a struct with fresh symbols but this is no longer the case, so we use a function fresh string instead. Dependencies in the solver that were not needed have been removed. For some functions this requieres us to now pass the string type as argument.
0ad726d
to
3cb7bca
Compare
@peterschrammel commits have been squashed: 3cb7bca |
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.
@kroening, this looks ready to go
…ween_DO_and_EVSes SEC-633: Bugfix: added alias-computation between a DO and EVSes in the domain.
src/util
is a more appropriate place for thestring_exprt
class, so it was moved there.We changed the constructor with one type argument to be similar to
other
exprt
constructors.This constructor was used to generate a struct with
fresh symbols but this is no longer the case, so we use a function
fresh string instead.
Dependencies in the solver that were not needed have been removed.
For some functions this requires us to now pass the string type as
argument, so the appropriate changes have been made.