2002-10-03 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Thu, 3 Oct 2002 17:40:04 +0000 (17:40 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 3 Oct 2002 17:40:04 +0000 (17:40 -0000)
* expression.cs (Cast.TryReduce): Also handle decimal types when
trying to perform a constant fold on the type.

* typemanager.cs (IsUnmanagedtype): Partially implemented.

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

mcs/mcs/ChangeLog
mcs/mcs/expression.cs
mcs/mcs/typemanager.cs

index 47dec0b575d466696e30404e2d09b7652a45d05e..96e5921d227e3a1f42f03274c0794024104ce957 100755 (executable)
@@ -1,5 +1,10 @@
 2002-10-03  Miguel de Icaza  <miguel@ximian.com>
 
+       * expression.cs (Cast.TryReduce): Also handle decimal types when
+       trying to perform a constant fold on the type.
+
+       * typemanager.cs (IsUnmanagedtype): Partially implemented.
+
        * parameter.cs: Removed ResolveAndDefine, as it was not needed, as
        that only turned off an error report, and did nothing else. 
 
index 33ee27f705738644d901300f66296176eff98300..2e35d4d02824f32efd16225dd280d3ececddb0a7 100755 (executable)
@@ -1205,6 +1205,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is SByteConstant){
                                sbyte v = ((SByteConstant) expr).Value;
@@ -1229,6 +1231,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is ShortConstant){
                                short v = ((ShortConstant) expr).Value;
@@ -1253,6 +1257,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is UShortConstant){
                                ushort v = ((UShortConstant) expr).Value;
@@ -1277,6 +1283,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is IntConstant){
                                int v = ((IntConstant) expr).Value;
@@ -1301,6 +1309,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is UIntConstant){
                                uint v = ((UIntConstant) expr).Value;
@@ -1325,6 +1335,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is LongConstant){
                                long v = ((LongConstant) expr).Value;
@@ -1349,6 +1361,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is ULongConstant){
                                ulong v = ((ULongConstant) expr).Value;
@@ -1373,6 +1387,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is FloatConstant){
                                float v = ((FloatConstant) expr).Value;
@@ -1397,6 +1413,8 @@ namespace Mono.CSharp {
                                        return new DoubleConstant ((double) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
                        if (expr is DoubleConstant){
                                double v = ((DoubleConstant) expr).Value;
@@ -1421,6 +1439,8 @@ namespace Mono.CSharp {
                                        return new FloatConstant ((float) v);
                                if (target_type == TypeManager.char_type)
                                        return new CharConstant ((char) v);
+                               if (target_type == TypeManager.decimal_type)
+                                       return new DecimalConstant ((decimal) v);
                        }
 
                        return null;
@@ -5337,6 +5357,11 @@ namespace Mono.CSharp {
                        if (type_queried == null)
                                return null;
 
+                       if (!TypeManager.IsUnmanagedType (type_queried)){
+                               Report.Error (208, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
+                               return null;
+                       }
+                       
                        type = TypeManager.int32_type;
                        eclass = ExprClass.Value;
                        return this;
index 724f3580c2e1bb015a918174180cdf9ebdfb6267..80fbfc346f1d4ddb07ec8d4d0592e05cbd7b289b 100755 (executable)
@@ -1062,7 +1062,30 @@ public class TypeManager {
                else
                        return false;
        }
-       
+
+       //
+       // Whether a type is unmanaged.  This is used by the unsafe code (25.2)
+       //
+       public static bool IsUnmanagedType (Type t)
+       {
+               if (IsBuiltinType (t))
+                       return true;
+               if (IsEnumType (t))
+                       return true;
+               if (t.IsPointer)
+                       return true;
+
+               if (IsValueType (t)){
+                       //
+                       // FIXME: Check that every field in the struct is Unmanaged
+                       //
+
+                       return true;
+               }
+               
+               return false;
+       }
+               
        public static bool IsValueType (Type t)
        {
                if (t.IsSubclassOf (TypeManager.value_type))