| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library('leg_apiimpl'); |
| 6 |
| 7 #import('leg.dart', prefix: 'leg'); |
| 8 #import('ssa/tracer.dart', prefix: 'ssa'); |
| 9 #import('../lang.dart', prefix: 'frog'); |
| 10 |
| 11 class Compiler extends leg.Compiler { |
| 12 ReadUriFromString provider; |
| 13 DiagnosticHandler handler; |
| 14 Uri libraryRoot; |
| 15 |
| 16 Compiler(this.provider, this.handler, this.libraryRoot) |
| 17 : super.withCurrentDirectory(null, tracer: new ssa.HTracer()); |
| 18 |
| 19 LibraryElement scanBuiltinLibrary(String filename) { |
| 20 Uri uri = libraryRoot.resolve(filename); |
| 21 LibraryElement library = scanner.loadLibrary(uri, null); |
| 22 return library; |
| 23 } |
| 24 |
| 25 void log(message) { |
| 26 handler(null, null, null, message, false); |
| 27 } |
| 28 |
| 29 Script readScript(Uri uri, [ScriptTag node]) { |
| 30 String uriName = uri.toString(); |
| 31 // TODO(ahe): Clean this up. |
| 32 if (uriName == 'dart:dom') { |
| 33 uri = libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart'); |
| 34 } else if (uriName == 'dart:html') { |
| 35 uri = libraryRoot.resolve('../../../client/html/frog/html_frog.dart'); |
| 36 } else if (uriName == 'dart:json') { |
| 37 uri = libraryRoot.resolve('../../../lib/json/json.dart'); |
| 38 } |
| 39 String text = ""; |
| 40 try { |
| 41 // TODO(ahe): We expect the future to be complete and call value |
| 42 // directly. In effect, we don't support truly asynchronous API. |
| 43 text = provider(uri).value; |
| 44 } catch (var exception) { |
| 45 cancel("${uri.path}: $exception", node: node); |
| 46 } |
| 47 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); |
| 48 return new leg.Script(uri, sourceFile); |
| 49 } |
| 50 |
| 51 bool run(Uri uri) { |
| 52 bool success = super.run(uri); |
| 53 for (final task in tasks) { |
| 54 log('${task.name} took ${task.timing}msec'); |
| 55 } |
| 56 return success; |
| 57 } |
| 58 } |
| OLD | NEW |