| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 /** | 702 /** |
| 703 * Map of top level elements that have been resynthesized so far. The first | 703 * Map of top level elements that have been resynthesized so far. The first |
| 704 * key is the URI of the compilation unit; the second is the name of the top | 704 * key is the URI of the compilation unit; the second is the name of the top |
| 705 * level element. | 705 * level element. |
| 706 */ | 706 */ |
| 707 final Map<String, Map<String, Element>> resummarizedElements = | 707 final Map<String, Map<String, Element>> resummarizedElements = |
| 708 <String, Map<String, Element>>{}; | 708 <String, Map<String, Element>>{}; |
| 709 | 709 |
| 710 /** | 710 /** |
| 711 * Type parameters for the generic class, typedef, or executable currently | 711 * Type parameters for the generic class, typedef, or executable currently |
| 712 * being resynthesized, if any. If multiple entities with type parameters | 712 * being resynthesized, if any. This is a list of lists; if multiple |
| 713 * are nested (e.g. a generic executable inside a generic class), this is the | 713 * entities with type parameters are nested (e.g. a generic executable inside |
| 714 * concatenation of all type parameters from all declarations currently in | 714 * a generic class), then the zeroth element of [currentTypeParameters] |
| 715 * force, with the outermost declaration appearing first. If there are no | 715 * contains the type parameters for the outermost nested entity, and further |
| 716 * type parameters, or we are not currently resynthesizing a class, typedef, | 716 * elements contain the type parameters for entities that are more deeply |
| 717 * or executable, then this is an empty list. | 717 * nested. If we are not currently resynthesizing a class, typedef, or |
| 718 * executable, then this is an empty list. |
| 718 */ | 719 */ |
| 719 List<TypeParameterElement> currentTypeParameters = <TypeParameterElement>[]; | 720 final List<List<TypeParameterElement>> currentTypeParameters = |
| 721 <List<TypeParameterElement>>[]; |
| 720 | 722 |
| 721 /** | 723 /** |
| 722 * If a class is currently being resynthesized, map from field name to the | 724 * If a class is currently being resynthesized, map from field name to the |
| 723 * corresponding field element. This is used when resynthesizing | 725 * corresponding field element. This is used when resynthesizing |
| 724 * initializing formal parameters. | 726 * initializing formal parameters. |
| 725 */ | 727 */ |
| 726 Map<String, FieldElementImpl> fields; | 728 Map<String, FieldElementImpl> fields; |
| 727 | 729 |
| 728 /** | 730 /** |
| 729 * If a class is currently being resynthesized, map from constructor name to | 731 * If a class is currently being resynthesized, map from constructor name to |
| 730 * the corresponding constructor element. This is used when resynthesizing | 732 * the corresponding constructor element. This is used when resynthesizing |
| 731 * constructor initializers. | 733 * constructor initializers. |
| 732 */ | 734 */ |
| 733 Map<String, ConstructorElementImpl> constructors; | 735 Map<String, ConstructorElementImpl> constructors; |
| 734 | 736 |
| 735 /** | 737 /** |
| 736 * List of [_ReferenceInfo] objects describing the references in the current | 738 * List of [_ReferenceInfo] objects describing the references in the current |
| 737 * compilation unit. | 739 * compilation unit. |
| 738 */ | 740 */ |
| 739 List<_ReferenceInfo> referenceInfos; | 741 List<_ReferenceInfo> referenceInfos; |
| 740 | 742 |
| 741 _LibraryResynthesizer(this.summaryResynthesizer, this.linkedLibrary, | 743 _LibraryResynthesizer(this.summaryResynthesizer, this.linkedLibrary, |
| 742 this.unlinkedUnits, this.librarySource) { | 744 this.unlinkedUnits, this.librarySource) { |
| 743 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; | 745 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; |
| 744 } | 746 } |
| 745 | 747 |
| 746 /** | 748 /** |
| 747 * Return a list of type arguments corresponding to [currentTypeParameters]. | |
| 748 */ | |
| 749 List<TypeParameterType> get currentTypeArguments => currentTypeParameters | |
| 750 ?.map((TypeParameterElement param) => param.type) | |
| 751 ?.toList(); | |
| 752 | |
| 753 /** | |
| 754 * Build the annotations for the given [element]. | 749 * Build the annotations for the given [element]. |
| 755 */ | 750 */ |
| 756 void buildAnnotations( | 751 void buildAnnotations( |
| 757 ElementImpl element, List<UnlinkedConst> serializedAnnotations) { | 752 ElementImpl element, List<UnlinkedConst> serializedAnnotations) { |
| 758 if (serializedAnnotations.isNotEmpty) { | 753 if (serializedAnnotations.isNotEmpty) { |
| 759 element.metadata = serializedAnnotations.map((UnlinkedConst a) { | 754 element.metadata = serializedAnnotations.map((UnlinkedConst a) { |
| 760 ElementAnnotationImpl elementAnnotation = | 755 ElementAnnotationImpl elementAnnotation = |
| 761 new ElementAnnotationImpl(this.currentCompilationUnit); | 756 new ElementAnnotationImpl(this.currentCompilationUnit); |
| 762 Expression constExpr = _buildConstExpression(a); | 757 Expression constExpr = _buildConstExpression(a); |
| 763 if (constExpr is Identifier) { | 758 if (constExpr is Identifier) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 782 return elementAnnotation; | 777 return elementAnnotation; |
| 783 }).toList(); | 778 }).toList(); |
| 784 } | 779 } |
| 785 } | 780 } |
| 786 | 781 |
| 787 /** | 782 /** |
| 788 * Resynthesize a [ClassElement] and place it in [unitHolder]. | 783 * Resynthesize a [ClassElement] and place it in [unitHolder]. |
| 789 */ | 784 */ |
| 790 void buildClass(UnlinkedClass serializedClass) { | 785 void buildClass(UnlinkedClass serializedClass) { |
| 791 try { | 786 try { |
| 792 currentTypeParameters = | |
| 793 serializedClass.typeParameters.map(buildTypeParameter).toList(); | |
| 794 for (int i = 0; i < serializedClass.typeParameters.length; i++) { | |
| 795 finishTypeParameter( | |
| 796 serializedClass.typeParameters[i], currentTypeParameters[i]); | |
| 797 } | |
| 798 ClassElementImpl classElement = new ClassElementImpl( | 787 ClassElementImpl classElement = new ClassElementImpl( |
| 799 serializedClass.name, serializedClass.nameOffset); | 788 serializedClass.name, serializedClass.nameOffset); |
| 789 classElement.typeParameters = |
| 790 buildTypeParameters(serializedClass.typeParameters); |
| 800 classElement.abstract = serializedClass.isAbstract; | 791 classElement.abstract = serializedClass.isAbstract; |
| 801 classElement.mixinApplication = serializedClass.isMixinApplication; | 792 classElement.mixinApplication = serializedClass.isMixinApplication; |
| 802 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); | 793 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); |
| 803 if (serializedClass.supertype != null) { | 794 if (serializedClass.supertype != null) { |
| 804 classElement.supertype = buildType(serializedClass.supertype); | 795 classElement.supertype = buildType(serializedClass.supertype); |
| 805 } else if (!serializedClass.hasNoSupertype) { | 796 } else if (!serializedClass.hasNoSupertype) { |
| 806 if (isCoreLibrary) { | 797 if (isCoreLibrary) { |
| 807 delayedObjectSubclasses.add(classElement); | 798 delayedObjectSubclasses.add(classElement); |
| 808 } else { | 799 } else { |
| 809 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 800 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 810 } | 801 } |
| 811 } | 802 } |
| 812 classElement.interfaces = | 803 classElement.interfaces = |
| 813 serializedClass.interfaces.map(buildType).toList(); | 804 serializedClass.interfaces.map(buildType).toList(); |
| 814 classElement.mixins = serializedClass.mixins.map(buildType).toList(); | 805 classElement.mixins = serializedClass.mixins.map(buildType).toList(); |
| 815 classElement.typeParameters = currentTypeParameters; | |
| 816 ElementHolder memberHolder = new ElementHolder(); | 806 ElementHolder memberHolder = new ElementHolder(); |
| 817 fields = <String, FieldElementImpl>{}; | 807 fields = <String, FieldElementImpl>{}; |
| 818 for (UnlinkedVariable serializedVariable in serializedClass.fields) { | 808 for (UnlinkedVariable serializedVariable in serializedClass.fields) { |
| 819 buildVariable(serializedVariable, memberHolder); | 809 buildVariable(serializedVariable, memberHolder); |
| 820 } | 810 } |
| 821 bool constructorFound = false; | 811 bool constructorFound = false; |
| 822 constructors = <String, ConstructorElementImpl>{}; | 812 constructors = <String, ConstructorElementImpl>{}; |
| 823 for (UnlinkedExecutable serializedExecutable | 813 for (UnlinkedExecutable serializedExecutable |
| 824 in serializedClass.executables) { | 814 in serializedClass.executables) { |
| 825 switch (serializedExecutable.kind) { | 815 switch (serializedExecutable.kind) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 836 } | 826 } |
| 837 } | 827 } |
| 838 if (!serializedClass.isMixinApplication) { | 828 if (!serializedClass.isMixinApplication) { |
| 839 if (!constructorFound) { | 829 if (!constructorFound) { |
| 840 // Synthesize implicit constructors. | 830 // Synthesize implicit constructors. |
| 841 ConstructorElementImpl constructor = | 831 ConstructorElementImpl constructor = |
| 842 new ConstructorElementImpl('', -1); | 832 new ConstructorElementImpl('', -1); |
| 843 constructor.synthetic = true; | 833 constructor.synthetic = true; |
| 844 constructor.returnType = correspondingType; | 834 constructor.returnType = correspondingType; |
| 845 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs( | 835 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 846 constructor, null, currentTypeArguments, false); | 836 constructor, null, getCurrentTypeArguments(), false); |
| 847 memberHolder.addConstructor(constructor); | 837 memberHolder.addConstructor(constructor); |
| 848 } | 838 } |
| 849 classElement.constructors = memberHolder.constructors; | 839 classElement.constructors = memberHolder.constructors; |
| 850 } | 840 } |
| 851 classElement.accessors = memberHolder.accessors; | 841 classElement.accessors = memberHolder.accessors; |
| 852 classElement.fields = memberHolder.fields; | 842 classElement.fields = memberHolder.fields; |
| 853 classElement.methods = memberHolder.methods; | 843 classElement.methods = memberHolder.methods; |
| 854 correspondingType.typeArguments = currentTypeArguments; | 844 correspondingType.typeArguments = getCurrentTypeArguments(); |
| 855 classElement.type = correspondingType; | 845 classElement.type = correspondingType; |
| 856 buildDocumentation(classElement, serializedClass.documentationComment); | 846 buildDocumentation(classElement, serializedClass.documentationComment); |
| 857 buildAnnotations(classElement, serializedClass.annotations); | 847 buildAnnotations(classElement, serializedClass.annotations); |
| 858 resolveConstructorInitializers(classElement); | 848 resolveConstructorInitializers(classElement); |
| 859 unitHolder.addType(classElement); | 849 unitHolder.addType(classElement); |
| 860 } finally { | 850 } finally { |
| 861 currentTypeParameters = <TypeParameterElement>[]; | 851 currentTypeParameters.removeLast(); |
| 852 assert(currentTypeParameters.isEmpty); |
| 862 fields = null; | 853 fields = null; |
| 863 constructors = null; | 854 constructors = null; |
| 864 } | 855 } |
| 865 } | 856 } |
| 866 | 857 |
| 867 /** | 858 /** |
| 868 * Resynthesize a [NamespaceCombinator]. | 859 * Resynthesize a [NamespaceCombinator]. |
| 869 */ | 860 */ |
| 870 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { | 861 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { |
| 871 if (serializedCombinator.shows.isNotEmpty) { | 862 if (serializedCombinator.shows.isNotEmpty) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 assert(false); | 1072 assert(false); |
| 1082 } | 1073 } |
| 1083 } | 1074 } |
| 1084 | 1075 |
| 1085 /** | 1076 /** |
| 1086 * Handle the parts of an executable element that are common to constructors, | 1077 * Handle the parts of an executable element that are common to constructors, |
| 1087 * functions, methods, getters, and setters. | 1078 * functions, methods, getters, and setters. |
| 1088 */ | 1079 */ |
| 1089 void buildExecutableCommonParts(ExecutableElementImpl executableElement, | 1080 void buildExecutableCommonParts(ExecutableElementImpl executableElement, |
| 1090 UnlinkedExecutable serializedExecutable) { | 1081 UnlinkedExecutable serializedExecutable) { |
| 1091 List<TypeParameterType> oldTypeArguments = currentTypeArguments; | 1082 executableElement.typeParameters = |
| 1092 int oldTypeParametersLength = currentTypeParameters.length; | 1083 buildTypeParameters(serializedExecutable.typeParameters); |
| 1093 if (serializedExecutable.typeParameters.isNotEmpty) { | |
| 1094 executableElement.typeParameters = | |
| 1095 serializedExecutable.typeParameters.map(buildTypeParameter).toList(); | |
| 1096 currentTypeParameters.addAll(executableElement.typeParameters); | |
| 1097 } | |
| 1098 executableElement.parameters = | 1084 executableElement.parameters = |
| 1099 serializedExecutable.parameters.map(buildParameter).toList(); | 1085 serializedExecutable.parameters.map(buildParameter).toList(); |
| 1100 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) { | 1086 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) { |
| 1101 // Caller handles setting the return type. | 1087 // Caller handles setting the return type. |
| 1102 assert(serializedExecutable.returnType == null); | 1088 assert(serializedExecutable.returnType == null); |
| 1103 } else { | 1089 } else { |
| 1104 bool isSetter = | 1090 bool isSetter = |
| 1105 serializedExecutable.kind == UnlinkedExecutableKind.setter; | 1091 serializedExecutable.kind == UnlinkedExecutableKind.setter; |
| 1106 executableElement.returnType = | 1092 executableElement.returnType = |
| 1107 buildLinkedType(serializedExecutable.inferredReturnTypeSlot) ?? | 1093 buildLinkedType(serializedExecutable.inferredReturnTypeSlot) ?? |
| 1108 buildType(serializedExecutable.returnType, | 1094 buildType(serializedExecutable.returnType, |
| 1109 defaultVoid: isSetter && summaryResynthesizer.strongMode); | 1095 defaultVoid: isSetter && summaryResynthesizer.strongMode); |
| 1110 executableElement.hasImplicitReturnType = | 1096 executableElement.hasImplicitReturnType = |
| 1111 serializedExecutable.returnType == null; | 1097 serializedExecutable.returnType == null; |
| 1112 } | 1098 } |
| 1113 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 1099 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 1114 executableElement, null, oldTypeArguments, false); | 1100 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); |
| 1115 executableElement.external = serializedExecutable.isExternal; | 1101 executableElement.external = serializedExecutable.isExternal; |
| 1116 currentTypeParameters.removeRange( | |
| 1117 oldTypeParametersLength, currentTypeParameters.length); | |
| 1118 buildDocumentation( | 1102 buildDocumentation( |
| 1119 executableElement, serializedExecutable.documentationComment); | 1103 executableElement, serializedExecutable.documentationComment); |
| 1120 buildAnnotations(executableElement, serializedExecutable.annotations); | 1104 buildAnnotations(executableElement, serializedExecutable.annotations); |
| 1121 executableElement.functions = | 1105 executableElement.functions = |
| 1122 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); | 1106 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); |
| 1123 executableElement.localVariables = | 1107 executableElement.localVariables = |
| 1124 serializedExecutable.localVariables.map(buildLocalVariable).toList(); | 1108 serializedExecutable.localVariables.map(buildLocalVariable).toList(); |
| 1109 currentTypeParameters.removeLast(); |
| 1125 } | 1110 } |
| 1126 | 1111 |
| 1127 /** | 1112 /** |
| 1128 * Resynthesize an [ExportElement], | 1113 * Resynthesize an [ExportElement], |
| 1129 */ | 1114 */ |
| 1130 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, | 1115 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, |
| 1131 UnlinkedExportNonPublic serializedExportNonPublic) { | 1116 UnlinkedExportNonPublic serializedExportNonPublic) { |
| 1132 ExportElementImpl exportElement = | 1117 ExportElementImpl exportElement = |
| 1133 new ExportElementImpl(serializedExportNonPublic.offset); | 1118 new ExportElementImpl(serializedExportNonPublic.offset); |
| 1134 String exportedLibraryUri = summaryResynthesizer.sourceFactory | 1119 String exportedLibraryUri = summaryResynthesizer.sourceFactory |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 if (serializedParameter.isFunctionTyped) { | 1481 if (serializedParameter.isFunctionTyped) { |
| 1497 FunctionElementImpl parameterTypeElement = | 1482 FunctionElementImpl parameterTypeElement = |
| 1498 new FunctionElementImpl('', -1); | 1483 new FunctionElementImpl('', -1); |
| 1499 parameterTypeElement.synthetic = true; | 1484 parameterTypeElement.synthetic = true; |
| 1500 parameterElement.parameters = | 1485 parameterElement.parameters = |
| 1501 serializedParameter.parameters.map(buildParameter).toList(); | 1486 serializedParameter.parameters.map(buildParameter).toList(); |
| 1502 parameterTypeElement.enclosingElement = parameterElement; | 1487 parameterTypeElement.enclosingElement = parameterElement; |
| 1503 parameterTypeElement.shareParameters(parameterElement.parameters); | 1488 parameterTypeElement.shareParameters(parameterElement.parameters); |
| 1504 parameterTypeElement.returnType = buildType(serializedParameter.type); | 1489 parameterTypeElement.returnType = buildType(serializedParameter.type); |
| 1505 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 1490 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 1506 parameterTypeElement, null, currentTypeArguments, false); | 1491 parameterTypeElement, null, getCurrentTypeArguments(), false); |
| 1507 } else { | 1492 } else { |
| 1508 if (serializedParameter.isInitializingFormal && | 1493 if (serializedParameter.isInitializingFormal && |
| 1509 serializedParameter.type == null) { | 1494 serializedParameter.type == null) { |
| 1510 // The type is inherited from the matching field. | 1495 // The type is inherited from the matching field. |
| 1511 parameterElement.type = fields[serializedParameter.name]?.type ?? | 1496 parameterElement.type = fields[serializedParameter.name]?.type ?? |
| 1512 summaryResynthesizer.typeProvider.dynamicType; | 1497 summaryResynthesizer.typeProvider.dynamicType; |
| 1513 } else { | 1498 } else { |
| 1514 parameterElement.type = | 1499 parameterElement.type = |
| 1515 buildLinkedType(serializedParameter.inferredTypeSlot) ?? | 1500 buildLinkedType(serializedParameter.inferredTypeSlot) ?? |
| 1516 buildType(serializedParameter.type); | 1501 buildType(serializedParameter.type); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 */ | 1554 */ |
| 1570 DartType buildType(EntityRef type, {bool defaultVoid: false}) { | 1555 DartType buildType(EntityRef type, {bool defaultVoid: false}) { |
| 1571 if (type == null) { | 1556 if (type == null) { |
| 1572 if (defaultVoid) { | 1557 if (defaultVoid) { |
| 1573 return VoidTypeImpl.instance; | 1558 return VoidTypeImpl.instance; |
| 1574 } else { | 1559 } else { |
| 1575 return summaryResynthesizer.typeProvider.dynamicType; | 1560 return summaryResynthesizer.typeProvider.dynamicType; |
| 1576 } | 1561 } |
| 1577 } | 1562 } |
| 1578 if (type.paramReference != 0) { | 1563 if (type.paramReference != 0) { |
| 1579 return currentTypeParameters[ | 1564 return getTypeParameterFromScope(type.paramReference); |
| 1580 currentTypeParameters.length - type.paramReference] | |
| 1581 .type; | |
| 1582 } else { | 1565 } else { |
| 1583 DartType getTypeArgument(int i) { | 1566 DartType getTypeArgument(int i) { |
| 1584 if (i < type.typeArguments.length) { | 1567 if (i < type.typeArguments.length) { |
| 1585 return buildType(type.typeArguments[i]); | 1568 return buildType(type.typeArguments[i]); |
| 1586 } else { | 1569 } else { |
| 1587 return summaryResynthesizer.typeProvider.dynamicType; | 1570 return summaryResynthesizer.typeProvider.dynamicType; |
| 1588 } | 1571 } |
| 1589 } | 1572 } |
| 1590 _ReferenceInfo referenceInfo = referenceInfos[type.reference]; | 1573 _ReferenceInfo referenceInfo = referenceInfos[type.reference]; |
| 1591 return referenceInfo.buildType( | 1574 return referenceInfo.buildType( |
| 1592 getTypeArgument, type.implicitFunctionTypeIndices); | 1575 getTypeArgument, type.implicitFunctionTypeIndices); |
| 1593 } | 1576 } |
| 1594 } | 1577 } |
| 1595 | 1578 |
| 1596 /** | 1579 /** |
| 1597 * Resynthesize a [FunctionTypeAliasElement] and place it in the | 1580 * Resynthesize a [FunctionTypeAliasElement] and place it in the |
| 1598 * [unitHolder]. | 1581 * [unitHolder]. |
| 1599 */ | 1582 */ |
| 1600 void buildTypedef(UnlinkedTypedef serializedTypedef) { | 1583 void buildTypedef(UnlinkedTypedef serializedTypedef) { |
| 1601 try { | 1584 try { |
| 1602 currentTypeParameters = | |
| 1603 serializedTypedef.typeParameters.map(buildTypeParameter).toList(); | |
| 1604 for (int i = 0; i < serializedTypedef.typeParameters.length; i++) { | |
| 1605 finishTypeParameter( | |
| 1606 serializedTypedef.typeParameters[i], currentTypeParameters[i]); | |
| 1607 } | |
| 1608 FunctionTypeAliasElementImpl functionTypeAliasElement = | 1585 FunctionTypeAliasElementImpl functionTypeAliasElement = |
| 1609 new FunctionTypeAliasElementImpl( | 1586 new FunctionTypeAliasElementImpl( |
| 1610 serializedTypedef.name, serializedTypedef.nameOffset); | 1587 serializedTypedef.name, serializedTypedef.nameOffset); |
| 1588 functionTypeAliasElement.typeParameters = |
| 1589 buildTypeParameters(serializedTypedef.typeParameters); |
| 1611 functionTypeAliasElement.parameters = | 1590 functionTypeAliasElement.parameters = |
| 1612 serializedTypedef.parameters.map(buildParameter).toList(); | 1591 serializedTypedef.parameters.map(buildParameter).toList(); |
| 1613 functionTypeAliasElement.returnType = | 1592 functionTypeAliasElement.returnType = |
| 1614 buildType(serializedTypedef.returnType); | 1593 buildType(serializedTypedef.returnType); |
| 1615 functionTypeAliasElement.type = | 1594 functionTypeAliasElement.type = |
| 1616 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 1595 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
| 1617 functionTypeAliasElement.typeParameters = currentTypeParameters; | |
| 1618 buildDocumentation( | 1596 buildDocumentation( |
| 1619 functionTypeAliasElement, serializedTypedef.documentationComment); | 1597 functionTypeAliasElement, serializedTypedef.documentationComment); |
| 1620 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); | 1598 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); |
| 1621 unitHolder.addTypeAlias(functionTypeAliasElement); | 1599 unitHolder.addTypeAlias(functionTypeAliasElement); |
| 1622 } finally { | 1600 } finally { |
| 1623 currentTypeParameters = <TypeParameterElement>[]; | 1601 currentTypeParameters.removeLast(); |
| 1602 assert(currentTypeParameters.isEmpty); |
| 1624 } | 1603 } |
| 1625 } | 1604 } |
| 1626 | 1605 |
| 1627 /** | 1606 /** |
| 1628 * Resynthesize a [TypeParameterElement], handling all parts of its except | 1607 * Resynthesize a [TypeParameterElement], handling all parts of its except |
| 1629 * its bound. | 1608 * its bound. |
| 1630 * | 1609 * |
| 1631 * The bound is deferred until later since it may refer to other type | 1610 * The bound is deferred until later since it may refer to other type |
| 1632 * parameters that have not been resynthesized yet. To handle the bound, | 1611 * parameters that have not been resynthesized yet. To handle the bound, |
| 1633 * call [finishTypeParameter]. | 1612 * call [finishTypeParameter]. |
| 1634 */ | 1613 */ |
| 1635 TypeParameterElement buildTypeParameter( | 1614 TypeParameterElement buildTypeParameter( |
| 1636 UnlinkedTypeParam serializedTypeParameter) { | 1615 UnlinkedTypeParam serializedTypeParameter) { |
| 1637 TypeParameterElementImpl typeParameterElement = | 1616 TypeParameterElementImpl typeParameterElement = |
| 1638 new TypeParameterElementImpl( | 1617 new TypeParameterElementImpl( |
| 1639 serializedTypeParameter.name, serializedTypeParameter.nameOffset); | 1618 serializedTypeParameter.name, serializedTypeParameter.nameOffset); |
| 1640 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); | 1619 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); |
| 1641 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations); | 1620 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations); |
| 1642 return typeParameterElement; | 1621 return typeParameterElement; |
| 1643 } | 1622 } |
| 1644 | 1623 |
| 1645 /** | 1624 /** |
| 1625 * Build [TypeParameterElements] corresponding to the type parameters in |
| 1626 * [serializedTypeParameters] and store them in [currentTypeParameters]. |
| 1627 * Also return them. |
| 1628 */ |
| 1629 List<TypeParameterElement> buildTypeParameters( |
| 1630 List<UnlinkedTypeParam> serializedTypeParameters) { |
| 1631 List<TypeParameterElement> typeParameters = |
| 1632 serializedTypeParameters.map(buildTypeParameter).toList(); |
| 1633 currentTypeParameters.add(typeParameters); |
| 1634 for (int i = 0; i < serializedTypeParameters.length; i++) { |
| 1635 finishTypeParameter(serializedTypeParameters[i], typeParameters[i]); |
| 1636 } |
| 1637 return typeParameters; |
| 1638 } |
| 1639 |
| 1640 /** |
| 1646 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. | 1641 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. |
| 1647 */ | 1642 */ |
| 1648 void buildVariable(UnlinkedVariable serializedVariable, | 1643 void buildVariable(UnlinkedVariable serializedVariable, |
| 1649 [ElementHolder holder]) { | 1644 [ElementHolder holder]) { |
| 1650 if (holder == null) { | 1645 if (holder == null) { |
| 1651 TopLevelVariableElementImpl element; | 1646 TopLevelVariableElementImpl element; |
| 1652 if (serializedVariable.constExpr != null) { | 1647 if (serializedVariable.constExpr != null) { |
| 1653 ConstTopLevelVariableElementImpl constElement = | 1648 ConstTopLevelVariableElementImpl constElement = |
| 1654 new ConstTopLevelVariableElementImpl( | 1649 new ConstTopLevelVariableElementImpl( |
| 1655 serializedVariable.name, serializedVariable.nameOffset); | 1650 serializedVariable.name, serializedVariable.nameOffset); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 void finishUnit() { | 1709 void finishUnit() { |
| 1715 unitHolder = null; | 1710 unitHolder = null; |
| 1716 linkedUnit = null; | 1711 linkedUnit = null; |
| 1717 unlinkedUnit = null; | 1712 unlinkedUnit = null; |
| 1718 linkedTypeMap = null; | 1713 linkedTypeMap = null; |
| 1719 referenceInfos = null; | 1714 referenceInfos = null; |
| 1720 currentCompilationUnit = null; | 1715 currentCompilationUnit = null; |
| 1721 } | 1716 } |
| 1722 | 1717 |
| 1723 /** | 1718 /** |
| 1719 * Return a list of type arguments corresponding to [currentTypeParameters], |
| 1720 * skipping the innermost [skipLevels] nesting levels. |
| 1721 * |
| 1722 * Type parameters are listed in nesting order from innermost to outermost, |
| 1723 * and then in declaration order. So for instance if we are resynthesizing a |
| 1724 * method declared as `class C<T, U> { void m<V, W>() { ... } }`, then the |
| 1725 * type parameters will be returned in the order `[V, W, T, U]`. |
| 1726 */ |
| 1727 List<TypeParameterType> getCurrentTypeArguments({int skipLevels: 0}) { |
| 1728 assert(currentTypeParameters.length >= skipLevels); |
| 1729 List<TypeParameterType> result = <TypeParameterType>[]; |
| 1730 for (int i = currentTypeParameters.length - 1 - skipLevels; i >= 0; i--) { |
| 1731 result.addAll(currentTypeParameters[i] |
| 1732 .map((TypeParameterElement param) => param.type)); |
| 1733 } |
| 1734 return result; |
| 1735 } |
| 1736 |
| 1737 /** |
| 1724 * Build the components of an [ElementLocationImpl] for the entity in the | 1738 * Build the components of an [ElementLocationImpl] for the entity in the |
| 1725 * given [unit] of the dependency located at [dependencyIndex], and having | 1739 * given [unit] of the dependency located at [dependencyIndex], and having |
| 1726 * the given [name]. | 1740 * the given [name]. |
| 1727 */ | 1741 */ |
| 1728 List<String> getReferencedLocationComponents( | 1742 List<String> getReferencedLocationComponents( |
| 1729 int dependencyIndex, int unit, String name) { | 1743 int dependencyIndex, int unit, String name) { |
| 1730 if (dependencyIndex == 0) { | 1744 if (dependencyIndex == 0) { |
| 1731 String referencedLibraryUri = librarySource.uri.toString(); | 1745 String referencedLibraryUri = librarySource.uri.toString(); |
| 1732 String partUri; | 1746 String partUri; |
| 1733 if (unit != 0) { | 1747 if (unit != 0) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1750 Source partSource = summaryResynthesizer.sourceFactory | 1764 Source partSource = summaryResynthesizer.sourceFactory |
| 1751 .resolveUri(referencedLibrarySource, uri); | 1765 .resolveUri(referencedLibrarySource, uri); |
| 1752 partUri = partSource.uri.toString(); | 1766 partUri = partSource.uri.toString(); |
| 1753 } else { | 1767 } else { |
| 1754 partUri = referencedLibraryUri; | 1768 partUri = referencedLibraryUri; |
| 1755 } | 1769 } |
| 1756 return <String>[referencedLibraryUri, partUri, name]; | 1770 return <String>[referencedLibraryUri, partUri, name]; |
| 1757 } | 1771 } |
| 1758 | 1772 |
| 1759 /** | 1773 /** |
| 1774 * Get the type parameter from the surrounding scope whose De Bruijn index is |
| 1775 * [index]. |
| 1776 */ |
| 1777 DartType getTypeParameterFromScope(int index) { |
| 1778 for (int i = currentTypeParameters.length - 1; i >= 0; i--) { |
| 1779 List<TypeParameterElement> paramsAtThisNestingLevel = |
| 1780 currentTypeParameters[i]; |
| 1781 int numParamsAtThisNestingLevel = paramsAtThisNestingLevel.length; |
| 1782 if (index <= numParamsAtThisNestingLevel) { |
| 1783 return paramsAtThisNestingLevel[numParamsAtThisNestingLevel - index] |
| 1784 .type; |
| 1785 } |
| 1786 index -= numParamsAtThisNestingLevel; |
| 1787 } |
| 1788 throw new StateError('Type parameter not found'); |
| 1789 } |
| 1790 |
| 1791 /** |
| 1760 * Populate [referenceInfos] with the correct information for the current | 1792 * Populate [referenceInfos] with the correct information for the current |
| 1761 * compilation unit. | 1793 * compilation unit. |
| 1762 */ | 1794 */ |
| 1763 void populateReferenceInfos() { | 1795 void populateReferenceInfos() { |
| 1764 int numLinkedReferences = linkedUnit.references.length; | 1796 int numLinkedReferences = linkedUnit.references.length; |
| 1765 int numUnlinkedReferences = unlinkedUnit.references.length; | 1797 int numUnlinkedReferences = unlinkedUnit.references.length; |
| 1766 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); | 1798 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); |
| 1767 for (int i = 0; i < numLinkedReferences; i++) { | 1799 for (int i = 0; i < numLinkedReferences; i++) { |
| 1768 LinkedReference linkedReference = linkedUnit.references[i]; | 1800 LinkedReference linkedReference = linkedUnit.references[i]; |
| 1769 _ReferenceInfo enclosingInfo = null; | 1801 _ReferenceInfo enclosingInfo = null; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 1913 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 1882 elementMap[typeAlias.name] = typeAlias; | 1914 elementMap[typeAlias.name] = typeAlias; |
| 1883 } | 1915 } |
| 1884 for (FunctionElement function in unit.functions) { | 1916 for (FunctionElement function in unit.functions) { |
| 1885 elementMap[function.name] = function; | 1917 elementMap[function.name] = function; |
| 1886 } | 1918 } |
| 1887 for (PropertyAccessorElementImpl accessor in unit.accessors) { | 1919 for (PropertyAccessorElementImpl accessor in unit.accessors) { |
| 1888 elementMap[accessor.identifier] = accessor; | 1920 elementMap[accessor.identifier] = accessor; |
| 1889 } | 1921 } |
| 1890 resummarizedElements[absoluteUri] = elementMap; | 1922 resummarizedElements[absoluteUri] = elementMap; |
| 1923 assert(currentTypeParameters.isEmpty); |
| 1891 } | 1924 } |
| 1892 | 1925 |
| 1893 /** | 1926 /** |
| 1894 * Set up data structures for deserializing a compilation unit. | 1927 * Set up data structures for deserializing a compilation unit. |
| 1895 */ | 1928 */ |
| 1896 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { | 1929 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { |
| 1897 linkedUnit = linkedLibrary.units[unitNum]; | 1930 linkedUnit = linkedLibrary.units[unitNum]; |
| 1898 unlinkedUnit = unlinkedUnits[unitNum]; | 1931 unlinkedUnit = unlinkedUnits[unitNum]; |
| 1899 linkedTypeMap = <int, EntityRef>{}; | 1932 linkedTypeMap = <int, EntityRef>{}; |
| 1900 currentCompilationUnit = unit; | 1933 currentCompilationUnit = unit; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2117 } | 2150 } |
| 2118 : () => this.element; | 2151 : () => this.element; |
| 2119 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2152 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2120 // isInstantiated? | 2153 // isInstantiated? |
| 2121 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2154 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2122 } else { | 2155 } else { |
| 2123 return null; | 2156 return null; |
| 2124 } | 2157 } |
| 2125 } | 2158 } |
| 2126 } | 2159 } |
| OLD | NEW |