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

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

Issue 10855174: Lazy implementation of final variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove lazy bailout initializers. Created 8 years, 3 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
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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 const bool REPORT_EXCESS_RESOLUTION = false; 10 const bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // TODO(ahe): Add structured diagnostics to the compiler API and 712 // TODO(ahe): Add structured diagnostics to the compiler API and
713 // use it to separate this from the --verbose option. 713 // use it to separate this from the --verbose option.
714 if (phase == PHASE_COMPILING) { 714 if (phase == PHASE_COMPILING) {
715 log('Compiled ${codegenWorld.generatedCode.length} methods.'); 715 log('Compiled ${codegenWorld.generatedCode.length} methods.');
716 } else { 716 } else {
717 log('Recompiled ${world.recompilationCandidates.processed} methods.'); 717 log('Recompiled ${world.recompilationCandidates.processed} methods.');
718 } 718 }
719 progress.reset(); 719 progress.reset();
720 } 720 }
721 if (work.element.kind.category == ElementCategory.VARIABLE) { 721 if (work.element.kind.category == ElementCategory.VARIABLE) {
722 constantHandler.compileWorkItem(work); 722 Constant initialValue = constantHandler.compileWorkItem(work);
723 } else { 723 if (initialValue !== null) {
724 backend.codegen(work); 724 return;
725 } else {
726 // If the constant-handler was not able to produce a result we have to
727 // go through the builder (below) to generate the lazy initializer for
728 // the static variable.
729 // We also need to register the use of the cyclic-error helper.
730 world.registerStaticUse(cyclicThrowHelper);
731 }
725 } 732 }
733 backend.codegen(work);
726 } 734 }
727 735
728 void registerInstantiatedClass(ClassElement cls) { 736 void registerInstantiatedClass(ClassElement cls) {
729 enqueuer.resolution.registerInstantiatedClass(cls); 737 enqueuer.resolution.registerInstantiatedClass(cls);
730 enqueuer.codegen.registerInstantiatedClass(cls); 738 enqueuer.codegen.registerInstantiatedClass(cls);
731 } 739 }
732 740
733 DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) { 741 DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) {
734 return resolver.resolveTypeAnnotation(element, annotation); 742 return resolver.resolveTypeAnnotation(element, annotation);
735 } 743 }
(...skipping 13 matching lines...) Expand all
749 withCurrentElement(element, 757 withCurrentElement(element,
750 () => resolver.resolveTypedef(element)); 758 () => resolver.resolveTypedef(element));
751 } 759 }
752 760
753 FunctionType computeFunctionType(Element element, 761 FunctionType computeFunctionType(Element element,
754 FunctionSignature signature) { 762 FunctionSignature signature) {
755 return withCurrentElement(element, 763 return withCurrentElement(element,
756 () => resolver.computeFunctionType(element, signature)); 764 () => resolver.computeFunctionType(element, signature));
757 } 765 }
758 766
767 bool isLazilyInitialized(VariableElement element) {
768 Constant initialValue = compileVariable(element);
769 return initialValue === null;
770 }
771
772 /** Compiles compile-time constants. Must not return `null`. */
773 Constant compileConstant(VariableElement element) {
774 return withCurrentElement(element, () {
775 return constantHandler.compileConstant(element);
776 });
777 }
778
759 Constant compileVariable(VariableElement element) { 779 Constant compileVariable(VariableElement element) {
760 return withCurrentElement(element, () { 780 return withCurrentElement(element, () {
761 return constantHandler.compileVariable(element); 781 return constantHandler.compileVariable(element);
762 }); 782 });
763 } 783 }
764 784
765 reportWarning(Node node, var message) { 785 reportWarning(Node node, var message) {
766 if (message is TypeWarning) { 786 if (message is TypeWarning) {
767 // TODO(ahe): Don't supress these warning when the type checker 787 // TODO(ahe): Don't supress these warning when the type checker
768 // is more complete. 788 // is more complete.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 861 }
842 862
843 Script readScript(Uri uri, [ScriptTag node]) { 863 Script readScript(Uri uri, [ScriptTag node]) {
844 unimplemented('Compiler.readScript'); 864 unimplemented('Compiler.readScript');
845 } 865 }
846 866
847 String get legDirectory { 867 String get legDirectory {
848 unimplemented('Compiler.legDirectory'); 868 unimplemented('Compiler.legDirectory');
849 } 869 }
850 870
871 Element get cyclicThrowHelper() {
872 return findHelper(const SourceString("throwCyclicInit"));
873 }
874
851 Element findHelper(SourceString name) 875 Element findHelper(SourceString name)
852 => jsHelperLibrary.findLocal(name); 876 => jsHelperLibrary.findLocal(name);
853 Element findInterceptor(SourceString name) 877 Element findInterceptor(SourceString name)
854 => interceptorsLibrary.findLocal(name); 878 => interceptorsLibrary.findLocal(name);
855 879
856 bool get isMockCompilation => false; 880 bool get isMockCompilation => false;
857 } 881 }
858 882
859 class CompilerTask { 883 class CompilerTask {
860 final Compiler compiler; 884 final Compiler compiler;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 final endOffset = end.charOffset + end.slowCharCount; 941 final endOffset = end.charOffset + end.slowCharCount;
918 942
919 // [begin] and [end] might be the same for the same empty token. This 943 // [begin] and [end] might be the same for the same empty token. This
920 // happens for instance when scanning '$$'. 944 // happens for instance when scanning '$$'.
921 assert(endOffset >= beginOffset); 945 assert(endOffset >= beginOffset);
922 return f(beginOffset, endOffset); 946 return f(beginOffset, endOffset);
923 } 947 }
924 948
925 String toString() => 'SourceSpan($uri, $begin, $end)'; 949 String toString() => 'SourceSpan($uri, $begin, $end)';
926 } 950 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698