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

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

Issue 9873012: Move member-iterating code into ClassElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 8 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 #library('elements'); 5 #library('elements');
6 6
7 #import('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 /** 772 /**
773 * Returns the super class, if any. 773 * Returns the super class, if any.
774 * 774 *
775 * The returned element may not be resolved yet. 775 * The returned element may not be resolved yet.
776 */ 776 */
777 ClassElement get superclass() { 777 ClassElement get superclass() {
778 assert(isResolved); 778 assert(isResolved);
779 return supertype === null ? null : supertype.element; 779 return supertype === null ? null : supertype.element;
780 } 780 }
781 781
782 /**
783 * Runs through all members of this class.
784 *
785 * The enclosing class is passed to the callback. This is useful when
786 * [includeSuperMembers] is [:true:].
787 */
788 void forEachMember([void f(ClassElement enclosingClass, Element member),
ahe 2012/04/19 10:02:31 Why is f optional?
floitsch 2012/04/19 10:41:32 So that you can give it a name and put it last. It
ahe 2012/04/19 10:43:58 I see.
789 includeBackendMembers = false,
790 includeSuperMembers = false]) {
791 ClassElement classElement = this;
792 do {
793 for (Element element in classElement.members) {
794 f(classElement, element);
795 }
796 if (includeBackendMembers) {
797 for (Element element in classElement.backendMembers) {
798 f(classElement, element);
799 }
800 }
801 classElement = includeSuperMembers ? classElement.superclass : null;
802 } while(classElement !== null);
803 }
804
805 /**
806 * Runs through all instance-field members of this class.
807 *
808 * The enclosing class is passed to the callback. This is useful when
809 * [includeSuperMembers] is [:true:].
810 *
811 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:]
812 * then the fields are visited in the same order as they need to be given
813 * to the JavaScript constructor.
814 */
815 void forEachInstanceField([void f(ClassElement enclosingClass, Element field),
ahe 2012/04/19 10:02:31 Ditto.
816 includeBackendMembers = false,
817 includeSuperMembers = false]) {
818 // Filters so that [f] is only invoked with instance fields.
819 void fieldFilter(ClassElement enclosingClass, Element member) {
820 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) {
821 f(enclosingClass, member);
822 }
823 }
824
825 forEachMember(fieldFilter, includeBackendMembers, includeSuperMembers);
826 }
827
782 bool isInterface() => false; 828 bool isInterface() => false;
783 bool isNative() => nativeName != null; 829 bool isNative() => nativeName != null;
784 SourceString nativeName; 830 SourceString nativeName;
785 } 831 }
786 832
787 class Elements { 833 class Elements {
788 static bool isLocal(Element element) { 834 static bool isLocal(Element element) {
789 return ((element !== null) 835 return ((element !== null)
790 && !element.isInstanceMember() 836 && !element.isInstanceMember()
791 && !isStaticOrTopLevelField(element) 837 && !isStaticOrTopLevelField(element)
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 final Node node; 1006 final Node node;
961 Type bound; 1007 Type bound;
962 Type type; 1008 Type type;
963 TypeVariableElement(name, Element enclosing, this.node, this.type, 1009 TypeVariableElement(name, Element enclosing, this.node, this.type,
964 [this.bound]) 1010 [this.bound])
965 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1011 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
966 Type computeType(compiler) => type; 1012 Type computeType(compiler) => type;
967 Node parseNode(compiler) => node; 1013 Node parseNode(compiler) => node;
968 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1014 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
969 } 1015 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698