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/cps_ir/cps_ir_builder_task.dart

Issue 1227873004: dart2js cps: Implement compilation of redirecting factory constructors for reflection. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add another comment. Created 5 years, 5 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
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698