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

Unified Diff: pkg/compiler/lib/src/closure.dart

Issue 1428853004: Use better names for captured variables in closures. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/field_naming_mixin.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/closure.dart
diff --git a/pkg/compiler/lib/src/closure.dart b/pkg/compiler/lib/src/closure.dart
index 00cb34ca1a62dca2496e1f335ff3f9d295c8ab1c..e14adef9debc880a86d00a81fc2d65105fe80fd3 100644
--- a/pkg/compiler/lib/src/closure.dart
+++ b/pkg/compiler/lib/src/closure.dart
@@ -103,7 +103,7 @@ abstract class CapturedVariable implements Element {}
// TODO(ahe): These classes continuously cause problems. We need to
// find a more general solution.
class ClosureFieldElement extends ElementX
- implements FieldElement, CapturedVariable {
+ implements FieldElement, CapturedVariable, PrivatelyNamedJSEntity {
/// The [BoxLocal] or [LocalElement] being accessed through the field.
final Local local;
@@ -120,6 +120,11 @@ class ClosureFieldElement extends ElementX
MemberElement get memberContext => closureClass.methodElement.memberContext;
+ @override
+ Entity get declaredEntity => local;
+ @override
+ Entity get rootOfScope => closureClass;
+
bool get hasNode => false;
Node get node {
@@ -246,10 +251,12 @@ class BoxLocal extends Local {
// TODO(ngeoffray, ahe): These classes continuously cause problems. We need to
// find a more general solution.
class BoxFieldElement extends ElementX
- implements TypedElement, CapturedVariable, FieldElement {
+ implements TypedElement, CapturedVariable, FieldElement,
+ PrivatelyNamedJSEntity {
final BoxLocal box;
- BoxFieldElement(String name, this.variableElement, BoxLocal box)
+ BoxFieldElement(String name, this.variableElement,
+ BoxLocal box)
: this.box = box,
super(name, ElementKind.FIELD, box.executableContext);
@@ -257,6 +264,11 @@ class BoxFieldElement extends ElementX
DartType get type => variableElement.type;
+ @override
+ Entity get declaredEntity => variableElement;
+ @override
+ Entity get rootOfScope => box;
+
final VariableElement variableElement;
accept(ElementVisitor visitor, arg) {
@@ -519,6 +531,8 @@ class ClosureTranslator extends Visitor {
///
/// Also, the names should be distinct from real field names to prevent
/// clashes with selectors for those fields.
+ ///
+ /// These names are not used in generated code, just as element name.
String getClosureVariableName(String name, int id) {
return "_captured_${name}_$id";
}
@@ -532,6 +546,8 @@ class ClosureTranslator extends Visitor {
///
/// Also, the names should be distinct from real field names to prevent
/// clashes with selectors for those fields.
+ ///
+ /// These names are not used in generated code, just as element name.
String getBoxFieldName(int id) {
return "_box_$id";
}
@@ -1134,3 +1150,14 @@ class TypeVariableLocal implements Local {
return typeVariable == other.typeVariable;
}
}
+
+///
+/// Move the below classes to a JS model eventually.
+///
+abstract class JSEntity implements Entity {
+ Entity get declaredEntity;
+}
+
+abstract class PrivatelyNamedJSEntity implements JSEntity {
+ Entity get rootOfScope;
+}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/field_naming_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698