| 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') uri = translateDartUri(uri, node); |
| 46 var translated = translateUri(uri, node); | 47 var translated = translateUri(uri, node); |
| 47 String text = ""; | 48 String text = ""; |
| 48 try { | 49 try { |
| 49 // TODO(ahe): We expect the future to be complete and call value | 50 // TODO(ahe): We expect the future to be complete and call value |
| 50 // directly. In effect, we don't support truly asynchronous API. | 51 // directly. In effect, we don't support truly asynchronous API. |
| 51 text = provider(translated).value; | 52 text = provider(translated).value; |
| 52 } catch (var exception) { | 53 } catch (var exception) { |
| 53 if (node !== null) { | 54 if (node !== null) { |
| 54 cancel("$exception", node: node); | 55 cancel("$exception", node: node); |
| 55 } else { | 56 } else { |
| 56 reportDiagnostic(const leg.SourceSpan(null, null, null), | 57 reportDiagnostic(const leg.SourceSpan(null, null, null), |
| 57 "$exception", true); | 58 "$exception", true); |
| 58 throw new leg.CompilerCancelledException("$exception"); | 59 throw new leg.CompilerCancelledException("$exception"); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 SourceFile sourceFile = new SourceFile(uri.toString(), text); | 62 SourceFile sourceFile = new SourceFile(uri.toString(), text); |
| 62 return new leg.Script(uri, sourceFile); | 63 return new leg.Script(uri, sourceFile); |
| 63 } | 64 } |
| 64 | 65 |
| 65 Uri translateUri(Uri uri, tree.Node node) { | 66 Uri translateUri(Uri uri, tree.Node node) { |
| 66 switch (uri.scheme) { | 67 switch (uri.scheme) { |
| 67 case 'dart': return translateDartUri(uri, node); | |
| 68 case 'package': return translatePackageUri(uri, node); | 68 case 'package': return translatePackageUri(uri, node); |
| 69 default: return uri; | 69 default: return uri; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 Uri translateDartUri(Uri uri, tree.Node node) { | 73 Uri translateDartUri(Uri uri, tree.Node node) { |
| 74 String path = DART2JS_LIBRARY_MAP[uri.path]; | 74 String path = DART2JS_LIBRARY_MAP[uri.path]; |
| 75 if (path === null || uri.path.startsWith('_')) { | 75 if (path === null || uri.path.startsWith('_')) { |
| 76 reportError(node, 'library not found ${uri}'); | 76 reportError(node, 'library not found ${uri}'); |
| 77 return null; | 77 return null; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 handler(translateUri(span.uri, null), span.begin, span.end, | 102 handler(translateUri(span.uri, null), span.begin, span.end, |
| 103 message, fatal); | 103 message, fatal); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool get isMockCompilation() { | 107 bool get isMockCompilation() { |
| 108 return mockableLibraryUsed | 108 return mockableLibraryUsed |
| 109 && (options.indexOf('--allow-mock-compilation') !== -1); | 109 && (options.indexOf('--allow-mock-compilation') !== -1); |
| 110 } | 110 } |
| 111 } | 111 } |
| OLD | NEW |