Don't print null on exit
[mono.git] / mcs / mcs / roottypes.cs
index 0c9b6b23e7793a0f8ee41ffdf223fede16d977bf..0144f0130300ae893ee1a083325b921b5d1d5350 100644 (file)
@@ -11,7 +11,7 @@
 //
 
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Runtime.InteropServices;
@@ -29,12 +29,12 @@ namespace Mono.CSharp
                protected Assembly assembly;
 
                public ModuleContainer (Assembly assembly)
-                       : base (null, null, MemberName.Null, null, Kind.Root)
+                       : base (null, null, MemberName.Null, null, 0)
                {
                        this.assembly = assembly;
                }
 
-               public Assembly Assembly {
+               public override Assembly Assembly {
                        get { return assembly; }
                }
 
@@ -55,8 +55,7 @@ namespace Mono.CSharp
        //
        public class ModuleCompiled : ModuleContainer
        {
-               // TODO: It'd be so nice to have generics
-               Hashtable anonymous_types;
+               Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
                readonly bool is_unsafe;
                readonly CompilerContext context;
 
@@ -72,8 +71,8 @@ namespace Mono.CSharp
                        this.is_unsafe = isUnsafe;
                        this.context = context;
 
-                       types = new ArrayList ();
-                       anonymous_types = new Hashtable ();
+                       types = new List<TypeContainer> ();
+                       anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
                }
 
                public override AttributeTargets AttributeTargets {
@@ -84,15 +83,17 @@ namespace Mono.CSharp
 
                public void AddAnonymousType (AnonymousTypeClass type)
                {
-                       ArrayList existing = (ArrayList)anonymous_types [type.Parameters.Count];
+                       List<AnonymousTypeClass> existing;
+                       if (!anonymous_types.TryGetValue (type.Parameters.Count, out existing))
                        if (existing == null) {
-                               existing = new ArrayList ();
+                               existing = new List<AnonymousTypeClass> ();
                                anonymous_types.Add (type.Parameters.Count, existing);
                        }
+
                        existing.Add (type);
                }
 
-               public void AddAttributes (ArrayList attrs)
+               public void AddAttributes (List<Attribute> attrs)
                {
                        foreach (Attribute a in attrs)
                                a.AttachTo (this, CodeGen.Assembly);
@@ -110,7 +111,7 @@ namespace Mono.CSharp
                        return AddPartial (nextPart, nextPart.Name);
                }
 
-               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
+               public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
                {
                        if (a.Type == pa.CLSCompliant) {
                                if (CodeGen.Assembly.ClsCompliantAttribute == null) {
@@ -122,7 +123,7 @@ namespace Mono.CSharp
                                }
                        }
 
-                       builder.SetCustomAttribute (cb);
+                       builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
                }
 
                public ModuleBuilder Builder {
@@ -146,19 +147,19 @@ namespace Mono.CSharp
                                OptAttributes.Emit ();
 
                        if (is_unsafe) {
-                               Type t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
+                               TypeSpec t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", MemberKind.Class, true);
                                if (t != null) {
-                                       ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, Type.EmptyTypes);
+                                       var unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, TypeSpec.EmptyTypes);
                                        if (unverifiable_code_ctor != null)
-                                               builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
+                                               builder.SetCustomAttribute (new CustomAttributeBuilder ((ConstructorInfo) unverifiable_code_ctor.GetMetaInfo (), new object[0]));
                                }
                        }
                }
 
-               public AnonymousTypeClass GetAnonymousType (ArrayList parameters)
+               public AnonymousTypeClass GetAnonymousType (IList<AnonymousTypeParameter> parameters)
                {
-                       ArrayList candidates = (ArrayList) anonymous_types [parameters.Count];
-                       if (candidates == null)
+                       List<AnonymousTypeClass> candidates;
+                       if (!anonymous_types.TryGetValue (parameters.Count, out candidates))
                                return null;
 
                        int i;
@@ -175,11 +176,6 @@ namespace Mono.CSharp
                        return null;
                }
 
-               public override bool GetClsCompliantAttributeValue ()
-               {
-                       return CodeGen.Assembly.IsClsCompliant;
-               }
-
                public bool HasDefaultCharSet {
                        get {
                                return has_default_charset;
@@ -193,14 +189,14 @@ namespace Mono.CSharp
 
                public override bool IsClsComplianceRequired ()
                {
-                       return true;
+                       return CodeGen.Assembly.IsClsCompliant;
                }
 
-               protected override bool AddMemberType (DeclSpace ds)
+               protected override bool AddMemberType (TypeContainer ds)
                {
                        if (!AddToContainer (ds, ds.Name))
                                return false;
-                       ds.NamespaceEntry.NS.AddDeclSpace (ds.Basename, ds);
+                       ds.NamespaceEntry.NS.AddType (ds.Definition);
                        return true;
                }
 
@@ -258,9 +254,9 @@ namespace Mono.CSharp
                }
        }
 
-       class RootDeclSpace : DeclSpace {
+       class RootDeclSpace : TypeContainer {
                public RootDeclSpace (NamespaceEntry ns)
-                       : base (ns, null, MemberName.Null, null)
+                       : base (ns, null, MemberName.Null, null, 0)
                {
                        PartialContainer = RootContext.ToplevelTypes;
                }
@@ -279,31 +275,22 @@ namespace Mono.CSharp
                        get { throw new InternalErrorException ("should not be called"); }
                }
 
-               public override bool Define ()
-               {
-                       throw new InternalErrorException ("should not be called");
-               }
+               //public override bool Define ()
+               //{
+               //    throw new InternalErrorException ("should not be called");
+               //}
 
                public override TypeBuilder DefineType ()
                {
                        throw new InternalErrorException ("should not be called");
                }
 
-               public override MemberCache MemberCache {
-                       get { return PartialContainer.MemberCache; }
-               }
-
                public override ModuleContainer Module {
                        get {
                                return PartialContainer.Module;
                        }
                }
 
-               public override bool GetClsCompliantAttributeValue ()
-               {
-                       return PartialContainer.GetClsCompliantAttributeValue ();
-               }
-
                public override bool IsClsComplianceRequired ()
                {
                        return PartialContainer.IsClsComplianceRequired ();