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

Unified Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1674403002: Materialize ConstructorElementImpl as we analyze constants. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/constant.dart
diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
index efa245c3b815303232cf264623744b8b825b0051..71230291bd61c840ac741c656850e037d8795334 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -13,6 +13,8 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart';
+import 'package:analyzer/src/generated/element_handle.dart'
+ show ConstructorElementHandle;
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/engine.dart'
show AnalysisEngine, RecordingErrorListener;
@@ -28,6 +30,16 @@ import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind;
import 'package:analyzer/src/generated/utilities_general.dart';
import 'package:analyzer/src/task/dart.dart';
+ConstructorElementImpl _getConstructorImpl(ConstructorElement constructor) {
+ if (constructor is ConstructorElementHandle) {
+ constructor = (constructor as ConstructorElementHandle).actualElement;
+ }
+ while (constructor is ConstructorMember) {
+ constructor = (constructor as ConstructorMember).baseElement;
+ }
+ return constructor;
+}
+
/**
* Callback used by [ReferenceFinder] to report that a dependency was found.
*/
@@ -339,17 +351,15 @@ class ConstantEvaluationEngine {
void computeConstantValue(ConstantEvaluationTarget constant) {
validator.beforeComputeValue(constant);
if (constant is ParameterElementImpl) {
- if (constant.initializer != null) {
- Expression defaultValue = constant.constantInitializer;
- if (defaultValue != null) {
- RecordingErrorListener errorListener = new RecordingErrorListener();
- ErrorReporter errorReporter =
- new ErrorReporter(errorListener, constant.source);
- DartObjectImpl dartObject =
- defaultValue.accept(new ConstantVisitor(this, errorReporter));
- constant.evaluationResult =
- new EvaluationResultImpl(dartObject, errorListener.errors);
- }
+ Expression defaultValue = constant.constantInitializer;
+ if (defaultValue != null) {
+ RecordingErrorListener errorListener = new RecordingErrorListener();
+ ErrorReporter errorReporter =
+ new ErrorReporter(errorListener, constant.source);
+ DartObjectImpl dartObject =
+ defaultValue.accept(new ConstantVisitor(this, errorReporter));
+ constant.evaluationResult =
+ new EvaluationResultImpl(dartObject, errorListener.errors);
}
} else if (constant is VariableElementImpl) {
Expression constantInitializer = constant.constantInitializer;
@@ -446,6 +456,9 @@ class ConstantEvaluationEngine {
void computeDependencies(
ConstantEvaluationTarget constant, ReferenceFinderCallback callback) {
ReferenceFinder referenceFinder = new ReferenceFinder(callback);
+ if (constant is ConstructorElement) {
+ constant = _getConstructorImpl(constant);
+ }
if (constant is VariableElementImpl) {
Expression initializer = constant.constantInitializer;
if (initializer != null) {
@@ -458,7 +471,7 @@ class ConstantEvaluationEngine {
getConstRedirectedConstructor(constant);
if (redirectedConstructor != null) {
ConstructorElement redirectedConstructorBase =
- _getConstructorBase(redirectedConstructor);
+ _getConstructorImpl(redirectedConstructor);
callback(redirectedConstructorBase);
return;
} else if (constant.isFactory) {
@@ -487,7 +500,7 @@ class ConstantEvaluationEngine {
(constant.returnType as InterfaceType).superclass;
if (superclass != null && !superclass.isObject) {
ConstructorElement unnamedConstructor =
- _getConstructorBase(superclass.element.unnamedConstructor);
+ _getConstructorImpl(superclass.element.unnamedConstructor);
if (unnamedConstructor != null) {
callback(unnamedConstructor);
}
@@ -582,7 +595,7 @@ class ConstantEvaluationEngine {
ConstructorElement constructor,
ConstantVisitor constantVisitor,
ErrorReporter errorReporter) {
- if (!_getConstructorBase(constructor).isCycleFree) {
+ if (!_getConstructorImpl(constructor).isCycleFree) {
// It's not safe to evaluate this constructor, so bail out.
// TODO(paulberry): ensure that a reasonable error message is produced
// in this case, as well as other cases involving constant expression
@@ -672,7 +685,7 @@ class ConstantEvaluationEngine {
// it an unknown value will suppress further errors.
return new DartObjectImpl.validWithUnknownValue(definingClass);
}
- ConstructorElementImpl constructorBase = _getConstructorBase(constructor);
+ ConstructorElementImpl constructorBase = _getConstructorImpl(constructor);
validator.beforeGetConstantInitializers(constructorBase);
List<ConstructorInitializer> initializers =
constructorBase.constantInitializers;
@@ -890,10 +903,10 @@ class ConstantEvaluationEngine {
if (redirectedConstructor == null) {
break;
} else {
- ConstructorElement constructorBase = _getConstructorBase(constructor);
+ ConstructorElement constructorBase = _getConstructorImpl(constructor);
constructorsVisited.add(constructorBase);
ConstructorElement redirectedConstructorBase =
- _getConstructorBase(redirectedConstructor);
+ _getConstructorImpl(redirectedConstructor);
if (constructorsVisited.contains(redirectedConstructorBase)) {
// Cycle in redirecting factory constructors--this is not allowed
// and is checked elsewhere--see
@@ -991,14 +1004,6 @@ class ConstantEvaluationEngine {
name.isEmpty ||
name == "void" ||
new JavaPatternMatcher(_PUBLIC_SYMBOL_PATTERN, name).matches();
-
- static ConstructorElementImpl _getConstructorBase(
- ConstructorElement constructor) {
- while (constructor is ConstructorMember) {
- constructor = (constructor as ConstructorMember).baseElement;
- }
- return constructor;
- }
}
/**
@@ -5155,8 +5160,7 @@ class ReferenceFinder extends RecursiveAstVisitor<Object> {
@override
Object visitInstanceCreationExpression(InstanceCreationExpression node) {
if (node.isConst) {
- ConstructorElement constructor =
- ConstantEvaluationEngine._getConstructorBase(node.staticElement);
+ ConstructorElement constructor = _getConstructorImpl(node.staticElement);
if (constructor != null) {
_callback(constructor);
}
@@ -5178,8 +5182,7 @@ class ReferenceFinder extends RecursiveAstVisitor<Object> {
Object visitRedirectingConstructorInvocation(
RedirectingConstructorInvocation node) {
super.visitRedirectingConstructorInvocation(node);
- ConstructorElement target =
- ConstantEvaluationEngine._getConstructorBase(node.staticElement);
+ ConstructorElement target = _getConstructorImpl(node.staticElement);
if (target != null) {
_callback(target);
}
@@ -5201,8 +5204,7 @@ class ReferenceFinder extends RecursiveAstVisitor<Object> {
@override
Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
super.visitSuperConstructorInvocation(node);
- ConstructorElement constructor =
- ConstantEvaluationEngine._getConstructorBase(node.staticElement);
+ ConstructorElement constructor = _getConstructorImpl(node.staticElement);
if (constructor != null) {
_callback(constructor);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698