// Ravi Pratap (ravi@ximian.com)
// Marek Safar (marek.safar@seznam.cz)
//
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
//
-// (C) 2001 Ximian, Inc (http://www.ximian.com)
+// Copyright 2001 Ximian, Inc (http://www.ximian.com)
+// Copyright 2003-2003 Novell, Inc (http://www.novell.com)
//
using System;
{
return DoResolveAsTypeStep (ec);
}
-
- public override string Name {
- get { return Enum.Name; }
- }
-
- public override string FullName {
- get { return Enum.Name; }
- }
}
static bool IsValidEnumType (Type t)
}
public object Value {
- get { return value.GetValue (); }
+ get { return ResolveValue () ? value.GetValue () : null; }
}
public override bool Define ()
{
+ if (!ResolveMemberType ())
+ return false;
+
const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType, attr);
Parent.MemberCache.AddMember (FieldBuilder, this);
if (c is EnumConstant)
c = ((EnumConstant)c).Child;
- c = c.ImplicitConversionRequired (ParentEnum.UnderlyingType, Location);
+ c = c.ImplicitConversionRequired (ec, ParentEnum.UnderlyingType, Location);
if (c == null)
return null;
return new EnumConstant (c, MemberType);
}
- if (prev_member == null) {
+ if (prev_member == null)
return new EnumConstant (
New.Constantify (ParentEnum.UnderlyingType), MemberType);
- }
- if (!prev_member.ResolveValue ()) {
- prev_member.value = new EnumConstant (
- New.Constantify (ParentEnum.UnderlyingType), MemberType);
+ if (!prev_member.ResolveValue ())
return null;
- }
try {
return (EnumConstant) prev_member.value.Increment ();
/// </summary>
public class Enum : TypeContainer
{
- Expression base_type;
+ public static readonly string UnderlyingValueField = "value__";
- public Type UnderlyingType;
+ TypeExpr base_type;
- public const int AllowedModifiers =
+ const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (NamespaceEntry ns, DeclSpace parent, Expression type,
+ public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpr type,
int mod_flags, MemberName name, Attributes attrs)
: base (ns, parent, name, attrs, Kind.Enum)
{
public void AddEnumMember (EnumMember em)
{
- if (em.Name == "value__") {
- Report.Error (76, em.Location, "An item in an enumeration cannot " +
- "have an identifier `value__'");
+ if (em.Name == UnderlyingValueField) {
+ Report.Error (76, em.Location, "An item in an enumeration cannot have an identifier `{0}'",
+ UnderlyingValueField);
return;
}
if (!base.DefineNestedTypes ())
return false;
- if (!(base_type is TypeLookupExpression)) {
- Error_1008 (Location);
- return false;
- }
-
- TypeExpr ute = base_type.ResolveAsTypeTerminal (this, false);
- UnderlyingType = ute.Type;
-
- if (UnderlyingType != TypeManager.int32_type &&
- UnderlyingType != TypeManager.uint32_type &&
- UnderlyingType != TypeManager.int64_type &&
- UnderlyingType != TypeManager.uint64_type &&
- UnderlyingType != TypeManager.short_type &&
- UnderlyingType != TypeManager.ushort_type &&
- UnderlyingType != TypeManager.byte_type &&
- UnderlyingType != TypeManager.sbyte_type) {
- Error_1008 (Location);
- return false;
- }
-
//
// Call MapToInternalType for corlib
//
- TypeBuilder.DefineField ("value__", UnderlyingType,
+ TypeBuilder.DefineField (UnderlyingValueField, UnderlyingType,
FieldAttributes.Public | FieldAttributes.SpecialName
| FieldAttributes.RTSpecialName);
return true;
}
- protected override bool DoDefineMembers ()
+ public override bool Define ()
{
member_cache = new MemberCache (TypeManager.enum_type, this);
DefineContainerMembers (constants);
return true;
}
- //
- // Used for error reporting only
- //
- public EnumMember GetDefinition (object value)
+ public override bool IsUnmanagedType ()
{
- foreach (EnumMember e in defined_names.Values) {
- if (e.Value.Equals (value))
- return e;
- }
+ return true;
+ }
- throw new ArgumentOutOfRangeException (value.ToString ());
+ public Type UnderlyingType {
+ get {
+ return base_type.Type;
+ }
}
protected override bool VerifyClsCompliance ()
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));
+ Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
}
return true;