| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 class ClassEmitter extends CodeEmitterHelper { | 7 class ClassEmitter extends CodeEmitterHelper { |
| 8 | 8 |
| 9 ClassStubGenerator get _stubGenerator => | 9 ClassStubGenerator get _stubGenerator => |
| 10 new ClassStubGenerator(compiler, namer, backend); | 10 new ClassStubGenerator(compiler, namer, backend); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 superName = namer.getNameOfClass(superclass); | 32 superName = namer.getNameOfClass(superclass); |
| 33 } | 33 } |
| 34 | 34 |
| 35 if (classElement.isMixinApplication) { | 35 if (classElement.isMixinApplication) { |
| 36 String mixinName = namer.getNameOfClass(computeMixinClass(classElement)); | 36 String mixinName = namer.getNameOfClass(computeMixinClass(classElement)); |
| 37 superName = '$superName+$mixinName'; | 37 superName = '$superName+$mixinName'; |
| 38 emitter.needsMixinSupport = true; | 38 emitter.needsMixinSupport = true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 ClassBuilder builder = new ClassBuilder(classElement, namer); | 41 ClassBuilder builder = new ClassBuilder(classElement, namer); |
| 42 builder.superName = superName; |
| 42 emitClassConstructor(classElement, builder, onlyForRti: onlyForRti); | 43 emitClassConstructor(classElement, builder, onlyForRti: onlyForRti); |
| 43 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); | 44 emitFields(classElement, builder, onlyForRti: onlyForRti); |
| 44 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); | 45 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); |
| 45 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); | 46 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); |
| 46 emitter.typeTestEmitter.emitIsTests(classElement, builder); | 47 emitter.typeTestEmitter.emitIsTests(classElement, builder); |
| 47 if (additionalProperties != null) { | 48 if (additionalProperties != null) { |
| 48 additionalProperties.forEach(builder.addProperty); | 49 additionalProperties.forEach(builder.addProperty); |
| 49 } | 50 } |
| 50 | 51 |
| 51 if (classElement == backend.closureClass) { | 52 if (classElement == backend.closureClass) { |
| 52 // We add a special getter here to allow for tearing off a closure from | 53 // We add a special getter here to allow for tearing off a closure from |
| 53 // itself. | 54 // itself. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 84 String constructorName = namer.getNameOfClass(classElement); | 85 String constructorName = namer.getNameOfClass(classElement); |
| 85 OutputUnit outputUnit = | 86 OutputUnit outputUnit = |
| 86 compiler.deferredLoadTask.outputUnitForElement(classElement); | 87 compiler.deferredLoadTask.outputUnitForElement(classElement); |
| 87 emitter.emitPrecompiledConstructor( | 88 emitter.emitPrecompiledConstructor( |
| 88 outputUnit, constructorName, constructorAst); | 89 outputUnit, constructorName, constructorAst); |
| 89 } | 90 } |
| 90 | 91 |
| 91 /// Returns `true` if fields added. | 92 /// Returns `true` if fields added. |
| 92 bool emitFields(Element element, | 93 bool emitFields(Element element, |
| 93 ClassBuilder builder, | 94 ClassBuilder builder, |
| 94 String superName, | |
| 95 { bool classIsNative: false, | 95 { bool classIsNative: false, |
| 96 bool emitStatics: false, | 96 bool emitStatics: false, |
| 97 bool onlyForRti: false }) { | 97 bool onlyForRti: false }) { |
| 98 assert(!emitStatics || !onlyForRti); | 98 assert(!emitStatics || !onlyForRti); |
| 99 if (element.isLibrary) { | 99 if (element.isLibrary) { |
| 100 assert(invariant(element, emitStatics)); | 100 assert(invariant(element, emitStatics)); |
| 101 } else if (!element.isClass) { | 101 } else if (!element.isClass) { |
| 102 throw new SpannableAssertionFailure( | 102 throw new SpannableAssertionFailure( |
| 103 element, 'Must be a ClassElement or a LibraryElement'); | 103 element, 'Must be a ClassElement or a LibraryElement'); |
| 104 } | 104 } |
| 105 if (emitStatics) { | |
| 106 assert(invariant(element, superName == null, message: superName)); | |
| 107 } else { | |
| 108 assert(invariant(element, superName != null)); | |
| 109 builder.superName = superName; | |
| 110 } | |
| 111 var fieldMetadata = []; | 105 var fieldMetadata = []; |
| 112 bool hasMetadata = false; | 106 bool hasMetadata = false; |
| 113 bool fieldsAdded = false; | 107 bool fieldsAdded = false; |
| 114 | 108 |
| 115 if (!onlyForRti) { | 109 if (!onlyForRti) { |
| 116 visitFields(element, emitStatics, | 110 visitFields(element, emitStatics, |
| 117 (VariableElement field, | 111 (VariableElement field, |
| 118 String name, | 112 String name, |
| 119 String accessorName, | 113 String accessorName, |
| 120 bool needsGetter, | 114 bool needsGetter, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 bool hasSuper = superclass != null; | 298 bool hasSuper = superclass != null; |
| 305 if ((!typeVariableProperties.isEmpty && !hasSuper) || | 299 if ((!typeVariableProperties.isEmpty && !hasSuper) || |
| 306 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { | 300 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { |
| 307 classBuilder.addProperty('<>', | 301 classBuilder.addProperty('<>', |
| 308 new jsAst.ArrayInitializer.from(typeVariableProperties)); | 302 new jsAst.ArrayInitializer.from(typeVariableProperties)); |
| 309 } | 303 } |
| 310 } | 304 } |
| 311 | 305 |
| 312 List<jsAst.Property> statics = new List<jsAst.Property>(); | 306 List<jsAst.Property> statics = new List<jsAst.Property>(); |
| 313 ClassBuilder staticsBuilder = new ClassBuilder(classElement, namer); | 307 ClassBuilder staticsBuilder = new ClassBuilder(classElement, namer); |
| 314 if (emitFields(classElement, staticsBuilder, null, emitStatics: true)) { | 308 if (emitFields(classElement, staticsBuilder, emitStatics: true)) { |
| 315 jsAst.ObjectInitializer initializer = | 309 jsAst.ObjectInitializer initializer = |
| 316 staticsBuilder.toObjectInitializer(); | 310 staticsBuilder.toObjectInitializer(); |
| 317 compiler.dumpInfoTask.registerElementAst(classElement, | 311 compiler.dumpInfoTask.registerElementAst(classElement, |
| 318 initializer); | 312 initializer); |
| 319 jsAst.Node property = initializer.properties.single; | 313 jsAst.Node property = initializer.properties.single; |
| 320 compiler.dumpInfoTask.registerElementAst(classElement, property); | 314 compiler.dumpInfoTask.registerElementAst(classElement, property); |
| 321 statics.add(property); | 315 statics.add(property); |
| 322 } | 316 } |
| 323 | 317 |
| 324 ClassBuilder classProperties = | 318 ClassBuilder classProperties = |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index); | 594 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index); |
| 601 } | 595 } |
| 602 jsAst.Expression convertRtiToRuntimeType = | 596 jsAst.Expression convertRtiToRuntimeType = |
| 603 namer.elementAccess(backend.findHelper('convertRtiToRuntimeType')); | 597 namer.elementAccess(backend.findHelper('convertRtiToRuntimeType')); |
| 604 compiler.dumpInfoTask.registerElementAst(element, | 598 compiler.dumpInfoTask.registerElementAst(element, |
| 605 builder.addProperty(name, | 599 builder.addProperty(name, |
| 606 js('function () { return #(#) }', | 600 js('function () { return #(#) }', |
| 607 [convertRtiToRuntimeType, computeTypeVariable]))); | 601 [convertRtiToRuntimeType, computeTypeVariable]))); |
| 608 } | 602 } |
| 609 } | 603 } |
| OLD | NEW |