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

Unified Diff: pkg/code_transformers/lib/src/resolvers.dart

Issue 181383015: Refactoring resolvers to make them able to be run in parallel. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_transformer.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/code_transformers/lib/src/resolvers.dart
diff --git a/pkg/code_transformers/lib/src/resolvers.dart b/pkg/code_transformers/lib/src/resolvers.dart
new file mode 100644
index 0000000000000000000000000000000000000000..568374600a8c8d22face56040ef2664992feb53b
--- /dev/null
+++ b/pkg/code_transformers/lib/src/resolvers.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2014, 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 code_transformers.src.resolvers;
+
+import 'dart:async';
+import 'package:barback/barback.dart' show AssetId, Transformer, Transform;
+
+import 'resolver.dart';
+import 'resolver_impl.dart';
+
+/// Barback-based code resolver which maintains up-to-date resolved ASTs for the
Siggi Cherem (dart-lang) 2014/02/28 01:45:12 resolver => resolvers?
+/// specified code entry points.
+///
+/// This can used by transformers dependent on resolved ASTs to handle the
+/// resolution of the AST and cache the results between compilations.
+///
+/// If multiple transformers rely on a resolved AST they should (ideally) share
+/// the same Resolvers object to minimize re-parsing the AST.
+class Resolvers {
+ final Map<AssetId, ResolverImpl> _resolvers = {};
+ final String dartSdkDirectory;
+
+ Resolvers(this.dartSdkDirectory);
+
+ /// Get a resolver for the AST starting from [id].
+ ///
+ /// [Resolver.release] must be called once it's done being used, or
+ /// [ResolverTransformer] should be used to automatically release the
+ /// resolver.
+ Future<Resolver> get(Transform transform) {
+ var id = transform.primaryInput.id;
+ var resolver = _resolvers.putIfAbsent(id,
+ () => new ResolverImpl(id, dartSdkDirectory));
+ return resolver.resolve(transform);
+ }
+}
+
+/// Transformer mixin which automatically gets and releases resolvers.
+///
+/// To use mix this class in, set the resolvers field and override
+/// [applyResolver].
+abstract class ResolverTransformer implements Transformer {
+ /// The cache of resolvers- must be set from subclass.
+ Resolvers resolvers;
+
+ Future apply(Transform transform) {
+ return resolvers.get(transform).then((resolver) {
+ return new Future.value(applyResolver(transform, resolver)).then((_) {
+ resolver.release();
+ });
+ });
+ }
+
+ /// Invoked when the resolver is ready to be processed.
+ ///
+ /// Return a Future to indicate when apply is completed.
+ applyResolver(Transform transform, Resolver resolver);
+}
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_transformer.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698