Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java

Issue 8523034: Compile Time Constants cycle check (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added new test to exercise code that was throwing ICE Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.base.Joiner; 7 import com.google.common.base.Joiner;
8 import com.google.common.base.Splitter; 8 import com.google.common.base.Splitter;
9 import com.google.common.collect.Lists; 9 import com.google.common.collect.Lists;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 @Override 42 @Override
43 public void setUp() { 43 public void setUp() {
44 resetParseErrors(); 44 resetParseErrors();
45 } 45 }
46 46
47 @Override 47 @Override
48 public void tearDown() { 48 public void tearDown() {
49 resetParseErrors(); 49 resetParseErrors();
50 } 50 }
51 51
52 private static CoreTypeProvider setupTypeProvider(DartUnit unit, TestCompilerC ontext context, Scope scope) {
53 new TopLevelElementBuilder().exec(unit, context);
54 new TopLevelElementBuilder().fillInUnitScope(unit, context, scope);
55 ClassElement object = (ClassElement) scope.findElement(null, "Object");
56 assertNotNull("Cannot resolve Object", object);
57 return new MockCoreTypeProvider(object);
58 }
59
52 static Scope resolve(DartUnit unit, TestCompilerContext context) { 60 static Scope resolve(DartUnit unit, TestCompilerContext context) {
53 Scope scope = new Scope("library", null); 61 Scope scope = new Scope("library", null);
54 new TopLevelElementBuilder().exec(unit, context); 62 CoreTypeProvider typeProvider = setupTypeProvider(unit, context, scope);
55 new TopLevelElementBuilder().fillInUnitScope(unit, context, scope);
56 ClassElement object = (ClassElement) scope.findElement(null, "Object");
57 assertNotNull("Cannot resolve Object", object);
58 CoreTypeProvider typeProvider = new MockCoreTypeProvider(object);
59 new SupertypeResolver().exec(unit, context, scope, typeProvider); 63 new SupertypeResolver().exec(unit, context, scope, typeProvider);
60 new MemberBuilder().exec(unit, context, scope, typeProvider); 64 new MemberBuilder().exec(unit, context, scope, typeProvider);
61 new Resolver(context, scope, typeProvider).exec(unit); 65 new Resolver(context, scope, typeProvider).exec(unit);
62 return scope; 66 return scope;
63 } 67 }
64 68
69 static Scope resolveCompileTimeConst (DartUnit unit, TestCompilerContext conte xt) {
70 Scope scope = new Scope("library", null);
71 CoreTypeProvider typeProvider = setupTypeProvider(unit, context, scope);
72 new SupertypeResolver().exec(unit, context, scope, typeProvider);
73 new MemberBuilder().exec(unit, context, scope, typeProvider);
74 // Substitute the lightweight CTConst resolver
75 new CompileTimeConstantResolver().exec(unit, context, scope, typeProvider);
76 new CompileTimeConstantAnalyzer(typeProvider, context).exec(unit);
77 return scope;
78 }
79
80
65 static DartClass makeClass(String name, DartTypeNode supertype, String... type Parameters) { 81 static DartClass makeClass(String name, DartTypeNode supertype, String... type Parameters) {
66 return makeClass(name, supertype, Collections.<DartTypeNode>emptyList(), typ eParameters); 82 return makeClass(name, supertype, Collections.<DartTypeNode>emptyList(), typ eParameters);
67 } 83 }
68 84
69 static DartClass makeClass(String name, DartTypeNode supertype, List<DartTypeN ode> interfaces, 85 static DartClass makeClass(String name, DartTypeNode supertype, List<DartTypeN ode> interfaces,
70 String... typeParameters) { 86 String... typeParameters) {
71 List<DartTypeParameter> parameterNodes = new ArrayList<DartTypeParameter>(); 87 List<DartTypeParameter> parameterNodes = new ArrayList<DartTypeParameter>();
72 for (String parameter : typeParameters) { 88 for (String parameter : typeParameters) {
73 parameterNodes.add(makeTypeVariable(parameter)); 89 parameterNodes.add(makeTypeVariable(parameter));
74 } 90 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 for (String line : Splitter.on("\n").split(source)) { 374 for (String line : Splitter.on("\n").split(source)) {
359 System.out.println(String.format(" %02d: %s", count++, line)); 375 System.out.println(String.format(" %02d: %s", count++, line));
360 } 376 }
361 } 377 }
362 } 378 }
363 /** 379 /**
364 * For debugging. 380 * For debugging.
365 */ 381 */
366 protected void printEncountered(List<DartCompilationError> encountered) { 382 protected void printEncountered(List<DartCompilationError> encountered) {
367 for (DartCompilationError error : encountered) { 383 for (DartCompilationError error : encountered) {
368 ErrorCode errorCode = (ErrorCode) error.getErrorCode(); 384 ErrorCode errorCode = error.getErrorCode();
369 String msg = 385 String msg =
370 String.format( 386 String.format(
371 "%s > %s (%d:%d)", 387 "%s > %s (%d:%d)",
372 errorCode.toString(), 388 errorCode.toString(),
373 error.getMessage(), 389 error.getMessage(),
374 error.getLineNumber(), 390 error.getLineNumber(),
375 error.getColumnNumber()); 391 error.getColumnNumber());
376 System.out.println(msg); 392 System.out.println(msg);
377 } 393 }
378 } 394 }
379 395
380 /** 396 /**
381 * Convenience method to parse and resolve a code snippet, then test for error codes. 397 * Convenience method to parse and resolve a code snippet, then test for error codes.
382 * 398 *
383 * @return resolve errors. 399 * @return resolve errors.
384 */ 400 */
385 protected List<DartCompilationError> resolveAndTest(String source, ErrorCode.. . errorCodes) { 401 protected List<DartCompilationError> resolveAndTest(String source, ErrorCode.. . errorCodes) {
386 // parse DartUnit 402 // parse DartUnit
387 DartUnit unit = parseUnit(source); 403 DartUnit unit = parseUnit(source);
388 if (parseErrors.size() != 0) { 404 if (parseErrors.size() != 0) {
389 printSource(source); 405 printSource(source);
390 printEncountered(parseErrors); 406 printEncountered(parseErrors);
391 assertEquals("Expected no errors in parse step:", 0, parseErrors.size()); 407 assertEquals("Expected no errors in parse step:", 0, parseErrors.size());
392 } 408 }
393 // prepare for recording resolving errors 409 // prepare for recording resolving errors
394 resetParseErrors(); 410 resetParseErrors();
395 final List<DartCompilationError> resolveErrors = Lists.newArrayList(); 411 final List<DartCompilationError> resolveErrors = Lists.newArrayList();
396 TestCompilerContext ctx = new TestCompilerContext() { 412 TestCompilerContext ctx = new TestCompilerContext() {
397 @Override 413 @Override
398 public void onError(DartCompilationError event) { 414 public void onError(DartCompilationError event) {
399 resolveErrors.add(event); 415 resolveErrors.add(event);
400 } 416 }
401 }; 417 };
402 // resolve and check errors 418 // resolve and check errors
403 resolve(unit, ctx); 419 resolve(unit, ctx);
404 checkExpectedErrors(resolveErrors, errorCodes, source); 420 checkExpectedErrors(resolveErrors, errorCodes, source);
405 return resolveErrors; 421 return resolveErrors;
406 } 422 }
423
424 /**
425 * Convenience method to parse and resolve a code snippet, then test for error codes.
426 *
427 * @return resolve errors.
428 */
429 protected List<DartCompilationError> resolveAndTestCtConst(String source, Erro rCode... errorCodes) {
430 // parse DartUnit
431 DartUnit unit = parseUnit(source);
432 if (parseErrors.size() != 0) {
433 printSource(source);
434 printEncountered(parseErrors);
435 assertEquals("Expected no errors in parse step:", 0, parseErrors.size());
436 }
437 // prepare for recording resolving errors
438 resetParseErrors();
439 final List<DartCompilationError> resolveErrors = Lists.newArrayList();
440 TestCompilerContext ctx = new TestCompilerContext() {
441 @Override
442 public void onError(DartCompilationError event) {
443 resolveErrors.add(event);
444 }
445 };
446 // resolve and check errors
447 resolveCompileTimeConst(unit, ctx);
448 checkExpectedErrors(resolveErrors, errorCodes, source);
449 return resolveErrors;
450 }
407 } 451 }
OLDNEW
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698