Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart |
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart |
index 8b81f396caaae6904c467358cdba280ebfbbb126..0ed53c4abb48d5ebe0038167f766ee2096bcbab2 100644 |
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart |
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart |
@@ -252,6 +252,56 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive> |
return null; |
} |
+ /// Construct a method that executes the forwarding call to the target |
+ /// constructor. This is only required, if the forwarding factory |
+ /// constructor can potentially be the target of a reflective call, because |
+ /// the builder shortcuts calls to redirecting factories at the call site |
+ /// (see [JsIrBuilderVisitor.handleConstructorInvoke]). |
+ visitRedirectingFactoryBody(ast.RedirectingFactoryBody node) { |
+ ConstructorElement targetConstructor = |
+ elements.getRedirectingTargetConstructor(node).implementation; |
+ ConstructorElement redirectingConstructor = |
+ irBuilder.state.currentElement.implementation; |
+ List<ir.Primitive> inputs = <ir.Primitive>[]; |
+ FunctionSignature targetSignature = targetConstructor.functionSignature; |
+ FunctionSignature redirectingSignature = |
+ redirectingConstructor.functionSignature; |
+ redirectingSignature.forEachRequiredParameter((ParameterElement parameter) { |
+ inputs.add(irBuilder.environment.lookup(parameter)); |
+ }); |
+ List<Element> targetOptionals = |
+ targetSignature.orderedOptionalParameters; |
+ List<Element> redirectingOptionals = |
+ redirectingSignature.orderedOptionalParameters; |
+ // TODO(karlklose): match named parameters correctly, once the mirror |
+ // system implements them. |
asgerf
2015/07/09 09:47:54
Please use normalizeStaticArguments and get rid of
|
+ int i = 0; |
+ for (; i < redirectingOptionals.length; i++) { |
+ ParameterElement parameter = redirectingOptionals[i]; |
+ inputs.add(irBuilder.environment.lookup(parameter)); |
+ } |
+ for (; i < targetOptionals.length; i++) { |
+ ConstantValue constantValue = getConstantForVariable(targetOptionals[i]); |
+ inputs.add(irBuilder.buildConstant(constantValue)); |
+ } |
+ ClassElement cls = redirectingConstructor.enclosingClass; |
+ InterfaceType targetType = |
+ redirectingConstructor.computeEffectiveTargetType(cls.thisType); |
+ List<String> namedParameters = redirectingSignature.optionalParameters |
+ .where((ParameterElement p) => p.isNamed) |
+ .map((ParameterElement p) => p.name) |
+ .toList(); |
+ CallStructure callStructure = new CallStructure( |
+ redirectingSignature.parameterCount, |
+ namedParameters); |
+ ir.Primitive instance = irBuilder.buildConstructorInvocation( |
+ targetConstructor, |
+ callStructure, |
+ targetType, |
+ inputs); |
+ irBuilder.buildReturn(instance); |
+ } |
+ |
visitFor(ast.For node) { |
List<LocalElement> loopVariables = <LocalElement>[]; |
if (node.initializer is ast.VariableDefinitions) { |