2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
4 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Licensed under the terms of the GNU GPL
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10 // TODO: Move the method verification stuff from the class.cs and interface.cs here
14 using System.Collections;
15 using System.Reflection.Emit;
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
25 public abstract class DeclSpace {
27 // this points to the actual definition that is being
28 // created with System.Reflection.Emit
30 TypeBuilder definition;
33 // Location where this declaration happens
35 public readonly Location Location;
37 string name, basename;
40 // The result value from adding an declaration into
41 // a struct or a class
43 public enum AdditionResult {
45 // The declaration has been successfully
46 // added to the declation space.
51 // The symbol has already been defined.
56 // Returned if the declation being added to the
57 // name space clashes with its container name.
59 // The only exceptions for this are constructors
60 // and static constructors
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
78 public string Basename {
85 // defined_names is used for toplevel objects
87 protected Hashtable defined_names;
89 public DeclSpace (string name, Location l)
92 this.basename = name.Substring (1 + name.LastIndexOf ('.'));
93 defined_names = new Hashtable ();
98 // Returns a status code based purely on the name
99 // of the member being added
101 protected AdditionResult IsValid (string name)
103 if (name == basename)
104 return AdditionResult.EnclosingClash;
106 if (defined_names.Contains (name))
107 return AdditionResult.NameExists;
109 return AdditionResult.Success;
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
117 protected void DefineName (string name, object o)
119 defined_names.Add (name, o);
122 bool in_transit = false;
125 // This function is used to catch recursive definitions
128 public bool InTransit {
138 public TypeBuilder TypeBuilder {