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)
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;
{
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;
return false;
}
- ReturnType = ResolveTypeExpr (ReturnType, false, Location);
+ ReturnType = ReturnType.ResolveAsTypeTerminal (ec, false);
if (ReturnType == null)
return false;
InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
TypeManager.RegisterMethod (InvokeBuilder,
- new InternalParameters (Parent, 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 (Parent, 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 (Parent, end_parameters),
+ new InternalParameters (end_param_types, end_parameters),
end_param_types);
return true;
public override void Emit ()
{
if (OptAttributes != null) {
- EmitContext ec = new EmitContext (
- Parent, this, Location, null, null, ModFlags, false);
Parameters.LabelParameters (ec, InvokeBuilder, Location);
OptAttributes.Emit (ec, this);
}
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.
public static MethodBase VerifyMethod (EmitContext ec, Type delegate_type, MethodBase mb,
Location loc)
{
- ParameterData pd = Invocation.GetParameterData (mb);
+ ParameterData pd = TypeManager.GetParameterData (mb);
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);
+ ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
if (invoke_pd.Count != pd_count)
return null;
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>
}
MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
- ParameterData pd = Invocation.GetParameterData (mb);
+ ParameterData pd = TypeManager.GetParameterData (mb);
int pd_count = pd.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;
}
}
MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
- ParameterData pd = Invocation.GetParameterData (mb);
+ ParameterData pd = TypeManager.GetParameterData (mb);
Expression probe_ml = Expression.MemberLookup (
ec, delegate_type, "Invoke", loc);
}
MethodBase probe_mb = ((MethodGroupExpr) probe_ml).Methods [0];
- ParameterData probe_pd = Invocation.GetParameterData (probe_mb);
+ ParameterData probe_pd = TypeManager.GetParameterData (probe_mb);
if (((MethodInfo) mb).ReturnType != ((MethodInfo) probe_mb).ReturnType)
return false;
}
}
+ //
+ // Represents header string for documentation comment.
+ //
+ public override string DocCommentHeader {
+ get { return "T:"; }
+ }
+
protected override void VerifyObsoleteAttribute()
{
CheckUsageOfObsoleteAttribute (ret_type);
ec, type, "Invoke", MemberTypes.Method,
Expression.AllBindingFlags, loc);
MethodBase method = ((MethodGroupExpr) invoke_method).Methods [0];
- ParameterData param = Invocation.GetParameterData (method);
+ ParameterData param = TypeManager.GetParameterData (method);
string delegate_desc = Delegate.FullDelegateDesc (type, method, param);
Report.Error (123, loc, "Method '" + method_desc + "' does not " +
// Check safe/unsafe of the delegate
//
if (!ec.InUnsafe){
- ParameterData param = Invocation.GetParameterData (delegate_method);
+ ParameterData param = TypeManager.GetParameterData (delegate_method);
int count = param.Count;
for (int i = 0; i < count; i++){
delegate_instance_expression = ec.GetThis (loc);
if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
- delegate_instance_expression = new BoxedCast (mg.InstanceExpression);
+ 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;
}