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

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

Issue 891673003: dart2js: Refactoring, documentation, and a few bugfixes in Namer class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: MEGAPATCH Created 5 years, 10 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) 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 String get finishIsolateConstructorName 143 String get finishIsolateConstructorName
144 => '${namer.isolateName}.\$finishIsolateConstructor'; 144 => '${namer.isolateName}.\$finishIsolateConstructor';
145 String get isolatePropertiesName 145 String get isolatePropertiesName
146 => '${namer.isolateName}.${namer.isolatePropertiesName}'; 146 => '${namer.isolateName}.${namer.isolatePropertiesName}';
147 String get lazyInitializerProperty 147 String get lazyInitializerProperty
148 => r'$lazy'; 148 => r'$lazy';
149 String get lazyInitializerName 149 String get lazyInitializerName
150 => '${namer.isolateName}.${lazyInitializerProperty}'; 150 => '${namer.isolateName}.${lazyInitializerProperty}';
151 String get initName => 'init'; 151 String get initName => 'init';
152 152
153 String get makeConstListProperty 153 String get makeConstListProperty => namer.internalGlobal('makeConstantList');
154 => namer.getMappedInstanceName('makeConstantList');
155 154
156 /// The name of the property that contains all field names. 155 /// The name of the property that contains all field names.
157 /// 156 ///
158 /// This property is added to constructors when isolate support is enabled. 157 /// This property is added to constructors when isolate support is enabled.
159 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; 158 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__";
160 159
161 /// For deferred loading we communicate the initializers via this global var. 160 /// For deferred loading we communicate the initializers via this global var.
162 final String deferredInitializers = r"$dart_deferred_initializers"; 161 final String deferredInitializers = r"$dart_deferred_initializers";
163 162
164 /// All the global state can be passed around with this variable. 163 /// Contains the global state that is needed to initialize and load a
165 String get globalsHolder => namer.getMappedGlobalName("globalsHolder"); 164 /// deferred library.
165 String get globalsHolder => namer.internalGlobal("globalsHolder");
166 166
167 @override 167 @override
168 jsAst.Expression generateEmbeddedGlobalAccess(String global) { 168 jsAst.Expression generateEmbeddedGlobalAccess(String global) {
169 return js(generateEmbeddedGlobalAccessString(global)); 169 return js(generateEmbeddedGlobalAccessString(global));
170 } 170 }
171 171
172 String generateEmbeddedGlobalAccessString(String global) { 172 String generateEmbeddedGlobalAccessString(String global) {
173 // TODO(floitsch): don't use 'init' as global embedder storage. 173 // TODO(floitsch): don't use 'init' as global embedder storage.
174 return '$initName.$global'; 174 return '$initName.$global';
175 } 175 }
176 176
177 jsAst.PropertyAccess globalPropertyAccess(Element element) { 177 jsAst.PropertyAccess globalPropertyAccess(Element element) {
178 String name = namer.getNameX(element); 178 String name = namer.globalPropertyName(element);
179 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field( 179 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field(
180 new jsAst.VariableUse(namer.globalObjectFor(element)), 180 new jsAst.VariableUse(namer.globalObjectFor(element)),
181 name); 181 name);
182 return pa; 182 return pa;
183 } 183 }
184 184
185 @override 185 @override
186 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { 186 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) {
187 return jsAst.js('#.#', [namer.globalObjectFor(element), 187 return jsAst.js('#.#', [namer.globalObjectFor(element),
188 namer.getLazyInitializerName(element)]); 188 namer.lazyInitializerName(element)]);
189 } 189 }
190 190
191 @override 191 @override
192 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) { 192 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) {
193 return jsAst.js('#.#()', 193 return jsAst.js('#.#()',
194 [namer.globalObjectFor(element), namer.getStaticClosureName(element)]); 194 [namer.globalObjectFor(element), namer.staticClosureName(element)]);
195 } 195 }
196 196
197 @override 197 @override
198 jsAst.PropertyAccess staticFieldAccess(FieldElement element) { 198 jsAst.PropertyAccess staticFieldAccess(FieldElement element) {
199 return globalPropertyAccess(element); 199 return globalPropertyAccess(element);
200 } 200 }
201 201
202 @override 202 @override
203 jsAst.PropertyAccess staticFunctionAccess(FunctionElement element) { 203 jsAst.PropertyAccess staticFunctionAccess(FunctionElement element) {
204 return globalPropertyAccess(element); 204 return globalPropertyAccess(element);
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 containerBuilder.addMember(element, builder); 713 containerBuilder.addMember(element, builder);
714 getElementDescriptor(element).properties.addAll(builder.properties); 714 getElementDescriptor(element).properties.addAll(builder.properties);
715 } 715 }
716 } 716 }
717 717
718 void emitStaticNonFinalFieldInitializations(CodeOutput output, 718 void emitStaticNonFinalFieldInitializations(CodeOutput output,
719 OutputUnit outputUnit) { 719 OutputUnit outputUnit) {
720 void emitInitialization(Element element, jsAst.Expression initialValue) { 720 void emitInitialization(Element element, jsAst.Expression initialValue) {
721 jsAst.Expression init = 721 jsAst.Expression init =
722 js('$isolateProperties.# = #', 722 js('$isolateProperties.# = #',
723 [namer.getNameOfGlobalField(element), initialValue]); 723 [namer.globalPropertyName(element), initialValue]);
724 output.addBuffer(jsAst.prettyPrint(init, compiler, 724 output.addBuffer(jsAst.prettyPrint(init, compiler,
725 monitor: compiler.dumpInfoTask)); 725 monitor: compiler.dumpInfoTask));
726 output.add('$N'); 726 output.add('$N');
727 } 727 }
728 728
729 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); 729 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
730 JavaScriptConstantCompiler handler = backend.constants; 730 JavaScriptConstantCompiler handler = backend.constants;
731 731
732 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; 732 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
733 // If the outputUnit does not contain any static non-final fields, then 733 // If the outputUnit does not contain any static non-final fields, then
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if (code == null) return null; 784 if (code == null) return null;
785 // The code only computes the initial value. We build the lazy-check 785 // The code only computes the initial value. We build the lazy-check
786 // here: 786 // here:
787 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 787 // lazyInitializer(prototype, 'name', fieldName, getterName, initial);
788 // The name is used for error reporting. The 'initial' must be a 788 // The name is used for error reporting. The 'initial' must be a
789 // closure that constructs the initial value. 789 // closure that constructs the initial value.
790 return js('#(#,#,#,#,#)', 790 return js('#(#,#,#,#,#)',
791 [js(lazyInitializerName), 791 [js(lazyInitializerName),
792 js(isolateProperties), 792 js(isolateProperties),
793 js.string(element.name), 793 js.string(element.name),
794 js.string(namer.getNameX(element)), 794 js.string(namer.globalPropertyName(element)),
795 js.string(namer.getLazyInitializerName(element)), 795 js.string(namer.lazyInitializerName(element)),
796 code]); 796 code]);
797 } 797 }
798 798
799 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { 799 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) {
800 if (constant.isFunction) return true; // Already emitted. 800 if (constant.isFunction) return true; // Already emitted.
801 if (constant.isPrimitive) return true; // Inlined. 801 if (constant.isPrimitive) return true; // Inlined.
802 if (constant.isDummy) return true; // Inlined. 802 if (constant.isDummy) return true; // Inlined.
803 // The name is null when the constant is already a JS constant. 803 // The name is null when the constant is already a JS constant.
804 // TODO(floitsch): every constant should be registered, so that we can 804 // TODO(floitsch): every constant should be registered, so that we can
805 // share the ones that take up too much space (like some strings). 805 // share the ones that take up too much space (like some strings).
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 ClassBuilder builder = new ClassBuilder(typedef, namer); 1242 ClassBuilder builder = new ClassBuilder(typedef, namer);
1243 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, 1243 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME,
1244 js.number(typeIndex)); 1244 js.number(typeIndex));
1245 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, 1245 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME,
1246 js.boolean(true)); 1246 js.boolean(true));
1247 1247
1248 // We can be pretty sure that the objectClass is initialized, since 1248 // We can be pretty sure that the objectClass is initialized, since
1249 // typedefs are only emitted with reflection, which requires lots of 1249 // typedefs are only emitted with reflection, which requires lots of
1250 // classes. 1250 // classes.
1251 assert(compiler.objectClass != null); 1251 assert(compiler.objectClass != null);
1252 builder.superName = namer.getNameOfClass(compiler.objectClass); 1252 builder.superName = namer.className(compiler.objectClass);
1253 jsAst.Node declaration = builder.toObjectInitializer(); 1253 jsAst.Node declaration = builder.toObjectInitializer();
1254 String mangledName = namer.getNameX(typedef); 1254 String mangledName = namer.globalPropertyName(typedef);
1255 String reflectionName = getReflectionName(typedef, mangledName); 1255 String reflectionName = getReflectionName(typedef, mangledName);
1256 getElementDescriptor(library) 1256 getElementDescriptor(library)
1257 ..addProperty(mangledName, declaration) 1257 ..addProperty(mangledName, declaration)
1258 ..addProperty("+$reflectionName", js.string('')); 1258 ..addProperty("+$reflectionName", js.string(''));
1259 // Also emit a trivial constructor for CSP mode. 1259 // Also emit a trivial constructor for CSP mode.
1260 String constructorName = mangledName; 1260 String constructorName = mangledName;
1261 jsAst.Expression constructorAst = js('function() {}'); 1261 jsAst.Expression constructorAst = js('function() {}');
1262 List<String> fieldNames = []; 1262 List<String> fieldNames = [];
1263 emitPrecompiledConstructor(mainOutputUnit, 1263 emitPrecompiledConstructor(mainOutputUnit,
1264 constructorName, 1264 constructorName,
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2038 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2039 if (element.isInstanceMember) { 2039 if (element.isInstanceMember) {
2040 cachedClassBuilders.remove(element.enclosingClass); 2040 cachedClassBuilders.remove(element.enclosingClass);
2041 2041
2042 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2042 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2043 2043
2044 } 2044 }
2045 } 2045 }
2046 } 2046 }
2047 } 2047 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698