| 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; |
| 11 | 11 |
| 12 String toString() => "ClosureFieldElement($name)"; | 12 String toString() => "ClosureFieldElement($name)"; |
| 13 } | 13 } |
| 14 | 14 |
| 15 class ClosureClassElement extends ClassElement { |
| 16 ClosureClassElement(Compiler compiler, Element enclosingElement) |
| 17 : super(Compiler.CLOSURE, enclosingElement) { |
| 18 isResolved = true; |
| 19 compiler.closureClass.ensureResolved(compiler); |
| 20 supertype = compiler.closureClass.computeType(compiler); |
| 21 } |
| 22 } |
| 23 |
| 15 // The box-element for a scope, and the captured variables that need to be | 24 // The box-element for a scope, and the captured variables that need to be |
| 16 // stored in the box. | 25 // stored in the box. |
| 17 class ClosureScope { | 26 class ClosureScope { |
| 18 Element boxElement; | 27 Element boxElement; |
| 19 Map<Element, Element> capturedVariableMapping; | 28 Map<Element, Element> capturedVariableMapping; |
| 20 // If the scope is attached to a [For] contains the variables that are | 29 // If the scope is attached to a [For] contains the variables that are |
| 21 // declared in the initializer of the [For] and that need to be boxed. | 30 // declared in the initializer of the [For] and that need to be boxed. |
| 22 // Otherwise contains the empty List. | 31 // Otherwise contains the empty List. |
| 23 List<Element> boxedLoopVariables; | 32 List<Element> boxedLoopVariables; |
| 24 | 33 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 Element element = elements[definition]; | 294 Element element = elements[definition]; |
| 286 if (capturedVariableMapping.containsKey(element)) { | 295 if (capturedVariableMapping.containsKey(element)) { |
| 287 result.add(element); | 296 result.add(element); |
| 288 }; | 297 }; |
| 289 } | 298 } |
| 290 scopeData.boxedLoopVariables = result; | 299 scopeData.boxedLoopVariables = result; |
| 291 } | 300 } |
| 292 | 301 |
| 293 ClosureData globalizeClosure(FunctionExpression node) { | 302 ClosureData globalizeClosure(FunctionExpression node) { |
| 294 FunctionElement element = elements[node]; | 303 FunctionElement element = elements[node]; |
| 295 SourceString name = const SourceString("Closure"); | 304 ClassElement globalizedElement = |
| 296 CompilationUnitElement compilationUnit = element.getCompilationUnit(); | 305 new ClosureClassElement(compiler, element.getCompilationUnit()); |
| 297 ClassElement globalizedElement = new ClassElement(name, compilationUnit); | |
| 298 FunctionElement callElement = | 306 FunctionElement callElement = |
| 299 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, | 307 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, |
| 300 element, | 308 element, |
| 301 globalizedElement); | 309 globalizedElement); |
| 302 globalizedElement.backendMembers = | 310 globalizedElement.backendMembers = |
| 303 const EmptyLink<Element>().prepend(callElement); | 311 const EmptyLink<Element>().prepend(callElement); |
| 304 globalizedElement.isResolved = true; | |
| 305 // TODO(karlklose): create function to get the resolved class object. | |
| 306 ClassElement objectClass = compiler.coreLibrary.find(Types.OBJECT); | |
| 307 globalizedElement.supertype = objectClass.computeType(compiler); | |
| 308 objectClass.ensureResolved(compiler); | |
| 309 // The nested function's 'this' is the same as the one for the outer | 312 // The nested function's 'this' is the same as the one for the outer |
| 310 // function. It could be [null] if we are inside a static method. | 313 // function. It could be [null] if we are inside a static method. |
| 311 Element thisElement = closureData.thisElement; | 314 Element thisElement = closureData.thisElement; |
| 312 return new ClosureData(element, globalizedElement, | 315 return new ClosureData(element, globalizedElement, |
| 313 callElement, thisElement); | 316 callElement, thisElement); |
| 314 } | 317 } |
| 315 | 318 |
| 316 visitFunctionExpression(FunctionExpression node) { | 319 visitFunctionExpression(FunctionExpression node) { |
| 317 Element element = elements[node]; | 320 Element element = elements[node]; |
| 318 if (element.kind === ElementKind.PARAMETER) { | 321 if (element.kind === ElementKind.PARAMETER) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 declareLocal(elements[node]); | 408 declareLocal(elements[node]); |
| 406 } | 409 } |
| 407 | 410 |
| 408 visitTryStatement(TryStatement node) { | 411 visitTryStatement(TryStatement node) { |
| 409 // TODO(ngeoffray): implement finer grain state. | 412 // TODO(ngeoffray): implement finer grain state. |
| 410 inTryCatchOrFinally = true; | 413 inTryCatchOrFinally = true; |
| 411 node.visitChildren(this); | 414 node.visitChildren(this); |
| 412 inTryCatchOrFinally = false; | 415 inTryCatchOrFinally = false; |
| 413 } | 416 } |
| 414 } | 417 } |
| OLD | NEW |