| 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('dart:uri'); | 7 #import('dart:uri'); |
| 8 | 8 |
| 9 #import('../compiler.dart', prefix: 'api'); | 9 #import('../compiler.dart', prefix: 'api'); |
| 10 #import('leg.dart', prefix: 'leg'); | 10 #import('leg.dart', prefix: 'leg'); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]); | 36 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]); |
| 37 elements.LibraryElement library = scanner.loadLibrary(uri, null); | 37 elements.LibraryElement library = scanner.loadLibrary(uri, null); |
| 38 return library; | 38 return library; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void log(message) { | 41 void log(message) { |
| 42 handler(null, null, null, message, false); | 42 handler(null, null, null, message, false); |
| 43 } | 43 } |
| 44 | 44 |
| 45 leg.Script readScript(Uri uri, [tree.Node node]) { | 45 leg.Script readScript(Uri uri, [tree.Node node]) { |
| 46 if (uri.scheme == 'dart') { | 46 var translated = translateUri(uri, node); |
| 47 uri = translateDartUri(uri, node); | |
| 48 } else if (uri.scheme == 'package') { | |
| 49 uri = translatePackageUri(uri, node); | |
| 50 } | |
| 51 String text = ""; | 47 String text = ""; |
| 52 try { | 48 try { |
| 53 // TODO(ahe): We expect the future to be complete and call value | 49 // TODO(ahe): We expect the future to be complete and call value |
| 54 // directly. In effect, we don't support truly asynchronous API. | 50 // directly. In effect, we don't support truly asynchronous API. |
| 55 text = provider(uri).value; | 51 text = provider(translated).value; |
| 56 } catch (var exception) { | 52 } catch (var exception) { |
| 57 if (node !== null) { | 53 if (node !== null) { |
| 58 cancel("$exception", node: node); | 54 cancel("$exception", node: node); |
| 59 } else { | 55 } else { |
| 60 reportDiagnostic(const leg.SourceSpan(null, null, null), | 56 reportDiagnostic(const leg.SourceSpan(null, null, null), |
| 61 "$exception", true); | 57 "$exception", true); |
| 62 throw new leg.CompilerCancelledException("$exception"); | 58 throw new leg.CompilerCancelledException("$exception"); |
| 63 } | 59 } |
| 64 } | 60 } |
| 65 SourceFile sourceFile = new SourceFile(uri.toString(), text); | 61 SourceFile sourceFile = new SourceFile(uri.toString(), text); |
| 66 return new leg.Script(uri, sourceFile); | 62 return new leg.Script(uri, sourceFile); |
| 67 } | 63 } |
| 68 | 64 |
| 69 translateDartUri(Uri uri, tree.Node node) { | 65 Uri translateUri(Uri uri, tree.Node node) { |
| 66 switch (uri.scheme) { |
| 67 case 'dart': return translateDartUri(uri, node); |
| 68 case 'package': return translatePackageUri(uri, node); |
| 69 default: return uri; |
| 70 } |
| 71 } |
| 72 |
| 73 Uri translateDartUri(Uri uri, tree.Node node) { |
| 70 String path = DART2JS_LIBRARY_MAP[uri.path]; | 74 String path = DART2JS_LIBRARY_MAP[uri.path]; |
| 71 if (path === null || uri.path.startsWith('_')) { | 75 if (path === null || uri.path.startsWith('_')) { |
| 72 reportError(node, 'library not found ${uri}'); | 76 reportError(node, 'library not found ${uri}'); |
| 73 return null; | 77 return null; |
| 74 } | 78 } |
| 75 if (uri.path == 'dom_deprecated' | 79 if (uri.path == 'dom_deprecated' |
| 76 || uri.path == 'html' || uri.path == 'io') { | 80 || uri.path == 'html' || uri.path == 'io') { |
| 77 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 81 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
| 78 // supports this use case better. | 82 // supports this use case better. |
| 79 mockableLibraryUsed = true; | 83 mockableLibraryUsed = true; |
| 80 } | 84 } |
| 81 return libraryRoot.resolve(path); | 85 return libraryRoot.resolve(path); |
| 82 } | 86 } |
| 83 | 87 |
| 84 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 88 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
| 85 | 89 |
| 86 bool run(Uri uri) { | 90 bool run(Uri uri) { |
| 87 bool success = super.run(uri); | 91 bool success = super.run(uri); |
| 88 for (final task in tasks) { | 92 for (final task in tasks) { |
| 89 log('${task.name} took ${task.timing}msec'); | 93 log('${task.name} took ${task.timing}msec'); |
| 90 } | 94 } |
| 91 return success; | 95 return success; |
| 92 } | 96 } |
| 93 | 97 |
| 94 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { | 98 void reportDiagnostic(leg.SourceSpan span, String message, bool fatal) { |
| 95 if (span === null) { | 99 if (span === null) { |
| 96 handler(null, null, null, message, fatal); | 100 handler(null, null, null, message, fatal); |
| 97 } else { | 101 } else { |
| 98 handler(span.uri, span.begin, span.end, message, fatal); | 102 handler(translateUri(span.uri, null), span.begin, span.end, |
| 103 message, fatal); |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 bool get isMockCompilation() { | 107 bool get isMockCompilation() { |
| 103 return mockableLibraryUsed | 108 return mockableLibraryUsed |
| 104 && (options.indexOf('--allow-mock-compilation') !== -1); | 109 && (options.indexOf('--allow-mock-compilation') !== -1); |
| 105 } | 110 } |
| 106 } | 111 } |
| OLD | NEW |