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

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

Issue 1321523002: Add a task to partially resolve a compilation unit (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/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 19 matching lines...) Expand all
30 import 'package:analyzer/task/general.dart'; 30 import 'package:analyzer/task/general.dart';
31 import 'package:analyzer/task/model.dart'; 31 import 'package:analyzer/task/model.dart';
32 32
33 /** 33 /**
34 * The [ResultCachingPolicy] for ASTs. 34 * The [ResultCachingPolicy] for ASTs.
35 */ 35 */
36 const ResultCachingPolicy AST_CACHING_POLICY = 36 const ResultCachingPolicy AST_CACHING_POLICY =
37 const SimpleResultCachingPolicy(8192, 8192); 37 const SimpleResultCachingPolicy(8192, 8192);
38 38
39 /** 39 /**
40 * The [ResultCachingPolicy] for [Element]s.
41 */
42 const ResultCachingPolicy ELEMENT_CACHING_POLICY =
43 const SimpleResultCachingPolicy(-1, -1);
44
45 /**
46 * The [ResultCachingPolicy] for [TOKEN_STREAM].
47 */
48 const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
49 const SimpleResultCachingPolicy(1, 1);
50
51 /**
40 * The errors produced while resolving a library directives. 52 * The errors produced while resolving a library directives.
41 * 53 *
42 * The list will be empty if there were no errors, but will not be `null`. 54 * The list will be empty if there were no errors, but will not be `null`.
43 * 55 *
44 * The result is only available for [Source]s representing a library. 56 * The result is only available for [Source]s representing a library.
45 */ 57 */
46 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS = 58 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS =
47 new ListResultDescriptor<AnalysisError>( 59 new ListResultDescriptor<AnalysisError>(
48 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS); 60 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
49 61
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 125
114 /** 126 /**
115 * The sources representing the libraries that include a given source as a part. 127 * The sources representing the libraries that include a given source as a part.
116 * 128 *
117 * The result is only available for [Source]s representing a compilation unit. 129 * The result is only available for [Source]s representing a compilation unit.
118 */ 130 */
119 final ListResultDescriptor<Source> CONTAINING_LIBRARIES = 131 final ListResultDescriptor<Source> CONTAINING_LIBRARIES =
120 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST); 132 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST);
121 133
122 /** 134 /**
123 * The [ResultCachingPolicy] for [Element]s.
124 */
125 const ResultCachingPolicy ELEMENT_CACHING_POLICY =
126 const SimpleResultCachingPolicy(-1, -1);
127
128 /**
129 * The sources representing the export closure of a library. 135 * The sources representing the export closure of a library.
130 * The [Source]s include only library sources, not their units. 136 * The [Source]s include only library sources, not their units.
131 * 137 *
132 * The result is only available for [Source]s representing a library. 138 * The result is only available for [Source]s representing a library.
133 */ 139 */
134 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 140 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
135 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 141 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
136 142
137 /** 143 /**
138 * The errors produced while generating hints a compilation unit. 144 * The errors produced while generating hints a compilation unit.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 * 256 *
251 * The list will be empty if there were no errors, but will not be `null`. 257 * The list will be empty if there were no errors, but will not be `null`.
252 * 258 *
253 * The result is only available for [Source]s representing a compilation unit. 259 * The result is only available for [Source]s representing a compilation unit.
254 */ 260 */
255 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = 261 final ListResultDescriptor<AnalysisError> PARSE_ERRORS =
256 new ListResultDescriptor<AnalysisError>( 262 new ListResultDescriptor<AnalysisError>(
257 'PARSE_ERRORS', AnalysisError.NO_ERRORS); 263 'PARSE_ERRORS', AnalysisError.NO_ERRORS);
258 264
259 /** 265 /**
266 * The errors produced while resolving references outside of function bodies.
267 *
268 * The list will be empty if there were no errors, but will not be `null`.
269 *
270 * The result is only available for [LibrarySpecificUnit]s.
271 */
272 final ListResultDescriptor<AnalysisError> PARTIALLY_RESOLVE_REFERENCES_ERRORS =
273 new ListResultDescriptor<AnalysisError>(
274 'PARTIALLY_RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS);
275
276 /**
260 * The names (resolved and not) referenced by a unit. 277 * The names (resolved and not) referenced by a unit.
261 * 278 *
262 * The result is only available for [Source]s representing a compilation unit. 279 * The result is only available for [Source]s representing a compilation unit.
263 */ 280 */
264 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = 281 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES =
265 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); 282 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null);
266 283
267 /** 284 /**
268 * The errors produced while resolving references. 285 * The errors produced while resolving references.
269 * 286 *
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 * 341 *
325 * [RESOLVED_UNIT3] plus resolved local variables and formal parameters. 342 * [RESOLVED_UNIT3] plus resolved local variables and formal parameters.
326 * 343 *
327 * The result is only available for [LibrarySpecificUnit]s. 344 * The result is only available for [LibrarySpecificUnit]s.
328 */ 345 */
329 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = 346 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
330 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null, 347 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null,
331 cachingPolicy: AST_CACHING_POLICY); 348 cachingPolicy: AST_CACHING_POLICY);
332 349
333 /** 350 /**
351 * The resolved [CompilationUnit] associated with a compilation unit in which
352 * elements and types have been initially resolved outside of method bodies in
353 * addition to everything that is true of a [RESOLVED_UNIT4].
354 *
355 * The result is only available for [LibrarySpecificUnit]s.
356 *
357 * TODO(brianwilkerson) Rename this to RESOLVED_UNIT_5.
Paul Berry 2015/08/26 17:05:23 Why not rename it now?
Brian Wilkerson 2015/08/26 20:33:53 No good reason (any more). Done.
358 */
359 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4_1 =
360 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4_1', null,
361 cachingPolicy: AST_CACHING_POLICY);
362
363 /**
334 * The resolved [CompilationUnit] associated with a compilation unit, with 364 * The resolved [CompilationUnit] associated with a compilation unit, with
335 * constants not yet resolved. 365 * constants not yet resolved.
336 * 366 *
337 * The result is only available for [LibrarySpecificUnit]s. 367 * The result is only available for [LibrarySpecificUnit]s.
338 */ 368 */
339 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 = 369 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
340 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null, 370 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null,
341 cachingPolicy: AST_CACHING_POLICY); 371 cachingPolicy: AST_CACHING_POLICY);
342 372
343 /** 373 /**
344 * The errors produced while scanning a compilation unit. 374 * The errors produced while scanning a compilation unit.
345 * 375 *
346 * The list will be empty if there were no errors, but will not be `null`. 376 * The list will be empty if there were no errors, but will not be `null`.
347 * 377 *
348 * The result is only available for [Source]s representing a compilation unit. 378 * The result is only available for [Source]s representing a compilation unit.
349 */ 379 */
350 final ListResultDescriptor<AnalysisError> SCAN_ERRORS = 380 final ListResultDescriptor<AnalysisError> SCAN_ERRORS =
351 new ListResultDescriptor<AnalysisError>( 381 new ListResultDescriptor<AnalysisError>(
352 'SCAN_ERRORS', AnalysisError.NO_ERRORS); 382 'SCAN_ERRORS', AnalysisError.NO_ERRORS);
353 383
354 /** 384 /**
355 * The [ResultCachingPolicy] for [TOKEN_STREAM].
356 */
357 const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
358 const SimpleResultCachingPolicy(1, 1);
359
360 /**
361 * The [TypeProvider] of the [AnalysisContext]. 385 * The [TypeProvider] of the [AnalysisContext].
362 */ 386 */
363 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = 387 final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
364 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); 388 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null);
365 389
366 /** 390 /**
367 * The [UsedImportedElements] of a [LibrarySpecificUnit]. 391 * The [UsedImportedElements] of a [LibrarySpecificUnit].
368 */ 392 */
369 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS = 393 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS =
370 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null, 394 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null,
(...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2594 if (code == UriValidationCode.INVALID_URI) { 2618 if (code == UriValidationCode.INVALID_URI) {
2595 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset, 2619 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
2596 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); 2620 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
2597 return null; 2621 return null;
2598 } 2622 }
2599 throw new AnalysisException('Failed to handle validation code: $code'); 2623 throw new AnalysisException('Failed to handle validation code: $code');
2600 } 2624 }
2601 } 2625 }
2602 2626
2603 /** 2627 /**
2628 * A task that builds [RESOLVED_UNIT4_1] for a unit.
2629 */
2630 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask {
2631 /**
2632 * The name of the [LIBRARY_ELEMENT5] input.
2633 */
2634 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2635
2636 /**
2637 * The name of the [RESOLVED_UNIT4] input.
2638 */
2639 static const String UNIT_INPUT = 'UNIT_INPUT';
2640
2641 /**
2642 * The name of the [TYPE_PROVIDER] input.
2643 */
2644 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2645
2646 /**
2647 * The task descriptor describing this kind of task.
2648 */
2649 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2650 'PartiallyResolveUnitReferencesTask',
2651 createTask,
2652 buildInputs, <ResultDescriptor>[
2653 PARTIALLY_RESOLVE_REFERENCES_ERRORS,
2654 RESOLVED_UNIT4_1
2655 ]);
2656
2657 PartiallyResolveUnitReferencesTask(
2658 InternalAnalysisContext context, AnalysisTarget target)
2659 : super(context, target);
2660
2661 @override
2662 TaskDescriptor get descriptor => DESCRIPTOR;
2663
2664 @override
2665 void internalPerform() {
2666 RecordingErrorListener errorListener = new RecordingErrorListener();
2667 //
2668 // Prepare inputs.
2669 //
2670 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
2671 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2672 CompilationUnitElement unitElement = unit.element;
2673 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2674 //
2675 // Resolve references.
2676 //
2677 InheritanceManager inheritanceManager =
2678 new InheritanceManager(libraryElement);
2679 // TODO(brianwilkerson) Improve performance by not resolving anything inside
2680 // function bodies. Function bodies will be resolved later so this is wasted
2681 // effort.
2682 AstVisitor visitor = new ResolverVisitor(
2683 libraryElement, unitElement.source, typeProvider, errorListener,
2684 inheritanceManager: inheritanceManager);
2685 unit.accept(visitor);
2686 //
2687 // Record outputs.
2688 //
2689 outputs[PARTIALLY_RESOLVE_REFERENCES_ERRORS] =
2690 removeDuplicateErrors(errorListener.errors);
2691 outputs[RESOLVED_UNIT4_1] = unit;
2692 }
2693
2694 /**
2695 * Return a map from the names of the inputs of this kind of task to the task
2696 * input descriptors describing those inputs for a task with the
2697 * given [target].
2698 */
2699 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2700 LibrarySpecificUnit unit = target;
2701 return <String, TaskInput>{
2702 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE
2703 .of(unit.library)
2704 .toListOf(LIBRARY_ELEMENT5),
2705 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
2706 UNIT_INPUT: RESOLVED_UNIT4.of(unit),
2707 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2708 };
2709 }
2710
2711 /**
2712 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target]
2713 * in the given [context].
2714 */
2715 static PartiallyResolveUnitReferencesTask createTask(
2716 AnalysisContext context, AnalysisTarget target) {
2717 return new PartiallyResolveUnitReferencesTask(context, target);
2718 }
2719 }
2720
2721 /**
2604 * The helper for building the public [Namespace] of a [LibraryElement]. 2722 * The helper for building the public [Namespace] of a [LibraryElement].
2605 */ 2723 */
2606 class PublicNamespaceBuilder { 2724 class PublicNamespaceBuilder {
2607 final HashMap<String, Element> definedNames = new HashMap<String, Element>(); 2725 final HashMap<String, Element> definedNames = new HashMap<String, Element>();
2608 2726
2609 /** 2727 /**
2610 * Build a public [Namespace] of the given [library]. 2728 * Build a public [Namespace] of the given [library].
2611 */ 2729 */
2612 Namespace build(LibraryElement library) { 2730 Namespace build(LibraryElement library) {
2613 definedNames.clear(); 2731 definedNames.clear();
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 3603
3486 @override 3604 @override
3487 bool moveNext() { 3605 bool moveNext() {
3488 if (_newSources.isEmpty) { 3606 if (_newSources.isEmpty) {
3489 return false; 3607 return false;
3490 } 3608 }
3491 currentTarget = _newSources.removeLast(); 3609 currentTarget = _newSources.removeLast();
3492 return true; 3610 return true;
3493 } 3611 }
3494 } 3612 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.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