| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 for (int start in lineStarts) { | 459 for (int start in lineStarts) { |
| 460 buffer.write(start); | 460 buffer.write(start); |
| 461 buffer.write(", "); | 461 buffer.write(", "); |
| 462 } | 462 } |
| 463 fail(buffer.toString()); | 463 fail(buffer.toString()); |
| 464 } | 464 } |
| 465 return firstToken; | 465 return firstToken; |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 | 468 |
| 469 /** |
| 470 * Implementation of [ConstantEvaluationValidator] used during unit tests; |
| 471 * verifies that any nodes referenced during constant evaluation are present in |
| 472 * the dependency graph. |
| 473 */ |
| 474 class ConstantEvaluationValidator_ForTest |
| 475 implements ConstantEvaluationValidator { |
| 476 ConstantValueComputer computer; |
| 477 |
| 478 AstNode _nodeBeingEvaluated; |
| 479 |
| 480 @override |
| 481 void beforeComputeValue(AstNode constNode) { |
| 482 _nodeBeingEvaluated = constNode; |
| 483 } |
| 484 |
| 485 @override |
| 486 void beforeGetConstantInitializers(ConstructorElement constructor) { |
| 487 // If we are getting the constant initializers for a node in the graph, |
| 488 // make sure we properly recorded the dependency. |
| 489 ConstructorDeclaration node = |
| 490 computer.findConstructorDeclaration(constructor); |
| 491 if (node != null && computer.referenceGraph.nodes.contains(node)) { |
| 492 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), |
| 493 isTrue); |
| 494 } |
| 495 } |
| 496 |
| 497 @override |
| 498 void beforeGetEvaluationResult(AstNode node) { |
| 499 // If we are getting the evaluation result for a node in the graph, |
| 500 // make sure we properly recorded the dependency. |
| 501 if (computer.referenceGraph.nodes.contains(node)) { |
| 502 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), |
| 503 isTrue); |
| 504 } |
| 505 } |
| 506 |
| 507 @override |
| 508 void beforeGetFieldEvaluationResult(FieldElementImpl field) { |
| 509 // If we are getting the constant value for a node in the graph, make sure |
| 510 // we properly recorded the dependency. |
| 511 VariableDeclaration node = computer.findVariableDeclaration(field); |
| 512 if (node != null && computer.referenceGraph.nodes.contains(node)) { |
| 513 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, node), |
| 514 isTrue); |
| 515 } |
| 516 } |
| 517 |
| 518 @override |
| 519 void beforeGetParameterDefault(ParameterElement parameter) { |
| 520 // Find the ConstructorElement and figure out which |
| 521 // parameter we're talking about. |
| 522 ConstructorElement constructor = |
| 523 parameter.getAncestor((element) => element is ConstructorElement); |
| 524 int parameterIndex; |
| 525 List<ParameterElement> parameters = constructor.parameters; |
| 526 int numParameters = parameters.length; |
| 527 for (parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) { |
| 528 if (identical(parameters[parameterIndex], parameter)) { |
| 529 break; |
| 530 } |
| 531 } |
| 532 expect(parameterIndex < numParameters, isTrue); |
| 533 // If we are getting the default parameter for a constructor in the graph, |
| 534 // make sure we properly recorded the dependency on the parameter. |
| 535 ConstructorDeclaration constructorNode = |
| 536 computer.constructorDeclarationMap[constructor]; |
| 537 if (constructorNode != null) { |
| 538 FormalParameter parameterNode = |
| 539 constructorNode.parameters.parameters[parameterIndex]; |
| 540 expect(computer.referenceGraph.nodes.contains(parameterNode), isTrue); |
| 541 expect(computer.referenceGraph.containsPath( |
| 542 _nodeBeingEvaluated, parameterNode), isTrue); |
| 543 } |
| 544 } |
| 545 } |
| 546 |
| 469 @reflectiveTest | 547 @reflectiveTest |
| 470 class ConstantEvaluatorTest extends ResolverTestCase { | 548 class ConstantEvaluatorTest extends ResolverTestCase { |
| 471 void fail_constructor() { | 549 void fail_constructor() { |
| 472 EvaluationResult result = _getExpressionValue("?"); | 550 EvaluationResult result = _getExpressionValue("?"); |
| 473 expect(result.isValid, isTrue); | 551 expect(result.isValid, isTrue); |
| 474 DartObject value = result.value; | 552 DartObject value = result.value; |
| 475 expect(value, null); | 553 expect(value, null); |
| 476 } | 554 } |
| 477 | 555 |
| 478 void fail_identifier_class() { | 556 void fail_identifier_class() { |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 class A { | 1504 class A { |
| 1427 const A() : x = 5; | 1505 const A() : x = 5; |
| 1428 final int x; | 1506 final int x; |
| 1429 } | 1507 } |
| 1430 class B extends A { | 1508 class B extends A { |
| 1431 const B(); | 1509 const B(); |
| 1432 } | 1510 } |
| 1433 const B b = const B();'''); | 1511 const B b = const B();'''); |
| 1434 } | 1512 } |
| 1435 | 1513 |
| 1514 void test_dependencyOnInitializedFinal() { |
| 1515 // a depends on A() depends on A.x |
| 1516 _assertProperDependencies(''' |
| 1517 class A { |
| 1518 const A(); |
| 1519 final int x = 1; |
| 1520 } |
| 1521 const A a = const A(); |
| 1522 '''); |
| 1523 } |
| 1524 |
| 1436 void test_dependencyOnInitializedNonStaticConst() { | 1525 void test_dependencyOnInitializedNonStaticConst() { |
| 1437 // Even though non-static consts are not allowed by the language, we need | 1526 // Even though non-static consts are not allowed by the language, we need |
| 1438 // to handle them for error recovery purposes. | 1527 // to handle them for error recovery purposes. |
| 1439 // a depends on A() depends on A.x | 1528 // a depends on A() depends on A.x |
| 1440 _assertProperDependencies(''' | 1529 _assertProperDependencies(''' |
| 1441 class A { | 1530 class A { |
| 1442 const A(); | 1531 const A(); |
| 1443 const int x = 1; | 1532 const int x = 1; |
| 1444 } | 1533 } |
| 1445 const A a = const A(); | 1534 const A a = const A(); |
| 1446 ''', [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); | 1535 ''', [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); |
| 1447 } | 1536 } |
| 1448 | 1537 |
| 1449 void test_dependencyOnInitializedFinal() { | |
| 1450 // a depends on A() depends on A.x | |
| 1451 _assertProperDependencies(''' | |
| 1452 class A { | |
| 1453 const A(); | |
| 1454 final int x = 1; | |
| 1455 } | |
| 1456 const A a = const A(); | |
| 1457 '''); | |
| 1458 } | |
| 1459 | |
| 1460 void test_dependencyOnNonFactoryRedirect() { | 1538 void test_dependencyOnNonFactoryRedirect() { |
| 1461 // a depends on A.foo() depends on A.bar() | 1539 // a depends on A.foo() depends on A.bar() |
| 1462 _assertProperDependencies(r''' | 1540 _assertProperDependencies(r''' |
| 1463 const A a = const A.foo(); | 1541 const A a = const A.foo(); |
| 1464 class A { | 1542 class A { |
| 1465 const A.foo() : this.bar(); | 1543 const A.foo() : this.bar(); |
| 1466 const A.bar(); | 1544 const A.bar(); |
| 1467 }'''); | 1545 }'''); |
| 1468 } | 1546 } |
| 1469 | 1547 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 | 1629 |
| 1552 const A a = const A(); | 1630 const A a = const A(); |
| 1553 '''); | 1631 '''); |
| 1554 EvaluationResultImpl result = | 1632 EvaluationResultImpl result = |
| 1555 _evaluateInstanceCreationExpression(compilationUnit, 'a'); | 1633 _evaluateInstanceCreationExpression(compilationUnit, 'a'); |
| 1556 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1634 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1557 expect(fields, hasLength(1)); | 1635 expect(fields, hasLength(1)); |
| 1558 _assertIntField(fields, "i", 123); | 1636 _assertIntField(fields, "i", 123); |
| 1559 } | 1637 } |
| 1560 | 1638 |
| 1561 void test_non_static_const_initialized_at_declaration() { | |
| 1562 // Even though non-static consts are not allowed by the language, we need | |
| 1563 // to handle them for error recovery purposes. | |
| 1564 CompilationUnit compilationUnit = resolveSource(''' | |
| 1565 class A { | |
| 1566 const int i = 123; | |
| 1567 const A(); | |
| 1568 } | |
| 1569 | |
| 1570 const A a = const A(); | |
| 1571 '''); | |
| 1572 EvaluationResultImpl result = | |
| 1573 _evaluateInstanceCreationExpression(compilationUnit, 'a'); | |
| 1574 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1575 expect(fields, hasLength(1)); | |
| 1576 _assertIntField(fields, "i", 123); | |
| 1577 } | |
| 1578 | |
| 1579 void test_fromEnvironment_bool_default_false() { | 1639 void test_fromEnvironment_bool_default_false() { |
| 1580 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); | 1640 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); |
| 1581 } | 1641 } |
| 1582 | 1642 |
| 1583 void test_fromEnvironment_bool_default_overridden() { | 1643 void test_fromEnvironment_bool_default_overridden() { |
| 1584 expect( | 1644 expect( |
| 1585 _assertValidBool(_check_fromEnvironment_bool("false", "true")), false); | 1645 _assertValidBool(_check_fromEnvironment_bool("false", "true")), false); |
| 1586 } | 1646 } |
| 1587 | 1647 |
| 1588 void test_fromEnvironment_bool_default_parseError() { | 1648 void test_fromEnvironment_bool_default_parseError() { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 expect(ConstantValueComputer.isValidPublicSymbol("if"), isFalse); | 2130 expect(ConstantValueComputer.isValidPublicSymbol("if"), isFalse); |
| 2071 expect(ConstantValueComputer.isValidPublicSymbol("if.foo"), isFalse); | 2131 expect(ConstantValueComputer.isValidPublicSymbol("if.foo"), isFalse); |
| 2072 expect(ConstantValueComputer.isValidPublicSymbol("foo.if"), isFalse); | 2132 expect(ConstantValueComputer.isValidPublicSymbol("foo.if"), isFalse); |
| 2073 expect(ConstantValueComputer.isValidPublicSymbol("foo=.bar"), isFalse); | 2133 expect(ConstantValueComputer.isValidPublicSymbol("foo=.bar"), isFalse); |
| 2074 expect(ConstantValueComputer.isValidPublicSymbol("foo."), isFalse); | 2134 expect(ConstantValueComputer.isValidPublicSymbol("foo."), isFalse); |
| 2075 expect(ConstantValueComputer.isValidPublicSymbol("+.foo"), isFalse); | 2135 expect(ConstantValueComputer.isValidPublicSymbol("+.foo"), isFalse); |
| 2076 expect(ConstantValueComputer.isValidPublicSymbol("void.foo"), isFalse); | 2136 expect(ConstantValueComputer.isValidPublicSymbol("void.foo"), isFalse); |
| 2077 expect(ConstantValueComputer.isValidPublicSymbol("foo.void"), isFalse); | 2137 expect(ConstantValueComputer.isValidPublicSymbol("foo.void"), isFalse); |
| 2078 } | 2138 } |
| 2079 | 2139 |
| 2140 void test_non_static_const_initialized_at_declaration() { |
| 2141 // Even though non-static consts are not allowed by the language, we need |
| 2142 // to handle them for error recovery purposes. |
| 2143 CompilationUnit compilationUnit = resolveSource(''' |
| 2144 class A { |
| 2145 const int i = 123; |
| 2146 const A(); |
| 2147 } |
| 2148 |
| 2149 const A a = const A(); |
| 2150 '''); |
| 2151 EvaluationResultImpl result = |
| 2152 _evaluateInstanceCreationExpression(compilationUnit, 'a'); |
| 2153 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 2154 expect(fields, hasLength(1)); |
| 2155 _assertIntField(fields, "i", 123); |
| 2156 } |
| 2157 |
| 2080 void test_symbolLiteral_void() { | 2158 void test_symbolLiteral_void() { |
| 2081 CompilationUnit compilationUnit = | 2159 CompilationUnit compilationUnit = |
| 2082 resolveSource("const voidSymbol = #void;"); | 2160 resolveSource("const voidSymbol = #void;"); |
| 2083 VariableDeclaration voidSymbol = | 2161 VariableDeclaration voidSymbol = |
| 2084 findTopLevelDeclaration(compilationUnit, "voidSymbol"); | 2162 findTopLevelDeclaration(compilationUnit, "voidSymbol"); |
| 2085 EvaluationResultImpl voidSymbolResult = | 2163 EvaluationResultImpl voidSymbolResult = |
| 2086 (voidSymbol.element as VariableElementImpl).evaluationResult; | 2164 (voidSymbol.element as VariableElementImpl).evaluationResult; |
| 2087 DartObjectImpl value = voidSymbolResult.value; | 2165 DartObjectImpl value = voidSymbolResult.value; |
| 2088 expect(value.type, typeProvider.symbolType); | 2166 expect(value.type, typeProvider.symbolType); |
| 2089 expect(value.value, "void"); | 2167 expect(value.value, "void"); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 } | 2365 } |
| 2288 | 2366 |
| 2289 EvaluationResultImpl _evaluateInstanceCreationExpression( | 2367 EvaluationResultImpl _evaluateInstanceCreationExpression( |
| 2290 CompilationUnit compilationUnit, String name) { | 2368 CompilationUnit compilationUnit, String name) { |
| 2291 Expression expression = | 2369 Expression expression = |
| 2292 findTopLevelConstantExpression(compilationUnit, name); | 2370 findTopLevelConstantExpression(compilationUnit, name); |
| 2293 return (expression as InstanceCreationExpression).evaluationResult; | 2371 return (expression as InstanceCreationExpression).evaluationResult; |
| 2294 } | 2372 } |
| 2295 | 2373 |
| 2296 ConstantValueComputer _makeConstantValueComputer() { | 2374 ConstantValueComputer _makeConstantValueComputer() { |
| 2297 return new ValidatingConstantValueComputer( | 2375 ConstantEvaluationValidator_ForTest validator = |
| 2298 analysisContext2.typeProvider, analysisContext2.declaredVariables); | 2376 new ConstantEvaluationValidator_ForTest(); |
| 2377 validator.computer = new ConstantValueComputer( |
| 2378 analysisContext2.typeProvider, analysisContext2.declaredVariables, |
| 2379 validator); |
| 2380 return validator.computer; |
| 2299 } | 2381 } |
| 2300 | 2382 |
| 2301 void _validate(bool shouldBeValid, VariableDeclarationList declarationList) { | 2383 void _validate(bool shouldBeValid, VariableDeclarationList declarationList) { |
| 2302 for (VariableDeclaration declaration in declarationList.variables) { | 2384 for (VariableDeclaration declaration in declarationList.variables) { |
| 2303 VariableElementImpl element = declaration.element as VariableElementImpl; | 2385 VariableElementImpl element = declaration.element as VariableElementImpl; |
| 2304 expect(element, isNotNull); | 2386 expect(element, isNotNull); |
| 2305 EvaluationResultImpl result = element.evaluationResult; | 2387 EvaluationResultImpl result = element.evaluationResult; |
| 2306 if (shouldBeValid) { | 2388 if (shouldBeValid) { |
| 2307 expect(result.value, isNotNull); | 2389 expect(result.value, isNotNull); |
| 2308 } else { | 2390 } else { |
| 2309 expect(result.value, isNull); | 2391 expect(result.value, isNull); |
| 2310 } | 2392 } |
| 2311 } | 2393 } |
| 2312 } | 2394 } |
| 2313 } | 2395 } |
| 2314 | 2396 |
| 2315 class ConstantValueComputerTest_ValidatingConstantVisitor | |
| 2316 extends ConstantVisitor { | |
| 2317 final DirectedGraph<AstNode> _referenceGraph; | |
| 2318 final AstNode _nodeBeingEvaluated; | |
| 2319 | |
| 2320 ConstantValueComputerTest_ValidatingConstantVisitor(TypeProvider typeProvider, | |
| 2321 this._referenceGraph, this._nodeBeingEvaluated, | |
| 2322 ErrorReporter errorReporter) | |
| 2323 : super.con1(typeProvider, errorReporter); | |
| 2324 | |
| 2325 @override | |
| 2326 void beforeGetEvaluationResult(AstNode node) { | |
| 2327 super.beforeGetEvaluationResult(node); | |
| 2328 // If we are getting the evaluation result for a node in the graph, | |
| 2329 // make sure we properly recorded the dependency. | |
| 2330 if (_referenceGraph.nodes.contains(node)) { | |
| 2331 expect(_referenceGraph.containsPath(_nodeBeingEvaluated, node), isTrue); | |
| 2332 } | |
| 2333 } | |
| 2334 } | |
| 2335 | |
| 2336 @reflectiveTest | 2397 @reflectiveTest |
| 2337 class ConstantVisitorTest extends ResolverTestCase { | 2398 class ConstantVisitorTest extends ResolverTestCase { |
| 2338 void test_visitConditionalExpression_false() { | 2399 void test_visitConditionalExpression_false() { |
| 2339 Expression thenExpression = AstFactory.integer(1); | 2400 Expression thenExpression = AstFactory.integer(1); |
| 2340 Expression elseExpression = AstFactory.integer(0); | 2401 Expression elseExpression = AstFactory.integer(0); |
| 2341 ConditionalExpression expression = AstFactory.conditionalExpression( | 2402 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2342 AstFactory.booleanLiteral(false), thenExpression, elseExpression); | 2403 AstFactory.booleanLiteral(false), thenExpression, elseExpression); |
| 2343 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2404 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2344 ErrorReporter errorReporter = | 2405 ErrorReporter errorReporter = |
| 2345 new ErrorReporter(errorListener, _dummySource()); | 2406 new ErrorReporter(errorListener, _dummySource()); |
| 2346 _assertValue(0, expression.accept( | 2407 _assertValue(0, expression |
| 2347 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); | 2408 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter))); |
| 2348 errorListener.assertNoErrors(); | 2409 errorListener.assertNoErrors(); |
| 2349 } | 2410 } |
| 2350 | 2411 |
| 2351 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { | 2412 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { |
| 2352 TestTypeProvider typeProvider = new TestTypeProvider(); | 2413 TestTypeProvider typeProvider = new TestTypeProvider(); |
| 2353 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); | 2414 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); |
| 2354 String className = "C"; | 2415 String className = "C"; |
| 2355 ClassElementImpl classElement = ElementFactory.classElement2(className); | 2416 ClassElementImpl classElement = ElementFactory.classElement2(className); |
| 2356 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= | 2417 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= |
| 2357 <ClassElement>[classElement]; | 2418 <ClassElement>[classElement]; |
| 2358 ConstructorElementImpl constructorElement = ElementFactory | 2419 ConstructorElementImpl constructorElement = ElementFactory |
| 2359 .constructorElement(classElement, null, true, [typeProvider.intType]); | 2420 .constructorElement(classElement, null, true, [typeProvider.intType]); |
| 2360 constructorElement.parameters[0] = | 2421 constructorElement.parameters[0] = |
| 2361 new FieldFormalParameterElementImpl(AstFactory.identifier3("x")); | 2422 new FieldFormalParameterElementImpl(AstFactory.identifier3("x")); |
| 2362 InstanceCreationExpression expression = AstFactory | 2423 InstanceCreationExpression expression = AstFactory |
| 2363 .instanceCreationExpression2(Keyword.CONST, | 2424 .instanceCreationExpression2(Keyword.CONST, |
| 2364 AstFactory.typeName4(className), [AstFactory.integer(0)]); | 2425 AstFactory.typeName4(className), [AstFactory.integer(0)]); |
| 2365 expression.staticElement = constructorElement; | 2426 expression.staticElement = constructorElement; |
| 2366 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2427 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2367 ErrorReporter errorReporter = | 2428 ErrorReporter errorReporter = |
| 2368 new ErrorReporter(errorListener, _dummySource()); | 2429 new ErrorReporter(errorListener, _dummySource()); |
| 2369 expression.accept(new ConstantVisitor.con1(typeProvider, errorReporter)); | 2430 expression.accept(new ConstantVisitor(typeProvider, errorReporter)); |
| 2370 errorListener | 2431 errorListener |
| 2371 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2432 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2372 } | 2433 } |
| 2373 | 2434 |
| 2374 void test_visitConditionalExpression_nonBooleanCondition() { | 2435 void test_visitConditionalExpression_nonBooleanCondition() { |
| 2375 Expression thenExpression = AstFactory.integer(1); | 2436 Expression thenExpression = AstFactory.integer(1); |
| 2376 Expression elseExpression = AstFactory.integer(0); | 2437 Expression elseExpression = AstFactory.integer(0); |
| 2377 NullLiteral conditionExpression = AstFactory.nullLiteral(); | 2438 NullLiteral conditionExpression = AstFactory.nullLiteral(); |
| 2378 ConditionalExpression expression = AstFactory.conditionalExpression( | 2439 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2379 conditionExpression, thenExpression, elseExpression); | 2440 conditionExpression, thenExpression, elseExpression); |
| 2380 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2441 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2381 ErrorReporter errorReporter = | 2442 ErrorReporter errorReporter = |
| 2382 new ErrorReporter(errorListener, _dummySource()); | 2443 new ErrorReporter(errorListener, _dummySource()); |
| 2383 DartObjectImpl result = expression.accept( | 2444 DartObjectImpl result = expression |
| 2384 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter)); | 2445 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); |
| 2385 expect(result, isNull); | 2446 expect(result, isNull); |
| 2386 errorListener | 2447 errorListener |
| 2387 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); | 2448 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); |
| 2388 } | 2449 } |
| 2389 | 2450 |
| 2390 void test_visitConditionalExpression_nonConstantElse() { | 2451 void test_visitConditionalExpression_nonConstantElse() { |
| 2391 Expression thenExpression = AstFactory.integer(1); | 2452 Expression thenExpression = AstFactory.integer(1); |
| 2392 Expression elseExpression = AstFactory.identifier3("x"); | 2453 Expression elseExpression = AstFactory.identifier3("x"); |
| 2393 ConditionalExpression expression = AstFactory.conditionalExpression( | 2454 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2394 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2455 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2395 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2456 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2396 ErrorReporter errorReporter = | 2457 ErrorReporter errorReporter = |
| 2397 new ErrorReporter(errorListener, _dummySource()); | 2458 new ErrorReporter(errorListener, _dummySource()); |
| 2398 DartObjectImpl result = expression.accept( | 2459 DartObjectImpl result = expression |
| 2399 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter)); | 2460 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); |
| 2400 expect(result, isNull); | 2461 expect(result, isNull); |
| 2401 errorListener | 2462 errorListener |
| 2402 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2463 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2403 } | 2464 } |
| 2404 | 2465 |
| 2405 void test_visitConditionalExpression_nonConstantThen() { | 2466 void test_visitConditionalExpression_nonConstantThen() { |
| 2406 Expression thenExpression = AstFactory.identifier3("x"); | 2467 Expression thenExpression = AstFactory.identifier3("x"); |
| 2407 Expression elseExpression = AstFactory.integer(0); | 2468 Expression elseExpression = AstFactory.integer(0); |
| 2408 ConditionalExpression expression = AstFactory.conditionalExpression( | 2469 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2409 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2470 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2410 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2471 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2411 ErrorReporter errorReporter = | 2472 ErrorReporter errorReporter = |
| 2412 new ErrorReporter(errorListener, _dummySource()); | 2473 new ErrorReporter(errorListener, _dummySource()); |
| 2413 DartObjectImpl result = expression.accept( | 2474 DartObjectImpl result = expression |
| 2414 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter)); | 2475 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); |
| 2415 expect(result, isNull); | 2476 expect(result, isNull); |
| 2416 errorListener | 2477 errorListener |
| 2417 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2478 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2418 } | 2479 } |
| 2419 | 2480 |
| 2420 void test_visitConditionalExpression_true() { | 2481 void test_visitConditionalExpression_true() { |
| 2421 Expression thenExpression = AstFactory.integer(1); | 2482 Expression thenExpression = AstFactory.integer(1); |
| 2422 Expression elseExpression = AstFactory.integer(0); | 2483 Expression elseExpression = AstFactory.integer(0); |
| 2423 ConditionalExpression expression = AstFactory.conditionalExpression( | 2484 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2424 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2485 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2425 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2486 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2426 ErrorReporter errorReporter = | 2487 ErrorReporter errorReporter = |
| 2427 new ErrorReporter(errorListener, _dummySource()); | 2488 new ErrorReporter(errorListener, _dummySource()); |
| 2428 _assertValue(1, expression.accept( | 2489 _assertValue(1, expression |
| 2429 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); | 2490 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter))); |
| 2430 errorListener.assertNoErrors(); | 2491 errorListener.assertNoErrors(); |
| 2431 } | 2492 } |
| 2432 | 2493 |
| 2433 void test_visitSimpleIdentifier_className() { | 2494 void test_visitSimpleIdentifier_className() { |
| 2434 CompilationUnit compilationUnit = resolveSource(''' | 2495 CompilationUnit compilationUnit = resolveSource(''' |
| 2435 const a = C; | 2496 const a = C; |
| 2436 class C {} | 2497 class C {} |
| 2437 '''); | 2498 '''); |
| 2438 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); | 2499 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); |
| 2439 expect(result.type, typeProvider.typeType); | 2500 expect(result.type, typeProvider.typeType); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 return new NonExistingSource("foo.dart", UriKind.FILE_URI); | 2550 return new NonExistingSource("foo.dart", UriKind.FILE_URI); |
| 2490 } | 2551 } |
| 2491 | 2552 |
| 2492 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | 2553 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, |
| 2493 Map<String, DartObjectImpl> lexicalEnvironment) { | 2554 Map<String, DartObjectImpl> lexicalEnvironment) { |
| 2494 Source source = compilationUnit.element.source; | 2555 Source source = compilationUnit.element.source; |
| 2495 Expression expression = | 2556 Expression expression = |
| 2496 findTopLevelConstantExpression(compilationUnit, name); | 2557 findTopLevelConstantExpression(compilationUnit, name); |
| 2497 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2558 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2498 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 2559 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 2499 DartObjectImpl result = expression.accept(new ConstantVisitor.con2( | 2560 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2500 typeProvider, lexicalEnvironment, errorReporter)); | 2561 typeProvider, errorReporter, null, lexicalEnvironment)); |
| 2501 errorListener.assertNoErrors(); | 2562 errorListener.assertNoErrors(); |
| 2502 return result; | 2563 return result; |
| 2503 } | 2564 } |
| 2504 } | 2565 } |
| 2505 | 2566 |
| 2506 @reflectiveTest | 2567 @reflectiveTest |
| 2507 class ContentCacheTest { | 2568 class ContentCacheTest { |
| 2508 void test_setContents() { | 2569 void test_setContents() { |
| 2509 Source source = new TestSource(); | 2570 Source source = new TestSource(); |
| 2510 ContentCache cache = new ContentCache(); | 2571 ContentCache cache = new ContentCache(); |
| (...skipping 5930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8441 | 8502 |
| 8442 @override | 8503 @override |
| 8443 Source resolveAbsolute(Uri uri) { | 8504 Source resolveAbsolute(Uri uri) { |
| 8444 if (uri.toString() == encoding) { | 8505 if (uri.toString() == encoding) { |
| 8445 return new TestSource(); | 8506 return new TestSource(); |
| 8446 } | 8507 } |
| 8447 return null; | 8508 return null; |
| 8448 } | 8509 } |
| 8449 } | 8510 } |
| 8450 | 8511 |
| 8451 class ValidatingConstantValueComputer extends ConstantValueComputer { | |
| 8452 AstNode _nodeBeingEvaluated; | |
| 8453 ValidatingConstantValueComputer( | |
| 8454 TypeProvider typeProvider, DeclaredVariables declaredVariables) | |
| 8455 : super(typeProvider, declaredVariables); | |
| 8456 | |
| 8457 @override | |
| 8458 void beforeComputeValue(AstNode constNode) { | |
| 8459 super.beforeComputeValue(constNode); | |
| 8460 _nodeBeingEvaluated = constNode; | |
| 8461 } | |
| 8462 | |
| 8463 @override | |
| 8464 void beforeGetFieldEvaluationResult(FieldElementImpl field) { | |
| 8465 super.beforeGetFieldEvaluationResult(field); | |
| 8466 // If we are getting the constant value for a node in the graph, make sure | |
| 8467 // we properly recorded the dependency. | |
| 8468 VariableDeclaration node = findVariableDeclaration(field); | |
| 8469 if (node != null && referenceGraph.nodes.contains(node)) { | |
| 8470 expect(referenceGraph.containsPath(_nodeBeingEvaluated, node), isTrue); | |
| 8471 } | |
| 8472 } | |
| 8473 | |
| 8474 @override | |
| 8475 void beforeGetConstantInitializers(ConstructorElement constructor) { | |
| 8476 super.beforeGetConstantInitializers(constructor); | |
| 8477 // If we are getting the constant initializers for a node in the graph, | |
| 8478 // make sure we properly recorded the dependency. | |
| 8479 ConstructorDeclaration node = findConstructorDeclaration(constructor); | |
| 8480 if (node != null && referenceGraph.nodes.contains(node)) { | |
| 8481 expect(referenceGraph.containsPath(_nodeBeingEvaluated, node), isTrue); | |
| 8482 } | |
| 8483 } | |
| 8484 | |
| 8485 @override | |
| 8486 void beforeGetParameterDefault(ParameterElement parameter) { | |
| 8487 super.beforeGetParameterDefault(parameter); | |
| 8488 // Find the ConstructorElement and figure out which | |
| 8489 // parameter we're talking about. | |
| 8490 ConstructorElement constructor = | |
| 8491 parameter.getAncestor((element) => element is ConstructorElement); | |
| 8492 int parameterIndex; | |
| 8493 List<ParameterElement> parameters = constructor.parameters; | |
| 8494 int numParameters = parameters.length; | |
| 8495 for (parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) { | |
| 8496 if (identical(parameters[parameterIndex], parameter)) { | |
| 8497 break; | |
| 8498 } | |
| 8499 } | |
| 8500 expect(parameterIndex < numParameters, isTrue); | |
| 8501 // If we are getting the default parameter for a constructor in the graph, | |
| 8502 // make sure we properly recorded the dependency on the parameter. | |
| 8503 ConstructorDeclaration constructorNode = | |
| 8504 constructorDeclarationMap[constructor]; | |
| 8505 if (constructorNode != null) { | |
| 8506 FormalParameter parameterNode = | |
| 8507 constructorNode.parameters.parameters[parameterIndex]; | |
| 8508 expect(referenceGraph.nodes.contains(parameterNode), isTrue); | |
| 8509 expect(referenceGraph.containsPath(_nodeBeingEvaluated, parameterNode), | |
| 8510 isTrue); | |
| 8511 } | |
| 8512 } | |
| 8513 | |
| 8514 @override | |
| 8515 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) { | |
| 8516 return new ConstantValueComputerTest_ValidatingConstantVisitor( | |
| 8517 typeProvider, referenceGraph, _nodeBeingEvaluated, errorReporter); | |
| 8518 } | |
| 8519 } | |
| 8520 | |
| 8521 /** | 8512 /** |
| 8522 * Instances of `XmlValidator` traverse an [XmlNode] structure and validate the
node | 8513 * Instances of `XmlValidator` traverse an [XmlNode] structure and validate the
node |
| 8523 * hierarchy. | 8514 * hierarchy. |
| 8524 */ | 8515 */ |
| 8525 class XmlValidator extends ht.RecursiveXmlVisitor<Object> { | 8516 class XmlValidator extends ht.RecursiveXmlVisitor<Object> { |
| 8526 /** | 8517 /** |
| 8527 * A list containing the errors found while traversing the AST structure. | 8518 * A list containing the errors found while traversing the AST structure. |
| 8528 */ | 8519 */ |
| 8529 List<String> _errors = new List<String>(); | 8520 List<String> _errors = new List<String>(); |
| 8530 /** | 8521 /** |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8784 if (_expectedExternalScriptName == null) { | 8775 if (_expectedExternalScriptName == null) { |
| 8785 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8776 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
| 8786 } else { | 8777 } else { |
| 8787 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8778 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
| 8788 String actualExternalScriptName = scriptSource.shortName; | 8779 String actualExternalScriptName = scriptSource.shortName; |
| 8789 expect(actualExternalScriptName, _expectedExternalScriptName, | 8780 expect(actualExternalScriptName, _expectedExternalScriptName, |
| 8790 reason: "script $scriptIndex"); | 8781 reason: "script $scriptIndex"); |
| 8791 } | 8782 } |
| 8792 } | 8783 } |
| 8793 } | 8784 } |
| OLD | NEW |