| 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 15 matching lines...) Expand all Loading... |
| 26 List<String> options) | 26 List<String> options) |
| 27 : this.options = options, | 27 : this.options = options, |
| 28 super( | 28 super( |
| 29 tracer: new ssa.HTracer(), | 29 tracer: new ssa.HTracer(), |
| 30 enableTypeAssertions: options.indexOf('--enable-checked-mode') != -1, | 30 enableTypeAssertions: options.indexOf('--enable-checked-mode') != -1, |
| 31 enableUserAssertions: options.indexOf('--enable-checked-mode') != -1, | 31 enableUserAssertions: options.indexOf('--enable-checked-mode') != -1, |
| 32 emitJavascript: options.indexOf('--output-type=dart') == -1, | 32 emitJavascript: options.indexOf('--output-type=dart') == -1, |
| 33 validateUnparse: options.indexOf('--unparse-validation') !== -1); | 33 validateUnparse: options.indexOf('--unparse-validation') !== -1); |
| 34 | 34 |
| 35 elements.LibraryElement scanBuiltinLibrary(String path) { | 35 elements.LibraryElement scanBuiltinLibrary(String path) { |
| 36 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]); | 36 Uri uri = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path].libraryPath); |
| 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, api.Diagnostic.VERBOSE_INFO); | 42 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
| 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 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 Uri translateUri(Uri uri, tree.Node node) { | 65 Uri translateUri(Uri uri, tree.Node node) { |
| 66 switch (uri.scheme) { | 66 switch (uri.scheme) { |
| 67 case 'package': return translatePackageUri(uri, node); | 67 case 'package': return translatePackageUri(uri, node); |
| 68 default: return uri; | 68 default: return uri; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 Uri translateDartUri(Uri uri, tree.Node node) { | 72 Uri translateDartUri(Uri uri, tree.Node node) { |
| 73 String path = DART2JS_LIBRARY_MAP[uri.path]; | 73 String path = DART2JS_LIBRARY_MAP[uri.path].libraryPath; |
| 74 if (path === null || uri.path.startsWith('_')) { | 74 if (path === null || uri.path.startsWith('_')) { |
| 75 reportError(node, 'library not found ${uri}'); | 75 reportError(node, 'library not found ${uri}'); |
| 76 return null; | 76 return null; |
| 77 } | 77 } |
| 78 if (uri.path == 'dom_deprecated' | 78 if (uri.path == 'dom_deprecated' |
| 79 || uri.path == 'html' || uri.path == 'io') { | 79 || uri.path == 'html' || uri.path == 'io') { |
| 80 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 80 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
| 81 // supports this use case better. | 81 // supports this use case better. |
| 82 mockableLibraryUsed = true; | 82 mockableLibraryUsed = true; |
| 83 } | 83 } |
| 84 return libraryRoot.resolve(path); | 84 return libraryRoot.resolve(path); |
| 85 } | 85 } |
| 86 | 86 |
| 87 Uri resolvePatchUri(String dartLibraryPath) { |
| 88 String patchPath = DART2JS_LIBRARY_MAP[dartLibraryPath].patchPath; |
| 89 if (patchPath === null) return null; |
| 90 return libraryRoot.resolve(patchPath); |
| 91 } |
| 92 |
| 87 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 93 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
| 88 | 94 |
| 89 bool run(Uri uri) { | 95 bool run(Uri uri) { |
| 90 bool success = super.run(uri); | 96 bool success = super.run(uri); |
| 91 for (final task in tasks) { | 97 for (final task in tasks) { |
| 92 log('${task.name} took ${task.timing}msec'); | 98 log('${task.name} took ${task.timing}msec'); |
| 93 } | 99 } |
| 94 return success; | 100 return success; |
| 95 } | 101 } |
| 96 | 102 |
| 97 void reportDiagnostic(leg.SourceSpan span, String message, | 103 void reportDiagnostic(leg.SourceSpan span, String message, |
| 98 api.Diagnostic kind) { | 104 api.Diagnostic kind) { |
| 99 if (kind === api.Diagnostic.ERROR || kind === api.Diagnostic.CRASH) { | 105 if (kind === api.Diagnostic.ERROR || kind === api.Diagnostic.CRASH) { |
| 100 compilationFailed = true; | 106 compilationFailed = true; |
| 101 } | 107 } |
| 102 if (span === null) { | 108 if (span === null) { |
| 103 handler(null, null, null, message, kind); | 109 handler(null, null, null, message, kind); |
| 104 } else { | 110 } else { |
| 105 handler(translateUri(span.uri, null), span.begin, span.end, | 111 handler(translateUri(span.uri, null), span.begin, span.end, |
| 106 message, kind); | 112 message, kind); |
| 107 } | 113 } |
| 108 } | 114 } |
| 109 | 115 |
| 110 bool get isMockCompilation() { | 116 bool get isMockCompilation() { |
| 111 return mockableLibraryUsed | 117 return mockableLibraryUsed |
| 112 && (options.indexOf('--allow-mock-compilation') !== -1); | 118 && (options.indexOf('--allow-mock-compilation') !== -1); |
| 113 } | 119 } |
| 114 } | 120 } |
| OLD | NEW |