| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 | 234 |
| 235 // If variables that are declared in the [node] scope are captured and need | 235 // If variables that are declared in the [node] scope are captured and need |
| 236 // to be boxed create a box-element and update the [capturingScopes] in the | 236 // to be boxed create a box-element and update the [capturingScopes] in the |
| 237 // current [closureData]. | 237 // current [closureData]. |
| 238 // The boxed variables are updated in the [capturedVariableMapping]. | 238 // The boxed variables are updated in the [capturedVariableMapping]. |
| 239 void attachCapturedScopeVariables(Node node) { | 239 void attachCapturedScopeVariables(Node node) { |
| 240 Element box = null; | 240 Element box = null; |
| 241 Map<Element, Element> scopeMapping = new Map<Element, Element>(); | 241 Map<Element, Element> scopeMapping = new Map<Element, Element>(); |
| 242 for (Element element in scopeVariables) { | 242 for (Element element in scopeVariables) { |
| 243 // No need to box non-assignable elements. |
| 244 if (!element.isAssignable()) continue; |
| 243 if (capturedVariableMapping.containsKey(element)) { | 245 if (capturedVariableMapping.containsKey(element)) { |
| 244 if (box == null) { | 246 if (box == null) { |
| 245 // TODO(floitsch): construct better box names. | 247 // TODO(floitsch): construct better box names. |
| 246 SourceString boxName = new SourceString("box${boxCounter++}"); | 248 SourceString boxName = new SourceString("box${boxCounter++}"); |
| 247 box = new Element(boxName, | 249 box = new Element(boxName, |
| 248 ElementKind.VARIABLE, | 250 ElementKind.VARIABLE, |
| 249 currentFunctionElement); | 251 currentFunctionElement); |
| 250 } | 252 } |
| 251 // TODO(floitsch): construct better boxed names. | 253 // TODO(floitsch): construct better boxed names. |
| 252 String elementName = element.name.slowToString(); | 254 String elementName = element.name.slowToString(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 thisEnclosingElement = body.constructor; | 349 thisEnclosingElement = body.constructor; |
| 348 } | 350 } |
| 349 thisElement = new Element(const SourceString("this"), | 351 thisElement = new Element(const SourceString("this"), |
| 350 ElementKind.PARAMETER, | 352 ElementKind.PARAMETER, |
| 351 thisEnclosingElement); | 353 thisEnclosingElement); |
| 352 } | 354 } |
| 353 closureData = new ClosureData(null, null, null, thisElement); | 355 closureData = new ClosureData(null, null, null, thisElement); |
| 354 } | 356 } |
| 355 scopeVariables = new List<Element>(); | 357 scopeVariables = new List<Element>(); |
| 356 | 358 |
| 357 // TODO(floitsch): a named function is visible from inside itself. Add | |
| 358 // the element to the block. | |
| 359 | |
| 360 // We have to declare the implicit 'this' parameter. | 359 // We have to declare the implicit 'this' parameter. |
| 361 if (!insideClosure && closureData.thisElement !== null) { | 360 if (!insideClosure && closureData.thisElement !== null) { |
| 362 declareLocal(closureData.thisElement); | 361 declareLocal(closureData.thisElement); |
| 363 } | 362 } |
| 364 // If we are inside a named closure we have to declare ourselve. For | 363 // If we are inside a named closure we have to declare ourselve. For |
| 365 // simplicity we declare the local even if the closure does not have a name | 364 // simplicity we declare the local even if the closure does not have a name |
| 366 // It will simply not be used. | 365 // It will simply not be used. |
| 367 if (insideClosure) { | 366 if (insideClosure) { |
| 368 declareLocal(element); | 367 declareLocal(element); |
| 369 } | 368 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 declareLocal(elements[node]); | 407 declareLocal(elements[node]); |
| 409 } | 408 } |
| 410 | 409 |
| 411 visitTryStatement(TryStatement node) { | 410 visitTryStatement(TryStatement node) { |
| 412 // TODO(ngeoffray): implement finer grain state. | 411 // TODO(ngeoffray): implement finer grain state. |
| 413 inTryCatchOrFinally = true; | 412 inTryCatchOrFinally = true; |
| 414 node.visitChildren(this); | 413 node.visitChildren(this); |
| 415 inTryCatchOrFinally = false; | 414 inTryCatchOrFinally = false; |
| 416 } | 415 } |
| 417 } | 416 } |
| OLD | NEW |