Skip to content

Make String.indexOf and String.lastIndexOf precise #978

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
Show all changes
21 commits
Select commit Hold shift + click to select a range
f9199a0
Make index_of precise diffblue/test-gen#77
romainbrenguier May 26, 2017
bc59d0c
Making lastIndexOf precise diffblue/test-gen#77
romainbrenguier May 31, 2017
4f4df8e
Optimize last_index_of for constant argument
romainbrenguier May 31, 2017
9b11653
Updating comments for index_of and last_index_of on characters
romainbrenguier May 31, 2017
bc3eedc
Replacing str and substring by haystack and needle
romainbrenguier Jun 5, 2017
666bec0
Removing comments about lastIndexOf being imprecise
romainbrenguier Jun 5, 2017
1eb3263
Making comments about the output more precise
romainbrenguier Jun 5, 2017
68cdc6f
Renaming str and substring to haystack and needle
romainbrenguier Jun 5, 2017
2d16c2c
Correct comments and axioms in lastIndexOf
romainbrenguier Jun 5, 2017
f3f5a19
Replacing str and substring by haystack and needle in the comments
romainbrenguier Jun 5, 2017
a4ab7db
Updating comments for functions adding axioms for index_of
romainbrenguier Jun 6, 2017
1eb7d74
Uniformising mathematical notations in comments
romainbrenguier Jun 6, 2017
069da51
Typo in comment
romainbrenguier Jun 6, 2017
7edfe0d
Typo in comment
romainbrenguier Jun 6, 2017
3e9668a
Correcting a mistake, universal variable was used in non-quantified f…
romainbrenguier Jun 6, 2017
b06476c
Correcting indentation in the comments
romainbrenguier Jun 6, 2017
af98378
Correcting misuse of univ variable qvar instead of qvar2
romainbrenguier Jun 6, 2017
80dff96
Correcting lower bound in axiom added for last_index_of
romainbrenguier Jun 6, 2017
d4a9b2a
More comments on the output of last_index_of functions
romainbrenguier Jun 6, 2017
94f99b5
Adding forgotten precondition in not_contains constraint
romainbrenguier Jun 6, 2017
cf5b5d3
Update regressions tests for indexOf and lastIndexOf
Jun 6, 2017
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
3 changes: 1 addition & 2 deletions regression/strings-smoke-tests/java_index_of/test.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
KNOWNBUG
CORE
test_index_of.class
--refine-strings
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
Issue: cbmc/test-gen#77
Binary file modified regression/strings-smoke-tests/java_index_of/test_index_of.class
Binary file not shown.
17 changes: 10 additions & 7 deletions regression/strings-smoke-tests/java_index_of/test_index_of.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
public class test_index_of
{
public static void main(/*String[] argv*/)
{
String s = "Abc";
String bc = "bc";
int i = s.indexOf(bc);
assert(i == 1);
}
public static void main(/*String[] argv*/)
{
String s = "Abc";
String bc = "bc";
String ab = "ab";
int i = s.indexOf(bc);
int j = s.indexOf(ab);
assert(i == 1);
assert(j == -1);
}
}
8 changes: 4 additions & 4 deletions regression/strings-smoke-tests/java_last_index_of/test.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
KNOWNBUG
CORE
test_last_index_of.class
--refine-strings
^EXIT=0$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
^\[.*assertion.1\].* line 8.* SUCCESS$
^\[.*assertion.2\].* line 9.* FAILURE$
--
Issue: diffblue/test-gen#77
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
public class test_last_index_of
{
public static void main(/*String[] argv*/)
{
String s = "abcab";
String ab = "ab";
int i = s.lastIndexOf(ab);
assert(i == 3);
}
public static void main(/*String[] argv*/)
{
String s = "abcab";
String ab = "ab";
int i = s.lastIndexOf(ab);
assert(i == 3);
assert(i == 1);
}
}
15 changes: 4 additions & 11 deletions src/solvers/refinement/string_constraint_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,18 @@ class string_constraint_generatort
const exprt &from_index);

// Add axioms corresponding to the String.indexOf:(String;I) java function
// TODO: the specifications are only partial:
// we add axioms stating that the returned value is either -1 or greater than
// from_index and the string beggining there has prefix substring
exprt add_axioms_for_index_of_string(
const string_exprt &str,
const string_exprt &substring,
const string_exprt &haystack,
const string_exprt &needle,
const exprt &from_index);

// Add axioms corresponding to the String.indexOf java functions
// TODO: the specifications are only partial for the ones that look for
// strings
exprt add_axioms_for_index_of(const function_application_exprt &f);

// Add axioms corresponding to the String.lastIndexOf:(String;I) java function
// TODO: the specifications are only partial
exprt add_axioms_for_last_index_of_string(
const string_exprt &str,
const string_exprt &substring,
const string_exprt &haystack,
const string_exprt &needle,
const exprt &from_index);

// Add axioms corresponding to the String.lastIndexOf:(CI) java function
Expand All @@ -221,7 +215,6 @@ class string_constraint_generatort
const exprt &from_index);

// Add axioms corresponding to the String.lastIndexOf java functions
// TODO: the specifications is only partial
exprt add_axioms_for_last_index_of(const function_application_exprt &f);

// TODO: the specifications of these functions is only partial
Expand Down
Loading