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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 bool isInstanceMember() => true; | 54 bool isInstanceMember() => true; |
| 55 bool isAssignable() => false; | 55 bool isAssignable() => false; |
| 56 | 56 |
| 57 String toString() => "ClosureFieldElement($name)"; | 57 String toString() => "ClosureFieldElement($name)"; |
| 58 } | 58 } |
| 59 | 59 |
| 60 class ClosureClassElement extends ClassElement { | 60 class ClosureClassElement extends ClassElement { |
| 61 ClosureClassElement(SourceString name, | 61 ClosureClassElement(SourceString name, |
| 62 Compiler compiler, | 62 Compiler compiler, |
| 63 this.originalElement, | |
| 63 Element enclosingElement) | 64 Element enclosingElement) |
| 64 : super(name, | 65 : super(name, |
| 65 enclosingElement, | 66 enclosingElement, |
| 66 // By assigning a fresh class-id we make sure that the hashcode | 67 // By assigning a fresh class-id we make sure that the hashcode |
| 67 // is unique, but also emit closure classes after all other | 68 // is unique, but also emit closure classes after all other |
| 68 // classes (since the emitter sorts classes by their id). | 69 // classes (since the emitter sorts classes by their id). |
| 69 compiler.getNextFreeClassId(), | 70 compiler.getNextFreeClassId(), |
| 70 STATE_DONE) { | 71 STATE_DONE) { |
| 71 compiler.closureClass.ensureResolved(compiler); | 72 compiler.closureClass.ensureResolved(compiler); |
| 72 supertype = compiler.closureClass.computeType(compiler); | 73 supertype = compiler.closureClass.computeType(compiler); |
| 73 interfaces = const EmptyLink<DartType>(); | 74 interfaces = const EmptyLink<DartType>(); |
| 74 allSupertypes = new Link<DartType>(supertype); | 75 allSupertypes = new Link<DartType>(supertype); |
| 75 } | 76 } |
| 77 | |
| 76 bool isClosure() => true; | 78 bool isClosure() => true; |
| 79 Element originalElement; | |
|
floitsch
2012/09/03 16:59:16
methodElement ?
It is not really the "original".
ngeoffray
2012/09/04 07:06:09
Done.
| |
| 77 } | 80 } |
| 78 | 81 |
| 79 class BoxElement extends Element { | 82 class BoxElement extends Element { |
| 80 BoxElement(SourceString name, Element enclosingElement) | 83 BoxElement(SourceString name, Element enclosingElement) |
| 81 : super(name, ElementKind.VARIABLE, enclosingElement); | 84 : super(name, ElementKind.VARIABLE, enclosingElement); |
| 82 } | 85 } |
| 83 | 86 |
| 84 class ThisElement extends Element { | 87 class ThisElement extends Element { |
| 85 ThisElement(Element enclosing) | 88 ThisElement(Element enclosing) |
| 86 : super(const SourceString('this'), ElementKind.PARAMETER, enclosing); | 89 : super(const SourceString('this'), ElementKind.PARAMETER, enclosing); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 result.add(element); | 391 result.add(element); |
| 389 }; | 392 }; |
| 390 } | 393 } |
| 391 scopeData.boxedLoopVariables = result; | 394 scopeData.boxedLoopVariables = result; |
| 392 } | 395 } |
| 393 | 396 |
| 394 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { | 397 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { |
| 395 SourceString closureName = | 398 SourceString closureName = |
| 396 new SourceString(compiler.namer.closureName(element)); | 399 new SourceString(compiler.namer.closureName(element)); |
| 397 ClassElement globalizedElement = new ClosureClassElement( | 400 ClassElement globalizedElement = new ClosureClassElement( |
| 398 closureName, compiler, element.getCompilationUnit()); | 401 closureName, compiler, element, element.getCompilationUnit()); |
| 399 FunctionElement callElement = | 402 FunctionElement callElement = |
| 400 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, | 403 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, |
| 401 element, | 404 element, |
| 402 globalizedElement); | 405 globalizedElement); |
| 403 globalizedElement.backendMembers = | 406 globalizedElement.backendMembers = |
| 404 const EmptyLink<Element>().prepend(callElement); | 407 const EmptyLink<Element>().prepend(callElement); |
| 405 // The nested function's 'this' is the same as the one for the outer | 408 // The nested function's 'this' is the same as the one for the outer |
| 406 // function. It could be [null] if we are inside a static method. | 409 // function. It could be [null] if we are inside a static method. |
| 407 Element thisElement = closureData.thisElement; | 410 Element thisElement = closureData.thisElement; |
| 408 return new ClosureClassMap(element, globalizedElement, | 411 return new ClosureClassMap(element, globalizedElement, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 } | 502 } |
| 500 | 503 |
| 501 visitTryStatement(TryStatement node) { | 504 visitTryStatement(TryStatement node) { |
| 502 // TODO(ngeoffray): implement finer grain state. | 505 // TODO(ngeoffray): implement finer grain state. |
| 503 bool oldInTryStatement = inTryStatement; | 506 bool oldInTryStatement = inTryStatement; |
| 504 inTryStatement = true; | 507 inTryStatement = true; |
| 505 node.visitChildren(this); | 508 node.visitChildren(this); |
| 506 inTryStatement = oldInTryStatement; | 509 inTryStatement = oldInTryStatement; |
| 507 } | 510 } |
| 508 } | 511 } |
| OLD | NEW |