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

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

Issue 1729523002: Revert collecting defined 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 /** 264 /**
265 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this 265 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this
266 * compilation unit (without requiring that the AST for it still be in cache). 266 * compilation unit (without requiring that the AST for it still be in cache).
267 * 267 *
268 * The result is only available for [LibrarySpecificUnit]s. 268 * The result is only available for [LibrarySpecificUnit]s.
269 */ 269 */
270 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 = 270 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 =
271 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false); 271 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false);
272 272
273 /** 273 /**
274 * The [Element]s defined in a [LibrarySpecificUnit].
275 */
276 final ListResultDescriptor<Element> DEFINED_ELEMENTS =
277 new ListResultDescriptor<Element>('DEFINED_ELEMENTS', null,
278 cachingPolicy: ELEMENT_CACHING_POLICY);
279
280 /**
281 * The sources representing the export closure of a library. 274 * The sources representing the export closure of a library.
282 * The [Source]s include only library sources, not their units. 275 * The [Source]s include only library sources, not their units.
283 * 276 *
284 * The result is only available for [Source]s representing a library. 277 * The result is only available for [Source]s representing a library.
285 */ 278 */
286 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 279 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
287 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 280 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
288 281
289 /** 282 /**
290 * The errors produced while generating hints a compilation unit. 283 * The errors produced while generating hints a compilation unit.
(...skipping 2262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 */ 2546 */
2554 static const String UNIT_INPUT = 'UNIT_INPUT'; 2547 static const String UNIT_INPUT = 'UNIT_INPUT';
2555 2548
2556 /** 2549 /**
2557 * The task descriptor describing this kind of task. 2550 * The task descriptor describing this kind of task.
2558 */ 2551 */
2559 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2552 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2560 'GatherUsedLocalElementsTask', 2553 'GatherUsedLocalElementsTask',
2561 createTask, 2554 createTask,
2562 buildInputs, 2555 buildInputs,
2563 <ResultDescriptor>[DEFINED_ELEMENTS, USED_LOCAL_ELEMENTS]); 2556 <ResultDescriptor>[USED_LOCAL_ELEMENTS]);
2564 2557
2565 GatherUsedLocalElementsTask( 2558 GatherUsedLocalElementsTask(
2566 InternalAnalysisContext context, AnalysisTarget target) 2559 InternalAnalysisContext context, AnalysisTarget target)
2567 : super(context, target); 2560 : super(context, target);
2568 2561
2569 @override 2562 @override
2570 TaskDescriptor get descriptor => DESCRIPTOR; 2563 TaskDescriptor get descriptor => DESCRIPTOR;
2571 2564
2572 @override 2565 @override
2573 void internalPerform() { 2566 void internalPerform() {
2574 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 2567 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2575 CompilationUnitElement unitElement = unit.element; 2568 CompilationUnitElement unitElement = unit.element;
2576 LibraryElement libraryElement = unitElement.library; 2569 LibraryElement libraryElement = unitElement.library;
2577 // 2570 //
2578 // Prepare defined and used local elements. 2571 // Prepare used local elements.
2579 // 2572 //
2580 GatherUsedLocalElementsVisitor visitor = 2573 GatherUsedLocalElementsVisitor visitor =
2581 new GatherUsedLocalElementsVisitor(libraryElement); 2574 new GatherUsedLocalElementsVisitor(libraryElement);
2582 unit.accept(visitor); 2575 unit.accept(visitor);
2583 // 2576 //
2584 // Record outputs. 2577 // Record outputs.
2585 // 2578 //
2586 outputs[DEFINED_ELEMENTS] = visitor.definedElements;
2587 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; 2579 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements;
2588 } 2580 }
2589 2581
2590 /** 2582 /**
2591 * Return a map from the names of the inputs of this kind of task to the task 2583 * Return a map from the names of the inputs of this kind of task to the task
2592 * input descriptors describing those inputs for a task with the 2584 * input descriptors describing those inputs for a task with the
2593 * given [target]. 2585 * given [target].
2594 */ 2586 */
2595 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2587 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2596 LibrarySpecificUnit unit = target; 2588 LibrarySpecificUnit unit = target;
(...skipping 13 matching lines...) Expand all
2610 /** 2602 /**
2611 * A task that generates [HINTS] for a unit. 2603 * A task that generates [HINTS] for a unit.
2612 */ 2604 */
2613 class GenerateHintsTask extends SourceBasedAnalysisTask { 2605 class GenerateHintsTask extends SourceBasedAnalysisTask {
2614 /** 2606 /**
2615 * The name of the [RESOLVED_UNIT10] input. 2607 * The name of the [RESOLVED_UNIT10] input.
2616 */ 2608 */
2617 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; 2609 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
2618 2610
2619 /** 2611 /**
2620 * The name of a list of [DEFINED_ELEMENTS] for each library unit input.
2621 */
2622 static const String DEFINED_ELEMENTS_INPUT = 'DEFINED_ELEMENTS';
2623
2624 /**
2625 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. 2612 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
2626 */ 2613 */
2627 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS'; 2614 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
2628 2615
2629 /** 2616 /**
2630 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input. 2617 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
2631 */ 2618 */
2632 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS'; 2619 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS';
2633 2620
2634 /** 2621 /**
(...skipping 25 matching lines...) Expand all
2660 // 2647 //
2661 RecordingErrorListener errorListener = new RecordingErrorListener(); 2648 RecordingErrorListener errorListener = new RecordingErrorListener();
2662 Source source = getRequiredSource(); 2649 Source source = getRequiredSource();
2663 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 2650 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
2664 // 2651 //
2665 // Prepare inputs. 2652 // Prepare inputs.
2666 // 2653 //
2667 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); 2654 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
2668 List<UsedImportedElements> usedImportedElementsList = 2655 List<UsedImportedElements> usedImportedElementsList =
2669 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT); 2656 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT);
2670 List<List<Element>> definedElementsList =
2671 getRequiredInput(DEFINED_ELEMENTS_INPUT);
2672 List<UsedLocalElements> usedLocalElementsList = 2657 List<UsedLocalElements> usedLocalElementsList =
2673 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT); 2658 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT);
2674 CompilationUnitElement unitElement = unit.element; 2659 CompilationUnitElement unitElement = unit.element;
2675 LibraryElement libraryElement = unitElement.library; 2660 LibraryElement libraryElement = unitElement.library;
2676 TypeSystem typeSystem = context.typeSystem; 2661 TypeSystem typeSystem = context.typeSystem;
2677 2662
2678 // 2663 //
2679 // Generate errors. 2664 // Generate errors.
2680 // 2665 //
2681 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem)); 2666 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem));
2682 // Verify imports. 2667 // Verify imports.
2683 { 2668 {
2684 ImportsVerifier verifier = new ImportsVerifier(); 2669 ImportsVerifier verifier = new ImportsVerifier();
2685 verifier.addImports(unit); 2670 verifier.addImports(unit);
2686 usedImportedElementsList.forEach(verifier.removeUsedElements); 2671 usedImportedElementsList.forEach(verifier.removeUsedElements);
2687 verifier.generateDuplicateImportHints(errorReporter); 2672 verifier.generateDuplicateImportHints(errorReporter);
2688 verifier.generateUnusedImportHints(errorReporter); 2673 verifier.generateUnusedImportHints(errorReporter);
2689 } 2674 }
2690 // Unused local elements. 2675 // Unused local elements.
2691 { 2676 {
2692 UsedLocalElements usedElements = 2677 UsedLocalElements usedElements =
2693 new UsedLocalElements.merge(usedLocalElementsList); 2678 new UsedLocalElements.merge(usedLocalElementsList);
2694 UnusedLocalElementsVerifier visitor = 2679 UnusedLocalElementsVerifier visitor =
2695 new UnusedLocalElementsVerifier(errorListener, usedElements); 2680 new UnusedLocalElementsVerifier(errorListener, usedElements);
2696 for (List<Element> definedElements in definedElementsList) { 2681 unitElement.accept(visitor);
2697 for (Element element in definedElements) {
2698 element.accept(visitor);
2699 }
2700 }
2701 } 2682 }
2702 // Dart2js analysis. 2683 // Dart2js analysis.
2703 if (analysisOptions.dart2jsHint) { 2684 if (analysisOptions.dart2jsHint) {
2704 unit.accept(new Dart2JSVerifier(errorReporter)); 2685 unit.accept(new Dart2JSVerifier(errorReporter));
2705 } 2686 }
2706 // Dart best practices. 2687 // Dart best practices.
2707 InheritanceManager inheritanceManager = 2688 InheritanceManager inheritanceManager =
2708 new InheritanceManager(libraryElement); 2689 new InheritanceManager(libraryElement);
2709 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 2690 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2710 2691
(...skipping 11 matching lines...) Expand all
2722 /** 2703 /**
2723 * Return a map from the names of the inputs of this kind of task to the task 2704 * Return a map from the names of the inputs of this kind of task to the task
2724 * input descriptors describing those inputs for a task with the 2705 * input descriptors describing those inputs for a task with the
2725 * given [target]. 2706 * given [target].
2726 */ 2707 */
2727 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2708 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2728 LibrarySpecificUnit unit = target; 2709 LibrarySpecificUnit unit = target;
2729 Source libSource = unit.library; 2710 Source libSource = unit.library;
2730 return <String, TaskInput>{ 2711 return <String, TaskInput>{
2731 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit), 2712 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit),
2732 DEFINED_ELEMENTS_INPUT:
2733 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(DEFINED_ELEMENTS),
2734 USED_LOCAL_ELEMENTS_INPUT: 2713 USED_LOCAL_ELEMENTS_INPUT:
2735 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_LOCAL_ELEMENTS), 2714 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_LOCAL_ELEMENTS),
2736 USED_IMPORTED_ELEMENTS_INPUT: 2715 USED_IMPORTED_ELEMENTS_INPUT:
2737 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_IMPORTED_ELEMENTS), 2716 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_IMPORTED_ELEMENTS),
2738 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 2717 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2739 }; 2718 };
2740 } 2719 }
2741 2720
2742 /** 2721 /**
2743 * Create a [GenerateHintsTask] based on the given [target] in 2722 * Create a [GenerateHintsTask] based on the given [target] in
(...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
5279 5258
5280 @override 5259 @override
5281 bool moveNext() { 5260 bool moveNext() {
5282 if (_newSources.isEmpty) { 5261 if (_newSources.isEmpty) {
5283 return false; 5262 return false;
5284 } 5263 }
5285 currentTarget = _newSources.removeLast(); 5264 currentTarget = _newSources.removeLast();
5286 return true; 5265 return true;
5287 } 5266 }
5288 } 5267 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698