| 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 | 8 |
| 9 import 'elements.dart'; | 9 import 'elements.dart'; |
| 10 import '../../compiler.dart' as api; | 10 import '../../compiler.dart' as api; |
| (...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 ClassElement get patch => super.patch; | 1363 ClassElement get patch => super.patch; |
| 1364 ClassElement get origin => super.origin; | 1364 ClassElement get origin => super.origin; |
| 1365 ClassElement get declaration => super.declaration; | 1365 ClassElement get declaration => super.declaration; |
| 1366 ClassElement get implementation => super.implementation; | 1366 ClassElement get implementation => super.implementation; |
| 1367 | 1367 |
| 1368 bool get hasBackendMembers => !backendMembers.isEmpty; | 1368 bool get hasBackendMembers => !backendMembers.isEmpty; |
| 1369 | 1369 |
| 1370 InterfaceType computeType(compiler) { | 1370 InterfaceType computeType(compiler) { |
| 1371 if (thisType == null) { | 1371 if (thisType == null) { |
| 1372 if (origin == null) { | 1372 if (origin == null) { |
| 1373 ClassNode node = parseNode(compiler); | 1373 Link<DartType> parameters = const Link<DartType>(); |
| 1374 Link<DartType> parameters = | 1374 // TODO(kasperl): Figure out how to get the type parameters |
| 1375 TypeDeclarationElementX.createTypeVariables(this, | 1375 // for a mixin application. |
| 1376 node.typeParameters); | 1376 if (!isMixinApplication) { |
| 1377 ClassNode node = parseNode(compiler); |
| 1378 parameters = TypeDeclarationElementX.createTypeVariables( |
| 1379 this, node.typeParameters); |
| 1380 } |
| 1377 thisType = new InterfaceType(this, parameters); | 1381 thisType = new InterfaceType(this, parameters); |
| 1378 if (parameters.isEmpty) { | 1382 if (parameters.isEmpty) { |
| 1379 rawType = thisType; | 1383 rawType = thisType; |
| 1380 } else { | 1384 } else { |
| 1381 var dynamicParameters = const Link<DartType>(); | 1385 var dynamicParameters = const Link<DartType>(); |
| 1382 parameters.forEach((_) { | 1386 parameters.forEach((_) { |
| 1383 dynamicParameters = | 1387 dynamicParameters = |
| 1384 dynamicParameters.prepend(compiler.types.dynamicType); | 1388 dynamicParameters.prepend(compiler.types.dynamicType); |
| 1385 }); | 1389 }); |
| 1386 rawType = new InterfaceType(this, dynamicParameters); | 1390 rawType = new InterfaceType(this, dynamicParameters); |
| 1387 } | 1391 } |
| 1388 } else { | 1392 } else { |
| 1389 thisType = origin.computeType(compiler); | 1393 thisType = origin.computeType(compiler); |
| 1390 rawType = origin.rawType; | 1394 rawType = origin.rawType; |
| 1391 } | 1395 } |
| 1392 } | 1396 } |
| 1393 return thisType; | 1397 return thisType; |
| 1394 } | 1398 } |
| 1395 | 1399 |
| 1396 /** | 1400 /** |
| 1397 * Return [:true:] if this element is the [:Object:] class for the [compiler]. | 1401 * Return [:true:] if this element is the [:Object:] class for the [compiler]. |
| 1398 */ | 1402 */ |
| 1399 bool isObject(Compiler compiler) => | 1403 bool isObject(Compiler compiler) => |
| 1400 identical(declaration, compiler.objectClass); | 1404 identical(declaration, compiler.objectClass); |
| 1401 | 1405 |
| 1402 Link<DartType> get typeVariables => thisType.typeArguments; | 1406 Link<DartType> get typeVariables => thisType.typeArguments; |
| 1403 | 1407 |
| 1408 ClassElement ensureResolved(Compiler compiler) { |
| 1409 if (resolutionState == STATE_NOT_STARTED) { |
| 1410 compiler.resolver.resolveClass(this); |
| 1411 } |
| 1412 return this; |
| 1413 } |
| 1414 |
| 1415 void addDefaultConstructorIfNeeded(Compiler compiler) { |
| 1416 if (hasConstructor) return; |
| 1417 FunctionElement constructor = |
| 1418 new SynthesizedConstructorElementX.forDefault(this, compiler); |
| 1419 setDefaultConstructor(constructor, compiler); |
| 1420 } |
| 1421 |
| 1422 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); |
| 1423 |
| 1404 void addBackendMember(Element member) { | 1424 void addBackendMember(Element member) { |
| 1405 backendMembers = backendMembers.prepend(member); | 1425 backendMembers = backendMembers.prepend(member); |
| 1406 } | 1426 } |
| 1407 | 1427 |
| 1408 void reverseBackendMembers() { | 1428 void reverseBackendMembers() { |
| 1409 backendMembers = backendMembers.reverse(); | 1429 backendMembers = backendMembers.reverse(); |
| 1410 } | 1430 } |
| 1411 | 1431 |
| 1412 /** | 1432 /** |
| 1413 * Lookup local members in the class. This will ignore constructors. | 1433 * Lookup local members in the class. This will ignore constructors. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 return false; | 1706 return false; |
| 1687 } | 1707 } |
| 1688 | 1708 |
| 1689 bool isInterface() => false; | 1709 bool isInterface() => false; |
| 1690 bool isNative() => nativeTagInfo != null; | 1710 bool isNative() => nativeTagInfo != null; |
| 1691 void setNative(String name) { | 1711 void setNative(String name) { |
| 1692 nativeTagInfo = new SourceString(name); | 1712 nativeTagInfo = new SourceString(name); |
| 1693 } | 1713 } |
| 1694 } | 1714 } |
| 1695 | 1715 |
| 1696 | |
| 1697 abstract class ClassElementX extends BaseClassElementX { | 1716 abstract class ClassElementX extends BaseClassElementX { |
| 1698 // Lazily applied patch of class members. | 1717 // Lazily applied patch of class members. |
| 1699 ClassElement patch = null; | 1718 ClassElement patch = null; |
| 1700 ClassElement origin = null; | 1719 ClassElement origin = null; |
| 1701 | 1720 |
| 1702 Link<Element> localMembers = const Link<Element>(); | 1721 Link<Element> localMembers = const Link<Element>(); |
| 1703 final ScopeX localScope = new ScopeX(); | 1722 final ScopeX localScope = new ScopeX(); |
| 1704 | 1723 |
| 1705 ClassElementX(SourceString name, Element enclosing, int id, int initialState) | 1724 ClassElementX(SourceString name, Element enclosing, int id, int initialState) |
| 1706 : super(name, enclosing, id, initialState); | 1725 : super(name, enclosing, id, initialState); |
| 1707 | 1726 |
| 1708 ClassNode parseNode(Compiler compiler); | 1727 ClassNode parseNode(Compiler compiler); |
| 1709 | 1728 |
| 1729 bool get isMixinApplication => false; |
| 1710 bool get isPatched => patch != null; | 1730 bool get isPatched => patch != null; |
| 1711 bool get isPatch => origin != null; | 1731 bool get isPatch => origin != null; |
| 1712 bool get hasLocalScopeMembers => !localScope.isEmpty; | 1732 bool get hasLocalScopeMembers => !localScope.isEmpty; |
| 1713 | 1733 |
| 1714 void addMember(Element element, DiagnosticListener listener) { | 1734 void addMember(Element element, DiagnosticListener listener) { |
| 1715 localMembers = localMembers.prepend(element); | 1735 localMembers = localMembers.prepend(element); |
| 1716 addToScope(element, listener); | 1736 addToScope(element, listener); |
| 1717 } | 1737 } |
| 1718 | 1738 |
| 1719 void addToScope(Element element, DiagnosticListener listener) { | 1739 void addToScope(Element element, DiagnosticListener listener) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1733 } | 1753 } |
| 1734 | 1754 |
| 1735 bool get hasConstructor { | 1755 bool get hasConstructor { |
| 1736 // Search in scope to be sure we search patched constructors. | 1756 // Search in scope to be sure we search patched constructors. |
| 1737 for (var element in localScope.values) { | 1757 for (var element in localScope.values) { |
| 1738 if (element.isConstructor()) return true; | 1758 if (element.isConstructor()) return true; |
| 1739 } | 1759 } |
| 1740 return false; | 1760 return false; |
| 1741 } | 1761 } |
| 1742 | 1762 |
| 1743 ClassElement ensureResolved(Compiler compiler) { | 1763 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { |
| 1744 if (resolutionState == STATE_NOT_STARTED) { | 1764 addToScope(constructor, compiler); |
| 1745 compiler.resolver.resolveClass(this); | |
| 1746 } | |
| 1747 return this; | |
| 1748 } | 1765 } |
| 1749 | 1766 |
| 1750 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); | 1767 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); |
| 1751 | 1768 |
| 1752 String toString() { | 1769 String toString() { |
| 1753 if (origin != null) { | 1770 if (origin != null) { |
| 1754 return 'patch ${super.toString()}'; | 1771 return 'patch ${super.toString()}'; |
| 1755 } else if (patch != null) { | 1772 } else if (patch != null) { |
| 1756 return 'origin ${super.toString()}'; | 1773 return 'origin ${super.toString()}'; |
| 1757 } else { | 1774 } else { |
| 1758 return super.toString(); | 1775 return super.toString(); |
| 1759 } | 1776 } |
| 1760 } | 1777 } |
| 1761 } | 1778 } |
| 1762 | 1779 |
| 1763 class MixinApplicationElementX extends BaseClassElementX { | 1780 class MixinApplicationElementX extends BaseClassElementX { |
| 1764 final MixinApplication cachedNode; | 1781 final MixinApplication cachedNode; |
| 1765 | 1782 |
| 1783 FunctionElement constructor; |
| 1784 ClassElement mixin; |
| 1785 |
| 1766 // TODO(kasperl): The analyzer complains when I don't have these two | 1786 // TODO(kasperl): The analyzer complains when I don't have these two |
| 1767 // fields. This is pretty weird. I cannot replace them with getters. | 1787 // fields. This is pretty weird. I cannot replace them with getters. |
| 1768 final ClassElement patch = null; | 1788 final ClassElement patch = null; |
| 1769 final ClassElement origin = null; | 1789 final ClassElement origin = null; |
| 1770 | 1790 |
| 1771 MixinApplicationElementX(SourceString name, Element enclosing, int id, | 1791 MixinApplicationElementX(SourceString name, Element enclosing, int id, |
| 1772 this.cachedNode) | 1792 this.cachedNode) |
| 1773 : super(name, enclosing, id, STATE_NOT_STARTED); | 1793 : super(name, enclosing, id, STATE_NOT_STARTED); |
| 1774 | 1794 |
| 1775 bool get hasConstructor => false; | 1795 bool get isMixinApplication => true; |
| 1796 bool get hasConstructor => constructor != null; |
| 1776 bool get hasLocalScopeMembers => false; | 1797 bool get hasLocalScopeMembers => false; |
| 1777 | 1798 |
| 1778 Token position() => cachedNode.getBeginToken(); | 1799 Token position() => cachedNode.getBeginToken(); |
| 1779 | 1800 |
| 1780 Node parseNode(DiagnosticListener listener) => cachedNode; | 1801 Node parseNode(DiagnosticListener listener) => cachedNode; |
| 1781 | 1802 |
| 1782 ClassElement ensureResolved(Compiler compiler) { | |
| 1783 if (resolutionState == STATE_NOT_STARTED) { | |
| 1784 compiler.resolver.resolveMixinApplication(this); | |
| 1785 } | |
| 1786 return this; | |
| 1787 } | |
| 1788 | |
| 1789 Element localLookup(SourceString name) { | 1803 Element localLookup(SourceString name) { |
| 1790 // TODO(kasperl): Unimplemented for now. | 1804 if (this.name == name) return constructor; |
| 1791 return null; | 1805 if (mixin != null) return mixin.localLookup(name); |
| 1792 } | 1806 } |
| 1793 | 1807 |
| 1794 void forEachLocalMember(void f(Element member)) { | 1808 void forEachLocalMember(void f(Element member)) { |
| 1795 // TODO(kasperl): Unimplemented for now. | 1809 if (mixin != null) mixin.forEachLocalMember(f); |
| 1796 } | 1810 } |
| 1797 | 1811 |
| 1798 void addMember(Element element, DiagnosticListener listener) { | 1812 void addMember(Element element, DiagnosticListener listener) { |
| 1799 throw new UnsupportedError("cannot add member to $this"); | 1813 throw new UnsupportedError("cannot add member to $this"); |
| 1800 } | 1814 } |
| 1801 | 1815 |
| 1802 void addToScope(Element element, DiagnosticListener listener) { | 1816 void addToScope(Element element, DiagnosticListener listener) { |
| 1803 throw new UnsupportedError("cannot add to scope of $this"); | 1817 throw new UnsupportedError("cannot add to scope of $this"); |
| 1804 } | 1818 } |
| 1819 |
| 1820 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { |
| 1821 assert(!hasConstructor); |
| 1822 this.constructor = constructor; |
| 1823 } |
| 1805 } | 1824 } |
| 1806 | 1825 |
| 1807 class LabelElementX extends ElementX implements LabelElement { | 1826 class LabelElementX extends ElementX implements LabelElement { |
| 1808 | 1827 |
| 1809 // We store the original label here so it can be returned by [parseNode]. | 1828 // We store the original label here so it can be returned by [parseNode]. |
| 1810 final Label label; | 1829 final Label label; |
| 1811 final String labelName; | 1830 final String labelName; |
| 1812 final TargetElement target; | 1831 final TargetElement target; |
| 1813 bool isBreakTarget = false; | 1832 bool isBreakTarget = false; |
| 1814 bool isContinueTarget = false; | 1833 bool isContinueTarget = false; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1930 | 1949 |
| 1931 MetadataAnnotation ensureResolved(Compiler compiler) { | 1950 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1932 if (resolutionState == STATE_NOT_STARTED) { | 1951 if (resolutionState == STATE_NOT_STARTED) { |
| 1933 compiler.resolver.resolveMetadataAnnotation(this); | 1952 compiler.resolver.resolveMetadataAnnotation(this); |
| 1934 } | 1953 } |
| 1935 return this; | 1954 return this; |
| 1936 } | 1955 } |
| 1937 | 1956 |
| 1938 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1957 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1939 } | 1958 } |
| OLD | NEW |