Chromium Code Reviews| Index: pkg/analyzer/lib/src/task/dart.dart |
| diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart |
| index 4af7107afd9b21229a60e4d75d9ba3858dcd9ef1..23c6d8f0a03357fbb61ae8665a608a03bec2c26f 100644 |
| --- a/pkg/analyzer/lib/src/task/dart.dart |
| +++ b/pkg/analyzer/lib/src/task/dart.dart |
| @@ -177,6 +177,13 @@ final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT3 = |
| cachingPolicy: ELEMENT_CACHING_POLICY); |
| /** |
| + * An [Element] that has been successfully constant-evaluated. |
| + * |
| + * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy? |
|
Brian Wilkerson
2015/05/08 19:22:38
Long term, probably not. But I don't think it will
Paul Berry
2015/05/08 19:44:22
Ok, I will leave the TODO message as a reminder to
|
| + */ |
| +final ResultDescriptor<Element> CONSTANT_EVALUATED_ELEMENT = new ResultDescriptor<Element>('CONST_EVALUATED_ELEMENT', null, cachingPolicy: ELEMENT_CACHING_POLICY); |
|
Brian Wilkerson
2015/05/08 19:22:38
Perhaps format the file?
Paul Berry
2015/05/08 19:44:22
Done.
|
| + |
| +/** |
| * The partial [LibraryElement] associated with a library. |
| * |
| * In addition to [LIBRARY_ELEMENT3] the [LibraryElement.entryPoint] is set, |
| @@ -1612,9 +1619,70 @@ class BuildTypeProviderTask extends SourceBasedAnalysisTask { |
| } |
| /** |
| + * A task that computes the value of a constant ([CONSTANT_EVALUATED_ELEMENT]) and |
| + * stores it in the element model. |
| + */ |
| +class ComputeConstantValueTask extends ElementBasedAnalysisTask { |
| + /** |
| + * The name of the input which ensures that dependent constants are evaluated |
| + * before the target. |
| + */ |
| + static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT'; |
| + |
| + static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ComputeConstantValueTask', |
| + createTask, buildInputs, <ResultDescriptor>[CONSTANT_EVALUATED_ELEMENT]); |
| + |
| + ComputeConstantValueTask(InternalAnalysisContext context, Element element) |
| + : super(context, element); |
| + |
| + @override |
| + TaskDescriptor get descriptor => DESCRIPTOR; |
| + |
| + @override |
| + void internalPerform() { |
| + // |
| + // Prepare inputs. |
| + // |
| + // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping |
| + // dependency to ensure that the constants that this constant depends on |
| + // are computed first. |
|
scheglov
2015/05/08 18:46:07
Should this comment be removed?
Paul Berry
2015/05/08 19:44:22
I think it should stay. I was trying to explain w
|
| + Element element = target; |
| + AnalysisContext context = element.context; |
| + TypeProvider typeProvider = context.typeProvider; |
| + // |
| + // Compute the value of the constant. |
| + // |
| + new ConstantEvaluationEngine(typeProvider, context.declaredVariables).computeConstantValue(element); |
| + // |
| + // Record outputs. |
| + // |
| + outputs[CONSTANT_EVALUATED_ELEMENT] = element; |
| + } |
| + |
| + /** |
| + * Return a map from the names of the inputs of this kind of task to the task |
| + * input descriptors describing those inputs for a task with the given |
| + * [target]. |
| + */ |
| + static Map<String, TaskInput> buildInputs(Element target) { |
| + return <String, TaskInput>{ |
| + DEPENDENCIES_INPUT: CONSTANT_DEPENDENCIES.of(target).toListOf(CONSTANT_EVALUATED_ELEMENT) |
| + }; |
| + } |
| + |
| + /** |
| + * Create a [ComputeConstantValueTask] based on the given [target] in the |
| + * given [context]. |
| + */ |
| + static ComputeConstantValueTask createTask(AnalysisContext context, AnalysisTarget target) { |
| + return new ComputeConstantValueTask(context, target); |
| + } |
| +} |
| + |
| +/** |
| * A task that computes [CONSTANT_DEPENDENCIES] for a constant. |
| */ |
| -class ComputeConstantDependenciesTask extends AnalysisTask { |
| +class ComputeConstantDependenciesTask extends ElementBasedAnalysisTask { |
| /** |
| * The name of the [RESOLVED_UNIT] input. |
| */ |
| @@ -1625,15 +1693,8 @@ class ComputeConstantDependenciesTask extends AnalysisTask { |
| <ResultDescriptor>[CONSTANT_DEPENDENCIES]); |
| ComputeConstantDependenciesTask( |
| - InternalAnalysisContext context, AnalysisTarget target) |
| - : super(context, target); |
| - |
| - @override |
| - String get description { |
| - Source source = target.source; |
| - String sourceName = source == null ? '<unknown source>' : source.fullName; |
| - return '${descriptor.name} for element $target in source $sourceName'; |
| - } |
| + InternalAnalysisContext context, Element element) |
| + : super(context, element); |
| @override |
| TaskDescriptor get descriptor => DESCRIPTOR; |