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

Side by Side Diff: pkg/front_end/lib/compiler_api.dart

Issue 2417043003: Initial API for the Dart front_end package. (Closed)
Patch Set: Created 4 years, 2 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
(Empty)
1 // Copyright (c) 2016, 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 /// Defines the front end API to be used by compiler back-ends.
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 nit: front end => front-end ? (that would match ba
Bob Nystrom 2016/10/13 23:56:11 /me puts on grammarian hat. (I'm kidding, of cour
Paul Berry 2016/10/14 00:09:35 I don't have a strong preference, but in my mind t
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 To make sure all options are on the table: my lean
Bob Nystrom 2016/10/14 16:12:18 "frontend" doesn't collapse well as a single word
Paul Berry 2016/10/14 21:32:34 I'm happy to defer to Kathy on this question. I'l
6 library front_end.compiler_api;
7
8 import 'compilation_error.dart';
9 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit;
10
11 /// Callback used by [CompilerApi] to report errors encountered during
12 /// compilation.
13 typedef void ErrorHandler(CompilationError);
scheglov 2016/10/13 23:58:17 typedef void ErrorHandler(CompilationError error);
Paul Berry 2016/10/14 00:09:36 Oops. Thank you.
14
15 /// Front end API for use by compiler back-ends.
16 ///
17 /// Intended use: create a CompilerApi object, set any desired options using
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 since these options are just set once, could we ma
Paul Berry 2016/10/14 00:09:36 Yeah, that's a good point. Making them named argu
Brian Wilkerson 2016/10/14 14:54:45 If you intend to deprecate the sourcesToResolvedAs
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Good point. +1 on making it a single top-level fun
Paul Berry 2016/10/14 21:32:34 After further discussion, I'm going to provisional
18 /// setters, and then call [sourcesToKernel] to obtain a Dart Kernel
19 /// representation of input source files.
20 ///
21 /// At the moment, this API only supports batch-mode compilation. Its methods
22 /// operate on whole source files, and do not cache intermediate results between
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 design discussion: I might be jumping ahead since
Paul Berry 2016/10/14 00:09:36 I don't think it's that simple, since changes to o
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 Sure - let's chat sometime later, maybe after the
23 /// method calls. Support for incremental updates will be added in the future
24 /// (e.g. to allow for hot reload features).
25 ///
26 /// All of the options have reasonable defaults, so a simple client may simply
27 /// do: `var kernel = new CompilerApi().sourcesToKernel([Uri.parse(...)]);`
28 abstract class CompilerApi {
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 minor nit: what do you think about renaming this a
Brian Wilkerson 2016/10/13 23:37:02 This doesn't provide any way to set any options, s
Paul Berry 2016/10/14 00:09:36 It's intended to be added in the future. My curre
Paul Berry 2016/10/14 00:09:36 I'd prefer not to, since the front end also needs
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 Ok, makes sense. My minor concern with [CompilerA
Paul Berry 2016/10/14 21:32:34 Good suggestions. Since I'm going to try re-worki
29 /// Creates an instance of [CompilerApi] with all options set to default
30 /// values.
31 factory CompilerApi() => throw new UnimplementedError();
32
33 /// Sets the path to the Dart SDK.
34 ///
35 /// If not set, the SDK will be searched for using [Platform.script] as a
36 /// starting point.
37 void set sdkPath(String path);
38
39 /// Sets a callback to which compilation errors should be delivered.
40 ///
41 /// If not set, the first error will be reported by throwing an exception of
42 /// type [CompilationError].
43 void set onError(ErrorHandler onError);
44
45 /// Sets the path to the ".packages" file.
46 ///
47 /// If not set, the ".packages" file will be found via the standard search
48 /// algorithm.
49 void set packages(String path);
Brian Wilkerson 2016/10/13 23:37:02 Analyzer currently supports setting a 'packages' d
Paul Berry 2016/10/14 00:09:36 Since the front end isn't likely to be used until
Brian Wilkerson 2016/10/14 14:54:45 I have asked several people, and as far as I can t
Paul Berry 2016/10/14 21:32:34 We had a bunch of discussion about this, and agree
50
51 /// Sets the paths to the input summary files.
52 ///
53 /// If not set, no input summaries will be used.
54 void set inputSummaries(List<String> paths);
Brian Wilkerson 2016/10/13 23:37:02 Does this include all summary files: sdk and non-s
scheglov 2016/10/13 23:58:17 Is using summaries for pub packages an implementat
Paul Berry 2016/10/14 00:09:35 I'm not sure. Let me think about this.
Paul Berry 2016/10/14 00:09:35 I think it should be not allowed; I don't think we
Brian Wilkerson 2016/10/14 14:54:45 While it might be reasonable for the front end to
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 My assumption here was also like Brian: this list
55
56 /// Sets the URI override map.
57 ///
58 /// This is a map from Uri to file path which overrides the normal URI
59 /// resolution algorithm. If not set, the normal URI resolution algorithm
60 /// will always be used.
61 void set uriOverride(Map<Uri, String> mapping);
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 is this for dart:* libraries or for mappings like
Brian Wilkerson 2016/10/13 23:37:01 What is this used for? (I don't remember seeing si
Paul Berry 2016/10/14 00:09:36 It's for the mappings we have to do for Bazel. It
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Ah - if it is mainly for bazel, this might be a go
Paul Berry 2016/10/14 21:32:34 I would like to learn more about this from you.
62
63 /// Sets the platform bit mask, which determines which patch files should be
64 /// applied to the SDK.
scheglov 2016/10/13 23:58:17 It is always a single platform, right? The phrase
Paul Berry 2016/10/14 00:09:36 It's always a single platform, but it must be a po
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 I wonder if we should add an enum to libraries.dar
Paul Berry 2016/10/14 21:32:34 That's a good idea, but I'm not sure how it would
Siggi Cherem (dart-lang) 2016/10/17 16:27:29 [sorry I forgot to send this comment earlier]: To
65 ///
66 /// The value should match the `PLATFORM` bit flags in
67 /// sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart. If not set, no
68 /// patch files will be applied.
69 void set platform(int value);
Brian Wilkerson 2016/10/13 23:37:02 Note that there is another definition of "platform
Paul Berry 2016/10/14 00:09:36 Acknowledged.
70
71 /// Limits the set of files which the front end is allowed to read.
72 ///
73 /// The front end will behave as though files not in this set do not exist.
74 /// If not set, the front end is allowed to read all files in the filesystem.
75 void set permittedFiles(Iterable<String> files);
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 is this mainly for validation in blaze? (to check
Brian Wilkerson 2016/10/13 23:37:02 What use case does this support? (I have to wonder
Paul Berry 2016/10/14 00:09:36 For the use case, see my answer to Siggi. As to w
Paul Berry 2016/10/14 00:09:36 It's for Bazel workers. Bazel workers aren't herm
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 What do you think about making the front-end herme
Paul Berry 2016/10/14 21:32:34 If we do this we won't be able to support the use
76
77 /// Sets the declared variables for use by configurable imports and constant
78 /// evaluation.
79 void set declaredVariables(Map<String, String> variables);
80
81 /// Processes the given [sources] and converts them to Dart Kernel format.
82 ///
83 /// TODO(paulberry): once Dart Kernel has been merged into the SDK, set the
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 since it's already pulled into DEPS, you might be
Paul Berry 2016/10/14 00:09:36 Oh, I didn't realize that. I will make that chang
84 /// return type correctly.
85 dynamic sourcesToKernel(List<Uri> sources);
86
87 /// Processes the given [sources] and converts them to resolved ASTs.
88 ///
89 /// This is intended to be used by dev_compiler prior to its conversion to
90 /// Dart Kernel.
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 + and will be deperecated in the future? OR, shou
Paul Berry 2016/10/14 00:09:36 Yes that's my intent.
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Let's keep it separate then (either on a separate
Paul Berry 2016/10/14 21:32:34 Agreed.
91 List<CompilationUnit> sourcesToResolvedAsts(List<Uri> sources);
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698