2 // delegate.cs: Delegate Handler
5 // Ravi Pratap (ravi@ximian.com)
6 // Miguel de Icaza (miguel@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
15 using System.Collections;
16 using System.Reflection;
17 using System.Reflection.Emit;
20 namespace Mono.CSharp {
25 public class Delegate : DeclSpace {
26 public Expression ReturnType;
27 public Parameters Parameters;
29 public ConstructorBuilder ConstructorBuilder;
30 public MethodBuilder InvokeBuilder;
31 public MethodBuilder BeginInvokeBuilder;
32 public MethodBuilder EndInvokeBuilder;
37 static string[] attribute_targets = new string [] { "type", "return" };
39 Expression instance_expr;
40 MethodBase delegate_method;
41 ReturnParameter return_attributes;
43 const int AllowedModifiers =
51 public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,
52 int mod_flags, string name, Parameters param_list,
53 Attributes attrs, Location l)
54 : base (ns, parent, name, attrs, l)
57 this.ReturnType = type;
58 ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
59 IsTopLevel ? Modifiers.INTERNAL :
60 Modifiers.PRIVATE, l);
61 Parameters = param_list;
64 public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
66 if (a.Target == "return") {
67 if (return_attributes == null)
68 return_attributes = new ReturnParameter (InvokeBuilder, Location);
70 return_attributes.ApplyAttributeBuilder (a, cb);
74 base.ApplyAttributeBuilder (a, cb);
77 public override TypeBuilder DefineType ()
79 if (TypeBuilder != null)
82 TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel) |
83 TypeAttributes.Class | TypeAttributes.Sealed;
86 if (TypeManager.NamespaceClash (Name, Location))
89 ModuleBuilder builder = CodeGen.Module.Builder;
91 TypeBuilder = builder.DefineType (
92 Name, attr, TypeManager.multicast_delegate_type);
94 TypeBuilder builder = Parent.TypeBuilder;
96 string name = Name.Substring (1 + Name.LastIndexOf ('.'));
97 TypeBuilder = builder.DefineNestedType (
98 name, attr, TypeManager.multicast_delegate_type);
101 TypeManager.AddDelegateType (Name, TypeBuilder, this);
106 public override bool DefineMembers (TypeContainer container)
111 public override bool Define (TypeContainer container)
113 MethodAttributes mattr;
115 EmitContext ec = new EmitContext (this, this, Location, null,
116 null, ModFlags, false);
118 // FIXME: POSSIBLY make this static, as it is always constant
120 Type [] const_arg_types = new Type [2];
121 const_arg_types [0] = TypeManager.object_type;
122 const_arg_types [1] = TypeManager.intptr_type;
124 mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
125 MethodAttributes.HideBySig | MethodAttributes.Public;
127 ConstructorBuilder = TypeBuilder.DefineConstructor (mattr,
128 CallingConventions.Standard,
131 ConstructorBuilder.DefineParameter (1, ParameterAttributes.None, "object");
132 ConstructorBuilder.DefineParameter (2, ParameterAttributes.None, "method");
134 // HACK because System.Reflection.Emit is lame
137 // FIXME: POSSIBLY make these static, as they are always the same
138 Parameter [] fixed_pars = new Parameter [2];
139 fixed_pars [0] = new Parameter (null, null, Parameter.Modifier.NONE, null);
140 fixed_pars [1] = new Parameter (null, null, Parameter.Modifier.NONE, null);
141 Parameters const_parameters = new Parameters (fixed_pars, null, Location);
143 TypeManager.RegisterMethod (
145 new InternalParameters (const_arg_types, const_parameters),
149 ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
152 // Here the various methods like Invoke, BeginInvoke etc are defined
154 // First, call the `out of band' special method for
155 // defining recursively any types we need:
157 if (!Parameters.ComputeAndDefineParameterTypes (this))
160 param_types = Parameters.GetParameterInfo (this);
161 if (param_types == null)
168 // Check accessibility
169 foreach (Type partype in param_types){
170 if (!container.AsAccessible (partype, ModFlags)) {
171 Report.Error (59, Location,
172 "Inconsistent accessibility: parameter type `" +
173 TypeManager.CSharpName (partype) + "` is less " +
174 "accessible than delegate `" + Name + "'");
177 if (partype.IsPointer && !UnsafeOK (container))
181 ReturnType = ResolveTypeExpr (ReturnType, false, Location);
182 if (ReturnType == null)
185 ret_type = ReturnType.Type;
186 if (ret_type == null)
189 if (!container.AsAccessible (ret_type, ModFlags)) {
190 Report.Error (58, Location,
191 "Inconsistent accessibility: return type `" +
192 TypeManager.CSharpName (ret_type) + "` is less " +
193 "accessible than delegate `" + Name + "'");
197 if (ret_type.IsPointer && !UnsafeOK (container))
201 // We don't have to check any others because they are all
202 // guaranteed to be accessible - they are standard types.
205 CallingConventions cc = Parameters.GetCallingConvention ();
207 mattr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
209 InvokeBuilder = TypeBuilder.DefineMethod ("Invoke",
216 // Define parameters, and count out/ref parameters
220 if (Parameters.FixedParameters != null){
221 int top = Parameters.FixedParameters.Length;
224 for (; i < top; i++) {
225 p = Parameters.FixedParameters [i];
226 p.DefineParameter (ec, InvokeBuilder, null, i + 1, Location);
228 if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
232 if (Parameters.ArrayParameter != null){
233 Parameter p = Parameters.ArrayParameter;
234 p.DefineParameter (ec, InvokeBuilder, null, i + 1, Location);
237 InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
239 TypeManager.RegisterMethod (InvokeBuilder,
240 new InternalParameters (container, Parameters),
246 int params_num = param_types.Length;
247 Type [] async_param_types = new Type [params_num + 2];
249 param_types.CopyTo (async_param_types, 0);
251 async_param_types [params_num] = TypeManager.asynccallback_type;
252 async_param_types [params_num + 1] = TypeManager.object_type;
254 mattr = MethodAttributes.Public | MethodAttributes.HideBySig |
255 MethodAttributes.Virtual | MethodAttributes.NewSlot;
257 BeginInvokeBuilder = TypeBuilder.DefineMethod ("BeginInvoke",
260 TypeManager.iasyncresult_type,
264 if (Parameters.FixedParameters != null){
265 int top = Parameters.FixedParameters.Length;
268 for (i = 0 ; i < top; i++) {
269 p = Parameters.FixedParameters [i];
271 p.DefineParameter (ec, BeginInvokeBuilder, null, i + 1, Location);
274 if (Parameters.ArrayParameter != null){
275 Parameter p = Parameters.ArrayParameter;
276 p.DefineParameter (ec, BeginInvokeBuilder, null, i + 1, Location);
281 BeginInvokeBuilder.DefineParameter (i + 1, ParameterAttributes.None, "callback");
282 BeginInvokeBuilder.DefineParameter (i + 2, ParameterAttributes.None, "object");
284 BeginInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
286 Parameter [] async_params = new Parameter [params_num + 2];
288 if (Parameters.FixedParameters != null){
289 Parameters.FixedParameters.CopyTo (async_params, 0);
290 n = Parameters.FixedParameters.Length;
292 if (Parameters.ArrayParameter != null)
293 async_params [n] = Parameters.ArrayParameter;
295 async_params [params_num] = new Parameter (
296 TypeManager.system_asynccallback_expr, "callback",
297 Parameter.Modifier.NONE, null);
298 async_params [params_num + 1] = new Parameter (
299 TypeManager.system_object_expr, "object",
300 Parameter.Modifier.NONE, null);
302 Parameters async_parameters = new Parameters (async_params, null, Location);
303 async_parameters.ComputeAndDefineParameterTypes (this);
305 async_parameters.ComputeAndDefineParameterTypes (this);
306 TypeManager.RegisterMethod (BeginInvokeBuilder,
307 new InternalParameters (container, async_parameters),
311 // EndInvoke is a bit more interesting, all the parameters labeled as
312 // out or ref have to be duplicated here.
315 Type [] end_param_types = new Type [out_params + 1];
316 Parameter [] end_params = new Parameter [out_params + 1];
319 int top = Parameters.FixedParameters.Length;
320 for (i = 0; i < top; i++){
321 Parameter p = Parameters.FixedParameters [i];
322 if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
325 end_param_types [param] = param_types [i];
326 end_params [param] = p;
330 end_param_types [out_params] = TypeManager.iasyncresult_type;
331 end_params [out_params] = new Parameter (TypeManager.system_iasyncresult_expr, "result", Parameter.Modifier.NONE, null);
334 // Create method, define parameters, register parameters with type system
336 EndInvokeBuilder = TypeBuilder.DefineMethod ("EndInvoke", mattr, cc, ret_type, end_param_types);
337 EndInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
340 // EndInvoke: Label the parameters
342 EndInvokeBuilder.DefineParameter (out_params + 1, ParameterAttributes.None, "result");
343 for (i = 0; i < end_params.Length-1; i++){
344 EndInvokeBuilder.DefineParameter (i + 1, end_params [i].Attributes, end_params [i].Name);
347 Parameters end_parameters = new Parameters (end_params, null, Location);
348 end_parameters.ComputeAndDefineParameterTypes (this);
350 TypeManager.RegisterMethod (
352 new InternalParameters (container, end_parameters),
358 public override void Emit (TypeContainer tc)
360 if (OptAttributes != null) {
361 EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
362 Parameters.LabelParameters (ec, InvokeBuilder, Location);
363 OptAttributes.Emit (ec, this);
369 protected override string[] ValidAttributeTargets {
371 return attribute_targets;
376 protected override bool VerifyClsCompliance (DeclSpace ds)
378 if (!base.VerifyClsCompliance (ds)) {
382 AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
384 if (!AttributeTester.IsClsCompliant (ReturnType.Type)) {
385 Report.Error_T (3002, Location, GetSignatureForError ());
391 /// Verifies whether the method in question is compatible with the delegate
392 /// Returns the method itself if okay and null if not.
394 public static MethodBase VerifyMethod (EmitContext ec, Type delegate_type, MethodBase mb,
397 ParameterData pd = Invocation.GetParameterData (mb);
399 int pd_count = pd.Count;
401 Expression ml = Expression.MemberLookup (
402 ec, delegate_type, "Invoke", loc);
404 if (!(ml is MethodGroupExpr)) {
405 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
409 MethodBase invoke_mb = ((MethodGroupExpr) ml).Methods [0];
411 ParameterData invoke_pd = Invocation.GetParameterData (invoke_mb);
413 if (invoke_pd.Count != pd_count)
416 for (int i = pd_count; i > 0; ) {
419 if (invoke_pd.ParameterType (i) == pd.ParameterType (i) &&
420 invoke_pd.ParameterModifier (i) == pd.ParameterModifier (i))
427 if (((MethodInfo) invoke_mb).ReturnType == ((MethodInfo) mb).ReturnType)
434 // Verifies whether the invocation arguments are compatible with the
435 // delegate's target method
437 public static bool VerifyApplicability (EmitContext ec,
447 arg_count = args.Count;
449 Expression ml = Expression.MemberLookup (
450 ec, delegate_type, "Invoke", loc);
452 if (!(ml is MethodGroupExpr)) {
453 Report.Error (-100, loc, "Internal error: could not find Invoke method!" + delegate_type);
457 MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
458 ParameterData pd = Invocation.GetParameterData (mb);
460 int pd_count = pd.Count;
462 bool params_method = (pd_count != 0) &&
463 (pd.ParameterModifier (pd_count - 1) == Parameter.Modifier.PARAMS);
465 if (!params_method && pd_count != arg_count) {
466 Report.Error (1593, loc,
467 "Delegate '" + delegate_type.ToString ()
468 + "' does not take '" + arg_count + "' arguments");
473 // Consider the case:
474 // delegate void FOO(param object[] args);
475 // FOO f = new FOO(...);
476 // f(new object[] {1, 2, 3});
478 // This should be treated like f(1,2,3). This is done by ignoring the
479 // 'param' modifier for that invocation. If that fails, then the
480 // 'param' modifier is considered.
482 // One issue is that 'VerifyArgumentsCompat' modifies the elements of
483 // the 'args' array. However, the modifications appear idempotent.
484 // Normal 'Invocation's also have the same behaviour, implicitly.
488 if (arg_count == pd_count)
489 ans = Invocation.VerifyArgumentsCompat (ec, args, arg_count, mb, false, delegate_type, loc);
490 if (!ans && params_method)
491 ans = Invocation.VerifyArgumentsCompat (ec, args, arg_count, mb, true, delegate_type, loc);
496 /// Verifies whether the delegate in question is compatible with this one in
497 /// order to determine if instantiation from the same is possible.
499 public static bool VerifyDelegate (EmitContext ec, Type delegate_type, Type probe_type, Location loc)
501 Expression ml = Expression.MemberLookup (
502 ec, delegate_type, "Invoke", loc);
504 if (!(ml is MethodGroupExpr)) {
505 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
509 MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
510 ParameterData pd = Invocation.GetParameterData (mb);
512 Expression probe_ml = Expression.MemberLookup (
513 ec, delegate_type, "Invoke", loc);
515 if (!(probe_ml is MethodGroupExpr)) {
516 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
520 MethodBase probe_mb = ((MethodGroupExpr) probe_ml).Methods [0];
521 ParameterData probe_pd = Invocation.GetParameterData (probe_mb);
523 if (((MethodInfo) mb).ReturnType != ((MethodInfo) probe_mb).ReturnType)
526 if (pd.Count != probe_pd.Count)
529 for (int i = pd.Count; i > 0; ) {
532 if (pd.ParameterType (i) != probe_pd.ParameterType (i) ||
533 pd.ParameterModifier (i) != probe_pd.ParameterModifier (i))
540 public static string FullDelegateDesc (Type del_type, MethodBase mb, ParameterData pd)
542 StringBuilder sb = new StringBuilder (TypeManager.CSharpName (((MethodInfo) mb).ReturnType));
544 sb.Append (" " + del_type.ToString ());
547 int length = pd.Count;
549 for (int i = length; i > 0; ) {
552 sb.Append (pd.ParameterDesc (length - i - 1));
558 return sb.ToString ();
562 // Hack around System.Reflection as found everywhere else
563 public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
564 MemberFilter filter, object criteria)
566 ArrayList members = new ArrayList ();
568 if ((mt & MemberTypes.Method) != 0) {
569 if (ConstructorBuilder != null)
570 if (filter (ConstructorBuilder, criteria))
571 members.Add (ConstructorBuilder);
573 if (InvokeBuilder != null)
574 if (filter (InvokeBuilder, criteria))
575 members.Add (InvokeBuilder);
577 if (BeginInvokeBuilder != null)
578 if (filter (BeginInvokeBuilder, criteria))
579 members.Add (BeginInvokeBuilder);
581 if (EndInvokeBuilder != null)
582 if (filter (EndInvokeBuilder, criteria))
583 members.Add (EndInvokeBuilder);
586 return new MemberList (members);
589 public override MemberCache MemberCache {
595 public Expression InstanceExpression {
597 return instance_expr;
600 instance_expr = value;
604 public MethodBase TargetMethod {
606 return delegate_method;
609 delegate_method = value;
613 public Type TargetReturnType {
619 public Type [] ParameterTypes {
625 public override AttributeTargets AttributeTargets {
627 return AttributeTargets.Delegate | AttributeTargets.ReturnValue;
631 protected override void VerifyObsoleteAttribute()
633 CheckUsageOfObsoleteAttribute (ret_type);
635 foreach (Type type in param_types) {
636 CheckUsageOfObsoleteAttribute (type);
642 // Base class for `NewDelegate' and `ImplicitDelegateCreation'
644 public abstract class DelegateCreation : Expression {
645 protected MethodBase constructor_method;
646 protected MethodBase delegate_method;
647 protected Expression delegate_instance_expr;
649 public DelegateCreation () {}
651 public static void Error_NoMatchingMethodForDelegate (EmitContext ec, MethodGroupExpr mg, Type type, Location loc)
655 if (mg.Methods.Length > 1)
656 method_desc = mg.Methods [0].Name;
658 method_desc = Invocation.FullMethodDesc (mg.Methods [0]);
660 Expression invoke_method = Expression.MemberLookup (
661 ec, type, "Invoke", MemberTypes.Method,
662 Expression.AllBindingFlags, loc);
663 MethodBase method = ((MethodGroupExpr) invoke_method).Methods [0];
664 ParameterData param = Invocation.GetParameterData (method);
665 string delegate_desc = Delegate.FullDelegateDesc (type, method, param);
667 Report.Error (123, loc, "Method '" + method_desc + "' does not " +
668 "match delegate '" + delegate_desc + "'");
671 public override void Emit (EmitContext ec)
673 if (delegate_instance_expr == null ||
674 delegate_method.IsStatic)
675 ec.ig.Emit (OpCodes.Ldnull);
677 delegate_instance_expr.Emit (ec);
679 if (delegate_method.IsVirtual) {
680 ec.ig.Emit (OpCodes.Dup);
681 ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
683 ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
684 ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
687 protected bool ResolveConstructorMethod (EmitContext ec)
689 Expression ml = Expression.MemberLookup (
690 ec, type, ".ctor", loc);
692 if (!(ml is MethodGroupExpr)) {
693 Report.Error (-100, loc, "Internal error: Could not find delegate constructor!");
697 constructor_method = ((MethodGroupExpr) ml).Methods [0];
701 protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg)
703 foreach (MethodInfo mi in mg.Methods){
704 delegate_method = Delegate.VerifyMethod (ec, type, mi, loc);
706 if (delegate_method != null)
710 if (delegate_method == null) {
711 Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
716 // Check safe/unsafe of the delegate
719 ParameterData param = Invocation.GetParameterData (delegate_method);
720 int count = param.Count;
722 for (int i = 0; i < count; i++){
723 if (param.ParameterType (i).IsPointer){
724 Expression.UnsafeError (loc);
730 //TODO: implement caching when performance will be low
731 IMethodData md = TypeManager.GetMethod (delegate_method);
733 if (System.Attribute.GetCustomAttribute (delegate_method, TypeManager.conditional_attribute_type) != null) {
734 // Cannot create delegate with '{0}' because it has a Conditional attribute
735 Report.Error_T (1618, loc, TypeManager.CSharpSignature (delegate_method));
738 if (md.OptAttributes != null && md.OptAttributes.Search (TypeManager.conditional_attribute_type, ec) != null) {
739 // Cannot create delegate with '{0}' because it has a Conditional attribute
740 Report.Error_T (1618, loc, TypeManager.CSharpSignature (delegate_method));
744 if (mg.InstanceExpression != null)
745 delegate_instance_expr = mg.InstanceExpression.Resolve (ec);
748 if (!delegate_method.IsStatic){
749 Report.Error (120, loc,
750 "An object reference is required for the non-static method " +
751 delegate_method.Name);
754 delegate_instance_expr = null;
756 delegate_instance_expr = ec.GetThis (loc);
759 if (delegate_instance_expr != null)
760 if (delegate_instance_expr.Type.IsValueType)
761 delegate_instance_expr = new BoxedCast (delegate_instance_expr);
763 eclass = ExprClass.Value;
769 // Created from the conversion code
771 public class ImplicitDelegateCreation : DelegateCreation {
773 ImplicitDelegateCreation (Type t, Location l)
779 public override Expression DoResolve (EmitContext ec)
784 static public Expression Create (EmitContext ec, MethodGroupExpr mge, Type target_type, Location loc)
786 ImplicitDelegateCreation d = new ImplicitDelegateCreation (target_type, loc);
787 if (d.ResolveConstructorMethod (ec))
788 return d.ResolveMethodGroupExpr (ec, mge);
795 // A delegate-creation-expression, invoked from the `New' class
797 public class NewDelegate : DelegateCreation {
798 public ArrayList Arguments;
801 // This constructor is invoked from the `New' expression
803 public NewDelegate (Type type, ArrayList Arguments, Location loc)
806 this.Arguments = Arguments;
810 public override Expression DoResolve (EmitContext ec)
812 if (Arguments == null || Arguments.Count != 1) {
813 Report.Error (149, loc,
814 "Method name expected");
818 if (!ResolveConstructorMethod (ec))
821 Argument a = (Argument) Arguments [0];
823 Expression invoke_method = Expression.MemberLookup (
824 ec, type, "Invoke", MemberTypes.Method,
825 Expression.AllBindingFlags, loc);
827 if (invoke_method == null) {
828 Report.Error (-200, loc, "Internal error ! Could not find Invoke method!");
832 if (!a.ResolveMethodGroup (ec, loc))
835 Expression e = a.Expr;
837 MethodGroupExpr mg = e as MethodGroupExpr;
839 return ResolveMethodGroupExpr (ec, mg);
841 Type e_type = e.Type;
843 if (!TypeManager.IsDelegateType (e_type)) {
844 e.Error_UnexpectedKind ("method");
848 // This is what MS' compiler reports. We could always choose
849 // to be more verbose and actually give delegate-level specifics
851 if (!Delegate.VerifyDelegate (ec, type, e_type, loc)) {
852 Report.Error (29, loc, "Cannot implicitly convert type '" + e_type + "' " +
853 "to type '" + type + "'");
857 delegate_instance_expr = e;
858 delegate_method = ((MethodGroupExpr) invoke_method).Methods [0];
860 eclass = ExprClass.Value;
864 public override void Emit (EmitContext ec)
866 if (delegate_instance_expr == null || delegate_method.IsStatic)
867 ec.ig.Emit (OpCodes.Ldnull);
869 delegate_instance_expr.Emit (ec);
871 if (delegate_method.IsVirtual) {
872 ec.ig.Emit (OpCodes.Dup);
873 ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
875 ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
876 ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
880 public class DelegateInvocation : ExpressionStatement {
882 public Expression InstanceExpr;
883 public ArrayList Arguments;
887 public DelegateInvocation (Expression instance_expr, ArrayList args, Location loc)
889 this.InstanceExpr = instance_expr;
890 this.Arguments = args;
894 public override Expression DoResolve (EmitContext ec)
896 if (InstanceExpr is EventExpr) {
898 EventInfo ei = ((EventExpr) InstanceExpr).EventInfo;
900 Expression ml = MemberLookup (
901 ec, ec.ContainerType, ei.Name,
902 MemberTypes.Event, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
906 // If this is the case, then the Event does not belong
907 // to this Type and so, according to the spec
908 // cannot be accessed directly
910 // Note that target will not appear as an EventExpr
911 // in the case it is being referenced within the same type container;
912 // it will appear as a FieldExpr in that case.
915 Assign.error70 (ei, loc);
921 Type del_type = InstanceExpr.Type;
922 if (del_type == null)
925 if (Arguments != null){
926 foreach (Argument a in Arguments){
927 if (!a.Resolve (ec, loc))
932 if (!Delegate.VerifyApplicability (ec, del_type, Arguments, loc))
935 Expression lookup = Expression.MemberLookup (ec, del_type, "Invoke", loc);
936 if (!(lookup is MethodGroupExpr)) {
937 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
941 method = ((MethodGroupExpr) lookup).Methods [0];
942 type = ((MethodInfo) method).ReturnType;
943 eclass = ExprClass.Value;
948 public override void Emit (EmitContext ec)
951 // Invocation on delegates call the virtual Invoke member
952 // so we are always `instance' calls
954 Invocation.EmitCall (ec, false, false, InstanceExpr, method, Arguments, loc);
957 public override void EmitStatement (EmitContext ec)
961 // Pop the return value if there is one
963 if (method is MethodInfo){
964 if (((MethodInfo) method).ReturnType != TypeManager.void_type)
965 ec.ig.Emit (OpCodes.Pop);