Author: marek
Date: 2006-09-23 14:37:59 -0400 (Sat, 23 Sep 2006)
New Revision: 65833

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/convert.cs
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/generic.cs
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/cfold.cs
   trunk/mcs/mcs/const.cs
   trunk/mcs/mcs/convert.cs
   trunk/mcs/mcs/ecore.cs
   trunk/mcs/mcs/expression.cs
   trunk/mcs/mcs/literal.cs
   trunk/mcs/mcs/statement.cs
Log:
2006-09-23  Marek Safar  <[EMAIL PROTECTED]>

        * cfold.cs (BinaryFold): On the guest to unify empty constant cast.

        * const.cs (Const.Define): Check for constant type.
        (Const.IsConstantTypeValid): Looks for valid constant types.

        * convert.cs (ImplicitReferenceConversion): NullCast to 
EmptyConstantCast.

        * ecore.cs (EmptyConstantCast): New common class for all constant based
        EmptyCast(s).

        * expression.cs (Is.DoResolve): Handle null constant especially.
        (New.DoResolve): Check for new void().
        (MemberAccess.DoResolve): Cope with all kind of nulls.

        * literal.cs (NullConstant): Uses EmptyConstantCast.
        (NullDefault): Based on EmptyConstantCast.
        (NullLiteral): Uses EmptyConstantCast.

        * statement.cs (Block.ResolveMeta): Check for constant type.

GMCS:

2006-09-23  Marek Safar  <[EMAIL PROTECTED]>

        * convert.cs (ImplicitReferenceConversion): NullCast to 
EmptyConstantCast.

        * cs-parser.jay: Parse correctly cast of default (T).

        * generic.cs (DefaultValueExpression.DoResolve): Check for void type.
        Store original type via EmptyConstantCast.

Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/gmcs/ChangeLog    2006-09-23 18:37:59 UTC (rev 65833)
@@ -1,3 +1,12 @@
+2006-09-23  Marek Safar  <[EMAIL PROTECTED]>
+
+       * convert.cs (ImplicitReferenceConversion): NullCast to 
EmptyConstantCast.
+
+       * cs-parser.jay: Parse correctly cast of default (T).
+
+       * generic.cs (DefaultValueExpression.DoResolve): Check for void type.
+       Store original type via EmptyConstantCast.
+
 2006-09-22  Martin Baulig  <[EMAIL PROTECTED]>
 
        * delegate.cs: Removed; this file is now shared with mcs.

Modified: trunk/mcs/gmcs/convert.cs
===================================================================
--- trunk/mcs/gmcs/convert.cs   2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/gmcs/convert.cs   2006-09-23 18:37:59 UTC (rev 65833)
@@ -211,7 +211,7 @@
                                if (TypeManager.IsValueType (expr_type))
                                        return new BoxedCast (expr, 
target_type);
                                if (expr_type == TypeManager.null_type)
-                                       return new NullCast 
((NullConstant)expr, target_type);
+                                       return new EmptyConstantCast 
((Constant)expr, target_type);
 
                                return null;
                        } else if (TypeManager.IsSubclassOf (expr_type, 
target_type)) {

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/gmcs/cs-parser.jay        2006-09-23 18:37:59 UTC (rev 65833)
@@ -3477,6 +3477,10 @@
          {
                $$ = new Cast ((Expression) $1, (Expression) $3);
          }
+       | parenthesized_expression_0 CLOSE_PARENS_NO_CAST 
default_value_expression
+         {
+               $$ = new Cast ((Expression) $1, (Expression) $3);
+         }
        | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
          {
                $$ = new Cast ((Expression) $1, (Expression) $3);

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/gmcs/generic.cs   2006-09-23 18:37:59 UTC (rev 65833)
@@ -1916,20 +1916,25 @@
 
                        type = texpr.Type;
 
+                       if (type == TypeManager.void_type) {
+                               Error_VoidInvalidInTheContext (loc);
+                               return null;
+                       }
+
                        if (type.IsGenericParameter)
                        {
                                GenericConstraints constraints = 
TypeManager.GetTypeParameterConstraints(type);
                                if (constraints != null && 
constraints.IsReferenceType)
-                                       return new NullDefault(loc, this);
+                                       return new NullDefault (new NullLiteral 
(Location), type);
                        }
                        else
                        {
                                Constant c = New.Constantify(type);
                                if (c != null)
-                                       return c;
+                                       return new NullDefault (c, type);
 
-                               if (!TypeManager.IsValueType(type))
-                                       return new NullDefault(loc, this);
+                               if (!TypeManager.IsValueType (type))
+                                       return new NullDefault (new NullLiteral 
(Location), type);
                        }
                        eclass = ExprClass.Variable;
                        return this;

Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/ChangeLog     2006-09-23 18:37:59 UTC (rev 65833)
@@ -1,3 +1,25 @@
+2006-09-23  Marek Safar  <[EMAIL PROTECTED]>
+
+       * cfold.cs (BinaryFold): On the guest to unify empty constant cast.
+
+       * const.cs (Const.Define): Check for constant type.
+       (Const.IsConstantTypeValid): Looks for valid constant types.
+
+       * convert.cs (ImplicitReferenceConversion): NullCast to 
EmptyConstantCast.
+
+       * ecore.cs (EmptyConstantCast): New common class for all constant based
+       EmptyCast(s).
+
+       * expression.cs (Is.DoResolve): Handle null constant especially.
+       (New.DoResolve): Check for new void().
+       (MemberAccess.DoResolve): Cope with all kind of nulls.
+
+       * literal.cs (NullConstant): Uses EmptyConstantCast.
+       (NullDefault): Based on EmptyConstantCast.
+       (NullLiteral): Uses EmptyConstantCast.
+
+       * statement.cs (Block.ResolveMeta): Check for constant type.
+
 2006-09-22  Martin Baulig  <[EMAIL PROTECTED]>
 
        * delegate.cs, attribute.cs: Merged with the gmcs versions.

Modified: trunk/mcs/mcs/cfold.cs
===================================================================
--- trunk/mcs/mcs/cfold.cs      2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/cfold.cs      2006-09-23 18:37:59 UTC (rev 65833)
@@ -175,11 +175,11 @@
                static public Expression BinaryFold (EmitContext ec, 
Binary.Operator oper,
                                                     Constant left, Constant 
right, Location loc)
                {
-                       if (left is NullCast)
-                               return BinaryFold (ec, oper, 
((NullCast)left).child, right, loc);
+                       if (left is EmptyConstantCast)
+                               return BinaryFold (ec, oper, 
((EmptyConstantCast)left).child, right, loc);
 
-                       if (right is NullCast)
-                               return BinaryFold (ec, oper, left, 
((NullCast)right).child, loc);
+                       if (right is EmptyConstantCast)
+                               return BinaryFold (ec, oper, left, 
((EmptyConstantCast)right).child, loc);
 
                        Type lt = left.Type;
                        Type rt = right.Type;

Modified: trunk/mcs/mcs/const.cs
===================================================================
--- trunk/mcs/mcs/const.cs      2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/const.cs      2006-09-23 18:37:59 UTC (rev 65833)
@@ -66,6 +66,11 @@
                                return false;
 
                        Type ttype = MemberType;
+                       if (!IsConstantTypeValid (ttype)) {
+                               Error_InvalidConstantType (ttype, Location);
+                               return false;
+                       }
+
                        while (ttype.IsArray)
                            ttype = TypeManager.GetElementType (ttype);
 
@@ -84,7 +89,21 @@
 
                        return true;
                }
-               
+
+               public static bool IsConstantTypeValid (Type t)
+               {
+                       if (TypeManager.IsBuiltinOrEnum (t))
+                               return true;
+
+                       if (t.IsPointer || t.IsValueType)
+                               return false;
+                       
+                       if (TypeManager.IsGenericParameter (t))
+                               return false;
+
+                       return true;
+               }
+
                /// <summary>
                ///  Emits the field value by evaluating the expression
                /// </summary>
@@ -107,13 +126,8 @@
                        base.Emit ();
                }
 
-               public static void Error_ExpressionMustBeConstant (Type 
constantType, Location loc, string e_name)
+               public static void Error_ExpressionMustBeConstant (Location 
loc, string e_name)
                {
-                       if (constantType != null && TypeManager.IsValueType 
(constantType) &&
-                               !TypeManager.IsBuiltinOrEnum (constantType)) {
-                               Report.Error (283, loc, "The type `{0}' cannot 
be declared const", TypeManager.CSharpName (constantType));
-                               return;
-                       }
                        Report.Error (133, loc, "The expression being assigned 
to `{0}' must be constant", e_name);
                }
 
@@ -129,6 +143,11 @@
                                name);
                }
 
+               public static void Error_InvalidConstantType (Type t, Location 
loc)
+               {
+                       Report.Error (283, loc, "The type `{0}' cannot be 
declared const", TypeManager.CSharpName (t));
+               }
+
                #region IConstant Members
 
                public bool ResolveValue ()

Modified: trunk/mcs/mcs/convert.cs
===================================================================
--- trunk/mcs/mcs/convert.cs    2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/convert.cs    2006-09-23 18:37:59 UTC (rev 65833)
@@ -58,7 +58,7 @@
                                if (expr_type.IsValueType)
                                        return new BoxedCast (expr, 
target_type);
                                if (expr_type == TypeManager.null_type)
-                                       return new NullCast 
((NullConstant)expr, target_type);
+                                       return new EmptyConstantCast 
((Constant)expr, target_type);
 
                                return null;
                        } else if (expr_type.IsSubclassOf (target_type)) {

Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs      2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/ecore.cs      2006-09-23 18:37:59 UTC (rev 65833)
@@ -339,7 +339,7 @@
                                return;
                        }
 
-                       if (Type != TypeManager.string_type && this is Constant 
&& !(this is NullCast)) {
+                       if (Type != TypeManager.string_type && this is Constant 
&& !(this is EmptyConstantCast)) {
                                Report.Error (31, loc, "Constant value `{0}' 
cannot be converted to a `{1}'",
                                        GetSignatureForError (), 
TypeManager.CSharpName (target));
                                return;
@@ -454,12 +454,7 @@
                        if (c != null)
                                return c;
 
-                       Type constant_type = null;
-                       if (mc is MemberBase) {
-                               constant_type = ((MemberBase)mc).MemberType;
-                       }
-
-                       Const.Error_ExpressionMustBeConstant (constant_type, 
loc, mc.GetSignatureForError ());
+                       Const.Error_ExpressionMustBeConstant (loc, 
mc.GetSignatureForError ());
                        return null;
                }
 
@@ -1351,32 +1346,62 @@
                }
        }
 
-        //
+       //
+       // Constant specialization of EmptyCast.
        // We need to special case this since an empty cast of
-       // a NullLiteral is still a Constant
+       // a constant is still a constant. 
        //
-       public class NullCast : NullConstant {
-               public NullConstant child;
-                               
-               public NullCast (NullConstant child, Type return_type):
-                       base (child.Location)
+       public class EmptyConstantCast : Constant
+       {
+               public readonly Constant child;
+
+               public EmptyConstantCast(Constant child, Type type)
+                       : base (child.Location)
                {
-                       type = return_type;
+                       eclass = child.eclass;
                        this.child = child;
+                       this.type = type;
                }
 
-               public override void Emit (EmitContext ec)
+               public override string AsString ()
                {
-                       child.Emit (ec);
+                       return child.AsString ();
                }
 
+               public override object GetValue ()
+               {
+                       return child.GetValue ();
+               }
+
                public override Constant Reduce (bool inCheckedContext, Type 
target_type)
                {
-                       if (type == target_type)
-                               return child.Reduce (inCheckedContext, 
target_type);
+                       return child.Reduce (inCheckedContext, target_type);
+               }
 
-                       return null;
+               public override Constant Increment ()
+               {
+                       return child.Increment ();
                }
+
+               public override bool IsDefaultValue
+               {
+                       get { return child.IsDefaultValue; }
+               }
+
+               public override bool IsNegative
+               {
+                       get { return child.IsNegative; }
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       child.Emit (ec);
+               }
+
+               public override Constant ToType (Type type)
+               {
+                       return child.ToType (type);
+               }
        }
 
 

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/expression.cs 2006-09-23 18:37:59 UTC (rev 65833)
@@ -1181,15 +1181,22 @@
                        //
                        Type probe_type = probe_type_expr.Type;
                        e = Convert.ImplicitConversionStandard (ec, expr, 
probe_type, loc);
-                       if (e != null && !(e is NullConstant)){
+                       if (e != null){
                                expr = e;
                                if (etype.IsValueType)
                                        action = Action.AlwaysTrue;
                                else
                                        action = Action.LeaveOnStack;
 
-                               Report.Warning(183, 1, loc, "The given 
expression is always of the provided (`{0}') type",
-                                       TypeManager.CSharpName(probe_type));
+                               Constant c = e as Constant;
+                               if (c != null && c.GetValue () == null) {
+                                       action = Action.AlwaysFalse;
+                                       Report.Warning (184, 1, loc, "The given 
expression is never of the provided (`{0}') type",
+                                               TypeManager.CSharpName 
(probe_type));
+                               } else {
+                                       Report.Warning (183, 1, loc, "The given 
expression is always of the provided (`{0}') type",
+                                               TypeManager.CSharpName 
(probe_type));
+                               }
                                return this;
                        }
                        
@@ -5719,6 +5726,11 @@
 
                        type = texpr.Type;
 
+                       if (type == TypeManager.void_type) {
+                               Error_VoidInvalidInTheContext (loc);
+                               return null;
+                       }
+
                        if (Arguments == null) {
                                Expression c = Constantify (type);
                                if (c != null)
@@ -7240,7 +7252,8 @@
                                return null;
                        }
 
-                       if (new_expr is NullConstant) {
+                       Constant c = new_expr as Constant;
+                       if (c != null && c.GetValue () == null) {
                                Report.Warning (1720, 1, loc, "Expression will 
always cause a `{0}'",
                                        "System.NullReferenceException");
                        }

Modified: trunk/mcs/mcs/literal.cs
===================================================================
--- trunk/mcs/mcs/literal.cs    2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/literal.cs    2006-09-23 18:37:59 UTC (rev 65833)
@@ -96,15 +96,15 @@
                public override Constant Reduce(bool inCheckedContext, Type 
target_type)
                {
                        if (!TypeManager.IsValueType (target_type))
-                               return new NullCast (this, target_type);
+                               return new EmptyConstantCast (this, 
target_type);
 
                        return null;
                }
 
                public override Constant ToType(Type targetType)
                {
-                       if (!targetType.IsValueType)
-                               return new NullCast (this, targetType);
+                       if (!TypeManager.IsValueType (targetType))
+                               return new EmptyConstantCast (this, targetType);
 
                        return null;
                }
@@ -113,20 +113,16 @@
        //
        // Represents default(X) when result can be reduced to null
        //
-       public class NullDefault : NullConstant
+       public class NullDefault : EmptyConstantCast
        {
-               Expression defaultExpression;
-
-               public NullDefault (Location loc, Expression defaultExpression)
-                       : base (loc)
+               public NullDefault(Constant value, Type type)
+                       : base (value, type)
                {
-                       type = defaultExpression.Type;
-                       this.defaultExpression = defaultExpression;
                }
 
                public override void Error_ValueCannotBeConverted (Location 
loc, Type target, bool expl)
                {
-                       defaultExpression.Error_ValueCannotBeConverted (loc, 
target, expl);
+                       base.Error_ValueCannotBeConverted(loc, target, expl);
                }
        }
 
@@ -160,7 +156,7 @@
                public override Constant ToType (Type targetType)
                {
                        if (targetType.IsPointer)
-                               return new NullCast (NullPointer.Null, 
targetType);
+                               return new EmptyConstantCast (NullPointer.Null, 
targetType);
 
                        if (TypeManager.IsGenericParameter(targetType)) {
                                GenericConstraints gc = null;
@@ -169,7 +165,7 @@
                                gc = 
TypeManager.GetTypeParameterConstraints(targetType);
 #endif
                                if (gc != null && gc.IsReferenceType)
-                                       return new NullCast(this, targetType);
+                                       return new EmptyConstantCast (this, 
targetType);
 
                                Error_ValueCannotBeConverted (loc, targetType, 
false);
                                return null;

Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs  2006-09-23 10:59:39 UTC (rev 65832)
+++ trunk/mcs/mcs/statement.cs  2006-09-23 18:37:59 UTC (rev 65833)
@@ -1751,6 +1751,11 @@
                                                // which in turn causes the 
'must be constant' error to be triggered.
                                                constants.Remove (name);
 
+                                               if (!Const.IsConstantTypeValid 
(variable_type)) {
+                                                       
Const.Error_InvalidConstantType (variable_type, loc);
+                                                       continue;
+                                               }
+
                                                using (ec.With 
(EmitContext.Flags.ConstantCheckState, (flags & Flags.Unchecked) == 0)) {
                                                        ec.CurrentBlock = this;
                                                        Expression e = 
cv.Resolve (ec);
@@ -1759,17 +1764,10 @@
 
                                                        Constant ce = e as 
Constant;
                                                        if (ce == null) {
-                                                               
Const.Error_ExpressionMustBeConstant (variable_type, vi.Location, name);
+                                                               
Const.Error_ExpressionMustBeConstant (vi.Location, name);
                                                                continue;
                                                        }
 
-#if GMCS_SOURCE
-                                                       if 
(TypeManager.IsGenericParameter (variable_type)) {
-                                                               
Const.Error_ExpressionMustBeConstant (variable_type, vi.Location, name);
-                                                               continue;
-                                                       }
-#endif
-
                                                        e = 
ce.ImplicitConversionRequired (variable_type, vi.Location);
                                                        if (e == null)
                                                                continue;

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

Reply via email to