2004-05-29 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / mcs / tree.cs
index 47b764ff096993c2f3c2aea95eb4e4d1cecf200c..0267f451d94ab24e91fff3a28be510f8f824d250 100755 (executable)
@@ -45,41 +45,61 @@ namespace Mono.CSharp
                
                public Tree ()
                {
-                       root_types = new TypeContainer (null, "", new Location (-1));
+                       root_types = new TypeContainer ();
 
                        decls = new Hashtable ();
                        namespaces = new Hashtable ();
                }
 
+               DoubleHash decl_ns_name = new DoubleHash ();
+               
                public void RecordDecl (string name, DeclSpace ds)
                {
                        if (decls.Contains (name)){
+                               DeclSpace other = (DeclSpace) decls [name];
+                               Report.SymbolRelatedToPreviousError (other.Location, other.GetSignatureForError ());
+
                                Report.Error (
                                        101, ds.Location,
                                        "There is already a definition for `" + name + "'");
-                               DeclSpace other = (DeclSpace) decls [name];
-                               Report.Error (0,
-                                       other.Location, "(Location of symbol related to previous error)");
                                return;
                        }
+
+                       ds.RecordDecl ();
+
+                       int p = name.LastIndexOf ('.');
+                       if (p == -1)
+                               decl_ns_name.Insert ("", name, ds);
+                       else {
+                               decl_ns_name.Insert (name.Substring (0, p), name.Substring (p+1), ds);
+                       }
+
                        decls.Add (name, ds);
                }
+
+               public DeclSpace LookupByNamespace (string ns, string name)
+               {
+                       object res;
+                       
+                       decl_ns_name.Lookup (ns, name, out res);
+                       return (DeclSpace) res;
+               }
                
-               public Namespace RecordNamespace (Namespace parent, SourceFile file, string name)
+               public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name, Location loc)
                {
-                       Namespace ns = new Namespace (parent, file, name);
+                       NamespaceEntry ns = new NamespaceEntry (parent, file, name, loc);
 
                        if (namespaces.Contains (file)){
                                Hashtable ns_ns = (Hashtable) namespaces [file];
 
-                               if (ns_ns.Contains (ns.Name))
-                                       return (Namespace) ns_ns [ns.Name];
-                               ns_ns.Add (ns.Name, ns);
+                               if (ns_ns.Contains (ns.FullName))
+                                       return (NamespaceEntry) ns_ns [ns.FullName];
+                               ns_ns.Add (ns.FullName, ns);
                        } else {
                                Hashtable new_table = new Hashtable ();
                                namespaces [file] = new_table;
 
-                               new_table.Add (ns.Name, ns);
+                               new_table.Add (ns.FullName, ns);
                        }
 
                        return ns;