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 "dart2jslib.dart"; | 8 import "dart2jslib.dart"; |
9 import "tree/tree.dart"; | 9 import "tree/tree.dart"; |
10 import "util/util.dart"; | 10 import "util/util.dart"; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // [capturedFieldMapping]. | 224 // [capturedFieldMapping]. |
225 void updateClosures() { | 225 void updateClosures() { |
226 for (Expression closure in closures) { | 226 for (Expression closure in closures) { |
227 // The captured variables that need to be stored in a field of the closure | 227 // The captured variables that need to be stored in a field of the closure |
228 // class. | 228 // class. |
229 Set<Element> fieldCaptures = new Set<Element>(); | 229 Set<Element> fieldCaptures = new Set<Element>(); |
230 ClosureClassMap data = closureMappingCache[closure]; | 230 ClosureClassMap data = closureMappingCache[closure]; |
231 Map<Element, Element> freeVariableMapping = data.freeVariableMapping; | 231 Map<Element, Element> freeVariableMapping = data.freeVariableMapping; |
232 // We get a copy of the keys and iterate over it, to avoid modifications | 232 // We get a copy of the keys and iterate over it, to avoid modifications |
233 // to the map while iterating over it. | 233 // to the map while iterating over it. |
234 freeVariableMapping.getKeys().forEach((Element fromElement) { | 234 freeVariableMapping.keys.forEach((Element fromElement) { |
235 assert(fromElement == freeVariableMapping[fromElement]); | 235 assert(fromElement == freeVariableMapping[fromElement]); |
236 Element updatedElement = capturedVariableMapping[fromElement]; | 236 Element updatedElement = capturedVariableMapping[fromElement]; |
237 assert(updatedElement != null); | 237 assert(updatedElement != null); |
238 if (fromElement == updatedElement) { | 238 if (fromElement == updatedElement) { |
239 assert(freeVariableMapping[fromElement] == updatedElement); | 239 assert(freeVariableMapping[fromElement] == updatedElement); |
240 assert(Elements.isLocal(updatedElement) | 240 assert(Elements.isLocal(updatedElement) |
241 || updatedElement.isTypeVariable()); | 241 || updatedElement.isTypeVariable()); |
242 // The variable has not been boxed. | 242 // The variable has not been boxed. |
243 fieldCaptures.add(updatedElement); | 243 fieldCaptures.add(updatedElement); |
244 } else { | 244 } else { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 ClosureClassMap savedClosureData = closureData; | 579 ClosureClassMap savedClosureData = closureData; |
580 bool savedInsideClosure = insideClosure; | 580 bool savedInsideClosure = insideClosure; |
581 | 581 |
582 // Restore old values. | 582 // Restore old values. |
583 insideClosure = oldInsideClosure; | 583 insideClosure = oldInsideClosure; |
584 closureData = oldClosureData; | 584 closureData = oldClosureData; |
585 currentElement = oldFunctionElement; | 585 currentElement = oldFunctionElement; |
586 | 586 |
587 // Mark all free variables as captured and use them in the outer function. | 587 // Mark all free variables as captured and use them in the outer function. |
588 List<Element> freeVariables = | 588 List<Element> freeVariables = |
589 savedClosureData.freeVariableMapping.getKeys(); | 589 savedClosureData.freeVariableMapping.keys; |
590 assert(freeVariables.isEmpty || savedInsideClosure); | 590 assert(freeVariables.isEmpty || savedInsideClosure); |
591 for (Element freeElement in freeVariables) { | 591 for (Element freeElement in freeVariables) { |
592 if (capturedVariableMapping[freeElement] != null && | 592 if (capturedVariableMapping[freeElement] != null && |
593 capturedVariableMapping[freeElement] != freeElement) { | 593 capturedVariableMapping[freeElement] != freeElement) { |
594 compiler.internalError('In closure analyzer', node: node); | 594 compiler.internalError('In closure analyzer', node: node); |
595 } | 595 } |
596 capturedVariableMapping[freeElement] = freeElement; | 596 capturedVariableMapping[freeElement] = freeElement; |
597 useLocal(freeElement); | 597 useLocal(freeElement); |
598 } | 598 } |
599 } | 599 } |
(...skipping 24 matching lines...) Expand all Loading... |
624 } | 624 } |
625 | 625 |
626 visitTryStatement(TryStatement node) { | 626 visitTryStatement(TryStatement node) { |
627 // TODO(ngeoffray): implement finer grain state. | 627 // TODO(ngeoffray): implement finer grain state. |
628 bool oldInTryStatement = inTryStatement; | 628 bool oldInTryStatement = inTryStatement; |
629 inTryStatement = true; | 629 inTryStatement = true; |
630 node.visitChildren(this); | 630 node.visitChildren(this); |
631 inTryStatement = oldInTryStatement; | 631 inTryStatement = oldInTryStatement; |
632 } | 632 } |
633 } | 633 } |
OLD | NEW |