Chromium Code Reviews| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 * | 340 * |
| 341 * The list will be empty if there were no errors, but will not be `null`. | 341 * The list will be empty if there were no errors, but will not be `null`. |
| 342 * | 342 * |
| 343 * The result is only available for [Source]s representing a compilation unit. | 343 * The result is only available for [Source]s representing a compilation unit. |
| 344 */ | 344 */ |
| 345 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = | 345 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = |
| 346 new ListResultDescriptor<AnalysisError>( | 346 new ListResultDescriptor<AnalysisError>( |
| 347 'PARSE_ERRORS', AnalysisError.NO_ERRORS); | 347 'PARSE_ERRORS', AnalysisError.NO_ERRORS); |
| 348 | 348 |
| 349 /** | 349 /** |
| 350 * The flag specifying that [LIBRARY_ELEMENT2] is ready for a library. | |
|
Brian Wilkerson
2015/10/23 21:50:55
Maybe include a longer explanation here like the o
| |
| 351 * | |
| 352 * The result is only available for [Source]s representing a library. | |
| 353 */ | |
| 354 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT2 = | |
| 355 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT2', false); | |
| 356 | |
| 357 /** | |
| 358 * The flag specifying that [LIBRARY_ELEMENT5] is ready for a library. | |
| 359 * | |
| 360 * The result is only available for [Source]s representing a library. | |
| 361 */ | |
| 362 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT5 = | |
| 363 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT5', false); | |
| 364 | |
| 365 /** | |
| 350 * The flag specifying that [RESOLVED_UNIT] is ready for a library. | 366 * The flag specifying that [RESOLVED_UNIT] is ready for a library. |
| 351 * | 367 * |
| 352 * The result is only available for [Source]s representing a library. | 368 * The result is only available for [Source]s representing a library. |
| 353 */ | 369 */ |
| 354 final ResultDescriptor<bool> READY_RESOLVED_UNIT = | 370 final ResultDescriptor<bool> READY_RESOLVED_UNIT = |
| 355 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); | 371 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); |
| 356 | 372 |
| 357 /** | 373 /** |
| 358 * The flag specifying that [RESOLVED_UNIT10] is ready for a library. | 374 * The flag specifying that [RESOLVED_UNIT10] is ready for a library. |
| 359 * | 375 * |
| (...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1936 } | 1952 } |
| 1937 | 1953 |
| 1938 /** | 1954 /** |
| 1939 * Return a map from the names of the inputs of this kind of task to the task | 1955 * Return a map from the names of the inputs of this kind of task to the task |
| 1940 * input descriptors describing those inputs for a task with the | 1956 * input descriptors describing those inputs for a task with the |
| 1941 * given [target]. | 1957 * given [target]. |
| 1942 */ | 1958 */ |
| 1943 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1959 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 1944 LibrarySpecificUnit unit = target; | 1960 LibrarySpecificUnit unit = target; |
| 1945 return <String, TaskInput>{ | 1961 return <String, TaskInput>{ |
| 1946 'resolveReachableLibraries': IMPORT_EXPORT_SOURCE_CLOSURE | 1962 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library), |
| 1947 .of(unit.library) | 1963 'resolveReachableLibraries': READY_LIBRARY_ELEMENT2.of(unit.library), |
| 1948 .toListOf(LIBRARY_ELEMENT2), | |
| 1949 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library) | |
| 1950 }; | 1964 }; |
| 1951 } | 1965 } |
| 1952 | 1966 |
| 1953 /** | 1967 /** |
| 1954 * Create a [ComputeLibraryCycleTask] based on the | 1968 * Create a [ComputeLibraryCycleTask] based on the |
| 1955 * given [target] in the given [context]. | 1969 * given [target] in the given [context]. |
| 1956 */ | 1970 */ |
| 1957 static ComputeLibraryCycleTask createTask( | 1971 static ComputeLibraryCycleTask createTask( |
| 1958 AnalysisContext context, AnalysisTarget target) { | 1972 AnalysisContext context, AnalysisTarget target) { |
| 1959 return new ComputeLibraryCycleTask(context, target); | 1973 return new ComputeLibraryCycleTask(context, target); |
| (...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3471 } | 3485 } |
| 3472 | 3486 |
| 3473 /** | 3487 /** |
| 3474 * Return a map from the names of the inputs of this kind of task to the task | 3488 * Return a map from the names of the inputs of this kind of task to the task |
| 3475 * input descriptors describing those inputs for a task with the | 3489 * input descriptors describing those inputs for a task with the |
| 3476 * given [target]. | 3490 * given [target]. |
| 3477 */ | 3491 */ |
| 3478 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3492 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3479 LibrarySpecificUnit unit = target; | 3493 LibrarySpecificUnit unit = target; |
| 3480 return <String, TaskInput>{ | 3494 return <String, TaskInput>{ |
| 3481 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE | 3495 'fullyBuiltLibraryElements': READY_LIBRARY_ELEMENT5.of(unit.library), |
| 3482 .of(unit.library) | |
| 3483 .toListOf(LIBRARY_ELEMENT5), | |
| 3484 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), | 3496 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), |
| 3485 UNIT_INPUT: RESOLVED_UNIT4.of(unit), | 3497 UNIT_INPUT: RESOLVED_UNIT4.of(unit), |
| 3486 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 3498 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
| 3487 // In strong mode, add additional dependencies to enforce inference | 3499 // In strong mode, add additional dependencies to enforce inference |
| 3488 // ordering. | 3500 // ordering. |
| 3489 | 3501 |
| 3490 // Require that full inference be complete for all dependencies of the | 3502 // Require that full inference be complete for all dependencies of the |
| 3491 // current library cycle. | 3503 // current library cycle. |
| 3492 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( | 3504 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( |
| 3493 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 | 3505 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3538 void _addPublicNames(CompilationUnitElement compilationUnit) { | 3550 void _addPublicNames(CompilationUnitElement compilationUnit) { |
| 3539 compilationUnit.accessors.forEach(_addIfPublic); | 3551 compilationUnit.accessors.forEach(_addIfPublic); |
| 3540 compilationUnit.enums.forEach(_addIfPublic); | 3552 compilationUnit.enums.forEach(_addIfPublic); |
| 3541 compilationUnit.functions.forEach(_addIfPublic); | 3553 compilationUnit.functions.forEach(_addIfPublic); |
| 3542 compilationUnit.functionTypeAliases.forEach(_addIfPublic); | 3554 compilationUnit.functionTypeAliases.forEach(_addIfPublic); |
| 3543 compilationUnit.types.forEach(_addIfPublic); | 3555 compilationUnit.types.forEach(_addIfPublic); |
| 3544 } | 3556 } |
| 3545 } | 3557 } |
| 3546 | 3558 |
| 3547 /** | 3559 /** |
| 3560 * A task that ensures that [LIBRARY_ELEMENT2] is ready for every unit of the | |
| 3561 * target library source and its import/export closure. | |
| 3562 */ | |
| 3563 class ReadyLibraryElement2Task extends SourceBasedAnalysisTask { | |
| 3564 static const String IS_CLIENT_LIST_INPUT1 = 'IS_CLIENT_LIST_INPUT1'; | |
| 3565 static const String IS_CLIENT_LIST_INPUT2 = 'IS_CLIENT_LIST_INPUT2'; | |
| 3566 | |
| 3567 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
| 3568 'ReadyLibraryElement2Task', | |
| 3569 createTask, | |
| 3570 buildInputs, | |
| 3571 <ResultDescriptor>[READY_LIBRARY_ELEMENT2, IS_CLIENT]); | |
| 3572 | |
| 3573 ReadyLibraryElement2Task( | |
| 3574 InternalAnalysisContext context, AnalysisTarget target) | |
| 3575 : super(context, target); | |
| 3576 | |
| 3577 @override | |
| 3578 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 3579 | |
| 3580 @override | |
| 3581 bool get handlesDependencyCycles => true; | |
| 3582 | |
| 3583 @override | |
| 3584 void internalPerform() { | |
| 3585 bool isClient = _isClient(); | |
| 3586 outputs[READY_LIBRARY_ELEMENT2] = true; | |
| 3587 outputs[IS_CLIENT] = isClient; | |
| 3588 } | |
| 3589 | |
| 3590 bool _isClient() { | |
| 3591 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML); | |
| 3592 Source source = getRequiredSource(); | |
| 3593 if (source == htmlSource) { | |
| 3594 return true; | |
| 3595 } | |
| 3596 if (_hasTrueElement(getRequiredInput(IS_CLIENT_LIST_INPUT1))) { | |
| 3597 return true; | |
| 3598 } | |
| 3599 if (_hasTrueElement(getRequiredInput(IS_CLIENT_LIST_INPUT2))) { | |
| 3600 return true; | |
| 3601 } | |
| 3602 return false; | |
| 3603 } | |
| 3604 | |
| 3605 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | |
| 3606 Source source = target; | |
| 3607 return <String, TaskInput>{ | |
| 3608 'thisLibraryElementReady': LIBRARY_ELEMENT2.of(source), | |
| 3609 IS_CLIENT_LIST_INPUT1: IMPORTED_LIBRARIES.of(source).toListOf(IS_CLIENT), | |
| 3610 IS_CLIENT_LIST_INPUT2: EXPORTED_LIBRARIES.of(source).toListOf(IS_CLIENT), | |
| 3611 'directlyImportedLibrariesReady': | |
| 3612 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), | |
| 3613 'directlyExportedLibrariesReady': | |
| 3614 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), | |
| 3615 }; | |
| 3616 } | |
| 3617 | |
| 3618 static ReadyLibraryElement2Task createTask( | |
| 3619 AnalysisContext context, AnalysisTarget target) { | |
| 3620 return new ReadyLibraryElement2Task(context, target); | |
| 3621 } | |
| 3622 | |
| 3623 static bool _hasTrueElement(List<bool> elements) { | |
| 3624 if (elements != null) { | |
| 3625 for (bool isClient in elements) { | |
| 3626 if (isClient == true) { | |
| 3627 return true; | |
| 3628 } | |
| 3629 } | |
| 3630 } | |
| 3631 return false; | |
| 3632 } | |
| 3633 } | |
| 3634 | |
| 3635 /** | |
| 3636 * A task that ensures that [LIBRARY_ELEMENT5] is ready for every unit of the | |
| 3637 * target library source and its import/export closure. | |
| 3638 */ | |
| 3639 class ReadyLibraryElement5Task extends SourceBasedAnalysisTask { | |
| 3640 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
| 3641 'ReadyLibraryElement5Task', | |
| 3642 createTask, | |
| 3643 buildInputs, | |
| 3644 <ResultDescriptor>[READY_LIBRARY_ELEMENT5]); | |
| 3645 | |
| 3646 ReadyLibraryElement5Task( | |
| 3647 InternalAnalysisContext context, AnalysisTarget target) | |
| 3648 : super(context, target); | |
| 3649 | |
| 3650 @override | |
| 3651 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 3652 | |
| 3653 @override | |
| 3654 bool get handlesDependencyCycles => true; | |
| 3655 | |
| 3656 @override | |
| 3657 void internalPerform() { | |
| 3658 outputs[READY_LIBRARY_ELEMENT5] = true; | |
| 3659 } | |
| 3660 | |
| 3661 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | |
| 3662 Source source = target; | |
| 3663 return <String, TaskInput>{ | |
| 3664 'thisLibraryElementReady': LIBRARY_ELEMENT5.of(source), | |
| 3665 'directlyImportedLibrariesReady': | |
| 3666 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT5), | |
| 3667 'directlyExportedLibrariesReady': | |
| 3668 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT5), | |
| 3669 }; | |
| 3670 } | |
| 3671 | |
| 3672 static ReadyLibraryElement5Task createTask( | |
| 3673 AnalysisContext context, AnalysisTarget target) { | |
| 3674 return new ReadyLibraryElement5Task(context, target); | |
| 3675 } | |
| 3676 } | |
| 3677 | |
| 3678 /** | |
| 3548 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the | 3679 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the |
| 3549 * target library source and its import/export closure. | 3680 * target library source and its import/export closure. |
| 3550 */ | 3681 */ |
| 3551 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { | 3682 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { |
| 3552 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 3683 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3553 'ReadyResolvedUnit10Task', | 3684 'ReadyResolvedUnit10Task', |
| 3554 createTask, | 3685 createTask, |
| 3555 buildInputs, | 3686 buildInputs, |
| 3556 <ResultDescriptor>[READY_RESOLVED_UNIT10]); | 3687 <ResultDescriptor>[READY_RESOLVED_UNIT10]); |
| 3557 | 3688 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3956 * Create a [ResolveLibraryReferencesTask] based on the given [target] in | 4087 * Create a [ResolveLibraryReferencesTask] based on the given [target] in |
| 3957 * the given [context]. | 4088 * the given [context]. |
| 3958 */ | 4089 */ |
| 3959 static ResolveLibraryReferencesTask createTask( | 4090 static ResolveLibraryReferencesTask createTask( |
| 3960 AnalysisContext context, AnalysisTarget target) { | 4091 AnalysisContext context, AnalysisTarget target) { |
| 3961 return new ResolveLibraryReferencesTask(context, target); | 4092 return new ResolveLibraryReferencesTask(context, target); |
| 3962 } | 4093 } |
| 3963 } | 4094 } |
| 3964 | 4095 |
| 3965 /** | 4096 /** |
| 3966 * An artifitial task that does nothing except to force type names resolution | 4097 * An artificial task that does nothing except to force type names resolution |
| 3967 * for the defining and part units of a library. | 4098 * for the defining and part units of a library. |
| 3968 */ | 4099 */ |
| 3969 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { | 4100 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { |
| 3970 /** | 4101 /** |
| 3971 * The name of the [LIBRARY_ELEMENT4] input. | 4102 * The name of the [LIBRARY_ELEMENT4] input. |
| 3972 */ | 4103 */ |
| 3973 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 4104 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 3974 | 4105 |
| 3975 /** | 4106 /** |
| 3976 * The name of the [TYPE_PROVIDER] input. | 4107 * The name of the [TYPE_PROVIDER] input. |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4737 | 4868 |
| 4738 @override | 4869 @override |
| 4739 bool moveNext() { | 4870 bool moveNext() { |
| 4740 if (_newSources.isEmpty) { | 4871 if (_newSources.isEmpty) { |
| 4741 return false; | 4872 return false; |
| 4742 } | 4873 } |
| 4743 currentTarget = _newSources.removeLast(); | 4874 currentTarget = _newSources.removeLast(); |
| 4744 return true; | 4875 return true; |
| 4745 } | 4876 } |
| 4746 } | 4877 } |
| OLD | NEW |