Example #1
0
        __CastResult __CanCastParamNoGC(DmdType fromParam, DmdType toParam)
        {
            if (fromParam == toParam)
            {
                return(__CastResult.CanCast);
            }

            var fromParamCorType = fromParam.__GetVerifierCorElementType();

            if (__IsObjRef(fromParamCorType))
            {
                return(fromParam.__CanCastToNoGC(toParam));
            }
            else if (__IsGenericVariable(fromParamCorType))
            {
                if (!fromParam.__ConstrainedAsObjRef())
                {
                    return(__CastResult.CannotCast);
                }

                return(fromParam.__CanCastToNoGC(toParam));
            }
            else if (__IsPrimitiveType(fromParamCorType))
            {
                var toParamCorType = toParam.__GetVerifierCorElementType();
                if (__IsPrimitiveType(toParamCorType))
                {
                    if (toParamCorType == fromParamCorType)
                    {
                        return(__CastResult.CanCast);
                    }

                    if ((toParamCorType != DDN.ElementType.Boolean) &&
                        (fromParamCorType != DDN.ElementType.Boolean) &&
                        (toParamCorType != DDN.ElementType.Char) &&
                        (fromParamCorType != DDN.ElementType.Char))
                    {
                        if ((__Size(toParamCorType) == __Size(fromParamCorType)) &&
                            (__IsFloat(toParamCorType) == __IsFloat(fromParamCorType)))
                        {
                            return(__CastResult.CanCast);
                        }
                    }
                }
            }
            else
            {
                if (fromParam.HasTypeEquivalence)
                {
                    return(__CastResult.MaybeCast);
                }
                if (toParam.HasTypeEquivalence)
                {
                    return(__CastResult.MaybeCast);
                }
            }

            return(__CastResult.CannotCast);
        }
Example #2
0
        bool __CanCastParam(DmdType fromParam, DmdType toParam)
        {
            if (fromParam.IsEquivalentTo(toParam))
            {
                return(true);
            }

            var fromParamCorType = fromParam.__GetVerifierCorElementType();

            if (__IsObjRef(fromParamCorType))
            {
                return(fromParam.__CanCastTo(toParam));
            }
            else if (__IsGenericVariable(fromParamCorType))
            {
                if (!fromParam.__ConstrainedAsObjRef())
                {
                    return(false);
                }

                return(fromParam.__CanCastTo(toParam));
            }
            else if (__IsPrimitiveType(fromParamCorType))
            {
                var toParamCorType = toParam.__GetVerifierCorElementType();
                if (__IsPrimitiveType(toParamCorType))
                {
                    if (toParamCorType == fromParamCorType)
                    {
                        return(true);
                    }

                    if ((toParamCorType != DDN.ElementType.Boolean) &&
                        (fromParamCorType != DDN.ElementType.Boolean) &&
                        (toParamCorType != DDN.ElementType.Char) &&
                        (fromParamCorType != DDN.ElementType.Char))
                    {
                        if ((__Size(toParamCorType) == __Size(fromParamCorType)) &&
                            (__IsFloat(toParamCorType) == __IsFloat(fromParamCorType)))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }