Work to support typing compilation-unit level declarations in the shell.
[mono.git] / mcs / mcs / roottypes.cs
1 //
2 // roottypes.cs: keeps a tree representation of the generated code
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //
6 // Dual licensed under the terms of the MIT X11 or GNU GPL
7 //
8 // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9 // Copyright 2003-2008 Novell, Inc.
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         // <summary>
21         //   We store here all the toplevel types that we have parsed,
22         //   this is the root of all information we have parsed.
23         // </summary>
24         public sealed class RootTypes : TypeContainer
25         {
26                 // TODO: It'd be so nice to have generics
27                 Hashtable anonymous_types;
28                 
29                 public RootTypes ()
30                         : base (null, null, MemberName.Null, null, Kind.Root)
31                 {
32                         types = new ArrayList ();
33                         anonymous_types = new Hashtable ();
34                 }
35
36                 public void AddAnonymousType (AnonymousTypeClass type)
37                 {
38                         ArrayList existing = (ArrayList)anonymous_types [type.Parameters.Count];
39                         if (existing == null) {
40                                 existing = new ArrayList ();
41                                 anonymous_types.Add (type.Parameters.Count, existing);
42                         }
43                         existing.Add (type);
44                 }
45
46                 public override bool IsClsComplianceRequired ()
47                 {
48                         return true;
49                 }
50
51                 public AnonymousTypeClass GetAnonymousType (ArrayList parameters)
52                 {
53                         ArrayList candidates = (ArrayList) anonymous_types [parameters.Count];
54                         if (candidates == null)
55                                 return null;
56
57                         int i;
58                         foreach (AnonymousTypeClass at in candidates) {
59                                 for (i = 0; i < parameters.Count; ++i) {
60                                         if (!parameters [i].Equals (at.Parameters [i]))
61                                                 break;
62                                 }
63
64                                 if (i == parameters.Count)
65                                         return at;
66                         }
67
68                         return null;
69                 }
70
71                 public override bool GetClsCompliantAttributeValue ()
72                 {
73                         return CodeGen.Assembly.IsClsCompliant;
74                 }
75
76                 public override string GetSignatureForError ()
77                 {
78                         return "";
79                 }
80
81                 protected override bool AddMemberType (DeclSpace ds)
82                 {
83                         if (!AddToContainer (ds, ds.Name))
84                                 return false;
85                         ds.NamespaceEntry.NS.AddDeclSpace (ds.Basename, ds);
86                         return true;
87                 }
88
89                 protected override void RemoveMemberType (DeclSpace ds)
90                 {
91                         ds.NamespaceEntry.NS.RemoveDeclSpace (ds.Basename);
92                         base.RemoveMemberType (ds);
93                 }
94                 
95                 public override TypeContainer AddPartial (TypeContainer nextPart)
96                 {
97                         return AddPartial (nextPart, nextPart.Name);
98                 }
99
100         }
101
102         public class RootDeclSpace : DeclSpace {
103                 public RootDeclSpace (NamespaceEntry ns)
104                         : base (ns, null, MemberName.Null, null)
105                 {
106                         PartialContainer = RootContext.ToplevelTypes;
107                 }
108
109                 public override AttributeTargets AttributeTargets {
110                         get { throw new InternalErrorException ("should not be called"); }
111                 }
112
113                 public override string DocCommentHeader {
114                         get { throw new InternalErrorException ("should not be called"); }
115                 }
116
117                 public override bool Define ()
118                 {
119                         throw new InternalErrorException ("should not be called");
120                 }
121
122                 public override TypeBuilder DefineType ()
123                 {
124                         throw new InternalErrorException ("should not be called");
125                 }
126
127                 public override MemberCache MemberCache {
128                         get { return PartialContainer.MemberCache; }
129                 }
130
131                 public override bool GetClsCompliantAttributeValue ()
132                 {
133                         return PartialContainer.GetClsCompliantAttributeValue ();
134                 }
135
136                 public override bool IsClsComplianceRequired ()
137                 {
138                         return PartialContainer.IsClsComplianceRequired ();
139                 }
140         }
141 }