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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1673913002: Separate CONSTANT_EXPRESSION_RESOLVED flag from RESOLVED_UNITx. (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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.dart ('k') | no next file » | 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 analyzer.src.task.dart; 5 library analyzer.src.task.dart;
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 * 110 *
111 * The result is only available for targets representing a 111 * The result is only available for targets representing a
112 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant 112 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant
113 * constructor, or a parameter element with a default value). 113 * constructor, or a parameter element with a default value).
114 */ 114 */
115 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES = 115 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES =
116 new ListResultDescriptor<ConstantEvaluationTarget>( 116 new ListResultDescriptor<ConstantEvaluationTarget>(
117 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]); 117 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]);
118 118
119 /** 119 /**
120 * The flag specifying that the target constant element expression AST is
121 * resolved, i.e. identifiers have all required elements set.
122 *
123 * The result is only available for targets representing a
124 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant
125 * constructor, or a parameter element with a default value).
126 */
127 final ResultDescriptor<bool> CONSTANT_EXPRESSION_RESOLVED =
128 new ResultDescriptor<bool>('CONSTANT_EXPRESSION_RESOLVED', false);
129
130 /**
120 * The list of [ConstantEvaluationTarget]s on which constant expressions of a 131 * The list of [ConstantEvaluationTarget]s on which constant expressions of a
121 * unit depend. 132 * unit depend.
122 * 133 *
123 * The result is only available for [LibrarySpecificUnit]s. 134 * The result is only available for [LibrarySpecificUnit]s.
124 */ 135 */
125 final ListResultDescriptor<ConstantEvaluationTarget> 136 final ListResultDescriptor<ConstantEvaluationTarget>
126 CONSTANT_EXPRESSIONS_DEPENDENCIES = 137 CONSTANT_EXPRESSIONS_DEPENDENCIES =
127 new ListResultDescriptor<ConstantEvaluationTarget>( 138 new ListResultDescriptor<ConstantEvaluationTarget>(
128 'CONSTANT_EXPRESSIONS_DEPENDENCIES', 139 'CONSTANT_EXPRESSIONS_DEPENDENCIES',
129 const <ConstantEvaluationTarget>[]); 140 const <ConstantEvaluationTarget>[]);
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 // 1658 //
1648 outputs[CONSTANT_DEPENDENCIES] = dependencies; 1659 outputs[CONSTANT_DEPENDENCIES] = dependencies;
1649 } 1660 }
1650 1661
1651 /** 1662 /**
1652 * Return a map from the names of the inputs of this kind of task to the task 1663 * Return a map from the names of the inputs of this kind of task to the task
1653 * input descriptors describing those inputs for a task with the 1664 * input descriptors describing those inputs for a task with the
1654 * given [target]. 1665 * given [target].
1655 */ 1666 */
1656 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1667 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1657 //
1658 // TODO(brianwilkerson) I believe that this does not properly guarantee that
1659 // all of the constructor initializers that we might encounter have been
1660 // copied into the element model. We tried forcing the computation of the
1661 // RESOLVED_UNIT9 for each unit reachable from the target's library, but
1662 // that had too big a performance impact. We could potentially mitigate the
1663 // impact by computing a more accurate list of the sources containing
1664 // constructors that are actually referenced, but other approaches should
1665 // be considered.
1666 //
1667 Source librarySource;
1668 if (target is Element) {
1669 CompilationUnitElementImpl unit = target
1670 .getAncestor((Element element) => element is CompilationUnitElement);
1671 librarySource = unit.librarySource;
1672 } else if (target is ElementAnnotationImpl) {
1673 librarySource = target.librarySource;
1674 } else {
1675 throw new AnalysisException(
1676 'Cannot build inputs for a ${target.runtimeType}');
1677 }
1678 return <String, TaskInput>{ 1668 return <String, TaskInput>{
1679 'resolvedUnit': RESOLVED_UNIT10 1669 'constantExpressionResolved': CONSTANT_EXPRESSION_RESOLVED.of(target),
1680 .of(new LibrarySpecificUnit(librarySource, target.source)),
1681 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 1670 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1682 }; 1671 };
1683 } 1672 }
1684 1673
1685 /** 1674 /**
1686 * Create a [ComputeConstantDependenciesTask] based on the given [target] in 1675 * Create a [ComputeConstantDependenciesTask] based on the given [target] in
1687 * the given [context]. 1676 * the given [context].
1688 */ 1677 */
1689 static ComputeConstantDependenciesTask createTask( 1678 static ComputeConstantDependenciesTask createTask(
1690 AnalysisContext context, AnalysisTarget target) { 1679 AnalysisContext context, AnalysisTarget target) {
(...skipping 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after
4183 String name = node.name; 4172 String name = node.name;
4184 names.names.add(name); 4173 names.names.add(name);
4185 if (dependsOn != null && bodyLevel == 0) { 4174 if (dependsOn != null && bodyLevel == 0) {
4186 dependsOn.add(name); 4175 dependsOn.add(name);
4187 } 4176 }
4188 } 4177 }
4189 } 4178 }
4190 } 4179 }
4191 4180
4192 /** 4181 /**
4182 * A task that ensures that the expression AST for a constant is resolved and
4183 * sets the [CONSTANT_EXPRESSION_RESOLVED] result.
4184 */
4185 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask {
4186 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4187 'ResolveConstantExpressionTask',
4188 createTask,
4189 buildInputs,
4190 <ResultDescriptor>[CONSTANT_EXPRESSION_RESOLVED]);
4191
4192 ResolveConstantExpressionTask(
4193 InternalAnalysisContext context, ConstantEvaluationTarget constant)
4194 : super(context, constant);
4195
4196 @override
4197 TaskDescriptor get descriptor => DESCRIPTOR;
4198
4199 @override
4200 void internalPerform() {
4201 //
4202 // Record outputs.
4203 //
4204 outputs[CONSTANT_EXPRESSION_RESOLVED] = true;
4205 }
4206
4207 /**
4208 * Return a map from the names of the inputs of this kind of task to the task
4209 * input descriptors describing those inputs for a task with the
4210 * given [target].
4211 */
4212 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4213 Source librarySource;
4214 if (target is Element) {
4215 CompilationUnitElementImpl unit = target
4216 .getAncestor((Element element) => element is CompilationUnitElement);
4217 librarySource = unit.librarySource;
4218 } else if (target is ElementAnnotationImpl) {
4219 librarySource = target.librarySource;
4220 } else {
4221 throw new AnalysisException(
4222 'Cannot build inputs for a ${target.runtimeType}');
4223 }
4224 return <String, TaskInput>{
4225 'createdResolvedUnit': CREATED_RESOLVED_UNIT10
4226 .of(new LibrarySpecificUnit(librarySource, target.source))
4227 };
4228 }
4229
4230 /**
4231 * Create a [ResolveConstantExpressionTask] based on the given [target] in
4232 * the given [context].
4233 */
4234 static ResolveConstantExpressionTask createTask(
4235 AnalysisContext context, AnalysisTarget target) {
4236 return new ResolveConstantExpressionTask(context, target);
4237 }
4238 }
4239
4240 /**
4193 * A task that ensures that all of the inferable instance members in a 4241 * A task that ensures that all of the inferable instance members in a
4194 * compilation unit have had their right hand sides re-resolved 4242 * compilation unit have had their right hand sides re-resolved
4195 */ 4243 */
4196 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask { 4244 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask {
4197 /** 4245 /**
4198 * The name of the [LIBRARY_ELEMENT5] input. 4246 * The name of the [LIBRARY_ELEMENT5] input.
4199 */ 4247 */
4200 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4248 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4201 4249
4202 /** 4250 /**
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
5232 5280
5233 @override 5281 @override
5234 bool moveNext() { 5282 bool moveNext() {
5235 if (_newSources.isEmpty) { 5283 if (_newSources.isEmpty) {
5236 return false; 5284 return false;
5237 } 5285 }
5238 currentTarget = _newSources.removeLast(); 5286 currentTarget = _newSources.removeLast();
5239 return true; 5287 return true;
5240 } 5288 }
5241 } 5289 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698