Skip to content

Commit 2120a44

Browse files
authored
Merge pull request #978 from romainbrenguier/feature/index-of-precise
Make String.indexOf and String.lastIndexOf precise
2 parents ff81171 + cf5b5d3 commit 2120a44

File tree

8 files changed

+241
-71
lines changed

8 files changed

+241
-71
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
KNOWNBUG
1+
CORE
22
test_index_of.class
33
--refine-strings
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
8-
Issue: cbmc/test-gen#77
Binary file not shown.
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
public class test_index_of
22
{
3-
public static void main(/*String[] argv*/)
4-
{
5-
String s = "Abc";
6-
String bc = "bc";
7-
int i = s.indexOf(bc);
8-
assert(i == 1);
9-
}
3+
public static void main(/*String[] argv*/)
4+
{
5+
String s = "Abc";
6+
String bc = "bc";
7+
String ab = "ab";
8+
int i = s.indexOf(bc);
9+
int j = s.indexOf(ab);
10+
assert(i == 1);
11+
assert(j == -1);
12+
}
1013
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
test_last_index_of.class
33
--refine-strings
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^\[.*assertion.1\].* line 8.* SUCCESS$
7+
^\[.*assertion.2\].* line 9.* FAILURE$
78
--
8-
Issue: diffblue/test-gen#77
Binary file not shown.
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
public class test_last_index_of
22
{
3-
public static void main(/*String[] argv*/)
4-
{
5-
String s = "abcab";
6-
String ab = "ab";
7-
int i = s.lastIndexOf(ab);
8-
assert(i == 3);
9-
}
3+
public static void main(/*String[] argv*/)
4+
{
5+
String s = "abcab";
6+
String ab = "ab";
7+
int i = s.lastIndexOf(ab);
8+
assert(i == 3);
9+
assert(i == 1);
10+
}
1011
}

src/solvers/refinement/string_constraint_generator.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,18 @@ class string_constraint_generatort
194194
const exprt &from_index);
195195

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

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

210205
// Add axioms corresponding to the String.lastIndexOf:(String;I) java function
211-
// TODO: the specifications are only partial
212206
exprt add_axioms_for_last_index_of_string(
213-
const string_exprt &str,
214-
const string_exprt &substring,
207+
const string_exprt &haystack,
208+
const string_exprt &needle,
215209
const exprt &from_index);
216210

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

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

227220
// TODO: the specifications of these functions is only partial

0 commit comments

Comments
 (0)