**** Merged r45106 from MCS ****
[mono.git] / mcs / gmcs / 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 (MemberName name, DeclSpace ds)
49                 {
50                         DeclSpace other = (DeclSpace) decls [name];
51                         if (other != null){
52                                 PartialContainer other_pc = other as PartialContainer;
53                                 if ((ds is TypeContainer) && (other_pc != null)) {
54                                         Report.Error (
55                                                 260, ds.Location, "Missing partial modifier " +
56                                                 "on declaration of type `{0}'; another " +
57                                                 "partial implementation of this type exists",
58                                                 name);
59
60                                         Report.LocationOfPreviousError (other.Location);
61                                         return;
62                                 }
63
64                                 Report.SymbolRelatedToPreviousError (
65                                         other.Location, other.GetSignatureForError ());
66
67                                 Report.Error (
68                                         101, ds.Location,
69                                         "There is already a definition for `" + name + "'");
70                                 return;
71                         }
72
73                         ds.RecordDecl ();
74
75                         decls.Add (name, ds);
76                 }
77                 
78                 //
79                 // FIXME: Why are we using Types?
80                 //
81                 public TypeContainer Types {
82                         get {
83                                 return root_types;
84                         }
85                 }
86
87                 public DeclSpace GetDecl (MemberName name)
88                 {
89                         return (DeclSpace) decls [name];
90                 }
91
92                 public Hashtable AllDecls {
93                         get {
94                                 return decls;
95                         }
96                 }
97         }
98
99         public class RootTypes : TypeContainer
100         {
101                 public RootTypes ()
102                         : base (null, null, MemberName.Null, null, Kind.Root, Location.Null)
103                 {
104                         ec = new EmitContext (null, this, Location.Null, null, null, 0, false);
105                 }
106
107                 public override PendingImplementation GetPendingImplementations ()
108                 {
109                         throw new InvalidOperationException ();
110                 }
111
112                 public override bool IsClsComplianceRequired (DeclSpace ds)
113                 {
114                         return true;
115                 }
116
117         }
118 }