2001-06-13 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / mcs / enum.cs
1 //
2 // enum.cs: Enum handling.
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //
6 // Licensed under the terms of the GNU GPL
7 //
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
9 //
10
11 using System;
12 using System.Collections;
13
14 namespace CIR {
15
16         public class Enum : DeclSpace {
17                 ArrayList ordered_enums;
18                 TypeRef typeref;
19                 string name;
20                 int mod_flags;
21
22                 public const int AllowedModifiers =
23                         Modifiers.NEW |
24                         Modifiers.PUBLIC |
25                         Modifiers.PROTECTED |
26                         Modifiers.INTERNAL |
27                         Modifiers.PRIVATE;
28
29                 public Enum (TypeRef typeref, int mod_flags, string name) : base (name)
30                 {
31                         this.typeref = typeref;
32                         this.name = name;
33                         this.mod_flags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PUBLIC);
34
35                         ordered_enums = new ArrayList ();
36                 }
37
38                 // <summary>
39                 //   Adds @name to the enumeration space, with @expr
40                 //   being its definition.  
41                 // </summary>
42                 public AdditionResult AddEnum (string name, Expression expr)
43                 {
44                         if (defined_names.Contains (name))
45                                 return AdditionResult.NameExists;
46
47                         DefineName (name, expr);
48
49                         ordered_enums.Add (name);
50                         return AdditionResult.Success;
51                 }
52
53                 public Type Type {
54                         get {
55                                 return typeref.Type;
56                         }
57                 }
58
59                 public ArrayList ValueNames {
60                         get {
61                                 return ordered_enums;
62                         }
63                 }
64
65                 public int ModFlags {
66                         get {
67                                 return mod_flags;
68                         }
69                 }
70                 
71                 // indexer
72                 public Expression this [string name] {
73                         get {
74                                 return (Expression) defined_names [name];
75                         }
76                 }
77
78                 public override Type Define (Tree tree)
79                 {
80                         return null;
81                 }
82         }
83 }