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 24 matching lines...) Expand all Loading... | |
35 } | 35 } |
36 | 36 |
37 ClassBuilder builder = new ClassBuilder(); | 37 ClassBuilder builder = new ClassBuilder(); |
38 emitClassConstructor(classElement, builder, runtimeName, | 38 emitClassConstructor(classElement, builder, runtimeName, |
39 onlyForRti: onlyForRti); | 39 onlyForRti: onlyForRti); |
40 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); | 40 emitFields(classElement, builder, superName, onlyForRti: onlyForRti); |
41 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); | 41 emitClassGettersSetters(classElement, builder, onlyForRti: onlyForRti); |
42 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); | 42 emitInstanceMembers(classElement, builder, onlyForRti: onlyForRti); |
43 task.typeTestEmitter.emitIsTests(classElement, builder); | 43 task.typeTestEmitter.emitIsTests(classElement, builder); |
44 | 44 |
45 emitTypeVariableReaders(classElement, builder); | |
46 | |
45 emitClassBuilderWithReflectionData( | 47 emitClassBuilderWithReflectionData( |
46 className, classElement, builder, buffer); | 48 className, classElement, builder, buffer); |
47 } | 49 } |
48 | 50 |
49 void emitClassConstructor(ClassElement classElement, | 51 void emitClassConstructor(ClassElement classElement, |
50 ClassBuilder builder, | 52 ClassBuilder builder, |
51 String runtimeName, | 53 String runtimeName, |
52 {bool onlyForRti: false}) { | 54 {bool onlyForRti: false}) { |
53 List<String> fields = <String>[]; | 55 List<String> fields = <String>[]; |
54 if (!onlyForRti && !classElement.isNative()) { | 56 if (!onlyForRti && !classElement.isNative()) { |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 Selector selector = isGetter | 596 Selector selector = isGetter |
595 ? new Selector.getter(member.name, member.getLibrary()) | 597 ? new Selector.getter(member.name, member.getLibrary()) |
596 : new Selector.setter(member.name, member.getLibrary()); | 598 : new Selector.setter(member.name, member.getLibrary()); |
597 String reflectionName = task.getReflectionName(selector, name); | 599 String reflectionName = task.getReflectionName(selector, name); |
598 if (reflectionName != null) { | 600 if (reflectionName != null) { |
599 var reflectable = | 601 var reflectable = |
600 js(backend.isAccessibleByReflection(member) ? '1' : '0'); | 602 js(backend.isAccessibleByReflection(member) ? '1' : '0'); |
601 builder.addProperty('+$reflectionName', reflectable); | 603 builder.addProperty('+$reflectionName', reflectable); |
602 } | 604 } |
603 } | 605 } |
606 | |
607 void emitTypeVariableReaders(ClassElement cls, ClassBuilder builder) { | |
608 List typeVariables = []; | |
609 ClassElement superclass = cls; | |
610 while (superclass != null) { | |
611 GenericType type = superclass.thisType; | |
612 for (TypeVariableType parameter in type.typeArguments) { | |
613 if (task.readTypeVariables.contains(parameter.element)) { | |
614 emitTypeVariableReader(cls, builder, parameter.element); | |
615 } | |
616 } | |
617 superclass = superclass.superclass; | |
Johnni Winther
2013/10/30 11:40:23
The superclass chain is not properly substuted. Fo
Johnni Winther
2013/10/30 12:02:19
Actually you will visit C<U>, B<S>, A<T> if [cls]
ahe
2013/10/30 12:04:05
I don't think that is enough.
Consider this situa
| |
618 } | |
619 } | |
620 | |
621 void emitTypeVariableReader(ClassElement cls, | |
622 ClassBuilder builder, | |
623 TypeVariableElement element) { | |
624 String name = namer.readTypeVariableName(element); | |
625 List<jsAst.Node> body; | |
626 if (cls != element.enclosingElement) { | |
627 body = <jsAst.Node>[ | |
628 new jsAst.Throw(js.string('Cannot read type variable ${element}'))]; | |
ahe
2013/10/29 22:42:49
This is the only thing that causes tests to fail,
Johnni Winther
2013/10/30 11:40:23
The change above should solve this.
| |
629 } else { | |
630 body = <jsAst.Node>[ | |
631 js.return_( | |
632 namer.elementAccess( | |
633 compiler.findHelper('convertRtiToRuntimeType'))( | |
634 js(r'this.$builtinTypeInfo[#]', | |
635 js.toExpression( | |
636 RuntimeTypes.getTypeVariableIndex(element)))))]; | |
637 } | |
638 builder.addProperty(name, js.fun([], body)); | |
639 } | |
604 } | 640 } |
OLD | NEW |