2009-10-27 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Tue, 27 Oct 2009 13:36:26 +0000 (13:36 -0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 27 Oct 2009 13:36:26 +0000 (13:36 -0000)
* constant.cs, nullable.cs: Create nullable-null as LiftedNull
constant.

* class.cs: Allow nullable binary user operators.

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

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/constant.cs
mcs/mcs/nullable.cs

index 0220881accfdfc0141def514ffea9f2862d51dbb..3f3b8403b05866b3a5b9ab7e4521d9d708d14388 100644 (file)
@@ -1,3 +1,10 @@
+2009-10-27  Marek Safar  <marek.safar@gmail.com>
+
+       * constant.cs, nullable.cs: Create nullable-null as LiftedNull
+       constant.
+       
+       * class.cs: Allow nullable binary user operators.
+
 2009-10-26  Marek Safar  <marek.safar@gmail.com>
 
        * expression.cs: Move binary expression optimization at the end of
index eaa359d928b89b006b21721e21f2511da2591861..13ce4e8e29b277fc8742db88796671622c25691d 100644 (file)
@@ -7897,15 +7897,16 @@ namespace Mono.CSharp {
                                        }
                                }
                                
-                       } else {
+                       } else if (!TypeManager.IsEqual (first_arg_type_unwrap, declaring_type)) {
                                // Checks for Binary operators
-                               
-                               if (first_arg_type != declaring_type &&
-                                   Parameters.Types [1] != declaring_type){
-                                       Report.Error (
-                                               563, Location,
-                                               "One of the parameters of a binary operator must " +
-                                               "be the containing type");
+
+                               var second_arg_type = ParameterTypes [1];
+                               if (TypeManager.IsNullableType (second_arg_type))
+                                       second_arg_type = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (second_arg_type) [0]);
+
+                               if (!TypeManager.IsEqual (second_arg_type, declaring_type)) {
+                                       Report.Error (563, Location,
+                                               "One of the parameters of a binary operator must be the containing type");
                                        return false;
                                }
                        }
index f5ea90d8abfecd7cd722da839ddda3532e518f38..69a49da843c96405a031ac69e75e0c7c7238f900 100644 (file)
@@ -154,8 +154,13 @@ namespace Mono.CSharp {
                                Type real_type = TypeManager.GetEnumUnderlyingType (t);
                                return new EnumConstant (CreateConstant (real_type, v, loc), t);
                        }
-                       if (v == null && !TypeManager.IsValueType (t))
-                               return new EmptyConstantCast (new NullLiteral (loc), t);
+                       if (v == null) {
+                               if (TypeManager.IsNullableType (t))
+                                       return Nullable.LiftedNull.Create (t, loc);
+
+                               if (TypeManager.IsReferenceType (t))
+                                       return new NullConstant (t, loc);
+                       }
 
                        throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'",
                                v, TypeManager.CSharpName (t));
index b34a900dc0ac4a9c337945ed4483dd46d98ed89d..307ebfb5d32515543b1ad707ecb54863d979d330 100644 (file)
@@ -337,10 +337,10 @@ namespace Mono.CSharp.Nullable
        //
        // Represents null literal lifted to nullable type
        //
-       public class LiftedNull : EmptyConstantCast, IMemoryLocation
+       public class LiftedNull : NullConstant, IMemoryLocation
        {
                private LiftedNull (Type nullable_type, Location loc)
-                       : base (new NullLiteral (loc), nullable_type)
+                       : base (nullable_type, loc)
                {
                        eclass = ExprClass.Value;
                }
@@ -358,15 +358,6 @@ namespace Mono.CSharp.Nullable
                        return ReducedExpression.Create (Create (e.Type, e.Location), e);
                }
 
-               public override Expression CreateExpressionTree (ResolveContext ec)
-               {
-                       Arguments args = new Arguments (2);
-                       args.Add (new Argument (this));
-                       args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
-
-                       return CreateExpressionFactoryCall (ec, "Constant", args);
-               }
-
                public override void Emit (EmitContext ec)
                {
                        // TODO: generate less temporary variables