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

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

Issue 10834243: Reduce usage of .enclosingElement to get enclosing class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 #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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 Type computeType(Compiler compiler) { 112 Type computeType(Compiler compiler) {
113 compiler.internalError("$this.computeType.", token: position()); 113 compiler.internalError("$this.computeType.", token: position());
114 } 114 }
115 115
116 void addMetadata(Node node) { 116 void addMetadata(Node node) {
117 metadata = metadata.prepend(node); 117 metadata = metadata.prepend(node);
118 } 118 }
119 119
120 bool isFunction() => kind === ElementKind.FUNCTION; 120 bool isFunction() => kind === ElementKind.FUNCTION;
121 bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor();
121 bool isClosure() => false; 122 bool isClosure() => false;
122 bool isMember() => 123 bool isMember() {
123 enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS; 124 // Check that this element is defined in the scope of a Class.
125 Element enclosing = enclosingElement;
126 // TODO(lrn): Skip any synthetic elements inserted, e.g.,
Anders Johnsen 2012/08/09 08:08:37 Maybe just travel up the tree and see if you hit a
Lasse Reichstein Nielsen 2012/08/09 11:22:09 Alas no. That would make the parameter of a method
127 // a compilation unit override.
128 return enclosing !== null && enclosing.isClass();
129 }
124 bool isInstanceMember() => false; 130 bool isInstanceMember() => false;
125 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory(); 131 bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory();
126 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; 132 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR;
127 bool isGenerativeConstructorBody() => 133 bool isGenerativeConstructorBody() =>
128 kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY; 134 kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY;
129 bool isCompilationUnit() { 135 bool isCompilationUnit() {
130 return kind === ElementKind.COMPILATION_UNIT || 136 return kind === ElementKind.COMPILATION_UNIT ||
131 kind === ElementKind.LIBRARY; 137 kind === ElementKind.LIBRARY;
132 } 138 }
133 bool isClass() => kind === ElementKind.CLASS; 139 bool isClass() => kind === ElementKind.CLASS;
134 bool isPrefix() => kind === ElementKind.PREFIX; 140 bool isPrefix() => kind === ElementKind.PREFIX;
135 bool isVariable() => kind === ElementKind.VARIABLE; 141 bool isVariable() => kind === ElementKind.VARIABLE;
136 bool isParameter() => kind === ElementKind.PARAMETER; 142 bool isParameter() => kind === ElementKind.PARAMETER;
137 bool isStatement() => kind === ElementKind.STATEMENT; 143 bool isStatement() => kind === ElementKind.STATEMENT;
138 bool isTypedef() => kind === ElementKind.TYPEDEF; 144 bool isTypedef() => kind === ElementKind.TYPEDEF;
139 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE; 145 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE;
140 bool isField() => kind === ElementKind.FIELD; 146 bool isField() => kind === ElementKind.FIELD;
141 bool isGetter() => kind === ElementKind.GETTER; 147 bool isGetter() => kind === ElementKind.GETTER;
142 bool isSetter() => kind === ElementKind.SETTER; 148 bool isSetter() => kind === ElementKind.SETTER;
143 bool isAccessor() => isGetter() || isSetter(); 149 bool isAccessor() => isGetter() || isSetter();
144 bool isForeign() => kind === ElementKind.FOREIGN; 150 bool isForeign() => kind === ElementKind.FOREIGN;
151 bool isLibrary() => kind === ElementKind.LIBRARY;
145 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; 152 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
146 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; 153 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
147 154
148 // TODO(johnniwinther): This breaks for libraries (for which enclosing 155 // TODO(johnniwinther): This breaks for libraries (for which enclosing
149 // elements are null) and is invalid for top level variable declarations for 156 // elements are null) and is invalid for top level variable declarations for
150 // which the enclosing element is a VariableDeclarations and not a compilation 157 // which the enclosing element is a VariableDeclarations and not a compilation
151 // unit. 158 // unit.
152 bool isTopLevel() => enclosingElement.isCompilationUnit(); 159 bool isTopLevel() => enclosingElement.isCompilationUnit();
153 160
154 bool isAssignable() { 161 bool isAssignable() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 LibraryElement getLibrary() { 193 LibraryElement getLibrary() {
187 Element element = this; 194 Element element = this;
188 while (element.kind !== ElementKind.LIBRARY) { 195 while (element.kind !== ElementKind.LIBRARY) {
189 element = element.enclosingElement; 196 element = element.enclosingElement;
190 } 197 }
191 return element; 198 return element;
192 } 199 }
193 200
194 ClassElement getEnclosingClass() { 201 ClassElement getEnclosingClass() {
195 for (Element e = this; e !== null; e = e.enclosingElement) { 202 for (Element e = this; e !== null; e = e.enclosingElement) {
196 if (e.kind === ElementKind.CLASS) return e; 203 if (e.isClass()) return e;
197 } 204 }
198 return null; 205 return null;
199 } 206 }
200 207
201 Element getEnclosingMember() { 208 Element getEnclosingMember() {
202 for (Element e = this; e !== null; e = e.enclosingElement) { 209 for (Element e = this; e !== null; e = e.enclosingElement) {
203 if (e.isMember()) return e; 210 if (e.isMember()) return e;
204 } 211 }
205 return null; 212 return null;
206 } 213 }
207 214
208 Element getOutermostEnclosingMemberOrTopLevel() { 215 Element getOutermostEnclosingMemberOrTopLevel() {
216 // TODO(lrn): Why is this called "Outermost"?
209 for (Element e = this; e !== null; e = e.enclosingElement) { 217 for (Element e = this; e !== null; e = e.enclosingElement) {
210 if (e.isMember() || e.isTopLevel()) { 218 if (e.isMember() || e.isTopLevel()) {
211 return e; 219 return e;
212 } 220 }
213 } 221 }
214 return null; 222 return null;
215 } 223 }
216 224
217 /** 225 /**
218 * Creates the scope for this element. The scope of the 226 * Creates the scope for this element. The scope of the
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 TypeVariableElement(name, Element enclosing, this.cachedNode, 1285 TypeVariableElement(name, Element enclosing, this.cachedNode,
1278 [this.type, this.bound]) 1286 [this.type, this.bound])
1279 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1287 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1280 1288
1281 TypeVariableType computeType(compiler) => type; 1289 TypeVariableType computeType(compiler) => type;
1282 1290
1283 Node parseNode(compiler) => cachedNode; 1291 Node parseNode(compiler) => cachedNode;
1284 1292
1285 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1293 String toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1286 } 1294 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | lib/compiler/implementation/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698