2007-08-09 Marek Safar <marek.safar@gmail.com>
[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 // 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         // <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 == candidates.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                 public override TypeContainer AddPartial (TypeContainer nextPart)
90                 {
91                         return AddPartial (nextPart, nextPart.Name);
92                 }
93         }
94
95         public class RootDeclSpace : DeclSpace {
96                 public RootDeclSpace (NamespaceEntry ns)
97                         : base (ns, null, MemberName.Null, null)
98                 {
99                         PartialContainer = RootContext.ToplevelTypes;
100                 }
101
102                 public override AttributeTargets AttributeTargets {
103                         get { throw new InternalErrorException ("should not be called"); }
104                 }
105
106                 public override string DocCommentHeader {
107                         get { throw new InternalErrorException ("should not be called"); }
108                 }
109
110                 public override bool Define ()
111                 {
112                         throw new InternalErrorException ("should not be called");
113                 }
114
115                 public override TypeBuilder DefineType ()
116                 {
117                         throw new InternalErrorException ("should not be called");
118                 }
119
120                 public override MemberList FindMembers (MemberTypes mt, BindingFlags bf, MemberFilter filter, object criteria)
121                 {
122                         throw new InternalErrorException ("should not be called");
123                 }
124
125                 public override MemberCache MemberCache {
126                         get { return PartialContainer.MemberCache; }
127                 }
128
129                 public override bool GetClsCompliantAttributeValue ()
130                 {
131                         return PartialContainer.GetClsCompliantAttributeValue ();
132                 }
133
134                 public override bool IsClsComplianceRequired ()
135                 {
136                         return PartialContainer.IsClsComplianceRequired ();
137                 }
138         }
139 }