svn path=/trunk/mcs/; revision=38482
[mono.git] / mcs / mbas / namespace.cs
index 31be01e48f41d3bcfc001d158ba39c984e3085a6..6cb6b3c5908d75a183494d30509063a82bd91dbc 100644 (file)
-//\r
-// namespace.cs: Tracks namespaces\r
-//\r
-// Author:\r
-//   Miguel de Icaza (miguel@ximian.com)\r
-//\r
-// (C) 2001 Ximian, Inc.\r
-//\r
-using System;\r
-using System.Collections;\r
-\r
-namespace Mono.CSharp {\r
-       using Mono.Languages;\r
-\r
-       /// <summary>\r
-       ///   Keeps track of the namespaces defined in the C# code.\r
-       /// </summary>\r
-       public class Namespace {\r
-               Namespace parent;\r
-               string name;\r
-               ArrayList using_clauses;\r
-               Hashtable aliases;\r
-               bool decl_found = false;\r
-               \r
-               /// <summary>\r
-               ///   Constructor Takes the current namespace and the\r
-               ///   name.  This is bootstrapped with parent == null\r
-               ///   and name = ""\r
-               /// </summary>\r
-               public Namespace (Namespace parent, string name)\r
-               {\r
-                       this.name = name;\r
-                       this.parent = parent;\r
-               }\r
-\r
-               /// <summary>\r
-               ///   The qualified name of the current namespace\r
-               /// </summary>\r
-               public string Name {\r
-                       get {\r
-                               string pname = parent != null ? parent.Name : "";\r
-                               \r
-                               if (pname == "")\r
-                                       return name;\r
-                               else\r
-                                       return parent.Name + "." + name;\r
-                       }\r
-               }\r
-\r
-               /// <summary>\r
-               ///   The parent of this namespace, used by the parser to "Pop"\r
-               ///   the current namespace declaration\r
-               /// </summary>\r
-               public Namespace Parent {\r
-                       get {\r
-                               return parent;\r
-                       }\r
-               }\r
-\r
-               /// <summary>\r
-               ///   When a declaration is found in a namespace,\r
-               ///   we call this function, to emit an error if the\r
-               ///   program attempts to use a using clause afterwards\r
-               /// </summary>\r
-               public void DeclarationFound ()\r
-               {\r
-                       decl_found = true;\r
-               }\r
-\r
-               /// <summary>\r
-               ///   Records a new namespace for resolving name references\r
-               /// </summary>\r
-               public void Using (string ns)\r
-               {\r
-                       if (decl_found){\r
-                               GenericParser.error (1529, "A using clause must precede all other namespace elements");\r
-                               return;\r
-                       }\r
-\r
-                       if (using_clauses == null)\r
-                               using_clauses = new ArrayList ();\r
-\r
-                       using_clauses.Add (ns);\r
-               }\r
-\r
-               public ArrayList UsingTable {\r
-                       get {\r
-                               return using_clauses;\r
-                       }\r
-               }\r
-\r
-               public void UsingAlias (string alias, string namespace_or_type, Location loc)\r
-               {\r
-                       if (aliases == null)\r
-                               aliases = new Hashtable ();\r
-                       \r
-                       if (aliases.Contains (alias)){\r
-                               Report.Error (1537, loc, "The using alias `" + alias +\r
-                                             "' appeared previously in this namespace");\r
-                               return;\r
-                       }\r
-                                       \r
-                       aliases [alias] = namespace_or_type;\r
-               }\r
-\r
-               public string LookupAlias (string alias)\r
-               {\r
-                       string value = null;\r
-\r
-                       // System.Console.WriteLine ("Lookup " + alias + " in " + name);\r
-\r
-                       if (aliases != null)\r
-                               value = (string) (aliases [alias]);\r
-                       if (value == null && Parent != null)\r
-                               value = Parent.LookupAlias (alias);\r
-\r
-                       return value;\r
-               }\r
-\r
-               /// <summary>\r
-               ///   Used to validate that all the using clauses are correct\r
-               ///   after we are finished parsing all the files\r
-               /// </summary>\r
-               public void VerifyUsing ()\r
-               {\r
-                       foreach (DictionaryEntry de in using_clauses){\r
-                               if (de.Value == null){\r
-                                       string name = (string) de.Key;\r
-                                       \r
-                                       GenericParser.error (234, "The type or namespace `" +\r
-                                                           name + "' does not exist in the " +\r
-                                                           "class or namespace `" + name + "'");\r
-                               }\r
-                       }\r
-               }\r
-\r
-       }\r
-}\r
-\r
+//
+// namespace.cs: Tracks namespaces
+//
+// Author:
+//   Miguel de Icaza (miguel@ximian.com)
+//
+// (C) 2001 Ximian, Inc.
+//
+using System;
+using System.Collections;
+using Mono.Languages;
+
+namespace Mono.MonoBASIC {
+
+       /// <summary>
+       ///   Keeps track of the namespaces defined in the C# code.
+       /// </summary>
+       public class Namespace {
+               static ArrayList all_namespaces = new ArrayList ();
+               
+               Namespace parent;
+               string name;
+                               
+               /// <summary>
+               ///   Constructor Takes the current namespace and the
+               ///   name.  This is bootstrapped with parent == null
+               ///   and name = ""
+               /// </summary>
+               public Namespace (Namespace parent, string name)
+               {
+                       this.name = name;
+                       this.parent = parent;
+
+                       all_namespaces.Add (this);
+               }
+
+               /// <summary>
+               ///   The qualified name of the current namespace
+               /// </summary>
+               public string Name {
+                       get {
+                               string pname = parent != null ? parent.Name : "";
+                               
+                               if (pname == "")
+                                       return name;
+                               else
+                                       return parent.Name + "." + name;
+                       }
+               }
+
+               /// <summary>
+               ///   The parent of this namespace, used by the parser to "Pop"
+               ///   the current namespace declaration
+               /// </summary>
+               public Namespace Parent {
+                       get {
+                               return parent;
+                       }
+               }
+               
+               /// <summary>
+               ///   Show the qualified name of the namespace contained here
+               /// </summary>
+               public override string ToString() {
+                       return Name;
+               }
+               
+       }
+}