2002-02-11 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / mcs / const.cs
index cdc0292c47c6f3e4e08744fa0cf7da5fa8772121..60dce6d89e862f819da4f3a1402679722d775557 100755 (executable)
@@ -47,7 +47,7 @@ namespace Mono.CSharp {
                        ConstantType = constant_type;
                        Name = name;
                        Expr = expr;
-                       ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE);
+                       ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE, loc);
                        OptAttributes = attrs;
                }
 
@@ -58,6 +58,7 @@ namespace Mono.CSharp {
                        }
                }
 
+#if DEBUG
                void dump_tree (Type t)
                {
                        Console.WriteLine ("Dumping hierarchy");
@@ -67,6 +68,7 @@ namespace Mono.CSharp {
                                t = t.BaseType;
                        }
                }
+#endif
 
                /// <summary>
                ///   Defines the constant in the @parent
@@ -123,14 +125,12 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       Expr = Expression.Reduce (ec, Expr);
-                       
-                       if (!(Expr is Literal)) {
+                       if (!(Expr is Constant)) {
                                Report.Error (150, Location, "A constant value is expected");
                                return null;
                        }
 
-                       ConstantValue = ((Literal) Expr).GetValue ();
+                       ConstantValue = ((Constant) Expr).GetValue ();
 
                        if (type.IsEnum){
                                //
@@ -139,10 +139,10 @@ namespace Mono.CSharp {
                                ConstantValue = System.Enum.ToObject (
                                        type, ConstantValue);
                        }
-                       
+
                        FieldBuilder.SetConstant (ConstantValue);
 
-                       if (!TypeManager.RegisterField (FieldBuilder, ConstantValue))
+                       if (!TypeManager.RegisterFieldValue (FieldBuilder, ConstantValue))
                                return null;
 
                        return ConstantValue;
@@ -154,9 +154,6 @@ namespace Mono.CSharp {
                /// </summary>
                public void EmitConstant (TypeContainer parent)
                {
-                       if (FieldBuilder == null)
-                               return;
-                       
                        EmitContext ec = new EmitContext (parent, Location, null, type, ModFlags);
                        LookupConstantValue (ec);