Treat pointers to enclosing declaration space as 'DeclSpace', not
[mono.git] / mcs / gmcs / const.cs
index f31a73dab35a4aea4663bb7c5128f19d934435ec..7bff36905e80a31ceccbc4cbbab5faf39d181389 100644 (file)
@@ -24,7 +24,6 @@ namespace Mono.CSharp {
        }
 
        public class Const : FieldMember, IConstant {
-               Expression Expr;
                Constant value;
                bool in_transit;
 
@@ -38,9 +37,9 @@ namespace Mono.CSharp {
                public Const (TypeContainer parent, Expression constant_type, string name,
                              Expression expr, int mod_flags, Attributes attrs, Location loc)
                        : base (parent, constant_type, mod_flags, AllowedModifiers,
-                               new MemberName (name, loc), expr, attrs)
+                               new MemberName (name, loc), attrs)
                {
-                       Expr = expr;
+                       initializer = expr;
                        ModFlags |= Modifiers.STATIC;
                }
 
@@ -136,8 +135,10 @@ namespace Mono.CSharp {
                        }
 
                        in_transit = true;
-                       EmitContext ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
-                       value = Expr.ResolveAsConstant (ec, this);
+                       EmitContext ec = new EmitContext (this, Parent, Location, null, MemberType, ModFlags);
+                       value = initializer.ResolveAsConstant (ec, this);
+                       in_transit = false;
+
                        if (value == null)
                                return false;
 
@@ -151,7 +152,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       in_transit = false;
                        return true;
                }
 
@@ -164,7 +164,7 @@ namespace Mono.CSharp {
                #endregion
        }
 
-       public class ExternalConstant: IConstant
+       public class ExternalConstant : IConstant
        {
                FieldInfo fi;
                Constant value;
@@ -174,6 +174,32 @@ namespace Mono.CSharp {
                        this.fi = fi;
                }
 
+               private ExternalConstant (FieldInfo fi, Constant value):
+                       this (fi)
+               {
+                       this.value = value;
+               }
+
+               //
+               // Decimal constants cannot be encoded in the constant blob, and thus are marked
+               // as IsInitOnly ('readonly' in C# parlance).  We get its value from the 
+               // DecimalConstantAttribute metadata.
+               //
+               public static IConstant CreateDecimal (FieldInfo fi)
+               {
+                       if (fi is FieldBuilder)
+                               return null;
+                       
+                       object[] attrs = fi.GetCustomAttributes (TypeManager.decimal_constant_attribute_type, false);
+                       if (attrs.Length != 1)
+                               return null;
+
+                       IConstant ic = new ExternalConstant (fi,
+                               new DecimalConstant (((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value, Location.Null));
+
+                       return ic;
+               }
+
                #region IConstant Members
 
                public void CheckObsoleteness (Location loc)