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

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: Rebase 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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 String get finishIsolateConstructorName 141 String get finishIsolateConstructorName
142 => '${namer.isolateName}.\$finishIsolateConstructor'; 142 => '${namer.isolateName}.\$finishIsolateConstructor';
143 String get isolatePropertiesName 143 String get isolatePropertiesName
144 => '${namer.isolateName}.${namer.isolatePropertiesName}'; 144 => '${namer.isolateName}.${namer.isolatePropertiesName}';
145 String get lazyInitializerProperty 145 String get lazyInitializerProperty
146 => r'$lazy'; 146 => r'$lazy';
147 String get lazyInitializerName 147 String get lazyInitializerName
148 => '${namer.isolateName}.${lazyInitializerProperty}'; 148 => '${namer.isolateName}.${lazyInitializerProperty}';
149 String get initName => 'init'; 149 String get initName => 'init';
150 150
151 String get makeConstListProperty 151 String get makeConstListProperty => namer.internalGlobal('makeConstantList');
152 => namer.getMappedInstanceName('makeConstantList');
153 152
154 /// The name of the property that contains all field names. 153 /// The name of the property that contains all field names.
155 /// 154 ///
156 /// This property is added to constructors when isolate support is enabled. 155 /// This property is added to constructors when isolate support is enabled.
157 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; 156 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__";
158 157
159 /// For deferred loading we communicate the initializers via this global var. 158 /// For deferred loading we communicate the initializers via this global var.
160 final String deferredInitializers = r"$dart_deferred_initializers"; 159 final String deferredInitializers = r"$dart_deferred_initializers";
161 160
162 /// All the global state can be passed around with this variable. 161 /// Contains the global state that is needed to initialize and load a
163 String get globalsHolder => namer.getMappedGlobalName("globalsHolder"); 162 /// deferred library.
163 String get globalsHolder => namer.internalGlobal("globalsHolder");
164 164
165 @override 165 @override
166 jsAst.Expression generateEmbeddedGlobalAccess(String global) { 166 jsAst.Expression generateEmbeddedGlobalAccess(String global) {
167 return js(generateEmbeddedGlobalAccessString(global)); 167 return js(generateEmbeddedGlobalAccessString(global));
168 } 168 }
169 169
170 String generateEmbeddedGlobalAccessString(String global) { 170 String generateEmbeddedGlobalAccessString(String global) {
171 // TODO(floitsch): don't use 'init' as global embedder storage. 171 // TODO(floitsch): don't use 'init' as global embedder storage.
172 return '$initName.$global'; 172 return '$initName.$global';
173 } 173 }
174 174
175 jsAst.PropertyAccess globalPropertyAccess(Element element) { 175 jsAst.PropertyAccess globalPropertyAccess(Element element) {
176 String name = namer.getNameX(element); 176 String name = namer.globalPropertyName(element);
177 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field( 177 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field(
178 new jsAst.VariableUse(namer.globalObjectFor(element)), 178 new jsAst.VariableUse(namer.globalObjectFor(element)),
179 name); 179 name);
180 return pa; 180 return pa;
181 } 181 }
182 182
183 @override 183 @override
184 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { 184 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) {
185 return jsAst.js('#.#', [namer.globalObjectFor(element), 185 return jsAst.js('#.#', [namer.globalObjectFor(element),
186 namer.getLazyInitializerName(element)]); 186 namer.lazyInitializerName(element)]);
187 } 187 }
188 188
189 @override 189 @override
190 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) { 190 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) {
191 return jsAst.js('#.#()', 191 return jsAst.js('#.#()',
192 [namer.globalObjectFor(element), namer.getStaticClosureName(element)]); 192 [namer.globalObjectFor(element), namer.staticClosureName(element)]);
193 } 193 }
194 194
195 @override 195 @override
196 jsAst.PropertyAccess staticFieldAccess(FieldElement element) { 196 jsAst.PropertyAccess staticFieldAccess(FieldElement element) {
197 return globalPropertyAccess(element); 197 return globalPropertyAccess(element);
198 } 198 }
199 199
200 @override 200 @override
201 jsAst.PropertyAccess staticFunctionAccess(FunctionElement element) { 201 jsAst.PropertyAccess staticFunctionAccess(FunctionElement element) {
202 return globalPropertyAccess(element); 202 return globalPropertyAccess(element);
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 containerBuilder.addMemberMethod(method, builder); 719 containerBuilder.addMemberMethod(method, builder);
720 getElementDescriptor(element).properties.addAll(builder.properties); 720 getElementDescriptor(element).properties.addAll(builder.properties);
721 } 721 }
722 } 722 }
723 723
724 void emitStaticNonFinalFieldInitializations(CodeOutput output, 724 void emitStaticNonFinalFieldInitializations(CodeOutput output,
725 OutputUnit outputUnit) { 725 OutputUnit outputUnit) {
726 void emitInitialization(Element element, jsAst.Expression initialValue) { 726 void emitInitialization(Element element, jsAst.Expression initialValue) {
727 jsAst.Expression init = 727 jsAst.Expression init =
728 js('$isolateProperties.# = #', 728 js('$isolateProperties.# = #',
729 [namer.getNameOfGlobalField(element), initialValue]); 729 [namer.globalPropertyName(element), initialValue]);
730 output.addBuffer(jsAst.prettyPrint(init, compiler, 730 output.addBuffer(jsAst.prettyPrint(init, compiler,
731 monitor: compiler.dumpInfoTask)); 731 monitor: compiler.dumpInfoTask));
732 output.add('$N'); 732 output.add('$N');
733 } 733 }
734 734
735 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); 735 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
736 JavaScriptConstantCompiler handler = backend.constants; 736 JavaScriptConstantCompiler handler = backend.constants;
737 737
738 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; 738 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
739 // If the outputUnit does not contain any static non-final fields, then 739 // If the outputUnit does not contain any static non-final fields, then
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 if (code == null) return null; 790 if (code == null) return null;
791 // The code only computes the initial value. We build the lazy-check 791 // The code only computes the initial value. We build the lazy-check
792 // here: 792 // here:
793 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 793 // lazyInitializer(prototype, 'name', fieldName, getterName, initial);
794 // The name is used for error reporting. The 'initial' must be a 794 // The name is used for error reporting. The 'initial' must be a
795 // closure that constructs the initial value. 795 // closure that constructs the initial value.
796 return js('#(#,#,#,#,#)', 796 return js('#(#,#,#,#,#)',
797 [js(lazyInitializerName), 797 [js(lazyInitializerName),
798 js(isolateProperties), 798 js(isolateProperties),
799 js.string(element.name), 799 js.string(element.name),
800 js.string(namer.getNameX(element)), 800 js.string(namer.globalPropertyName(element)),
801 js.string(namer.getLazyInitializerName(element)), 801 js.string(namer.lazyInitializerName(element)),
802 code]); 802 code]);
803 } 803 }
804 804
805 void emitMetadata(List<String> globalMetadata, CodeOutput output) { 805 void emitMetadata(List<String> globalMetadata, CodeOutput output) {
806 String metadataAccess = 806 String metadataAccess =
807 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); 807 generateEmbeddedGlobalAccessString(embeddedNames.METADATA);
808 output.add('$metadataAccess$_=$_['); 808 output.add('$metadataAccess$_=$_[');
809 for (String metadata in globalMetadata) { 809 for (String metadata in globalMetadata) {
810 if (metadata is String) { 810 if (metadata is String) {
811 if (metadata != 'null') { 811 if (metadata != 'null') {
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 ClassBuilder builder = new ClassBuilder(typedef, namer); 1205 ClassBuilder builder = new ClassBuilder(typedef, namer);
1206 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, 1206 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME,
1207 js.number(typeIndex)); 1207 js.number(typeIndex));
1208 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, 1208 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME,
1209 js.boolean(true)); 1209 js.boolean(true));
1210 1210
1211 // We can be pretty sure that the objectClass is initialized, since 1211 // We can be pretty sure that the objectClass is initialized, since
1212 // typedefs are only emitted with reflection, which requires lots of 1212 // typedefs are only emitted with reflection, which requires lots of
1213 // classes. 1213 // classes.
1214 assert(compiler.objectClass != null); 1214 assert(compiler.objectClass != null);
1215 builder.superName = namer.getNameOfClass(compiler.objectClass); 1215 builder.superName = namer.className(compiler.objectClass);
1216 jsAst.Node declaration = builder.toObjectInitializer(); 1216 jsAst.Node declaration = builder.toObjectInitializer();
1217 String mangledName = namer.getNameX(typedef); 1217 String mangledName = namer.globalPropertyName(typedef);
1218 String reflectionName = getReflectionName(typedef, mangledName); 1218 String reflectionName = getReflectionName(typedef, mangledName);
1219 getElementDescriptor(library) 1219 getElementDescriptor(library)
1220 ..addProperty(mangledName, declaration) 1220 ..addProperty(mangledName, declaration)
1221 ..addProperty("+$reflectionName", js.string('')); 1221 ..addProperty("+$reflectionName", js.string(''));
1222 // Also emit a trivial constructor for CSP mode. 1222 // Also emit a trivial constructor for CSP mode.
1223 String constructorName = mangledName; 1223 String constructorName = mangledName;
1224 jsAst.Expression constructorAst = js('function() {}'); 1224 jsAst.Expression constructorAst = js('function() {}');
1225 List<String> fieldNames = []; 1225 List<String> fieldNames = [];
1226 emitPrecompiledConstructor(mainOutputUnit, 1226 emitPrecompiledConstructor(mainOutputUnit,
1227 constructorName, 1227 constructorName,
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2001 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2002 if (element.isInstanceMember) { 2002 if (element.isInstanceMember) {
2003 cachedClassBuilders.remove(element.enclosingClass); 2003 cachedClassBuilders.remove(element.enclosingClass);
2004 2004
2005 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2005 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2006 2006
2007 } 2007 }
2008 } 2008 }
2009 } 2009 }
2010 } 2010 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698