Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 return typeArguments; | 1550 return typeArguments; |
| 1551 } | 1551 } |
| 1552 } | 1552 } |
| 1553 | 1553 |
| 1554 class _ResynthesizerContext implements ResynthesizerContext { | 1554 class _ResynthesizerContext implements ResynthesizerContext { |
| 1555 final _UnitResynthesizer _unitResynthesizer; | 1555 final _UnitResynthesizer _unitResynthesizer; |
| 1556 | 1556 |
| 1557 _ResynthesizerContext(this._unitResynthesizer); | 1557 _ResynthesizerContext(this._unitResynthesizer); |
| 1558 | 1558 |
| 1559 @override | 1559 @override |
| 1560 ElementAnnotationImpl buildAnnotation(UnlinkedConst uc) { | |
| 1561 ElementAnnotationImpl elementAnnotation = | |
| 1562 new ElementAnnotationImpl(_unitResynthesizer.unit); | |
| 1563 Expression constExpr = _unitResynthesizer._buildConstExpression(uc); | |
| 1564 if (constExpr is Identifier) { | |
| 1565 elementAnnotation.element = constExpr.staticElement; | |
| 1566 elementAnnotation.annotationAst = AstFactory.annotation(constExpr); | |
| 1567 } else if (constExpr is InstanceCreationExpression) { | |
| 1568 elementAnnotation.element = constExpr.staticElement; | |
| 1569 Identifier typeName = constExpr.constructorName.type.name; | |
| 1570 SimpleIdentifier constructorName = constExpr.constructorName.name; | |
| 1571 if (typeName is SimpleIdentifier && constructorName != null) { | |
| 1572 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as | |
| 1573 // a PrefixedIdentifier, we need to resynthesize it as one. | |
| 1574 typeName = AstFactory.identifier(typeName, constructorName); | |
| 1575 constructorName = null; | |
| 1576 } | |
| 1577 elementAnnotation.annotationAst = AstFactory.annotation2( | |
| 1578 typeName, constructorName, constExpr.argumentList); | |
| 1579 } else { | |
| 1580 throw new StateError( | |
| 1581 'Unexpected annotation type: ${constExpr.runtimeType}'); | |
| 1582 } | |
| 1583 return elementAnnotation; | |
| 1584 } | |
| 1585 | |
| 1586 @override | |
| 1560 DartType resolveTypeRef( | 1587 DartType resolveTypeRef( |
| 1561 EntityRef type, TypeParameterizedElementMixin typeParameterContext, | 1588 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 1562 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) { | 1589 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) { |
| 1563 return _unitResynthesizer.buildType(type, typeParameterContext, | 1590 return _unitResynthesizer.buildType(type, typeParameterContext, |
| 1564 defaultVoid: defaultVoid, | 1591 defaultVoid: defaultVoid, |
| 1565 instantiateToBoundsAllowed: instantiateToBoundsAllowed); | 1592 instantiateToBoundsAllowed: instantiateToBoundsAllowed); |
| 1566 } | 1593 } |
| 1567 } | 1594 } |
| 1568 | 1595 |
| 1569 /** | 1596 /** |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1689 | 1716 |
| 1690 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; | 1717 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; |
| 1691 | 1718 |
| 1692 /** | 1719 /** |
| 1693 * Build the annotations for the given [element]. | 1720 * Build the annotations for the given [element]. |
| 1694 */ | 1721 */ |
| 1695 void buildAnnotations( | 1722 void buildAnnotations( |
| 1696 ElementImpl element, List<UnlinkedConst> serializedAnnotations) { | 1723 ElementImpl element, List<UnlinkedConst> serializedAnnotations) { |
| 1697 if (serializedAnnotations.isNotEmpty) { | 1724 if (serializedAnnotations.isNotEmpty) { |
| 1698 element.metadata = serializedAnnotations.map((UnlinkedConst a) { | 1725 element.metadata = serializedAnnotations.map((UnlinkedConst a) { |
| 1699 ElementAnnotationImpl elementAnnotation = | 1726 ElementAnnotationImpl elementAnnotation = |
|
Paul Berry
2016/05/17 20:45:33
It looks like this code has been extracted to _Res
scheglov
2016/05/17 21:17:41
Oh, yes, of course!
Thank you for catching this.
| |
| 1700 new ElementAnnotationImpl(this.unit); | 1727 new ElementAnnotationImpl(this.unit); |
| 1701 Expression constExpr = _buildConstExpression(a); | 1728 Expression constExpr = _buildConstExpression(a); |
| 1702 if (constExpr is Identifier) { | 1729 if (constExpr is Identifier) { |
| 1703 elementAnnotation.element = constExpr.staticElement; | 1730 elementAnnotation.element = constExpr.staticElement; |
| 1704 elementAnnotation.annotationAst = AstFactory.annotation(constExpr); | 1731 elementAnnotation.annotationAst = AstFactory.annotation(constExpr); |
| 1705 } else if (constExpr is InstanceCreationExpression) { | 1732 } else if (constExpr is InstanceCreationExpression) { |
| 1706 elementAnnotation.element = constExpr.staticElement; | 1733 elementAnnotation.element = constExpr.staticElement; |
| 1707 Identifier typeName = constExpr.constructorName.type.name; | 1734 Identifier typeName = constExpr.constructorName.type.name; |
| 1708 SimpleIdentifier constructorName = constExpr.constructorName.name; | 1735 SimpleIdentifier constructorName = constExpr.constructorName.name; |
| 1709 if (typeName is SimpleIdentifier && constructorName != null) { | 1736 if (typeName is SimpleIdentifier && constructorName != null) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1815 } | 1842 } |
| 1816 classElement.interfaces = serializedClass.interfaces | 1843 classElement.interfaces = serializedClass.interfaces |
| 1817 .map((EntityRef t) => buildType(t, classElement)) | 1844 .map((EntityRef t) => buildType(t, classElement)) |
| 1818 .toList(); | 1845 .toList(); |
| 1819 classElement.mixins = serializedClass.mixins | 1846 classElement.mixins = serializedClass.mixins |
| 1820 .map((EntityRef t) => buildType(t, classElement)) | 1847 .map((EntityRef t) => buildType(t, classElement)) |
| 1821 .toList(); | 1848 .toList(); |
| 1822 // TODO(scheglov) move to ClassElementImpl | 1849 // TODO(scheglov) move to ClassElementImpl |
| 1823 correspondingType.typeArguments = classElement.typeParameterTypes; | 1850 correspondingType.typeArguments = classElement.typeParameterTypes; |
| 1824 classElement.type = correspondingType; | 1851 classElement.type = correspondingType; |
| 1825 buildAnnotations(classElement, serializedClass.annotations); | |
| 1826 assert(currentTypeParameters.isEmpty); | 1852 assert(currentTypeParameters.isEmpty); |
| 1827 // TODO(scheglov) Somehow Observatory shows too much time spent here | 1853 // TODO(scheglov) Somehow Observatory shows too much time spent here |
| 1828 // during DDC run on the large codebase. I would expect only Object here. | 1854 // during DDC run on the large codebase. I would expect only Object here. |
| 1829 if (handle == null) { | 1855 if (handle == null) { |
| 1830 buildClassExecutables(classElement, serializedClass); | 1856 buildClassExecutables(classElement, serializedClass); |
| 1831 } | 1857 } |
| 1832 fields = null; | 1858 fields = null; |
| 1833 constructors = null; | 1859 constructors = null; |
| 1834 return classElement; | 1860 return classElement; |
| 1835 } | 1861 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2109 serializedExecutable.inferredReturnTypeSlot, | 2135 serializedExecutable.inferredReturnTypeSlot, |
| 2110 _currentTypeParameterizedElement) ?? | 2136 _currentTypeParameterizedElement) ?? |
| 2111 buildType( | 2137 buildType( |
| 2112 serializedExecutable.returnType, _currentTypeParameterizedElement, | 2138 serializedExecutable.returnType, _currentTypeParameterizedElement, |
| 2113 defaultVoid: isSetter && summaryResynthesizer.strongMode); | 2139 defaultVoid: isSetter && summaryResynthesizer.strongMode); |
| 2114 executableElement.hasImplicitReturnType = | 2140 executableElement.hasImplicitReturnType = |
| 2115 serializedExecutable.returnType == null; | 2141 serializedExecutable.returnType == null; |
| 2116 } | 2142 } |
| 2117 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 2143 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 2118 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); | 2144 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); |
| 2119 buildAnnotations(executableElement, serializedExecutable.annotations); | |
| 2120 executableElement.functions = | 2145 executableElement.functions = |
| 2121 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); | 2146 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); |
| 2122 executableElement.labels = | 2147 executableElement.labels = |
| 2123 serializedExecutable.localLabels.map(buildLocalLabel).toList(); | 2148 serializedExecutable.localLabels.map(buildLocalLabel).toList(); |
| 2124 executableElement.localVariables = | 2149 executableElement.localVariables = |
| 2125 serializedExecutable.localVariables.map(buildLocalVariable).toList(); | 2150 serializedExecutable.localVariables.map(buildLocalVariable).toList(); |
| 2126 currentTypeParameters.removeLast(); | 2151 currentTypeParameters.removeLast(); |
| 2127 } | 2152 } |
| 2128 | 2153 |
| 2129 /** | 2154 /** |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2442 new FunctionTypeAliasElementImpl.forSerialized( | 2467 new FunctionTypeAliasElementImpl.forSerialized( |
| 2443 _resynthesizerContext, serializedTypedef); | 2468 _resynthesizerContext, serializedTypedef); |
| 2444 functionTypeAliasElement.typeParameters = | 2469 functionTypeAliasElement.typeParameters = |
| 2445 buildTypeParameters(serializedTypedef.typeParameters); | 2470 buildTypeParameters(serializedTypedef.typeParameters); |
| 2446 functionTypeAliasElement.parameters = | 2471 functionTypeAliasElement.parameters = |
| 2447 serializedTypedef.parameters.map(buildParameter).toList(); | 2472 serializedTypedef.parameters.map(buildParameter).toList(); |
| 2448 functionTypeAliasElement.returnType = buildType( | 2473 functionTypeAliasElement.returnType = buildType( |
| 2449 serializedTypedef.returnType, _currentTypeParameterizedElement); | 2474 serializedTypedef.returnType, _currentTypeParameterizedElement); |
| 2450 functionTypeAliasElement.type = | 2475 functionTypeAliasElement.type = |
| 2451 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 2476 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
| 2452 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); | |
| 2453 unitHolder.addTypeAlias(functionTypeAliasElement); | 2477 unitHolder.addTypeAlias(functionTypeAliasElement); |
| 2454 currentTypeParameters.removeLast(); | 2478 currentTypeParameters.removeLast(); |
| 2455 assert(currentTypeParameters.isEmpty); | 2479 assert(currentTypeParameters.isEmpty); |
| 2456 } | 2480 } |
| 2457 | 2481 |
| 2458 /** | 2482 /** |
| 2459 * Resynthesize a [TypeParameterElement], handling all parts of its except | 2483 * Resynthesize a [TypeParameterElement], handling all parts of its except |
| 2460 * its bound. | 2484 * its bound. |
| 2461 * | 2485 * |
| 2462 * The bound is deferred until later since it may refer to other type | 2486 * The bound is deferred until later since it may refer to other type |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2850 static String _getElementIdentifier(String name, ReferenceKind kind) { | 2874 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 2851 if (kind == ReferenceKind.topLevelPropertyAccessor || | 2875 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 2852 kind == ReferenceKind.propertyAccessor) { | 2876 kind == ReferenceKind.propertyAccessor) { |
| 2853 if (!name.endsWith('=')) { | 2877 if (!name.endsWith('=')) { |
| 2854 return name + '?'; | 2878 return name + '?'; |
| 2855 } | 2879 } |
| 2856 } | 2880 } |
| 2857 return name; | 2881 return name; |
| 2858 } | 2882 } |
| 2859 } | 2883 } |
| OLD | NEW |