* *.cs: Introduced non-generic method specification.
svn path=/trunk/mcs/; revision=149419
+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.
//
// 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)
// 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);
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);
}
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)
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);
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);
}
}
- protected virtual ConstructorInfo ResolveConstructor (ResolveContext ec)
+ protected virtual MethodSpec ResolveConstructor (ResolveContext ec)
{
if (PosArguments != null) {
bool dynamic;
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;
}
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;
}
}
- protected override ConstructorInfo ResolveConstructor (ResolveContext ec)
+ protected override MethodSpec ResolveConstructor (ResolveContext ec)
{
try {
Enter ();
if (is_type_exposed)
continue;
- f.SetMemberIsUsed ();
+ f.SetIsUsed ();
}
if (!f.IsUsed){
{
if (my_event != null) {
// my_event.SetAssigned ();
- my_event.SetMemberIsUsed ();
+ my_event.SetIsUsed ();
}
}
}
if (!base.Define ())
return false;
- SetMemberIsUsed ();
+ SetIsUsed ();
return true;
}
}
if (!HasBackingField) {
- SetMemberIsUsed ();
+ SetIsUsed ();
return true;
}
// 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);
{
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;
}
/// 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> ();
// 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;
/// <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> ();
//
// 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;
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)
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];
/// 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;
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)
bool look_for_explicit, bool return_convert)
{
Type source_type = source.Type;
- MethodInfo method = null;
+ MethodSpec method = null;
Expression expr = null;
object o;
}
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;
}
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
/// 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
}
}
- public void SetMemberIsUsed ()
+ public void SetIsUsed ()
{
caching_flags |= Flags.IsUsed;
}
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)
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 {
}
}
- public interface IMemberDetails
+ //
+ // Member details which are same between all member
+ // specifications
+ //
+ public interface IMemberDefinition
{
ObsoleteAttribute GetObsoleteAttribute ();
+ void SetIsUsed ();
}
/// <summary>
//
// 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)
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;
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));
}
}
}
- 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;
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,
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;
}
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,
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;
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 {
//
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;
{
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;
}
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));
}
}
}
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));
}
}
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;
}
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;
}
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;
}
// 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);
}
{
readonly Expression InstanceExpr;
Arguments arguments;
- MethodInfo method;
+ MethodSpec method;
public DelegateInvocation (Expression instance_expr, Arguments args, Location loc)
{
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;
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
- method = storey.MutateGenericMethod (method);
+ storey.MutateGenericMethod (method);
type = storey.MutateType (type);
if (arguments != null)
//
//
+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
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
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;
}
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));
}
}
}
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);
}
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)
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;
{
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;
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;
}
}
}
+ public MethodSpec BestCandidate {
+ get {
+ return best_candidate;
+ }
+ }
+
public Type DelegateType {
set {
delegate_type = value;
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 {
if (best_candidate != null)
return !best_candidate.IsStatic;
- foreach (MethodBase mb in Methods)
+ foreach (var mb in Methods)
if (!mb.IsStatic)
return true;
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;
}
//
/// 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;
//
// 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;
}
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");
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));
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",
Name, arg_count.ToString ());
}
- protected virtual int GetApplicableParametersCount (MethodBase method, AParametersCollection parameters)
+ protected virtual int GetApplicableParametersCount (MethodSpec method, AParametersCollection parameters)
{
return parameters.Count;
}
/// 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;
}
}
- 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;
//
// 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)
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);
}
{
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>
{
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
//
// 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;
// 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;
}
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;
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) {
}
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);
// 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);
candidate, cand_params))
{
if (!may_fail)
- ec.Report.SymbolRelatedToPreviousError (candidate);
+ ec.Report.SymbolRelatedToPreviousError (candidate.MetaInfo);
ambiguous = candidate;
}
}
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);
}
}
}
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;
//
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;
}
// 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);
}
}
}
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;
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];
"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",
protected override Expression DoResolve (ResolveContext rc)
{
-// constant.IsUsed = true;
+ constant.MemberDefinition.SetIsUsed ();
if (!rc.IsObsolete) {
var oa = constant.GetObsoleteAttribute ();
public Expression CreateTypeOfExpression ()
{
- return new TypeOfField (GetConstructedFieldInfo (), loc);
+ return new TypeOfField (Import.CreateField (GetConstructedFieldInfo ()), loc);
}
protected override Expression DoResolve (ResolveContext ec)
if ((f.ModFlags & Modifiers.VOLATILE) != 0)
is_volatile = true;
- f.SetMemberIsUsed ();
+ f.SetIsUsed ();
}
if (IsStatic){
if ((mode & AddressOp.Store) != 0)
f.SetAssigned ();
if ((mode & AddressOp.Load) != 0)
- f.SetMemberIsUsed ();
+ f.SetIsUsed ();
}
//
public class PropertyExpr : MemberExpr, IDynamicAssign
{
public readonly PropertyInfo PropertyInfo;
- MethodInfo getter, setter;
+ MethodSpec getter, setter;
bool is_static;
TypeArguments targs;
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;
MethodBase the_getter = TypeManager.DropGenericMethodArguments (getter);
IMethodData md = TypeManager.GetMethod (the_getter);
if (md != null)
- md.SetMemberIsUsed ();
+ md.SetIsUsed ();
is_static = getter.IsStatic;
}
MethodBase the_setter = TypeManager.DropGenericMethodArguments (setter);
IMethodData md = TypeManager.GetMethod (the_setter);
if (md != null)
- md.SetMemberIsUsed ();
+ md.SetIsUsed ();
is_static = setter.IsStatic;
}
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)
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)
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 ());
}
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);
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;
}
if (getter != null) {
- if (TypeManager.GetParameterData (getter).Count != 0) {
+ if (!getter.Parameters.IsEmpty) {
Error_PropertyNotFound (ec, getter, true);
return false;
}
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;
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;
return false;
if (IsBase && add_accessor.IsAbstract) {
- Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(add_accessor));
+ Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(add_accessor.MetaInfo));
return false;
}
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;
}
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 {
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));
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);
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
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);
}
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;
}
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;
}
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);
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;
/// <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 ();
return false;
}
- return AttributeTester.IsConditionalMethodExcluded (method, loc);
+ return AttributeTester.IsConditionalMethodExcluded (mb, loc);
}
/// <remarks>
/// </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);
}
// 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;
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;
}
// 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)
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)
{
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) {
}
if (vr != null) {
- ig.Emit (OpCodes.Call, (ConstructorInfo) method);
+ ig.Emit (OpCodes.Call, (ConstructorInfo) method.BestCandidate.MetaInfo);
return false;
}
}
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);
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);
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)
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);
}
//
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)
}
}
- 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);
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);
get { return "RuntimeMethodHandle"; }
}
- protected override MethodInfo TypeFromHandle {
+ protected override MethodSpec TypeFromHandle {
get {
return TypeManager.methodbase_get_type_from_handle;
}
}
}
- protected override MethodInfo TypeFromHandleGeneric {
+ protected override MethodSpec TypeFromHandleGeneric {
get {
return TypeManager.methodbase_get_type_from_handle_generic;
}
}
}
- 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;
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);
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);
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)
{
}
public override void Emit (EmitContext ec)
{
- ec.ig.Emit (OpCodes.Ldtoken, (FieldInfo) member);
+ ec.ig.Emit (OpCodes.Ldtoken, member.MetaInfo);
base.Emit (ec);
}
get { return "RuntimeFieldHandle"; }
}
- protected override MethodInfo TypeFromHandle {
+ protected override MethodSpec TypeFromHandle {
get {
return TypeManager.fieldinfo_get_field_from_handle;
}
}
}
- protected override MethodInfo TypeFromHandleGeneric {
+ protected override MethodSpec TypeFromHandleGeneric {
get {
return TypeManager.fieldinfo_get_field_from_handle_generic;
}
}
}
- 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
class Indexers
{
// Contains either property getter or setter
- public List<MethodBase> Methods;
+ public List<MethodSpec> Methods;
public List<PropertyInfo> Properties;
Indexers ()
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);
}
}
//
// Points to our "data" repository
//
- MethodInfo get, set;
+ MethodSpec get, set;
bool is_base_indexer;
bool prepared;
LocalTemporary temp;
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;
}
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",
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 {
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
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
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)
}
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;
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);
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);
}
}
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)
{
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;
}
}
}
- // Obsolete
- public Type DeclaringType {
+ public override Type DeclaringType {
get {
return MetaInfo.DeclaringType;
}
{
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;
}
/// 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);
if (i_args.Length == 0)
return 0;
- method = ((MethodInfo) method).MakeGenericMethod (i_args);
+ method = method.Inflate (i_args);
return 0;
}
}
}
- public abstract Type[] InferMethodArguments (ResolveContext ec, MethodBase method);
+ public abstract Type[] InferMethodArguments (ResolveContext ec, MethodSpec method);
// public abstract Type[] InferDelegateArguments (ResolveContext ec, MethodBase method);
}
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;
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))
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);
// 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))
}
// All generic input arguments have to be fixed
- AParametersCollection d_parameters = TypeManager.GetParameterData (invoke);
+ AParametersCollection d_parameters = invoke.Parameters;
return AllTypesAreFixed (d_parameters.Types);
}
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;
}
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;
{
public static FieldSpec CreateField (FieldInfo fi)
{
- // TODO: remove after MemberCache fix
+ // TODO MemberCache: remove
var cs = TypeManager.GetConstant (fi);
if (cs != null)
return cs;
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) {
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;
// 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;
}
//
}
}
- class ImportedMemberDetails : IMemberDetails
+ class ImportedMemberDefinition : IMemberDefinition
{
- readonly ICustomAttributeProvider provider;
+ protected readonly ICustomAttributeProvider provider;
- public ImportedMemberDetails (ICustomAttributeProvider provider)
+ public ImportedMemberDefinition (ICustomAttributeProvider provider)
{
this.provider = provider;
}
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
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);
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);
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];
}
}
- if (!TypeManager.IsGenericMethod (method))
+ if (!method.IsGenericMethod)
return false;
if (mg.Name == "SelectMany") {
{
public readonly ParametersCompiled Parameters;
protected ToplevelBlock block;
+ protected MethodSpec spec;
public MethodCore (DeclSpace parent, GenericMethod generic,
FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
return base.EnableOverloadChecks (overload);
}
+ public MethodSpec Spec {
+ get { return spec; }
+ }
+
protected override bool VerifyClsCompliance ()
{
if (!base.VerifyClsCompliance ())
}
}
+ 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;
+ }
}
}
MethodBase mb = new PartialMethodDefinitionInfo (this);
Parent.MemberCache.AddMember (mb, this);
TypeManager.AddMethod (mb, this);
+
+ spec = new MethodSpec (this, mb, Parameters, ModFlags);
}
return true;
MethodBuilder = MethodData.MethodBuilder;
+ spec = new MethodSpec (this, MethodBuilder, Parameters, ModFlags);
+
if (TypeManager.IsGenericMethod (MethodBuilder))
Parent.MemberCache.AddGenericMember (MethodBuilder, this);
}
}
- public class Method : MethodOrOperator {
-
+ public class Method : MethodOrOperator, IGenericMethodDefinition
+ {
/// <summary>
/// Modifiers allowed in a class declaration
/// </summary>
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 {
return mi;
}
+ public MethodInfo MakeGenericMethod (Type[] targs)
+ {
+ return MethodBuilder.MakeGenericMethod (targs);
+ }
+
public void SetPartialDefinition (Method methodDefinition)
{
caching_flags |= Flags.PartialDefinitionExists;
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));
}
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",
string GetSignatureForError ();
bool IsExcluded ();
bool IsClsComplianceRequired ();
- void SetMemberIsUsed ();
+ void SetIsUsed ();
void EmitExtraSymbolInfo (SourceMethod source);
}
///
/// 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;
///
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)
{
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)
{
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)) {
// 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 }));
}
}
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)
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);
}
}
}
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);
}
}
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);
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)
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);
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)
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)
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;
}
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;
}
}
local_copy.AddressOf (ec, AddressOp.Load);
- ig.Emit (OpCodes.Call, mi);
+ ig.Emit (OpCodes.Call, (MethodInfo) mi.MetaInfo);
}
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
MethodGroupExpr get_enumerator;
PropertyExpr get_current;
- MethodInfo move_next;
+ MethodSpec move_next;
Expression var_type;
Type enumerator_type;
bool enumerator_found;
throw new NotImplementedException ();
}
- bool GetEnumeratorFilter (ResolveContext ec, MethodInfo mi)
+ bool GetEnumeratorFilter (ResolveContext ec, MethodSpec mi)
{
Type return_type = mi.ReturnType;
if ((TypeManager.GetParameterData (mi).Count == 0) &&
TypeManager.TypeToCoreType (mi.ReturnType) == TypeManager.bool_type) {
- move_next = mi;
+ move_next = Import.CreateMethod (mi);
return true;
}
}
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))
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))
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;
}
}
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) {
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;
// 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.
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;
return CSharpSignature (mb, false);
}
+ static public string CSharpSignature (MethodSpec ms)
+ {
+ return CSharpSignature (ms.MetaInfo);
+ }
+
/// <summary>
/// Returns the signature of the method
/// </summary>
// 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)
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)
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 &&
//
// 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;
return t.GetGenericTypeDefinition ();
}
+ public static MethodBase DropGenericMethodArguments (MethodSpec m)
+ {
+ return DropGenericMethodArguments (m.MetaInfo);
+ }
+
public static MethodBase DropGenericMethodArguments (MethodBase m)
{
if (m.IsGenericMethod)