Пример #1
0
            public CodegenExpression CodegenNoNullCheck(
                CodegenExpression value,
                Type valueType,
                CodegenExpression lower,
                Type lowerType,
                CodegenExpression higher,
                Type higherType,
                CodegenMethodScope codegenMethodScope,
                CodegenClassScope codegenClassScope)
            {
                var block = codegenMethodScope
                    .MakeChild(typeof(bool), typeof(ExprBetweenCompBigInteger), codegenClassScope)
                    .AddParam(typeof(BigInteger), "value")
                    .AddParam(typeof(BigInteger), "lower")
                    .AddParam(typeof(BigInteger), "upper")
                    .Block
                    .IfRefNullReturnFalse("value")
                    .IfRefNullReturnFalse("lower")
                    .IfRefNullReturnFalse("upper")
                    .IfCondition(Relational(ExprDotMethod(Ref("lower"), "CompareTo", Ref("upper")), GT, Constant(0)))
                    .DeclareVar<BigInteger>("temp", Ref("upper"))
                    .AssignRef("upper", Ref("lower"))
                    .AssignRef("lower", Ref("temp"))
                    .BlockEnd();
                var ifValueGtLower = block.IfCondition(
                    Relational(ExprDotMethod(Ref("value"), "CompareTo", Ref("lower")), GT, Constant(0)));
                {
                    ifValueGtLower
                        .IfCondition(
                            Relational(ExprDotMethod(Ref("value"), "CompareTo", Ref("upper")), LT, Constant(0)))
                        .BlockReturn(ConstantTrue());
                    if (_isHighIncluded) {
                        ifValueGtLower.BlockReturn(ExprDotMethod(Ref("value"), "Equals", Ref("upper")));
                    }
                    else {
                        ifValueGtLower.BlockReturn(ConstantFalse());
                    }
                }
                CodegenMethod method;
                if (_isLowIncluded) {
                    method = block.MethodReturn(ExprDotMethod(Ref("value"), "Equals", Ref("lower")));
                }
                else {
                    method = block.MethodReturn(ConstantFalse());
                }

                CodegenExpression valueCoerced = _numberCoercerValue.CoerceBoxedBigIntCodegen(value, valueType);
                CodegenExpression lowerCoerced = _numberCoercerValue.CoerceBoxedBigIntCodegen(lower, lowerType);
                CodegenExpression higherCoerced = _numberCoercerValue.CoerceBoxedBigIntCodegen(higher, higherType);
                return LocalMethod(method, valueCoerced, lowerCoerced, higherCoerced);
            }
            public CodegenExpression Codegen(
                CodegenMethodScope codegenMethodScope,
                CodegenClassScope codegenClassScope,
                CodegenExpressionRef left,
                CodegenExpressionRef right,
                Type ltype,
                Type rtype)
            {
                var leftAsBig  = _convOne.CoerceBoxedBigIntCodegen(left, ltype);
                var rightAsBig = _convTwo.CoerceBoxedBigIntCodegen(right, rtype);

                return(CodegenExpressionBuilder.Op(leftAsBig, "+", rightAsBig));
            }
Пример #3
0
        public static CodegenExpression CodegenBigIntConv(
            CodegenExpression lhs,
            Type lhsType,
            CodegenExpression rhs,
            Type rhsType,
            BigIntegerCoercer convLeft,
            BigIntegerCoercer convRight,
            CodegenExpressionRelational.CodegenRelational rel)
        {
            var leftConv  = convLeft.CoerceBoxedBigIntCodegen(lhs, lhsType);
            var rightConv = convRight.CoerceBoxedBigIntCodegen(rhs, rhsType);

            return(CodegenExpressionBuilder.Relational(
                       CodegenExpressionBuilder.ExprDotMethod(leftConv, "CompareTo", rightConv),
                       rel,
                       CodegenExpressionBuilder.Constant(0)));
        }
            public CodegenExpression Codegen(
                CodegenMethodScope codegenMethodScope,
                CodegenClassScope codegenClassScope,
                CodegenExpressionRef left,
                CodegenExpressionRef right,
                Type ltype,
                Type rtype)
            {
                var method = codegenMethodScope
                             .MakeChild(typeof(BigInteger?), typeof(DivideBigIntConvComputer), codegenClassScope)
                             .AddParam(ltype, "d1")
                             .AddParam(rtype, "d2")
                             .Block
                             .DeclareVar <BigInteger?>("s1", _convOne.CoerceBoxedBigIntCodegen(Ref("d1"), ltype))
                             .DeclareVar <BigInteger?>("s2", _convTwo.CoerceBoxedBigIntCodegen(Ref("d2"), rtype))
                             .IfCondition(EqualsIdentity(Ref("s2"), EnumValue(typeof(BigInteger), "Zero")))
                             .BlockReturn(ConstantNull())
                             .MethodReturn(Op(Ref("s1"), "/", Ref("s2")));

                return(LocalMethodBuild(method).Pass(left).Pass(right).Call());
            }