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

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

Issue 1899873003: Support for type inference of top-level function invocations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/resynthesize_ast_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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 compilationUnit.addReference(element.enclosingExecutable); 193 compilationUnit.addReference(element.enclosingExecutable);
194 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices; 194 result.implicitFunctionTypeIndices = element.implicitFunctionTypeIndices;
195 if (type.typeArguments.isNotEmpty) { 195 if (type.typeArguments.isNotEmpty) {
196 result.typeArguments = type.typeArguments 196 result.typeArguments = type.typeArguments
197 .map((DartType t) => 197 .map((DartType t) =>
198 _createLinkedType(t, compilationUnit, typeParameterContext)) 198 _createLinkedType(t, compilationUnit, typeParameterContext))
199 .toList(); 199 .toList();
200 } 200 }
201 return result; 201 return result;
202 } 202 }
203 if (element is TopLevelFunctionElementForLink) {
204 result.reference = compilationUnit.addReference(element);
205 if (type.typeArguments.isNotEmpty) {
206 result.typeArguments = type.typeArguments
207 .map((DartType t) =>
208 _createLinkedType(t, compilationUnit, typeParameterContext))
209 .toList();
210 }
211 return result;
212 }
203 if (element is MethodElementForLink) { 213 if (element is MethodElementForLink) {
204 result.reference = compilationUnit.addReference(element); 214 result.reference = compilationUnit.addReference(element);
205 if (type.typeArguments.isNotEmpty) { 215 if (type.typeArguments.isNotEmpty) {
206 result.typeArguments = type.typeArguments 216 result.typeArguments = type.typeArguments
207 .map((DartType t) => 217 .map((DartType t) =>
208 _createLinkedType(t, compilationUnit, typeParameterContext)) 218 _createLinkedType(t, compilationUnit, typeParameterContext))
209 .toList(); 219 .toList();
210 } 220 }
211 return result; 221 return result;
212 } 222 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 669
660 /** 670 /**
661 * The absolute URI of this compilation unit. 671 * The absolute URI of this compilation unit.
662 */ 672 */
663 final String _absoluteUri; 673 final String _absoluteUri;
664 674
665 List<ClassElementForLink_Class> _types; 675 List<ClassElementForLink_Class> _types;
666 Map<String, ReferenceableElementForLink> _containedNames; 676 Map<String, ReferenceableElementForLink> _containedNames;
667 List<TopLevelVariableElementForLink> _topLevelVariables; 677 List<TopLevelVariableElementForLink> _topLevelVariables;
668 List<ClassElementForLink_Enum> _enums; 678 List<ClassElementForLink_Enum> _enums;
679 List<TopLevelFunctionElementForLink> _functions;
669 680
670 /** 681 /**
671 * Index of this unit in the list of units in the enclosing library. 682 * Index of this unit in the list of units in the enclosing library.
672 */ 683 */
673 final int unitNum; 684 final int unitNum;
674 685
675 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum, 686 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum,
676 int numReferences, this._absoluteUri) 687 int numReferences, this._absoluteUri)
677 : _references = new List<ReferenceableElementForLink>(numReferences), 688 : _references = new List<ReferenceableElementForLink>(numReferences),
678 _unlinkedUnit = unlinkedUnit; 689 _unlinkedUnit = unlinkedUnit;
679 690
680 @override 691 @override
681 LibraryElementForLink get enclosingElement; 692 LibraryElementForLink get enclosingElement;
682 693
683 @override 694 @override
684 List<ClassElementForLink_Enum> get enums { 695 List<ClassElementForLink_Enum> get enums {
685 if (_enums == null) { 696 if (_enums == null) {
686 _enums = <ClassElementForLink_Enum>[]; 697 _enums = <ClassElementForLink_Enum>[];
687 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { 698 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) {
688 _enums.add(new ClassElementForLink_Enum(this, unlinkedEnum)); 699 _enums.add(new ClassElementForLink_Enum(this, unlinkedEnum));
689 } 700 }
690 } 701 }
691 return _enums; 702 return _enums;
692 } 703 }
693 704
694 @override 705 @override
706 List<TopLevelFunctionElementForLink> get functions {
707 if (_functions == null) {
708 _functions = <TopLevelFunctionElementForLink>[];
709 for (UnlinkedExecutable executable in _unlinkedUnit.executables) {
Paul Berry 2016/04/18 20:08:27 Is CompilationUnitElement.functions supposed to re
scheglov 2016/04/18 20:24:34 You're right. Done.
710 _functions.add(new TopLevelFunctionElementForLink(this, executable));
711 }
712 }
713 return _functions;
714 }
715
716 @override
695 String get identifier => _absoluteUri; 717 String get identifier => _absoluteUri;
696 718
697 /** 719 /**
698 * Indicates whether this compilation element is part of the build unit 720 * Indicates whether this compilation element is part of the build unit
699 * currently being linked. 721 * currently being linked.
700 */ 722 */
701 bool get isInBuildUnit; 723 bool get isInBuildUnit;
702 724
703 /** 725 /**
704 * Determine whether type inference is complete in this compilation unit. 726 * Determine whether type inference is complete in this compilation unit.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // TODO(paulberry): what's the correct way to handle name conflicts? 776 // TODO(paulberry): what's the correct way to handle name conflicts?
755 for (ClassElementForLink_Class type in types) { 777 for (ClassElementForLink_Class type in types) {
756 _containedNames[type.name] = type; 778 _containedNames[type.name] = type;
757 } 779 }
758 for (ClassElementForLink_Enum enm in enums) { 780 for (ClassElementForLink_Enum enm in enums) {
759 _containedNames[enm.name] = enm; 781 _containedNames[enm.name] = enm;
760 } 782 }
761 for (TopLevelVariableElementForLink variable in topLevelVariables) { 783 for (TopLevelVariableElementForLink variable in topLevelVariables) {
762 _containedNames[variable.name] = variable; 784 _containedNames[variable.name] = variable;
763 } 785 }
786 for (TopLevelFunctionElementForLink function in functions) {
787 _containedNames[function.name] = function;
788 }
764 // TODO(paulberry): fill in other top level entities (typedefs 789 // TODO(paulberry): fill in other top level entities (typedefs
765 // and executables). 790 // and executables).
766 } 791 }
767 return _containedNames.putIfAbsent( 792 return _containedNames.putIfAbsent(
768 name, () => UndefinedElementForLink.instance); 793 name, () => UndefinedElementForLink.instance);
769 } 794 }
770 795
771 /** 796 /**
772 * Compute the type referred to by the given linked type [slot] (interpreted 797 * Compute the type referred to by the given linked type [slot] (interpreted
773 * relative to [typeParameterContext]). If there is no inferred type in the 798 * relative to [typeParameterContext]). If there is no inferred type in the
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 * to [element], return its index. Otherwise add a new reference to the table 962 * to [element], return its index. Otherwise add a new reference to the table
938 * and return its index. 963 * and return its index.
939 */ 964 */
940 int addReference(Element element) { 965 int addReference(Element element) {
941 if (element is ClassElementForLink) { 966 if (element is ClassElementForLink) {
942 return addRawReference(element.name, 967 return addRawReference(element.name,
943 dependency: library.addDependency(element.library), 968 dependency: library.addDependency(element.library),
944 numTypeParameters: element.typeParameters.length, 969 numTypeParameters: element.typeParameters.length,
945 unitNum: element.enclosingElement.unitNum); 970 unitNum: element.enclosingElement.unitNum);
946 } else if (element is ExecutableElementForLink) { 971 } else if (element is ExecutableElementForLink) {
947 // TODO(paulberry): will this code ever be executed for an executable 972 ClassElementForLink_Class enclosingClass = element.enclosingClass;
948 // element that's not inside a class?
949 assert(element.enclosingElement is ClassElementForLink_Class);
950 ReferenceKind kind; 973 ReferenceKind kind;
951 switch (element._unlinkedExecutable.kind) { 974 switch (element._unlinkedExecutable.kind) {
952 case UnlinkedExecutableKind.functionOrMethod: 975 case UnlinkedExecutableKind.functionOrMethod:
953 kind = ReferenceKind.method; 976 kind = enclosingClass != null
977 ? ReferenceKind.method
978 : ReferenceKind.topLevelFunction;
954 break; 979 break;
955 case UnlinkedExecutableKind.setter: 980 case UnlinkedExecutableKind.setter:
956 kind = ReferenceKind.propertyAccessor; 981 kind = ReferenceKind.propertyAccessor;
957 break; 982 break;
958 default: 983 default:
959 // TODO(paulberry): implement other cases as necessary 984 // TODO(paulberry): implement other cases as necessary
960 throw new UnimplementedError('${element._unlinkedExecutable.kind}'); 985 throw new UnimplementedError('${element._unlinkedExecutable.kind}');
961 } 986 }
962 return addRawReference(element.name, 987 return addRawReference(element.name,
963 numTypeParameters: element.typeParameters.length, 988 numTypeParameters: element.typeParameters.length,
964 containingReference: addReference(element.enclosingElement), 989 containingReference:
990 enclosingClass != null ? addReference(enclosingClass) : null,
965 kind: kind); 991 kind: kind);
966 } 992 }
967 // TODO(paulberry): implement other cases 993 // TODO(paulberry): implement other cases
968 throw new UnimplementedError('${element.runtimeType}'); 994 throw new UnimplementedError('${element.runtimeType}');
969 } 995 }
970 996
971 @override 997 @override
972 DartType getLinkedType( 998 DartType getLinkedType(
973 int slot, TypeParameterizedElementForLink typeParameterContext) { 999 int slot, TypeParameterizedElementForLink typeParameterContext) {
974 // This method should only be called on compilation units that come from 1000 // This method should only be called on compilation units that come from
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 if (superClass != null && !superClass.isObject) { 1165 if (superClass != null && !superClass.isObject) {
1140 ConstructorElementForLink constructor = superClass 1166 ConstructorElementForLink constructor = superClass
1141 .getContainedName(constructorInitializer.name) 1167 .getContainedName(constructorInitializer.name)
1142 .asConstructor; 1168 .asConstructor;
1143 safeAddDependency(constructor?._constNode); 1169 safeAddDependency(constructor?._constNode);
1144 } 1170 }
1145 } else if (constructorInitializer.kind == 1171 } else if (constructorInitializer.kind ==
1146 UnlinkedConstructorInitializerKind.thisInvocation) { 1172 UnlinkedConstructorInitializerKind.thisInvocation) {
1147 defaultSuperInvocationNeeded = false; 1173 defaultSuperInvocationNeeded = false;
1148 ConstructorElementForLink constructor = constructorElement 1174 ConstructorElementForLink constructor = constructorElement
1149 .enclosingElement 1175 .enclosingClass
1150 .getContainedName(constructorInitializer.name) 1176 .getContainedName(constructorInitializer.name)
1151 .asConstructor; 1177 .asConstructor;
1152 safeAddDependency(constructor?._constNode); 1178 safeAddDependency(constructor?._constNode);
1153 } 1179 }
1154 CompilationUnitElementForLink compilationUnit = 1180 CompilationUnitElementForLink compilationUnit =
1155 constructorElement.enclosingElement.enclosingElement; 1181 constructorElement.enclosingElement.enclosingElement;
1156 collectDependencies( 1182 collectDependencies(
1157 dependencies, constructorInitializer.expression, compilationUnit); 1183 dependencies, constructorInitializer.expression, compilationUnit);
1158 for (UnlinkedConst unlinkedConst in constructorInitializer.arguments) { 1184 for (UnlinkedConst unlinkedConst in constructorInitializer.arguments) {
1159 collectDependencies(dependencies, unlinkedConst, compilationUnit); 1185 collectDependencies(dependencies, unlinkedConst, compilationUnit);
(...skipping 25 matching lines...) Expand all
1185 } 1211 }
1186 1212
1187 /** 1213 /**
1188 * If [constructorElement] redirects to another constructor via a factory 1214 * If [constructorElement] redirects to another constructor via a factory
1189 * redirect, return the constructor it redirects to. 1215 * redirect, return the constructor it redirects to.
1190 */ 1216 */
1191 ConstructorElementForLink _getFactoryRedirectedConstructor() { 1217 ConstructorElementForLink _getFactoryRedirectedConstructor() {
1192 EntityRef redirectedConstructor = 1218 EntityRef redirectedConstructor =
1193 constructorElement._unlinkedExecutable.redirectedConstructor; 1219 constructorElement._unlinkedExecutable.redirectedConstructor;
1194 if (redirectedConstructor != null) { 1220 if (redirectedConstructor != null) {
1195 return constructorElement.enclosingElement.enclosingElement 1221 return constructorElement.enclosingUnit
1196 ._resolveRef(redirectedConstructor.reference) 1222 ._resolveRef(redirectedConstructor.reference)
1197 .asConstructor; 1223 .asConstructor;
1198 } else { 1224 } else {
1199 return null; 1225 return null;
1200 } 1226 }
1201 } 1227 }
1202 } 1228 }
1203 1229
1204 /** 1230 /**
1205 * Specialization of [DependencyWalker] for detecting constant 1231 * Specialization of [DependencyWalker] for detecting constant
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 */ 1333 */
1308 class ConstructorElementForLink extends ExecutableElementForLink 1334 class ConstructorElementForLink extends ExecutableElementForLink
1309 implements ConstructorElementImpl, ReferenceableElementForLink { 1335 implements ConstructorElementImpl, ReferenceableElementForLink {
1310 /** 1336 /**
1311 * If this is a `const` constructor and the enclosing library is 1337 * If this is a `const` constructor and the enclosing library is
1312 * part of the build unit being linked, the constructor's node in 1338 * part of the build unit being linked, the constructor's node in
1313 * the constant evaluation dependency graph. Otherwise `null`. 1339 * the constant evaluation dependency graph. Otherwise `null`.
1314 */ 1340 */
1315 ConstConstructorNode _constNode; 1341 ConstConstructorNode _constNode;
1316 1342
1317 ConstructorElementForLink(ClassElementForLink_Class enclosingElement, 1343 ConstructorElementForLink(ClassElementForLink_Class enclosingClass,
1318 UnlinkedExecutable unlinkedExecutable) 1344 UnlinkedExecutable unlinkedExecutable)
1319 : super(enclosingElement, unlinkedExecutable) { 1345 : super(enclosingClass.enclosingElement, enclosingClass,
1320 if (enclosingElement.enclosingElement.isInBuildUnit && 1346 unlinkedExecutable) {
1347 if (enclosingClass.enclosingElement.isInBuildUnit &&
1321 _unlinkedExecutable != null && 1348 _unlinkedExecutable != null &&
1322 _unlinkedExecutable.constCycleSlot != 0) { 1349 _unlinkedExecutable.constCycleSlot != 0) {
1323 _constNode = new ConstConstructorNode(this); 1350 _constNode = new ConstConstructorNode(this);
1324 } 1351 }
1325 } 1352 }
1326 1353
1327 @override 1354 @override
1328 ConstructorElementForLink get asConstructor => this; 1355 ConstructorElementForLink get asConstructor => this;
1329 1356
1330 @override 1357 @override
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 1593
1567 DartType _declaredReturnType; 1594 DartType _declaredReturnType;
1568 DartType _inferredReturnType; 1595 DartType _inferredReturnType;
1569 FunctionTypeImpl _type; 1596 FunctionTypeImpl _type;
1570 List<TypeParameterElementForLink> _typeParameters; 1597 List<TypeParameterElementForLink> _typeParameters;
1571 String _name; 1598 String _name;
1572 List<ParameterElementForLink> _parameters; 1599 List<ParameterElementForLink> _parameters;
1573 String _displayName; 1600 String _displayName;
1574 1601
1575 /** 1602 /**
1576 * TODO(paulberry): this won't always be a class element. 1603 * Return the class in which this executable appears, maybe `null` for a
1604 * top-level function.
1577 */ 1605 */
1578 @override 1606 final ClassElementForLink_Class enclosingClass;
1579 final ClassElementForLink_Class enclosingElement;
1580
1581 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable);
1582 1607
1583 /** 1608 /**
1584 * Return the compilation unit in which this executable appears. 1609 * Return the compilation unit in which this executable appears.
1585 */ 1610 */
1586 CompilationUnitElementForLink get compilationUnit => 1611 final CompilationUnitElementForLink enclosingUnit;
1587 enclosingElement.enclosingElement; 1612
1613 ExecutableElementForLink(
1614 this.enclosingUnit, this.enclosingClass, this._unlinkedExecutable);
1588 1615
1589 @override 1616 @override
1590 String get displayName { 1617 String get displayName {
1591 if (_displayName == null) { 1618 if (_displayName == null) {
1592 _displayName = _unlinkedExecutable.name; 1619 _displayName = _unlinkedExecutable.name;
1593 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { 1620 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
1594 _displayName = _displayName.substring(0, _displayName.length - 1); 1621 _displayName = _displayName.substring(0, _displayName.length - 1);
1595 } 1622 }
1596 } 1623 }
1597 return _displayName; 1624 return _displayName;
1598 } 1625 }
1599 1626
1600 @override 1627 @override
1628 Element get enclosingElement => enclosingClass ?? enclosingUnit;
1629
1630 @override
1601 TypeParameterizedElementForLink get enclosingTypeParameterContext => 1631 TypeParameterizedElementForLink get enclosingTypeParameterContext =>
1602 enclosingElement; 1632 enclosingClass;
1603 1633
1604 @override 1634 @override
1605 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; 1635 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null;
1606 1636
1607 @override 1637 @override
1608 bool get isStatic => _unlinkedExecutable.isStatic; 1638 bool get isStatic => _unlinkedExecutable.isStatic;
1609 1639
1610 @override 1640 @override
1611 bool get isSynthetic => false; 1641 bool get isSynthetic => false;
1612 1642
(...skipping 12 matching lines...) Expand all
1625 } 1655 }
1626 1656
1627 @override 1657 @override
1628 List<ParameterElementForLink> get parameters { 1658 List<ParameterElementForLink> get parameters {
1629 if (_parameters == null) { 1659 if (_parameters == null) {
1630 int numParameters = _unlinkedExecutable.parameters.length; 1660 int numParameters = _unlinkedExecutable.parameters.length;
1631 _parameters = new List<ParameterElementForLink>(numParameters); 1661 _parameters = new List<ParameterElementForLink>(numParameters);
1632 for (int i = 0; i < numParameters; i++) { 1662 for (int i = 0; i < numParameters; i++) {
1633 UnlinkedParam unlinkedParam = _unlinkedExecutable.parameters[i]; 1663 UnlinkedParam unlinkedParam = _unlinkedExecutable.parameters[i];
1634 _parameters[i] = new ParameterElementForLink( 1664 _parameters[i] = new ParameterElementForLink(
1635 this, unlinkedParam, this, enclosingElement.enclosingElement, i); 1665 this, unlinkedParam, this, enclosingUnit, i);
1636 } 1666 }
1637 } 1667 }
1638 return _parameters; 1668 return _parameters;
1639 } 1669 }
1640 1670
1641 @override 1671 @override
1642 DartType get returnType { 1672 DartType get returnType {
1643 if (_inferredReturnType != null) { 1673 if (_inferredReturnType != null) {
1644 return _inferredReturnType; 1674 return _inferredReturnType;
1645 } else if (_declaredReturnType == null) { 1675 } else if (_declaredReturnType == null) {
1646 if (_unlinkedExecutable.returnType == null) { 1676 if (_unlinkedExecutable.returnType == null) {
1647 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { 1677 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) {
1648 // TODO(paulberry): implement. 1678 // TODO(paulberry): implement.
1649 throw new UnimplementedError(); 1679 throw new UnimplementedError();
1650 } else if (!compilationUnit.isInBuildUnit) { 1680 } else if (!enclosingUnit.isInBuildUnit) {
1651 _inferredReturnType = compilationUnit.getLinkedType( 1681 _inferredReturnType = enclosingUnit.getLinkedType(
1652 _unlinkedExecutable.inferredReturnTypeSlot, this); 1682 _unlinkedExecutable.inferredReturnTypeSlot, this);
1653 return _inferredReturnType; 1683 return _inferredReturnType;
1654 } else if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter && 1684 } else if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter &&
1655 library._linker.strongMode) { 1685 library._linker.strongMode) {
1656 // In strong mode, setters without an explicit return type are 1686 // In strong mode, setters without an explicit return type are
1657 // considered to return `void`. 1687 // considered to return `void`.
1658 _declaredReturnType = VoidTypeImpl.instance; 1688 _declaredReturnType = VoidTypeImpl.instance;
1659 } else { 1689 } else {
1660 _declaredReturnType = DynamicTypeImpl.instance; 1690 _declaredReturnType = DynamicTypeImpl.instance;
1661 } 1691 }
1662 } else { 1692 } else {
1663 _declaredReturnType = enclosingElement.enclosingElement 1693 _declaredReturnType =
1664 ._resolveTypeRef(_unlinkedExecutable.returnType, this); 1694 enclosingUnit._resolveTypeRef(_unlinkedExecutable.returnType, this);
1665 } 1695 }
1666 } 1696 }
1667 return _declaredReturnType; 1697 return _declaredReturnType;
1668 } 1698 }
1669 1699
1670 @override 1700 @override
1671 void set returnType(DartType inferredType) { 1701 void set returnType(DartType inferredType) {
1672 assert(_inferredReturnType == null); 1702 assert(_inferredReturnType == null);
1673 _inferredReturnType = inferredType; 1703 _inferredReturnType = inferredType;
1674 } 1704 }
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 }()); 2044 }());
2015 } 2045 }
2016 2046
2017 void _doInvokeConstructor() { 2047 void _doInvokeConstructor() {
2018 int numNamed = _getNextInt(); 2048 int numNamed = _getNextInt();
2019 int numPositional = _getNextInt(); 2049 int numPositional = _getNextInt();
2020 // TODO(paulberry): don't just pop the args; use their types 2050 // TODO(paulberry): don't just pop the args; use their types
2021 // to infer the type of type arguments. 2051 // to infer the type of type arguments.
2022 stack.length -= numNamed + numPositional; 2052 stack.length -= numNamed + numPositional;
2023 strPtr += numNamed; 2053 strPtr += numNamed;
2024 EntityRef ref = unlinkedConst.references[refPtr++]; 2054 EntityRef ref = _getNextRef();
2025 ConstructorElementForLink element = 2055 ConstructorElementForLink element =
2026 unit._resolveRef(ref.reference).asConstructor; 2056 unit._resolveRef(ref.reference).asConstructor;
2027 if (element != null) { 2057 if (element != null) {
2028 stack.add(element.enclosingElement.buildType( 2058 stack.add(element.enclosingClass.buildType(
2029 (int i) => i >= ref.typeArguments.length 2059 (int i) => i >= ref.typeArguments.length
2030 ? DynamicTypeImpl.instance 2060 ? DynamicTypeImpl.instance
2031 : unit._resolveTypeRef( 2061 : unit._resolveTypeRef(
2032 ref.typeArguments[i], variable._typeParameterContext), 2062 ref.typeArguments[i], variable._typeParameterContext),
2033 const [])); 2063 const []));
2034 } else { 2064 } else {
2035 stack.add(DynamicTypeImpl.instance); 2065 stack.add(DynamicTypeImpl.instance);
2036 } 2066 }
2037 } 2067 }
2038 2068
(...skipping 20 matching lines...) Expand all
2059 return DynamicTypeImpl.instance; 2089 return DynamicTypeImpl.instance;
2060 }()); 2090 }());
2061 } 2091 }
2062 2092
2063 void _doInvokeMethodRef() { 2093 void _doInvokeMethodRef() {
2064 int numNamed = _getNextInt(); 2094 int numNamed = _getNextInt();
2065 int numPositional = _getNextInt(); 2095 int numPositional = _getNextInt();
2066 List<String> namedArgNames = _getNextStrings(numNamed); 2096 List<String> namedArgNames = _getNextStrings(numNamed);
2067 List<DartType> namedArgTypeList = _popList(numNamed); 2097 List<DartType> namedArgTypeList = _popList(numNamed);
2068 List<DartType> positionalArgTypes = _popList(numPositional); 2098 List<DartType> positionalArgTypes = _popList(numPositional);
2069 EntityRef ref = unlinkedConst.references[refPtr++]; 2099 EntityRef ref = _getNextRef();
2070 ReferenceableElementForLink element = unit._resolveRef(ref.reference); 2100 ReferenceableElementForLink element = unit._resolveRef(ref.reference);
2071 stack.add(() { 2101 stack.add(() {
2072 DartType rawType = element.asStaticType; 2102 DartType rawType = element.asStaticType;
2073 if (rawType is FunctionType) { 2103 if (rawType is FunctionType) {
2074 FunctionType inferredType = _inferExecutableType(rawType, numNamed, 2104 FunctionType inferredType = _inferExecutableType(rawType, numNamed,
2075 numPositional, namedArgNames, namedArgTypeList, positionalArgTypes); 2105 numPositional, namedArgNames, namedArgTypeList, positionalArgTypes);
2076 if (inferredType != null) { 2106 if (inferredType != null) {
2077 return inferredType.returnType; 2107 return inferredType.returnType;
2078 } 2108 }
2079 } 2109 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 valueType = 2146 valueType =
2117 valueType == null ? type : _leastUpperBound(valueType, type); 2147 valueType == null ? type : _leastUpperBound(valueType, type);
2118 } 2148 }
2119 } 2149 }
2120 keyType = _dynamicIfNull(keyType); 2150 keyType = _dynamicIfNull(keyType);
2121 valueType = _dynamicIfNull(valueType); 2151 valueType = _dynamicIfNull(valueType);
2122 stack.add(typeProvider.mapType.instantiate(<DartType>[keyType, valueType])); 2152 stack.add(typeProvider.mapType.instantiate(<DartType>[keyType, valueType]));
2123 } 2153 }
2124 2154
2125 void _doPushReference() { 2155 void _doPushReference() {
2126 EntityRef ref = unlinkedConst.references[refPtr++]; 2156 EntityRef ref = _getNextRef();
2127 if (ref.paramReference != 0) { 2157 if (ref.paramReference != 0) {
2128 stack.add(typeProvider.typeType); 2158 stack.add(typeProvider.typeType);
2129 } else { 2159 } else {
2130 // Synthetic function types can't be directly referred 2160 // Synthetic function types can't be directly referred
2131 // to by expressions. 2161 // to by expressions.
2132 assert(ref.syntheticReturnType == null); 2162 assert(ref.syntheticReturnType == null);
2133 // Nor can implicit function types derived from 2163 // Nor can implicit function types derived from
2134 // function-typed parameters. 2164 // function-typed parameters.
2135 assert(ref.implicitFunctionTypeIndices.isEmpty); 2165 assert(ref.implicitFunctionTypeIndices.isEmpty);
2136 ReferenceableElementForLink element = 2166 ReferenceableElementForLink element = unit._resolveRef(ref.reference);
2137 variable.compilationUnit._resolveRef(ref.reference);
2138 stack.add(element.asStaticType); 2167 stack.add(element.asStaticType);
2139 } 2168 }
2140 } 2169 }
2141 2170
2142 int _getNextInt() { 2171 int _getNextInt() {
2143 return unlinkedConst.ints[intPtr++]; 2172 return unlinkedConst.ints[intPtr++];
2144 } 2173 }
2145 2174
2175 EntityRef _getNextRef() => unlinkedConst.references[refPtr++];
2176
2146 String _getNextString() { 2177 String _getNextString() {
2147 return unlinkedConst.strings[strPtr++]; 2178 return unlinkedConst.strings[strPtr++];
2148 } 2179 }
2149 2180
2150 List<String> _getNextStrings(int n) { 2181 List<String> _getNextStrings(int n) {
2151 List<String> result = new List<String>(n); 2182 List<String> result = new List<String>(n);
2152 for (int i = 0; i < n; i++) { 2183 for (int i = 0; i < n; i++) {
2153 result[i] = _getNextString(); 2184 result[i] = _getNextString();
2154 } 2185 }
2155 return result; 2186 return result;
2156 } 2187 }
2157 2188
2158 DartType _getNextTypeRef() { 2189 DartType _getNextTypeRef() {
2159 EntityRef ref = unlinkedConst.references[refPtr++]; 2190 EntityRef ref = _getNextRef();
2160 return unit._resolveTypeRef(ref, variable._typeParameterContext); 2191 return unit._resolveTypeRef(ref, variable._typeParameterContext);
2161 } 2192 }
2162 2193
2163 /** 2194 /**
2164 * Return the type of the property with the given [propertyName] in the 2195 * Return the type of the property with the given [propertyName] in the
2165 * given [targetType]. May return `dynamic` if the property cannot be 2196 * given [targetType]. May return `dynamic` if the property cannot be
2166 * resolved. 2197 * resolved.
2167 */ 2198 */
2168 DartType _getPropertyType(DartType targetType, String propertyName) { 2199 DartType _getPropertyType(DartType targetType, String propertyName) {
2169 return targetType is InterfaceType 2200 return targetType is InterfaceType
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 library.unlink(); 3115 library.unlink();
3085 } 3116 }
3086 } 3117 }
3087 } 3118 }
3088 3119
3089 /** 3120 /**
3090 * Element representing a method resynthesized from a summary during linking. 3121 * Element representing a method resynthesized from a summary during linking.
3091 */ 3122 */
3092 class MethodElementForLink extends ExecutableElementForLink 3123 class MethodElementForLink extends ExecutableElementForLink
3093 implements MethodElementImpl { 3124 implements MethodElementImpl {
3094 MethodElementForLink(ClassElementForLink_Class enclosingElement, 3125 MethodElementForLink(ClassElementForLink_Class enclosingClass,
3095 UnlinkedExecutable unlinkedExecutable) 3126 UnlinkedExecutable unlinkedExecutable)
3096 : super(enclosingElement, unlinkedExecutable); 3127 : super(enclosingClass.enclosingElement, enclosingClass,
3128 unlinkedExecutable);
3097 3129
3098 @override 3130 @override
3099 String get identifier => name; 3131 String get identifier => name;
3100 3132
3101 @override 3133 @override
3102 ElementKind get kind => ElementKind.METHOD; 3134 ElementKind get kind => ElementKind.METHOD;
3103 3135
3104 @override 3136 @override
3105 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3137 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3106 3138
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3358 /** 3390 /**
3359 * Specialization of [PropertyAccessorElementForLink] for non-synthetic 3391 * Specialization of [PropertyAccessorElementForLink] for non-synthetic
3360 * accessors explicitly declared in the source code. 3392 * accessors explicitly declared in the source code.
3361 */ 3393 */
3362 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink 3394 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink
3363 implements PropertyAccessorElementForLink { 3395 implements PropertyAccessorElementForLink {
3364 @override 3396 @override
3365 SyntheticVariableElementForLink variable; 3397 SyntheticVariableElementForLink variable;
3366 3398
3367 PropertyAccessorElementForLink_Executable( 3399 PropertyAccessorElementForLink_Executable(
3368 ClassElementForLink_Class enclosingElement, 3400 ClassElementForLink_Class enclosingClass,
3369 UnlinkedExecutable unlinkedExecutable, 3401 UnlinkedExecutable unlinkedExecutable,
3370 this.variable) 3402 this.variable)
3371 : super(enclosingElement, unlinkedExecutable); 3403 : super(enclosingClass.enclosingElement, enclosingClass,
3404 unlinkedExecutable);
3372 3405
3373 @override 3406 @override
3374 PropertyAccessorElementForLink_Executable get correspondingGetter => 3407 PropertyAccessorElementForLink_Executable get correspondingGetter =>
3375 variable.getter; 3408 variable.getter;
3376 3409
3377 @override 3410 @override
3378 bool get isGetter => 3411 bool get isGetter =>
3379 _unlinkedExecutable.kind == UnlinkedExecutableKind.getter; 3412 _unlinkedExecutable.kind == UnlinkedExecutableKind.getter;
3380 3413
3381 @override 3414 @override
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 PropertyAccessorElementForLink_Executable get setter => _setter; 3625 PropertyAccessorElementForLink_Executable get setter => _setter;
3593 3626
3594 @override 3627 @override
3595 void set type(DartType inferredType) {} 3628 void set type(DartType inferredType) {}
3596 3629
3597 @override 3630 @override
3598 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3631 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3599 } 3632 }
3600 3633
3601 /** 3634 /**
3635 * Element representing a top-level function.
3636 */
3637 class TopLevelFunctionElementForLink extends ExecutableElementForLink
3638 implements FunctionElementImpl, ReferenceableElementForLink {
3639 DartType _returnType;
3640
3641 TopLevelFunctionElementForLink(
3642 CompilationUnitElementForLink enclosingUnit, UnlinkedExecutable _buf)
3643 : super(enclosingUnit, null, _buf);
3644
3645 @override
3646 ConstVariableNode get asConstVariable => null;
3647
3648 @override
3649 DartType get asStaticType => type;
3650
3651 @override
3652 TypeInferenceNode get asTypeInferenceNode => null;
3653
3654 @override
3655 ElementKind get kind => ElementKind.FUNCTION;
3656
3657 @override
3658 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3659 }
3660
3661 /**
3602 * Element representing a top level variable resynthesized from a 3662 * Element representing a top level variable resynthesized from a
3603 * summary during linking. 3663 * summary during linking.
3604 */ 3664 */
3605 class TopLevelVariableElementForLink extends VariableElementForLink 3665 class TopLevelVariableElementForLink extends VariableElementForLink
3606 implements TopLevelVariableElement { 3666 implements TopLevelVariableElement {
3607 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement, 3667 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement,
3608 UnlinkedVariable unlinkedVariable) 3668 UnlinkedVariable unlinkedVariable)
3609 : super(unlinkedVariable, enclosingElement); 3669 : super(unlinkedVariable, enclosingElement);
3610 3670
3611 @override 3671 @override
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 if (type is InterfaceType) { 4261 if (type is InterfaceType) {
4202 Element result = type.lookUpGetter(name, compilationUnit.library); 4262 Element result = type.lookUpGetter(name, compilationUnit.library);
4203 result ??= type.lookUpMethod(name, compilationUnit.library); 4263 result ??= type.lookUpMethod(name, compilationUnit.library);
4204 return result; 4264 return result;
4205 } 4265 }
4206 } 4266 }
4207 // TODO(scheglov): implement for propagated types 4267 // TODO(scheglov): implement for propagated types
4208 return null; 4268 return null;
4209 } 4269 }
4210 } 4270 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698