Changeset 1718
- Timestamp:
- 11/01/08 04:12:37 (2 months ago)
- Location:
- cobra/trunk/Source
- Files:
-
- 8 modified
-
Boxes.cobra (modified) (2 diffs)
-
ClrType.cobra (modified) (3 diffs)
-
Compiler.cobra (modified) (2 diffs)
-
Enums.cobra (modified) (2 diffs)
-
ScanClrType.cobra (modified) (4 diffs)
-
SharpGenerator.cobra (modified) (2 diffs)
-
TypeProxies.cobra (modified) (3 diffs)
-
Types.cobra (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Boxes.cobra
r1710 r1718 979 979 base.init(TokenFix.empty, ClrTypeProxy.cobraNameForSharpBoxName(nativeType.name), List<of IType>(), List<of String>(), AttributeList(), List<of ITypeProxy>(), nil) 980 980 if nativeType.baseType 981 _baseNode = ClrTypeProxy(nativeType.baseType to Clr Type) # TODO: fix native. Change to NativeTypeProxy981 _baseNode = ClrTypeProxy(nativeType.baseType to ClrNativeType) # TODO: fix native. Change to NativeTypeProxy 982 982 _initNativeType(nativeType) 983 983 … … 1463 1463 # the real extended type is not this type, but the type of the first argument of any method 1464 1464 for methInfo in .clrType.getMethods # TODO: fix native. break this out to a method 1465 nativeType = Clr Type(methInfo.getParameters[0].parameterType)1465 nativeType = ClrNativeType(methInfo.getParameters[0].parameterType) 1466 1466 break 1467 1467 _extendedBoxProxy = ClrTypeProxy(nativeType) -
cobra/trunk/Source/ClrType.cobra
r1671 r1718 1 class Clr Type1 class ClrNativeType 2 2 inherits NativeType 3 3 … … 7 7 _type = type 8 8 9 get theClrType as Type 9 def equals(other as Object) as bool is override 10 if other is this 11 return true 12 if other inherits ClrNativeType 13 return .clrType == other.clrType 14 else 15 return false 16 17 def getHashCode as int is override 18 return .clrType.getHashCode 19 20 get clrType as Type 10 21 return _type 11 22 … … 20 31 21 32 get baseType as NativeType? is override 22 return if(_type.baseType, Clr Type(_type.baseType), nil)33 return if(_type.baseType, ClrNativeType(_type.baseType), nil) 23 34 24 35 -
cobra/trunk/Source/Compiler.cobra
r1710 r1718 877 877 if verbosity >= 4 878 878 print ' Reading type [type.name] in namespace "[namespaceName]"' 879 clrType = Clr Type(type)879 clrType = ClrNativeType(type) 880 880 if type.isClass 881 881 if type.name.startsWith('Extend_') and Utils.countChars(type.name, c'_') >= 2 … … 1336 1336 return .codeMemberStack.peek.findLocal(name) 1337 1337 1338 def clrType(qualifiedName as String) as System.Type 1338 def nativeType(qualifiedName as String) as NativeType 1339 return ClrNativeType(_clrType(qualifiedName)) 1340 1341 def _clrType(qualifiedName as String) as System.Type 1339 1342 # eventually this method will be key in targeting different versions of the CLR 1340 1343 # suppose you are on .NET 3.0 and want to target .NET 2.0 -
cobra/trunk/Source/Enums.cobra
r1703 r1718 24 24 _attribs = AttributeList() 25 25 _nativeType = nativeType 26 _storageTypeNode = ClrTypeProxy(Enum.getUnderlyingType((_nativeType to Clr Type).theClrType)) # TODO: fix native26 _storageTypeNode = ClrTypeProxy(Enum.getUnderlyingType((_nativeType to ClrNativeType).clrType)) # TODO: fix native 27 27 _needScanNativeType = true 28 28 … … 30 30 # TODO: read attribs 31 31 _needScanNativeType = false 32 clrType = (_nativeType to Clr Type).theClrType # TODO: fix native32 clrType = (_nativeType to ClrNativeType).clrType # TODO: fix native 33 33 isByte = Enum.getUnderlyingType(clrType).name == 'Byte' 34 34 is64 = Enum.getUnderlyingType(clrType).name == 'Int64' -
cobra/trunk/Source/ScanClrType.cobra
r1671 r1718 7 7 Throws exception rather than return nil. 8 8 """ 9 return (.nativeType to Clr Type).theClrType9 return (.nativeType to ClrNativeType).clrType 10 10 11 11 def _scanNativeType … … 30 30 if .clrType.isGenericType 31 31 for genArg in .clrType.getGenericArguments 32 _genericParams.add(GenericParam(Clr Type(genArg)))32 _genericParams.add(GenericParam(ClrNativeType(genArg))) 33 33 34 34 def _scanImplements … … 39 39 def _scanNestedTypes 40 40 for type in .clrType.getNestedTypes 41 clrType = Clr Type(type)41 clrType = ClrNativeType(type) 42 42 if type.isClass 43 43 .addDecl(Class(clrType)) … … 200 200 genericParams = List<of IType>() 201 201 for genArg in methInfo.getGenericArguments 202 genericParams.add(GenericParam(Clr Type(genArg)))202 genericParams.add(GenericParam(ClrNativeType(genArg))) 203 203 params = _scanParams(methInfo.getParameters) 204 204 isNames = _isNamesForMethodInfo(methInfo) -
cobra/trunk/Source/SharpGenerator.cobra
r1716 r1718 727 727 728 728 get sharpName as String is override 729 return _ clrType.name729 return _nativeType.name 730 730 731 731 … … 734 734 735 735 get sharpName as String is override 736 return _ clrType.name736 return _nativeType.name 737 737 738 738 -
cobra/trunk/Source/TypeProxies.cobra
r1681 r1718 141 141 142 142 def init(nativeType as NativeType) # TODO: HACK 143 .init((nativeType to Clr Type).theClrType)143 .init((nativeType to ClrNativeType).clrType) 144 144 145 145 def init(clrType as Type) … … 165 165 for bt in .compiler.basicTypes 166 166 if bt.systemAliasProxy 167 key = .compiler.clrType((bt.systemAliasProxy to LibraryTypeProxy).qualifiedName)167 key = (.compiler.nativeType((bt.systemAliasProxy to LibraryTypeProxy).qualifiedName) to ClrNativeType).clrType # TODO: cleanup 168 168 clrPrimitiveToIType[key] = bt 169 169 assert clrPrimitiveToIType.count == 0 or clrPrimitiveToIType.count > 9 … … 201 201 # generic parameters 202 202 if clrType.isGenericParameter 203 return GenericParam(Clr Type(clrType))203 return GenericParam(ClrNativeType(clrType)) 204 204 205 205 # compute type name -
cobra/trunk/Source/Types.cobra
r1707 r1718 44 44 """ 45 45 46 def equals(other as Object) as bool is override 47 throw Exception('Subclasses must override .equals') 48 49 def getHashCode as int is override 50 throw Exception('Subclasses must override .getHashCode') 51 46 52 47 53 interface ITypeProvider … … 99 105 def libraryType(qualifiedName as String) as IType 100 106 101 def clrType(qualifiedName as String) as System.Type107 def nativeType(qualifiedName as String) as NativeType 102 108 103 109 def defaultType as IType … … 230 236 231 237 def libraryType(qualifiedName as String) as IType 232 clrType = $sharp('Type.GetType(qualifiedName)') to Type? 233 return BasicLibraryType(clrType) 234 235 def clrType(qualifiedName as String) as System.Type 236 return sharp'Type.GetType(qualifiedName)' to System.Type 238 return BasicLibraryType(.nativeType(qualifiedName)) 239 240 def nativeType(qualifiedName as String) as NativeType 241 return ClrNativeType(sharp'Type.GetType(qualifiedName)' to System.Type) 237 242 238 243 def defaultType as IType … … 254 259 255 260 def systemObjectType as BasicLibraryType 256 return BasicLibraryType( $sharp('typeof(System.Object)'))257 258 var _ clrType asType259 260 def init( clrType asType)261 _ clrType = clrType261 return BasicLibraryType(ClrNativeType(sharp'typeof(System.Object)')) 262 263 var _nativeType as NativeType 264 265 def init(nativeType as NativeType) 266 _nativeType = nativeType 262 267 263 268 def toString as String is override 264 return '[.getType.name]([. clrType])'269 return '[.getType.name]([.nativeType])' 265 270 266 271 def equals(other as Object?) as bool is override 267 272 if other 268 273 if other inherits BasicLibraryType 269 return . clrType == other.clrType274 return .nativeType == other.nativeType 270 275 else 271 276 return false … … 274 279 275 280 def getHashCode as int is override 276 return _ clrType.getHashCode277 278 get clrType from var281 return _nativeType.getHashCode 282 283 get nativeType from var 279 284 280 285 ## IType Properties … … 295 300 296 301 get isSystemObjectClass as bool 297 return _ clrType.name == 'Object'302 return _nativeType.name == 'Object' 298 303 299 304 get isSystemTypeClass as bool 300 return _ clrType.name == 'Type'305 return _nativeType.name == 'Type' 301 306 302 307 def isAssignableTo(t as IType) as bool … … 313 318 314 319 get isReference as bool 315 return not _ clrType.isValueType320 return not _nativeType.isValueType 316 321 317 322 def isStrictDescendantOf(t as IType) as bool … … 413 418 414 419 get name as String 415 return . clrType.name420 return .nativeType.name 416 421 417 422 get typeForIdentifier as IType … … 788 793 var _systemAliasType as IType? 789 794 790 var _ clrType asType?795 var _nativeType as NativeType? 791 796 792 797 var _box as Box? … … 799 804 base.init(superType) 800 805 801 get clrType from var806 get nativeType from var 802 807 803 808 get systemAliasProxy from var … … 821 826 # _systemAliasType.bindInt 822 827 823 if .compiler and _ clrType828 if .compiler and _nativeType 824 829 meths = List<of Method>() 825 _installNativeMethodsFrom(_ clrType to !, meths)826 _installNativeMethodsFrom( System.Math.getType, meths)830 _installNativeMethodsFrom(_nativeType to !, meths) 831 _installNativeMethodsFrom(ClrNativeType(System.Math.getType), meths) 827 832 _box.bindInt 828 833 if false … … 843 848 print ' [meth.cobraSourceSignature]' 844 849 845 def _installNativeMethodsFrom(clrType as Type, meths as List<of Method>) 850 def _installNativeMethodsFrom(nativeType as NativeType, meths as List<of Method>) 851 argClrType = (nativeType to ClrNativeType).clrType 852 thisClrType = (_nativeType to ClrNativeType).clrType 846 853 box = _box 847 854 # print 848 855 # print '** [.name], clrType' 849 isSameNativeType = clrType == _clrType850 for methInfo in clrType.getMethods(BindingFlags(DeclaredOnly, Static, Instance, Public))856 isSameNativeType = argClrType == thisClrType 857 for methInfo in argClrType.getMethods(BindingFlags(DeclaredOnly, Static, Instance, Public)) 851 858 if methInfo.isSpecialName, continue 852 859 # print … … 862 869 first = false 863 870 if methInfo.isStatic 864 if methInfo.getParameters[0].parameterType == _clrType871 if methInfo.getParameters[0].parameterType == thisClrType 865 872 # When the first arg of the shared method is the same type, 866 873 # then make an instance method that can be used directly on values of the type. … … 882 889 meth = Method(Token.empty, box, name, newParams, ClrTypeProxy(methInfo.returnType), nil, modifiers, AttributeList(), '') 883 890 if methInfo.isStatic 884 meth.sharedMethodBacking = clrType.name + '.' + methInfo.name891 meth.sharedMethodBacking = argClrType.name + '.' + methInfo.name 885 892 if 'shared' in modifiers, meth.sharedMethodBackingIsAlias = true 886 893 … … 938 945 def init 939 946 base.init 940 _ clrType = .typeProvider.clrType('System.Boolean')947 _nativeType = .typeProvider.nativeType('System.Boolean') 941 948 _systemAliasProxy = LibraryTypeProxy('System.Boolean') 942 949 … … 951 958 def init 952 959 base.init 953 _ clrType = .typeProvider.clrType('System.Char')960 _nativeType = .typeProvider.nativeType('System.Char') 954 961 _systemAliasProxy = LibraryTypeProxy('System.Char') 955 962 … … 975 982 def init 976 983 base.init 977 _ clrType = .typeProvider.clrType('System.Decimal')984 _nativeType = .typeProvider.nativeType('System.Decimal') 978 985 _systemAliasProxy = LibraryTypeProxy('System.Decimal') 979 986 … … 1075 1082 _size = size 1076 1083 branch size 1077 on 32, _ clrType = .typeProvider.clrType('System.Single')1078 on 64, _ clrType = .typeProvider.clrType('System.Double')1084 on 32, _nativeType = .typeProvider.nativeType('System.Single') 1085 on 64, _nativeType = .typeProvider.nativeType('System.Double') 1079 1086 else, throw FallThroughException(size) 1080 _systemAliasProxy = LibraryTypeProxy(_ clrType.fullName)1087 _systemAliasProxy = LibraryTypeProxy(_nativeType.fullName) 1081 1088 1082 1089 def addMinFields … … 1188 1195 if signed 1189 1196 branch size 1190 on 8, _ clrType = .typeProvider.clrType('System.SByte')1191 on 16, _ clrType = .typeProvider.clrType('System.Int16')1192 on 32, _ clrType = .typeProvider.clrType('System.Int32')1193 on 64, _ clrType = .typeProvider.clrType('System.Int64')1197 on 8, _nativeType = .typeProvider.nativeType('System.SByte') 1198 on 16, _nativeType = .typeProvider.nativeType('System.Int16') 1199 on 32, _nativeType = .typeProvider.nativeType('System.Int32') 1200 on 64, _nativeType = .typeProvider.nativeType('System.Int64') 1194 1201 else: throw FallThroughException(size) 1195 1202 else 1196 1203 branch size 1197 on 8, _ clrType = .typeProvider.clrType('System.Byte')1198 on 16, _ clrType = .typeProvider.clrType('System.UInt16')1199 on 32, _ clrType = .typeProvider.clrType('System.UInt32')1200 on 64, _ clrType = .typeProvider.clrType('System.UInt64')1204 on 8, _nativeType = .typeProvider.nativeType('System.Byte') 1205 on 16, _nativeType = .typeProvider.nativeType('System.UInt16') 1206 on 32, _nativeType = .typeProvider.nativeType('System.UInt32') 1207 on 64, _nativeType = .typeProvider.nativeType('System.UInt64') 1201 1208 else, throw FallThroughException(size) 1202 _systemAliasProxy = LibraryTypeProxy(_ clrType.fullName)1209 _systemAliasProxy = LibraryTypeProxy(_nativeType.fullName) 1203 1210 1204 1211 def addMinFields
