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

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

Issue 2814163002: Revert "Pass ElementImpl as a context for resynthesizing types." (Closed)
Patch Set: Created 3 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
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/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 587 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
588 } 588 }
589 } 589 }
590 590
591 /** 591 /**
592 * Convert the next reference to the [DartType] and return the AST 592 * Convert the next reference to the [DartType] and return the AST
593 * corresponding to this type. 593 * corresponding to this type.
594 */ 594 */
595 TypeAnnotation _newTypeName() { 595 TypeAnnotation _newTypeName() {
596 EntityRef typeRef = uc.references[refPtr++]; 596 EntityRef typeRef = uc.references[refPtr++];
597 DartType type = resynthesizer.buildType(context, typeRef); 597 DartType type =
598 resynthesizer.buildType(typeRef, context?.typeParameterContext);
598 return _buildTypeAst(type); 599 return _buildTypeAst(type);
599 } 600 }
600 601
601 Expression _pop() => stack.removeLast(); 602 Expression _pop() => stack.removeLast();
602 603
603 void _push(Expression expr) { 604 void _push(Expression expr) {
604 stack.add(expr); 605 stack.add(expr);
605 } 606 }
606 607
607 void _pushBinary(TokenType operator) { 608 void _pushBinary(TokenType operator) {
(...skipping 27 matching lines...) Expand all
635 constructorName = null; 636 constructorName = null;
636 } else { 637 } else {
637 List<Expression> arguments = _buildArguments(); 638 List<Expression> arguments = _buildArguments();
638 SimpleIdentifier name = AstTestFactory.identifier3(info.name); 639 SimpleIdentifier name = AstTestFactory.identifier3(info.name);
639 name.staticElement = info.element; 640 name.staticElement = info.element;
640 name.setProperty(ARGUMENT_LIST, AstTestFactory.argumentList(arguments)); 641 name.setProperty(ARGUMENT_LIST, AstTestFactory.argumentList(arguments));
641 _push(name); 642 _push(name);
642 return; 643 return;
643 } 644 }
644 InterfaceType definingType = resynthesizer._createConstructorDefiningType( 645 InterfaceType definingType = resynthesizer._createConstructorDefiningType(
645 context, info, ref.typeArguments); 646 context?.typeParameterContext, info, ref.typeArguments);
646 constructorElement = 647 constructorElement =
647 resynthesizer._getConstructorForInfo(definingType, info); 648 resynthesizer._getConstructorForInfo(definingType, info);
648 typeNode = _buildTypeAst(definingType); 649 typeNode = _buildTypeAst(definingType);
649 } else { 650 } else {
650 if (info.enclosing != null) { 651 if (info.enclosing != null) {
651 if (info.enclosing.enclosing != null) { 652 if (info.enclosing.enclosing != null) {
652 PrefixedIdentifier typeName = AstTestFactory.identifier5( 653 PrefixedIdentifier typeName = AstTestFactory.identifier5(
653 info.enclosing.enclosing.name, info.enclosing.name); 654 info.enclosing.enclosing.name, info.enclosing.name);
654 typeName.prefix.staticElement = info.enclosing.enclosing.element; 655 typeName.prefix.staticElement = info.enclosing.enclosing.element;
655 typeName.identifier.staticElement = info.enclosing.element; 656 typeName.identifier.staticElement = info.enclosing.element;
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 return _unitResynthesizer.parametersInheritingCovariant.contains(slot); 1432 return _unitResynthesizer.parametersInheritingCovariant.contains(slot);
1432 } 1433 }
1433 1434
1434 @override 1435 @override
1435 bool isInConstCycle(int slot) { 1436 bool isInConstCycle(int slot) {
1436 return _unitResynthesizer.constCycles.contains(slot); 1437 return _unitResynthesizer.constCycles.contains(slot);
1437 } 1438 }
1438 1439
1439 @override 1440 @override
1440 ConstructorElement resolveConstructorRef( 1441 ConstructorElement resolveConstructorRef(
1441 ElementImpl context, EntityRef entry) { 1442 TypeParameterizedElementMixin typeParameterContext, EntityRef entry) {
1442 return _unitResynthesizer._getConstructorForEntry(context, entry); 1443 return _unitResynthesizer._getConstructorForEntry(
1444 typeParameterContext, entry);
1443 } 1445 }
1444 1446
1445 @override 1447 @override
1446 DartType resolveLinkedType(ElementImpl context, int slot) { 1448 DartType resolveLinkedType(
1447 return _unitResynthesizer.buildLinkedType(context, slot); 1449 int slot, TypeParameterizedElementMixin typeParameterContext) {
1450 return _unitResynthesizer.buildLinkedType(slot, typeParameterContext);
1448 } 1451 }
1449 1452
1450 @override 1453 @override
1451 DartType resolveTypeRef(ElementImpl context, EntityRef type, 1454 DartType resolveTypeRef(
1455 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
1452 {bool defaultVoid: false, 1456 {bool defaultVoid: false,
1453 bool instantiateToBoundsAllowed: true, 1457 bool instantiateToBoundsAllowed: true,
1454 bool declaredType: false}) { 1458 bool declaredType: false}) {
1455 return _unitResynthesizer.buildType(context, type, 1459 return _unitResynthesizer.buildType(type, typeParameterContext,
1456 defaultVoid: defaultVoid, 1460 defaultVoid: defaultVoid,
1457 instantiateToBoundsAllowed: instantiateToBoundsAllowed, 1461 instantiateToBoundsAllowed: instantiateToBoundsAllowed,
1458 declaredType: declaredType); 1462 declaredType: declaredType);
1459 } 1463 }
1460 } 1464 }
1461 1465
1462 /** 1466 /**
1463 * An instance of [_UnitResynthesizer] is responsible for resynthesizing the 1467 * An instance of [_UnitResynthesizer] is responsible for resynthesizing the
1464 * elements in a single unit from that unit's summary. 1468 * elements in a single unit from that unit's summary.
1465 */ 1469 */
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 PropertyAccessorElementImpl_ImplicitSetter setter = 1618 PropertyAccessorElementImpl_ImplicitSetter setter =
1615 new PropertyAccessorElementImpl_ImplicitSetter(property); 1619 new PropertyAccessorElementImpl_ImplicitSetter(property);
1616 setter.enclosingElement = property.enclosingElement; 1620 setter.enclosingElement = property.enclosingElement;
1617 return setter; 1621 return setter;
1618 } 1622 }
1619 1623
1620 /** 1624 /**
1621 * Build the appropriate [DartType] object corresponding to a slot id in the 1625 * Build the appropriate [DartType] object corresponding to a slot id in the
1622 * [LinkedUnit.types] table. 1626 * [LinkedUnit.types] table.
1623 */ 1627 */
1624 DartType buildLinkedType(ElementImpl context, int slot) { 1628 DartType buildLinkedType(
1629 int slot, TypeParameterizedElementMixin typeParameterContext) {
1625 if (slot == 0) { 1630 if (slot == 0) {
1626 // A slot id of 0 means there is no [DartType] object to build. 1631 // A slot id of 0 means there is no [DartType] object to build.
1627 return null; 1632 return null;
1628 } 1633 }
1629 EntityRef type = linkedTypeMap[slot]; 1634 EntityRef type = linkedTypeMap[slot];
1630 if (type == null) { 1635 if (type == null) {
1631 // A missing entry in [LinkedUnit.types] means there is no [DartType] 1636 // A missing entry in [LinkedUnit.types] means there is no [DartType]
1632 // stored in this slot. 1637 // stored in this slot.
1633 return null; 1638 return null;
1634 } 1639 }
1635 return buildType(context, type); 1640 return buildType(type, typeParameterContext);
1636 } 1641 }
1637 1642
1638 /** 1643 /**
1639 * Build a [DartType] object based on a [EntityRef]. This [DartType] 1644 * Build a [DartType] object based on a [EntityRef]. This [DartType]
1640 * may refer to elements in other libraries than the library being 1645 * may refer to elements in other libraries than the library being
1641 * deserialized, so handles are used to avoid having to deserialize other 1646 * deserialized, so handles are used to avoid having to deserialize other
1642 * libraries in the process. 1647 * libraries in the process.
1643 */ 1648 */
1644 DartType buildType(ElementImpl context, EntityRef type, 1649 DartType buildType(
1650 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
1645 {bool defaultVoid: false, 1651 {bool defaultVoid: false,
1646 bool instantiateToBoundsAllowed: true, 1652 bool instantiateToBoundsAllowed: true,
1647 bool declaredType: false}) { 1653 bool declaredType: false}) {
1648 if (type == null) { 1654 if (type == null) {
1649 if (defaultVoid) { 1655 if (defaultVoid) {
1650 return VoidTypeImpl.instance; 1656 return VoidTypeImpl.instance;
1651 } else { 1657 } else {
1652 return DynamicTypeImpl.instance; 1658 return DynamicTypeImpl.instance;
1653 } 1659 }
1654 } 1660 }
1655 if (type.paramReference != 0) { 1661 if (type.paramReference != 0) {
1656 return context.typeParameterContext 1662 return typeParameterContext.getTypeParameterType(type.paramReference);
1657 .getTypeParameterType(type.paramReference);
1658 } else if (type.entityKind == EntityRefKind.genericFunctionType) { 1663 } else if (type.entityKind == EntityRefKind.genericFunctionType) {
1659 GenericFunctionTypeElement element = 1664 GenericFunctionTypeElement element =
1660 new GenericFunctionTypeElementImpl.forSerialized(context, type); 1665 new GenericFunctionTypeElementImpl.forSerialized(
1666 type, typeParameterContext);
1661 return element.type; 1667 return element.type;
1662 } else if (type.syntheticReturnType != null) { 1668 } else if (type.syntheticReturnType != null) {
1663 FunctionElementImpl element = new FunctionElementImpl_forLUB( 1669 FunctionElementImpl element =
1664 unit, context.typeParameterContext, type); 1670 new FunctionElementImpl_forLUB(unit, typeParameterContext, type);
1665 return element.type; 1671 return element.type;
1666 } else { 1672 } else {
1667 DartType getTypeArgument(int i) { 1673 DartType getTypeArgument(int i) {
1668 if (i < type.typeArguments.length) { 1674 if (i < type.typeArguments.length) {
1669 return buildType(context, type.typeArguments[i], 1675 return buildType(type.typeArguments[i], typeParameterContext,
1670 declaredType: declaredType); 1676 declaredType: declaredType);
1671 } else { 1677 } else {
1672 return DynamicTypeImpl.instance; 1678 return DynamicTypeImpl.instance;
1673 } 1679 }
1674 } 1680 }
1675 1681
1676 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference); 1682 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference);
1677 if (declaredType && !referenceInfo.isDeclarableType) { 1683 if (declaredType && !referenceInfo.isDeclarableType) {
1678 return DynamicTypeImpl.instance; 1684 return DynamicTypeImpl.instance;
1679 } 1685 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1922
1917 Expression _buildConstExpression(ElementImpl context, UnlinkedExpr uc) { 1923 Expression _buildConstExpression(ElementImpl context, UnlinkedExpr uc) {
1918 return new _ConstExprBuilder(this, context, uc).build(); 1924 return new _ConstExprBuilder(this, context, uc).build();
1919 } 1925 }
1920 1926
1921 /** 1927 /**
1922 * Return the defining type for a [ConstructorElement] by applying 1928 * Return the defining type for a [ConstructorElement] by applying
1923 * [typeArgumentRefs] to the given linked [info]. Return [DynamicTypeImpl] 1929 * [typeArgumentRefs] to the given linked [info]. Return [DynamicTypeImpl]
1924 * if the [info] is unresolved. 1930 * if the [info] is unresolved.
1925 */ 1931 */
1926 DartType _createConstructorDefiningType(ElementImpl context, 1932 DartType _createConstructorDefiningType(
1927 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) { 1933 TypeParameterizedElementMixin typeParameterContext,
1934 _ReferenceInfo info,
1935 List<EntityRef> typeArgumentRefs) {
1928 bool isClass = info.element is ClassElement; 1936 bool isClass = info.element is ClassElement;
1929 _ReferenceInfo classInfo = isClass ? info : info.enclosing; 1937 _ReferenceInfo classInfo = isClass ? info : info.enclosing;
1930 if (classInfo == null) { 1938 if (classInfo == null) {
1931 return DynamicTypeImpl.instance; 1939 return DynamicTypeImpl.instance;
1932 } 1940 }
1933 List<DartType> typeArguments = 1941 List<DartType> typeArguments = typeArgumentRefs
1934 typeArgumentRefs.map((t) => buildType(context, t)).toList(); 1942 .map((t) => buildType(t, typeParameterContext))
1943 .toList();
1935 return classInfo.buildType(true, typeArguments.length, (i) { 1944 return classInfo.buildType(true, typeArguments.length, (i) {
1936 if (i < typeArguments.length) { 1945 if (i < typeArguments.length) {
1937 return typeArguments[i]; 1946 return typeArguments[i];
1938 } else { 1947 } else {
1939 return DynamicTypeImpl.instance; 1948 return DynamicTypeImpl.instance;
1940 } 1949 }
1941 }, const <int>[]); 1950 }, const <int>[]);
1942 } 1951 }
1943 1952
1944 /** 1953 /**
1945 * Return the [ConstructorElement] corresponding to the given [entry]. 1954 * Return the [ConstructorElement] corresponding to the given [entry].
1946 */ 1955 */
1947 ConstructorElement _getConstructorForEntry( 1956 ConstructorElement _getConstructorForEntry(
1948 ElementImpl context, EntityRef entry) { 1957 TypeParameterizedElementMixin typeParameterContext, EntityRef entry) {
1949 _ReferenceInfo info = getReferenceInfo(entry.reference); 1958 _ReferenceInfo info = getReferenceInfo(entry.reference);
1950 DartType type = 1959 DartType type = _createConstructorDefiningType(
1951 _createConstructorDefiningType(context, info, entry.typeArguments); 1960 typeParameterContext, info, entry.typeArguments);
1952 if (type is InterfaceType) { 1961 if (type is InterfaceType) {
1953 return _getConstructorForInfo(type, info); 1962 return _getConstructorForInfo(type, info);
1954 } 1963 }
1955 return null; 1964 return null;
1956 } 1965 }
1957 1966
1958 /** 1967 /**
1959 * Return the [ConstructorElement] corresponding to the given linked [info], 1968 * Return the [ConstructorElement] corresponding to the given linked [info],
1960 * using the [classType] which has already been computed (e.g. by 1969 * using the [classType] which has already been computed (e.g. by
1961 * [_createConstructorDefiningType]). Both cases when [info] is a 1970 * [_createConstructorDefiningType]). Both cases when [info] is a
(...skipping 22 matching lines...) Expand all
1984 static String _getElementIdentifier(String name, ReferenceKind kind) { 1993 static String _getElementIdentifier(String name, ReferenceKind kind) {
1985 if (kind == ReferenceKind.topLevelPropertyAccessor || 1994 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1986 kind == ReferenceKind.propertyAccessor) { 1995 kind == ReferenceKind.propertyAccessor) {
1987 if (!name.endsWith('=')) { 1996 if (!name.endsWith('=')) {
1988 return name + '?'; 1997 return name + '?';
1989 } 1998 }
1990 } 1999 }
1991 return name; 2000 return name;
1992 } 2001 }
1993 } 2002 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698