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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 /** | 155 /** |
156 * The sources representing the combined import/export closure of a library. | 156 * The sources representing the combined import/export closure of a library. |
157 * The [Source]s include only library sources, not their units. | 157 * The [Source]s include only library sources, not their units. |
158 * | 158 * |
159 * The result is only available for [Source]s representing a library. | 159 * The result is only available for [Source]s representing a library. |
160 */ | 160 */ |
161 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE = | 161 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE = |
162 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null); | 162 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null); |
163 | 163 |
164 /** | 164 /** |
165 * The errors produced while inferring the type of a static variable. | |
166 * | |
167 * The list will be empty if there were no errors, but will not be `null`. | |
168 * | |
169 * The result is only available for [VariableElement]s, and only when strong | |
170 * mode is enabled. | |
171 */ | |
172 final ListResultDescriptor<AnalysisError> INFER_STATIC_VARIABLE_ERRORS = | |
173 new ListResultDescriptor<AnalysisError>( | |
174 'INFER_STATIC_VARIABLE_ERRORS', AnalysisError.NO_ERRORS); | |
175 | |
176 /** | |
177 * The errors produced while inferring the types of all of the static variables | |
178 * in a compilation unit. | |
179 * | |
180 * The list will be empty if there were no errors, but will not be `null`. | |
181 * | |
182 * The result is only available for [LibrarySpecificUnit]s. | |
183 */ | |
184 final ListResultDescriptor<AnalysisError> INFER_STATIC_VARIABLE_TYPES_ERRORS = | |
185 new ListResultDescriptor<AnalysisError>( | |
186 'INFER_STATIC_VARIABLE_TYPES_ERRORS', AnalysisError.NO_ERRORS); | |
187 | |
188 /** | |
165 * A list of the [VariableElement]s whose type should be inferred that another | 189 * A list of the [VariableElement]s whose type should be inferred that another |
166 * inferable static variable (the target) depends on. | 190 * inferable static variable (the target) depends on. |
167 * | 191 * |
168 * The result is only available for [VariableElement]s, and only when strong | 192 * The result is only available for [VariableElement]s, and only when strong |
169 * mode is enabled. | 193 * mode is enabled. |
170 */ | 194 */ |
171 final ListResultDescriptor< | 195 final ListResultDescriptor< |
172 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = | 196 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = |
173 new ListResultDescriptor<VariableElement>( | 197 new ListResultDescriptor<VariableElement>( |
174 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); | 198 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); |
175 | 199 |
176 /** | 200 /** |
177 * A list of the [VariableElement]s defined in a unit whose type should be | 201 * A list of the [VariableElement]s defined in a unit whose type should be |
178 * inferred. This includes variables defined at the library level as well as | 202 * inferred. This includes variables defined at the library level as well as |
179 * static members inside classes. | 203 * static members inside classes. |
180 * | 204 * |
181 * The result is only available for [LibrarySpecificUnit]s, and only when strong | 205 * The result is only available for [LibrarySpecificUnit]s, and only when strong |
182 * mode is enabled. | 206 * mode is enabled. |
183 */ | 207 */ |
184 final ListResultDescriptor<VariableElement> INFERABLE_STATIC_VARIABLES_IN_UNIT = | 208 final ListResultDescriptor<VariableElement> INFERABLE_STATIC_VARIABLES_IN_UNIT = |
185 new ListResultDescriptor<VariableElement>( | 209 new ListResultDescriptor<VariableElement>( |
186 'INFERABLE_STATIC_VARIABLES_IN_UNIT', null); | 210 'INFERABLE_STATIC_VARIABLES_IN_UNIT', null); |
187 | 211 |
188 /** | 212 /** |
189 * An inferrable static variable ([VariableElement]) whose type has been | 213 * An inferrable static variable ([VariableElement]) whose type has been |
190 * inferred. | 214 * inferred. |
215 * | |
216 * The result is only available for [VariableElement]s, and only when strong | |
217 * mode is enabled. | |
191 */ | 218 */ |
192 final ResultDescriptor<VariableElement> INFERRED_STATIC_VARIABLE = | 219 final ResultDescriptor<VariableElement> INFERRED_STATIC_VARIABLE = |
193 new ResultDescriptor<VariableElement>('INFERRED_STATIC_VARIABLE', null, | 220 new ResultDescriptor<VariableElement>('INFERRED_STATIC_VARIABLE', null, |
194 cachingPolicy: ELEMENT_CACHING_POLICY); | 221 cachingPolicy: ELEMENT_CACHING_POLICY); |
195 | 222 |
196 /** | 223 /** |
197 * The partial [LibraryElement] associated with a library. | 224 * The partial [LibraryElement] associated with a library. |
198 * | 225 * |
199 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each | 226 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each |
200 * other. Directives 'library', 'part' and 'part of' are resolved. | 227 * other. Directives 'library', 'part' and 'part of' are resolved. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 | 323 |
297 /** | 324 /** |
298 * The names (resolved and not) referenced by a unit. | 325 * The names (resolved and not) referenced by a unit. |
299 * | 326 * |
300 * The result is only available for [Source]s representing a compilation unit. | 327 * The result is only available for [Source]s representing a compilation unit. |
301 */ | 328 */ |
302 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = | 329 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = |
303 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); | 330 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); |
304 | 331 |
305 /** | 332 /** |
333 * The errors produced while resolving the function bodies within a compilation | |
334 * unit. | |
335 * | |
336 * The list will be empty if there were no errors, but will not be `null`. | |
337 * | |
338 * The result is only available for [LibrarySpecificUnit]s. | |
339 */ | |
340 final ListResultDescriptor<AnalysisError> RESOLVE_FUNCTION_BODIES_ERRORS = | |
341 new ListResultDescriptor<AnalysisError>( | |
342 'RESOLVE_FUNCTION_BODIES_ERRORS', AnalysisError.NO_ERRORS); | |
343 | |
344 /** | |
306 * The errors produced while resolving references. | 345 * The errors produced while resolving references. |
307 * | 346 * |
308 * The list will be empty if there were no errors, but will not be `null`. | 347 * The list will be empty if there were no errors, but will not be `null`. |
309 * | 348 * |
310 * The result is only available for [LibrarySpecificUnit]s. | 349 * The result is only available for [LibrarySpecificUnit]s. |
311 */ | 350 */ |
312 final ListResultDescriptor<AnalysisError> RESOLVE_REFERENCES_ERRORS = | 351 final ListResultDescriptor<AnalysisError> RESOLVE_REFERENCES_ERRORS = |
Paul Berry
2015/09/02 17:10:08
It looks like this result descriptor is not needed
Brian Wilkerson
2015/09/03 15:08:37
Yes. I guess I should have said so in the CL's mes
| |
313 new ListResultDescriptor<AnalysisError>( | 352 new ListResultDescriptor<AnalysisError>( |
314 'RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS); | 353 'RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS); |
315 | 354 |
316 /** | 355 /** |
317 * The errors produced while resolving type names. | 356 * The errors produced while resolving type names. |
318 * | 357 * |
319 * The list will be empty if there were no errors, but will not be `null`. | 358 * The list will be empty if there were no errors, but will not be `null`. |
320 * | 359 * |
321 * The result is only available for [LibrarySpecificUnit]s. | 360 * The result is only available for [LibrarySpecificUnit]s. |
322 */ | 361 */ |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2527 */ | 2566 */ |
2528 static const String UNIT_INPUT = 'UNIT_INPUT'; | 2567 static const String UNIT_INPUT = 'UNIT_INPUT'; |
2529 | 2568 |
2530 /** | 2569 /** |
2531 * The name of the input whose value is a list of the inferrable static | 2570 * The name of the input whose value is a list of the inferrable static |
2532 * variables whose types have been computed. | 2571 * variables whose types have been computed. |
2533 */ | 2572 */ |
2534 static const String INFERRED_VARIABLES_INPUT = 'INFERRED_VARIABLES_INPUT'; | 2573 static const String INFERRED_VARIABLES_INPUT = 'INFERRED_VARIABLES_INPUT'; |
2535 | 2574 |
2536 /** | 2575 /** |
2576 * The name of the input whose value is a list of the errors produced while | |
2577 * inferring types for static variables. | |
2578 */ | |
2579 static const String INFER_STATIC_VARIABLE_ERRORS_INPUT = 'INFER_STATIC_VARIABL E_ERRORS'; | |
2580 | |
2581 /** | |
2537 * The task descriptor describing this kind of task. | 2582 * The task descriptor describing this kind of task. |
2538 */ | 2583 */ |
2539 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 2584 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
2540 'InferStaticVariableTypesInUnitTask', | 2585 'InferStaticVariableTypesInUnitTask', |
2541 createTask, | 2586 createTask, |
2542 buildInputs, | 2587 buildInputs, |
2543 <ResultDescriptor>[RESOLVED_UNIT6]); | 2588 <ResultDescriptor>[INFER_STATIC_VARIABLE_TYPES_ERRORS, RESOLVED_UNIT6]); |
2544 | 2589 |
2545 /** | 2590 /** |
2546 * Initialize a newly created task to build a library element for the given | 2591 * Initialize a newly created task to build a library element for the given |
2547 * [unit] in the given [context]. | 2592 * [unit] in the given [context]. |
2548 */ | 2593 */ |
2549 InferStaticVariableTypesInUnitTask( | 2594 InferStaticVariableTypesInUnitTask( |
2550 InternalAnalysisContext context, LibrarySpecificUnit unit) | 2595 InternalAnalysisContext context, LibrarySpecificUnit unit) |
2551 : super(context, unit); | 2596 : super(context, unit); |
2552 | 2597 |
2553 @override | 2598 @override |
2554 TaskDescriptor get descriptor => DESCRIPTOR; | 2599 TaskDescriptor get descriptor => DESCRIPTOR; |
2555 | 2600 |
2556 @override | 2601 @override |
2557 void internalPerform() { | 2602 void internalPerform() { |
2558 // | 2603 // |
2559 // Prepare inputs. | 2604 // Prepare inputs. |
2560 // | 2605 // |
2561 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2606 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
2607 List<List<AnalysisError>> perVariableErrors = getRequiredInput(INFER_STATIC_ VARIABLE_ERRORS_INPUT); | |
Paul Berry
2015/09/02 17:10:08
Long line. Did you forget to run the formatter?
Brian Wilkerson
2015/09/03 15:08:37
It appears so, yes.
| |
2608 List<AnalysisError> errors = <AnalysisError>[]; | |
2609 for (List<AnalysisError> variableErrors in perVariableErrors) { | |
2610 errors.addAll(variableErrors); | |
2611 } | |
2562 // | 2612 // |
2563 // Record outputs. There is no additional work to be done at this time | 2613 // Record outputs. There is no additional work to be done at this time |
2564 // because the work has implicitly been done by virtue of the task model | 2614 // because the work has implicitly been done by virtue of the task model |
2565 // preparing all of the inputs. | 2615 // preparing all of the inputs. |
2566 // | 2616 // |
2617 outputs[INFER_STATIC_VARIABLE_TYPES_ERRORS] = errors; | |
2567 outputs[RESOLVED_UNIT6] = unit; | 2618 outputs[RESOLVED_UNIT6] = unit; |
2568 } | 2619 } |
2569 | 2620 |
2570 /** | 2621 /** |
2571 * Return a map from the names of the inputs of this kind of task to the task | 2622 * Return a map from the names of the inputs of this kind of task to the task |
2572 * input descriptors describing those inputs for a task with the given | 2623 * input descriptors describing those inputs for a task with the given |
2573 * [libSource]. | 2624 * [libSource]. |
2574 */ | 2625 */ |
2575 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2626 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
2576 LibrarySpecificUnit unit = target; | 2627 LibrarySpecificUnit unit = target; |
2577 return <String, TaskInput>{ | 2628 return <String, TaskInput>{ |
2578 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT | 2629 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT |
2579 .of(unit) | 2630 .of(unit) |
2580 .toListOf(INFERRED_STATIC_VARIABLE), | 2631 .toListOf(INFERRED_STATIC_VARIABLE), |
2632 INFER_STATIC_VARIABLE_ERRORS_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT | |
2633 .of(unit) | |
2634 .toListOf(INFER_STATIC_VARIABLE_ERRORS), | |
2581 UNIT_INPUT: RESOLVED_UNIT5.of(unit) | 2635 UNIT_INPUT: RESOLVED_UNIT5.of(unit) |
2582 }; | 2636 }; |
2583 } | 2637 } |
2584 | 2638 |
2585 /** | 2639 /** |
2586 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target] | 2640 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target] |
2587 * in the given [context]. | 2641 * in the given [context]. |
2588 */ | 2642 */ |
2589 static InferStaticVariableTypesInUnitTask createTask( | 2643 static InferStaticVariableTypesInUnitTask createTask( |
2590 AnalysisContext context, AnalysisTarget target) { | 2644 AnalysisContext context, AnalysisTarget target) { |
(...skipping 18 matching lines...) Expand all Loading... | |
2609 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 2663 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
2610 | 2664 |
2611 /** | 2665 /** |
2612 * The name of the [RESOLVED_UNIT5] input. | 2666 * The name of the [RESOLVED_UNIT5] input. |
2613 */ | 2667 */ |
2614 static const String UNIT_INPUT = 'UNIT_INPUT'; | 2668 static const String UNIT_INPUT = 'UNIT_INPUT'; |
2615 | 2669 |
2616 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 2670 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
2617 'InferStaticVariableTypeTask', | 2671 'InferStaticVariableTypeTask', |
2618 createTask, | 2672 createTask, |
2619 buildInputs, | 2673 buildInputs, <ResultDescriptor>[ |
2620 <ResultDescriptor>[INFERRED_STATIC_VARIABLE]); | 2674 INFER_STATIC_VARIABLE_ERRORS, |
2675 INFERRED_STATIC_VARIABLE | |
2676 ]); | |
2621 | 2677 |
2622 InferStaticVariableTypeTask( | 2678 InferStaticVariableTypeTask( |
2623 InternalAnalysisContext context, VariableElement variable) | 2679 InternalAnalysisContext context, VariableElement variable) |
2624 : super(context, variable); | 2680 : super(context, variable); |
2625 | 2681 |
2626 @override | 2682 @override |
2627 TaskDescriptor get descriptor => DESCRIPTOR; | 2683 TaskDescriptor get descriptor => DESCRIPTOR; |
2628 | 2684 |
2629 @override | 2685 @override |
2630 bool get handlesDependencyCycles => true; | 2686 bool get handlesDependencyCycles => true; |
2631 | 2687 |
2632 @override | 2688 @override |
2633 void internalPerform() { | 2689 void internalPerform() { |
2634 // | 2690 // |
2635 // Prepare inputs. | 2691 // Prepare inputs. |
2636 // | 2692 // |
2637 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping | 2693 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping |
2638 // dependency to ensure that the variables that this variable references | 2694 // dependency to ensure that the variables that this variable references |
2639 // have types inferred before inferring the type of this variable. | 2695 // have types inferred before inferring the type of this variable. |
2640 // | 2696 // |
2641 VariableElementImpl variable = target; | 2697 VariableElementImpl variable = target; |
2642 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2698 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
2643 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | 2699 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
2700 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
2644 if (dependencyCycle == null) { | 2701 if (dependencyCycle == null) { |
2645 // | 2702 // |
2646 // Re-resolve the variable's initializer so that the inferred types of oth er | 2703 // Re-resolve the variable's initializer so that the inferred types of oth er |
2647 // variables will be propagated. | 2704 // variables will be propagated. |
2648 // | 2705 // |
2649 NodeLocator locator = new NodeLocator(variable.nameOffset); | 2706 NodeLocator locator = new NodeLocator(variable.nameOffset); |
2650 AstNode node = locator.searchWithin(unit); | 2707 AstNode node = locator.searchWithin(unit); |
2651 VariableDeclaration declaration = node | 2708 VariableDeclaration declaration = node |
2652 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); | 2709 .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); |
2653 if (declaration == null || declaration.name != node) { | 2710 if (declaration == null || declaration.name != node) { |
2654 throw new AnalysisException( | 2711 throw new AnalysisException( |
2655 "NodeLocator failed to find a variable's declaration"); | 2712 "NodeLocator failed to find a variable's declaration"); |
2656 } | 2713 } |
2657 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
2658 Expression initializer = declaration.initializer; | 2714 Expression initializer = declaration.initializer; |
2659 ResolutionContext resolutionContext = | 2715 ResolutionContext resolutionContext = |
2660 ResolutionContextBuilder.contextFor(initializer, errorListener); | 2716 ResolutionContextBuilder.contextFor(initializer, errorListener); |
2661 ResolverVisitor visitor = new ResolverVisitor( | 2717 ResolverVisitor visitor = new ResolverVisitor( |
2662 variable.library, variable.source, typeProvider, errorListener, | 2718 variable.library, variable.source, typeProvider, errorListener, |
2663 nameScope: resolutionContext.scope); | 2719 nameScope: resolutionContext.scope); |
2664 if (resolutionContext.enclosingClassDeclaration != null) { | 2720 if (resolutionContext.enclosingClassDeclaration != null) { |
2665 visitor.prepareToResolveMembersInClass( | 2721 visitor.prepareToResolveMembersInClass( |
2666 resolutionContext.enclosingClassDeclaration); | 2722 resolutionContext.enclosingClassDeclaration); |
2667 } | 2723 } |
(...skipping 17 matching lines...) Expand all Loading... | |
2685 // variables or fields involved in a cycle. We could try to be smarter | 2741 // variables or fields involved in a cycle. We could try to be smarter |
2686 // by re-resolving the initializer in a context in which the types of all | 2742 // by re-resolving the initializer in a context in which the types of all |
2687 // of the variables in the cycle are assumed to be `null`, but it isn't | 2743 // of the variables in the cycle are assumed to be `null`, but it isn't |
2688 // clear to me that this would produce better results often enough to | 2744 // clear to me that this would produce better results often enough to |
2689 // warrant the extra effort. | 2745 // warrant the extra effort. |
2690 } | 2746 } |
2691 // | 2747 // |
2692 // Record outputs. | 2748 // Record outputs. |
2693 // | 2749 // |
2694 outputs[INFERRED_STATIC_VARIABLE] = variable; | 2750 outputs[INFERRED_STATIC_VARIABLE] = variable; |
2751 outputs[INFER_STATIC_VARIABLE_ERRORS] = errorListener.errors; | |
2695 } | 2752 } |
2696 | 2753 |
2697 /** | 2754 /** |
2698 * Return a map from the names of the inputs of this kind of task to the task | 2755 * Return a map from the names of the inputs of this kind of task to the task |
2699 * input descriptors describing those inputs for a task with the given | 2756 * input descriptors describing those inputs for a task with the given |
2700 * [target]. | 2757 * [target]. |
2701 */ | 2758 */ |
2702 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2759 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
2703 VariableElement variable = target; | 2760 VariableElement variable = target; |
2704 LibrarySpecificUnit unit = | 2761 LibrarySpecificUnit unit = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2773 * A task that merges all of the errors for a single source into a single list | 2830 * A task that merges all of the errors for a single source into a single list |
2774 * of errors. | 2831 * of errors. |
2775 */ | 2832 */ |
2776 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { | 2833 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
2777 /** | 2834 /** |
2778 * The name of the [HINTS] input. | 2835 * The name of the [HINTS] input. |
2779 */ | 2836 */ |
2780 static const String HINTS_INPUT = 'HINTS'; | 2837 static const String HINTS_INPUT = 'HINTS'; |
2781 | 2838 |
2782 /** | 2839 /** |
2783 * The name of the [RESOLVE_REFERENCES_ERRORS] input. | 2840 * The name of the [INFER_STATIC_VARIABLE_TYPES_ERRORS] input. |
2784 */ | 2841 */ |
2785 static const String RESOLVE_REFERENCES_ERRORS_INPUT = | 2842 static const String INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT = |
2786 'RESOLVE_REFERENCES_ERRORS'; | 2843 'INFER_STATIC_VARIABLE_TYPES_ERRORS'; |
2844 | |
2845 /** | |
2846 * The name of the [PARTIALLY_RESOLVE_REFERENCES_ERRORS] input. | |
2847 */ | |
2848 static const String PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT = | |
2849 'PARTIALLY_RESOLVE_REFERENCES_ERRORS'; | |
2850 | |
2851 /** | |
2852 * The name of the [RESOLVE_FUNCTION_BODIES_ERRORS] input. | |
2853 */ | |
2854 static const String RESOLVE_FUNCTION_BODIES_ERRORS_INPUT = | |
2855 'RESOLVE_FUNCTION_BODIES_ERRORS'; | |
2787 | 2856 |
2788 /** | 2857 /** |
2789 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. | 2858 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. |
2790 */ | 2859 */ |
2791 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = | 2860 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = |
2792 'RESOLVE_TYPE_NAMES_ERRORS'; | 2861 'RESOLVE_TYPE_NAMES_ERRORS'; |
2793 | 2862 |
2794 /** | 2863 /** |
2795 * The name of the [VARIABLE_REFERENCE_ERRORS] input. | 2864 * The name of the [VARIABLE_REFERENCE_ERRORS] input. |
2796 */ | 2865 */ |
(...skipping 20 matching lines...) Expand all Loading... | |
2817 @override | 2886 @override |
2818 TaskDescriptor get descriptor => DESCRIPTOR; | 2887 TaskDescriptor get descriptor => DESCRIPTOR; |
2819 | 2888 |
2820 @override | 2889 @override |
2821 void internalPerform() { | 2890 void internalPerform() { |
2822 // | 2891 // |
2823 // Prepare inputs. | 2892 // Prepare inputs. |
2824 // | 2893 // |
2825 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; | 2894 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
2826 errorLists.add(getRequiredInput(HINTS_INPUT)); | 2895 errorLists.add(getRequiredInput(HINTS_INPUT)); |
2827 errorLists.add(getRequiredInput(RESOLVE_REFERENCES_ERRORS_INPUT)); | 2896 errorLists.add(getRequiredInput(INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT)); |
2897 errorLists.add(getRequiredInput(PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT)); | |
2898 errorLists.add(getRequiredInput(RESOLVE_FUNCTION_BODIES_ERRORS_INPUT)); | |
2828 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); | 2899 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); |
2829 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); | 2900 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); |
2830 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); | 2901 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); |
2831 // | 2902 // |
2832 // Record outputs. | 2903 // Record outputs. |
2833 // | 2904 // |
2834 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); | 2905 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); |
2835 } | 2906 } |
2836 | 2907 |
2837 /** | 2908 /** |
2838 * Return a map from the names of the inputs of this kind of task to the task | 2909 * Return a map from the names of the inputs of this kind of task to the task |
2839 * input descriptors describing those inputs for a task with the | 2910 * input descriptors describing those inputs for a task with the |
2840 * given [unit]. | 2911 * given [unit]. |
2841 */ | 2912 */ |
2842 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2913 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
2843 LibrarySpecificUnit unit = target; | 2914 LibrarySpecificUnit unit = target; |
2844 return <String, TaskInput>{ | 2915 return <String, TaskInput>{ |
2845 HINTS_INPUT: HINTS.of(unit), | 2916 HINTS_INPUT: HINTS.of(unit), |
2846 RESOLVE_REFERENCES_ERRORS_INPUT: RESOLVE_REFERENCES_ERRORS.of(unit), | 2917 INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT: INFER_STATIC_VARIABLE_TYPES_ERRO RS.of(unit), |
2918 PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT: PARTIALLY_RESOLVE_REFERENCES_ER RORS.of(unit), | |
2919 RESOLVE_FUNCTION_BODIES_ERRORS_INPUT: RESOLVE_FUNCTION_BODIES_ERRORS.of(un it), | |
2847 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), | 2920 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), |
2848 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), | 2921 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), |
2849 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) | 2922 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) |
2850 }; | 2923 }; |
2851 } | 2924 } |
2852 | 2925 |
2853 /** | 2926 /** |
2854 * Create a [LibraryUnitErrorsTask] based on the given [target] in the given | 2927 * Create a [LibraryUnitErrorsTask] based on the given [target] in the given |
2855 * [context]. | 2928 * [context]. |
2856 */ | 2929 */ |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3288 String name = node.name; | 3361 String name = node.name; |
3289 names.names.add(name); | 3362 names.names.add(name); |
3290 if (dependsOn != null && bodyLevel == 0) { | 3363 if (dependsOn != null && bodyLevel == 0) { |
3291 dependsOn.add(name); | 3364 dependsOn.add(name); |
3292 } | 3365 } |
3293 } | 3366 } |
3294 } | 3367 } |
3295 } | 3368 } |
3296 | 3369 |
3297 /** | 3370 /** |
3371 * A task that resolves the bodies of top-level functions, constructors, and | |
3372 * methods within a single compilation unit. | |
3373 */ | |
3374 class ResolveFunctionBodiesInUnitTask extends SourceBasedAnalysisTask { | |
3375 /** | |
3376 * The name of the [TYPE_PROVIDER] input. | |
3377 */ | |
3378 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | |
3379 | |
3380 /** | |
3381 * The name of the [RESOLVED_UNIT7] input. | |
3382 */ | |
3383 static const String UNIT_INPUT = 'UNIT_INPUT'; | |
3384 | |
3385 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
3386 'ResolveFunctionBodiesInUnitTask', | |
3387 createTask, | |
3388 buildInputs, | |
3389 <ResultDescriptor>[RESOLVE_FUNCTION_BODIES_ERRORS, RESOLVED_UNIT8]); | |
3390 | |
3391 ResolveFunctionBodiesInUnitTask( | |
3392 InternalAnalysisContext context, LibrarySpecificUnit compilationUnit) | |
3393 : super(context, compilationUnit); | |
3394 | |
3395 @override | |
3396 TaskDescriptor get descriptor => DESCRIPTOR; | |
3397 | |
3398 @override | |
3399 void internalPerform() { | |
3400 // | |
3401 // Prepare inputs. | |
3402 // | |
3403 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | |
3404 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | |
3405 // | |
3406 // Resolve function bodies. | |
3407 // | |
3408 CompilationUnitElement unitElement = unit.element; | |
3409 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
3410 for (CompilationUnitMember unitMember in unit.declarations) { | |
3411 if (unitMember is FunctionDeclaration) { | |
3412 _resolveFunctionBody(unitMember.functionExpression.body, unitElement, | |
3413 typeProvider, errorListener); | |
3414 } else if (unitMember is ClassDeclaration) { | |
3415 for (ClassMember classMember in unitMember.members) { | |
3416 if (classMember is ConstructorDeclaration) { | |
3417 _resolveFunctionBody( | |
3418 classMember.body, unitElement, typeProvider, errorListener); | |
3419 } else if (classMember is MethodDeclaration) { | |
3420 _resolveFunctionBody( | |
3421 classMember.body, unitElement, typeProvider, errorListener); | |
3422 } | |
3423 } | |
3424 } | |
3425 } | |
3426 // | |
3427 // Record outputs. | |
3428 // | |
3429 outputs[RESOLVE_FUNCTION_BODIES_ERRORS] = errorListener.errors; | |
3430 outputs[RESOLVED_UNIT8] = unit; | |
3431 } | |
3432 | |
3433 void _resolveFunctionBody( | |
3434 FunctionBody functionBody, | |
3435 CompilationUnitElement unitElement, | |
3436 TypeProvider typeProvider, | |
3437 RecordingErrorListener errorListener) { | |
3438 ResolutionContext resolutionContext = | |
3439 ResolutionContextBuilder.contextFor(functionBody, errorListener); | |
3440 ResolverVisitor visitor = new ResolverVisitor( | |
3441 unitElement.library, unitElement.source, typeProvider, errorListener, | |
3442 nameScope: resolutionContext.scope); | |
3443 if (resolutionContext.enclosingClassDeclaration != null) { | |
3444 visitor.prepareToResolveMembersInClass( | |
3445 resolutionContext.enclosingClassDeclaration); | |
3446 } | |
3447 visitor.initForIncrementalResolution(); | |
3448 functionBody.accept(visitor); | |
3449 } | |
3450 | |
3451 /** | |
3452 * Return a map from the names of the inputs of this kind of task to the task | |
3453 * input descriptors describing those inputs for a task with the given | |
3454 * [target]. | |
3455 */ | |
3456 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | |
3457 LibrarySpecificUnit unit = target; | |
3458 return <String, TaskInput>{ | |
3459 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | |
3460 UNIT_INPUT: RESOLVED_UNIT7.of(unit) | |
3461 }; | |
3462 } | |
3463 | |
3464 /** | |
3465 * Create a [ResolveFunctionBodiesInUnitTask] based on the given [target] in | |
3466 * the given [context]. | |
3467 */ | |
3468 static ResolveFunctionBodiesInUnitTask createTask( | |
3469 AnalysisContext context, AnalysisTarget target) { | |
3470 return new ResolveFunctionBodiesInUnitTask(context, target); | |
3471 } | |
3472 } | |
3473 | |
3474 /** | |
3298 * A task that finishes resolution by requesting [RESOLVED_UNIT_NO_CONSTANTS] fo r every | 3475 * A task that finishes resolution by requesting [RESOLVED_UNIT_NO_CONSTANTS] fo r every |
3299 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. | 3476 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. |
3300 */ | 3477 */ |
3301 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { | 3478 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { |
3302 /** | 3479 /** |
3303 * The name of the [LIBRARY_ELEMENT5] input. | 3480 * The name of the [LIBRARY_ELEMENT5] input. |
3304 */ | 3481 */ |
3305 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 3482 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
3306 | 3483 |
3307 /** | 3484 /** |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3425 */ | 3602 */ |
3426 static ResolveLibraryTypeNamesTask createTask( | 3603 static ResolveLibraryTypeNamesTask createTask( |
3427 AnalysisContext context, AnalysisTarget target) { | 3604 AnalysisContext context, AnalysisTarget target) { |
3428 return new ResolveLibraryTypeNamesTask(context, target); | 3605 return new ResolveLibraryTypeNamesTask(context, target); |
3429 } | 3606 } |
3430 } | 3607 } |
3431 | 3608 |
3432 /** | 3609 /** |
3433 * A task that builds [RESOLVED_UNIT8] for a unit. | 3610 * A task that builds [RESOLVED_UNIT8] for a unit. |
3434 */ | 3611 */ |
3435 class ResolveUnitReferencesTask extends SourceBasedAnalysisTask { | 3612 class ResolveUnitReferencesTask extends SourceBasedAnalysisTask { |
Paul Berry
2015/09/02 17:10:08
I think we can delete this task too.
| |
3436 /** | 3613 /** |
3437 * The name of the [LIBRARY_ELEMENT5] input. | 3614 * The name of the [LIBRARY_ELEMENT5] input. |
3438 */ | 3615 */ |
3439 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 3616 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
3440 | 3617 |
3441 /** | 3618 /** |
3442 * The name of the [RESOLVED_UNIT4] input. | 3619 * The name of the [RESOLVED_UNIT4] input. |
3443 */ | 3620 */ |
3444 static const String UNIT_INPUT = 'UNIT_INPUT'; | 3621 static const String UNIT_INPUT = 'UNIT_INPUT'; |
3445 | 3622 |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4042 | 4219 |
4043 @override | 4220 @override |
4044 bool moveNext() { | 4221 bool moveNext() { |
4045 if (_newSources.isEmpty) { | 4222 if (_newSources.isEmpty) { |
4046 return false; | 4223 return false; |
4047 } | 4224 } |
4048 currentTarget = _newSources.removeLast(); | 4225 currentTarget = _newSources.removeLast(); |
4049 return true; | 4226 return true; |
4050 } | 4227 } |
4051 } | 4228 } |
OLD | NEW |