2010-01-12 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Tue, 12 Jan 2010 17:10:11 +0000 (17:10 -0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 12 Jan 2010 17:10:11 +0000 (17:10 -0000)
* *.cs: Introduced non-generic method specification.

svn path=/trunk/mcs/; revision=149419

20 files changed:
mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/const.cs
mcs/mcs/convert.cs
mcs/mcs/decl.cs
mcs/mcs/delegate.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/field.cs
mcs/mcs/generic.cs
mcs/mcs/import.cs
mcs/mcs/iterators.cs
mcs/mcs/linq.cs
mcs/mcs/method.cs
mcs/mcs/namespace.cs
mcs/mcs/nullable.cs
mcs/mcs/statement.cs
mcs/mcs/typemanager.cs

index 3c7ea0b466574760db64f8ed6c2ae50951300509..a8fcd5ec6a02a284c29581f87bc98586ea6bbd00 100644 (file)
@@ -1,3 +1,7 @@
+2010-01-12  Marek Safar  <marek.safar@gmail.com>
+
+       * *.cs: Introduced non-generic method specification.
+
 2010-01-07  Marek Safar  <marek.safar@gmail.com>
 
        * method.cs: Move all method based declarations into a new file.
index 610426ce29948bf6ba62feabb4a5a0c5ccc9fd91..289305e5149807aaf99124b18a5cf7760cda4866 100644 (file)
@@ -489,43 +489,44 @@ namespace Mono.CSharp {
                //
                // Changes method type arguments (MVAR) to storey (VAR) type arguments
                //
-               public MethodInfo MutateGenericMethod (MethodInfo method)
+               public void MutateGenericMethod (MethodSpec ms)
                {
+                       var method = (MethodInfo) ms.MetaInfo;
                        Type [] t_args = TypeManager.GetGenericArguments (method);
                        if (TypeManager.IsGenericType (method.DeclaringType)) {
                                Type t = MutateGenericType (method.DeclaringType);
                                if (t != method.DeclaringType) {
                                        method = (MethodInfo) TypeManager.DropGenericMethodArguments (method);
                                        if (TypeManager.IsBeingCompiled (method))
-                                               method = TypeBuilder.GetMethod (t, method);
+                                               ms.MetaInfo = TypeBuilder.GetMethod (t, method);
                                        else
-                                               method = (MethodInfo) MethodInfo.GetMethodFromHandle (method.MethodHandle, t.TypeHandle);
+                                               ms.MetaInfo = MethodInfo.GetMethodFromHandle (method.MethodHandle, t.TypeHandle);
                                }                               
                        }
 
                        if (t_args == null || t_args.Length == 0)
-                               return method;
+                               return;
 
                        for (int i = 0; i < t_args.Length; ++i)
                                t_args [i] = MutateType (t_args [i]);
 
-                       return method.GetGenericMethodDefinition ().MakeGenericMethod (t_args);
+                       method = (MethodInfo) ms.MetaInfo;
+                       ms.MetaInfo = method.GetGenericMethodDefinition ().MakeGenericMethod (t_args);
                }
 
-               public ConstructorInfo MutateConstructor (ConstructorInfo ctor)
+               public void MutateConstructor (MethodSpec ms)
                {
+                       var ctor = (ConstructorInfo) ms.MetaInfo;
                        if (TypeManager.IsGenericType (ctor.DeclaringType)) {
                                Type t = MutateGenericType (ctor.DeclaringType);
                                if (t != ctor.DeclaringType) {
                                        ctor = (ConstructorInfo) TypeManager.DropGenericMethodArguments (ctor);
                                        if (TypeManager.IsBeingCompiled (ctor))
-                                               return TypeBuilder.GetConstructor (t, ctor);
-                                               
-                                       return (ConstructorInfo) ConstructorInfo.GetMethodFromHandle (ctor.MethodHandle, t.TypeHandle);
+                                               ms.MetaInfo = TypeBuilder.GetConstructor (t, ctor);
+                                       else
+                                               ms.MetaInfo = ConstructorInfo.GetMethodFromHandle (ctor.MethodHandle, t.TypeHandle);
                                }
                        }
-
-                       return ctor;
                }
                
                public void MutateField (FieldSpec fs)
@@ -1053,7 +1054,7 @@ namespace Mono.CSharp {
                        // needed for the anonymous method.  We create the method here.
                        //
 
-                       MethodInfo invoke_mb = Delegate.GetInvokeMethod (ec.Compiler,
+                       var invoke_mb = Delegate.GetInvokeMethod (ec.Compiler,
                                ec.CurrentType, delegate_type);
                        Type return_type = TypeManager.TypeToCoreType (invoke_mb.ReturnType);
 
@@ -1629,12 +1630,12 @@ namespace Mono.CSharp {
 
                        ig.Emit (OpCodes.Ldftn, delegate_method);
 
-                       ConstructorInfo constructor_method = Delegate.GetConstructor (ec.MemberContext.Compiler, ec.CurrentType, type);
+                       var constructor_method = Delegate.GetConstructor (ec.MemberContext.Compiler, ec.CurrentType, type);
 #if MS_COMPATIBLE
-            if (type.IsGenericType && type is TypeBuilder)
-                constructor_method = TypeBuilder.GetConstructor (type, constructor_method);
+//            if (type.IsGenericType && type is TypeBuilder)
+//                constructor_method = TypeBuilder.GetConstructor (type, constructor_method);
 #endif
-                       ig.Emit (OpCodes.Newobj, constructor_method);
+                       ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method.MetaInfo);
 
                        if (am_cache != null) {
                                ig.Emit (OpCodes.Stsfld, am_cache.Spec.MetaInfo);
index bcbae60f2dcd9cf11e35a007c6dc010435bd33f2..be7ef05b475f2b050716b10e7111d74b73186541 100644 (file)
@@ -401,7 +401,7 @@ namespace Mono.CSharp {
                        }
 
                        ResolveContext rc = new ResolveContext (context, ResolveContext.Options.ConstantScope);
-                       ConstructorInfo ctor = ResolveConstructor (rc);
+                       var ctor = ResolveConstructor (rc);
                        if (ctor == null) {
                                if (Type is TypeBuilder && 
                                    TypeManager.LookupDeclSpace (Type).MemberCache == null)
@@ -414,12 +414,13 @@ namespace Mono.CSharp {
                        ApplyModuleCharSet (rc);
 
                        try {
+                               var ctor_meta = (ConstructorInfo) ctor.MetaInfo;
                                // SRE does not allow private ctor but we want to report all source code errors
-                               if (ctor.IsPrivate)
+                               if (ctor.MetaInfo.IsPrivate)
                                        return null;
 
                                if (NamedArguments == null) {
-                                       cb = new CustomAttributeBuilder (ctor, pos_values);
+                                       cb = new CustomAttributeBuilder (ctor_meta, pos_values);
 
                                        if (pos_values.Length == 0)
                                                att_cache.Add (Type, cb);
@@ -432,7 +433,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               cb = new CustomAttributeBuilder (ctor, pos_values,
+                               cb = new CustomAttributeBuilder (ctor_meta, pos_values,
                                                prop_info_arr, prop_values_arr,
                                                field_info_arr, field_values_arr);
 
@@ -445,7 +446,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected virtual ConstructorInfo ResolveConstructor (ResolveContext ec)
+               protected virtual MethodSpec ResolveConstructor (ResolveContext ec)
                {
                        if (PosArguments != null) {
                                bool dynamic;
@@ -468,14 +469,12 @@ namespace Mono.CSharp {
                        if (mg == null)
                                return null;
                        
-                       ConstructorInfo constructor = (ConstructorInfo)mg;
+                       var constructor = (MethodSpec) mg;
                        if (PosArguments == null) {
                                pos_values = EmptyObject;
                                return constructor;
                        }
 
-                       AParametersCollection pd = TypeManager.GetParameterData (constructor);
-
                        if (!PosArguments.GetAttributableValue (ec, out pos_values))
                                return null;
 
@@ -507,7 +506,7 @@ namespace Mono.CSharp {
                        }
 
                        if (Type == pa.MethodImpl && pos_values.Length == 1 &&
-                               pd.Types [0] == TypeManager.short_type &&
+                               constructor.Parameters.Types [0] == TypeManager.short_type &&
                                !System.Enum.IsDefined (typeof (MethodImplOptions), pos_values [0].ToString ())) {
                                Error_AttributeEmitError ("Incorrect argument value.");
                                return null;
@@ -1357,7 +1356,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override ConstructorInfo ResolveConstructor (ResolveContext ec)
+               protected override MethodSpec ResolveConstructor (ResolveContext ec)
                {
                        try {
                                Enter ();
index 30bcd3ad93f8d6bfbf71934145745c03f3453d49..4ed44e61411f6b11d9ca7dc56dcabaa2438cd75e 100644 (file)
@@ -2074,7 +2074,7 @@ namespace Mono.CSharp {
                                                        if (is_type_exposed)
                                                                continue;
 
-                                                       f.SetMemberIsUsed ();
+                                                       f.SetIsUsed ();
                                                }                               
                                                
                                                if (!f.IsUsed){
@@ -4569,7 +4569,7 @@ namespace Mono.CSharp {
                {
                        if (my_event != null) {
 //                             my_event.SetAssigned ();
-                               my_event.SetMemberIsUsed ();
+                               my_event.SetIsUsed ();
                        }
                }
        }
@@ -4630,7 +4630,7 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       SetMemberIsUsed ();
+                       SetIsUsed ();
                        return true;
                }
 
@@ -4745,7 +4745,7 @@ namespace Mono.CSharp {
                        }
 
                        if (!HasBackingField) {
-                               SetMemberIsUsed ();
+                               SetIsUsed ();
                                return true;
                        }
 
@@ -4753,10 +4753,10 @@ namespace Mono.CSharp {
                        // we are using FieldExpr instead of EventExpr for event access in that
                        // case.  When this issue will be fixed this hack can be removed.
                        if (TypeManager.IsGenericType (MemberType) || Parent.IsGeneric)
-                               SetMemberIsUsed ();
+                               SetIsUsed ();
 
                        if (Add.IsInterfaceImplementation)
-                               SetMemberIsUsed ();
+                               SetIsUsed ();
 
                        TypeManager.RegisterEventField (EventBuilder, this);
 
index 70412338ad5d3ddfcfc2a6dc71b8028545e91449..673554cf15654308f5e0ec76f41856b01bba693d 100644 (file)
@@ -153,8 +153,8 @@ namespace Mono.CSharp {
        {
                Expression value;
 
-               public ConstSpec (IMemberDetails details, FieldInfo fi, Modifiers mod, Expression value)
-                       : base (details, fi, mod)
+               public ConstSpec (IMemberDefinition definition, FieldInfo fi, Modifiers mod, Expression value)
+                       : base (definition, fi, mod)
                {
                        this.value = value;
                }
index c1e9980f2931e3930c3e6599ac6f30e20cc45093..533f828c4ff0711e234d29a9ec36e87322642295 100644 (file)
@@ -879,7 +879,7 @@ namespace Mono.CSharp {
                ///   by making use of FindMostEncomp* methods. Applies the correct rules separately
                ///   for explicit and implicit conversion operators.
                /// </summary>
-               static public Type FindMostSpecificSource (IList<MethodInfo> list,
+               static public Type FindMostSpecificSource (IList<MethodSpec> list,
                                                           Expression source, bool apply_explicit_conv_rules)
                {
                        var src_types_set = new List<Type> ();
@@ -888,9 +888,8 @@ namespace Mono.CSharp {
                        // If any operator converts from S then Sx = S
                        //
                        Type source_type = source.Type;
-                       foreach (MethodBase mb in list){
-                               AParametersCollection pd = TypeManager.GetParameterData (mb);
-                               Type param_type = pd.Types [0];
+                       foreach (var mb in list){
+                               Type param_type = mb.Parameters.Types [0];
 
                                if (param_type == source_type)
                                        return param_type;
@@ -925,7 +924,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///  Finds the most specific target Tx according to section 13.4.4
                /// </summary>
-               static public Type FindMostSpecificTarget (IList<MethodInfo> list,
+               static public Type FindMostSpecificTarget (IList<MethodSpec> list,
                                                           Type target, bool apply_explicit_conv_rules)
                {
                        var tgt_types_set = new List<Type> ();
@@ -933,7 +932,7 @@ namespace Mono.CSharp {
                        //
                        // If any operator converts to T then Tx = T
                        //
-                       foreach (MethodInfo mi in list){
+                       foreach (var mi in list){
                                Type ret_type = TypeManager.TypeToCoreType (mi.ReturnType);
                                if (ret_type == target)
                                        return ret_type;
@@ -989,7 +988,7 @@ namespace Mono.CSharp {
                        return UserDefinedConversion (ec, source, target, loc, true, true);
                }
 
-               static void AddConversionOperators (List<MethodInfo> list,
+               static void AddConversionOperators (List<MethodSpec> list,
                                                    Expression source, Type target_type,
                                                    bool look_for_explicit,
                                                    MethodGroupExpr mg)
@@ -1013,8 +1012,8 @@ namespace Mono.CSharp {
                                        target_type = TypeManager.uint64_type;
                        }
 
-                       foreach (MethodInfo m in mg.Methods) {
-                               AParametersCollection pd = TypeManager.GetParameterData (m);
+                       foreach (var m in mg.Methods) {
+                               AParametersCollection pd = m.Parameters;
                                Type return_type = TypeManager.TypeToCoreType (m.ReturnType);
                                Type arg_type = pd.Types [0];
 
@@ -1053,9 +1052,9 @@ namespace Mono.CSharp {
                ///   Compute the user-defined conversion operator from source_type to target_type.
                ///   `look_for_explicit' controls whether we should also include the list of explicit operators
                /// </summary>
-               static MethodInfo GetConversionOperator (CompilerContext ctx, Type container_type, Expression source, Type target_type, bool look_for_explicit)
+               static MethodSpec GetConversionOperator (CompilerContext ctx, Type container_type, Expression source, Type target_type, bool look_for_explicit)
                {
-                       var ops = new List<MethodInfo> (4);
+                       var ops = new List<MethodSpec> (4);
 
                        Type source_type = source.Type;
 
@@ -1090,12 +1089,12 @@ namespace Mono.CSharp {
                        if (most_specific_target == null)
                                return null;
 
-                       MethodInfo method = null;
+                       MethodSpec method = null;
 
-                       foreach (MethodInfo m in ops) {
+                       foreach (var m in ops) {
                                if (TypeManager.TypeToCoreType (m.ReturnType) != most_specific_target)
                                        continue;
-                               if (TypeManager.GetParameterData (m).Types [0] != most_specific_source)
+                               if (m.Parameters.Types [0] != most_specific_source)
                                        continue;
                                // Ambiguous: more than one conversion operator satisfies the signature.
                                if (method != null)
@@ -1114,7 +1113,7 @@ namespace Mono.CSharp {
                                                                bool look_for_explicit, bool return_convert)
                {
                        Type source_type = source.Type;
-                       MethodInfo method = null;
+                       MethodSpec method = null;
                        Expression expr = null;
 
                        object o;
@@ -1130,7 +1129,7 @@ namespace Mono.CSharp {
                        }                       
 
                        if (!(source is Constant) && hash.Lookup (source_type, target, out o)) {
-                               method = (MethodInfo) o;
+                               method = (MethodSpec) o;
                        } else {
                                if (TypeManager.IsDynamicType (source_type))
                                        return null;
@@ -1139,7 +1138,7 @@ namespace Mono.CSharp {
                        }
 
                        if (method != null) {
-                               Type most_specific_source = TypeManager.GetParameterData (method).Types[0];
+                               Type most_specific_source = method.Parameters.Types[0];
 
                                //
                                // This will do the conversion to the best match that we
index 9242735fe6464df3fb283f2ab9ca0d49c08a661c..270c7c4f5e89d818524cfd8cbe52371fbe8299c2 100644 (file)
@@ -247,7 +247,7 @@ namespace Mono.CSharp {
        ///   Base representation for members.  This is used to keep track
        ///   of Name, Location and Modifier flags, and handling Attributes.
        /// </summary>
-       public abstract class MemberCore : Attributable, IMemberContext, IMemberDetails
+       public abstract class MemberCore : Attributable, IMemberContext, IMemberDefinition
        {
                /// <summary>
                ///   Public name
@@ -462,7 +462,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void SetMemberIsUsed ()
+               public void SetIsUsed ()
                {
                        caching_flags |= Flags.IsUsed;
                }
@@ -900,17 +900,19 @@ namespace Mono.CSharp {
                protected readonly Modifiers modifiers;
                readonly string name;
                StateFlags state;
-               IMemberDetails details;
+               protected IMemberDefinition definition;
 
-               protected MemberSpec (IMemberDetails details, string name, Modifiers modifiers)
+               protected MemberSpec (IMemberDefinition definition, string name, Modifiers modifiers)
                {
-                       this.details = details;
+                       this.definition = definition;
                        this.name = name;
                        this.modifiers = modifiers;
 
                        state = StateFlags.Obsolete_Undetected;
                }
 
+               public abstract Type DeclaringType { get; }
+
                public ObsoleteAttribute GetObsoleteAttribute ()
                {
                        if ((state & (StateFlags.Obsolete | StateFlags.Obsolete_Undetected)) == 0)
@@ -918,16 +920,15 @@ namespace Mono.CSharp {
 
                        state &= ~StateFlags.Obsolete_Undetected;
 
-                       var oa = details.GetObsoleteAttribute ();
+                       var oa = definition.GetObsoleteAttribute ();
                        if (oa != null)
                                state |= StateFlags.Obsolete;
 
                        return oa;
                }
 
-               // TODO: Obsolete, remove after MemberCache
-               public IMemberDetails MemberDetails {
-                       get { return details; }
+               public IMemberDefinition MemberDefinition {
+                       get { return definition; }
                }
                
                public string Name {
@@ -939,9 +940,14 @@ namespace Mono.CSharp {
                }
        }
 
-       public interface IMemberDetails
+       //
+       // Member details which are same between all member
+       // specifications
+       //
+       public interface IMemberDefinition
        {
                ObsoleteAttribute GetObsoleteAttribute ();
+               void SetIsUsed ();
        }
 
        /// <summary>
@@ -2380,7 +2386,7 @@ namespace Mono.CSharp {
                //
                // Looks for extension methods with defined name and extension type
                //
-               public List<MethodBase> FindExtensionMethods (Assembly thisAssembly, Type extensionType, string name, bool publicOnly)
+               public List<MethodSpec> FindExtensionMethods (Assembly thisAssembly, Type extensionType, string name, bool publicOnly)
                {
                        List<CacheEntry> entries;
                        if (method_hash != null)
@@ -2395,7 +2401,7 @@ namespace Mono.CSharp {
                        EntryType entry_type = EntryType.Static | EntryType.Method | EntryType.NotExtensionMethod;
                        EntryType found_entry_type = entry_type & ~EntryType.NotExtensionMethod;
 
-                       List<MethodBase> candidates = null;
+                       List<MethodSpec> candidates = null;
                        foreach (CacheEntry entry in entries) {
                                if ((entry.EntryType & entry_type) == found_entry_type) {
                                        MethodBase mb = (MethodBase)entry.Member;
@@ -2420,11 +2426,9 @@ namespace Mono.CSharp {
                                                continue;
                                        }
 
-                                       //if (implicit conversion between ex_type and extensionType exist) {
-                                               if (candidates == null)
-                                                       candidates = new List<MethodBase> (2);
-                                               candidates.Add (mb);
-                                       //}
+                                       if (candidates == null)
+                                               candidates = new List<MethodSpec> (2);
+                                       candidates.Add (Import.CreateMethod (mb));
                                }
                        }
 
index 68de7b53ff781c5ca96ea8524d938a490837c0bf..a37822f9813196d9caa64345b26e54046907f499 100644 (file)
@@ -329,7 +329,7 @@ namespace Mono.CSharp {
                }
 
 
-               public static ConstructorInfo GetConstructor (CompilerContext ctx, Type container_type, Type delegate_type)
+               public static MethodSpec GetConstructor (CompilerContext ctx, Type container_type, Type delegate_type)
                {
                        Type dt = delegate_type;
                        Type[] g_args = null;
@@ -341,9 +341,9 @@ namespace Mono.CSharp {
                        Delegate d = TypeManager.LookupDelegate (delegate_type);
                        if (d != null) {
                                if (g_args != null)
-                                       return TypeBuilder.GetConstructor (dt, d.Constructor.ConstructorBuilder);
+                                       return Import.CreateMethod (TypeBuilder.GetConstructor (dt, d.Constructor.ConstructorBuilder));
 
-                               return d.Constructor.ConstructorBuilder;
+                               return d.Constructor.Spec;
                        }
 
                        Expression ml = Expression.MemberLookup (ctx, container_type,
@@ -357,14 +357,14 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       return (ConstructorInfo) mg.Methods[0];
+                       return mg.Methods[0];
                }
 
                //
                // Returns the MethodBase for "Invoke" from a delegate type, this is used
                // to extract the signature of a delegate.
                //
-               public static MethodInfo GetInvokeMethod (CompilerContext ctx, Type container_type, Type delegate_type)
+               public static MethodSpec GetInvokeMethod (CompilerContext ctx, Type container_type, Type delegate_type)
                {
                        Type dt = delegate_type;
 
@@ -375,17 +375,17 @@ namespace Mono.CSharp {
                        }
 
                        Delegate d = TypeManager.LookupDelegate (delegate_type);
-                       MethodInfo invoke;
+                       MethodSpec invoke;
                        if (d != null) {
                                if (g_args != null) {
-                                       invoke = TypeBuilder.GetMethod (dt, d.InvokeBuilder.MethodBuilder);
+                                       invoke = Import.CreateMethod (TypeBuilder.GetMethod (dt, d.InvokeBuilder.MethodBuilder));
 #if MS_COMPATIBLE
-                                       ParametersCompiled p = (ParametersCompiled) d.Parameters.InflateTypes (g_args, g_args);
-                                       TypeManager.RegisterMethod (invoke, p);
+//                                     ParametersCompiled p = (ParametersCompiled) d.Parameters.InflateTypes (g_args, g_args);
+//                                     TypeManager.RegisterMethod (invoke, p);
 #endif
                                        return invoke;
                                }
-                               return d.InvokeBuilder.MethodBuilder;
+                               return d.InvokeBuilder.Spec;
                        }
 
                        Expression ml = Expression.MemberLookup (ctx, container_type, null, dt,
@@ -398,14 +398,14 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       invoke = (MethodInfo) mg.Methods[0];
+                       invoke = mg.Methods[0];
 #if MS_COMPATIBLE
-                       if (g_args != null) {
-                               AParametersCollection p = TypeManager.GetParameterData (invoke);
-                               p = p.InflateTypes (g_args, g_args);
-                               TypeManager.RegisterMethod (invoke, p);
-                               return invoke;
-                       }
+//                     if (g_args != null) {
+//                             AParametersCollection p = TypeManager.GetParameterData (invoke);
+//                             p = p.InflateTypes (g_args, g_args);
+//                             TypeManager.RegisterMethod (invoke, p);
+//                             return invoke;
+//                     }
 #endif
 
                        return invoke;
@@ -430,9 +430,9 @@ namespace Mono.CSharp {
                        return Convert.ImplicitReferenceConversionExists (a, b);
                }
 
-               public static string FullDelegateDesc (MethodBase invoke_method)
+               public static string FullDelegateDesc (MethodSpec invoke_method)
                {
-                       return TypeManager.GetFullNameSignature (invoke_method).Replace (".Invoke", "");
+                       return TypeManager.GetFullNameSignature (invoke_method.MetaInfo).Replace (".Invoke", "");
                }
                
                public Expression InstanceExpression {
@@ -450,8 +450,8 @@ namespace Mono.CSharp {
        //
        public abstract class DelegateCreation : Expression, MethodGroupExpr.IErrorHandler
        {
-               protected ConstructorInfo constructor_method;
-               protected MethodInfo delegate_method;
+               protected MethodSpec constructor_method;
+               protected MethodSpec delegate_method;
                // We keep this to handle IsBase only
                protected MethodGroupExpr method_group;
                protected Expression delegate_instance_expression;
@@ -504,20 +504,20 @@ namespace Mono.CSharp {
                {
                        constructor_method = Delegate.GetConstructor (ec.Compiler, ec.CurrentType, type);
 
-                       MethodInfo invoke_method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, type);
+                       var invoke_method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, type);
                        method_group.DelegateType = type;
                        method_group.CustomErrorHandler = this;
 
-                       Arguments arguments = CreateDelegateMethodArguments (TypeManager.GetParameterData (invoke_method), loc);
+                       Arguments arguments = CreateDelegateMethodArguments (invoke_method.Parameters, loc);
                        method_group = method_group.OverloadResolve (ec, ref arguments, false, loc);
                        if (method_group == null)
                                return null;
 
-                       delegate_method = (MethodInfo) method_group;
+                       delegate_method = (MethodSpec) method_group;
                        
                        if (TypeManager.IsNullableType (delegate_method.DeclaringType)) {
                                ec.Report.Error (1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type",
-                                       TypeManager.GetFullNameSignature (delegate_method));
+                                       TypeManager.GetFullNameSignature (delegate_method.MetaInfo));
                                return null;
                        }               
                        
@@ -529,7 +529,7 @@ namespace Mono.CSharp {
                                Type e_type = delegate_instance_expression.Type;
                                if (TypeManager.IsValueType (e_type)) {
                                        ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
-                                               TypeManager.CSharpSignature (delegate_method), TypeManager.CSharpName (e_type));
+                                               TypeManager.CSharpSignature (delegate_method.MetaInfo), TypeManager.CSharpName (e_type));
                                }
                        }
 
@@ -540,14 +540,14 @@ namespace Mono.CSharp {
                        }
 
                        if (Invocation.IsMethodExcluded (delegate_method, loc)) {
-                               ec.Report.SymbolRelatedToPreviousError (delegate_method);
-                               MethodOrOperator m = TypeManager.GetMethod (delegate_method) as MethodOrOperator;
+                               ec.Report.SymbolRelatedToPreviousError (delegate_method.MetaInfo);
+                               MethodOrOperator m = TypeManager.GetMethod (delegate_method.MetaInfo) as MethodOrOperator;
                                if (m != null && m.IsPartialDefinition) {
                                        ec.Report.Error (762, loc, "Cannot create delegate from partial method declaration `{0}'",
-                                               TypeManager.CSharpSignature (delegate_method));
+                                               TypeManager.CSharpSignature (delegate_method.MetaInfo));
                                } else {
                                        ec.Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
-                                               TypeManager.CSharpSignature (delegate_method));
+                                               TypeManager.CSharpSignature (delegate_method.MetaInfo));
                                }
                        }
 
@@ -591,26 +591,26 @@ namespace Mono.CSharp {
 
                        if (!delegate_method.DeclaringType.IsSealed && delegate_method.IsVirtual && !method_group.IsBase) {
                                ec.ig.Emit (OpCodes.Dup);
-                               ec.ig.Emit (OpCodes.Ldvirtftn, delegate_method);
+                               ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method.MetaInfo);
                        } else {
-                               ec.ig.Emit (OpCodes.Ldftn, delegate_method);
+                               ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method.MetaInfo);
                        }
 
-                       ec.ig.Emit (OpCodes.Newobj, constructor_method);
+                       ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method.MetaInfo);
                }
 
-               void Error_ConversionFailed (ResolveContext ec, MethodBase method, Expression return_type)
+               void Error_ConversionFailed (ResolveContext ec, MethodSpec method, Expression return_type)
                {
-                       MethodInfo invoke_method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, type);
+                       var invoke_method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, type);
                        string member_name = delegate_instance_expression != null ?
                                Delegate.FullDelegateDesc (method) :
-                               TypeManager.GetFullNameSignature (method);
+                               TypeManager.GetFullNameSignature (method.MetaInfo);
 
                        ec.Report.SymbolRelatedToPreviousError (type);
-                       ec.Report.SymbolRelatedToPreviousError (method);
+                       ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                        if (RootContext.Version == LanguageVersion.ISO_1) {
                                ec.Report.Error (410, loc, "A method or delegate `{0} {1}' parameters and return type must be same as delegate `{2} {3}' parameters and return type",
-                                       TypeManager.CSharpName (((MethodInfo) method).ReturnType), member_name,
+                                       TypeManager.CSharpName (method.ReturnType), member_name,
                                        TypeManager.CSharpName (invoke_method.ReturnType), Delegate.FullDelegateDesc (invoke_method));
                                return;
                        }
@@ -631,9 +631,9 @@ namespace Mono.CSharp {
                                return false;
 
                        mg.DelegateType = target_type;
-                       MethodInfo invoke = Delegate.GetInvokeMethod (ec.Compiler, null, target_type);
+                       var invoke = Delegate.GetInvokeMethod (ec.Compiler, null, target_type);
 
-                       Arguments arguments = CreateDelegateMethodArguments (TypeManager.GetParameterData (invoke), mg.Location);
+                       Arguments arguments = CreateDelegateMethodArguments (invoke.Parameters, mg.Location);
                        return mg.OverloadResolve (ec, ref arguments, true, mg.Location) != null;
                }
 
@@ -642,22 +642,22 @@ namespace Mono.CSharp {
                        if (delegate_instance_expression != null)
                                delegate_instance_expression.MutateHoistedGenericType (storey);
 
-                       delegate_method = storey.MutateGenericMethod (delegate_method);
-                       constructor_method = storey.MutateConstructor (constructor_method);
+                       storey.MutateGenericMethod (delegate_method);
+                       storey.MutateConstructor (constructor_method);
                }
 
                #region IErrorHandler Members
 
-               public bool NoExactMatch (ResolveContext ec, MethodBase method)
+               public bool NoExactMatch (ResolveContext ec, MethodSpec method)
                {
-                       if (TypeManager.IsGenericMethod (method))
+                       if (method.IsGenericMethod)
                                return false;
 
                        Error_ConversionFailed (ec, method, null);
                        return true;
                }
 
-               public bool AmbiguousCall (ResolveContext ec, MethodBase ambiguous)
+               public bool AmbiguousCall (ResolveContext ec, MethodSpec ambiguous)
                {
                        return false;
                }
@@ -737,7 +737,7 @@ namespace Mono.CSharp {
                                // An argument is not a method but another delegate
                                //
                                delegate_instance_expression = e;
-                               method_group = new MethodGroupExpr (new MemberInfo [] { 
+                               method_group = new MethodGroupExpr (new [] { 
                                        Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, e.Type) }, e.Type, loc);
                        }
 
@@ -752,7 +752,7 @@ namespace Mono.CSharp {
        {
                readonly Expression InstanceExpr;
                Arguments arguments;
-               MethodInfo method;
+               MethodSpec method;
                
                public DelegateInvocation (Expression instance_expr, Arguments args, Location loc)
                {
@@ -781,11 +781,11 @@ namespace Mono.CSharp {
                                return null;
                        
                        method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, del_type);
-                       MethodBase mb = method;
+                       var mb = method;
                        var me = new MethodGroupExpr (new [] { mb }, del_type, loc);
                        me.InstanceExpression = InstanceExpr;
-                       
-                       AParametersCollection pd = TypeManager.GetParameterData (mb);
+
+                       AParametersCollection pd = mb.Parameters;
                        int pd_count = pd.Count;
 
                        int arg_count = arguments == null ? 0 : arguments.Count;
@@ -835,7 +835,7 @@ namespace Mono.CSharp {
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
                {
-                       method = storey.MutateGenericMethod (method);
+                       storey.MutateGenericMethod (method);
                        type = storey.MutateType (type);
 
                        if (arguments != null)
index 345c915047e16733bfcac87666bfe1f9702ed46c..821e4221748314d878c23052a116e683f1c74772 100644 (file)
 //
 //
 
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+using SLE = System.Linq.Expressions;
+using System.Linq;
+
 namespace Mono.CSharp {
-       using System;
-       using System.Collections.Generic;
-       using System.Diagnostics;
-       using System.Reflection;
-       using System.Reflection.Emit;
-       using System.Text;
-       using SLE = System.Linq.Expressions;
 
        /// <remarks>
        ///   The ExprClass class contains the is used to pass the 
@@ -147,9 +149,9 @@ namespace Mono.CSharp {
                        return TypeManager.CSharpName (type);
                }
 
-               public static bool IsAccessorAccessible (Type invocation_type, MethodInfo mi, out bool must_do_cs1540_check)
+               public static bool IsAccessorAccessible (Type invocation_type, MethodSpec mi, out bool must_do_cs1540_check)
                {
-                       MethodAttributes ma = mi.Attributes & MethodAttributes.MemberAccessMask;
+                       MethodAttributes ma = mi.MetaInfo.Attributes & MethodAttributes.MemberAccessMask;
 
                        must_do_cs1540_check = false; // by default we do not check for this
 
@@ -674,12 +676,12 @@ namespace Mono.CSharp {
 
                        if (mi.Length > 1) {
                                bool is_interface = qualifier_type != null && qualifier_type.IsInterface;
-                               var methods = new List<MethodBase> (2);
+                               var methods = new List<MethodSpec> (2);
                                List<MemberInfo> non_methods = null;
 
-                               foreach (MemberInfo m in mi) {
+                               foreach (var m in mi) {
                                        if (m is MethodBase) {
-                                               methods.Add ((MethodBase) m);
+                                               methods.Add (Import.CreateMethod ((MethodBase) m));
                                                continue;
                                        }
 
@@ -716,23 +718,23 @@ namespace Mono.CSharp {
                                        return ExprClassFromMemberInfo (container_type, (MemberInfo)non_methods [0], loc);
 
                                if (non_methods != null && non_methods.Count > 0) {
-                                       MethodBase method = (MethodBase) methods [0];
+                                       var method = methods [0];
                                        MemberInfo non_method = (MemberInfo) non_methods [0];
                                        if (method.DeclaringType == non_method.DeclaringType) {
                                                // Cannot happen with C# code, but is valid in IL
-                                               ctx.Report.SymbolRelatedToPreviousError (method);
+                                               ctx.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                                                ctx.Report.SymbolRelatedToPreviousError (non_method);
                                                ctx.Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
                                                              TypeManager.GetFullNameSignature (non_method),
-                                                             TypeManager.CSharpSignature (method));
+                                                             TypeManager.CSharpSignature (method.MetaInfo));
                                                return null;
                                        }
 
                                        if (is_interface) {
-                                               ctx.Report.SymbolRelatedToPreviousError (method);
+                                               ctx.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                                                ctx.Report.SymbolRelatedToPreviousError (non_method);
                                                ctx.Report.Warning (467, 2, loc, "Ambiguity between method `{0}' and non-method `{1}'. Using method `{0}'",
-                                                               TypeManager.CSharpSignature (method), TypeManager.GetFullNameSignature (non_method));
+                                                               TypeManager.CSharpSignature (method.MetaInfo), TypeManager.GetFullNameSignature (non_method));
                                        }
                                }
 
@@ -740,7 +742,7 @@ namespace Mono.CSharp {
                        }
 
                        if (mi [0] is MethodBase)
-                               return new MethodGroupExpr (mi, queried_type, loc);
+                               return new MethodGroupExpr (mi.Select (l => Import.CreateMethod ((MethodBase) l)).ToArray (), queried_type, loc);
 
                        return ExprClassFromMemberInfo (container_type, mi [0], loc);
                }
@@ -877,13 +879,16 @@ namespace Mono.CSharp {
 
                protected virtual Expression Error_MemberLookupFailed (ResolveContext ec, Type type, MemberInfo[] members)
                {
+                       List<MethodSpec> methods = new List<MethodSpec> ();
                        for (int i = 0; i < members.Length; ++i) {
                                if (!(members [i] is MethodBase))
                                        return null;
+
+                               methods.Add (Import.CreateMethod (members[i] as MethodBase));
                        }
 
                        // By default propagate the closest candidates upwards
-                       return new MethodGroupExpr (members, type, loc, true);
+                       return new MethodGroupExpr (methods.ToArray (), type, loc, true);
                }
 
                protected virtual void Error_NegativeArrayIndex (ResolveContext ec, Location loc)
@@ -3245,7 +3250,7 @@ namespace Mono.CSharp {
                public Expression ExtensionExpression;
                Argument extension_argument;
 
-               public ExtensionMethodGroupExpr (List<MethodBase> list, NamespaceEntry n, Type extensionType, Location l)
+               public ExtensionMethodGroupExpr (List<MethodSpec> list, NamespaceEntry n, Type extensionType, Location l)
                        : base (list, extensionType, l)
                {
                        this.namespace_entry = n;
@@ -3311,13 +3316,13 @@ namespace Mono.CSharp {
        {
                public interface IErrorHandler
                {
-                       bool AmbiguousCall (ResolveContext ec, MethodBase ambiguous);
-                       bool NoExactMatch (ResolveContext ec, MethodBase method);
+                       bool AmbiguousCall (ResolveContext ec, MethodSpec ambiguous);
+                       bool NoExactMatch (ResolveContext ec, MethodSpec method);
                }
 
-               public IErrorHandler CustomErrorHandler;                
-               public MethodBase [] Methods;
-               MethodBase best_candidate;
+               public IErrorHandler CustomErrorHandler;
+               public MethodSpec [] Methods;
+               MethodSpec best_candidate;
                // TODO: make private
                public TypeArguments type_arguments;
                bool identical_type_name;
@@ -3325,31 +3330,31 @@ namespace Mono.CSharp {
                Type delegate_type;
                Type queried_type;
                
-               public MethodGroupExpr (MemberInfo [] mi, Type type, Location l)
+               public MethodGroupExpr (MethodSpec [] mi, Type type, Location l)
                        : this (type, l)
                {
-                       Methods = new MethodBase [mi.Length];
+                       Methods = new MethodSpec[mi.Length];
                        mi.CopyTo (Methods, 0);
                }
 
-               public MethodGroupExpr (MemberInfo[] mi, Type type, Location l, bool inacessibleCandidatesOnly)
+               public MethodGroupExpr (MethodSpec[] mi, Type type, Location l, bool inacessibleCandidatesOnly)
                        : this (mi, type, l)
                {
                        has_inaccessible_candidates_only = inacessibleCandidatesOnly;
                }
 
-               public MethodGroupExpr (List<MethodBase> list, Type type, Location l)
+               public MethodGroupExpr (List<MethodSpec> list, Type type, Location l)
                        : this (type, l)
                {
                        try {
                                Methods = list.ToArray ();
                        } catch {
-                               foreach (MemberInfo m in list){
-                                       if (!(m is MethodBase)){
-                                               Console.WriteLine ("Name " + m.Name);
-                                               Console.WriteLine ("Found a: " + m.GetType ().FullName);
-                                       }
-                               }
+                               //foreach (MemberInfo m in list){
+                               //    if (!(m is MethodBase)){
+                               //        Console.WriteLine ("Name " + m.Name);
+                               //        Console.WriteLine ("Found a: " + m.GetType ().FullName);
+                               //    }
+                               //}
                                throw;
                        }
 
@@ -3370,6 +3375,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public MethodSpec BestCandidate {
+                       get {
+                               return best_candidate;
+                       }
+               }
+
                public Type DelegateType {
                        set {
                                delegate_type = value;
@@ -3385,9 +3396,9 @@ namespace Mono.CSharp {
                public override string GetSignatureForError ()
                {
                        if (best_candidate != null)
-                               return TypeManager.CSharpSignature (best_candidate);
+                               return TypeManager.CSharpSignature (best_candidate.MetaInfo);
                        
-                       return TypeManager.CSharpSignature (Methods [0]);
+                       return TypeManager.CSharpSignature (Methods [0].MetaInfo);
                }
 
                public override string Name {
@@ -3401,7 +3412,7 @@ namespace Mono.CSharp {
                                if (best_candidate != null)
                                        return !best_candidate.IsStatic;
 
-                               foreach (MethodBase mb in Methods)
+                               foreach (var mb in Methods)
                                        if (!mb.IsStatic)
                                                return true;
 
@@ -3414,22 +3425,17 @@ namespace Mono.CSharp {
                                if (best_candidate != null)
                                        return best_candidate.IsStatic;
 
-                               foreach (MethodBase mb in Methods)
+                               foreach (var mb in Methods)
                                        if (mb.IsStatic)
                                                return true;
 
                                return false;
                        }
                }
-               
-               public static explicit operator ConstructorInfo (MethodGroupExpr mg)
-               {
-                       return (ConstructorInfo)mg.best_candidate;
-               }
 
-               public static explicit operator MethodInfo (MethodGroupExpr mg)
+               public static explicit operator MethodSpec (MethodGroupExpr mg)
                {
-                       return (MethodInfo)mg.best_candidate;
+                       return mg.best_candidate;
                }
 
                //
@@ -3541,11 +3547,11 @@ namespace Mono.CSharp {
                ///     true  if candidate is better than the current best match
                /// </remarks>
                static bool BetterFunction (ResolveContext ec, Arguments args, int argument_count,
-                       MethodBase candidate, bool candidate_params,
-                       MethodBase best, bool best_params)
+                       MethodSpec candidate, bool candidate_params,
+                       MethodSpec best, bool best_params)
                {
-                       AParametersCollection candidate_pd = TypeManager.GetParameterData (candidate);
-                       AParametersCollection best_pd = TypeManager.GetParameterData (best);
+                       AParametersCollection candidate_pd = candidate.Parameters;
+                       AParametersCollection best_pd = best.Parameters;
                
                        bool better_at_least_one = false;
                        bool same = true;
@@ -3607,10 +3613,10 @@ namespace Mono.CSharp {
                        //
                        // The two methods have equal parameter types.  Now apply tie-breaking rules
                        //
-                       if (TypeManager.IsGenericMethod (best)) {
-                               if (!TypeManager.IsGenericMethod (candidate))
+                       if (best.IsGenericMethod) {
+                               if (!candidate.IsGenericMethod)
                                        return true;
-                       } else if (TypeManager.IsGenericMethod (candidate)) {
+                       } else if (candidate.IsGenericMethod) {
                                return false;
                        }
 
@@ -3698,7 +3704,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       IMethodData md = TypeManager.GetMethod (best_candidate);
+                       IMethodData md = TypeManager.GetMethod (best_candidate.MetaInfo);
                        if (md != null && md.IsExcluded ())
                                ec.Report.Error (765, loc,
                                        "Partial methods with only a defining declaration or removed conditional methods cannot be used in an expression tree");
@@ -3736,23 +3742,23 @@ namespace Mono.CSharp {
                        Invocation.EmitCall (ec, IsBase, InstanceExpression, best_candidate, arguments, loc);                   
                }
 
-               void Error_AmbiguousCall (ResolveContext ec, MethodBase ambiguous)
+               void Error_AmbiguousCall (ResolveContext ec, MethodSpec ambiguous)
                {
                        if (CustomErrorHandler != null && CustomErrorHandler.AmbiguousCall (ec, ambiguous))
                                return;
 
-                       ec.Report.SymbolRelatedToPreviousError (best_candidate);
+                       ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
                        ec.Report.Error (121, loc, "The call is ambiguous between the following methods or properties: `{0}' and `{1}'",
-                               TypeManager.CSharpSignature (ambiguous), TypeManager.CSharpSignature (best_candidate));
+                               TypeManager.CSharpSignature (ambiguous), TypeManager.CSharpSignature (best_candidate.MetaInfo));
                }
 
-               protected virtual void Error_InvalidArguments (ResolveContext ec, Location loc, int idx, MethodBase method,
+               protected virtual void Error_InvalidArguments (ResolveContext ec, Location loc, int idx, MethodSpec method,
                                                                                                        Argument a, AParametersCollection expected_par, Type paramType)
                {
                        ExtensionMethodGroupExpr emg = this as ExtensionMethodGroupExpr;
 
                        if (a is CollectionElementInitializer.ElementInitializerArgument) {
-                               ec.Report.SymbolRelatedToPreviousError (method);
+                               ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                                if ((expected_par.FixedParameters [idx].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
                                        ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier",
                                                TypeManager.CSharpSignature (method));
@@ -3764,7 +3770,7 @@ namespace Mono.CSharp {
                                ec.Report.Error (1594, loc, "Delegate `{0}' has some invalid arguments",
                                        TypeManager.CSharpName (method.DeclaringType));
                        } else {
-                               ec.Report.SymbolRelatedToPreviousError (method);
+                               ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                                if (emg != null) {
                                        ec.Report.Error (1928, loc,
                                                "Type `{0}' does not contain a member `{1}' and the best extension method overload `{2}' has some invalid arguments",
@@ -3819,7 +3825,7 @@ namespace Mono.CSharp {
                                      Name, arg_count.ToString ());
                }
                
-               protected virtual int GetApplicableParametersCount (MethodBase method, AParametersCollection parameters)
+               protected virtual int GetApplicableParametersCount (MethodSpec method, AParametersCollection parameters)
                {
                        return parameters.Count;
                }               
@@ -3838,11 +3844,11 @@ namespace Mono.CSharp {
                /// 0 = the best, int.MaxValue = the worst
                ///
                public int IsApplicable (ResolveContext ec,
-                                               ref Arguments arguments, int arg_count, ref MethodBase method, ref bool params_expanded_form)
+                                               ref Arguments arguments, int arg_count, ref MethodSpec method, ref bool params_expanded_form)
                {
-                       MethodBase candidate = method;
+                       var candidate = method;
 
-                       AParametersCollection pd = TypeManager.GetParameterData (candidate);
+                       AParametersCollection pd = candidate.Parameters;
                        int param_count = GetApplicableParametersCount (candidate, pd);
                        int optional_count = 0;
 
@@ -3854,7 +3860,7 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               int args_gap = Math.Abs (arg_count - param_count);
+                               int args_gap = System.Math.Abs (arg_count - param_count);
                                if (optional_count != 0) {
                                        if (args_gap > optional_count)
                                                return int.MaxValue - 10000 + args_gap - optional_count;
@@ -3940,26 +3946,25 @@ namespace Mono.CSharp {
                        //
                        // 1. Handle generic method using type arguments when specified or type inference
                        //
-                       if (TypeManager.IsGenericMethod (candidate)) {
+                       if (candidate.IsGenericMethod) {
                                if (type_arguments != null) {
                                        Type [] g_args = candidate.GetGenericArguments ();
                                        if (g_args.Length != type_arguments.Count)
-                                               return int.MaxValue - 20000 + Math.Abs (type_arguments.Count - g_args.Length);
+                                               return int.MaxValue - 20000 + System.Math.Abs (type_arguments.Count - g_args.Length);
 
-                                       // TODO: Don't create new method, create Parameters only
-                                       method = TypeManager.MakeGenericMethod ((MethodInfo) candidate, type_arguments.Arguments);
+                                       method = candidate.Inflate (type_arguments.Arguments);
                                        candidate = method;
-                                       pd = TypeManager.GetParameterData (candidate);
+                                       pd = candidate.Parameters;
                                } else {
                                        int score = TypeManager.InferTypeArguments (ec, arguments, ref candidate);
                                        if (score != 0)
                                                return score - 20000;
 
-                                       if (TypeManager.IsGenericMethodDefinition (candidate))
+                                       if (TypeManager.IsGenericMethodDefinition (candidate.MetaInfo))
                                                throw new InternalErrorException ("A generic method `{0}' definition took part in overload resolution",
-                                                       TypeManager.CSharpSignature (candidate));
+                                                       TypeManager.CSharpSignature (candidate.MetaInfo));
 
-                                       pd = TypeManager.GetParameterData (candidate);
+                                       pd = candidate.Parameters;
                                }
                        } else {
                                if (type_arguments != null)
@@ -4088,9 +4093,9 @@ namespace Mono.CSharp {
                        if (mg2 == null)
                                return mg1;
 
-                       var all = new List<MethodBase> (mg1.Methods);
-                       foreach (MethodBase m in mg2.Methods){
-                               if (!TypeManager.ArrayContainsMethod (mg1.Methods, m, false))
+                       var all = new List<MethodSpec> (mg1.Methods);
+                       foreach (var m in mg2.Methods){
+                               if (!TypeManager.ArrayContainsMethod (mg1.Methods.Select (l => l.MetaInfo).ToArray (), m.MetaInfo, false))
                                        all.Add (m);
                        }
 
@@ -4144,13 +4149,11 @@ namespace Mono.CSharp {
                {
                        base.MutateHoistedGenericType (storey);
 
-                       MethodInfo mi = best_candidate as MethodInfo;
-                       if (mi != null) {
-                               best_candidate = storey.MutateGenericMethod (mi);
-                               return;
+                       if (best_candidate.IsConstructor) {
+                               storey.MutateConstructor (best_candidate);
+                       } else {
+                               storey.MutateGenericMethod (best_candidate);                            
                        }
-
-                       best_candidate = storey.MutateConstructor ((ConstructorInfo) this);
                }
 
                /// <summary>
@@ -4174,8 +4177,8 @@ namespace Mono.CSharp {
                {
                        bool method_params = false;
                        Type applicable_type = null;
-                       var candidates = new List<MethodBase> (2);
-                       List<MethodBase> candidate_overrides = null;
+                       var candidates = new List<MethodSpec> (2);
+                       List<MethodSpec> candidate_overrides = null;
 
                        //
                        // Used to keep a map between the candidate
@@ -4184,8 +4187,8 @@ namespace Mono.CSharp {
                        //
                        // false is normal form, true is expanded form
                        //
-                       Dictionary<MethodBase, MethodBase> candidate_to_form = null;
-                       Dictionary<MethodBase, Arguments> candidates_expanded = null;
+                       Dictionary<MethodSpec, MethodSpec> candidate_to_form = null;
+                       Dictionary<MethodSpec, Arguments> candidates_expanded = null;
                        Arguments candidate_args = Arguments;
 
                        int arg_count = Arguments != null ? Arguments.Count : 0;
@@ -4210,18 +4213,20 @@ namespace Mono.CSharp {
                                // with non-C# libraries which change the visibility of overrides (#75636)
                                //
                                int j = 0;
+                               MethodBase mb = null;
                                for (int i = 0; i < Methods.Length; ++i) {
-                                       MethodBase m = Methods [i];
+                                       var m = Methods [i];
+                                       mb = m.MetaInfo;
                                        if (TypeManager.IsOverride (m)) {
                                                if (candidate_overrides == null)
-                                                       candidate_overrides = new List<MethodBase> ();
+                                                       candidate_overrides = new List<MethodSpec> ();
                                                candidate_overrides.Add (m);
-                                               m = TypeManager.TryGetBaseDefinition (m);
-                                               if (m != null && Array.Exists (Methods, l => l == m))
+                                               mb = TypeManager.TryGetBaseDefinition (mb);
+                                               if (mb != null && Array.Exists (Methods, l => l.MetaInfo == mb))
                                                        continue;
                                        }
-                                       if (m != null)
-                                               Methods [j++] = m;
+                                       if (mb != null)
+                                               Methods [j++] = Import.CreateMethod (mb);
                                }
                                nmethods = j;
                        }
@@ -4260,14 +4265,14 @@ namespace Mono.CSharp {
                                
                                if (params_expanded_form) {
                                        if (candidate_to_form == null)
-                                               candidate_to_form = new Dictionary<MethodBase, MethodBase> (4, ReferenceEquality<MethodBase>.Default);
-                                       MethodBase candidate = Methods [i];
+                                               candidate_to_form = new Dictionary<MethodSpec, MethodSpec> (4, ReferenceEquality<MethodSpec>.Default);
+                                       var candidate = Methods [i];
                                        candidate_to_form [candidate] = candidate;
                                }
                                
                                if (candidate_args != Arguments) {
                                        if (candidates_expanded == null)
-                                               candidates_expanded = new Dictionary<MethodBase, Arguments> (4, ReferenceEquality<MethodBase>.Default);
+                                               candidates_expanded = new Dictionary<MethodSpec, Arguments> (4, ReferenceEquality<MethodSpec>.Default);
 
                                        candidates_expanded.Add (Methods [i], candidate_args);
                                        candidate_args = Arguments;
@@ -4372,7 +4377,7 @@ namespace Mono.CSharp {
                                        int j = finalized; // where to put the next finalized candidate
                                        int k = finalized; // where to put the next undiscarded candidate
                                        for (int i = finalized; i < candidate_top; ++i) {
-                                               MethodBase candidate = candidates [i];
+                                               var candidate = candidates [i];
                                                Type decl_type = candidate.DeclaringType;
 
                                                if (decl_type == applicable_type) {
@@ -4418,9 +4423,9 @@ namespace Mono.CSharp {
                        }
 
                        for (int ix = 1; ix < candidate_top; ix++) {
-                               MethodBase candidate = (MethodBase) candidates [ix];
+                               var candidate = candidates [ix];
 
-                               if (candidate == best_candidate)
+                               if (candidate.MetaInfo == best_candidate.MetaInfo)
                                        continue;
 
                                bool cand_params = candidate_to_form != null && candidate_to_form.ContainsKey (candidate);
@@ -4436,11 +4441,11 @@ namespace Mono.CSharp {
                        // Now check that there are no ambiguities i.e the selected method
                        // should be better than all the others
                        //
-                       MethodBase ambiguous = null;
+                       MethodSpec ambiguous = null;
                        for (int ix = 1; ix < candidate_top; ix++) {
-                               MethodBase candidate = candidates [ix];
+                               var candidate = candidates [ix];
 
-                               if (candidate == best_candidate)
+                               if (candidate.MetaInfo == best_candidate.MetaInfo)
                                        continue;
 
                                bool cand_params = candidate_to_form != null && candidate_to_form.ContainsKey (candidate);
@@ -4449,7 +4454,7 @@ namespace Mono.CSharp {
                                        candidate, cand_params)) 
                                {
                                        if (!may_fail)
-                                               ec.Report.SymbolRelatedToPreviousError (candidate);
+                                               ec.Report.SymbolRelatedToPreviousError (candidate.MetaInfo);
                                        ambiguous = candidate;
                                }
                        }
@@ -4470,29 +4475,29 @@ namespace Mono.CSharp {
                                if (candidate_overrides != null) {
                                        Type[] gen_args = null;
                                        bool gen_override = false;
-                                       if (TypeManager.IsGenericMethod (best_candidate))
-                                               gen_args = TypeManager.GetGenericArguments (best_candidate);
+                                       if (best_candidate.IsGenericMethod)
+                                               gen_args = TypeManager.GetGenericArguments (best_candidate.MetaInfo);
 
-                                       foreach (MethodBase candidate in candidate_overrides) {
-                                               if (TypeManager.IsGenericMethod (candidate)) {
+                                       foreach (var candidate in candidate_overrides) {
+                                               if (candidate.IsGenericMethod) {
                                                        if (gen_args == null)
                                                                continue;
 
-                                                       if (gen_args.Length != TypeManager.GetGenericArguments (candidate).Length)
+                                                       if (gen_args.Length != TypeManager.GetGenericArguments (candidate.MetaInfo).Length)
                                                                continue;
                                                } else {
                                                        if (gen_args != null)
                                                                continue;
                                                }
                                                
-                                               if (IsOverride (candidate, best_candidate)) {
+                                               if (IsOverride (candidate.MetaInfo, best_candidate.MetaInfo)) {
                                                        gen_override = true;
                                                        best_candidate = candidate;
                                                }
                                        }
 
                                        if (gen_override && gen_args != null) {
-                                               best_candidate = ((MethodInfo) best_candidate).MakeGenericMethod (gen_args);
+                                               best_candidate = best_candidate.Inflate (gen_args);
                                        }
                                }
                        }
@@ -4512,7 +4517,7 @@ namespace Mono.CSharp {
 
                        MethodBase the_method = TypeManager.DropGenericMethodArguments (best_candidate);
                        if (TypeManager.IsGenericMethodDefinition (the_method) &&
-                           !ConstraintChecker.CheckConstraints (ec, the_method, best_candidate, loc))
+                           !ConstraintChecker.CheckConstraints (ec, the_method, best_candidate.MetaInfo, loc))
                                return null;
 
                        //
@@ -4524,37 +4529,37 @@ namespace Mono.CSharp {
 
                        IMethodData data = TypeManager.GetMethod (the_method);
                        if (data != null)
-                               data.SetMemberIsUsed ();
+                               data.SetIsUsed ();
 
                        Arguments = candidate_args;
                        return this;
                }
 
-               bool NoExactMatch (ResolveContext ec, ref Arguments Arguments, IDictionary<MethodBase, MethodBase> candidate_to_form)
+               bool NoExactMatch (ResolveContext ec, ref Arguments Arguments, IDictionary<MethodSpec, MethodSpec> candidate_to_form)
                {
-                       AParametersCollection pd = TypeManager.GetParameterData (best_candidate);
+                       AParametersCollection pd = best_candidate.Parameters;
                        int arg_count = Arguments == null ? 0 : Arguments.Count;
 
                        if (arg_count == pd.Count || pd.HasParams) {
-                               if (TypeManager.IsGenericMethodDefinition (best_candidate)) {
+                               if (TypeManager.IsGenericMethodDefinition (best_candidate.MetaInfo)) {
                                        if (type_arguments == null) {
                                                ec.Report.Error (411, loc,
                                                        "The type arguments for method `{0}' cannot be inferred from " +
                                                        "the usage. Try specifying the type arguments explicitly",
-                                                       TypeManager.CSharpSignature (best_candidate));
+                                                       TypeManager.CSharpSignature (best_candidate.MetaInfo));
                                                return true;
                                        }
 
-                                       Type[] g_args = TypeManager.GetGenericArguments (best_candidate);
+                                       Type[] g_args = TypeManager.GetGenericArguments (best_candidate.MetaInfo);
                                        if (type_arguments.Count != g_args.Length) {
-                                               ec.Report.SymbolRelatedToPreviousError (best_candidate);
+                                               ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
                                                ec.Report.Error (305, loc, "Using the generic method `{0}' requires `{1}' type argument(s)",
-                                                       TypeManager.CSharpSignature (best_candidate),
+                                                       TypeManager.CSharpSignature (best_candidate.MetaInfo),
                                                        g_args.Length.ToString ());
                                                return true;
                                        }
                                } else {
-                                       if (type_arguments != null && !TypeManager.IsGenericMethod (best_candidate)) {
+                                       if (type_arguments != null && !best_candidate.IsGenericMethod) {
                                                Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
                                                return true;
                                        }
@@ -4567,9 +4572,9 @@ namespace Mono.CSharp {
                                                // base class (CS1540).  If the qualifier_type is a base of the
                                                // ec.CurrentType and the lookup succeeds with the latter one,
                                                // then we are in this situation.
-                                               Error_CannotAccessProtected (ec, loc, best_candidate, queried_type, ec.CurrentType);
+                                               Error_CannotAccessProtected (ec, loc, best_candidate.MetaInfo, queried_type, ec.CurrentType);
                                        } else {
-                                               ec.Report.SymbolRelatedToPreviousError (best_candidate);
+                                               ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
                                                ErrorIsInaccesible (loc, GetSignatureForError (), ec.Report);
                                        }
                                }
@@ -4591,11 +4596,11 @@ namespace Mono.CSharp {
                }
 
                public bool VerifyArgumentsCompat (ResolveContext ec, ref Arguments arguments,
-                                                         int arg_count, MethodBase method,
+                                                         int arg_count, MethodSpec method,
                                                          bool chose_params_expanded,
                                                          bool may_fail, Location loc)
                {
-                       AParametersCollection pd = TypeManager.GetParameterData (method);
+                       AParametersCollection pd = method.Parameters;
                        int param_count = GetApplicableParametersCount (method, pd);
 
                        int errors = ec.Report.Errors;
@@ -4604,7 +4609,7 @@ namespace Mono.CSharp {
                        int a_idx = 0, a_pos = 0;
                        Argument a = null;
                        ArrayInitializer params_initializers = null;
-                       bool has_unsafe_arg = method is MethodInfo ? ((MethodInfo) method).ReturnType.IsPointer : false;
+                       bool has_unsafe_arg = method.ReturnType.IsPointer;
 
                        for (; a_idx < arg_count; a_idx++, ++a_pos) {
                                a = arguments [a_idx];
@@ -4643,16 +4648,16 @@ namespace Mono.CSharp {
                                                                        "The delegate `{0}' does not contain a parameter named `{1}'",
                                                                        TypeManager.CSharpName (DeclaringType), na.Name);
                                                        } else {
-                                                               ec.Report.SymbolRelatedToPreviousError (best_candidate);
+                                                               ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
                                                                ec.Report.Error (1739, na.Location,
                                                                        "The best overloaded method match for `{0}' does not contain a parameter named `{1}'",
-                                                                       TypeManager.CSharpSignature (method), na.Name);
+                                                                       TypeManager.CSharpSignature (method.MetaInfo), na.Name);
                                                        }
                                                } else if (arguments[name_index] != a) {
                                                        if (DeclaringType != null && TypeManager.IsDelegateType (DeclaringType))
                                                                ec.Report.SymbolRelatedToPreviousError (DeclaringType);
                                                        else
-                                                               ec.Report.SymbolRelatedToPreviousError (best_candidate);
+                                                               ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
 
                                                        ec.Report.Error (1744, na.Location,
                                                                "Named argument `{0}' cannot be used for a parameter which has positional argument specified",
@@ -4768,7 +4773,7 @@ namespace Mono.CSharp {
 
                protected override Expression DoResolve (ResolveContext rc)
                {
-//                     constant.IsUsed = true;
+                       constant.MemberDefinition.SetIsUsed ();
 
                        if (!rc.IsObsolete) {
                                var oa = constant.GetObsoleteAttribute ();
@@ -4911,7 +4916,7 @@ namespace Mono.CSharp {
 
                public Expression CreateTypeOfExpression ()
                {
-                       return new TypeOfField (GetConstructedFieldInfo (), loc);
+                       return new TypeOfField (Import.CreateField (GetConstructedFieldInfo ()), loc);
                }
 
                protected override Expression DoResolve (ResolveContext ec)
@@ -5164,7 +5169,7 @@ namespace Mono.CSharp {
                                if ((f.ModFlags & Modifiers.VOLATILE) != 0)
                                        is_volatile = true;
 
-                               f.SetMemberIsUsed ();
+                               f.SetIsUsed ();
                        }
                        
                        if (IsStatic){
@@ -5270,7 +5275,7 @@ namespace Mono.CSharp {
                                if ((mode & AddressOp.Store) != 0)
                                        f.SetAssigned ();
                                if ((mode & AddressOp.Load) != 0)
-                                       f.SetMemberIsUsed ();
+                                       f.SetIsUsed ();
                        }
 
                        //
@@ -5345,7 +5350,7 @@ namespace Mono.CSharp {
        public class PropertyExpr : MemberExpr, IDynamicAssign
        {
                public readonly PropertyInfo PropertyInfo;
-               MethodInfo getter, setter;
+               MethodSpec getter, setter;
                bool is_static;
 
                TypeArguments targs;
@@ -5442,13 +5447,19 @@ namespace Mono.CSharp {
 
                                PropertyInfo pi = (PropertyInfo) group [0];
 
-                               if (getter == null)
-                                       getter = pi.GetGetMethod (true);
+                               if (getter == null) {
+                                       var m = pi.GetGetMethod (true);
+                                       if (m != null)
+                                               getter = Import.CreateMethod (m);
+                               }
 
-                               if (setter == null)
-                                       setter = pi.GetSetMethod (true);
+                               if (setter == null) {
+                                       var m = pi.GetSetMethod (true);
+                                       if (m != null)
+                                               setter = Import.CreateMethod (m);
+                               }
 
-                               MethodInfo accessor = getter != null ? getter : setter;
+                               var accessor = getter != null ? getter : setter;
 
                                if (!accessor.IsVirtual)
                                        return;
@@ -5468,7 +5479,7 @@ namespace Mono.CSharp {
                                MethodBase the_getter = TypeManager.DropGenericMethodArguments (getter);
                                IMethodData md = TypeManager.GetMethod (the_getter);
                                if (md != null)
-                                       md.SetMemberIsUsed ();
+                                       md.SetIsUsed ();
 
                                is_static = getter.IsStatic;
                        }
@@ -5477,7 +5488,7 @@ namespace Mono.CSharp {
                                MethodBase the_setter = TypeManager.DropGenericMethodArguments (setter);
                                IMethodData md = TypeManager.GetMethod (the_setter);
                                if (md != null)
-                                       md.SetMemberIsUsed ();
+                                       md.SetIsUsed ();
 
                                is_static = setter.IsStatic;
                        }
@@ -5485,12 +5496,12 @@ namespace Mono.CSharp {
 
                public SLE.Expression MakeAssignExpression (BuilderContext ctx)
                {
-                       return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), setter);
+                       return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), (MethodInfo) setter.MetaInfo);
                }
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), getter);
+                       return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), (MethodInfo) getter.MetaInfo);
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
@@ -5500,9 +5511,9 @@ namespace Mono.CSharp {
 
                        type = storey.MutateType (type);
                        if (getter != null)
-                               getter = storey.MutateGenericMethod (getter);
+                               storey.MutateGenericMethod (getter);
                        if (setter != null)
-                               setter = storey.MutateGenericMethod (setter);
+                               storey.MutateGenericMethod (setter);
                }
 
                bool InstanceResolve (ResolveContext ec, bool lvalue_instance, bool must_do_cs1540_check)
@@ -5538,22 +5549,22 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               void Error_PropertyNotFound (ResolveContext ec, MethodInfo mi, bool getter)
+               void Error_PropertyNotFound (ResolveContext ec, MethodSpec mi, bool getter)
                {
                        // TODO: correctly we should compare arguments but it will lead to bigger changes
-                       if (mi is MethodBuilder) {
+                       if (mi.MetaInfo is MethodBuilder) {
                                Error_TypeDoesNotContainDefinition (ec, loc, PropertyInfo.DeclaringType, Name);
                                return;
                        }
                        
                        StringBuilder sig = new StringBuilder (TypeManager.CSharpName (mi.DeclaringType));
                        sig.Append ('.');
-                       AParametersCollection iparams = TypeManager.GetParameterData (mi);
+                       AParametersCollection iparams = mi.Parameters;
                        sig.Append (getter ? "get_" : "set_");
                        sig.Append (Name);
                        sig.Append (iparams.GetSignatureForError ());
 
-                       ec.Report.SymbolRelatedToPreviousError (mi);
+                       ec.Report.SymbolRelatedToPreviousError (mi.MetaInfo);
                        ec.Report.Error (1546, loc, "Property `{0}' is not supported by the C# language. Try to call the accessor method `{1}' directly",
                                Name, sig.ToString ());
                }
@@ -5561,7 +5572,7 @@ namespace Mono.CSharp {
                public bool IsAccessibleFrom (Type invocation_type, bool lvalue)
                {
                        bool dummy;
-                       MethodInfo accessor = lvalue ? setter : getter;
+                       var accessor = lvalue ? setter : getter;
                        if (accessor == null && lvalue)
                                accessor = getter;
                        return accessor != null && IsAccessorAccessible (invocation_type, accessor, out dummy);
@@ -5672,21 +5683,21 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (TypeManager.GetParameterData (setter).Count != 1){
+                       if (setter.Parameters.Count != 1){
                                Error_PropertyNotFound (ec, setter, false);
                                return null;
                        }
 
                        bool must_do_cs1540_check;
                        if (!IsAccessorAccessible (ec.CurrentType, setter, out must_do_cs1540_check)) {
-                               PropertyBase.PropertyMethod pm = TypeManager.GetMethod (setter) as PropertyBase.PropertyMethod;
+                               PropertyBase.PropertyMethod pm = TypeManager.GetMethod (setter.MetaInfo) as PropertyBase.PropertyMethod;
                                if (pm != null && pm.HasCustomAccessModifier) {
                                        ec.Report.SymbolRelatedToPreviousError (pm);
                                        ec.Report.Error (272, loc, "The property or indexer `{0}' cannot be used in this context because the set accessor is inaccessible",
                                                TypeManager.CSharpSignature (setter));
                                }
                                else {
-                                       ec.Report.SymbolRelatedToPreviousError (setter);
+                                       ec.Report.SymbolRelatedToPreviousError (setter.MetaInfo);
                                        ErrorIsInaccesible (loc, TypeManager.CSharpSignature (setter), ec.Report);
                                }
                                return null;
@@ -5793,7 +5804,7 @@ namespace Mono.CSharp {
                        }
 
                        if (getter != null) {
-                               if (TypeManager.GetParameterData (getter).Count != 0) {
+                               if (!getter.Parameters.IsEmpty) {
                                        Error_PropertyNotFound (ec, getter, true);
                                        return false;
                                }
@@ -5818,14 +5829,14 @@ namespace Mono.CSharp {
 
                        if (getter != null &&
                                !IsAccessorAccessible (ec.CurrentType, getter, out must_do_cs1540_check)) {
-                               PropertyBase.PropertyMethod pm = TypeManager.GetMethod (getter) as PropertyBase.PropertyMethod;
+                               PropertyBase.PropertyMethod pm = TypeManager.GetMethod (getter.MetaInfo) as PropertyBase.PropertyMethod;
                                if (pm != null && pm.HasCustomAccessModifier) {
                                        ec.Report.SymbolRelatedToPreviousError (pm);
                                        ec.Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because the get accessor is inaccessible",
-                                               TypeManager.CSharpSignature (getter));
+                                               TypeManager.CSharpSignature (getter.MetaInfo));
                                } else {
-                                       ec.Report.SymbolRelatedToPreviousError (getter);
-                                       ErrorIsInaccesible (loc, TypeManager.CSharpSignature (getter), ec.Report);
+                                       ec.Report.SymbolRelatedToPreviousError (getter.MetaInfo);
+                                       ErrorIsInaccesible (loc, TypeManager.CSharpSignature (getter.MetaInfo), ec.Report);
                                }
 
                                return false;
@@ -5847,15 +5858,15 @@ namespace Mono.CSharp {
                public readonly EventInfo EventInfo;
 
                bool is_static;
-               MethodInfo add_accessor, remove_accessor;
+               MethodSpec add_accessor, remove_accessor;
 
                public EventExpr (EventInfo ei, Location loc)
                {
                        EventInfo = ei;
                        this.loc = loc;
 
-                       add_accessor = TypeManager.GetAddMethod (ei);
-                       remove_accessor = TypeManager.GetRemoveMethod (ei);
+                       add_accessor = Import.CreateMethod (TypeManager.GetAddMethod (ei));
+                       remove_accessor = Import.CreateMethod (TypeManager.GetRemoveMethod (ei));
                        if (add_accessor.IsStatic || remove_accessor.IsStatic)
                                is_static = true;
 
@@ -5948,7 +5959,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (IsBase && add_accessor.IsAbstract) {
-                               Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(add_accessor));
+                               Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(add_accessor.MetaInfo));
                                return false;
                        }
 
index 54a940e0697afa1d5b439468c34e914d073da200..2d535ee28986201f9d39caabc64dc571e02c813a 100644 (file)
@@ -36,7 +36,7 @@ namespace Mono.CSharp {
                        this.arguments = args;
                        this.expr_tree = expr_tree;
 
-                       type = TypeManager.TypeToCoreType (((MethodInfo) mg).ReturnType);
+                       type = TypeManager.TypeToCoreType (((MethodSpec) mg).ReturnType);
                        eclass = ExprClass.Value;
                        this.loc = loc;
                }
@@ -73,7 +73,8 @@ namespace Mono.CSharp {
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       return SLE.Expression.Call ((MethodInfo) mg, Arguments.MakeExpression (arguments, ctx));
+                       var method = ((MethodSpec) mg).MetaInfo as MethodInfo;
+                       return SLE.Expression.Call (method, Arguments.MakeExpression (arguments, ctx));
                }
 
                public MethodGroupExpr Method {
@@ -2811,7 +2812,7 @@ namespace Mono.CSharp {
                        if (is_equality)
                                return ResolveUserOperator (ec, l, r);
 
-                       MethodInfo method;
+                       MethodSpec method;
                        Arguments args = new Arguments (2);
                        args.Add (new Argument (left));
                        args.Add (new Argument (right));
@@ -2832,7 +2833,7 @@ namespace Mono.CSharp {
                                method = TypeManager.delegate_remove_delegate_delegate;
                        }
 
-                       MethodGroupExpr mg = new MethodGroupExpr (new MemberInfo [] { method }, TypeManager.delegate_type, loc);
+                       MethodGroupExpr mg = new MethodGroupExpr (new [] { method }, TypeManager.delegate_type, loc);
                        mg = mg.OverloadResolve (ec, ref args, false, loc);
 
                        return new ClassCast (new UserOperatorCall (mg, args, CreateExpressionTree, loc), l);
@@ -3311,7 +3312,7 @@ namespace Mono.CSharp {
                                                if (left is NullLiteral || right is NullLiteral)
                                                        oper_expr = ReducedExpression.Create (this, oper_expr);
                                        } else if (l != r) {
-                                               MethodInfo mi = (MethodInfo) union;
+                                               var mi = union.BestCandidate;
                                                
                                                //
                                                // Two System.Delegate(s) are never equal
@@ -3853,7 +3854,7 @@ namespace Mono.CSharp {
                        if (++pos == arguments.Count)
                                return expr;
 
-                       left = new Argument (new EmptyExpression (((MethodInfo)method).ReturnType));
+                       left = new Argument (new EmptyExpression (method.BestCandidate.ReturnType));
                        return CreateExpressionAddCall (ec, left, expr, pos);
                }
 
@@ -3937,13 +3938,13 @@ namespace Mono.CSharp {
                
                protected override Expression DoResolve (ResolveContext ec)
                {
-                       MethodInfo method = (MethodInfo)mg;
+                       var method = mg.BestCandidate;
                        type = TypeManager.TypeToCoreType (method.ReturnType);
-                       AParametersCollection pd = TypeManager.GetParameterData (method);
+                       AParametersCollection pd = method.Parameters;
                        if (!TypeManager.IsEqual (type, type) || !TypeManager.IsEqual (type, pd.Types [0]) || !TypeManager.IsEqual (type, pd.Types [1])) {
                                ec.Report.Error (217, loc,
                                        "A user-defined operator `{0}' must have parameters and return values of the same type in order to be applicable as a short circuit operator",
-                                       TypeManager.CSharpSignature (method));
+                                       TypeManager.CSharpSignature (method.MetaInfo));
                                return null;
                        }
 
@@ -3953,7 +3954,7 @@ namespace Mono.CSharp {
                        if (op_true == null || op_false == null) {
                                ec.Report.Error (218, loc,
                                        "The type `{0}' must have operator `true' and operator `false' defined when `{1}' is used as a short circuit operator",
-                                       TypeManager.CSharpName (type), TypeManager.CSharpSignature (method));
+                                       TypeManager.CSharpName (type), TypeManager.CSharpSignature (method.MetaInfo));
                                return null;
                        }
 
@@ -4993,7 +4994,7 @@ namespace Mono.CSharp {
                        if (dynamic_arg || dynamic_member)
                                return DoResolveDynamic (ec, member_expr);
 
-                       MethodInfo method = (MethodInfo)mg;
+                       var method = mg.BestCandidate;
                        if (method != null) {
                                type = TypeManager.TypeToCoreType (method.ReturnType);
 
@@ -5090,24 +5091,24 @@ namespace Mono.CSharp {
                        return mg.OverloadResolve (ec, ref arguments, false, loc);
                }
 
-               public static bool IsSpecialMethodInvocation (ResolveContext ec, MethodBase method, Location loc)
+               public static bool IsSpecialMethodInvocation (ResolveContext ec, MethodSpec method, Location loc)
                {
-                       if (!TypeManager.IsSpecialMethod (method))
+                       if (!TypeManager.IsSpecialMethod (method.MetaInfo))
                                return false;
 
                        if (ec.HasSet (ResolveContext.Options.InvokeSpecialName))
                                return false;
 
-                       ec.Report.SymbolRelatedToPreviousError (method);
+                       ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
                        ec.Report.Error (571, loc, "`{0}': cannot explicitly call operator or accessor",
-                               TypeManager.CSharpSignature (method, true));
+                               TypeManager.CSharpSignature (method.MetaInfo, true));
        
                        return true;
                }
 
-               static Type[] GetVarargsTypes (MethodBase mb, Arguments arguments)
+               static Type[] GetVarargsTypes (MethodSpec mb, Arguments arguments)
                {
-                       AParametersCollection pd = TypeManager.GetParameterData (mb);
+                       AParametersCollection pd = mb.Parameters;
                        
                        Argument a = arguments [pd.Count - 1];
                        Arglist list = (Arglist) a.Expr;
@@ -5118,14 +5119,14 @@ namespace Mono.CSharp {
                /// <summary>
                /// This checks the ConditionalAttribute on the method 
                /// </summary>
-               public static bool IsMethodExcluded (MethodBase method, Location loc)
+               public static bool IsMethodExcluded (MethodSpec method, Location loc)
                {
                        if (method.IsConstructor)
                                return false;
 
-                       method = TypeManager.DropGenericMethodArguments (method);
-                       if (TypeManager.IsBeingCompiled (method)) {
-                               IMethodData md = TypeManager.GetMethod (method);
+                       var mb = TypeManager.DropGenericMethodArguments (method.MetaInfo);
+                       if (TypeManager.IsBeingCompiled (mb)) {
+                               IMethodData md = TypeManager.GetMethod (mb);
                                if (md != null)
                                        return md.IsExcluded ();
 
@@ -5134,7 +5135,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       return AttributeTester.IsConditionalMethodExcluded (method, loc);
+                       return AttributeTester.IsConditionalMethodExcluded (mb, loc);
                }
 
                /// <remarks>
@@ -5154,7 +5155,7 @@ namespace Mono.CSharp {
                /// </remarks>
                public static void EmitCall (EmitContext ec, bool is_base,
                                             Expression instance_expr,
-                                            MethodBase method, Arguments Arguments, Location loc)
+                                            MethodSpec method, Arguments Arguments, Location loc)
                {
                        EmitCall (ec, is_base, instance_expr, method, Arguments, loc, false, false);
                }
@@ -5167,7 +5168,7 @@ namespace Mono.CSharp {
                // only have been evaluated once.
                public static void EmitCall (EmitContext ec, bool is_base,
                                             Expression instance_expr,
-                                            MethodBase method, Arguments Arguments, Location loc,
+                                            MethodSpec method, Arguments Arguments, Location loc,
                                             bool dup_args, bool omit_args)
                {
                        ILGenerator ig = ec.ig;
@@ -5259,9 +5260,9 @@ namespace Mono.CSharp {
                                        ig.Emit (OpCodes.Constrained, instance_expr.Type);
                        }
 
-                       if ((method.CallingConvention & CallingConventions.VarArgs) != 0) {
+                       if ((method.MetaInfo.CallingConvention & CallingConventions.VarArgs) != 0) {
                                Type[] varargs_types = GetVarargsTypes (method, Arguments);
-                               ig.EmitCall (call_op, (MethodInfo) method, varargs_types);
+                               ig.EmitCall (call_op, (MethodInfo) method.MetaInfo, varargs_types);
                                return;
                        }
 
@@ -5271,10 +5272,10 @@ namespace Mono.CSharp {
                        // and DoFoo is not virtual, you can omit the callvirt,
                        // because you don't need the null checking behavior.
                        //
-                       if (method is MethodInfo)
-                               ig.Emit (call_op, (MethodInfo) method);
+                       if (method.IsConstructor)
+                               ig.Emit (call_op, (ConstructorInfo) method.MetaInfo);
                        else
-                               ig.Emit (call_op, (ConstructorInfo) method);
+                               ig.Emit (call_op, (MethodInfo) method.MetaInfo);
                }
 
                public override void Emit (EmitContext ec)
@@ -5305,13 +5306,13 @@ namespace Mono.CSharp {
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       return MakeExpression (ctx, mg.InstanceExpression, (MethodInfo) mg, arguments);
+                       return MakeExpression (ctx, mg.InstanceExpression, (MethodSpec) mg, arguments);
                }
 
-               public static SLE.Expression MakeExpression (BuilderContext ctx, Expression instance, MethodInfo mi, Arguments args)
+               public static SLE.Expression MakeExpression (BuilderContext ctx, Expression instance, MethodSpec mi, Arguments args)
                {
                        var instance_expr = instance == null ? null : instance.MakeExpression (ctx);
-                       return SLE.Expression.Call (instance_expr, mi, Arguments.MakeExpression (args, ctx));
+                       return SLE.Expression.Call (instance_expr, (MethodInfo) mi.MetaInfo, Arguments.MakeExpression (args, ctx));
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
@@ -5557,8 +5558,8 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
 
-                       MethodInfo ci = TypeManager.activator_create_instance.MakeGenericMethod (
-                               new Type [] { type });
+                       MethodInfo ci = (MethodInfo) TypeManager.activator_create_instance.MetaInfo;
+                       ci = ci.MakeGenericMethod (new Type [] { type });
 
                        GenericConstraints gc = TypeManager.GetTypeParameterConstraints (type);
                        if (gc.HasReferenceTypeConstraint || gc.HasClassConstraint) {
@@ -5642,7 +5643,7 @@ namespace Mono.CSharp {
                                }
 
                                if (vr != null) {
-                                       ig.Emit (OpCodes.Call, (ConstructorInfo) method);
+                                       ig.Emit (OpCodes.Call, (ConstructorInfo) method.BestCandidate.MetaInfo);
                                        return false;
                                }
                        }
@@ -5650,7 +5651,7 @@ namespace Mono.CSharp {
                        if (is_type_parameter)
                                return DoEmitTypeParameter (ec);                        
 
-                       ConstructorInfo ci = (ConstructorInfo) method;
+                       ConstructorInfo ci = (ConstructorInfo) method.BestCandidate.MetaInfo;
 #if MS_COMPATIBLE
                        if (TypeManager.IsGenericType (type) && type.IsGenericTypeDefinition)
                                ci = TypeBuilder.GetConstructor (type, ci);
@@ -5724,7 +5725,7 @@ namespace Mono.CSharp {
                                if (Arguments != null)
                                        Arguments.Emit (ec);
 
-                               ec.ig.Emit (OpCodes.Call, (ConstructorInfo) method);
+                               ec.ig.Emit (OpCodes.Call, (ConstructorInfo) method.BestCandidate.MetaInfo);
                        }
                        
                        value_target.AddressOf (ec, mode);
@@ -5743,7 +5744,7 @@ namespace Mono.CSharp {
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       return SLE.Expression.New ((ConstructorInfo) method, Arguments.MakeExpression (Arguments, ctx));
+                       return SLE.Expression.New ((ConstructorInfo) method.BestCandidate.MetaInfo, Arguments.MakeExpression (Arguments, ctx));
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
@@ -6348,8 +6349,7 @@ namespace Mono.CSharp {
 
                        ig.Emit (OpCodes.Dup);
                        ig.Emit (OpCodes.Ldtoken, fb);
-                       ig.Emit (OpCodes.Call,
-                                TypeManager.void_initializearray_array_fieldhandle);
+                       ig.Emit (OpCodes.Call, (MethodInfo) TypeManager.void_initializearray_array_fieldhandle.MetaInfo);
                }
 
                //
@@ -7013,7 +7013,7 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        ec.ig.Emit (OpCodes.Ldtoken, TypeManager.TypeToReflectionType (typearg));
-                       ec.ig.Emit (OpCodes.Call, TypeManager.system_type_get_type_from_handle);
+                       ec.ig.Emit (OpCodes.Call, (MethodInfo) TypeManager.system_type_get_type_from_handle.MetaInfo);
                }
 
                public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
@@ -7072,23 +7072,23 @@ namespace Mono.CSharp {
                }
        }
 
-       class TypeOfMethod : TypeOfMember
+       class TypeOfMethod : TypeOfMember<MethodSpec>
        {
-               public TypeOfMethod (MethodBase method, Location loc)
+               public TypeOfMethod (MethodSpec method, Location loc)
                        : base (method, loc)
                {
                }
 
                protected override Expression DoResolve (ResolveContext ec)
                {
-                       if (member is MethodInfo) {
-                               type = TypeManager.methodinfo_type;
-                               if (type == null)
-                                       type = TypeManager.methodinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "MethodInfo", Kind.Class, true);
-                       } else {
+                       if (member.IsConstructor) {
                                type = TypeManager.ctorinfo_type;
                                if (type == null)
                                        type = TypeManager.ctorinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "ConstructorInfo", Kind.Class, true);
+                       } else {
+                               type = TypeManager.methodinfo_type;
+                               if (type == null)
+                                       type = TypeManager.methodinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "MethodInfo", Kind.Class, true);
                        }
 
                        return base.DoResolve (ec);
@@ -7096,10 +7096,10 @@ namespace Mono.CSharp {
 
                public override void Emit (EmitContext ec)
                {
-                       if (member is ConstructorInfo)
-                               ec.ig.Emit (OpCodes.Ldtoken, (ConstructorInfo) member);
+                       if (member.IsConstructor)
+                               ec.ig.Emit (OpCodes.Ldtoken, (ConstructorInfo) member.MetaInfo);
                        else
-                               ec.ig.Emit (OpCodes.Ldtoken, (MethodInfo) member);
+                               ec.ig.Emit (OpCodes.Ldtoken, (MethodInfo) member.MetaInfo);
 
                        base.Emit (ec);
                        ec.ig.Emit (OpCodes.Castclass, type);
@@ -7113,7 +7113,7 @@ namespace Mono.CSharp {
                        get { return "RuntimeMethodHandle"; }
                }
 
-               protected override MethodInfo TypeFromHandle {
+               protected override MethodSpec TypeFromHandle {
                        get {
                                return TypeManager.methodbase_get_type_from_handle;
                        }
@@ -7122,7 +7122,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override MethodInfo TypeFromHandleGeneric {
+               protected override MethodSpec TypeFromHandleGeneric {
                        get {
                                return TypeManager.methodbase_get_type_from_handle_generic;
                        }
@@ -7136,11 +7136,11 @@ namespace Mono.CSharp {
                }
        }
 
-       abstract class TypeOfMember : Expression
+       abstract class TypeOfMember<T> : Expression where T : MemberSpec
        {
-               protected readonly MemberInfo member;
+               protected readonly T member;
 
-               protected TypeOfMember (MemberInfo member, Location loc)
+               protected TypeOfMember (T member, Location loc)
                {
                        this.member = member;
                        this.loc = loc;
@@ -7157,7 +7157,7 @@ namespace Mono.CSharp {
                protected override Expression DoResolve (ResolveContext ec)
                {
                        bool is_generic = TypeManager.IsGenericType (member.DeclaringType);
-                       MethodInfo mi = is_generic ? TypeFromHandleGeneric : TypeFromHandle;
+                       var mi = is_generic ? TypeFromHandleGeneric : TypeFromHandle;
 
                        if (mi == null) {
                                Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, Kind.Class, true);
@@ -7184,7 +7184,7 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        bool is_generic = TypeManager.IsGenericType (member.DeclaringType);
-                       MethodInfo mi;
+                       MethodSpec mi;
                        if (is_generic) {
                                mi = TypeFromHandleGeneric;
                                ec.ig.Emit (OpCodes.Ldtoken, member.DeclaringType);
@@ -7192,19 +7192,19 @@ namespace Mono.CSharp {
                                mi = TypeFromHandle;
                        }
 
-                       ec.ig.Emit (OpCodes.Call, mi);
+                       ec.ig.Emit (OpCodes.Call, (MethodInfo) mi.MetaInfo);
                }
 
                protected abstract string GetMethodName { get; }
                protected abstract string RuntimeHandleName { get; }
-               protected abstract MethodInfo TypeFromHandle { get; set; }
-               protected abstract MethodInfo TypeFromHandleGeneric { get; set; }
+               protected abstract MethodSpec TypeFromHandle { get; set; }
+               protected abstract MethodSpec TypeFromHandleGeneric { get; set; }
                protected abstract string TypeName { get; }
        }
 
-       class TypeOfField : TypeOfMember
+       class TypeOfField : TypeOfMember<FieldSpec>
        {
-               public TypeOfField (FieldInfo field, Location loc)
+               public TypeOfField (FieldSpec field, Location loc)
                        : base (field, loc)
                {
                }
@@ -7220,7 +7220,7 @@ namespace Mono.CSharp {
 
                public override void Emit (EmitContext ec)
                {
-                       ec.ig.Emit (OpCodes.Ldtoken, (FieldInfo) member);
+                       ec.ig.Emit (OpCodes.Ldtoken, member.MetaInfo);
                        base.Emit (ec);
                }
 
@@ -7232,7 +7232,7 @@ namespace Mono.CSharp {
                        get { return "RuntimeFieldHandle"; }
                }
 
-               protected override MethodInfo TypeFromHandle {
+               protected override MethodSpec TypeFromHandle {
                        get {
                                return TypeManager.fieldinfo_get_field_from_handle;
                        }
@@ -7241,7 +7241,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override MethodInfo TypeFromHandleGeneric {
+               protected override MethodSpec TypeFromHandleGeneric {
                        get {
                                return TypeManager.fieldinfo_get_field_from_handle_generic;
                        }
@@ -8358,7 +8358,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       protected override int GetApplicableParametersCount (MethodBase method, AParametersCollection parameters)
+                       protected override int GetApplicableParametersCount (MethodSpec method, AParametersCollection parameters)
                        {
                                //
                                // Here is the trick, decrease number of arguments by 1 when only
@@ -8376,7 +8376,7 @@ namespace Mono.CSharp {
                class Indexers
                {
                        // Contains either property getter or setter
-                       public List<MethodBase> Methods;
+                       public List<MethodSpec> Methods;
                        public List<PropertyInfo> Properties;
 
                        Indexers ()
@@ -8394,11 +8394,11 @@ namespace Mono.CSharp {
                                                accessor = property.GetSetMethod (true);
 
                                        if (Methods == null) {
-                                               Methods = new List<MethodBase> ();
+                                               Methods = new List<MethodSpec> ();
                                                Properties = new List<PropertyInfo> ();
                                        }
 
-                                       Methods.Add (accessor);
+                                       Methods.Add (Import.CreateMethod (accessor));
                                        Properties.Add (property);
                                }
                        }
@@ -8458,7 +8458,7 @@ namespace Mono.CSharp {
                //
                // Points to our "data" repository
                //
-               MethodInfo get, set;
+               MethodSpec get, set;
                bool is_base_indexer;
                bool prepared;
                LocalTemporary temp;
@@ -8568,10 +8568,10 @@ namespace Mono.CSharp {
                                return expr.Resolve (ec);
                        }
 
-                       MethodInfo mi = (MethodInfo) mg;
+                       var mi = (MethodSpec) mg;
                        PropertyInfo pi = null;
                        for (int i = 0; i < ilist.Methods.Count; ++i) {
-                               if (ilist.Methods [i] == mi) {
+                               if (ilist.Methods [i].MetaInfo == mi.MetaInfo) {
                                        pi = (PropertyInfo) ilist.Properties [i];
                                        break;
                                }
@@ -8581,11 +8581,15 @@ namespace Mono.CSharp {
                        if (type.IsPointer && !ec.IsUnsafe)
                                UnsafeError (ec, loc);
 
-                       MethodInfo accessor;
+                       MethodSpec accessor = null;
                        if (right_side == null) {
-                               accessor = get = pi.GetGetMethod (true);
+                               var m = pi.GetGetMethod (true);
+                               if (m != null)
+                                       accessor = get = Import.CreateMethod (m);
                        } else {
-                               accessor = set = pi.GetSetMethod (true);
+                               var m = pi.GetSetMethod (true);
+                               if (m != null)
+                                       accessor = set = Import.CreateMethod (m);
                                if (accessor == null && pi.GetGetMethod (true) != null) {
                                        ec.Report.SymbolRelatedToPreviousError (pi);
                                        ec.Report.Error (200, loc, "The read only property or indexer `{0}' cannot be assigned to",
@@ -8612,14 +8616,19 @@ namespace Mono.CSharp {
 
                        bool must_do_cs1540_check;
                        if (!IsAccessorAccessible (ec.CurrentType, accessor, out must_do_cs1540_check)) {
-                               if (set == null)
-                                       set = pi.GetSetMethod (true);
-                               else
-                                       get = pi.GetGetMethod (true);
+                               if (set == null) {
+                                       var m = pi.GetSetMethod (true);
+                                       if (m != null)
+                                               set = Import.CreateMethod (m);
+                               } else {
+                                       var m = pi.GetGetMethod (true);
+                                       if (m != null)
+                                               get = Import.CreateMethod (m);
+                               }
 
                                if (set != null && get != null &&
-                                       (set.Attributes & MethodAttributes.MemberAccessMask) != (get.Attributes & MethodAttributes.MemberAccessMask)) {
-                                       ec.Report.SymbolRelatedToPreviousError (accessor);
+                                       (set.MetaInfo.Attributes & MethodAttributes.MemberAccessMask) != (get.MetaInfo.Attributes & MethodAttributes.MemberAccessMask)) {
+                                       ec.Report.SymbolRelatedToPreviousError (accessor.MetaInfo);
                                        ec.Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because a `{1}' accessor is inaccessible",
                                                TypeManager.GetFullNameSignature (pi), GetAccessorName (right_side != null));
                                } else {
@@ -8698,7 +8707,7 @@ namespace Mono.CSharp {
                
                public override string GetSignatureForError ()
                {
-                       return TypeManager.CSharpSignature (get != null ? get : set, false);
+                       return TypeManager.CSharpSignature (get != null ? get.MetaInfo : set.MetaInfo, false);
                }
 
 #if NET_4_0
@@ -8708,7 +8717,7 @@ namespace Mono.CSharp {
                        var args = Arguments.MakeExpression (arguments, ctx).Concat (value);
 
                        return SLE.Expression.Block (
-                                       SLE.Expression.Call (instance_expr.MakeExpression (ctx), set, args),
+                                       SLE.Expression.Call (instance_expr.MakeExpression (ctx), (MethodInfo) set.MetaInfo, args),
                                        value [0]);
                }
 #endif
@@ -8716,15 +8725,15 @@ namespace Mono.CSharp {
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
                        var args = Arguments.MakeExpression (arguments, ctx);
-                       return SLE.Expression.Call (instance_expr.MakeExpression (ctx), get, args);
+                       return SLE.Expression.Call (instance_expr.MakeExpression (ctx), (MethodInfo) get.MetaInfo, args);
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
                {
                        if (get != null)
-                               get = storey.MutateGenericMethod (get);
+                               storey.MutateGenericMethod (get);
                        if (set != null)
-                               set = storey.MutateGenericMethod (set);
+                               storey.MutateGenericMethod (set);
 
                        instance_expr.MutateHoistedGenericType (storey);
                        if (arguments != null)
@@ -9019,10 +9028,10 @@ namespace Mono.CSharp {
        }       
 
        public class UserCast : Expression {
-               MethodInfo method;
+               MethodSpec method;
                Expression source;
                
-               public UserCast (MethodInfo method, Expression source, Location l)
+               public UserCast (MethodSpec method, Expression source, Location l)
                {
                        this.method = method;
                        this.source = source;
@@ -9047,7 +9056,7 @@ namespace Mono.CSharp {
                        
                protected override Expression DoResolve (ResolveContext ec)
                {
-                       ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method);
+                       ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method.MetaInfo);
                        if (oa != null)
                                AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
 
@@ -9058,23 +9067,23 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        source.Emit (ec);
-                       ec.ig.Emit (OpCodes.Call, method);
+                       ec.ig.Emit (OpCodes.Call, (MethodInfo) method.MetaInfo);
                }
 
                public override string GetSignatureForError ()
                {
-                       return TypeManager.CSharpSignature (method);
+                       return TypeManager.CSharpSignature (method.MetaInfo);
                }
 
                public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       return SLE.Expression.Convert (source.MakeExpression (ctx), type, method);
+                       return SLE.Expression.Convert (source.MakeExpression (ctx), type, (MethodInfo) method.MetaInfo);
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
                {
                        source.MutateHoistedGenericType (storey);
-                       method = storey.MutateGenericMethod (method);
+                       storey.MutateGenericMethod (method);
                }
        }
 
@@ -9845,7 +9854,7 @@ namespace Mono.CSharp {
 
                        var init = new ArrayInitializer (parameters.Count, loc);
                        foreach (Property p in anonymous_type.Properties)
-                               init.Add (new TypeOfMethod (TypeBuilder.GetMethod (type, p.GetBuilder), loc));
+                               init.Add (new TypeOfMethod (Import.CreateMethod (TypeBuilder.GetMethod (type, p.GetBuilder)), loc));
 
                        var ctor_args = new ArrayInitializer (Arguments.Count, loc);
                        foreach (Argument a in Arguments)
index b20153fcafea522b1cd7cf860efa6ea806206518..9b8679aff4073df4762ae3dd30f7abf693ed0188 100644 (file)
@@ -234,8 +234,8 @@ namespace Mono.CSharp
        {
                FieldInfo info;
 
-               public FieldSpec (IMemberDetails details, FieldInfo info, Modifiers modifiers)
-                       : base (details, info.Name, modifiers)
+               public FieldSpec (IMemberDefinition definition, FieldInfo info, Modifiers modifiers)
+                       : base (definition, info.Name, modifiers)
                {
                        this.info = info;
                }
@@ -253,8 +253,7 @@ namespace Mono.CSharp
                        }
                }
 
-               // Obsolete
-               public Type DeclaringType {
+               public override Type DeclaringType {
                        get {
                                return MetaInfo.DeclaringType;
                        }
@@ -440,8 +439,8 @@ namespace Mono.CSharp
        {
                readonly FieldInfo element;
 
-               public FixedFieldSpec (IMemberDetails details, FieldInfo info, FieldInfo element, Modifiers modifiers)
-                        : base (details, info, modifiers)
+               public FixedFieldSpec (IMemberDefinition definition, FieldInfo info, FieldInfo element, Modifiers modifiers)
+                        : base (definition, info, modifiers)
                {
                        this.element = element;
                }
index ddf34fbd5be22d94593e4b0bf782ec1f478049f4..2677bfeae90dac3925565532294e6db638a40043 100644 (file)
@@ -2166,7 +2166,7 @@ namespace Mono.CSharp {
                ///   when resolving an Invocation or a DelegateInvocation and the user
                ///   did not explicitly specify type arguments.
                /// </summary>
-               public static int InferTypeArguments (ResolveContext ec, Arguments arguments, ref MethodBase method)
+               public static int InferTypeArguments (ResolveContext ec, Arguments arguments, ref MethodSpec method)
                {
                        ATypeInference ti = ATypeInference.CreateInstance (arguments);
                        Type[] i_args = ti.InferMethodArguments (ec, method);
@@ -2176,7 +2176,7 @@ namespace Mono.CSharp {
                        if (i_args.Length == 0)
                                return 0;
 
-                       method = ((MethodInfo) method).MakeGenericMethod (i_args);
+                       method = method.Inflate (i_args);
                        return 0;
                }
 
@@ -2220,7 +2220,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public abstract Type[] InferMethodArguments (ResolveContext ec, MethodBase method);
+               public abstract Type[] InferMethodArguments (ResolveContext ec, MethodSpec method);
 //             public abstract Type[] InferDelegateArguments (ResolveContext ec, MethodBase method);
        }
 
@@ -2271,14 +2271,14 @@ namespace Mono.CSharp {
                        return context.InferredTypeArguments;
                }
 */
-               public override Type[] InferMethodArguments (ResolveContext ec, MethodBase method)
+               public override Type[] InferMethodArguments (ResolveContext ec, MethodSpec method)
                {
-                       Type[] method_generic_args = method.GetGenericArguments ();
+                       var method_generic_args = method.GetGenericArguments ();
                        TypeInferenceContext context = new TypeInferenceContext (method_generic_args);
                        if (!context.UnfixedVariableExists)
                                return Type.EmptyTypes;
 
-                       AParametersCollection pd = TypeManager.GetParameterData (method);
+                       AParametersCollection pd = method.Parameters;
                        if (!InferInPhases (ec, context, pd))
                                return null;
 
@@ -2389,13 +2389,13 @@ namespace Mono.CSharp {
                                        t_i = t_i.GetGenericArguments () [0];
                                }
 
-                               MethodInfo mi = Delegate.GetInvokeMethod (ec.Compiler, t_i, t_i);
+                               var mi = Delegate.GetInvokeMethod (ec.Compiler, t_i, t_i);
                                Type rtype = mi.ReturnType;
 
 #if MS_COMPATIBLE
                                // Blablabla, because reflection does not work with dynamic types
-                               Type[] g_args = t_i.GetGenericArguments ();
-                               rtype = g_args[rtype.GenericParameterPosition];
+//                             Type[] g_args = t_i.GetGenericArguments ();
+//                             rtype = g_args[rtype.GenericParameterPosition];
 #endif
 
                                if (tic.IsReturnTypeNonDependent (ec, mi, rtype))
@@ -2625,17 +2625,17 @@ namespace Mono.CSharp {
                                if (t.IsGenericParameter)
                                        continue;
 
-                               MethodInfo invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
+                               var invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
                                Type rtype = invoke.ReturnType;
                                if (!rtype.IsGenericParameter && !rtype.IsGenericType)
                                        continue;
 
 #if MS_COMPATIBLE
                                // Blablabla, because reflection does not work with dynamic types
-                               if (rtype.IsGenericParameter) {
-                                       Type [] g_args = t.GetGenericArguments ();
-                                       rtype = g_args [rtype.GenericParameterPosition];
-                               }
+//                             if (rtype.IsGenericParameter) {
+//                                     Type [] g_args = t.GetGenericArguments ();
+//                                     rtype = g_args [rtype.GenericParameterPosition];
+//                             }
 #endif
                                // Remove dependent types, they cannot be fixed yet
                                RemoveDependentTypes (types_to_fix, rtype);
@@ -2784,7 +2784,7 @@ namespace Mono.CSharp {
                // Tests whether all delegate input arguments are fixed and generic output type
                // requires output type inference 
                //
-               public bool IsReturnTypeNonDependent (ResolveContext ec, MethodInfo invoke, Type returnType)
+               public bool IsReturnTypeNonDependent (ResolveContext ec, MethodSpec invoke, Type returnType)
                {
                        if (returnType.IsGenericParameter) {
                                if (IsFixed (returnType))
@@ -2805,7 +2805,7 @@ namespace Mono.CSharp {
                        }
 
                        // All generic input arguments have to be fixed
-                       AParametersCollection d_parameters = TypeManager.GetParameterData (invoke);
+                       AParametersCollection d_parameters = invoke.Parameters;
                        return AllTypesAreFixed (d_parameters.Types);
                }
                
@@ -2966,18 +2966,18 @@ namespace Mono.CSharp {
                        AnonymousMethodExpression ame = e as AnonymousMethodExpression;
                        if (ame != null) {
                                Type rt = ame.InferReturnType (ec, this, t);
-                               MethodInfo invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
+                               var invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
 
                                if (rt == null) {
-                                       AParametersCollection pd = TypeManager.GetParameterData (invoke);
+                                       AParametersCollection pd = invoke.Parameters;
                                        return ame.Parameters.Count == pd.Count ? 1 : 0;
                                }
 
                                Type rtype = invoke.ReturnType;
 #if MS_COMPATIBLE
                                // Blablabla, because reflection does not work with dynamic types
-                               Type [] g_args = t.GetGenericArguments ();
-                               rtype = g_args [rtype.GenericParameterPosition];
+//                             Type [] g_args = t.GetGenericArguments ();
+//                             rtype = g_args [rtype.GenericParameterPosition];
 #endif
                                return LowerBoundInference (rt, rtype) + 1;
                        }
@@ -2993,19 +2993,19 @@ namespace Mono.CSharp {
                                if (!TypeManager.IsDelegateType (t))
                                        return 0;
 
-                               MethodInfo invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
+                               var invoke = Delegate.GetInvokeMethod (ec.Compiler, t, t);
                                Type rtype = invoke.ReturnType;
 #if MS_COMPATIBLE
                                // Blablabla, because reflection does not work with dynamic types
-                               Type [] g_args = t.GetGenericArguments ();
-                               rtype = g_args [rtype.GenericParameterPosition];
+//                             Type [] g_args = t.GetGenericArguments ();
+//                             rtype = g_args [rtype.GenericParameterPosition];
 #endif
 
                                if (!TypeManager.IsGenericType (rtype))
                                        return 0;
 
                                MethodGroupExpr mg = (MethodGroupExpr) e;
-                               Arguments args = DelegateCreation.CreateDelegateMethodArguments (TypeManager.GetParameterData (invoke), e.Location);
+                               Arguments args = DelegateCreation.CreateDelegateMethodArguments (invoke.Parameters, e.Location);
                                mg = mg.OverloadResolve (ec, ref args, true, e.Location);
                                if (mg == null)
                                        return 0;
index 3f333c02cc74deb7b1b7a97af07b5d0a9f7ba714..e5c990d47bda4db4a395a6071103dfc3798fe0a4 100644 (file)
@@ -19,7 +19,7 @@ namespace Mono.CSharp
        {
                public static FieldSpec CreateField (FieldInfo fi)
                {
-                       // TODO: remove after MemberCache fix
+                       // TODO MemberCache: remove
                        var cs = TypeManager.GetConstant (fi);
                        if (cs != null)
                                return cs;
@@ -48,18 +48,18 @@ namespace Mono.CSharp
                                        break;
                        }
 
-                       // TODO: Remove completely
-                       IMemberDetails details;
+                       // TODO MemberCache: Remove completely and use only Imported
+                       IMemberDefinition definition;
                        var gfd = TypeManager.GetGenericFieldDefinition (fi);
                        fb = TypeManager.GetFieldCore (gfd);
                        if (fb != null) {
-                               details = fb;
+                               definition = fb;
                        } else {
                                cs = TypeManager.GetConstant (gfd);
                                if (cs != null)
-                                       details = cs.MemberDetails;
+                                       definition = cs.MemberDefinition;
                                else
-                                       details = new ImportedMemberDetails (fi);
+                                       definition = new ImportedMemberDefinition (fi);
                        }
 
                        if ((fa & FieldAttributes.Literal) != 0) {
@@ -71,14 +71,14 @@ namespace Mono.CSharp
                                        c = Constant.CreateConstantFromValue (fi.FieldType, gfd.GetValue (gfd), Location.Null);
                                }
 
-                               return new ConstSpec (details, fi, mod, c);
+                               return new ConstSpec (definition, fi, mod, c);
                        }
 
                        if ((fa & FieldAttributes.InitOnly) != 0) {
                                if (fi.FieldType == TypeManager.decimal_type) {
                                        var dc = ReadDecimalConstant (gfd);
                                        if (dc != null)
-                                               return new ConstSpec (details, fi, mod, dc);
+                                               return new ConstSpec (definition, fi, mod, dc);
                                }
 
                                mod |= Modifiers.READONLY;
@@ -94,14 +94,66 @@ namespace Mono.CSharp
                                                 // TODO: Remove this after MemberCache fix
                                        } else if (gfd.IsDefined (pa.Type, false)) {
                                                var element_field = fi.FieldType.GetField (FixedField.FixedElementName);
-                                               return new FixedFieldSpec (details, fi, element_field, mod);
+                                               return new FixedFieldSpec (definition, fi, element_field, mod);
                                        }
                                }
                        }
 
                        // TODO: volatile
 
-                       return new FieldSpec (details, fi, mod);
+                       return new FieldSpec (definition, fi, mod);
+               }
+
+               public static MethodSpec CreateMethod (MethodBase mb)
+               {
+                       // TODO MemberCache: Remove
+                       MethodCore mc = TypeManager.GetMethod (mb) as MethodCore;
+                       if (mc != null)
+                               return mc.Spec;
+
+                       Modifiers mod = 0;
+                       var ma = mb.Attributes;
+                       switch (ma & MethodAttributes.MemberAccessMask) {
+                               case MethodAttributes.Public:
+                                       mod = Modifiers.PUBLIC;
+                                       break;
+                               case MethodAttributes.Assembly:
+                                       mod = Modifiers.INTERNAL;
+                                       break;
+                               case MethodAttributes.Family:
+                                       mod = Modifiers.PROTECTED;
+                                       break;
+                               case MethodAttributes.FamORAssem:
+                                       mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
+                                       break;
+                               default:
+                                       mod = Modifiers.PRIVATE;
+                                       break;
+                       }
+
+                       if ((ma & MethodAttributes.Static) != 0)
+                               mod |= Modifiers.STATIC;
+                       if ((ma & MethodAttributes.Virtual) != 0)
+                               mod |= Modifiers.VIRTUAL;
+                       if ((ma & MethodAttributes.Abstract) != 0)
+                               mod |= Modifiers.ABSTRACT;
+                       if ((ma & MethodAttributes.Final) != 0)
+                               mod |= Modifiers.SEALED;
+
+                       IMemberDefinition definition;
+                       var gmd = mb as MethodInfo;
+                       if (gmd != null && gmd.IsGenericMethodDefinition) {
+                               definition = new ImportedGenericMethodDefinition (gmd);
+                       } else if (mb.IsGenericMethod) {        // TODO MemberCache: Remove me
+                               definition = new ImportedGenericMethodDefinition ((MethodInfo) TypeManager.DropGenericMethodArguments (mb));
+                       } else {
+                               definition = new ImportedMemberDefinition (mb);
+                       }
+
+                       // TODO MemberCache: Use AParametersCollection p = ParametersImported.Create (mb);
+                       AParametersCollection p = TypeManager.GetParameterData (mb);
+                       MethodSpec ms = new MethodSpec (definition, mb, p, mod);
+                       return ms;
                }
 
                //
@@ -123,11 +175,11 @@ namespace Mono.CSharp
                }
        }
 
-       class ImportedMemberDetails : IMemberDetails
+       class ImportedMemberDefinition : IMemberDefinition
        {
-               readonly ICustomAttributeProvider provider;
+               protected readonly ICustomAttributeProvider provider;
 
-               public ImportedMemberDetails (ICustomAttributeProvider provider)
+               public ImportedMemberDefinition (ICustomAttributeProvider provider)
                {
                        this.provider = provider;
                }
@@ -140,5 +192,23 @@ namespace Mono.CSharp
 
                        return res [0] as ObsoleteAttribute;
                }
+
+               public void SetIsUsed ()
+               {
+                       // Not interested for imported members
+               }
+       }
+
+       class ImportedGenericMethodDefinition : ImportedMemberDefinition, IGenericMethodDefinition
+       {
+               public ImportedGenericMethodDefinition (MethodInfo provider)
+                       : base (provider)
+               {
+               }
+
+               public MethodInfo MakeGenericMethod (Type[] targs)
+               {
+                       return ((MethodInfo) provider).MakeGenericMethod (targs);
+               }
        }
 }
\ No newline at end of file
index 5362bba08bcfb75ea0a8366906d77dc9f60e1f97..6a817ecb0a5ee99b59b14d6bdd50f4c05d8efbc7 100644 (file)
@@ -276,7 +276,7 @@ namespace Mono.CSharp {
                                        ig.Emit (OpCodes.Ldflda, host.PC.Spec.MetaInfo);
                                        IntConstant.EmitInt (ig, (int) Iterator.State.Start);
                                        IntConstant.EmitInt (ig, (int) Iterator.State.Uninitialized);
-                                       ig.Emit (OpCodes.Call, TypeManager.int_interlocked_compare_exchange);
+                                       ig.Emit (OpCodes.Call, (MethodInfo) TypeManager.int_interlocked_compare_exchange.MetaInfo);
 
                                        IntConstant.EmitInt (ig, (int) Iterator.State.Uninitialized);
                                        ig.Emit (OpCodes.Bne_Un_S, label_init);
@@ -362,7 +362,7 @@ namespace Mono.CSharp {
 
                        protected override Expression DoResolve (ResolveContext ec)
                        {
-                               Methods = new MethodBase [] { method.MethodBuilder };
+                               Methods = new [] { method.Spec };
                                type = method.Parent.TypeBuilder;
                                InstanceExpression = new CompilerGeneratedThis (type, Location);
                                return base.DoResolve (ec);
index a4b427e482b8231432c6052aff4b40383cab8c4d..2932b650646114ce1122a6e1431730b7a79cd1fa 100644 (file)
@@ -94,18 +94,18 @@ namespace Mono.CSharp.Linq
                                return rmg;
                        }
 
-                       public bool AmbiguousCall (ResolveContext ec, MethodBase ambiguous)
+                       public bool AmbiguousCall (ResolveContext ec, MethodSpec ambiguous)
                        {
-                               ec.Report.SymbolRelatedToPreviousError ((MethodInfo) mg);
-                               ec.Report.SymbolRelatedToPreviousError (ambiguous);
+                               ec.Report.SymbolRelatedToPreviousError (mg.BestCandidate.MetaInfo);
+                               ec.Report.SymbolRelatedToPreviousError (ambiguous.MetaInfo);
                                ec.Report.Error (1940, loc, "Ambiguous implementation of the query pattern `{0}' for source type `{1}'",
                                        mg.Name, mg.InstanceExpression.GetSignatureForError ());
                                return true;
                        }
 
-                       public bool NoExactMatch (ResolveContext ec, MethodBase method)
+                       public bool NoExactMatch (ResolveContext ec, MethodSpec method)
                        {
-                               AParametersCollection pd = TypeManager.GetParameterData (method);
+                               var pd = method.Parameters;
                                Type source_type = pd.ExtensionMethodType;
                                if (source_type != null) {
                                        Argument a = arguments [0];
@@ -125,7 +125,7 @@ namespace Mono.CSharp.Linq
                                        }
                                }
 
-                               if (!TypeManager.IsGenericMethod (method))
+                               if (!method.IsGenericMethod)
                                        return false;
 
                                if (mg.Name == "SelectMany") {
index f7f9f350790409426f50a1d506da6319445a2f62..abecb38e5f8b73cc331ddc668c9b9a47443f3bec 100644 (file)
@@ -35,6 +35,7 @@ namespace Mono.CSharp {
        {
                public readonly ParametersCompiled Parameters;
                protected ToplevelBlock block;
+               protected MethodSpec spec;
 
                public MethodCore (DeclSpace parent, GenericMethod generic,
                        FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
@@ -130,6 +131,10 @@ namespace Mono.CSharp {
                        return base.EnableOverloadChecks (overload);
                }
 
+               public MethodSpec Spec {
+                       get { return spec; }
+               }
+
                protected override bool VerifyClsCompliance ()
                {
                        if (!base.VerifyClsCompliance ())
@@ -149,13 +154,88 @@ namespace Mono.CSharp {
                }
        }
 
+       interface IGenericMethodDefinition : IMemberDefinition
+       {
+               MethodInfo MakeGenericMethod (Type[] targs);
+       }
+
        public class MethodSpec : MemberSpec
        {
-               public MethodInfo MetaInfo;
+               MethodBase metaInfo;
+               readonly AParametersCollection parameters;
+
+               public MethodSpec (IMemberDefinition details, MethodBase info, AParametersCollection parameters, Modifiers modifiers)
+                       : base (details, info.Name, modifiers)
+               {
+                       this.MetaInfo = info;
+                       this.parameters = parameters;
+               }
 
-               protected MethodSpec (IMemberDetails details, string name, Modifiers modifiers)
-                       : base (details, name, modifiers)
+               public override Type DeclaringType {
+                       get {
+                               return MetaInfo.DeclaringType;
+                       }
+               }
+
+               public Type[] GetGenericArguments ()
                {
+                       return MetaInfo.GetGenericArguments ();
+               }
+
+               public MethodSpec Inflate (Type[] targs)
+               {
+                       // TODO: Only create MethodSpec and inflate parameters, defer the call for later
+                       var mb = ((IGenericMethodDefinition) definition).MakeGenericMethod (targs);
+
+                       // TODO: Does not work on .NET
+                       var par = TypeManager.GetParameterData (mb);
+
+                       return new MethodSpec (definition, mb, par, modifiers);
+               }
+
+               public bool IsAbstract {
+                       get {
+                               return (modifiers & Modifiers.ABSTRACT) != 0;
+                       }
+               }
+
+               public bool IsConstructor {
+                       get {
+                               return MetaInfo.IsConstructor;
+                       }
+               }
+
+               public bool IsGenericMethod {
+                       get {
+                               return MetaInfo.IsGenericMethod;
+                       }
+               }
+
+               // When is virtual or abstract
+               public bool IsVirtual {
+                       get {
+                               return (modifiers & (Modifiers.VIRTUAL | Modifiers.ABSTRACT)) != 0;
+                       }
+               }
+
+               public MethodBase MetaInfo {
+                       get {
+                               return metaInfo;
+                       }
+                       set {
+                               metaInfo = value;
+                       }
+               }
+
+               public AParametersCollection Parameters {
+                       get { return parameters; }
+               }
+
+               public Type ReturnType {
+                       get {
+                               return IsConstructor ?
+                                       TypeManager.void_type : ((MethodInfo) MetaInfo).ReturnType;
+                       }
                }
        }
 
@@ -267,6 +347,8 @@ namespace Mono.CSharp {
                                        MethodBase mb = new PartialMethodDefinitionInfo (this);
                                        Parent.MemberCache.AddMember (mb, this);
                                        TypeManager.AddMethod (mb, this);
+
+                                       spec = new MethodSpec (this, mb, Parameters, ModFlags);
                                }
 
                                return true;
@@ -280,6 +362,8 @@ namespace Mono.CSharp {
                                        
                        MethodBuilder = MethodData.MethodBuilder;
 
+                       spec = new MethodSpec (this, MethodBuilder, Parameters, ModFlags);
+
                        if (TypeManager.IsGenericMethod (MethodBuilder))
                                Parent.MemberCache.AddGenericMember (MethodBuilder, this);
                        
@@ -515,8 +599,8 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Method : MethodOrOperator {
-
+       public class Method : MethodOrOperator, IGenericMethodDefinition
+       {
                /// <summary>
                ///   Modifiers allowed in a class declaration
                /// </summary>
@@ -756,7 +840,7 @@ namespace Mono.CSharp {
                                                        Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
                                                                GetSignatureForError ());
                                                } else {
-                                                       SetMemberIsUsed ();
+                                                       SetIsUsed ();
                                                        RootContext.EntryPoint = this;
                                                }
                                        } else {
@@ -835,6 +919,11 @@ namespace Mono.CSharp {
                        return mi;
                }
 
+               public MethodInfo MakeGenericMethod (Type[] targs)
+               {
+                       return MethodBuilder.MakeGenericMethod (targs);
+               }
+
                public void SetPartialDefinition (Method methodDefinition)
                {
                        caching_flags |= Flags.PartialDefinitionExists;
@@ -957,9 +1046,9 @@ namespace Mono.CSharp {
                        if (!ec.IsStatic)
                                base_constructor_group.InstanceExpression = ec.GetThis (loc);
                        
-                       ConstructorInfo base_ctor = (ConstructorInfo)base_constructor_group;
+                       var base_ctor = base_constructor_group.BestCandidate;
 
-                       if (base_ctor == caller_builder){
+                       if (base_ctor.MetaInfo == caller_builder){
                                ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
                        }
                                                
@@ -1148,6 +1237,8 @@ namespace Mono.CSharp {
                                ca, CallingConventions,
                                Parameters.GetEmitTypes ());
 
+                       spec = new MethodSpec (this, ConstructorBuilder, Parameters, ModFlags);
+
                        if (Parent.PartialContainer.IsComImport) {
                                if (!IsDefault ()) {
                                        Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
@@ -1337,7 +1428,7 @@ namespace Mono.CSharp {
                string GetSignatureForError ();
                bool IsExcluded ();
                bool IsClsComplianceRequired ();
-               void SetMemberIsUsed ();
+               void SetIsUsed ();
                void EmitExtraSymbolInfo (SourceMethod source);
        }
 
index 480185af63eef61c7f9839ff6fa54e2cbe2a42dd..98a5c6501f02949ffaec969cb00e7d7dd6bbdf1e 100644 (file)
@@ -602,9 +602,9 @@ namespace Mono.CSharp {
                /// 
                /// Looks for extension method in this namespace
                /// 
-               public List<MethodBase> LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
+               public List<MethodSpec> LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
                {
-                       List<MethodBase> found = null;
+                       List<MethodSpec> found = null;
 
                        // TODO: problematic
                        var invocation_assembly = CodeGen.Assembly.Builder;
@@ -1033,7 +1033,7 @@ namespace Mono.CSharp {
                ///
                public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
                {
-                       List<MethodBase> candidates = null;
+                       List<MethodSpec> candidates = null;
                        foreach (Namespace n in GetUsingTable ()) {
                                var a = n.LookupExtensionMethod (extensionType, null, name);
                                if (a == null)
index c5ec3b4ff86a72b86d75117fb1413292e9b2bcfd..46709456493e94713f7b94b2676e8012a9a20afb 100644 (file)
@@ -55,10 +55,10 @@ namespace Mono.CSharp.Nullable
        {
                public readonly Type Type;
                public readonly Type UnderlyingType;
-               public MethodInfo HasValue;
-               public MethodInfo Value;
-               public MethodInfo GetValueOrDefault;
-               public ConstructorInfo Constructor;
+               public MethodSpec HasValue;
+               public MethodSpec Value;
+               public MethodSpec GetValueOrDefault;
+               public MethodSpec Constructor;
 
                public NullableInfo (Type type)
                {
@@ -69,8 +69,8 @@ namespace Mono.CSharp.Nullable
                        PropertyInfo value_pi = TypeManager.GetPredefinedProperty (type, "Value", Location.Null, Type.EmptyTypes);
                        GetValueOrDefault = TypeManager.GetPredefinedMethod (type, "GetValueOrDefault", Location.Null, Type.EmptyTypes);
 
-                       HasValue = has_value_pi.GetGetMethod (false);
-                       Value = value_pi.GetGetMethod (false);
+                       HasValue = Import.CreateMethod (has_value_pi.GetGetMethod (false));
+                       Value = Import.CreateMethod (value_pi.GetGetMethod (false));
 
                        // When compiling corlib
                        if (TypeManager.IsBeingCompiled (type)) {
@@ -79,19 +79,19 @@ namespace Mono.CSharp.Nullable
                                // TODO: check for correct overload
                                Constructor c = ((Constructor) tc.InstanceConstructors [0]);
 
-                               Constructor = TypeBuilder.GetConstructor (type, c.ConstructorBuilder);
+                               Constructor = Import.CreateMethod (TypeBuilder.GetConstructor (type, c.ConstructorBuilder));
                                return;
                        }
 
 #if MS_COMPATIBLE
-                       if (TypeManager.IsBeingCompiled (UnderlyingType)) {
-                               ConstructorInfo cinfo = TypeManager.DropGenericTypeArguments (type).GetConstructors ()[0];
-                               Constructor = TypeBuilder.GetConstructor (type, cinfo);
-                               return;
-                       }
+//                     if (TypeManager.IsBeingCompiled (UnderlyingType)) {
+//                             ConstructorInfo cinfo = TypeManager.DropGenericTypeArguments (type).GetConstructors ()[0];
+//                             Constructor = TypeBuilder.GetConstructor (type, cinfo);
+//                             return;
+//                     }
 #endif
 
-                       Constructor = type.GetConstructor (new Type[] { UnderlyingType });
+                       Constructor = Import.CreateMethod (type.GetConstructor (new Type[] { UnderlyingType }));
                }
        }
 
@@ -212,10 +212,10 @@ namespace Mono.CSharp.Nullable
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
                {
                        type = storey.MutateType (type);
-                       info.Constructor = storey.MutateConstructor (info.Constructor);
-                       info.HasValue = storey.MutateGenericMethod (info.HasValue);
-                       info.GetValueOrDefault = storey.MutateGenericMethod (info.GetValueOrDefault);
-                       info.Value = storey.MutateGenericMethod (info.Value);
+                       storey.MutateConstructor (info.Constructor);
+                       storey.MutateGenericMethod (info.HasValue);
+                       storey.MutateGenericMethod (info.GetValueOrDefault);
+                       storey.MutateGenericMethod (info.Value);
                }
 
                public void AddressOf (EmitContext ec, AddressOp mode)
@@ -281,7 +281,7 @@ namespace Mono.CSharp.Nullable
                        public override void Emit (EmitContext ec)
                        {
                                expr.Emit (ec);
-                               ec.ig.Emit (OpCodes.Newobj, info.Constructor);
+                               ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) info.Constructor.MetaInfo);
                        }
                }
        }
@@ -327,7 +327,7 @@ namespace Mono.CSharp.Nullable
                public override void Emit (EmitContext ec)
                {
                        child.Emit (ec);
-                       ec.ig.Emit (OpCodes.Newobj, info.Constructor);
+                       ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) info.Constructor.MetaInfo);
                }
        }
 
@@ -519,7 +519,7 @@ namespace Mono.CSharp.Nullable
                                EmitOperator (ec, ni.UnderlyingType);
                        }
 
-                       ig.Emit (OpCodes.Newobj, ni.Constructor);
+                       ig.Emit (OpCodes.Newobj, (ConstructorInfo) ni.Constructor.MetaInfo);
                        ig.Emit (OpCodes.Br_S, end_label);
 
                        ig.MarkLabel (is_null_label);
@@ -573,7 +573,7 @@ namespace Mono.CSharp.Nullable
                bool left_null_lifted, right_null_lifted;
                Expression left_orig, right_orig;
                Expression user_operator;
-               ConstructorInfo wrap_ctor;
+               MethodSpec wrap_ctor;
 
                public LiftedBinaryOperator (Binary.Operator op, Expression left, Expression right,
                                             Location loc)
@@ -804,7 +804,7 @@ namespace Mono.CSharp.Nullable
                        EmitOperator (ec, left.Type);
 
                        if (wrap_ctor != null)
-                               ig.Emit (OpCodes.Newobj, wrap_ctor);
+                               ig.Emit (OpCodes.Newobj, (ConstructorInfo) wrap_ctor.MetaInfo);
 
                        ig.Emit (OpCodes.Br_S, end_label);
                        ig.MarkLabel (is_null_label);
index 4741b4530f72be634451a70465ec073dc08b8080..1502f667d5ff5fd23b8e3db4409b1a0a407687f1 100644 (file)
@@ -4138,7 +4138,7 @@ namespace Mono.CSharp {
 
                        temp.EmitAssign (ec, expr);
                        temp.Emit (ec);
-                       ig.Emit (OpCodes.Call, TypeManager.void_monitor_enter_object);
+                       ig.Emit (OpCodes.Call, (MethodInfo) TypeManager.void_monitor_enter_object.MetaInfo);
                }
 
                protected override void EmitTryBody (EmitContext ec)
@@ -4149,7 +4149,7 @@ namespace Mono.CSharp {
                protected override void EmitFinallyBody (EmitContext ec)
                {
                        temp.Emit (ec);
-                       ec.ig.Emit (OpCodes.Call, TypeManager.void_monitor_exit_object);
+                       ec.ig.Emit (OpCodes.Call, (MethodInfo) TypeManager.void_monitor_exit_object.MetaInfo);
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
@@ -4945,7 +4945,7 @@ namespace Mono.CSharp {
                                local_copy.Emit (ec);
                                ig.Emit (OpCodes.Brfalse, skip);
                                local_copy.Emit (ec);
-                               ig.Emit (OpCodes.Callvirt, TypeManager.void_dispose_void);
+                               ig.Emit (OpCodes.Callvirt, (MethodInfo) TypeManager.void_dispose_void.MetaInfo);
                                ig.MarkLabel (skip);
                                return;
                        }
@@ -4957,14 +4957,14 @@ namespace Mono.CSharp {
                        if (!(ml is MethodGroupExpr)) {
                                local_copy.Emit (ec);
                                ig.Emit (OpCodes.Box, expr_type);
-                               ig.Emit (OpCodes.Callvirt, TypeManager.void_dispose_void);
+                               ig.Emit (OpCodes.Callvirt, (MethodInfo) TypeManager.void_dispose_void.MetaInfo);
                                return;
                        }
 
-                       MethodInfo mi = null;
+                       MethodSpec mi = null;
 
-                       foreach (MethodInfo mk in ((MethodGroupExpr) ml).Methods) {
-                               if (TypeManager.GetParameterData (mk).Count == 0) {
+                       foreach (var mk in ((MethodGroupExpr) ml).Methods) {
+                               if (mk.Parameters.IsEmpty) {
                                        mi = mk;
                                        break;
                                }
@@ -4976,7 +4976,7 @@ namespace Mono.CSharp {
                        }
 
                        local_copy.AddressOf (ec, AddressOp.Load);
-                       ig.Emit (OpCodes.Call, mi);
+                       ig.Emit (OpCodes.Call, (MethodInfo) mi.MetaInfo);
                }
 
                public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
@@ -5374,7 +5374,7 @@ namespace Mono.CSharp {
 
                        MethodGroupExpr get_enumerator;
                        PropertyExpr get_current;
-                       MethodInfo move_next;
+                       MethodSpec move_next;
                        Expression var_type;
                        Type enumerator_type;
                        bool enumerator_found;
@@ -5394,7 +5394,7 @@ namespace Mono.CSharp {
                                throw new NotImplementedException ();
                        }
 
-                       bool GetEnumeratorFilter (ResolveContext ec, MethodInfo mi)
+                       bool GetEnumeratorFilter (ResolveContext ec, MethodSpec mi)
                        {
                                Type return_type = mi.ReturnType;
 
@@ -5487,7 +5487,7 @@ namespace Mono.CSharp {
                                
                                        if ((TypeManager.GetParameterData (mi).Count == 0) &&
                                            TypeManager.TypeToCoreType (mi.ReturnType) == TypeManager.bool_type) {
-                                               move_next = mi;
+                                               move_next = Import.CreateMethod (mi);
                                                return true;
                                        }
                                }
@@ -5521,8 +5521,9 @@ namespace Mono.CSharp {
                                        TypeManager.CSharpName (expr.Type));
                        }
 
-                       bool IsOverride (MethodInfo m)
+                       bool IsOverride (MethodSpec ms)
                        {
+                               MethodInfo m = (MethodInfo) ms.MetaInfo;
                                m = (MethodInfo) TypeManager.DropGenericMethodArguments (m);
 
                                if (!m.IsVirtual || ((m.Attributes & MethodAttributes.NewSlot) != 0))
@@ -5542,16 +5543,16 @@ namespace Mono.CSharp {
                                if (mg == null)
                                        return false;
 
-                               MethodInfo result = null;
-                               MethodInfo tmp_move_next = null;
+                               MethodSpec result = null;
+                               MethodSpec tmp_move_next = null;
                                PropertyExpr tmp_get_cur = null;
                                Type tmp_enumerator_type = enumerator_type;
-                               foreach (MethodInfo mi in mg.Methods) {
-                                       if (TypeManager.GetParameterData (mi).Count != 0)
+                               foreach (var mi in mg.Methods) {
+                                       if (!mi.Parameters.IsEmpty)
                                                continue;
                        
                                        // Check whether GetEnumerator is public
-                                       if ((mi.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
+                                       if ((mi.MetaInfo.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
                                                continue;
 
                                        if (IsOverride (mi))
@@ -5581,10 +5582,10 @@ namespace Mono.CSharp {
                                                            TypeManager.ImplementsInterface (result.DeclaringType, mi.DeclaringType))
                                                                continue;
 
-                                                       ec.Report.SymbolRelatedToPreviousError (result);
-                                                       ec.Report.SymbolRelatedToPreviousError (mi);
+                                                       ec.Report.SymbolRelatedToPreviousError (result.MetaInfo);
+                                                       ec.Report.SymbolRelatedToPreviousError (mi.MetaInfo);
                                                        ec.Report.Warning (278, 2, loc, "`{0}' contains ambiguous implementation of `{1}' pattern. Method `{2}' is ambiguous with method `{3}'",
-                                                                       TypeManager.CSharpName (t), "enumerable", TypeManager.CSharpSignature (result), TypeManager.CSharpSignature (mi));
+                                                                       TypeManager.CSharpName (t), "enumerable", TypeManager.CSharpSignature (result.MetaInfo), TypeManager.CSharpSignature (mi.MetaInfo));
                                                        return false;
                                                }
                                        }
@@ -5600,7 +5601,7 @@ namespace Mono.CSharp {
                                        move_next = tmp_move_next;
                                        get_current = tmp_get_cur;
                                        enumerator_type = tmp_enumerator_type;
-                                       MethodInfo[] mi = new MethodInfo[] { (MethodInfo) result };
+                                       var mi = new [] { result };
                                        get_enumerator = new MethodGroupExpr (mi, enumerator_type, loc);
 
                                        if (t != expr.Type) {
@@ -5678,7 +5679,7 @@ namespace Mono.CSharp {
 
                                Expression move_next_expr;
                                {
-                                       MemberInfo[] mi = new MemberInfo[] { move_next };
+                                       var mi = new [] { move_next };
                                        MethodGroupExpr mg = new MethodGroupExpr (mi, var_type.Type, loc);
                                        mg.InstanceExpression = enumerator;
 
index 0cd52e4d0a03428861dbf647633ab12141bb5d42..2efc8e699a984417ee42280b04677ef50778e3f4 100644 (file)
@@ -124,22 +124,22 @@ namespace Mono.CSharp {
        // These methods are called by code generated by the compiler
        //
        static public FieldInfo string_empty;
-       static public MethodInfo system_type_get_type_from_handle;
-       static public MethodInfo bool_movenext_void;
-       static public MethodInfo void_dispose_void;
-       static public MethodInfo void_monitor_enter_object;
-       static public MethodInfo void_monitor_exit_object;
-       static public MethodInfo void_initializearray_array_fieldhandle;
-       static public MethodInfo delegate_combine_delegate_delegate;
-       static public MethodInfo delegate_remove_delegate_delegate;
+       static public MethodSpec system_type_get_type_from_handle;
+       static public MethodSpec bool_movenext_void;
+       static public MethodSpec void_dispose_void;
+       static public MethodSpec void_monitor_enter_object;
+       static public MethodSpec void_monitor_exit_object;
+       static public MethodSpec void_initializearray_array_fieldhandle;
+       static public MethodSpec delegate_combine_delegate_delegate;
+       static public MethodSpec delegate_remove_delegate_delegate;
        static public PropertyInfo int_get_offset_to_string_data;
-       static public MethodInfo int_interlocked_compare_exchange;
+       static public MethodSpec int_interlocked_compare_exchange;
        static public PropertyInfo ienumerator_getcurrent;
-       public static MethodInfo methodbase_get_type_from_handle;
-       public static MethodInfo methodbase_get_type_from_handle_generic;
-       public static MethodInfo fieldinfo_get_field_from_handle;
-       public static MethodInfo fieldinfo_get_field_from_handle_generic;
-       static public MethodInfo activator_create_instance;
+       public static MethodSpec methodbase_get_type_from_handle;
+       public static MethodSpec methodbase_get_type_from_handle_generic;
+       public static MethodSpec fieldinfo_get_field_from_handle;
+       public static MethodSpec fieldinfo_get_field_from_handle_generic;
+       static public MethodSpec activator_create_instance;
 
        //
        // The constructors.
@@ -269,14 +269,14 @@ namespace Mono.CSharp {
                void_monitor_enter_object =
                void_monitor_exit_object =
                void_initializearray_array_fieldhandle =
-               delegate_combine_delegate_delegate =
-               delegate_remove_delegate_delegate =
                int_interlocked_compare_exchange =
                methodbase_get_type_from_handle =
                methodbase_get_type_from_handle_generic =
                fieldinfo_get_field_from_handle =
                fieldinfo_get_field_from_handle_generic =
-               activator_create_instance = null;
+               activator_create_instance =
+               delegate_combine_delegate_delegate =
+               delegate_remove_delegate_delegate = null;
 
                int_get_offset_to_string_data =
                ienumerator_getcurrent = null;
@@ -696,6 +696,11 @@ namespace Mono.CSharp {
                return CSharpSignature (mb, false);
        }
 
+       static public string CSharpSignature (MethodSpec ms)
+       {
+               return CSharpSignature (ms.MetaInfo);
+       }
+
        /// <summary>
        ///   Returns the signature of the method
        /// </summary>
@@ -887,9 +892,13 @@ namespace Mono.CSharp {
        // Returns the MethodInfo for a method named `name' defined
        // in type `t' which takes arguments of types `args'
        //
-       public static MethodInfo GetPredefinedMethod (Type t, string name, Location loc, params Type [] args)
+       public static MethodSpec GetPredefinedMethod (Type t, string name, Location loc, params Type [] args)
        {
-               return (MethodInfo)GetPredefinedMember (t, name, MemberTypes.Method, loc, args);
+               var m = GetPredefinedMember (t, name, MemberTypes.Method, loc, args) as MethodBase;
+               if (m == null)
+                       return null;
+
+               return Import.CreateMethod (m);
        }
 
        public static FieldInfo GetPredefinedField (Type t, string name, Location loc, params Type [] args)
@@ -1802,8 +1811,8 @@ namespace Mono.CSharp {
                if (d != null)
                        return d.Parameters;
 
-               MethodInfo invoke_mb = Delegate.GetInvokeMethod (ec.Compiler, t, t);
-               return GetParameterData (invoke_mb);
+               var invoke_mb = Delegate.GetInvokeMethod (ec.Compiler, t, t);
+               return invoke_mb.Parameters;
        }
 
        static public void RegisterOverride (MethodBase override_method, MethodBase base_method)
@@ -1814,8 +1823,9 @@ namespace Mono.CSharp {
                        throw new InternalErrorException ("Override mismatch: " + override_method);
        }
 
-       static public bool IsOverride (MethodBase m)
+       static public bool IsOverride (MethodSpec ms)
        {
+               MethodBase m = ms.MetaInfo;
                m = DropGenericMethodArguments (m);
 
                return m.IsVirtual &&
@@ -2423,7 +2433,7 @@ namespace Mono.CSharp {
        //
        // Returns whether the array of memberinfos contains the given method
        //
-       public static bool ArrayContainsMethod (MemberInfo [] array, MethodBase new_method, bool ignoreDeclType)
+       public static bool ArrayContainsMethod (MethodBase [] array, MethodBase new_method, bool ignoreDeclType)
        {
                Type [] new_args = TypeManager.GetParameterData (new_method).Types;
                
@@ -2643,6 +2653,11 @@ namespace Mono.CSharp {
                return t.GetGenericTypeDefinition ();
        }
 
+       public static MethodBase DropGenericMethodArguments (MethodSpec m)
+       {
+               return DropGenericMethodArguments (m.MetaInfo);
+       }
+
        public static MethodBase DropGenericMethodArguments (MethodBase m)
        {
                if (m.IsGenericMethod)