Esempio n. 1
0
        protected override ParametersCompiled ResolveParameters(ResolveContext ec, TypeInferenceContext tic, TypeSpec delegateType)
        {
            if (!delegateType.IsDelegate)
            {
                return(null);
            }

            AParametersCollection d_params = Delegate.GetParameters(delegateType);

            if (HasExplicitParameters)
            {
                if (!VerifyExplicitParameters(ec, delegateType, d_params))
                {
                    return(null);
                }

                return(Parameters);
            }

            //
            // If L has an implicitly typed parameter list we make implicit parameters explicit
            // Set each parameter of L is given the type of the corresponding parameter in D
            //
            if (!VerifyParameterCompatibility(ec, delegateType, d_params, ec.IsInProbingMode))
            {
                return(null);
            }

            TypeSpec [] ptypes = new TypeSpec [Parameters.Count];
            for (int i = 0; i < d_params.Count; i++)
            {
                // D has no ref or out parameters
                if ((d_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask) != 0)
                {
                    return(null);
                }

                TypeSpec d_param = d_params.Types [i];

                //
                // When type inference context exists try to apply inferred type arguments
                //
                if (tic != null)
                {
                    d_param = tic.InflateGenericArgument(ec, d_param);
                }

                ptypes [i] = d_param;
                ImplicitLambdaParameter ilp = (ImplicitLambdaParameter)Parameters.FixedParameters [i];
                ilp.SetParameterType(d_param);
                ilp.Resolve(null, i);
            }

            Parameters.Types = ptypes;
            return(Parameters);
        }
Esempio n. 2
0
		protected override ParametersCompiled ResolveParameters (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegateType)
		{
			if (!delegateType.IsDelegate)
				return null;

			AParametersCollection d_params = Delegate.GetParameters (delegateType);

			if (HasExplicitParameters) {
				if (!VerifyExplicitParameters (ec, delegateType, d_params))
					return null;

				return Parameters;
			}

			//
			// If L has an implicitly typed parameter list we make implicit parameters explicit
			// Set each parameter of L is given the type of the corresponding parameter in D
			//
			if (!VerifyParameterCompatibility (ec, delegateType, d_params, ec.IsInProbingMode))
				return null;

			TypeSpec [] ptypes = new TypeSpec [Parameters.Count];
			for (int i = 0; i < d_params.Count; i++) {
				// D has no ref or out parameters
				if ((d_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask) != 0)
					return null;

				TypeSpec d_param = d_params.Types [i];

				//
				// When type inference context exists try to apply inferred type arguments
				//
				if (tic != null) {
					d_param = tic.InflateGenericArgument (ec, d_param);
				}

				ptypes [i] = d_param;
				ImplicitLambdaParameter ilp = (ImplicitLambdaParameter) Parameters.FixedParameters [i];
				ilp.SetParameterType (d_param);
				ilp.Resolve (null, i);
			}

			Parameters.Types = ptypes;
			return Parameters;
		}
Esempio n. 3
0
		protected bool VerifyParameterCompatibility (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type, AParametersCollection invoke_pd, bool ignore_errors)
		{
			if (Parameters.Count != invoke_pd.Count) {
				if (ignore_errors)
					return false;
				
				ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
					      delegate_type.GetSignatureForError (), Parameters.Count.ToString ());
				return false;
			}

			bool has_implicit_parameters = !HasExplicitParameters;
			bool error = false;

			for (int i = 0; i < Parameters.Count; ++i) {
				Parameter.Modifier p_mod = invoke_pd.FixedParameters [i].ModFlags;
				if (Parameters.FixedParameters [i].ModFlags != p_mod && p_mod != Parameter.Modifier.PARAMS) {
					if (ignore_errors)
						return false;
					
					if (p_mod == Parameter.Modifier.NONE)
						ec.Report.Error (1677, Parameters[i].Location, "Parameter `{0}' should not be declared with the `{1}' keyword",
							      (i + 1).ToString (), Parameter.GetModifierSignature (Parameters [i].ModFlags));
					else
						ec.Report.Error (1676, Parameters[i].Location, "Parameter `{0}' must be declared with the `{1}' keyword",
							      (i+1).ToString (), Parameter.GetModifierSignature (p_mod));
					error = true;
				}

				if (has_implicit_parameters)
					continue;

				TypeSpec type = invoke_pd.Types [i];

				if (tic != null)
					type = tic.InflateGenericArgument (ec, type);
				
				if (!TypeSpecComparer.IsEqual (type, Parameters.Types [i])) {
					if (ignore_errors)
						return false;
					
					ec.Report.Error (1678, Parameters [i].Location, "Parameter `{0}' is declared as type `{1}' but should be `{2}'",
						      (i+1).ToString (),
						      Parameters.Types [i].GetSignatureForError (),
						      invoke_pd.Types [i].GetSignatureForError ());
					error = true;
				}
			}

			return !error;
		}
Esempio n. 4
0
        protected ParametersCompiled ResolveParameters(ParseContext ec, TypeInferenceContext tic, Type delegateType)
        {
            if (!TypeManager.IsDelegateType(delegateType))
            {
                return(null);
            }

            var delegateParameters = TypeManager.GetParameterData(delegateType.GetMethod("Invoke"));

            if (HasExplicitParameters)
            {
                if (!VerifyExplicitParameters(ec, delegateType, delegateParameters))
                {
                    return(null);
                }

                return(_scope.Parameters.Clone());
            }

            //
            // If L has an implicitly typed parameter list we make implicit parameters explicit
            // Set each parameter of L is given the type of the corresponding parameter in D
            //
            if (!VerifyParameterCompatibility(ec, delegateType, delegateParameters, ec.IsInProbingMode))
            {
                return(null);
            }

            var ptypes = new Type[_scope.Parameters.Count];

            for (int i = 0; i < delegateParameters.Count; i++)
            {
                // D has no ref or out parameters
                if ((delegateParameters.FixedParameters[i].ModifierFlags & Parameter.Modifier.IsByRef) != 0)
                {
                    return(null);
                }

                Type dParam = delegateParameters.Types[i];

                // Blablabla, because reflection does not work with dynamic types
                if (dParam.IsGenericParameter)
                {
                    dParam = delegateType.GetGenericArguments() [dParam.GenericParameterPosition];
                }

                //
                // When type inference context exists try to apply inferred type arguments
                //
                if (tic != null)
                {
                    dParam = tic.InflateGenericArgument(dParam);
                }

                ptypes[i] = dParam;
                ((ImplicitLambdaParameter)_scope.Parameters.FixedParameters[i]).ParameterType = dParam;
            }

            // TODO : FIX THIS
            //ptypes.CopyTo(_scope.Parameters.Types, 0);

            // TODO: STOP DOING THIS
            _scope.Parameters.Types = ptypes;

            return(_scope.Parameters);
        }