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

Side by Side 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, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library code_transformers.src.resolvers;
6
7 import 'dart:async';
8 import 'package:barback/barback.dart' show AssetId, Transformer, Transform;
9
10 import 'resolver.dart';
11 import 'resolver_impl.dart';
12
13 /// 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?
14 /// specified code entry points.
15 ///
16 /// This can used by transformers dependent on resolved ASTs to handle the
17 /// resolution of the AST and cache the results between compilations.
18 ///
19 /// If multiple transformers rely on a resolved AST they should (ideally) share
20 /// the same Resolvers object to minimize re-parsing the AST.
21 class Resolvers {
22 final Map<AssetId, ResolverImpl> _resolvers = {};
23 final String dartSdkDirectory;
24
25 Resolvers(this.dartSdkDirectory);
26
27 /// Get a resolver for the AST starting from [id].
28 ///
29 /// [Resolver.release] must be called once it's done being used, or
30 /// [ResolverTransformer] should be used to automatically release the
31 /// resolver.
32 Future<Resolver> get(Transform transform) {
33 var id = transform.primaryInput.id;
34 var resolver = _resolvers.putIfAbsent(id,
35 () => new ResolverImpl(id, dartSdkDirectory));
36 return resolver.resolve(transform);
37 }
38 }
39
40 /// Transformer mixin which automatically gets and releases resolvers.
41 ///
42 /// To use mix this class in, set the resolvers field and override
43 /// [applyResolver].
44 abstract class ResolverTransformer implements Transformer {
45 /// The cache of resolvers- must be set from subclass.
46 Resolvers resolvers;
47
48 Future apply(Transform transform) {
49 return resolvers.get(transform).then((resolver) {
50 return new Future.value(applyResolver(transform, resolver)).then((_) {
51 resolver.release();
52 });
53 });
54 }
55
56 /// Invoked when the resolver is ready to be processed.
57 ///
58 /// Return a Future to indicate when apply is completed.
59 applyResolver(Transform transform, Resolver resolver);
60 }
OLDNEW
« 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