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