2 // delegate.cs: Delegate Handler
\r
5 // Ravi Pratap (ravi@ximian.com)
\r
6 // Miguel de Icaza (miguel@ximian.com)
\r
8 // Licensed under the terms of the GNU GPL
\r
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
\r
15 using System.Collections;
\r
16 using System.Reflection;
\r
17 using System.Reflection.Emit;
\r
20 namespace Mono.CSharp {
\r
25 public class Delegate : DeclSpace {
\r
26 public Expression ReturnType;
\r
27 public Parameters Parameters;
\r
29 public ConstructorBuilder ConstructorBuilder;
\r
30 public MethodBuilder InvokeBuilder;
\r
31 public MethodBuilder BeginInvokeBuilder;
\r
32 public MethodBuilder EndInvokeBuilder;
\r
34 Type [] param_types;
\r
37 Expression instance_expr;
\r
38 MethodBase delegate_method;
\r
40 const int AllowedModifiers =
\r
43 Modifiers.PROTECTED |
\r
44 Modifiers.INTERNAL |
\r
48 public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,
\r
49 int mod_flags, string name, Parameters param_list,
\r
50 Attributes attrs, Location l)
\r
51 : base (ns, parent, name, attrs, l)
54 this.ReturnType = type;
\r
55 ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
\r
56 IsTopLevel ? Modifiers.INTERNAL :
\r
57 Modifiers.PRIVATE, l);
\r
58 Parameters = param_list;
\r }
\r
60 public override TypeBuilder DefineType ()
\r
62 if (TypeBuilder != null)
\r
65 TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel) |
\r
66 TypeAttributes.Class | TypeAttributes.Sealed;
\r
69 if (TypeManager.NamespaceClash (Name, Location))
\r
72 ModuleBuilder builder = CodeGen.ModuleBuilder;
\r
74 TypeBuilder = builder.DefineType (
\r
75 Name, attr, TypeManager.multicast_delegate_type);
\r
77 TypeBuilder builder = Parent.TypeBuilder;
\r
79 string name = Name.Substring (1 + Name.LastIndexOf ('.'));
\r
80 TypeBuilder = builder.DefineNestedType (
\r
81 name, attr, TypeManager.multicast_delegate_type);
\r
84 TypeManager.AddDelegateType (Name, TypeBuilder, this);
\r
89 public override bool DefineMembers (TypeContainer container)
\r
94 public override bool Define (TypeContainer container)
\r
96 MethodAttributes mattr;
\r
98 ParameterBuilder pb;
\r
100 EmitContext ec = new EmitContext (this, this, Location, null,
\r
101 null, ModFlags, false);
\r
103 // FIXME: POSSIBLY make this static, as it is always constant
\r
105 Type [] const_arg_types = new Type [2];
\r
106 const_arg_types [0] = TypeManager.object_type;
\r
107 const_arg_types [1] = TypeManager.intptr_type;
\r
109 mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
\r
110 MethodAttributes.HideBySig | MethodAttributes.Public;
\r
112 ConstructorBuilder = TypeBuilder.DefineConstructor (mattr,
\r
113 CallingConventions.Standard,
\r
116 ConstructorBuilder.DefineParameter (1, ParameterAttributes.None, "object");
\r
117 ConstructorBuilder.DefineParameter (2, ParameterAttributes.None, "method");
\r
119 // HACK because System.Reflection.Emit is lame
\r
122 // FIXME: POSSIBLY make these static, as they are always the same
\r
123 Parameter [] fixed_pars = new Parameter [2];
\r
124 fixed_pars [0] = new Parameter (null, null, Parameter.Modifier.NONE, null);
\r
125 fixed_pars [1] = new Parameter (null, null, Parameter.Modifier.NONE, null);
\r
126 Parameters const_parameters = new Parameters (fixed_pars, null, Location);
\r
128 TypeManager.RegisterMethod (
\r
129 ConstructorBuilder,
\r
130 new InternalParameters (const_arg_types, const_parameters),
\r
134 ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
\r
137 // Here the various methods like Invoke, BeginInvoke etc are defined
\r
139 // First, call the `out of band' special method for
\r
140 // defining recursively any types we need:
\r
142 if (!Parameters.ComputeAndDefineParameterTypes (this))
\r
145 param_types = Parameters.GetParameterInfo (this);
\r
146 if (param_types == null)
\r
153 // Check accessibility
\r
154 foreach (Type partype in param_types){
\r
155 if (!container.AsAccessible (partype, ModFlags)) {
\r
156 Report.Error (59, Location,
\r
157 "Inconsistent accessibility: parameter type `" +
\r
158 TypeManager.CSharpName (partype) + "` is less " +
\r
159 "accessible than delegate `" + Name + "'");
\r
162 if (partype.IsPointer && !UnsafeOK (container))
\r
166 ReturnType = ResolveTypeExpr (ReturnType, false, Location);
\r
167 ret_type = ReturnType.Type;
\r
168 if (ret_type == null)
\r
171 if (!container.AsAccessible (ret_type, ModFlags)) {
\r
172 Report.Error (58, Location,
\r
173 "Inconsistent accessibility: return type `" +
\r
174 TypeManager.CSharpName (ret_type) + "` is less " +
\r
175 "accessible than delegate `" + Name + "'");
\r
179 if (ret_type.IsPointer && !UnsafeOK (container))
\r
183 // We don't have to check any others because they are all
\r
184 // guaranteed to be accessible - they are standard types.
\r
187 CallingConventions cc = Parameters.GetCallingConvention ();
\r
189 mattr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
\r
191 InvokeBuilder = TypeBuilder.DefineMethod ("Invoke",
\r
198 // Define parameters, and count out/ref parameters
\r
200 int out_params = 0;
\r
202 if (Parameters.FixedParameters != null){
\r
203 int top = Parameters.FixedParameters.Length;
\r
206 for (; i < top; i++) {
\r
207 p = Parameters.FixedParameters [i];
\r
208 pb = InvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);
\r
209 cattr = p.OptAttributes;
\r
211 Attribute.ApplyAttributes (ec, pb, pb, cattr);
\r
213 if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
\r
217 if (Parameters.ArrayParameter != null){
\r
218 Parameter p = Parameters.ArrayParameter;
\r
220 pb = InvokeBuilder.DefineParameter (
\r
221 i+1, p.Attributes, p.Name);
\r
222 cattr = p.OptAttributes;
\r
224 Attribute.ApplyAttributes (ec, pb, pb, cattr);
\r
227 InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
\r
229 TypeManager.RegisterMethod (InvokeBuilder,
\r
230 new InternalParameters (container, Parameters),
\r
236 int params_num = param_types.Length;
\r
237 Type [] async_param_types = new Type [params_num + 2];
\r
239 param_types.CopyTo (async_param_types, 0);
\r
241 async_param_types [params_num] = TypeManager.asynccallback_type;
\r
242 async_param_types [params_num + 1] = TypeManager.object_type;
\r
244 mattr = MethodAttributes.Public | MethodAttributes.HideBySig |
\r
245 MethodAttributes.Virtual | MethodAttributes.NewSlot;
\r
247 BeginInvokeBuilder = TypeBuilder.DefineMethod ("BeginInvoke",
\r
250 TypeManager.iasyncresult_type,
\r
251 async_param_types);
\r
254 if (Parameters.FixedParameters != null){
\r
255 int top = Parameters.FixedParameters.Length;
\r
258 for (i = 0 ; i < top; i++) {
\r
259 p = Parameters.FixedParameters [i];
\r
261 pb = BeginInvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);
\r
262 cattr = p.OptAttributes;
\r
264 Attribute.ApplyAttributes (ec, pb, pb, cattr);
\r
267 if (Parameters.ArrayParameter != null){
\r
268 Parameter p = Parameters.ArrayParameter;
\r
270 pb = BeginInvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);
\r
271 cattr = p.OptAttributes;
\r
273 Attribute.ApplyAttributes (ec, pb, pb, cattr);
\r
277 BeginInvokeBuilder.DefineParameter (i + 1, ParameterAttributes.None, "callback");
\r
278 BeginInvokeBuilder.DefineParameter (i + 2, ParameterAttributes.None, "object");
\r
280 BeginInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
\r
282 Parameter [] async_params = new Parameter [params_num + 2];
\r
284 if (Parameters.FixedParameters != null){
\r
285 Parameters.FixedParameters.CopyTo (async_params, 0);
\r
286 n = Parameters.FixedParameters.Length;
\r
288 if (Parameters.ArrayParameter != null)
\r
289 async_params [n] = Parameters.ArrayParameter;
\r
291 async_params [params_num] = new Parameter (
\r
292 TypeManager.system_asynccallback_expr, "callback",
\r
293 Parameter.Modifier.NONE, null);
\r
294 async_params [params_num + 1] = new Parameter (
\r
295 TypeManager.system_object_expr, "object",
\r
296 Parameter.Modifier.NONE, null);
\r
298 Parameters async_parameters = new Parameters (async_params, null, Location);
\r
299 async_parameters.ComputeAndDefineParameterTypes (this);
\r
301 async_parameters.ComputeAndDefineParameterTypes (this);
\r
302 TypeManager.RegisterMethod (BeginInvokeBuilder,
\r
303 new InternalParameters (container, async_parameters),
\r
304 async_param_types);
\r
307 // EndInvoke is a bit more interesting, all the parameters labeled as
\r
308 // out or ref have to be duplicated here.
\r
311 Type [] end_param_types = new Type [out_params + 1];
\r
312 Parameter [] end_params = new Parameter [out_params + 1];
\r
314 if (out_params > 0){
\r
315 int top = Parameters.FixedParameters.Length;
\r
316 for (i = 0; i < top; i++){
\r
317 Parameter p = Parameters.FixedParameters [i];
\r
318 if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
\r
321 end_param_types [param] = param_types [i];
\r
322 end_params [param] = p;
\r
326 end_param_types [out_params] = TypeManager.iasyncresult_type;
\r
327 end_params [out_params] = new Parameter (TypeManager.system_iasyncresult_expr, "result", Parameter.Modifier.NONE, null);
\r
330 // Create method, define parameters, register parameters with type system
\r
332 EndInvokeBuilder = TypeBuilder.DefineMethod ("EndInvoke", mattr, cc, ret_type, end_param_types);
\r
333 EndInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
\r
336 // EndInvoke: Label the parameters
\r
338 EndInvokeBuilder.DefineParameter (out_params + 1, ParameterAttributes.None, "result");
\r
339 for (i = 0; i < end_params.Length-1; i++){
\r
340 EndInvokeBuilder.DefineParameter (i + 1, end_params [i].Attributes, end_params [i].Name);
\r
343 Parameters end_parameters = new Parameters (end_params, null, Location);
\r
344 end_parameters.ComputeAndDefineParameterTypes (this);
\r
346 TypeManager.RegisterMethod (
\r
348 new InternalParameters (container, end_parameters),
\r
351 Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
\r
356 /// Verifies whether the method in question is compatible with the delegate
\r
357 /// Returns the method itself if okay and null if not.
\r
359 public static MethodBase VerifyMethod (EmitContext ec, Type delegate_type, MethodBase mb,
\r
362 ParameterData pd = Invocation.GetParameterData (mb);
\r
364 int pd_count = pd.Count;
\r
366 Expression ml = Expression.MemberLookup (
\r
367 ec, delegate_type, "Invoke", loc);
\r
369 if (!(ml is MethodGroupExpr)) {
\r
370 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
\r
374 MethodBase invoke_mb = ((MethodGroupExpr) ml).Methods [0];
\r
376 ParameterData invoke_pd = Invocation.GetParameterData (invoke_mb);
\r
378 if (invoke_pd.Count != pd_count)
\r
381 for (int i = pd_count; i > 0; ) {
\r
384 if (invoke_pd.ParameterType (i) == pd.ParameterType (i) &&
\r
385 invoke_pd.ParameterModifier (i) == pd.ParameterModifier (i))
\r
392 if (((MethodInfo) invoke_mb).ReturnType == ((MethodInfo) mb).ReturnType)
\r
399 // Verifies whether the invocation arguments are compatible with the
\r
400 // delegate's target method
\r
402 public static bool VerifyApplicability (EmitContext ec,
\r
403 Type delegate_type,
\r
412 arg_count = args.Count;
\r
414 Expression ml = Expression.MemberLookup (
\r
415 ec, delegate_type, "Invoke", loc);
\r
417 if (!(ml is MethodGroupExpr)) {
\r
418 Report.Error (-100, loc, "Internal error: could not find Invoke method!" + delegate_type);
\r
422 MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
\r
423 ParameterData pd = Invocation.GetParameterData (mb);
\r
425 int pd_count = pd.Count;
\r
427 bool not_params_method = (pd_count == 0) ||
\r
428 (pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS);
\r
430 if (not_params_method && pd_count != arg_count) {
\r
431 Report.Error (1593, loc,
\r
432 "Delegate '" + delegate_type.ToString ()
\r
433 + "' does not take '" + arg_count + "' arguments");
\r
437 return Invocation.VerifyArgumentsCompat (ec, args, arg_count, mb, !not_params_method,
\r
438 delegate_type, loc);
\r
442 /// Verifies whether the delegate in question is compatible with this one in
\r
443 /// order to determine if instantiation from the same is possible.
\r
445 public static bool VerifyDelegate (EmitContext ec, Type delegate_type, Type probe_type, Location loc)
\r
447 Expression ml = Expression.MemberLookup (
\r
448 ec, delegate_type, "Invoke", loc);
\r
450 if (!(ml is MethodGroupExpr)) {
\r
451 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
\r
455 MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
\r
456 ParameterData pd = Invocation.GetParameterData (mb);
\r
458 Expression probe_ml = Expression.MemberLookup (
\r
459 ec, delegate_type, "Invoke", loc);
\r
461 if (!(probe_ml is MethodGroupExpr)) {
\r
462 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
\r
466 MethodBase probe_mb = ((MethodGroupExpr) probe_ml).Methods [0];
\r
467 ParameterData probe_pd = Invocation.GetParameterData (probe_mb);
\r
469 if (((MethodInfo) mb).ReturnType != ((MethodInfo) probe_mb).ReturnType)
\r
472 if (pd.Count != probe_pd.Count)
\r
475 for (int i = pd.Count; i > 0; ) {
\r
478 if (pd.ParameterType (i) != probe_pd.ParameterType (i) ||
\r
479 pd.ParameterModifier (i) != probe_pd.ParameterModifier (i))
\r
486 public static string FullDelegateDesc (Type del_type, MethodBase mb, ParameterData pd)
\r
488 StringBuilder sb = new StringBuilder (TypeManager.CSharpName (((MethodInfo) mb).ReturnType));
\r
490 sb.Append (" " + del_type.ToString ());
\r
493 int length = pd.Count;
\r
495 for (int i = length; i > 0; ) {
\r
498 sb.Append (pd.ParameterDesc (length - i - 1));
\r
504 return sb.ToString ();
\r
508 // Hack around System.Reflection as found everywhere else
\r
509 public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
\r
510 MemberFilter filter, object criteria)
\r
512 ArrayList members = new ArrayList ();
\r
514 if ((mt & MemberTypes.Method) != 0) {
\r
515 if (ConstructorBuilder != null)
\r
516 if (filter (ConstructorBuilder, criteria))
\r
517 members.Add (ConstructorBuilder);
\r
519 if (InvokeBuilder != null)
\r
520 if (filter (InvokeBuilder, criteria))
\r
521 members.Add (InvokeBuilder);
\r
523 if (BeginInvokeBuilder != null)
\r
524 if (filter (BeginInvokeBuilder, criteria))
\r
525 members.Add (BeginInvokeBuilder);
\r
527 if (EndInvokeBuilder != null)
\r
528 if (filter (EndInvokeBuilder, criteria))
\r
529 members.Add (EndInvokeBuilder);
\r
532 return new MemberList (members);
\r
535 public override MemberCache MemberCache {
\r
541 public Expression InstanceExpression {
\r
543 return instance_expr;
\r
546 instance_expr = value;
\r
550 public MethodBase TargetMethod {
\r
552 return delegate_method;
\r
555 delegate_method = value;
\r
559 public Type TargetReturnType {
\r
565 public Type [] ParameterTypes {
\r
567 return param_types;
\r
574 // Base class for `NewDelegate' and `ImplicitDelegateCreation'
\r
576 public abstract class DelegateCreation : Expression {
\r
577 protected MethodBase constructor_method;
\r
578 protected MethodBase delegate_method;
\r
579 protected Expression delegate_instance_expr;
\r
581 public DelegateCreation () {}
\r
583 public static void Error_NoMatchingMethodForDelegate (MethodGroupExpr mg, Type t, MethodBase method, Location loc)
\r
585 string method_desc;
\r
587 if (mg.Methods.Length > 1)
\r
588 method_desc = mg.Methods [0].Name;
\r
590 method_desc = Invocation.FullMethodDesc (mg.Methods [0]);
\r
592 ParameterData param = Invocation.GetParameterData (method);
\r
593 string delegate_desc = Delegate.FullDelegateDesc (t, method, param);
\r
595 Report.Error (123, loc, "Method '" + method_desc + "' does not " +
\r
596 "match delegate '" + delegate_desc + "'");
\r
599 public override void Emit (EmitContext ec)
\r
601 if (delegate_instance_expr == null ||
\r
602 delegate_method.IsStatic)
\r
603 ec.ig.Emit (OpCodes.Ldnull);
\r
605 delegate_instance_expr.Emit (ec);
\r
607 if (delegate_method.IsVirtual) {
\r
608 ec.ig.Emit (OpCodes.Dup);
\r
609 ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
\r
611 ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
\r
612 ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
\r
615 protected bool ResolveConstructorMethod (EmitContext ec)
\r
617 Expression ml = Expression.MemberLookup (
\r
618 ec, type, ".ctor", loc);
\r
620 if (!(ml is MethodGroupExpr)) {
\r
621 Report.Error (-100, loc, "Internal error: Could not find delegate constructor!");
\r
625 constructor_method = ((MethodGroupExpr) ml).Methods [0];
\r
629 protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg)
\r
631 foreach (MethodInfo mi in mg.Methods){
\r
632 delegate_method = Delegate.VerifyMethod (ec, type, mi, loc);
\r
634 if (delegate_method != null)
\r
638 if (delegate_method == null) {
\r
639 Error_NoMatchingMethodForDelegate (mg, type, delegate_method, loc);
\r
644 // Check safe/unsafe of the delegate
\r
647 ParameterData param = Invocation.GetParameterData (delegate_method);
\r
648 int count = param.Count;
\r
650 for (int i = 0; i < count; i++){
\r
651 if (param.ParameterType (i).IsPointer){
\r
652 Expression.UnsafeError (loc);
\r
658 if (mg.InstanceExpression != null)
\r
659 delegate_instance_expr = mg.InstanceExpression.Resolve (ec);
\r
662 if (!delegate_method.IsStatic){
\r
663 Report.Error (120, loc,
\r
664 "An object reference is required for the non-static method " +
\r
665 delegate_method.Name);
\r
668 delegate_instance_expr = null;
\r
670 delegate_instance_expr = ec.GetThis (loc);
\r
673 if (delegate_instance_expr != null)
\r
674 if (delegate_instance_expr.Type.IsValueType)
\r
675 delegate_instance_expr = new BoxedCast (delegate_instance_expr);
\r
677 eclass = ExprClass.Value;
\r
683 // Created from the conversion code
\r
685 public class ImplicitDelegateCreation : DelegateCreation {
\r
687 ImplicitDelegateCreation (Type t, Location l)
\r
693 public override Expression DoResolve (EmitContext ec)
\r
698 static public Expression Create (EmitContext ec, MethodGroupExpr mge, Type target_type, Location loc)
\r
700 ImplicitDelegateCreation d = new ImplicitDelegateCreation (target_type, loc);
\r
701 if (d.ResolveConstructorMethod (ec))
\r
702 return d.ResolveMethodGroupExpr (ec, mge);
\r
709 // A delegate-creation-expression, invoked from the `New' class
\r
711 public class NewDelegate : DelegateCreation {
\r
712 public ArrayList Arguments;
\r
715 // This constructor is invoked from the `New' expression
\r
717 public NewDelegate (Type type, ArrayList Arguments, Location loc)
\r
720 this.Arguments = Arguments;
\r
724 public override Expression DoResolve (EmitContext ec)
\r
726 if (Arguments == null || Arguments.Count != 1) {
\r
727 Report.Error (149, loc,
\r
728 "Method name expected");
\r
732 if (!ResolveConstructorMethod (ec))
\r
735 Argument a = (Argument) Arguments [0];
\r
737 Expression invoke_method = Expression.MemberLookup (
\r
738 ec, type, "Invoke", MemberTypes.Method,
\r
739 Expression.AllBindingFlags, loc);
\r
741 if (invoke_method == null) {
\r
742 Report.Error (-200, loc, "Internal error ! Could not find Invoke method!");
\r
746 if (!a.ResolveMethodGroup (ec, loc))
\r
749 Expression e = a.Expr;
\r
751 MethodGroupExpr mg = e as MethodGroupExpr;
\r
753 return ResolveMethodGroupExpr (ec, mg);
\r
755 Type e_type = e.Type;
\r
757 if (!TypeManager.IsDelegateType (e_type)) {
\r
758 e.Error_UnexpectedKind ("method");
\r
762 // This is what MS' compiler reports. We could always choose
\r
763 // to be more verbose and actually give delegate-level specifics
\r
765 if (!Delegate.VerifyDelegate (ec, type, e_type, loc)) {
\r
766 Report.Error (29, loc, "Cannot implicitly convert type '" + e_type + "' " +
\r
767 "to type '" + type + "'");
\r
771 delegate_instance_expr = e;
\r
772 delegate_method = ((MethodGroupExpr) invoke_method).Methods [0];
\r
774 eclass = ExprClass.Value;
\r
778 public override void Emit (EmitContext ec)
\r
780 if (delegate_instance_expr == null || delegate_method.IsStatic)
\r
781 ec.ig.Emit (OpCodes.Ldnull);
\r
783 delegate_instance_expr.Emit (ec);
\r
785 if (delegate_method.IsVirtual) {
\r
786 ec.ig.Emit (OpCodes.Dup);
\r
787 ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
\r
789 ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
\r
790 ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
\r
794 public class DelegateInvocation : ExpressionStatement {
\r
796 public Expression InstanceExpr;
\r
797 public ArrayList Arguments;
\r
801 public DelegateInvocation (Expression instance_expr, ArrayList args, Location loc)
\r
803 this.InstanceExpr = instance_expr;
\r
804 this.Arguments = args;
\r
808 public override Expression DoResolve (EmitContext ec)
\r
810 if (InstanceExpr is EventExpr) {
\r
812 EventInfo ei = ((EventExpr) InstanceExpr).EventInfo;
\r
814 Expression ml = MemberLookup (
\r
815 ec, ec.ContainerType, ei.Name,
\r
816 MemberTypes.Event, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
\r
820 // If this is the case, then the Event does not belong
\r
821 // to this Type and so, according to the spec
\r
822 // cannot be accessed directly
\r
824 // Note that target will not appear as an EventExpr
\r
825 // in the case it is being referenced within the same type container;
\r
826 // it will appear as a FieldExpr in that case.
\r
829 Assign.error70 (ei, loc);
\r
835 Type del_type = InstanceExpr.Type;
\r
836 if (del_type == null)
\r
839 if (Arguments != null){
\r
840 foreach (Argument a in Arguments){
\r
841 if (!a.Resolve (ec, loc))
\r
846 if (!Delegate.VerifyApplicability (ec, del_type, Arguments, loc))
\r
849 Expression lookup = Expression.MemberLookup (ec, del_type, "Invoke", loc);
\r
850 if (!(lookup is MethodGroupExpr)) {
\r
851 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
\r
855 method = ((MethodGroupExpr) lookup).Methods [0];
\r
856 type = ((MethodInfo) method).ReturnType;
\r
857 eclass = ExprClass.Value;
\r
862 public override void Emit (EmitContext ec)
\r
865 // Invocation on delegates call the virtual Invoke member
\r
866 // so we are always `instance' calls
\r
868 Invocation.EmitCall (ec, false, false, InstanceExpr, method, Arguments, loc);
\r
871 public override void EmitStatement (EmitContext ec)
\r
875 // Pop the return value if there is one
\r
877 if (method is MethodInfo){
\r
878 if (((MethodInfo) method).ReturnType != TypeManager.void_type)
\r
879 ec.ig.Emit (OpCodes.Pop);
\r