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

Side by Side Diff: frog/leg/ssa/builder.dart

Issue 9166010: Implement super calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 11 months 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 compiler.registerInstantiatedClass(globalizedClosureElement); 544 compiler.registerInstantiatedClass(globalizedClosureElement);
545 push(new HForeignNew(globalizedClosureElement, <HInstruction>[])); 545 push(new HForeignNew(globalizedClosureElement, <HInstruction>[]));
546 } 546 }
547 547
548 visitIdentifier(Identifier node) { 548 visitIdentifier(Identifier node) {
549 if (node.isThis()) { 549 if (node.isThis()) {
550 if (thisDefinition === null) { 550 if (thisDefinition === null) {
551 compiler.unimplemented("Ssa.visitIdentifier.", node: node); 551 compiler.unimplemented("Ssa.visitIdentifier.", node: node);
552 } 552 }
553 stack.add(thisDefinition); 553 stack.add(thisDefinition);
554 } else if (node.isSuper()) {
555 // super should not be visited as an identifier.
556 compiler.internalError("unexpected identifier: super", node: node);
554 } else { 557 } else {
555 Element element = elements[node]; 558 Element element = elements[node];
556 compiler.ensure(element !== null); 559 compiler.ensure(element !== null);
557 HInstruction def = definitions[element]; 560 HInstruction def = definitions[element];
558 if (def === null) { 561 if (def === null) {
559 compiler.unimplemented("Ssa.visitIdentifier.", node: node); 562 compiler.unimplemented("Ssa.visitIdentifier.", node: node);
560 } 563 }
561 stack.add(def); 564 stack.add(def);
562 } 565 }
563 } 566 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 797 }
795 798
796 void generateGetter(Send send, Element element) { 799 void generateGetter(Send send, Element element) {
797 if (Elements.isStaticOrTopLevelField(element)) { 800 if (Elements.isStaticOrTopLevelField(element)) {
798 push(new HStatic(element)); 801 push(new HStatic(element));
799 } else if (element === null || Elements.isInstanceField(element)) { 802 } else if (element === null || Elements.isInstanceField(element)) {
800 HInstruction receiver; 803 HInstruction receiver;
801 if (send.receiver == null) { 804 if (send.receiver == null) {
802 receiver = thisDefinition; 805 receiver = thisDefinition;
803 if (receiver === null) { 806 if (receiver === null) {
804 compiler.unimplemented("Ssa.generateGetter.", node: node); 807 compiler.unimplemented("Ssa.generateGetter.", node: send);
805 } 808 }
806 } else { 809 } else {
807 visit(send.receiver); 810 visit(send.receiver);
808 receiver = pop(); 811 receiver = pop();
809 } 812 }
810 SourceString getterName = send.selector.asIdentifier().source; 813 SourceString getterName = send.selector.asIdentifier().source;
811 Element staticInterceptor = null; 814 Element staticInterceptor = null;
812 if (methodInterceptionEnabled) { 815 if (methodInterceptionEnabled) {
813 staticInterceptor = interceptors.getStaticGetInterceptor(getterName); 816 staticInterceptor = interceptors.getStaticGetInterceptor(getterName);
814 } 817 }
(...skipping 17 matching lines...) Expand all
832 } 835 }
833 836
834 void generateSetter(SendSet send, Element element, HInstruction value) { 837 void generateSetter(SendSet send, Element element, HInstruction value) {
835 if (Elements.isStaticOrTopLevelField(element)) { 838 if (Elements.isStaticOrTopLevelField(element)) {
836 add(new HStaticStore(element, value)); 839 add(new HStaticStore(element, value));
837 stack.add(value); 840 stack.add(value);
838 } else if (Elements.isInstanceField(element)) { 841 } else if (Elements.isInstanceField(element)) {
839 String methodName = compiler.namer.setterName(element.name); 842 String methodName = compiler.namer.setterName(element.name);
840 HInstruction receiver = thisDefinition; 843 HInstruction receiver = thisDefinition;
841 if (receiver === null) { 844 if (receiver === null) {
842 compiler.unimplemented("Ssa.generateSetter.", node: node); 845 compiler.unimplemented("Ssa.generateSetter.", node: send);
843 } 846 }
844 add(new HInvokeDynamicSetter(element, methodName, receiver, value)); 847 add(new HInvokeDynamicSetter(element, methodName, receiver, value));
845 stack.add(value); 848 stack.add(value);
846 } else if (element === null) { 849 } else if (element === null) {
847 SourceString dartSetterName = send.selector.asIdentifier().source; 850 SourceString dartSetterName = send.selector.asIdentifier().source;
848 String jsSetterName = compiler.namer.setterName(dartSetterName); 851 String jsSetterName = compiler.namer.setterName(dartSetterName);
849 HInstruction receiver; 852 HInstruction receiver;
850 if (send.receiver == null) { 853 if (send.receiver == null) {
851 receiver = thisDefinition; 854 receiver = thisDefinition;
852 if (receiver === null) { 855 if (receiver === null) {
853 compiler.unimplemented("Ssa.generateSetter.", node: node); 856 compiler.unimplemented("Ssa.generateSetter.", node: send);
854 } 857 }
855 } else { 858 } else {
856 visit(send.receiver); 859 visit(send.receiver);
857 receiver = pop(); 860 receiver = pop();
858 } 861 }
859 add(new HInvokeDynamicSetter(null, jsSetterName, receiver, value)); 862 add(new HInvokeDynamicSetter(null, jsSetterName, receiver, value));
860 stack.add(value); 863 stack.add(value);
861 } else { 864 } else {
862 stack.add(updateDefinition(send, value)); 865 stack.add(updateDefinition(send, value));
863 } 866 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 assert(closureTarget !== null); 953 assert(closureTarget !== null);
951 } 954 }
952 var inputs = <HInstruction>[]; 955 var inputs = <HInstruction>[];
953 inputs.add(closureTarget); 956 inputs.add(closureTarget);
954 addVisitedSendArgumentsToList(node.arguments, inputs); 957 addVisitedSendArgumentsToList(node.arguments, inputs);
955 String jsMethodName = compiler.namer.closureInvocationName(); 958 String jsMethodName = compiler.namer.closureInvocationName();
956 push(new HInvokeDynamicMethod(jsMethodName, inputs)); 959 push(new HInvokeDynamicMethod(jsMethodName, inputs));
957 } 960 }
958 961
959 visitForeignSend(Send node) { 962 visitForeignSend(Send node) {
960 switch (node.selector.source.stringValue) { 963 switch (node.selector.asIdentifier().source.stringValue) {
961 case "JS": 964 case "JS":
962 Link<Node> link = node.arguments; 965 Link<Node> link = node.arguments;
963 // If the invoke is on foreign code, don't visit the first 966 // If the invoke is on foreign code, don't visit the first
964 // argument, which is the type, and the second argument, 967 // argument, which is the type, and the second argument,
965 // which is the foreign code. 968 // which is the foreign code.
966 link = link.tail.tail; 969 link = link.tail.tail;
967 var inputs = <HInstruction>[]; 970 var inputs = <HInstruction>[];
968 addVisitedSendArgumentsToList(link, inputs); 971 addVisitedSendArgumentsToList(link, inputs);
969 LiteralString type = node.arguments.head; 972 LiteralString type = node.arguments.head;
970 LiteralString literal = node.arguments.tail.head; 973 LiteralString literal = node.arguments.tail.head;
(...skipping 10 matching lines...) Expand all
981 Expression expression = link.head; 984 Expression expression = link.head;
982 disableMethodInterception(); 985 disableMethodInterception();
983 visit(expression); 986 visit(expression);
984 enableMethodInterception(); 987 enableMethodInterception();
985 break; 988 break;
986 default: 989 default:
987 throw "Unknown foreign: ${node.selector}"; 990 throw "Unknown foreign: ${node.selector}";
988 } 991 }
989 } 992 }
990 993
994 visitSuperSend(Send node) {
995 Element element = elements[node];
996 HStatic target = new HStatic(element);
997 HThis context = thisDefinition;
998 if (context === null) {
999 compiler.unimplemented("Ssa.visitSuperSend without thisDefinition.",
1000 node: node);
1001 }
1002 add(target);
1003 var inputs = <HInstruction>[target, context];
1004 addVisitedSendArgumentsToList(node.arguments, inputs);
1005 push(new HInvokeSuper(inputs));
1006 }
1007
991 visitStaticSend(Send node) { 1008 visitStaticSend(Send node) {
992 Element element = elements[node]; 1009 Element element = elements[node];
993 HStatic target = new HStatic(element); 1010 HStatic target = new HStatic(element);
994 add(target); 1011 add(target);
995 var inputs = <HInstruction>[]; 1012 var inputs = <HInstruction>[];
996 inputs.add(target); 1013 inputs.add(target);
997 addVisitedSendArgumentsToList(node.arguments, inputs); 1014 addVisitedSendArgumentsToList(node.arguments, inputs);
998 push(new HInvokeStatic(inputs)); 1015 push(new HInvokeStatic(inputs));
999 } 1016 }
1000 1017
1001 visitSend(Send node) { 1018 visitSend(Send node) {
1002 if (node.selector is Operator) { 1019 if (node.selector is Operator) {
1003 visitOperatorSend(node); 1020 visitOperatorSend(node);
1004 } else if (node.isPropertyAccess) { 1021 } else if (node.isPropertyAccess) {
1005 generateGetter(node, elements[node]); 1022 generateGetter(node, elements[node]);
1006 } else if (Elements.isClosureSend(node, elements)) { 1023 } else if (Elements.isClosureSend(node, elements)) {
1007 visitClosureSend(node); 1024 visitClosureSend(node);
1025 } else if (node.receiver !== null &&
1026 node.receiver.asIdentifier() !== null &&
1027 node.receiver.asIdentifier().isSuper()) {
ngeoffray 2012/01/11 13:00:48 I think we can add a Send.isSuperCall to the Send
karlklose 2012/01/11 13:46:12 Done.
1028 visitSuperSend(node);
1008 } else { 1029 } else {
1009 Element element = elements[node]; 1030 Element element = elements[node];
1010 if (element === null) { 1031 if (element === null) {
1011 // Example: f() with 'f' unbound. 1032 // Example: f() with 'f' unbound.
1012 // This can only happen inside an instance method. 1033 // This can only happen inside an instance method.
1013 visitDynamicSend(node); 1034 visitDynamicSend(node);
1014 } else if (element.isInstanceMember()) { 1035 } else if (element.isInstanceMember()) {
1015 // Example: f() with 'f' bound to instance method. 1036 // Example: f() with 'f' bound to instance method.
1016 visitDynamicSend(node); 1037 visitDynamicSend(node);
1017 } else if (element.kind === ElementKind.FOREIGN) { 1038 } else if (element.kind === ElementKind.FOREIGN) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 } 1343 }
1323 1344
1324 visitCatchBlock(CatchBlock node) { 1345 visitCatchBlock(CatchBlock node) {
1325 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node); 1346 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node);
1326 } 1347 }
1327 1348
1328 visitTypedef(Typedef node) { 1349 visitTypedef(Typedef node) {
1329 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1350 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1330 } 1351 }
1331 } 1352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698