2001-10-31 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / mcs / tree.cs
1 //
2 // tree.cs: keeps a tree representation of the generated code
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //
6 // Licensed under the terms of the GNU GPL
7 //
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
9 //
10 //
11
12 using System;
13 using System.Collections;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.IO;
17
18 namespace CIR
19 {
20
21         public interface ITreeDump {
22                 int  Dump (Tree tree, StreamWriter output);
23                 void ParseOptions (string options);
24         }
25
26         // <summary>
27         //   
28         //   We store here all the toplevel types that we have parsed,
29         //   this is the root of all information we have parsed.
30         // 
31         // </summary>
32         
33         public class Tree {
34                 TypeContainer root_types;
35
36                 // <summary>
37                 //   Keeps track of the interfaces defined in the source code
38                 // </summary>
39                 Hashtable ifaces;
40
41                 // <summary>
42                 //   Keeps track of the structs defined in the source code
43                 // </summary>
44                 Hashtable structs;
45
46                 // <summary>
47                 //   Keeps track of the classes defined in the source code
48                 // </summary>
49                 Hashtable classes;
50
51                 // <summary>
52                 //  Keeps track of namespaces defined in the source code
53                 // </summary>
54                 Hashtable namespaces;
55
56                 RootContext rc;
57                 
58                 public Tree (RootContext rc)
59                 {
60                         root_types = new TypeContainer (rc, null, "", new Location (-1));
61                         this.rc = rc;
62                 }
63
64
65                 public void RecordInterface (string name, Interface iface)
66                 {
67                         if (ifaces == null)
68                                 ifaces = new Hashtable ();
69
70                         ifaces.Add (name, iface);
71                 }
72                 
73                 public void RecordStruct (string name, Struct s)
74                 {
75                         if (structs == null)
76                                 structs = new Hashtable ();
77
78                         structs.Add (name, s);
79                 }
80                 
81                 public void RecordClass (string name, Class c)
82                 {
83                         if (classes == null)
84                                 classes = new Hashtable ();
85
86                         classes.Add (name, c);
87                 }
88
89                 public Namespace RecordNamespace (Namespace parent, string name)
90                 {
91                         if (namespaces == null)
92                                 namespaces = new Hashtable ();
93
94                         if (namespaces.ContainsKey (name))
95                                 return (Namespace) namespaces [name];
96                                                                              
97                         Namespace ns = new Namespace (parent, name);
98                         namespaces.Add (ns.Name, ns);
99                         return ns;
100                 }
101                 
102                 public TypeContainer Types {
103                         get {
104                                 return root_types;
105                         }
106                 }
107
108                 public Hashtable Interfaces {
109                         get {
110                                 return ifaces;
111                         }
112                 }
113
114                 public Hashtable Classes {
115                         get {
116                                 return classes;
117                         }
118                 }
119
120                 public Hashtable Structs {
121                         get {
122                                 return structs;
123                         }
124                 }
125
126                 public Hashtable Namespaces {
127                         get {
128                                 return namespaces;
129                         }
130                 }
131         }
132 }