Repository navigation
Expand file tree
/
Copy pathCorrectLoopInvariants.java
More file actions
91 lines (79 loc) · 1.91 KB
/
Copy pathCorrectLoopInvariants.java
File metadata and controls
91 lines (79 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package testSuite;
import liquidjava.specification.Refinement;
// Facts about the int locals a loop changes that hold on every iteration are inferred (#537)
@SuppressWarnings("unused")
public class CorrectLoopInvariants {
static boolean next() {
return true;
}
static int read(byte[] buffer, @Refinement("_ >= 0") int offset, int length) {
return 0;
}
static void use(@Refinement("_ >= 0") int x) {}
static void counter() {
for (int i = 0; i < 10; i++) {
use(i);
}
}
static void accumulator() {
int total = 0;
while (total < 1024) {
use(total);
total = total + 1;
}
}
static void fill(byte[] buffer, int limit) {
int total = 0;
while (total < limit) {
int n = read(buffer, total, limit - total);
if (n < 0)
break;
total += n;
}
}
static void symbolicStart(int k) {
if (k < 0)
return;
for (int i = k; i < 100; i++) {
use(i);
}
}
static void nested() {
for (int i = 0; i < 10; i++) {
for (int j = i; j < 10; j++) {
use(i);
use(j);
}
}
}
// a continue goes on to the update
static void continueInFor() {
for (int i = 0; i < 10; i++) {
if (next())
continue;
use(i);
}
}
static void continueInWhile() {
int i = 0;
while (i < 10) {
use(i);
if (next()) {
i++;
continue;
}
i = i + 2;
}
}
static void continueInDoWhile() {
int i = 0;
do {
use(i);
if (next()) {
i++;
continue;
}
i = i + 2;
} while (i < 10);
}
}