| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 final bool checkDeprecationInSdk; | 121 final bool checkDeprecationInSdk; |
| 122 | 122 |
| 123 bool disableInlining = false; | 123 bool disableInlining = false; |
| 124 | 124 |
| 125 final Tracer tracer; | 125 final Tracer tracer; |
| 126 | 126 |
| 127 CompilerTask measuredTask; | 127 CompilerTask measuredTask; |
| 128 Element _currentElement; | 128 Element _currentElement; |
| 129 LibraryElement coreLibrary; | 129 LibraryElement coreLibrary; |
| 130 LibraryElement isolateLibrary; | 130 LibraryElement isolateLibrary; |
| 131 LibraryElement isolateHelperLibrary; |
| 131 LibraryElement jsHelperLibrary; | 132 LibraryElement jsHelperLibrary; |
| 132 LibraryElement interceptorsLibrary; | 133 LibraryElement interceptorsLibrary; |
| 133 LibraryElement foreignLibrary; | 134 LibraryElement foreignLibrary; |
| 134 LibraryElement mainApp; | 135 LibraryElement mainApp; |
| 135 | 136 |
| 136 ClassElement objectClass; | 137 ClassElement objectClass; |
| 137 ClassElement closureClass; | 138 ClassElement closureClass; |
| 138 ClassElement dynamicClass; | 139 ClassElement dynamicClass; |
| 139 ClassElement boolClass; | 140 ClassElement boolClass; |
| 140 ClassElement numClass; | 141 ClassElement numClass; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 396 |
| 396 createInvocationMirrorElement = | 397 createInvocationMirrorElement = |
| 397 findHelper(CREATE_INVOCATION_MIRROR); | 398 findHelper(CREATE_INVOCATION_MIRROR); |
| 398 enqueuer.resolution.addToWorkList(createInvocationMirrorElement); | 399 enqueuer.resolution.addToWorkList(createInvocationMirrorElement); |
| 399 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); | 400 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); |
| 400 } | 401 } |
| 401 | 402 |
| 402 void enableIsolateSupport(LibraryElement element) { | 403 void enableIsolateSupport(LibraryElement element) { |
| 403 // TODO(ahe): Move this method to Enqueuer. | 404 // TODO(ahe): Move this method to Enqueuer. |
| 404 isolateLibrary = element.patch; | 405 isolateLibrary = element.patch; |
| 405 enqueuer.resolution.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); | |
| 406 enqueuer.resolution.addToWorkList( | 406 enqueuer.resolution.addToWorkList( |
| 407 isolateLibrary.find(const SourceString('_currentIsolate'))); | 407 isolateHelperLibrary.find(START_ROOT_ISOLATE)); |
| 408 enqueuer.resolution.addToWorkList( | 408 enqueuer.resolution.addToWorkList( |
| 409 isolateLibrary.find(const SourceString('_callInIsolate'))); | 409 isolateHelperLibrary.find(const SourceString('_currentIsolate'))); |
| 410 enqueuer.codegen.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); | 410 enqueuer.resolution.addToWorkList( |
| 411 isolateHelperLibrary.find(const SourceString('_callInIsolate'))); |
| 412 enqueuer.codegen.addToWorkList( |
| 413 isolateHelperLibrary.find(START_ROOT_ISOLATE)); |
| 411 } | 414 } |
| 412 | 415 |
| 413 bool hasIsolateSupport() => isolateLibrary != null; | 416 bool hasIsolateSupport() => isolateLibrary != null; |
| 414 | 417 |
| 415 /** | 418 /** |
| 416 * This method is called before [library] import and export scopes have been | 419 * This method is called before [library] import and export scopes have been |
| 417 * set up. | 420 * set up. |
| 418 */ | 421 */ |
| 419 void onLibraryScanned(LibraryElement library, Uri uri) { | 422 void onLibraryScanned(LibraryElement library, Uri uri) { |
| 420 if (dynamicClass != null) { | 423 if (dynamicClass != null) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 types = new Types(this, dynamicClass); | 459 types = new Types(this, dynamicClass); |
| 457 if (!missingClasses.isEmpty) { | 460 if (!missingClasses.isEmpty) { |
| 458 cancel('core library does not contain required classes: $missingClasses'); | 461 cancel('core library does not contain required classes: $missingClasses'); |
| 459 } | 462 } |
| 460 } | 463 } |
| 461 | 464 |
| 462 void scanBuiltinLibraries() { | 465 void scanBuiltinLibraries() { |
| 463 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 466 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
| 464 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 467 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
| 465 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); | 468 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); |
| 469 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); |
| 470 // The helper library does not use the native language extension, |
| 471 // so we manually set the native classes this library defines. |
| 472 // TODO(ngeoffray): Enable annotations on these classes. |
| 473 ClassElement cls = |
| 474 isolateHelperLibrary.find(const SourceString('_WorkerStub')); |
| 475 cls.setNative('"*Worker"'); |
| 466 | 476 |
| 467 // The core library was loaded and patched before jsHelperLibrary was | 477 // The core library was loaded and patched before jsHelperLibrary was |
| 468 // initialized, so it wasn't imported into those two libraries during | 478 // initialized, so it wasn't imported into those two libraries during |
| 469 // patching. | 479 // patching. |
| 470 importHelperLibrary(coreLibrary); | 480 importHelperLibrary(coreLibrary); |
| 471 importHelperLibrary(interceptorsLibrary); | 481 importHelperLibrary(interceptorsLibrary); |
| 472 | 482 |
| 473 importForeignLibrary(jsHelperLibrary); | 483 importForeignLibrary(jsHelperLibrary); |
| 474 importForeignLibrary(interceptorsLibrary); | 484 importForeignLibrary(interceptorsLibrary); |
| 475 | 485 |
| 486 importForeignLibrary(isolateHelperLibrary); |
| 487 importHelperLibrary(isolateHelperLibrary); |
| 488 |
| 476 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 489 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
| 477 identicalFunction = coreLibrary.find(const SourceString('identical')); | 490 identicalFunction = coreLibrary.find(const SourceString('identical')); |
| 478 | 491 |
| 479 initializeSpecialClasses(); | 492 initializeSpecialClasses(); |
| 480 | 493 |
| 481 functionClass.ensureResolved(this); | 494 functionClass.ensureResolved(this); |
| 482 functionApplyMethod = | 495 functionApplyMethod = |
| 483 functionClass.lookupLocalMember(const SourceString('apply')); | 496 functionClass.lookupLocalMember(const SourceString('apply')); |
| 484 jsInvocationMirrorClass.ensureResolved(this); | 497 jsInvocationMirrorClass.ensureResolved(this); |
| 485 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( | 498 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( |
| 486 const SourceString('invokeOn')); | 499 const SourceString('invokeOn')); |
| 487 } | 500 } |
| 488 | 501 |
| 489 void importHelperLibrary(LibraryElement library) { | 502 void importHelperLibrary(LibraryElement library) { |
| 490 if (jsHelperLibrary != null) { | 503 if (jsHelperLibrary != null) { |
| 491 libraryLoader.importLibrary(library, jsHelperLibrary, null); | 504 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
| 492 } | 505 } |
| 493 } | 506 } |
| 494 | 507 |
| 495 /** | 508 /** |
| 496 * Get an [Uri] pointing to a patch for the dart: library with | 509 * Get an [Uri] pointing to a patch for the dart: library with |
| 497 * the given path. Returns null if there is no patch. | 510 * the given path. Returns null if there is no patch. |
| 498 */ | 511 */ |
| 499 Uri resolvePatchUri(String dartLibraryPath); | 512 Uri resolvePatchUri(String dartLibraryPath); |
| 500 | 513 |
| 501 /** Define the JS helper functions in the given library. */ | 514 /** Define the JS helper functions in the given library. */ |
| 502 void importForeignLibrary(LibraryElement library) { | 515 void importForeignLibrary(LibraryElement library) { |
| 503 if (jsHelperLibrary != null) { | 516 if (foreignLibrary != null) { |
| 504 libraryLoader.importLibrary(library, foreignLibrary, null); | 517 libraryLoader.importLibrary(library, foreignLibrary, null); |
| 505 } | 518 } |
| 506 } | 519 } |
| 507 | 520 |
| 521 void importIsolateHelperLibrary(LibraryElement library) { |
| 522 if (isolateHelperLibrary != null) { |
| 523 libraryLoader.importLibrary(library, isolateHelperLibrary, null); |
| 524 } |
| 525 } |
| 526 |
| 508 // TODO(karlklose,floitsch): move this to the javascript backend. | 527 // TODO(karlklose,floitsch): move this to the javascript backend. |
| 509 /** Enable the 'JS' helper for a library if needed. */ | 528 /** Enable the 'JS' helper for a library if needed. */ |
| 510 void maybeEnableJSHelper(LibraryElement library) { | 529 void maybeEnableJSHelper(LibraryElement library) { |
| 511 String libraryName = library.uri.toString(); | 530 String libraryName = library.uri.toString(); |
| 512 bool nativeTest = library.entryCompilationUnit.script.name.contains( | 531 bool nativeTest = library.entryCompilationUnit.script.name.contains( |
| 513 'dart/tests/compiler/dart2js_native'); | 532 'dart/tests/compiler/dart2js_native'); |
| 514 if (nativeTest | 533 if (nativeTest |
| 515 || libraryName == 'dart:mirrors' | 534 || libraryName == 'dart:mirrors' |
| 516 || libraryName == 'dart:isolate' | |
| 517 || libraryName == 'dart:math' | 535 || libraryName == 'dart:math' |
| 518 || libraryName == 'dart:html' | 536 || libraryName == 'dart:html' |
| 519 || libraryName == 'dart:html_common' | 537 || libraryName == 'dart:html_common' |
| 520 || libraryName == 'dart:indexed_db' | 538 || libraryName == 'dart:indexed_db' |
| 521 || libraryName == 'dart:svg' | 539 || libraryName == 'dart:svg' |
| 522 || libraryName == 'dart:web_audio') { | 540 || libraryName == 'dart:web_audio') { |
| 523 if (nativeTest | 541 if (nativeTest |
| 524 || libraryName == 'dart:html' | 542 || libraryName == 'dart:html' |
| 525 || libraryName == 'dart:html_common' | 543 || libraryName == 'dart:html_common' |
| 526 || libraryName == 'dart:indexed_db' | 544 || libraryName == 'dart:indexed_db' |
| 527 || libraryName == 'dart:svg') { | 545 || libraryName == 'dart:svg') { |
| 528 // dart:html and dart:svg need access to convertDartClosureToJS and | 546 // dart:html and dart:svg need access to convertDartClosureToJS and |
| 529 // annotation classes. | 547 // annotation classes. |
| 530 // dart:mirrors needs access to the Primitives class. | 548 // dart:mirrors needs access to the Primitives class. |
| 531 importHelperLibrary(library); | 549 importHelperLibrary(library); |
| 532 } | 550 } |
| 533 library.addToScope( | 551 library.addToScope( |
| 534 foreignLibrary.findLocal(const SourceString('JS')), this); | 552 foreignLibrary.findLocal(const SourceString('JS')), this); |
| 535 Element jsIndexingBehaviorInterface = | 553 Element jsIndexingBehaviorInterface = |
| 536 findHelper(const SourceString('JavaScriptIndexingBehavior')); | 554 findHelper(const SourceString('JavaScriptIndexingBehavior')); |
| 537 if (jsIndexingBehaviorInterface != null) { | 555 if (jsIndexingBehaviorInterface != null) { |
| 538 library.addToScope(jsIndexingBehaviorInterface, this); | 556 library.addToScope(jsIndexingBehaviorInterface, this); |
| 539 } | 557 } |
| 540 } | 558 } |
| 541 } | 559 } |
| 542 | 560 |
| 561 void maybeEnableIsolateHelper(LibraryElement library) { |
| 562 String libraryName = library.uri.toString(); |
| 563 if (libraryName == 'dart:isolate' |
| 564 || libraryName == 'dart:html') { |
| 565 importIsolateHelperLibrary(library); |
| 566 } |
| 567 } |
| 568 |
| 543 void runCompiler(Uri uri) { | 569 void runCompiler(Uri uri) { |
| 544 log('compiling $uri ($BUILD_ID)'); | 570 log('compiling $uri ($BUILD_ID)'); |
| 545 scanBuiltinLibraries(); | 571 scanBuiltinLibraries(); |
| 546 mainApp = libraryLoader.loadLibrary(uri, null, uri); | 572 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
| 547 libraries.forEach((_, library) { | 573 libraries.forEach((_, library) { |
| 548 maybeEnableJSHelper(library); | 574 maybeEnableJSHelper(library); |
| 575 maybeEnableIsolateHelper(library); |
| 549 }); | 576 }); |
| 550 final Element main = mainApp.find(MAIN); | 577 final Element main = mainApp.find(MAIN); |
| 551 if (main == null) { | 578 if (main == null) { |
| 552 reportFatalError('Could not find $MAIN', mainApp); | 579 reportFatalError('Could not find $MAIN', mainApp); |
| 553 } else { | 580 } else { |
| 554 if (!main.isFunction()) reportFatalError('main is not a function', main); | 581 if (!main.isFunction()) reportFatalError('main is not a function', main); |
| 555 FunctionElement mainMethod = main; | 582 FunctionElement mainMethod = main; |
| 556 FunctionSignature parameters = mainMethod.computeSignature(this); | 583 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 557 parameters.forEachParameter((Element parameter) { | 584 parameters.forEachParameter((Element parameter) { |
| 558 reportFatalError('main cannot have parameters', parameter); | 585 reportFatalError('main cannot have parameters', parameter); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 981 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 955 // information on assertion errors. | 982 // information on assertion errors. |
| 956 if (condition is Function){ | 983 if (condition is Function){ |
| 957 condition = condition(); | 984 condition = condition(); |
| 958 } | 985 } |
| 959 if (spannable == null || !condition) { | 986 if (spannable == null || !condition) { |
| 960 throw new SpannableAssertionFailure(spannable, message); | 987 throw new SpannableAssertionFailure(spannable, message); |
| 961 } | 988 } |
| 962 return true; | 989 return true; |
| 963 } | 990 } |
| OLD | NEW |