OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 @override | 520 @override |
521 int get codeOffset { | 521 int get codeOffset { |
522 if (_unlinkedClass != null) { | 522 if (_unlinkedClass != null) { |
523 return _unlinkedClass.codeRange?.offset; | 523 return _unlinkedClass.codeRange?.offset; |
524 } | 524 } |
525 return super.codeOffset; | 525 return super.codeOffset; |
526 } | 526 } |
527 | 527 |
528 @override | 528 @override |
529 List<ConstructorElement> get constructors { | 529 List<ConstructorElement> get constructors { |
530 if (!isMixinApplication) { | 530 if (isMixinApplication) { |
531 assert(_constructors != null); | 531 return _computeMixinAppConstructors(); |
532 return _constructors ?? ConstructorElement.EMPTY_LIST; | |
533 } | 532 } |
534 return _computeMixinAppConstructors(); | 533 if (_unlinkedClass != null && _constructors == null) { |
534 _constructors = _unlinkedClass.executables | |
535 .where((e) => e.kind == UnlinkedExecutableKind.constructor) | |
536 .map((e) => new ConstructorElementImpl.forSerialized(e, this)) | |
537 .toList(growable: false); | |
538 // Ensure at least implicit default constructor. | |
539 if (_constructors.isEmpty) { | |
540 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1); | |
541 constructor.enclosingElement = this; | |
542 constructor.synthetic = true; | |
543 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs( | |
544 constructor, null, type.typeArguments, false); | |
545 _constructors = <ConstructorElement>[constructor]; | |
546 } | |
547 } | |
548 assert(_constructors != null); | |
549 return _constructors ?? const <ConstructorElement>[]; | |
Brian Wilkerson
2016/06/03 16:06:34
This doesn't make sense. If _constructors is not n
scheglov
2016/06/03 16:10:38
I agree, but this change just keeps the previous s
Brian Wilkerson
2016/06/03 16:18:15
Ok, I see. Are we doing the same everywhere that w
Paul Berry
2016/06/03 16:21:50
Yes, that was my intention when I wrote this code,
| |
535 } | 550 } |
536 | 551 |
537 /** | 552 /** |
538 * Set the constructors contained in this class to the given [constructors]. | 553 * Set the constructors contained in this class to the given [constructors]. |
539 * | 554 * |
540 * Should only be used for class elements that are not mixin applications. | 555 * Should only be used for class elements that are not mixin applications. |
541 */ | 556 */ |
542 void set constructors(List<ConstructorElement> constructors) { | 557 void set constructors(List<ConstructorElement> constructors) { |
558 assert(_unlinkedClass == null); | |
543 assert(!isMixinApplication); | 559 assert(!isMixinApplication); |
544 for (ConstructorElement constructor in constructors) { | 560 for (ConstructorElement constructor in constructors) { |
545 (constructor as ConstructorElementImpl).enclosingElement = this; | 561 (constructor as ConstructorElementImpl).enclosingElement = this; |
546 } | 562 } |
547 this._constructors = constructors; | 563 this._constructors = constructors; |
548 } | 564 } |
549 | 565 |
550 @override | 566 @override |
551 SourceRange get docRange { | 567 SourceRange get docRange { |
552 if (_unlinkedClass != null) { | 568 if (_unlinkedClass != null) { |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1671 ExecutableElementImpl enclosingExecutable) | 1687 ExecutableElementImpl enclosingExecutable) |
1672 : super.forSerialized(unlinkedVariable, enclosingExecutable); | 1688 : super.forSerialized(unlinkedVariable, enclosingExecutable); |
1673 } | 1689 } |
1674 | 1690 |
1675 /** | 1691 /** |
1676 * A concrete implementation of a [ConstructorElement]. | 1692 * A concrete implementation of a [ConstructorElement]. |
1677 */ | 1693 */ |
1678 class ConstructorElementImpl extends ExecutableElementImpl | 1694 class ConstructorElementImpl extends ExecutableElementImpl |
1679 implements ConstructorElement { | 1695 implements ConstructorElement { |
1680 /** | 1696 /** |
1681 * Set of slots corresponding to const constructors that are part of cycles. | |
1682 */ | |
1683 final Set<int> _constCycles; | |
1684 | |
1685 /** | |
1686 * The constructor to which this constructor is redirecting. | 1697 * The constructor to which this constructor is redirecting. |
1687 */ | 1698 */ |
1688 ConstructorElement _redirectedConstructor; | 1699 ConstructorElement _redirectedConstructor; |
1689 | 1700 |
1690 /** | 1701 /** |
1691 * The initializers for this constructor (used for evaluating constant | 1702 * The initializers for this constructor (used for evaluating constant |
1692 * instance creation expressions). | 1703 * instance creation expressions). |
1693 */ | 1704 */ |
1694 List<ConstructorInitializer> _constantInitializers; | 1705 List<ConstructorInitializer> _constantInitializers; |
1695 | 1706 |
(...skipping 11 matching lines...) Expand all Loading... | |
1707 /** | 1718 /** |
1708 * True if this constructor has been found by constant evaluation to be free | 1719 * True if this constructor has been found by constant evaluation to be free |
1709 * of redirect cycles, and is thus safe to evaluate. | 1720 * of redirect cycles, and is thus safe to evaluate. |
1710 */ | 1721 */ |
1711 bool _isCycleFree = false; | 1722 bool _isCycleFree = false; |
1712 | 1723 |
1713 /** | 1724 /** |
1714 * Initialize a newly created constructor element to have the given [name] and | 1725 * Initialize a newly created constructor element to have the given [name] and |
1715 * [offset]. | 1726 * [offset]. |
1716 */ | 1727 */ |
1717 ConstructorElementImpl(String name, int offset) | 1728 ConstructorElementImpl(String name, int offset) : super(name, offset); |
1718 : _constCycles = null, | |
1719 super(name, offset); | |
1720 | 1729 |
1721 /** | 1730 /** |
1722 * Initialize a newly created constructor element to have the given [name]. | 1731 * Initialize a newly created constructor element to have the given [name]. |
1723 */ | 1732 */ |
1724 ConstructorElementImpl.forNode(Identifier name) | 1733 ConstructorElementImpl.forNode(Identifier name) : super.forNode(name); |
1725 : _constCycles = null, | |
1726 super.forNode(name); | |
1727 | 1734 |
1728 /** | 1735 /** |
1729 * Initialize using the given serialized information. | 1736 * Initialize using the given serialized information. |
1730 */ | 1737 */ |
1731 ConstructorElementImpl.forSerialized(UnlinkedExecutable serializedExecutable, | 1738 ConstructorElementImpl.forSerialized( |
1732 this._constCycles, ClassElementImpl enclosingClass) | 1739 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) |
1733 : super.forSerialized(serializedExecutable, enclosingClass); | 1740 : super.forSerialized(serializedExecutable, enclosingClass); |
1734 | 1741 |
1735 /** | 1742 /** |
1736 * Set whether this constructor represents a 'const' constructor. | 1743 * Set whether this constructor represents a 'const' constructor. |
1737 */ | 1744 */ |
1738 void set const2(bool isConst) { | 1745 void set const2(bool isConst) { |
1739 assert(serializedExecutable == null); | 1746 assert(serializedExecutable == null); |
1740 setModifier(Modifier.CONST, isConst); | 1747 setModifier(Modifier.CONST, isConst); |
1741 } | 1748 } |
1742 | 1749 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1775 bool get isConst { | 1782 bool get isConst { |
1776 if (serializedExecutable != null) { | 1783 if (serializedExecutable != null) { |
1777 return serializedExecutable.isConst; | 1784 return serializedExecutable.isConst; |
1778 } | 1785 } |
1779 return hasModifier(Modifier.CONST); | 1786 return hasModifier(Modifier.CONST); |
1780 } | 1787 } |
1781 | 1788 |
1782 bool get isCycleFree { | 1789 bool get isCycleFree { |
1783 if (serializedExecutable != null) { | 1790 if (serializedExecutable != null) { |
1784 return serializedExecutable.isConst && | 1791 return serializedExecutable.isConst && |
1785 !_constCycles.contains(serializedExecutable.constCycleSlot); | 1792 !enclosingUnit.resynthesizerContext |
1793 .isInConstCycle(serializedExecutable.constCycleSlot); | |
1786 } | 1794 } |
1787 return _isCycleFree; | 1795 return _isCycleFree; |
1788 } | 1796 } |
1789 | 1797 |
1790 void set isCycleFree(bool isCycleFree) { | 1798 void set isCycleFree(bool isCycleFree) { |
1791 assert(serializedExecutable == null); | 1799 assert(serializedExecutable == null); |
1792 _isCycleFree = isCycleFree; | 1800 _isCycleFree = isCycleFree; |
1793 } | 1801 } |
1794 | 1802 |
1795 @override | 1803 @override |
(...skipping 5591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7387 * Build explicit top-level property accessors. | 7395 * Build explicit top-level property accessors. |
7388 */ | 7396 */ |
7389 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); | 7397 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); |
7390 | 7398 |
7391 /** | 7399 /** |
7392 * Build explicit top-level variables. | 7400 * Build explicit top-level variables. |
7393 */ | 7401 */ |
7394 UnitExplicitTopLevelVariables buildTopLevelVariables(); | 7402 UnitExplicitTopLevelVariables buildTopLevelVariables(); |
7395 | 7403 |
7396 /** | 7404 /** |
7405 * Return `true` if the given const constructor [slot] is a part of cycle. | |
7406 */ | |
7407 bool isInConstCycle(int slot); | |
7408 | |
7409 /** | |
7397 * Resolve an [EntityRef] into a constructor. If the reference is | 7410 * Resolve an [EntityRef] into a constructor. If the reference is |
7398 * unresolved, return `null`. | 7411 * unresolved, return `null`. |
7399 */ | 7412 */ |
7400 ConstructorElement resolveConstructorRef( | 7413 ConstructorElement resolveConstructorRef( |
7401 TypeParameterizedElementMixin typeParameterContext, EntityRef entry); | 7414 TypeParameterizedElementMixin typeParameterContext, EntityRef entry); |
7402 | 7415 |
7403 /** | 7416 /** |
7404 * Build the appropriate [DartType] object corresponding to a slot id in the | 7417 * Build the appropriate [DartType] object corresponding to a slot id in the |
7405 * [LinkedUnit.types] table. | 7418 * [LinkedUnit.types] table. |
7406 */ | 7419 */ |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8047 | 8060 |
8048 @override | 8061 @override |
8049 void visitElement(Element element) { | 8062 void visitElement(Element element) { |
8050 int offset = element.nameOffset; | 8063 int offset = element.nameOffset; |
8051 if (offset != -1) { | 8064 if (offset != -1) { |
8052 map[offset] = element; | 8065 map[offset] = element; |
8053 } | 8066 } |
8054 super.visitElement(element); | 8067 super.visitElement(element); |
8055 } | 8068 } |
8056 } | 8069 } |
OLD | NEW |