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 library dart2js.resolution; | 5 library dart2js.resolution; |
6 | 6 |
7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
8 | 8 |
9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
10 Identifiers; | 10 Identifiers; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 } | 414 } |
415 return result; | 415 return result; |
416 } | 416 } |
417 | 417 |
418 void resolveRedirectionChain(ConstructorElementX constructor, | 418 void resolveRedirectionChain(ConstructorElementX constructor, |
419 Spannable node) { | 419 Spannable node) { |
420 ConstructorElementX target = constructor; | 420 ConstructorElementX target = constructor; |
421 InterfaceType targetType; | 421 InterfaceType targetType; |
422 List<Element> seen = new List<Element>(); | 422 List<Element> seen = new List<Element>(); |
423 // Follow the chain of redirections and check for cycles. | 423 // Follow the chain of redirections and check for cycles. |
424 while (target.isRedirectingFactory) { | 424 while (target.isRedirectingFactory || target.isPatched) { |
425 if (target.internalEffectiveTarget != null) { | 425 if (target.internalEffectiveTarget != null) { |
426 // We found a constructor that already has been processed. | 426 // We found a constructor that already has been processed. |
427 targetType = target.effectiveTargetType; | 427 targetType = target.effectiveTargetType; |
428 assert(invariant(target, targetType != null, | 428 assert(invariant(target, targetType != null, |
429 message: 'Redirection target type has not been computed for ' | 429 message: 'Redirection target type has not been computed for ' |
430 '$target')); | 430 '$target')); |
431 target = target.internalEffectiveTarget; | 431 target = target.internalEffectiveTarget; |
432 break; | 432 break; |
433 } | 433 } |
434 | 434 |
435 Element nextTarget = target.immediateRedirectionTarget; | 435 Element nextTarget; |
436 if (target.isPatched) { | |
437 nextTarget = target.implementation; | |
438 } else { | |
439 nextTarget = target.immediateRedirectionTarget; | |
440 } | |
441 | |
436 if (seen.contains(nextTarget)) { | 442 if (seen.contains(nextTarget)) { |
437 compiler.reportErrorMessage( | 443 compiler.reportErrorMessage( |
438 node, MessageKind.CYCLIC_REDIRECTING_FACTORY); | 444 node, MessageKind.CYCLIC_REDIRECTING_FACTORY); |
439 targetType = target.enclosingClass.thisType; | 445 targetType = target.enclosingClass.thisType; |
440 break; | 446 break; |
441 } | 447 } |
442 seen.add(target); | 448 seen.add(target); |
443 target = nextTarget; | 449 target = nextTarget; |
444 } | 450 } |
445 | 451 |
(...skipping 10 matching lines...) Expand all Loading... | |
456 while (!seen.isEmpty) { | 462 while (!seen.isEmpty) { |
457 ConstructorElementX factory = seen.removeLast(); | 463 ConstructorElementX factory = seen.removeLast(); |
458 | 464 |
459 // [factory] must already be analyzed but the [TreeElements] might not | 465 // [factory] must already be analyzed but the [TreeElements] might not |
460 // have been stored in the enqueuer cache yet. | 466 // have been stored in the enqueuer cache yet. |
461 // TODO(johnniwinther): Store [TreeElements] in the cache before | 467 // TODO(johnniwinther): Store [TreeElements] in the cache before |
462 // resolution of the element. | 468 // resolution of the element. |
463 TreeElements treeElements = factory.treeElements; | 469 TreeElements treeElements = factory.treeElements; |
464 assert(invariant(node, treeElements != null, | 470 assert(invariant(node, treeElements != null, |
465 message: 'No TreeElements cached for $factory.')); | 471 message: 'No TreeElements cached for $factory.')); |
466 FunctionExpression functionNode = factory.parseNode(parsing); | 472 if (!factory.isPatched) { |
467 RedirectingFactoryBody redirectionNode = functionNode.body; | 473 FunctionExpression functionNode = factory.parseNode(parsing); |
468 DartType factoryType = treeElements.getType(redirectionNode); | 474 Statement redirectionNode = functionNode.body; |
Johnni Winther
2015/10/06 10:38:14
Why is this needed?
Harry Terkelsen
2015/10/12 18:17:44
Good catch, it's not needed. It was from an earlie
| |
469 if (!factoryType.isDynamic) { | 475 DartType factoryType = treeElements.getType(redirectionNode); |
470 targetType = targetType.substByContext(factoryType); | 476 if (!factoryType.isDynamic) { |
477 targetType = targetType.substByContext(factoryType); | |
478 } | |
471 } | 479 } |
472 factory.effectiveTarget = target; | 480 factory.effectiveTarget = target; |
473 factory.effectiveTargetType = targetType; | 481 factory.effectiveTargetType = targetType; |
474 } | 482 } |
475 } | 483 } |
476 | 484 |
477 /** | 485 /** |
478 * Load and resolve the supertypes of [cls]. | 486 * Load and resolve the supertypes of [cls]. |
479 * | 487 * |
480 * Warning: do not call this method directly. It should only be | 488 * Warning: do not call this method directly. It should only be |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 TreeElements get treeElements { | 1081 TreeElements get treeElements { |
1074 assert(invariant(this, _treeElements !=null, | 1082 assert(invariant(this, _treeElements !=null, |
1075 message: "TreeElements have not been computed for $this.")); | 1083 message: "TreeElements have not been computed for $this.")); |
1076 return _treeElements; | 1084 return _treeElements; |
1077 } | 1085 } |
1078 | 1086 |
1079 void reuseElement() { | 1087 void reuseElement() { |
1080 _treeElements = null; | 1088 _treeElements = null; |
1081 } | 1089 } |
1082 } | 1090 } |
OLD | NEW |