Author: jambunathan
Date: 2005-02-28 13:16:38 -0500 (Mon, 28 Feb 2005)
New Revision: 41294

Modified:
   trunk/mcs/bmcs/ChangeLog
   trunk/mcs/bmcs/convert.cs
   trunk/mcs/bmcs/ecore.cs
   trunk/mcs/bmcs/typemanager.cs
Log:
* convert.cs: Added the following conversion routines:
BooleanConversions, WideningStringConversions,
NarrowingStringConversions.

* ecore.cs: Added following helper classes: BooleanToNumericCast,
NumericToBooleanCast
        
* typemanager.cs: Added System.DateTime to the cached types.



Modified: trunk/mcs/bmcs/ChangeLog
===================================================================
--- trunk/mcs/bmcs/ChangeLog    2005-02-28 18:16:34 UTC (rev 41293)
+++ trunk/mcs/bmcs/ChangeLog    2005-02-28 18:16:38 UTC (rev 41294)
@@ -1,3 +1,14 @@
+2005-03-01  Jambunathan K  <[EMAIL PROTECTED]>
+
+       * convert.cs: Added the following conversion routines:
+       BooleanConversions, WideningStringConversions,
+       NarrowingStringConversions.
+
+       * ecore.cs: Added following helper classes: BooleanToNumericCast,
+       NumericToBooleanCast
+       
+       * typemanager.cs: Added System.DateTime to the cached types.
+
 2005-02-28  Jambunathan K  <[EMAIL PROTECTED]>
 
        * ecore.cs (StringToExpression):

Modified: trunk/mcs/bmcs/convert.cs
===================================================================
--- trunk/mcs/bmcs/convert.cs   2005-02-28 18:16:34 UTC (rev 41293)
+++ trunk/mcs/bmcs/convert.cs   2005-02-28 18:16:38 UTC (rev 41294)
@@ -1674,6 +1674,184 @@
                        return null;
                }
 
+               /// <summary> 
+               /// VB.NET specific: Convert to and from boolean
+               /// </summary>
+
+               static public Expression BooleanConversions (EmitContext ec, 
Expression expr,
+                                                                   Type 
target_type, Location loc)
+               {
+                       Type expr_type = expr.Type;
+                       Type real_target_type = target_type;
+
+                       if (expr_type == TypeManager.bool_type) {
+
+                               //
+                               // From boolean to byte, short, int,
+                               // long, float, double, decimal
+                               //
+
+                               if (real_target_type == TypeManager.byte_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_U1);
+                               if (real_target_type == TypeManager.short_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_I2);
+                               if (real_target_type == TypeManager.int32_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_I4);
+                               if (real_target_type == TypeManager.int64_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_I8);
+                               if (real_target_type == TypeManager.float_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_R4);
+                               if (real_target_type == TypeManager.double_type)
+                                       return new BooleanToNumericCast (expr, 
target_type, OpCodes.Conv_R8);
+                               if (real_target_type == 
TypeManager.decimal_type) {
+                                       return new 
ImplicitInvocation("DecimalType", "FromBoolean", loc, expr);
+                               }
+                       } if (real_target_type == TypeManager.bool_type) {
+
+                               //
+                               // From byte, short, int, long, float,
+                               // double, decimal to boolean
+                               //
+
+                               if (expr_type == TypeManager.byte_type ||
+                                       expr_type == TypeManager.short_type ||
+                                       expr_type == TypeManager.int32_type ||
+                                       expr_type == TypeManager.int64_type || 
+                                       expr_type == TypeManager.float_type || 
+                                       expr_type == TypeManager.double_type)
+                                               return new NumericToBooleanCast 
(expr, expr_type);
+                               if (expr_type == TypeManager.decimal_type) {
+                                       return new ImplicitInvocation("System", 
"Convert", "ToBoolean", loc, expr);
+                               }
+                       }
+
+                       return null;
+               }
+
+               /// <summary> 
+               /// VB.NET specific: Widening conversions to string
+               /// </summary>
+
+               static public Expression WideningStringConversions (EmitContext 
ec, Expression expr,
+                                                                   Type 
target_type, Location loc)
+               {
+                       Expression ret_expr = DoWideningStringConversions (ec, 
expr, target_type, loc);
+
+                       if (ret_expr != null)
+                               ret_expr = ret_expr.Resolve (ec);
+
+                       return ret_expr;
+               }
+
+               static public Expression DoWideningStringConversions 
(EmitContext ec, Expression expr,
+                                                                   Type 
target_type, Location loc)
+
+               {
+                       Type expr_type = expr.Type;
+                       Type real_target_type = target_type;
+
+                       if (real_target_type == TypeManager.string_type) {
+                               //
+                               // From char to string
+                               //
+                               if (expr_type == TypeManager.char_type)
+                                       return new ImplicitInvocation 
("StringType", "FromChar", loc, expr);
+                       }
+
+                       if(expr_type.IsArray && (expr_type.GetElementType() == 
TypeManager.char_type)) {
+                               //
+                               // From char array to string
+                               //
+                               return new ImplicitNew ("System", "String", 
loc, expr);
+                       }
+
+                       return null;
+               }
+               
+               /// <summary> 
+               /// VB.NET specific: Narrowing conversions involving strings
+               /// </summary>
+
+               static public Expression NarrowingStringConversions 
(EmitContext ec, Expression expr,
+                                                                   Type 
target_type, Location loc)
+               {
+                       Expression ret_expr = DoNarrowingStringConversions (ec, 
expr, target_type, loc);
+
+                       if (ret_expr != null)
+                               ret_expr = ret_expr.Resolve (ec);
+
+                       return ret_expr;
+               }
+               
+               static public Expression DoNarrowingStringConversions 
(EmitContext ec, Expression expr,
+                                                                   Type 
target_type, Location loc)
+               {
+                       Type expr_type = expr.Type;
+                       Type real_target_type = target_type;
+
+                       // FIXME: Need to take care of Constants
+
+                       if (expr_type == TypeManager.string_type) {
+
+                               //
+                               // From string to chararray, bool,
+                               // byte, short, char, int, long,
+                               // float, double, decimal and date 
+                               //
+
+                               if (real_target_type.IsArray && 
(real_target_type.GetElementType() == TypeManager.char_type))
+                                       return new 
ImplicitInvocation("CharArrayType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.bool_type)
+                                       return new 
ImplicitInvocation("BooleanType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.byte_type)
+                                       return new 
ImplicitInvocation("ByteType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.short_type)
+                                       return new 
ImplicitInvocation("ShortType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.char_type)
+                                       return new 
ImplicitInvocation("CharType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.int32_type)
+                                       return new 
ImplicitInvocation("IntegerType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.int64_type)
+                                       return new 
ImplicitInvocation("LongType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.float_type)
+                                       return new 
ImplicitInvocation("SingleType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.double_type)
+                                       return new 
ImplicitInvocation("DoubleType", "FromString", loc, expr);
+                               if (real_target_type == 
TypeManager.decimal_type)
+                                       return new 
ImplicitInvocation("DecimalType", "FromString", loc, expr);
+                               if (real_target_type == TypeManager.date_type)
+                                       return new 
ImplicitInvocation("DateType", "FromString", loc, expr);
+                       } if (real_target_type == TypeManager.string_type) {
+
+                               //
+                               // From bool, byte, short, char, int,
+                               // long, float, double, decimal and
+                               // date to string
+                               //
+
+                               if (expr_type == TypeManager.bool_type)
+                                       return new 
ImplicitInvocation("StringType", "FromBoolean", loc, expr);
+                               if (expr_type == TypeManager.byte_type)
+                                       return new 
ImplicitInvocation("StringType", "FromByte", loc, expr);
+                               if (expr_type == TypeManager.short_type)
+                                       return new 
ImplicitInvocation("StringType", "FromShort", loc, expr);
+                               if (expr_type == TypeManager.int32_type)
+                                       return new 
ImplicitInvocation("StringType", "FromInteger", loc, expr);
+                               if (expr_type == TypeManager.int64_type)
+                                       return new 
ImplicitInvocation("StringType", "FromLong", loc, expr);
+                               if (expr_type == TypeManager.float_type)
+                                       return new 
ImplicitInvocation("StringType", "FromSingle", loc, expr);
+                               if (expr_type == TypeManager.double_type)
+                                       return new 
ImplicitInvocation("StringType", "FromDouble", loc, expr);
+                               if (expr_type == TypeManager.decimal_type)
+                                       return new 
ImplicitInvocation("StringType", "FromDecimal", loc, expr);
+                               if (expr_type == TypeManager.date_type)
+                                       return new 
ImplicitInvocation("StringType", "FromDate", loc, expr);
+                       }
+
+                       return null;
+               }
+
                /// <summary>
                ///  Returns whether an explicit reference conversion can be 
performed
                ///  from source_type to target_type

Modified: trunk/mcs/bmcs/ecore.cs
===================================================================
--- trunk/mcs/bmcs/ecore.cs     2005-02-28 18:16:34 UTC (rev 41293)
+++ trunk/mcs/bmcs/ecore.cs     2005-02-28 18:16:38 UTC (rev 41294)
@@ -2034,6 +2034,88 @@
                                ec.ig.Emit (OpCodes.Castclass, type);
                }
        }
+
+       //
+       // VB.NET specific
+       //
+       public class BooleanToNumericCast : EmptyCast {
+               OpCode op, op2;
+               
+               public BooleanToNumericCast (Expression child, Type 
return_type, OpCode op)
+                       : base (child, return_type)
+                       
+               {
+                       this.op = op;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       // This should never be invoked, we are born in fully
+                       // initialized state.
+
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       base.Emit (ec);
+                       ec.ig.Emit (OpCodes.Ldc_I4_0);
+                       ec.ig.Emit (OpCodes.Cgt_Un);
+                       ec.ig.Emit (OpCodes.Neg);
+                       ec.ig.Emit (op);
+               }                       
+       }
+
+       //
+       // VB.NET specific
+       //
+       public class NumericToBooleanCast : EmptyCast {
+
+               Type expr_type; 
+
+               public NumericToBooleanCast (Expression child, Type src_type)
+                       : base (child, TypeManager.bool_type)
+                       
+               {
+                       expr_type = src_type;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       // This should never be invoked, we are born in fully
+                       // initialized state.
+
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       base.Emit (ec);
+
+                       if (expr_type == TypeManager.byte_type ||
+                               expr_type == TypeManager.short_type ||
+                               expr_type == TypeManager.int32_type) {
+                               ec.ig.Emit (OpCodes.Ldc_I4_0);
+                               ec.ig.Emit (OpCodes.Cgt_Un);
+                               return;
+                       }
+
+                       if (expr_type == TypeManager.int64_type) {
+                               ec.ig.Emit (OpCodes.Ldc_I8, (long) 0);
+                               ec.ig.Emit (OpCodes.Cgt_Un);
+                               return;
+                       }
+
+                       if (expr_type == TypeManager.float_type)
+                               ec.ig.Emit (OpCodes.Ldc_R4, (float) 0);
+                       else if (expr_type == TypeManager.double_type) 
+                               ec.ig.Emit (OpCodes.Ldc_R8, (double) 0);
+               
+                       ec.ig.Emit (OpCodes.Ceq);
+                       ec.ig.Emit (OpCodes.Ldc_I4_0);
+                       ec.ig.Emit (OpCodes.Ceq);
+               }                       
+       }
        
        /// <summary>
        ///   SimpleName expressions are formed of a single word and only 
happen at the beginning 

Modified: trunk/mcs/bmcs/typemanager.cs
===================================================================
--- trunk/mcs/bmcs/typemanager.cs       2005-02-28 18:16:34 UTC (rev 41293)
+++ trunk/mcs/bmcs/typemanager.cs       2005-02-28 18:16:38 UTC (rev 41294)
@@ -98,6 +98,7 @@
        static public Type struct_layout_attribute_type;
        static public Type field_offset_attribute_type;
        static public Type security_attr_type;
+       static public Type date_type;
 
        //
        // An empty array of types
@@ -124,6 +125,11 @@
        static public TypeExpr system_intptr_expr;
 
        //
+       // VB.NET Specific
+       //
+       static public TypeExpr system_date_expr;
+
+       //
        // This is only used when compiling corlib
        //
        static public Type system_int32_type;
@@ -362,6 +368,11 @@
                system_iasyncresult_expr = new TypeLookupExpression 
("System.IAsyncResult");
                system_valuetype_expr  = new TypeLookupExpression 
("System.ValueType");
                system_intptr_expr  = new TypeLookupExpression 
("System.IntPtr");
+
+               //
+               // VB.NET Specific
+               //
+               system_date_expr = new TypeLookupExpression ("System.DateTime");
        }
 
        static TypeManager ()
@@ -1108,6 +1119,11 @@
                bool_type     = CoreLookupType ("System.Boolean");
                enum_type     = CoreLookupType ("System.Enum");
 
+               //
+               // VB.NET Specific
+               //
+               date_type  = CoreLookupType ("System.DateTime");
+
                multicast_delegate_type = CoreLookupType 
("System.MulticastDelegate");
                delegate_type           = CoreLookupType ("System.Delegate");
 
@@ -1257,7 +1273,13 @@
                system_iasyncresult_expr.Type = iasyncresult_type;
                system_valuetype_expr.Type = value_type;
 
+
                //
+               // VB.NET Specific
+               //
+               system_date_expr.Type  = date_type;
+
+               //
                // These are only used for compare purposes
                //
                anonymous_method_type = typeof (AnonymousMethod);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to