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