}
public class Const : FieldMember, IConstant {
- Expression Expr;
Constant value;
bool in_transit;
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;
}
}
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;
return false;
}
- in_transit = false;
return true;
}
#endregion
}
- public class ExternalConstant: IConstant
+ public class ExternalConstant : IConstant
{
FieldInfo fi;
Constant value;
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)