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

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

Issue 906273002: Revert "dart2js: Refactoring, documentation, and a few bugfixes in Namer class." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 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 => namer.internalGlobal('makeConstantList'); 151 String get makeConstListProperty
152 => namer.getMappedInstanceName('makeConstantList');
152 153
153 /// The name of the property that contains all field names. 154 /// The name of the property that contains all field names.
154 /// 155 ///
155 /// This property is added to constructors when isolate support is enabled. 156 /// This property is added to constructors when isolate support is enabled.
156 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; 157 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__";
157 158
158 /// For deferred loading we communicate the initializers via this global var. 159 /// For deferred loading we communicate the initializers via this global var.
159 final String deferredInitializers = r"$dart_deferred_initializers"; 160 final String deferredInitializers = r"$dart_deferred_initializers";
160 161
161 /// Contains the global state that is needed to initialize and load a 162 /// All the global state can be passed around with this variable.
162 /// deferred library. 163 String get globalsHolder => namer.getMappedGlobalName("globalsHolder");
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.globalPropertyName(element); 176 String name = namer.getNameX(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.lazyInitializerName(element)]); 186 namer.getLazyInitializerName(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.staticClosureName(element)]); 192 [namer.globalObjectFor(element), namer.getStaticClosureName(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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 containerBuilder.addMemberMethod(method, builder); 711 containerBuilder.addMemberMethod(method, builder);
712 getElementDescriptor(element).properties.addAll(builder.properties); 712 getElementDescriptor(element).properties.addAll(builder.properties);
713 } 713 }
714 } 714 }
715 715
716 void emitStaticNonFinalFieldInitializations(CodeOutput output, 716 void emitStaticNonFinalFieldInitializations(CodeOutput output,
717 OutputUnit outputUnit) { 717 OutputUnit outputUnit) {
718 void emitInitialization(Element element, jsAst.Expression initialValue) { 718 void emitInitialization(Element element, jsAst.Expression initialValue) {
719 jsAst.Expression init = 719 jsAst.Expression init =
720 js('$isolateProperties.# = #', 720 js('$isolateProperties.# = #',
721 [namer.globalPropertyName(element), initialValue]); 721 [namer.getNameOfGlobalField(element), initialValue]);
722 output.addBuffer(jsAst.prettyPrint(init, compiler, 722 output.addBuffer(jsAst.prettyPrint(init, compiler,
723 monitor: compiler.dumpInfoTask)); 723 monitor: compiler.dumpInfoTask));
724 output.add('$N'); 724 output.add('$N');
725 } 725 }
726 726
727 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); 727 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
728 JavaScriptConstantCompiler handler = backend.constants; 728 JavaScriptConstantCompiler handler = backend.constants;
729 729
730 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; 730 Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
731 // If the outputUnit does not contain any static non-final fields, then 731 // If the outputUnit does not contain any static non-final fields, then
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 if (code == null) return null; 782 if (code == null) return null;
783 // The code only computes the initial value. We build the lazy-check 783 // The code only computes the initial value. We build the lazy-check
784 // here: 784 // here:
785 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 785 // lazyInitializer(prototype, 'name', fieldName, getterName, initial);
786 // The name is used for error reporting. The 'initial' must be a 786 // The name is used for error reporting. The 'initial' must be a
787 // closure that constructs the initial value. 787 // closure that constructs the initial value.
788 return js('#(#,#,#,#,#)', 788 return js('#(#,#,#,#,#)',
789 [js(lazyInitializerName), 789 [js(lazyInitializerName),
790 js(isolateProperties), 790 js(isolateProperties),
791 js.string(element.name), 791 js.string(element.name),
792 js.string(namer.globalPropertyName(element)), 792 js.string(namer.getNameX(element)),
793 js.string(namer.lazyInitializerName(element)), 793 js.string(namer.getLazyInitializerName(element)),
794 code]); 794 code]);
795 } 795 }
796 796
797 void emitMetadata(List<String> globalMetadata, CodeOutput output) { 797 void emitMetadata(List<String> globalMetadata, CodeOutput output) {
798 String metadataAccess = 798 String metadataAccess =
799 generateEmbeddedGlobalAccessString(embeddedNames.METADATA); 799 generateEmbeddedGlobalAccessString(embeddedNames.METADATA);
800 output.add('$metadataAccess$_=$_['); 800 output.add('$metadataAccess$_=$_[');
801 for (String metadata in globalMetadata) { 801 for (String metadata in globalMetadata) {
802 if (metadata is String) { 802 if (metadata is String) {
803 if (metadata != 'null') { 803 if (metadata != 'null') {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 ClassBuilder builder = new ClassBuilder(typedef, namer); 1257 ClassBuilder builder = new ClassBuilder(typedef, namer);
1258 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, 1258 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME,
1259 js.number(typeIndex)); 1259 js.number(typeIndex));
1260 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, 1260 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME,
1261 js.boolean(true)); 1261 js.boolean(true));
1262 1262
1263 // We can be pretty sure that the objectClass is initialized, since 1263 // We can be pretty sure that the objectClass is initialized, since
1264 // typedefs are only emitted with reflection, which requires lots of 1264 // typedefs are only emitted with reflection, which requires lots of
1265 // classes. 1265 // classes.
1266 assert(compiler.objectClass != null); 1266 assert(compiler.objectClass != null);
1267 builder.superName = namer.className(compiler.objectClass); 1267 builder.superName = namer.getNameOfClass(compiler.objectClass);
1268 jsAst.Node declaration = builder.toObjectInitializer(); 1268 jsAst.Node declaration = builder.toObjectInitializer();
1269 String mangledName = namer.globalPropertyName(typedef); 1269 String mangledName = namer.getNameX(typedef);
1270 String reflectionName = getReflectionName(typedef, mangledName); 1270 String reflectionName = getReflectionName(typedef, mangledName);
1271 getElementDescriptor(library) 1271 getElementDescriptor(library)
1272 ..addProperty(mangledName, declaration) 1272 ..addProperty(mangledName, declaration)
1273 ..addProperty("+$reflectionName", js.string('')); 1273 ..addProperty("+$reflectionName", js.string(''));
1274 // Also emit a trivial constructor for CSP mode. 1274 // Also emit a trivial constructor for CSP mode.
1275 String constructorName = mangledName; 1275 String constructorName = mangledName;
1276 jsAst.Expression constructorAst = js('function() {}'); 1276 jsAst.Expression constructorAst = js('function() {}');
1277 List<String> fieldNames = []; 1277 List<String> fieldNames = [];
1278 emitPrecompiledConstructor(mainOutputUnit, 1278 emitPrecompiledConstructor(mainOutputUnit,
1279 constructorName, 1279 constructorName,
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2053 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2054 if (element.isInstanceMember) { 2054 if (element.isInstanceMember) {
2055 cachedClassBuilders.remove(element.enclosingClass); 2055 cachedClassBuilders.remove(element.enclosingClass);
2056 2056
2057 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2057 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2058 2058
2059 } 2059 }
2060 } 2060 }
2061 } 2061 }
2062 } 2062 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698