2006-08-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mbas / 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.MonoBASIC
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 namespaces defined in the source code
38                 // </summary>
39                 Hashtable namespaces;
40
41                 // <summary>
42                 //   Keeps track of all the types definied (classes, structs, ifaces, enums)
43                 // </summary>
44                 Hashtable decls;
45                 
46                 public Tree ()
47                 {
48                         root_types = new TypeContainer (null, "", null, new Location (-1, 0));
49
50                         decls = new Hashtable ();
51                         namespaces = new Hashtable ();
52                 }
53
54                 public void RecordDecl (string name, DeclSpace ds)
55                 {
56                         if (decls.Contains (name)){
57                                 Report.Error (
58                                         30179, ds.Location,
59                                         "There is already a definition for `" + name + "'");
60                                 DeclSpace other = (DeclSpace) decls [name];
61                                 Report.Error (0,
62                                         other.Location, "(Location of symbol related to previous error)");
63                                 return;
64                         }
65                         decls.Add (name, ds);
66                 }
67                 
68                 public Namespace RecordNamespace (Namespace parent, string file, string name)
69                 {
70                         Namespace ns = new Namespace (parent, name);
71
72                         if (namespaces.Contains (file)){
73                                 Hashtable ns_ns = (Hashtable) namespaces [file];
74
75                                 if (ns_ns.Contains (ns.Name))
76                                         return (Namespace) ns_ns [ns.Name];
77                                 ns_ns.Add (ns.Name, ns);
78                         } else {
79                                 Hashtable new_table = new Hashtable ();
80                                 namespaces [file] = new_table;
81
82                                 new_table.Add (ns.Name, ns);
83                         }
84
85                         return ns;
86                 }
87
88                 //
89                 // FIXME: Why are we using Types?
90                 //
91                 public TypeContainer Types {
92                         get {
93                                 return root_types;
94                         }
95                 }
96
97                 public Hashtable Decls {
98                         get {
99                                 return decls;
100                         }
101                 }
102
103                 public Hashtable Namespaces {
104                         get {
105                                 return namespaces;
106                         }
107                 }
108         }
109 }