Beispiel #1
0
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), this.GetType(), classScope);
            var left = symbols.GetAddLeftResult(method);
            method.Block.DeclareVar<bool>("hasNullRow", ConstantFalse());
            var @foreach = method.Block.ForEach(typeof(EventBean), "theEvent", symbols.GetAddMatchingEvents(method));
            {
                @foreach.AssignArrayElement(NAME_EPS, Constant(0), Ref("theEvent"));
                if (filterEval != null) {
                    CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                        @foreach,
                        filterEval.EvaluationType,
                        filterEval.EvaluateCodegen(typeof(bool?), method, symbols, classScope));
                }

                @foreach.IfRefNullReturnNull(left);

                Type valueRightType;
                if (selectEval != null) {
                    valueRightType = Boxing.GetBoxedType(selectEval.EvaluationType);
                    @foreach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        selectEval.EvaluateCodegen(valueRightType, method, symbols, classScope));
                }
                else {
                    valueRightType = subselect.RawEventType.UnderlyingType;
                    @foreach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        Cast(valueRightType, ExprDotUnderlying(ArrayAtIndex(symbols.GetAddEPS(method), Constant(0)))));
                }

                var ifRight = @foreach.IfCondition(NotEqualsNull(Ref("valueRight")));
                {
                    if (coercer == null) {
                        ifRight.IfCondition(ExprDotMethod(left, "Equals", Ref("valueRight")))
                            .BlockReturn(Constant(!isNotIn));
                    }
                    else {
                        ifRight.DeclareVar<object>("left", coercer.CoerceCodegen(left, symbols.LeftResultType))
                            .DeclareVar<object>("right", coercer.CoerceCodegen(Ref("valueRight"), valueRightType))
                            .DeclareVar<bool>("eq", ExprDotMethod(Ref("left"), "Equals", Ref("right")))
                            .IfCondition(Ref("eq"))
                            .BlockReturn(Constant(!isNotIn));
                    }
                }
                ifRight.IfElse().AssignRef("hasNullRow", ConstantTrue());
            }

            method.Block
                .IfCondition(Ref("hasNullRow"))
                .BlockReturn(ConstantNull())
                .MethodReturn(Constant(isNotIn));
            return LocalMethod(method);
        }
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), GetType(), classScope);
            var eps = symbols.GetAddEPS(method);
            var evalCtx = symbols.GetAddExprEvalCtx(method);
            var left = symbols.GetAddLeftResult(method);

            method.Block.IfNullReturnNull(symbols.GetAddLeftResult(method));
            if (havingEval != null) {
                CodegenExpression having = LocalMethod(
                    CodegenLegoMethodExpression.CodegenExpression(havingEval, method, classScope, true),
                    eps,
                    ConstantTrue(),
                    evalCtx);
                CodegenLegoBooleanExpression.CodegenReturnValueIfNullOrNotPass(
                    method.Block,
                    havingEval.EvaluationType,
                    having,
                    ConstantNull());
            }

            CodegenExpression select = LocalMethod(
                CodegenLegoMethodExpression.CodegenExpression(selectEval, method, classScope, true),
                eps,
                ConstantTrue(),
                evalCtx);
            var rightEvalType = selectEval.EvaluationType.GetBoxedType();
            method.Block
                .DeclareVar(rightEvalType, "rhs", select)
                .IfRefNullReturnNull("rhs");

            if (coercer == null) {
                method.Block.DeclareVar<bool>("eq", ExprDotMethod(left, "Equals", Ref("rhs")));
                if (isNot) {
                    method.Block.IfCondition(Ref("eq")).BlockReturn(ConstantFalse());
                }
                else {
                    method.Block.IfCondition(Not(Ref("eq"))).BlockReturn(ConstantFalse());
                }
            }
            else {
                method.Block
                    .DeclareVar<object>("left", coercer.CoerceCodegen(left, symbols.LeftResultType))
                    .DeclareVar<object>("right", coercer.CoerceCodegen(Ref("rhs"), rightEvalType))
                    .DeclareVar<bool>("eq", StaticMethod<object>("Equals", Ref("left"), Ref("right")));
                if (isNot) {
                    method.Block.IfCondition(Ref("eq")).BlockReturn(ConstantFalse());
                }
                else {
                    method.Block.IfCondition(Not(Ref("eq"))).BlockReturn(ConstantFalse());
                }
            }

            method.Block.MethodReturn(ConstantTrue());
            return LocalMethod(method);
        }
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), GetType(), classScope);
            CodegenExpression eps = symbols.GetAddEPS(method);
            CodegenExpression evalCtx = symbols.GetAddExprEvalCtx(method);
            var left = symbols.GetAddLeftResult(method);

            if (havingEval != null) {
                CodegenExpression having = LocalMethod(
                    CodegenLegoMethodExpression.CodegenExpression(havingEval, method, classScope, true),
                    eps,
                    ConstantTrue(),
                    evalCtx);
                CodegenLegoBooleanExpression.CodegenReturnValueIfNullOrNotPass(
                    method.Block,
                    havingEval.EvaluationType,
                    having,
                    ConstantNull());
            }

            CodegenExpression rhsSide = LocalMethod(
                CodegenLegoMethodExpression.CodegenExpression(selectEval, method, classScope, true),
                eps,
                ConstantTrue(),
                evalCtx);
            var rhsType = selectEval.EvaluationType.GetBoxedType();
            method.Block
                .DeclareVar(rhsType, "rhs", rhsSide)
                .IfRefNullReturnNull("rhs")
                .MethodReturn(computer.Codegen(left, symbols.LeftResultType, Ref("rhs"), rhsType));

            return LocalMethod(method);
        }
Beispiel #4
0
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpression aggService = classScope.NamespaceScope.AddOrGetDefaultFieldWellKnown(
                new CodegenFieldNameSubqueryAgg(subselect.SubselectNumber),
                typeof(AggregationResultFuture));

            var method = parent.MakeChild(subselect.EvaluationType, this.GetType(), classScope);
            var evalCtx = symbols.GetAddExprEvalCtx(method);
            var left = symbols.GetAddLeftResult(method);

            method.Block
                .DeclareVar<int>("cpid", ExprDotName(evalCtx, "AgentInstanceId"))
                .DeclareVar<AggregationService>(
                    "aggregationService",
                    ExprDotMethod(aggService, "GetContextPartitionAggregationService", Ref("cpid")))
                .DeclareVar<ICollection<object>>(
                    "groupKeys",
                    ExprDotMethod(Ref("aggregationService"), "GetGroupKeys", evalCtx))
                .DeclareVar<bool>("hasNullRow", ConstantFalse());

            var forEach = method.Block.ForEach(typeof(object), "groupKey", Ref("groupKeys"));
            {
                forEach.IfCondition(EqualsNull(left))
                    .BlockReturn(ConstantNull())
                    .ExprDotMethod(
                        Ref("aggregationService"),
                        "SetCurrentAccess",
                        Ref("groupKey"),
                        Ref("cpid"),
                        ConstantNull());

                if (havingEval != null) {
                    CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                        forEach,
                        havingEval.EvaluationType,
                        havingEval.EvaluateCodegen(havingEval.EvaluationType, method, symbols, classScope));
                }

                Type valueRightType;
                if (selectEval != null) {
                    valueRightType = Boxing.GetBoxedType(selectEval.EvaluationType);
                    forEach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        selectEval.EvaluateCodegen(valueRightType, method, symbols, classScope));
                }
                else {
                    valueRightType = typeof(object);
                    forEach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        ExprDotUnderlying(ArrayAtIndex(symbols.GetAddEPS(method), Constant(0))));
                }

                var ifRightNotNull = forEach.IfCondition(EqualsNull(Ref("valueRight")))
                    .AssignRef("hasNullRow", ConstantTrue())
                    .IfElse();
                {
                    if (coercer == null) {
                        ifRightNotNull.DeclareVar<bool>("eq", ExprDotMethod(left, "Equals", Ref("valueRight")));
                    }
                    else {
                        ifRightNotNull.DeclareVar<object>("left", coercer.CoerceCodegen(left, symbols.LeftResultType))
                            .DeclareVar<object>("right", coercer.CoerceCodegen(Ref("valueRight"), valueRightType))
                            .DeclareVar<bool>("eq", StaticMethod<object>("Equals", Ref("left"), Ref("right")));
                    }

                    if (isNot) {
                        if (isAll) {
                            ifRightNotNull.IfCondition(Ref("eq")).BlockReturn(ConstantFalse());
                        }
                        else {
                            ifRightNotNull.IfCondition(Not(Ref("eq"))).BlockReturn(ConstantTrue());
                        }
                    }
                    else {
                        if (isAll) {
                            ifRightNotNull.IfCondition(Not(Ref("eq"))).BlockReturn(ConstantFalse());
                        }
                        else {
                            ifRightNotNull.IfCondition(Ref("eq")).BlockReturn(ConstantTrue());
                        }
                    }
                }
            }

            method.Block
                .IfCondition(Ref("hasNullRow"))
                .BlockReturn(ConstantNull())
                .MethodReturn(isAll ? ConstantTrue() : ConstantFalse());

            return LocalMethod(method);
        }
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), GetType(), classScope);
            method.Block
                .DeclareVar<bool>("hasRows", ConstantFalse())
                .DeclareVar<bool>("hasNullRow", ConstantFalse());
            var @foreach = method.Block.ForEach(
                typeof(EventBean),
                "subselectEvent",
                symbols.GetAddMatchingEvents(method));
            {
                @foreach.AssignArrayElement(NAME_EPS, Constant(0), Ref("subselectEvent"));
                if (filterOrHavingEval != null) {
                    CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                        @foreach,
                        filterOrHavingEval.EvaluationType,
                        filterOrHavingEval.EvaluateCodegen(typeof(bool?), method, symbols, classScope));
                }

                @foreach.AssignRef("hasRows", ConstantTrue());

                Type valueRightType;
                if (selectEval != null) {
                    valueRightType = selectEval.EvaluationType.GetBoxedType();
                    @foreach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        selectEval.EvaluateCodegen(valueRightType, method, symbols, classScope));
                }
                else {
                    valueRightType = typeof(object);
                    @foreach.DeclareVar(
                        valueRightType,
                        "valueRight",
                        ExprDotUnderlying(ArrayAtIndex(symbols.GetAddEPS(method), Constant(0))));
                }

                @foreach.IfRefNull("valueRight")
                    .AssignRef("hasNullRow", ConstantTrue())
                    .IfElse()
                    .IfCondition(NotEqualsNull(symbols.GetAddLeftResult(method)))
                    .IfCondition(
                        Not(
                            computer.Codegen(
                                symbols.GetAddLeftResult(method),
                                symbols.LeftResultType,
                                Ref("valueRight"),
                                valueRightType)))
                    .BlockReturn(ConstantFalse());
            }

            method.Block
                .IfCondition(Not(Ref("hasRows")))
                .BlockReturn(ConstantTrue())
                .IfCondition(EqualsNull(symbols.GetAddLeftResult(method)))
                .BlockReturn(ConstantNull())
                .IfCondition(Ref("hasNullRow"))
                .BlockReturn(ConstantNull())
                .MethodReturn(ConstantTrue());
            return LocalMethod(method);
        }