// // tree.cs: keeps a tree representation of the generated code // // Author: Miguel de Icaza (miguel@gnu.org) // // Licensed under the terms of the GNU GPL // // (C) 2001 Ximian, Inc (http://www.ximian.com) // // using System; using System.Collections; using System.Reflection; using System.Reflection.Emit; using System.IO; namespace Mono.CSharp { public interface ITreeDump { int Dump (Tree tree, StreamWriter output); void ParseOptions (string options); } // // // We store here all the toplevel types that we have parsed, // this is the root of all information we have parsed. // // public class Tree { TypeContainer root_types; // // Keeps track of the interfaces defined in the source code // Hashtable ifaces; // // Keeps track of the structs defined in the source code // Hashtable structs; // // Keeps track of the classes defined in the source code // Hashtable classes; // // Keeps track of namespaces defined in the source code // Hashtable namespaces; // // Keeps track of enums defined // Hashtable enums; public Tree () { root_types = new TypeContainer (null, "", new Location (-1)); } void RecordDecl (Hashtable decl, string name, DeclSpace ds) { if (decl.Contains (name)){ Report.Error ( 101, ds.Location, "There is already a definition for `" + name + "'"); DeclSpace other = (DeclSpace) decl [name]; Report.Error (0, other.Location, "(Location of symbol related to previous error)"); return; } decl.Add (name, ds); } public void RecordInterface (string name, Interface iface) { if (ifaces == null) ifaces = new Hashtable (); RecordDecl (ifaces, name, iface); } public void RecordStruct (string name, Struct s) { if (structs == null) structs = new Hashtable (); RecordDecl (structs, name, s); } public void RecordClass (string name, Class c) { if (classes == null) classes = new Hashtable (); RecordDecl (classes, name, c); } public void RecordEnum (string name, Enum e) { if (enums == null) enums = new Hashtable (); RecordDecl (enums, name, e); } public Namespace RecordNamespace (Namespace parent, string file, string name) { if (namespaces == null) namespaces = new Hashtable (); Namespace ns = new Namespace (parent, name); 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); } else { Hashtable new_table = new Hashtable (); namespaces [file] = new_table; new_table.Add (ns.Name, ns); } return ns; } public TypeContainer Types { get { return root_types; } } public Hashtable Interfaces { get { return ifaces; } } public Hashtable Classes { get { return classes; } } public Hashtable Structs { get { return structs; } } public Hashtable Namespaces { get { return namespaces; } } public Hashtable Enums { get { return enums; } } } }