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

Side by Side Diff: lib/compiler/implementation/js_backend/emitter.dart

Issue 10854158: Make selector registration in the resolver and code generator more explicit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge from master. Created 8 years, 4 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 678
679 void emitStaticFunctionGetters(CodeBuffer buffer) { 679 void emitStaticFunctionGetters(CodeBuffer buffer) {
680 Set<FunctionElement> functionsNeedingGetter = 680 Set<FunctionElement> functionsNeedingGetter =
681 compiler.codegenWorld.staticFunctionsNeedingGetter; 681 compiler.codegenWorld.staticFunctionsNeedingGetter;
682 for (FunctionElement element in functionsNeedingGetter) { 682 for (FunctionElement element in functionsNeedingGetter) {
683 // The static function does not have the correct name. Since 683 // The static function does not have the correct name. Since
684 // [addParameterStubs] use the name to create its stubs we simply 684 // [addParameterStubs] use the name to create its stubs we simply
685 // create a fake element with the correct name. 685 // create a fake element with the correct name.
686 // Note: the callElement will not have any enclosingElement. 686 // Note: the callElement will not have any enclosingElement.
687 FunctionElement callElement = 687 FunctionElement callElement =
688 new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, element); 688 new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, element);
689 String staticName = namer.getName(element); 689 String staticName = namer.getName(element);
690 int parameterCount = element.parameterCount(compiler); 690 int parameterCount = element.parameterCount(compiler);
691 String invocationName = 691 String invocationName =
692 namer.instanceMethodName(element.getLibrary(), callElement.name, 692 namer.instanceMethodName(element.getLibrary(), callElement.name,
693 parameterCount); 693 parameterCount);
694 String fieldAccess = '$isolateProperties.$staticName'; 694 String fieldAccess = '$isolateProperties.$staticName';
695 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n"); 695 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n");
696 addParameterStubs(callElement, (String name, CodeBuffer value) { 696 addParameterStubs(callElement, (String name, CodeBuffer value) {
697 buffer.add('$fieldAccess.$name = $value;\n'); 697 buffer.add('$fieldAccess.$name = $value;\n');
698 }); 698 });
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 boundClosureBuffer.add(""" 746 boundClosureBuffer.add("""
747 $classesCollector.$mangledName = {'': 747 $classesCollector.$mangledName = {'':
748 ['self', 'target'], 748 ['self', 'target'],
749 'super': '$superName', 749 'super': '$superName',
750 """); 750 """);
751 // Now add the methods on the closure class. The instance method does not 751 // Now add the methods on the closure class. The instance method does not
752 // have the correct name. Since [addParameterStubs] use the name to create 752 // have the correct name. Since [addParameterStubs] use the name to create
753 // its stubs we simply create a fake element with the correct name. 753 // its stubs we simply create a fake element with the correct name.
754 // Note: the callElement will not have any enclosingElement. 754 // Note: the callElement will not have any enclosingElement.
755 FunctionElement callElement = 755 FunctionElement callElement =
756 new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, member); 756 new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, member);
757 757
758 String invocationName = 758 String invocationName =
759 namer.instanceMethodName(member.getLibrary(), 759 namer.instanceMethodName(member.getLibrary(),
760 callElement.name, parameterCount); 760 callElement.name, parameterCount);
761 List<String> arguments = new List<String>(parameterCount); 761 List<String> arguments = new List<String>(parameterCount);
762 for (int i = 0; i < parameterCount; i++) { 762 for (int i = 0; i < parameterCount; i++) {
763 arguments[i] = "p$i"; 763 arguments[i] = "p$i";
764 } 764 }
765 String joinedArgs = Strings.join(arguments, ", "); 765 String joinedArgs = Strings.join(arguments, ", ");
766 boundClosureBuffer.add( 766 boundClosureBuffer.add(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 798 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()";
799 } else { 799 } else {
800 String name = namer.instanceFieldName(member.getLibrary(), member.name); 800 String name = namer.instanceFieldName(member.getLibrary(), member.name);
801 getter = "this.$name"; 801 getter = "this.$name";
802 } 802 }
803 for (Selector selector in selectors) { 803 for (Selector selector in selectors) {
804 if (selector.applies(member, compiler)) { 804 if (selector.applies(member, compiler)) {
805 String invocationName = 805 String invocationName =
806 namer.instanceMethodInvocationName(member.getLibrary(), member.name, 806 namer.instanceMethodInvocationName(member.getLibrary(), member.name,
807 selector); 807 selector);
808 SourceString callName = namer.CLOSURE_INVOCATION_NAME; 808 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
809 String closureCallName = 809 String closureCallName =
810 namer.instanceMethodInvocationName(member.getLibrary(), callName, 810 namer.instanceMethodInvocationName(member.getLibrary(), callName,
811 selector); 811 selector);
812 List<String> arguments = <String>[]; 812 List<String> arguments = <String>[];
813 for (int i = 0; i < selector.argumentCount; i++) { 813 for (int i = 0; i < selector.argumentCount; i++) {
814 arguments.add("arg$i"); 814 arguments.add("arg$i");
815 } 815 }
816 String joined = Strings.join(arguments, ", "); 816 String joined = Strings.join(arguments, ", ");
817 CodeBuffer getterBuffer = new CodeBuffer(); 817 CodeBuffer getterBuffer = new CodeBuffer();
818 getterBuffer.add( 818 getterBuffer.add(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 // 1010 //
1011 // If we're calling bar on an object of type A we do need the 1011 // If we're calling bar on an object of type A we do need the
1012 // handler because we may have to call B.noSuchMethod since B 1012 // handler because we may have to call B.noSuchMethod since B
1013 // does not implement bar. 1013 // does not implement bar.
1014 Set<ClassElement> holders = noSuchMethodHoldersFor(receiverType); 1014 Set<ClassElement> holders = noSuchMethodHoldersFor(receiverType);
1015 if (holders.every(hasMatchingMember)) continue; 1015 if (holders.every(hasMatchingMember)) continue;
1016 1016
1017 for (LibraryElement lib in libraries) { 1017 for (LibraryElement lib in libraries) {
1018 String jsName = null; 1018 String jsName = null;
1019 String methodName = null; 1019 String methodName = null;
1020 if (selector.kind === SelectorKind.GETTER) { 1020 if (selector.isGetter()) {
1021 jsName = namer.getterName(lib, name); 1021 jsName = namer.getterName(lib, name);
1022 methodName = 'get:$nameString'; 1022 methodName = 'get:$nameString';
1023 } else if (selector.kind === SelectorKind.SETTER) { 1023 } else if (selector.isSetter()) {
1024 jsName = namer.setterName(lib, name); 1024 jsName = namer.setterName(lib, name);
1025 methodName = 'set:$nameString'; 1025 methodName = 'set:$nameString';
1026 } else if (selector.kind === SelectorKind.INVOCATION) { 1026 } else if (selector.isCall()) {
1027 jsName = namer.instanceMethodInvocationName(lib, name, selector); 1027 jsName = namer.instanceMethodInvocationName(lib, name, selector);
1028 methodName = nameString; 1028 methodName = nameString;
1029 } else { 1029 } else {
1030 // We simply ignore selectors that do not need 1030 // We simply ignore selectors that do not need
1031 // noSuchMethod handlers. 1031 // noSuchMethod handlers.
1032 continue; 1032 continue;
1033 } 1033 }
1034 if (!addedJsNames.contains(jsName)) { 1034 if (!addedJsNames.contains(jsName)) {
1035 CodeBuffer jsCode = generateMethod(methodName, selector); 1035 CodeBuffer jsCode = generateMethod(methodName, selector);
1036 defineInstanceMember(jsName, jsCode); 1036 defineInstanceMember(jsName, jsCode);
(...skipping 10 matching lines...) Expand all
1047 1047
1048 String buildIsolateSetup(CodeBuffer buffer, 1048 String buildIsolateSetup(CodeBuffer buffer,
1049 Element appMain, 1049 Element appMain,
1050 Element isolateMain) { 1050 Element isolateMain) {
1051 String mainAccess = "${namer.isolateAccess(appMain)}"; 1051 String mainAccess = "${namer.isolateAccess(appMain)}";
1052 String currentIsolate = "${namer.CURRENT_ISOLATE}"; 1052 String currentIsolate = "${namer.CURRENT_ISOLATE}";
1053 String mainEnsureGetter = ''; 1053 String mainEnsureGetter = '';
1054 // Since we pass the closurized version of the main method to 1054 // Since we pass the closurized version of the main method to
1055 // the isolate method, we must make sure that it exists. 1055 // the isolate method, we must make sure that it exists.
1056 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) { 1056 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) {
1057 Selector selector = new Selector.callAny(0); 1057 Selector selector = new Selector.callClosure(0);
1058 String invocationName = "${namer.closureInvocationName(selector)}"; 1058 String invocationName = "${namer.closureInvocationName(selector)}";
1059 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess"; 1059 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess";
1060 } 1060 }
1061 1061
1062 // TODO(ngeoffray): These globals are currently required by the isolate 1062 // TODO(ngeoffray): These globals are currently required by the isolate
1063 // library, but since leg already generates code on an Isolate object, they 1063 // library, but since leg already generates code on an Isolate object, they
1064 // are not really needed. We should remove them once Leg replaces Frog. 1064 // are not really needed. We should remove them once Leg replaces Frog.
1065 buffer.add(""" 1065 buffer.add("""
1066 var \$globalThis = $currentIsolate; 1066 var \$globalThis = $currentIsolate;
1067 var \$globalState; 1067 var \$globalState;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 sourceName = token.slowToString(); 1175 sourceName = token.slowToString();
1176 } 1176 }
1177 int totalOffset = bufferOffset + offset; 1177 int totalOffset = bufferOffset + offset;
1178 sourceMapBuilder.addMapping( 1178 sourceMapBuilder.addMapping(
1179 sourceFile, token.charOffset, sourceName, totalOffset); 1179 sourceFile, token.charOffset, sourceName, totalOffset);
1180 }); 1180 });
1181 } 1181 }
1182 } 1182 }
1183 1183
1184 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); 1184 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698