namespace Mono.CSharp {
- public class EnumMember: MemberCore, IConstant {
+ public class EnumMember : MemberCore, IConstant {
static string[] attribute_targets = new string [] { "field" };
public FieldBuilder builder;
Constant value;
bool in_transit;
+ // TODO: remove or simplify
+ EmitContext ec;
+
public EnumMember (Enum parent_enum, EnumMember prev_member, Expression expr,
MemberName name, Attributes attrs):
- base (parent_enum.Parent, name, attrs)
+ base (parent_enum, name, attrs)
{
this.parent_enum = parent_enum;
this.ModFlags = parent_enum.ModFlags;
this.ValueExpr = expr;
this.prev_member = prev_member;
+
+ ec = new EmitContext (this, parent_enum, parent_enum, Location, null, null, ModFlags, false);
+ ec.InEnumContext = true;
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
}
}
- bool IsValidEnumType (Type t)
+ static bool IsValidEnumType (Type t)
{
return (t == TypeManager.int32_type || t == TypeManager.uint32_type || t == TypeManager.int64_type ||
t == TypeManager.byte_type || t == TypeManager.sbyte_type || t == TypeManager.short_type ||
const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
TypeBuilder tb = parent_enum.TypeBuilder;
builder = tb.DefineField (Name, tb, attr);
+ ec.ContainerType = tb;
TypeManager.RegisterConstant (builder, this);
return true;
if (ValueExpr != null) {
in_transit = true;
- Constant c = ValueExpr.ResolveAsConstant (parent_enum.EmitContext, this);
+ Constant c = ValueExpr.ResolveAsConstant (ec, this);
in_transit = false;
if (c == null)
return true;
}
- public bool Emit (EmitContext ec)
+ public override void Emit ()
{
if (OptAttributes != null)
- OptAttributes.Emit (ec, this);
+ OptAttributes.Emit ();
if (!ResolveValue ())
- return false;
+ return;
builder.SetConstant (value.GetValue ());
- Emit ();
- return true;
+ base.Emit ();
}
public override string GetSignatureForError()
}
}
- protected override bool VerifyClsCompliance(DeclSpace ds)
- {
- // Because parent is TypeContainer and we have only DeclSpace parent.
- // Parameter replacing is required
- return base.VerifyClsCompliance (parent_enum);
- }
-
public override string DocCommentHeader {
get { return "F:"; }
}
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (NamespaceEntry ns, TypeContainer parent, Expression type,
+ public Enum (NamespaceEntry ns, DeclSpace parent, Expression type,
int mod_flags, MemberName name, Attributes attrs)
: base (ns, parent, name, attrs)
{
if (TypeBuilder != null)
return TypeBuilder;
- ec = new EmitContext (this, this, Location, null, null, ModFlags, false);
- ec.InEnumContext = true;
-
if (!(BaseType is TypeLookupExpression)) {
Report.Error (1008, Location,
"Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
return null;
}
- TypeExpr ute = ResolveBaseTypeExpr (BaseType, false, Location);
+ TypeExpr ute = BaseType.ResolveAsTypeTerminal (this, false);
UnderlyingType = ute.Type;
if (UnderlyingType != TypeManager.int32_type &&
Basename, TypeAttr, TypeManager.enum_type);
}
- ec.ContainerType = TypeBuilder;
-
//
// Call MapToInternalType for corlib
//
FieldAttributes.Public | FieldAttributes.SpecialName
| FieldAttributes.RTSpecialName);
- TypeManager.AddUserType (Name, this);
+ TypeManager.AddUserType (this);
foreach (EnumMember em in defined_names.Values) {
if (!em.Define ())
public override void Emit ()
{
if (OptAttributes != null) {
- OptAttributes.Emit (ec, this);
+ OptAttributes.Emit ();
}
foreach (EnumMember em in defined_names.Values) {
- if (!em.Emit (ec))
- return;
+ em.Emit ();
}
base.Emit ();
{
HybridDictionary dict = new HybridDictionary (defined_names.Count, true);
foreach (EnumMember em in defined_names.Values) {
- if (!em.IsClsCompliaceRequired (this))
+ if (!em.IsClsComplianceRequired ())
continue;
try {
}
}
- protected override bool VerifyClsCompliance (DeclSpace ds)
+ protected override bool VerifyClsCompliance ()
{
- if (!base.VerifyClsCompliance (ds))
+ if (!base.VerifyClsCompliance ())
return false;
VerifyClsName ();