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

Unified Diff: pkg/analyzer/lib/src/task/dart_work_manager.dart

Issue 1132893003: Add DartWorkManager to manage Dart-specific results computation scheduling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | « no previous file | pkg/analyzer/lib/src/task/driver.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_work_manager.dart
diff --git a/pkg/analyzer/lib/src/task/dart_work_manager.dart b/pkg/analyzer/lib/src/task/dart_work_manager.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b91c0b7ff9bef67fc59f0a1db50f98a8aadb0600
--- /dev/null
+++ b/pkg/analyzer/lib/src/task/dart_work_manager.dart
@@ -0,0 +1,135 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analyzer.src.task.dart_work_manager;
+
+import 'dart:collection';
+
+import 'package:analyzer/src/context/cache.dart';
+import 'package:analyzer/src/generated/engine.dart'
+ show AnalysisEngine, CacheState, InternalAnalysisContext;
+import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/task/dart.dart';
+import 'package:analyzer/src/task/driver.dart';
+import 'package:analyzer/task/dart.dart';
+import 'package:analyzer/task/model.dart';
+
+/**
+ * The manager for Dart specific analysis.
+ */
+class DartWorkManager implements WorkManager {
+ final InternalAnalysisContext context;
+
+ /**
+ * The explicit sources to analyze.
+ */
+ final HashSet<Source> explicitSources = new HashSet<Source>();
Brian Wilkerson 2015/05/09 17:22:00 The sets of 'explicitSources', 'librarySources' an
scheglov 2015/05/09 23:20:17 Well, you're right that they're not used now. But:
+
+ /**
+ * The known library source.
+ */
+ final HashSet<Source> librarySources = new HashSet<Source>();
+
+ /**
+ * The know part sources.
+ */
+ final HashSet<Source> partSources = new HashSet<Source>();
+
+ /**
+ * The sources whose kind we don't know yet.
+ */
+ final LinkedHashSet<Source> unknownSourceQueue = new LinkedHashSet<Source>();
+
+ /**
+ * The queue of library sources to process.
+ */
+ final LinkedHashSet<Source> librarySourceQueue = new LinkedHashSet<Source>();
+
+ /**
+ * Initialize a newly created manager.
+ */
+ DartWorkManager(this.context);
+
+ /**
+ * Notifies the manager about changes in the explicit source list.
+ */
+ void applyChange(List<Source> addedSources, List<Source> changedSources,
+ List<Source> removedSources) {
+ addedSources = addedSources.where(_isDartSource).toList();
+ changedSources = changedSources.where(_isDartSource).toList();
+ removedSources = removedSources.where(_isDartSource).toList();
+ // explicit
+ explicitSources.addAll(addedSources);
+ explicitSources.removeAll(removedSources);
+ // library
+ librarySources.removeAll(changedSources);
+ librarySources.removeAll(removedSources);
+ // part
+ partSources.removeAll(changedSources);
+ partSources.removeAll(removedSources);
+ // unknown queue
+ unknownSourceQueue.addAll(addedSources);
+ unknownSourceQueue.addAll(changedSources);
+ unknownSourceQueue.removeAll(removedSources);
+ // library queue
+ librarySourceQueue.removeAll(changedSources);
+ librarySourceQueue.removeAll(removedSources);
+ }
+
+ @override
+ TargetedResult getNextResult() {
+ // Try to find a new library to analyze.
+ while (librarySourceQueue.isNotEmpty) {
+ Source librarySource = librarySourceQueue.first;
+ CacheEntry entry = context.getCacheEntry(librarySource);
+ CacheState state = entry.getState(LIBRARY_ERRORS_READY);
+ // Maybe done with this library.
+ if (state == CacheState.VALID || state == CacheState.ERROR) {
+ librarySourceQueue.remove(librarySource);
+ continue;
+ }
+ // Analyze this library.
+ return new TargetedResult(librarySource, LIBRARY_ERRORS_READY);
+ }
+ // No libraries in the queue, check whether there are sources to organize.
+ while (unknownSourceQueue.isNotEmpty) {
+ Source source = unknownSourceQueue.first;
+ CacheEntry entry = context.getCacheEntry(source);
+ CacheState state = entry.getState(SOURCE_KIND);
+ // Maybe done with this source.
+ if (state == CacheState.VALID || state == CacheState.ERROR) {
+ unknownSourceQueue.remove(source);
+ continue;
+ }
+ // Compute the kind of this source.
+ return new TargetedResult(source, SOURCE_KIND);
+ }
+ // No results to compute.
+ return null;
Brian Wilkerson 2015/05/09 17:22:00 The old work manager also maintained a queue of pa
scheglov 2015/05/09 23:20:17 Good idea. I've added a TODO comment.
+ }
+
+ @override
+ void resultsComputed(
+ AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) {
+ // Organize sources.
+ if (_isDartSource(target)) {
+ SourceKind kind = outputs[SOURCE_KIND];
+ if (kind != null) {
+ unknownSourceQueue.remove(target);
+ if (kind == SourceKind.PART) {
+ librarySources.remove(target);
+ partSources.add(target);
+ } else {
+ librarySources.add(target);
+ partSources.remove(target);
+ librarySourceQueue.add(target);
+ }
+ }
+ }
+ }
+
+ bool _isDartSource(AnalysisTarget target) {
+ return target is Source && AnalysisEngine.isDartFileName(target.fullName);
+ }
+}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698