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

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

Issue 779593002: Move elementAccess() from namer to emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 6 years 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) 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 jsAst.Expression generateEmbeddedGlobalAccess(String global) { 175 jsAst.Expression generateEmbeddedGlobalAccess(String global) {
176 return js(generateEmbeddedGlobalAccessString(global)); 176 return js(generateEmbeddedGlobalAccessString(global));
177 } 177 }
178 178
179 String generateEmbeddedGlobalAccessString(String global) { 179 String generateEmbeddedGlobalAccessString(String global) {
180 // TODO(floitsch): don't use 'init' as global embedder storage. 180 // TODO(floitsch): don't use 'init' as global embedder storage.
181 return '$initName.$global'; 181 return '$initName.$global';
182 } 182 }
183 183
184 jsAst.PropertyAccess globalPropertyAccess(Element element) {
185 String name = namer.getNameX(element);
186 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field(
187 new jsAst.VariableUse(namer.globalObjectFor(element)),
188 name);
189 return pa;
190 }
191
192 jsAst.PropertyAccess staticFieldAccess(Element element) {
193 return globalPropertyAccess(element);
194 }
195
196 jsAst.PropertyAccess staticFunctionAccess(Element element) {
197 return globalPropertyAccess(element);
198 }
199
200 jsAst.PropertyAccess classAccess(Element element) {
201 return globalPropertyAccess(element);
202 }
203
204 jsAst.PropertyAccess typedefAccess(Element element) {
205 return globalPropertyAccess(element);
206 }
207
184 jsAst.FunctionDeclaration get generateAccessorFunction { 208 jsAst.FunctionDeclaration get generateAccessorFunction {
185 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; 209 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1;
186 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; 210 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1;
187 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); 211 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST);
188 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); 212 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST);
189 const RANGE3_ADJUST = 213 const RANGE3_ADJUST =
190 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); 214 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST);
191 215
192 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; 216 String receiverParamName = compiler.enableMinification ? "r" : "receiver";
193 String valueParamName = compiler.enableMinification ? "v" : "value"; 217 String valueParamName = compiler.enableMinification ? "v" : "value";
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 }''', 663 }''',
640 [namer.isolatePropertiesName, namer.isolatePropertiesName, 664 [namer.isolatePropertiesName, namer.isolatePropertiesName,
641 needsDefineClass, finishClassesProperty, finishClassesProperty, 665 needsDefineClass, finishClassesProperty, finishClassesProperty,
642 task.outputContainsConstantList, 666 task.outputContainsConstantList,
643 makeConstListProperty, makeConstListProperty ]); 667 makeConstListProperty, makeConstListProperty ]);
644 } 668 }
645 669
646 jsAst.Fun get lazyInitializerFunction { 670 jsAst.Fun get lazyInitializerFunction {
647 String isolate = namer.currentIsolate; 671 String isolate = namer.currentIsolate;
648 jsAst.Expression cyclicThrow = 672 jsAst.Expression cyclicThrow =
649 namer.elementAccess(backend.getCyclicThrowHelper()); 673 staticFunctionAccess(backend.getCyclicThrowHelper());
650 jsAst.Expression laziesAccess = 674 jsAst.Expression laziesAccess =
651 generateEmbeddedGlobalAccess(embeddedNames.LAZIES); 675 generateEmbeddedGlobalAccess(embeddedNames.LAZIES);
652 676
653 return js(''' 677 return js('''
654 function (prototype, staticName, fieldName, getterName, lazyValue) { 678 function (prototype, staticName, fieldName, getterName, lazyValue) {
655 if (!#) # = Object.create(null); 679 if (!#) # = Object.create(null);
656 #[fieldName] = getterName; 680 #[fieldName] = getterName;
657 681
658 var sentinelUndefined = {}; 682 var sentinelUndefined = {};
659 var sentinelInProgress = {}; 683 var sentinelInProgress = {};
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 } 1060 }
1037 1061
1038 /// Returns the code equivalent to: 1062 /// Returns the code equivalent to:
1039 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` 1063 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }`
1040 jsAst.Expression buildIsolateSetupClosure(Element appMain, 1064 jsAst.Expression buildIsolateSetupClosure(Element appMain,
1041 Element isolateMain) { 1065 Element isolateMain) {
1042 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); 1066 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain);
1043 // Since we pass the closurized version of the main method to 1067 // Since we pass the closurized version of the main method to
1044 // the isolate method, we must make sure that it exists. 1068 // the isolate method, we must make sure that it exists.
1045 return js('function(a){ #(#, a); }', 1069 return js('function(a){ #(#, a); }',
1046 [namer.elementAccess(isolateMain), mainAccess]); 1070 [backend.emitter.staticFunctionAccess(isolateMain), mainAccess]);
1047 } 1071 }
1048 1072
1049 /** 1073 /**
1050 * Emits code that sets the `isolateTag embedded global to a unique string. 1074 * Emits code that sets the `isolateTag embedded global to a unique string.
1051 */ 1075 */
1052 jsAst.Expression generateIsolateAffinityTagInitialization() { 1076 jsAst.Expression generateIsolateAffinityTagInitialization() {
1053 jsAst.Expression getIsolateTagAccess = 1077 jsAst.Expression getIsolateTagAccess =
1054 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG); 1078 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG);
1055 jsAst.Expression isolateTagAccess = 1079 jsAst.Expression isolateTagAccess =
1056 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG); 1080 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1132
1109 emitMain(CodeBuffer buffer) { 1133 emitMain(CodeBuffer buffer) {
1110 if (compiler.isMockCompilation) return; 1134 if (compiler.isMockCompilation) return;
1111 Element main = compiler.mainFunction; 1135 Element main = compiler.mainFunction;
1112 jsAst.Expression mainCallClosure = null; 1136 jsAst.Expression mainCallClosure = null;
1113 if (compiler.hasIsolateSupport) { 1137 if (compiler.hasIsolateSupport) {
1114 Element isolateMain = 1138 Element isolateMain =
1115 backend.isolateHelperLibrary.find(JavaScriptBackend.START_ROOT_ISOLATE); 1139 backend.isolateHelperLibrary.find(JavaScriptBackend.START_ROOT_ISOLATE);
1116 mainCallClosure = buildIsolateSetupClosure(main, isolateMain); 1140 mainCallClosure = buildIsolateSetupClosure(main, isolateMain);
1117 } else if (compiler.hasIncrementalSupport) { 1141 } else if (compiler.hasIncrementalSupport) {
1118 mainCallClosure = 1142 mainCallClosure = js(
1119 js('function() { return #(); }', namer.elementAccess(main)); 1143 'function() { return #(); }',
1144 backend.emitter.staticFunctionAccess(main));
1120 } else { 1145 } else {
1121 mainCallClosure = namer.elementAccess(main); 1146 mainCallClosure = backend.emitter.staticFunctionAccess(main);
1122 } 1147 }
1123 1148
1124 if (backend.needToInitializeIsolateAffinityTag) { 1149 if (backend.needToInitializeIsolateAffinityTag) {
1125 buffer.write( 1150 buffer.write(
1126 jsAst.prettyPrint(generateIsolateAffinityTagInitialization(), 1151 jsAst.prettyPrint(generateIsolateAffinityTagInitialization(),
1127 compiler, monitor: compiler.dumpInfoTask)); 1152 compiler, monitor: compiler.dumpInfoTask));
1128 buffer.write(N); 1153 buffer.write(N);
1129 } 1154 }
1130 if (backend.needToInitializeDispatchProperty) { 1155 if (backend.needToInitializeDispatchProperty) {
1131 assert(backend.needToInitializeIsolateAffinityTag); 1156 assert(backend.needToInitializeIsolateAffinityTag);
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2093 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2069 if (element.isInstanceMember) { 2094 if (element.isInstanceMember) {
2070 cachedClassBuilders.remove(element.enclosingClass); 2095 cachedClassBuilders.remove(element.enclosingClass);
2071 2096
2072 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2097 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2073 2098
2074 } 2099 }
2075 } 2100 }
2076 } 2101 }
2077 } 2102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698