| 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' as api; | 9 import '../compiler.dart' as api; |
| 10 import 'dart2jslib.dart' as leg; | 10 import 'dart2jslib.dart' as leg; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 elements.LibraryElement library = | 93 elements.LibraryElement library = |
| 94 libraryLoader.loadLibrary(uri, null, canonicalUri); | 94 libraryLoader.loadLibrary(uri, null, canonicalUri); |
| 95 return library; | 95 return library; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void log(message) { | 98 void log(message) { |
| 99 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); | 99 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
| 100 } | 100 } |
| 101 | 101 |
| 102 leg.Script readScript(Uri uri, [tree.Node node]) { | 102 leg.Script readScript(Uri uri, [tree.Node node]) { |
| 103 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); | 103 return fileReadingTask.measure(() { |
| 104 var translated = translateUri(uri, node); | 104 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); |
| 105 String text = ""; | 105 var translated = translateUri(uri, node); |
| 106 try { | 106 String text = ""; |
| 107 // TODO(ahe): We expect the future to be complete and call value | 107 try { |
| 108 // directly. In effect, we don't support truly asynchronous API. | 108 // TODO(ahe): We expect the future to be complete and call value |
| 109 text = provider(translated).value; | 109 // directly. In effect, we don't support truly asynchronous API. |
| 110 } catch (exception) { | 110 text = provider(translated).value; |
| 111 if (node != null) { | 111 } catch (exception) { |
| 112 cancel("$exception", node: node); | 112 if (node != null) { |
| 113 } else { | 113 cancel("$exception", node: node); |
| 114 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); | 114 } else { |
| 115 throw new leg.CompilerCancelledException("$exception"); | 115 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); |
| 116 throw new leg.CompilerCancelledException("$exception"); |
| 117 } |
| 116 } | 118 } |
| 117 } | 119 SourceFile sourceFile = new SourceFile(translated.toString(), text); |
| 118 SourceFile sourceFile = new SourceFile(translated.toString(), text); | 120 return new leg.Script(uri, sourceFile); |
| 119 return new leg.Script(uri, sourceFile); | 121 }); |
| 120 } | 122 } |
| 121 | 123 |
| 122 Uri translateUri(Uri uri, tree.Node node) { | 124 Uri translateUri(Uri uri, tree.Node node) { |
| 123 switch (uri.scheme) { | 125 switch (uri.scheme) { |
| 124 case 'package': return translatePackageUri(uri, node); | 126 case 'package': return translatePackageUri(uri, node); |
| 125 default: return uri; | 127 default: return uri; |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 | 130 |
| 129 Uri translateDartUri(Uri uri, tree.Node node) { | 131 Uri translateDartUri(Uri uri, tree.Node node) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 149 Uri resolvePatchUri(String dartLibraryPath) { | 151 Uri resolvePatchUri(String dartLibraryPath) { |
| 150 String patchPath = lookupPatchPath(dartLibraryPath); | 152 String patchPath = lookupPatchPath(dartLibraryPath); |
| 151 if (patchPath == null) return null; | 153 if (patchPath == null) return null; |
| 152 return libraryRoot.resolve(patchPath); | 154 return libraryRoot.resolve(patchPath); |
| 153 } | 155 } |
| 154 | 156 |
| 155 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 157 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
| 156 | 158 |
| 157 bool run(Uri uri) { | 159 bool run(Uri uri) { |
| 158 bool success = super.run(uri); | 160 bool success = super.run(uri); |
| 161 int total = 0; |
| 159 for (final task in tasks) { | 162 for (final task in tasks) { |
| 163 total += task.timing; |
| 160 log('${task.name} took ${task.timing}msec'); | 164 log('${task.name} took ${task.timing}msec'); |
| 161 } | 165 } |
| 166 log('Cumulated ${total}msec'); |
| 162 return success; | 167 return success; |
| 163 } | 168 } |
| 164 | 169 |
| 165 void reportDiagnostic(leg.SourceSpan span, String message, | 170 void reportDiagnostic(leg.SourceSpan span, String message, |
| 166 api.Diagnostic kind) { | 171 api.Diagnostic kind) { |
| 167 if (identical(kind, api.Diagnostic.ERROR) | 172 if (identical(kind, api.Diagnostic.ERROR) |
| 168 || identical(kind, api.Diagnostic.CRASH)) { | 173 || identical(kind, api.Diagnostic.CRASH)) { |
| 169 compilationFailed = true; | 174 compilationFailed = true; |
| 170 } | 175 } |
| 171 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For | 176 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For |
| 172 // instance in the [Types] constructor in typechecker.dart. | 177 // instance in the [Types] constructor in typechecker.dart. |
| 173 if (span == null || span.uri == null) { | 178 if (span == null || span.uri == null) { |
| 174 handler(null, null, null, message, kind); | 179 handler(null, null, null, message, kind); |
| 175 } else { | 180 } else { |
| 176 handler(translateUri(span.uri, null), span.begin, span.end, | 181 handler(translateUri(span.uri, null), span.begin, span.end, |
| 177 message, kind); | 182 message, kind); |
| 178 } | 183 } |
| 179 } | 184 } |
| 180 | 185 |
| 181 bool get isMockCompilation { | 186 bool get isMockCompilation { |
| 182 return mockableLibraryUsed | 187 return mockableLibraryUsed |
| 183 && (options.indexOf('--allow-mock-compilation') != -1); | 188 && (options.indexOf('--allow-mock-compilation') != -1); |
| 184 } | 189 } |
| 185 } | 190 } |
| OLD | NEW |