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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 46d86e5e14b6a15756dae09df7d472b261f4ca57..9a23538dc2749d9a75b536269faec00a0a9cb9d5 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -37,6 +37,18 @@ const ResultCachingPolicy AST_CACHING_POLICY =
const SimpleResultCachingPolicy(8192, 8192);
/**
+ * The [ResultCachingPolicy] for [Element]s.
+ */
+const ResultCachingPolicy ELEMENT_CACHING_POLICY =
+ const SimpleResultCachingPolicy(-1, -1);
+
+/**
+ * The [ResultCachingPolicy] for [TOKEN_STREAM].
+ */
+const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
+ const SimpleResultCachingPolicy(1, 1);
+
+/**
* The errors produced while resolving a library directives.
*
* The list will be empty if there were no errors, but will not be `null`.
@@ -120,12 +132,6 @@ final ListResultDescriptor<Source> CONTAINING_LIBRARIES =
new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST);
/**
- * The [ResultCachingPolicy] for [Element]s.
- */
-const ResultCachingPolicy ELEMENT_CACHING_POLICY =
- const SimpleResultCachingPolicy(-1, -1);
-
-/**
* The sources representing the export closure of a library.
* The [Source]s include only library sources, not their units.
*
@@ -257,6 +263,17 @@ final ListResultDescriptor<AnalysisError> PARSE_ERRORS =
'PARSE_ERRORS', AnalysisError.NO_ERRORS);
/**
+ * The errors produced while resolving references outside of function bodies.
+ *
+ * The list will be empty if there were no errors, but will not be `null`.
+ *
+ * The result is only available for [LibrarySpecificUnit]s.
+ */
+final ListResultDescriptor<AnalysisError> PARTIALLY_RESOLVE_REFERENCES_ERRORS =
+ new ListResultDescriptor<AnalysisError>(
+ 'PARTIALLY_RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS);
+
+/**
* The names (resolved and not) referenced by a unit.
*
* The result is only available for [Source]s representing a compilation unit.
@@ -331,6 +348,19 @@ final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
cachingPolicy: AST_CACHING_POLICY);
/**
+ * The resolved [CompilationUnit] associated with a compilation unit in which
+ * elements and types have been initially resolved outside of method bodies in
+ * addition to everything that is true of a [RESOLVED_UNIT4].
+ *
+ * The result is only available for [LibrarySpecificUnit]s.
+ *
+ * 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.
+ */
+final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4_1 =
+ new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4_1', null,
+ cachingPolicy: AST_CACHING_POLICY);
+
+/**
* The resolved [CompilationUnit] associated with a compilation unit, with
* constants not yet resolved.
*
@@ -352,12 +382,6 @@ final ListResultDescriptor<AnalysisError> SCAN_ERRORS =
'SCAN_ERRORS', AnalysisError.NO_ERRORS);
/**
- * The [ResultCachingPolicy] for [TOKEN_STREAM].
- */
-const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
- const SimpleResultCachingPolicy(1, 1);
-
-/**
* The [TypeProvider] of the [AnalysisContext].
*/
final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
@@ -2601,6 +2625,100 @@ class ParseDartTask extends SourceBasedAnalysisTask {
}
/**
+ * A task that builds [RESOLVED_UNIT4_1] for a unit.
+ */
+class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask {
+ /**
+ * The name of the [LIBRARY_ELEMENT5] input.
+ */
+ static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
+
+ /**
+ * The name of the [RESOLVED_UNIT4] input.
+ */
+ static const String UNIT_INPUT = 'UNIT_INPUT';
+
+ /**
+ * The name of the [TYPE_PROVIDER] input.
+ */
+ static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
+
+ /**
+ * The task descriptor describing this kind of task.
+ */
+ static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
+ 'PartiallyResolveUnitReferencesTask',
+ createTask,
+ buildInputs, <ResultDescriptor>[
+ PARTIALLY_RESOLVE_REFERENCES_ERRORS,
+ RESOLVED_UNIT4_1
+ ]);
+
+ PartiallyResolveUnitReferencesTask(
+ InternalAnalysisContext context, AnalysisTarget target)
+ : super(context, target);
+
+ @override
+ TaskDescriptor get descriptor => DESCRIPTOR;
+
+ @override
+ void internalPerform() {
+ RecordingErrorListener errorListener = new RecordingErrorListener();
+ //
+ // Prepare inputs.
+ //
+ LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
+ CompilationUnit unit = getRequiredInput(UNIT_INPUT);
+ CompilationUnitElement unitElement = unit.element;
+ TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
+ //
+ // Resolve references.
+ //
+ InheritanceManager inheritanceManager =
+ new InheritanceManager(libraryElement);
+ // TODO(brianwilkerson) Improve performance by not resolving anything inside
+ // function bodies. Function bodies will be resolved later so this is wasted
+ // effort.
+ AstVisitor visitor = new ResolverVisitor(
+ libraryElement, unitElement.source, typeProvider, errorListener,
+ inheritanceManager: inheritanceManager);
+ unit.accept(visitor);
+ //
+ // Record outputs.
+ //
+ outputs[PARTIALLY_RESOLVE_REFERENCES_ERRORS] =
+ removeDuplicateErrors(errorListener.errors);
+ outputs[RESOLVED_UNIT4_1] = unit;
+ }
+
+ /**
+ * Return a map from the names of the inputs of this kind of task to the task
+ * input descriptors describing those inputs for a task with the
+ * given [target].
+ */
+ static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
+ LibrarySpecificUnit unit = target;
+ return <String, TaskInput>{
+ 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE
+ .of(unit.library)
+ .toListOf(LIBRARY_ELEMENT5),
+ LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
+ UNIT_INPUT: RESOLVED_UNIT4.of(unit),
+ TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
+ };
+ }
+
+ /**
+ * Create a [PartiallyResolveUnitReferencesTask] based on the given [target]
+ * in the given [context].
+ */
+ static PartiallyResolveUnitReferencesTask createTask(
+ AnalysisContext context, AnalysisTarget target) {
+ return new PartiallyResolveUnitReferencesTask(context, target);
+ }
+}
+
+/**
* The helper for building the public [Namespace] of a [LibraryElement].
*/
class PublicNamespaceBuilder {
« 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