Revert my patch to constants, they broke corlib and System
authorMiguel de Icaza <miguel@gnome.org>
Sun, 10 Oct 2004 15:13:48 +0000 (15:13 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sun, 10 Oct 2004 15:13:48 +0000 (15:13 -0000)
svn path=/trunk/mcs/; revision=34844

mcs/mcs/ChangeLog
mcs/mcs/const.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/statement.cs

index 2f095b3d50b9104ce8125ef19579c56e3b05bfcb..4a326c5d63e136fd136378c52cf5d11f60c64086 100755 (executable)
@@ -1,26 +1,3 @@
-2004-10-10  Miguel de Icaza  <miguel@ximian.com>
-
-       * expression.cs (MemberAccess.ResolveMemberAccess): When looking
-       up a constant, do not use the "Const" object after LookupConstant,
-       instead use the result that is returned in the `out' parameter
-       that already has the GetValue done.   Fixes the corlib regression,
-       and removes duplicated code.
-
-2004-10-09  Miguel de Icaza  <miguel@ximian.com>
-
-       * const.cs (ConvertExpressionToConstant): Refactor code that does
-       the Expression to Constant checking.  This can be used in other
-       places in the compiler that need to go from an Expression that
-       wraps a Constant (like the casts) to a Constant.
-
-       * ecore.cs (Expression.ConvertIntLiteral): If we got enumerations,
-       unfold those into the underlying types before testing for the
-       ImplicitConversions, as that code wont cope with casts from
-       enumerations to constants.
-
-       * statement.cs (SwitchLabel.ResolveAndReduce): Reuse
-       ConvertExpressionToConstant.
-
 2004-10-07  Raja R Harinath  <rharinath@novell.com>
 
        More DeclSpace.ResolveType avoidance.
index 4a6851a88465ccf4b0243e08e5bc947da3e8d365..1e0b00b2f44f83f886b5cc44c98920c570d88faa 100755 (executable)
@@ -160,46 +160,6 @@ namespace Mono.CSharp {
                        
                        return retval;
                }
-
-               static void ReportConstantError (Location loc, string opt_name)
-               {
-                       if (opt_name != null)
-                               Report.Error (133, loc, String.Format ("The expression being assigned to `{0}' must be constant"));
-                       else
-                               Report.Error (150, loc, "A constant value is expected");
-               }
-                       
-               public static Constant ConvertExpressionToConstant (Expression expr, Location loc, bool show_errors, string opt_name)
-               {
-                       Constant ce = expr as Constant;
-                       if (ce == null){
-                               UnCheckedExpr un_expr = expr as UnCheckedExpr;
-                               CheckedExpr ch_expr = expr as CheckedExpr;
-                               EmptyCast ec_expr = expr as EmptyCast;
-
-                               if ((un_expr != null) && (un_expr.Expr is Constant))
-                                       expr = un_expr.Expr;
-                               else if ((ch_expr != null) && (ch_expr.Expr is Constant))
-                                       expr = ch_expr.Expr;
-                               else if ((ec_expr != null) && (ec_expr.Child is Constant))
-                                       expr = ec_expr.Child;
-                               else if (expr is ArrayCreation){
-                                       if (show_errors)
-                                               Report.Error (133, loc, "Arrays can not be constant");
-                               } else {
-                                       if (show_errors)
-                                               ReportConstantError (loc, opt_name);
-                                       return null;
-                               }
-
-                               ce = expr as Constant;
-                               if (ce == null){
-                                       if (show_errors)
-                                               ReportConstantError (loc, opt_name);
-                               }
-                       }
-                       return ce;
-               }
                
                /// <summary>
                ///  Looks up the value of a constant field. Defines it if it hasn't
@@ -244,12 +204,30 @@ namespace Mono.CSharp {
 
                        Expression real_expr = Expr;
 
-                       Constant ce = ConvertExpressionToConstant (Expr, Location, errors == Report.Errors, null);
+                       Constant ce = Expr as Constant;
                        if (ce == null){
-                               value = null;
-                               return false;
+                               UnCheckedExpr un_expr = Expr as UnCheckedExpr;
+                               CheckedExpr ch_expr = Expr as CheckedExpr;
+                               EmptyCast ec_expr = Expr as EmptyCast;
+
+                               if ((un_expr != null) && (un_expr.Expr is Constant))
+                                       Expr = un_expr.Expr;
+                               else if ((ch_expr != null) && (ch_expr.Expr is Constant))
+                                       Expr = ch_expr.Expr;
+                               else if ((ec_expr != null) && (ec_expr.Child is Constant))
+                                       Expr = ec_expr.Child;
+                               else if (Expr is ArrayCreation){
+                                       Report.Error (133, Location, "Arrays can not be constant");
+                               } else {
+                                       if (errors == Report.Errors)
+                                               Report.Error (150, Location, "A constant value is expected");
+                                       value = null;
+                                       return false;
+                               }
+
+                               ce = Expr as Constant;
                        }
-                       
+
                        if (MemberType != real_expr.Type) {
                                ce = ChangeType (Location, ce, MemberType);
                                if (ce == null){
index 9ccdfed2bb324498e2158e677940318e242ea98e..f5482ac197ead5c8e75bf08ccba280ad0525025b 100755 (executable)
@@ -885,16 +885,6 @@ namespace Mono.CSharp {
                /// </summary>
                public static object ConvertIntLiteral (Constant c, Type target_type, Location loc)
                {
-                       if (TypeManager.IsEnumType (target_type))
-                               target_type = TypeManager.EnumToUnderlying (target_type);
-
-                       //
-                       // Make into one of the literals we handle, we dont really care
-                       // about this value as we will just return a few limited types
-                       // 
-                       if (c is EnumConstant)
-                               c = ((EnumConstant)c).WidenToCompilerConstant ();
-                       
                        if (!Convert.ImplicitStandardConversionExists (c, target_type)){
                                Convert.Error_CannotImplicitConversion (loc, c.Type, target_type);
                                return null;
@@ -905,6 +895,12 @@ namespace Mono.CSharp {
                        if (c.Type == target_type)
                                return ((Constant) c).GetValue ();
 
+                       //
+                       // Make into one of the literals we handle, we dont really care
+                       // about this value as we will just return a few limited types
+                       // 
+                       if (c is EnumConstant)
+                               c = ((EnumConstant)c).WidenToCompilerConstant ();
 
                        if (c is IntConstant){
                                int v = ((IntConstant) c).Value;
index eb0285ebeadb6a822014480b61608d519bb3978a..127210c50a796f34081eeb6bf5d115a0b646aecb 100755 (executable)
@@ -1795,7 +1795,6 @@ namespace Mono.CSharp {
                                return null;
                        }
                        expr = Convert.ExplicitConversion (ec, expr, type, loc);
-
                        return expr;
                }
 
@@ -6948,7 +6947,9 @@ namespace Mono.CSharp {
                                                if (!c.LookupConstantValue (out o))
                                                        return null;
 
-                                               return Constantify (o, fi.FieldType);
+                                               object real_value = ((Constant) c.Expr).GetValue ();
+
+                                               return Constantify (real_value, fi.FieldType);
                                        }
                                }
 
index d2b1afc600c0d86247e54280d00f67f71de8acdc..2d5370d16fd994b00ff69ceafc2baa19cd7a16d7 100755 (executable)
@@ -1996,14 +1996,10 @@ namespace Mono.CSharp {
                        if (e == null)
                                return false;
 
-                       Expression ee = e as Constant;
-                       if (ee == null)
-                               ee = Const.ConvertExpressionToConstant (e, loc, true, null);
-                       if (ee == null){
+                       if (!(e is Constant)){
                                Report.Error (150, loc, "A constant value is expected, got: " + e);
                                return false;
                        }
-                       e = ee;
 
                        if (e is StringConstant || e is NullLiteral){
                                if (required_type == TypeManager.string_type){