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 "dart2jslib.dart"; | 8 import "dart2jslib.dart"; |
| 9 import "dart_types.dart"; | 9 import "dart_types.dart"; |
| 10 import "scanner/scannerlib.dart" show Token; | 10 import "scanner/scannerlib.dart" show Token; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(ahe): These classes continuously cause problems. We need to | 71 // TODO(ahe): These classes continuously cause problems. We need to |
| 72 // move these classes to elements/modelx.dart or see if we can find a | 72 // move these classes to elements/modelx.dart or see if we can find a |
| 73 // more general solution. | 73 // more general solution. |
| 74 class ClosureFieldElement extends ElementX implements VariableElement { | 74 class ClosureFieldElement extends ElementX implements VariableElement { |
| 75 /// The source variable this element refers to. | 75 /// The source variable this element refers to. |
| 76 final Element variableElement; | 76 final Element variableElement; |
| 77 | 77 |
| 78 List<FunctionElement> nestedClosures = new List<FunctionElement>(); | |
|
ngeoffray
2013/12/05 09:29:28
What is this for a ClosureFieldElement? Please add
sigurdm
2013/12/05 11:35:03
Actually nothing - I had misunderstood what a Clos
| |
| 79 | |
| 78 ClosureFieldElement(String name, | 80 ClosureFieldElement(String name, |
| 79 this.variableElement, | 81 this.variableElement, |
| 80 ClassElement enclosing) | 82 ClassElement enclosing) |
| 81 : super(name, ElementKind.FIELD, enclosing); | 83 : super(name, ElementKind.FIELD, enclosing); |
| 82 | 84 |
| 83 VariableListElement get variables { | 85 VariableListElement get variables { |
| 84 throw new SpannableAssertionFailure( | 86 throw new SpannableAssertionFailure( |
| 85 variableElement, 'Should not access variables of ClosureFieldElement.'); | 87 variableElement, 'Should not access variables of ClosureFieldElement.'); |
| 86 } | 88 } |
| 87 | 89 |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 } | 695 } |
| 694 | 696 |
| 695 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { | 697 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { |
| 696 String closureName = computeClosureName(element); | 698 String closureName = computeClosureName(element); |
| 697 ClassElement globalizedElement = new ClosureClassElement( | 699 ClassElement globalizedElement = new ClosureClassElement( |
| 698 node, closureName, compiler, element, element.getCompilationUnit()); | 700 node, closureName, compiler, element, element.getCompilationUnit()); |
| 699 FunctionElement callElement = | 701 FunctionElement callElement = |
| 700 new FunctionElementX.from(Compiler.CALL_OPERATOR_NAME, | 702 new FunctionElementX.from(Compiler.CALL_OPERATOR_NAME, |
| 701 element, | 703 element, |
| 702 globalizedElement); | 704 globalizedElement); |
| 705 ClosureContainer enclosing = element.enclosingElement; | |
| 706 enclosing.nestedClosures.add(callElement); | |
| 703 globalizedElement.addMember(callElement, compiler); | 707 globalizedElement.addMember(callElement, compiler); |
| 704 // The nested function's 'this' is the same as the one for the outer | 708 // The nested function's 'this' is the same as the one for the outer |
| 705 // function. It could be [null] if we are inside a static method. | 709 // function. It could be [null] if we are inside a static method. |
| 706 Element thisElement = closureData.thisElement; | 710 Element thisElement = closureData.thisElement; |
| 707 return new ClosureClassMap(element, globalizedElement, | 711 return new ClosureClassMap(element, globalizedElement, |
| 708 callElement, thisElement); | 712 callElement, thisElement); |
| 709 } | 713 } |
| 710 | 714 |
| 711 void visitInvokable(Element element, Expression node, void visitChildren()) { | 715 void visitInvokable(Element element, Expression node, void visitChildren()) { |
| 712 bool oldInsideClosure = insideClosure; | 716 bool oldInsideClosure = insideClosure; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 } | 814 } |
| 811 | 815 |
| 812 visitTryStatement(TryStatement node) { | 816 visitTryStatement(TryStatement node) { |
| 813 // TODO(ngeoffray): implement finer grain state. | 817 // TODO(ngeoffray): implement finer grain state. |
| 814 bool oldInTryStatement = inTryStatement; | 818 bool oldInTryStatement = inTryStatement; |
| 815 inTryStatement = true; | 819 inTryStatement = true; |
| 816 node.visitChildren(this); | 820 node.visitChildren(this); |
| 817 inTryStatement = oldInTryStatement; | 821 inTryStatement = oldInTryStatement; |
| 818 } | 822 } |
| 819 } | 823 } |
| OLD | NEW |