2001-12-19 Miguel de Icaza <miguel@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 Mono.CSharp
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                 public Tree ()
57                 {
58                         root_types = new TypeContainer (null, "", new Location (-1));
59                 }
60
61
62                 public void RecordInterface (string name, Interface iface)
63                 {
64                         if (ifaces == null)
65                                 ifaces = new Hashtable ();
66
67                         ifaces.Add (name, iface);
68                 }
69                 
70                 public void RecordStruct (string name, Struct s)
71                 {
72                         if (structs == null)
73                                 structs = new Hashtable ();
74
75                         structs.Add (name, s);
76                 }
77                 
78                 public void RecordClass (string name, Class c)
79                 {
80                         if (classes == null)
81                                 classes = new Hashtable ();
82
83                         classes.Add (name, c);
84                 }
85
86                 public Namespace RecordNamespace (Namespace parent, string file, string name)
87                 {
88                         if (namespaces == null)
89                                 namespaces = new Hashtable ();
90                                                                                                      
91                         Namespace ns = new Namespace (parent, name);
92
93                         if (namespaces.Contains (file)){
94                                 Hashtable ns_ns = (Hashtable) namespaces [file];
95
96                                 if (ns_ns.Contains (ns.Name))
97                                         return (Namespace) ns_ns [ns.Name];
98                                 ns_ns.Add (ns.Name, ns);
99                         } else {
100                                 Hashtable new_table = new Hashtable ();
101                                 namespaces [file] = new_table;
102
103                                 new_table.Add (ns.Name, ns);
104                         }
105
106                         return ns;
107                 }
108                 
109                 public TypeContainer Types {
110                         get {
111                                 return root_types;
112                         }
113                 }
114
115                 public Hashtable Interfaces {
116                         get {
117                                 return ifaces;
118                         }
119                 }
120
121                 public Hashtable Classes {
122                         get {
123                                 return classes;
124                         }
125                 }
126
127                 public Hashtable Structs {
128                         get {
129                                 return structs;
130                         }
131                 }
132
133                 public Hashtable Namespaces {
134                         get {
135                                 return namespaces;
136                         }
137                 }
138         }
139 }