Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart

Issue 50313007: Implement dynamic function checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r30897. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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;
ngeoffray 2013/12/09 09:48:52 superclass -> currentClass ? I find it confusing t
ahe 2013/12/09 15:30:06 Done.
572 while (superclass != null) {
573 for (TypeVariableType parameter in superclass.typeVariables) {
574 if (task.readTypeVariables.contains(parameter.element)) {
575 emitTypeVariableReader(cls, builder, parameter.element);
576 }
577 }
578 superclass = superclass.superclass;
579 }
580 }
581
582 void emitTypeVariableReader(ClassElement cls,
583 ClassBuilder builder,
584 TypeVariableElement element) {
585 String name = namer.readTypeVariableName(element);
586 jsAst.Expression index =
587 js.toExpression(RuntimeTypes.getTypeVariableIndex(element));
588 jsAst.Expression computeTypeVariable;
589
590 Substitution substitution =
591 backend.rti.computeSubstitution(
592 cls, element.enclosingElement, alwaysGenerateFunction: true);
593 if (substitution != null) {
594 jsAst.Expression typeArguments =
595 substitution.getCode(backend.rti, true)['apply'](
596 ['null', r'this.$builtinTypeInfo']);
597 computeTypeVariable = typeArguments[index];
598 } else {
599 // TODO(ahe): These can be generated dynamically.
600 computeTypeVariable =
601 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]', index);
602 }
603 jsAst.Expression convertRtiToRuntimeType =
604 namer.elementAccess(compiler.findHelper('convertRtiToRuntimeType'));
605 builder.addProperty(
606 name, js.fun(
607 [], [js.return_(convertRtiToRuntimeType(computeTypeVariable))]));
608 }
566 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698