Modifiers.PRIVATE;
public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,
- int mod_flags, string name, Parameters param_list,
+ int mod_flags, MemberName name, Parameters param_list,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
- if (a.Target == "return") {
+ if (a.Target == AttributeTargets.ReturnValue) {
if (return_attributes == null)
return_attributes = new ReturnParameter (InvokeBuilder, Location);
if (TypeBuilder != null)
return TypeBuilder;
+ ec = new EmitContext (this, this, Location, null, null, ModFlags, false);
+
TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel) |
TypeAttributes.Class | TypeAttributes.Sealed;
+ if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
+ TypeExpr expr = new TypeLookupExpression ("System.MulticastDelegate");
+ TypeManager.multicast_delegate_type = expr.ResolveType (ec);
+ }
+
+ if (TypeManager.multicast_delegate_type == null)
+ throw new InternalErrorException ("System.MulticastDelegate unresolved");
+
if (IsTopLevel) {
if (TypeManager.NamespaceClash (Name, Location))
return null;
return true;
}
- public override bool Define (TypeContainer container)
+ public override bool Define ()
{
MethodAttributes mattr;
int i;
- EmitContext ec = new EmitContext (this, this, Location, null,
- null, ModFlags, false);
+
+ if (ec == null)
+ throw new InternalErrorException ("Define called before DefineType?");
// FIXME: POSSIBLY make this static, as it is always constant
//
//
// FIXME: POSSIBLY make these static, as they are always the same
Parameter [] fixed_pars = new Parameter [2];
- fixed_pars [0] = new Parameter (null, null, Parameter.Modifier.NONE, null);
- fixed_pars [1] = new Parameter (null, null, Parameter.Modifier.NONE, null);
+ fixed_pars [0] = new Parameter (TypeManager.system_object_expr, "object",
+ Parameter.Modifier.NONE, null);
+ fixed_pars [1] = new Parameter (TypeManager.system_intptr_expr, "method",
+ Parameter.Modifier.NONE, null);
Parameters const_parameters = new Parameters (fixed_pars, null, Location);
TypeManager.RegisterMethod (
// First, call the `out of band' special method for
// defining recursively any types we need:
- if (!Parameters.ComputeAndDefineParameterTypes (this))
+ if (!Parameters.ComputeAndDefineParameterTypes (ec))
return false;
- param_types = Parameters.GetParameterInfo (this);
+ param_types = Parameters.GetParameterInfo (ec);
if (param_types == null)
return false;
// 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;
}
- ReturnType = ResolveTypeExpr (ReturnType, false, Location);
+ ReturnType = ReturnType.ResolveAsTypeTerminal (ec, false);
if (ReturnType == null)
return false;
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 " +
return false;
}
- if (ret_type.IsPointer && !UnsafeOK (container))
+ if (ret_type.IsPointer && !UnsafeOK (Parent))
return false;
//
InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
TypeManager.RegisterMethod (InvokeBuilder,
- new InternalParameters (container, Parameters),
+ new InternalParameters (param_types, Parameters),
param_types);
//
Parameter.Modifier.NONE, null);
Parameters async_parameters = new Parameters (async_params, null, Location);
- async_parameters.ComputeAndDefineParameterTypes (this);
-
- async_parameters.ComputeAndDefineParameterTypes (this);
+ async_parameters.ComputeAndDefineParameterTypes (ec);
+
TypeManager.RegisterMethod (BeginInvokeBuilder,
- new InternalParameters (container, async_parameters),
+ new InternalParameters (async_param_types, async_parameters),
async_param_types);
//
}
Parameters end_parameters = new Parameters (end_params, null, Location);
- end_parameters.ComputeAndDefineParameterTypes (this);
+ end_parameters.ComputeAndDefineParameterTypes (ec);
TypeManager.RegisterMethod (
EndInvokeBuilder,
- new InternalParameters (container, end_parameters),
+ new InternalParameters (end_param_types, 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);
Parameters.LabelParameters (ec, InvokeBuilder, Location);
OptAttributes.Emit (ec, this);
}
- base.Emit (tc);
+ base.Emit ();
}
- protected override string[] ValidAttributeTargets {
+ public override string[] ValidAttributeTargets {
get {
return attribute_targets;
}
AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
if (!AttributeTester.IsClsCompliant (ReturnType.Type)) {
- Report.Error_T (3002, Location, GetSignatureForError ());
+ Report.Error (3002, Location, "Return type of '{0}' is not CLS-compliant", GetSignatureForError ());
}
return true;
}
+ //
+ // Returns the MethodBase for "Invoke" from a delegate type, this is used
+ // to extract the signature of a delegate.
+ //
+ public static MethodInfo GetInvokeMethod (EmitContext ec, Type delegate_type, Location loc)
+ {
+ Expression ml = Expression.MemberLookup (
+ ec, delegate_type, "Invoke", loc);
+
+ if (!(ml is MethodGroupExpr)) {
+ Report.Error (-100, loc, "Internal error: could not find Invoke method!");
+ return null;
+ }
+
+ return (MethodInfo) (((MethodGroupExpr) ml).Methods [0]);
+ }
+
/// <summary>
/// Verifies whether the method in question is compatible with the delegate
/// Returns the method itself if okay and null if not.
int pd_count = pd.Count;
- Expression ml = Expression.MemberLookup (
- ec, delegate_type, "Invoke", loc);
-
- if (!(ml is MethodGroupExpr)) {
- Report.Error (-100, loc, "Internal error: could not find Invoke method!");
+ MethodBase invoke_mb = GetInvokeMethod (ec, delegate_type, loc);
+ if (invoke_mb == null)
return null;
- }
-
- MethodBase invoke_mb = ((MethodGroupExpr) ml).Methods [0];
ParameterData invoke_pd = Invocation.GetParameterData (invoke_mb);
for (int i = pd_count; i > 0; ) {
i--;
- if (invoke_pd.ParameterType (i) == pd.ParameterType (i) &&
- invoke_pd.ParameterModifier (i) == pd.ParameterModifier (i))
+ Type invoke_pd_type = invoke_pd.ParameterType (i);
+ Type pd_type = pd.ParameterType (i);
+ Parameter.Modifier invoke_pd_type_mod = invoke_pd.ParameterModifier (i);
+ Parameter.Modifier pd_type_mod = pd.ParameterModifier (i);
+
+ if (invoke_pd_type == pd_type &&
+ invoke_pd_type_mod == pd_type_mod)
continue;
- else {
- return null;
- }
+
+ if (invoke_pd_type.IsSubclassOf (pd_type) &&
+ invoke_pd_type_mod == pd_type_mod)
+ if (RootContext.Version == LanguageVersion.ISO_1) {
+ Report.FeatureIsNotStandardized (loc, "contravariance");
+ return null;
+ } else
+ continue;
+
+ return null;
}
- if (((MethodInfo) invoke_mb).ReturnType == ((MethodInfo) mb).ReturnType)
+ Type invoke_mb_retval = ((MethodInfo) invoke_mb).ReturnType;
+ Type mb_retval = ((MethodInfo) mb).ReturnType;
+ if (invoke_mb_retval == mb_retval)
return mb;
- else
- return null;
+
+ if (mb_retval.IsSubclassOf (invoke_mb_retval))
+ if (RootContext.Version == LanguageVersion.ISO_1) {
+ Report.FeatureIsNotStandardized (loc, "covariance");
+ return null;
+ }
+ else
+ return mb;
+
+ return null;
}
// <summary>
// Verifies whether the invocation arguments are compatible with the
// delegate's target method
// </summary>
- public static bool VerifyApplicability (EmitContext ec,
- Type delegate_type,
- ArrayList args,
- Location loc)
+ public static bool VerifyApplicability (EmitContext ec, Type delegate_type,
+ ArrayList args, Location loc)
{
int arg_count;
if (!params_method && pd_count != arg_count) {
Report.Error (1593, loc,
- "Delegate '" + delegate_type.ToString ()
- + "' does not take '" + arg_count + "' arguments");
+ "Delegate '{0}' does not take {1} arguments",
+ delegate_type.ToString (), arg_count);
return false;
}
bool ans = false;
if (arg_count == pd_count)
- ans = Invocation.VerifyArgumentsCompat (ec, args, arg_count, mb, false, delegate_type, loc);
+ ans = Invocation.VerifyArgumentsCompat (
+ ec, args, arg_count, mb, false,
+ delegate_type, false, loc);
if (!ans && params_method)
- ans = Invocation.VerifyArgumentsCompat (ec, args, arg_count, mb, true, delegate_type, loc);
+ ans = Invocation.VerifyArgumentsCompat (
+ ec, args, arg_count, mb, true,
+ delegate_type, false, loc);
return ans;
}
public override AttributeTargets AttributeTargets {
get {
- return AttributeTargets.Delegate | AttributeTargets.ReturnValue;
+ return AttributeTargets.Delegate;
}
}
+ //
+ // Represents header string for documentation comment.
+ //
+ public override string DocCommentHeader {
+ get { return "T:"; }
+ }
+
protected override void VerifyObsoleteAttribute()
{
CheckUsageOfObsoleteAttribute (ret_type);
protected MethodBase constructor_method;
protected MethodBase delegate_method;
protected MethodGroupExpr method_group;
+ protected Expression delegate_instance_expression;
public DelegateCreation () {}
public override void Emit (EmitContext ec)
{
- if (method_group.InstanceExpression == null ||
- delegate_method.IsStatic)
+ if (delegate_instance_expression == null || delegate_method.IsStatic)
ec.ig.Emit (OpCodes.Ldnull);
else
- method_group.InstanceExpression.Emit (ec);
+ delegate_instance_expression.Emit (ec);
if (delegate_method.IsVirtual && !method_group.IsBase) {
ec.ig.Emit (OpCodes.Dup);
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));
+ Report.Error (1618, loc, "Cannot create delegate with '{0}' because it has a Conditional attribute", 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));
+ Report.Error (1618, loc, "Cannot create delegate with '{0}' because it has a Conditional attribute", TypeManager.CSharpSignature (delegate_method));
}
}
if (mg.InstanceExpression != null)
- mg.InstanceExpression = mg.InstanceExpression.Resolve (ec);
+ delegate_instance_expression = mg.InstanceExpression.Resolve (ec);
else if (ec.IsStatic) {
if (!delegate_method.IsStatic) {
Report.Error (120, loc,
delegate_method.Name);
return null;
}
- mg.InstanceExpression = null;
+ delegate_instance_expression = null;
} else
- mg.InstanceExpression = ec.GetThis (loc);
+ delegate_instance_expression = ec.GetThis (loc);
- if (mg.InstanceExpression != null && mg.InstanceExpression.Type.IsValueType)
- mg.InstanceExpression = new BoxedCast (mg.InstanceExpression);
+ if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
+ delegate_instance_expression = new BoxedCast (delegate_instance_expression);
method_group = mg;
eclass = ExprClass.Value;
return null;
}
}
-
+
//
// A delegate-creation-expression, invoked from the `New' class
//
Expression e = a.Expr;
+ if (e is AnonymousMethod && RootContext.Version != LanguageVersion.ISO_1)
+ return ((AnonymousMethod) e).Compatible (ec, type, false);
+
MethodGroupExpr mg = e as MethodGroupExpr;
if (mg != null)
return ResolveMethodGroupExpr (ec, mg);
Type e_type = e.Type;
if (!TypeManager.IsDelegateType (e_type)) {
- e.Error_UnexpectedKind ("method");
+ Report.Error (149, loc, "Method name expected");
return null;
}
return null;
}
- method_group.InstanceExpression = e;
+ delegate_instance_expression = e;
delegate_method = method_group.Methods [0];
eclass = ExprClass.Value;