Changeset 1768
- Timestamp:
- 11/16/08 00:26:47 (8 weeks ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 7 modified
-
BackEndClr/SharpGenerator.cobra (modified) (4 diffs)
-
BinaryOpExpr.cobra (modified) (8 diffs)
-
Boxes.cobra (modified) (2 diffs)
-
Container.cobra (modified) (3 diffs)
-
Expr.cobra (modified) (6 diffs)
-
Members.cobra (modified) (2 diffs)
-
Types.cobra (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/BackEndClr/SharpGenerator.cobra
r1767 r1768 3374 3374 .writeSharpArgs(sw) 3375 3375 sw.write(')') 3376 else if expr.type.isDescendantOf(.compiler.delegateType) 3377 isMethodSig = true 3378 else if expr.type inherits NilableType and (expr.type to NilableType).theWrappedType.isDescendantOf(.compiler.delegateType) 3376 else if expr.type.nonNil.isDescendantOf(.compiler.delegateType) 3379 3377 isMethodSig = true 3380 3378 else if expr.type.isSystemTypeClass or _type.isDynamic … … 3383 3381 assert false, expr 3384 3382 else if expr inherits IndexExpr 3385 if expr.type. isDescendantOf(.compiler.delegateType)3383 if expr.type.nonNil.isDescendantOf(.compiler.delegateType) 3386 3384 isMethodSig = true 3387 3385 else if expr.type.isSystemTypeClass or _type.isDynamic … … 3868 3866 def writeSharpDef(sw as SharpWriter, parens as bool) is override 3869 3867 type = _expr.type 3870 if type inherits NilableType and not (type to NilableType).theWrappedType.isReference3868 if type inherits NilableType and not type.nonNil.isReference 3871 3869 # ex: (x).Value 3872 3870 # ex: (obj.foo).Value … … 4410 4408 right = .right 4411 4409 t = right.definition to IType 4412 if t inherits NilableType, t = t.theWrappedType4410 t = t.nonNil 4413 4411 typeSharpRef = t.sharpRef 4414 4412 if t.isReference -
cobra/trunk/Source/BinaryOpExpr.cobra
r1767 r1768 296 296 tstring = .compiler.stringType 297 297 cannotMix = false 298 leftType = _left.type 299 if leftType inherits NilableType 300 leftType = leftType.theWrappedType 301 rightType = _right.type 302 if rightType inherits NilableType 303 rightType = rightType.theWrappedType 304 305 tgcd = leftType.greatestCommonDenominatorWith(rightType to !) 298 leftType = _left.type.nonNil 299 rightType = _right.type.nonNil 300 301 tgcd = leftType.greatestCommonDenominatorWith(rightType) 306 302 307 303 if leftType.isDescendantOf(tint) … … 383 379 # TODO: error 384 380 pass 385 else if .left.type. isDescendantOf(.compiler.delegateType)381 else if .left.type.nonNil.isDescendantOf(.compiler.delegateType) 386 382 leftSource = .left.toCobraSource 387 383 rightSource = .right.toCobraSource … … 459 455 def _bindImp # TODO: this is all messed up. does this get called? TODO: this is missing, so its not being run. resolve with base class: is override 460 456 base._bindImp 461 lt = _left.type 462 if lt inherits NilableType 463 lt = lt.theWrappedType 464 rt = _right.type 465 if rt inherits NilableType 466 rt = rt.theWrappedType 457 lt = _left.type.nonNil 458 rt = _right.type.nonNil 467 459 if lt is rt 468 460 assert _type == lt or (_type is .compiler.decimalType and _op=='SLASH') … … 731 723 if leftType 732 724 okay = true 733 if leftType inherits DynamicType or (leftType inherits NilableType and (leftType to NilableType).theWrappedType inherits DynamicType)725 if leftType.isDynamic 734 726 pass 735 727 else if leftType.isDescendantOf(rightType) … … 738 730 # ex: someShape inherits Circle 739 731 pass 740 else if leftType inherits NilableType and not rightType inherits NilableType and rightType.isStrictDescendantOf( (leftType to NilableType).theWrappedType)732 else if leftType inherits NilableType and not rightType inherits NilableType and rightType.isStrictDescendantOf(leftType.nonNil) 741 733 # ex: someNilableShape inherits Circle 742 734 pass 743 else if leftType inherits NilableType and not rightType inherits NilableType and (leftType to NilableType).theWrappedType.isDescendantOf(rightType)735 else if leftType inherits NilableType and not rightType inherits NilableType and leftType.nonNil.isDescendantOf(rightType) 744 736 # ex: someNilableCircle inherits Shape 745 737 .compiler.warning(this, 'The expression will always be of type "[.right.toCobraSource]" when not nil. You can just check for not nil by removing "inherits [.right.toCobraSource]".') … … 823 815 if rightType 824 816 if _left.type inherits NilableType and not rightType inherits NilableType 825 if (_left.type to NilableType).theWrappedType isrightType817 if _left.type.nonNil == rightType 826 818 .compiler.warning(this, 'The given expression is already a "[_rightTypeExpr.toCobraSource]", but nilable. You can just use "to !".') 827 819 else if not _left.type inherits NilableType and rightType inherits NilableType 828 if (rightType to NilableType).theWrappedType== _left.type820 if rightType.nonNil == _left.type 829 821 .compiler.warning(this, 'The given expression is already a "[_left.type.name]", but not nilable. You can just use "to ?".') 830 822 else if _left.type == rightType … … 868 860 else if _left.type inherits NilableType and not _right.type inherits NilableType 869 861 # x ? y ...where x can be nil, but y cannot 870 _type = (_left.type to NilableType).theWrappedType# TODO: should be greatest common denominator between the two862 _type = _left.type.nonNil # TODO: should be greatest common denominator between the two 871 863 else 872 864 # the catch all case … … 894 886 # else if _right.type inherits NilableType and not _right.type inherits NilableType 895 887 # # x ? y ...where x can be nil, but y cannot 896 # _type = _left.type. theWrappedType# TODO: should be greatest common denominator between the two888 # _type = _left.type.nonNil # TODO: should be greatest common denominator between the two 897 889 else 898 890 # the catch all case -
cobra/trunk/Source/Boxes.cobra
r1718 r1768 426 426 break 427 427 rt = getEnum.resultType 428 if rt is .compiler.passThroughType428 if rt.isDynamicOrPassThrough 429 429 return rt 430 if rt.isDynamic 431 return rt 432 if rt inherits NilableType 433 # nilable is not a concern; unwrap it: 434 rt = rt.theWrappedType 430 rt = rt.nonNil # nilable is not a concern; unwrap it 435 431 if rt inherits Box and (rt to Box).isGeneric 436 432 # don't take the first argument of the result type -- that won't work for a nested type in a generic class, like ValueCollection, which gets the generic params of its parents … … 688 684 r = base.isAssignableTo(type) 689 685 if not r 690 if type inherits NilableType 691 type = type.theWrappedType 686 type = type.nonNil 692 687 if type inherits PrimitiveType 693 688 if type.systemAliasType == this -
cobra/trunk/Source/Container.cobra
r1656 r1768 253 253 if not type.didBindInt # TODO: shouldn't need this 254 254 type.bindInt 255 return .isAssignableTo(type.theWrappedType to passthrough) # CC: weird cast 255 return .isAssignableTo(type.theWrappedType to passthrough) # CC: weird cast. bug. has to do with if-inherits and invoking the same method 256 256 result_ = .isDescendantOf(type) # CC: rename to result 257 257 return result_ … … 259 259 # CC: duplicated from Type 260 260 def isComparableTo(t as IType) as bool 261 t = t.nonNil 261 262 if t inherits NilableType 262 263 t = t.theWrappedType … … 269 270 # CC: duplicated from Type 270 271 def isEquatableTo(t as IType) as bool 271 if t inherits NilableType 272 t = t.theWrappedType 272 t = t.nonNil 273 273 if .isAssignableTo(t) or t.isAssignableTo(this) # CC: to ! or assert above with nil flow analysis 274 274 return true 275 275 return false 276 277 # CC: duplicated from Type 278 get nonNil as IType 279 return this 276 280 277 281 def isDescendantOf(type as IType) as bool -
cobra/trunk/Source/Expr.cobra
r1767 r1768 609 609 else if arg.canBeAssignedTo(param.type) 610 610 score += 10 611 else if arg.type inherits NilableType and (arg.type to NilableType).theWrappedType.isAssignableTo(param.type)611 else if arg.type.nonNil.isAssignableTo(param.type) 612 612 # Cobra's code and data flow analysis sometimes leaves us with a nilable type that's not actually nil anymore 613 613 # due to an assignment, possibly wrapped in an if statement. Eventually this will be corrected, but for now … … 706 706 print '<> param.type =', param.type 707 707 print '<> param.ifInheritsStack.count =', param.ifInheritsStack.count 708 if arg.type inherits NilableType and not param.type inherits NilableType and (arg.type to NilableType).theWrappedType.isAssignableTo(param.type)708 if arg.type inherits NilableType and not param.type inherits NilableType and arg.type.nonNil.isAssignableTo(param.type) 709 709 .throwError('Argument [i+1] of method "[_name]" expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]).') 710 710 else … … 1167 1167 print '<> param = ' stop 1168 1168 param.writeDeepString 1169 if arg.type inherits NilableType and not param.type inherits NilableType and (arg.type to NilableType).theWrappedType.isAssignableTo(param.type)1169 if arg.type inherits NilableType and not param.type inherits NilableType and arg.type.nonNil.isAssignableTo(param.type) 1170 1170 .throwError('Argument [i+1] of indexer expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]).') 1171 1171 else … … 1567 1567 if _type is nil 1568 1568 assert expr.type is not nil 1569 exprType = expr.type 1570 if exprType inherits NilableType 1571 exprType = exprType.theWrappedType 1569 exprType = expr.type.nonNil 1572 1570 if exprType inherits MethodSig 1573 1571 _type = exprType.returnType … … 1935 1933 _expr.bindImp 1936 1934 else if type inherits NilableType 1937 if type. theWrappedTypeinherits DynamicType1935 if type.nonNil inherits DynamicType 1938 1936 _treatment = Treatment.InvokeRuntime 1939 1937 else … … 2883 2881 base._bindImp 2884 2882 if (et = _expr.type) inherits NilableType 2885 _type = et. theWrappedType2883 _type = et.nonNil 2886 2884 else 2887 2885 .compiler.warning(this, 'The given expression is already non-nilable so "to !" is redundant. You can remove it.') # TODO: needs test case -
cobra/trunk/Source/Members.cobra
r1767 r1768 287 287 return true 288 288 if (a inherits NilableType) <> (b inherits NilableType) 289 if a inherits NilableType, a = a.theWrappedType 290 if b inherits NilableType, b = b.theWrappedType 291 return a == b 289 return a.nonNil == b.nonNil 292 290 return false 293 291 … … 374 372 _handlerType = _handlerTypeProxy.realType 375 373 # TODO: error check that _handlerType is a delegate 376 # _handlerType. isDescendantOf(.compiler.delegateType)374 # _handlerType.nonNil.isDescendantOf(.compiler.delegateType) 377 375 378 376 -
cobra/trunk/Source/Types.cobra
r1737 r1768 323 323 return this is not t and t.isSystemObjectClass 324 324 325 get nonNil as IType 326 return this 327 325 328 ## Methods 326 329 … … 512 515 """ 513 516 Returns true if this type can be compared to the given type via `is`, `is not`, `==` and `<>`. 517 """ 518 519 get nonNil as IType 520 """ 521 Returns the non-nil version of the receiver. 522 This is normally just the receiver itself, except in the case of NilableType. 514 523 """ 515 524 … … 616 625 617 626 def isComparableTo(t as IType) as bool 618 if t inherits NilableType 619 t = t.theWrappedType 627 t = t.nonNil 620 628 compareTo = .memberForName('compareTo') 621 629 if compareTo and compareTo.isMethod and compareTo.resultType is .compiler.intType and t.isDescendantOf(this) … … 627 635 628 636 def isEquatableTo(t as IType) as bool 629 if t inherits NilableType 630 t = t.theWrappedType 637 t = t.nonNil 631 638 if .isAssignableTo(t) or t.isAssignableTo(this) 632 639 return true 633 640 return false 641 642 get nonNil as IType 643 return this 634 644 635 645 get requiresThis as bool … … 1319 1329 if _wrappedType.isDynamic, return true 1320 1330 if type inherits PassThroughType, return true 1321 if type inherits NilableType, return _wrappedType.isAssignableTo(type. theWrappedType)1331 if type inherits NilableType, return _wrappedType.isAssignableTo(type.nonNil) 1322 1332 return false 1323 1333 … … 1336 1346 else 1337 1347 return _wrappedType.isEquatableTo(b) 1348 1349 get nonNil as IType is override 1350 return _wrappedType 1338 1351 1339 1352 def memberForName(name as String) as IMember? is override … … 1346 1359 return this 1347 1360 if type inherits NilableType 1348 if _wrappedType is type. theWrappedType1361 if _wrappedType is type.nonNil 1349 1362 return this 1350 1363 else 1351 return NilableType(_wrappedType.greatestCommonDenominatorWith(type. theWrappedType))1364 return NilableType(_wrappedType.greatestCommonDenominatorWith(type.nonNil)) 1352 1365 return NilableType(_wrappedType.greatestCommonDenominatorWith(type)) 1353 1366 … … 1367 1380 1368 1381 def isAssignableTo(type as IType) as bool is override 1369 if this is type 1370 return true 1371 if type is .compiler.passThroughType 1372 return true 1373 if type inherits NilableType 1374 return true 1382 if this is type, return true 1383 if type is .compiler.passThroughType, return true 1384 if type inherits NilableType, return true 1375 1385 return false 1376 1386 … … 1623 1633 1624 1634 def isNilableAndDescendantOf(otherType as IType) as bool 1625 return this inherits NilableType and ((this to NilableType).theWrappedType).isDescendantOf(otherType)1635 return this inherits NilableType and .nonNil.isDescendantOf(otherType) 1626 1636 1627 1637 def isSequenceLike as bool … … 1633 1643 type = this 1634 1644 if type inherits NilableType 1635 return type. theWrappedType.isSequenceLike1645 return type.nonNil.isSequenceLike 1636 1646 # TODO: check for ISliceable which would have a .getSlice 1637 1647 tp = Node.getCompiler # 'tp' for 'type provider' … … 1667 1677 type = this 1668 1678 if type inherits NilableType 1669 return type. theWrappedType.isDictionaryLike1679 return type.nonNil.isDictionaryLike 1670 1680 tp = Node.getCompiler # 'tp' for 'type provider' # TODO? expand ITypeProvider to cover idictionaryType, dictionaryOfType, idictionaryOfType 1671 1681 if type.isDescendantOf(tp.idictionaryType)
