| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'compiler_helper.dart'; | 6 import 'compiler_helper.dart'; |
| 7 | 7 |
| 8 const int REMOVED = 0; | 8 const int REMOVED = 0; |
| 9 const int ABOVE_ZERO = 1; | 9 const int ABOVE_ZERO = 1; |
| 10 const int BELOW_LENGTH = 2; | 10 const int BELOW_LENGTH = 2; |
| 11 const int KEPT = 3; | 11 const int KEPT = 3; |
| 12 const int ONE_CHECK = 4; | 12 const int ONE_CHECK = 4; |
| 13 const int ONE_ZERO_CHECK = 5; | 13 const int ONE_ZERO_CHECK = 5; |
| 14 const int BELOW_ZERO_CHECK = 6; |
| 14 | 15 |
| 15 final List TESTS = [ | 16 final List TESTS = [ |
| 16 """ | 17 """ |
| 17 main() { | 18 main() { |
| 18 var a = new List(); | 19 var a = new List(); |
| 19 var sum = 0; | 20 var sum = 0; |
| 20 for (int i = 0; i < a.length; i++) { | 21 for (int i = 0; i < a.length; i++) { |
| 21 sum += a[i]; | 22 sum += a[i]; |
| 22 } | 23 } |
| 23 return sum; | 24 return sum; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // want an int. | 191 // want an int. |
| 191 int sum = ~value; | 192 int sum = ~value; |
| 192 for (int i = 0; i < 42; i++) sum += (value & 4); | 193 for (int i = 0; i < 42; i++) sum += (value & 4); |
| 193 var a = new List(); | 194 var a = new List(); |
| 194 if (value >= a.length) return; | 195 if (value >= a.length) return; |
| 195 if (value <= -1) return; | 196 if (value <= -1) return; |
| 196 return a[value]; | 197 return a[value]; |
| 197 } | 198 } |
| 198 """, | 199 """, |
| 199 REMOVED, | 200 REMOVED, |
| 201 """ |
| 202 main(value) { |
| 203 var a = new List(4); |
| 204 var sum = 0; |
| 205 for (int i = 0; i < a.length; i++) { |
| 206 sum += a[i]; |
| 207 if (sum == 0) i++; |
| 208 } |
| 209 return sum; |
| 210 } |
| 211 """, |
| 212 REMOVED, |
| 213 """ |
| 214 main(value) { |
| 215 var a = new List(5); |
| 216 var sum = 0; |
| 217 for (int i = a.length - 1; i >= 0; i--) { |
| 218 sum += a[i]; |
| 219 if (sum == 0) i--; |
| 220 } |
| 221 return sum; |
| 222 } |
| 223 """, |
| 224 REMOVED, |
| 225 """ |
| 226 main(value) { |
| 227 var a = new List(6); |
| 228 var sum = 0; |
| 229 for (int i = 0; i < a.length; i++) { |
| 230 sum += a[i]; |
| 231 if (sum == 0) i--; |
| 232 } |
| 233 return sum; |
| 234 } |
| 235 """, |
| 236 BELOW_ZERO_CHECK, |
| 237 """ |
| 238 main(value) { |
| 239 var a = new List(7); |
| 240 var sum = 0; |
| 241 for (int i = 0; i < a.length;) { |
| 242 sum += a[i]; |
| 243 sum == 0 ? i-- : i++; |
| 244 } |
| 245 return sum; |
| 246 } |
| 247 """, |
| 248 BELOW_ZERO_CHECK, |
| 249 """ |
| 250 main(value) { |
| 251 var a = new List(7); |
| 252 var sum = 0; |
| 253 for (int i = -2; i < a.length; i = 0) { |
| 254 sum += a[i]; |
| 255 } |
| 256 return sum; |
| 257 } |
| 258 """, |
| 259 BELOW_ZERO_CHECK, |
| 200 ]; | 260 ]; |
| 201 | 261 |
| 202 // TODO(ahe): It would probably be better if this test used the real | 262 // TODO(ahe): It would probably be better if this test used the real |
| 203 // core library sources, as its purpose is to detect failure to | 263 // core library sources, as its purpose is to detect failure to |
| 204 // optimize fixed-sized arrays. | 264 // optimize fixed-sized arrays. |
| 205 const String DEFAULT_CORELIB_WITH_LIST_INTERFACE = r''' | 265 const String DEFAULT_CORELIB_WITH_LIST_INTERFACE = r''' |
| 206 print(var obj) {} | 266 print(var obj) {} |
| 207 abstract class num {} | 267 abstract class num {} |
| 208 abstract class int extends num { } | 268 abstract class int extends num { } |
| 209 abstract class double extends num { } | 269 abstract class double extends num { } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 coreSource: DEFAULT_CORELIB_WITH_LIST_INTERFACE, | 343 coreSource: DEFAULT_CORELIB_WITH_LIST_INTERFACE, |
| 284 interceptorsSource: INTERCEPTORSLIB_WITH_MEMBERS); | 344 interceptorsSource: INTERCEPTORSLIB_WITH_MEMBERS); |
| 285 switch (kind) { | 345 switch (kind) { |
| 286 case REMOVED: | 346 case REMOVED: |
| 287 Expect.isTrue(!generated.contains('ioore')); | 347 Expect.isTrue(!generated.contains('ioore')); |
| 288 break; | 348 break; |
| 289 | 349 |
| 290 case ABOVE_ZERO: | 350 case ABOVE_ZERO: |
| 291 Expect.isTrue(!generated.contains('< 0')); | 351 Expect.isTrue(!generated.contains('< 0')); |
| 292 Expect.isTrue(generated.contains('ioore')); | 352 Expect.isTrue(generated.contains('ioore')); |
| 353 break; |
| 354 |
| 355 case BELOW_ZERO_CHECK: |
| 356 Expect.isTrue(generated.contains('< 0')); |
| 357 Expect.isTrue(!generated.contains('||')); |
| 293 Expect.isTrue(generated.contains('ioore')); | 358 Expect.isTrue(generated.contains('ioore')); |
| 294 break; | 359 break; |
| 295 | 360 |
| 296 case BELOW_LENGTH: | 361 case BELOW_LENGTH: |
| 297 Expect.isTrue(!generated.contains('||')); | 362 Expect.isTrue(!generated.contains('||')); |
| 298 Expect.isTrue(generated.contains('ioore')); | 363 Expect.isTrue(generated.contains('ioore')); |
| 299 break; | 364 break; |
| 300 | 365 |
| 301 case KEPT: | 366 case KEPT: |
| 302 Expect.isTrue(generated.contains('ioore')); | 367 Expect.isTrue(generated.contains('ioore')); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 315 break; | 380 break; |
| 316 } | 381 } |
| 317 } | 382 } |
| 318 | 383 |
| 319 | 384 |
| 320 main() { | 385 main() { |
| 321 for (int i = 0; i < TESTS.length; i += 2) { | 386 for (int i = 0; i < TESTS.length; i += 2) { |
| 322 expect(TESTS[i], TESTS[i + 1]); | 387 expect(TESTS[i], TESTS[i + 1]); |
| 323 } | 388 } |
| 324 } | 389 } |
| OLD | NEW |