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

Unified Diff: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart

Issue 1018403002: Revert "Use an explicit 'this' parameter instead of 'This' nodes." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
diff --git a/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart b/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
index 640017c08b035f504903e7d3303cef71e30f08ad..8017ba65f47139a2866f32c6084ffe7b5592055c 100644
--- a/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
+++ b/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
@@ -67,8 +67,6 @@ class Builder implements cps_ir.Visitor<Node> {
List<cps_ir.Continuation> safeForInlining = <cps_ir.Continuation>[];
ExecutableElement currentElement;
- /// The 'this' Parameter for currentElement or the enclosing method.
- cps_ir.Parameter thisParameter;
cps_ir.Continuation returnContinuation;
Builder parent;
@@ -122,10 +120,7 @@ class Builder implements cps_ir.Visitor<Node> {
/// referred to by [reference].
/// This increments the reference count for the given variable, so the
/// returned expression must be used in the tree.
- Expression getVariableUse(cps_ir.Reference<cps_ir.Primitive> reference) {
- if (thisParameter != null && reference.definition == thisParameter) {
- return new This();
- }
+ VariableUse getVariableUse(cps_ir.Reference<cps_ir.Primitive> reference) {
Variable variable = getVariable(reference.definition);
if (variable == null) {
// Note: this may fail because you forgot to implement a visit-function
@@ -175,12 +170,6 @@ class Builder implements cps_ir.Visitor<Node> {
FunctionDefinition buildFunction(cps_ir.FunctionDefinition node) {
currentElement = node.element;
- if (parent != null) {
- // Local function's 'this' refers to enclosing method's 'this'
- thisParameter = parent.thisParameter;
- } else {
- thisParameter = node.thisParameter;
- }
List<Variable> parameters =
node.parameters.map(addFunctionParameter).toList();
Statement body;
@@ -196,7 +185,6 @@ class Builder implements cps_ir.Visitor<Node> {
ConstructorDefinition buildConstructor(cps_ir.ConstructorDefinition node) {
currentElement = node.element;
- thisParameter = node.thisParameter;
List<Variable> parameters =
node.parameters.map(addFunctionParameter).toList();
List<Initializer> initializers;
@@ -231,11 +219,11 @@ class Builder implements cps_ir.Visitor<Node> {
///
/// The `readCount` of these variables will not be incremented. Instead,
/// [buildPhiAssignments] will handle the increment, if necessary.
- /* List<Variable> translatePhiArguments(List<cps_ir.Reference> args) {
+ List<Variable> translatePhiArguments(List<cps_ir.Reference> args) {
return new List<Variable>.generate(args.length,
(int index) => getVariable(args[index].definition),
growable: false);
- }*/
+ }
Statement buildContinuationAssignment(
cps_ir.Parameter parameter,
@@ -256,7 +244,7 @@ class Builder implements cps_ir.Visitor<Node> {
/// then continues at the statement created by [buildRest].
Statement buildPhiAssignments(
List<cps_ir.Parameter> parameters,
- List<Expression> arguments,
+ List<Variable> arguments,
Statement buildRest()) {
assert(parameters.length == arguments.length);
// We want a parallel assignment to all parameters simultaneously.
@@ -270,51 +258,43 @@ class Builder implements cps_ir.Visitor<Node> {
Map<Variable, List<int>> rightHand = <Variable, List<int>>{};
for (int i = 0; i < parameters.length; i++) {
Variable param = getVariable(parameters[i]);
- Expression arg = arguments[i];
- if (arg is VariableUse) {
- if (param == null || param == arg.variable) {
- // No assignment necessary.
- --arg.variable.readCount;
- continue;
- }
- // v1 = v0
- List<int> list = rightHand[arg.variable];
- if (list == null) {
- rightHand[arg.variable] = list = <int>[];
- }
- list.add(i);
- } else {
- // v1 = this;
+ Variable arg = arguments[i];
+ if (param == null || param == arg) {
+ continue; // No assignment necessary.
+ }
+ List<int> list = rightHand[arg];
+ if (list == null) {
+ rightHand[arg] = list = <int>[];
}
+ list.add(i);
}
Statement first, current;
- void addAssignment(Variable dst, Expression src) {
+ void addAssignment(Variable dst, Variable src) {
if (first == null) {
- first = current = new Assign(dst, src, null);
+ first = current = new Assign(dst, new VariableUse(src), null);
} else {
- current = current.next = new Assign(dst, src, null);
+ current = current.next = new Assign(dst, new VariableUse(src), null);
}
}
- List<Expression> assignmentSrc = new List<Expression>(parameters.length);
- List<bool> done = new List<bool>.filled(parameters.length, false);
+ List<Variable> assignmentSrc = new List<Variable>(parameters.length);
+ List<bool> done = new List<bool>(parameters.length);
void visitAssignment(int i) {
- if (done[i]) {
+ if (done[i] == true) {
return;
}
Variable param = getVariable(parameters[i]);
- Expression arg = arguments[i];
- if (param == null || (arg is VariableUse && param == arg.variable)) {
+ Variable arg = arguments[i];
+ if (param == null || param == arg) {
return; // No assignment necessary.
}
if (assignmentSrc[i] != null) {
// Cycle found; store argument in a temporary variable.
// The temporary will then be used as right-hand side when the
// assignment gets added.
- VariableUse source = assignmentSrc[i];
- if (source.variable != phiTempVar) { // Only move to temporary once.
- assignmentSrc[i] = new VariableUse(phiTempVar);
+ if (assignmentSrc[i] != phiTempVar) { // Only move to temporary once.
+ assignmentSrc[i] = phiTempVar;
addAssignment(phiTempVar, arg);
}
return;
@@ -331,7 +311,7 @@ class Builder implements cps_ir.Visitor<Node> {
}
for (int i = 0; i < parameters.length; i++) {
- if (!done[i]) {
+ if (done[i] == null) {
visitAssignment(i);
}
}
@@ -546,7 +526,7 @@ class Builder implements cps_ir.Visitor<Node> {
assert(node.arguments.length == 1);
return new Return(getVariableUse(node.arguments.single));
} else {
- List<Expression> arguments = translateArguments(node.arguments);
+ List<Variable> arguments = translatePhiArguments(node.arguments);
return buildPhiAssignments(cont.parameters, arguments,
() {
// Translate invocations of recursive and non-recursive
@@ -595,6 +575,10 @@ class Builder implements cps_ir.Visitor<Node> {
return new Constant(node.expression);
}
+ Expression visitThis(cps_ir.This node) {
+ return new This();
+ }
+
Expression visitReifyTypeVar(cps_ir.ReifyTypeVar node) {
return new ReifyTypeVar(node.typeVariable);
}
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/dart_backend.dart ('k') | pkg/compiler/lib/src/tree_ir/tree_ir_integrity.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698