| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 final Script script; | 87 final Script script; |
| 88 CompilationUnitElement(Script script, Element enclosing) | 88 CompilationUnitElement(Script script, Element enclosing) |
| 89 : super(new SourceString(script.name), | 89 : super(new SourceString(script.name), |
| 90 ElementKind.COMPILATION_UNIT, | 90 ElementKind.COMPILATION_UNIT, |
| 91 enclosing), | 91 enclosing), |
| 92 this.script = script; | 92 this.script = script; |
| 93 } | 93 } |
| 94 | 94 |
| 95 class VariableElement extends Element { | 95 class VariableElement extends Element { |
| 96 final VariableListElement variables; | 96 final VariableListElement variables; |
| 97 final Node node; // The send or the identifier in the variables list. | 97 Expression node; // The send or the identifier in the variables list. |
| 98 | 98 |
| 99 Modifiers get modifiers() => variables.modifiers; | 99 Modifiers get modifiers() => variables.modifiers; |
| 100 | 100 |
| 101 VariableElement(SourceString name, | 101 VariableElement(SourceString name, |
| 102 Node this.node, | |
| 103 VariableListElement this.variables, | 102 VariableListElement this.variables, |
| 104 ElementKind kind, | 103 ElementKind kind, |
| 105 Element enclosing) | 104 Element enclosing) |
| 106 : super(name, kind, enclosing); | 105 : super(name, kind, enclosing); |
| 107 | 106 |
| 108 Node parseNode(Canceler canceler, Logger logger) { | 107 Node parseNode(Canceler canceler, Logger logger) { |
| 109 assert(node != null); | 108 if (node !== null) return node; |
| 110 return node; | 109 VariableDefinitions definitions = variables.parseNode(canceler, logger); |
| 110 for (Link<Node> link = definitions.definitions.nodes; |
| 111 !link.isEmpty(); link = link.tail) { |
| 112 Expression initializedIdentifier = link.head; |
| 113 Identifier identifier = initializedIdentifier.asIdentifier(); |
| 114 if (identifier === null) { |
| 115 identifier = initializedIdentifier.asSendSet().selector.asIdentifier(); |
| 116 } |
| 117 if (name === identifier.source) { |
| 118 node = initializedIdentifier; |
| 119 return node; |
| 120 } |
| 121 } |
| 122 canceler.cancel('internal error: could not find $name', node: variables); |
| 111 } | 123 } |
| 112 | 124 |
| 113 Type computeType(Compiler compiler) { | 125 Type computeType(Compiler compiler) { |
| 114 return variables.computeType(compiler); | 126 return variables.computeType(compiler); |
| 115 } | 127 } |
| 116 | 128 |
| 117 Type get type() => variables.type; | 129 Type get type() => variables.type; |
| 118 | 130 |
| 119 bool isInstanceMember() { | 131 bool isInstanceMember() { |
| 120 return isMember() && !modifiers.isStatic(); | 132 return isMember() && !modifiers.isStatic(); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 if (send.isPropertyAccess) return false; | 401 if (send.isPropertyAccess) return false; |
| 390 if (send.receiver !== null) return false; | 402 if (send.receiver !== null) return false; |
| 391 Element element = elements[send]; | 403 Element element = elements[send]; |
| 392 // (o)() or foo()(). | 404 // (o)() or foo()(). |
| 393 if (element === null && send.selector.asIdentifier() === null) return true; | 405 if (element === null && send.selector.asIdentifier() === null) return true; |
| 394 if (element === null) return false; | 406 if (element === null) return false; |
| 395 // foo() with foo a local or a parameter. | 407 // foo() with foo a local or a parameter. |
| 396 return element.isVariable() || element.isParameter(); | 408 return element.isVariable() || element.isParameter(); |
| 397 } | 409 } |
| 398 } | 410 } |
| OLD | NEW |