2001-11-13 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / mcs / decl.cs
1 //
2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
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 // TODO: Move the method verification stuff from the class.cs and interface.cs here
11 //
12
13 using System;
14 using System.Collections;
15 using System.Reflection.Emit;
16
17 namespace CIR {
18
19         // <summary>
20         //   Base class for structs, classes, enums and interfaces.  They all create
21         //   new declaration spaces.  This provides the common foundation
22         //   for managing those name spaces
23         // </summary>
24         
25         public abstract class DeclSpace {
26                 // <summary>
27                 //   this points to the actual definition that is being
28                 //   created with System.Reflection.Emit
29                 // </summary>
30                 TypeBuilder definition;
31
32                 // <summary>
33                 //   Location where this declaration happens
34                 // </summary>
35                 public readonly Location Location;
36                 
37                 string name, basename;
38                 
39                 // <summary>
40                 //   The result value from adding an declaration into
41                 //   a struct or a class
42                 // </summary>
43                 public enum AdditionResult {
44                         //
45                         // The declaration has been successfully
46                         // added to the declation space.
47                         //
48                         Success,
49
50                         //
51                         // The symbol has already been defined.
52                         //
53                         NameExists,
54
55                         //
56                         // Returned if the declation being added to the
57                         // name space clashes with its container name.
58                         //
59                         // The only exceptions for this are constructors
60                         // and static constructors
61                         //
62                         EnclosingClash,
63
64                         //
65                         // Returned if a constructor was created (because syntactically
66                         // it looked like a constructor) but was not (because the name
67                         // of the method is not the same as the container class
68                         //
69                         NotAConstructor
70                 }
71
72                 public string Name {
73                         get {
74                                 return name;
75                         }
76                 }
77
78                 public string Basename {
79                         get {
80                                 return basename;
81                         }
82                 }
83                 
84                 // <summary>
85                 //   defined_names is used for toplevel objects
86                 // </summary>
87                 protected Hashtable defined_names;
88
89                 public DeclSpace (string name, Location l)
90                 {
91                         this.name = name;
92                         this.basename = name.Substring (1 + name.LastIndexOf ('.'));
93                         defined_names = new Hashtable ();
94                         Location = l;
95                 }
96
97                 // <summary>
98                 //   Returns a status code based purely on the name
99                 //   of the member being added
100                 // </summary>
101                 protected AdditionResult IsValid (string name)
102                 {
103                         if (name == basename)
104                                 return AdditionResult.EnclosingClash;
105
106                         if (defined_names.Contains (name))
107                                 return AdditionResult.NameExists;
108
109                         return AdditionResult.Success;
110                 }
111
112                 // <summary>
113                 //   Introduce @name into this declaration space and
114                 //   associates it with the object @o.  Note that for
115                 //   methods this will just point to the first method. o
116                 // </summary>
117                 protected void DefineName (string name, object o)
118                 {
119                         defined_names.Add (name, o);
120                 }
121
122                 bool in_transit = false;
123                 
124                 // <summary>
125                 //   This function is used to catch recursive definitions
126                 //   in declarations.
127                 // </summary>
128                 public bool InTransit {
129                         get {
130                                 return in_transit;
131                         }
132
133                         set {
134                                 in_transit = value;
135                         }
136                 }
137
138                 public TypeBuilder TypeBuilder {
139                         get {
140                                 return definition;
141                         }
142
143                         set {
144                                 definition = value;
145                         }
146                 }
147
148         }
149 }
150
151
152
153
154
155