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

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

Issue 1125423004: Add a task to the new task model for computing constant values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | pkg/analyzer/lib/src/plugin/engine_plugin.dart » ('j') | pkg/analyzer/lib/src/task/dart.dart » ('J')
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 a09d7adfd91e3238f03be3d1ce43a48ec65f060a..42b579d3008526776d933992b8896f622cb5b4c0 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -308,6 +308,64 @@ class ConstantEvaluationEngine {
}
/**
+ * Compute the constant value associated with the given [element].
+ */
+ void computeConstantValue(Element element) {
+ validator.beforeComputeValue(element);
+ if (element is ParameterElement) {
+ if (element.initializer != null) {
+ Expression defaultValue =
+ (element as PotentiallyConstVariableElement).constantInitializer;
+ if (defaultValue != null) {
+ RecordingErrorListener errorListener = new RecordingErrorListener();
+ ErrorReporter errorReporter =
+ new ErrorReporter(errorListener, element.source);
+ DartObjectImpl dartObject =
+ defaultValue.accept(new ConstantVisitor(this, errorReporter));
+ (element as ParameterElementImpl).evaluationResult =
+ new EvaluationResultImpl.con2(dartObject, errorListener.errors);
+ }
+ }
+ } else if (element is VariableElement) {
+ RecordingErrorListener errorListener = new RecordingErrorListener();
+ ErrorReporter errorReporter =
+ new ErrorReporter(errorListener, element.source);
+ DartObjectImpl dartObject =
+ (element as PotentiallyConstVariableElement).constantInitializer
+ .accept(new ConstantVisitor(this, errorReporter));
+ // Only check the type for truly const declarations (don't check final
+ // fields with initializers, since their types may be generic. The type
+ // of the final field will be checked later, when the constructor is
+ // invoked).
+ if (dartObject != null && element.isConst) {
+ if (!runtimeTypeMatch(dartObject, element.type)) {
+ errorReporter.reportErrorForElement(
+ CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, element, [
+ dartObject.type,
+ element.type
+ ]);
+ }
+ }
+ (element as VariableElementImpl).evaluationResult =
+ new EvaluationResultImpl.con2(dartObject, errorListener.errors);
+ } else if (element is ConstructorElement) {
+ // No evaluation needs to be done; constructor declarations are only in
+ // the dependency graph to ensure that any constants referred to in
+ // initializer lists and parameter defaults are evaluated before
+ // invocations of the constructor. However we do need to annotate the
+ // element as being free of constant evaluation cycles so that later code
+ // will know that it is safe to evaluate.
+ (element as ConstructorElementImpl).isCycleFree = true;
+ } else {
+ // Should not happen.
+ assert(false);
+ AnalysisEngine.instance.logger.logError(
+ "Constant value computer trying to compute the value of a node of type ${element.runtimeType}");
+ return;
+ }
+ }
+
+ /**
* Determine which constant elements need to have their values computed
* prior to computing the value of [element], and report them using
* [callback].
@@ -1110,58 +1168,7 @@ class ConstantValueComputer {
// a previous stage of analysis.
return;
}
- evaluationEngine.validator.beforeComputeValue(element);
- if (element is ParameterElement) {
- if (element.initializer != null) {
- Expression defaultValue =
- (element as PotentiallyConstVariableElement).constantInitializer;
- if (defaultValue != null) {
- RecordingErrorListener errorListener = new RecordingErrorListener();
- ErrorReporter errorReporter =
- new ErrorReporter(errorListener, element.source);
- DartObjectImpl dartObject = defaultValue
- .accept(new ConstantVisitor(evaluationEngine, errorReporter));
- (element as ParameterElementImpl).evaluationResult =
- new EvaluationResultImpl.con2(dartObject, errorListener.errors);
- }
- }
- } else if (element is VariableElement) {
- RecordingErrorListener errorListener = new RecordingErrorListener();
- ErrorReporter errorReporter =
- new ErrorReporter(errorListener, element.source);
- DartObjectImpl dartObject =
- (element as PotentiallyConstVariableElement).constantInitializer
- .accept(new ConstantVisitor(evaluationEngine, errorReporter));
- // Only check the type for truly const declarations (don't check final
- // fields with initializers, since their types may be generic. The type
- // of the final field will be checked later, when the constructor is
- // invoked).
- if (dartObject != null && element.isConst) {
- if (!evaluationEngine.runtimeTypeMatch(dartObject, element.type)) {
- errorReporter.reportErrorForElement(
- CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, element, [
- dartObject.type,
- element.type
- ]);
- }
- }
- (element as VariableElementImpl).evaluationResult =
- new EvaluationResultImpl.con2(dartObject, errorListener.errors);
- } else if (element is ConstructorElement) {
- // No evaluation needs to be done; constructor declarations are only in
- // the dependency graph to ensure that any constants referred to in
- // initializer lists and parameter defaults are evaluated before
- // invocations of the constructor. However we do need to annotate the
- // element as being free of constant evaluation cycles so that later code
- // will know that it is safe to evaluate.
- (element as ConstructorElementImpl).isCycleFree = true;
- } else {
- // Should not happen.
- assert(false);
- AnalysisEngine.instance.logger.logError(
- "Constant value computer trying to compute the value of a node of type ${element.runtimeType}");
- return;
- }
+ evaluationEngine.computeConstantValue(element);
}
/**
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/plugin/engine_plugin.dart » ('j') | pkg/analyzer/lib/src/task/dart.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698