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