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 2650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2661 | 2661 |
| 2662 FunctionSignature targetSignature = | 2662 FunctionSignature targetSignature = |
| 2663 redirectionTarget.computeSignature(compiler); | 2663 redirectionTarget.computeSignature(compiler); |
| 2664 FunctionSignature constructorSignature = | 2664 FunctionSignature constructorSignature = |
| 2665 constructor.computeSignature(compiler); | 2665 constructor.computeSignature(compiler); |
| 2666 if (!targetSignature.isCompatibleWith(constructorSignature)) { | 2666 if (!targetSignature.isCompatibleWith(constructorSignature)) { |
| 2667 assert(!isSubtype); | 2667 assert(!isSubtype); |
| 2668 compiler.backend.registerThrowNoSuchMethod(mapping); | 2668 compiler.backend.registerThrowNoSuchMethod(mapping); |
| 2669 } | 2669 } |
| 2670 | 2670 |
| 2671 // TODO(ahe): Check that this doesn't lead to a cycle. For now, | 2671 // Register a post process to check for cycles in the redirection chain and |
| 2672 // just make sure that the redirection target isn't itself a | 2672 // set the actual generative constructor at the end of the chain. |
| 2673 // redirecting factory. | 2673 compiler.enqueuer.resolution.addPostProcessAction(constructor, () { |
| 2674 { // This entire block is temporary code per the above TODO. | 2674 FunctionElementX current = constructor; |
| 2675 FunctionElement targetImplementation = redirectionTarget.implementation; | 2675 List<Element> seen = new List<Element>(); |
| 2676 FunctionExpression function = targetImplementation.parseNode(compiler); | 2676 // Follow the chain of redirections and check for cycles. |
| 2677 if (function != null | 2677 while (current != current.defaultImplementation) { |
| 2678 && function.body != null | 2678 if (current.internalRedirectionTarget != null) { |
| 2679 && function.body.asReturn() != null | 2679 // We found a constructor that already has been processed. |
| 2680 && function.body.asReturn().isRedirectingFactoryBody) { | 2680 current = current.internalRedirectionTarget; |
| 2681 unimplemented(node.expression, 'redirecting to redirecting factory'); | 2681 break; |
| 2682 } | |
| 2683 Element target = current.defaultImplementation; | |
| 2684 if (seen.contains(target)) { | |
| 2685 error(node, MessageKind.CYCLIC_REDIRECTING_FACTORY); | |
| 2686 return; | |
| 2687 } | |
| 2688 seen.add(current); | |
| 2689 current = target; | |
| 2682 } | 2690 } |
| 2683 } | 2691 // [current] is now the actual target of the redirections. Run through |
| 2692 // the constructors again and set their [redirectionTarget]. | |
|
ngeoffray
2013/09/18 12:52:07
Please add a comment that this is an optimization
| |
| 2693 while (!seen.isEmpty) { | |
| 2694 FunctionElementX factory = seen.removeLast(); | |
| 2695 factory.redirectionTarget = current; | |
| 2696 } | |
| 2697 }); | |
| 2698 | |
| 2684 world.registerStaticUse(redirectionTarget); | 2699 world.registerStaticUse(redirectionTarget); |
| 2685 world.registerInstantiatedClass( | 2700 world.registerInstantiatedClass( |
| 2686 redirectionTarget.enclosingElement.declaration, mapping); | 2701 redirectionTarget.enclosingElement.declaration, mapping); |
| 2687 if (isSymbolConstructor) { | 2702 if (isSymbolConstructor) { |
| 2688 compiler.backend.registerSymbolConstructor(mapping); | 2703 compiler.backend.registerSymbolConstructor(mapping); |
| 2689 } | 2704 } |
| 2690 } | 2705 } |
| 2691 | 2706 |
| 2692 visitThrow(Throw node) { | 2707 visitThrow(Throw node) { |
| 2693 compiler.backend.registerThrowExpression(mapping); | 2708 compiler.backend.registerThrowExpression(mapping); |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4319 return e; | 4334 return e; |
| 4320 } | 4335 } |
| 4321 | 4336 |
| 4322 /// Assumed to be called by [resolveRedirectingFactory]. | 4337 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4323 Element visitReturn(Return node) { | 4338 Element visitReturn(Return node) { |
| 4324 Node expression = node.expression; | 4339 Node expression = node.expression; |
| 4325 return finishConstructorReference(visit(expression), | 4340 return finishConstructorReference(visit(expression), |
| 4326 expression, expression); | 4341 expression, expression); |
| 4327 } | 4342 } |
| 4328 } | 4343 } |
| OLD | NEW |