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 18 matching lines...) Expand all Loading... | |
| 29 * | 29 * |
| 30 * Invariant: [element] must be a declaration element. | 30 * Invariant: [element] must be a declaration element. |
| 31 */ | 31 */ |
| 32 final Element element; | 32 final Element element; |
| 33 TreeElements resolutionTree; | 33 TreeElements resolutionTree; |
| 34 | 34 |
| 35 WorkItem(this.element, this.compilationContext) { | 35 WorkItem(this.element, this.compilationContext) { |
| 36 assert(invariant(element, element.isDeclaration)); | 36 assert(invariant(element, element.isDeclaration)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | |
| 40 void run(Compiler compiler, Enqueuer world); | 39 void run(Compiler compiler, Enqueuer world); |
| 41 } | 40 } |
| 42 | 41 |
| 43 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. | 42 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. |
| 44 class ResolutionWorkItem extends WorkItem { | 43 class ResolutionWorkItem extends WorkItem { |
| 45 ResolutionWorkItem(Element element, | 44 ResolutionWorkItem(Element element, |
| 46 ItemCompilationContext compilationContext) | 45 ItemCompilationContext compilationContext) |
| 47 : super(element, compilationContext); | 46 : super(element, compilationContext); |
| 48 | 47 |
| 49 void run(Compiler compiler, ResolutionEnqueuer world) { | 48 void run(Compiler compiler, ResolutionEnqueuer world) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 74 | 73 |
| 75 typedef void PostProcessAction(); | 74 typedef void PostProcessAction(); |
| 76 | 75 |
| 77 class PostProcessTask { | 76 class PostProcessTask { |
| 78 final Element element; | 77 final Element element; |
| 79 final PostProcessAction action; | 78 final PostProcessAction action; |
| 80 | 79 |
| 81 PostProcessTask(this.element, this.action); | 80 PostProcessTask(this.element, this.action); |
| 82 } | 81 } |
| 83 | 82 |
| 84 class ReadingFilesTask extends CompilerTask { | |
| 85 ReadingFilesTask(Compiler compiler) : super(compiler); | |
| 86 String get name => 'Reading input files'; | |
| 87 } | |
| 88 | |
| 89 abstract class Backend { | 83 abstract class Backend { |
| 90 final Compiler compiler; | 84 final Compiler compiler; |
| 91 final ConstantSystem constantSystem; | 85 final ConstantSystem constantSystem; |
| 92 | 86 |
| 93 Backend(this.compiler, | 87 Backend(this.compiler, |
| 94 [ConstantSystem constantSystem = DART_CONSTANT_SYSTEM]) | 88 [ConstantSystem constantSystem = DART_CONSTANT_SYSTEM]) |
| 95 : this.constantSystem = constantSystem; | 89 : this.constantSystem = constantSystem; |
| 96 | 90 |
| 97 void initializeHelperClasses() {} | 91 void initializeHelperClasses() {} |
| 98 | 92 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass; | 232 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass; |
| 239 | 233 |
| 240 bool isDefaultNoSuchMethodImplementation(Element element) { | 234 bool isDefaultNoSuchMethodImplementation(Element element) { |
| 241 assert(element.name == Compiler.NO_SUCH_METHOD); | 235 assert(element.name == Compiler.NO_SUCH_METHOD); |
| 242 ClassElement classElement = element.getEnclosingClass(); | 236 ClassElement classElement = element.getEnclosingClass(); |
| 243 return classElement == compiler.objectClass; | 237 return classElement == compiler.objectClass; |
| 244 } | 238 } |
| 245 | 239 |
| 246 void registerStaticUse(Element element, Enqueuer enqueuer) {} | 240 void registerStaticUse(Element element, Enqueuer enqueuer) {} |
| 247 | 241 |
| 248 void onLibraryLoaded(LibraryElement library, Uri uri) {} | 242 Future onLibraryLoaded(LibraryElement library, Uri uri) { |
| 243 return new Future.value(); | |
| 244 } | |
| 249 | 245 |
| 250 void registerMetadataInstantiatedType(DartType type, TreeElements elements) {} | 246 void registerMetadataInstantiatedType(DartType type, TreeElements elements) {} |
| 251 void registerMetadataStaticUse(Element element) {} | 247 void registerMetadataStaticUse(Element element) {} |
| 252 void registerMetadataGetOfStaticFunction(FunctionElement element) {} | 248 void registerMetadataGetOfStaticFunction(FunctionElement element) {} |
| 253 | 249 |
| 254 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed | 250 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed |
| 255 /// annotations. The arguments corresponds to the unions of the corresponding | 251 /// annotations. The arguments corresponds to the unions of the corresponding |
| 256 /// fields of the annotations. | 252 /// fields of the annotations. |
| 257 void registerMirrorUsage(Set<String> symbols, | 253 void registerMirrorUsage(Set<String> symbols, |
| 258 Set<Element> targets, | 254 Set<Element> targets, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 LibraryLoader libraryLoader; | 490 LibraryLoader libraryLoader; |
| 495 TreeValidatorTask validator; | 491 TreeValidatorTask validator; |
| 496 ResolverTask resolver; | 492 ResolverTask resolver; |
| 497 closureMapping.ClosureTask closureToClassMapper; | 493 closureMapping.ClosureTask closureToClassMapper; |
| 498 TypeCheckerTask checker; | 494 TypeCheckerTask checker; |
| 499 ti.TypesTask typesTask; | 495 ti.TypesTask typesTask; |
| 500 Backend backend; | 496 Backend backend; |
| 501 ConstantHandler constantHandler; | 497 ConstantHandler constantHandler; |
| 502 ConstantHandler metadataHandler; | 498 ConstantHandler metadataHandler; |
| 503 EnqueueTask enqueuer; | 499 EnqueueTask enqueuer; |
| 504 CompilerTask fileReadingTask; | |
| 505 DeferredLoadTask deferredLoadTask; | 500 DeferredLoadTask deferredLoadTask; |
| 506 MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask; | 501 MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask; |
| 507 ContainerTracer containerTracer; | 502 ContainerTracer containerTracer; |
| 508 String buildId; | 503 String buildId; |
| 509 | 504 |
| 510 static const SourceString MAIN = const SourceString('main'); | 505 static const SourceString MAIN = const SourceString('main'); |
| 511 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); | 506 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); |
| 512 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); | 507 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); |
| 513 static const int NO_SUCH_METHOD_ARG_COUNT = 1; | 508 static const int NO_SUCH_METHOD_ARG_COUNT = 1; |
| 514 static const SourceString CREATE_INVOCATION_MIRROR = | 509 static const SourceString CREATE_INVOCATION_MIRROR = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 backend = jsBackend; | 591 backend = jsBackend; |
| 597 } else { | 592 } else { |
| 598 closureNamer = new closureMapping.ClosureNamer(); | 593 closureNamer = new closureMapping.ClosureNamer(); |
| 599 backend = new dart_backend.DartBackend(this, strips); | 594 backend = new dart_backend.DartBackend(this, strips); |
| 600 } | 595 } |
| 601 | 596 |
| 602 // No-op in production mode. | 597 // No-op in production mode. |
| 603 validator = new TreeValidatorTask(this); | 598 validator = new TreeValidatorTask(this); |
| 604 | 599 |
| 605 tasks = [ | 600 tasks = [ |
| 606 fileReadingTask = new ReadingFilesTask(this), | |
| 607 libraryLoader = new LibraryLoaderTask(this), | 601 libraryLoader = new LibraryLoaderTask(this), |
| 608 scanner = new ScannerTask(this), | 602 scanner = new ScannerTask(this), |
| 609 dietParser = new DietParserTask(this), | 603 dietParser = new DietParserTask(this), |
| 610 parser = new ParserTask(this), | 604 parser = new ParserTask(this), |
| 611 patchParser = new PatchParserTask(this), | 605 patchParser = new PatchParserTask(this), |
| 612 resolver = new ResolverTask(this), | 606 resolver = new ResolverTask(this), |
| 613 closureToClassMapper = new closureMapping.ClosureTask(this, closureNamer), | 607 closureToClassMapper = new closureMapping.ClosureTask(this, closureNamer), |
| 614 checker = new TypeCheckerTask(this), | 608 checker = new TypeCheckerTask(this), |
| 615 typesTask = new ti.TypesTask(this), | 609 typesTask = new ti.TypesTask(this), |
| 616 containerTracer = new ContainerTracer(this), | 610 containerTracer = new ContainerTracer(this), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 return spanFromTokens(annotation.beginToken, annotation.endToken); | 708 return spanFromTokens(annotation.beginToken, annotation.endToken); |
| 715 } else { | 709 } else { |
| 716 throw 'No error location.'; | 710 throw 'No error location.'; |
| 717 } | 711 } |
| 718 } | 712 } |
| 719 | 713 |
| 720 void log(message) { | 714 void log(message) { |
| 721 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 715 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
| 722 } | 716 } |
| 723 | 717 |
| 724 bool run(Uri uri) { | 718 Future<bool> run(Uri uri) { |
| 725 totalCompileTime.start(); | 719 totalCompileTime.start(); |
| 726 try { | 720 |
| 727 runCompiler(uri); | 721 return runCompiler(uri).catchError((error) { |
|
ahe
2013/09/02 13:43:24
I think runCompiler needs to be wrapped in try-cat
Johnni Winther
2013/09/03 07:51:39
Done.
| |
| 728 } on CompilerCancelledException catch (exception) { | 722 if (error is CompilerCancelledException) { |
| 729 log('Error: $exception'); | 723 log('Error: $error'); |
| 730 return false; | 724 return false; |
| 731 } catch (exception) { | 725 } |
| 726 | |
| 732 try { | 727 try { |
| 733 if (!hasCrashed) { | 728 if (!hasCrashed) { |
| 734 hasCrashed = true; | 729 hasCrashed = true; |
| 735 reportDiagnostic(new SourceSpan(uri, 0, 0), | 730 reportDiagnostic(new SourceSpan(uri, 0, 0), |
| 736 MessageKind.COMPILER_CRASHED.error().toString(), | 731 MessageKind.COMPILER_CRASHED.error().toString(), |
| 737 api.Diagnostic.CRASH); | 732 api.Diagnostic.CRASH); |
| 738 pleaseReportCrash(); | 733 pleaseReportCrash(); |
| 739 } | 734 } |
| 740 } catch (doubleFault) { | 735 } catch (doubleFault) { |
| 741 // Ignoring exceptions in exception handling. | 736 // Ignoring exceptions in exception handling. |
| 742 } | 737 } |
| 743 rethrow; | 738 throw error; |
| 744 } finally { | 739 }).whenComplete(() { |
| 745 tracer.close(); | 740 tracer.close(); |
| 746 totalCompileTime.stop(); | 741 totalCompileTime.stop(); |
| 747 } | 742 }).then((_) { |
| 748 return !compilationFailed; | 743 return !compilationFailed; |
| 744 }); | |
| 749 } | 745 } |
| 750 | 746 |
| 751 bool hasIsolateSupport() => isolateLibrary != null; | 747 bool hasIsolateSupport() => isolateLibrary != null; |
| 752 | 748 |
| 753 /** | 749 /** |
| 754 * This method is called before [library] import and export scopes have been | 750 * This method is called before [library] import and export scopes have been |
| 755 * set up. | 751 * set up. |
| 756 */ | 752 */ |
| 757 void onLibraryLoaded(LibraryElement library, Uri uri) { | 753 Future onLibraryLoaded(LibraryElement library, Uri uri) { |
| 758 if (dynamicClass != null) { | 754 if (dynamicClass != null) { |
| 759 // When loading the built-in libraries, dynamicClass is null. We | 755 // When loading the built-in libraries, dynamicClass is null. We |
| 760 // take advantage of this as core imports js_helper and sees [dynamic] | 756 // take advantage of this as core imports js_helper and sees [dynamic] |
| 761 // this way. | 757 // this way. |
| 762 withCurrentElement(dynamicClass, () { | 758 withCurrentElement(dynamicClass, () { |
| 763 library.addToScope(dynamicClass, this); | 759 library.addToScope(dynamicClass, this); |
| 764 }); | 760 }); |
| 765 } | 761 } |
| 766 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) { | 762 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) { |
| 767 mirrorsLibrary = library; | 763 mirrorsLibrary = library; |
| 768 mirrorSystemClass = | 764 mirrorSystemClass = |
| 769 findRequiredElement(library, const SourceString('MirrorSystem')); | 765 findRequiredElement(library, const SourceString('MirrorSystem')); |
| 770 mirrorsUsedClass = | 766 mirrorsUsedClass = |
| 771 findRequiredElement(library, const SourceString('MirrorsUsed')); | 767 findRequiredElement(library, const SourceString('MirrorsUsed')); |
| 772 } else if (uri == new Uri(scheme: 'dart', path: '_collection-dev')) { | 768 } else if (uri == new Uri(scheme: 'dart', path: '_collection-dev')) { |
| 773 symbolImplementationClass = | 769 symbolImplementationClass = |
| 774 findRequiredElement(library, const SourceString('Symbol')); | 770 findRequiredElement(library, const SourceString('Symbol')); |
| 775 } else if (uri == new Uri(scheme: 'dart', path: 'async')) { | 771 } else if (uri == new Uri(scheme: 'dart', path: 'async')) { |
| 776 deferredLibraryClass = | 772 deferredLibraryClass = |
| 777 findRequiredElement(library, const SourceString('DeferredLibrary')); | 773 findRequiredElement(library, const SourceString('DeferredLibrary')); |
| 778 } else if (isolateHelperLibrary == null | 774 } else if (isolateHelperLibrary == null |
| 779 && (uri == new Uri(scheme: 'dart', path: '_isolate_helper'))) { | 775 && (uri == new Uri(scheme: 'dart', path: '_isolate_helper'))) { |
| 780 isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper'); | 776 isolateHelperLibrary = library; |
| 781 } else if (foreignLibrary == null | 777 } else if (foreignLibrary == null |
| 782 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) { | 778 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) { |
| 783 foreignLibrary = scanBuiltinLibrary('_foreign_helper'); | 779 foreignLibrary = library; |
| 784 } | 780 } |
| 785 backend.onLibraryLoaded(library, uri); | 781 return backend.onLibraryLoaded(library, uri); |
| 786 } | 782 } |
| 787 | 783 |
| 788 Element findRequiredElement(LibraryElement library, SourceString name) { | 784 Element findRequiredElement(LibraryElement library, SourceString name) { |
| 789 var element = library.find(name); | 785 var element = library.find(name); |
| 790 if (element == null) { | 786 if (element == null) { |
| 791 internalErrorOnElement( | 787 internalErrorOnElement( |
| 792 library, | 788 library, |
| 793 'The library "${library.canonicalUri}" does not contain required ' | 789 'The library "${library.canonicalUri}" does not contain required ' |
| 794 'element: ${name.slowToString()}'); | 790 'element: ${name.slowToString()}'); |
| 795 } | 791 } |
| 796 return element; | 792 return element; |
| 797 } | 793 } |
| 798 | 794 |
| 799 void onClassResolved(ClassElement cls) { | 795 void onClassResolved(ClassElement cls) { |
| 800 if (mirrorSystemClass == cls) { | 796 if (mirrorSystemClass == cls) { |
| 801 mirrorSystemGetNameFunction = | 797 mirrorSystemGetNameFunction = |
| 802 cls.lookupLocalMember(const SourceString('getName')); | 798 cls.lookupLocalMember(const SourceString('getName')); |
| 803 } else if (symbolClass == cls) { | 799 } else if (symbolClass == cls) { |
| 804 symbolConstructor = cls.constructors.head; | 800 symbolConstructor = cls.constructors.head; |
| 805 } else if (symbolImplementationClass == cls) { | 801 } else if (symbolImplementationClass == cls) { |
| 806 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( | 802 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( |
| 807 symbolValidatedConstructorSelector); | 803 symbolValidatedConstructorSelector); |
| 808 } else if (mirrorsUsedClass == cls) { | 804 } else if (mirrorsUsedClass == cls) { |
| 809 mirrorsUsedConstructor = cls.constructors.head; | 805 mirrorsUsedConstructor = cls.constructors.head; |
| 810 } | 806 } |
| 811 } | 807 } |
| 812 | 808 |
| 813 LibraryElement scanBuiltinLibrary(String filename); | 809 Future<LibraryElement> scanBuiltinLibrary(String filename); |
| 814 | 810 |
| 815 void initializeSpecialClasses() { | 811 void initializeSpecialClasses() { |
| 816 final List missingCoreClasses = []; | 812 final List missingCoreClasses = []; |
| 817 ClassElement lookupCoreClass(String name) { | 813 ClassElement lookupCoreClass(String name) { |
| 818 ClassElement result = coreLibrary.find(new SourceString(name)); | 814 ClassElement result = coreLibrary.find(new SourceString(name)); |
| 819 if (result == null) { | 815 if (result == null) { |
| 820 missingCoreClasses.add(name); | 816 missingCoreClasses.add(name); |
| 821 } | 817 } |
| 822 return result; | 818 return result; |
| 823 } | 819 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 | 877 |
| 882 Element _filledListConstructor; | 878 Element _filledListConstructor; |
| 883 Element get filledListConstructor { | 879 Element get filledListConstructor { |
| 884 if (_filledListConstructor != null) return _filledListConstructor; | 880 if (_filledListConstructor != null) return _filledListConstructor; |
| 885 Selector callConstructor = new Selector.callConstructor( | 881 Selector callConstructor = new Selector.callConstructor( |
| 886 const SourceString("filled"), listClass.getLibrary()); | 882 const SourceString("filled"), listClass.getLibrary()); |
| 887 return _filledListConstructor = | 883 return _filledListConstructor = |
| 888 listClass.lookupConstructor(callConstructor); | 884 listClass.lookupConstructor(callConstructor); |
| 889 } | 885 } |
| 890 | 886 |
| 891 void scanBuiltinLibraries() { | 887 Future scanBuiltinLibraries() { |
| 892 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 888 return scanBuiltinLibrary('_js_helper').then((LibraryElement library) { |
| 893 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 889 jsHelperLibrary = library; |
| 894 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 890 return scanBuiltinLibrary('_interceptors'); |
| 895 identicalFunction = coreLibrary.find(const SourceString('identical')); | 891 }).then((LibraryElement library) { |
| 892 interceptorsLibrary = library; | |
| 896 | 893 |
| 897 initializeSpecialClasses(); | 894 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
| 895 identicalFunction = coreLibrary.find(const SourceString('identical')); | |
| 898 | 896 |
| 899 functionClass.ensureResolved(this); | 897 initializeSpecialClasses(); |
| 900 functionApplyMethod = | |
| 901 functionClass.lookupLocalMember(const SourceString('apply')); | |
| 902 jsInvocationMirrorClass.ensureResolved(this); | |
| 903 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
| 904 | 898 |
| 905 if (preserveComments) { | 899 functionClass.ensureResolved(this); |
| 906 var uri = new Uri(scheme: 'dart', path: 'mirrors'); | 900 functionApplyMethod = |
| 907 LibraryElement libraryElement = | 901 functionClass.lookupLocalMember(const SourceString('apply')); |
| 908 libraryLoader.loadLibrary(uri, null, uri); | 902 jsInvocationMirrorClass.ensureResolved(this); |
| 909 documentClass = libraryElement.find(const SourceString('Comment')); | 903 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); |
| 910 } | 904 |
| 905 if (preserveComments) { | |
| 906 var uri = new Uri(scheme: 'dart', path: 'mirrors'); | |
| 907 return libraryLoader.loadLibrary(uri, null, uri).then( | |
| 908 (LibraryElement libraryElement) { | |
| 909 documentClass = libraryElement.find(const SourceString('Comment')); | |
| 910 }); | |
| 911 } | |
| 912 }); | |
| 911 } | 913 } |
| 912 | 914 |
| 913 void importHelperLibrary(LibraryElement library) { | 915 void importHelperLibrary(LibraryElement library) { |
| 914 if (jsHelperLibrary != null) { | 916 if (jsHelperLibrary != null) { |
| 915 libraryLoader.importLibrary(library, jsHelperLibrary, null); | 917 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
| 916 } | 918 } |
| 917 } | 919 } |
| 918 | 920 |
| 919 /** | 921 /** |
| 920 * Get an [Uri] pointing to a patch for the dart: library with | 922 * Get an [Uri] pointing to a patch for the dart: library with |
| 921 * the given path. Returns null if there is no patch. | 923 * the given path. Returns null if there is no patch. |
| 922 */ | 924 */ |
| 923 Uri resolvePatchUri(String dartLibraryPath); | 925 Uri resolvePatchUri(String dartLibraryPath); |
| 924 | 926 |
| 925 void runCompiler(Uri uri) { | 927 Future runCompiler(Uri uri) { |
| 926 // TODO(ahe): This prevents memory leaks when invoking the compiler | 928 // TODO(ahe): This prevents memory leaks when invoking the compiler |
| 927 // multiple times. Implement a better mechanism where StringWrapper | 929 // multiple times. Implement a better mechanism where StringWrapper |
| 928 // instances are shared on a per library basis. | 930 // instances are shared on a per library basis. |
| 929 SourceString.canonicalizedValues.clear(); | 931 SourceString.canonicalizedValues.clear(); |
| 930 | 932 |
| 931 assert(uri != null || analyzeOnly); | 933 assert(uri != null || analyzeOnly); |
| 932 scanBuiltinLibraries(); | 934 return scanBuiltinLibraries().then((_) { |
| 933 if (librariesToAnalyzeWhenRun != null) { | 935 if (librariesToAnalyzeWhenRun != null) { |
| 934 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 936 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { |
| 935 log('analyzing $libraryUri ($buildId)'); | 937 log('analyzing $libraryUri ($buildId)'); |
| 936 libraryLoader.loadLibrary(libraryUri, null, libraryUri); | 938 return libraryLoader.loadLibrary(libraryUri, null, libraryUri); |
| 939 }); | |
| 937 } | 940 } |
| 938 } | 941 }).then((_) { |
| 939 if (uri != null) { | 942 if (uri != null) { |
| 940 if (analyzeOnly) { | 943 if (analyzeOnly) { |
| 941 log('analyzing $uri ($buildId)'); | 944 log('analyzing $uri ($buildId)'); |
| 942 } else { | 945 } else { |
| 943 log('compiling $uri ($buildId)'); | 946 log('compiling $uri ($buildId)'); |
| 947 } | |
| 948 return libraryLoader.loadLibrary(uri, null, uri) | |
| 949 .then((LibraryElement library) { | |
| 950 mainApp = library; | |
| 951 }); | |
| 944 } | 952 } |
| 945 mainApp = libraryLoader.loadLibrary(uri, null, uri); | 953 }).then((_) { |
| 946 } | 954 compileLoadedLibraries(); |
| 955 }); | |
| 956 } | |
| 957 | |
| 958 /// Performs the compilation when all libraries have been loaded. | |
| 959 void compileLoadedLibraries() { | |
| 947 Element main = null; | 960 Element main = null; |
| 948 if (mainApp != null) { | 961 if (mainApp != null) { |
| 949 main = mainApp.find(MAIN); | 962 main = mainApp.find(MAIN); |
| 950 if (main == null) { | 963 if (main == null) { |
| 951 if (!analyzeOnly) { | 964 if (!analyzeOnly) { |
| 952 // Allow analyze only of libraries with no main. | 965 // Allow analyze only of libraries with no main. |
| 953 reportFatalError( | 966 reportFatalError( |
| 954 mainApp, | 967 mainApp, |
| 955 MessageKind.GENERIC, | 968 MessageKind.GENERIC, |
| 956 {'text': 'Error: Could not find "${MAIN.slowToString()}".'}); | 969 {'text': 'Error: Could not find "${MAIN.slowToString()}".'}); |
| 957 } else if (!analyzeAll) { | 970 } else if (!analyzeAll) { |
| 958 reportFatalError( | 971 reportFatalError( |
| 959 mainApp, | 972 mainApp, |
| 960 MessageKind.GENERIC, | 973 MessageKind.GENERIC, |
| 961 {'text': 'Error: Could not find "${MAIN.slowToString()}". ' | 974 {'text': 'Error: Could not find "${MAIN.slowToString()}". ' |
| 962 'No source will be analyzed. ' | 975 'No source will be analyzed. ' |
| 963 'Use "--analyze-all" to analyze all code in the library.'}); | 976 'Use "--analyze-all" to analyze all code in the library.'}); |
| 964 } | 977 } |
| 965 } else { | 978 } else { |
| 966 if (!main.isFunction()) { | 979 if (!main.isFunction()) { |
| 967 reportFatalError( | 980 reportFatalError( |
| 968 main, | 981 main, |
| 969 MessageKind.GENERIC, | 982 MessageKind.GENERIC, |
| 970 {'text': 'Error: "${MAIN.slowToString()}" is not a function.'}); | 983 {'text': 'Error: "${MAIN.slowToString()}" is not a function.'}); |
| 971 } | 984 } |
| 972 FunctionElement mainMethod = main; | 985 FunctionElement mainMethod = main; |
| 973 FunctionSignature parameters = mainMethod.computeSignature(this); | 986 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 974 parameters.forEachParameter((Element parameter) { | 987 parameters.forEachParameter((Element parameter) { |
| 975 reportError( | 988 reportError( |
| 976 parameter, | 989 parameter, |
| 977 MessageKind.GENERIC, | 990 MessageKind.GENERIC, |
| 978 {'text': | 991 {'text': |
| 979 'Error: "${MAIN.slowToString()}" cannot have parameters.'}); | 992 'Error: "${MAIN.slowToString()}" cannot have parameters.'}); |
| 980 }); | 993 }); |
| 981 } | 994 } |
| 982 | 995 |
| 983 mirrorUsageAnalyzerTask.analyzeUsage(mainApp); | 996 mirrorUsageAnalyzerTask.analyzeUsage(mainApp); |
| 984 | 997 |
| 985 // In order to see if a library is deferred, we must compute the | 998 // In order to see if a library is deferred, we must compute the |
| 986 // compile-time constants that are metadata. This means adding | 999 // compile-time constants that are metadata. This means adding |
| 987 // something to the resolution queue. So we cannot wait with | 1000 // something to the resolution queue. So we cannot wait with |
| 988 // this until after the resolution queue is processed. | 1001 // this until after the resolution queue is processed. |
| 989 // TODO(ahe): Clean this up, for example, by not enqueueing | 1002 // TODO(ahe): Clean this up, for example, by not enqueueing |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1026 if (hasIsolateSupport()) { | 1039 if (hasIsolateSupport()) { |
| 1027 enqueuer.codegen.addToWorkList( | 1040 enqueuer.codegen.addToWorkList( |
| 1028 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); | 1041 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); |
| 1029 enqueuer.codegen.registerGetOfStaticFunction(mainApp.find(MAIN)); | 1042 enqueuer.codegen.registerGetOfStaticFunction(mainApp.find(MAIN)); |
| 1030 } | 1043 } |
| 1031 if (enabledNoSuchMethod) { | 1044 if (enabledNoSuchMethod) { |
| 1032 enqueuer.codegen.registerInvocation(noSuchMethodSelector); | 1045 enqueuer.codegen.registerInvocation(noSuchMethodSelector); |
| 1033 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); | 1046 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); |
| 1034 } | 1047 } |
| 1035 if (compileAll) { | 1048 if (compileAll) { |
| 1036 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, enqueuer.codegen)); | 1049 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, |
| 1050 enqueuer.codegen)); | |
| 1037 } | 1051 } |
| 1038 processQueue(enqueuer.codegen, main); | 1052 processQueue(enqueuer.codegen, main); |
| 1039 enqueuer.codegen.logSummary(log); | 1053 enqueuer.codegen.logSummary(log); |
| 1040 | 1054 |
| 1041 if (compilationFailed) return; | 1055 if (compilationFailed) return; |
| 1042 | 1056 |
| 1043 backend.assembleProgram(); | 1057 backend.assembleProgram(); |
| 1044 | 1058 |
| 1045 checkQueues(); | 1059 checkQueues(); |
| 1046 | 1060 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 Uri translateResolvedUri(LibraryElement importingLibrary, | 1367 Uri translateResolvedUri(LibraryElement importingLibrary, |
| 1354 Uri resolvedUri, Node node) { | 1368 Uri resolvedUri, Node node) { |
| 1355 unimplemented('Compiler.translateResolvedUri'); | 1369 unimplemented('Compiler.translateResolvedUri'); |
| 1356 } | 1370 } |
| 1357 | 1371 |
| 1358 /** | 1372 /** |
| 1359 * Reads the script specified by the [readableUri]. | 1373 * Reads the script specified by the [readableUri]. |
| 1360 * | 1374 * |
| 1361 * See [LibraryLoader] for terminology on URIs. | 1375 * See [LibraryLoader] for terminology on URIs. |
| 1362 */ | 1376 */ |
| 1363 Script readScript(Uri readableUri, [Node node]) { | 1377 Future<Script> readScript(Uri readableUri, [Element element, Node node]) { |
| 1364 unimplemented('Compiler.readScript'); | 1378 unimplemented('Compiler.readScript'); |
| 1365 } | 1379 } |
| 1366 | 1380 |
| 1367 String get legDirectory { | 1381 String get legDirectory { |
| 1368 unimplemented('Compiler.legDirectory'); | 1382 unimplemented('Compiler.legDirectory'); |
| 1369 } | 1383 } |
| 1370 | 1384 |
| 1371 // TODO(karlklose): split into findHelperFunction and findHelperClass and | 1385 // TODO(karlklose): split into findHelperFunction and findHelperClass and |
| 1372 // add a check that the element has the expected kind. | 1386 // add a check that the element has the expected kind. |
| 1373 Element findHelper(SourceString name) | 1387 Element findHelper(SourceString name) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1497 * [invariant] as the argument to an [:assert:] statement: | 1511 * [invariant] as the argument to an [:assert:] statement: |
| 1498 * | 1512 * |
| 1499 * assert(invariant(position, isValid)); | 1513 * assert(invariant(position, isValid)); |
| 1500 * | 1514 * |
| 1501 * [spannable] must be non-null and will be used to provide positional | 1515 * [spannable] must be non-null and will be used to provide positional |
| 1502 * information in the generated error message. | 1516 * information in the generated error message. |
| 1503 */ | 1517 */ |
| 1504 bool invariant(Spannable spannable, var condition, {var message: null}) { | 1518 bool invariant(Spannable spannable, var condition, {var message: null}) { |
| 1505 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 1519 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 1506 // information on assertion errors. | 1520 // information on assertion errors. |
| 1521 if (spannable == null) { | |
| 1522 throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE, | |
| 1523 "Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE."); | |
| 1524 } | |
| 1507 if (condition is Function){ | 1525 if (condition is Function){ |
| 1508 condition = condition(); | 1526 condition = condition(); |
| 1509 } | 1527 } |
| 1510 if (spannable == null || !condition) { | 1528 if (!condition) { |
| 1511 if (message is Function) { | 1529 if (message is Function) { |
| 1512 message = message(); | 1530 message = message(); |
| 1513 } | 1531 } |
| 1514 throw new SpannableAssertionFailure(spannable, message); | 1532 throw new SpannableAssertionFailure(spannable, message); |
| 1515 } | 1533 } |
| 1516 return true; | 1534 return true; |
| 1517 } | 1535 } |
| 1518 | 1536 |
| 1519 /// A sink that drains into /dev/null. | 1537 /// A sink that drains into /dev/null. |
| 1520 class NullSink implements EventSink<String> { | 1538 class NullSink implements EventSink<String> { |
| 1521 final String name; | 1539 final String name; |
| 1522 | 1540 |
| 1523 NullSink(this.name); | 1541 NullSink(this.name); |
| 1524 | 1542 |
| 1525 add(String value) {} | 1543 add(String value) {} |
| 1526 | 1544 |
| 1527 void addError(Object error) {} | 1545 void addError(Object error) {} |
| 1528 | 1546 |
| 1529 void close() {} | 1547 void close() {} |
| 1530 | 1548 |
| 1531 toString() => name; | 1549 toString() => name; |
| 1532 | 1550 |
| 1533 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1551 /// Convenience method for getting an [api.CompilerOutputProvider]. |
| 1534 static NullSink outputProvider(String name, String extension) { | 1552 static NullSink outputProvider(String name, String extension) { |
| 1535 return new NullSink('$name.$extension'); | 1553 return new NullSink('$name.$extension'); |
| 1536 } | 1554 } |
| 1537 } | 1555 } |
| OLD | NEW |