2005-07-07 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / tree.cs
old mode 100755 (executable)
new mode 100644 (file)
index 57e4740..e0453ca
@@ -33,11 +33,6 @@ namespace Mono.CSharp
        public class Tree {
                TypeContainer root_types;
 
-               // <summary>
-               //  Keeps track of namespaces defined in the source code
-               // </summary>
-               Hashtable namespaces;
-
                // <summary>
                //   Keeps track of all the types definied (classes, structs, ifaces, enums)
                // </summary>
@@ -45,46 +40,37 @@ namespace Mono.CSharp
                
                public Tree ()
                {
-                       root_types = new TypeContainer (null, "", new Location (-1));
+                       root_types = new RootTypes ();
 
                        decls = new Hashtable ();
-                       namespaces = new Hashtable ();
                }
 
-               public void RecordDecl (string name, DeclSpace ds)
+               public void RecordDecl (Namespace ns, MemberName name, DeclSpace ds)
                {
-                       if (decls.Contains (name)){
-                               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)");
+                       DeclSpace other = (DeclSpace) decls [name];
+                       if (other != null){
+                               Report.SymbolRelatedToPreviousError (other);
+
+                               PartialContainer other_pc = other as PartialContainer;
+                               if (ds is TypeContainer && other_pc != null)
+                                       Report.Error (
+                                               260, ds.Location, "Missing partial modifier " +
+                                               "on declaration of type '{0}'; another " +
+                                               "partial implementation of this type exists",
+                                               name);
+                               else
+                                       Report.Error (
+                                               101, ds.Location,
+                                               "There is already a definition for '{0}'", name);
                                return;
                        }
-                       decls.Add (name, ds);
-               }
-               
-               public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name)
-               {
-                       NamespaceEntry ns = new NamespaceEntry (parent, file, name);
-
-                       if (namespaces.Contains (file)){
-                               Hashtable ns_ns = (Hashtable) namespaces [file];
 
-                               if (ns_ns.Contains (ns.Name))
-                                       return (NamespaceEntry) ns_ns [ns.Name];
-                               ns_ns.Add (ns.Name, ns);
-                       } else {
-                               Hashtable new_table = new Hashtable ();
-                               namespaces [file] = new_table;
-
-                               new_table.Add (ns.Name, ns);
-                       }
+                       decls.Add (name, ds);
 
-                       return ns;
+                       if (ds.Parent == Types)
+                               ns.DefineName (name.Basename, ds);
                }
-
+               
                //
                // FIXME: Why are we using Types?
                //
@@ -94,16 +80,35 @@ namespace Mono.CSharp
                         }
                 }
 
-               public Hashtable Decls {
+               public DeclSpace GetDecl (MemberName name)
+               {
+                       return (DeclSpace) decls [name];
+               }
+
+               public Hashtable AllDecls {
                        get {
                                return decls;
                        }
                }
+       }
 
-               public Hashtable Namespaces {
-                       get {
-                               return namespaces;
-                       }
+       public class RootTypes : TypeContainer
+       {
+               public RootTypes ()
+                       : base (null, null, MemberName.Null, null, Kind.Root, Location.Null)
+               {
+                       ec = new EmitContext (null, this, Location.Null, null, null, 0, false);
                }
+
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       throw new InvalidOperationException ();
+               }
+
+               public override bool IsClsComplianceRequired (DeclSpace ds)
+               {
+                       return true;
+               }
+
        }
 }