* ecore.cs (ImplicitInvocation, ImplicitNew, FloatingToFixedCast): Added
authorJambunathan K <jambunathan@mono-cvs.ximian.com>
Tue, 1 Mar 2005 12:51:34 +0000 (12:51 -0000)
committerJambunathan K <jambunathan@mono-cvs.ximian.com>
Tue, 1 Mar 2005 12:51:34 +0000 (12:51 -0000)
* expression.cs (ImplicitInvocation, ImplicitNew): Removed

* driver.cs, rootcontext.cs: Added the 'removeintchecks' and
'optionstrict' command line options

* convert.cs (WideningNumericConversion,
NarrowingNumericConversion): Updated to refelct VB.NET semantics.

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

mcs/bmcs/ChangeLog
mcs/bmcs/convert.cs
mcs/bmcs/driver.cs
mcs/bmcs/ecore.cs
mcs/bmcs/expression.cs
mcs/bmcs/rootcontext.cs

index 44d2d35968590b612c2b53e6196b5bb1a5502307..d4442604a023e2619365a294a1bd35ad7482cb1a 100644 (file)
@@ -1,3 +1,14 @@
+2005-03-01  Jambunathan K  <kjambunathan.devel@gmail.com>
+
+       * ecore.cs (ImplicitInvocation, ImplicitNew, FloatingToFixedCast): Added
+       * expression.cs (ImplicitInvocation, ImplicitNew): Removed
+
+       * driver.cs, rootcontext.cs: Added the 'removeintchecks' and
+       'optionstrict' command line options
+
+       * convert.cs (WideningNumericConversion,
+       NarrowingNumericConversion): Updated to refelct VB.NET semantics.
+
 2005-03-01  Jambunathan K  <kjambunathan.devel@gmail.com>
 
        * convert.cs: Added the following conversion routines:
index 3dea5af0046662cd1579ff94ada05aa41c31f93d..ab09c536804575c69e693e6d9b78a4512bc48d1d 100644 (file)
@@ -381,6 +381,7 @@ namespace Mono.CSharp {
                ///   expr is the expression to convert, returns a new expression of type
                ///   target_type or null if an implicit conversion is not possible.
                /// </summary>
+
                static public Expression WideningNumericConversion (EmitContext ec, Expression expr,
                                                                    Type target_type, Location loc)
                {
@@ -411,38 +412,22 @@ namespace Mono.CSharp {
                        
                        Type real_target_type = target_type;
 
-                       if (expr_type == TypeManager.sbyte_type){
-                               //
-                               // From sbyte to short, int, long, float, double.
-                               //
-                               if (real_target_type == TypeManager.int32_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I4);
-                               if (real_target_type == TypeManager.int64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I8);
-                               if (real_target_type == TypeManager.double_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
-                               if (real_target_type == TypeManager.float_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
-                               if (real_target_type == TypeManager.short_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I2);
-                       } else if (expr_type == TypeManager.byte_type){
+                        if (expr_type == TypeManager.byte_type){
                                //
                                // From byte to short, ushort, int, uint, long, ulong, float, double
                                // 
                                if ((real_target_type == TypeManager.short_type) ||
-                                   (real_target_type == TypeManager.ushort_type) ||
-                                   (real_target_type == TypeManager.int32_type) ||
-                                   (real_target_type == TypeManager.uint32_type))
+                                   (real_target_type == TypeManager.int32_type))
                                        return new EmptyCast (expr, target_type);
 
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_U8);
                                if (real_target_type == TypeManager.int64_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_I8);
                                if (real_target_type == TypeManager.float_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
                                if (real_target_type == TypeManager.double_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);
                        } else if (expr_type == TypeManager.short_type){
                                //
                                // From short to int, long, float, double
@@ -455,23 +440,8 @@ namespace Mono.CSharp {
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
                                if (real_target_type == TypeManager.float_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
-                       } else if (expr_type == TypeManager.ushort_type){
-                               //
-                               // From ushort to int, uint, long, ulong, float, double
-                               //
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new EmptyCast (expr, target_type);
-
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_U8);
-                               if (real_target_type == TypeManager.int32_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I4);
-                               if (real_target_type == TypeManager.int64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I8);
-                               if (real_target_type == TypeManager.double_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
-                               if (real_target_type == TypeManager.float_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);
                        } else if (expr_type == TypeManager.int32_type){
                                //
                                // From int to long, float, double
@@ -482,20 +452,8 @@ namespace Mono.CSharp {
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
                                if (real_target_type == TypeManager.float_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
-                       } else if (expr_type == TypeManager.uint32_type){
-                               //
-                               // From uint to long, ulong, float, double
-                               //
-                               if (real_target_type == TypeManager.int64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_U8);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_U8);
-                               if (real_target_type == TypeManager.double_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un,
-                                                              OpCodes.Conv_R8);
-                               if (real_target_type == TypeManager.float_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un,
-                                                              OpCodes.Conv_R4);
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);
                        } else if (expr_type == TypeManager.int64_type){
                                //
                                // From long/ulong to float, double
@@ -504,32 +462,16 @@ namespace Mono.CSharp {
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
                                if (real_target_type == TypeManager.float_type)
                                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);     
-                       } else if (expr_type == TypeManager.uint64_type){
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);    
+                       } else if (expr_type == TypeManager.decimal_type){
                                //
-                               // From ulong to float, double
+                               // From decimal to float, double
                                //
                                if (real_target_type == TypeManager.double_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un,
-                                                              OpCodes.Conv_R8);
-                               if (real_target_type == TypeManager.float_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un,
-                                                              OpCodes.Conv_R4);        
-                       } else if (expr_type == TypeManager.char_type){
-                               //
-                               // From char to ushort, int, uint, long, ulong, float, double
-                               // 
-                               if ((real_target_type == TypeManager.ushort_type) ||
-                                   (real_target_type == TypeManager.int32_type) ||
-                                   (real_target_type == TypeManager.uint32_type))
-                                       return new EmptyCast (expr, target_type);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_U8);
-                               if (real_target_type == TypeManager.int64_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_I8);
+                                       return new ImplicitInvocation (ec, "System", "Convert", "ToDouble", loc, expr); 
                                if (real_target_type == TypeManager.float_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
-                               if (real_target_type == TypeManager.double_type)
-                                       return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
+                                       return new ImplicitInvocation (ec, "System", "Convert" ,"ToSingle", loc, expr); 
                        } else if (expr_type == TypeManager.float_type){
                                //
                                // float to double
@@ -1330,6 +1272,15 @@ namespace Mono.CSharp {
                                if (errors != Report.Errors)
                                        return new EmptyCast (expr, target_type);
                        }
+
+                       //
+                       // VB.NET specific conversions
+                       //
+
+                       e = WideningStringConversions (ec, expr, target_type, loc);
+                       if (e != null)
+                               return e;
+
                        
                        return null;
                }
@@ -1458,6 +1409,10 @@ namespace Mono.CSharp {
                                type, suffix);
                }
 
+               /// <summary>
+               ///   Performs the explicit numeric conversions
+               /// </summary>
+
                /// <summary>
                ///   Performs the explicit numeric conversions
                /// </summary>
@@ -1483,194 +1438,74 @@ namespace Mono.CSharp {
                                return ce;
                        }
                        
-                       if (expr_type == TypeManager.sbyte_type){
+                       if (expr_type == TypeManager.short_type){
                                //
-                               // From sbyte to byte, ushort, uint, ulong, char
+                               // From short to byte
                                //
-                               if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U1);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U2);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U4);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_CH);
-                       } else if (expr_type == TypeManager.byte_type){
-                               //
-                               // From byte to sbyte and char
-                               //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U1_I1);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U1_CH);
-                       } else if (expr_type == TypeManager.short_type){
-                               //
-                               // From short to sbyte, byte, ushort, uint, ulong, char
-                               //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_I1);
                                if (real_target_type == TypeManager.byte_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U1);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U2);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U4);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_CH);
-                       } else if (expr_type == TypeManager.ushort_type){
-                               //
-                               // From ushort to sbyte, byte, short, char
-                               //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_I1);
-                               if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_U1);
-                               if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_I2);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_CH);
                        } else if (expr_type == TypeManager.int32_type){
                                //
-                               // From int to sbyte, byte, short, ushort, uint, ulong, char
+                               // From int to byte, short
                                //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_I1);
                                if (real_target_type == TypeManager.byte_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U1);
                                if (real_target_type == TypeManager.short_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U2);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U4);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_CH);
-                       } else if (expr_type == TypeManager.uint32_type){
-                               //
-                               // From uint to sbyte, byte, short, ushort, int, char
-                               //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I1);
-                               if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_U1);
-                               if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_U2);
-                               if (real_target_type == TypeManager.int32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I4);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_CH);
                        } else if (expr_type == TypeManager.int64_type){
                                //
-                               // From long to sbyte, byte, short, ushort, int, uint, ulong, char
+                               // From long to byte, short, int
                                //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I1);
                                if (real_target_type == TypeManager.byte_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U1);
                                if (real_target_type == TypeManager.short_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U2);
                                if (real_target_type == TypeManager.int32_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I4);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U4);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_CH);
-                       } else if (expr_type == TypeManager.uint64_type){
+                       } else if (expr_type == TypeManager.decimal_type){
                                //
-                               // From ulong to sbyte, byte, short, ushort, int, uint, long, char
+                               // From decimal to byte, short, int, long
                                //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I1);
                                if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U1);
+                                       return new ImplicitInvocation (ec, "System", "Convert" , "ToByte", loc, expr);  
                                if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U2);
+                                       return new ImplicitInvocation (ec, "System", "Convert", "ToInt16", loc, expr);  
                                if (real_target_type == TypeManager.int32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I4);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U4);
+                                       return new ImplicitInvocation (ec, "System", "Convert", "ToInt32", loc, expr);  
                                if (real_target_type == TypeManager.int64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_CH);
-                       } else if (expr_type == TypeManager.char_type){
-                               //
-                               // From char to sbyte, byte, short
-                               //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_I1);
-                               if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_U1);
-                               if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_I2);
+                                       return new ImplicitInvocation (ec, "System", "Convert", "ToInt64", loc, expr);  
                        } else if (expr_type == TypeManager.float_type){
                                //
-                               // From float to sbyte, byte, short,
-                               // ushort, int, uint, long, ulong, char
-                               // or decimal
+                               // From float to byte, short, int, long, decimal
                                //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I1);
                                if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U1);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_U1);
                                if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U2);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_I2);
                                if (real_target_type == TypeManager.int32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I4);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U4);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_I4);
                                if (real_target_type == TypeManager.int64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I8);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_CH);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_I8);
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);    
                        } else if (expr_type == TypeManager.double_type){
                                //
-                               // From double to byte, byte, short,
-                               // ushort, int, uint, long, ulong,
-                               // char, float or decimal
+                               // From double to byte, short, int, long, float, decimal
                                //
-                               if (real_target_type == TypeManager.sbyte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I1);
                                if (real_target_type == TypeManager.byte_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U1);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_U1);
                                if (real_target_type == TypeManager.short_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I2);
-                               if (real_target_type == TypeManager.ushort_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U2);
+                                       return new FloatingToFixedCast (ec, expr, target_type, ConvCast.Mode.R8_I2);
                                if (real_target_type == TypeManager.int32_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I4);
-                               if (real_target_type == TypeManager.uint32_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U4);
                                if (real_target_type == TypeManager.int64_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I8);
-                               if (real_target_type == TypeManager.uint64_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U8);
-                               if (real_target_type == TypeManager.char_type)
-                                       return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_CH);
                                if (real_target_type == TypeManager.float_type)
                                        return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_R4);
+                               if (real_target_type == TypeManager.decimal_type)
+                                       return new ImplicitNew (ec, "System", "Decimal", loc, expr);
                        } 
 
-                       // decimal is taken care of by the op_Explicit methods.
-
                        return null;
                }
 
@@ -1704,7 +1539,7 @@ namespace Mono.CSharp {
                                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);
+                                       return new ImplicitInvocation (ec, "DecimalType", "FromBoolean", loc, expr);
                                }
                        } if (real_target_type == TypeManager.bool_type) {
 
@@ -1721,7 +1556,7 @@ namespace Mono.CSharp {
                                        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 new ImplicitInvocation (ec, "System", "Convert", "ToBoolean", loc, expr);
                                }
                        }
 
@@ -1734,17 +1569,6 @@ namespace Mono.CSharp {
 
                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;
@@ -1755,14 +1579,14 @@ namespace Mono.CSharp {
                                // From char to string
                                //
                                if (expr_type == TypeManager.char_type)
-                                       return new ImplicitInvocation ("StringType", "FromChar", loc, expr);
+                                       return new ImplicitInvocation (ec, "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 new ImplicitNew (ec, "System", "String", loc, expr);
                        }
 
                        return null;
@@ -1774,17 +1598,6 @@ namespace Mono.CSharp {
 
                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;
@@ -1800,27 +1613,27 @@ namespace Mono.CSharp {
                                //
 
                                if (real_target_type.IsArray && (real_target_type.GetElementType() == TypeManager.char_type))
-                                       return new ImplicitInvocation("CharArrayType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "CharArrayType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.bool_type)
-                                       return new ImplicitInvocation("BooleanType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "BooleanType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.byte_type)
-                                       return new ImplicitInvocation("ByteType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "ByteType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.short_type)
-                                       return new ImplicitInvocation("ShortType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "ShortType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.char_type)
-                                       return new ImplicitInvocation("CharType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "CharType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.int32_type)
-                                       return new ImplicitInvocation("IntegerType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "IntegerType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.int64_type)
-                                       return new ImplicitInvocation("LongType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "LongType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.float_type)
-                                       return new ImplicitInvocation("SingleType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "SingleType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.double_type)
-                                       return new ImplicitInvocation("DoubleType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "DoubleType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.decimal_type)
-                                       return new ImplicitInvocation("DecimalType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "DecimalType", "FromString", loc, expr);
                                if (real_target_type == TypeManager.date_type)
-                                       return new ImplicitInvocation("DateType", "FromString", loc, expr);
+                                       return new ImplicitInvocation (ec, "DateType", "FromString", loc, expr);
                        } if (real_target_type == TypeManager.string_type) {
 
                                //
@@ -1830,23 +1643,23 @@ namespace Mono.CSharp {
                                //
 
                                if (expr_type == TypeManager.bool_type)
-                                       return new ImplicitInvocation("StringType", "FromBoolean", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromBoolean", loc, expr);
                                if (expr_type == TypeManager.byte_type)
-                                       return new ImplicitInvocation("StringType", "FromByte", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromByte", loc, expr);
                                if (expr_type == TypeManager.short_type)
-                                       return new ImplicitInvocation("StringType", "FromShort", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromShort", loc, expr);
                                if (expr_type == TypeManager.int32_type)
-                                       return new ImplicitInvocation("StringType", "FromInteger", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromInteger", loc, expr);
                                if (expr_type == TypeManager.int64_type)
-                                       return new ImplicitInvocation("StringType", "FromLong", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromLong", loc, expr);
                                if (expr_type == TypeManager.float_type)
-                                       return new ImplicitInvocation("StringType", "FromSingle", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromSingle", loc, expr);
                                if (expr_type == TypeManager.double_type)
-                                       return new ImplicitInvocation("StringType", "FromDouble", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromDouble", loc, expr);
                                if (expr_type == TypeManager.decimal_type)
-                                       return new ImplicitInvocation("StringType", "FromDecimal", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromDecimal", loc, expr);
                                if (expr_type == TypeManager.date_type)
-                                       return new ImplicitInvocation("StringType", "FromDate", loc, expr);
+                                       return new ImplicitInvocation (ec, "StringType", "FromDate", loc, expr);
                        }
 
                        return null;
@@ -2187,6 +2000,19 @@ namespace Mono.CSharp {
                                        }
                                }
                        }
+
+                       //
+                       // VB.NET specific conversions
+                       //
+
+                       ne = BooleanConversions (ec, expr, target_type, loc);
+                       if (ne != null)
+                               return ne;
+
+                       ne = NarrowingStringConversions (ec, expr, target_type, loc);
+                       if (ne != null)
+                               return ne;
+                       
                        
                        //
                        // VB.NET has no notion of User defined conversions
index 35aafa8592de39a2521916ab5596b9e82a06e880..3b6c73a389cc7fd643e0c6d7269dee6e1917574e 100644 (file)
@@ -232,6 +232,13 @@ namespace Mono.CSharp
                                "   -warnaserror[+|-]  Treat warnings as errors\n" +
                                "   -warn:LEVEL        Sets warning level (the highest is 4, the default is 2)\n" +
                                "   -help2             Show other help flags\n" + 
+
+                               //
+                               // VB.NET specific compiler options
+                               //
+                               "   -removeintchecks[+|-]      Set default context to unchecked\n" +
+                               "   -optionstrict[+|-]      Enables stricter type checking\n" +
+                               
                                "\n" +
                                "Resources:\n" +
                                "   -linkresource:FILE[,ID] Links FILE as a resource\n" +
@@ -725,6 +732,7 @@ namespace Mono.CSharp
                        case "--checked":
                                RootContext.Checked = true;
                                return true;
+
                                
                        case "--stacktrace":
                                Report.Stacktrace = true;
@@ -887,6 +895,19 @@ namespace Mono.CSharp
                        case "--noconfig":
                                load_default_config = false;
                                return true;
+
+                               //
+                               // VB.NET specific compiler options
+                               //
+
+                       case "--removeintchecks":
+                               RootContext.Checked = false;
+                               return true;
+
+                       case "--optionstrict":
+                               RootContext.StricterTypeChecking= true;
+                               return true;
+                               
                        }
 
                        return false;
@@ -1141,6 +1162,7 @@ namespace Mono.CSharp
                                RootContext.Checked = false;
                                return true;
 
+
                        case "/clscheck":
                        case "/clscheck+":
                                return true;
@@ -1303,6 +1325,29 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
                                return true;
+
+                               //
+                               // VB.NET specific compiler options
+                               //
+
+                       case "/removeintchecks":
+                       case "/removeintchecks+":
+                               RootContext.Checked = false;
+                               return true;
+
+                       case "/removeintchecks-":
+                               RootContext.Checked = true;
+                               return true;
+
+                       case "/optionstrict":
+                       case "/optionstrict+":
+                               RootContext.StricterTypeChecking = true;
+                               return true;
+
+                       case "/optionstrict-":
+                               RootContext.StricterTypeChecking = false;
+                               return true;
+
                        }
                        //Report.Error (2007, String.Format ("Unrecognized command-line option: '{0}'", option));
                        //Environment.Exit (1);
index 7386ee1700298e109c0ce50bf34e242b4c3b87fb..c1d545fbc68b645156c0011dd06f4874a9cdf08e 100644 (file)
@@ -1495,6 +1495,81 @@ namespace Mono.CSharp {
                }
        }
 
+       
+       /// <summary> 
+       /// ImplicitInvocation of methods or delegates. Used by the
+       /// VB.NET compiler specifically to emit calls to the
+       /// Microsoft.VisualBasic.CompilerServices helper routines
+       /// </summary>
+
+       public class ImplicitInvocation : Expression
+       {
+               const string DEFAULT_NS_PREFIX = "Microsoft.VisualBasic.CompilerServices";
+
+               Expression child;
+               
+               public ImplicitInvocation (EmitContext ec, string klass, string method, Location l, params Expression [] exprs) 
+                       : this (ec, DEFAULT_NS_PREFIX, klass, method, l, exprs)
+               {
+               }
+
+               public ImplicitInvocation (EmitContext ec, string ns, string klass, string method, Location l, params Expression [] exprs)
+               {
+                       ArrayList args = new ArrayList ();
+                       string name = ns + "." + klass + "." + method;
+               
+                       foreach (Expression expr in exprs)
+                               args.Add (new Argument (expr, Argument.AType.Expression));
+
+                       child = new Invocation (StringToExpression (name, l), args, l).Resolve (ec);
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       child.Emit (ec);
+               }
+       }
+
+       /// <summary> 
+       /// Implicit Creation of types. Used by the VB.NET compiler
+       /// (in the context of Type Conversions) to emit calls to the
+       /// appropriate constructors available in the core libraries.
+       /// </summary>
+
+       public class ImplicitNew : Expression
+       {
+               Expression child;
+               
+               public ImplicitNew (EmitContext ec, string ns, string name, Location l, params Expression [] exprs)
+               {
+                       name = ns + "." + name;
+                       ArrayList args = new ArrayList ();
+               
+                       foreach (Expression expr in exprs)
+                               args.Add (new Argument (expr, Argument.AType.Expression));
+
+                       child = new New (StringToExpression (name, l), args, l).Resolve (ec);
+               }
+
+               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)
+               {
+                       child.Emit (ec);
+               }
+       }
+
         //
        // We need to special case this since an empty cast of
        // a NullLiteral is still a Constant
@@ -2116,6 +2191,20 @@ namespace Mono.CSharp {
                        ec.ig.Emit (OpCodes.Ceq);
                }                       
        }
+
+       //
+       // VB.NET specific
+       //
+       public class FloatingToFixedCast : ConvCast {
+               public FloatingToFixedCast (EmitContext ec, Expression child, Type return_type, Mode mode)
+                       : base (ec, new ImplicitInvocation (ec, "System", "Math", "Round", child.Location, 
+                                                           (child.Type == TypeManager.float_type) ? 
+                                                           new OpcodeCast (child, TypeManager.double_type, OpCodes.Conv_R8) : child), 
+                               return_type, mode)
+               {
+               }
+       }
+       
        
        /// <summary>
        ///   SimpleName expressions are formed of a single word and only happen at the beginning 
index 5c5cf43e0bb5049a6be1a5ff7e3216825eae76b4..cbd36152cd5c05a8e008dd6662c1be7881a1ebfa 100644 (file)
@@ -4294,10 +4294,6 @@ namespace Mono.CSharp {
                // delegate invocation (7.5.5)
                //
 
-               protected Invocation ()
-               {
-                       Arguments = new ArrayList ();
-               }
                
                public Invocation (Expression expr, ArrayList arguments, Location l)
                {
@@ -5626,32 +5622,6 @@ namespace Mono.CSharp {
        }
 
 
-       /// <summary> 
-       /// ImplicitInvocation of methods or delegates. Used by the
-       /// VB.NET compiler specifically to emit calls to the
-       /// Microsoft.VisualBasic.CompilerServices helper routines
-       /// </summary>
-
-       public class ImplicitInvocation : Invocation
-       {
-               const string DEFAULT_NS_PREFIX = "Microsoft.VisualBasic.CompilerServices";
-               
-               public ImplicitInvocation (string klass, string method, Location l, params Expression [] exprs) 
-                       : this (DEFAULT_NS_PREFIX, klass, method, l, exprs)
-               {
-               }
-
-               public ImplicitInvocation (string ns, string klass, string method, Location l, params Expression [] exprs)
-               {
-                       string name = ns + "." + klass + "." + method;
-                       this.expr = StringToExpression (name, l);
-               
-                       foreach (Expression expr in exprs)
-                               Arguments.Add (new Argument (expr, Argument.AType.Expression));
-
-                       loc =l;
-               }
-       }
        
        public class InvocationOrCast : ExpressionStatement
        {
@@ -5792,11 +5762,6 @@ namespace Mono.CSharp {
                bool value_target_set = false;
                bool is_type_parameter = false;
 
-               protected New ()
-               {
-                       Arguments = new ArrayList ();
-               }
-
                public New (Expression requested_type, ArrayList arguments, Location l)
                {
                        RequestedType = requested_type;
@@ -6089,25 +6054,6 @@ namespace Mono.CSharp {
                }
        }
 
-       /// <summary> 
-       /// Implicit Creation of types. Used by the VB.NET compiler
-       /// (in the context of Type Conversions) to emit calls to the
-       /// appropriate constructors available in the core libraries.
-       /// </summary>
-
-       public class ImplicitNew : New
-       {
-               public ImplicitNew (string ns, string name, Location l, params Expression [] exprs)
-               {
-                       name = ns + "." + name;
-                       this.RequestedType= StringToExpression (name, l);
-               
-                       foreach (Expression expr in exprs)
-                               Arguments.Add (new Argument (expr, Argument.AType.Expression));
-
-                       loc =l;
-               }
-       }
 
        /// <summary>
        ///   14.5.10.2: Represents an array creation expression.
index 2824da00840d2b489a253daa496655bd89113fc5..9b42c52ee4904e3fa7ca27886fae6ffd0c3d57a1 100644 (file)
@@ -123,14 +123,24 @@ namespace Mono.CSharp {
                }
                
                // 
-               // The default compiler checked state
+               // The default compiler checked state. It's "On" in case of VB.NET compiler.
                //
-               static public bool Checked = false;
+               static public bool Checked = true;
+
 
                //
                // Whether to allow Unsafe code
                //
                static public bool Unsafe = false;
+
+               //
+               // VB.NET specific compiler options
+               //
+
+               // 
+               // The default type checking state
+               //
+               static public bool StricterTypeChecking = false;
                
                static string MakeFQN (string nsn, string name)
                {