2004-07-14 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / typemanager.cs
index b63a87a59ccfdbe428452d50b40a4afb3558920a..843e41083c1fbd39fe0df266e3068f519442da1d 100755 (executable)
@@ -70,6 +70,7 @@ public class TypeManager {
        static public Type intptr_type;
        static public Type monitor_type;
        static public Type runtime_field_handle_type;
+       static public Type runtime_argument_handle_type;
        static public Type attribute_type;
        static public Type attribute_usage_type;
        static public Type dllimport_type;
@@ -94,6 +95,9 @@ public class TypeManager {
        static public Type struct_layout_attribute_type;
        static public Type field_offset_attribute_type;
 
+       static public Type generic_ienumerator_type;
+       static public Type generic_ienumerable_type;
+
        //
        // An empty array of types
        //
@@ -582,6 +586,11 @@ public class TypeManager {
                assemblies = n;
        }
 
+        public static Assembly [] GetAssemblies ()
+        {
+                return assemblies;
+        }
+
        /// <summary>
        ///  Registers a module builder to lookup types from
        /// </summary>
@@ -1114,6 +1123,7 @@ public class TypeManager {
                type_type     = CoreLookupType ("System.Type");
 
                runtime_field_handle_type = CoreLookupType ("System.RuntimeFieldHandle");
+               runtime_argument_handle_type = CoreLookupType ("System.RuntimeArgumentHandle");
                runtime_helpers_type = CoreLookupType ("System.Runtime.CompilerServices.RuntimeHelpers");
                default_member_type  = CoreLookupType ("System.Reflection.DefaultMemberAttribute");
                runtime_handle_type  = CoreLookupType ("System.RuntimeTypeHandle");
@@ -1164,6 +1174,13 @@ public class TypeManager {
                struct_layout_attribute_type = CoreLookupType ("System.Runtime.InteropServices.StructLayoutAttribute");
                field_offset_attribute_type = CoreLookupType ("System.Runtime.InteropServices.FieldOffsetAttribute");
 
+               //
+               // Generic types
+               //
+               generic_ienumerator_type     = CoreLookupType ("System.Collections.Generic.IEnumerator`1");
+               generic_ienumerable_type     = CoreLookupType ("System.Collections.Generic.IEnumerable`1");
+
+
                //
                // When compiling corlib, store the "real" types here.
                //
@@ -1975,20 +1992,24 @@ public class TypeManager {
        /// </summary>
        static public Type [] GetArgumentTypes (MethodBase mb)
        {
-               if (method_arguments.Contains (mb))
-                       return (Type []) method_arguments [mb];
-               else {
+               object t = method_arguments [mb];
+               if (t != null)
+                       return (Type []) t;
+
                        ParameterInfo [] pi = mb.GetParameters ();
                        int c = pi.Length;
-                       Type [] types = new Type [c];
+               Type [] types;
                        
+               if (c == 0) {
+                       types = NoTypes;
+               } else {
+                       types = new Type [c];
                        for (int i = 0; i < c; i++)
                                types [i] = pi [i].ParameterType;
-
+               }
                        method_arguments.Add (mb, types);
                        return types;
                }
-       }
 
        /// <summary>
        ///    Returns the argument types for an indexer based on its PropertyInfo
@@ -2574,23 +2595,27 @@ public class TypeManager {
                return "Item";
        }
 
-       static MethodInfo pinned_method = null;
-       public static void MakePinned (LocalBuilder builder)
-       {
-               if (pinned_method == null) {
-                       pinned_method = typeof (LocalBuilder).GetMethod ("MakePinned", BindingFlags.Instance | BindingFlags.NonPublic);
-                       if (pinned_method == null) {
-                               Report.Warning (-24, new Location (-1), "Microsoft.NET does not support making pinned variables." +
+       static MethodInfo declare_local_method = null;
+       
+       public static LocalBuilder DeclareLocalPinned (ILGenerator ig, Type t)
+       {
+               if (declare_local_method == null){
+                       declare_local_method = typeof (ILGenerator).GetMethod (
+                               "DeclareLocal",
+                               BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
+                               null, 
+                               new Type [] { typeof (Type), typeof (bool)},
+                               null);
+                       if (declare_local_method == null){
+                               Report.Warning (-24, new Location (-1),
+                                               "This version of the runtime does not support making pinned local variables.  " +
                                        "This code may cause errors on a runtime with a moving GC");
-                               
-                               return;
+                               return ig.DeclareLocal (t);
                        }
                }
-               
-               pinned_method.Invoke (builder, null);
+               return (LocalBuilder) declare_local_method.Invoke (ig, new object [] { t, true });
        }
 
-
        //
        // Returns whether the array of memberinfos contains the given method
        //