예제 #1
0
        public IList <ResolveResult> GetArgumentsWithConversions()
        {
            if (bestCandidate == null)
            {
                return(arguments);
            }
            var conversions = this.ArgumentConversions;

            ResolveResult[] args = new ResolveResult[arguments.Length];
            for (int i = 0; i < args.Length; i++)
            {
                if (conversions[i] == Conversion.IdentityConversion || conversions[i] == Conversion.None)
                {
                    args[i] = arguments[i];
                }
                else
                {
                    int   parameterIndex = bestCandidate.ArgumentToParameterMap[i];
                    IType parameterType;
                    if (parameterIndex >= 0)
                    {
                        parameterType = bestCandidate.ParameterTypes[parameterIndex];
                    }
                    else
                    {
                        parameterType = SpecialType.UnknownType;
                    }
                    args[i] = new ConversionResolveResult(parameterType, arguments[i], conversions[i]);
                }
            }
            return(args);
        }
예제 #2
0
 protected void AssertConversion(ResolveResult conversionResult, ResolveResult expectedRR, Conversion expectedConversion, string text)
 {
     if (expectedConversion == Conversion.IdentityConversion)
     {
         Assert.AreSame(expectedRR, conversionResult, "Expected no " + text);
     }
     else
     {
         ConversionResolveResult crr = conversionResult as ConversionResolveResult;
         Assert.IsNotNull(crr, "Could not find ConversionResolveResult for " + text);
         Assert.AreEqual(expectedConversion, crr.Conversion, text);
         Assert.AreSame(expectedRR, crr.Input, "Input of " + text);
     }
 }
예제 #3
0
        IList <ResolveResult> GetArgumentsWithConversions(ResolveResult targetResolveResult, IParameterizedMember bestCandidateForNamedArguments)
        {
            var conversions = this.ArgumentConversions;

            ResolveResult[] args = new ResolveResult[arguments.Length];
            for (int i = 0; i < args.Length; i++)
            {
                var argument = arguments[i];
                if (this.IsExtensionMethodInvocation && i == 0 && targetResolveResult != null)
                {
                    argument = targetResolveResult;
                }
                int parameterIndex = bestCandidate.ArgumentToParameterMap[i];
                if (parameterIndex >= 0 && conversions[i] != Conversion.IdentityConversion)
                {
                    // Wrap argument in ConversionResolveResult
                    IType parameterType = bestCandidate.ParameterTypes[parameterIndex];
                    if (parameterType.Kind != TypeKind.Unknown)
                    {
                        if (arguments[i].IsCompileTimeConstant && conversions[i] != Conversion.None)
                        {
                            argument = new CSharpResolver(compilation).WithCheckForOverflow(CheckForOverflow).ResolveCast(parameterType, argument);
                        }
                        else
                        {
                            argument = new ConversionResolveResult(parameterType, argument, conversions[i], CheckForOverflow);
                        }
                    }
                }
                if (bestCandidateForNamedArguments != null && argumentNames[i] != null)
                {
                    // Wrap argument in NamedArgumentResolveResult
                    if (parameterIndex >= 0)
                    {
                        argument = new NamedArgumentResolveResult(bestCandidateForNamedArguments.Parameters[parameterIndex], argument, bestCandidateForNamedArguments);
                    }
                    else
                    {
                        argument = new NamedArgumentResolveResult(argumentNames[i], argument);
                    }
                }
                args[i] = argument;
            }
            return(args);
        }
예제 #4
0
        IList <ResolveResult> GetArgumentsWithConversions(ResolveResult targetResolveResult)
        {
            var conversions = this.ArgumentConversions;

            ResolveResult[] args = new ResolveResult[arguments.Length];
            for (int i = 0; i < args.Length; i++)
            {
                var argument = arguments[i];
                if (this.IsExtensionMethodInvocation && i == 0 && targetResolveResult != null)
                {
                    argument = targetResolveResult;
                }
                if (conversions[i] == Conversion.IdentityConversion)
                {
                    args[i] = argument;
                }
                else
                {
                    int   parameterIndex = bestCandidate.ArgumentToParameterMap[i];
                    IType parameterType;
                    if (parameterIndex >= 0)
                    {
                        parameterType = bestCandidate.ParameterTypes[parameterIndex];
                    }
                    else
                    {
                        parameterType = SpecialType.UnknownType;
                    }
                    if (arguments[i].IsCompileTimeConstant && conversions[i] != Conversion.None)
                    {
                        args[i] = new CSharpResolver(compilation).ResolveCast(parameterType, argument);
                    }
                    else
                    {
                        args[i] = new ConversionResolveResult(parameterType, argument, conversions[i]);
                    }
                }
            }
            return(args);
        }
예제 #5
0
        // The reason this class exists is that for code like this:
        //    int i = ...;
        //    long n = 0;
        //    n = n + (long)i;
        // The resolver will produce (and process) an CastResolveResult for the cast,
        // (with Conversion = implicit numeric conversion)
        // and then pass it into CSharpResolver.ResolveBinaryOperator().
        // That method normally wraps input arguments into another conversion
        // (the implicit conversion applied by the operator).
        // However, identity conversions do not cause the creation of ConversionResolveResult instances,
        // so the OperatorResolveResult's argument will be the CastResolveResult
        // of the cast.
        // Without this class (and instead using ConversionResolveResult for both purposes),
        // it would be hard for the conversion-processing code
        // in the ResolveVisitor to distinguish the existing conversion from the CastExpression
        // from an implicit conversion introduced by the binary operator.
        // This would cause the conversion to be processed yet again.
        // The following unit tests would fail without this class:
        //  * CastTests.ExplicitConversion_In_Assignment
        //  * FindReferencesTest.FindReferencesForOpImplicitInAssignment_ExplicitCast
        //  * CS0029InvalidConversionIssueTests.ExplicitConversionFromUnknownType

        public CastResolveResult(ConversionResolveResult rr)
            : base(rr.Type, rr.Input, rr.Conversion, rr.CheckForOverflow)
        {
        }
예제 #6
0
            internal override bool IsMatch(ResolveResult rr)
            {
                ConversionResolveResult crr = rr as ConversionResolveResult;

                return(crr != null && crr.Conversion.IsUserDefined && crr.Conversion.Method.MemberDefinition == op);
            }
예제 #7
0
		public IList<ResolveResult> GetArgumentsWithConversions()
		{
			if (bestCandidate == null)
				return arguments;
			var conversions = this.ArgumentConversions;
			ResolveResult[] args = new ResolveResult[arguments.Length];
			for (int i = 0; i < args.Length; i++) {
				if (conversions[i] == Conversion.IdentityConversion || conversions[i] == Conversion.None) {
					args[i] = arguments[i];
				} else {
					int parameterIndex = bestCandidate.ArgumentToParameterMap[i];
					IType parameterType;
					if (parameterIndex >= 0)
						parameterType = bestCandidate.ParameterTypes[parameterIndex];
					else
						parameterType = SharedTypes.UnknownType;
					args[i] = new ConversionResolveResult(parameterType, arguments[i], conversions[i]);
				}
			}
			return args;
		}