| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class NativeEmitter { | 7 class NativeEmitter { |
| 8 | 8 |
| 9 final Map<Element, ClassBuilder> cachedBuilders; | 9 final Map<Element, ClassBuilder> cachedBuilders; |
| 10 | 10 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 generateClassInfo(backend.jsInterceptorClass); | 225 generateClassInfo(backend.jsInterceptorClass); |
| 226 for (ClassElement classElement in classes) { | 226 for (ClassElement classElement in classes) { |
| 227 generateClassInfo(classElement); | 227 generateClassInfo(classElement); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Emit the native class interceptors that were actually used. | 231 // Emit the native class interceptors that were actually used. |
| 232 for (ClassElement classElement in classes) { | 232 for (ClassElement classElement in classes) { |
| 233 if (!classElement.isNative) continue; | 233 if (!classElement.isNative) continue; |
| 234 if (neededClasses.contains(classElement)) { | 234 if (neededClasses.contains(classElement)) { |
| 235 ClassBuilder builder = builders[classElement]; | |
| 236 | |
| 237 // In CSP mode [emitClassConstructor] and [emitClassGettersSetters] have | |
| 238 // a side-effect on "precompiled" functions in [OldEmitter]. For this | |
| 239 // reason, it is important that we don't call these methods before we | |
| 240 // are certain that a class is needed. | |
| 241 | |
| 242 // [emitClassConstructor] only affects the generation of constructors | |
| 243 // in CSP mode. | |
| 244 emitterTask.oldEmitter.classEmitter.emitClassConstructor( | |
| 245 classElement, builder); | |
| 246 | |
| 247 // [emitClassGettersSetters] does not affect whether or not a class is | |
| 248 // needed. If getters/setters are emitted, the class has fields and | |
| 249 // is therefore non-trivial. | |
| 250 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( | |
| 251 classElement, builder); | |
| 252 | |
| 253 // Define interceptor class for [classElement]. | 235 // Define interceptor class for [classElement]. |
| 254 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( | 236 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( |
| 255 backend.namer.getNameOfClass(classElement), classElement, builder, | 237 backend.namer.getNameOfClass(classElement), |
| 238 classElement, builders[classElement], |
| 256 emitterTask.oldEmitter.getElementDescriptor(classElement)); | 239 emitterTask.oldEmitter.getElementDescriptor(classElement)); |
| 257 emitterTask.oldEmitter.needsClassSupport = true; | 240 emitterTask.oldEmitter.needsClassSupport = true; |
| 258 } | 241 } |
| 259 } | 242 } |
| 260 } | 243 } |
| 261 | 244 |
| 262 /** | 245 /** |
| 263 * Computes the native classes that are extended (subclassed) by non-native | 246 * Computes the native classes that are extended (subclassed) by non-native |
| 264 * classes and the set non-mative classes that extend them. (A List is used | 247 * classes and the set non-mative classes that extend them. (A List is used |
| 265 * instead of a Set for out stability). | 248 * instead of a Set for out stability). |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (compiler.hasIncrementalSupport) { | 294 if (compiler.hasIncrementalSupport) { |
| 312 builder = cachedBuilders[classElement]; | 295 builder = cachedBuilders[classElement]; |
| 313 if (builder != null) return builder; | 296 if (builder != null) return builder; |
| 314 builder = new ClassBuilder(classElement, backend.namer); | 297 builder = new ClassBuilder(classElement, backend.namer); |
| 315 cachedBuilders[classElement] = builder; | 298 cachedBuilders[classElement] = builder; |
| 316 } else { | 299 } else { |
| 317 builder = new ClassBuilder(classElement, backend.namer); | 300 builder = new ClassBuilder(classElement, backend.namer); |
| 318 } | 301 } |
| 319 builder.superName = superName; | 302 builder.superName = superName; |
| 320 | 303 |
| 304 emitterTask.oldEmitter.classEmitter.emitClassConstructor( |
| 305 classElement, builder); |
| 321 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( | 306 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( |
| 322 classElement, builder, classIsNative: true); | 307 classElement, builder, classIsNative: true); |
| 323 int propertyCount = builder.properties.length; | 308 int propertyCount = builder.properties.length; |
| 324 | 309 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( |
| 310 classElement, builder); |
| 325 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( | 311 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( |
| 326 classElement, builder); | 312 classElement, builder); |
| 327 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); | 313 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); |
| 328 | 314 |
| 329 if (!hasFields && | 315 if (!hasFields && |
| 330 builder.properties.length == propertyCount && | 316 builder.properties.length == propertyCount && |
| 331 superclass is! MixinApplicationElement) { | 317 superclass is! MixinApplicationElement) { |
| 332 builder.isTrivial = true; | 318 builder.isTrivial = true; |
| 333 } | 319 } |
| 334 | 320 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 targetOutput.add(';'); | 470 targetOutput.add(';'); |
| 485 } | 471 } |
| 486 targetOutput.addBuffer(jsAst.prettyPrint( | 472 targetOutput.addBuffer(jsAst.prettyPrint( |
| 487 new jsAst.ExpressionStatement(init), compiler)); | 473 new jsAst.ExpressionStatement(init), compiler)); |
| 488 targetOutput.add('\n'); | 474 targetOutput.add('\n'); |
| 489 } | 475 } |
| 490 | 476 |
| 491 targetOutput.add('\n'); | 477 targetOutput.add('\n'); |
| 492 } | 478 } |
| 493 } | 479 } |
| OLD | NEW |