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 | |
| 237 // In CSP mode [emitClassConstructor] and [emitClassGettersSetters] emit | |
| 238 // code outside the classBuilder. They are called here to avoid emitting | |
| 239 // code for unneeded classes. | |
| 240 // | |
| 241 // Having the calls here (instead of in the classBuilder) is safe: | |
|
ahe
2015/01/15 08:49:51
I'm not sure this comment adds value long term. Wh
zarah
2015/01/15 15:10:19
Done.
| |
| 242 // | |
| 243 // [emitClassConstructor] only affects the generation of constructors | |
|
ahe
2015/01/15 08:49:51
Shouldn't this be part of emitClassConstructor's d
floitsch
2015/01/15 14:37:20
Probably both.
zarah
2015/01/15 15:10:19
Added documentation of the function as well.
| |
| 244 // in CSP mode. | |
| 245 // | |
| 246 // [emitClassGettersSetters] does not affect whether or not a class is | |
|
ahe
2015/01/15 08:49:51
Ditto.
floitsch
2015/01/15 14:37:20
No. this comment should be here.
It explains why w
zarah
2015/01/15 15:10:19
Added documentation of the function as well.
| |
| 247 // needed. If getters/setters are emitted, the class has fields and | |
| 248 // is therefore non-trivial. | |
| 249 emitterTask.oldEmitter.classEmitter.emitClassConstructor( | |
| 250 classElement, builder); | |
| 251 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( | |
| 252 classElement, builder); | |
| 235 // Define interceptor class for [classElement]. | 253 // Define interceptor class for [classElement]. |
| 236 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( | 254 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( |
| 237 backend.namer.getNameOfClass(classElement), | 255 backend.namer.getNameOfClass(classElement), classElement, builder, |
| 238 classElement, builders[classElement], | |
| 239 emitterTask.oldEmitter.getElementDescriptor(classElement)); | 256 emitterTask.oldEmitter.getElementDescriptor(classElement)); |
| 240 emitterTask.oldEmitter.needsClassSupport = true; | 257 emitterTask.oldEmitter.needsClassSupport = true; |
| 241 } | 258 } |
| 242 } | 259 } |
| 243 } | 260 } |
| 244 | 261 |
| 245 /** | 262 /** |
| 246 * Computes the native classes that are extended (subclassed) by non-native | 263 * 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 | 264 * classes and the set non-mative classes that extend them. (A List is used |
| 248 * instead of a Set for out stability). | 265 * instead of a Set for out stability). |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 if (compiler.hasIncrementalSupport) { | 311 if (compiler.hasIncrementalSupport) { |
| 295 builder = cachedBuilders[classElement]; | 312 builder = cachedBuilders[classElement]; |
| 296 if (builder != null) return builder; | 313 if (builder != null) return builder; |
| 297 builder = new ClassBuilder(classElement, backend.namer); | 314 builder = new ClassBuilder(classElement, backend.namer); |
| 298 cachedBuilders[classElement] = builder; | 315 cachedBuilders[classElement] = builder; |
| 299 } else { | 316 } else { |
| 300 builder = new ClassBuilder(classElement, backend.namer); | 317 builder = new ClassBuilder(classElement, backend.namer); |
| 301 } | 318 } |
| 302 builder.superName = superName; | 319 builder.superName = superName; |
| 303 | 320 |
| 304 emitterTask.oldEmitter.classEmitter.emitClassConstructor( | |
| 305 classElement, builder); | |
| 306 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( | 321 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( |
| 307 classElement, builder, classIsNative: true); | 322 classElement, builder, classIsNative: true); |
| 308 int propertyCount = builder.properties.length; | 323 int propertyCount = builder.properties.length; |
| 309 emitterTask.oldEmitter.classEmitter.emitClassGettersSetters( | 324 |
| 310 classElement, builder); | |
| 311 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( | 325 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( |
| 312 classElement, builder); | 326 classElement, builder); |
| 313 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); | 327 emitterTask.oldEmitter.typeTestEmitter.emitIsTests(classElement, builder); |
| 314 | 328 |
| 315 if (!hasFields && | 329 if (!hasFields && |
| 316 builder.properties.length == propertyCount && | 330 builder.properties.length == propertyCount && |
| 317 superclass is! MixinApplicationElement) { | 331 superclass is! MixinApplicationElement) { |
| 318 builder.isTrivial = true; | 332 builder.isTrivial = true; |
| 319 } | 333 } |
| 320 | 334 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 targetOutput.add(';'); | 484 targetOutput.add(';'); |
| 471 } | 485 } |
| 472 targetOutput.addBuffer(jsAst.prettyPrint( | 486 targetOutput.addBuffer(jsAst.prettyPrint( |
| 473 new jsAst.ExpressionStatement(init), compiler)); | 487 new jsAst.ExpressionStatement(init), compiler)); |
| 474 targetOutput.add('\n'); | 488 targetOutput.add('\n'); |
| 475 } | 489 } |
| 476 | 490 |
| 477 targetOutput.add('\n'); | 491 targetOutput.add('\n'); |
| 478 } | 492 } |
| 479 } | 493 } |
| OLD | NEW |