Changeset 2316
- Timestamp:
- 03/14/10 06:45:43 (2 years ago)
- Location:
- cobra/trunk
- Files:
-
- 6 modified
-
Source/Boxes.cobra (modified) (1 diff)
-
Source/Compiler.cobra (modified) (2 diffs)
-
Source/Expr.cobra (modified) (3 diffs)
-
Source/TypeProxies.cobra (modified) (3 diffs)
-
Source/Types.cobra (modified) (13 diffs)
-
Tests/240-generics/100-use-generics-collections/100-use-list.cobra (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Boxes.cobra
r2307 r2316 537 537 r = true 538 538 if not r and ('dynamic' in .name or 'dynamic' in t.name) # TODO: hacky 539 r = true 540 if not r and t inherits ArrayType and (t to ArrayType).isEquatableTo(this) # TODO: hacky 539 541 r = true 540 542 return r -
cobra/trunk/Source/Compiler.cobra
r2315 r2316 486 486 var _anyFloatType as AnyFloatType? 487 487 var _anyIntType as AnyIntType? 488 var _arrayTypes as Dictionary<of IType, ArrayType>? 488 489 var _boolType as BoolType? 489 490 var _charType as CharType? … … 518 519 _anyIntType = AnyIntType() 519 520 return _anyIntType to ! 521 522 def arrayType(type as IType) as ArrayType 523 if _arrayTypes is nil, _arrayTypes = Dictionary<of IType, ArrayType>() 524 if _arrayTypes.containsKey(type) 525 return _arrayTypes[type] 526 else 527 _arrayTypes[type] = at = ArrayType(type) 528 at.bindInh 529 at.bindInt 530 return at 520 531 521 532 get boolType as BoolType -
cobra/trunk/Source/Expr.cobra
r2304 r2316 1204 1204 if _target.isKindOf(.compiler.typeType) 1205 1205 if _target inherits IPotentialTypeExpr and (pt = (_target to IPotentialTypeExpr).potentialType) 1206 _transformTo(TypeExpr(.token, ArrayType(pt)))1207 return 1206 _transformTo(TypeExpr(.token, .typeProvider.arrayType(pt to !))) 1207 return 1208 1208 else 1209 1209 .throwError('Unknown array type.') … … 2838 2838 2839 2839 2840 class ArrayLit 2841 is partial 2842 inherits SequenceLit 2840 class ArrayLit inherits SequenceLit is partial 2843 2841 2844 2842 # CC: should just inherit this because no initializers are defined … … 2847 2845 2848 2846 def _makeTypeWith(type as IType) as IType is override 2849 return ArrayType(type)2847 return .typeProvider.arrayType(type) 2850 2848 2851 2849 get brackets as List<of String> is override -
cobra/trunk/Source/TypeProxies.cobra
r2304 r2316 185 185 if clrType.isArray 186 186 # assert clrType.name.endsWith(r'[]') # could be [,] so TODO: handle multidim arrays 187 return ArrayType(_realTypeWithCache(clrType.getElementType to !))187 return .typeProvider.arrayType(_realTypeWithCache(clrType.getElementType to !)) 188 188 else if clrType.isNested and not clrType.isGenericParameter 189 189 declaringType = _realTypeWithCache(clrType.declaringType to !) … … 462 462 463 463 464 class ArrayTypeIdentifier 465 inherits WrappedTypeIdentifier 464 class ArrayTypeIdentifier inherits WrappedTypeIdentifier 466 465 467 466 cue init(token as IToken, typeId as AbstractTypeIdentifier) … … 472 471 473 472 def _resolveType as IType is override 474 t = ArrayType(_typeId.realType) 475 t.bindInh 476 t.bindInt 477 return t 473 return .typeProvider.arrayType(_typeId.realType) 478 474 479 475 -
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 -
cobra/trunk/Tests/240-generics/100-use-generics-collections/100-use-list.cobra
r1177 r2316 1 1 class Test 2 2 3 def main is shared 4 3 def main 4 .testBasics 5 .compareWithArrays 6 7 def testBasics 5 8 t as List<of String> = List<of String>() 6 9 assert t.count == 0 … … 22 25 # assert v[0].equals('aoeu') 23 26 # assert v[1].equals(1) 27 28 def compareWithArrays 29 a as int[] = @[1, 2, 3] 30 b as List<of int> = [1, 2, 3] 31 c as List<of int> = [1, 2, 3, 4] 32 assert a == b 33 assert b == a 34 assert a <> c 35 assert c <> a



