@@ -4,7 +4,7 @@ public class B {
4
4
// that should also be annotated.
5
5
static void bound (int b ) { }
6
6
7
- public int forloop () {
7
+ public int forLoop () {
8
8
int result = 0 ;
9
9
for (int i = 0 ;
10
10
i < 10 ; // $ bound="i in [0..10]"
@@ -14,31 +14,31 @@ public int forloop() {
14
14
return result ; // $ bound="result in [0..9]"
15
15
}
16
16
17
- public int forloopexit () {
17
+ public int forLoopExit () {
18
18
int result = 0 ;
19
19
for (; result < 10 ;) { // $ bound="result in [0..10]"
20
20
result += 1 ; // $ bound="result in [0..9]"
21
21
}
22
22
return result ; // $ bound="result = 10"
23
23
}
24
24
25
- public int forloopexitstep () {
25
+ public int forLoopExitStep () {
26
26
int result = 0 ;
27
27
for (; result < 10 ;) { // $ bound="result in [0..12]"
28
28
result += 3 ; // $ bound="result in [0..9]"
29
29
}
30
30
return result ; // $ bound="result = 12"
31
31
}
32
32
33
- public int forloopexitupd () {
33
+ public int forLoopExitUpd () {
34
34
int result = 0 ;
35
35
for (; result < 10 ; // $ bound="result in [0..10]"
36
36
result ++) { // $ bound="result in [0..9]"
37
37
}
38
38
return result ; // $ bound="result = 10"
39
39
}
40
40
41
- public int forloopexitnested () {
41
+ public int forLoopExitNested () {
42
42
int result = 0 ;
43
43
for (; result < 10 ;) {
44
44
int i = 0 ;
@@ -50,7 +50,7 @@ public int forloopexitnested() {
50
50
return result ; // $ MISSING:bound="result = 12"
51
51
}
52
52
53
- public int emptyforloop () {
53
+ public int emptyForLoop () {
54
54
int result = 0 ;
55
55
for (int i = 0 ; i < 0 ; // $ bound="i = 0"
56
56
i ++) { // $ bound="i in [0..-1]"
@@ -59,45 +59,45 @@ public int emptyforloop() {
59
59
return result ; // $ bound="result = 0"
60
60
}
61
61
62
- public int noloop () {
62
+ public int noLoop () {
63
63
int result = 0 ;
64
64
result += 1 ; // $ bound="result = 0"
65
65
return result ; // $ bound="result = 1"
66
66
}
67
67
68
- public int foreachloop () {
68
+ public int foreachLoop () {
69
69
int result = 0 ;
70
70
for (int i : new int [] {1 , 2 , 3 , 4 , 5 }) {
71
71
result = i ;
72
72
}
73
73
return result ;
74
74
}
75
75
76
- public int emptyforeachloop () {
76
+ public int emptyForeachLoop () {
77
77
int result = 0 ;
78
78
for (int i : new int [] {}) {
79
79
result = i ;
80
80
}
81
81
return result ;
82
82
}
83
83
84
- public int whileloop () {
84
+ public int whileLoop () {
85
85
int result = 100 ;
86
86
while (result > 5 ) { // $ bound="result in [4..100]"
87
87
result = result - 2 ; // $ bound="result in [6..100]"
88
88
}
89
89
return result ; // $ bound="result = 4"
90
90
}
91
91
92
- public int oddwhileloop () {
92
+ public int oddWhileLoop () {
93
93
int result = 101 ;
94
94
while (result > 5 ) { // $ bound="result in [5..101]"
95
95
result = result - 2 ; // $ bound="result in [7..101]"
96
96
}
97
97
return result ; // $ bound="result = 5"
98
98
}
99
99
100
- static void arraylength (int [] arr ) {
100
+ static void arrayLength (int [] arr ) {
101
101
bound (arr .length );
102
102
for (int i = 0 ;
103
103
i < arr .length ;
@@ -106,15 +106,53 @@ static void arraylength(int[] arr) {
106
106
}
107
107
}
108
108
109
- static int varbound (int b ) {
109
+ static int varBound (int b ) {
110
110
bound (b );
111
111
int result = 0 ;
112
112
for (int i = 0 ;
113
113
i < b ;
114
114
i ++) { // $ bound="i <= b - 1"
115
115
result = i ; // $ bound="i <= b - 1"
116
116
}
117
+ return result ; // We cannot conclude anything here, since we do not know that b > 0
118
+ }
119
+
120
+ static int varBoundPositiveGuard (int b ) {
121
+ bound (b );
122
+ if (b > 0 ) {
123
+ int result = 0 ;
124
+ for (int i = 0 ;
125
+ i < b ;
126
+ i ++) { // $ bound="i <= b - 1"
127
+ result = i ; // $ bound="i <= b - 1"
128
+ }
129
+ return result ; // $ MISSING: bound="result <= b - 1"
130
+ } else {
131
+ return 0 ;
132
+ }
133
+ }
134
+
135
+ static int varBoundPositiveGuardEarlyReturn (int b ) {
136
+ bound (b );
137
+ if (b <= 0 ) return 0 ;
138
+ int result = 0 ;
139
+ for (int i = 0 ;
140
+ i < b ;
141
+ i ++) { // $ bound="i <= b - 1"
142
+ result = i ; // $ bound="i <= b - 1"
143
+ }
117
144
return result ; // $ MISSING: bound="result <= b - 1"
118
145
}
119
146
147
+ static int varBoundPositiveAssert (int b ) {
148
+ bound (b );
149
+ assert b > 0 ;
150
+ int result = 0 ;
151
+ for (int i = 0 ;
152
+ i < b ;
153
+ i ++) { // $ bound="i <= b - 1"
154
+ result = i ; // $ bound="i <= b - 1"
155
+ }
156
+ return result ; // $ MISSING: bound="result <= b - 1"
157
+ }
120
158
}
0 commit comments