Wiki
Show
Ignore:
Timestamp:
03/14/10 06:45:43 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Arrays and lists can now be compared with == and <>.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/Types.cobra

    r2313 r2316  
    7070    def typeOrNilForName(name as String) as IType? 
    7171 
     72    def arrayType(type as IType) as ArrayType 
     73 
    7274    get boolType as BoolType 
    7375 
     
    122124    var _anyFloatType       as AnyFloatType? 
    123125    var _anyIntType         as AnyIntType? 
     126    var _arrayTypes         as Dictionary<of IType, ArrayType>? 
    124127    var _boolType           as BoolType? 
    125128    var _charType           as CharType? 
     
    154157            _anyIntType = AnyIntType() 
    155158        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 
    156169 
    157170    get boolType as BoolType 
     
    975988        return r 
    976989 
    977     # TODO? 
    978 #   def isComparableTo(t as IType) as bool 
    979 #       return this is t 
    980  
    981 #   def isEquatableTo(t as IType) as bool 
    982  
    983990    def isComparableTo(t as IType) as bool 
    984991        return this is t or base.isComparableTo(t) 
     992 
     993# TODO? 
     994#   def isEquatableTo(t as IType) as bool 
    985995 
    986996 
     
    16711681    """ 
    16721682    Represents an array. 
     1683 
    16731684    Only single dimension arrays have been tested and are officially supported. These are common in 
    16741685    the BCL as return types and sometimes as parameters. Multi-dim and jagged arrays are not popular. 
    16751686    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         
    16771696    TODO: Get this related to System.Array. 
    16781697    """ 
     
    16891708            Node.typeProvider = saveTP 
    16901709 
     1710    var _ilistOf as Interface? 
     1711     
    16911712    cue init(wrappedType as IType) 
    16921713        base.init(wrappedType) 
     
    17251746        return base.isDescendantOf(type) or .box.isDescendantOf(type) 
    17261747 
     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 
    17271752    def memberForName(name as String) as IMember? is override 
    17281753        m = base.memberForName(name) 
     
    17361761        return m 
    17371762 
     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 
    17381769    def suggestionsForBadMemberName(name as String) as List<of String> is override 
    17391770        return .box.suggestionsForBadMemberName(name) 
     
    17451776            icoll = (.compiler.libraryType('System.Collections.Generic.ICollection<of>') to Box).constructedTypeFor([.theWrappedType]) 
    17461777            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.split 
     1778            _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 
    17491780            _box = Class(Token.empty, Token.empty, '[.getType.name]_[.serialNum]', List<of IType>(), List<of String>(), AttributeList(), nil, interfaces, List<of ITypeProxy>(), nil) 
    17501781            # TODO: make members based on System.Array 
     
    17651796 
    17661797 
    1767 class VariType 
    1768     is partial 
    1769     inherits ArrayType 
     1798class VariType inherits ArrayType is partial 
    17701799    """ 
    17711800    Represents the type for variable number of arguments: 
     
    17741803    """ 
    17751804 
    1776     var _ilistOf as Interface?  # TODO: does ArrayType need _ilistOf too? 
    1777  
    17781805    cue init(wrappedType as IType) 
    17791806        base.init(wrappedType) 
     
    17851812        return _wrappedType 
    17861813 
    1787     def isEquatableTo(t as IType) as bool is override 
    1788         # vari type inherits IList<of> 
    1789         assert .didBindInh 
    1790         return base.isEquatableTo(t) or t.isDescendantOf(_ilistOf to !) or _ilistOf.isDescendantOf(t) 
    1791  
    17921814    get name as String is override 
    17931815        return 'vari ' + _wrappedType.name 
     
    17951817    def _bindInh 
    17961818        base._bindInh 
    1797         if .compiler  # will be nil during unit tests 
    1798             _ilistOf = .compiler.ilistOfType.constructedTypeFor([.theWrappedType]) to Interface 
    1799             _ilistOf.bindInh 
    18001819 
    18011820    def _bindInt