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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 999933007: dart2js: emit info on lazy fields in array. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 }); 845 });
846 } 846 }
847 } 847 }
848 848
849 void emitLazilyInitializedStaticFields(CodeOutput output) { 849 void emitLazilyInitializedStaticFields(CodeOutput output) {
850 JavaScriptConstantCompiler handler = backend.constants; 850 JavaScriptConstantCompiler handler = backend.constants;
851 List<VariableElement> lazyFields = 851 List<VariableElement> lazyFields =
852 handler.getLazilyInitializedFieldsForEmission(); 852 handler.getLazilyInitializedFieldsForEmission();
853 if (!lazyFields.isEmpty) { 853 if (!lazyFields.isEmpty) {
854 needsLazyInitializer = true; 854 needsLazyInitializer = true;
855 for (VariableElement element in Elements.sortedByPosition(lazyFields)) { 855 List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields);
856 jsAst.Expression init = 856 jsAst.Statement code = js.statement('''
857 buildLazilyInitializedStaticField(element, isolateProperties); 857 {
herhut 2015/04/01 07:43:05 Why the block? If you were hoping for a new variab
zarah 2015/04/01 11:05:08 No it was to have a single statement. Changed it t
858 if (init == null) continue; 858 var lazies = #laziesInfo;
859 output.addBuffer( 859 for (var i = 0; i < lazies.length; i += 5) {
860 jsAst.prettyPrint(init, compiler, monitor: compiler.dumpInfoTask)); 860 var prototype = lazies[i];
861 output.add("$N"); 861 var staticName = lazies[i + 1];
862 } 862 var fieldName = lazies [i + 2];
863 var getterName = lazies[i + 3];
864 var lazyValue = lazies[i + 4];
865
866 // We build the lazy-check here:
867 // lazyInitializer(prototype, staticName, fieldName, getterName,
868 // lazyValue);
869 // The staticName is used for error reporting. The 'lazyValue' must
870 // be a closure that constructs the initial value.
871 #lazy(prototype, staticName, fieldName, getterName, lazyValue);
herhut 2015/04/01 07:43:05 This has become a little more complicated now, as
zarah 2015/04/01 11:05:08 Changed to handle this.
872 }
873 }
874 ''', {'laziesInfo': new jsAst.ArrayInitializer(laziesInfo),
875 'lazy': js(lazyInitializerName)});
876
877 output.addBuffer(
878 jsAst.prettyPrint(code, compiler, monitor: compiler.dumpInfoTask));
879 output.add("$N");
863 } 880 }
864 } 881 }
865 882
866 jsAst.Expression buildLazilyInitializedStaticField( 883 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) {
867 VariableElement element, String isolateProperties) { 884 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[];
868 jsAst.Expression code = backend.generatedCode[element]; 885 for (VariableElement element in Elements.sortedByPosition(lazies)) {
869 // The code is null if we ended up not needing the lazily 886 jsAst.Expression code = backend.generatedCode[element];
870 // initialized field after all because of constant folding 887 // The code is null if we ended up not needing the lazily
871 // before code generation. 888 // initialized field after all because of constant folding
872 if (code == null) return null; 889 // before code generation.
873 // The code only computes the initial value. We build the lazy-check 890 if (code == null) continue;
874 // here: 891 laziesInfo.addAll([js(isolateProperties),
875 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 892 js.string(element.name),
floitsch 2015/03/24 16:28:17 nit: indentation seems off.
zarah 2015/04/01 11:05:08 Done.
876 // The name is used for error reporting. The 'initial' must be a 893 js.string(namer.globalPropertyName(element)),
877 // closure that constructs the initial value. 894 js.string(namer.lazyInitializerName(element)),
878 return js('#(#,#,#,#,#)', 895 code]);
879 [js(lazyInitializerName), 896 }
880 js(isolateProperties), 897 return laziesInfo;
881 js.string(element.name),
882 js.string(namer.globalPropertyName(element)),
883 js.string(namer.lazyInitializerName(element)),
884 code]);
885 } 898 }
886 899
887 void emitMetadata(Program program, CodeOutput output) { 900 void emitMetadata(Program program, CodeOutput output) {
888 901
889 addMetadataGlobal(List<String> list, String global) { 902 addMetadataGlobal(List<String> list, String global) {
890 String globalAccess = generateEmbeddedGlobalAccessString(global); 903 String globalAccess = generateEmbeddedGlobalAccessString(global);
891 output.add('$globalAccess$_=$_['); 904 output.add('$globalAccess$_=$_[');
892 for (String data in list) { 905 for (String data in list) {
893 if (data is String) { 906 if (data is String) {
894 if (data != 'null') { 907 if (data != 'null') {
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2141 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2129 if (element.isInstanceMember) { 2142 if (element.isInstanceMember) {
2130 cachedClassBuilders.remove(element.enclosingClass); 2143 cachedClassBuilders.remove(element.enclosingClass);
2131 2144
2132 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2145 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2133 2146
2134 } 2147 }
2135 } 2148 }
2136 } 2149 }
2137 } 2150 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698