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;
17 namespace Mono.CSharp {
20 /// Base class for structs, classes, enumerations and interfaces.
23 /// They all create new declaration spaces. This
24 /// provides the common foundation for managing those name
27 public abstract class DeclSpace {
29 /// this points to the actual definition that is being
30 /// created with System.Reflection.Emit
32 TypeBuilder definition;
35 /// Location where this declaration happens
37 public readonly Location Location;
39 string name, basename;
42 /// The result value from adding an declaration into
43 /// a struct or a class
45 public enum AdditionResult {
47 /// The declaration has been successfully
48 /// added to the declation space.
53 /// The symbol has already been defined.
58 /// Returned if the declation being added to the
59 /// name space clashes with its container name.
61 /// The only exceptions for this are constructors
62 /// and static constructors
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
80 public string Basename {
87 /// defined_names is used for toplevel objects
89 protected Hashtable defined_names;
91 public DeclSpace (string name, Location l)
94 this.basename = name.Substring (1 + name.LastIndexOf ('.'));
95 defined_names = new Hashtable ();
100 /// Returns a status code based purely on the name
101 /// of the member being added
103 protected AdditionResult IsValid (string name)
105 if (name == basename)
106 return AdditionResult.EnclosingClash;
108 if (defined_names.Contains (name))
109 return AdditionResult.NameExists;
111 return AdditionResult.Success;
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
119 protected void DefineName (string name, object o)
121 defined_names.Add (name, o);
124 bool in_transit = false;
127 /// This function is used to catch recursive definitions
130 public bool InTransit {
140 public TypeBuilder TypeBuilder {