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

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

Issue 1986853003: Move TypeParameterizedElementForLink and TypeParameterElementForLink to impl. (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
OLDNEW
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/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 541 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
542 } 542 }
543 } 543 }
544 544
545 /** 545 /**
546 * Convert the next reference to the [DartType] and return the AST 546 * Convert the next reference to the [DartType] and return the AST
547 * corresponding to this type. 547 * corresponding to this type.
548 */ 548 */
549 TypeName _newTypeName() { 549 TypeName _newTypeName() {
550 EntityRef typeRef = uc.references[refPtr++]; 550 EntityRef typeRef = uc.references[refPtr++];
551 DartType type = resynthesizer.buildType(typeRef); 551 DartType type = resynthesizer.buildType(
552 typeRef, resynthesizer._currentTypeParameterizedElement);
552 return _buildTypeAst(type); 553 return _buildTypeAst(type);
553 } 554 }
554 555
555 Expression _pop() => stack.removeLast(); 556 Expression _pop() => stack.removeLast();
556 557
557 void _push(Expression expr) { 558 void _push(Expression expr) {
558 stack.add(expr); 559 stack.add(expr);
559 } 560 }
560 561
561 void _pushBinary(TokenType operator) { 562 void _pushBinary(TokenType operator) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 List<Expression> _removeTopItems(int count) { 695 List<Expression> _removeTopItems(int count) {
695 int start = stack.length - count; 696 int start = stack.length - count;
696 int end = stack.length; 697 int end = stack.length;
697 List<Expression> items = stack.getRange(start, end).toList(); 698 List<Expression> items = stack.getRange(start, end).toList();
698 stack.removeRange(start, end); 699 stack.removeRange(start, end);
699 return items; 700 return items;
700 } 701 }
701 } 702 }
702 703
703 /** 704 /**
705 * TODO(scheglov) remove after MLI
Paul Berry 2016/05/17 19:28:02 The meaning of "MLI" isn't obvious here either.
scheglov 2016/05/17 19:42:21 Done.
706 * Temporary [TypeParameterizedElementMixin] implementation.
707 */
708 class _CurrentTypeParameterizedElement
709 implements TypeParameterizedElementMixin {
710 final _UnitResynthesizer unitResynthesizer;
711
712 _CurrentTypeParameterizedElement(this.unitResynthesizer);
713
714 @override
715 TypeParameterType getTypeParameterType(int index) {
716 return unitResynthesizer.getTypeParameterFromScope(index);
717 }
718
719 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
720 }
721
722 /**
704 * A class element that has been resynthesized from a summary. The actual 723 * A class element that has been resynthesized from a summary. The actual
705 * element won't be constructed until it is requested. But properties 724 * element won't be constructed until it is requested. But properties
706 * [context], [displayName], [enclosingElement] and [name] can be used without 725 * [context], [displayName], [enclosingElement] and [name] can be used without
707 * creating the actual element. This allows to put these elements into 726 * creating the actual element. This allows to put these elements into
708 * namespaces without creating actual elements until they are really needed. 727 * namespaces without creating actual elements until they are really needed.
709 */ 728 */
710 class _DeferredClassElement extends ClassElementHandle { 729 class _DeferredClassElement extends ClassElementHandle {
711 final _UnitResynthesizer unitResynthesizer; 730 final _UnitResynthesizer unitResynthesizer;
712 final CompilationUnitElement unitElement; 731 final CompilationUnitElement unitElement;
713 final UnlinkedClass serializedClass; 732 final UnlinkedClass serializedClass;
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 if (numTypeArguments != 0) { 1543 if (numTypeArguments != 0) {
1525 typeArguments = <DartType>[]; 1544 typeArguments = <DartType>[];
1526 for (int i = 0; i < numTypeArguments; i++) { 1545 for (int i = 0; i < numTypeArguments; i++) {
1527 typeArguments.add(getTypeArgument(i)); 1546 typeArguments.add(getTypeArgument(i));
1528 } 1547 }
1529 } 1548 }
1530 return typeArguments; 1549 return typeArguments;
1531 } 1550 }
1532 } 1551 }
1533 1552
1553 class _ResynthesizerContext implements ResynthesizerContext {
1554 final _UnitResynthesizer _unitResynthesizer;
1555
1556 _ResynthesizerContext(this._unitResynthesizer);
1557
1558 @override
1559 DartType resolveTypeRef(
1560 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
1561 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) {
1562 return _unitResynthesizer.buildType(type, typeParameterContext,
1563 defaultVoid: defaultVoid,
1564 instantiateToBoundsAllowed: instantiateToBoundsAllowed);
1565 }
1566 }
1567
1534 /** 1568 /**
1535 * An instance of [_UnitResynthesizer] is responsible for resynthesizing the 1569 * An instance of [_UnitResynthesizer] is responsible for resynthesizing the
1536 * elements in a single unit from that unit's summary. 1570 * elements in a single unit from that unit's summary.
1537 */ 1571 */
1538 class _UnitResynthesizer { 1572 class _UnitResynthesizer {
1539 /** 1573 /**
1540 * The [_LibraryResynthesizer] which is being used to obtain summaries. 1574 * The [_LibraryResynthesizer] which is being used to obtain summaries.
1541 */ 1575 */
1542 final _LibraryResynthesizer libraryResynthesizer; 1576 final _LibraryResynthesizer libraryResynthesizer;
1543 1577
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 int numLinkedReferences; 1652 int numLinkedReferences;
1619 int numUnlinkedReferences; 1653 int numUnlinkedReferences;
1620 1654
1621 /** 1655 /**
1622 * List of [_ReferenceInfo] objects describing the references in the current 1656 * List of [_ReferenceInfo] objects describing the references in the current
1623 * compilation unit. This list is works as a lazily filled cache, use 1657 * compilation unit. This list is works as a lazily filled cache, use
1624 * [getReferenceInfo] to get the [_ReferenceInfo] for an index. 1658 * [getReferenceInfo] to get the [_ReferenceInfo] for an index.
1625 */ 1659 */
1626 List<_ReferenceInfo> referenceInfos; 1660 List<_ReferenceInfo> referenceInfos;
1627 1661
1662 /**
1663 * The [ResynthesizerContext] for this resynthesize session.
1664 */
1665 ResynthesizerContext _resynthesizerContext;
1666
1667 /**
1668 * TODO(scheglov) clean up after MLI
Paul Berry 2016/05/17 19:28:02 Ditto
scheglov 2016/05/17 19:42:21 Done.
1669 */
1670 TypeParameterizedElementMixin _currentTypeParameterizedElement;
1671
1628 _UnitResynthesizer(this.libraryResynthesizer, this.unlinkedUnit, 1672 _UnitResynthesizer(this.libraryResynthesizer, this.unlinkedUnit,
1629 this.linkedUnit, this.unit) { 1673 this.linkedUnit, this.unit) {
1630 for (EntityRef t in linkedUnit.types) { 1674 for (EntityRef t in linkedUnit.types) {
1631 linkedTypeMap[t.slot] = t; 1675 linkedTypeMap[t.slot] = t;
1632 } 1676 }
1633 constCycles = linkedUnit.constCycles.toSet(); 1677 constCycles = linkedUnit.constCycles.toSet();
1634 numLinkedReferences = linkedUnit.references.length; 1678 numLinkedReferences = linkedUnit.references.length;
1635 numUnlinkedReferences = unlinkedUnit.references.length; 1679 numUnlinkedReferences = unlinkedUnit.references.length;
1636 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences); 1680 referenceInfos = new List<_ReferenceInfo>(numLinkedReferences);
1681 _resynthesizerContext = new _ResynthesizerContext(this);
1682 _currentTypeParameterizedElement =
1683 new _CurrentTypeParameterizedElement(this);
1637 } 1684 }
1638 1685
1639 SummaryResynthesizer get summaryResynthesizer => 1686 SummaryResynthesizer get summaryResynthesizer =>
1640 libraryResynthesizer.summaryResynthesizer; 1687 libraryResynthesizer.summaryResynthesizer;
1641 1688
1642 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; 1689 TypeProvider get typeProvider => summaryResynthesizer.typeProvider;
1643 1690
1644 /** 1691 /**
1645 * Build the annotations for the given [element]. 1692 * Build the annotations for the given [element].
1646 */ 1693 */
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 assert(currentTypeParameters.isEmpty); 1793 assert(currentTypeParameters.isEmpty);
1747 } 1794 }
1748 1795
1749 /** 1796 /**
1750 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then 1797 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then
1751 * executables are not resynthesized, and [InterfaceTypeImpl] is created 1798 * executables are not resynthesized, and [InterfaceTypeImpl] is created
1752 * around the [handle], so that executables are resynthesized lazily. 1799 * around the [handle], so that executables are resynthesized lazily.
1753 */ 1800 */
1754 ClassElementImpl buildClassImpl( 1801 ClassElementImpl buildClassImpl(
1755 UnlinkedClass serializedClass, ClassElementHandle handle) { 1802 UnlinkedClass serializedClass, ClassElementHandle handle) {
1756 ClassElementImpl classElement = 1803 ClassElementImpl classElement = new ClassElementImpl.forSerialized(
1757 new ClassElementImpl.forSerialized(serializedClass); 1804 _resynthesizerContext, serializedClass);
1758 classElement.hasBeenInferred = summaryResynthesizer.strongMode; 1805 classElement.hasBeenInferred = summaryResynthesizer.strongMode;
1759 classElement.typeParameters =
1760 buildTypeParameters(serializedClass.typeParameters);
1761 classElement.mixinApplication = serializedClass.isMixinApplication; 1806 classElement.mixinApplication = serializedClass.isMixinApplication;
1762 InterfaceTypeImpl correspondingType = 1807 InterfaceTypeImpl correspondingType =
1763 new InterfaceTypeImpl(handle ?? classElement); 1808 new InterfaceTypeImpl(handle ?? classElement);
1764 if (serializedClass.supertype != null) { 1809 if (serializedClass.supertype != null) {
1765 classElement.supertype = buildType(serializedClass.supertype); 1810 classElement.supertype =
1811 buildType(serializedClass.supertype, classElement);
1766 } else if (!libraryResynthesizer.isCoreLibrary) { 1812 } else if (!libraryResynthesizer.isCoreLibrary) {
1767 classElement.supertype = typeProvider.objectType; 1813 classElement.supertype = typeProvider.objectType;
1768 } 1814 }
1769 classElement.interfaces = 1815 classElement.interfaces = serializedClass.interfaces
1770 serializedClass.interfaces.map(buildType).toList(); 1816 .map((EntityRef t) => buildType(t, classElement))
1771 classElement.mixins = serializedClass.mixins.map(buildType).toList(); 1817 .toList();
1772 correspondingType.typeArguments = getCurrentTypeArguments(); 1818 classElement.mixins = serializedClass.mixins
1819 .map((EntityRef t) => buildType(t, classElement))
1820 .toList();
1821 // TODO(scheglov) move to ClassElementImpl
1822 correspondingType.typeArguments = classElement.typeParameterTypes;
1773 classElement.type = correspondingType; 1823 classElement.type = correspondingType;
1774 buildAnnotations(classElement, serializedClass.annotations); 1824 buildAnnotations(classElement, serializedClass.annotations);
1775 currentTypeParameters.removeLast();
1776 assert(currentTypeParameters.isEmpty); 1825 assert(currentTypeParameters.isEmpty);
1777 // TODO(scheglov) Somehow Observatory shows too much time spent here 1826 // TODO(scheglov) Somehow Observatory shows too much time spent here
1778 // during DDC run on the large codebase. I would expect only Object here. 1827 // during DDC run on the large codebase. I would expect only Object here.
1779 if (handle == null) { 1828 if (handle == null) {
1829 if (classElement.name == 'Comparable') {
Paul Berry 2016/05/17 19:28:02 Why do we need special case code for `Comparable`?
scheglov 2016/05/17 19:42:21 I forgot to remove this debug code after fixing th
1830 classElement.getTypeParameterType(1);
1831 }
1780 buildClassExecutables(classElement, serializedClass); 1832 buildClassExecutables(classElement, serializedClass);
1781 } 1833 }
1782 fields = null; 1834 fields = null;
1783 constructors = null; 1835 constructors = null;
1784 return classElement; 1836 return classElement;
1785 } 1837 }
1786 1838
1787 void buildCodeRange(ElementImpl element, CodeRange codeRange) { 1839 void buildCodeRange(ElementImpl element, CodeRange codeRange) {
1788 if (codeRange != null) { 1840 if (codeRange != null) {
1789 element.setCodeRange(codeRange.offset, codeRange.length); 1841 element.setCodeRange(codeRange.offset, codeRange.length);
(...skipping 22 matching lines...) Expand all
1812 } 1864 }
1813 1865
1814 /** 1866 /**
1815 * Resynthesize a [ConstructorElement] and place it in the given [holder]. 1867 * Resynthesize a [ConstructorElement] and place it in the given [holder].
1816 * [classType] is the type of the class for which this element is a 1868 * [classType] is the type of the class for which this element is a
1817 * constructor. 1869 * constructor.
1818 */ 1870 */
1819 void buildConstructor(UnlinkedExecutable serializedExecutable, 1871 void buildConstructor(UnlinkedExecutable serializedExecutable,
1820 ElementHolder holder, InterfaceType classType) { 1872 ElementHolder holder, InterfaceType classType) {
1821 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); 1873 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor);
1822 currentConstructor = 1874 currentConstructor = new ConstructorElementImpl.forSerialized(
1823 new ConstructorElementImpl.forSerialized(serializedExecutable); 1875 _resynthesizerContext, serializedExecutable);
1824 currentConstructor.isCycleFree = serializedExecutable.isConst && 1876 currentConstructor.isCycleFree = serializedExecutable.isConst &&
1825 !constCycles.contains(serializedExecutable.constCycleSlot); 1877 !constCycles.contains(serializedExecutable.constCycleSlot);
1826 if (serializedExecutable.name.isEmpty) { 1878 if (serializedExecutable.name.isEmpty) {
1827 currentConstructor.nameEnd = 1879 currentConstructor.nameEnd =
1828 serializedExecutable.nameOffset + classType.name.length; 1880 serializedExecutable.nameOffset + classType.name.length;
1829 } else { 1881 } else {
1830 currentConstructor.nameEnd = serializedExecutable.nameEnd; 1882 currentConstructor.nameEnd = serializedExecutable.nameEnd;
1831 currentConstructor.periodOffset = serializedExecutable.periodOffset; 1883 currentConstructor.periodOffset = serializedExecutable.periodOffset;
1832 } 1884 }
1833 constructors[serializedExecutable.name] = currentConstructor; 1885 constructors[serializedExecutable.name] = currentConstructor;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 UnlinkedExecutableKind kind = serializedExecutable.kind; 2036 UnlinkedExecutableKind kind = serializedExecutable.kind;
1985 String name = serializedExecutable.name; 2037 String name = serializedExecutable.name;
1986 if (kind == UnlinkedExecutableKind.setter) { 2038 if (kind == UnlinkedExecutableKind.setter) {
1987 assert(name.endsWith('=')); 2039 assert(name.endsWith('='));
1988 name = name.substring(0, name.length - 1); 2040 name = name.substring(0, name.length - 1);
1989 } 2041 }
1990 switch (kind) { 2042 switch (kind) {
1991 case UnlinkedExecutableKind.functionOrMethod: 2043 case UnlinkedExecutableKind.functionOrMethod:
1992 if (isTopLevel) { 2044 if (isTopLevel) {
1993 FunctionElementImpl executableElement = 2045 FunctionElementImpl executableElement =
1994 new FunctionElementImpl.forSerialized(serializedExecutable); 2046 new FunctionElementImpl.forSerialized(
2047 _resynthesizerContext, serializedExecutable);
1995 buildExecutableCommonParts(executableElement, serializedExecutable); 2048 buildExecutableCommonParts(executableElement, serializedExecutable);
1996 holder.addFunction(executableElement); 2049 holder.addFunction(executableElement);
1997 } else { 2050 } else {
1998 MethodElementImpl executableElement = 2051 MethodElementImpl executableElement =
1999 new MethodElementImpl.forSerialized(serializedExecutable); 2052 new MethodElementImpl.forSerialized(
2053 _resynthesizerContext, serializedExecutable);
2000 buildExecutableCommonParts(executableElement, serializedExecutable); 2054 buildExecutableCommonParts(executableElement, serializedExecutable);
2001 holder.addMethod(executableElement); 2055 holder.addMethod(executableElement);
2002 } 2056 }
2003 break; 2057 break;
2004 case UnlinkedExecutableKind.getter: 2058 case UnlinkedExecutableKind.getter:
2005 case UnlinkedExecutableKind.setter: 2059 case UnlinkedExecutableKind.setter:
2006 PropertyAccessorElementImpl executableElement = 2060 PropertyAccessorElementImpl executableElement =
2007 new PropertyAccessorElementImpl.forSerialized(serializedExecutable); 2061 new PropertyAccessorElementImpl.forSerialized(
2062 _resynthesizerContext, serializedExecutable);
2008 buildExecutableCommonParts(executableElement, serializedExecutable); 2063 buildExecutableCommonParts(executableElement, serializedExecutable);
2009 DartType type; 2064 DartType type;
2010 if (kind == UnlinkedExecutableKind.getter) { 2065 if (kind == UnlinkedExecutableKind.getter) {
2011 type = executableElement.returnType; 2066 type = executableElement.returnType;
2012 } else { 2067 } else {
2013 type = executableElement.parameters[0].type; 2068 type = executableElement.parameters[0].type;
2014 } 2069 }
2015 holder.addAccessor(executableElement); 2070 holder.addAccessor(executableElement);
2016 PropertyInducingElementImpl implicitVariable; 2071 PropertyInducingElementImpl implicitVariable;
2017 if (isTopLevel) { 2072 if (isTopLevel) {
(...skipping 27 matching lines...) Expand all
2045 executableElement.typeParameters = 2100 executableElement.typeParameters =
2046 buildTypeParameters(serializedExecutable.typeParameters); 2101 buildTypeParameters(serializedExecutable.typeParameters);
2047 executableElement.parameters = 2102 executableElement.parameters =
2048 serializedExecutable.parameters.map(buildParameter).toList(); 2103 serializedExecutable.parameters.map(buildParameter).toList();
2049 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) { 2104 if (serializedExecutable.kind == UnlinkedExecutableKind.constructor) {
2050 // Caller handles setting the return type. 2105 // Caller handles setting the return type.
2051 assert(serializedExecutable.returnType == null); 2106 assert(serializedExecutable.returnType == null);
2052 } else { 2107 } else {
2053 bool isSetter = 2108 bool isSetter =
2054 serializedExecutable.kind == UnlinkedExecutableKind.setter; 2109 serializedExecutable.kind == UnlinkedExecutableKind.setter;
2055 executableElement.returnType = 2110 executableElement.returnType = buildLinkedType(
2056 buildLinkedType(serializedExecutable.inferredReturnTypeSlot) ?? 2111 serializedExecutable.inferredReturnTypeSlot,
2057 buildType(serializedExecutable.returnType, 2112 _currentTypeParameterizedElement) ??
2058 defaultVoid: isSetter && summaryResynthesizer.strongMode); 2113 buildType(
2114 serializedExecutable.returnType, _currentTypeParameterizedElement,
2115 defaultVoid: isSetter && summaryResynthesizer.strongMode);
2059 executableElement.hasImplicitReturnType = 2116 executableElement.hasImplicitReturnType =
2060 serializedExecutable.returnType == null; 2117 serializedExecutable.returnType == null;
2061 } 2118 }
2062 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 2119 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
2063 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); 2120 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false);
2064 buildAnnotations(executableElement, serializedExecutable.annotations); 2121 buildAnnotations(executableElement, serializedExecutable.annotations);
2065 executableElement.functions = 2122 executableElement.functions =
2066 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); 2123 serializedExecutable.localFunctions.map(buildLocalFunction).toList();
2067 executableElement.labels = 2124 executableElement.labels =
2068 serializedExecutable.localLabels.map(buildLocalLabel).toList(); 2125 serializedExecutable.localLabels.map(buildLocalLabel).toList();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 // TODO(paulberry): what if the getter and setter have a type mismatch? 2205 // TODO(paulberry): what if the getter and setter have a type mismatch?
2149 variable.final2 = false; 2206 variable.final2 = false;
2150 return variable; 2207 return variable;
2151 } 2208 }
2152 } 2209 }
2153 2210
2154 /** 2211 /**
2155 * Build the appropriate [DartType] object corresponding to a slot id in the 2212 * Build the appropriate [DartType] object corresponding to a slot id in the
2156 * [LinkedUnit.types] table. 2213 * [LinkedUnit.types] table.
2157 */ 2214 */
2158 DartType buildLinkedType(int slot) { 2215 DartType buildLinkedType(
2216 int slot, TypeParameterizedElementMixin typeParameterContext) {
2159 if (slot == 0) { 2217 if (slot == 0) {
2160 // A slot id of 0 means there is no [DartType] object to build. 2218 // A slot id of 0 means there is no [DartType] object to build.
2161 return null; 2219 return null;
2162 } 2220 }
2163 EntityRef type = linkedTypeMap[slot]; 2221 EntityRef type = linkedTypeMap[slot];
2164 if (type == null) { 2222 if (type == null) {
2165 // A missing entry in [LinkedUnit.types] means there is no [DartType] 2223 // A missing entry in [LinkedUnit.types] means there is no [DartType]
2166 // stored in this slot. 2224 // stored in this slot.
2167 return null; 2225 return null;
2168 } 2226 }
2169 return buildType(type); 2227 return buildType(type, typeParameterContext);
2170 } 2228 }
2171 2229
2172 /** 2230 /**
2173 * Resynthesize a local [FunctionElement]. 2231 * Resynthesize a local [FunctionElement].
2174 */ 2232 */
2175 FunctionElementImpl buildLocalFunction( 2233 FunctionElementImpl buildLocalFunction(
2176 UnlinkedExecutable serializedExecutable) { 2234 UnlinkedExecutable serializedExecutable) {
2177 FunctionElementImpl element = 2235 FunctionElementImpl element = new FunctionElementImpl.forSerialized(
2178 new FunctionElementImpl.forSerialized(serializedExecutable); 2236 _resynthesizerContext, serializedExecutable);
2179 if (serializedExecutable.visibleOffset != 0) { 2237 if (serializedExecutable.visibleOffset != 0) {
2180 element.setVisibleRange(serializedExecutable.visibleOffset, 2238 element.setVisibleRange(serializedExecutable.visibleOffset,
2181 serializedExecutable.visibleLength); 2239 serializedExecutable.visibleLength);
2182 } 2240 }
2183 buildExecutableCommonParts(element, serializedExecutable); 2241 buildExecutableCommonParts(element, serializedExecutable);
2184 return element; 2242 return element;
2185 } 2243 }
2186 2244
2187 /** 2245 /**
2188 * Resynthesize a [LabelElement]. 2246 * Resynthesize a [LabelElement].
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 List<ParameterElement> subParameters = serializedParameter.parameters 2330 List<ParameterElement> subParameters = serializedParameter.parameters
2273 .map((UnlinkedParam p) => buildParameter(p, synthetic: synthetic)) 2331 .map((UnlinkedParam p) => buildParameter(p, synthetic: synthetic))
2274 .toList(); 2332 .toList();
2275 if (synthetic) { 2333 if (synthetic) {
2276 parameterTypeElement.parameters = subParameters; 2334 parameterTypeElement.parameters = subParameters;
2277 } else { 2335 } else {
2278 parameterElement.parameters = subParameters; 2336 parameterElement.parameters = subParameters;
2279 parameterTypeElement.shareParameters(subParameters); 2337 parameterTypeElement.shareParameters(subParameters);
2280 parameterTypeElement.enclosingElement = parameterElement; 2338 parameterTypeElement.enclosingElement = parameterElement;
2281 } 2339 }
2282 parameterTypeElement.returnType = buildType(serializedParameter.type); 2340 parameterTypeElement.returnType =
2341 buildType(serializedParameter.type, _currentTypeParameterizedElement);
2283 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 2342 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
2284 parameterTypeElement, null, getCurrentTypeArguments(), false); 2343 parameterTypeElement, null, getCurrentTypeArguments(), false);
2285 parameterTypeElement.type = parameterElement.type; 2344 parameterTypeElement.type = parameterElement.type;
2286 } else { 2345 } else {
2287 if (serializedParameter.isInitializingFormal && 2346 if (serializedParameter.isInitializingFormal &&
2288 serializedParameter.type == null) { 2347 serializedParameter.type == null) {
2289 // The type is inherited from the matching field. 2348 // The type is inherited from the matching field.
2290 parameterElement.type = 2349 parameterElement.type =
2291 fields[serializedParameter.name]?.type ?? DynamicTypeImpl.instance; 2350 fields[serializedParameter.name]?.type ?? DynamicTypeImpl.instance;
2292 } else { 2351 } else {
2293 parameterElement.type = 2352 parameterElement.type = buildLinkedType(
2294 buildLinkedType(serializedParameter.inferredTypeSlot) ?? 2353 serializedParameter.inferredTypeSlot,
2295 buildType(serializedParameter.type); 2354 _currentTypeParameterizedElement) ??
2355 buildType(
2356 serializedParameter.type, _currentTypeParameterizedElement);
2296 } 2357 }
2297 parameterElement.hasImplicitType = serializedParameter.type == null; 2358 parameterElement.hasImplicitType = serializedParameter.type == null;
2298 } 2359 }
2299 buildVariableInitializer(parameterElement, serializedParameter.initializer); 2360 buildVariableInitializer(parameterElement, serializedParameter.initializer);
2300 switch (serializedParameter.kind) { 2361 switch (serializedParameter.kind) {
2301 case UnlinkedParamKind.named: 2362 case UnlinkedParamKind.named:
2302 parameterElement.parameterKind = ParameterKind.NAMED; 2363 parameterElement.parameterKind = ParameterKind.NAMED;
2303 break; 2364 break;
2304 case UnlinkedParamKind.positional: 2365 case UnlinkedParamKind.positional:
2305 parameterElement.parameterKind = ParameterKind.POSITIONAL; 2366 parameterElement.parameterKind = ParameterKind.POSITIONAL;
2306 break; 2367 break;
2307 case UnlinkedParamKind.required: 2368 case UnlinkedParamKind.required:
2308 parameterElement.parameterKind = ParameterKind.REQUIRED; 2369 parameterElement.parameterKind = ParameterKind.REQUIRED;
2309 break; 2370 break;
2310 } 2371 }
2311 if (serializedParameter.visibleOffset != 0) { 2372 if (serializedParameter.visibleOffset != 0) {
2312 parameterElement.setVisibleRange( 2373 parameterElement.setVisibleRange(
2313 serializedParameter.visibleOffset, serializedParameter.visibleLength); 2374 serializedParameter.visibleOffset, serializedParameter.visibleLength);
2314 } 2375 }
2315 return parameterElement; 2376 return parameterElement;
2316 } 2377 }
2317 2378
2318 /** 2379 /**
2319 * Handle the parts that are common to top level variables and fields. 2380 * Handle the parts that are common to top level variables and fields.
2320 */ 2381 */
2321 void buildPropertyIntroducingElementCommonParts( 2382 void buildPropertyIntroducingElementCommonParts(
2322 PropertyInducingElementImpl element, 2383 PropertyInducingElementImpl element,
2323 UnlinkedVariable serializedVariable) { 2384 UnlinkedVariable serializedVariable) {
2324 buildVariableCommonParts(element, serializedVariable); 2385 buildVariableCommonParts(element, serializedVariable);
2325 element.propagatedType = 2386 element.propagatedType = buildLinkedType(
2326 buildLinkedType(serializedVariable.propagatedTypeSlot); 2387 serializedVariable.propagatedTypeSlot,
2388 _currentTypeParameterizedElement);
2327 } 2389 }
2328 2390
2329 /** 2391 /**
2330 * Build a [DartType] object based on a [EntityRef]. This [DartType] 2392 * Build a [DartType] object based on a [EntityRef]. This [DartType]
2331 * may refer to elements in other libraries than the library being 2393 * may refer to elements in other libraries than the library being
2332 * deserialized, so handles are used to avoid having to deserialize other 2394 * deserialized, so handles are used to avoid having to deserialize other
2333 * libraries in the process. 2395 * libraries in the process.
2334 */ 2396 */
2335 DartType buildType(EntityRef type, 2397 DartType buildType(
2398 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
2336 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) { 2399 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) {
2337 if (type == null) { 2400 if (type == null) {
2338 if (defaultVoid) { 2401 if (defaultVoid) {
2339 return VoidTypeImpl.instance; 2402 return VoidTypeImpl.instance;
2340 } else { 2403 } else {
2341 return DynamicTypeImpl.instance; 2404 return DynamicTypeImpl.instance;
2342 } 2405 }
2343 } 2406 }
2344 if (type.paramReference != 0) { 2407 if (type.paramReference != 0) {
2345 return getTypeParameterFromScope(type.paramReference); 2408 return typeParameterContext.getTypeParameterType(type.paramReference);
2346 } else if (type.syntheticReturnType != null) { 2409 } else if (type.syntheticReturnType != null) {
2347 FunctionElementImpl element = new FunctionElementImpl('', -1); 2410 FunctionElementImpl element = new FunctionElementImpl('', -1);
2348 element.synthetic = true; 2411 element.synthetic = true;
2349 element.parameters = type.syntheticParams 2412 element.parameters = type.syntheticParams
2350 .map((UnlinkedParam param) => buildParameter(param, synthetic: true)) 2413 .map((UnlinkedParam param) => buildParameter(param, synthetic: true))
2351 .toList(); 2414 .toList();
2352 element.returnType = buildType(type.syntheticReturnType); 2415 element.returnType =
2416 buildType(type.syntheticReturnType, typeParameterContext);
2353 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs( 2417 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs(
2354 element, null, null, false); 2418 element, null, null, false);
2355 element.type = result; 2419 element.type = result;
2356 return result; 2420 return result;
2357 } else { 2421 } else {
2358 DartType getTypeArgument(int i) { 2422 DartType getTypeArgument(int i) {
2359 if (i < type.typeArguments.length) { 2423 if (i < type.typeArguments.length) {
2360 return buildType(type.typeArguments[i]); 2424 return buildType(type.typeArguments[i], typeParameterContext);
2361 } else { 2425 } else {
2362 return DynamicTypeImpl.instance; 2426 return DynamicTypeImpl.instance;
2363 } 2427 }
2364 } 2428 }
2365 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference); 2429 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference);
2366 return referenceInfo.buildType( 2430 return referenceInfo.buildType(
2367 instantiateToBoundsAllowed, 2431 instantiateToBoundsAllowed,
2368 type.typeArguments.length, 2432 type.typeArguments.length,
2369 getTypeArgument, 2433 getTypeArgument,
2370 type.implicitFunctionTypeIndices); 2434 type.implicitFunctionTypeIndices);
2371 } 2435 }
2372 } 2436 }
2373 2437
2374 /** 2438 /**
2375 * Resynthesize a [FunctionTypeAliasElement] and place it in the 2439 * Resynthesize a [FunctionTypeAliasElement] and place it in the
2376 * [unitHolder]. 2440 * [unitHolder].
2377 */ 2441 */
2378 void buildTypedef(UnlinkedTypedef serializedTypedef) { 2442 void buildTypedef(UnlinkedTypedef serializedTypedef) {
2379 FunctionTypeAliasElementImpl functionTypeAliasElement = 2443 FunctionTypeAliasElementImpl functionTypeAliasElement =
2380 new FunctionTypeAliasElementImpl.forSerialized(serializedTypedef); 2444 new FunctionTypeAliasElementImpl.forSerialized(
2445 _resynthesizerContext, serializedTypedef);
2381 functionTypeAliasElement.typeParameters = 2446 functionTypeAliasElement.typeParameters =
2382 buildTypeParameters(serializedTypedef.typeParameters); 2447 buildTypeParameters(serializedTypedef.typeParameters);
2383 functionTypeAliasElement.parameters = 2448 functionTypeAliasElement.parameters =
2384 serializedTypedef.parameters.map(buildParameter).toList(); 2449 serializedTypedef.parameters.map(buildParameter).toList();
2385 functionTypeAliasElement.returnType = 2450 functionTypeAliasElement.returnType = buildType(
2386 buildType(serializedTypedef.returnType); 2451 serializedTypedef.returnType, _currentTypeParameterizedElement);
2387 functionTypeAliasElement.type = 2452 functionTypeAliasElement.type =
2388 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); 2453 new FunctionTypeImpl.forTypedef(functionTypeAliasElement);
2389 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); 2454 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations);
2390 unitHolder.addTypeAlias(functionTypeAliasElement); 2455 unitHolder.addTypeAlias(functionTypeAliasElement);
2391 currentTypeParameters.removeLast(); 2456 currentTypeParameters.removeLast();
2392 assert(currentTypeParameters.isEmpty); 2457 assert(currentTypeParameters.isEmpty);
2393 } 2458 }
2394 2459
2395 /** 2460 /**
2396 * Resynthesize a [TypeParameterElement], handling all parts of its except 2461 * Resynthesize a [TypeParameterElement], handling all parts of its except
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 buildImplicitAccessors(element, holder); 2533 buildImplicitAccessors(element, holder);
2469 fields[element.name] = element; 2534 fields[element.name] = element;
2470 } 2535 }
2471 } 2536 }
2472 2537
2473 /** 2538 /**
2474 * Handle the parts that are common to variables. 2539 * Handle the parts that are common to variables.
2475 */ 2540 */
2476 void buildVariableCommonParts( 2541 void buildVariableCommonParts(
2477 VariableElementImpl element, UnlinkedVariable serializedVariable) { 2542 VariableElementImpl element, UnlinkedVariable serializedVariable) {
2478 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? 2543 element.type = buildLinkedType(serializedVariable.inferredTypeSlot,
2479 buildType(serializedVariable.type); 2544 _currentTypeParameterizedElement) ??
2545 buildType(serializedVariable.type, _currentTypeParameterizedElement);
2480 element.const3 = serializedVariable.isConst; 2546 element.const3 = serializedVariable.isConst;
2481 element.final2 = serializedVariable.isFinal; 2547 element.final2 = serializedVariable.isFinal;
2482 element.hasImplicitType = serializedVariable.type == null; 2548 element.hasImplicitType = serializedVariable.type == null;
2483 buildVariableInitializer(element, serializedVariable.initializer); 2549 buildVariableInitializer(element, serializedVariable.initializer);
2484 buildDocumentation(element, serializedVariable.documentationComment); 2550 buildDocumentation(element, serializedVariable.documentationComment);
2485 buildAnnotations(element, serializedVariable.annotations); 2551 buildAnnotations(element, serializedVariable.annotations);
2486 buildCodeRange(element, serializedVariable.codeRange); 2552 buildCodeRange(element, serializedVariable.codeRange);
2487 } 2553 }
2488 2554
2489 /** 2555 /**
(...skipping 10 matching lines...) Expand all
2500 initializerElement.synthetic = true; 2566 initializerElement.synthetic = true;
2501 variable.initializer = initializerElement; 2567 variable.initializer = initializerElement;
2502 } 2568 }
2503 2569
2504 /** 2570 /**
2505 * Finish creating a [TypeParameterElement] by deserializing its bound. 2571 * Finish creating a [TypeParameterElement] by deserializing its bound.
2506 */ 2572 */
2507 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 2573 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
2508 TypeParameterElementImpl typeParameterElement) { 2574 TypeParameterElementImpl typeParameterElement) {
2509 if (serializedTypeParameter.bound != null) { 2575 if (serializedTypeParameter.bound != null) {
2510 typeParameterElement.bound = buildType(serializedTypeParameter.bound, 2576 typeParameterElement.bound = buildType(
2577 serializedTypeParameter.bound, _currentTypeParameterizedElement,
2511 instantiateToBoundsAllowed: false); 2578 instantiateToBoundsAllowed: false);
2512 } 2579 }
2513 } 2580 }
2514 2581
2515 /** 2582 /**
2516 * Return a list of type arguments corresponding to [currentTypeParameters], 2583 * Return a list of type arguments corresponding to [currentTypeParameters],
2517 * skipping the innermost [skipLevels] nesting levels. 2584 * skipping the innermost [skipLevels] nesting levels.
2518 * 2585 *
2519 * Type parameters are listed in nesting order from innermost to outermost, 2586 * Type parameters are listed in nesting order from innermost to outermost,
2520 * and then in declaration order. So for instance if we are resynthesizing a 2587 * and then in declaration order. So for instance if we are resynthesizing a
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2739 } 2806 }
2740 2807
2741 /** 2808 /**
2742 * Return the defining type for a [ConstructorElement] by applying 2809 * Return the defining type for a [ConstructorElement] by applying
2743 * [typeArgumentRefs] to the given linked [info]. 2810 * [typeArgumentRefs] to the given linked [info].
2744 */ 2811 */
2745 InterfaceType _createConstructorDefiningType( 2812 InterfaceType _createConstructorDefiningType(
2746 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) { 2813 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) {
2747 bool isClass = info.element is ClassElement; 2814 bool isClass = info.element is ClassElement;
2748 _ReferenceInfo classInfo = isClass ? info : info.enclosing; 2815 _ReferenceInfo classInfo = isClass ? info : info.enclosing;
2749 List<DartType> typeArguments = typeArgumentRefs.map(buildType).toList(); 2816 List<DartType> typeArguments = typeArgumentRefs
2817 .map((t) => buildType(t, _currentTypeParameterizedElement))
2818 .toList();
2750 return classInfo.buildType(true, typeArguments.length, (i) { 2819 return classInfo.buildType(true, typeArguments.length, (i) {
2751 if (i < typeArguments.length) { 2820 if (i < typeArguments.length) {
2752 return typeArguments[i]; 2821 return typeArguments[i];
2753 } else { 2822 } else {
2754 return DynamicTypeImpl.instance; 2823 return DynamicTypeImpl.instance;
2755 } 2824 }
2756 }, const <int>[]); 2825 }, const <int>[]);
2757 } 2826 }
2758 2827
2759 /** 2828 /**
(...skipping 23 matching lines...) Expand all
2783 static String _getElementIdentifier(String name, ReferenceKind kind) { 2852 static String _getElementIdentifier(String name, ReferenceKind kind) {
2784 if (kind == ReferenceKind.topLevelPropertyAccessor || 2853 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2785 kind == ReferenceKind.propertyAccessor) { 2854 kind == ReferenceKind.propertyAccessor) {
2786 if (!name.endsWith('=')) { 2855 if (!name.endsWith('=')) {
2787 return name + '?'; 2856 return name + '?';
2788 } 2857 }
2789 } 2858 }
2790 return name; 2859 return name;
2791 } 2860 }
2792 } 2861 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698