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

Side by Side Diff: pkg/compiler/lib/src/closure.dart

Issue 2956393002: Entity-ify BoxLocal. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | no next file » | 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 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 accept(ElementVisitor visitor, arg) { 493 accept(ElementVisitor visitor, arg) {
494 return visitor.visitClosureClassElement(this, arg); 494 return visitor.visitClosureClassElement(this, arg);
495 } 495 }
496 } 496 }
497 497
498 /// A local variable that contains the box object holding the [BoxFieldElement] 498 /// A local variable that contains the box object holding the [BoxFieldElement]
499 /// fields. 499 /// fields.
500 class BoxLocal extends Local { 500 class BoxLocal extends Local {
501 final String name; 501 final String name;
502 final ExecutableElement executableContext; 502 final Entity executableContext;
503 final MemberEntity memberContext;
503 504
504 final int hashCode = _nextHashCode = (_nextHashCode + 10007).toUnsigned(30); 505 final int hashCode = _nextHashCode = (_nextHashCode + 10007).toUnsigned(30);
505 static int _nextHashCode = 0; 506 static int _nextHashCode = 0;
506 507
507 BoxLocal(this.name, this.executableContext); 508 BoxLocal(this.name, this.executableContext, this.memberContext);
508
509 @override
510 MemberElement get memberContext => executableContext.memberContext;
511 509
512 String toString() => 'BoxLocal($name)'; 510 String toString() => 'BoxLocal($name)';
513 } 511 }
514 512
515 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to 513 // TODO(ngeoffray, ahe): These classes continuously cause problems. We need to
516 // find a more general solution. 514 // find a more general solution.
517 class BoxFieldElement extends ElementX 515 class BoxFieldElement extends ElementX
518 implements TypedElement, FieldElement, PrivatelyNamedJSEntity { 516 implements TypedElement, FieldElement, PrivatelyNamedJSEntity {
519 final LocalVariableElement variableElement; 517 final LocalVariableElement variableElement;
520 final BoxLocal box; 518 final BoxLocal box;
(...skipping 21 matching lines...) Expand all
542 540
543 @override 541 @override
544 bool get hasResolvedAst => false; 542 bool get hasResolvedAst => false;
545 543
546 @override 544 @override
547 Expression get initializer { 545 Expression get initializer {
548 throw new UnsupportedError("BoxFieldElement.initializer"); 546 throw new UnsupportedError("BoxFieldElement.initializer");
549 } 547 }
550 548
551 @override 549 @override
552 MemberElement get memberContext => box.executableContext.memberContext; 550 MemberElement get memberContext => box.memberContext;
553 551
554 @override 552 @override
555 List<FunctionElement> get nestedClosures => const <FunctionElement>[]; 553 List<FunctionElement> get nestedClosures => const <FunctionElement>[];
556 554
557 @override 555 @override
558 VariableDefinitions get node { 556 VariableDefinitions get node {
559 throw new UnsupportedError("BoxFieldElement.node"); 557 throw new UnsupportedError("BoxFieldElement.node");
560 } 558 }
561 559
562 @override 560 @override
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 void attachCapturedScopeVariables(Node node) { 1219 void attachCapturedScopeVariables(Node node) {
1222 BoxLocal box = null; 1220 BoxLocal box = null;
1223 Map<LocalVariableElement, BoxFieldElement> scopeMapping = 1221 Map<LocalVariableElement, BoxFieldElement> scopeMapping =
1224 new Map<LocalVariableElement, BoxFieldElement>(); 1222 new Map<LocalVariableElement, BoxFieldElement>();
1225 1223
1226 void boxCapturedVariable(LocalVariableElement variable) { 1224 void boxCapturedVariable(LocalVariableElement variable) {
1227 if (isCapturedVariable(variable)) { 1225 if (isCapturedVariable(variable)) {
1228 if (box == null) { 1226 if (box == null) {
1229 // TODO(floitsch): construct better box names. 1227 // TODO(floitsch): construct better box names.
1230 String boxName = getBoxFieldName(closureFieldCounter++); 1228 String boxName = getBoxFieldName(closureFieldCounter++);
1231 box = new BoxLocal(boxName, executableContext); 1229 box = new BoxLocal(
1230 boxName, executableContext, executableContext.memberContext);
1232 } 1231 }
1233 String elementName = variable.name; 1232 String elementName = variable.name;
1234 String boxedName = 1233 String boxedName =
1235 getClosureVariableName(elementName, boxedFieldCounter++); 1234 getClosureVariableName(elementName, boxedFieldCounter++);
1236 // TODO(kasperl): Should this be a FieldElement instead? 1235 // TODO(kasperl): Should this be a FieldElement instead?
1237 BoxFieldElement boxed = new BoxFieldElement(boxedName, variable, box); 1236 BoxFieldElement boxed = new BoxFieldElement(boxedName, variable, box);
1238 scopeMapping[variable] = boxed; 1237 scopeMapping[variable] = boxed;
1239 setCapturedVariableBoxField(variable, boxed); 1238 setCapturedVariableBoxField(variable, boxed);
1240 } 1239 }
1241 } 1240 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 /// 1524 ///
1526 /// Move the below classes to a JS model eventually. 1525 /// Move the below classes to a JS model eventually.
1527 /// 1526 ///
1528 abstract class JSEntity implements MemberEntity { 1527 abstract class JSEntity implements MemberEntity {
1529 Local get declaredEntity; 1528 Local get declaredEntity;
1530 } 1529 }
1531 1530
1532 abstract class PrivatelyNamedJSEntity implements JSEntity { 1531 abstract class PrivatelyNamedJSEntity implements JSEntity {
1533 Entity get rootOfScope; 1532 Entity get rootOfScope;
1534 } 1533 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698