Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compiler.dart

Issue 11973006: Private libraries used. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update copy_dart.py to handle show in one line. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/lib/async_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 internalErrorOnElement(coreLibrary,
515 'dart:core library does not contain required classes: '
516 '$missingCoreClasses');
517 }
518
519 final List missingHelperClasses = [];
520 ClassElement lookupHelperClass(SourceString name) {
521 ClassElement result = jsHelperLibrary.find(name);
522 if (result == null) {
523 missingHelperClasses.add(name.slowToString());
524 }
525 return result;
526 }
513 jsInvocationMirrorClass = 527 jsInvocationMirrorClass =
514 lookupSpecialClass(const SourceString('JSInvocationMirror')); 528 lookupHelperClass(const SourceString('JSInvocationMirror'));
515 closureClass = lookupSpecialClass(const SourceString('Closure')); 529 closureClass = lookupHelperClass(const SourceString('Closure'));
516 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); 530 dynamicClass = lookupHelperClass(const SourceString('Dynamic_'));
517 nullClass = lookupSpecialClass(const SourceString('Null')); 531 nullClass = lookupHelperClass(const SourceString('Null'));
532 if (!missingHelperClasses.isEmpty) {
533 internalErrorOnElement(jsHelperLibrary,
534 'dart:_js_helper library does not contain required classes: '
535 '$missingHelperClasses');
536 }
537
518 types = new Types(this, dynamicClass); 538 types = new Types(this, dynamicClass);
519 if (!missingClasses.isEmpty) {
520 cancel('core library does not contain required classes: $missingClasses');
521 }
522 } 539 }
523 540
524 void scanBuiltinLibraries() { 541 void scanBuiltinLibraries() {
525 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); 542 jsHelperLibrary = scanBuiltinLibrary('_js_helper');
526 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); 543 interceptorsLibrary = scanBuiltinLibrary('_interceptors');
527 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); 544 foreignLibrary = scanBuiltinLibrary('_foreign_helper');
528 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); 545 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper');
529 // The helper library does not use the native language extension, 546 // The helper library does not use the native language extension,
530 // so we manually set the native classes this library defines. 547 // so we manually set the native classes this library defines.
531 // TODO(ngeoffray): Enable annotations on these classes. 548 // TODO(ngeoffray): Enable annotations on these classes.
532 ClassElement cls = 549 ClassElement cls =
533 isolateHelperLibrary.find(const SourceString('_WorkerStub')); 550 isolateHelperLibrary.find(const SourceString('_WorkerStub'));
534 cls.setNative('"*Worker"'); 551 cls.setNative('"*Worker"');
535 552
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')); 553 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper'));
549 identicalFunction = coreLibrary.find(const SourceString('identical')); 554 identicalFunction = coreLibrary.find(const SourceString('identical'));
550 555
551 initializeSpecialClasses(); 556 initializeSpecialClasses();
552 557
553 functionClass.ensureResolved(this); 558 functionClass.ensureResolved(this);
554 functionApplyMethod = 559 functionApplyMethod =
555 functionClass.lookupLocalMember(const SourceString('apply')); 560 functionClass.lookupLocalMember(const SourceString('apply'));
556 jsInvocationMirrorClass.ensureResolved(this); 561 jsInvocationMirrorClass.ensureResolved(this);
557 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( 562 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(
(...skipping 12 matching lines...) Expand all
570 libraryLoader.importLibrary(library, jsHelperLibrary, null); 575 libraryLoader.importLibrary(library, jsHelperLibrary, null);
571 } 576 }
572 } 577 }
573 578
574 /** 579 /**
575 * Get an [Uri] pointing to a patch for the dart: library with 580 * Get an [Uri] pointing to a patch for the dart: library with
576 * the given path. Returns null if there is no patch. 581 * the given path. Returns null if there is no patch.
577 */ 582 */
578 Uri resolvePatchUri(String dartLibraryPath); 583 Uri resolvePatchUri(String dartLibraryPath);
579 584
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.canonicalUri.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:chrome'
602 || libraryName == 'dart:mirrors'
603 || libraryName == 'dart:math'
604 || libraryName == 'dart:html'
605 || libraryName == 'dart:html_common'
606 || libraryName == 'dart:indexed_db'
607 || libraryName == 'dart:svg'
608 || libraryName == 'dart:web_audio') {
609 if (nativeTest
610 || libraryName == 'dart:chrome'
611 || libraryName == 'dart:html'
612 || libraryName == 'dart:html_common'
613 || libraryName == 'dart:indexed_db'
614 || libraryName == 'dart:svg') {
615 // dart:html and dart:svg need access to convertDartClosureToJS and
616 // annotation classes.
617 // dart:mirrors needs access to the Primitives class.
618 importHelperLibrary(library);
619 }
620 library.addToScope(
621 foreignLibrary.findLocal(const SourceString('JS')), this);
622 Element jsIndexingBehaviorInterface =
623 findHelper(const SourceString('JavaScriptIndexingBehavior'));
624 if (jsIndexingBehaviorInterface != null) {
625 library.addToScope(jsIndexingBehaviorInterface, this);
626 }
627 }
628 }
629
630 void maybeEnableIsolateHelper(LibraryElement library) {
631 String libraryName = library.canonicalUri.toString();
632 if (libraryName == 'dart:isolate'
633 || libraryName == 'dart:html'
634 // TODO(floitsch): create a separate async-helper library instead of
635 // importing the isolate-library just for TimerImpl.
636 || libraryName == 'dart:async') {
637 importIsolateHelperLibrary(library);
638 }
639 }
640
641 void runCompiler(Uri uri) { 585 void runCompiler(Uri uri) {
642 assert(uri != null || analyzeOnly); 586 assert(uri != null || analyzeOnly);
643 scanBuiltinLibraries(); 587 scanBuiltinLibraries();
644 if (librariesToAnalyzeWhenRun != null) { 588 if (librariesToAnalyzeWhenRun != null) {
645 for (Uri libraryUri in librariesToAnalyzeWhenRun) { 589 for (Uri libraryUri in librariesToAnalyzeWhenRun) {
646 log('analyzing $libraryUri ($BUILD_ID)'); 590 log('analyzing $libraryUri ($BUILD_ID)');
647 libraryLoader.loadLibrary(libraryUri, null, libraryUri); 591 libraryLoader.loadLibrary(libraryUri, null, libraryUri);
648 } 592 }
649 } 593 }
650 if (uri != null) { 594 if (uri != null) {
651 if (analyzeOnly) { 595 if (analyzeOnly) {
652 log('analyzing $uri ($BUILD_ID)'); 596 log('analyzing $uri ($BUILD_ID)');
653 } else { 597 } else {
654 log('compiling $uri ($BUILD_ID)'); 598 log('compiling $uri ($BUILD_ID)');
655 } 599 }
656 mainApp = libraryLoader.loadLibrary(uri, null, uri); 600 mainApp = libraryLoader.loadLibrary(uri, null, uri);
657 } 601 }
658 libraries.forEach((_, library) {
659 maybeEnableJSHelper(library);
660 maybeEnableIsolateHelper(library);
661 });
662 Element main = null; 602 Element main = null;
663 if (mainApp != null) { 603 if (mainApp != null) {
664 main = mainApp.find(MAIN); 604 main = mainApp.find(MAIN);
665 if (main == null) { 605 if (main == null) {
666 if (!analyzeOnly) { 606 if (!analyzeOnly) {
667 // Allow analyze only of libraries with no main. 607 // Allow analyze only of libraries with no main.
668 reportFatalError('Could not find $MAIN', mainApp); 608 reportFatalError('Could not find $MAIN', mainApp);
669 } else if (!analyzeAll) { 609 } else if (!analyzeAll) {
670 reportFatalError( 610 reportFatalError(
671 "Could not find $MAIN. " 611 "Could not find $MAIN. "
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 // TODO(johnniwinther): Use [spannable] and [message] to provide better 1080 // TODO(johnniwinther): Use [spannable] and [message] to provide better
1141 // information on assertion errors. 1081 // information on assertion errors.
1142 if (condition is Function){ 1082 if (condition is Function){
1143 condition = condition(); 1083 condition = condition();
1144 } 1084 }
1145 if (spannable == null || !condition) { 1085 if (spannable == null || !condition) {
1146 throw new SpannableAssertionFailure(spannable, message); 1086 throw new SpannableAssertionFailure(spannable, message);
1147 } 1087 }
1148 return true; 1088 return true;
1149 } 1089 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/lib/async_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698