{
void CheckObsoleteness (Location loc);
bool ResolveValue ();
- Constant Value { get; }
+ Constant CreateConstantReference (Location loc);
}
public class Const : FieldMember, IConstant {
Constant value;
bool in_transit;
+ bool define_called;
public const int AllowedModifiers =
Modifiers.NEW |
/// </summary>
public override bool Define ()
{
- // Make Define () idempotent, but ensure that the error check happens.
- if (FieldBuilder != null)
- return base.CheckBase ();
+ // Because constant define can be called from other class
+ if (define_called) {
+ CheckBase ();
+ return FieldBuilder != null;
+ }
+
+ define_called = true;
if (!base.Define ())
return false;
return true;
}
- public Constant Value {
- get {
- return value;
- }
+ public Constant CreateConstantReference (Location loc)
+ {
+ if (value == null)
+ return null;
+
+ return Constant.CreateConstant (value.Type, value.GetValue(), loc);
}
#endregion
public class ExternalConstant : IConstant
{
FieldInfo fi;
- Constant value;
+ object value;
public ExternalConstant (FieldInfo fi)
{
this.fi = fi;
}
- private ExternalConstant (FieldInfo fi, Constant value):
+ private ExternalConstant (FieldInfo fi, object value):
this (fi)
{
this.value = value;
return null;
IConstant ic = new ExternalConstant (fi,
- new DecimalConstant (((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value, Location.Null));
+ ((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value);
return ic;
}
if (value != null)
return true;
- if (fi.DeclaringType.IsEnum) {
- value = Expression.Constantify (fi.GetValue (fi), TypeManager.EnumToUnderlying (fi.FieldType));
- value = new EnumConstant (value, fi.DeclaringType);
- return true;
- }
-
- value = Expression.Constantify (fi.GetValue (fi), fi.FieldType);
+ value = fi.GetValue (fi);
return true;
}
- public Constant Value {
- get {
- return value;
- }
+ public Constant CreateConstantReference (Location loc)
+ {
+ return Constant.CreateConstant (fi.FieldType, value, loc);
}
#endregion