using System.Reflection;
using System.Reflection.Emit;
using System.Globalization;
-using System.Xml;
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)
if (marshal != null) {
builder.SetMarshal (marshal);
}
- return;
- }
+ return;
+ }
if (a.Type.IsSubclassOf (TypeManager.security_attr_type)) {
a.Error_InvalidSecurityParent ();
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;
}
+ // Because parent is TypeContainer and we have DeclSpace only
+ public override void CheckObsoleteness (Location loc)
+ {
+ parent_enum.CheckObsoleteness (loc);
+
+ ObsoleteAttribute oa = GetObsoleteAttribute ();
+ if (oa == null) {
+ return;
+ }
+
+ AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
+ }
+
public bool ResolveValue ()
{
if (value != null)
if (ValueExpr != null) {
in_transit = true;
+ Constant c = ValueExpr.ResolveAsConstant (ec, this);
+ in_transit = false;
- Constant c = ValueExpr.ResolveAsConstant (parent_enum.EmitContext, this);
if (c == null)
return false;
return true;
}
- public void Emit (EmitContext ec)
+ public override void Emit ()
{
if (OptAttributes != null)
- OptAttributes.Emit (ec, this);
+ OptAttributes.Emit ();
- if (ResolveValue ())
- builder.SetConstant (value.GetValue ());
+ if (!ResolveValue ())
+ return;
- Emit ();
+ builder.SetConstant (value.GetValue ());
+ base.Emit ();
}
public override string GetSignatureForError()
{
- return String.Concat (parent_enum.GetSignatureForError (), '.', base.GetSignatureForError ());
+ return String.Concat (parent_enum.GetSignatureForError (), '.', Name);
}
public override string[] ValidAttributeTargets {
}
}
- 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);
- }
-
- // There is no base type
- protected override void VerifyObsoleteAttribute()
- {
- }
-
public override string DocCommentHeader {
get { return "F:"; }
}
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);
- if (ute == null)
- return null;
-
+ 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) {
- em.Emit (ec);
+ em.Emit ();
}
base.Emit ();
{
HybridDictionary dict = new HybridDictionary (defined_names.Count, true);
foreach (EnumMember em in defined_names.Values) {
- if (!em.IsClsComplianceRequired (this))
+ if (!em.IsClsComplianceRequired ())
continue;
try {
dict.Add (em.Name, em);
}
catch (ArgumentException) {
- Report.SymbolRelatedToPreviousError ((MemberCore)dict [em.Name]);
- Report.Warning (3005, em.Location, "Identifier `{0}' differing only in case is not CLS-compliant", em.GetSignatureForError ());
+ Report.SymbolRelatedToPreviousError (em);
+ MemberCore col = (MemberCore)dict [em.Name];
+ Report.Warning (3005, 1, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
}
}
}
- protected override bool VerifyClsCompliance (DeclSpace ds)
+ protected override bool VerifyClsCompliance ()
{
- if (!base.VerifyClsCompliance (ds))
+ if (!base.VerifyClsCompliance ())
return false;
VerifyClsName ();
- if (!AttributeTester.IsClsCompliant (UnderlyingType)) {
+ if (UnderlyingType == TypeManager.uint32_type ||
+ UnderlyingType == TypeManager.uint64_type ||
+ UnderlyingType == TypeManager.ushort_type) {
Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
}
}
}
- protected override void VerifyObsoleteAttribute()
- {
- // UnderlyingType is never obsolete
- }
-
//
// Generates xml doc comments (if any), and if required,
// handle warning report.