| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 elements.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
| 9 | 9 |
| 10 import 'elements.dart'; | 10 import 'elements.dart'; |
| (...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 void addDefaultConstructorIfNeeded(Compiler compiler) { | 1491 void addDefaultConstructorIfNeeded(Compiler compiler) { |
| 1492 if (hasConstructor) return; | 1492 if (hasConstructor) return; |
| 1493 FunctionElement constructor = | 1493 FunctionElement constructor = |
| 1494 new SynthesizedConstructorElementX.forDefault(this, compiler); | 1494 new SynthesizedConstructorElementX.forDefault(this, compiler); |
| 1495 setDefaultConstructor(constructor, compiler); | 1495 setDefaultConstructor(constructor, compiler); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); | 1498 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); |
| 1499 | 1499 |
| 1500 void addBackendMember(Element member) { | 1500 void addBackendMember(Element member) { |
| 1501 // TODO(ngeoffray): Deprecate this method. |
| 1502 assert(member.isGenerativeConstructorBody()); |
| 1501 backendMembers = backendMembers.prepend(member); | 1503 backendMembers = backendMembers.prepend(member); |
| 1502 } | 1504 } |
| 1503 | 1505 |
| 1504 void reverseBackendMembers() { | 1506 void reverseBackendMembers() { |
| 1505 backendMembers = backendMembers.reverse(); | 1507 backendMembers = backendMembers.reverse(); |
| 1506 } | 1508 } |
| 1507 | 1509 |
| 1508 /** | 1510 /** |
| 1509 * Lookup local members in the class. This will ignore constructors. | 1511 * Lookup local members in the class. This will ignore constructors. |
| 1510 */ | 1512 */ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 } | 1585 } |
| 1584 | 1586 |
| 1585 Element internalLookupSelector(Selector selector, bool isSuperLookup) { | 1587 Element internalLookupSelector(Selector selector, bool isSuperLookup) { |
| 1586 SourceString name = selector.name; | 1588 SourceString name = selector.name; |
| 1587 bool isPrivate = name.isPrivate(); | 1589 bool isPrivate = name.isPrivate(); |
| 1588 LibraryElement library = selector.library; | 1590 LibraryElement library = selector.library; |
| 1589 for (ClassElement current = isSuperLookup ? superclass : this; | 1591 for (ClassElement current = isSuperLookup ? superclass : this; |
| 1590 current != null; | 1592 current != null; |
| 1591 current = current.superclass) { | 1593 current = current.superclass) { |
| 1592 Element member = current.lookupLocalMember(name); | 1594 Element member = current.lookupLocalMember(name); |
| 1595 if (member == null && current.isPatched) { |
| 1596 // Doing lookups on selectors is done after resolution, so it |
| 1597 // is safe to look in the patch class. |
| 1598 member = current.patch.lookupLocalMember(name); |
| 1599 } |
| 1593 if (member == null) continue; | 1600 if (member == null) continue; |
| 1594 // Private members from a different library are not visible. | 1601 // Private members from a different library are not visible. |
| 1595 if (isPrivate && !identical(library, member.getLibrary())) continue; | 1602 if (isPrivate && !identical(library, member.getLibrary())) continue; |
| 1596 // Static members are not inherited. | 1603 // Static members are not inherited. |
| 1597 if (member.modifiers.isStatic() && !identical(this, current)) continue; | 1604 if (member.modifiers.isStatic() && !identical(this, current)) continue; |
| 1598 // If we find an abstract field we have to make sure that it has | 1605 // If we find an abstract field we have to make sure that it has |
| 1599 // the getter or setter part we're actually looking | 1606 // the getter or setter part we're actually looking |
| 1600 // for. Otherwise, we continue up the superclass chain. | 1607 // for. Otherwise, we continue up the superclass chain. |
| 1601 if (member.isAbstractField()) { | 1608 if (member.isAbstractField()) { |
| 1602 AbstractFieldElement field = member; | 1609 AbstractFieldElement field = member; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 */ | 1715 */ |
| 1709 ClassElement get superclass { | 1716 ClassElement get superclass { |
| 1710 assert(supertypeLoadState == STATE_DONE); | 1717 assert(supertypeLoadState == STATE_DONE); |
| 1711 return supertype == null ? null : supertype.element; | 1718 return supertype == null ? null : supertype.element; |
| 1712 } | 1719 } |
| 1713 | 1720 |
| 1714 /** | 1721 /** |
| 1715 * Runs through all members of this class. | 1722 * Runs through all members of this class. |
| 1716 * | 1723 * |
| 1717 * The enclosing class is passed to the callback. This is useful when | 1724 * The enclosing class is passed to the callback. This is useful when |
| 1718 * [includeSuperMembers] is [:true:]. | 1725 * [includeSuperAndInjectedMembers] is [:true:]. |
| 1719 * | 1726 * |
| 1720 * When called on an implementation element both the members in the origin | 1727 * When called on an implementation element both the members in the origin |
| 1721 * and patch class are included. | 1728 * and patch class are included. |
| 1722 */ | 1729 */ |
| 1723 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. | 1730 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. |
| 1724 void forEachMember(void f(ClassElement enclosingClass, Element member), | 1731 void forEachMember(void f(ClassElement enclosingClass, Element member), |
| 1725 {includeBackendMembers: false, | 1732 {includeBackendMembers: false, |
| 1726 includeSuperMembers: false}) { | 1733 includeSuperAndInjectedMembers: false}) { |
| 1727 bool includeInjectedMembers = isPatch; | 1734 bool includeInjectedMembers = includeSuperAndInjectedMembers || isPatch; |
| 1728 Set<ClassElement> seen = new Set<ClassElement>(); | 1735 Set<ClassElement> seen = new Set<ClassElement>(); |
| 1729 ClassElement classElement = declaration; | 1736 ClassElement classElement = declaration; |
| 1730 do { | 1737 do { |
| 1731 if (seen.contains(classElement)) return; | 1738 if (seen.contains(classElement)) return; |
| 1732 seen.add(classElement); | 1739 seen.add(classElement); |
| 1733 | 1740 |
| 1734 // Iterate through the members in textual order, which requires | 1741 // Iterate through the members in textual order, which requires |
| 1735 // to reverse the data structure [localMembers] we created. | 1742 // to reverse the data structure [localMembers] we created. |
| 1736 // Textual order may be important for certain operations, for | 1743 // Textual order may be important for certain operations, for |
| 1737 // example when emitting the initializers of fields. | 1744 // example when emitting the initializers of fields. |
| 1738 classElement.forEachLocalMember((e) => f(classElement, e)); | 1745 classElement.forEachLocalMember((e) => f(classElement, e)); |
| 1739 if (includeBackendMembers) { | 1746 if (includeBackendMembers) { |
| 1740 classElement.forEachBackendMember((e) => f(classElement, e)); | 1747 classElement.forEachBackendMember((e) => f(classElement, e)); |
| 1741 } | 1748 } |
| 1742 if (includeInjectedMembers) { | 1749 if (includeInjectedMembers) { |
| 1743 if (classElement.patch != null) { | 1750 if (classElement.patch != null) { |
| 1744 classElement.patch.forEachLocalMember((e) { | 1751 classElement.patch.forEachLocalMember((e) { |
| 1745 if (!e.isPatch) f(classElement, e); | 1752 if (!e.isPatch) f(classElement, e); |
| 1746 }); | 1753 }); |
| 1747 } | 1754 } |
| 1748 } | 1755 } |
| 1749 classElement = includeSuperMembers ? classElement.superclass : null; | 1756 classElement = includeSuperAndInjectedMembers |
| 1757 ? classElement.superclass |
| 1758 : null; |
| 1750 } while(classElement != null); | 1759 } while(classElement != null); |
| 1751 } | 1760 } |
| 1752 | 1761 |
| 1753 /** | 1762 /** |
| 1754 * Runs through all instance-field members of this class. | 1763 * Runs through all instance-field members of this class. |
| 1755 * | 1764 * |
| 1756 * The enclosing class is passed to the callback. This is useful when | 1765 * The enclosing class is passed to the callback. This is useful when |
| 1757 * [includeSuperMembers] is [:true:]. | 1766 * [includeSuperAndInjectedMembers] is [:true:]. |
| 1758 * | |
| 1759 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] | |
| 1760 * then the fields are visited in the same order as they need to be given | |
| 1761 * to the JavaScript constructor. | |
| 1762 * | 1767 * |
| 1763 * When called on the implementation element both the fields declared in the | 1768 * When called on the implementation element both the fields declared in the |
| 1764 * origin and in the patch are included. | 1769 * origin and in the patch are included. |
| 1765 */ | 1770 */ |
| 1766 void forEachInstanceField(void f(ClassElement enclosingClass, Element field), | 1771 void forEachInstanceField(void f(ClassElement enclosingClass, Element field), |
| 1767 {includeBackendMembers: false, | 1772 {includeSuperAndInjectedMembers: false}) { |
| 1768 includeSuperMembers: false}) { | |
| 1769 // Filters so that [f] is only invoked with instance fields. | 1773 // Filters so that [f] is only invoked with instance fields. |
| 1770 void fieldFilter(ClassElement enclosingClass, Element member) { | 1774 void fieldFilter(ClassElement enclosingClass, Element member) { |
| 1771 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 1775 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { |
| 1772 f(enclosingClass, member); | 1776 f(enclosingClass, member); |
| 1773 } | 1777 } |
| 1774 } | 1778 } |
| 1775 | 1779 |
| 1776 forEachMember(fieldFilter, | 1780 forEachMember(fieldFilter, |
| 1777 includeBackendMembers: includeBackendMembers, | 1781 includeSuperAndInjectedMembers: includeSuperAndInjectedMembers); |
| 1778 includeSuperMembers: includeSuperMembers); | |
| 1779 } | 1782 } |
| 1780 | 1783 |
| 1781 void forEachBackendMember(void f(Element member)) { | 1784 void forEachBackendMember(void f(Element member)) { |
| 1782 backendMembers.forEach(f); | 1785 backendMembers.forEach(f); |
| 1783 } | 1786 } |
| 1784 | 1787 |
| 1785 bool implementsInterface(ClassElement intrface) { | 1788 bool implementsInterface(ClassElement intrface) { |
| 1786 for (DartType implementedInterfaceType in allSupertypes) { | 1789 for (DartType implementedInterfaceType in allSupertypes) { |
| 1787 ClassElement implementedInterface = implementedInterfaceType.element; | 1790 ClassElement implementedInterface = implementedInterfaceType.element; |
| 1788 if (identical(implementedInterface, intrface)) { | 1791 if (identical(implementedInterface, intrface)) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 | 2089 |
| 2087 MetadataAnnotation ensureResolved(Compiler compiler) { | 2090 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 2088 if (resolutionState == STATE_NOT_STARTED) { | 2091 if (resolutionState == STATE_NOT_STARTED) { |
| 2089 compiler.resolver.resolveMetadataAnnotation(this); | 2092 compiler.resolver.resolveMetadataAnnotation(this); |
| 2090 } | 2093 } |
| 2091 return this; | 2094 return this; |
| 2092 } | 2095 } |
| 2093 | 2096 |
| 2094 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 2097 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 2095 } | 2098 } |
| OLD | NEW |