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

Side by Side Diff: dart/frog/leg/api.dart

Issue 9639012: Implement the compiler API and use it in frog_leg.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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
« no previous file with comments | « no previous file | dart/frog/leg/compiler.dart » ('j') | dart/frog/leg/frog_leg.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('leg_api'); 5 #library('leg_api');
6 #import('dart:uri'); 6 #import('../../lib/uri/uri.dart');
7 #import('leg.dart', prefix: 'leg');
8 #import('ssa/tracer.dart');
kasperl 2012/03/08 15:13:02 Should we give this a prefix too?
ahe 2012/03/08 16:29:42 Done.
9 #import('../lang.dart', prefix: 'frog');
7 10
8 // Unless explicitly allowed, passing null for any argument to the 11 // Unless explicitly allowed, passing null for any argument to the
9 // methods of library will result in a NullPointerException being 12 // methods of library will result in a NullPointerException being
10 // thrown. 13 // thrown.
11 14
12 /** 15 /**
13 * Returns the source corresponding to [uri]. If no such source exists 16 * Returns the source corresponding to [uri]. If no such source exists
14 * or if an error occur while fetching it, this method must throw an 17 * or if an error occur while fetching it, this method must throw an
15 * exception. 18 * exception.
16 */ 19 */
(...skipping 11 matching lines...) Expand all
28 */ 31 */
29 typedef void DiagnosticHandler(Uri uri, int begin, int end, 32 typedef void DiagnosticHandler(Uri uri, int begin, int end,
30 String message, bool fatal); 33 String message, bool fatal);
31 34
32 /** 35 /**
33 * Returns [script] compiled to JavaScript. If the compilation fails, 36 * Returns [script] compiled to JavaScript. If the compilation fails,
34 * null is returned and [handler] will have been invoked at least once 37 * null is returned and [handler] will have been invoked at least once
35 * with [:fatal == true:]. 38 * with [:fatal == true:].
36 */ 39 */
37 Future<String> compile(Uri script, Uri libraryRoot, 40 Future<String> compile(Uri script, Uri libraryRoot,
38 ReadUriFromString provider, DiagnosticHandler handler); 41 ReadUriFromString provider, DiagnosticHandler handler) {
kasperl 2012/03/08 15:13:02 In these cases I prefer one argument per line.
ahe 2012/03/08 16:29:42 I don't agree, but done.
39 // TODO(ahe): Document libraryRoot argument. 42 Compiler compiler = new Compiler(provider, handler, libraryRoot);
43 compiler.run(script);
44 String code = compiler.assembledCode;
45 Completer<String> completer = new Completer<String>();
46 completer.complete(code);
47 return completer.future;
48 }
49
50 // Implementation:
51 class Compiler extends leg.Compiler {
52 ReadUriFromString provider;
53 DiagnosticHandler handler;
54 Uri libraryRoot;
55
56 Compiler(this.provider, this.handler, this.libraryRoot)
57 : super.withCurrentDirectory(null, tracer: new HTracer());
58
59 LibraryElement scanBuiltinLibrary(String filename) {
60 Uri uri = libraryRoot.resolve(filename);
61 LibraryElement library = scanner.loadLibrary(uri, null);
62 return library;
63 }
64
65 void log(message) {
66 handler(null, null, null, message, false);
67 }
68
69 Script readScript(Uri uri, [ScriptTag node]) {
70 String uriName = uri.toString();
71 // TODO(ahe): Clean this up.
72 if (uriName == 'dart:dom') {
73 uri = libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart');
74 } else if (uriName == 'dart:html') {
75 uri = libraryRoot.resolve('../../../client/html/frog/html_frog.dart');
76 } else if (uriName == 'dart:json') {
77 uri = libraryRoot.resolve('../../../lib/json/json.dart');
78 }
79 String text = "";
80 try {
81 text = provider(uri).value;
kasperl 2012/03/08 15:13:02 Maybe add a comment here that explain why this is
ahe 2012/03/08 16:29:42 Done.
82 } catch (var exception) {
83 cancel("${uri.path}: $exception", node: node);
84 }
85 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text);
86 return new leg.Script(uri, sourceFile);
87 }
88
89 bool run(Uri uri) {
90 bool success = super.run(uri);
91 for (final task in tasks) {
92 log('${task.name} took ${task.timing}msec');
93 }
94 return success;
95 }
96 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/compiler.dart » ('j') | dart/frog/leg/frog_leg.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698