Chromium Code Reviews| 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..35a762b0b66f33573473e9bc2b7b75b5aa845658 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 ThisLocal implements Local { |
| + final ExecutableElement executableContext; |
| + ThisLocal(this.executableContext); |
| + String get name => 'this'; |
| + toString() => 'ThisLocal($executableContext)'; |
| } |
|
asgerf
2015/03/18 13:28:25
There is already a ThisLocal in closure.dart. Can
sra1
2015/03/19 10:42:51
I kept this one (but renamed).
The other one has g
|
| /// 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. |
| /// |
| @@ -404,6 +419,7 @@ abstract class IrBuilder { |
| ClosureEnvironment env}) { |
| _enterClosureEnvironment(env); |
| _enterScope(closureScope); |
| + _createThisParameter(); |
| parameters.forEach(_createFunctionParameter); |
| return _parameters; |
| } |
| @@ -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,14 @@ class DartIrBuilder extends IrBuilder { |
| } |
| } |
| + void _createThisParameter() { |
| + if (state.currentElement.isGenerativeConstructor || |
| + !Elements.isStaticOrTopLevel(state.currentElement)) { |
|
asgerf
2015/03/18 13:28:25
I think this will also create a this parameter for
sra1
2015/03/19 10:42:51
Done.
|
| + state.thisParameter = |
| + new ir.Parameter(new ThisLocal(state.currentElement)); |
| + } |
| + } |
| + |
| void declareLocalVariable(LocalVariableElement variableElement, |
| {ir.Primitive initialValue}) { |
| assert(isOpen); |
| @@ -2102,9 +2126,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 +2174,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 +2237,13 @@ class JsIrBuilder extends IrBuilder { |
| } |
| } |
| + void _createThisParameter() { |
| + if (!Elements.isStaticOrTopLevel(state.currentElement)) { |
| + state.thisParameter = |
| + new ir.Parameter(new ThisLocal(state.currentElement)); |
| + } |
| + } |
| + |
| void declareLocalVariable(LocalElement variableElement, |
| {ir.Primitive initialValue}) { |
| assert(isOpen); |
| @@ -2324,9 +2352,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 +2396,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); |