Exemplo n.º 1
0
        /// <summary>
        /// Calculates override cost, i.e. whether the override is possible and its value.
        /// In case of more possible overrides, the one with better cost is selected.
        /// </summary>
        /// <param name="method">Source method.</param>
        /// <param name="basemethod">A hypothetical base method.</param>
        /// <returns></returns>
        static ConversionCost OverrideCost(MethodSymbol method, MethodSymbol basemethod)
        {
            Contract.ThrowIfNull(method);
            Contract.ThrowIfNull(basemethod);

            //
            if (method.Name.EqualsOrdinalIgnoreCase(basemethod.Name) == false ||
                basemethod.IsOverrideable() == false ||
                method.CanOverride() == false)
            {
                return(ConversionCost.NoConversion);
            }

            //if (method.ReturnType != basemethod.ReturnType)   // the return type is not important for the override cost
            //{
            //    return ConversionCost.ImplicitCast;
            //}

            return(OverrideCost(method.Parameters, basemethod.Parameters));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates override cost, i.e. whether the override is possible and its value.
        /// In case of more possible overrides, the one with better cost is selected.
        /// </summary>
        /// <param name="method">Source method.</param>
        /// <param name="basemethod">A hypothetical base method.</param>
        /// <returns></returns>
        static ConversionCost OverrideCost(MethodSymbol method, MethodSymbol basemethod)
        {
            Contract.ThrowIfNull(method);
            Contract.ThrowIfNull(basemethod);

            //
            if (!string.Equals(method.RoutineName, basemethod.RoutineName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(ConversionCost.Error);
            }

            if (!basemethod.IsOverrideable() ||
                !method.CanOverride())
            {
                return(ConversionCost.Error);
            }

            //if (method.ReturnType != basemethod.ReturnType)   // the return type is not important for the override cost
            //{
            //    return ConversionCost.ImplicitCast;
            //}

            return(OverrideCost(method.Parameters, basemethod.Parameters));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates override cost, i.e. whether the override is possible and its value.
        /// In case of more possible overrides, the one with better cost is selected.
        /// </summary>
        /// <param name="method">Source method.</param>
        /// <param name="basemethod">A hypothetical base method.</param>
        /// <returns></returns>
        static ConversionCost OverrideCost(MethodSymbol method, MethodSymbol basemethod)
        {
            Contract.ThrowIfNull(method);
            Contract.ThrowIfNull(basemethod);

            //
            if (method.Name.EqualsOrdinalIgnoreCase(basemethod.Name) == false ||
                basemethod.IsOverrideable() == false ||
                method.CanOverride() == false)
            {
                return(ConversionCost.NoConversion);
            }

            //if (method.ReturnType != basemethod.ReturnType)   // the return type is not important for the override cost
            //{
            //    return ConversionCost.ImplicitCast;
            //}

            //
            var ps     = method.Parameters;
            var psbase = basemethod.Parameters;

            //
            var result = ConversionCost.Pass;

            // NOTE: there shouldn't be any implicit parameters (Context and LateBoundType are known from this instance)

            for (int i = 0; i < ps.Length; i++)
            {
                if (i < psbase.Length)
                {
                    var p     = ps[i];
                    var pbase = psbase[i];

                    if (p.Type != pbase.Type)
                    {
                        if (p.Type.IsOfType(pbase.Type) || p.Type.Is_PhpValue() || p.Type.Is_PhpAlias())
                        {
                            result |= ConversionCost.ImplicitCast;
                        }
                        else
                        {
                            result |= ConversionCost.NoConversion;
                        }
                    }
                }
                else
                {
                    result |= ConversionCost.TooManyArgs;
                }
            }

            //
            if (ps.Length < psbase.Length)
            {
                result |= ConversionCost.MissingArgs;
            }

            //
            return(result);
        }