public override FullNamedExpression Resolve(IMemberContext rc, bool local) { if (resolved != null || value == null) { return(resolved); } if (local) { return(null); } resolved = value.GetTypeExpression().ResolveAsTypeStep(rc, false); if (resolved == null) { value = null; return(null); } if (resolved is TypeExpr) { resolved = resolved.ResolveAsTypeTerminal(rc, false); } return(resolved); }
// <summary> // Resolve is used in method definitions // </summary> public virtual TypeSpec Resolve(IMemberContext rc, int index) { if (parameter_type != null) { return(parameter_type); } if (attributes != null) { attributes.AttachTo(this, rc); } var expr = texpr.ResolveAsTypeTerminal(rc, false); if (expr == null) { return(null); } this.idx = index; texpr = expr; parameter_type = texpr.Type; if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && TypeManager.IsSpecialType(parameter_type)) { rc.Module.Compiler.Report.Error(1601, Location, "Method or delegate parameter cannot be of type `{0}'", GetSignatureForError()); return(null); } TypeManager.CheckTypeVariance(parameter_type, (modFlags & Parameter.Modifier.ISBYREF) != 0 ? Variance.None : Variance.Contravariant, rc); if (parameter_type.IsStatic) { rc.Module.Compiler.Report.Error(721, Location, "`{0}': static types cannot be used as parameters", texpr.GetSignatureForError()); return(parameter_type); } if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type == InternalType.Dynamic)) { rc.Module.Compiler.Report.Error(1103, Location, "The extension method cannot be of type `{0}'", TypeManager.CSharpName(parameter_type)); } return(parameter_type); }
// <summary> // Resolve is used in method definitions // </summary> public virtual Type Resolve(IResolveContext ec) { // HACK: to resolve attributes correctly this.resolve_context = ec; if (parameter_type != null) { return(parameter_type); } TypeExpr texpr = TypeName.ResolveAsTypeTerminal(ec, false); if (texpr == null) { return(null); } parameter_type = texpr.Type; if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && TypeManager.IsSpecialType(parameter_type)) { Report.Error(1601, Location, "Method or delegate parameter cannot be of type `{0}'", GetSignatureForError()); return(null); } #if GMCS_SOURCE TypeParameterExpr tparam = texpr as TypeParameterExpr; if (tparam != null) { return(parameter_type); } #endif if ((parameter_type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) { Report.Error(721, Location, "`{0}': static types cannot be used as parameters", texpr.GetSignatureForError()); return(parameter_type); } if ((modFlags & Modifier.This) != 0 && parameter_type.IsPointer) { Report.Error(1103, Location, "The type of extension method cannot be `{0}'", TypeManager.CSharpName(parameter_type)); } return(parameter_type); }
protected override bool DoDefineMembers() { var builtin_types = Compiler.BuiltinTypes; var ctor_parameters = ParametersCompiled.CreateFullyResolved( new [] { new Parameter(new TypeExpression(builtin_types.Object, Location), "object", Parameter.Modifier.NONE, null, Location), new Parameter(new TypeExpression(builtin_types.IntPtr, Location), "method", Parameter.Modifier.NONE, null, Location) }, new [] { builtin_types.Object, builtin_types.IntPtr } ); Constructor = new Constructor(this, Constructor.ConstructorName, Modifiers.PUBLIC, null, ctor_parameters, null, Location); Constructor.Define(); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: // var p = parameters; if (!p.Resolve(this)) { return(false); } // // Invoke method // // Check accessibility foreach (var partype in p.Types) { if (!IsAccessibleAs(partype)) { Report.SymbolRelatedToPreviousError(partype); Report.Error(59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", TypeManager.CSharpName(partype), GetSignatureForError()); } } ReturnType = ReturnType.ResolveAsTypeTerminal(this, false); if (ReturnType == null) { return(false); } var ret_type = ReturnType.Type; // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // if (!IsAccessibleAs(ret_type)) { Report.SymbolRelatedToPreviousError(ret_type); Report.Error(58, Location, "Inconsistent accessibility: return type `" + TypeManager.CSharpName(ret_type) + "' is less " + "accessible than delegate `" + GetSignatureForError() + "'"); return(false); } CheckProtectedModifier(); if (Compiler.Settings.StdLib && ret_type.IsSpecialRuntimeType) { Method.Error1599(Location, ret_type, Report); return(false); } TypeManager.CheckTypeVariance(ret_type, Variance.Covariant, this); InvokeBuilder = new Method(this, null, ReturnType, MethodModifiers, new MemberName(InvokeMethodName), p, null); InvokeBuilder.Define(); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (!IsCompilerGenerated) { DefineAsyncMethods(Parameters.CallingConvention); } return(true); }
public override FullNamedExpression Resolve (IMemberContext rc, bool local) { if (resolved != null || value == null) return resolved; if (local) return null; resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false); if (resolved == null) { value = null; return null; } if (resolved is TypeExpr) resolved = resolved.ResolveAsTypeTerminal (rc, false); return resolved; }
protected override bool DoDefineMembers() { if (IsGeneric) { foreach (TypeParameter type_param in TypeParameters) { if (!type_param.Resolve(this)) { return(false); } } foreach (TypeParameter type_param in TypeParameters) { if (!type_param.DefineType(this)) { return(false); } } } member_cache = new MemberCache(TypeManager.multicast_delegate_type, this); // FIXME: POSSIBLY make this static, as it is always constant // Type [] const_arg_types = new Type [2]; const_arg_types [0] = TypeManager.object_type; const_arg_types [1] = TypeManager.intptr_type; const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public; ConstructorBuilder = TypeBuilder.DefineConstructor(ctor_mattr, CallingConventions.Standard, const_arg_types); ConstructorBuilder.DefineParameter(1, ParameterAttributes.None, "object"); ConstructorBuilder.DefineParameter(2, ParameterAttributes.None, "method"); // // HACK because System.Reflection.Emit is lame // IParameterData [] fixed_pars = new IParameterData [] { new ParameterData("object", Parameter.Modifier.NONE), new ParameterData("method", Parameter.Modifier.NONE) }; AParametersCollection const_parameters = new ParametersImported( fixed_pars, new Type[] { TypeManager.object_type, TypeManager.intptr_type }); TypeManager.RegisterMethod(ConstructorBuilder, const_parameters); member_cache.AddMember(ConstructorBuilder, this); ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: if (!Parameters.Resolve(this)) { return(false); } // // Invoke method // // Check accessibility foreach (Type partype in Parameters.Types) { if (!IsAccessibleAs(partype)) { Report.SymbolRelatedToPreviousError(partype); Report.Error(59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", TypeManager.CSharpName(partype), GetSignatureForError()); return(false); } } ReturnType = ReturnType.ResolveAsTypeTerminal(this, false); if (ReturnType == null) { return(false); } ret_type = ReturnType.Type; if (!IsAccessibleAs(ret_type)) { Report.SymbolRelatedToPreviousError(ret_type); Report.Error(58, Location, "Inconsistent accessibility: return type `" + TypeManager.CSharpName(ret_type) + "' is less " + "accessible than delegate `" + GetSignatureForError() + "'"); return(false); } CheckProtectedModifier(); if (RootContext.StdLib && TypeManager.IsSpecialType(ret_type)) { Method.Error1599(Location, ret_type, Report); return(false); } TypeManager.CheckTypeVariance(ret_type, Variance.Covariant, this); // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // CallingConventions cc = Parameters.CallingConvention; InvokeBuilder = TypeBuilder.DefineMethod("Invoke", mattr, cc, ret_type, Parameters.GetEmitTypes()); InvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); TypeManager.RegisterMethod(InvokeBuilder, Parameters); member_cache.AddMember(InvokeBuilder, this); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated) { DefineAsyncMethods(cc); } return(true); }
// <summary> // Resolve is used in method definitions // </summary> public virtual Type Resolve(IMemberContext rc) { if (parameter_type != null) { return(parameter_type); } if (attributes != null) { attributes.AttachTo(this, rc); } TypeExpr texpr = TypeName.ResolveAsTypeTerminal(rc, false); if (texpr == null) { return(null); } parameter_type = texpr.Type; // Ignore all checks for dummy members AbstractPropertyEventMethod pem = rc as AbstractPropertyEventMethod; if (pem != null && pem.IsDummy) { return(parameter_type); } if (default_expr != null) { ResolveContext ec = new ResolveContext(rc); default_expr = default_expr.Resolve(ec); if (default_expr != null) { Constant value = default_expr as Constant; if (value == null) { if (default_expr != null) { bool is_valid = false; if (default_expr is DefaultValueExpression) { is_valid = true; } else if (default_expr is New && ((New)default_expr).IsDefaultValueType) { is_valid = TypeManager.IsEqual(parameter_type, default_expr.Type) || (TypeManager.IsNullableType(parameter_type) && Convert.ImplicitNulableConversion(ec, default_expr, parameter_type) != EmptyExpression.Null); } else { rc.Compiler.Report.Error(1736, default_expr.Location, "The expression being assigned to optional parameter `{0}' must be a constant or default value", Name); is_valid = true; } if (!is_valid) { default_expr = null; ec.Compiler.Report.Error(1763, Location, "Optional parameter `{0}' of type `{1}' can only be initialized with `null'", Name, GetSignatureForError()); } } } else { Constant c = value.ConvertImplicitly(parameter_type); if (c == null) { if (parameter_type == TypeManager.object_type) { rc.Compiler.Report.Error(1763, Location, "Optional parameter `{0}' of type `{1}' can only be initialized with `null'", Name, GetSignatureForError()); } else { rc.Compiler.Report.Error(1750, Location, "Optional parameter value `{0}' cannot be converted to parameter type `{1}'", value.GetValue(), GetSignatureForError()); } default_expr = null; } } } } if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && TypeManager.IsSpecialType(parameter_type)) { rc.Compiler.Report.Error(1601, Location, "Method or delegate parameter cannot be of type `{0}'", GetSignatureForError()); return(null); } TypeManager.CheckTypeVariance(parameter_type, (modFlags & Parameter.Modifier.ISBYREF) != 0 ? Variance.None : Variance.Contravariant, rc); if (TypeManager.IsGenericParameter(parameter_type)) { return(parameter_type); } if ((parameter_type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) { rc.Compiler.Report.Error(721, Location, "`{0}': static types cannot be used as parameters", texpr.GetSignatureForError()); return(parameter_type); } if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || TypeManager.IsDynamicType(parameter_type))) { rc.Compiler.Report.Error(1103, Location, "The extension method cannot be of type `{0}'", TypeManager.CSharpName(parameter_type)); } return(parameter_type); }
public void Resolve(IMemberContext context) { Type = Type.ResolveAsTypeTerminal(context, true); }