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

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

Issue 221873002: Compute frontend/backend specific constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 6 years, 8 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 /** 7 /**
8 * Generates the code for all used classes in the program. Static fields (even 8 * Generates the code for all used classes in the program. Static fields (even
9 * in classes) are ignored, since they can be treated as non-class elements. 9 * in classes) are ignored, since they can be treated as non-class elements.
10 * 10 *
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 backend.generatedCode.keys.where(isStaticFunction); 835 backend.generatedCode.keys.where(isStaticFunction);
836 836
837 for (Element element in Elements.sortedByPosition(elements)) { 837 for (Element element in Elements.sortedByPosition(elements)) {
838 ClassBuilder builder = new ClassBuilder(namer); 838 ClassBuilder builder = new ClassBuilder(namer);
839 containerBuilder.addMember(element, builder); 839 containerBuilder.addMember(element, builder);
840 getElementDecriptor(element).properties.addAll(builder.properties); 840 getElementDecriptor(element).properties.addAll(builder.properties);
841 } 841 }
842 } 842 }
843 843
844 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { 844 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) {
845 ConstantHandler handler = compiler.constantHandler; 845 JavaScriptConstantCompiler handler = backend.constants;
846 Iterable<VariableElement> staticNonFinalFields = 846 Iterable<VariableElement> staticNonFinalFields =
847 handler.getStaticNonFinalFieldsForEmission(); 847 handler.getStaticNonFinalFieldsForEmission();
848 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { 848 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
849 // [:interceptedNames:] is handled in [emitInterceptedNames]. 849 // [:interceptedNames:] is handled in [emitInterceptedNames].
850 if (element == backend.interceptedNames) continue; 850 if (element == backend.interceptedNames) continue;
851 // `mapTypeToInterceptor` is handled in [emitMapTypeToInterceptor]. 851 // `mapTypeToInterceptor` is handled in [emitMapTypeToInterceptor].
852 if (element == backend.mapTypeToInterceptor) continue; 852 if (element == backend.mapTypeToInterceptor) continue;
853 compiler.withCurrentElement(element, () { 853 compiler.withCurrentElement(element, () {
854 Constant initialValue = handler.getInitialValueFor(element); 854 Constant initialValue = handler.getInitialValueFor(element);
855 jsAst.Expression init = 855 jsAst.Expression init =
856 js('$isolateProperties.${namer.getNameOfGlobalField(element)} = #', 856 js('$isolateProperties.${namer.getNameOfGlobalField(element)} = #',
857 constantEmitter.referenceInInitializationContext(initialValue)); 857 constantEmitter.referenceInInitializationContext(initialValue));
858 buffer.write(jsAst.prettyPrint(init, compiler)); 858 buffer.write(jsAst.prettyPrint(init, compiler));
859 buffer.write('$N'); 859 buffer.write('$N');
860 }); 860 });
861 } 861 }
862 } 862 }
863 863
864 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { 864 void emitLazilyInitializedStaticFields(CodeBuffer buffer) {
865 ConstantHandler handler = compiler.constantHandler; 865 JavaScriptConstantCompiler handler = backend.constants;
866 List<VariableElement> lazyFields = 866 List<VariableElement> lazyFields =
867 handler.getLazilyInitializedFieldsForEmission(); 867 handler.getLazilyInitializedFieldsForEmission();
868 if (!lazyFields.isEmpty) { 868 if (!lazyFields.isEmpty) {
869 needsLazyInitializer = true; 869 needsLazyInitializer = true;
870 for (VariableElement element in Elements.sortedByPosition(lazyFields)) { 870 for (VariableElement element in Elements.sortedByPosition(lazyFields)) {
871 jsAst.Expression code = backend.generatedCode[element]; 871 jsAst.Expression code = backend.generatedCode[element];
872 // The code is null if we ended up not needing the lazily 872 // The code is null if we ended up not needing the lazily
873 // initialized field after all because of constant folding 873 // initialized field after all because of constant folding
874 // before code generation. 874 // before code generation.
875 if (code == null) continue; 875 if (code == null) continue;
(...skipping 18 matching lines...) Expand all
894 } 894 }
895 } 895 }
896 } 896 }
897 897
898 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { 898 jsAst.Expression buildLazyInitializedGetter(VariableElement element) {
899 // Nothing to do, the 'lazy' function will create the getter. 899 // Nothing to do, the 'lazy' function will create the getter.
900 return null; 900 return null;
901 } 901 }
902 902
903 void emitCompileTimeConstants(CodeBuffer buffer, OutputUnit outputUnit) { 903 void emitCompileTimeConstants(CodeBuffer buffer, OutputUnit outputUnit) {
904 ConstantHandler handler = compiler.constantHandler; 904 JavaScriptConstantCompiler handler = backend.constants;
905 List<Constant> constants = handler.getConstantsForEmission( 905 List<Constant> constants = handler.getConstantsForEmission(
906 compareConstants); 906 compareConstants);
907 Set<Constant> outputUnitConstants = null; 907 Set<Constant> outputUnitConstants = null;
908 // TODO(sigurdm): We shouldn't run through all constants for every 908 // TODO(sigurdm): We shouldn't run through all constants for every
909 // outputUnit. 909 // outputUnit.
910 for (Constant constant in constants) { 910 for (Constant constant in constants) {
911 if (isConstantInlinedOrAlreadyEmitted(constant)) continue; 911 if (isConstantInlinedOrAlreadyEmitted(constant)) continue;
912 OutputUnit constantUnit = 912 OutputUnit constantUnit =
913 compiler.deferredLoadTask.outputUnitForConstant(constant); 913 compiler.deferredLoadTask.outputUnitForConstant(constant);
914 if (constantUnit != outputUnit && constantUnit != null) continue; 914 if (constantUnit != outputUnit && constantUnit != null) continue;
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 String sourceMap = sourceMapBuilder.build(compiledFile); 1701 String sourceMap = sourceMapBuilder.build(compiledFile);
1702 compiler.outputProvider(name, 'js.map') 1702 compiler.outputProvider(name, 'js.map')
1703 ..add(sourceMap) 1703 ..add(sourceMap)
1704 ..close(); 1704 ..close();
1705 } 1705 }
1706 1706
1707 void registerReadTypeVariable(TypeVariableElement element) { 1707 void registerReadTypeVariable(TypeVariableElement element) {
1708 readTypeVariables.add(element); 1708 readTypeVariables.add(element);
1709 } 1709 }
1710 } 1710 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698