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

Side by Side Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1620963003: final fields shouldn't be dependencies of const variables (Closed) Base URL: git@github.com:dart-lang/sdk.git@movetest
Patch Set: Created 4 years, 11 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.generated.constant; 5 library analyzer.src.generated.constant;
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/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 AnalysisEngine.instance.logger.logError( 436 AnalysisEngine.instance.logger.logError(
437 "Constant value computer trying to compute the value of a node of type ${constant.runtimeType}"); 437 "Constant value computer trying to compute the value of a node of type ${constant.runtimeType}");
438 return; 438 return;
439 } 439 }
440 } 440 }
441 441
442 /** 442 /**
443 * Determine which constant elements need to have their values computed 443 * Determine which constant elements need to have their values computed
444 * prior to computing the value of [constant], and report them using 444 * prior to computing the value of [constant], and report them using
445 * [callback]. 445 * [callback].
446 *
447 * Note that it's possible (in erroneous code) for a constant to depend on a
448 * non-constant. When this happens, we report the dependency anyhow so that
449 * if the non-constant changes to a constant, we will know to recompute the
450 * thing that depends on it. [computeDependencies] and
451 * [computeConstantValue] are responsible for ignoring the request if they
452 * are asked to act on a non-constant target.
453 */ 446 */
454 void computeDependencies( 447 void computeDependencies(
455 ConstantEvaluationTarget constant, ReferenceFinderCallback callback) { 448 ConstantEvaluationTarget constant, ReferenceFinderCallback callback) {
456 ReferenceFinder referenceFinder = new ReferenceFinder(callback); 449 ReferenceFinder referenceFinder = new ReferenceFinder(callback);
457 if (constant is ParameterElementImpl) { 450 if (constant is ParameterElementImpl) {
458 if (constant.initializer != null) { 451 if (constant.initializer != null) {
459 Expression defaultValue = constant.constantInitializer; 452 Expression defaultValue = constant.constantInitializer;
460 if (defaultValue != null) { 453 if (defaultValue != null) {
461 defaultValue.accept(referenceFinder); 454 defaultValue.accept(referenceFinder);
462 } 455 }
(...skipping 4780 matching lines...) Expand 10 before | Expand all | Expand 10 after
5243 } 5236 }
5244 return null; 5237 return null;
5245 } 5238 }
5246 5239
5247 @override 5240 @override
5248 Object visitSimpleIdentifier(SimpleIdentifier node) { 5241 Object visitSimpleIdentifier(SimpleIdentifier node) {
5249 Element element = node.staticElement; 5242 Element element = node.staticElement;
5250 if (element is PropertyAccessorElement) { 5243 if (element is PropertyAccessorElement) {
5251 element = (element as PropertyAccessorElement).variable; 5244 element = (element as PropertyAccessorElement).variable;
5252 } 5245 }
5253 if (element is VariableElement) { 5246 if (element is VariableElement && element.isConst) {
5254 _callback(element); 5247 _callback(element);
5255 } 5248 }
5256 return null; 5249 return null;
5257 } 5250 }
5258 5251
5259 @override 5252 @override
5260 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 5253 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
5261 super.visitSuperConstructorInvocation(node); 5254 super.visitSuperConstructorInvocation(node);
5262 ConstructorElement constructor = 5255 ConstructorElement constructor =
5263 ConstantEvaluationEngine._getConstructorBase(node.staticElement); 5256 ConstantEvaluationEngine._getConstructorBase(node.staticElement);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
5468 return BoolState.from(_element == rightElement); 5461 return BoolState.from(_element == rightElement);
5469 } else if (rightOperand is DynamicState) { 5462 } else if (rightOperand is DynamicState) {
5470 return BoolState.UNKNOWN_VALUE; 5463 return BoolState.UNKNOWN_VALUE;
5471 } 5464 }
5472 return BoolState.FALSE_STATE; 5465 return BoolState.FALSE_STATE;
5473 } 5466 }
5474 5467
5475 @override 5468 @override
5476 String toString() => _element == null ? "-unknown-" : _element.name; 5469 String toString() => _element == null ? "-unknown-" : _element.name;
5477 } 5470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698