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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 12093019: Support type variables on redirecting factory constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of ssa; 5 part of ssa;
6 6
7 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 } else { 3224 } else {
3225 return HType.UNKNOWN; 3225 return HType.UNKNOWN;
3226 } 3226 }
3227 } 3227 }
3228 3228
3229 Element constructor = elements[node]; 3229 Element constructor = elements[node];
3230 Selector selector = elements.getSelector(node); 3230 Selector selector = elements.getSelector(node);
3231 if (compiler.enqueuer.resolution.getCachedElements(constructor) == null) { 3231 if (compiler.enqueuer.resolution.getCachedElements(constructor) == null) {
3232 compiler.internalError("Unresolved element: $constructor", node: node); 3232 compiler.internalError("Unresolved element: $constructor", node: node);
3233 } 3233 }
3234
3235 // Compute the right target and type for redirecting generative and
ngeoffray 2013/02/18 09:44:28 What's a redirecting generative constructor?
karlklose 2013/02/19 13:20:27 One that uses this(...), but they never actually e
3236 // factory constructors.
3234 FunctionElement functionElement = constructor; 3237 FunctionElement functionElement = constructor;
3235 constructor = functionElement.redirectionTarget; 3238 if (functionElement.redirectionTarget != functionElement) {
ngeoffray 2013/02/18 09:44:28 Shouldn't you get the redirectionTarget until it's
karlklose 2013/02/19 13:20:27 Yes. It does not matter currently, because we bail
3239 FunctionExpression functionNode = constructor.parseNode(compiler);
3240 if (functionNode.isRedirectingFactory) {
3241 // Lookup the type expression used in the body and substitute the type
3242 // variables with the call's type arguments in it.
3243 Return redirectionNode = functionNode.body;
3244 TreeElements treeElements =
3245 compiler.enqueuer.resolution.getCachedElements(
3246 constructor.declaration);
3247 ClassElement targetClass = constructor.getEnclosingClass();
3248 DartType targetType = treeElements.getType(redirectionNode.expression);
3249 Link<DartType> typeVariables = targetClass.typeVariables;
3250 Link<DartType> typeArguments = type.typeArguments;
3251 type = targetType.subst(typeArguments, typeVariables);
3252 }
3253 constructor = functionElement.redirectionTarget;
3254 }
3255
3256 // TODO(karlklose): move this type registration to the codegen.
3257 compiler.codegenWorld.instantiatedTypes.add(type);
3258
3236 // TODO(5346): Try to avoid the need for calling [declaration] before 3259 // TODO(5346): Try to avoid the need for calling [declaration] before
3237 // creating an [HStatic]. 3260 // creating an [HStatic].
3238 HInstruction target = new HStatic(constructor.declaration); 3261 HInstruction target = new HStatic(constructor.declaration);
3239 add(target); 3262 add(target);
3240 var inputs = <HInstruction>[]; 3263 var inputs = <HInstruction>[];
3241 inputs.add(target); 3264 inputs.add(target);
3242 // TODO(5347): Try to avoid the need for calling [implementation] before 3265 // TODO(5347): Try to avoid the need for calling [implementation] before
3243 // calling [addStaticSendArgumentsToList]. 3266 // calling [addStaticSendArgumentsToList].
3244 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, 3267 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments,
3245 constructor.implementation, 3268 constructor.implementation,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3484 Constant constant = handler.compileNodeWithDefinitions(node, elements); 3507 Constant constant = handler.compileNodeWithDefinitions(node, elements);
3485 stack.add(graph.addConstant(constant)); 3508 stack.add(graph.addConstant(constant));
3486 } else { 3509 } else {
3487 DartType type = elements.getType(node); 3510 DartType type = elements.getType(node);
3488 if (compiler.enableTypeAssertions && type.isMalformed) { 3511 if (compiler.enableTypeAssertions && type.isMalformed) {
3489 String reasons = Types.fetchReasonsFromMalformedType(type); 3512 String reasons = Types.fetchReasonsFromMalformedType(type);
3490 // TODO(johnniwinther): Change to resemble type errors from bounds check 3513 // TODO(johnniwinther): Change to resemble type errors from bounds check
3491 // on type arguments. 3514 // on type arguments.
3492 generateRuntimeError(node, '$type is malformed: $reasons'); 3515 generateRuntimeError(node, '$type is malformed: $reasons');
3493 } else { 3516 } else {
3494 // TODO(karlklose): move this type registration to the codegen.
3495 compiler.codegenWorld.instantiatedTypes.add(type);
3496 visitNewSend(node.send, type); 3517 visitNewSend(node.send, type);
3497 } 3518 }
3498 } 3519 }
3499 } 3520 }
3500 3521
3501 HInvokeDynamicMethod buildInvokeDynamic(Node node, 3522 HInvokeDynamicMethod buildInvokeDynamic(Node node,
3502 Selector selector, 3523 Selector selector,
3503 HInstruction receiver, 3524 HInstruction receiver,
3504 List<HInstruction> arguments) { 3525 List<HInstruction> arguments) {
3505 Set<ClassElement> interceptedClasses = getInterceptedClassesOn(selector); 3526 Set<ClassElement> interceptedClasses = getInterceptedClassesOn(selector);
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
4951 new HSubGraphBlockInformation(elseBranch.graph)); 4972 new HSubGraphBlockInformation(elseBranch.graph));
4952 4973
4953 HBasicBlock conditionStartBlock = conditionBranch.block; 4974 HBasicBlock conditionStartBlock = conditionBranch.block;
4954 conditionStartBlock.setBlockFlow(info, joinBlock); 4975 conditionStartBlock.setBlockFlow(info, joinBlock);
4955 SubGraph conditionGraph = conditionBranch.graph; 4976 SubGraph conditionGraph = conditionBranch.graph;
4956 HIf branch = conditionGraph.end.last; 4977 HIf branch = conditionGraph.end.last;
4957 assert(branch is HIf); 4978 assert(branch is HIf);
4958 branch.blockInformation = conditionStartBlock.blockFlow; 4979 branch.blockInformation = conditionStartBlock.blockFlow;
4959 } 4980 }
4960 } 4981 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698