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