| 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:async'; | 7 import 'dart:async'; |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 Uri resolvedUri, tree.Node node) { | 152 Uri resolvedUri, tree.Node node) { |
| 153 if (resolvedUri.scheme == 'dart') { | 153 if (resolvedUri.scheme == 'dart') { |
| 154 return translateDartUri(importingLibrary, resolvedUri, node); | 154 return translateDartUri(importingLibrary, resolvedUri, node); |
| 155 } | 155 } |
| 156 return resolvedUri; | 156 return resolvedUri; |
| 157 } | 157 } |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Reads the script designated by [readableUri]. | 160 * Reads the script designated by [readableUri]. |
| 161 */ | 161 */ |
| 162 Future<leg.Script> readScript(Uri readableUri, | 162 Future<leg.Script> readScript(leg.Spannable node, Uri readableUri) { |
| 163 [elements.Element element, tree.Node node]) { | |
| 164 if (!readableUri.isAbsolute) { | 163 if (!readableUri.isAbsolute) { |
| 165 internalError('Relative uri $readableUri provided to readScript(Uri)', | 164 internalError(node, |
| 166 node: node); | 165 'Relative uri $readableUri provided to readScript(Uri).'); |
| 167 } | 166 } |
| 168 | 167 |
| 169 // TODO(johnniwinther): Add [:report(..., {Element element}):] to | 168 // We need to store the current element since we are reporting read errors |
| 170 // report methods in Compiler. | 169 // asynchronously and therefore need to restore the current element for |
| 170 // [node] to be valid. |
| 171 elements.Element element = currentElement; |
| 171 void reportReadError(exception) { | 172 void reportReadError(exception) { |
| 172 withCurrentElement(element, () { | 173 withCurrentElement(element, () { |
| 173 reportError(node, | 174 reportError(node, |
| 174 leg.MessageKind.READ_SCRIPT_ERROR, | 175 leg.MessageKind.READ_SCRIPT_ERROR, |
| 175 {'uri': readableUri, 'exception': exception}); | 176 {'uri': readableUri, 'exception': exception}); |
| 176 }); | 177 }); |
| 177 } | 178 } |
| 178 | 179 |
| 179 Uri resourceUri = translateUri(readableUri, node); | 180 Uri resourceUri = translateUri(node, readableUri); |
| 180 // TODO(johnniwinther): Wrap the result from [provider] in a specialized | 181 // TODO(johnniwinther): Wrap the result from [provider] in a specialized |
| 181 // [Future] to ensure that we never execute an asynchronous action without | 182 // [Future] to ensure that we never execute an asynchronous action without |
| 182 // setting up the current element of the compiler. | 183 // setting up the current element of the compiler. |
| 183 return new Future.sync(() => callUserProvider(resourceUri)).then((data) { | 184 return new Future.sync(() => callUserProvider(resourceUri)).then((data) { |
| 184 SourceFile sourceFile; | 185 SourceFile sourceFile; |
| 185 String resourceUriString = resourceUri.toString(); | 186 String resourceUriString = resourceUri.toString(); |
| 186 if (data is List<int>) { | 187 if (data is List<int>) { |
| 187 sourceFile = new Utf8BytesSourceFile(resourceUriString, data); | 188 sourceFile = new Utf8BytesSourceFile(resourceUriString, data); |
| 188 } else if (data is String) { | 189 } else if (data is String) { |
| 189 sourceFile = new StringSourceFile(resourceUriString, data); | 190 sourceFile = new StringSourceFile(resourceUriString, data); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 reportReadError(error); | 202 reportReadError(error); |
| 202 return null; | 203 return null; |
| 203 }); | 204 }); |
| 204 } | 205 } |
| 205 | 206 |
| 206 /** | 207 /** |
| 207 * Translates a readable URI into a resource URI. | 208 * Translates a readable URI into a resource URI. |
| 208 * | 209 * |
| 209 * See [LibraryLoader] for terminology on URIs. | 210 * See [LibraryLoader] for terminology on URIs. |
| 210 */ | 211 */ |
| 211 Uri translateUri(Uri readableUri, tree.Node node) { | 212 Uri translateUri(leg.Spannable node, Uri readableUri) { |
| 212 switch (readableUri.scheme) { | 213 switch (readableUri.scheme) { |
| 213 case 'package': return translatePackageUri(readableUri, node); | 214 case 'package': return translatePackageUri(node, readableUri); |
| 214 default: return readableUri; | 215 default: return readableUri; |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 Uri translateDartUri(elements.LibraryElement importingLibrary, | 219 Uri translateDartUri(elements.LibraryElement importingLibrary, |
| 219 Uri resolvedUri, tree.Node node) { | 220 Uri resolvedUri, tree.Node node) { |
| 220 LibraryInfo libraryInfo = LIBRARIES[resolvedUri.path]; | 221 LibraryInfo libraryInfo = LIBRARIES[resolvedUri.path]; |
| 221 String path = lookupLibraryPath(resolvedUri.path); | 222 String path = lookupLibraryPath(resolvedUri.path); |
| 222 if (libraryInfo != null && | 223 if (libraryInfo != null && |
| 223 libraryInfo.category == "Internal") { | 224 libraryInfo.category == "Internal") { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 259 } |
| 259 return libraryRoot.resolve(path); | 260 return libraryRoot.resolve(path); |
| 260 } | 261 } |
| 261 | 262 |
| 262 Uri resolvePatchUri(String dartLibraryPath) { | 263 Uri resolvePatchUri(String dartLibraryPath) { |
| 263 String patchPath = lookupPatchPath(dartLibraryPath); | 264 String patchPath = lookupPatchPath(dartLibraryPath); |
| 264 if (patchPath == null) return null; | 265 if (patchPath == null) return null; |
| 265 return libraryRoot.resolve(patchPath); | 266 return libraryRoot.resolve(patchPath); |
| 266 } | 267 } |
| 267 | 268 |
| 268 Uri translatePackageUri(Uri uri, tree.Node node) { | 269 Uri translatePackageUri(leg.Spannable node, Uri uri) { |
| 269 if (packageRoot == null) { | 270 if (packageRoot == null) { |
| 270 reportFatalError( | 271 reportFatalError( |
| 271 node, leg.MessageKind.PACKAGE_ROOT_NOT_SET, {'uri': uri}); | 272 node, leg.MessageKind.PACKAGE_ROOT_NOT_SET, {'uri': uri}); |
| 272 } | 273 } |
| 273 return packageRoot.resolve(uri.path); | 274 return packageRoot.resolve(uri.path); |
| 274 } | 275 } |
| 275 | 276 |
| 276 Future<bool> run(Uri uri) { | 277 Future<bool> run(Uri uri) { |
| 277 log('Allowed library categories: $allowedLibraryCategories'); | 278 log('Allowed library categories: $allowedLibraryCategories'); |
| 278 return super.run(uri).then((bool success) { | 279 return super.run(uri).then((bool success) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 295 if (identical(kind, api.Diagnostic.ERROR) | 296 if (identical(kind, api.Diagnostic.ERROR) |
| 296 || identical(kind, api.Diagnostic.CRASH)) { | 297 || identical(kind, api.Diagnostic.CRASH)) { |
| 297 compilationFailed = true; | 298 compilationFailed = true; |
| 298 } | 299 } |
| 299 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For | 300 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For |
| 300 // instance in the [Types] constructor in typechecker.dart. | 301 // instance in the [Types] constructor in typechecker.dart. |
| 301 if (span == null || span.uri == null) { | 302 if (span == null || span.uri == null) { |
| 302 callUserHandler(null, null, null, '$message', kind); | 303 callUserHandler(null, null, null, '$message', kind); |
| 303 } else { | 304 } else { |
| 304 callUserHandler( | 305 callUserHandler( |
| 305 translateUri(span.uri, null), span.begin, span.end, '$message', kind); | 306 translateUri(null, span.uri), span.begin, span.end, '$message', kind); |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 | 309 |
| 309 bool get isMockCompilation { | 310 bool get isMockCompilation { |
| 310 return mockableLibraryUsed | 311 return mockableLibraryUsed |
| 311 && (options.indexOf('--allow-mock-compilation') != -1); | 312 && (options.indexOf('--allow-mock-compilation') != -1); |
| 312 } | 313 } |
| 313 | 314 |
| 314 void callUserHandler(Uri uri, int begin, int end, | 315 void callUserHandler(Uri uri, int begin, int end, |
| 315 String message, api.Diagnostic kind) { | 316 String message, api.Diagnostic kind) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 332 } | 333 } |
| 333 | 334 |
| 334 void diagnoseCrashInUserCode(String message, exception, stackTrace) { | 335 void diagnoseCrashInUserCode(String message, exception, stackTrace) { |
| 335 hasCrashed = true; | 336 hasCrashed = true; |
| 336 print('$message: ${tryToString(exception)}'); | 337 print('$message: ${tryToString(exception)}'); |
| 337 print(tryToString(stackTrace)); | 338 print(tryToString(stackTrace)); |
| 338 } | 339 } |
| 339 | 340 |
| 340 fromEnvironment(String name) => environment[name]; | 341 fromEnvironment(String name) => environment[name]; |
| 341 } | 342 } |
| OLD | NEW |