| 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.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 Loading... |
| 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 JavaScriptConstantCompiler handler = backend.constants; | 845 ConstantHandler handler = compiler.constantHandler; |
| 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 JavaScriptConstantCompiler handler = backend.constants; | 865 ConstantHandler handler = compiler.constantHandler; |
| 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 Loading... |
| 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 JavaScriptConstantCompiler handler = backend.constants; | 904 ConstantHandler handler = compiler.constantHandler; |
| 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 Loading... |
| 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 } |
| OLD | NEW |