| 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 import 'common/names.dart' show Identifiers; | 5 import 'common/names.dart' show Identifiers; |
| 6 import 'common/resolution.dart' show ParsingContext, Resolution; | 6 import 'common/resolution.dart' show ParsingContext, Resolution; |
| 7 import 'common/tasks.dart' show CompilerTask, Measurer; | 7 import 'common/tasks.dart' show CompilerTask, Measurer; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compiler.dart' show Compiler; | 9 import 'compiler.dart' show Compiler; |
| 10 import 'constants/expressions.dart'; | 10 import 'constants/expressions.dart'; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 534 |
| 535 accept(ElementVisitor visitor, arg) { | 535 accept(ElementVisitor visitor, arg) { |
| 536 return visitor.visitClosureClassElement(this, arg); | 536 return visitor.visitClosureClassElement(this, arg); |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 /// A local variable that contains the box object holding the [BoxFieldElement] | 540 /// A local variable that contains the box object holding the [BoxFieldElement] |
| 541 /// fields. | 541 /// fields. |
| 542 class BoxLocal extends Local { | 542 class BoxLocal extends Local { |
| 543 final String name; | 543 final String name; |
| 544 final Entity executableContext; | |
| 545 final MemberEntity memberContext; | 544 final MemberEntity memberContext; |
| 546 | 545 |
| 547 final int hashCode = _nextHashCode = (_nextHashCode + 10007).toUnsigned(30); | 546 final int hashCode = _nextHashCode = (_nextHashCode + 10007).toUnsigned(30); |
| 548 static int _nextHashCode = 0; | 547 static int _nextHashCode = 0; |
| 549 | 548 |
| 550 BoxLocal(this.name, this.executableContext, this.memberContext); | 549 BoxLocal(this.name, this.memberContext); |
| 550 |
| 551 Entity get executableContext => memberContext; |
| 551 | 552 |
| 552 String toString() => 'BoxLocal($name)'; | 553 String toString() => 'BoxLocal($name)'; |
| 553 } | 554 } |
| 554 | 555 |
| 555 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to | 556 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to |
| 556 // find a more general solution. | 557 // find a more general solution. |
| 557 class BoxFieldElement extends ElementX | 558 class BoxFieldElement extends ElementX |
| 558 implements TypedElement, FieldElement, PrivatelyNamedJSEntity { | 559 implements TypedElement, FieldElement, PrivatelyNamedJSEntity { |
| 559 final LocalVariableElement variableElement; | 560 final LocalVariableElement variableElement; |
| 560 final BoxLocal box; | 561 final BoxLocal box; |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 void attachCapturedScopeVariables(Node node) { | 1254 void attachCapturedScopeVariables(Node node) { |
| 1254 BoxLocal box = null; | 1255 BoxLocal box = null; |
| 1255 Map<LocalVariableElement, BoxFieldElement> scopeMapping = | 1256 Map<LocalVariableElement, BoxFieldElement> scopeMapping = |
| 1256 new Map<LocalVariableElement, BoxFieldElement>(); | 1257 new Map<LocalVariableElement, BoxFieldElement>(); |
| 1257 | 1258 |
| 1258 void boxCapturedVariable(LocalVariableElement variable) { | 1259 void boxCapturedVariable(LocalVariableElement variable) { |
| 1259 if (isCapturedVariable(variable)) { | 1260 if (isCapturedVariable(variable)) { |
| 1260 if (box == null) { | 1261 if (box == null) { |
| 1261 // TODO(floitsch): construct better box names. | 1262 // TODO(floitsch): construct better box names. |
| 1262 String boxName = getBoxFieldName(closureFieldCounter++); | 1263 String boxName = getBoxFieldName(closureFieldCounter++); |
| 1263 box = new BoxLocal( | 1264 box = new BoxLocal(boxName, executableContext.memberContext); |
| 1264 boxName, executableContext, executableContext.memberContext); | |
| 1265 } | 1265 } |
| 1266 String elementName = variable.name; | 1266 String elementName = variable.name; |
| 1267 String boxedName = | 1267 String boxedName = |
| 1268 getClosureVariableName(elementName, boxedFieldCounter++); | 1268 getClosureVariableName(elementName, boxedFieldCounter++); |
| 1269 // TODO(kasperl): Should this be a FieldElement instead? | 1269 // TODO(kasperl): Should this be a FieldElement instead? |
| 1270 BoxFieldElement boxed = new BoxFieldElement(boxedName, variable, box); | 1270 BoxFieldElement boxed = new BoxFieldElement(boxedName, variable, box); |
| 1271 scopeMapping[variable] = boxed; | 1271 scopeMapping[variable] = boxed; |
| 1272 setCapturedVariableBoxField(variable, boxed); | 1272 setCapturedVariableBoxField(variable, boxed); |
| 1273 } | 1273 } |
| 1274 } | 1274 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 /// | 1552 /// |
| 1553 /// Move the below classes to a JS model eventually. | 1553 /// Move the below classes to a JS model eventually. |
| 1554 /// | 1554 /// |
| 1555 abstract class JSEntity implements MemberEntity { | 1555 abstract class JSEntity implements MemberEntity { |
| 1556 Local get declaredEntity; | 1556 Local get declaredEntity; |
| 1557 } | 1557 } |
| 1558 | 1558 |
| 1559 abstract class PrivatelyNamedJSEntity implements JSEntity { | 1559 abstract class PrivatelyNamedJSEntity implements JSEntity { |
| 1560 Entity get rootOfScope; | 1560 Entity get rootOfScope; |
| 1561 } | 1561 } |
| OLD | NEW |