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/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
13 import 'package:analyzer/dart/element/type.dart'; | 13 import 'package:analyzer/dart/element/type.dart'; |
14 import 'package:analyzer/src/context/cache.dart'; | 14 import 'package:analyzer/src/context/cache.dart'; |
15 import 'package:analyzer/src/context/context.dart'; | 15 import 'package:analyzer/src/context/context.dart'; |
16 import 'package:analyzer/src/dart/ast/utilities.dart'; | 16 import 'package:analyzer/src/dart/ast/utilities.dart'; |
17 import 'package:analyzer/src/dart/element/builder.dart'; | 17 import 'package:analyzer/src/dart/element/builder.dart'; |
18 import 'package:analyzer/src/dart/element/element.dart'; | 18 import 'package:analyzer/src/dart/element/element.dart'; |
19 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; | 19 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; |
20 import 'package:analyzer/src/dart/scanner/reader.dart'; | 20 import 'package:analyzer/src/dart/scanner/reader.dart'; |
21 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 21 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
22 import 'package:analyzer/src/error/pending_error.dart'; | |
22 import 'package:analyzer/src/generated/constant.dart'; | 23 import 'package:analyzer/src/generated/constant.dart'; |
23 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
24 import 'package:analyzer/src/generated/error.dart'; | 25 import 'package:analyzer/src/generated/error.dart'; |
25 import 'package:analyzer/src/generated/error_verifier.dart'; | 26 import 'package:analyzer/src/generated/error_verifier.dart'; |
26 import 'package:analyzer/src/generated/incremental_resolver.dart'; | 27 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
27 import 'package:analyzer/src/generated/java_engine.dart'; | 28 import 'package:analyzer/src/generated/java_engine.dart'; |
28 import 'package:analyzer/src/generated/parser.dart'; | 29 import 'package:analyzer/src/generated/parser.dart'; |
29 import 'package:analyzer/src/generated/resolver.dart'; | 30 import 'package:analyzer/src/generated/resolver.dart'; |
30 import 'package:analyzer/src/generated/sdk.dart'; | 31 import 'package:analyzer/src/generated/sdk.dart'; |
31 import 'package:analyzer/src/generated/source.dart'; | 32 import 'package:analyzer/src/generated/source.dart'; |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 * | 557 * |
557 * The list will be empty if there were no errors, but will not be `null`. | 558 * The list will be empty if there were no errors, but will not be `null`. |
558 * | 559 * |
559 * The result is only available for [Source]s representing a compilation unit. | 560 * The result is only available for [Source]s representing a compilation unit. |
560 */ | 561 */ |
561 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = | 562 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = |
562 new ListResultDescriptor<AnalysisError>( | 563 new ListResultDescriptor<AnalysisError>( |
563 'PARSE_ERRORS', AnalysisError.NO_ERRORS); | 564 'PARSE_ERRORS', AnalysisError.NO_ERRORS); |
564 | 565 |
565 /** | 566 /** |
567 * The list of [PendingError]s for a compilation unit. | |
568 * | |
569 * The result is only available for [LibrarySpecificUnit]s. | |
570 */ | |
571 final ListResultDescriptor<PendingError> PENDING_ERRORS = | |
572 new ListResultDescriptor<PendingError>( | |
573 'PENDING_ERRORS', const <PendingError>[]); | |
574 | |
575 /** | |
566 * A list of the [VariableElement]s whose type should be known to propagate | 576 * A list of the [VariableElement]s whose type should be known to propagate |
567 * the type of another variable (the target). | 577 * the type of another variable (the target). |
568 * | 578 * |
569 * The result is only available for [VariableElement]s. | 579 * The result is only available for [VariableElement]s. |
570 */ | 580 */ |
571 final ListResultDescriptor<VariableElement> PROPAGABLE_VARIABLE_DEPENDENCIES = | 581 final ListResultDescriptor<VariableElement> PROPAGABLE_VARIABLE_DEPENDENCIES = |
572 new ListResultDescriptor<VariableElement>( | 582 new ListResultDescriptor<VariableElement>( |
573 'PROPAGABLE_VARIABLE_DEPENDENCIES', null); | 583 'PROPAGABLE_VARIABLE_DEPENDENCIES', null); |
574 | 584 |
575 /** | 585 /** |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 * | 651 * |
642 * The list is the union of [IMPORTED_LIBRARIES], [EXPORTED_LIBRARIES] and | 652 * The list is the union of [IMPORTED_LIBRARIES], [EXPORTED_LIBRARIES] and |
643 * [UNITS] of the defining unit and [INCLUDED_PARTS]. Never empty or `null`. | 653 * [UNITS] of the defining unit and [INCLUDED_PARTS]. Never empty or `null`. |
644 * | 654 * |
645 * The result is only available for [Source]s representing a library. | 655 * The result is only available for [Source]s representing a library. |
646 */ | 656 */ |
647 final ListResultDescriptor<Source> REFERENCED_SOURCES = | 657 final ListResultDescriptor<Source> REFERENCED_SOURCES = |
648 new ListResultDescriptor<Source>('REFERENCED_SOURCES', Source.EMPTY_LIST); | 658 new ListResultDescriptor<Source>('REFERENCED_SOURCES', Source.EMPTY_LIST); |
649 | 659 |
650 /** | 660 /** |
661 * The list of [ConstantEvaluationTarget]s on which error verification depends. | |
662 * | |
663 * The result is only available for [LibrarySpecificUnit]s. | |
664 */ | |
665 final ListResultDescriptor<ConstantEvaluationTarget> REQUIRED_CONSTANTS = | |
666 new ListResultDescriptor<ConstantEvaluationTarget>( | |
667 'REQUIRED_CONSTANTS', const <ConstantEvaluationTarget>[]); | |
668 | |
669 /** | |
651 * The errors produced while resolving bounds of type parameters of classes, | 670 * The errors produced while resolving bounds of type parameters of classes, |
652 * class and function aliases. | 671 * class and function aliases. |
653 * | 672 * |
654 * The list will be empty if there were no errors, but will not be `null`. | 673 * The list will be empty if there were no errors, but will not be `null`. |
655 * | 674 * |
656 * The result is only available for [LibrarySpecificUnit]s. | 675 * The result is only available for [LibrarySpecificUnit]s. |
657 */ | 676 */ |
658 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_BOUNDS_ERRORS = | 677 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_BOUNDS_ERRORS = |
659 new ListResultDescriptor<AnalysisError>( | 678 new ListResultDescriptor<AnalysisError>( |
660 'RESOLVE_TYPE_BOUNDS_ERRORS', AnalysisError.NO_ERRORS); | 679 'RESOLVE_TYPE_BOUNDS_ERRORS', AnalysisError.NO_ERRORS); |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2240 * Create a [ComputePropagableVariableDependenciesTask] based on the | 2259 * Create a [ComputePropagableVariableDependenciesTask] based on the |
2241 * given [target] in the given [context]. | 2260 * given [target] in the given [context]. |
2242 */ | 2261 */ |
2243 static ComputePropagableVariableDependenciesTask createTask( | 2262 static ComputePropagableVariableDependenciesTask createTask( |
2244 AnalysisContext context, AnalysisTarget target) { | 2263 AnalysisContext context, AnalysisTarget target) { |
2245 return new ComputePropagableVariableDependenciesTask(context, target); | 2264 return new ComputePropagableVariableDependenciesTask(context, target); |
2246 } | 2265 } |
2247 } | 2266 } |
2248 | 2267 |
2249 /** | 2268 /** |
2269 * A task that builds [REQUIRED_CONSTANTS] for a unit. | |
2270 */ | |
2271 class ComputeRequiredConstantsTask extends SourceBasedAnalysisTask { | |
2272 /** | |
2273 * The name of the [RESOLVED_UNIT] input. | |
scheglov
2016/05/13 17:59:48
All the comments are misformatted :-(
Brian Wilkerson
2016/05/13 18:11:14
Grr. IntelliJ decided the file should used 4 space
| |
2274 */ | |
2275 static const String UNIT_INPUT = 'UNIT_INPUT'; | |
2276 | |
2277 /** | |
2278 * The task descriptor describing this kind of task. | |
2279 */ | |
2280 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
2281 'ComputeRequiredConstantsTask', | |
2282 createTask, | |
2283 buildInputs, | |
2284 <ResultDescriptor>[PENDING_ERRORS, REQUIRED_CONSTANTS]); | |
2285 | |
2286 ComputeRequiredConstantsTask( | |
2287 InternalAnalysisContext context, AnalysisTarget target) | |
2288 : super(context, target); | |
2289 | |
2290 @override | |
2291 TaskDescriptor get descriptor => DESCRIPTOR; | |
2292 | |
2293 @override | |
2294 void internalPerform() { | |
2295 Source source = getRequiredSource(); | |
2296 // | |
2297 // Prepare inputs. | |
2298 // | |
2299 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | |
2300 // | |
2301 // Use the ErrorVerifier to compute errors. | |
2302 // | |
2303 RequiredConstantsComputer computer = new RequiredConstantsComputer(source); | |
2304 unit.accept(computer); | |
2305 List<PendingError> pendingErrors = computer.pendingErrors; | |
2306 List<ConstantEvaluationTarget> requiredConstants = | |
2307 computer.requiredConstants; | |
2308 // | |
2309 // Record outputs. | |
2310 // | |
2311 outputs[PENDING_ERRORS] = pendingErrors; | |
2312 outputs[REQUIRED_CONSTANTS] = requiredConstants; | |
2313 } | |
2314 | |
2315 /** | |
2316 * Return a map from the names of the inputs of this kind of task to the tas k | |
2317 * input descriptors describing those inputs for a task with the | |
2318 * given [target]. | |
2319 */ | |
2320 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | |
2321 LibrarySpecificUnit unit = target; | |
2322 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(unit)}; | |
2323 } | |
2324 | |
2325 /** | |
2326 * Create a [ComputeRequiredConstantsTask] based on the given [target] in | |
2327 * the given [context]. | |
2328 */ | |
2329 static ComputeRequiredConstantsTask createTask( | |
2330 AnalysisContext context, AnalysisTarget target) { | |
2331 return new ComputeRequiredConstantsTask(context, target); | |
2332 } | |
2333 } | |
2334 | |
2335 /** | |
2250 * A base class for analysis tasks whose target is expected to be a | 2336 * A base class for analysis tasks whose target is expected to be a |
2251 * [ConstantEvaluationTarget]. | 2337 * [ConstantEvaluationTarget]. |
2252 */ | 2338 */ |
2253 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask { | 2339 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask { |
2254 /** | 2340 /** |
2255 * Initialize a newly created task to perform analysis within the given | 2341 * Initialize a newly created task to perform analysis within the given |
2256 * [context] in order to produce results for the given [constant]. | 2342 * [context] in order to produce results for the given [constant]. |
2257 */ | 2343 */ |
2258 ConstantEvaluationAnalysisTask( | 2344 ConstantEvaluationAnalysisTask( |
2259 AnalysisContext context, ConstantEvaluationTarget constant) | 2345 AnalysisContext context, ConstantEvaluationTarget constant) |
(...skipping 3280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5540 AnalysisContext context, AnalysisTarget target) { | 5626 AnalysisContext context, AnalysisTarget target) { |
5541 return new StrongModeVerifyUnitTask(context, target); | 5627 return new StrongModeVerifyUnitTask(context, target); |
5542 } | 5628 } |
5543 } | 5629 } |
5544 | 5630 |
5545 /** | 5631 /** |
5546 * A task that builds [VERIFY_ERRORS] for a unit. | 5632 * A task that builds [VERIFY_ERRORS] for a unit. |
5547 */ | 5633 */ |
5548 class VerifyUnitTask extends SourceBasedAnalysisTask { | 5634 class VerifyUnitTask extends SourceBasedAnalysisTask { |
5549 /** | 5635 /** |
5550 * The name of the [RESOLVED_UNIT] input. | 5636 * The name of the [PENDING_ERRORS] input. |
5551 */ | 5637 */ |
5552 static const String UNIT_INPUT = 'UNIT_INPUT'; | 5638 static const String PENDING_ERRORS_INPUT = 'PENDING_ERRORS_INPUT'; |
5553 | 5639 |
5554 /** | 5640 /** |
5555 * The name of the input of a mapping from [REFERENCED_SOURCES] to their | 5641 * The name of the input of a mapping from [REFERENCED_SOURCES] to their |
5556 * [MODIFICATION_TIME]s. | 5642 * [MODIFICATION_TIME]s. |
5557 */ | 5643 */ |
5558 static const String REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT = | 5644 static const String REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT = |
5559 'REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT'; | 5645 'REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT'; |
5560 | 5646 |
5561 /** | 5647 /** |
5562 * The name of the [TYPE_PROVIDER] input. | 5648 * The name of the [TYPE_PROVIDER] input. |
5563 */ | 5649 */ |
5564 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 5650 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
5565 | 5651 |
5566 /** | 5652 /** |
5653 * The name of the [RESOLVED_UNIT] input. | |
5654 */ | |
5655 static const String UNIT_INPUT = 'UNIT_INPUT'; | |
5656 | |
5657 /** | |
5567 * The task descriptor describing this kind of task. | 5658 * The task descriptor describing this kind of task. |
5568 */ | 5659 */ |
5569 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('VerifyUnitTask', | 5660 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('VerifyUnitTask', |
5570 createTask, buildInputs, <ResultDescriptor>[VERIFY_ERRORS]); | 5661 createTask, buildInputs, <ResultDescriptor>[VERIFY_ERRORS]); |
5571 | 5662 |
5572 /** | 5663 /** |
5573 * The [ErrorReporter] to report errors to. | 5664 * The [ErrorReporter] to report errors to. |
5574 */ | 5665 */ |
5575 ErrorReporter errorReporter; | 5666 ErrorReporter errorReporter; |
5576 | 5667 |
(...skipping 10 matching lines...) Expand all Loading... | |
5587 TaskDescriptor get descriptor => DESCRIPTOR; | 5678 TaskDescriptor get descriptor => DESCRIPTOR; |
5588 | 5679 |
5589 @override | 5680 @override |
5590 void internalPerform() { | 5681 void internalPerform() { |
5591 RecordingErrorListener errorListener = new RecordingErrorListener(); | 5682 RecordingErrorListener errorListener = new RecordingErrorListener(); |
5592 Source source = getRequiredSource(); | 5683 Source source = getRequiredSource(); |
5593 errorReporter = new ErrorReporter(errorListener, source); | 5684 errorReporter = new ErrorReporter(errorListener, source); |
5594 // | 5685 // |
5595 // Prepare inputs. | 5686 // Prepare inputs. |
5596 // | 5687 // |
5597 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | |
5598 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 5688 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
5599 sourceTimeMap = | |
5600 getRequiredInput(REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT); | |
5601 CompilationUnitElement unitElement = unit.element; | 5689 CompilationUnitElement unitElement = unit.element; |
5602 LibraryElement libraryElement = unitElement.library; | 5690 LibraryElement libraryElement = unitElement.library; |
5603 if (libraryElement == null) { | 5691 if (libraryElement == null) { |
5604 throw new AnalysisException( | 5692 throw new AnalysisException( |
5605 'VerifyUnitTask verifying a unit with no library: ' | 5693 'VerifyUnitTask verifying a unit with no library: ' |
5606 '${unitElement.source.fullName}'); | 5694 '${unitElement.source.fullName}'); |
5607 } | 5695 } |
5696 List<PendingError> pendingErrors = getRequiredInput(PENDING_ERRORS_INPUT); | |
5697 sourceTimeMap = | |
5698 getRequiredInput(REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT); | |
5699 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | |
5608 // | 5700 // |
5609 // Validate the directives. | 5701 // Validate the directives. |
5610 // | 5702 // |
5611 validateDirectives(unit); | 5703 validateDirectives(unit); |
5612 // | 5704 // |
5613 // Use the ConstantVerifier to compute errors. | 5705 // Use the ConstantVerifier to compute errors. |
5614 // | 5706 // |
5615 ConstantVerifier constantVerifier = new ConstantVerifier( | 5707 ConstantVerifier constantVerifier = new ConstantVerifier( |
5616 errorReporter, libraryElement, typeProvider, context.declaredVariables); | 5708 errorReporter, libraryElement, typeProvider, context.declaredVariables); |
5617 unit.accept(constantVerifier); | 5709 unit.accept(constantVerifier); |
5618 // | 5710 // |
5619 // Use the ErrorVerifier to compute errors. | 5711 // Use the ErrorVerifier to compute errors. |
5620 // | 5712 // |
5621 ErrorVerifier errorVerifier = new ErrorVerifier( | 5713 ErrorVerifier errorVerifier = new ErrorVerifier( |
5622 errorReporter, | 5714 errorReporter, |
5623 libraryElement, | 5715 libraryElement, |
5624 typeProvider, | 5716 typeProvider, |
5625 new InheritanceManager(libraryElement), | 5717 new InheritanceManager(libraryElement), |
5626 context.analysisOptions.enableSuperMixins, | 5718 context.analysisOptions.enableSuperMixins, |
5627 context.analysisOptions.enableAssertMessage); | 5719 context.analysisOptions.enableAssertMessage); |
5628 unit.accept(errorVerifier); | 5720 unit.accept(errorVerifier); |
5629 | 5721 // |
5722 // Convert the pending errors into actual errors. | |
5723 // | |
5724 for (PendingError pendingError in pendingErrors) { | |
5725 errorListener.onError(pendingError.toAnalysisError()); | |
5726 } | |
5630 // | 5727 // |
5631 // Record outputs. | 5728 // Record outputs. |
5632 // | 5729 // |
5633 outputs[VERIFY_ERRORS] = getUniqueErrors(errorListener.errors); | 5730 outputs[VERIFY_ERRORS] = getUniqueErrors(errorListener.errors); |
5634 } | 5731 } |
5635 | 5732 |
5636 /** | 5733 /** |
5637 * Check each directive in the given [unit] to see if the referenced source | 5734 * Check each directive in the given [unit] to see if the referenced source |
5638 * exists and report an error if it does not. | 5735 * exists and report an error if it does not. |
5639 */ | 5736 */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5675 * input descriptors describing those inputs for a task with the | 5772 * input descriptors describing those inputs for a task with the |
5676 * given [target]. | 5773 * given [target]. |
5677 */ | 5774 */ |
5678 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 5775 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
5679 LibrarySpecificUnit unit = target; | 5776 LibrarySpecificUnit unit = target; |
5680 return <String, TaskInput>{ | 5777 return <String, TaskInput>{ |
5681 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(unit.library), | 5778 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(unit.library), |
5682 UNIT_INPUT: RESOLVED_UNIT.of(unit), | 5779 UNIT_INPUT: RESOLVED_UNIT.of(unit), |
5683 REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT: | 5780 REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT: |
5684 REFERENCED_SOURCES.of(unit.library).toMapOf(MODIFICATION_TIME), | 5781 REFERENCED_SOURCES.of(unit.library).toMapOf(MODIFICATION_TIME), |
5782 PENDING_ERRORS_INPUT: PENDING_ERRORS.of(unit), | |
5783 'requiredConstants': REQUIRED_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE), | |
5685 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) | 5784 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) |
5686 }; | 5785 }; |
5687 } | 5786 } |
5688 | 5787 |
5689 /** | 5788 /** |
5690 * Create a [VerifyUnitTask] based on the given [target] in | 5789 * Create a [VerifyUnitTask] based on the given [target] in |
5691 * the given [context]. | 5790 * the given [context]. |
5692 */ | 5791 */ |
5693 static VerifyUnitTask createTask( | 5792 static VerifyUnitTask createTask( |
5694 AnalysisContext context, AnalysisTarget target) { | 5793 AnalysisContext context, AnalysisTarget target) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5800 | 5899 |
5801 @override | 5900 @override |
5802 bool moveNext() { | 5901 bool moveNext() { |
5803 if (_newSources.isEmpty) { | 5902 if (_newSources.isEmpty) { |
5804 return false; | 5903 return false; |
5805 } | 5904 } |
5806 currentTarget = _newSources.removeLast(); | 5905 currentTarget = _newSources.removeLast(); |
5807 return true; | 5906 return true; |
5808 } | 5907 } |
5809 } | 5908 } |
OLD | NEW |