ArrayList ordered_enums;
public Expression BaseType;
- public Attributes OptAttributes;
public Type UnderlyingType;
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (TypeContainer parent, Expression type, int mod_flags, string name, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Enum (NamespaceEntry ns, TypeContainer parent, Expression type, int mod_flags,
+ string name, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
{
this.BaseType = type;
ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE, l);
- OptAttributes = attrs;
ordered_enums = new ArrayList ();
member_to_location = new Hashtable ();
return AdditionResult.Success;
}
+ public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+ {
+ ((TypeBuilder) builder).SetCustomAttribute (cb);
+ }
+
//
// This is used by corlib compilation: we map from our
// type to a type that is consumable by the DefineField
UnderlyingType != TypeManager.short_type &&
UnderlyingType != TypeManager.ushort_type &&
UnderlyingType != TypeManager.byte_type &&
- UnderlyingType != TypeManager.char_type &&
UnderlyingType != TypeManager.sbyte_type) {
Report.Error (1008, Location,
- "Type byte, sbyte, short, char, ushort, int, uint, " +
+ "Type byte, sbyte, short, ushort, int, uint, " +
"long, or ulong expected (got: " +
TypeManager.CSharpName (UnderlyingType) + ")");
return null;
if (TypeManager.NamespaceClash (Name, Location))
return null;
- ModuleBuilder builder = CodeGen.ModuleBuilder;
+ ModuleBuilder builder = CodeGen.Module.Builder;
TypeBuilder = builder.DefineType (Name, attr, TypeManager.enum_type);
} else {
default_value = GetNextDefaultValue (default_value);
}
+ return true;
+ }
- Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
+ public override void Emit (TypeContainer tc)
+ {
+ if (OptAttributes != null) {
+ EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
+ Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
+ }
+
+ base.Emit (tc);
+ }
+
+ protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+ {
+ if (!base.IsIdentifierClsCompliant (ds))
+ return false;
+
+ for (int i = 1; i < ordered_enums.Count; ++i) {
+ string checked_name = ordered_enums [i] as string;
+ for (int ii = 0; ii < ordered_enums.Count; ++ii) {
+ if (ii == i)
+ continue;
+
+ string enumerator_name = ordered_enums [ii] as string;
+ if (String.Compare (checked_name, enumerator_name, true) == 0) {
+ Report.SymbolRelatedToPreviousError ((Location)member_to_location [enumerator_name], enumerator_name);
+ Report.Error_T (3005, (Location)member_to_location [checked_name], GetEnumeratorName (checked_name));
+ break;
+ }
+ }
+ }
+ return true;
+ }
+
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds))
+ return false;
+
+ if (!AttributeTester.IsClsCompliant (UnderlyingType)) {
+ Report.Error_T (3009, Location, GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
+ }
return true;
}
+ /// <summary>
+ /// Returns full enum name.
+ /// </summary>
+ string GetEnumeratorName (string valueName)
+ {
+ return String.Concat (Name, ".", valueName);
+ }
+
//
// IMemberFinder
//