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 * Documentation wanted -- johnniwinther | 9 * Documentation wanted -- johnniwinther |
10 * | 10 * |
(...skipping 29 matching lines...) Expand all Loading... | |
40 emitClassConstructor(classElement, builder, runtimeName, | 40 emitClassConstructor(classElement, builder, runtimeName, |
41 onlyForRti: onlyForRti); | 41 onlyForRti: onlyForRti); |
42 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); | 42 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); |
43 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); | 43 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); |
44 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); | 44 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); |
45 task.typeTestEmitter.emitIsTests(classElement, builder); | 45 task.typeTestEmitter.emitIsTests(classElement, builder); |
46 if (additionalProperties != null) { | 46 if (additionalProperties != null) { |
47 additionalProperties.forEach(builder.addProperty); | 47 additionalProperties.forEach(builder.addProperty); |
48 } | 48 } |
49 | 49 |
50 emitTypeVariableReaders(classElement, builder); | |
51 | |
50 emitClassBuilderWithReflectionData( | 52 emitClassBuilderWithReflectionData( |
51 className, classElement, builder, properties); | 53 className, classElement, builder, properties); |
52 } | 54 } |
53 | 55 |
54 void emitClassConstructor(ClassElement classElement, | 56 void emitClassConstructor(ClassElement classElement, |
55 ClassBuilder builder, | 57 ClassBuilder builder, |
56 String runtimeName, | 58 String runtimeName, |
57 {bool onlyForRti: false}) { | 59 {bool onlyForRti: false}) { |
58 List<String> fields = <String>[]; | 60 List<String> fields = <String>[]; |
59 if (!onlyForRti && !classElement.isNative()) { | 61 if (!onlyForRti && !classElement.isNative()) { |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 Selector selector = isGetter | 558 Selector selector = isGetter |
557 ? new Selector.getter(member.name, member.getLibrary()) | 559 ? new Selector.getter(member.name, member.getLibrary()) |
558 : new Selector.setter(member.name, member.getLibrary()); | 560 : new Selector.setter(member.name, member.getLibrary()); |
559 String reflectionName = task.getReflectionName(selector, name); | 561 String reflectionName = task.getReflectionName(selector, name); |
560 if (reflectionName != null) { | 562 if (reflectionName != null) { |
561 var reflectable = | 563 var reflectable = |
562 js(backend.isAccessibleByReflection(member) ? '1' : '0'); | 564 js(backend.isAccessibleByReflection(member) ? '1' : '0'); |
563 builder.addProperty('+$reflectionName', reflectable); | 565 builder.addProperty('+$reflectionName', reflectable); |
564 } | 566 } |
565 } | 567 } |
568 | |
569 void emitTypeVariableReaders(ClassElement cls, ClassBuilder builder) { | |
570 List typeVariables = []; | |
571 ClassElement superclass = cls; | |
572 while (superclass != null) { | |
573 GenericType type = superclass.thisType; | |
574 for (TypeVariableType parameter in type.typeArguments) { | |
Johnni Winther
2013/12/03 10:33:16
Replace `type.typeArguments` with `superclass.type
ahe
2013/12/05 14:24:23
Done.
| |
575 if (task.readTypeVariables.contains(parameter.element)) { | |
576 emitTypeVariableReader(cls, builder, parameter.element); | |
577 } | |
578 } | |
579 superclass = superclass.superclass; | |
580 } | |
581 } | |
582 | |
583 void emitTypeVariableReader(ClassElement cls, | |
584 ClassBuilder builder, | |
585 TypeVariableElement element) { | |
586 String name = namer.readTypeVariableName(element); | |
587 jsAst.Expression index = | |
588 js.toExpression(RuntimeTypes.getTypeVariableIndex(element)); | |
589 jsAst.Expression computeTypeVariable; | |
590 | |
591 Substitution substitution = | |
592 backend.rti.computeSubstitution( | |
593 cls, element.enclosingElement, alwaysGenerateFunction: true); | |
594 if (substitution != null) { | |
595 jsAst.Expression typeArguments = | |
596 substitution.getCode(backend.rti, true)['apply']( | |
Johnni Winther
2013/12/03 10:33:16
Seems the last argument to getCode should be named
ahe
2013/12/05 14:24:23
I like to avoid adding named arguments as they add
| |
597 ['null', r'this.$builtinTypeInfo']); | |
598 computeTypeVariable = typeArguments[index]; | |
599 } else { | |
600 // TODO(ahe): These can be generated dynamically. | |
601 computeTypeVariable = | |
602 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index); | |
603 } | |
604 jsAst.Expression convertRtiToRuntimeType = | |
605 namer.elementAccess(compiler.findHelper('convertRtiToRuntimeType')); | |
606 builder.addProperty( | |
607 name, js.fun( | |
608 [], [js.return_(convertRtiToRuntimeType(computeTypeVariable))])); | |
609 } | |
566 } | 610 } |
OLD | NEW |