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

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: Typo and TODO about clash in named parameters 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.internGlobal('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 /// All the global state can be passed around with this variable.
floitsch 2015/01/30 21:03:38 Please update comment: Contains the global state t
asgerf 2015/02/03 17:39:13 Done.
165 String get globalsHolder => namer.getMappedGlobalName("globalsHolder"); 164 String get globalsHolder => namer.internGlobal("globalsHolder");
166 165
167 @override 166 @override
168 jsAst.Expression generateEmbeddedGlobalAccess(String global) { 167 jsAst.Expression generateEmbeddedGlobalAccess(String global) {
169 return js(generateEmbeddedGlobalAccessString(global)); 168 return js(generateEmbeddedGlobalAccessString(global));
170 } 169 }
171 170
172 String generateEmbeddedGlobalAccessString(String global) { 171 String generateEmbeddedGlobalAccessString(String global) {
173 // TODO(floitsch): don't use 'init' as global embedder storage. 172 // TODO(floitsch): don't use 'init' as global embedder storage.
174 return '$initName.$global'; 173 return '$initName.$global';
175 } 174 }
176 175
177 jsAst.PropertyAccess globalPropertyAccess(Element element) { 176 jsAst.PropertyAccess globalPropertyAccess(Element element) {
178 String name = namer.getNameX(element); 177 String name = namer.globalPropertyName(element);
179 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field( 178 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field(
180 new jsAst.VariableUse(namer.globalObjectFor(element)), 179 new jsAst.VariableUse(namer.globalObjectFor(element)),
181 name); 180 name);
182 return pa; 181 return pa;
183 } 182 }
184 183
185 @override 184 @override
186 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { 185 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) {
187 return jsAst.js('#.#', [namer.globalObjectFor(element), 186 return jsAst.js('#.#', [namer.globalObjectFor(element),
188 namer.getLazyInitializerName(element)]); 187 namer.getLazyInitializerName(element)]);
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 containerBuilder.addMember(element, builder); 712 containerBuilder.addMember(element, builder);
714 getElementDescriptor(element).properties.addAll(builder.properties); 713 getElementDescriptor(element).properties.addAll(builder.properties);
715 } 714 }
716 } 715 }
717 716
718 void emitStaticNonFinalFieldInitializations(CodeOutput output, 717 void emitStaticNonFinalFieldInitializations(CodeOutput output,
719 OutputUnit outputUnit) { 718 OutputUnit outputUnit) {
720 void emitInitialization(Element element, jsAst.Expression initialValue) { 719 void emitInitialization(Element element, jsAst.Expression initialValue) {
721 jsAst.Expression init = 720 jsAst.Expression init =
722 js('$isolateProperties.# = #', 721 js('$isolateProperties.# = #',
723 [namer.getNameOfGlobalField(element), initialValue]); 722 [namer.globalPropertyName(element), initialValue]);
724 output.addBuffer(jsAst.prettyPrint(init, compiler, 723 output.addBuffer(jsAst.prettyPrint(init, compiler,
725 monitor: compiler.dumpInfoTask)); 724 monitor: compiler.dumpInfoTask));
726 output.add('$N'); 725 output.add('$N');
727 } 726 }
728 727
729 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); 728 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
730 JavaScriptConstantCompiler handler = backend.constants; 729 JavaScriptConstantCompiler handler = backend.constants;
731 730
732 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; 731 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
733 // If the outputUnit does not contain any static non-final fields, then 732 // 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; 783 if (code == null) return null;
785 // The code only computes the initial value. We build the lazy-check 784 // The code only computes the initial value. We build the lazy-check
786 // here: 785 // here:
787 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 786 // lazyInitializer(prototype, 'name', fieldName, getterName, initial);
788 // The name is used for error reporting. The 'initial' must be a 787 // The name is used for error reporting. The 'initial' must be a
789 // closure that constructs the initial value. 788 // closure that constructs the initial value.
790 return js('#(#,#,#,#,#)', 789 return js('#(#,#,#,#,#)',
791 [js(lazyInitializerName), 790 [js(lazyInitializerName),
792 js(isolateProperties), 791 js(isolateProperties),
793 js.string(element.name), 792 js.string(element.name),
794 js.string(namer.getNameX(element)), 793 js.string(namer.globalPropertyName(element)),
795 js.string(namer.getLazyInitializerName(element)), 794 js.string(namer.getLazyInitializerName(element)),
796 code]); 795 code]);
797 } 796 }
798 797
799 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { 798 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) {
800 if (constant.isFunction) return true; // Already emitted. 799 if (constant.isFunction) return true; // Already emitted.
801 if (constant.isPrimitive) return true; // Inlined. 800 if (constant.isPrimitive) return true; // Inlined.
802 if (constant.isDummy) return true; // Inlined. 801 if (constant.isDummy) return true; // Inlined.
803 // The name is null when the constant is already a JS constant. 802 // The name is null when the constant is already a JS constant.
804 // TODO(floitsch): every constant should be registered, so that we can 803 // TODO(floitsch): every constant should be registered, so that we can
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 js.number(typeIndex)); 1243 js.number(typeIndex));
1245 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, 1244 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME,
1246 js.boolean(true)); 1245 js.boolean(true));
1247 1246
1248 // We can be pretty sure that the objectClass is initialized, since 1247 // We can be pretty sure that the objectClass is initialized, since
1249 // typedefs are only emitted with reflection, which requires lots of 1248 // typedefs are only emitted with reflection, which requires lots of
1250 // classes. 1249 // classes.
1251 assert(compiler.objectClass != null); 1250 assert(compiler.objectClass != null);
1252 builder.superName = namer.getNameOfClass(compiler.objectClass); 1251 builder.superName = namer.getNameOfClass(compiler.objectClass);
1253 jsAst.Node declaration = builder.toObjectInitializer(); 1252 jsAst.Node declaration = builder.toObjectInitializer();
1254 String mangledName = namer.getNameX(typedef); 1253 String mangledName = namer.globalPropertyName(typedef);
1255 String reflectionName = getReflectionName(typedef, mangledName); 1254 String reflectionName = getReflectionName(typedef, mangledName);
1256 getElementDescriptor(library) 1255 getElementDescriptor(library)
1257 ..addProperty(mangledName, declaration) 1256 ..addProperty(mangledName, declaration)
1258 ..addProperty("+$reflectionName", js.string('')); 1257 ..addProperty("+$reflectionName", js.string(''));
1259 // Also emit a trivial constructor for CSP mode. 1258 // Also emit a trivial constructor for CSP mode.
1260 String constructorName = mangledName; 1259 String constructorName = mangledName;
1261 jsAst.Expression constructorAst = js('function() {}'); 1260 jsAst.Expression constructorAst = js('function() {}');
1262 List<String> fieldNames = []; 1261 List<String> fieldNames = [];
1263 emitPrecompiledConstructor(mainOutputUnit, 1262 emitPrecompiledConstructor(mainOutputUnit,
1264 constructorName, 1263 constructorName,
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2037 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2039 if (element.isInstanceMember) { 2038 if (element.isInstanceMember) {
2040 cachedClassBuilders.remove(element.enclosingClass); 2039 cachedClassBuilders.remove(element.enclosingClass);
2041 2040
2042 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2041 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2043 2042
2044 } 2043 }
2045 } 2044 }
2046 } 2045 }
2047 } 2046 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698