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

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: Address 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..797a68964ff36b79a630339c7319a327b5397aac 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,42 @@ 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> arguments = <ir.Primitive>[];
+ FunctionSignature redirectingSignature =
+ redirectingConstructor.functionSignature;
+ List<String> namedParameters = <String>[];
+ redirectingSignature.forEachParameter((ParameterElement parameter) {
+ arguments.add(irBuilder.environment.lookup(parameter));
+ if (parameter.isNamed) {
+ namedParameters.add(parameter.name);
+ }
+ });
+ ClassElement cls = redirectingConstructor.enclosingClass;
+ InterfaceType targetType =
+ redirectingConstructor.computeEffectiveTargetType(cls.thisType);
+ CallStructure callStructure = new CallStructure(
+ redirectingSignature.parameterCount,
+ namedParameters);
+ arguments = normalizeStaticArguments(callStructure, targetConstructor,
+ arguments);
+ ir.Primitive instance = irBuilder.buildConstructorInvocation(
+ targetConstructor,
+ callStructure,
+ targetType,
+ arguments);
+ 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