Changeset 2304
- Timestamp:
- 03/08/10 06:19:46 (2 years ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 8 modified
-
BinaryOpExpr.cobra (modified) (1 diff)
-
Compiler.cobra (modified) (3 diffs)
-
Container.cobra (modified) (1 diff)
-
Expr.cobra (modified) (1 diff)
-
Phases/BindInheritancePhase.cobra (modified) (1 diff)
-
Phases/BindInterfacePhase.cobra (modified) (1 diff)
-
TypeProxies.cobra (modified) (5 diffs)
-
Types.cobra (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/BinaryOpExpr.cobra
r2297 r2304 962 962 base._bindImp 963 963 if not _type inherits NilableType 964 _type = NilableType(_type).bindAll to NilableType # CC: axe cast when 'as this' is supported964 _type = .typeProvider.nilableType(_type to !) 965 965 # warn about redundancy 966 966 if not .left.hasError and not .right.hasError -
cobra/trunk/Source/Compiler.cobra
r2277 r2304 483 483 var _unspecifiedType as UnspecifiedType? 484 484 var _voidType as VoidType? 485 var _nilableTypes as Dictionary<of INode, NilableType>? 485 486 var _variTypes as Dictionary<of INode, VariType>? 486 487 var _nilableDynamicType as NilableType? … … 597 598 return _voidType to ! 598 599 600 def nilableType(type as IType) as NilableType 601 if type inherits NilableType, return type 602 if _nilableTypes is nil 603 _nilableTypes = Dictionary<of INode, NilableType>() 604 if _nilableTypes.containsKey(type) 605 return _nilableTypes[type] 606 else 607 _nilableTypes[type] = nt = NilableType(type) 608 nt.bindInh 609 nt.bindInt 610 return nt 611 599 612 def variType(type as IType) as VariType 600 613 if _variTypes is nil … … 615 628 616 629 ## More type stuff 617 618 def nilableType(t as IType) as NilableType619 """620 Returns a NilableType wrapper for t, unless t is already a NilableType in which case621 it is returned directly.622 """623 if t inherits NilableType624 return t625 else626 return NilableType(t).bindAll to NilableType # CC: axe cast after "as this"627 630 628 631 def readSystemTypes -
cobra/trunk/Source/Container.cobra
r2299 r2304 220 220 return type.greatestCommonDenominatorWith(this) 221 221 if type inherits NilType 222 return NilableType(this)222 return .typeProvider.nilableType(this) 223 223 if .isDescendantOf(type) 224 224 return type -
cobra/trunk/Source/Expr.cobra
r2297 r2304 3039 3039 def _bindImp 3040 3040 base._bindImp 3041 if _expr.type inherits NilableType 3042 _type = _expr.type 3043 .compiler.warning(this, 'The given expression is already nilable so "to ?" is redundant. You can remove it.') # TODO: needs test case 3044 else 3045 _type = NilableType(_expr.type) 3041 if not _expr.hasError 3042 assert _expr.type 3043 if _expr.type inherits NilableType 3044 _type = _expr.type 3045 .compiler.warning(this, 'The given expression is already nilable so "to ?" is redundant. You can remove it.') # TODO: needs test case 3046 else 3047 _type = .typeProvider.nilableType(_expr.type to !) 3046 3048 3047 3049 -
cobra/trunk/Source/Phases/BindInheritancePhase.cobra
r2277 r2304 17 17 c.objectType.bindInh 18 18 c.stringType.bindInh 19 c.dynamicType.bindInh 20 c.passThroughType.bindInh 19 21 for mod in c.modules.clone 20 22 c.curModule = mod -
cobra/trunk/Source/Phases/BindInterfacePhase.cobra
r2277 r2304 18 18 c.objectType.bindInt 19 19 c.stringType.bindInt 20 c.dynamicType.bindInt 21 c.passThroughType.bindInt 20 22 for mod in c.modules.clone 21 23 c.curModule = mod -
cobra/trunk/Source/TypeProxies.cobra
r2277 r2304 84 84 85 85 get realType as IType is override 86 return NilableType(_innerType.realType)86 return .typeProvider.nilableType(_innerType.realType) 87 87 88 88 … … 267 267 if member.qualifiedName == 'System.Nullable<of>' 268 268 assert args.count == 1 269 member = NilableType(args[0])269 member = .typeProvider.nilableType(args[0]) 270 270 else 271 271 member = (member to Box).constructedTypeFor(args) … … 472 472 473 473 def _resolveType as IType is override 474 return ArrayType(_typeId.realType) 474 t = ArrayType(_typeId.realType) 475 t.bindInh 476 t.bindInt 477 return t 475 478 476 479 … … 485 488 486 489 def _resolveType as IType is override 487 return NilableType(_typeId.realType)490 return .typeProvider.nilableType(_typeId.realType) 488 491 489 492 get name as String is override … … 493 496 m = container.memberForName(.name[:-1]) 494 497 if m inherits IType 495 return NilableType(m)498 return .typeProvider.nilableType(m) 496 499 else 497 500 return m -
cobra/trunk/Source/Types.cobra
r2240 r2304 103 103 get voidType as VoidType 104 104 105 # TODO: def nilableType ... just like .variType. cache and get "is" testing105 def nilableType(t as IType) as NilableType 106 106 107 107 def variType(type as IType) as VariType … … 133 133 var _unspecifiedType as UnspecifiedType? 134 134 var _voidType as VoidType? 135 var _nilableTypes as Dictionary<of IType, NilableType>? 135 136 var _variTypes as Dictionary<of IType, VariType>? 136 137 var _defaultType as IType? … … 231 232 return _voidType to ! 232 233 234 def nilableType(type as IType) as NilableType 235 if type inherits NilableType, return type 236 if _nilableTypes is nil 237 _nilableTypes = Dictionary<of IType, NilableType>() 238 if _nilableTypes.containsKey(type) 239 return _nilableTypes[type] 240 else 241 _nilableTypes[type] = nt = NilableType(type) 242 nt.bindInh 243 nt.bindInt 244 return nt 245 233 246 def variType(type as IType) as VariType 234 247 if _variTypes is nil … … 247 260 def defaultType as IType 248 261 if _defaultType is nil 249 _defaultType = NilableType(.dynamicType)262 _defaultType = .nilableType(.dynamicType) 250 263 return _defaultType to ! 251 264 … … 698 711 return type.greatestCommonDenominatorWith(this) 699 712 if type inherits NilType 700 return NilableType(this)713 return .typeProvider.nilableType(this) 701 714 if .isDescendantOf(type) 702 715 return type … … 757 770 Returns a named member of System.Object by default. 758 771 """ 772 assert .didBindInh and .didBindInt 759 773 objectClass = .compiler.objectType 760 774 return objectClass.memberForName(name) … … 1064 1078 if this == type 1065 1079 return this 1066 if type inherits NilableType 1067 return NilableType(this) 1068 if type inherits NilType 1069 return NilableType(this) 1080 if type inherits NilableType or type inherits NilType 1081 return .typeProvider.nilableType(this) 1070 1082 return this 1071 1083 … … 1323 1335 1324 1336 class NilableType inherits WrappedType is partial 1337 """ 1338 Rather than instantiating this type directly, use: 1339 1340 .typeProvider.nilableType(t) 1341 1342 Or if the code block already belongs to a type provider: 1343 1344 .nilableType(t) 1345 """ 1325 1346 1326 1347 cue init(t as IType?) … … 1373 1394 1374 1395 def memberForName(name as String) as IMember? is override 1396 _bindBasics 1375 1397 return _wrappedType.memberForName(name) 1376 1398 … … 1384 1406 return this 1385 1407 else 1386 return NilableType(_wrappedType.greatestCommonDenominatorWith(type.nonNil))1387 return NilableType(_wrappedType.greatestCommonDenominatorWith(type))1408 return .typeProvider.nilableType(_wrappedType.greatestCommonDenominatorWith(type.nonNil)) 1409 return .typeProvider.nilableType(_wrappedType.greatestCommonDenominatorWith(type)) 1388 1410 1389 1411 def suggestionsForBadMemberName(name as String) as List<of String> is override … … 1419 1441 return type 1420 1442 else 1421 return NilableType(type)1443 return .typeProvider.nilableType(type) 1422 1444 1423 1445 # TODO: … … 1623 1645 1624 1646 get innerType as IType? is override 1625 return _wrappedType.innerType # TODO: 2008-11-22, I think this should just be _wrappedType 1647 return _wrappedType.innerType # TODO: 2008-11-22, I think this should just be _wrappedType; 2010-03-07: or abstract and make subclasses specify 1626 1648 1627 1649 get suffix as String is abstract 1628 1650 1651 def memberForName(name as String) as IMember? is override 1652 _bindBasics 1653 return base.memberForName(name) 1654 1629 1655 def secondaryConstructedTypeFor(box as Box, gpToType as Dictionary<of GenericParam, IType>) as IType is override 1630 1656 thisType = .getType 1631 1657 return thisType(_wrappedType.secondaryConstructedTypeFor(box, gpToType)) 1658 1659 def _bindBasics 1660 .bindInh 1661 .bindInt 1632 1662 1633 1663



