| 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 class ClosureFieldElement extends Element { | 5 class ClosureFieldElement extends Element { |
| 6 ClosureFieldElement(SourceString name, ClassElement enclosing) | 6 ClosureFieldElement(SourceString name, ClassElement enclosing) |
| 7 : super(name, ElementKind.FIELD, enclosing); | 7 : super(name, ElementKind.FIELD, enclosing); |
| 8 | 8 |
| 9 bool isInstanceMember() => true; | 9 bool isInstanceMember() => true; |
| 10 bool isAssignable() => false; | 10 bool isAssignable() => false; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 new ClosureFieldElement(boxElement.name, closureElement); | 140 new ClosureFieldElement(boxElement.name, closureElement); |
| 141 closureElement.backendMembers = | 141 closureElement.backendMembers = |
| 142 closureElement.backendMembers.prepend(fieldElement); | 142 closureElement.backendMembers.prepend(fieldElement); |
| 143 data.capturedFieldMapping[fieldElement] = boxElement; | 143 data.capturedFieldMapping[fieldElement] = boxElement; |
| 144 freeVariableMapping[boxElement] = fieldElement; | 144 freeVariableMapping[boxElement] = fieldElement; |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void useLocal(Element element) { | 149 void useLocal(Element element) { |
| 150 if (element.enclosingElement != currentFunctionElement) { | 150 // TODO(floitsch): replace this with a general solution. |
| 151 Element functionElement = currentFunctionElement; |
| 152 if (functionElement.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 153 ConstructorBodyElement body = functionElement; |
| 154 functionElement = body.constructor; |
| 155 } |
| 156 if (element.enclosingElement != functionElement) { |
| 151 assert(closureData.freeVariableMapping[element] == null || | 157 assert(closureData.freeVariableMapping[element] == null || |
| 152 closureData.freeVariableMapping[element] == element); | 158 closureData.freeVariableMapping[element] == element); |
| 153 closureData.freeVariableMapping[element] = element; | 159 closureData.freeVariableMapping[element] = element; |
| 154 } else if (inTryCatchOrFinally) { | 160 } else if (inTryCatchOrFinally) { |
| 155 // TODO(ngeoffray): only do this if the variable is mutated. | 161 // TODO(ngeoffray): only do this if the variable is mutated. |
| 156 closureData.usedVariablesInTry.add(element); | 162 closureData.usedVariablesInTry.add(element); |
| 157 } | 163 } |
| 158 } | 164 } |
| 159 | 165 |
| 160 void declareLocal(Element element) { | 166 void declareLocal(Element element) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 321 } |
| 316 } | 322 } |
| 317 | 323 |
| 318 visitTryStatement(TryStatement node) { | 324 visitTryStatement(TryStatement node) { |
| 319 // TODO(ngeoffray): implement finer grain state. | 325 // TODO(ngeoffray): implement finer grain state. |
| 320 inTryCatchOrFinally = true; | 326 inTryCatchOrFinally = true; |
| 321 node.visitChildren(this); | 327 node.visitChildren(this); |
| 322 inTryCatchOrFinally = false; | 328 inTryCatchOrFinally = false; |
| 323 } | 329 } |
| 324 } | 330 } |
| OLD | NEW |