Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: lib/compiler/implementation/closure.dart

Issue 10916079: Allow access to super fields inside a closure. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/js_backend/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.methodElement,
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
80 /**
81 * The most outer method this closure is declared into.
82 */
83 Element methodElement;
77 } 84 }
78 85
79 class BoxElement extends Element { 86 class BoxElement extends Element {
80 BoxElement(SourceString name, Element enclosingElement) 87 BoxElement(SourceString name, Element enclosingElement)
81 : super(name, ElementKind.VARIABLE, enclosingElement); 88 : super(name, ElementKind.VARIABLE, enclosingElement);
82 } 89 }
83 90
84 class ThisElement extends Element { 91 class ThisElement extends Element {
85 ThisElement(Element enclosing) 92 ThisElement(Element enclosing)
86 : super(const SourceString('this'), ElementKind.PARAMETER, enclosing); 93 : super(const SourceString('this'), ElementKind.PARAMETER, enclosing);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 result.add(element); 395 result.add(element);
389 }; 396 };
390 } 397 }
391 scopeData.boxedLoopVariables = result; 398 scopeData.boxedLoopVariables = result;
392 } 399 }
393 400
394 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { 401 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) {
395 SourceString closureName = 402 SourceString closureName =
396 new SourceString(compiler.namer.closureName(element)); 403 new SourceString(compiler.namer.closureName(element));
397 ClassElement globalizedElement = new ClosureClassElement( 404 ClassElement globalizedElement = new ClosureClassElement(
398 closureName, compiler, element.getCompilationUnit()); 405 closureName, compiler, element, element.getCompilationUnit());
399 FunctionElement callElement = 406 FunctionElement callElement =
400 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, 407 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME,
401 element, 408 element,
402 globalizedElement); 409 globalizedElement);
403 globalizedElement.backendMembers = 410 globalizedElement.backendMembers =
404 const EmptyLink<Element>().prepend(callElement); 411 const EmptyLink<Element>().prepend(callElement);
405 // The nested function's 'this' is the same as the one for the outer 412 // 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. 413 // function. It could be [null] if we are inside a static method.
407 Element thisElement = closureData.thisElement; 414 Element thisElement = closureData.thisElement;
408 return new ClosureClassMap(element, globalizedElement, 415 return new ClosureClassMap(element, globalizedElement,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 506 }
500 507
501 visitTryStatement(TryStatement node) { 508 visitTryStatement(TryStatement node) {
502 // TODO(ngeoffray): implement finer grain state. 509 // TODO(ngeoffray): implement finer grain state.
503 bool oldInTryStatement = inTryStatement; 510 bool oldInTryStatement = inTryStatement;
504 inTryStatement = true; 511 inTryStatement = true;
505 node.visitChildren(this); 512 node.visitChildren(this);
506 inTryStatement = oldInTryStatement; 513 inTryStatement = oldInTryStatement;
507 } 514 }
508 } 515 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/js_backend/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698