-//\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.CSharp {
+
+ /// <summary>
+ /// Keeps track of the namespaces defined in the C# code.
+ /// </summary>
+ public class Namespace {
+ Namespace parent;
+ string name;
+ ArrayList using_clauses;
+ Hashtable aliases;
+ public bool DeclarationFound = false;
+
+ /// <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;
+ }
+
+ /// <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>
+ /// Records a new namespace for resolving name references
+ /// </summary>
+ public void Using (string ns, Location loc)
+ {
+ if (DeclarationFound){
+ Report.Error (1529, loc, "A using clause must precede all other namespace elements");
+ return;
+ }
+
+ if (using_clauses == null)
+ using_clauses = new ArrayList ();
+
+ using_clauses.Add (ns);
+ }
+
+ public ArrayList UsingTable {
+ get {
+ return using_clauses;
+ }
+ }
+
+ public void UsingAlias (string alias, string namespace_or_type, Location loc)
+ {
+ if (aliases == null)
+ aliases = new Hashtable ();
+
+ if (aliases.Contains (alias)){
+ Report.Error (1537, loc, "The using alias `" + alias +
+ "' appeared previously in this namespace");
+ return;
+ }
+
+ aliases [alias] = namespace_or_type;
+ }
+
+ public string LookupAlias (string alias)
+ {
+ string value = null;
+
+ // System.Console.WriteLine ("Lookup " + alias + " in " + name);
+
+ if (aliases != null)
+ value = (string) (aliases [alias]);
+ if (value == null && Parent != null)
+ value = Parent.LookupAlias (alias);
+
+ return value;
+ }
+
+ /// <summary>
+ /// Used to validate that all the using clauses are correct
+ /// after we are finished parsing all the files
+ /// </summary>
+ public void VerifyUsing ()
+ {
+ foreach (DictionaryEntry de in using_clauses){
+ if (de.Value == null){
+ string name = (string) de.Key;
+
+ Report.Error (234, "The type or namespace `" +
+ name + "' does not exist in the " +
+ "class or namespace `" + name + "'");
+ }
+ }
+ }
+
+ }
+}
+