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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1011383003: Use an explicit 'this' parameter instead of 'This' nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: test updates 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/cps_ir/cps_ir_builder.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
index 87203a2b1e5b13c412e29782d33cdc19f7a66513..40cb8ff9451bde2917fe6037de180ee30269e2f0 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
@@ -219,10 +219,24 @@ class IrBuilderDelimitedState {
final ExecutableElement currentElement;
final ir.Continuation returnContinuation = new ir.Continuation.retrn();
+ ir.Parameter _thisParameter;
final List<ir.Definition> functionParameters = <ir.Definition>[];
IrBuilderDelimitedState(this.constantSystem, this.currentElement);
+
+ ir.Parameter get thisParameter => _thisParameter;
+ void set thisParameter(ir.Parameter value) {
+ assert(_thisParameter == null);
+ _thisParameter = value;
+ }
+}
+
+class ThisParameterLocal implements Local {
+ final ExecutableElement executableContext;
+ ThisParameterLocal(this.executableContext);
+ String get name => 'this';
+ toString() => 'ThisParameterLocal($executableContext)';
}
/// A factory for building the cps IR.
@@ -296,6 +310,7 @@ abstract class IrBuilder {
/// Add the given function parameter to the IR, and bind it in the environment
/// or put it in its box, if necessary.
void _createFunctionParameter(ParameterElement parameterElement);
+ void _createThisParameter();
/// Creates an access to the receiver from the current (or enclosing) method.
///
@@ -402,6 +417,7 @@ abstract class IrBuilder {
List<ir.Primitive> buildFunctionHeader(Iterable<ParameterElement> parameters,
{ClosureScope closureScope,
ClosureEnvironment env}) {
+ _createThisParameter();
_enterClosureEnvironment(env);
_enterScope(closureScope);
parameters.forEach(_createFunctionParameter);
@@ -658,11 +674,11 @@ abstract class IrBuilder {
message: "Local constants for abstract method $element: "
"${state.localConstants}"));
return new ir.FunctionDefinition.abstract(
- element, state.functionParameters, defaults);
+ element, state.thisParameter, state.functionParameters, defaults);
} else {
ir.RunnableBody body = makeRunnableBody();
return new ir.FunctionDefinition(
- element, state.functionParameters, body,
+ element, state.thisParameter, state.functionParameters, body,
state.localConstants, defaults);
}
}
@@ -686,7 +702,7 @@ abstract class IrBuilder {
FunctionElement element = state.currentElement;
ir.RunnableBody body = makeRunnableBody();
return new ir.ConstructorDefinition(
- element, state.functionParameters, body, initializers,
+ element, state.thisParameter, state.functionParameters, body, initializers,
state.localConstants, defaults);
}
@@ -2037,6 +2053,15 @@ class DartIrBuilder extends IrBuilder {
}
}
+ void _createThisParameter() {
+ if (state.currentElement.isGenerativeConstructor ||
+ !(Elements.isStaticOrTopLevel(state.currentElement) ||
+ state.currentElement.isLocal)) {
+ state.thisParameter =
+ new ir.Parameter(new ThisParameterLocal(state.currentElement));
+ }
+ }
+
void declareLocalVariable(LocalVariableElement variableElement,
{ir.Primitive initialValue}) {
assert(isOpen);
@@ -2102,9 +2127,7 @@ class DartIrBuilder extends IrBuilder {
}
ir.Primitive buildThis() {
- ir.Primitive thisPrim = new ir.This();
- add(new ir.LetPrim(thisPrim));
- return thisPrim;
+ return state.thisParameter;
}
ir.Primitive buildSuperInvocation(Element target,
@@ -2152,8 +2175,7 @@ class JsIrBuilder extends IrBuilder {
if (env == null) return;
// Obtain a reference to the function object (this).
- ir.Primitive thisPrim = new ir.This();
- add(new ir.LetPrim(thisPrim));
+ ir.Parameter thisPrim = state.thisParameter;
// Obtain access to the free variables.
env.freeVariables.forEach((Local local, ClosureLocation location) {
@@ -2216,6 +2238,13 @@ class JsIrBuilder extends IrBuilder {
}
}
+ void _createThisParameter() {
+ if (Element.isStaticOrTopLevel(state.currentElement)) return;
+ if (state.currentElement.isLocal) return;
+ state.thisParameter =
+ new ir.Parameter(new ThisParameterLocal(state.currentElement));
+ }
+
void declareLocalVariable(LocalElement variableElement,
{ir.Primitive initialValue}) {
assert(isOpen);
@@ -2324,9 +2353,7 @@ class JsIrBuilder extends IrBuilder {
ir.Primitive buildThis() {
if (jsState.receiver != null) return jsState.receiver;
- ir.Primitive thisPrim = new ir.This();
- add(new ir.LetPrim(thisPrim));
- return thisPrim;
+ return state.thisParameter;
}
ir.Primitive buildSuperInvocation(Element target,
@@ -2370,6 +2397,7 @@ class JsIrBuilder extends IrBuilder {
/// instead of being created in the header.
void buildConstructorBodyHeader(Iterable<Local> parameters,
ClosureScope closureScope) {
+ _createThisParameter();
for (Local param in parameters) {
ir.Parameter parameter = createLocalParameter(param);
state.functionParameters.add(parameter);

Powered by Google App Engine
This is Rietveld 408576698