| OLD | NEW | 
|---|
| 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  Loading... | 
| 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 718       containerBuilder.addMemberMethod(method, builder); | 718       containerBuilder.addMemberMethod(method, builder); | 
| 719       getElementDescriptor(element).properties.addAll(builder.properties); | 719       getElementDescriptor(element).properties.addAll(builder.properties); | 
| 720     } | 720     } | 
| 721   } | 721   } | 
| 722 | 722 | 
| 723   void emitStaticNonFinalFieldInitializations(CodeOutput output, | 723   void emitStaticNonFinalFieldInitializations(CodeOutput output, | 
| 724                                               OutputUnit outputUnit) { | 724                                               OutputUnit outputUnit) { | 
| 725     void emitInitialization(Element element, jsAst.Expression initialValue) { | 725     void emitInitialization(Element element, jsAst.Expression initialValue) { | 
| 726       jsAst.Expression init = | 726       jsAst.Expression init = | 
| 727         js('$isolateProperties.# = #', | 727         js('$isolateProperties.# = #', | 
| 728             [namer.globalPropertyName(element), initialValue]); | 728             [namer.getNameOfGlobalField(element), initialValue]); | 
| 729       output.addBuffer(jsAst.prettyPrint(init, compiler, | 729       output.addBuffer(jsAst.prettyPrint(init, compiler, | 
| 730                                          monitor: compiler.dumpInfoTask)); | 730                                          monitor: compiler.dumpInfoTask)); | 
| 731       output.add('$N'); | 731       output.add('$N'); | 
| 732     } | 732     } | 
| 733 | 733 | 
| 734     bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); | 734     bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); | 
| 735     JavaScriptConstantCompiler handler = backend.constants; | 735     JavaScriptConstantCompiler handler = backend.constants; | 
| 736 | 736 | 
| 737     Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; | 737     Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit]; | 
| 738     // If the outputUnit does not contain any static non-final fields, then | 738     // If the outputUnit does not contain any static non-final fields, then | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 789     if (code == null) return null; | 789     if (code == null) return null; | 
| 790     // The code only computes the initial value. We build the lazy-check | 790     // The code only computes the initial value. We build the lazy-check | 
| 791     // here: | 791     // here: | 
| 792     //   lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 792     //   lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 
| 793     // The name is used for error reporting. The 'initial' must be a | 793     // The name is used for error reporting. The 'initial' must be a | 
| 794     // closure that constructs the initial value. | 794     // closure that constructs the initial value. | 
| 795     return js('#(#,#,#,#,#)', | 795     return js('#(#,#,#,#,#)', | 
| 796         [js(lazyInitializerName), | 796         [js(lazyInitializerName), | 
| 797             js(isolateProperties), | 797             js(isolateProperties), | 
| 798             js.string(element.name), | 798             js.string(element.name), | 
| 799             js.string(namer.globalPropertyName(element)), | 799             js.string(namer.getNameX(element)), | 
| 800             js.string(namer.lazyInitializerName(element)), | 800             js.string(namer.getLazyInitializerName(element)), | 
| 801             code]); | 801             code]); | 
| 802   } | 802   } | 
| 803 | 803 | 
| 804   void emitMetadata(List<String> globalMetadata, CodeOutput output) { | 804   void emitMetadata(List<String> globalMetadata, CodeOutput output) { | 
| 805     String metadataAccess = | 805     String metadataAccess = | 
| 806         generateEmbeddedGlobalAccessString(embeddedNames.METADATA); | 806         generateEmbeddedGlobalAccessString(embeddedNames.METADATA); | 
| 807     output.add('$metadataAccess$_=$_['); | 807     output.add('$metadataAccess$_=$_['); | 
| 808     for (String metadata in globalMetadata) { | 808     for (String metadata in globalMetadata) { | 
| 809       if (metadata is String) { | 809       if (metadata is String) { | 
| 810         if (metadata != 'null') { | 810         if (metadata != 'null') { | 
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1201       ClassBuilder builder = new ClassBuilder(typedef, namer); | 1201       ClassBuilder builder = new ClassBuilder(typedef, namer); | 
| 1202       builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, | 1202       builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, | 
| 1203                           js.number(typeIndex)); | 1203                           js.number(typeIndex)); | 
| 1204       builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 1204       builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 
| 1205                           js.boolean(true)); | 1205                           js.boolean(true)); | 
| 1206 | 1206 | 
| 1207       // We can be pretty sure that the objectClass is initialized, since | 1207       // We can be pretty sure that the objectClass is initialized, since | 
| 1208       // typedefs are only emitted with reflection, which requires lots of | 1208       // typedefs are only emitted with reflection, which requires lots of | 
| 1209       // classes. | 1209       // classes. | 
| 1210       assert(compiler.objectClass != null); | 1210       assert(compiler.objectClass != null); | 
| 1211       builder.superName = namer.className(compiler.objectClass); | 1211       builder.superName = namer.getNameOfClass(compiler.objectClass); | 
| 1212       jsAst.Node declaration = builder.toObjectInitializer(); | 1212       jsAst.Node declaration = builder.toObjectInitializer(); | 
| 1213       String mangledName = namer.globalPropertyName(typedef); | 1213       String mangledName = namer.getNameX(typedef); | 
| 1214       String reflectionName = getReflectionName(typedef, mangledName); | 1214       String reflectionName = getReflectionName(typedef, mangledName); | 
| 1215       getElementDescriptor(library) | 1215       getElementDescriptor(library) | 
| 1216           ..addProperty(mangledName, declaration) | 1216           ..addProperty(mangledName, declaration) | 
| 1217           ..addProperty("+$reflectionName", js.string('')); | 1217           ..addProperty("+$reflectionName", js.string('')); | 
| 1218       // Also emit a trivial constructor for CSP mode. | 1218       // Also emit a trivial constructor for CSP mode. | 
| 1219       String constructorName = mangledName; | 1219       String constructorName = mangledName; | 
| 1220       jsAst.Expression constructorAst = js('function() {}'); | 1220       jsAst.Expression constructorAst = js('function() {}'); | 
| 1221       List<String> fieldNames = []; | 1221       List<String> fieldNames = []; | 
| 1222       emitPrecompiledConstructor(mainOutputUnit, | 1222       emitPrecompiledConstructor(mainOutputUnit, | 
| 1223                                  constructorName, | 1223                                  constructorName, | 
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1997     for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1997     for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 
| 1998       if (element.isInstanceMember) { | 1998       if (element.isInstanceMember) { | 
| 1999         cachedClassBuilders.remove(element.enclosingClass); | 1999         cachedClassBuilders.remove(element.enclosingClass); | 
| 2000 | 2000 | 
| 2001         nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2001         nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 
| 2002 | 2002 | 
| 2003       } | 2003       } | 
| 2004     } | 2004     } | 
| 2005   } | 2005   } | 
| 2006 } | 2006 } | 
| OLD | NEW | 
|---|