Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element get currentElement; | 8 Element get currentElement; |
| 9 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2659 } | 2659 } |
| 2660 | 2660 |
| 2661 FunctionSignature targetSignature = | 2661 FunctionSignature targetSignature = |
| 2662 redirectionTarget.computeSignature(compiler); | 2662 redirectionTarget.computeSignature(compiler); |
| 2663 FunctionSignature constructorSignature = | 2663 FunctionSignature constructorSignature = |
| 2664 constructor.computeSignature(compiler); | 2664 constructor.computeSignature(compiler); |
| 2665 if (!targetSignature.isCompatibleWith(constructorSignature)) { | 2665 if (!targetSignature.isCompatibleWith(constructorSignature)) { |
| 2666 compiler.backend.registerThrowNoSuchMethod(mapping); | 2666 compiler.backend.registerThrowNoSuchMethod(mapping); |
| 2667 } | 2667 } |
| 2668 | 2668 |
| 2669 // TODO(ahe): Check that this doesn't lead to a cycle. For now, | 2669 // Register a post process to check for cycles in the redirection chain and |
| 2670 // just make sure that the redirection target isn't itself a | 2670 // set the actual generative constructor at the end of the chain. |
| 2671 // redirecting factory. | 2671 compiler.enqueuer.resolution.addPostProcessAction(constructor, () { |
| 2672 { // This entire block is temporary code per the above TODO. | 2672 FunctionElementX current = constructor; |
| 2673 FunctionElement targetImplementation = redirectionTarget.implementation; | 2673 if (current.internalRedirectionTarget != null) { |
| 2674 FunctionExpression function = targetImplementation.parseNode(compiler); | 2674 return; |
| 2675 if (function != null | |
| 2676 && function.body != null | |
| 2677 && function.body.asReturn() != null | |
| 2678 && function.body.asReturn().isRedirectingFactoryBody) { | |
| 2679 unimplemented(node.expression, 'redirecting to redirecting factory'); | |
| 2680 } | 2675 } |
| 2681 } | 2676 List<Element> seen = new List<Element>(); |
| 2677 // Follow the chain of redirections and check for cycles. | |
| 2678 while (current != current.defaultImplementation && | |
| 2679 current.internalRedirectionTarget == null) { | |
| 2680 Element target = current.defaultImplementation; | |
| 2681 if (seen.contains(target)) { | |
| 2682 error(node, MessageKind.CYCLIC_REDIRECTING_FACTORY); | |
| 2683 return; | |
| 2684 } | |
| 2685 seen.add(current); | |
| 2686 current = target; | |
| 2687 } | |
| 2688 // [current] is now the actual target of the redirections. Run through | |
| 2689 // the constructors again and set their [redirectionTarget]. | |
|
ngeoffray
2013/09/18 11:19:23
Why do you need to do this for all seen targets? W
karlklose
2013/09/18 12:30:39
It is an optimization to not do the lookup again i
| |
| 2690 while (!seen.isEmpty) { | |
| 2691 FunctionElementX factory = seen.removeLast(); | |
| 2692 factory.redirectionTarget = current; | |
| 2693 } | |
| 2694 }); | |
| 2695 | |
| 2682 world.registerStaticUse(redirectionTarget); | 2696 world.registerStaticUse(redirectionTarget); |
| 2683 world.registerInstantiatedClass( | 2697 world.registerInstantiatedClass( |
| 2684 redirectionTarget.enclosingElement.declaration, mapping); | 2698 redirectionTarget.enclosingElement.declaration, mapping); |
| 2685 if (isSymbolConstructor) { | 2699 if (isSymbolConstructor) { |
| 2686 compiler.backend.registerSymbolConstructor(mapping); | 2700 compiler.backend.registerSymbolConstructor(mapping); |
| 2687 } | 2701 } |
| 2688 } | 2702 } |
| 2689 | 2703 |
| 2690 visitThrow(Throw node) { | 2704 visitThrow(Throw node) { |
| 2691 compiler.backend.registerThrowExpression(mapping); | 2705 compiler.backend.registerThrowExpression(mapping); |
| (...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4223 return e; | 4237 return e; |
| 4224 } | 4238 } |
| 4225 | 4239 |
| 4226 /// Assumed to be called by [resolveRedirectingFactory]. | 4240 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4227 Element visitReturn(Return node) { | 4241 Element visitReturn(Return node) { |
| 4228 Node expression = node.expression; | 4242 Node expression = node.expression; |
| 4229 return finishConstructorReference(visit(expression), | 4243 return finishConstructorReference(visit(expression), |
| 4230 expression, expression); | 4244 expression, expression); |
| 4231 } | 4245 } |
| 4232 } | 4246 } |
| OLD | NEW |