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("closureToClassMapper"); | 5 #library("closureToClassMapper"); |
| 6 | 6 |
| 7 #import("elements/elements.dart"); | 7 #import("elements/elements.dart"); |
| 8 #import("leg.dart"); | 8 #import("leg.dart"); |
| 9 #import("scanner/scannerlib.dart"); | 9 #import("scanner/scannerlib.dart"); |
| 10 #import("tree/tree.dart"); | 10 #import("tree/tree.dart"); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 } | 310 } |
| 311 | 311 |
| 312 visitSendSet(SendSet node) { | 312 visitSendSet(SendSet node) { |
| 313 Element element = elements[node]; | 313 Element element = elements[node]; |
| 314 if (Elements.isLocal(element)) { | 314 if (Elements.isLocal(element)) { |
| 315 mutatedVariables.add(element); | 315 mutatedVariables.add(element); |
| 316 } | 316 } |
| 317 super.visitSendSet(node); | 317 super.visitSendSet(node); |
| 318 } | 318 } |
| 319 | 319 |
| 320 visitNewExpression(NewExpression node) { | |
| 321 bool hasTypeVariable(DartType type) { | |
| 322 if (type is TypeVariableType) { | |
| 323 return true; | |
| 324 } else if (type is InterfaceType) { | |
| 325 InterfaceType ifcType = type; | |
| 326 for (DartType argument in ifcType.arguments) { | |
| 327 if (hasTypeVariable(argument)) { | |
| 328 return true; | |
| 329 } | |
| 330 } | |
| 331 } | |
| 332 return false; | |
| 333 } | |
| 334 TypeAnnotation annotation = node.send.getTypeAnnotation(); | |
| 335 DartType type = elements.getType(annotation); | |
| 336 if (hasTypeVariable(type)) { | |
| 337 if (closureData.thisElement !== null) { | |
|
floitsch
2012/09/03 14:04:15
Add comment why this is necessary. Maybe find a mo
| |
| 338 useLocal(closureData.thisElement); | |
| 339 } | |
| 340 } | |
| 341 node.visitChildren(this); | |
| 342 } | |
| 343 | |
| 320 // If variables that are declared in the [node] scope are captured and need | 344 // If variables that are declared in the [node] scope are captured and need |
| 321 // to be boxed create a box-element and update the [capturingScopes] in the | 345 // to be boxed create a box-element and update the [capturingScopes] in the |
| 322 // current [closureData]. | 346 // current [closureData]. |
| 323 // The boxed variables are updated in the [capturedVariableMapping]. | 347 // The boxed variables are updated in the [capturedVariableMapping]. |
| 324 void attachCapturedScopeVariables(Node node) { | 348 void attachCapturedScopeVariables(Node node) { |
| 325 Element box = null; | 349 Element box = null; |
| 326 Map<Element, Element> scopeMapping = new Map<Element, Element>(); | 350 Map<Element, Element> scopeMapping = new Map<Element, Element>(); |
| 327 for (Element element in scopeVariables) { | 351 for (Element element in scopeVariables) { |
| 328 // No need to box non-assignable elements. | 352 // No need to box non-assignable elements. |
| 329 if (!element.isAssignable()) continue; | 353 if (!element.isAssignable()) continue; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 } | 523 } |
| 500 | 524 |
| 501 visitTryStatement(TryStatement node) { | 525 visitTryStatement(TryStatement node) { |
| 502 // TODO(ngeoffray): implement finer grain state. | 526 // TODO(ngeoffray): implement finer grain state. |
| 503 bool oldInTryStatement = inTryStatement; | 527 bool oldInTryStatement = inTryStatement; |
| 504 inTryStatement = true; | 528 inTryStatement = true; |
| 505 node.visitChildren(this); | 529 node.visitChildren(this); |
| 506 inTryStatement = oldInTryStatement; | 530 inTryStatement = oldInTryStatement; |
| 507 } | 531 } |
| 508 } | 532 } |
| OLD | NEW |