Changeset 2316 for cobra/trunk/Source/Types.cobra
- Timestamp:
- 03/14/10 06:45:43 (2 years ago)
- Files:
-
- 1 modified
-
cobra/trunk/Source/Types.cobra (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Types.cobra
r2313 r2316 70 70 def typeOrNilForName(name as String) as IType? 71 71 72 def arrayType(type as IType) as ArrayType 73 72 74 get boolType as BoolType 73 75 … … 122 124 var _anyFloatType as AnyFloatType? 123 125 var _anyIntType as AnyIntType? 126 var _arrayTypes as Dictionary<of IType, ArrayType>? 124 127 var _boolType as BoolType? 125 128 var _charType as CharType? … … 154 157 _anyIntType = AnyIntType() 155 158 return _anyIntType to ! 159 160 def arrayType(type as IType) as ArrayType 161 if _arrayTypes is nil, _arrayTypes = Dictionary<of IType, ArrayType>() 162 if _arrayTypes.containsKey(type) 163 return _arrayTypes[type] 164 else 165 _arrayTypes[type] = at = ArrayType(type) 166 at.bindInh 167 at.bindInt 168 return at 156 169 157 170 get boolType as BoolType … … 975 988 return r 976 989 977 # TODO?978 # def isComparableTo(t as IType) as bool979 # return this is t980 981 # def isEquatableTo(t as IType) as bool982 983 990 def isComparableTo(t as IType) as bool 984 991 return this is t or base.isComparableTo(t) 992 993 # TODO? 994 # def isEquatableTo(t as IType) as bool 985 995 986 996 … … 1671 1681 """ 1672 1682 Represents an array. 1683 1673 1684 Only single dimension arrays have been tested and are officially supported. These are common in 1674 1685 the BCL as return types and sometimes as parameters. Multi-dim and jagged arrays are not popular. 1675 1686 Also, most projects can get by just fine with nested List<of>s. 1676 TODO: Nevertheless, this should be expanded. 1687 1688 Rather than instantiating this type directly, use: 1689 1690 .typeProvider.arrayType(t) 1691 1692 Or if the code block already belongs to a type provider: 1693 1694 .arrayType(t) 1695 1677 1696 TODO: Get this related to System.Array. 1678 1697 """ … … 1689 1708 Node.typeProvider = saveTP 1690 1709 1710 var _ilistOf as Interface? 1711 1691 1712 cue init(wrappedType as IType) 1692 1713 base.init(wrappedType) … … 1725 1746 return base.isDescendantOf(type) or .box.isDescendantOf(type) 1726 1747 1748 def isEquatableTo(t as IType) as bool 1749 assert .didBindInh 1750 return base.isEquatableTo(t) or t.isDescendantOf(_ilistOf to !) or _ilistOf.isDescendantOf(t) 1751 1727 1752 def memberForName(name as String) as IMember? is override 1728 1753 m = base.memberForName(name) … … 1736 1761 return m 1737 1762 1763 def secondaryConstructedTypeFor(box as Box, gpToType as Dictionary<of GenericParam, IType>) as IType is override 1764 at = ArrayType(_wrappedType.secondaryConstructedTypeFor(box, gpToType)) 1765 at.bindInh 1766 at.bindInt 1767 return at 1768 1738 1769 def suggestionsForBadMemberName(name as String) as List<of String> is override 1739 1770 return .box.suggestionsForBadMemberName(name) … … 1745 1776 icoll = (.compiler.libraryType('System.Collections.Generic.ICollection<of>') to Box).constructedTypeFor([.theWrappedType]) 1746 1777 ienum = .compiler.enumerableOfType.constructedTypeFor([.theWrappedType]) 1747 # TODO: ilist = .compiler.ilistOfType.constructedTypeFor([.theWrappedType])1748 interfaces = [iclone to ITypeProxy, icoll, ienum] # TODO:, ilist] -- problems with cobra -ert:yes hello and extension method String.split1778 _ilistOf = .compiler.ilistOfType.constructedTypeFor([.theWrappedType]) to Interface 1779 interfaces = [iclone to ITypeProxy, icoll, ienum] # TODO:, _ilistOf] -- problems with cobra -ert:yes hello and extension method String.split 1749 1780 _box = Class(Token.empty, Token.empty, '[.getType.name]_[.serialNum]', List<of IType>(), List<of String>(), AttributeList(), nil, interfaces, List<of ITypeProxy>(), nil) 1750 1781 # TODO: make members based on System.Array … … 1765 1796 1766 1797 1767 class VariType 1768 is partial 1769 inherits ArrayType 1798 class VariType inherits ArrayType is partial 1770 1799 """ 1771 1800 Represents the type for variable number of arguments: … … 1774 1803 """ 1775 1804 1776 var _ilistOf as Interface? # TODO: does ArrayType need _ilistOf too?1777 1778 1805 cue init(wrappedType as IType) 1779 1806 base.init(wrappedType) … … 1785 1812 return _wrappedType 1786 1813 1787 def isEquatableTo(t as IType) as bool is override1788 # vari type inherits IList<of>1789 assert .didBindInh1790 return base.isEquatableTo(t) or t.isDescendantOf(_ilistOf to !) or _ilistOf.isDescendantOf(t)1791 1792 1814 get name as String is override 1793 1815 return 'vari ' + _wrappedType.name … … 1795 1817 def _bindInh 1796 1818 base._bindInh 1797 if .compiler # will be nil during unit tests1798 _ilistOf = .compiler.ilistOfType.constructedTypeFor([.theWrappedType]) to Interface1799 _ilistOf.bindInh1800 1819 1801 1820 def _bindInt



