2002-05-06 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Mon, 6 May 2002 22:53:24 +0000 (22:53 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 6 May 2002 22:53:24 +0000 (22:53 -0000)
* ecore.cs (StandardConversionExists): Augment with missing code:
deal with IntConstant, LongConstants and Enumerations.

svn path=/trunk/mcs/; revision=4353

mcs/mcs/ChangeLog
mcs/mcs/assign.cs
mcs/mcs/ecore.cs

index 46f56c0a3d24aad9581a48db2b2f8a9d0638aa6f..6e3035cdf73b11af8e99cb4dc3bbe5122fe74683 100755 (executable)
@@ -1,5 +1,8 @@
 2002-05-06  Miguel de Icaza  <miguel@ximian.com>
 
+       * ecore.cs (StandardConversionExists): Augment with missing code:
+       deal with IntConstant, LongConstants and Enumerations.
+
        * assign.cs: Report the error, instead of failing silently
 
        * rootcontext.cs (AddGlobalAttributes): Track attributes on the
index bc3ee69d74ad2349ae4ef1d0e2f9708682dd2852..af30e1dc81b5c0e94bb1e645c34b8286dac6a01e 100755 (executable)
@@ -260,7 +260,7 @@ namespace Mono.CSharp {
                                        if (StandardConversionExists (a.original_source, target_type))
                                                return this;
 
-                                       Error_CannotConvertImplicit (l, source_type, target_type);
+                                       Error_CannotConvertImplicit (l, a.original_source.Type, target_type);
                                        return null;
                                }
                        }
index 5a6204a73aa4c3095c54eec863261cc80663380f..07b6e96cc9e5a47a54b2eff676a68ce978a8f0f9 100755 (executable)
@@ -746,7 +746,7 @@ namespace Mono.CSharp {
                                return true;
 
                        // First numeric conversions 
-                       
+
                        if (expr_type == TypeManager.sbyte_type){
                                //
                                // From sbyte to short, int, long, float, double.
@@ -917,6 +917,55 @@ namespace Mono.CSharp {
                                
                        }
 
+                       if (expr is IntConstant){
+                               int value = ((IntConstant) expr).Value;
+
+                               if (target_type == TypeManager.sbyte_type){
+                                       if (value >= SByte.MinValue && value <= SByte.MaxValue)
+                                               return true;
+                               } else if (target_type == TypeManager.byte_type){
+                                       if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
+                                               return true;
+                               } else if (target_type == TypeManager.short_type){
+                                       if (value >= Int16.MinValue && value <= Int16.MaxValue)
+                                               return true;
+                               } else if (target_type == TypeManager.ushort_type){
+                                       if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
+                                               return true;
+                               } else if (target_type == TypeManager.uint32_type){
+                                       if (value >= 0)
+                                               return true;
+                               } else if (target_type == TypeManager.uint64_type){
+                                        //
+                                        // we can optimize this case: a positive int32
+                                        // always fits on a uint64.  But we need an opcode
+                                        // to do it.
+                                        //
+                                       if (value >= 0)
+                                               return true;
+                               }
+                               
+                               if (value == 0 && expr is IntLiteral && TypeManager.IsEnumType (target_type))
+                                       return true;
+                       }
+
+                       if (expr is LongConstant && target_type == TypeManager.uint64_type){
+                               //
+                               // Try the implicit constant expression conversion
+                               // from long to ulong, instead of a nice routine,
+                               // we just inline it
+                               //
+                               long v = ((LongConstant) expr).Value;
+                               if (v > 0)
+                                       return true;
+                       }
+                       
+                       if (target_type.IsSubclassOf (TypeManager.enum_type) && expr is IntLiteral){
+                               IntLiteral i = (IntLiteral) expr;
+
+                               if (i.Value == 0)
+                                       return true;
+                       }
                        return false;
                }