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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1951173005: Add typedef support to summary linker. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return result; 180 return result;
181 } else if (type is TypeParameterType) { 181 } else if (type is TypeParameterType) {
182 TypeParameterElementForLink element = type.element; 182 TypeParameterElementForLink element = type.element;
183 result.paramReference = 183 result.paramReference =
184 typeParameterContext.typeParameterNestingLevel - element.nestingLevel; 184 typeParameterContext.typeParameterNestingLevel - element.nestingLevel;
185 return result; 185 return result;
186 } else if (type is FunctionType) { 186 } else if (type is FunctionType) {
187 Element element = type.element; 187 Element element = type.element;
188 if (element is FunctionElementForLink_FunctionTypedParam) { 188 if (element is FunctionElementForLink_FunctionTypedParam) {
189 result.reference = 189 result.reference =
190 compilationUnit.addReference(element.innermostExecutable); 190 compilationUnit.addReference(element.typeParameterContext);
191 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices; 191 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices;
192 _storeTypeArguments( 192 _storeTypeArguments(
193 type.typeArguments, result, compilationUnit, typeParameterContext); 193 type.typeArguments, result, compilationUnit, typeParameterContext);
194 return result; 194 return result;
195 } 195 }
196 if (element is TopLevelFunctionElementForLink) { 196 if (element is TopLevelFunctionElementForLink) {
197 result.reference = compilationUnit.addReference(element); 197 result.reference = compilationUnit.addReference(element);
198 _storeTypeArguments( 198 _storeTypeArguments(
199 type.typeArguments, result, compilationUnit, typeParameterContext); 199 type.typeArguments, result, compilationUnit, typeParameterContext);
200 return result; 200 return result;
201 } 201 }
202 if (element is MethodElementForLink) { 202 if (element is MethodElementForLink) {
203 result.reference = compilationUnit.addReference(element); 203 result.reference = compilationUnit.addReference(element);
204 _storeTypeArguments( 204 _storeTypeArguments(
205 type.typeArguments, result, compilationUnit, typeParameterContext); 205 type.typeArguments, result, compilationUnit, typeParameterContext);
206 return result; 206 return result;
207 } 207 }
208 if (element is FunctionTypeAliasElementForLink) {
209 result.reference = compilationUnit.addReference(element);
210 _storeTypeArguments(
211 type.typeArguments, result, compilationUnit, typeParameterContext);
212 return result;
213 }
208 // TODO(paulberry): implement other cases. 214 // TODO(paulberry): implement other cases.
209 throw new UnimplementedError('${element.runtimeType}'); 215 throw new UnimplementedError('${element.runtimeType}');
210 } 216 }
211 // TODO(paulberry): implement other cases. 217 // TODO(paulberry): implement other cases.
212 throw new UnimplementedError('${type.runtimeType}'); 218 throw new UnimplementedError('${type.runtimeType}');
213 } 219 }
214 220
215 /** 221 /**
216 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and 222 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and
217 * [typeParameterContext] to serialize them. 223 * [typeParameterContext] to serialize them.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 _accessors.add(field.getter); 404 _accessors.add(field.getter);
399 if (!field.isConst && !field.isFinal) { 405 if (!field.isConst && !field.isFinal) {
400 _accessors.add(field.setter); 406 _accessors.add(field.setter);
401 } 407 }
402 } 408 }
403 } 409 }
404 return _accessors; 410 return _accessors;
405 } 411 }
406 412
407 @override 413 @override
414 CompilationUnitElementForLink get compilationUnit => enclosingElement;
415
416 @override
408 List<ConstructorElementForLink> get constructors { 417 List<ConstructorElementForLink> get constructors {
409 if (_constructors == null) { 418 if (_constructors == null) {
410 _constructors = <ConstructorElementForLink>[]; 419 _constructors = <ConstructorElementForLink>[];
411 for (UnlinkedExecutable unlinkedExecutable 420 for (UnlinkedExecutable unlinkedExecutable
412 in _unlinkedClass.executables) { 421 in _unlinkedClass.executables) {
413 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { 422 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) {
414 _constructors 423 _constructors
415 .add(new ConstructorElementForLink(this, unlinkedExecutable)); 424 .add(new ConstructorElementForLink(this, unlinkedExecutable));
416 } 425 }
417 } 426 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 * The absolute URI of this compilation unit. 692 * The absolute URI of this compilation unit.
684 */ 693 */
685 final String _absoluteUri; 694 final String _absoluteUri;
686 695
687 List<ClassElementForLink_Class> _types; 696 List<ClassElementForLink_Class> _types;
688 Map<String, ReferenceableElementForLink> _containedNames; 697 Map<String, ReferenceableElementForLink> _containedNames;
689 List<TopLevelVariableElementForLink> _topLevelVariables; 698 List<TopLevelVariableElementForLink> _topLevelVariables;
690 List<ClassElementForLink_Enum> _enums; 699 List<ClassElementForLink_Enum> _enums;
691 List<TopLevelFunctionElementForLink> _functions; 700 List<TopLevelFunctionElementForLink> _functions;
692 List<PropertyAccessorElementForLink> _accessors; 701 List<PropertyAccessorElementForLink> _accessors;
702 List<FunctionTypeAliasElementForLink> _functionTypeAliases;
693 703
694 /** 704 /**
695 * Index of this unit in the list of units in the enclosing library. 705 * Index of this unit in the list of units in the enclosing library.
696 */ 706 */
697 final int unitNum; 707 final int unitNum;
698 708
699 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum, 709 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum,
700 int numReferences, this._absoluteUri) 710 int numReferences, this._absoluteUri)
701 : _references = new List<ReferenceableElementForLink>(numReferences), 711 : _references = new List<ReferenceableElementForLink>(numReferences),
702 _unlinkedUnit = unlinkedUnit; 712 _unlinkedUnit = unlinkedUnit;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 for (UnlinkedExecutable executable in _unlinkedUnit.executables) { 769 for (UnlinkedExecutable executable in _unlinkedUnit.executables) {
760 if (executable.kind == UnlinkedExecutableKind.functionOrMethod) { 770 if (executable.kind == UnlinkedExecutableKind.functionOrMethod) {
761 _functions.add(new TopLevelFunctionElementForLink(this, executable)); 771 _functions.add(new TopLevelFunctionElementForLink(this, executable));
762 } 772 }
763 } 773 }
764 } 774 }
765 return _functions; 775 return _functions;
766 } 776 }
767 777
768 @override 778 @override
779 List<FunctionTypeAliasElementForLink> get functionTypeAliases =>
780 _functionTypeAliases ??= _unlinkedUnit.typedefs
781 .map((UnlinkedTypedef t) =>
782 new FunctionTypeAliasElementForLink(this, t))
783 .toList();
784
785 @override
769 String get identifier => _absoluteUri; 786 String get identifier => _absoluteUri;
770 787
771 /** 788 /**
772 * Indicates whether this compilation element is part of the build unit 789 * Indicates whether this compilation element is part of the build unit
773 * currently being linked. 790 * currently being linked.
774 */ 791 */
775 bool get isInBuildUnit; 792 bool get isInBuildUnit;
776 793
777 /** 794 /**
778 * Determine whether type inference is complete in this compilation unit. 795 * Determine whether type inference is complete in this compilation unit.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 } 848 }
832 for (ClassElementForLink_Enum enm in enums) { 849 for (ClassElementForLink_Enum enm in enums) {
833 _containedNames[enm.name] = enm; 850 _containedNames[enm.name] = enm;
834 } 851 }
835 for (TopLevelFunctionElementForLink function in functions) { 852 for (TopLevelFunctionElementForLink function in functions) {
836 _containedNames[function.name] = function; 853 _containedNames[function.name] = function;
837 } 854 }
838 for (PropertyAccessorElementForLink accessor in accessors) { 855 for (PropertyAccessorElementForLink accessor in accessors) {
839 _containedNames[accessor.name] = accessor; 856 _containedNames[accessor.name] = accessor;
840 } 857 }
858 for (FunctionTypeAliasElementForLink functionTypeAlias
859 in functionTypeAliases) {
860 _containedNames[functionTypeAlias.name] = functionTypeAlias;
861 }
841 // TODO(paulberry): fill in other top level entities (typedefs 862 // TODO(paulberry): fill in other top level entities (typedefs
842 // and executables). 863 // and executables).
843 } 864 }
844 return _containedNames.putIfAbsent( 865 return _containedNames.putIfAbsent(
845 name, () => UndefinedElementForLink.instance); 866 name, () => UndefinedElementForLink.instance);
846 } 867 }
847 868
848 /** 869 /**
849 * Compute the type referred to by the given linked type [slot] (interpreted 870 * Compute the type referred to by the given linked type [slot] (interpreted
850 * relative to [typeParameterContext]). If there is no inferred type in the 871 * relative to [typeParameterContext]). If there is no inferred type in the
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 * If this compilation unit already has a reference in its references table 1034 * If this compilation unit already has a reference in its references table
1014 * to [element], return its index. Otherwise add a new reference to the table 1035 * to [element], return its index. Otherwise add a new reference to the table
1015 * and return its index. 1036 * and return its index.
1016 */ 1037 */
1017 int addReference(Element element) { 1038 int addReference(Element element) {
1018 if (element is ClassElementForLink) { 1039 if (element is ClassElementForLink) {
1019 return addRawReference(element.name, 1040 return addRawReference(element.name,
1020 dependency: library.addDependency(element.library), 1041 dependency: library.addDependency(element.library),
1021 numTypeParameters: element.typeParameters.length, 1042 numTypeParameters: element.typeParameters.length,
1022 unitNum: element.enclosingElement.unitNum); 1043 unitNum: element.enclosingElement.unitNum);
1044 } else if (element is FunctionTypeAliasElementForLink) {
1045 return addRawReference(element.name,
1046 dependency: library.addDependency(element.library),
1047 numTypeParameters: element.typeParameters.length,
1048 unitNum: element.enclosingElement.unitNum,
1049 kind: ReferenceKind.typedef);
1023 } else if (element is ExecutableElementForLink) { 1050 } else if (element is ExecutableElementForLink) {
1024 ClassElementForLink_Class enclosingClass = element.enclosingClass; 1051 ClassElementForLink_Class enclosingClass = element.enclosingClass;
1025 ReferenceKind kind; 1052 ReferenceKind kind;
1026 switch (element._unlinkedExecutable.kind) { 1053 switch (element._unlinkedExecutable.kind) {
1027 case UnlinkedExecutableKind.functionOrMethod: 1054 case UnlinkedExecutableKind.functionOrMethod:
1028 kind = enclosingClass != null 1055 kind = enclosingClass != null
1029 ? ReferenceKind.method 1056 ? ReferenceKind.method
1030 : ReferenceKind.topLevelFunction; 1057 : ReferenceKind.topLevelFunction;
1031 break; 1058 break;
1032 case UnlinkedExecutableKind.setter: 1059 case UnlinkedExecutableKind.setter:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1290 }
1264 1291
1265 /** 1292 /**
1266 * If [constructorElement] redirects to another constructor via a factory 1293 * If [constructorElement] redirects to another constructor via a factory
1267 * redirect, return the constructor it redirects to. 1294 * redirect, return the constructor it redirects to.
1268 */ 1295 */
1269 ConstructorElementForLink _getFactoryRedirectedConstructor() { 1296 ConstructorElementForLink _getFactoryRedirectedConstructor() {
1270 EntityRef redirectedConstructor = 1297 EntityRef redirectedConstructor =
1271 constructorElement._unlinkedExecutable.redirectedConstructor; 1298 constructorElement._unlinkedExecutable.redirectedConstructor;
1272 if (redirectedConstructor != null) { 1299 if (redirectedConstructor != null) {
1273 return constructorElement.enclosingUnit 1300 return constructorElement.compilationUnit
1274 ._resolveRef(redirectedConstructor.reference) 1301 ._resolveRef(redirectedConstructor.reference)
1275 .asConstructor; 1302 .asConstructor;
1276 } else { 1303 } else {
1277 return null; 1304 return null;
1278 } 1305 }
1279 } 1306 }
1280 } 1307 }
1281 1308
1282 /** 1309 /**
1283 * Specialization of [DependencyWalker] for detecting constant 1310 * Specialization of [DependencyWalker] for detecting constant
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 with TypeParameterizedElementForLink, ParameterParentElementForLink 1667 with TypeParameterizedElementForLink, ParameterParentElementForLink
1641 implements ExecutableElementImpl { 1668 implements ExecutableElementImpl {
1642 /** 1669 /**
1643 * The unlinked representation of the method in the summary. 1670 * The unlinked representation of the method in the summary.
1644 */ 1671 */
1645 final UnlinkedExecutable _unlinkedExecutable; 1672 final UnlinkedExecutable _unlinkedExecutable;
1646 1673
1647 DartType _declaredReturnType; 1674 DartType _declaredReturnType;
1648 DartType _inferredReturnType; 1675 DartType _inferredReturnType;
1649 FunctionTypeImpl _type; 1676 FunctionTypeImpl _type;
1650 List<TypeParameterElementForLink> _typeParameters;
1651 String _name; 1677 String _name;
1652 String _displayName; 1678 String _displayName;
1653 1679
1654 /** 1680 /**
1655 * Return the class in which this executable appears, maybe `null` for a 1681 * Return the class in which this executable appears, maybe `null` for a
1656 * top-level function. 1682 * top-level function.
1657 */ 1683 */
1658 final ClassElementForLink_Class enclosingClass; 1684 final ClassElementForLink_Class enclosingClass;
1659 1685
1660 /** 1686 @override
1661 * Return the compilation unit in which this executable appears. 1687 final CompilationUnitElementForLink compilationUnit;
1662 */
1663 final CompilationUnitElementForLink enclosingUnit;
1664 1688
1665 ExecutableElementForLink( 1689 ExecutableElementForLink(
1666 this.enclosingUnit, this.enclosingClass, this._unlinkedExecutable); 1690 this.compilationUnit, this.enclosingClass, this._unlinkedExecutable);
1667 1691
1668 /** 1692 /**
1669 * If the executable element had an explicitly declared return type, return 1693 * If the executable element had an explicitly declared return type, return
1670 * it. Otherwise return `null`. 1694 * it. Otherwise return `null`.
1671 */ 1695 */
1672 DartType get declaredReturnType { 1696 DartType get declaredReturnType {
1673 if (_unlinkedExecutable.returnType == null) { 1697 if (_unlinkedExecutable.returnType == null) {
1674 return null; 1698 return null;
1675 } else { 1699 } else {
1676 return _declaredReturnType ??= 1700 return _declaredReturnType ??=
1677 enclosingUnit._resolveTypeRef(_unlinkedExecutable.returnType, this); 1701 compilationUnit._resolveTypeRef(_unlinkedExecutable.returnType, this);
1678 } 1702 }
1679 } 1703 }
1680 1704
1681 @override 1705 @override
1682 String get displayName { 1706 String get displayName {
1683 if (_displayName == null) { 1707 if (_displayName == null) {
1684 _displayName = _unlinkedExecutable.name; 1708 _displayName = _unlinkedExecutable.name;
1685 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { 1709 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
1686 _displayName = _displayName.substring(0, _displayName.length - 1); 1710 _displayName = _displayName.substring(0, _displayName.length - 1);
1687 } 1711 }
1688 } 1712 }
1689 return _displayName; 1713 return _displayName;
1690 } 1714 }
1691 1715
1692 @override 1716 @override
1693 Element get enclosingElement => enclosingClass ?? enclosingUnit; 1717 Element get enclosingElement => enclosingClass ?? compilationUnit;
1694 1718
1695 @override 1719 @override
1696 TypeParameterizedElementForLink get enclosingTypeParameterContext => 1720 TypeParameterizedElementForLink get enclosingTypeParameterContext =>
1697 enclosingClass; 1721 enclosingClass;
1698 1722
1699 @override 1723 @override
1700 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; 1724 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null;
1701 1725
1702 @override 1726 @override
1703 List<int> get implicitFunctionTypeIndices => const <int>[]; 1727 List<int> get implicitFunctionTypeIndices => const <int>[];
1704 1728
1705 /** 1729 /**
1706 * Return the inferred return type of the executable element. Should only be 1730 * Return the inferred return type of the executable element. Should only be
1707 * called if no return type was explicitly declared. 1731 * called if no return type was explicitly declared.
1708 */ 1732 */
1709 DartType get inferredReturnType { 1733 DartType get inferredReturnType {
1710 // We should only try to infer a return type when none is explicitly 1734 // We should only try to infer a return type when none is explicitly
1711 // declared. 1735 // declared.
1712 assert(_unlinkedExecutable.returnType == null); 1736 assert(_unlinkedExecutable.returnType == null);
1713 if (Linker._initializerTypeInferenceCycle != null && 1737 if (Linker._initializerTypeInferenceCycle != null &&
1714 Linker._initializerTypeInferenceCycle == 1738 Linker._initializerTypeInferenceCycle ==
1715 enclosingUnit.library.libraryCycleForLink) { 1739 compilationUnit.library.libraryCycleForLink) {
1716 // We are currently computing the type of an initializer expression in the 1740 // We are currently computing the type of an initializer expression in the
1717 // current library cycle, so type inference results should be ignored. 1741 // current library cycle, so type inference results should be ignored.
1718 return _computeDefaultReturnType(); 1742 return _computeDefaultReturnType();
1719 } 1743 }
1720 if (_inferredReturnType == null) { 1744 if (_inferredReturnType == null) {
1721 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { 1745 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) {
1722 // TODO(paulberry): implement. 1746 // TODO(paulberry): implement.
1723 throw new UnimplementedError(); 1747 throw new UnimplementedError();
1724 } else if (enclosingUnit.isInBuildUnit) { 1748 } else if (compilationUnit.isInBuildUnit) {
1725 _inferredReturnType = _computeDefaultReturnType(); 1749 _inferredReturnType = _computeDefaultReturnType();
1726 } else { 1750 } else {
1727 _inferredReturnType = enclosingUnit.getLinkedType( 1751 _inferredReturnType = compilationUnit.getLinkedType(
1728 _unlinkedExecutable.inferredReturnTypeSlot, this); 1752 _unlinkedExecutable.inferredReturnTypeSlot, this);
1729 } 1753 }
1730 } 1754 }
1731 return _inferredReturnType; 1755 return _inferredReturnType;
1732 } 1756 }
1733 1757
1734 @override 1758 @override
1735 ExecutableElementForLink get innermostExecutable => this;
1736
1737 @override
1738 bool get isStatic => _unlinkedExecutable.isStatic; 1759 bool get isStatic => _unlinkedExecutable.isStatic;
1739 1760
1740 @override 1761 @override
1741 bool get isSynthetic => false; 1762 bool get isSynthetic => false;
1742 1763
1743 @override 1764 @override
1744 LibraryElementForLink get library => enclosingElement.library; 1765 LibraryElementForLink get library => enclosingElement.library;
1745 1766
1746 @override 1767 @override
1747 String get name { 1768 String get name {
(...skipping 12 matching lines...) Expand all
1760 @override 1781 @override
1761 void set returnType(DartType inferredType) { 1782 void set returnType(DartType inferredType) {
1762 assert(_inferredReturnType == null); 1783 assert(_inferredReturnType == null);
1763 _inferredReturnType = inferredType; 1784 _inferredReturnType = inferredType;
1764 } 1785 }
1765 1786
1766 @override 1787 @override
1767 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); 1788 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
1768 1789
1769 @override 1790 @override
1791 TypeParameterizedElementForLink get typeParameterContext => this;
1792
1793 @override
1770 List<UnlinkedParam> get unlinkedParameters => _unlinkedExecutable.parameters; 1794 List<UnlinkedParam> get unlinkedParameters => _unlinkedExecutable.parameters;
1771 1795
1772 @override 1796 @override
1773 List<UnlinkedTypeParam> get _unlinkedTypeParams => 1797 List<UnlinkedTypeParam> get _unlinkedTypeParams =>
1774 _unlinkedExecutable.typeParameters; 1798 _unlinkedExecutable.typeParameters;
1775 1799
1776 @override 1800 @override
1777 bool isAccessibleIn(LibraryElement library) => 1801 bool isAccessibleIn(LibraryElement library) =>
1778 !Identifier.isPrivateName(name) || identical(this.library, library); 1802 !Identifier.isPrivateName(name) || identical(this.library, library);
1779 1803
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 * Element representing a function-typed parameter resynthesied from a summary 2564 * Element representing a function-typed parameter resynthesied from a summary
2541 * during linking. 2565 * during linking.
2542 */ 2566 */
2543 class FunctionElementForLink_FunctionTypedParam extends Object 2567 class FunctionElementForLink_FunctionTypedParam extends Object
2544 with ParameterParentElementForLink 2568 with ParameterParentElementForLink
2545 implements FunctionElement { 2569 implements FunctionElement {
2546 @override 2570 @override
2547 final ParameterElementForLink enclosingElement; 2571 final ParameterElementForLink enclosingElement;
2548 2572
2549 @override 2573 @override
2550 final ExecutableElementForLink innermostExecutable; 2574 final TypeParameterizedElementForLink typeParameterContext;
2551 2575
2552 @override 2576 @override
2553 final List<UnlinkedParam> unlinkedParameters; 2577 final List<UnlinkedParam> unlinkedParameters;
2554 2578
2555 DartType _returnType; 2579 DartType _returnType;
2556 List<int> _implicitFunctionTypeIndices; 2580 List<int> _implicitFunctionTypeIndices;
2557 2581
2558 FunctionElementForLink_FunctionTypedParam( 2582 FunctionElementForLink_FunctionTypedParam(this.enclosingElement,
2559 this.enclosingElement, this.innermostExecutable, this.unlinkedParameters); 2583 this.typeParameterContext, this.unlinkedParameters);
2560 2584
2561 @override 2585 @override
2562 List<int> get implicitFunctionTypeIndices { 2586 List<int> get implicitFunctionTypeIndices {
2563 if (_implicitFunctionTypeIndices == null) { 2587 if (_implicitFunctionTypeIndices == null) {
2564 _implicitFunctionTypeIndices = enclosingElement 2588 _implicitFunctionTypeIndices = enclosingElement
2565 .enclosingElement.implicitFunctionTypeIndices 2589 .enclosingElement.implicitFunctionTypeIndices
2566 .toList(); 2590 .toList();
2567 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex); 2591 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex);
2568 } 2592 }
2569 return _implicitFunctionTypeIndices; 2593 return _implicitFunctionTypeIndices;
2570 } 2594 }
2571 2595
2572 @override 2596 @override
2573 DartType get returnType { 2597 DartType get returnType {
2574 if (_returnType == null) { 2598 if (_returnType == null) {
2575 if (enclosingElement._unlinkedParam.type == null) { 2599 if (enclosingElement._unlinkedParam.type == null) {
2576 _returnType = DynamicTypeImpl.instance; 2600 _returnType = DynamicTypeImpl.instance;
2577 } else { 2601 } else {
2578 _returnType = enclosingElement.compilationUnit._resolveTypeRef( 2602 _returnType = enclosingElement.compilationUnit._resolveTypeRef(
2579 enclosingElement._unlinkedParam.type, innermostExecutable); 2603 enclosingElement._unlinkedParam.type, typeParameterContext);
2580 } 2604 }
2581 } 2605 }
2582 return _returnType; 2606 return _returnType;
2583 } 2607 }
2584 2608
2585 @override 2609 @override
2586 List<TypeParameterElement> get typeParameters => const []; 2610 List<TypeParameterElement> get typeParameters => const [];
2587 2611
2588 @override 2612 @override
2589 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2613 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
(...skipping 29 matching lines...) Expand all
2619 void set returnType(DartType newType) { 2643 void set returnType(DartType newType) {
2620 // InstanceMemberInferrer stores the new type both here and on the variable 2644 // InstanceMemberInferrer stores the new type both here and on the variable
2621 // element. We don't need to record both values, so we ignore it here. 2645 // element. We don't need to record both values, so we ignore it here.
2622 } 2646 }
2623 2647
2624 @override 2648 @override
2625 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2649 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2626 } 2650 }
2627 2651
2628 /** 2652 /**
2653 * Element representing a typedef resynthesized from a summary during linking.
2654 */
2655 class FunctionTypeAliasElementForLink extends Object
2656 with TypeParameterizedElementForLink, ParameterParentElementForLink
2657 implements
2658 FunctionTypeAliasElement,
2659 ReferenceableElementForLink,
2660 ElementImpl {
2661 @override
2662 final CompilationUnitElementForLink enclosingElement;
2663
2664 /**
2665 * The unlinked representation of the typedef in the summary.
2666 */
2667 final UnlinkedTypedef _unlinkedTypedef;
2668
2669 FunctionTypeImpl _type;
2670 DartType _returnType;
2671
2672 FunctionTypeAliasElementForLink(this.enclosingElement, this._unlinkedTypedef);
2673
2674 @override
2675 ConstructorElementForLink get asConstructor => null;
2676
2677 @override
2678 ConstVariableNode get asConstVariable {
2679 // When a typedef name is used as a constant variable, it doesn't depend on
2680 // anything, so it is not necessary to include it in the constant
2681 // dependency graph.
2682 return null;
2683 }
2684
2685 @override
2686 DartType get asStaticType {
2687 return enclosingElement.enclosingElement._linker.typeProvider.typeType;
2688 }
2689
2690 @override
2691 TypeInferenceNode get asTypeInferenceNode => null;
2692
2693 @override
2694 CompilationUnitElementForLink get compilationUnit => enclosingElement;
2695
2696 @override
2697 TypeParameterizedElementForLink get enclosingTypeParameterContext => null;
2698
2699 @override
2700 String get identifier => _unlinkedTypedef.name;
2701
2702 @override
2703 List<int> get implicitFunctionTypeIndices => const <int>[];
2704
2705 @override
2706 bool get isSynthetic => false;
2707
2708 @override
2709 LibraryElementForLink get library => enclosingElement.library;
2710
2711 @override
2712 String get name => _unlinkedTypedef.name;
2713
2714 @override
2715 DartType get returnType => _returnType ??=
2716 enclosingElement._resolveTypeRef(_unlinkedTypedef.returnType, this);
2717
2718 @override
2719 TypeParameterizedElementForLink get typeParameterContext => this;
2720
2721 @override
2722 List<UnlinkedParam> get unlinkedParameters => _unlinkedTypedef.parameters;
2723
2724 @override
2725 List<UnlinkedTypeParam> get _unlinkedTypeParams =>
2726 _unlinkedTypedef.typeParameters;
2727
2728 @override
2729 DartType buildType(
2730 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
2731 int numTypeParameters = _unlinkedTypedef.typeParameters.length;
2732 if (numTypeParameters != 0) {
2733 List<DartType> typeArguments = new List<DartType>(numTypeParameters);
2734 for (int i = 0; i < numTypeParameters; i++) {
2735 typeArguments[i] = getTypeArgument(i);
2736 }
2737 return new FunctionTypeImpl.elementWithNameAndArgs(
2738 this, name, typeArguments, true);
2739 } else {
2740 return _type ??= new FunctionTypeImpl.forTypedef(this);
2741 }
2742 }
2743
2744 @override
2745 ReferenceableElementForLink getContainedName(String name) {
2746 // TODO(paulberry): implement.
2747 throw new UnimplementedError();
2748 }
2749
2750 @override
2751 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2752 }
2753
2754 /**
2629 * Specialization of [DependencyWalker] for linking library cycles. 2755 * Specialization of [DependencyWalker] for linking library cycles.
2630 */ 2756 */
2631 class LibraryCycleDependencyWalker extends DependencyWalker<LibraryCycleNode> { 2757 class LibraryCycleDependencyWalker extends DependencyWalker<LibraryCycleNode> {
2632 @override 2758 @override
2633 void evaluate(LibraryCycleNode v) { 2759 void evaluate(LibraryCycleNode v) {
2634 v.link(); 2760 v.link();
2635 } 2761 }
2636 2762
2637 @override 2763 @override
2638 void evaluateScc(List<LibraryCycleNode> scc) { 2764 void evaluateScc(List<LibraryCycleNode> scc) {
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3304 * Element representing a function or method parameter resynthesized 3430 * Element representing a function or method parameter resynthesized
3305 * from a summary during linking. 3431 * from a summary during linking.
3306 */ 3432 */
3307 class ParameterElementForLink implements ParameterElementImpl { 3433 class ParameterElementForLink implements ParameterElementImpl {
3308 /** 3434 /**
3309 * The unlinked representation of the parameter in the summary. 3435 * The unlinked representation of the parameter in the summary.
3310 */ 3436 */
3311 final UnlinkedParam _unlinkedParam; 3437 final UnlinkedParam _unlinkedParam;
3312 3438
3313 /** 3439 /**
3314 * The innermost executable element containing this parameter. 3440 * The innermost enclosing element that can declare type parameters.
3315 */ 3441 */
3316 final ExecutableElementForLink _innermostExecutable; 3442 final TypeParameterizedElementForLink _typeParameterContext;
3317 3443
3318 /** 3444 /**
3319 * If this parameter has a default value and the enclosing library 3445 * If this parameter has a default value and the enclosing library
3320 * is part of the build unit being linked, the parameter's node in 3446 * is part of the build unit being linked, the parameter's node in
3321 * the constant evaluation dependency graph. Otherwise `null`. 3447 * the constant evaluation dependency graph. Otherwise `null`.
3322 */ 3448 */
3323 ConstNode _constNode; 3449 ConstNode _constNode;
3324 3450
3325 /** 3451 /**
3326 * The compilation unit in which this parameter appears. 3452 * The compilation unit in which this parameter appears.
3327 */ 3453 */
3328 final CompilationUnitElementForLink compilationUnit; 3454 final CompilationUnitElementForLink compilationUnit;
3329 3455
3330 /** 3456 /**
3331 * The index of this parameter within [enclosingElement]'s parameter list. 3457 * The index of this parameter within [enclosingElement]'s parameter list.
3332 */ 3458 */
3333 final int _parameterIndex; 3459 final int _parameterIndex;
3334 3460
3335 @override 3461 @override
3336 final ParameterParentElementForLink enclosingElement; 3462 final ParameterParentElementForLink enclosingElement;
3337 3463
3338 DartType _inferredType; 3464 DartType _inferredType;
3339 DartType _declaredType; 3465 DartType _declaredType;
3340 3466
3341 ParameterElementForLink(this.enclosingElement, this._unlinkedParam, 3467 ParameterElementForLink(this.enclosingElement, this._unlinkedParam,
3342 this._innermostExecutable, this.compilationUnit, this._parameterIndex) { 3468 this._typeParameterContext, this.compilationUnit, this._parameterIndex) {
3343 if (_unlinkedParam.defaultValue != null) { 3469 if (_unlinkedParam.defaultValue != null) {
3344 _constNode = new ConstParameterNode(this); 3470 _constNode = new ConstParameterNode(this);
3345 } 3471 }
3346 } 3472 }
3347 3473
3348 @override 3474 @override
3475 String get displayName => _unlinkedParam.name;
3476
3477 @override
3349 bool get hasImplicitType => 3478 bool get hasImplicitType =>
3350 !_unlinkedParam.isFunctionTyped && _unlinkedParam.type == null; 3479 !_unlinkedParam.isFunctionTyped && _unlinkedParam.type == null;
3351 3480
3352 @override 3481 @override
3353 String get name => _unlinkedParam.name; 3482 String get name => _unlinkedParam.name;
3354 3483
3355 @override 3484 @override
3356 ParameterKind get parameterKind { 3485 ParameterKind get parameterKind {
3357 switch (_unlinkedParam.kind) { 3486 switch (_unlinkedParam.kind) {
3358 case UnlinkedParamKind.required: 3487 case UnlinkedParamKind.required:
3359 return ParameterKind.REQUIRED; 3488 return ParameterKind.REQUIRED;
3360 case UnlinkedParamKind.positional: 3489 case UnlinkedParamKind.positional:
3361 return ParameterKind.POSITIONAL; 3490 return ParameterKind.POSITIONAL;
3362 case UnlinkedParamKind.named: 3491 case UnlinkedParamKind.named:
3363 return ParameterKind.NAMED; 3492 return ParameterKind.NAMED;
3364 } 3493 }
3365 } 3494 }
3366 3495
3367 @override 3496 @override
3368 DartType get type { 3497 DartType get type {
3369 if (_inferredType != null) { 3498 if (_inferredType != null) {
3370 return _inferredType; 3499 return _inferredType;
3371 } else if (_declaredType == null) { 3500 } else if (_declaredType == null) {
3372 if (_unlinkedParam.isFunctionTyped) { 3501 if (_unlinkedParam.isFunctionTyped) {
3373 _declaredType = new FunctionTypeImpl( 3502 _declaredType = new FunctionTypeImpl(
3374 new FunctionElementForLink_FunctionTypedParam( 3503 new FunctionElementForLink_FunctionTypedParam(
3375 this, _innermostExecutable, _unlinkedParam.parameters)); 3504 this, _typeParameterContext, _unlinkedParam.parameters));
3376 } else if (_unlinkedParam.type == null) { 3505 } else if (_unlinkedParam.type == null) {
3377 if (!compilationUnit.isInBuildUnit) { 3506 if (!compilationUnit.isInBuildUnit) {
3378 _inferredType = compilationUnit.getLinkedType( 3507 _inferredType = compilationUnit.getLinkedType(
3379 _unlinkedParam.inferredTypeSlot, _innermostExecutable); 3508 _unlinkedParam.inferredTypeSlot, _typeParameterContext);
3380 return _inferredType; 3509 return _inferredType;
3381 } else { 3510 } else {
3382 _declaredType = DynamicTypeImpl.instance; 3511 _declaredType = DynamicTypeImpl.instance;
3383 } 3512 }
3384 } else { 3513 } else {
3385 _declaredType = compilationUnit._resolveTypeRef( 3514 _declaredType = compilationUnit._resolveTypeRef(
3386 _unlinkedParam.type, _innermostExecutable); 3515 _unlinkedParam.type, _typeParameterContext);
3387 } 3516 }
3388 } 3517 }
3389 return _declaredType; 3518 return _declaredType;
3390 } 3519 }
3391 3520
3392 @override 3521 @override
3393 void set type(DartType inferredType) { 3522 void set type(DartType inferredType) {
3394 assert(_inferredType == null); 3523 assert(_inferredType == null);
3395 _inferredType = inferredType; 3524 _inferredType = inferredType;
3396 } 3525 }
3397 3526
3398 /** 3527 /**
3399 * Store the results of type inference for this parameter in 3528 * Store the results of type inference for this parameter in
3400 * [compilationUnit]. 3529 * [compilationUnit].
3401 */ 3530 */
3402 void link(CompilationUnitElementInBuildUnit compilationUnit) { 3531 void link(CompilationUnitElementInBuildUnit compilationUnit) {
3403 compilationUnit._storeLinkedType( 3532 compilationUnit._storeLinkedType(
3404 _unlinkedParam.inferredTypeSlot, _inferredType, _innermostExecutable); 3533 _unlinkedParam.inferredTypeSlot, _inferredType, _typeParameterContext);
3405 } 3534 }
3406 3535
3407 @override 3536 @override
3408 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3537 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3409 } 3538 }
3410 3539
3411 /** 3540 /**
3412 * Element representing the parameter of a synthetic setter for a variable 3541 * Element representing the parameter of a synthetic setter for a variable
3413 * resynthesized during linking. 3542 * resynthesized during linking.
3414 */ 3543 */
(...skipping 28 matching lines...) Expand all
3443 /** 3572 /**
3444 * Get the appropriate integer list to store in 3573 * Get the appropriate integer list to store in
3445 * [EntityRef.implicitFunctionTypeIndices] to refer to this element. For an 3574 * [EntityRef.implicitFunctionTypeIndices] to refer to this element. For an
3446 * element representing a function-typed parameter, this should return a 3575 * element representing a function-typed parameter, this should return a
3447 * non-empty list. For an element representing an executable, this should 3576 * non-empty list. For an element representing an executable, this should
3448 * return the empty list. 3577 * return the empty list.
3449 */ 3578 */
3450 List<int> get implicitFunctionTypeIndices; 3579 List<int> get implicitFunctionTypeIndices;
3451 3580
3452 /** 3581 /**
3453 * Get the innermost enclosing ExecutableElement (which may be [this], or may
3454 * be a parent when there are function-typed parameters).
3455 */
3456 ExecutableElementForLink get innermostExecutable;
3457
3458 /**
3459 * Get all the parameters of this element. 3582 * Get all the parameters of this element.
3460 */ 3583 */
3461 List<ParameterElementForLink> get parameters { 3584 List<ParameterElementForLink> get parameters {
3462 if (_parameters == null) { 3585 if (_parameters == null) {
3463 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters; 3586 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters;
3464 int numParameters = unlinkedParameters.length; 3587 int numParameters = unlinkedParameters.length;
3465 _parameters = new List<ParameterElementForLink>(numParameters); 3588 _parameters = new List<ParameterElementForLink>(numParameters);
3466 for (int i = 0; i < numParameters; i++) { 3589 for (int i = 0; i < numParameters; i++) {
3467 UnlinkedParam unlinkedParam = unlinkedParameters[i]; 3590 UnlinkedParam unlinkedParam = unlinkedParameters[i];
3468 _parameters[i] = new ParameterElementForLink(this, unlinkedParam, 3591 _parameters[i] = new ParameterElementForLink(this, unlinkedParam,
3469 innermostExecutable, innermostExecutable.enclosingUnit, i); 3592 typeParameterContext, typeParameterContext.compilationUnit, i);
3470 } 3593 }
3471 } 3594 }
3472 return _parameters; 3595 return _parameters;
3473 } 3596 }
3474 3597
3475 /** 3598 /**
3599 * Get the innermost enclosing element that can declare type parameters (which
3600 * may be [this], or may be a parent when there are function-typed
3601 * parameters).
3602 */
3603 TypeParameterizedElementForLink get typeParameterContext;
3604
3605 /**
3476 * Get the list of unlinked parameters of this element. 3606 * Get the list of unlinked parameters of this element.
3477 */ 3607 */
3478 List<UnlinkedParam> get unlinkedParameters; 3608 List<UnlinkedParam> get unlinkedParameters;
3479 } 3609 }
3480 3610
3481 /** 3611 /**
3482 * Element representing a getter or setter resynthesized from a summary during 3612 * Element representing a getter or setter resynthesized from a summary during
3483 * linking. 3613 * linking.
3484 */ 3614 */
3485 abstract class PropertyAccessorElementForLink 3615 abstract class PropertyAccessorElementForLink
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
4022 /** 4152 /**
4023 * Mixin representing an element which can have type parameters. 4153 * Mixin representing an element which can have type parameters.
4024 */ 4154 */
4025 abstract class TypeParameterizedElementForLink 4155 abstract class TypeParameterizedElementForLink
4026 implements TypeParameterizedElement { 4156 implements TypeParameterizedElement {
4027 List<TypeParameterType> _typeParameterTypes; 4157 List<TypeParameterType> _typeParameterTypes;
4028 List<TypeParameterElementForLink> _typeParameters; 4158 List<TypeParameterElementForLink> _typeParameters;
4029 int _nestingLevel; 4159 int _nestingLevel;
4030 4160
4031 /** 4161 /**
4162 * Get the compilation unit in which this element is declared.
4163 */
4164 CompilationUnitElementForLink get compilationUnit;
4165
4166 /**
4032 * Get the type parameter context enclosing this one, if any. 4167 * Get the type parameter context enclosing this one, if any.
4033 */ 4168 */
4034 TypeParameterizedElementForLink get enclosingTypeParameterContext; 4169 TypeParameterizedElementForLink get enclosingTypeParameterContext;
4035 4170
4036 /** 4171 /**
4037 * Find out how many type parameters are in scope in this context. 4172 * Find out how many type parameters are in scope in this context.
4038 */ 4173 */
4039 int get typeParameterNestingLevel => 4174 int get typeParameterNestingLevel =>
4040 _nestingLevel ??= _unlinkedTypeParams.length + 4175 _nestingLevel ??= _unlinkedTypeParams.length +
4041 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); 4176 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
4414 * there are no type parameters in scope. 4549 * there are no type parameters in scope.
4415 */ 4550 */
4416 TypeParameterizedElementForLink get _typeParameterContext; 4551 TypeParameterizedElementForLink get _typeParameterContext;
4417 4552
4418 @override 4553 @override
4419 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4554 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4420 4555
4421 @override 4556 @override
4422 String toString() => '$enclosingElement.$name'; 4557 String toString() => '$enclosingElement.$name';
4423 } 4558 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698