OLD | NEW |
---|---|
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 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 static final int ALIAS = 32; | 32 static final int ALIAS = 32; |
33 | 33 |
34 static final int SUPER = 64; | 34 static final int SUPER = 64; |
35 | 35 |
36 /** Type variable */ | 36 /** Type variable */ |
37 static final int TYPE_VARIABLE = 128; | 37 static final int TYPE_VARIABLE = 128; |
38 | 38 |
39 static final int IMPLIES_TYPE = CLASS | ALIAS | TYPE_VARIABLE; | 39 static final int IMPLIES_TYPE = CLASS | ALIAS | TYPE_VARIABLE; |
40 | 40 |
41 static final int IS_EXTENDABLE = CLASS | ALIAS; | 41 static final int IS_EXTENDABLE = CLASS; |
42 } | 42 } |
43 | 43 |
44 class ElementKind { | 44 class ElementKind { |
45 final String id; | 45 final String id; |
46 final int category; | 46 final int category; |
47 | 47 |
48 const ElementKind(String this.id, this.category); | 48 const ElementKind(String this.id, this.category); |
49 | 49 |
50 static final ElementKind VARIABLE = | 50 static final ElementKind VARIABLE = |
51 const ElementKind('variable', ElementCategory.VARIABLE); | 51 const ElementKind('variable', ElementCategory.VARIABLE); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 return element; | 191 return element; |
192 } | 192 } |
193 | 193 |
194 ClassElement getEnclosingClass() { | 194 ClassElement getEnclosingClass() { |
195 for (Element e = this; e !== null; e = e.enclosingElement) { | 195 for (Element e = this; e !== null; e = e.enclosingElement) { |
196 if (e.kind === ElementKind.CLASS) return e; | 196 if (e.kind === ElementKind.CLASS) return e; |
197 } | 197 } |
198 return null; | 198 return null; |
199 } | 199 } |
200 | 200 |
201 Element getEnclosingClassOrTypedef() { | |
202 for (Element e = this; e !== null; e = e.enclosingElement) { | |
203 if (e.kind === ElementKind.CLASS | |
204 || e.kind === ElementKind.TYPEDEF) return e; | |
ahe
2012/07/30 10:30:05
I'd prefer if you keep the condition on the same l
Johnni Winther
2012/08/01 10:12:28
Removed.
| |
205 } | |
206 return null; | |
207 } | |
208 | |
201 Element getEnclosingMember() { | 209 Element getEnclosingMember() { |
202 for (Element e = this; e !== null; e = e.enclosingElement) { | 210 for (Element e = this; e !== null; e = e.enclosingElement) { |
203 if (e.isMember()) return e; | 211 if (e.isMember()) return e; |
204 } | 212 } |
205 return null; | 213 return null; |
206 } | 214 } |
207 | 215 |
208 Element getOutermostEnclosingMemberOrTopLevel() { | 216 Element getOutermostEnclosingMemberOrTopLevel() { |
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()) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 } | 420 } |
413 | 421 |
414 lookupLocalMember(SourceString memberName) => imported[memberName]; | 422 lookupLocalMember(SourceString memberName) => imported[memberName]; |
415 | 423 |
416 Type computeType(Compiler compiler) => compiler.types.dynamicType; | 424 Type computeType(Compiler compiler) => compiler.types.dynamicType; |
417 | 425 |
418 Token position() => firstPosition; | 426 Token position() => firstPosition; |
419 } | 427 } |
420 | 428 |
421 class TypedefElement extends Element { | 429 class TypedefElement extends Element { |
430 TypedefElement(SourceString name, Element enclosing) | |
431 : typeParameters = new LinkedHashMap<SourceString, TypeVariableElement>(), | |
432 super(name, ElementKind.TYPEDEF, enclosing); | |
433 | |
434 LinkedHashMap<SourceString, TypeVariableElement> typeParameters; | |
ahe
2012/07/30 10:30:05
I don't think this should be a map. The overhead o
Johnni Winther
2012/08/01 10:12:28
Done.
| |
435 | |
422 Type cachedType; | 436 Type cachedType; |
423 Typedef cachedNode; | 437 Typedef cachedNode; |
424 | 438 |
425 TypedefElement(SourceString name, Element enclosing) | |
426 : super(name, ElementKind.TYPEDEF, enclosing); | |
427 | |
428 Type computeType(Compiler compiler) { | 439 Type computeType(Compiler compiler) { |
429 if (cachedType !== null) return cachedType; | 440 if (cachedType !== null) return cachedType; |
430 cachedType = compiler.computeFunctionType( | 441 compiler.resolveTypedef(this); |
ahe
2012/07/30 10:30:05
This method may be called twice. You need to ensur
Johnni Winther
2012/08/01 10:12:28
Done.
| |
431 this, compiler.resolveTypedef(this)); | |
432 return cachedType; | 442 return cachedType; |
433 } | 443 } |
434 } | 444 } |
435 | 445 |
436 class VariableElement extends Element { | 446 class VariableElement extends Element { |
437 final VariableListElement variables; | 447 final VariableListElement variables; |
438 Expression cachedNode; // The send or the identifier in the variables list. | 448 Expression cachedNode; // The send or the identifier in the variables list. |
439 | 449 |
440 Modifiers get modifiers() => variables.modifiers; | 450 Modifiers get modifiers() => variables.modifiers; |
441 | 451 |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1212 final Node node; | 1222 final Node node; |
1213 Type bound; | 1223 Type bound; |
1214 TypeVariableType type; | 1224 TypeVariableType type; |
1215 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1225 TypeVariableElement(name, Element enclosing, this.node, this.type, |
1216 [this.bound]) | 1226 [this.bound]) |
1217 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1227 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
1218 TypeVariableType computeType(compiler) => type; | 1228 TypeVariableType computeType(compiler) => type; |
1219 Node parseNode(compiler) => node; | 1229 Node parseNode(compiler) => node; |
1220 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1230 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
1221 } | 1231 } |
OLD | NEW |