| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /** |
| 6 * This library is capable of producing linked summaries from unlinked | 6 * This library is capable of producing linked summaries from unlinked |
| 7 * ones (or prelinked ones). It functions by building a miniature | 7 * ones (or prelinked ones). It functions by building a miniature |
| 8 * element model to represent the contents of the summaries, and then | 8 * element model to represent the contents of the summaries, and then |
| 9 * scanning the element model to gather linked information and adding | 9 * scanning the element model to gather linked information and adding |
| 10 * it to the summary data structures. | 10 * it to the summary data structures. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 * during linking. | 162 * during linking. |
| 163 */ | 163 */ |
| 164 abstract class ClassElementForLink | 164 abstract class ClassElementForLink |
| 165 implements ClassElementImpl, ReferenceableElementForLink { | 165 implements ClassElementImpl, ReferenceableElementForLink { |
| 166 Map<String, ReferenceableElementForLink> _containedNames; | 166 Map<String, ReferenceableElementForLink> _containedNames; |
| 167 | 167 |
| 168 @override | 168 @override |
| 169 final CompilationUnitElementForLink enclosingElement; | 169 final CompilationUnitElementForLink enclosingElement; |
| 170 | 170 |
| 171 @override | 171 @override |
| 172 bool hasBeenInferred = false; | 172 bool hasBeenInferred; |
| 173 | 173 |
| 174 ClassElementForLink(this.enclosingElement); | 174 ClassElementForLink(CompilationUnitElementForLink enclosingElement) |
| 175 : enclosingElement = enclosingElement, |
| 176 hasBeenInferred = !enclosingElement.isInBuildUnit; |
| 175 | 177 |
| 176 @override | 178 @override |
| 177 ConstructorElementForLink get asConstructor => unnamedConstructor; | 179 ConstructorElementForLink get asConstructor => unnamedConstructor; |
| 178 | 180 |
| 179 @override | 181 @override |
| 180 ConstVariableNode get asConstVariable { | 182 ConstVariableNode get asConstVariable { |
| 181 // When a class name is used as a constant variable, it doesn't depend on | 183 // When a class name is used as a constant variable, it doesn't depend on |
| 182 // anything, so it is not necessary to include it in the constant | 184 // anything, so it is not necessary to include it in the constant |
| 183 // dependency graph. | 185 // dependency graph. |
| 184 return null; | 186 return null; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 222 } |
| 221 } | 223 } |
| 222 // TODO(paulberry): add methods. | 224 // TODO(paulberry): add methods. |
| 223 } | 225 } |
| 224 return _containedNames.putIfAbsent( | 226 return _containedNames.putIfAbsent( |
| 225 name, () => UndefinedElementForLink.instance); | 227 name, () => UndefinedElementForLink.instance); |
| 226 } | 228 } |
| 227 | 229 |
| 228 /** | 230 /** |
| 229 * Perform type inference and cycle detection on this class and | 231 * Perform type inference and cycle detection on this class and |
| 230 * store the resulting information in the enclosing elements. | 232 * store the resulting information in [compilationUnit]. |
| 231 */ | 233 */ |
| 232 void link(LinkedUnitBuilder linkedUnit); | 234 void link(CompilationUnitElementInBuildUnit compilationUnit); |
| 233 | 235 |
| 234 @override | 236 @override |
| 235 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 237 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 236 | 238 |
| 237 /** | 239 /** |
| 238 * Throw away any information produced by a previous call to [link]. | 240 * Throw away any information produced by a previous call to [link]. |
| 239 */ | 241 */ |
| 240 void unlink(); | 242 void unlink(); |
| 241 } | 243 } |
| 242 | 244 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 400 } |
| 399 } | 401 } |
| 400 | 402 |
| 401 @override | 403 @override |
| 402 TypeParameterType getTypeParameterType(int index) { | 404 TypeParameterType getTypeParameterType(int index) { |
| 403 List<TypeParameterType> types = typeParameterTypes; | 405 List<TypeParameterType> types = typeParameterTypes; |
| 404 return types[types.length - index]; | 406 return types[types.length - index]; |
| 405 } | 407 } |
| 406 | 408 |
| 407 @override | 409 @override |
| 408 void link(LinkedUnitBuilder linkedUnit) { | 410 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 409 for (ConstructorElementForLink constructorElement in constructors) { | 411 for (ConstructorElementForLink constructorElement in constructors) { |
| 410 constructorElement.link(linkedUnit); | 412 constructorElement.link(compilationUnit); |
| 411 } | 413 } |
| 412 for (MethodElementForLink methodElement in methods) { | 414 for (MethodElementForLink methodElement in methods) { |
| 413 methodElement.link(linkedUnit); | 415 methodElement.link(compilationUnit); |
| 414 } | 416 } |
| 415 } | 417 } |
| 416 | 418 |
| 417 @override | 419 @override |
| 418 void unlink() { | 420 void unlink() { |
| 419 hasBeenInferred = false; | 421 hasBeenInferred = false; |
| 420 for (MethodElementForLink methodElement in methods) { | 422 for (MethodElementForLink methodElement in methods) { |
| 421 methodElement.unlink(); | 423 methodElement.unlink(); |
| 422 } | 424 } |
| 423 } | 425 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 502 |
| 501 @override | 503 @override |
| 502 ConstructorElementForLink get unnamedConstructor => null; | 504 ConstructorElementForLink get unnamedConstructor => null; |
| 503 | 505 |
| 504 @override | 506 @override |
| 505 DartType buildType(DartType getTypeArgument(int i), | 507 DartType buildType(DartType getTypeArgument(int i), |
| 506 List<int> implicitFunctionTypeIndices) => | 508 List<int> implicitFunctionTypeIndices) => |
| 507 _type ??= new InterfaceTypeImpl(this); | 509 _type ??= new InterfaceTypeImpl(this); |
| 508 | 510 |
| 509 @override | 511 @override |
| 510 void link(LinkedUnitBuilder linkedUnit) {} | 512 void link(CompilationUnitElementInBuildUnit compilationUnit) {} |
| 511 | 513 |
| 512 @override | 514 @override |
| 513 void unlink() {} | 515 void unlink() {} |
| 514 } | 516 } |
| 515 | 517 |
| 516 /** | 518 /** |
| 517 * Element representing a compilation unit resynthesized from a | 519 * Element representing a compilation unit resynthesized from a |
| 518 * summary during linking. | 520 * summary during linking. |
| 519 */ | 521 */ |
| 520 abstract class CompilationUnitElementForLink implements CompilationUnitElement { | 522 abstract class CompilationUnitElementForLink implements CompilationUnitElement { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 * Perform type inference and const cycle detection on this | 746 * Perform type inference and const cycle detection on this |
| 745 * compilation unit. | 747 * compilation unit. |
| 746 */ | 748 */ |
| 747 void link() { | 749 void link() { |
| 748 if (library._linker.strongMode) { | 750 if (library._linker.strongMode) { |
| 749 new InstanceMemberInferrer(enclosingElement._linker.typeProvider, | 751 new InstanceMemberInferrer(enclosingElement._linker.typeProvider, |
| 750 enclosingElement.inheritanceManager) | 752 enclosingElement.inheritanceManager) |
| 751 .inferCompilationUnit(this); | 753 .inferCompilationUnit(this); |
| 752 } | 754 } |
| 753 for (ClassElementForLink classElement in types) { | 755 for (ClassElementForLink classElement in types) { |
| 754 classElement.link(_linkedUnit); | 756 classElement.link(this); |
| 755 } | 757 } |
| 756 } | 758 } |
| 757 | 759 |
| 758 /** | 760 /** |
| 759 * Throw away any information produced by a previous call to [link]. | 761 * Throw away any information produced by a previous call to [link]. |
| 760 */ | 762 */ |
| 761 void unlink() { | 763 void unlink() { |
| 762 _linkedUnit.constCycles.clear(); | 764 _linkedUnit.constCycles.clear(); |
| 763 _linkedUnit.references.length = _unlinkedUnit.references.length; | 765 _linkedUnit.references.length = _unlinkedUnit.references.length; |
| 764 _linkedUnit.types.clear(); | 766 _linkedUnit.types.clear(); |
| 765 for (ClassElementForLink classElement in types) { | 767 for (ClassElementForLink classElement in types) { |
| 766 classElement.unlink(); | 768 classElement.unlink(); |
| 767 } | 769 } |
| 768 } | 770 } |
| 771 |
| 772 /** |
| 773 * Store the fact that the given [slot] represents a constant constructor |
| 774 * that is part of a cycle. |
| 775 */ |
| 776 void _storeConstCycle(int slot) { |
| 777 _linkedUnit.constCycles.add(slot); |
| 778 } |
| 779 |
| 780 /** |
| 781 * Store the given [linkedType] in the given [slot] of the this compilation |
| 782 * unit's linked type list. |
| 783 */ |
| 784 void _storeLinkedType(int slot, DartType linkedType) { |
| 785 if (slot != 0) { |
| 786 if (linkedType != null && !linkedType.isDynamic) { |
| 787 _linkedUnit.types.add(_createLinkedType(linkedType, this, slot: slot)); |
| 788 } |
| 789 } |
| 790 } |
| 769 } | 791 } |
| 770 | 792 |
| 771 /** | 793 /** |
| 772 * Element representing a compilation unit which is depended upon | 794 * Element representing a compilation unit which is depended upon |
| 773 * (either directly or indirectly) by the build unit being linked. | 795 * (either directly or indirectly) by the build unit being linked. |
| 796 * |
| 797 * TODO(paulberry): ensure that inferred types in dependencies are properly |
| 798 * resynthesized. |
| 774 */ | 799 */ |
| 775 class CompilationUnitElementInDependency extends CompilationUnitElementForLink { | 800 class CompilationUnitElementInDependency extends CompilationUnitElementForLink { |
| 776 @override | 801 @override |
| 777 final LinkedUnit _linkedUnit; | 802 final LinkedUnit _linkedUnit; |
| 778 | 803 |
| 779 @override | 804 @override |
| 780 final LibraryElementInDependency enclosingElement; | 805 final LibraryElementInDependency enclosingElement; |
| 781 | 806 |
| 782 CompilationUnitElementInDependency(this.enclosingElement, | 807 CompilationUnitElementInDependency(this.enclosingElement, |
| 783 UnlinkedUnit unlinkedUnit, this._linkedUnit, int unitNum) | 808 UnlinkedUnit unlinkedUnit, this._linkedUnit, int unitNum) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 } | 1073 } |
| 1049 | 1074 |
| 1050 @override | 1075 @override |
| 1051 String get name => _unlinkedExecutable.name; | 1076 String get name => _unlinkedExecutable.name; |
| 1052 | 1077 |
| 1053 @override | 1078 @override |
| 1054 List<ParameterElementForLink> get parameters { | 1079 List<ParameterElementForLink> get parameters { |
| 1055 if (_parameters == null) { | 1080 if (_parameters == null) { |
| 1056 _parameters = <ParameterElementForLink>[]; | 1081 _parameters = <ParameterElementForLink>[]; |
| 1057 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { | 1082 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { |
| 1058 _parameters.add(new ParameterElementForLink( | 1083 _parameters.add(new ParameterElementForLink(unlinkedParam, |
| 1059 unlinkedParam, enclosingElement.enclosingElement)); | 1084 enclosingElement, enclosingElement.enclosingElement)); |
| 1060 } | 1085 } |
| 1061 } | 1086 } |
| 1062 return _parameters; | 1087 return _parameters; |
| 1063 } | 1088 } |
| 1064 | 1089 |
| 1065 @override | 1090 @override |
| 1066 DartType buildType(DartType getTypeArgument(int i), | 1091 DartType buildType(DartType getTypeArgument(int i), |
| 1067 List<int> implicitFunctionTypeIndices) => | 1092 List<int> implicitFunctionTypeIndices) => |
| 1068 DynamicTypeImpl.instance; | 1093 DynamicTypeImpl.instance; |
| 1069 | 1094 |
| 1070 @override | 1095 @override |
| 1071 ReferenceableElementForLink getContainedName(String name) => | 1096 ReferenceableElementForLink getContainedName(String name) => |
| 1072 UndefinedElementForLink.instance; | 1097 UndefinedElementForLink.instance; |
| 1073 | 1098 |
| 1074 /** | 1099 /** |
| 1075 * Perform const cycle detection on this constructor. | 1100 * Perform const cycle detection on this constructor. |
| 1076 */ | 1101 */ |
| 1077 void link(LinkedUnitBuilder linkedUnit) { | 1102 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 1078 if (_constNode != null && !isCycleFree) { | 1103 if (_constNode != null && !isCycleFree) { |
| 1079 linkedUnit.constCycles.add(_unlinkedExecutable.constCycleSlot); | 1104 compilationUnit._storeConstCycle(_unlinkedExecutable.constCycleSlot); |
| 1080 } | 1105 } |
| 1081 } | 1106 } |
| 1082 | 1107 |
| 1083 @override | 1108 @override |
| 1084 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1109 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1085 } | 1110 } |
| 1086 | 1111 |
| 1087 /** | 1112 /** |
| 1088 * Instance of [ConstNode] representing a constant field or constant | 1113 * Instance of [ConstNode] representing a constant field or constant |
| 1089 * top level variable. | 1114 * top level variable. |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 } | 1492 } |
| 1468 } | 1493 } |
| 1469 | 1494 |
| 1470 /** | 1495 /** |
| 1471 * Throw away any information produced by a previous call to [link]. | 1496 * Throw away any information produced by a previous call to [link]. |
| 1472 */ | 1497 */ |
| 1473 void unlink() { | 1498 void unlink() { |
| 1474 _linkedLibrary.dependencies.length = | 1499 _linkedLibrary.dependencies.length = |
| 1475 _linkedLibrary.numPrelinkedDependencies; | 1500 _linkedLibrary.numPrelinkedDependencies; |
| 1476 for (CompilationUnitElementInBuildUnit unit in units) { | 1501 for (CompilationUnitElementInBuildUnit unit in units) { |
| 1477 unit.link(); | 1502 unit.unlink(); |
| 1478 } | 1503 } |
| 1479 } | 1504 } |
| 1480 | 1505 |
| 1481 @override | 1506 @override |
| 1482 CompilationUnitElementInBuildUnit _makeUnitElement( | 1507 CompilationUnitElementInBuildUnit _makeUnitElement( |
| 1483 UnlinkedUnit unlinkedUnit, int i) => | 1508 UnlinkedUnit unlinkedUnit, int i) => |
| 1484 new CompilationUnitElementInBuildUnit( | 1509 new CompilationUnitElementInBuildUnit( |
| 1485 this, unlinkedUnit, _linkedLibrary.units[i], i); | 1510 this, unlinkedUnit, _linkedLibrary.units[i], i); |
| 1486 } | 1511 } |
| 1487 | 1512 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1511 class MethodElementForLink implements MethodElementImpl, TypeParameterContext { | 1536 class MethodElementForLink implements MethodElementImpl, TypeParameterContext { |
| 1512 /** | 1537 /** |
| 1513 * The unlinked representation of the method in the summary. | 1538 * The unlinked representation of the method in the summary. |
| 1514 */ | 1539 */ |
| 1515 final UnlinkedExecutable _unlinkedExecutable; | 1540 final UnlinkedExecutable _unlinkedExecutable; |
| 1516 | 1541 |
| 1517 DartType _declaredReturnType; | 1542 DartType _declaredReturnType; |
| 1518 DartType _inferredReturnType; | 1543 DartType _inferredReturnType; |
| 1519 FunctionTypeImpl _type; | 1544 FunctionTypeImpl _type; |
| 1520 List<TypeParameterElementForLink> _typeParameters; | 1545 List<TypeParameterElementForLink> _typeParameters; |
| 1546 List<ParameterElementForLink> _parameters; |
| 1521 | 1547 |
| 1522 @override | 1548 @override |
| 1523 final ClassElementForLink_Class enclosingElement; | 1549 final ClassElementForLink_Class enclosingElement; |
| 1524 | 1550 |
| 1525 MethodElementForLink(this.enclosingElement, this._unlinkedExecutable); | 1551 MethodElementForLink(this.enclosingElement, this._unlinkedExecutable); |
| 1526 | 1552 |
| 1527 @override | 1553 @override |
| 1528 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; | 1554 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; |
| 1529 | 1555 |
| 1530 @override | 1556 @override |
| 1531 bool get isStatic => _unlinkedExecutable.isStatic; | 1557 bool get isStatic => _unlinkedExecutable.isStatic; |
| 1532 | 1558 |
| 1533 @override | 1559 @override |
| 1534 bool get isSynthetic => false; | 1560 bool get isSynthetic => false; |
| 1535 | 1561 |
| 1536 @override | 1562 @override |
| 1537 ElementKind get kind => ElementKind.METHOD; | 1563 ElementKind get kind => ElementKind.METHOD; |
| 1538 | 1564 |
| 1539 @override | 1565 @override |
| 1540 LibraryElementForLink get library => enclosingElement.library; | 1566 LibraryElementForLink get library => enclosingElement.library; |
| 1541 | 1567 |
| 1542 @override | 1568 @override |
| 1543 String get name => _unlinkedExecutable.name; | 1569 String get name => _unlinkedExecutable.name; |
| 1544 | 1570 |
| 1545 @override | 1571 @override |
| 1546 List<ParameterElementForLink> get parameters { | 1572 List<ParameterElementForLink> get parameters { |
| 1547 // TODO(paulberry): implement. | 1573 if (_parameters == null) { |
| 1548 return const []; | 1574 _parameters = <ParameterElementForLink>[]; |
| 1575 for (UnlinkedParam unlinkedParam in _unlinkedExecutable.parameters) { |
| 1576 _parameters.add(new ParameterElementForLink( |
| 1577 unlinkedParam, this, enclosingElement.enclosingElement)); |
| 1578 } |
| 1579 } |
| 1580 return _parameters; |
| 1549 } | 1581 } |
| 1550 | 1582 |
| 1551 @override | 1583 @override |
| 1552 DartType get returnType { | 1584 DartType get returnType { |
| 1553 if (_inferredReturnType != null) { | 1585 if (_inferredReturnType != null) { |
| 1554 return _inferredReturnType; | 1586 return _inferredReturnType; |
| 1555 } else if (_declaredReturnType == null) { | 1587 } else if (_declaredReturnType == null) { |
| 1556 if (_unlinkedExecutable.returnType == null) { | 1588 if (_unlinkedExecutable.returnType == null) { |
| 1557 _declaredReturnType = DynamicTypeImpl.instance; | 1589 _declaredReturnType = DynamicTypeImpl.instance; |
| 1558 } else { | 1590 } else { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1586 TypeParameterType getTypeParameterType(int index) { | 1618 TypeParameterType getTypeParameterType(int index) { |
| 1587 // TODO(paulberry): implement. | 1619 // TODO(paulberry): implement. |
| 1588 throw new UnimplementedError(); | 1620 throw new UnimplementedError(); |
| 1589 } | 1621 } |
| 1590 | 1622 |
| 1591 @override | 1623 @override |
| 1592 bool isAccessibleIn(LibraryElement library) => | 1624 bool isAccessibleIn(LibraryElement library) => |
| 1593 !Identifier.isPrivateName(name) || identical(this.library, library); | 1625 !Identifier.isPrivateName(name) || identical(this.library, library); |
| 1594 | 1626 |
| 1595 /** | 1627 /** |
| 1596 * Store the results of type inference for this method in [linkedUnit]. | 1628 * Store the results of type inference for this method in [compilationUnit]. |
| 1597 */ | 1629 */ |
| 1598 void link(LinkedUnitBuilder linkedUnit) { | 1630 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 1599 int slot = _unlinkedExecutable.inferredReturnTypeSlot; | 1631 compilationUnit._storeLinkedType( |
| 1600 if (slot != 0) { | 1632 _unlinkedExecutable.inferredReturnTypeSlot, _inferredReturnType); |
| 1601 DartType inferredReturnType = returnType; | 1633 for (ParameterElementForLink parameterElement in parameters) { |
| 1602 if (!inferredReturnType.isDynamic) { | 1634 parameterElement.link(compilationUnit); |
| 1603 linkedUnit.types.add(_createLinkedType( | |
| 1604 inferredReturnType, enclosingElement.enclosingElement, | |
| 1605 slot: slot)); | |
| 1606 } | |
| 1607 } | 1635 } |
| 1608 } | 1636 } |
| 1609 | 1637 |
| 1610 @override | 1638 @override |
| 1611 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1639 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1612 | 1640 |
| 1613 /** | 1641 /** |
| 1614 * Throw away any information produced by type inference. | 1642 * Throw away any information produced by type inference. |
| 1615 */ | 1643 */ |
| 1616 void unlink() { | 1644 void unlink() { |
| 1645 for (ParameterElementForLink parameterElement in parameters) { |
| 1646 parameterElement.unlink(); |
| 1647 } |
| 1617 _inferredReturnType = null; | 1648 _inferredReturnType = null; |
| 1618 } | 1649 } |
| 1619 } | 1650 } |
| 1620 | 1651 |
| 1621 /** | 1652 /** |
| 1622 * Instances of [Node] represent nodes in a dependency graph. The | 1653 * Instances of [Node] represent nodes in a dependency graph. The |
| 1623 * type parameter, [NodeType], is the derived type (this affords some | 1654 * type parameter, [NodeType], is the derived type (this affords some |
| 1624 * extra type safety by making it difficult to accidentally construct | 1655 * extra type safety by making it difficult to accidentally construct |
| 1625 * bridges between unrelated dependency graphs). | 1656 * bridges between unrelated dependency graphs). |
| 1626 */ | 1657 */ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 DynamicTypeImpl.instance; | 1714 DynamicTypeImpl.instance; |
| 1684 | 1715 |
| 1685 @override | 1716 @override |
| 1686 ReferenceableElementForLink getContainedName(String name) => this; | 1717 ReferenceableElementForLink getContainedName(String name) => this; |
| 1687 } | 1718 } |
| 1688 | 1719 |
| 1689 /** | 1720 /** |
| 1690 * Element representing a function or method parameter resynthesized | 1721 * Element representing a function or method parameter resynthesized |
| 1691 * from a summary during linking. | 1722 * from a summary during linking. |
| 1692 */ | 1723 */ |
| 1693 class ParameterElementForLink implements ParameterElement { | 1724 class ParameterElementForLink implements ParameterElementImpl { |
| 1694 /** | 1725 /** |
| 1695 * The unlinked representation of the parameter in the summary. | 1726 * The unlinked representation of the parameter in the summary. |
| 1696 */ | 1727 */ |
| 1697 final UnlinkedParam _unlinkedParam; | 1728 final UnlinkedParam _unlinkedParam; |
| 1698 | 1729 |
| 1699 /** | 1730 /** |
| 1731 * The context in which type parameters should be interpreted. |
| 1732 */ |
| 1733 final TypeParameterContext _typeParameterContext; |
| 1734 |
| 1735 /** |
| 1700 * If this parameter has a default value and the enclosing library | 1736 * If this parameter has a default value and the enclosing library |
| 1701 * is part of the build unit being linked, the parameter's node in | 1737 * is part of the build unit being linked, the parameter's node in |
| 1702 * the constant evaluation dependency graph. Otherwise `null`. | 1738 * the constant evaluation dependency graph. Otherwise `null`. |
| 1703 */ | 1739 */ |
| 1704 ConstNode _constNode; | 1740 ConstNode _constNode; |
| 1705 | 1741 |
| 1706 /** | 1742 /** |
| 1707 * The compilation unit in which this parameter appears. | 1743 * The compilation unit in which this parameter appears. |
| 1708 */ | 1744 */ |
| 1709 final CompilationUnitElementForLink compilationUnit; | 1745 final CompilationUnitElementForLink compilationUnit; |
| 1710 | 1746 |
| 1711 ParameterElementForLink(this._unlinkedParam, this.compilationUnit) { | 1747 DartType _inferredType; |
| 1748 DartType _declaredType; |
| 1749 |
| 1750 ParameterElementForLink( |
| 1751 this._unlinkedParam, this._typeParameterContext, this.compilationUnit) { |
| 1712 if (_unlinkedParam.defaultValue != null) { | 1752 if (_unlinkedParam.defaultValue != null) { |
| 1713 _constNode = new ConstParameterNode(this); | 1753 _constNode = new ConstParameterNode(this); |
| 1714 } | 1754 } |
| 1715 } | 1755 } |
| 1716 | 1756 |
| 1717 @override | 1757 @override |
| 1758 bool get hasImplicitType => |
| 1759 !_unlinkedParam.isFunctionTyped && _unlinkedParam.type == null; |
| 1760 |
| 1761 @override |
| 1762 ParameterKind get parameterKind { |
| 1763 switch (_unlinkedParam.kind) { |
| 1764 case UnlinkedParamKind.required: |
| 1765 return ParameterKind.REQUIRED; |
| 1766 case UnlinkedParamKind.positional: |
| 1767 return ParameterKind.POSITIONAL; |
| 1768 case UnlinkedParamKind.named: |
| 1769 return ParameterKind.NAMED; |
| 1770 } |
| 1771 } |
| 1772 |
| 1773 @override |
| 1774 DartType get type { |
| 1775 if (_inferredType != null) { |
| 1776 return _inferredType; |
| 1777 } else if (_declaredType == null) { |
| 1778 if (_unlinkedParam.isFunctionTyped) { |
| 1779 // TODO(paulberry): implement. |
| 1780 throw new UnimplementedError(); |
| 1781 } else if (_unlinkedParam.type == null) { |
| 1782 _declaredType = DynamicTypeImpl.instance; |
| 1783 } else { |
| 1784 _declaredType = compilationUnit._resolveTypeRef( |
| 1785 _unlinkedParam.type, _typeParameterContext); |
| 1786 } |
| 1787 } |
| 1788 return _declaredType; |
| 1789 } |
| 1790 |
| 1791 @override |
| 1792 void set type(DartType inferredType) { |
| 1793 assert(_inferredType == null); |
| 1794 _inferredType = inferredType; |
| 1795 } |
| 1796 |
| 1797 /** |
| 1798 * Store the results of type inference for this parameter in |
| 1799 * [compilationUnit]. |
| 1800 */ |
| 1801 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 1802 compilationUnit._storeLinkedType( |
| 1803 _unlinkedParam.inferredTypeSlot, _inferredType); |
| 1804 } |
| 1805 |
| 1806 @override |
| 1718 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1807 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1808 |
| 1809 /** |
| 1810 * Throw away any information produced by type inference. |
| 1811 */ |
| 1812 void unlink() { |
| 1813 _inferredType = null; |
| 1814 } |
| 1719 } | 1815 } |
| 1720 | 1816 |
| 1721 /** | 1817 /** |
| 1722 * Abstract base class representing an element which can be the target | 1818 * Abstract base class representing an element which can be the target |
| 1723 * of a reference. | 1819 * of a reference. |
| 1724 */ | 1820 */ |
| 1725 abstract class ReferenceableElementForLink { | 1821 abstract class ReferenceableElementForLink { |
| 1726 /** | 1822 /** |
| 1727 * If this element can be used in a constructor invocation context, | 1823 * If this element can be used in a constructor invocation context, |
| 1728 * return the associated constructor (which may be `this` or some | 1824 * return the associated constructor (which may be `this` or some |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 } | 2094 } |
| 1999 } | 2095 } |
| 2000 | 2096 |
| 2001 @override | 2097 @override |
| 2002 ConstructorElementForLink get asConstructor => null; | 2098 ConstructorElementForLink get asConstructor => null; |
| 2003 | 2099 |
| 2004 @override | 2100 @override |
| 2005 ConstVariableNode get asConstVariable => _constNode; | 2101 ConstVariableNode get asConstVariable => _constNode; |
| 2006 | 2102 |
| 2007 @override | 2103 @override |
| 2008 bool get hasImplicitType => unlinkedVariable.type != null; | 2104 bool get hasImplicitType => unlinkedVariable.type == null; |
| 2009 | 2105 |
| 2010 @override | 2106 @override |
| 2011 FunctionElementForLink_Initializer get initializer => | 2107 FunctionElementForLink_Initializer get initializer => |
| 2012 _initializer ??= new FunctionElementForLink_Initializer(); | 2108 _initializer ??= new FunctionElementForLink_Initializer(); |
| 2013 | 2109 |
| 2014 @override | 2110 @override |
| 2015 bool get isConst => unlinkedVariable.isConst; | 2111 bool get isConst => unlinkedVariable.isConst; |
| 2016 | 2112 |
| 2017 @override | 2113 @override |
| 2018 bool get isFinal => unlinkedVariable.isFinal; | 2114 bool get isFinal => unlinkedVariable.isFinal; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 | 2232 |
| 2137 /** | 2233 /** |
| 2138 * Throw away any information produced by a previous call to [link]. | 2234 * Throw away any information produced by a previous call to [link]. |
| 2139 */ | 2235 */ |
| 2140 void unlink() { | 2236 void unlink() { |
| 2141 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { | 2237 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { |
| 2142 library.unlink(); | 2238 library.unlink(); |
| 2143 } | 2239 } |
| 2144 } | 2240 } |
| 2145 } | 2241 } |
| OLD | NEW |