2 // namespace.cs: Tracks namespaces
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2001 Ximian, Inc.
10 using System.Collections;
12 namespace Mono.CSharp {
15 /// Keeps track of the namespaces defined in the C# code.
17 public class Namespace {
20 ArrayList using_clauses;
22 bool decl_found = false;
25 /// Constructor Takes the current namespace and the
26 /// name. This is bootstrapped with parent == null
29 public Namespace (Namespace parent, string name)
36 /// The qualified name of the current namespace
40 string pname = parent != null ? parent.Name : "";
45 return parent.Name + "." + name;
50 /// The parent of this namespace, used by the parser to "Pop"
51 /// the current namespace declaration
53 public Namespace Parent {
60 /// When a declaration is found in a namespace,
61 /// we call this function, to emit an error if the
62 /// program attempts to use a using clause afterwards
64 public void DeclarationFound ()
70 /// Records a new namespace for resolving name references
72 public void Using (string ns)
75 CSharpParser.error (1529, "A using clause must precede all other namespace elements");
79 if (using_clauses == null)
80 using_clauses = new ArrayList ();
82 using_clauses.Add (ns);
85 public ArrayList UsingTable {
91 public void UsingAlias (string alias, string namespace_or_type, Location loc)
94 aliases = new Hashtable ();
96 if (aliases.Contains (alias)){
97 Report.Error (1537, loc, "The using alias `" + alias +
98 "' appeared previously in this namespace");
102 aliases [alias] = namespace_or_type;
105 public string LookupAlias (string alias)
109 // System.Console.WriteLine ("Lookup " + alias + " in " + name);
112 value = (string) (aliases [alias]);
113 if (value == null && Parent != null)
114 value = Parent.LookupAlias (alias);
120 /// Used to validate that all the using clauses are correct
121 /// after we are finished parsing all the files
123 public void VerifyUsing ()
125 foreach (DictionaryEntry de in using_clauses){
126 if (de.Value == null){
127 string name = (string) de.Key;
129 CSharpParser.error (234, "The type or namespace `" +
130 name + "' does not exist in the " +
131 "class or namespace `" + name + "'");