Chromium Code Reviews| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 for (Element e = this; e !== null; e = e.enclosingElement) { | 209 for (Element e = this; e !== null; e = e.enclosingElement) { |
| 210 if (e.isMember() || e.isTopLevel()) { | 210 if (e.isMember() || e.isTopLevel()) { |
| 211 return e; | 211 return e; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 return null; | 214 return null; |
| 215 } | 215 } |
| 216 | 216 |
| 217 String toString() { | 217 String toString() { |
| 218 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an | 218 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an |
| 219 // invariant for all element types. | 219 // invariant for all element types? |
| 220 var nameText = name !== null ? name.slowToString() : '?'; | |
| 220 if (enclosingElement !== null && !isTopLevel()) { | 221 if (enclosingElement !== null && !isTopLevel()) { |
| 221 String holderName = enclosingElement.name.slowToString(); | 222 String holderName = enclosingElement.name !== null |
| 222 return '$kind($holderName#${name.slowToString()})'; | 223 ? enclosingElement.name.slowToString() |
| 224 : '${enclosingElement.kind}?'; | |
| 225 return '$kind($holderName#${nameText})'; | |
| 223 } else { | 226 } else { |
| 224 return '$kind(${name.slowToString()})'; | 227 return '$kind(${nameText})'; |
| 225 } | 228 } |
| 226 } | 229 } |
| 227 | 230 |
| 228 bool _isNative = false; | 231 bool _isNative = false; |
| 229 void setNative() { _isNative = true; } | 232 void setNative() { _isNative = true; } |
| 230 bool isNative() => _isNative; | 233 bool isNative() => _isNative; |
| 231 | 234 |
| 232 FunctionElement asFunctionElement() => null; | 235 FunctionElement asFunctionElement() => null; |
| 233 } | 236 } |
| 234 | 237 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 | 496 |
| 494 // This element represents a list of variable or field declaration. | 497 // This element represents a list of variable or field declaration. |
| 495 // It contains the node, and the type. A [VariableElement] always | 498 // It contains the node, and the type. A [VariableElement] always |
| 496 // references its [VariableListElement]. It forwards its | 499 // references its [VariableListElement]. It forwards its |
| 497 // [computeType] and [parseNode] methods to this element. | 500 // [computeType] and [parseNode] methods to this element. |
| 498 class VariableListElement extends Element { | 501 class VariableListElement extends Element { |
| 499 VariableDefinitions cachedNode; | 502 VariableDefinitions cachedNode; |
| 500 Type type; | 503 Type type; |
| 501 final Modifiers modifiers; | 504 final Modifiers modifiers; |
| 502 | 505 |
| 506 /** | |
| 507 * Function signature for a variable with a function type. The signature is | |
| 508 * kept to provide full information about parameter names through the the | |
| 509 * mirror system. | |
| 510 */ | |
| 511 FunctionSignature functionSignature; | |
|
ahe
2012/08/02 19:20:25
We plan to turn this into a type, right?
| |
| 512 | |
| 503 VariableListElement(ElementKind kind, | 513 VariableListElement(ElementKind kind, |
| 504 Modifiers this.modifiers, | 514 Modifiers this.modifiers, |
| 505 Element enclosing) | 515 Element enclosing) |
| 506 : super(null, kind, enclosing); | 516 : super(null, kind, enclosing); |
| 507 | 517 |
| 508 VariableListElement.node(VariableDefinitions node, | 518 VariableListElement.node(VariableDefinitions node, |
| 509 ElementKind kind, | 519 ElementKind kind, |
| 510 Element enclosing) | 520 Element enclosing) |
| 511 : super(null, kind, enclosing), | 521 : super(null, kind, enclosing), |
| 512 this.cachedNode = node, | 522 this.cachedNode = node, |
| 513 this.modifiers = node.modifiers; | 523 this.modifiers = node.modifiers; |
| 514 | 524 |
| 515 VariableDefinitions parseNode(DiagnosticListener listener) { | 525 VariableDefinitions parseNode(DiagnosticListener listener) { |
| 516 return cachedNode; | 526 return cachedNode; |
| 517 } | 527 } |
| 518 | 528 |
| 519 Type computeType(Compiler compiler) { | 529 Type computeType(Compiler compiler) { |
| 520 if (type != null) return type; | 530 if (type != null) return type; |
| 521 type = compiler.resolveTypeAnnotation(this, parseNode(compiler).type); | 531 VariableDefinitions node = parseNode(compiler); |
| 532 if (node.type !== null) { | |
| 533 type = compiler.resolveTypeAnnotation(this, node.type); | |
| 534 } else { | |
|
ahe
2012/08/02 19:20:25
We are already changing this, right? This looks sc
| |
| 535 // Is node.definitions exactly one FunctionExpression? | |
| 536 Link<Node> link = node.definitions.nodes; | |
| 537 if (!link.isEmpty() && | |
| 538 link.head.asFunctionExpression() !== null && | |
| 539 link.tail.isEmpty()) { | |
| 540 FunctionExpression functionExpression = link.head; | |
| 541 // We found exactly one FunctionExpression | |
| 542 compiler.withCurrentElement(this, () { | |
| 543 functionSignature = | |
| 544 compiler.resolveFunctionExpression(this, functionExpression); | |
| 545 }); | |
| 546 type = compiler.computeFunctionType(compiler.functionClass, | |
| 547 functionSignature); | |
| 548 } else { | |
| 549 type = compiler.types.dynamicType; | |
| 550 } | |
| 551 } | |
| 552 assert(type != null); | |
| 522 return type; | 553 return type; |
| 523 } | 554 } |
| 524 | 555 |
| 525 Token position() => cachedNode.getBeginToken(); | 556 Token position() => cachedNode.getBeginToken(); |
| 526 } | 557 } |
| 527 | 558 |
| 528 class ForeignElement extends Element { | 559 class ForeignElement extends Element { |
| 529 ForeignElement(SourceString name, ContainerElement enclosingElement) | 560 ForeignElement(SourceString name, ContainerElement enclosingElement) |
| 530 : super(name, ElementKind.FOREIGN, enclosingElement); | 561 : super(name, ElementKind.FOREIGN, enclosingElement); |
| 531 | 562 |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 final Node node; | 1183 final Node node; |
| 1153 Type bound; | 1184 Type bound; |
| 1154 Type type; | 1185 Type type; |
| 1155 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1186 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1156 [this.bound]) | 1187 [this.bound]) |
| 1157 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1188 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1158 Type computeType(compiler) => type; | 1189 Type computeType(compiler) => type; |
| 1159 Node parseNode(compiler) => node; | 1190 Node parseNode(compiler) => node; |
| 1160 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1191 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1161 } | 1192 } |
| OLD | NEW |