new tests + update
[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                 public void RecordDecl (Namespace ns, MemberName name, DeclSpace ds)
49                 {
50                         // This is recorded for tracking inner partial classes only
51                         decls [name] = ds;
52
53                         if (ds.Parent == root_types)
54                                 ns.AddDeclSpace (name.Basename, ds);
55                 }
56                 
57                 //
58                 // FIXME: Why are we using Types?
59                 //
60                 public TypeContainer Types {
61                         get { return root_types; }
62                 }
63
64                 public DeclSpace GetDecl (MemberName name)
65                 {
66                         return (DeclSpace) decls [name];
67                 }
68
69                 public Hashtable AllDecls {
70                         get { return decls; }
71                 }
72         }
73
74         public sealed class RootTypes : TypeContainer
75         {
76                 public RootTypes ()
77                         : base (null, null, MemberName.Null, null, Kind.Root)
78                 {
79                         ec = new EmitContext (null, this, Location.Null, null, null, 0, false);
80                 }
81
82                 public override PendingImplementation GetPendingImplementations ()
83                 {
84                         throw new InvalidOperationException ();
85                 }
86
87                 public override bool IsClsCompliaceRequired (DeclSpace ds)
88                 {
89                         return true;
90                 }
91
92                 public override string GetSignatureForError ()
93                 {
94                         return "";
95                 }
96
97                 protected override bool AddToTypeContainer (DeclSpace ds)
98                 {
99                         return AddToContainer (ds, ds.Name);
100                 }
101         }
102 }