2 // namespace.cs: Tracks namespaces
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2001 Ximian, Inc.
10 using System.Collections;
13 namespace Mono.CSharp {
16 /// Keeps track of the namespaces defined in the C# code.
18 public class Namespace {
21 ArrayList using_clauses;
23 public bool DeclarationFound = false;
26 /// Constructor Takes the current namespace and the
27 /// name. This is bootstrapped with parent == null
30 public Namespace (Namespace parent, string name)
37 /// The qualified name of the current namespace
41 string pname = parent != null ? parent.Name : "";
46 return parent.Name + "." + name;
51 /// The parent of this namespace, used by the parser to "Pop"
52 /// the current namespace declaration
54 public Namespace Parent {
61 /// Records a new namespace for resolving name references
63 public void Using (string ns, Location loc)
65 if (DeclarationFound){
66 Report.Error (1529, loc, "A using clause must precede all other namespace elements");
70 if (using_clauses == null)
71 using_clauses = new ArrayList ();
73 using_clauses.Add (ns);
76 public ArrayList UsingTable {
82 public void UsingAlias (string alias, string namespace_or_type, Location loc)
85 aliases = new Hashtable ();
87 if (aliases.Contains (alias)){
88 Report.Error (1537, loc, "The using alias `" + alias +
89 "' appeared previously in this namespace");
93 aliases [alias] = namespace_or_type;
96 public string LookupAlias (string alias)
100 // System.Console.WriteLine ("Lookup " + alias + " in " + name);
103 value = (string) (aliases [alias]);
104 if (value == null && Parent != null)
105 value = Parent.LookupAlias (alias);
111 /// Used to validate that all the using clauses are correct
112 /// after we are finished parsing all the files
114 public void VerifyUsing ()
116 foreach (DictionaryEntry de in using_clauses){
117 if (de.Value == null){
118 string name = (string) de.Key;
120 Report.Error (234, "The type or namespace `" +
121 name + "' does not exist in the " +
122 "class or namespace `" + name + "'");