| 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; |
| 11 import "tree/tree.dart"; | 11 import "tree/tree.dart"; |
| 12 import "util/util.dart"; | 12 import "util/util.dart"; |
| 13 import "elements/modelx.dart" show ElementX, FunctionElementX, ClassElementX; | 13 import "elements/modelx.dart" show ElementX, FunctionElementX, ClassElementX; |
| 14 import "elements/visitor.dart" show ElementVisitor; |
| 14 | 15 |
| 15 class ClosureNamer { | 16 class ClosureNamer { |
| 16 String getClosureVariableName(String name, int id) { | 17 String getClosureVariableName(String name, int id) { |
| 17 return "${name}_$id"; | 18 return "${name}_$id"; |
| 18 } | 19 } |
| 19 } | 20 } |
| 20 | 21 |
| 21 class ClosureTask extends CompilerTask { | 22 class ClosureTask extends CompilerTask { |
| 22 Map<Node, ClosureClassMap> closureMappingCache; | 23 Map<Node, ClosureClassMap> closureMappingCache; |
| 23 ClosureNamer namer; | 24 ClosureNamer namer; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool isInstanceMember() => true; | 94 bool isInstanceMember() => true; |
| 94 bool isAssignable() => false; | 95 bool isAssignable() => false; |
| 95 | 96 |
| 96 DartType computeType(Compiler compiler) { | 97 DartType computeType(Compiler compiler) { |
| 97 return variableElement.computeType(compiler); | 98 return variableElement.computeType(compiler); |
| 98 } | 99 } |
| 99 | 100 |
| 100 String toString() => "ClosureFieldElement($name)"; | 101 String toString() => "ClosureFieldElement($name)"; |
| 102 |
| 103 accept(ElementVisitor visitor) => visitor.visitClosureFieldElement(this); |
| 101 } | 104 } |
| 102 | 105 |
| 103 // TODO(ahe): These classes continuously cause problems. We need to | 106 // TODO(ahe): These classes continuously cause problems. We need to |
| 104 // move these classes to elements/modelx.dart or see if we can find a | 107 // move these classes to elements/modelx.dart or see if we can find a |
| 105 // more general solution. | 108 // more general solution. |
| 106 class ClosureClassElement extends ClassElementX { | 109 class ClosureClassElement extends ClassElementX { |
| 107 DartType rawType; | 110 DartType rawType; |
| 108 DartType thisType; | 111 DartType thisType; |
| 109 /// Node that corresponds to this closure, used for source position. | 112 /// Node that corresponds to this closure, used for source position. |
| 110 final FunctionExpression node; | 113 final FunctionExpression node; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 135 bool isClosure() => true; | 138 bool isClosure() => true; |
| 136 | 139 |
| 137 Token position() => node.getBeginToken(); | 140 Token position() => node.getBeginToken(); |
| 138 | 141 |
| 139 Node parseNode(DiagnosticListener listener) => node; | 142 Node parseNode(DiagnosticListener listener) => node; |
| 140 | 143 |
| 141 /** | 144 /** |
| 142 * The most outer method this closure is declared into. | 145 * The most outer method this closure is declared into. |
| 143 */ | 146 */ |
| 144 final Element methodElement; | 147 final Element methodElement; |
| 148 |
| 149 accept(ElementVisitor visitor) => visitor.visitClosureClassElement(this); |
| 145 } | 150 } |
| 146 | 151 |
| 147 // TODO(ahe): These classes continuously cause problems. We need to | 152 // TODO(ahe): These classes continuously cause problems. We need to |
| 148 // move these classes to elements/modelx.dart or see if we can find a | 153 // move these classes to elements/modelx.dart or see if we can find a |
| 149 // more general solution. | 154 // more general solution. |
| 150 class BoxElement extends ElementX { | 155 class BoxElement extends ElementX { |
| 151 BoxElement(String name, Element enclosingElement) | 156 BoxElement(String name, Element enclosingElement) |
| 152 : super(name, ElementKind.VARIABLE_LIST, enclosingElement); | 157 : super(name, ElementKind.VARIABLE_LIST, enclosingElement); |
| 153 | 158 |
| 154 DartType computeType(Compiler compiler) => compiler.types.dynamicType; | 159 DartType computeType(Compiler compiler) => compiler.types.dynamicType; |
| 160 |
| 161 accept(ElementVisitor visitor) => visitor.visitBoxElement(this); |
| 155 } | 162 } |
| 156 | 163 |
| 157 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to | 164 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to |
| 158 // move these classes to elements/modelx.dart or see if we can find a | 165 // move these classes to elements/modelx.dart or see if we can find a |
| 159 // more general solution. | 166 // more general solution. |
| 160 class BoxFieldElement extends ElementX { | 167 class BoxFieldElement extends ElementX { |
| 161 BoxFieldElement(String name, | 168 BoxFieldElement(String name, |
| 162 this.variableElement, | 169 this.variableElement, |
| 163 BoxElement enclosingBox) | 170 BoxElement enclosingBox) |
| 164 : super(name, ElementKind.FIELD, enclosingBox); | 171 : super(name, ElementKind.FIELD, enclosingBox); |
| 165 | 172 |
| 166 DartType computeType(Compiler compiler) { | 173 DartType computeType(Compiler compiler) { |
| 167 return variableElement.computeType(compiler); | 174 return variableElement.computeType(compiler); |
| 168 } | 175 } |
| 169 | 176 |
| 170 final Element variableElement; | 177 final Element variableElement; |
| 178 |
| 179 accept(ElementVisitor visitor) => visitor.visitBoxFieldElement(this); |
| 171 } | 180 } |
| 172 | 181 |
| 173 // TODO(ahe): These classes continuously cause problems. We need to | 182 // TODO(ahe): These classes continuously cause problems. We need to |
| 174 // move these classes to elements/modelx.dart or see if we can find a | 183 // move these classes to elements/modelx.dart or see if we can find a |
| 175 // more general solution. | 184 // more general solution. |
| 176 class ThisElement extends ElementX { | 185 class ThisElement extends ElementX { |
| 177 ThisElement(Element enclosing) | 186 ThisElement(Element enclosing) |
| 178 : super('this', ElementKind.PARAMETER, enclosing); | 187 : super('this', ElementKind.PARAMETER, enclosing); |
| 179 | 188 |
| 180 bool isAssignable() => false; | 189 bool isAssignable() => false; |
| 181 | 190 |
| 182 DartType computeType(Compiler compiler) => compiler.types.dynamicType; | 191 DartType computeType(Compiler compiler) => compiler.types.dynamicType; |
| 183 | 192 |
| 184 // Since there is no declaration corresponding to 'this', use the position of | 193 // Since there is no declaration corresponding to 'this', use the position of |
| 185 // the enclosing method. | 194 // the enclosing method. |
| 186 Token position() => enclosingElement.position(); | 195 Token position() => enclosingElement.position(); |
| 196 |
| 197 accept(ElementVisitor visitor) => visitor.visitThisElement(this); |
| 187 } | 198 } |
| 188 | 199 |
| 189 // TODO(ahe): These classes continuously cause problems. We need to | 200 // TODO(ahe): These classes continuously cause problems. We need to |
| 190 // move these classes to elements/modelx.dart or see if we can find a | 201 // move these classes to elements/modelx.dart or see if we can find a |
| 191 // more general solution. | 202 // more general solution. |
| 192 class CheckVariableElement extends ElementX { | 203 class CheckVariableElement extends ElementX { |
| 193 Element parameter; | 204 Element parameter; |
| 194 CheckVariableElement(String name, this.parameter, Element enclosing) | 205 CheckVariableElement(String name, this.parameter, Element enclosing) |
| 195 : super(name, ElementKind.VARIABLE, enclosing); | 206 : super(name, ElementKind.VARIABLE, enclosing); |
| 196 | 207 |
| 197 DartType computeType(Compiler compiler) => compiler.types.dynamicType; | 208 DartType computeType(Compiler compiler) => compiler.types.dynamicType; |
| 198 | 209 |
| 199 // Since there is no declaration for the synthetic 'check' variable, use | 210 // Since there is no declaration for the synthetic 'check' variable, use |
| 200 // parameter. | 211 // parameter. |
| 201 Token position() => parameter.position(); | 212 Token position() => parameter.position(); |
| 213 |
| 214 accept(ElementVisitor visitor) => visitor.visitCheckVariableElement(this); |
| 202 } | 215 } |
| 203 | 216 |
| 204 // The box-element for a scope, and the captured variables that need to be | 217 // The box-element for a scope, and the captured variables that need to be |
| 205 // stored in the box. | 218 // stored in the box. |
| 206 class ClosureScope { | 219 class ClosureScope { |
| 207 Element boxElement; | 220 Element boxElement; |
| 208 Map<Element, Element> capturedVariableMapping; | 221 Map<Element, Element> capturedVariableMapping; |
| 209 // If the scope is attached to a [For] contains the variables that are | 222 // If the scope is attached to a [For] contains the variables that are |
| 210 // declared in the initializer of the [For] and that need to be boxed. | 223 // declared in the initializer of the [For] and that need to be boxed. |
| 211 // Otherwise contains the empty List. | 224 // Otherwise contains the empty List. |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 } | 840 } |
| 828 | 841 |
| 829 visitTryStatement(TryStatement node) { | 842 visitTryStatement(TryStatement node) { |
| 830 // TODO(ngeoffray): implement finer grain state. | 843 // TODO(ngeoffray): implement finer grain state. |
| 831 bool oldInTryStatement = inTryStatement; | 844 bool oldInTryStatement = inTryStatement; |
| 832 inTryStatement = true; | 845 inTryStatement = true; |
| 833 node.visitChildren(this); | 846 node.visitChildren(this); |
| 834 inTryStatement = oldInTryStatement; | 847 inTryStatement = oldInTryStatement; |
| 835 } | 848 } |
| 836 } | 849 } |
| OLD | NEW |