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

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

Issue 10542073: RFC: Resolution based tree-shaking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor tweaks for the unit tests 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 #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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bool isMember() => 116 bool isMember() =>
117 enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS; 117 enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS;
118 bool isInstanceMember() => false; 118 bool isInstanceMember() => false;
119 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory(); 119 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory();
120 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; 120 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR;
121 bool isCompilationUnit() { 121 bool isCompilationUnit() {
122 return kind === ElementKind.COMPILATION_UNIT || 122 return kind === ElementKind.COMPILATION_UNIT ||
123 kind === ElementKind.LIBRARY; 123 kind === ElementKind.LIBRARY;
124 } 124 }
125 bool isClass() => kind === ElementKind.CLASS; 125 bool isClass() => kind === ElementKind.CLASS;
126 bool isPrefix() => kind === ElementKind.PREFIX;
126 bool isVariable() => kind === ElementKind.VARIABLE; 127 bool isVariable() => kind === ElementKind.VARIABLE;
127 bool isParameter() => kind === ElementKind.PARAMETER; 128 bool isParameter() => kind === ElementKind.PARAMETER;
128 bool isStatement() => kind === ElementKind.STATEMENT; 129 bool isStatement() => kind === ElementKind.STATEMENT;
129 bool isTypedef() => kind === ElementKind.TYPEDEF; 130 bool isTypedef() => kind === ElementKind.TYPEDEF;
130 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE; 131 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE;
131 bool isField() => kind === ElementKind.FIELD; 132 bool isField() => kind === ElementKind.FIELD;
132 bool isGetter() => kind === ElementKind.GETTER; 133 bool isGetter() => kind === ElementKind.GETTER;
133 bool isSetter() => kind === ElementKind.SETTER; 134 bool isSetter() => kind === ElementKind.SETTER;
135 bool isAccessor() => isGetter() || isSetter();
136 bool isForeign() => kind === ElementKind.FOREIGN;
134 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; 137 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
135 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; 138 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
136 139
140 bool isTopLevel() => enclosingElement.isCompilationUnit();
141
137 bool isAssignable() { 142 bool isAssignable() {
138 if (modifiers != null && modifiers.isFinal()) return false; 143 if (modifiers != null && modifiers.isFinal()) return false;
139 if (isFunction() || isGenerativeConstructor()) return false; 144 if (isFunction() || isGenerativeConstructor()) return false;
140 return true; 145 return true;
141 } 146 }
142 147
143 Token position() => null; 148 Token position() => null;
144 149
145 Token findMyName(Token token) { 150 Token findMyName(Token token) {
146 for (Token t = token; t.kind !== EOF_TOKEN; t = t.next) { 151 for (Token t = token; t.kind !== EOF_TOKEN; t = t.next) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return null; 186 return null;
182 } 187 }
183 188
184 Element getEnclosingMember() { 189 Element getEnclosingMember() {
185 for (Element e = this; e !== null; e = e.enclosingElement) { 190 for (Element e = this; e !== null; e = e.enclosingElement) {
186 if (e.isMember()) return e; 191 if (e.isMember()) return e;
187 } 192 }
188 return null; 193 return null;
189 } 194 }
190 195
191 toString() => '$kind(${name.slowToString()})'; 196 Element getOutermostEnclosingMemberOrTopLevel() {
197 for (Element e = this; e !== null; e = e.enclosingElement) {
198 if (e.isMember() || e.isTopLevel()) {
199 return e;
200 }
201 }
202 return null;
203 }
204
205 toString() {
206 if (!isTopLevel()) {
207 String holderName = enclosingElement.name.slowToString();
208 return '$kind($holderName#${name.slowToString()})';
209 } else {
210 return '$kind(${name.slowToString()})';
211 }
212 }
192 213
193 bool _isNative = false; 214 bool _isNative = false;
194 void setNative() { _isNative = true; } 215 void setNative() { _isNative = true; }
195 bool isNative() => _isNative; 216 bool isNative() => _isNative;
196 } 217 }
197 218
198 class ContainerElement extends Element { 219 class ContainerElement extends Element {
199 ContainerElement(name, kind, enclosingElement) : 220 ContainerElement(name, kind, enclosingElement) :
200 super(name, kind, enclosingElement); 221 super(name, kind, enclosingElement);
201 222
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 806
786 /** 807 /**
787 * Runs through all members of this class. 808 * Runs through all members of this class.
788 * 809 *
789 * The enclosing class is passed to the callback. This is useful when 810 * The enclosing class is passed to the callback. This is useful when
790 * [includeSuperMembers] is [:true:]. 811 * [includeSuperMembers] is [:true:].
791 */ 812 */
792 void forEachMember([void f(ClassElement enclosingClass, Element member), 813 void forEachMember([void f(ClassElement enclosingClass, Element member),
793 includeBackendMembers = false, 814 includeBackendMembers = false,
794 includeSuperMembers = false]) { 815 includeSuperMembers = false]) {
816 Set<ClassElement> seen = new Set<ClassElement>();
795 ClassElement classElement = this; 817 ClassElement classElement = this;
796 do { 818 do {
819 if (seen.contains(classElement)) return;
820 seen.add(classElement);
797 for (Element element in classElement.members) { 821 for (Element element in classElement.members) {
798 f(classElement, element); 822 f(classElement, element);
799 } 823 }
800 if (includeBackendMembers) { 824 if (includeBackendMembers) {
801 for (Element element in classElement.backendMembers) { 825 for (Element element in classElement.backendMembers) {
802 f(classElement, element); 826 f(classElement, element);
803 } 827 }
804 } 828 }
805 classElement = includeSuperMembers ? classElement.superclass : null; 829 classElement = includeSuperMembers ? classElement.superclass : null;
806 } while(classElement !== null); 830 } while(classElement !== null);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 final Node node; 1059 final Node node;
1036 Type bound; 1060 Type bound;
1037 Type type; 1061 Type type;
1038 TypeVariableElement(name, Element enclosing, this.node, this.type, 1062 TypeVariableElement(name, Element enclosing, this.node, this.type,
1039 [this.bound]) 1063 [this.bound])
1040 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1064 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1041 Type computeType(compiler) => type; 1065 Type computeType(compiler) => type;
1042 Node parseNode(compiler) => node; 1066 Node parseNode(compiler) => node;
1043 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1067 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1044 } 1068 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698