Merge pull request #3869 from radical/mcs-ignore-arg
[mono.git] / mcs / mcs / const.cs
index 74a36da54b68cf9e33e54e55555bd483b9d91ca6..046aec24c1b18b8bb3619e23a5a899bbb074f27a 100644 (file)
@@ -26,7 +26,7 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Const (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+               public Const (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
                        : base (parent, type, mod_flags, AllowedModifiers, name, attrs)
                {
                        ModFlags |= Modifiers.STATIC;
@@ -59,16 +59,16 @@ namespace Mono.CSharp {
 
                        if ((field_attr & FieldAttributes.InitOnly) != 0)
                                Parent.PartialContainer.RegisterFieldForInitialization (this,
-                                       new FieldInitializer (spec, initializer, this));
+                                       new FieldInitializer (this, initializer, Location));
 
                        if (declarators != null) {
                                var t = new TypeExpression (MemberType, TypeExpression.Location);
-                               int index = Parent.PartialContainer.Constants.IndexOf (this);
                                foreach (var d in declarators) {
                                        var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
                                        c.initializer = d.Initializer;
                                        ((ConstInitializer) c.initializer).Name = d.Name.Value;
-                                       Parent.PartialContainer.Constants.Insert (++index, c);
+                                       c.Define ();
+                                       Parent.PartialContainer.Members.Add (c);
                                }
                        }
 
@@ -100,12 +100,23 @@ namespace Mono.CSharp {
                {
                        if (t.IsGenericParameter) {
                                Report.Error (1959, loc,
-                                       "Type parameter `{0}' cannot be declared const", TypeManager.CSharpName (t));
+                                       "Type parameter `{0}' cannot be declared const", t.GetSignatureForError ());
                        } else {
                                Report.Error (283, loc,
-                                       "The type `{0}' cannot be declared const", TypeManager.CSharpName (t));
+                                       "The type `{0}' cannot be declared const", t.GetSignatureForError ());
                        }
                }
+
+               public override void Accept (StructuralVisitor visitor)
+               {
+                       visitor.Visit (this);
+               }
+
+               public override void PrepareEmit ()
+               {
+                       base.PrepareEmit ();
+                       DefineValue ();
+               }
        }
 
        public class ConstSpec : FieldSpec
@@ -195,12 +206,12 @@ namespace Mono.CSharp {
                                        c = field.ConvertInitializer (rc, c);
 
                                if (c == null) {
-                                       if (TypeManager.IsReferenceType (field.MemberType))
+                                       if (TypeSpec.IsReferenceType (field.MemberType))
                                                Error_ConstantCanBeInitializedWithNullOnly (rc, field.MemberType, expr.Location, GetSignatureForError ());
                                        else if (!(expr is Constant))
                                                Error_ExpressionMustBeConstant (rc, expr.Location, GetSignatureForError ());
                                        else
-                                               expr.Error_ValueCannotBeConverted (rc, expr.Location, field.MemberType, false);
+                                               expr.Error_ValueCannotBeConverted (rc, field.MemberType, false);
                                }
 
                                expr = c;
@@ -223,5 +234,10 @@ namespace Mono.CSharp {
 
                        return field.Parent.GetSignatureForError () + "." + Name;
                }
+
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 }