2 // roottypes.cs: keeps a tree representation of the generated code
4 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Dual licensed under the terms of the MIT X11 or GNU GPL
8 // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9 // Copyright 2003-2008 Novell, Inc.
13 using System.Collections;
14 using System.Reflection;
15 using System.Reflection.Emit;
21 // We store here all the toplevel types that we have parsed,
22 // this is the root of all information we have parsed.
24 public sealed class RootTypes : TypeContainer
26 // TODO: It'd be so nice to have generics
27 Hashtable anonymous_types;
30 : base (null, null, MemberName.Null, null, Kind.Root)
32 types = new ArrayList ();
33 anonymous_types = new Hashtable ();
36 public void AddAnonymousType (AnonymousTypeClass type)
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);
46 public override bool IsClsComplianceRequired ()
51 public AnonymousTypeClass GetAnonymousType (ArrayList parameters)
53 ArrayList candidates = (ArrayList) anonymous_types [parameters.Count];
54 if (candidates == null)
58 foreach (AnonymousTypeClass at in candidates) {
59 for (i = 0; i < parameters.Count; ++i) {
60 if (!parameters [i].Equals (at.Parameters [i]))
64 if (i == parameters.Count)
71 public override bool GetClsCompliantAttributeValue ()
73 return CodeGen.Assembly.IsClsCompliant;
76 public override string GetSignatureForError ()
81 protected override bool AddMemberType (DeclSpace ds)
83 if (!AddToContainer (ds, ds.Name))
85 ds.NamespaceEntry.NS.AddDeclSpace (ds.Basename, ds);
89 protected override void RemoveMemberType (DeclSpace ds)
91 ds.NamespaceEntry.NS.RemoveDeclSpace (ds.Basename);
92 base.RemoveMemberType (ds);
95 public override TypeContainer AddPartial (TypeContainer nextPart)
97 return AddPartial (nextPart, nextPart.Name);
102 public class RootDeclSpace : DeclSpace {
103 public RootDeclSpace (NamespaceEntry ns)
104 : base (ns, null, MemberName.Null, null)
106 PartialContainer = RootContext.ToplevelTypes;
109 public override AttributeTargets AttributeTargets {
110 get { throw new InternalErrorException ("should not be called"); }
113 public override string DocCommentHeader {
114 get { throw new InternalErrorException ("should not be called"); }
117 public override bool Define ()
119 throw new InternalErrorException ("should not be called");
122 public override TypeBuilder DefineType ()
124 throw new InternalErrorException ("should not be called");
127 public override MemberCache MemberCache {
128 get { return PartialContainer.MemberCache; }
131 public override bool GetClsCompliantAttributeValue ()
133 return PartialContainer.GetClsCompliantAttributeValue ();
136 public override bool IsClsComplianceRequired ()
138 return PartialContainer.IsClsComplianceRequired ();