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

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

Issue 10574046: Remove static fields in the namer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 632
633 void emitStaticFunctionGetters(StringBuffer buffer) { 633 void emitStaticFunctionGetters(StringBuffer buffer) {
634 Set<FunctionElement> functionsNeedingGetter = 634 Set<FunctionElement> functionsNeedingGetter =
635 compiler.codegenWorld.staticFunctionsNeedingGetter; 635 compiler.codegenWorld.staticFunctionsNeedingGetter;
636 for (FunctionElement element in functionsNeedingGetter) { 636 for (FunctionElement element in functionsNeedingGetter) {
637 // The static function does not have the correct name. Since 637 // The static function does not have the correct name. Since
638 // [addParameterStubs] use the name to create its stubs we simply 638 // [addParameterStubs] use the name to create its stubs we simply
639 // create a fake element with the correct name. 639 // create a fake element with the correct name.
640 // Note: the callElement will not have any enclosingElement. 640 // Note: the callElement will not have any enclosingElement.
641 FunctionElement callElement = 641 FunctionElement callElement =
642 new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, element); 642 new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, element);
643 String staticName = namer.getName(element); 643 String staticName = namer.getName(element);
644 int parameterCount = element.parameterCount(compiler); 644 int parameterCount = element.parameterCount(compiler);
645 String invocationName = 645 String invocationName =
646 namer.instanceMethodName(element.getLibrary(), callElement.name, 646 namer.instanceMethodName(element.getLibrary(), callElement.name,
647 parameterCount); 647 parameterCount);
648 String fieldAccess = '$isolateProperties.$staticName'; 648 String fieldAccess = '$isolateProperties.$staticName';
649 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n"); 649 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n");
650 addParameterStubs(callElement, (String name, String value) { 650 addParameterStubs(callElement, (String name, String value) {
651 buffer.add('$fieldAccess.$name = $value;\n'); 651 buffer.add('$fieldAccess.$name = $value;\n');
652 }); 652 });
653 // If a static function is used as a closure we need to add its name 653 // If a static function is used as a closure we need to add its name
654 // in case it is used in spawnFunction. 654 // in case it is used in spawnFunction.
655 String fieldName = Namer.STATIC_CLOSURE_NAME_NAME; 655 String fieldName = namer.STATIC_CLOSURE_NAME_NAME;
656 buffer.add('$fieldAccess.$fieldName = "$staticName";\n'); 656 buffer.add('$fieldAccess.$fieldName = "$staticName";\n');
657 } 657 }
658 } 658 }
659 659
660 void emitDynamicFunctionGetter(FunctionElement member, 660 void emitDynamicFunctionGetter(FunctionElement member,
661 defineInstanceMember(String invocationName, 661 defineInstanceMember(String invocationName,
662 String definition)) { 662 String definition)) {
663 // For every method that has the same name as a property-get we create a 663 // For every method that has the same name as a property-get we create a
664 // getter that returns a bound closure. Say we have a class 'A' with method 664 // getter that returns a bound closure. Say we have a class 'A' with method
665 // 'foo' and somewhere in the code there is a dynamic property get of 665 // 'foo' and somewhere in the code there is a dynamic property get of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // Define the constructor with a name so that Object.toString can 699 // Define the constructor with a name so that Object.toString can
700 // find the class name of the closure class. 700 // find the class name of the closure class.
701 boundClosureBuffer.add("$defineClassName('$mangledName', '$superName', "); 701 boundClosureBuffer.add("$defineClassName('$mangledName', '$superName', ");
702 boundClosureBuffer.add("['self', 'target'], {\n"); 702 boundClosureBuffer.add("['self', 'target'], {\n");
703 703
704 // Now add the methods on the closure class. The instance method does not 704 // Now add the methods on the closure class. The instance method does not
705 // have the correct name. Since [addParameterStubs] use the name to create 705 // have the correct name. Since [addParameterStubs] use the name to create
706 // its stubs we simply create a fake element with the correct name. 706 // its stubs we simply create a fake element with the correct name.
707 // Note: the callElement will not have any enclosingElement. 707 // Note: the callElement will not have any enclosingElement.
708 FunctionElement callElement = 708 FunctionElement callElement =
709 new ClosureInvocationElement(Namer.CLOSURE_INVOCATION_NAME, member); 709 new ClosureInvocationElement(namer.CLOSURE_INVOCATION_NAME, member);
710 710
711 String invocationName = 711 String invocationName =
712 namer.instanceMethodName(member.getLibrary(), 712 namer.instanceMethodName(member.getLibrary(),
713 callElement.name, parameterCount); 713 callElement.name, parameterCount);
714 List<String> arguments = new List<String>(parameterCount); 714 List<String> arguments = new List<String>(parameterCount);
715 for (int i = 0; i < parameterCount; i++) { 715 for (int i = 0; i < parameterCount; i++) {
716 arguments[i] = "p$i"; 716 arguments[i] = "p$i";
717 } 717 }
718 String joinedArgs = Strings.join(arguments, ", "); 718 String joinedArgs = Strings.join(arguments, ", ");
719 boundClosureBuffer.add( 719 boundClosureBuffer.add(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 } else { 752 } else {
753 String name = namer.instanceFieldName(member.getEnclosingClass(), 753 String name = namer.instanceFieldName(member.getEnclosingClass(),
754 member.name); 754 member.name);
755 getter = "this.$name"; 755 getter = "this.$name";
756 } 756 }
757 for (Selector selector in selectors) { 757 for (Selector selector in selectors) {
758 if (selector.applies(member, compiler)) { 758 if (selector.applies(member, compiler)) {
759 String invocationName = 759 String invocationName =
760 namer.instanceMethodInvocationName(member.getLibrary(), member.name, 760 namer.instanceMethodInvocationName(member.getLibrary(), member.name,
761 selector); 761 selector);
762 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; 762 SourceString callName = namer.CLOSURE_INVOCATION_NAME;
763 String closureCallName = 763 String closureCallName =
764 namer.instanceMethodInvocationName(member.getLibrary(), callName, 764 namer.instanceMethodInvocationName(member.getLibrary(), callName,
765 selector); 765 selector);
766 List<String> arguments = <String>[]; 766 List<String> arguments = <String>[];
767 for (int i = 0; i < selector.argumentCount; i++) { 767 for (int i = 0; i < selector.argumentCount; i++) {
768 arguments.add("arg$i"); 768 arguments.add("arg$i");
769 } 769 }
770 String joined = Strings.join(arguments, ", "); 770 String joined = Strings.join(arguments, ", ");
771 defineInstanceMember( 771 defineInstanceMember(
772 invocationName, 772 invocationName,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 buffer.add(" ? this.$noSuchMethodName('$methodName', [$args])\n"); 863 buffer.add(" ? this.$noSuchMethodName('$methodName', [$args])\n");
864 buffer.add(" : $runtimeObjectPrototype.$noSuchMethodName.call("); 864 buffer.add(" : $runtimeObjectPrototype.$noSuchMethodName.call(");
865 buffer.add("this, '$methodName', [$args])\n"); 865 buffer.add("this, '$methodName', [$args])\n");
866 buffer.add('}'); 866 buffer.add('}');
867 return buffer.toString(); 867 return buffer.toString();
868 } 868 }
869 869
870 compiler.codegenWorld.invokedNames.forEach((SourceString methodName, 870 compiler.codegenWorld.invokedNames.forEach((SourceString methodName,
871 Set<Selector> selectors) { 871 Set<Selector> selectors) {
872 if (objectClass.lookupLocalMember(methodName) === null 872 if (objectClass.lookupLocalMember(methodName) === null
873 && methodName != Namer.OPERATOR_EQUALS) { 873 && methodName != Elements.OPERATOR_EQUALS) {
874 for (Selector selector in selectors) { 874 for (Selector selector in selectors) {
875 if (methodName.isPrivate()) { 875 if (methodName.isPrivate()) {
876 for (LibraryElement lib in libraries) { 876 for (LibraryElement lib in libraries) {
877 String jsName = 877 String jsName =
878 namer.instanceMethodInvocationName(lib, methodName, selector); 878 namer.instanceMethodInvocationName(lib, methodName, selector);
879 String method = 879 String method =
880 generateMethod(methodName.slowToString(), selector); 880 generateMethod(methodName.slowToString(), selector);
881 defineInstanceMember(jsName, method); 881 defineInstanceMember(jsName, method);
882 } 882 }
883 } else { 883 } else {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 mainBuffer.add('function init() {\n'); 1029 mainBuffer.add('function init() {\n');
1030 mainBuffer.add(' $isolateProperties = {};\n'); 1030 mainBuffer.add(' $isolateProperties = {};\n');
1031 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); 1031 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer);
1032 emitFinishIsolateConstructor(mainBuffer); 1032 emitFinishIsolateConstructor(mainBuffer);
1033 mainBuffer.add('}\n'); 1033 mainBuffer.add('}\n');
1034 compiler.assembledCode = mainBuffer.toString(); 1034 compiler.assembledCode = mainBuffer.toString();
1035 }); 1035 });
1036 return compiler.assembledCode; 1036 return compiler.assembledCode;
1037 } 1037 }
1038 } 1038 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698