IsPrimitiveNumericTypeFitForDouble() статический приватный Метод

static private IsPrimitiveNumericTypeFitForDouble ( IReflect ir ) : bool
ir IReflect
Результат bool
Пример #1
0
        internal override IReflect InferType(JSField inference_target)
        {
            MethodInfo oper;

            if (this.type1 == null || inference_target != null)
            {
                oper = this.GetOperator(this.operand1.InferType(inference_target), this.operand2.InferType(inference_target));
            }
            else
            {
                oper = this.GetOperator(this.type1, this.type2);
            }
            if (oper != null)
            {
                this.metaData = oper;
                return(oper.ReturnType);
            }
            if (this.type1 == Typeob.String || this.type2 == Typeob.String)
            {
                return(Typeob.String);
            }
            if (Convert.IsPrimitiveNumericType(this.type1))
            {
                if (Convert.IsPromotableTo(this.type2, this.type1) || ((this.operand2 is ConstantWrapper) && ((ConstantWrapper)this.operand2).IsAssignableTo(this.type1)))
                {
                    return(this.type1);
                }
                else if (Convert.IsPrimitiveNumericType(this.type1) && Convert.IsPrimitiveNumericTypeFitForDouble(this.type2))
                {
                    return(Typeob.Double);
                }
            }
            return(Typeob.Object);
        }
 internal void SetInferredType(IReflect ir, AST expr)
 {
     this.isDefined = true;
     if (this.type != null)
     {
         return; //The local variable has a type annotation.
     }
     if (this.outerField != null)
     {
         this.outerField.SetInferredType(ir, expr);
         return;
     }
     if (Convert.IsPrimitiveNumericTypeFitForDouble(ir))
     {
         ir = Typeob.Double;
     }
     else if (ir == Typeob.Void)
     {
         ir = Typeob.Object;
     }
     if (this.inferred_type == null)
     {
         this.inferred_type = ir;
     }
     else
     {
         //Check to see if ir is compatible with this.inferred_type. If not, generalize this.inferred_type to Object and invalidate dependants.
         if (ir == this.inferred_type)
         {
             return;
         }
         if (!Convert.IsPrimitiveNumericType(this.inferred_type) || !Convert.IsPrimitiveNumericType(ir) ||
             !Convert.IsPromotableTo(ir, this.inferred_type))
         {
             this.inferred_type = Typeob.Object;
             if (this.dependents != null)
             {
                 for (int i = 0, n = this.dependents.Count; i < n; i++)
                 {
                     ((JSLocalField)this.dependents[i]).SetInferredType(Typeob.Object, null);
                 }
             }
         }
     }
 }
Пример #3
0
        internal override IReflect InferType(JSField inference_target)
        {
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.type1));
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.type2));
            MethodInfo oper;

            if (this.type1 == null || inference_target != null)
            {
                oper = this.GetOperator(this.operand1.InferType(inference_target), this.operand2.InferType(inference_target));
            }
            else
            {
                oper = this.GetOperator(this.type1, this.type2);
            }
            if (oper != null)
            {
                this.metaData = oper;
                return(oper.ReturnType);
            }
            if (this.type1 == Typeob.Char && this.operatorTok == JSToken.Minus)
            {
                TypeCode t2 = Type.GetTypeCode(this.type2);
                if (Convert.IsPrimitiveNumericTypeCode(t2) || t2 == TypeCode.Boolean)
                {
                    return(Typeob.Char);
                }
                else if (t2 == TypeCode.Char)
                {
                    return(Typeob.Int32);
                }
            }
            if (Convert.IsPrimitiveNumericType(this.type1))
            {
                if (Convert.IsPromotableTo(this.type2, this.type1) || ((this.operand2 is ConstantWrapper) && ((ConstantWrapper)this.operand2).IsAssignableTo(this.type1)))
                {
                    return(this.type1);
                }
                else if (Convert.IsPrimitiveNumericType(this.type1) && Convert.IsPrimitiveNumericTypeFitForDouble(this.type2))
                {
                    return(Typeob.Double);
                }
            }
            return(Typeob.Object);
        }
Пример #4
0
        internal override IReflect InferType(JSField inference_target)
        {
            MethodInfo oper;

            if (this.type1 == null || inference_target != null)
            {
                oper = this.GetOperator(this.operand1.InferType(inference_target), this.operand2.InferType(inference_target));
            }
            else
            {
                oper = this.GetOperator(this.type1, this.type2);
            }
            if (oper != null)
            {
                this.metaData = oper;
                return(oper.ReturnType);
            }
            if (this.type1 == Typeob.Char && this.operatorTok == JSToken.Minus)
            {
                TypeCode t2 = Type.GetTypeCode(this.type2);
                if (Convert.IsPrimitiveNumericTypeCode(t2) || t2 == TypeCode.Boolean)
                {
                    return(Typeob.Char);
                }
                else if (t2 == TypeCode.Char)
                {
                    return(Typeob.Int32);
                }
            }
            if ((Convert.IsPrimitiveNumericTypeFitForDouble(this.type1) || Typeob.JSObject.IsAssignableFrom(this.type1)) &&
                (Convert.IsPrimitiveNumericTypeFitForDouble(this.type2) || Typeob.JSObject.IsAssignableFrom(this.type2)))
            {
                return(Typeob.Double);
            }
            else
            {
                return(Typeob.Object);
            }
        }
Пример #5
0
        internal override IReflect InferType(JSField inference_target)
        {
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.type1));
            Debug.Assert(Globals.TypeRefs.InReferenceContext(this.type2));
            MethodInfo oper;

            if (this.type1 == null || inference_target != null)
            {
                oper = this.GetOperator(this.operand1.InferType(inference_target), this.operand2.InferType(inference_target));
            }
            else
            {
                oper = this.GetOperator(this.type1, this.type2);
            }
            if (oper != null)
            {
                this.metaData = oper;
                return(oper.ReturnType);
            }
            if (this.type1 == Typeob.String || this.type2 == Typeob.String)
            {
                return(Typeob.String);
            }
            else if (this.type1 == Typeob.Char && this.type2 == Typeob.Char)
            {
                return(Typeob.String);
            }
            else if (Convert.IsPrimitiveNumericTypeFitForDouble(this.type1))
            {
                if (this.type2 == Typeob.Char)
                {
                    return(Typeob.Char);
                }
                else if (Convert.IsPrimitiveNumericTypeFitForDouble(this.type2))
                {
                    return(Typeob.Double);
                }
                else
                {
                    return(Typeob.Object);
                }
            }
            else if (Convert.IsPrimitiveNumericTypeFitForDouble(this.type2))
            {
                if (this.type1 == Typeob.Char)
                {
                    return(Typeob.Char);
                }
                else if (Convert.IsPrimitiveNumericTypeFitForDouble(this.type1))
                {
                    return(Typeob.Double);
                }
                else
                {
                    return(Typeob.Object);
                }
            }
            else if (this.type1 == Typeob.Boolean && this.type2 == Typeob.Char)
            {
                return(Typeob.Char);
            }
            else if (this.type1 == Typeob.Char && this.type2 == Typeob.Boolean)
            {
                return(Typeob.Char);
            }
            else
            {
                return(Typeob.Object);
            }
        }