コード例 #1
0
        public override CheckTypesResult CheckExprTypeBounds()
        {
            CheckTypesResult result = new CheckTypesResult();
            Exprent          param1 = lstOperands[0];
            VarType          type1  = param1.GetExprType();
            Exprent          param2 = null;
            VarType          type2  = null;

            if (lstOperands.Count > 1)
            {
                param2 = lstOperands[1];
                type2  = param2.GetExprType();
            }
            switch (funcType)
            {
            case Function_Iif:
            {
                VarType supertype = GetExprType();
                result.AddMinTypeExprent(param1, VarType.Vartype_Boolean);
                result.AddMinTypeExprent(param2, VarType.GetMinTypeInFamily(supertype.typeFamily)
                                         );
                result.AddMinTypeExprent(lstOperands[2], VarType.GetMinTypeInFamily(supertype.typeFamily
                                                                                    ));
                break;
            }

            case Function_I2l:
            case Function_I2f:
            case Function_I2d:
            case Function_I2b:
            case Function_I2c:
            case Function_I2s:
            {
                result.AddMinTypeExprent(param1, VarType.Vartype_Bytechar);
                result.AddMaxTypeExprent(param1, VarType.Vartype_Int);
                break;
            }

            case Function_Imm:
            case Function_Ipp:
            case Function_Mmi:
            case Function_Ppi:
            {
                result.AddMinTypeExprent(param1, implicitType);
                result.AddMaxTypeExprent(param1, implicitType);
                break;
            }

            case Function_Add:
            case Function_Sub:
            case Function_Mul:
            case Function_Div:
            case Function_Rem:
            case Function_Shl:
            case Function_Shr:
            case Function_Ushr:
            case Function_Lt:
            case Function_Ge:
            case Function_Gt:
            case Function_Le:
            {
                result.AddMinTypeExprent(param2, VarType.Vartype_Bytechar);
                goto case Function_Bit_Not;
            }

            case Function_Bit_Not:
            case Function_Neg:
            {
                // case FUNCTION_BOOL_NOT:
                result.AddMinTypeExprent(param1, VarType.Vartype_Bytechar);
                break;
            }

            case Function_And:
            case Function_Or:
            case Function_Xor:
            case Function_Eq:
            case Function_Ne:
            {
                if (type1.type == ICodeConstants.Type_Boolean)
                {
                    if (type2.IsStrictSuperset(type1))
                    {
                        result.AddMinTypeExprent(param1, VarType.Vartype_Bytechar);
                    }
                    else
                    {
                        // both are booleans
                        bool param1_false_boolean = type1.IsFalseBoolean() || (param1.type == Exprent.Exprent_Const &&
                                                                               !((ConstExprent)param1).HasBooleanValue());
                        bool param2_false_boolean = type1.IsFalseBoolean() || (param2.type == Exprent.Exprent_Const &&
                                                                               !((ConstExprent)param2).HasBooleanValue());
                        if (param1_false_boolean || param2_false_boolean)
                        {
                            result.AddMinTypeExprent(param1, VarType.Vartype_Bytechar);
                            result.AddMinTypeExprent(param2, VarType.Vartype_Bytechar);
                        }
                    }
                }
                else if (type2.type == ICodeConstants.Type_Boolean)
                {
                    if (type1.IsStrictSuperset(type2))
                    {
                        result.AddMinTypeExprent(param2, VarType.Vartype_Bytechar);
                    }
                }
                break;
            }
            }
            return(result);
        }