| OLD | NEW |
| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 * | 279 * |
| 280 * [LIBRARY_ELEMENT4] plus resolved types for every element. | 280 * [LIBRARY_ELEMENT4] plus resolved types for every element. |
| 281 * | 281 * |
| 282 * The result is only available for [Source]s representing a library. | 282 * The result is only available for [Source]s representing a library. |
| 283 */ | 283 */ |
| 284 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 = | 284 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 = |
| 285 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null, | 285 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null, |
| 286 cachingPolicy: ELEMENT_CACHING_POLICY); | 286 cachingPolicy: ELEMENT_CACHING_POLICY); |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * The partial [LibraryElement] associated with a library. |
| 290 * |
| 291 * [LIBRARY_ELEMENT5] plus propagated types for propagable variables. |
| 292 * |
| 293 * The result is only available for [Source]s representing a library. |
| 294 */ |
| 295 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT6 = |
| 296 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT6', null, |
| 297 cachingPolicy: ELEMENT_CACHING_POLICY); |
| 298 |
| 299 /** |
| 300 * The partial [LibraryElement] associated with a library. |
| 301 * |
| 302 * [LIBRARY_ELEMENT6] for the library and its import/export closure. |
| 303 * |
| 304 * The result is only available for [Source]s representing a library. |
| 305 */ |
| 306 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 = |
| 307 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null, |
| 308 cachingPolicy: ELEMENT_CACHING_POLICY); |
| 309 |
| 310 /** |
| 289 * The flag specifying whether all analysis errors are computed in a specific | 311 * The flag specifying whether all analysis errors are computed in a specific |
| 290 * library. | 312 * library. |
| 291 * | 313 * |
| 292 * The result is only available for [Source]s representing a library. | 314 * The result is only available for [Source]s representing a library. |
| 293 */ | 315 */ |
| 294 final ResultDescriptor<bool> LIBRARY_ERRORS_READY = | 316 final ResultDescriptor<bool> LIBRARY_ERRORS_READY = |
| 295 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false); | 317 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false); |
| 296 | 318 |
| 297 /** | 319 /** |
| 298 * The [LibrarySpecificUnit]s that a library consists of. | 320 * The [LibrarySpecificUnit]s that a library consists of. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 /** | 401 /** |
| 380 * The flag specifying that [LIBRARY_ELEMENT5] is ready for a library and its | 402 * The flag specifying that [LIBRARY_ELEMENT5] is ready for a library and its |
| 381 * import/export closure. | 403 * import/export closure. |
| 382 * | 404 * |
| 383 * The result is only available for [Source]s representing a library. | 405 * The result is only available for [Source]s representing a library. |
| 384 */ | 406 */ |
| 385 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT5 = | 407 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT5 = |
| 386 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT5', false); | 408 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT5', false); |
| 387 | 409 |
| 388 /** | 410 /** |
| 411 * The flag specifying that [LIBRARY_ELEMENT6] is ready for a library and its |
| 412 * import/export closure. |
| 413 * |
| 414 * The result is only available for [Source]s representing a library. |
| 415 */ |
| 416 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT6 = |
| 417 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT6', false); |
| 418 |
| 419 /** |
| 389 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a | 420 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a |
| 390 * library and its import/export closure. | 421 * library and its import/export closure. |
| 391 * | 422 * |
| 392 * The result is only available for [Source]s representing a library. | 423 * The result is only available for [Source]s representing a library. |
| 393 */ | 424 */ |
| 394 final ResultDescriptor<bool> READY_RESOLVED_UNIT = | 425 final ResultDescriptor<bool> READY_RESOLVED_UNIT = |
| 395 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); | 426 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); |
| 396 | 427 |
| 397 /** | 428 /** |
| 398 * The flag specifying that [RESOLVED_UNIT10] is ready for all of the units of a | 429 * The flag specifying that [RESOLVED_UNIT10] is ready for all of the units of a |
| (...skipping 3219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3618 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target] | 3649 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target] |
| 3619 * in the given [context]. | 3650 * in the given [context]. |
| 3620 */ | 3651 */ |
| 3621 static PartiallyResolveUnitReferencesTask createTask( | 3652 static PartiallyResolveUnitReferencesTask createTask( |
| 3622 AnalysisContext context, AnalysisTarget target) { | 3653 AnalysisContext context, AnalysisTarget target) { |
| 3623 return new PartiallyResolveUnitReferencesTask(context, target); | 3654 return new PartiallyResolveUnitReferencesTask(context, target); |
| 3624 } | 3655 } |
| 3625 } | 3656 } |
| 3626 | 3657 |
| 3627 /** | 3658 /** |
| 3659 * An artificial task that does nothing except to force propagated types for |
| 3660 * all propagable variables in the import/export closure a library. |
| 3661 */ |
| 3662 class PropagateVariableTypesInLibraryClosureTask |
| 3663 extends SourceBasedAnalysisTask { |
| 3664 /** |
| 3665 * The name of the [LIBRARY_ELEMENT6] input. |
| 3666 */ |
| 3667 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 3668 |
| 3669 /** |
| 3670 * The task descriptor describing this kind of task. |
| 3671 */ |
| 3672 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3673 'PropagateVariableTypesInLibraryClosureTask', |
| 3674 createTask, |
| 3675 buildInputs, |
| 3676 <ResultDescriptor>[LIBRARY_ELEMENT7]); |
| 3677 |
| 3678 PropagateVariableTypesInLibraryClosureTask( |
| 3679 InternalAnalysisContext context, AnalysisTarget target) |
| 3680 : super(context, target); |
| 3681 |
| 3682 @override |
| 3683 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3684 |
| 3685 @override |
| 3686 void internalPerform() { |
| 3687 LibraryElement library = getRequiredInput(LIBRARY_INPUT); |
| 3688 outputs[LIBRARY_ELEMENT7] = library; |
| 3689 } |
| 3690 |
| 3691 /** |
| 3692 * Return a map from the names of the inputs of this kind of task to the task |
| 3693 * input descriptors describing those inputs for a task with the |
| 3694 * given [target]. |
| 3695 */ |
| 3696 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3697 Source source = target; |
| 3698 return <String, TaskInput>{ |
| 3699 'readyForClosure': READY_LIBRARY_ELEMENT6.of(source), |
| 3700 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(source), |
| 3701 }; |
| 3702 } |
| 3703 |
| 3704 /** |
| 3705 * Create a [PropagateVariableTypesInLibraryClosureTask] based on the given |
| 3706 * [target] in the given [context]. |
| 3707 */ |
| 3708 static PropagateVariableTypesInLibraryClosureTask createTask( |
| 3709 AnalysisContext context, AnalysisTarget target) { |
| 3710 return new PropagateVariableTypesInLibraryClosureTask(context, target); |
| 3711 } |
| 3712 } |
| 3713 |
| 3714 /** |
| 3715 * An artificial task that does nothing except to force propagated types for |
| 3716 * all propagable variables in the defining and part units of a library. |
| 3717 */ |
| 3718 class PropagateVariableTypesInLibraryTask extends SourceBasedAnalysisTask { |
| 3719 /** |
| 3720 * The name of the [LIBRARY_ELEMENT5] input. |
| 3721 */ |
| 3722 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 3723 |
| 3724 /** |
| 3725 * The task descriptor describing this kind of task. |
| 3726 */ |
| 3727 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3728 'PropagateVariableTypesInLibraryTask', |
| 3729 createTask, |
| 3730 buildInputs, |
| 3731 <ResultDescriptor>[LIBRARY_ELEMENT6]); |
| 3732 |
| 3733 PropagateVariableTypesInLibraryTask( |
| 3734 InternalAnalysisContext context, AnalysisTarget target) |
| 3735 : super(context, target); |
| 3736 |
| 3737 @override |
| 3738 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3739 |
| 3740 @override |
| 3741 void internalPerform() { |
| 3742 LibraryElement library = getRequiredInput(LIBRARY_INPUT); |
| 3743 outputs[LIBRARY_ELEMENT6] = library; |
| 3744 } |
| 3745 |
| 3746 /** |
| 3747 * Return a map from the names of the inputs of this kind of task to the task |
| 3748 * input descriptors describing those inputs for a task with the |
| 3749 * given [target]. |
| 3750 */ |
| 3751 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3752 Source source = target; |
| 3753 return <String, TaskInput>{ |
| 3754 'propagatedVariableTypesInUnits': |
| 3755 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT6), |
| 3756 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source), |
| 3757 }; |
| 3758 } |
| 3759 |
| 3760 /** |
| 3761 * Create a [PropagateVariableTypesInLibraryTask] based on the given [target] |
| 3762 * in the given [context]. |
| 3763 */ |
| 3764 static PropagateVariableTypesInLibraryTask createTask( |
| 3765 AnalysisContext context, AnalysisTarget target) { |
| 3766 return new PropagateVariableTypesInLibraryTask(context, target); |
| 3767 } |
| 3768 } |
| 3769 |
| 3770 /** |
| 3628 * A task that ensures that all of the propagable variables in a compilation | 3771 * A task that ensures that all of the propagable variables in a compilation |
| 3629 * unit have had their type propagated. | 3772 * unit have had their type propagated. |
| 3630 */ | 3773 */ |
| 3631 class PropagateVariableTypesInUnitTask extends SourceBasedAnalysisTask { | 3774 class PropagateVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
| 3632 /** | 3775 /** |
| 3633 * The name of the input whose value is the [RESOLVED_UNIT5] for the | 3776 * The name of the input whose value is the [RESOLVED_UNIT5] for the |
| 3634 * compilation unit. | 3777 * compilation unit. |
| 3635 */ | 3778 */ |
| 3636 static const String UNIT_INPUT = 'UNIT_INPUT'; | 3779 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 3637 | 3780 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3910 }; | 4053 }; |
| 3911 } | 4054 } |
| 3912 | 4055 |
| 3913 static ReadyLibraryElement5Task createTask( | 4056 static ReadyLibraryElement5Task createTask( |
| 3914 AnalysisContext context, AnalysisTarget target) { | 4057 AnalysisContext context, AnalysisTarget target) { |
| 3915 return new ReadyLibraryElement5Task(context, target); | 4058 return new ReadyLibraryElement5Task(context, target); |
| 3916 } | 4059 } |
| 3917 } | 4060 } |
| 3918 | 4061 |
| 3919 /** | 4062 /** |
| 4063 * A task that ensures that [LIBRARY_ELEMENT6] is ready for the target library |
| 4064 * source and its import/export closure. |
| 4065 */ |
| 4066 class ReadyLibraryElement6Task extends SourceBasedAnalysisTask { |
| 4067 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 4068 'ReadyLibraryElement6Task', |
| 4069 createTask, |
| 4070 buildInputs, |
| 4071 <ResultDescriptor>[READY_LIBRARY_ELEMENT6]); |
| 4072 |
| 4073 ReadyLibraryElement6Task( |
| 4074 InternalAnalysisContext context, AnalysisTarget target) |
| 4075 : super(context, target); |
| 4076 |
| 4077 @override |
| 4078 TaskDescriptor get descriptor => DESCRIPTOR; |
| 4079 |
| 4080 @override |
| 4081 bool get handlesDependencyCycles => true; |
| 4082 |
| 4083 @override |
| 4084 void internalPerform() { |
| 4085 outputs[READY_LIBRARY_ELEMENT6] = true; |
| 4086 } |
| 4087 |
| 4088 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4089 Source source = target; |
| 4090 return <String, TaskInput>{ |
| 4091 'thisLibraryElementReady': LIBRARY_ELEMENT6.of(source), |
| 4092 'directlyImportedLibrariesReady': |
| 4093 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT6), |
| 4094 'directlyExportedLibrariesReady': |
| 4095 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT6), |
| 4096 }; |
| 4097 } |
| 4098 |
| 4099 static ReadyLibraryElement6Task createTask( |
| 4100 AnalysisContext context, AnalysisTarget target) { |
| 4101 return new ReadyLibraryElement6Task(context, target); |
| 4102 } |
| 4103 } |
| 4104 |
| 4105 /** |
| 3920 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the | 4106 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the |
| 3921 * target library source and its import/export closure. | 4107 * target library source and its import/export closure. |
| 3922 */ | 4108 */ |
| 3923 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { | 4109 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { |
| 3924 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 4110 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3925 'ReadyResolvedUnit10Task', | 4111 'ReadyResolvedUnit10Task', |
| 3926 createTask, | 4112 createTask, |
| 3927 buildInputs, | 4113 buildInputs, |
| 3928 <ResultDescriptor>[READY_RESOLVED_UNIT10]); | 4114 <ResultDescriptor>[READY_RESOLVED_UNIT10]); |
| 3929 | 4115 |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4407 return new ResolveLibraryTypeNamesTask(context, target); | 4593 return new ResolveLibraryTypeNamesTask(context, target); |
| 4408 } | 4594 } |
| 4409 } | 4595 } |
| 4410 | 4596 |
| 4411 /** | 4597 /** |
| 4412 * A task that resolves the bodies of top-level functions, constructors, and | 4598 * A task that resolves the bodies of top-level functions, constructors, and |
| 4413 * methods within a single compilation unit. | 4599 * methods within a single compilation unit. |
| 4414 */ | 4600 */ |
| 4415 class ResolveUnitTask extends SourceBasedAnalysisTask { | 4601 class ResolveUnitTask extends SourceBasedAnalysisTask { |
| 4416 /** | 4602 /** |
| 4417 * The name of the input whose value is the defining [LIBRARY_ELEMENT5]. | 4603 * The name of the input whose value is the defining [LIBRARY_ELEMENT7]. |
| 4418 */ | 4604 */ |
| 4419 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 4605 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 4420 | 4606 |
| 4421 /** | 4607 /** |
| 4422 * The name of the [TYPE_PROVIDER] input. | 4608 * The name of the [TYPE_PROVIDER] input. |
| 4423 */ | 4609 */ |
| 4424 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 4610 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
| 4425 | 4611 |
| 4426 /** | 4612 /** |
| 4427 * The name of the [RESOLVED_UNIT9] input. | 4613 * The name of the [RESOLVED_UNIT9] input. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4469 } | 4655 } |
| 4470 | 4656 |
| 4471 /** | 4657 /** |
| 4472 * Return a map from the names of the inputs of this kind of task to the task | 4658 * Return a map from the names of the inputs of this kind of task to the task |
| 4473 * input descriptors describing those inputs for a task with the given | 4659 * input descriptors describing those inputs for a task with the given |
| 4474 * [target]. | 4660 * [target]. |
| 4475 */ | 4661 */ |
| 4476 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 4662 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4477 LibrarySpecificUnit unit = target; | 4663 LibrarySpecificUnit unit = target; |
| 4478 return <String, TaskInput>{ | 4664 return <String, TaskInput>{ |
| 4479 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), | 4665 LIBRARY_INPUT: LIBRARY_ELEMENT7.of(unit.library), |
| 4480 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 4666 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
| 4481 UNIT_INPUT: RESOLVED_UNIT9.of(unit), | 4667 UNIT_INPUT: RESOLVED_UNIT9.of(unit), |
| 4482 // In strong mode, add additional dependencies to enforce inference | 4668 // In strong mode, add additional dependencies to enforce inference |
| 4483 // ordering. | 4669 // ordering. |
| 4484 | 4670 |
| 4485 // Require that inference be complete for all units in the | 4671 // Require that inference be complete for all units in the |
| 4486 // current library cycle. | 4672 // current library cycle. |
| 4487 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList( | 4673 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList( |
| 4488 (CompilationUnitElementImpl unit) => RESOLVED_UNIT9 | 4674 (CompilationUnitElementImpl unit) => RESOLVED_UNIT9 |
| 4489 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) | 4675 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5087 | 5273 |
| 5088 @override | 5274 @override |
| 5089 bool moveNext() { | 5275 bool moveNext() { |
| 5090 if (_newSources.isEmpty) { | 5276 if (_newSources.isEmpty) { |
| 5091 return false; | 5277 return false; |
| 5092 } | 5278 } |
| 5093 currentTarget = _newSources.removeLast(); | 5279 currentTarget = _newSources.removeLast(); |
| 5094 return true; | 5280 return true; |
| 5095 } | 5281 } |
| 5096 } | 5282 } |
| OLD | NEW |