Changeset 1703

Show
Ignore:
Timestamp:
10/23/08 13:27:14 (3 months ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Reading enums with non-int32 storage types (such as uint32 and uint64) causes an exception in the compiler.
credit:khjklujn,Chuck
ticket:53

Location:
cobra/trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1702 r1703  
    169169 
    170170* Fixed: CobraCore.exePath uses `Assembly.getExecutingAssembly` when it should be using `Assembly.getEntryAssembly` instead. This reveals itself when using -embed-run-time:no. 
     171 
     172* Fixed: Reading enums with non-int32 storage types (such as uint32 and uint64) causes an exception in the compiler. 
  • cobra/trunk/Source/Enums.cobra

    r1681 r1703  
    3131                _needScanNativeType = false 
    3232                clrType = (_nativeType to ClrType).theClrType # TODO: fix native 
    33                 isByte = Enum.getUnderlyingType(clrType).name == 'Byte' 
    34                 is64 = Enum.getUnderlyingType(clrType).name == 'Int64' 
    35                 values = Enum.getValues(clrType) 
     33                isByte  = Enum.getUnderlyingType(clrType).name == 'Byte' 
     34                is64    = Enum.getUnderlyingType(clrType).name == 'Int64' 
     35                isU32   = Enum.getUnderlyingType(clrType).name == 'UInt32' 
     36                isU64   = Enum.getUnderlyingType(clrType).name == 'UInt64' 
     37                values  = Enum.getValues(clrType) 
    3638                i = 0 
    3739                for name in Enum.getNames(clrType) 
     
    4547                                catch OverflowException 
    4648                                        intValue = 999  # CC: omg. but probably doesn't affect anything. we're reading the DLL here, not creating one 
     49                        else if isU32 
     50                                try 
     51                                        intValue = int.parse((value to UInt32).toString) 
     52                                catch OverflowException 
     53                                        intValue = 2147483647 
     54                        else if isU64 
     55                                try 
     56                                        intValue = int.parse((value to UInt64).toString) 
     57                                catch OverflowException 
     58                                        intValue = 2147483647 
    4759                        else 
    4860                                intValue = value to int 
     
    8799                if _storageTypeNode 
    88100                        _storageType = _storageTypeNode.realType 
    89                         # TODO: give error if _storageType is not some kind of int or char or whatever is legal 
     101                        if not _storageType.isDescendantOf(.compiler.anyIntType) 
     102                                .throwError('The enumeration storage type must be a primitive integer type such as int8, uint8, int16, uint16, int, uint, int64 or uint64.') 
    90103                if _needScanNativeType 
    91104                        _scanClrType 
     
    94107                base._bindImp 
    95108                for attrib in .attributes, attrib.bindImp 
    96                 # TODO: can this be removed? since the storage type is always something primitive like 'int', there should be no need for enum to give it .bindImp 
    97                 if _storageType 
    98                         _storageType.bindImp 
     109                # the storage type is always a primitive type like `int` so no _bindImp is necessary 
    99110 
    100111        def extensionMemberFor(box as Box, name as String) as IMember?