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>
public Tree ()
{
- root_types = new TypeContainer ();
+ root_types = new RootTypes ();
decls = new Hashtable ();
- namespaces = new Hashtable ();
}
- DoubleHash decl_ns_name = new DoubleHash ();
-
- public void RecordDecl (string name, DeclSpace ds)
+ public void RecordDecl (Namespace ns, MemberName 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];
+ 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;
}
- 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;
+ if (ds.Parent == Types)
+ ns.DefineName (name.Basename, ds);
}
- public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name, Location loc)
- {
- NamespaceEntry ns = new NamespaceEntry (parent, file, name, loc);
-
- if (namespaces.Contains (file)){
- Hashtable ns_ns = (Hashtable) namespaces [file];
-
- 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.FullName, ns);
- }
-
- return ns;
- }
-
//
// FIXME: Why are we using Types?
//
}
}
- 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;
+ }
+
}
}