2004-08-06 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / gmcs / delegate.cs
index 26a2a73a8ef8087dfe5316d168c212834dd04b14..03425e1468348e3dac02b46ba7c8f7972e22b645 100644 (file)
@@ -138,7 +138,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        MethodAttributes mattr;
                        int i;
@@ -202,14 +202,14 @@ namespace Mono.CSharp {
 
                        // Check accessibility
                        foreach (Type partype in param_types){
-                               if (!container.AsAccessible (partype, ModFlags)) {
+                               if (!Parent.AsAccessible (partype, ModFlags)) {
                                        Report.Error (59, Location,
                                                      "Inconsistent accessibility: parameter type `" +
                                                      TypeManager.CSharpName (partype) + "` is less " +
                                                      "accessible than delegate `" + Name + "'");
                                        return false;
                                }
-                               if (partype.IsPointer && !UnsafeOK (container))
+                               if (partype.IsPointer && !UnsafeOK (Parent))
                                        return false;
                        }
                        
@@ -221,7 +221,7 @@ namespace Mono.CSharp {
                        if (ret_type == null)
                                return false;
 
-                       if (!container.AsAccessible (ret_type, ModFlags)) {
+                       if (!Parent.AsAccessible (ret_type, ModFlags)) {
                                Report.Error (58, Location,
                                              "Inconsistent accessibility: return type `" +
                                              TypeManager.CSharpName (ret_type) + "` is less " +
@@ -229,7 +229,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (ret_type.IsPointer && !UnsafeOK (container))
+                       if (ret_type.IsPointer && !UnsafeOK (Parent))
                                return false;
 
                        //
@@ -272,7 +272,7 @@ namespace Mono.CSharp {
                        InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
 
                        TypeManager.RegisterMethod (InvokeBuilder,
-                                                   new InternalParameters (container, Parameters),
+                                                   new InternalParameters (Parent, Parameters),
                                                    param_types);
 
                        //
@@ -339,7 +339,7 @@ namespace Mono.CSharp {
                        
                        async_parameters.ComputeAndDefineParameterTypes (this);
                        TypeManager.RegisterMethod (BeginInvokeBuilder,
-                                                   new InternalParameters (container, async_parameters),
+                                                   new InternalParameters (Parent, async_parameters),
                                                    async_param_types);
 
                        //
@@ -384,21 +384,22 @@ namespace Mono.CSharp {
 
                        TypeManager.RegisterMethod (
                                EndInvokeBuilder,
-                               new InternalParameters (container, end_parameters),
+                               new InternalParameters (Parent, end_parameters),
                                end_param_types);
 
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
+                               EmitContext ec = new EmitContext (
+                                       Parent, this, Location, null, null, ModFlags, false);
                                Parameters.LabelParameters (ec, InvokeBuilder, Location);
                                OptAttributes.Emit (ec, this);
                        }
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
 
                protected override string[] ValidAttributeTargets {
@@ -775,6 +776,20 @@ namespace Mono.CSharp {
                                        }
                                }
                                                
+                       //TODO: implement caching when performance will be low
+                       IMethodData md = TypeManager.GetMethod (delegate_method);
+                       if (md == null) {
+                               if (System.Attribute.GetCustomAttribute (delegate_method, TypeManager.conditional_attribute_type) != null) {
+                                       // Cannot create delegate with '{0}' because it has a Conditional attribute
+                                       Report.Error_T (1618, loc, TypeManager.CSharpSignature (delegate_method));
+                               }
+                       } else {
+                               if (md.OptAttributes != null && md.OptAttributes.Search (TypeManager.conditional_attribute_type, ec) != null) {
+                                       // Cannot create delegate with '{0}' because it has a Conditional attribute
+                                       Report.Error_T (1618, loc, TypeManager.CSharpSignature (delegate_method));
+                               }
+                       }
+                       
                                if (mg.InstanceExpression != null)
                                        delegate_instance_expr = mg.InstanceExpression.Resolve (ec);
                                else {