Merge pull request #5206 from alexrp/profiler-gc-base-init
[mono.git] / mcs / mcs / const.cs
index d40ce91675d91aeb6cb057281f7c6b5b8cf1009b..046aec24c1b18b8bb3619e23a5a899bbb074f27a 100644 (file)
@@ -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
@@ -200,7 +211,7 @@ namespace Mono.CSharp {
                                        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;