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

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

Issue 2013883003: Migrate UnlinkedVariable.constExpr to UnlinkedExecutable.bodyExpr. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix a comment Created 4 years, 6 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 | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.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 2275 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 serializedLabel.isOnSwitchStatement, 2286 serializedLabel.isOnSwitchStatement,
2287 serializedLabel.isOnSwitchMember); 2287 serializedLabel.isOnSwitchMember);
2288 } 2288 }
2289 2289
2290 /** 2290 /**
2291 * Resynthesize a [LocalVariableElement]. 2291 * Resynthesize a [LocalVariableElement].
2292 */ 2292 */
2293 LocalVariableElement buildLocalVariable(UnlinkedVariable serializedVariable, 2293 LocalVariableElement buildLocalVariable(UnlinkedVariable serializedVariable,
2294 ExecutableElementImpl enclosingExecutable) { 2294 ExecutableElementImpl enclosingExecutable) {
2295 LocalVariableElementImpl element; 2295 LocalVariableElementImpl element;
2296 if (serializedVariable.constExpr != null && serializedVariable.isConst) { 2296 if (serializedVariable.initializer?.bodyExpr != null &&
2297 serializedVariable.isConst) {
2297 ConstLocalVariableElementImpl constElement = 2298 ConstLocalVariableElementImpl constElement =
2298 new ConstLocalVariableElementImpl.forSerialized( 2299 new ConstLocalVariableElementImpl.forSerialized(
2299 serializedVariable, enclosingExecutable); 2300 serializedVariable, enclosingExecutable);
2300 element = constElement; 2301 element = constElement;
2301 constElement.constantInitializer = _buildConstExpression( 2302 constElement.constantInitializer = _buildConstExpression(
2302 enclosingExecutable, serializedVariable.constExpr); 2303 enclosingExecutable, serializedVariable.initializer.bodyExpr);
2303 } else { 2304 } else {
2304 element = new LocalVariableElementImpl.forSerialized( 2305 element = new LocalVariableElementImpl.forSerialized(
2305 serializedVariable, enclosingExecutable); 2306 serializedVariable, enclosingExecutable);
2306 } 2307 }
2307 if (serializedVariable.visibleOffset != 0) { 2308 if (serializedVariable.visibleOffset != 0) {
2308 element.setVisibleRange( 2309 element.setVisibleRange(
2309 serializedVariable.visibleOffset, serializedVariable.visibleLength); 2310 serializedVariable.visibleOffset, serializedVariable.visibleLength);
2310 } 2311 }
2311 buildVariableCommonParts(element, serializedVariable); 2312 buildVariableCommonParts(element, serializedVariable);
2312 return element; 2313 return element;
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 } 2605 }
2605 2606
2606 UnitExplicitTopLevelVariables buildUnitExplicitTopLevelVariables() { 2607 UnitExplicitTopLevelVariables buildUnitExplicitTopLevelVariables() {
2607 List<UnlinkedVariable> unlinkedVariables = unlinkedUnit.variables; 2608 List<UnlinkedVariable> unlinkedVariables = unlinkedUnit.variables;
2608 int numberOfVariables = unlinkedVariables.length; 2609 int numberOfVariables = unlinkedVariables.length;
2609 UnitExplicitTopLevelVariables variablesData = 2610 UnitExplicitTopLevelVariables variablesData =
2610 new UnitExplicitTopLevelVariables(numberOfVariables); 2611 new UnitExplicitTopLevelVariables(numberOfVariables);
2611 for (int i = 0; i < numberOfVariables; i++) { 2612 for (int i = 0; i < numberOfVariables; i++) {
2612 UnlinkedVariable unlinkedVariable = unlinkedVariables[i]; 2613 UnlinkedVariable unlinkedVariable = unlinkedVariables[i];
2613 TopLevelVariableElementImpl element; 2614 TopLevelVariableElementImpl element;
2614 if (unlinkedVariable.constExpr != null && unlinkedVariable.isConst) { 2615 if (unlinkedVariable.initializer?.bodyExpr != null &&
2616 unlinkedVariable.isConst) {
2615 ConstTopLevelVariableElementImpl constElement = 2617 ConstTopLevelVariableElementImpl constElement =
2616 new ConstTopLevelVariableElementImpl.forSerialized( 2618 new ConstTopLevelVariableElementImpl.forSerialized(
2617 unlinkedVariable, unit); 2619 unlinkedVariable, unit);
2618 element = constElement; 2620 element = constElement;
2619 constElement.constantInitializer = 2621 constElement.constantInitializer =
2620 _buildConstExpression(null, unlinkedVariable.constExpr); 2622 _buildConstExpression(null, unlinkedVariable.initializer.bodyExpr);
2621 } else { 2623 } else {
2622 element = new TopLevelVariableElementImpl.forSerialized( 2624 element = new TopLevelVariableElementImpl.forSerialized(
2623 unlinkedVariable, unit); 2625 unlinkedVariable, unit);
2624 } 2626 }
2625 buildPropertyIntroducingElementCommonParts(element, unlinkedVariable); 2627 buildPropertyIntroducingElementCommonParts(element, unlinkedVariable);
2626 variablesData.variables[i] = element; 2628 variablesData.variables[i] = element;
2627 // implicit accessors 2629 // implicit accessors
2628 String name = element.name; 2630 String name = element.name;
2629 DartType type = element.type; 2631 DartType type = element.type;
2630 variablesData.implicitAccessors 2632 variablesData.implicitAccessors
2631 .add(buildImplicitGetter(element, name, type)); 2633 .add(buildImplicitGetter(element, name, type));
2632 if (!(element.isConst || element.isFinal)) { 2634 if (!(element.isConst || element.isFinal)) {
2633 variablesData.implicitAccessors 2635 variablesData.implicitAccessors
2634 .add(buildImplicitSetter(element, name, type)); 2636 .add(buildImplicitSetter(element, name, type));
2635 } 2637 }
2636 } 2638 }
2637 return variablesData; 2639 return variablesData;
2638 } 2640 }
2639 2641
2640 /** 2642 /**
2641 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. 2643 * Resynthesize a [TopLevelVariableElement] or [FieldElement].
2642 */ 2644 */
2643 void buildVariable( 2645 void buildVariable(
2644 ClassElementImpl enclosingClass, UnlinkedVariable serializedVariable, 2646 ClassElementImpl enclosingClass, UnlinkedVariable serializedVariable,
2645 [ElementHolder holder]) { 2647 [ElementHolder holder]) {
2646 if (holder == null) { 2648 if (holder == null) {
2647 throw new UnimplementedError('Must be lazy'); 2649 throw new UnimplementedError('Must be lazy');
2648 } else { 2650 } else {
2649 FieldElementImpl element; 2651 FieldElementImpl element;
2650 if (serializedVariable.constExpr != null && 2652 if (serializedVariable.initializer?.bodyExpr != null &&
2651 (serializedVariable.isConst || 2653 (serializedVariable.isConst ||
2652 serializedVariable.isFinal && !serializedVariable.isStatic)) { 2654 serializedVariable.isFinal && !serializedVariable.isStatic)) {
2653 ConstFieldElementImpl constElement = 2655 ConstFieldElementImpl constElement =
2654 new ConstFieldElementImpl.forSerialized( 2656 new ConstFieldElementImpl.forSerialized(
2655 serializedVariable, enclosingClass); 2657 serializedVariable, enclosingClass);
2656 element = constElement; 2658 element = constElement;
2657 constElement.constantInitializer = 2659 constElement.constantInitializer = _buildConstExpression(
2658 _buildConstExpression(enclosingClass, serializedVariable.constExpr); 2660 enclosingClass, serializedVariable.initializer.bodyExpr);
2659 } else { 2661 } else {
2660 element = new FieldElementImpl.forSerialized( 2662 element = new FieldElementImpl.forSerialized(
2661 serializedVariable, enclosingClass); 2663 serializedVariable, enclosingClass);
2662 } 2664 }
2663 buildPropertyIntroducingElementCommonParts(element, serializedVariable); 2665 buildPropertyIntroducingElementCommonParts(element, serializedVariable);
2664 element.static = serializedVariable.isStatic; 2666 element.static = serializedVariable.isStatic;
2665 holder.addField(element); 2667 holder.addField(element);
2666 buildImplicitAccessors(element, holder); 2668 buildImplicitAccessors(element, holder);
2667 fields[element.name] = element; 2669 fields[element.name] = element;
2668 } 2670 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 static String _getElementIdentifier(String name, ReferenceKind kind) { 2962 static String _getElementIdentifier(String name, ReferenceKind kind) {
2961 if (kind == ReferenceKind.topLevelPropertyAccessor || 2963 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2962 kind == ReferenceKind.propertyAccessor) { 2964 kind == ReferenceKind.propertyAccessor) {
2963 if (!name.endsWith('=')) { 2965 if (!name.endsWith('=')) {
2964 return name + '?'; 2966 return name + '?';
2965 } 2967 }
2966 } 2968 }
2967 return name; 2969 return name;
2968 } 2970 }
2969 } 2971 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698