readonly Expression ValueExpr;
readonly EnumMember prev_member;
- Constant value;
+ EnumConstant 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;
return true;
if (in_transit) {
- // suppress cyclic errors
- value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
Const.Error_CyclicDeclaration (this);
return false;
}
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)
if (c is EnumConstant)
c = ((EnumConstant)c).Child;
- c = c.ToType (parent_enum.UnderlyingType, Location);
+ c = c.ImplicitConversionRequired (parent_enum.UnderlyingType, Location);
if (c == null)
return false;
return true;
}
- if (!prev_member.ResolveValue ())
+ if (!prev_member.ResolveValue ()) {
+ // Suppress cyclic error
+ prev_member.value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
return false;
+ }
in_transit = true;
try {
- value = prev_member.value.Increment ();
+ value = (EnumConstant)prev_member.value.Increment ();
}
catch (OverflowException) {
Report.Error (543, Location, "The enumerator value `{0}' is too large to fit in its type `{1}'",
return true;
}
- public bool Emit (EmitContext ec)
+ public override void Emit ()
{
if (OptAttributes != null)
- OptAttributes.Emit (ec, this);
+ OptAttributes.Emit ();
- if (!ResolveValue ())
- return false;
+ if (!ResolveValue ()) {
+ // Suppress cyclic errors
+ value = new EnumConstant(New.Constantify(parent_enum.UnderlyingType), parent_enum.TypeBuilder);
+ 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:"; }
}
#region IConstant Members
- public Constant Value {
- get {
- return value;
- }
+ public Constant CreateConstantReference (Location loc)
+ {
+ if (value == null)
+ return null;
+
+ return new EnumConstant (Constant.CreateConstant (value.Child.Type, value.Child.GetValue(), loc),
+ value.Type);
}
#endregion
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
//
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 {
catch (ArgumentException) {
Report.SymbolRelatedToPreviousError (em);
MemberCore col = (MemberCore)dict [em.Name];
+#if GMCS_SOURCE
+ Report.Warning (3005, 1, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
+#else
Report.Error (3005, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
+#endif
}
}
}
- protected override bool VerifyClsCompliance (DeclSpace ds)
+ protected override bool VerifyClsCompliance ()
{
- if (!base.VerifyClsCompliance (ds))
+ if (!base.VerifyClsCompliance ())
return false;
VerifyClsName ();