Wiki
Show
Ignore:
Timestamp:
11/28/08 20:11:01 (3 years ago)
Author:
Chuck.Esterbrook
Message:

Added streams to the language. For example, int* or String*

Files:
1 modified

Legend:

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

    r1768 r1781  
    306306 
    307307    def isAssignableTo(t as IType) as bool 
    308         return this is t or t.isSystemObjectClass 
     308        return this == t or t.isSystemObjectClass 
    309309 
    310310    def isComparableTo(t as IType) as bool 
    311         return this is t 
     311        return this == t 
    312312 
    313313    def isEquatableTo(t as IType) as bool 
    314         return this is t 
     314        return this == t 
    315315 
    316316    def isDescendantOf(t as IType) as bool 
     
    320320        return not _nativeType.isValueType 
    321321 
     322    get isUninitializedForLocalVars as bool 
     323        return .isReference 
     324 
    322325    def isStrictDescendantOf(t as IType) as bool 
    323326        return this is not t and t.isSystemObjectClass 
     
    329332 
    330333    def greatestCommonDenominatorWith(type as IType) as IType 
    331         if type is this 
     334        if type == this 
    332335            return this 
    333336        else 
     
    505508        """ 
    506509        Return true if this type represents/is System.Type. 
     510        """ 
     511 
     512    get isUninitializedForLocalVars as bool 
     513        """ 
     514        Return true if a local var of this type is uninitialized without an explicit assignment. 
     515        The default implementation is typically: return .isReference 
     516        because non-nil reference types need an initial value. 
    507517        """ 
    508518 
     
    624634        return false 
    625635 
     636    get isUninitializedForLocalVars as bool 
     637        return .isReference 
     638 
    626639    def isComparableTo(t as IType) as bool 
    627640        t = t.nonNil 
     
    636649    def isEquatableTo(t as IType) as bool 
    637650        t = t.nonNil 
     651        if this == t 
     652            return true 
    638653        if .isAssignableTo(t) or t.isAssignableTo(this) 
    639654            return true 
     
    667682 
    668683    def greatestCommonDenominatorWith(type as IType) as IType 
    669         if this is type 
     684        if this == type 
    670685            return this 
    671686        if type inherits NilableType 
     
    689704            .typeProvider 
    690705        body 
    691             if type is .typeProvider.passThroughType 
    692                 return true 
    693             if type is .typeProvider.dynamicType 
    694                 return true 
    695             if type is .typeProvider.objectType 
    696                 return true 
    697             # TODO: remove this: 
    698             if type inherits GenericParam 
    699                 return true 
     706            if this == type, return true 
     707            if type is .typeProvider.passThroughType, return true 
     708            if type is .typeProvider.dynamicType, return true 
     709            if type is .typeProvider.objectType, return true 
     710            if type inherits GenericParam, return true  # TODO: remove this: 
    700711            # TODO: would this be needed if not for qualified types? 
    701             if type inherits WrappedType 
     712            if type inherits WrappedType  # TODO: I think this is wrong as it covers VariType and StreamType. It should only be non-nil 
    702713                return .isAssignableTo(type.theWrappedType to passthrough) # CC: bug with if-inherits changes the parameter type 
    703714            return .isDescendantOf(type) 
     
    707718        Returns true if this type is a subtype (direct or indirect) of type. 
    708719        """ 
    709         if not .didBindInh 
    710             .bindInh 
    711         if this is type 
    712             return true 
     720        if not .didBindInh, .bindInh 
     721        if this == type, return true 
    713722        curType = this to IType? 
    714723        counter = 0 
    715724        while true 
    716             if curType is type 
    717                 return true 
     725            if curType == type, return true 
    718726            curType = curType.superType 
    719             if curType is nil 
    720                 break 
     727            if curType is nil, break 
    721728            counter += 1 
    722729            assert counter < 1000 
     
    724731 
    725732    def isStrictDescendantOf(type as IType) as bool 
    726         if type is this 
     733        if type == this 
    727734            return false 
    728735        else 
     
    10411048 
    10421049    def greatestCommonDenominatorWith(type as IType) as IType is override 
    1043         if this is type 
     1050        if this == type 
    10441051            return this 
    10451052        if type inherits NilableType 
     
    11371144 
    11381145    def isAssignableTo(type as IType) as bool 
    1139         if type is this  # common case 
     1146        if type == this  # common case 
    11401147            return true 
    11411148        if type inherits FloatType 
     
    12701277 
    12711278    def isAssignableTo(type as IType) as bool 
    1272         if type is this  # common case 
     1279        if type == this  # common case 
    12731280            return true 
    12741281        if type is .typeProvider.decimalType 
     
    13221329        return _wrappedType.isReference 
    13231330 
     1331    get isUninitializedForLocalVars as bool is override 
     1332        return false  # because nil is fine for the default value 
     1333 
    13241334    # TODO: I think the following is appropriate, but come up with a test case for it first. 
    13251335    #get innerType 
     
    13541364 
    13551365    def greatestCommonDenominatorWith(type as IType) as IType is override 
    1356         if this is type 
     1366        if this == type 
    13571367            return this 
    13581368        if type inherits NilType 
    13591369            return this 
    13601370        if type inherits NilableType 
    1361             if _wrappedType is type.nonNil 
     1371            if _wrappedType == type.nonNil 
    13621372                return this 
    13631373            else 
     
    13801390 
    13811391    def isAssignableTo(type as IType) as bool is override 
    1382         if this is type, return true 
     1392        if this == type, return true 
    13831393        if type is .compiler.passThroughType, return true 
    13841394        if type inherits NilableType, return true 
     
    13861396 
    13871397    def greatestCommonDenominatorWith(type as IType) as IType is override 
    1388         if this is type 
     1398        if this == type 
    13891399            return this 
    13901400        if type inherits NilableType 
     
    14491459 
    14501460 
     1461class StreamType 
     1462    is partial 
     1463    inherits WrappedType 
     1464    """ 
     1465    - Streams are portable between backends, whereas .NET's IEnumerable<of> and JVM's Iterable<of> are not. 
     1466    - Streams are two-way compatible with IEnumerable/Iterable: 
     1467        - Streams can be used whereever a compatible IEnumerable/Iterable is expected. 
     1468        - An IEnumerable/Iterable can be used whereever a compatible stream type is expected. 
     1469        - The term "compatible" means the same inner type: int* is compatible with IEnumerable<of int>/Iterable<of int>, but not IEnumerable<of String>/Iterable<of String> 
     1470    - Streams are an abstract type, so you cannot create them directly with a call on the type such as `int*()`. Instead, use a concrete class such as `List<of>` or `yield` results out of a method. 
     1471    - Streams are defaulted to be empty rather than nil. 
     1472    """ 
     1473 
     1474    var _box as Box? 
     1475 
     1476    def init(t as IType) 
     1477        base.init(t) 
     1478 
     1479    get englishName as String is override 
     1480        return 'stream of ' + _wrappedType.englishName 
     1481 
     1482    get box from var 
     1483 
     1484    get name as String is override 
     1485        return _wrappedType.name + '*' 
     1486 
     1487    get isReference as bool is override 
     1488        return true 
     1489 
     1490    get isUninitializedForLocalVars as bool is override 
     1491        return false  # because streams get initialized to EmptyStream<of T> for convenience 
     1492 
     1493    get innerType as IType? is override 
     1494        return .theWrappedType 
     1495 
     1496    def isAssignableTo(type as IType) as bool is override 
     1497        return base.isAssignableTo(type) 
     1498 
     1499    def isComparableTo(b as IType) as bool is override 
     1500        return base.isComparableTo(b) 
     1501 
     1502    def isDescendantOf(type as IType) as bool 
     1503        return base.isDescendantOf(type) or .box.isDescendantOf(type) 
     1504 
     1505    def isEquatableTo(b as IType) as bool is override 
     1506        return base.isEquatableTo(b) 
     1507 
     1508    def memberForName(name as String) as IMember? is override 
     1509        return _box.memberForName(name) 
     1510 
     1511    def greatestCommonDenominatorWith(type as IType) as IType is override 
     1512        return base.greatestCommonDenominatorWith(type) 
     1513 
     1514    def _bindInh 
     1515        base._bindInh 
     1516        if .compiler  # will be nil during unit tests 
     1517            _box = .compiler.enumerableOfType.constructedTypeFor([.theWrappedType]) 
     1518            _box.bindInh 
     1519            _superType = _box 
     1520        else if _superType is nil  # TODO: is this really needed? 
     1521            _superType = .compiler.objectType 
     1522 
     1523    def _bindInt 
     1524        base._bindInt 
     1525        # TODO: why do we have to do this? 
     1526        if not .didBindInh 
     1527            .bindInh 
     1528 
     1529 
    14511530class VoidType 
    14521531    is partial 
     
    15151594 
    15161595    get innerType as IType? is override 
    1517         return _wrappedType.innerType 
     1596        return _wrappedType.innerType  # TODO: 2008-11-22, I think this should just be _wrappedType 
    15181597 
    15191598    def secondaryConstructedTypeFor(box as Box, gpToType as Dictionary<of GenericParam, IType>) as IType is override 
     
    15601639 
    15611640    get name as String is override 
    1562         return _wrappedType.name+r'[]' 
     1641        return _wrappedType.name + r'[]' 
    15631642 
    15641643    def isAssignableTo(type as IType) as bool is override 
     
    15681647            if _wrappedType == type.theWrappedType 
    15691648                return true 
     1649        if type inherits StreamType 
     1650            return .isAssignableTo(type.box to !) 
    15701651        return false 
    15711652 
    15721653    def _bindInh 
    15731654        base._bindInh 
    1574         ienum = .compiler.enumerableOfType 
    1575         _superType = ienum.constructedTypeFor([.theWrappedType]) 
     1655        _superType = .compiler.enumerableOfType.constructedTypeFor([.theWrappedType]) 
    15761656 
    15771657    def memberForName(name as String) as IMember?