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

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

Issue 1687403003: Resynthesize local variables and functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 serializedExecutable.returnType == null; 1110 serializedExecutable.returnType == null;
1111 } 1111 }
1112 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 1112 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
1113 executableElement, null, oldTypeArguments, false); 1113 executableElement, null, oldTypeArguments, false);
1114 executableElement.external = serializedExecutable.isExternal; 1114 executableElement.external = serializedExecutable.isExternal;
1115 currentTypeParameters.removeRange( 1115 currentTypeParameters.removeRange(
1116 oldTypeParametersLength, currentTypeParameters.length); 1116 oldTypeParametersLength, currentTypeParameters.length);
1117 buildDocumentation( 1117 buildDocumentation(
1118 executableElement, serializedExecutable.documentationComment); 1118 executableElement, serializedExecutable.documentationComment);
1119 buildAnnotations(executableElement, serializedExecutable.annotations); 1119 buildAnnotations(executableElement, serializedExecutable.annotations);
1120 executableElement.functions =
1121 serializedExecutable.localFunctions.map(buildLocalFunction).toList();
1122 executableElement.localVariables =
1123 serializedExecutable.localVariables.map(buildLocalVariable).toList();
1120 } 1124 }
1121 1125
1122 /** 1126 /**
1123 * Resynthesize an [ExportElement], 1127 * Resynthesize an [ExportElement],
1124 */ 1128 */
1125 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, 1129 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic,
1126 UnlinkedExportNonPublic serializedExportNonPublic) { 1130 UnlinkedExportNonPublic serializedExportNonPublic) {
1127 ExportElementImpl exportElement = 1131 ExportElementImpl exportElement =
1128 new ExportElementImpl(serializedExportNonPublic.offset); 1132 new ExportElementImpl(serializedExportNonPublic.offset);
1129 String exportedLibraryUri = summaryResynthesizer.sourceFactory 1133 String exportedLibraryUri = summaryResynthesizer.sourceFactory
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 EntityRef type = linkedTypeMap[slot]; 1412 EntityRef type = linkedTypeMap[slot];
1409 if (type == null) { 1413 if (type == null) {
1410 // A missing entry in [LinkedUnit.types] means there is no [DartType] 1414 // A missing entry in [LinkedUnit.types] means there is no [DartType]
1411 // stored in this slot. 1415 // stored in this slot.
1412 return null; 1416 return null;
1413 } 1417 }
1414 return buildType(type); 1418 return buildType(type);
1415 } 1419 }
1416 1420
1417 /** 1421 /**
1422 * Resynthesize a local [FunctionElement].
1423 */
1424 FunctionElement buildLocalFunction(UnlinkedExecutable serializedExecutable) {
1425 FunctionElementImpl element = new FunctionElementImpl(
1426 serializedExecutable.name, serializedExecutable.nameOffset);
1427 if (serializedExecutable.visibleOffset != 0) {
1428 element.setVisibleRange(serializedExecutable.visibleOffset,
1429 serializedExecutable.visibleLength);
1430 }
1431 buildExecutableCommonParts(element, serializedExecutable);
1432 return element;
1433 }
1434
1435 /**
1436 * Resynthesize a [LocalVariableElement].
1437 */
1438 LocalVariableElement buildLocalVariable(UnlinkedVariable serializedVariable) {
1439 LocalVariableElementImpl element;
1440 if (serializedVariable.constExpr != null) {
1441 ConstLocalVariableElementImpl constElement =
1442 new ConstLocalVariableElementImpl(
1443 serializedVariable.name, serializedVariable.nameOffset);
1444 element = constElement;
1445 constElement.constantInitializer =
1446 _buildConstExpression(serializedVariable.constExpr);
1447 } else {
1448 element = new LocalVariableElementImpl(
1449 serializedVariable.name, serializedVariable.nameOffset);
1450 }
1451 if (serializedVariable.visibleOffset != 0) {
1452 element.setVisibleRange(
1453 serializedVariable.visibleOffset, serializedVariable.visibleLength);
1454 }
1455 buildVariableCommonParts(element, serializedVariable);
1456 return element;
1457 }
1458
1459 /**
1418 * Resynthesize a [ParameterElement]. 1460 * Resynthesize a [ParameterElement].
1419 */ 1461 */
1420 ParameterElement buildParameter(UnlinkedParam serializedParameter) { 1462 ParameterElement buildParameter(UnlinkedParam serializedParameter) {
1421 ParameterElementImpl parameterElement; 1463 ParameterElementImpl parameterElement;
1422 if (serializedParameter.isInitializingFormal) { 1464 if (serializedParameter.isInitializingFormal) {
1423 FieldFormalParameterElementImpl initializingParameter; 1465 FieldFormalParameterElementImpl initializingParameter;
1424 if (serializedParameter.defaultValue != null) { 1466 if (serializedParameter.defaultValue != null) {
1425 DefaultFieldFormalParameterElementImpl defaultParameter = 1467 DefaultFieldFormalParameterElementImpl defaultParameter =
1426 new DefaultFieldFormalParameterElementImpl( 1468 new DefaultFieldFormalParameterElementImpl(
1427 serializedParameter.name, serializedParameter.nameOffset); 1469 serializedParameter.name, serializedParameter.nameOffset);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 partUnit.uriOffset = partDecl.uriOffset; 1541 partUnit.uriOffset = partDecl.uriOffset;
1500 partUnit.uriEnd = partDecl.uriEnd; 1542 partUnit.uriEnd = partDecl.uriEnd;
1501 partUnit.source = unitSource; 1543 partUnit.source = unitSource;
1502 partUnit.librarySource = librarySource; 1544 partUnit.librarySource = librarySource;
1503 partUnit.uri = uri; 1545 partUnit.uri = uri;
1504 buildAnnotations(partUnit, partDecl.annotations); 1546 buildAnnotations(partUnit, partDecl.annotations);
1505 return partUnit; 1547 return partUnit;
1506 } 1548 }
1507 1549
1508 /** 1550 /**
1551 * Handle the parts that are common to top level variables and fields.
1552 */
1553 void buildPropertyIntroducingElementCommonParts(
1554 PropertyInducingElementImpl element,
1555 UnlinkedVariable serializedVariable) {
1556 buildVariableCommonParts(element, serializedVariable);
1557 element.propagatedType =
1558 buildLinkedType(serializedVariable.propagatedTypeSlot);
1559 }
1560
1561 /**
1509 * Build a [DartType] object based on a [EntityRef]. This [DartType] 1562 * Build a [DartType] object based on a [EntityRef]. This [DartType]
1510 * may refer to elements in other libraries than the library being 1563 * may refer to elements in other libraries than the library being
1511 * deserialized, so handles are used to avoid having to deserialize other 1564 * deserialized, so handles are used to avoid having to deserialize other
1512 * libraries in the process. 1565 * libraries in the process.
1513 */ 1566 */
1514 DartType buildType(EntityRef type, {bool defaultVoid: false}) { 1567 DartType buildType(EntityRef type, {bool defaultVoid: false}) {
1515 if (type == null) { 1568 if (type == null) {
1516 if (defaultVoid) { 1569 if (defaultVoid) {
1517 return VoidTypeImpl.instance; 1570 return VoidTypeImpl.instance;
1518 } else { 1571 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 ConstTopLevelVariableElementImpl constElement = 1650 ConstTopLevelVariableElementImpl constElement =
1598 new ConstTopLevelVariableElementImpl( 1651 new ConstTopLevelVariableElementImpl(
1599 serializedVariable.name, serializedVariable.nameOffset); 1652 serializedVariable.name, serializedVariable.nameOffset);
1600 element = constElement; 1653 element = constElement;
1601 constElement.constantInitializer = 1654 constElement.constantInitializer =
1602 _buildConstExpression(serializedVariable.constExpr); 1655 _buildConstExpression(serializedVariable.constExpr);
1603 } else { 1656 } else {
1604 element = new TopLevelVariableElementImpl( 1657 element = new TopLevelVariableElementImpl(
1605 serializedVariable.name, serializedVariable.nameOffset); 1658 serializedVariable.name, serializedVariable.nameOffset);
1606 } 1659 }
1607 buildVariableCommonParts(element, serializedVariable); 1660 buildPropertyIntroducingElementCommonParts(element, serializedVariable);
1608 unitHolder.addTopLevelVariable(element); 1661 unitHolder.addTopLevelVariable(element);
1609 buildImplicitAccessors(element, unitHolder); 1662 buildImplicitAccessors(element, unitHolder);
1610 } else { 1663 } else {
1611 FieldElementImpl element; 1664 FieldElementImpl element;
1612 if (serializedVariable.constExpr != null) { 1665 if (serializedVariable.constExpr != null) {
1613 ConstFieldElementImpl constElement = new ConstFieldElementImpl( 1666 ConstFieldElementImpl constElement = new ConstFieldElementImpl(
1614 serializedVariable.name, serializedVariable.nameOffset); 1667 serializedVariable.name, serializedVariable.nameOffset);
1615 element = constElement; 1668 element = constElement;
1616 constElement.constantInitializer = 1669 constElement.constantInitializer =
1617 _buildConstExpression(serializedVariable.constExpr); 1670 _buildConstExpression(serializedVariable.constExpr);
1618 } else { 1671 } else {
1619 element = new FieldElementImpl( 1672 element = new FieldElementImpl(
1620 serializedVariable.name, serializedVariable.nameOffset); 1673 serializedVariable.name, serializedVariable.nameOffset);
1621 } 1674 }
1622 buildVariableCommonParts(element, serializedVariable); 1675 buildPropertyIntroducingElementCommonParts(element, serializedVariable);
1623 element.static = serializedVariable.isStatic; 1676 element.static = serializedVariable.isStatic;
1624 holder.addField(element); 1677 holder.addField(element);
1625 buildImplicitAccessors(element, holder); 1678 buildImplicitAccessors(element, holder);
1626 fields[element.name] = element; 1679 fields[element.name] = element;
1627 } 1680 }
1628 } 1681 }
1629 1682
1630 /** 1683 /**
1631 * Handle the parts that are common to top level variables and fields. 1684 * Handle the parts that are common to variables.
1632 */ 1685 */
1633 void buildVariableCommonParts(PropertyInducingElementImpl element, 1686 void buildVariableCommonParts(
1634 UnlinkedVariable serializedVariable) { 1687 VariableElementImpl element, UnlinkedVariable serializedVariable) {
1635 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? 1688 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ??
1636 buildType(serializedVariable.type); 1689 buildType(serializedVariable.type);
1637 element.const3 = serializedVariable.isConst; 1690 element.const3 = serializedVariable.isConst;
1638 element.final2 = serializedVariable.isFinal; 1691 element.final2 = serializedVariable.isFinal;
1639 element.hasImplicitType = serializedVariable.type == null; 1692 element.hasImplicitType = serializedVariable.type == null;
1640 element.propagatedType =
1641 buildLinkedType(serializedVariable.propagatedTypeSlot);
1642 buildDocumentation(element, serializedVariable.documentationComment); 1693 buildDocumentation(element, serializedVariable.documentationComment);
1643 buildAnnotations(element, serializedVariable.annotations); 1694 buildAnnotations(element, serializedVariable.annotations);
1644 } 1695 }
1645 1696
1646 /** 1697 /**
1647 * Finish creating a [TypeParameterElement] by deserializing its bound. 1698 * Finish creating a [TypeParameterElement] by deserializing its bound.
1648 */ 1699 */
1649 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 1700 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
1650 TypeParameterElementImpl typeParameterElement) { 1701 TypeParameterElementImpl typeParameterElement) {
1651 if (serializedTypeParameter.bound != null) { 1702 if (serializedTypeParameter.bound != null) {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 } 2114 }
2064 : () => this.element; 2115 : () => this.element;
2065 // TODO(paulberry): Is it a bug that we have to pass `false` for 2116 // TODO(paulberry): Is it a bug that we have to pass `false` for
2066 // isInstantiated? 2117 // isInstantiated?
2067 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 2118 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
2068 } else { 2119 } else {
2069 return null; 2120 return null;
2070 } 2121 }
2071 } 2122 }
2072 } 2123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698