ReturnParameter return_attributes;
MemberCache member_cache;
-
+
+ const MethodAttributes mattr = MethodAttributes.Public | MethodAttributes.HideBySig |
+ MethodAttributes.Virtual | MethodAttributes.NewSlot;
+
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
if (TypeBuilder != null)
return TypeBuilder;
- if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
- Namespace system = RootNamespace.Global.GetNamespace ("System", true);
- TypeExpr expr = system.Lookup (this, "MulticastDelegate", Location) as TypeExpr;
- TypeManager.multicast_delegate_type = expr.Type;
- }
-
- if (TypeManager.multicast_delegate_type == null)
- Report.Error (-100, Location, "Internal error: delegate used before " +
- "System.MulticastDelegate is resolved. This can only " +
- "happen during corlib compilation, when using a delegate " +
- "in any of the `core' classes. See bug #72015 for details.");
-
if (IsTopLevel) {
if (TypeManager.NamespaceClash (Name, Location))
return null;
// Check accessibility
foreach (Type partype in Parameters.Types){
- if (!Parent.AsAccessible (partype, ModFlags)) {
+ if (!IsAccessibleAs (partype)) {
+ Report.SymbolRelatedToPreviousError (partype);
Report.Error (59, Location,
"Inconsistent accessibility: parameter type `" +
TypeManager.CSharpName (partype) + "' is less " +
- "accessible than delegate `" + Name + "'");
+ "accessible than delegate `" + GetSignatureForError () + "'");
return false;
}
}
ret_type = ReturnType.Type;
- if (!Parent.AsAccessible (ret_type, ModFlags)) {
+ if (!IsAccessibleAs (ret_type)) {
+ Report.SymbolRelatedToPreviousError (ret_type);
Report.Error (58, Location,
"Inconsistent accessibility: return type `" +
TypeManager.CSharpName (ret_type) + "' is less " +
- "accessible than delegate `" + Name + "'");
+ "accessible than delegate `" + GetSignatureForError () + "'");
return false;
}
+ CheckProtectedModifier ();
+
if (RootContext.StdLib && (ret_type == TypeManager.arg_iterator_type || ret_type == TypeManager.typed_reference_type)) {
Method.Error1599 (Location, ret_type);
return false;
CallingConventions cc = Parameters.CallingConvention;
- const MethodAttributes mattr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.NewSlot;
-
InvokeBuilder = TypeBuilder.DefineMethod ("Invoke",
mattr,
cc,
TypeManager.RegisterMethod (InvokeBuilder, Parameters);
member_cache.AddMember (InvokeBuilder, this);
+ if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null) {
+ DefineAsyncMethods (cc);
+ }
+
+ return true;
+ }
+
+ void DefineAsyncMethods (CallingConventions cc)
+ {
//
// BeginInvoke
//
-
- Parameters async_parameters = Parameters.MergeGenerated (Parameters,
+ Parameters async_parameters = Parameters.MergeGenerated (Parameters,
new Parameter (TypeManager.asynccallback_type, "callback", Parameter.Modifier.NONE, null, Location),
new Parameter (TypeManager.object_type, "object", Parameter.Modifier.NONE, null, Location));
-
+
BeginInvokeBuilder = TypeBuilder.DefineMethod ("BeginInvoke",
mattr, cc, TypeManager.iasyncresult_type, async_parameters.Types);
if (out_params > 0) {
Type [] end_param_types = new Type [out_params];
- Parameter [] end_params = new Parameter [out_params ];
+ Parameter [] end_params = new Parameter [out_params];
- int param = 0;
+ int param = 0;
for (int i = 0; i < Parameters.FixedParameters.Length; ++i) {
Parameter p = Parameters.FixedParameters [i];
if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
continue;
- end_param_types [param] = p.ExternalType();
+ end_param_types [param] = p.ExternalType ();
end_params [param] = p;
++param;
}
end_parameters = Parameters.CreateFullyResolved (end_params, end_param_types);
- }
- else {
+ } else {
end_parameters = Parameters.EmptyReadOnlyParameters;
}
end_parameters = Parameters.MergeGenerated (end_parameters,
new Parameter (TypeManager.iasyncresult_type, "result", Parameter.Modifier.NONE, null, Location));
-
+
//
// Create method, define parameters, register parameters with type system
//
end_parameters.ApplyAttributes (EndInvokeBuilder);
TypeManager.RegisterMethod (EndInvokeBuilder, end_parameters);
member_cache.AddMember (EndInvokeBuilder, this);
-
- return true;
}
public override void Emit ()
{
Parameters.ApplyAttributes (InvokeBuilder);
- Parameters p = (Parameters)TypeManager.GetParameterData (BeginInvokeBuilder);
- p.ApplyAttributes (BeginInvokeBuilder);
+ if (BeginInvokeBuilder != null) {
+ Parameters p = (Parameters) TypeManager.GetParameterData (BeginInvokeBuilder);
+ p.ApplyAttributes (BeginInvokeBuilder);
+ }
if (OptAttributes != null) {
OptAttributes.Emit ();
Location loc)
{
MethodInfo invoke_mb = GetInvokeMethod (container_type, delegate_type);
+ if (invoke_mb == null)
+ return null;
+
ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
#if GMCS_SOURCE
- if (!old_mg.HasTypeArguments &&
+ if (old_mg.type_arguments == null &&
!TypeManager.InferTypeArguments (invoke_pd, ref mb))
return null;
#endif
Type invoke_mb_retval = ((MethodInfo) invoke_mb).ReturnType;
Type mb_retval = ((MethodInfo) mb).ReturnType;
- if (invoke_mb_retval == mb_retval)
+ if (TypeManager.TypeToCoreType (invoke_mb_retval) == TypeManager.TypeToCoreType (mb_retval))
return mb;
//if (!IsTypeCovariant (mb_retval, invoke_mb_retval))
bool params_method = pd.HasParams;
bool is_params_applicable = false;
me.DelegateType = delegate_type;
- bool is_applicable = me.IsApplicable (ec, args, arg_count, ref mb) == 0;
-
- if (!is_applicable && params_method &&
- me.IsParamsMethodApplicable (ec, args, arg_count, ref mb))
- is_applicable = is_params_applicable = true;
+ bool is_applicable = me.IsApplicable (ec, args, arg_count, ref mb, ref is_params_applicable) == 0;
if (!is_applicable && !params_method && arg_count != pd_count) {
Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
}
return me.VerifyArgumentsCompat (
- ec, args, arg_count, mb,
+ ec, ref args, arg_count, mb,
is_params_applicable || (!is_applicable && params_method),
false, loc);
}
public abstract class DelegateCreation : Expression, MethodGroupExpr.IErrorHandler
{
protected ConstructorInfo constructor_method;
- protected MethodBase delegate_method;
+ protected MethodInfo delegate_method;
// We keep this to handle IsBase only
protected MethodGroupExpr method_group;
protected Expression delegate_instance_expression;
atype = atype.GetElementType ();
break;
case Parameter.Modifier.ARGLIST:
- // TODO: investigate and test
- throw new NotImplementedException ();
+ // __arglist is not valid
+ throw new InternalErrorException ("__arglist modifier");
default:
atype_modifier = Argument.AType.Expression;
break;
MethodInfo invoke_method = Delegate.GetInvokeMethod (ec.ContainerType, type);
method_group.DelegateType = type;
method_group.CustomErrorHandler = this;
- method_group = method_group.OverloadResolve (ec, CreateDelegateMethodArguments (invoke_method), false, loc);
+
+ ArrayList arguments = CreateDelegateMethodArguments (invoke_method);
+ method_group = method_group.OverloadResolve (ec, ref arguments, false, loc);
if (method_group == null)
return null;
delegate_method = (MethodInfo) method_group;
- if (method_group is ExtensionMethodGroupExpr) {
- ParameterData p = TypeManager.GetParameterData (delegate_method);
- if (p.ExtensionMethodType.IsValueType) {
+ ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
+ if (emg != null) {
+ delegate_instance_expression = emg.ExtensionExpression;
+ Type e_type = delegate_instance_expression.Type;
+ if (TypeManager.IsValueType (e_type)) {
Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
- TypeManager.CSharpSignature (delegate_method), TypeManager.CSharpName (p.ExtensionMethodType));
+ TypeManager.CSharpSignature (delegate_method), TypeManager.CSharpName (e_type));
}
}
- Expression ret_expr = new TypeExpression (((MethodInfo) delegate_method).ReturnType, loc);
- if (!Delegate.IsTypeCovariant (ret_expr, (invoke_method.ReturnType))) {
+ Type rt = TypeManager.TypeToCoreType (delegate_method.ReturnType);
+ Expression ret_expr = new TypeExpression (rt, loc);
+ if (!Delegate.IsTypeCovariant (ret_expr, (TypeManager.TypeToCoreType (invoke_method.ReturnType)))) {
Error_ConversionFailed (ec, delegate_method, ret_expr);
}
+ DoResolveInstanceExpression (ec);
+ eclass = ExprClass.Value;
+ return this;
+ }
+
+ void DoResolveInstanceExpression (EmitContext ec)
+ {
+ //
+ // Argument is another delegate
+ //
+ if (delegate_instance_expression != null)
+ return;
+
if (method_group.InstanceExpression != null)
delegate_instance_expression = method_group.InstanceExpression;
- else if (!ec.IsStatic)
+ else if (!delegate_method.IsStatic && !ec.IsStatic)
delegate_instance_expression = ec.GetThis (loc);
if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
delegate_instance_expression = new BoxedCast (
delegate_instance_expression, TypeManager.object_type);
-
- eclass = ExprClass.Value;
- return this;
}
public override void Emit (EmitContext ec)
{
- if (delegate_instance_expression == null || delegate_method.IsStatic)
+ if (delegate_instance_expression == null)
ec.ig.Emit (OpCodes.Ldnull);
else
delegate_instance_expression.Emit (ec);
- if (delegate_method.IsVirtual && !method_group.IsBase) {
+ if (!delegate_method.DeclaringType.IsSealed && delegate_method.IsVirtual && !method_group.IsBase) {
ec.ig.Emit (OpCodes.Dup);
ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
} else
public static MethodBase ImplicitStandardConversionExists (MethodGroupExpr mg, Type target_type)
{
+ if (target_type == TypeManager.delegate_type || target_type == TypeManager.multicast_delegate_type)
+ return null;
+
foreach (MethodInfo mi in mg.Methods){
MethodBase mb = Delegate.VerifyMethod (mg.DeclaringType, target_type, mg, mi, Location.Null);
if (mb != null)
Expression e = a.Expr;
if (e is AnonymousMethodExpression && RootContext.Version != LanguageVersion.ISO_1) {
- AnonymousMethod am = ((AnonymousMethodExpression) e).Compatible (ec, type);
- if (am == null)
+ e = ((AnonymousMethodExpression) e).Compatible (ec, type);
+ if (e == null)
return null;
- return am.Resolve (ec);
+ return e.Resolve (ec);
}
method_group = e as MethodGroupExpr;
method = Delegate.GetInvokeMethod (ec.ContainerType, del_type);
type = ((MethodInfo) method).ReturnType;
+ type = TypeManager.TypeToCoreType (type);
eclass = ExprClass.Value;
return this;