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

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

Issue 1486663003: Ensure that a complete library element has constants evaluated (issue 24890) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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) 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/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 * 301 *
302 * [LIBRARY_ELEMENT6] for the library and its import/export closure. 302 * [LIBRARY_ELEMENT6] for the library and its import/export closure.
303 * 303 *
304 * The result is only available for [Source]s representing a library. 304 * The result is only available for [Source]s representing a library.
305 */ 305 */
306 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 = 306 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 =
307 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null, 307 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null,
308 cachingPolicy: ELEMENT_CACHING_POLICY); 308 cachingPolicy: ELEMENT_CACHING_POLICY);
309 309
310 /** 310 /**
311 * The partial [LibraryElement] associated with a library.
312 *
313 * The same as a [LIBRARY_ELEMENT7].
Paul Berry 2015/11/30 20:44:35 Next time I'm in the office I'd like to better und
Brian Wilkerson 2015/11/30 21:35:39 Good question. I was assuming that there was a dis
314 *
315 * The result is only available for [Source]s representing a library.
316 */
317 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT8 =
318 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT8', null,
319 cachingPolicy: ELEMENT_CACHING_POLICY);
320
321 /**
311 * The flag specifying whether all analysis errors are computed in a specific 322 * The flag specifying whether all analysis errors are computed in a specific
312 * library. 323 * library.
313 * 324 *
314 * The result is only available for [Source]s representing a library. 325 * The result is only available for [Source]s representing a library.
315 */ 326 */
316 final ResultDescriptor<bool> LIBRARY_ERRORS_READY = 327 final ResultDescriptor<bool> LIBRARY_ERRORS_READY =
317 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false); 328 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false);
318 329
319 /** 330 /**
320 * The [LibrarySpecificUnit]s that a library consists of. 331 * The [LibrarySpecificUnit]s that a library consists of.
(...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 } 2421 }
2411 2422
2412 /** 2423 /**
2413 * Return a map from the names of the inputs of this kind of task to the task 2424 * Return a map from the names of the inputs of this kind of task to the task
2414 * input descriptors describing those inputs for a task with the 2425 * input descriptors describing those inputs for a task with the
2415 * given [target]. 2426 * given [target].
2416 */ 2427 */
2417 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2428 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2418 LibrarySpecificUnit unit = target; 2429 LibrarySpecificUnit unit = target;
2419 return <String, TaskInput>{ 2430 return <String, TaskInput>{
2420 'libraryElement': LIBRARY_ELEMENT.of(unit.library), 2431 'libraryElement': LIBRARY_ELEMENT8.of(unit.library),
2421 UNIT_INPUT: RESOLVED_UNIT10.of(unit), 2432 UNIT_INPUT: RESOLVED_UNIT10.of(unit),
2422 CONSTANT_VALUES: 2433 CONSTANT_VALUES:
2423 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE) 2434 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE)
2424 }; 2435 };
2425 } 2436 }
2426 2437
2427 /** 2438 /**
2428 * Create an [EvaluateUnitConstantsTask] based on the given [target] in 2439 * Create an [EvaluateUnitConstantsTask] based on the given [target] in
2429 * the given [context]. 2440 * the given [context].
2430 */ 2441 */
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
3220 } 3231 }
3221 3232
3222 /** 3233 /**
3223 * Return a map from the names of the inputs of this kind of task to the task 3234 * Return a map from the names of the inputs of this kind of task to the task
3224 * input descriptors describing those inputs for a task with the 3235 * input descriptors describing those inputs for a task with the
3225 * given [target]. 3236 * given [target].
3226 */ 3237 */
3227 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3238 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3228 Source source = target; 3239 Source source = target;
3229 return <String, TaskInput>{ 3240 return <String, TaskInput>{
3230 'allErrors': UNITS.of(source).toListOf(DART_ERRORS) 3241 'allErrors': UNITS.of(source).toListOf(DART_ERRORS),
3242 'libraryElement': LIBRARY_ELEMENT.of(source)
3231 }; 3243 };
3232 } 3244 }
3233 3245
3234 /** 3246 /**
3235 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given 3247 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given
3236 * [context]. 3248 * [context].
3237 */ 3249 */
3238 static LibraryErrorsReadyTask createTask( 3250 static LibraryErrorsReadyTask createTask(
3239 AnalysisContext context, AnalysisTarget target) { 3251 AnalysisContext context, AnalysisTarget target) {
3240 return new LibraryErrorsReadyTask(context, target); 3252 return new LibraryErrorsReadyTask(context, target);
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
4451 * the given [context]. 4463 * the given [context].
4452 */ 4464 */
4453 static ResolveInstanceFieldsInUnitTask createTask( 4465 static ResolveInstanceFieldsInUnitTask createTask(
4454 AnalysisContext context, AnalysisTarget target) { 4466 AnalysisContext context, AnalysisTarget target) {
4455 return new ResolveInstanceFieldsInUnitTask(context, target); 4467 return new ResolveInstanceFieldsInUnitTask(context, target);
4456 } 4468 }
4457 } 4469 }
4458 4470
4459 /** 4471 /**
4460 * A task that finishes resolution by requesting [RESOLVED_UNIT10] for every 4472 * A task that finishes resolution by requesting [RESOLVED_UNIT10] for every
4461 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. 4473 * unit in the libraries closure and produces [LIBRARY_ELEMENT8].
4462 */ 4474 */
4463 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { 4475 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask {
4464 /** 4476 /**
4465 * The name of the [LIBRARY_ELEMENT5] input. 4477 * The name of the [LIBRARY_ELEMENT7] input.
4466 */ 4478 */
4467 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4479 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4468 4480
4469 /** 4481 /**
4470 * The name of the list of [RESOLVED_UNIT10] input. 4482 * The name of the list of [RESOLVED_UNIT10] input.
4471 */ 4483 */
4472 static const String UNITS_INPUT = 'UNITS_INPUT'; 4484 static const String UNITS_INPUT = 'UNITS_INPUT';
4473 4485
4474 /** 4486 /**
4475 * The task descriptor describing this kind of task. 4487 * The task descriptor describing this kind of task.
4476 */ 4488 */
4477 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 4489 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4478 'ResolveLibraryReferencesTask', 4490 'ResolveLibraryReferencesTask',
4479 createTask, 4491 createTask,
4480 buildInputs, 4492 buildInputs,
4481 <ResultDescriptor>[LIBRARY_ELEMENT, REFERENCED_NAMES]); 4493 <ResultDescriptor>[LIBRARY_ELEMENT8, REFERENCED_NAMES]);
4482 4494
4483 ResolveLibraryReferencesTask( 4495 ResolveLibraryReferencesTask(
4484 InternalAnalysisContext context, AnalysisTarget target) 4496 InternalAnalysisContext context, AnalysisTarget target)
4485 : super(context, target); 4497 : super(context, target);
4486 4498
4487 @override 4499 @override
4488 TaskDescriptor get descriptor => DESCRIPTOR; 4500 TaskDescriptor get descriptor => DESCRIPTOR;
4489 4501
4490 @override 4502 @override
4491 void internalPerform() { 4503 void internalPerform() {
4492 // 4504 //
4493 // Prepare inputs. 4505 // Prepare inputs.
4494 // 4506 //
4495 LibraryElement library = getRequiredInput(LIBRARY_INPUT); 4507 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
4496 List<CompilationUnit> units = getRequiredInput(UNITS_INPUT); 4508 List<CompilationUnit> units = getRequiredInput(UNITS_INPUT);
4497 // Compute referenced names. 4509 // Compute referenced names.
4498 ReferencedNames referencedNames = new ReferencedNames(); 4510 ReferencedNames referencedNames = new ReferencedNames();
4499 for (CompilationUnit unit in units) { 4511 for (CompilationUnit unit in units) {
4500 new ReferencedNamesBuilder(referencedNames).build(unit); 4512 new ReferencedNamesBuilder(referencedNames).build(unit);
4501 } 4513 }
4502 // 4514 //
4503 // Record outputs. 4515 // Record outputs.
4504 // 4516 //
4505 outputs[LIBRARY_ELEMENT] = library; 4517 outputs[LIBRARY_ELEMENT8] = library;
4506 outputs[REFERENCED_NAMES] = referencedNames; 4518 outputs[REFERENCED_NAMES] = referencedNames;
4507 } 4519 }
4508 4520
4509 /** 4521 /**
4510 * Return a map from the names of the inputs of this kind of task to the task 4522 * Return a map from the names of the inputs of this kind of task to the task
4511 * input descriptors describing those inputs for a task with the 4523 * input descriptors describing those inputs for a task with the
4512 * given [target]. 4524 * given [target].
4513 */ 4525 */
4514 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4526 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4515 Source source = target; 4527 Source source = target;
4516 return <String, TaskInput>{ 4528 return <String, TaskInput>{
4517 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source), 4529 LIBRARY_INPUT: LIBRARY_ELEMENT7.of(source),
4518 UNITS_INPUT: LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT10), 4530 UNITS_INPUT: LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT10),
4519 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT10.of(source), 4531 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT10.of(source),
4520 }; 4532 };
4521 } 4533 }
4522 4534
4523 /** 4535 /**
4524 * Create a [ResolveLibraryReferencesTask] based on the given [target] in 4536 * Create a [ResolveLibraryReferencesTask] based on the given [target] in
4525 * the given [context]. 4537 * the given [context].
4526 */ 4538 */
4527 static ResolveLibraryReferencesTask createTask( 4539 static ResolveLibraryReferencesTask createTask(
4528 AnalysisContext context, AnalysisTarget target) { 4540 AnalysisContext context, AnalysisTarget target) {
4529 return new ResolveLibraryReferencesTask(context, target); 4541 return new ResolveLibraryReferencesTask(context, target);
4530 } 4542 }
4531 } 4543 }
4532 4544
4533 /** 4545 /**
4546 * A task that finishes resolution by requesting [RESOLVED_UNIT11] for every
4547 * unit in the libraries closure and produces [LIBRARY_ELEMENT].
4548 */
4549 class ResolveLibraryTask extends SourceBasedAnalysisTask {
4550 /**
4551 * The name of the [LIBRARY_ELEMENT8] input.
4552 */
4553 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4554
4555 /**
4556 * The name of the list of [RESOLVED_UNIT11] input.
4557 */
4558 static const String UNITS_INPUT = 'UNITS_INPUT';
4559
4560 /**
4561 * The task descriptor describing this kind of task.
4562 */
4563 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4564 'ResolveLibraryTask',
4565 createTask,
4566 buildInputs,
4567 <ResultDescriptor>[LIBRARY_ELEMENT]);
4568
4569 ResolveLibraryTask(InternalAnalysisContext context, AnalysisTarget target)
4570 : super(context, target);
4571
4572 @override
4573 TaskDescriptor get descriptor => DESCRIPTOR;
4574
4575 @override
4576 void internalPerform() {
4577 //
4578 // Prepare inputs.
4579 //
4580 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
4581 //
4582 // Record outputs.
4583 //
4584 outputs[LIBRARY_ELEMENT] = library;
4585 }
4586
4587 /**
4588 * Return a map from the names of the inputs of this kind of task to the task
4589 * input descriptors describing those inputs for a task with the
4590 * given [target].
4591 */
4592 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4593 Source source = target;
4594 return <String, TaskInput>{
4595 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(source),
4596 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(source),
4597 };
4598 }
4599
4600 /**
4601 * Create a [ResolveLibraryTask] based on the given [target] in the given
4602 * [context].
4603 */
4604 static ResolveLibraryTask createTask(
4605 AnalysisContext context, AnalysisTarget target) {
4606 return new ResolveLibraryTask(context, target);
4607 }
4608 }
4609
4610 /**
4534 * An artificial task that does nothing except to force type names resolution 4611 * An artificial task that does nothing except to force type names resolution
4535 * for the defining and part units of a library. 4612 * for the defining and part units of a library.
4536 */ 4613 */
4537 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { 4614 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask {
4538 /** 4615 /**
4539 * The name of the [LIBRARY_ELEMENT4] input. 4616 * The name of the [LIBRARY_ELEMENT4] input.
4540 */ 4617 */
4541 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4618 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4542 4619
4543 /** 4620 /**
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
5282 5359
5283 @override 5360 @override
5284 bool moveNext() { 5361 bool moveNext() {
5285 if (_newSources.isEmpty) { 5362 if (_newSources.isEmpty) {
5286 return false; 5363 return false;
5287 } 5364 }
5288 currentTarget = _newSources.removeLast(); 5365 currentTarget = _newSources.removeLast();
5289 return true; 5366 return true;
5290 } 5367 }
5291 } 5368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698