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

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

Issue 1701413005: Fix for making variable initializer synthetic. (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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_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) 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 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 // A missing entry in [LinkedUnit.types] means there is no [DartType] 1459 // A missing entry in [LinkedUnit.types] means there is no [DartType]
1460 // stored in this slot. 1460 // stored in this slot.
1461 return null; 1461 return null;
1462 } 1462 }
1463 return buildType(type); 1463 return buildType(type);
1464 } 1464 }
1465 1465
1466 /** 1466 /**
1467 * Resynthesize a local [FunctionElement]. 1467 * Resynthesize a local [FunctionElement].
1468 */ 1468 */
1469 FunctionElement buildLocalFunction(UnlinkedExecutable serializedExecutable) { 1469 FunctionElementImpl buildLocalFunction(
1470 UnlinkedExecutable serializedExecutable) {
1470 FunctionElementImpl element = new FunctionElementImpl( 1471 FunctionElementImpl element = new FunctionElementImpl(
1471 serializedExecutable.name, serializedExecutable.nameOffset); 1472 serializedExecutable.name, serializedExecutable.nameOffset);
1472 if (serializedExecutable.visibleOffset != 0) { 1473 if (serializedExecutable.visibleOffset != 0) {
1473 element.setVisibleRange(serializedExecutable.visibleOffset, 1474 element.setVisibleRange(serializedExecutable.visibleOffset,
1474 serializedExecutable.visibleLength); 1475 serializedExecutable.visibleLength);
1475 } 1476 }
1476 buildExecutableCommonParts(element, serializedExecutable); 1477 buildExecutableCommonParts(element, serializedExecutable);
1477 return element; 1478 return element;
1478 } 1479 }
1479 1480
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 // The type is inherited from the matching field. 1557 // The type is inherited from the matching field.
1557 parameterElement.type = fields[serializedParameter.name]?.type ?? 1558 parameterElement.type = fields[serializedParameter.name]?.type ??
1558 summaryResynthesizer.typeProvider.dynamicType; 1559 summaryResynthesizer.typeProvider.dynamicType;
1559 } else { 1560 } else {
1560 parameterElement.type = 1561 parameterElement.type =
1561 buildLinkedType(serializedParameter.inferredTypeSlot) ?? 1562 buildLinkedType(serializedParameter.inferredTypeSlot) ??
1562 buildType(serializedParameter.type); 1563 buildType(serializedParameter.type);
1563 } 1564 }
1564 parameterElement.hasImplicitType = serializedParameter.type == null; 1565 parameterElement.hasImplicitType = serializedParameter.type == null;
1565 } 1566 }
1566 if (serializedParameter.initializer != null) { 1567 buildVariableInitializer(parameterElement, serializedParameter.initializer);
1567 parameterElement.initializer =
1568 buildLocalFunction(serializedParameter.initializer);
1569 }
1570 switch (serializedParameter.kind) { 1568 switch (serializedParameter.kind) {
1571 case UnlinkedParamKind.named: 1569 case UnlinkedParamKind.named:
1572 parameterElement.parameterKind = ParameterKind.NAMED; 1570 parameterElement.parameterKind = ParameterKind.NAMED;
1573 break; 1571 break;
1574 case UnlinkedParamKind.positional: 1572 case UnlinkedParamKind.positional:
1575 parameterElement.parameterKind = ParameterKind.POSITIONAL; 1573 parameterElement.parameterKind = ParameterKind.POSITIONAL;
1576 break; 1574 break;
1577 case UnlinkedParamKind.required: 1575 case UnlinkedParamKind.required:
1578 parameterElement.parameterKind = ParameterKind.REQUIRED; 1576 parameterElement.parameterKind = ParameterKind.REQUIRED;
1579 break; 1577 break;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 /** 1741 /**
1744 * Handle the parts that are common to variables. 1742 * Handle the parts that are common to variables.
1745 */ 1743 */
1746 void buildVariableCommonParts( 1744 void buildVariableCommonParts(
1747 VariableElementImpl element, UnlinkedVariable serializedVariable) { 1745 VariableElementImpl element, UnlinkedVariable serializedVariable) {
1748 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? 1746 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ??
1749 buildType(serializedVariable.type); 1747 buildType(serializedVariable.type);
1750 element.const3 = serializedVariable.isConst; 1748 element.const3 = serializedVariable.isConst;
1751 element.final2 = serializedVariable.isFinal; 1749 element.final2 = serializedVariable.isFinal;
1752 element.hasImplicitType = serializedVariable.type == null; 1750 element.hasImplicitType = serializedVariable.type == null;
1753 if (serializedVariable.initializer != null) { 1751 buildVariableInitializer(element, serializedVariable.initializer);
1754 element.initializer = buildLocalFunction(serializedVariable.initializer);
1755 }
1756 buildDocumentation(element, serializedVariable.documentationComment); 1752 buildDocumentation(element, serializedVariable.documentationComment);
1757 buildAnnotations(element, serializedVariable.annotations); 1753 buildAnnotations(element, serializedVariable.annotations);
1758 } 1754 }
1759 1755
1760 /** 1756 /**
1757 * If the given [serializedInitializer] is not `null`, create the
1758 * corresponding [FunctionElementImpl] and set it for the [variable].
1759 */
1760 void buildVariableInitializer(
1761 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) {
1762 if (serializedInitializer == null) {
1763 return null;
1764 }
1765 FunctionElementImpl initializerElement =
1766 buildLocalFunction(serializedInitializer);
1767 initializerElement.synthetic = true;
1768 variable.initializer = initializerElement;
1769 }
1770
1771 /**
1761 * Finish creating a [TypeParameterElement] by deserializing its bound. 1772 * Finish creating a [TypeParameterElement] by deserializing its bound.
1762 */ 1773 */
1763 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 1774 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
1764 TypeParameterElementImpl typeParameterElement) { 1775 TypeParameterElementImpl typeParameterElement) {
1765 if (serializedTypeParameter.bound != null) { 1776 if (serializedTypeParameter.bound != null) {
1766 typeParameterElement.bound = buildType(serializedTypeParameter.bound); 1777 typeParameterElement.bound = buildType(serializedTypeParameter.bound);
1767 } 1778 }
1768 } 1779 }
1769 1780
1770 /** 1781 /**
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 } 2227 }
2217 : () => this.element; 2228 : () => this.element;
2218 // TODO(paulberry): Is it a bug that we have to pass `false` for 2229 // TODO(paulberry): Is it a bug that we have to pass `false` for
2219 // isInstantiated? 2230 // isInstantiated?
2220 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 2231 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
2221 } else { 2232 } else {
2222 return null; 2233 return null;
2223 } 2234 }
2224 } 2235 }
2225 } 2236 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698