Make mkbundle use SDKs instead of a single runtime for cross compilation
[mono.git] / mcs / mcs / cfold.cs
index 19580312941055b10a5b562d976c3785127a77cb..da85bf386b21c306f44105af857dec6196e43509 100644 (file)
@@ -309,10 +309,10 @@ namespace Mono.CSharp {
                                                return new StringConstant (ec.BuiltinTypes, (string)left.GetValue () + (string)right.GetValue (),
                                                        left.Location);
 
-                                       if (lt == InternalType.NullLiteral)
+                                       if (lt == InternalType.NullLiteral || left.IsNull)
                                                return new StringConstant (ec.BuiltinTypes, "" + right.GetValue (), left.Location);
 
-                                       if (rt == InternalType.NullLiteral)
+                                       if (rt == InternalType.NullLiteral || right.IsNull)
                                                return new StringConstant (ec.BuiltinTypes, left.GetValue () + "", left.Location);
 
                                        return null;
@@ -367,8 +367,8 @@ namespace Mono.CSharp {
                                                return null;
 
                                        result = result.Reduce (ec, lt);
-                                       if (result == null)
-                                               return null;
+                                       if (result == null || lt.IsEnum)
+                                               return result;
 
                                        return new EnumConstant (result, lt);
                                }
@@ -861,9 +861,22 @@ namespace Mono.CSharp {
                                                                         ((IntConstant) right).Value);
 
                                                return new IntConstant (ec.BuiltinTypes, res, left.Location);
-                                       } else {
-                                               throw new Exception ( "Unexepected modulus input: " + left);
                                        }
+
+                                       if (left is DecimalConstant) {
+                                               decimal res;
+
+                                               if (ec.ConstantCheckState)
+                                                       res = checked (((DecimalConstant) left).Value %
+                                                               ((DecimalConstant) right).Value);
+                                               else
+                                                       res = unchecked (((DecimalConstant) left).Value %
+                                                               ((DecimalConstant) right).Value);
+
+                                               return new DecimalConstant (ec.BuiltinTypes, res, left.Location);
+                                       }
+
+                                       throw new Exception ( "Unexepected modulus input: " + left);
                                } catch (DivideByZeroException){
                                        ec.Report.Error (20, loc, "Division by constant zero");
                                } catch (OverflowException){
@@ -883,7 +896,6 @@ namespace Mono.CSharp {
 
                                IntConstant ic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
                                if (ic == null){
-                                       Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
                                        return null;
                                }
 
@@ -905,8 +917,7 @@ namespace Mono.CSharp {
                                if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
                                        return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value << lshift_val, left.Location);
 
-                               Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
-                               break;
+                               return null;
 
                                //
                                // There is no overflow checking on right shift
@@ -920,7 +931,6 @@ namespace Mono.CSharp {
 
                                IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
                                if (sic == null){
-                                       Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
                                        return null;
                                }
                                int rshift_val = sic.Value;
@@ -941,8 +951,7 @@ namespace Mono.CSharp {
                                if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
                                        return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value >> rshift_val, left.Location);
 
-                               Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
-                               break;
+                               return null;
 
                        case Binary.Operator.Equality:
                                if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
@@ -1176,7 +1185,7 @@ namespace Mono.CSharp {
 
                                return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
                        }
-                                       
+
                        return null;
                }
        }