| OLD | NEW |
| 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_apiimpl'); | 5 #library('leg_apiimpl'); |
| 6 | 6 |
| 7 #import('leg.dart', prefix: 'leg'); | 7 #import('leg.dart', prefix: 'leg'); |
| 8 #import('elements/elements.dart', prefix: 'leg'); | 8 #import('elements/elements.dart', prefix: 'leg'); |
| 9 #import('tree/tree.dart', prefix: 'leg'); | 9 #import('tree/tree.dart', prefix: 'leg'); |
| 10 #import('ssa/tracer.dart', prefix: 'ssa'); | 10 #import('ssa/tracer.dart', prefix: 'ssa'); |
| 11 // TODO(ahe): Remove dependency on frog. | 11 // TODO(ahe): Remove dependency on frog. |
| 12 #import('../../../frog/lang.dart', prefix: 'frog'); | 12 #import('../../../frog/lang.dart', prefix: 'frog'); |
| 13 #import('../compiler.dart'); | 13 #import('../compiler.dart'); |
| 14 #import('../../uri/uri.dart'); | 14 #import('../../uri/uri.dart'); |
| 15 #import('library_map.dart'); |
| 16 |
| 15 | 17 |
| 16 class Compiler extends leg.Compiler { | 18 class Compiler extends leg.Compiler { |
| 17 ReadUriFromString provider; | 19 ReadUriFromString provider; |
| 18 DiagnosticHandler handler; | 20 DiagnosticHandler handler; |
| 19 Uri libraryRoot; | 21 Uri libraryRoot; |
| 20 List<String> options; | 22 List<String> options; |
| 21 bool mockableLibraryUsed = false; | 23 bool mockableLibraryUsed = false; |
| 22 | 24 |
| 23 Compiler(this.provider, this.handler, this.libraryRoot, this.options) | 25 Compiler(this.provider, this.handler, this.libraryRoot, this.options) |
| 24 : super.withCurrentDirectory(null, tracer: new ssa.HTracer()); | 26 : super(tracer: new ssa.HTracer()); |
| 25 | 27 |
| 26 leg.LibraryElement scanBuiltinLibrary(String filename) { | 28 leg.LibraryElement scanBuiltinLibrary(String path) { |
| 27 Uri uri = libraryRoot.resolve(filename); | 29 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]); |
| 28 leg.LibraryElement library = scanner.loadLibrary(uri, null); | 30 leg.LibraryElement library = scanner.loadLibrary(uri, null); |
| 29 return library; | 31 return library; |
| 30 } | 32 } |
| 31 | 33 |
| 32 void log(message) { | 34 void log(message) { |
| 33 handler(null, null, null, message, false); | 35 handler(null, null, null, message, false); |
| 34 } | 36 } |
| 35 | 37 |
| 36 leg.Script readScript(Uri uri, [leg.ScriptTag node]) { | 38 leg.Script readScript(Uri uri, [leg.ScriptTag node]) { |
| 37 if (uri.scheme == 'dart') { | 39 if (uri.scheme == 'dart') { |
| 38 uri = translateDartUri(uri, node); | 40 uri = translateDartUri(uri, node); |
| 39 } | 41 } |
| 40 String text = ""; | 42 String text = ""; |
| 41 try { | 43 try { |
| 42 // TODO(ahe): We expect the future to be complete and call value | 44 // TODO(ahe): We expect the future to be complete and call value |
| 43 // directly. In effect, we don't support truly asynchronous API. | 45 // directly. In effect, we don't support truly asynchronous API. |
| 44 text = provider(uri).value; | 46 text = provider(uri).value; |
| 45 } catch (var exception) { | 47 } catch (var exception) { |
| 46 cancel("${uri}: $exception", node: node); | 48 cancel("${uri}: $exception", node: node); |
| 47 } | 49 } |
| 48 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); | 50 frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text); |
| 49 return new leg.Script(uri, sourceFile); | 51 return new leg.Script(uri, sourceFile); |
| 50 } | 52 } |
| 51 | 53 |
| 52 translateDartUri(Uri uri, leg.ScriptTag node) { | 54 translateDartUri(Uri uri, leg.ScriptTag node) { |
| 53 String uriName = uri.toString(); | 55 String path = DART2JS_LIBRARY_MAP[uri.path]; |
| 54 // TODO(ahe): Clean this up. | 56 if (path === null || uri.path.startsWith('_')) { |
| 55 if (uriName == 'dart:dom') { | 57 reportError(node, 'library not found ${uri}'); |
| 58 return null; |
| 59 } |
| 60 if (uri.path == 'dom' || uri.path == 'html' || uri.path == 'io') { |
| 61 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
| 62 // supports this use case better. |
| 56 mockableLibraryUsed = true; | 63 mockableLibraryUsed = true; |
| 57 return libraryRoot.resolve('../../../../lib/dom/frog/dom_frog.dart'); | |
| 58 } else if (uriName == 'dart:html') { | |
| 59 mockableLibraryUsed = true; | |
| 60 return libraryRoot.resolve('../../../../lib/html/frog/html_frog.dart'); | |
| 61 } else if (uriName == 'dart:json') { | |
| 62 return libraryRoot.resolve('../../../../lib/json/json.dart'); | |
| 63 } else if (uriName == 'dart:isolate') { | |
| 64 return libraryRoot.resolve('../../../../lib/isolate/isolate_leg.dart'); | |
| 65 } else if (uriName == 'dart:io') { | |
| 66 mockableLibraryUsed = true; | |
| 67 return libraryRoot.resolve('io.dart'); | |
| 68 } else if (uriName == 'dart:utf') { | |
| 69 return libraryRoot.resolve('../../../../lib/utf/utf.dart'); | |
| 70 } else if (uriName == 'dart:uri') { | |
| 71 return libraryRoot.resolve('../../../../lib/uri/uri.dart'); | |
| 72 } | 64 } |
| 73 reportError(node, "library not found $uriName"); | 65 return libraryRoot.resolve(path); |
| 74 } | 66 } |
| 75 | 67 |
| 76 bool run(Uri uri) { | 68 bool run(Uri uri) { |
| 77 bool success = super.run(uri); | 69 bool success = super.run(uri); |
| 78 for (final task in tasks) { | 70 for (final task in tasks) { |
| 79 log('${task.name} took ${task.timing}msec'); | 71 log('${task.name} took ${task.timing}msec'); |
| 80 } | 72 } |
| 81 return success; | 73 return success; |
| 82 } | 74 } |
| 83 | 75 |
| 84 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { | 76 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { |
| 85 if (span === null) { | 77 if (span === null) { |
| 86 handler(null, null, null, message, fatal); | 78 handler(null, null, null, message, fatal); |
| 87 } else { | 79 } else { |
| 88 handler(span.uri, span.begin, span.end, message, fatal); | 80 handler(span.uri, span.begin, span.end, message, fatal); |
| 89 } | 81 } |
| 90 } | 82 } |
| 91 | 83 |
| 92 bool get isMockCompilation() { | 84 bool get isMockCompilation() { |
| 93 return mockableLibraryUsed | 85 return mockableLibraryUsed |
| 94 && (options.indexOf('--allow-mock-compilation') !== -1); | 86 && (options.indexOf('--allow-mock-compilation') !== -1); |
| 95 } | 87 } |
| 96 } | 88 } |
| OLD | NEW |