Chromium Code Reviews| 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 // In CSP mode [emitClassConstructor] and [emitClassGettersSetters] have | |
|
floitsch
2015/01/15 15:14:40
nit: newline before.
zarah
2015/01/16 08:48:50
Done.
| |
| 237 // a side-effect on "precompiled" functions in [OldEmitter]. For this | |
| 238 // reason, it is important that we don't call these methods before we | |
| 239 // are certain that a class is needed. | |
| 240 | |
| 241 // [emitClassConstructor] only affects the generation of constructors | |
| 242 // in CSP mode. | |
| 243 emitterTask.oldEmitter.classEmitter.emitClassConstructor( | |
| 244 classElement, builder); | |
| 245 // [emitClassGettersSetters] does not affect whether or not a class is | |
|
floitsch
2015/01/15 15:14:40
nit: newline before.
zarah
2015/01/16 08:48:50
Done.
| |
| 246 // needed. If getters/setters are emitted, the class has fields and | |
| 247 // is therefore non-trivial. | |
| 248 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( | |
| 249 classElement, builder); | |
| 235 // Define interceptor class for [classElement]. | 250 // Define interceptor class for [classElement]. |
| 236 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( | 251 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( |
| 237 backend.namer.getNameOfClass(classElement), | 252 backend.namer.getNameOfClass(classElement), classElement, builder, |
| 238 classElement, builders[classElement], | |
| 239 emitterTask.oldEmitter.getElementDescriptor(classElement)); | 253 emitterTask.oldEmitter.getElementDescriptor(classElement)); |
| 240 emitterTask.oldEmitter.needsClassSupport = true; | 254 emitterTask.oldEmitter.needsClassSupport = true; |
| 241 } | 255 } |
| 242 } | 256 } |
| 243 } | 257 } |
| 244 | 258 |
| 245 /** | 259 /** |
| 246 * Computes the native classes that are extended (subclassed) by non-native | 260 * Computes the native classes that are extended (subclassed) by non-native |
| 247 * classes and the set non-mative classes that extend them. (A List is used | 261 * classes and the set non-mative classes that extend them. (A List is used |
| 248 * instead of a Set for out stability). | 262 * instead of a Set for out stability). |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 if (compiler.hasIncrementalSupport) { | 308 if (compiler.hasIncrementalSupport) { |
| 295 builder = cachedBuilders[classElement]; | 309 builder = cachedBuilders[classElement]; |
| 296 if (builder != null) return builder; | 310 if (builder != null) return builder; |
| 297 builder = new ClassBuilder(classElement, backend.namer); | 311 builder = new ClassBuilder(classElement, backend.namer); |
| 298 cachedBuilders[classElement] = builder; | 312 cachedBuilders[classElement] = builder; |
| 299 } else { | 313 } else { |
| 300 builder = new ClassBuilder(classElement, backend.namer); | 314 builder = new ClassBuilder(classElement, backend.namer); |
| 301 } | 315 } |
| 302 builder.superName = superName; | 316 builder.superName = superName; |
| 303 | 317 |
| 304 emitterTask.oldEmitter.classEmitter.emitClassConstructor( | |
| 305 classElement, builder); | |
| 306 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( | 318 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( |
| 307 classElement, builder, classIsNative: true); | 319 classElement, builder, classIsNative: true); |
| 308 int propertyCount = builder.properties.length; | 320 int propertyCount = builder.properties.length; |
| 309 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( | 321 |
| 310 classElement, builder); | |
| 311 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( | 322 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( |
| 312 classElement, builder); | 323 classElement, builder); |
| 313 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); | 324 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); |
| 314 | 325 |
| 315 if (!hasFields && | 326 if (!hasFields && |
| 316 builder.properties.length == propertyCount && | 327 builder.properties.length == propertyCount && |
| 317 superclass is! MixinApplicationElement) { | 328 superclass is! MixinApplicationElement) { |
| 318 builder.isTrivial = true; | 329 builder.isTrivial = true; |
| 319 } | 330 } |
| 320 | 331 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 targetOutput.add(';'); | 481 targetOutput.add(';'); |
| 471 } | 482 } |
| 472 targetOutput.addBuffer(jsAst.prettyPrint( | 483 targetOutput.addBuffer(jsAst.prettyPrint( |
| 473 new jsAst.ExpressionStatement(init), compiler)); | 484 new jsAst.ExpressionStatement(init), compiler)); |
| 474 targetOutput.add('\n'); | 485 targetOutput.add('\n'); |
| 475 } | 486 } |
| 476 | 487 |
| 477 targetOutput.add('\n'); | 488 targetOutput.add('\n'); |
| 478 } | 489 } |
| 479 } | 490 } |
| OLD | NEW |