| 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('mirrors.dart2js'); | 5 #library('mirrors.dart2js'); |
| 6 | 6 |
| 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics'); | 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics'); |
| 8 #import('../../compiler/implementation/elements/elements.dart'); | 8 #import('../../compiler/implementation/elements/elements.dart'); |
| 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); | 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); |
| 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); | 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 print(message); | 310 print(message); |
| 311 throw message; | 311 throw message; |
| 312 } else if (fatal) { | 312 } else if (fatal) { |
| 313 SourceFile file = sourceFiles[uri.toString()]; | 313 SourceFile file = sourceFiles[uri.toString()]; |
| 314 print(file.getLocationMessage(message, begin, end, true, (s) => s)); | 314 print(file.getLocationMessage(message, begin, end, true, (s) => s)); |
| 315 throw message; | 315 throw message; |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 Dart2JsCompilation(String script, String libraryRoot, | 319 Dart2JsCompilation(Path script, Path libraryRoot, |
| 320 [String packageRoot, List<String> opts = const <String>[]]) | 320 [Path packageRoot, List<String> opts = const <String>[]]) |
| 321 : cwd = getCurrentDirectory(), sourceFiles = <SourceFile>{} { | 321 : cwd = getCurrentDirectory(), sourceFiles = <SourceFile>{} { |
| 322 var libraryUri = cwd.resolve(nativeToUriPath(libraryRoot)); | 322 var libraryUri = cwd.resolve(nativeToUriPath(libraryRoot.toNativePath())); |
| 323 var packageUri; | 323 var packageUri; |
| 324 if (packageRoot !== null) { | 324 if (packageRoot !== null) { |
| 325 packageUri = cwd.resolve(nativeToUriPath(packageRoot)); | 325 packageUri = cwd.resolve(nativeToUriPath(packageRoot.toNativePath())); |
| 326 } else { | 326 } else { |
| 327 packageUri = libraryUri; | 327 packageUri = libraryUri; |
| 328 } | 328 } |
| 329 _compiler = new api.Compiler(provider, handler, | 329 _compiler = new api.Compiler(provider, handler, |
| 330 libraryUri, packageUri, <String>[]); | 330 libraryUri, packageUri, <String>[]); |
| 331 var scriptUri = cwd.resolve(nativeToUriPath(script)); | 331 var scriptUri = cwd.resolve(nativeToUriPath(script.toNativePath())); |
| 332 // TODO(johnniwinther): Detect file not found | 332 // TODO(johnniwinther): Detect file not found |
| 333 _compiler.run(scriptUri); | 333 _compiler.run(scriptUri); |
| 334 } | 334 } |
| 335 | 335 |
| 336 Dart2JsCompilation.library(List<String> libraries, String libraryRoot, | 336 Dart2JsCompilation.library(List<Path> libraries, Path libraryRoot, |
| 337 [String packageRoot, List<String> opts = const []]) | 337 [Path packageRoot, List<String> opts = const <String>[]]) |
| 338 : cwd = getCurrentDirectory(), sourceFiles = <SourceFile>{} { | 338 : cwd = getCurrentDirectory(), sourceFiles = <SourceFile>{} { |
| 339 var libraryUri = cwd.resolve(nativeToUriPath(libraryRoot)); | 339 var libraryUri = cwd.resolve(nativeToUriPath(libraryRoot.toNativePath())); |
| 340 var packageUri; | 340 var packageUri; |
| 341 if (packageRoot !== null) { | 341 if (packageRoot !== null) { |
| 342 packageUri = cwd.resolve(nativeToUriPath(packageRoot)); | 342 packageUri = cwd.resolve(nativeToUriPath(packageRoot.toNativePath())); |
| 343 } else { | 343 } else { |
| 344 packageUri = libraryUri; | 344 packageUri = libraryUri; |
| 345 } | 345 } |
| 346 _compiler = new LibraryCompiler(provider, handler, | 346 _compiler = new LibraryCompiler(provider, handler, |
| 347 libraryUri, packageUri, <String>[]); | 347 libraryUri, packageUri, <String>[]); |
| 348 var librariesUri = <Uri>[]; | 348 var librariesUri = <Uri>[]; |
| 349 for (var library in libraries) { | 349 for (Path library in libraries) { |
| 350 librariesUri.add(cwd.resolve(nativeToUriPath(library))); | 350 librariesUri.add(cwd.resolve(nativeToUriPath(library.toNativePath()))); |
| 351 // TODO(johnniwinther): Detect file not found | 351 // TODO(johnniwinther): Detect file not found |
| 352 } | 352 } |
| 353 _compiler.runList(librariesUri); | 353 _compiler.runList(librariesUri); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void addLibrary(String path) { | 356 void addLibrary(String path) { |
| 357 var uri = cwd.resolve(nativeToUriPath(path)); | 357 var uri = cwd.resolve(nativeToUriPath(path)); |
| 358 _compiler.scanner.loadLibrary(uri, null); | 358 _compiler.scanner.loadLibrary(uri, null); |
| 359 } | 359 } |
| 360 | 360 |
| 361 MirrorSystem mirrors() => new Dart2JsMirrorSystem(_compiler); | 361 MirrorSystem mirrors() => new Dart2JsMirrorSystem(_compiler); |
| 362 |
| 363 Future<String> compileToJavaScript() => |
| 364 new Future<String>.immediate(_compiler.assembledCode); |
| 362 } | 365 } |
| 363 | 366 |
| 364 | 367 |
| 365 //------------------------------------------------------------------------------ | 368 //------------------------------------------------------------------------------ |
| 366 // Dart2Js specific extensions of mirror interfaces | 369 // Dart2Js specific extensions of mirror interfaces |
| 367 //------------------------------------------------------------------------------ | 370 //------------------------------------------------------------------------------ |
| 368 | 371 |
| 369 interface Dart2JsMirror extends Mirror { | 372 interface Dart2JsMirror extends Mirror { |
| 370 /** | 373 /** |
| 371 * A unique name used as the key in maps. | 374 * A unique name used as the key in maps. |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 if (node !== null) { | 1314 if (node !== null) { |
| 1312 var span = system.compiler.spanFromNode(node, script.uri); | 1315 var span = system.compiler.spanFromNode(node, script.uri); |
| 1313 return new Dart2JsLocation(script, span); | 1316 return new Dart2JsLocation(script, span); |
| 1314 } else { | 1317 } else { |
| 1315 var span = system.compiler.spanFromElement(_variable); | 1318 var span = system.compiler.spanFromElement(_variable); |
| 1316 return new Dart2JsLocation(script, span); | 1319 return new Dart2JsLocation(script, span); |
| 1317 } | 1320 } |
| 1318 } | 1321 } |
| 1319 } | 1322 } |
| 1320 | 1323 |
| OLD | NEW |