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

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

Issue 1687573002: Collect defined elements together with used elements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months 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/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 /** 261 /**
262 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this 262 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this
263 * compilation unit (without requiring that the AST for it still be in cache). 263 * compilation unit (without requiring that the AST for it still be in cache).
264 * 264 *
265 * The result is only available for [LibrarySpecificUnit]s. 265 * The result is only available for [LibrarySpecificUnit]s.
266 */ 266 */
267 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 = 267 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 =
268 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false); 268 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false);
269 269
270 /** 270 /**
271 * The [Element]s defined in a [LibrarySpecificUnit].
272 */
273 final ListResultDescriptor<Element> DEFINED_ELEMENTS =
274 new ListResultDescriptor<Element>('DEFINED_ELEMENTS', null,
275 cachingPolicy: ELEMENT_CACHING_POLICY);
276
277 /**
271 * The sources representing the export closure of a library. 278 * The sources representing the export closure of a library.
272 * The [Source]s include only library sources, not their units. 279 * The [Source]s include only library sources, not their units.
273 * 280 *
274 * The result is only available for [Source]s representing a library. 281 * The result is only available for [Source]s representing a library.
275 */ 282 */
276 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 283 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
277 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 284 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
278 285
279 /** 286 /**
280 * The errors produced while generating hints a compilation unit. 287 * The errors produced while generating hints a compilation unit.
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 */ 2538 */
2532 static const String UNIT_INPUT = 'UNIT_INPUT'; 2539 static const String UNIT_INPUT = 'UNIT_INPUT';
2533 2540
2534 /** 2541 /**
2535 * The task descriptor describing this kind of task. 2542 * The task descriptor describing this kind of task.
2536 */ 2543 */
2537 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2544 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2538 'GatherUsedLocalElementsTask', 2545 'GatherUsedLocalElementsTask',
2539 createTask, 2546 createTask,
2540 buildInputs, 2547 buildInputs,
2541 <ResultDescriptor>[USED_LOCAL_ELEMENTS]); 2548 <ResultDescriptor>[DEFINED_ELEMENTS, USED_LOCAL_ELEMENTS]);
2542 2549
2543 GatherUsedLocalElementsTask( 2550 GatherUsedLocalElementsTask(
2544 InternalAnalysisContext context, AnalysisTarget target) 2551 InternalAnalysisContext context, AnalysisTarget target)
2545 : super(context, target); 2552 : super(context, target);
2546 2553
2547 @override 2554 @override
2548 TaskDescriptor get descriptor => DESCRIPTOR; 2555 TaskDescriptor get descriptor => DESCRIPTOR;
2549 2556
2550 @override 2557 @override
2551 void internalPerform() { 2558 void internalPerform() {
2552 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 2559 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2553 CompilationUnitElement unitElement = unit.element; 2560 CompilationUnitElement unitElement = unit.element;
2554 LibraryElement libraryElement = unitElement.library; 2561 LibraryElement libraryElement = unitElement.library;
2555 // 2562 //
2556 // Prepare used local elements. 2563 // Prepare defined and used local elements.
2557 // 2564 //
2558 GatherUsedLocalElementsVisitor visitor = 2565 GatherUsedLocalElementsVisitor visitor =
2559 new GatherUsedLocalElementsVisitor(libraryElement); 2566 new GatherUsedLocalElementsVisitor(libraryElement);
2560 unit.accept(visitor); 2567 unit.accept(visitor);
2561 // 2568 //
2562 // Record outputs. 2569 // Record outputs.
2563 // 2570 //
2571 outputs[DEFINED_ELEMENTS] = visitor.definedElements;
2564 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; 2572 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements;
2565 } 2573 }
2566 2574
2567 /** 2575 /**
2568 * Return a map from the names of the inputs of this kind of task to the task 2576 * Return a map from the names of the inputs of this kind of task to the task
2569 * input descriptors describing those inputs for a task with the 2577 * input descriptors describing those inputs for a task with the
2570 * given [target]. 2578 * given [target].
2571 */ 2579 */
2572 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2580 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2573 LibrarySpecificUnit unit = target; 2581 LibrarySpecificUnit unit = target;
(...skipping 13 matching lines...) Expand all
2587 /** 2595 /**
2588 * A task that generates [HINTS] for a unit. 2596 * A task that generates [HINTS] for a unit.
2589 */ 2597 */
2590 class GenerateHintsTask extends SourceBasedAnalysisTask { 2598 class GenerateHintsTask extends SourceBasedAnalysisTask {
2591 /** 2599 /**
2592 * The name of the [RESOLVED_UNIT10] input. 2600 * The name of the [RESOLVED_UNIT10] input.
2593 */ 2601 */
2594 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; 2602 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
2595 2603
2596 /** 2604 /**
2605 * The name of a list of [DEFINED_ELEMENTS] for each library unit input.
2606 */
2607 static const String DEFINED_ELEMENTS_INPUT = 'DEFINED_ELEMENTS';
2608
2609 /**
2597 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. 2610 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
2598 */ 2611 */
2599 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS'; 2612 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
2600 2613
2601 /** 2614 /**
2602 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input. 2615 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
2603 */ 2616 */
2604 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS'; 2617 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS';
2605 2618
2606 /** 2619 /**
(...skipping 25 matching lines...) Expand all
2632 // 2645 //
2633 RecordingErrorListener errorListener = new RecordingErrorListener(); 2646 RecordingErrorListener errorListener = new RecordingErrorListener();
2634 Source source = getRequiredSource(); 2647 Source source = getRequiredSource();
2635 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 2648 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
2636 // 2649 //
2637 // Prepare inputs. 2650 // Prepare inputs.
2638 // 2651 //
2639 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); 2652 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
2640 List<UsedImportedElements> usedImportedElementsList = 2653 List<UsedImportedElements> usedImportedElementsList =
2641 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT); 2654 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT);
2655 List<List<Element>> definedElementsList =
2656 getRequiredInput(DEFINED_ELEMENTS_INPUT);
2642 List<UsedLocalElements> usedLocalElementsList = 2657 List<UsedLocalElements> usedLocalElementsList =
2643 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT); 2658 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT);
2644 CompilationUnitElement unitElement = unit.element; 2659 CompilationUnitElement unitElement = unit.element;
2645 LibraryElement libraryElement = unitElement.library; 2660 LibraryElement libraryElement = unitElement.library;
2646 TypeSystem typeSystem = context.typeSystem; 2661 TypeSystem typeSystem = context.typeSystem;
2647 2662
2648 // 2663 //
2649 // Generate errors. 2664 // Generate errors.
2650 // 2665 //
2651 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem)); 2666 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem));
2652 // Verify imports. 2667 // Verify imports.
2653 { 2668 {
2654 ImportsVerifier verifier = new ImportsVerifier(); 2669 ImportsVerifier verifier = new ImportsVerifier();
2655 verifier.addImports(unit); 2670 verifier.addImports(unit);
2656 usedImportedElementsList.forEach(verifier.removeUsedElements); 2671 usedImportedElementsList.forEach(verifier.removeUsedElements);
2657 verifier.generateDuplicateImportHints(errorReporter); 2672 verifier.generateDuplicateImportHints(errorReporter);
2658 verifier.generateUnusedImportHints(errorReporter); 2673 verifier.generateUnusedImportHints(errorReporter);
2659 } 2674 }
2660 // Unused local elements. 2675 // Unused local elements.
2661 { 2676 {
2662 UsedLocalElements usedElements = 2677 UsedLocalElements usedElements =
2663 new UsedLocalElements.merge(usedLocalElementsList); 2678 new UsedLocalElements.merge(usedLocalElementsList);
2664 UnusedLocalElementsVerifier visitor = 2679 UnusedLocalElementsVerifier visitor =
2665 new UnusedLocalElementsVerifier(errorListener, usedElements); 2680 new UnusedLocalElementsVerifier(errorListener, usedElements);
2666 unitElement.accept(visitor); 2681 for (List<Element> definedElements in definedElementsList) {
2682 for (Element element in definedElements) {
2683 visitor.visitElement(element);
2684 }
2685 }
2667 } 2686 }
2668 // Dart2js analysis. 2687 // Dart2js analysis.
2669 if (analysisOptions.dart2jsHint) { 2688 if (analysisOptions.dart2jsHint) {
2670 unit.accept(new Dart2JSVerifier(errorReporter)); 2689 unit.accept(new Dart2JSVerifier(errorReporter));
2671 } 2690 }
2672 // Dart best practices. 2691 // Dart best practices.
2673 InheritanceManager inheritanceManager = 2692 InheritanceManager inheritanceManager =
2674 new InheritanceManager(libraryElement); 2693 new InheritanceManager(libraryElement);
2675 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 2694 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2676 2695
(...skipping 11 matching lines...) Expand all
2688 /** 2707 /**
2689 * Return a map from the names of the inputs of this kind of task to the task 2708 * Return a map from the names of the inputs of this kind of task to the task
2690 * input descriptors describing those inputs for a task with the 2709 * input descriptors describing those inputs for a task with the
2691 * given [target]. 2710 * given [target].
2692 */ 2711 */
2693 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2712 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2694 LibrarySpecificUnit unit = target; 2713 LibrarySpecificUnit unit = target;
2695 Source libSource = unit.library; 2714 Source libSource = unit.library;
2696 return <String, TaskInput>{ 2715 return <String, TaskInput>{
2697 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit), 2716 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit),
2717 DEFINED_ELEMENTS_INPUT:
2718 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(DEFINED_ELEMENTS),
2698 USED_LOCAL_ELEMENTS_INPUT: 2719 USED_LOCAL_ELEMENTS_INPUT:
2699 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_LOCAL_ELEMENTS), 2720 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_LOCAL_ELEMENTS),
2700 USED_IMPORTED_ELEMENTS_INPUT: 2721 USED_IMPORTED_ELEMENTS_INPUT:
2701 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_IMPORTED_ELEMENTS), 2722 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_IMPORTED_ELEMENTS),
2702 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 2723 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2703 }; 2724 };
2704 } 2725 }
2705 2726
2706 /** 2727 /**
2707 * Create a [GenerateHintsTask] based on the given [target] in 2728 * Create a [GenerateHintsTask] based on the given [target] in
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after
5280 5301
5281 @override 5302 @override
5282 bool moveNext() { 5303 bool moveNext() {
5283 if (_newSources.isEmpty) { 5304 if (_newSources.isEmpty) {
5284 return false; 5305 return false;
5285 } 5306 }
5286 currentTarget = _newSources.removeLast(); 5307 currentTarget = _newSources.removeLast();
5287 return true; 5308 return true;
5288 } 5309 }
5289 } 5310 }
OLDNEW
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698