* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[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 all the types definied (classes, structs, ifaces, enums)
38                 // </summary>
39                 Hashtable decls;
40                 
41                 public Tree ()
42                 {
43                         root_types = new RootTypes ();
44
45                         decls = new Hashtable ();
46                 }
47
48                 DoubleHash decl_ns_name = new DoubleHash ();
49                 
50                 public void RecordDecl (string name, DeclSpace ds)
51                 {
52                         DeclSpace other = (DeclSpace) decls [name];
53                         if (other != null){
54                                 PartialContainer other_pc = other as PartialContainer;
55                                 if ((ds is TypeContainer) && (other_pc != null)) {
56                                         Report.Error (
57                                                 260, ds.Location, "Missing partial modifier " +
58                                                 "on declaration of type `{0}'; another " +
59                                                 "partial implementation of this type exists",
60                                                 name);
61
62                                         Report.LocationOfPreviousError (other.Location);
63                                         return;
64                                 }
65
66                                 Report.SymbolRelatedToPreviousError (
67                                         other.Location, other.GetSignatureForError ());
68
69                                 Report.Error (
70                                         101, ds.Location,
71                                         "There is already a definition for `" + name + "'");
72                                 return;
73                         }
74
75                         ds.RecordDecl ();
76
77                         int p = name.LastIndexOf ('.');
78                         if (p == -1)
79                                 decl_ns_name.Insert ("", name, ds);
80                         else {
81                                 decl_ns_name.Insert (name.Substring (0, p), name.Substring (p+1), ds);
82                         }
83
84                         decls.Add (name, ds);
85                 }
86
87                 public DeclSpace LookupByNamespace (string ns, string name)
88                 {
89                         object res;
90                         
91                         decl_ns_name.Lookup (ns, name, out res);
92                         return (DeclSpace) res;
93                 }
94                 
95                 //
96                 // FIXME: Why are we using Types?
97                 //
98                 public TypeContainer Types {
99                         get {
100                                 return root_types;
101                         }
102                 }
103
104                 public Hashtable Decls {
105                         get {
106                                 return decls;
107                         }
108                 }
109         }
110
111         public class RootTypes : TypeContainer
112         {
113                 public RootTypes ()
114                         : base (null, null, MemberName.Null, null, Kind.Root,
115                                 new Location (-1))
116                 { }
117
118                 public override void Register ()
119                 {
120                         throw new InvalidOperationException ();
121                 }
122
123                 public override PendingImplementation GetPendingImplementations ()
124                 {
125                         throw new InvalidOperationException ();
126                 }
127         }
128 }