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