**** Merged from MCS ****
[mono.git] / mcs / gmcs / enum.cs
1 //
2 // enum.cs: Enum handling.
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //         Ravi Pratap     (ravi@ximian.com)
6 //
7 // Licensed under the terms of the GNU GPL
8 //
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10 //
11
12 using System;
13 using System.Collections;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Globalization;
17
18 namespace Mono.CSharp {
19
20         class EnumMember: MemberCore {
21                 static string[] attribute_targets = new string [] { "field" };
22
23                 Enum parent_enum;
24                 public FieldBuilder builder;
25                 internal readonly Expression Type;
26
27                 public EnumMember (Enum parent_enum, Expression expr, string name,
28                                    Location loc, Attributes attrs):
29                         base (null, new MemberName (name), attrs, loc)
30                 {
31                         this.parent_enum = parent_enum;
32                         this.ModFlags = parent_enum.ModFlags;
33                         this.Type = expr;
34                 }
35
36                 public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
37                 {
38                         if (a.Type == TypeManager.marshal_as_attr_type) {
39                                 UnmanagedMarshal marshal = a.GetMarshal (this);
40                                 if (marshal != null) {
41                                         builder.SetMarshal (marshal);
42                                 }
43                                         return;
44                                 }
45
46                         if (a.Type.IsSubclassOf (TypeManager.security_attr_type)) {
47                                 a.Error_InvalidSecurityParent ();
48                                 return;
49                         }
50
51                         builder.SetCustomAttribute (cb);
52                 }
53
54                 public override AttributeTargets AttributeTargets {
55                         get {
56                                 return AttributeTargets.Field;
57                         }
58                 }
59
60                 public void DefineMember (TypeBuilder tb)
61                 {
62                         FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static
63                                 | FieldAttributes.Literal;
64                         
65                         builder = tb.DefineField (Name, tb, attr);
66                 }
67
68                 public override bool Define ()
69                 {
70                         throw new NotImplementedException ();
71                 }
72
73                 public void Emit (EmitContext ec)
74                 {
75                         if (OptAttributes != null)
76                                 OptAttributes.Emit (ec, this); 
77
78                         Emit ();
79                 }
80
81                 public override string GetSignatureForError()
82                 {
83                         return String.Concat (parent_enum.GetSignatureForError (), '.', base.GetSignatureForError ());
84                 }
85
86                 public override string[] ValidAttributeTargets {
87                         get {
88                                 return attribute_targets;
89                         }
90                 }
91
92                 protected override bool VerifyClsCompliance(DeclSpace ds)
93                 {
94                         // Because parent is TypeContainer and we have only DeclSpace parent.
95                         // Parameter replacing is required
96                         return base.VerifyClsCompliance (parent_enum);
97                 }
98
99                 // There is no base type
100                 protected override void VerifyObsoleteAttribute()
101                 {
102                 }
103         }
104
105         /// <summary>
106         ///   Enumeration container
107         /// </summary>
108         public class Enum : DeclSpace {
109                 ArrayList ordered_enums;
110                 
111                 public Expression BaseType;
112                 
113                 public Type UnderlyingType;
114
115                 Hashtable member_to_location;
116
117                 //
118                 // This is for members that have been defined
119                 //
120                 Hashtable member_to_value;
121
122                 //
123                 // This is used to mark members we're currently defining
124                 //
125                 Hashtable in_transit;
126                 
127                 ArrayList field_builders;
128                 
129                 public const int AllowedModifiers =
130                         Modifiers.NEW |
131                         Modifiers.PUBLIC |
132                         Modifiers.PROTECTED |
133                         Modifiers.INTERNAL |
134                         Modifiers.PRIVATE;
135
136                 public Enum (NamespaceEntry ns, TypeContainer parent, Expression type,
137                              int mod_flags, MemberName name, Attributes attrs, Location l)
138                         : base (ns, parent, name, attrs, l)
139                 {
140                         this.BaseType = type;
141                         ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
142                                                     IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE, l);
143
144                         ordered_enums = new ArrayList ();
145                         member_to_location = new Hashtable ();
146                         member_to_value = new Hashtable ();
147                         in_transit = new Hashtable ();
148                         field_builders = new ArrayList ();
149                 }
150
151                 /// <summary>
152                 ///   Adds @name to the enumeration space, with @expr
153                 ///   being its definition.  
154                 /// </summary>
155                 public void AddEnumMember (string name, Expression expr, Location loc, Attributes opt_attrs)
156                 {
157                         if (name == "value__") {
158                                 Report.Error (76, loc, "An item in an enumeration can't have an identifier `value__'");
159                                 return;
160                         }
161
162                         EnumMember em = new EnumMember (this, expr, name, loc, opt_attrs);
163                         if (!AddToContainer (em, false, name, ""))
164                                 return;
165
166
167                         // TODO: can be almost deleted
168                         ordered_enums.Add (name);
169                         member_to_location.Add (name, loc);
170                 }
171
172                 //
173                 // This is used by corlib compilation: we map from our
174                 // type to a type that is consumable by the DefineField
175                 //
176                 Type MapToInternalType (Type t)
177                 {
178                         if (t == TypeManager.int32_type)
179                                 return typeof (int);
180                         if (t == TypeManager.int64_type)
181                                 return typeof (long);
182                         if (t == TypeManager.uint32_type)
183                                 return typeof (uint);
184                         if (t == TypeManager.uint64_type)
185                                 return typeof (ulong);
186                         if (t == TypeManager.float_type)
187                                 return typeof (float);
188                         if (t == TypeManager.double_type)
189                                 return typeof (double);
190                         if (t == TypeManager.byte_type)
191                                 return typeof (byte);
192                         if (t == TypeManager.sbyte_type)
193                                 return typeof (sbyte);
194                         if (t == TypeManager.char_type)
195                                 return typeof (char);
196                         if (t == TypeManager.short_type)
197                                 return typeof (short);
198                         if (t == TypeManager.ushort_type)
199                                 return typeof (ushort);
200
201                         throw new Exception ();
202                 }
203                 
204                 public override TypeBuilder DefineType ()
205                 {
206                         if (TypeBuilder != null)
207                                 return TypeBuilder;
208
209                         TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel);
210
211                         attr |= TypeAttributes.Class | TypeAttributes.Sealed;
212
213                         if (!(BaseType is TypeLookupExpression)) {
214                                 Report.Error (1008, Location,
215                                               "Type byte, sbyte, short, ushort, int, uint, " +
216                                               "long, or ulong expected (got: `{0}')", BaseType);
217                                 return null;
218                         }
219
220                         UnderlyingType = ResolveType (BaseType, false, Location);
221
222                         if (UnderlyingType != TypeManager.int32_type &&
223                             UnderlyingType != TypeManager.uint32_type &&
224                             UnderlyingType != TypeManager.int64_type &&
225                             UnderlyingType != TypeManager.uint64_type &&
226                             UnderlyingType != TypeManager.short_type &&
227                             UnderlyingType != TypeManager.ushort_type &&
228                             UnderlyingType != TypeManager.byte_type  &&
229                             UnderlyingType != TypeManager.sbyte_type) {
230                                 Report.Error (1008, Location,
231                                               "Type byte, sbyte, short, ushort, int, uint, " +
232                                               "long, or ulong expected (got: " +
233                                               TypeManager.CSharpName (UnderlyingType) + ")");
234                                 return null;
235                         }
236
237                         if (IsTopLevel) {
238                                 if (TypeManager.NamespaceClash (Name, Location))
239                                         return null;
240                                 
241                                 ModuleBuilder builder = CodeGen.Module.Builder;
242
243                                 TypeBuilder = builder.DefineType (Name, attr, TypeManager.enum_type);
244                         } else {
245                                 TypeBuilder builder = Parent.TypeBuilder;
246
247                                 TypeBuilder = builder.DefineNestedType (
248                                         Basename, attr, TypeManager.enum_type);
249                         }
250
251                         //
252                         // Call MapToInternalType for corlib
253                         //
254                         TypeBuilder.DefineField ("value__", UnderlyingType,
255                                                  FieldAttributes.Public | FieldAttributes.SpecialName
256                                                  | FieldAttributes.RTSpecialName);
257
258                         TypeManager.AddEnumType (Name, TypeBuilder, this);
259
260                         return TypeBuilder;
261                 }
262
263                 bool IsValidEnumConstant (Expression e)
264                 {
265                         if (!(e is Constant))
266                                 return false;
267
268                         if (e is IntConstant || e is UIntConstant || e is LongConstant ||
269                             e is ByteConstant || e is SByteConstant || e is ShortConstant ||
270                             e is UShortConstant || e is ULongConstant || e is EnumConstant ||
271                             e is CharConstant)
272                                 return true;
273                         else
274                                 return false;
275                 }
276
277                 object GetNextDefaultValue (object default_value)
278                 {
279                         if (UnderlyingType == TypeManager.int32_type) {
280                                 int i = (int) default_value;
281                                 
282                                 if (i < System.Int32.MaxValue)
283                                         return ++i;
284                                 else
285                                         return null;
286                         } else if (UnderlyingType == TypeManager.uint32_type) {
287                                 uint i = (uint) default_value;
288
289                                 if (i < System.UInt32.MaxValue)
290                                         return ++i;
291                                 else
292                                         return null;
293                         } else if (UnderlyingType == TypeManager.int64_type) {
294                                 long i = (long) default_value;
295
296                                 if (i < System.Int64.MaxValue)
297                                         return ++i;
298                                 else
299                                         return null;
300                         } else if (UnderlyingType == TypeManager.uint64_type) {
301                                 ulong i = (ulong) default_value;
302
303                                 if (i < System.UInt64.MaxValue)
304                                         return ++i;
305                                 else
306                                         return null;
307                         } else if (UnderlyingType == TypeManager.short_type) {
308                                 short i = (short) default_value;
309
310                                 if (i < System.Int16.MaxValue)
311                                         return ++i;
312                                 else
313                                         return null;
314                         } else if (UnderlyingType == TypeManager.ushort_type) {
315                                 ushort i = (ushort) default_value;
316
317                                 if (i < System.UInt16.MaxValue)
318                                         return ++i;
319                                 else
320                                         return null;
321                         } else if (UnderlyingType == TypeManager.byte_type) {
322                                 byte i = (byte) default_value;
323
324                                 if (i < System.Byte.MaxValue)
325                                         return ++i;
326                                 else
327                                         return null;
328                         } else if (UnderlyingType == TypeManager.sbyte_type) {
329                                 sbyte i = (sbyte) default_value;
330
331                                 if (i < System.SByte.MaxValue)
332                                         return ++i;
333                                 else
334                                         return null;
335                         }
336
337                         return null;
338                 }
339
340                 void Error_ConstantValueCannotBeConverted (object val, Location loc)
341                 {
342                         if (val is Constant)
343                                 Report.Error (31, loc, "Constant value '" + ((Constant) val).AsString () +
344                                               "' cannot be converted" +
345                                               " to a " + TypeManager.CSharpName (UnderlyingType));
346                         else 
347                                 Report.Error (31, loc, "Constant value '" + val +
348                                               "' cannot be converted" +
349                                               " to a " + TypeManager.CSharpName (UnderlyingType));
350                         return;
351                 }
352
353                 /// <summary>
354                 ///  Determines if a standard implicit conversion exists from
355                 ///  expr_type to target_type
356                 /// </summary>
357                 public static bool ImplicitConversionExists (Type expr_type, Type target_type)
358                 {
359                         expr_type = TypeManager.TypeToCoreType (expr_type);
360
361                         if (expr_type == TypeManager.void_type)
362                                 return false;
363                         
364                         if (expr_type == target_type)
365                                 return true;
366
367                         // First numeric conversions 
368
369                         if (expr_type == TypeManager.sbyte_type){
370                                 //
371                                 // From sbyte to short, int, long, float, double.
372                                 //
373                                 if ((target_type == TypeManager.int32_type) || 
374                                     (target_type == TypeManager.int64_type) ||
375                                     (target_type == TypeManager.double_type) ||
376                                     (target_type == TypeManager.float_type)  ||
377                                     (target_type == TypeManager.short_type) ||
378                                     (target_type == TypeManager.decimal_type))
379                                         return true;
380                                 
381                         } else if (expr_type == TypeManager.byte_type){
382                                 //
383                                 // From byte to short, ushort, int, uint, long, ulong, float, double
384                                 // 
385                                 if ((target_type == TypeManager.short_type) ||
386                                     (target_type == TypeManager.ushort_type) ||
387                                     (target_type == TypeManager.int32_type) ||
388                                     (target_type == TypeManager.uint32_type) ||
389                                     (target_type == TypeManager.uint64_type) ||
390                                     (target_type == TypeManager.int64_type) ||
391                                     (target_type == TypeManager.float_type) ||
392                                     (target_type == TypeManager.double_type) ||
393                                     (target_type == TypeManager.decimal_type))
394                                         return true;
395         
396                         } else if (expr_type == TypeManager.short_type){
397                                 //
398                                 // From short to int, long, float, double
399                                 // 
400                                 if ((target_type == TypeManager.int32_type) ||
401                                     (target_type == TypeManager.int64_type) ||
402                                     (target_type == TypeManager.double_type) ||
403                                     (target_type == TypeManager.float_type) ||
404                                     (target_type == TypeManager.decimal_type))
405                                         return true;
406                                         
407                         } else if (expr_type == TypeManager.ushort_type){
408                                 //
409                                 // From ushort to int, uint, long, ulong, float, double
410                                 //
411                                 if ((target_type == TypeManager.uint32_type) ||
412                                     (target_type == TypeManager.uint64_type) ||
413                                     (target_type == TypeManager.int32_type) ||
414                                     (target_type == TypeManager.int64_type) ||
415                                     (target_type == TypeManager.double_type) ||
416                                     (target_type == TypeManager.float_type) ||
417                                     (target_type == TypeManager.decimal_type))
418                                         return true;
419                                     
420                         } else if (expr_type == TypeManager.int32_type){
421                                 //
422                                 // From int to long, float, double
423                                 //
424                                 if ((target_type == TypeManager.int64_type) ||
425                                     (target_type == TypeManager.double_type) ||
426                                     (target_type == TypeManager.float_type) ||
427                                     (target_type == TypeManager.decimal_type))
428                                         return true;
429                                         
430                         } else if (expr_type == TypeManager.uint32_type){
431                                 //
432                                 // From uint to long, ulong, float, double
433                                 //
434                                 if ((target_type == TypeManager.int64_type) ||
435                                     (target_type == TypeManager.uint64_type) ||
436                                     (target_type == TypeManager.double_type) ||
437                                     (target_type == TypeManager.float_type) ||
438                                     (target_type == TypeManager.decimal_type))
439                                         return true;
440                                         
441                         } else if ((expr_type == TypeManager.uint64_type) ||
442                                    (expr_type == TypeManager.int64_type)) {
443                                 //
444                                 // From long/ulong to float, double
445                                 //
446                                 if ((target_type == TypeManager.double_type) ||
447                                     (target_type == TypeManager.float_type) ||
448                                     (target_type == TypeManager.decimal_type))
449                                         return true;
450                                     
451                         } else if (expr_type == TypeManager.char_type){
452                                 //
453                                 // From char to ushort, int, uint, long, ulong, float, double
454                                 // 
455                                 if ((target_type == TypeManager.ushort_type) ||
456                                     (target_type == TypeManager.int32_type) ||
457                                     (target_type == TypeManager.uint32_type) ||
458                                     (target_type == TypeManager.uint64_type) ||
459                                     (target_type == TypeManager.int64_type) ||
460                                     (target_type == TypeManager.float_type) ||
461                                     (target_type == TypeManager.double_type) ||
462                                     (target_type == TypeManager.decimal_type))
463                                         return true;
464
465                         } else if (expr_type == TypeManager.float_type){
466                                 //
467                                 // float to double
468                                 //
469                                 if (target_type == TypeManager.double_type)
470                                         return true;
471                         }       
472                         
473                         return false;
474                 }
475
476                 //
477                 // Horrible, horrible.  But there is no other way we can pass the EmitContext
478                 // to the recursive definition triggered by the evaluation of a forward
479                 // expression
480                 //
481                 static EmitContext current_ec = null;
482                 
483                 /// <summary>
484                 ///  This is used to lookup the value of an enum member. If the member is undefined,
485                 ///  it attempts to define it and return its value
486                 /// </summary>
487                 public object LookupEnumValue (EmitContext ec, string name, Location loc)
488                 {
489                         
490                         object default_value = null;
491                         Constant c = null;
492
493                         default_value = member_to_value [name];
494
495                         if (default_value != null)
496                                 return default_value;
497
498                         //
499                         // This may happen if we're calling a method in System.Enum, for instance
500                         // Enum.IsDefined().
501                         //
502                         if (!defined_names.Contains (name))
503                                 return null;
504
505                         if (in_transit.Contains (name)) {
506                                 Report.Error (110, loc, "The evaluation of the constant value for `" +
507                                               Name + "." + name + "' involves a circular definition.");
508                                 return null;
509                         }
510
511                         //
512                         // So if the above doesn't happen, we have a member that is undefined
513                         // We now proceed to define it 
514                         //
515                         Expression val = this [name];
516
517                         if (val == null) {
518                                 
519                                 int idx = ordered_enums.IndexOf (name);
520
521                                 if (idx == 0)
522                                         default_value = 0;
523                                 else {
524                                         for (int i = 0; i < idx; ++i) {
525                                                 string n = (string) ordered_enums [i];
526                                                 Location m_loc = (Mono.CSharp.Location)
527                                                         member_to_location [n];
528                                                 in_transit.Add (name, true);
529
530                                                 EmitContext old_ec = current_ec;
531                                                 current_ec = ec;
532                         
533                                                 default_value = LookupEnumValue (ec, n, m_loc);
534
535                                                 current_ec = old_ec;
536                                                 
537                                                 in_transit.Remove (name);
538                                                 if (default_value == null)
539                                                         return null;
540                                         }
541                                         
542                                         default_value = GetNextDefaultValue (default_value);
543                                 }
544                                 
545                         } else {
546                                 bool old = ec.InEnumContext;
547                                 ec.InEnumContext = true;
548                                 in_transit.Add (name, true);
549
550                                 EmitContext old_ec = current_ec;
551                                 current_ec = ec;
552                                 val = val.Resolve (ec);
553                                 current_ec = old_ec;
554                                 
555                                 in_transit.Remove (name);
556                                 ec.InEnumContext = old;
557
558                                 if (val == null)
559                                         return null;
560
561                                 if (!IsValidEnumConstant (val)) {
562                                         Report.Error (
563                                                 1008, loc,
564                                                 "Type byte, sbyte, short, ushort, int, uint, long, or " +
565                                                 "ulong expected (have: " + val + ")");
566                                         return null;
567                                 }
568
569                                 c = (Constant) val;
570                                 default_value = c.GetValue ();
571
572                                 if (default_value == null) {
573                                         Error_ConstantValueCannotBeConverted (c, loc);
574                                         return null;
575                                 }
576
577                                 if (val is EnumConstant){
578                                         Type etype = TypeManager.EnumToUnderlying (c.Type);
579                                         
580                                         if (!ImplicitConversionExists (etype, UnderlyingType)){
581                                                 Convert.Error_CannotImplicitConversion (
582                                                         loc, c.Type, UnderlyingType);
583                                                 return null;
584                                         }
585                                 }
586                         }
587
588                         EnumMember em = (EnumMember) defined_names [name];
589                         em.DefineMember (TypeBuilder);
590
591                         bool fail;
592                         default_value = TypeManager.ChangeType (default_value, UnderlyingType, out fail);
593                         if (fail){
594                                 Error_ConstantValueCannotBeConverted (c, loc);
595                                 return null;
596                         }
597
598                         em.builder.SetConstant (default_value);
599                         field_builders.Add (em.builder);
600                         member_to_value [name] = default_value;
601
602                         if (!TypeManager.RegisterFieldValue (em.builder, default_value))
603                                 return null;
604
605                         return default_value;
606                 }
607
608                 public override bool DefineMembers (TypeContainer parent)
609                 {
610                         return true;
611                 }
612                 
613                 public override bool Define ()
614                 {
615                         //
616                         // If there was an error during DefineEnum, return
617                         //
618                         if (TypeBuilder == null)
619                                 return false;
620
621                         ec = new EmitContext (this, this, Location, null, UnderlyingType, ModFlags, false);
622                         
623                         object default_value = 0;
624                         
625                 
626                         foreach (string name in ordered_enums) {
627                                 //
628                                 // Have we already been defined, thanks to some cross-referencing ?
629                                 // 
630                                 if (member_to_value.Contains (name))
631                                         continue;
632                                 
633                                 Location loc = (Mono.CSharp.Location) member_to_location [name];
634
635                                 if (this [name] != null) {
636                                         default_value = LookupEnumValue (ec, name, loc);
637
638                                         if (default_value == null)
639                                                 return true;
640                                 } else {
641                                         if (name == "value__"){
642                                                 Report.Error (76, loc, "The name `value__' is reserved for enumerations");
643                                                 return false;
644                                         }
645
646                                         EnumMember em = (EnumMember) defined_names [name];
647
648                                         em.DefineMember (TypeBuilder);
649                                         FieldBuilder fb = em.builder;
650                                         
651                                         if (default_value == null) {
652                                            Report.Error (543, loc, "Enumerator value for '" + name + "' is too large to " +
653                                                               "fit in its type");
654                                                 return false;
655                                         }
656
657                                         bool fail;
658                                         default_value = TypeManager.ChangeType (default_value, UnderlyingType, out fail);
659                                         if (fail){
660                                                 Error_ConstantValueCannotBeConverted (default_value, loc);
661                                                 return false;
662                                         }
663
664                                         fb.SetConstant (default_value);
665                                         field_builders.Add (fb);
666                                         member_to_value [name] = default_value;
667                                         
668                                         if (!TypeManager.RegisterFieldValue (fb, default_value))
669                                                 return false;
670                                 }
671
672                                 default_value = GetNextDefaultValue (default_value);
673                         }
674
675                         return true;
676                 }
677
678                 public override void Emit ()
679                 {
680                         if (OptAttributes != null) {
681                                 OptAttributes.Emit (ec, this);
682                         }
683
684                         foreach (EnumMember em in defined_names.Values) {
685                                 em.Emit (ec);
686                         }
687
688                         base.Emit ();
689                 }
690                 
691                 void VerifyClsName ()
692                 {
693                         Hashtable ht = new Hashtable ();
694                         foreach (string name in ordered_enums) {
695                                 string locase = name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
696                                 if (!ht.Contains (locase)) {
697                                         ht.Add (locase, defined_names [name]);
698                                         continue;
699                                 }
700  
701                                 MemberCore conflict = (MemberCore)ht [locase];
702                                 Report.SymbolRelatedToPreviousError (conflict);
703                                 conflict = GetDefinition (name);
704                                 Report.Error (3005, conflict.Location, "Identifier '{0}' differing only in case is not CLS-compliant", conflict.GetSignatureForError ());
705                         }
706                 }
707
708                 protected override bool VerifyClsCompliance (DeclSpace ds)
709                 {
710                         if (!base.VerifyClsCompliance (ds))
711                                 return false;
712
713                         VerifyClsName ();
714
715                         if (!AttributeTester.IsClsCompliant (UnderlyingType)) {
716                                 Report.Error (3009, Location, "'{0}': base type '{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
717                         }
718
719                         return true;
720                 }
721                 
722                 /// <summary>
723                 /// Returns full enum name.
724                 /// </summary>
725                 string GetEnumeratorName (string valueName)
726                 {
727                         return String.Concat (Name, ".", valueName);
728                 }
729
730                 //
731                 // IMemberFinder
732                 //
733                 public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
734                                                         MemberFilter filter, object criteria)
735                 {
736                         ArrayList members = new ArrayList ();
737
738                         if ((mt & MemberTypes.Field) != 0) {
739                                 if (criteria is string){
740                                         if (member_to_value [criteria] == null && current_ec != null){
741                                                 LookupEnumValue (current_ec, (string) criteria, Location.Null);
742                                         }
743                                 }
744                                 
745                                 foreach (FieldBuilder fb in field_builders)
746                                         if (filter (fb, criteria) == true)
747                                                 members.Add (fb);
748                         }
749
750                         return new MemberList (members);
751                 }
752
753                 public override MemberCache MemberCache {
754                         get {
755                                 return null;
756                         }
757                 }
758
759                 public ArrayList ValueNames {
760                         get {
761                                 return ordered_enums;
762                         }
763                 }
764
765                 // indexer
766                 public Expression this [string name] {
767                         get {
768                                 return ((EnumMember) defined_names [name]).Type;
769                         }
770                 }
771
772                 public override AttributeTargets AttributeTargets {
773                         get {
774                                 return AttributeTargets.Enum;
775                         }
776                 }
777
778                 protected override void VerifyObsoleteAttribute()
779                 {
780                         // UnderlyingType is never obsolete
781                 }
782         }
783 }