Chromium Code Reviews| 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 // this way. | 485 // this way. |
| 486 withCurrentElement(dynamicClass, () { | 486 withCurrentElement(dynamicClass, () { |
| 487 library.addToScope(dynamicClass, this); | 487 library.addToScope(dynamicClass, this); |
| 488 }); | 488 }); |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 LibraryElement scanBuiltinLibrary(String filename); | 492 LibraryElement scanBuiltinLibrary(String filename); |
| 493 | 493 |
| 494 void initializeSpecialClasses() { | 494 void initializeSpecialClasses() { |
| 495 final List missingClasses = []; | 495 final List missingCoreClasses = []; |
| 496 ClassElement lookupSpecialClass(SourceString name) { | 496 ClassElement lookupCoreClass(SourceString name) { |
| 497 ClassElement result = coreLibrary.find(name); | 497 ClassElement result = coreLibrary.find(name); |
| 498 if (result == null) { | 498 if (result == null) { |
| 499 missingClasses.add(name.slowToString()); | 499 missingCoreClasses.add(name.slowToString()); |
| 500 } | 500 } |
| 501 return result; | 501 return result; |
| 502 } | 502 } |
| 503 objectClass = lookupSpecialClass(const SourceString('Object')); | 503 objectClass = lookupCoreClass(const SourceString('Object')); |
| 504 boolClass = lookupSpecialClass(const SourceString('bool')); | 504 boolClass = lookupCoreClass(const SourceString('bool')); |
| 505 numClass = lookupSpecialClass(const SourceString('num')); | 505 numClass = lookupCoreClass(const SourceString('num')); |
| 506 intClass = lookupSpecialClass(const SourceString('int')); | 506 intClass = lookupCoreClass(const SourceString('int')); |
| 507 doubleClass = lookupSpecialClass(const SourceString('double')); | 507 doubleClass = lookupCoreClass(const SourceString('double')); |
| 508 stringClass = lookupSpecialClass(const SourceString('String')); | 508 stringClass = lookupCoreClass(const SourceString('String')); |
| 509 functionClass = lookupSpecialClass(const SourceString('Function')); | 509 functionClass = lookupCoreClass(const SourceString('Function')); |
| 510 listClass = lookupSpecialClass(const SourceString('List')); | 510 listClass = lookupCoreClass(const SourceString('List')); |
| 511 typeClass = lookupSpecialClass(const SourceString('Type')); | 511 typeClass = lookupCoreClass(const SourceString('Type')); |
| 512 mapClass = lookupSpecialClass(const SourceString('Map')); | 512 mapClass = lookupCoreClass(const SourceString('Map')); |
| 513 if (!missingCoreClasses.isEmpty) { | |
| 514 cancel('core library does not contain required classes: ' | |
|
ahe
2013/01/16 18:13:41
core -> dart:core.
ahe
2013/01/16 18:13:41
internalErrorOnElement(coreLibrary, ...
Then the
Johnni Winther
2013/01/22 13:35:53
Done.
Johnni Winther
2013/01/22 13:35:53
Done.
| |
| 515 '$missingCoreClasses'); | |
| 516 } | |
| 517 | |
| 518 final List missingHelperClasses = []; | |
| 519 ClassElement lookupHelperClass(SourceString name) { | |
| 520 ClassElement result = jsHelperLibrary.find(name); | |
| 521 if (result == null) { | |
| 522 missingHelperClasses.add(name.slowToString()); | |
| 523 } | |
| 524 return result; | |
| 525 } | |
| 513 jsInvocationMirrorClass = | 526 jsInvocationMirrorClass = |
| 514 lookupSpecialClass(const SourceString('JSInvocationMirror')); | 527 lookupHelperClass(const SourceString('JSInvocationMirror')); |
| 515 closureClass = lookupSpecialClass(const SourceString('Closure')); | 528 closureClass = lookupHelperClass(const SourceString('Closure')); |
| 516 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); | 529 dynamicClass = lookupHelperClass(const SourceString('Dynamic_')); |
| 517 nullClass = lookupSpecialClass(const SourceString('Null')); | 530 nullClass = lookupHelperClass(const SourceString('Null')); |
| 531 if (!missingHelperClasses.isEmpty) { | |
| 532 cancel('js helper library does not contain required classes: ' | |
|
ahe
2013/01/16 18:13:41
js helper -> dart:_whatever_its_name_is
ahe
2013/01/16 18:13:41
Also, internalErrorOnElement. Even more important
Johnni Winther
2013/01/22 13:35:53
Done.
Johnni Winther
2013/01/22 13:35:53
Done.
| |
| 533 '$missingHelperClasses'); | |
| 534 } | |
| 535 | |
| 518 types = new Types(this, dynamicClass); | 536 types = new Types(this, dynamicClass); |
| 519 if (!missingClasses.isEmpty) { | |
| 520 cancel('core library does not contain required classes: $missingClasses'); | |
| 521 } | |
| 522 } | 537 } |
| 523 | 538 |
| 524 void scanBuiltinLibraries() { | 539 void scanBuiltinLibraries() { |
| 525 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 540 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
| 526 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 541 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
| 527 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); | 542 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); |
| 528 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); | 543 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); |
| 529 // The helper library does not use the native language extension, | 544 // The helper library does not use the native language extension, |
| 530 // so we manually set the native classes this library defines. | 545 // so we manually set the native classes this library defines. |
| 531 // TODO(ngeoffray): Enable annotations on these classes. | 546 // TODO(ngeoffray): Enable annotations on these classes. |
| 532 ClassElement cls = | 547 ClassElement cls = |
| 533 isolateHelperLibrary.find(const SourceString('_WorkerStub')); | 548 isolateHelperLibrary.find(const SourceString('_WorkerStub')); |
| 534 cls.setNative('"*Worker"'); | 549 cls.setNative('"*Worker"'); |
| 535 | 550 |
| 536 // The core library was loaded and patched before jsHelperLibrary was | |
| 537 // initialized, so it wasn't imported into those two libraries during | |
| 538 // patching. | |
| 539 importHelperLibrary(coreLibrary); | |
| 540 importHelperLibrary(interceptorsLibrary); | |
| 541 | |
| 542 importForeignLibrary(jsHelperLibrary); | |
| 543 importForeignLibrary(interceptorsLibrary); | |
| 544 | |
| 545 importForeignLibrary(isolateHelperLibrary); | |
| 546 importHelperLibrary(isolateHelperLibrary); | |
| 547 | |
| 548 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 551 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
| 549 identicalFunction = coreLibrary.find(const SourceString('identical')); | 552 identicalFunction = coreLibrary.find(const SourceString('identical')); |
| 550 | 553 |
| 551 initializeSpecialClasses(); | 554 initializeSpecialClasses(); |
| 552 | 555 |
| 553 functionClass.ensureResolved(this); | 556 functionClass.ensureResolved(this); |
| 554 functionApplyMethod = | 557 functionApplyMethod = |
| 555 functionClass.lookupLocalMember(const SourceString('apply')); | 558 functionClass.lookupLocalMember(const SourceString('apply')); |
| 556 jsInvocationMirrorClass.ensureResolved(this); | 559 jsInvocationMirrorClass.ensureResolved(this); |
| 557 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( | 560 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 570 libraryLoader.importLibrary(library, jsHelperLibrary, null); | 573 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
| 571 } | 574 } |
| 572 } | 575 } |
| 573 | 576 |
| 574 /** | 577 /** |
| 575 * Get an [Uri] pointing to a patch for the dart: library with | 578 * Get an [Uri] pointing to a patch for the dart: library with |
| 576 * the given path. Returns null if there is no patch. | 579 * the given path. Returns null if there is no patch. |
| 577 */ | 580 */ |
| 578 Uri resolvePatchUri(String dartLibraryPath); | 581 Uri resolvePatchUri(String dartLibraryPath); |
| 579 | 582 |
| 580 /** Define the JS helper functions in the given library. */ | |
| 581 void importForeignLibrary(LibraryElement library) { | |
| 582 if (foreignLibrary != null) { | |
| 583 libraryLoader.importLibrary(library, foreignLibrary, null); | |
| 584 } | |
| 585 } | |
| 586 | |
| 587 void importIsolateHelperLibrary(LibraryElement library) { | |
| 588 if (isolateHelperLibrary != null) { | |
| 589 libraryLoader.importLibrary(library, isolateHelperLibrary, null); | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 // TODO(karlklose,floitsch): move this to the javascript backend. | |
| 594 /** Enable the 'JS' helper for a library if needed. */ | |
| 595 void maybeEnableJSHelper(LibraryElement library) { | |
| 596 String libraryName = library.uri.toString(); | |
| 597 bool nativeTest = library.entryCompilationUnit.script.name.contains( | |
| 598 'dart/tests/compiler/dart2js_native'); | |
| 599 if (nativeTest | |
| 600 || libraryName == 'dart:async' | |
| 601 || libraryName == 'dart:mirrors' | |
| 602 || libraryName == 'dart:math' | |
| 603 || libraryName == 'dart:html' | |
| 604 || libraryName == 'dart:html_common' | |
| 605 || libraryName == 'dart:indexed_db' | |
| 606 || libraryName == 'dart:svg' | |
| 607 || libraryName == 'dart:web_audio') { | |
| 608 if (nativeTest | |
| 609 || libraryName == 'dart:html' | |
| 610 || libraryName == 'dart:html_common' | |
| 611 || libraryName == 'dart:indexed_db' | |
| 612 || libraryName == 'dart:svg') { | |
| 613 // dart:html and dart:svg need access to convertDartClosureToJS and | |
| 614 // annotation classes. | |
| 615 // dart:mirrors needs access to the Primitives class. | |
| 616 importHelperLibrary(library); | |
| 617 } | |
| 618 library.addToScope( | |
| 619 foreignLibrary.findLocal(const SourceString('JS')), this); | |
| 620 Element jsIndexingBehaviorInterface = | |
| 621 findHelper(const SourceString('JavaScriptIndexingBehavior')); | |
| 622 if (jsIndexingBehaviorInterface != null) { | |
| 623 library.addToScope(jsIndexingBehaviorInterface, this); | |
| 624 } | |
| 625 } | |
| 626 } | |
| 627 | |
| 628 void maybeEnableIsolateHelper(LibraryElement library) { | |
| 629 String libraryName = library.uri.toString(); | |
| 630 if (libraryName == 'dart:isolate' | |
| 631 || libraryName == 'dart:html' | |
| 632 // TODO(floitsch): create a separate async-helper library instead of | |
| 633 // importing the isolate-library just for TimerImpl. | |
| 634 || libraryName == 'dart:async') { | |
| 635 importIsolateHelperLibrary(library); | |
| 636 } | |
| 637 } | |
| 638 | |
| 639 void runCompiler(Uri uri) { | 583 void runCompiler(Uri uri) { |
| 640 assert(uri != null || analyzeOnly); | 584 assert(uri != null || analyzeOnly); |
| 641 scanBuiltinLibraries(); | 585 scanBuiltinLibraries(); |
| 642 if (librariesToAnalyzeWhenRun != null) { | 586 if (librariesToAnalyzeWhenRun != null) { |
| 643 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 587 for (Uri libraryUri in librariesToAnalyzeWhenRun) { |
| 644 log('analyzing $libraryUri ($BUILD_ID)'); | 588 log('analyzing $libraryUri ($BUILD_ID)'); |
| 645 libraryLoader.loadLibrary(libraryUri, null, libraryUri); | 589 libraryLoader.loadLibrary(libraryUri, null, libraryUri); |
| 646 } | 590 } |
| 647 } | 591 } |
| 648 if (uri != null) { | 592 if (uri != null) { |
| 649 log('compiling $uri ($BUILD_ID)'); | 593 log('compiling $uri ($BUILD_ID)'); |
| 650 mainApp = libraryLoader.loadLibrary(uri, null, uri); | 594 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
| 651 } | 595 } |
| 652 libraries.forEach((_, library) { | |
| 653 maybeEnableJSHelper(library); | |
| 654 maybeEnableIsolateHelper(library); | |
| 655 }); | |
| 656 Element main = null; | 596 Element main = null; |
| 657 if (!analyzeOnly) { | 597 if (!analyzeOnly) { |
| 658 main = mainApp.find(MAIN); | 598 main = mainApp.find(MAIN); |
| 659 if (main == null) { | 599 if (main == null) { |
| 660 reportFatalError('Could not find $MAIN', mainApp); | 600 reportFatalError('Could not find $MAIN', mainApp); |
| 661 } else { | 601 } else { |
| 662 if (!main.isFunction()) reportFatalError('main is not a function', main) ; | 602 if (!main.isFunction()) reportFatalError('main is not a function', main) ; |
| 663 FunctionElement mainMethod = main; | 603 FunctionElement mainMethod = main; |
| 664 FunctionSignature parameters = mainMethod.computeSignature(this); | 604 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 665 parameters.forEachParameter((Element parameter) { | 605 parameters.forEachParameter((Element parameter) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 1047 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 1108 // information on assertion errors. | 1048 // information on assertion errors. |
| 1109 if (condition is Function){ | 1049 if (condition is Function){ |
| 1110 condition = condition(); | 1050 condition = condition(); |
| 1111 } | 1051 } |
| 1112 if (spannable == null || !condition) { | 1052 if (spannable == null || !condition) { |
| 1113 throw new SpannableAssertionFailure(spannable, message); | 1053 throw new SpannableAssertionFailure(spannable, message); |
| 1114 } | 1054 } |
| 1115 return true; | 1055 return true; |
| 1116 } | 1056 } |
| OLD | NEW |