Chromium Code Reviews| Index: dart/frog/leg/api.dart |
| diff --git a/dart/frog/leg/api.dart b/dart/frog/leg/api.dart |
| index 306093135c7bb2c1bb1c055558b5eeecca11e3a2..a03d51ed5b5cc6de9fd5e46446cc3967db8bb998 100644 |
| --- a/dart/frog/leg/api.dart |
| +++ b/dart/frog/leg/api.dart |
| @@ -3,7 +3,10 @@ |
| // BSD-style license that can be found in the LICENSE file. |
| #library('leg_api'); |
| -#import('dart:uri'); |
| +#import('../../lib/uri/uri.dart'); |
| +#import('leg.dart', prefix: 'leg'); |
| +#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.
|
| +#import('../lang.dart', prefix: 'frog'); |
| // Unless explicitly allowed, passing null for any argument to the |
| // methods of library will result in a NullPointerException being |
| @@ -35,5 +38,59 @@ typedef void DiagnosticHandler(Uri uri, int begin, int end, |
| * with [:fatal == true:]. |
| */ |
| Future<String> compile(Uri script, Uri libraryRoot, |
| - ReadUriFromString provider, DiagnosticHandler handler); |
| -// TODO(ahe): Document libraryRoot argument. |
| + 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.
|
| + Compiler compiler = new Compiler(provider, handler, libraryRoot); |
| + compiler.run(script); |
| + String code = compiler.assembledCode; |
| + Completer<String> completer = new Completer<String>(); |
| + completer.complete(code); |
| + return completer.future; |
| +} |
| + |
| +// Implementation: |
| +class Compiler extends leg.Compiler { |
| + ReadUriFromString provider; |
| + DiagnosticHandler handler; |
| + Uri libraryRoot; |
| + |
| + Compiler(this.provider, this.handler, this.libraryRoot) |
| + : super.withCurrentDirectory(null, tracer: new HTracer()); |
| + |
| + LibraryElement scanBuiltinLibrary(String filename) { |
| + Uri uri = libraryRoot.resolve(filename); |
| + LibraryElement library = scanner.loadLibrary(uri, null); |
| + return library; |
| + } |
| + |
| + void log(message) { |
| + handler(null, null, null, message, false); |
| + } |
| + |
| + Script readScript(Uri uri, [ScriptTag node]) { |
| + String uriName = uri.toString(); |
| + // TODO(ahe): Clean this up. |
| + if (uriName == 'dart:dom') { |
| + uri = libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart'); |
| + } else if (uriName == 'dart:html') { |
| + uri = libraryRoot.resolve('../../../client/html/frog/html_frog.dart'); |
| + } else if (uriName == 'dart:json') { |
| + uri = libraryRoot.resolve('../../../lib/json/json.dart'); |
| + } |
| + String text = ""; |
| + try { |
| + 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.
|
| + } catch (var exception) { |
| + cancel("${uri.path}: $exception", node: node); |
| + } |
| + frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); |
| + return new leg.Script(uri, sourceFile); |
| + } |
| + |
| + bool run(Uri uri) { |
| + bool success = super.run(uri); |
| + for (final task in tasks) { |
| + log('${task.name} took ${task.timing}msec'); |
| + } |
| + return success; |
| + } |
| +} |