public override CodegenExpression EvaluateCodegen(
     CodegenMethodScope parent,
     ExprSubselectEvalMatchSymbol symbols,
     CodegenClassScope classScope)
 {
     var eventToPublic = TableDeployTimeResolver.MakeTableEventToPublicField(table, classScope, GetType());
     var method = parent.MakeChild(subselect.EvaluationType, GetType(), classScope);
     method.Block
         .IfCondition(
             Relational(
                 ExprDotName(symbols.GetAddMatchingEvents(method), "Count"),
                 CodegenExpressionRelational.CodegenRelational.GT,
                 Constant(1)))
         .BlockReturn(ConstantNull())
         .DeclareVar<EventBean>(
             "@event",
             StaticMethod(
                 typeof(EventBeanUtility),
                 "GetNonemptyFirstEvent",
                 symbols.GetAddMatchingEvents(method)))
         .MethodReturn(
             ExprDotMethod(
                 eventToPublic,
                 "ConvertToUnd",
                 Ref("@event"),
                 symbols.GetAddEPS(method),
                 symbols.GetAddIsNewData(method),
                 symbols.GetAddExprEvalCtx(method)));
     return LocalMethod(method);
 }
Exemplo n.º 2
0
        public override CodegenExpression EvaluateGetCollScalarCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.FilterExpr == null) {
                if (subselect.SelectClause == null) {
                    return ConstantNull();
                }
                else {
                    var method = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);
                    method.Block
                        .DeclareVar<IList<object>>("result", NewInstance(typeof(List<object>)))
                        .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);
                    var selectClause = GetSelectClauseExpr(method, symbols, classScope);
                    var @foreach = method.Block.ForEach(
                        typeof(EventBean),
                        "@event",
                        symbols.GetAddMatchingEvents(method));
                    {
                        @foreach.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"))
                            .DeclareVar<object>("value", selectClause)
                            .ExprDotMethod(Ref("result"), "Add", Ref("value"));
                    }
                    method.Block.MethodReturn(FlexWrap(Ref("result")));
                    return LocalMethod(method);
                }
            }

            if (subselect.SelectClause == null) {
                return ConstantNull();
            }

            var methodX = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);
            methodX.Block
                .DeclareVar<IList<object>>("result", NewInstance(typeof(List<object>)))
                .ApplyTri(DECLARE_EVENTS_SHIFTED, methodX, symbols);
            var selectClauseX = GetSelectClauseExpr(methodX, symbols, classScope);
            var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, methodX, classScope, true);
            var foreachX = methodX.Block.ForEach(
                typeof(EventBean),
                "@event",
                symbols.GetAddMatchingEvents(methodX));
            {
                foreachX.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                    foreachX,
                    typeof(bool?),
                    LocalMethod(
                        filter,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(methodX),
                        symbols.GetAddExprEvalCtx(methodX)));
                foreachX.DeclareVar<object>("value", selectClauseX)
                    .ExprDotMethod(Ref("result"), "Add", Ref("value"));
            }
            methodX.Block.MethodReturn(FlexWrap(Ref("result")));
            return LocalMethod(methodX);
        }
        public CodegenExpression EvaluateMatchesCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool), GetType(), classScope);
            method.Block.ApplyTri(new ReturnIfNoMatch(ConstantFalse(), ConstantFalse()), method, symbols);

            if (filterEval == null && havingEval == null) {
                method.Block.MethodReturn(ConstantTrue());
                return LocalMethod(method);
            }

            method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);
            if (havingEval != null) {
                throw new UnsupportedOperationException();
            }

            var filter = CodegenLegoMethodExpression.CodegenExpression(filterEval, method, classScope, true);
            method.Block
                .ForEach(typeof(EventBean), "subselectEvent", symbols.GetAddMatchingEvents(method))
                .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("subselectEvent"))
                .DeclareVar<bool?>(
                    "pass",
                    LocalMethod(filter, REF_EVENTS_SHIFTED, ConstantTrue(), symbols.GetAddExprEvalCtx(method)))
                .IfCondition(And(NotEqualsNull(Ref("pass")), Unbox(Ref("pass"))))
                .BlockReturn(ConstantTrue())
                .BlockEnd()
                .MethodReturn(ConstantFalse());
            return LocalMethod(method);
        }
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol 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);

            method.Block
                .DeclareVar<int>("cpid", ExprDotName(evalCtx, "AgentInstanceId"))
                .DeclareVar<ICollection<object>>(
                    "groupKeys",
                    ExprDotMethod(aggService, "GetGroupKeys", evalCtx))
                .IfCondition(Not(EqualsIdentity(ExprDotName(Ref("groupKeys"), "Count"), Constant(1))))
                .BlockReturn(ConstantNull())
                .ExprDotMethod(
                    aggService,
                    "SetCurrentAccess",
                    ExprDotMethodChain(Ref("groupKeys")).Add("First"),
                    Ref("cpid"),
                    ConstantNull())
                .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                .AssignArrayElement(
                    REF_EVENTS_SHIFTED,
                    Constant(0),
                    StaticMethod(
                        typeof(EventBeanUtility),
                        "GetNonemptyFirstEvent",
                        symbols.GetAddMatchingEvents(method)));

            if (subselect.SelectClause.Length == 1) {
                var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[0].Forge, method, classScope, true);
                method.Block.MethodReturn(
                    LocalMethod(eval, REF_EVENTS_SHIFTED, ConstantTrue(), symbols.GetAddExprEvalCtx(method)));
            }
            else {
                var methodSelect = ExprNodeUtilityCodegen.CodegenMapSelect(
                    subselect.SelectClause,
                    subselect.SelectAsNames,
                    this.GetType(),
                    method,
                    classScope);
                CodegenExpression select = LocalMethod(
                    methodSelect,
                    REF_EVENTS_SHIFTED,
                    ConstantTrue(),
                    symbols.GetAddExprEvalCtx(method));
                method.Block.MethodReturn(select);
            }

            return LocalMethod(method);
        }
Exemplo n.º 5
0
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpressionInstanceField eventToPublic =
                TableDeployTimeResolver.MakeTableEventToPublicField(table, classScope, this.GetType());
            CodegenMethod method = parent.MakeChild(subselect.EvaluationType, this.GetType(), classScope);

            method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

            method.Block.DeclareVar<EventBean>("filtered", ConstantNull());
            CodegenBlock @foreach = method.Block.ForEach(
                typeof(EventBean),
                "@event",
                symbols.GetAddMatchingEvents(method));
            {
                @foreach.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                CodegenMethod filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                    @foreach,
                    typeof(bool?),
                    LocalMethod(
                        filter,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
                @foreach.IfCondition(NotEqualsNull(Ref("filtered")))
                    .BlockReturn(ConstantNull())
                    .AssignRef("filtered", Ref("@event"));
            }

            method.Block.IfRefNullReturnNull("filtered")
                .MethodReturn(
                    ExprDotMethod(
                        eventToPublic,
                        "ConvertToUnd",
                        Ref("filtered"),
                        symbols.GetAddEPS(method),
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
            return LocalMethod(method);
        }
Exemplo n.º 6
0
        public CodegenExpression EvaluateMatchesCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            var leftResultType = valueEval.EvaluationType.GetBoxedType();
            var method = parent.MakeChild(subselect.EvaluationType, GetType(), classScope);
            method.Block
                .ApplyTri(
                    new ReturnIfNoMatch(Constant(resultWhenNoMatchingEvents), Constant(resultWhenNoMatchingEvents)),
                    method,
                    symbols)
                .DeclareVar(
                    leftResultType,
                    "leftResult",
                    valueEval.EvaluateCodegen(valueEval.EvaluationType, parent, symbols, classScope))
                .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

            var nrSymbols = new SubselectForgeNRSymbol(leftResultType);
            var child = parent
                .MakeChildWithScope(subselect.EvaluationType, GetType(), nrSymbols, classScope)
                .AddParam(leftResultType, NAME_LEFTRESULT)
                .AddParam(typeof(EventBean[]), NAME_EPS)
                .AddParam(typeof(bool), NAME_ISNEWDATA)
                .AddParam(typeof(FlexCollection), NAME_MATCHINGEVENTS)
                .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT);
            child.Block.MethodReturn(CodegenEvaluateInternal(child, nrSymbols, classScope));
            method.Block.MethodReturn(
                LocalMethod(
                    child,
                    REF_LEFTRESULT,
                    REF_EVENTS_SHIFTED,
                    symbols.GetAddIsNewData(method),
                    symbols.GetAddMatchingEvents(method),
                    symbols.GetAddExprEvalCtx(method)));

            return LocalMethod(method);
        }
Exemplo n.º 7
0
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(subselect.EvaluationType, this.GetType(), classScope);

            if (subselect.FilterExpr == null) {
                method.Block
                    .IfCondition(
                        Relational(
                            ExprDotName(symbols.GetAddMatchingEvents(method), "Count"),
                            CodegenExpressionRelational.CodegenRelational.GT,
                            Constant(1)))
                    .BlockReturn(ConstantNull());
                if (subselect.SelectClause == null) {
                    method.Block.MethodReturn(
                        Cast(
                            subselect.EvaluationType,
                            StaticMethod(
                                typeof(EventBeanUtility),
                                "GetNonemptyFirstEventUnderlying",
                                symbols.GetAddMatchingEvents(method))));
                    return LocalMethod(method);
                }
                else {
                    method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                        .AssignArrayElement(
                            REF_EVENTS_SHIFTED,
                            Constant(0),
                            StaticMethod(
                                typeof(EventBeanUtility),
                                "GetNonemptyFirstEvent",
                                symbols.GetAddMatchingEvents(method)));
                }
            }
            else {
                method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

                method.Block.DeclareVar<EventBean>("filtered", ConstantNull());
                var @foreach = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    @foreach.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                    var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                    CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                        @foreach,
                        typeof(bool?),
                        LocalMethod(
                            filter,
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddExprEvalCtx(method)));
                    @foreach.IfCondition(NotEqualsNull(Ref("filtered")))
                        .BlockReturn(ConstantNull())
                        .AssignRef("filtered", Ref("@event"));
                }

                if (subselect.SelectClause == null) {
                    method.Block.IfRefNullReturnNull("filtered")
                        .MethodReturn(Cast(subselect.EvaluationType, ExprDotUnderlying(Ref("filtered"))));
                    return LocalMethod(method);
                }

                method.Block.IfRefNullReturnNull("filtered")
                    .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("filtered"));
            }

            var selectClause = GetSelectClauseExpr(method, symbols, classScope);
            method.Block.MethodReturn(selectClause);
            return LocalMethod(method);
        }
Exemplo n.º 8
0
        public override CodegenExpression EvaluateGetBeanCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause == null) {
                return ConstantNull();
            }

            var method = parent.MakeChild(typeof(EventBean), this.GetType(), classScope);
            var eventBeanSvc =
                classScope.AddOrGetDefaultFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE);
            var typeMember = classScope.AddDefaultFieldUnshared(
                true,
                typeof(EventType),
                EventTypeUtility.ResolveTypeCodegen(
                    subselect.subselectMultirowType,
                    EPStatementInitServicesConstants.REF));

            if (subselect.FilterExpr == null) {
                method.Block
                    .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                    .AssignArrayElement(
                        REF_EVENTS_SHIFTED,
                        Constant(0),
                        StaticMethod(
                            typeof(EventBeanUtility),
                            "GetNonemptyFirstEvent",
                            symbols.GetAddMatchingEvents(method)))
                    .DeclareVar<IDictionary<string, object>>(
                        "row",
                        LocalMethod(
                            subselect.EvaluateRowCodegen(method, classScope),
                            REF_EVENTS_SHIFTED,
                            ConstantTrue(),
                            symbols.GetAddExprEvalCtx(method)))
                    .DeclareVar<EventBean>(
                        "bean",
                        ExprDotMethod(eventBeanSvc, "AdapterForTypedMap", Ref("row"), typeMember))
                    .MethodReturn(Ref("bean"));
                return LocalMethod(method);
            }

            var filter = ExprNodeUtilityCodegen.CodegenEvaluator(
                subselect.FilterExpr,
                method,
                this.GetType(),
                classScope);
            method.Block
                .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                .DeclareVar<EventBean>(
                    "subSelectResult",
                    StaticMethod(
                        typeof(EventBeanUtility),
                        "EvaluateFilterExpectSingleMatch",
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddMatchingEvents(method),
                        symbols.GetAddExprEvalCtx(method),
                        filter))
                .IfRefNullReturnNull("subselectResult")
                .DeclareVar<IDictionary<string, object>>(
                    "row",
                    LocalMethod(
                        subselect.EvaluateRowCodegen(method, classScope),
                        REF_EVENTS_SHIFTED,
                        ConstantTrue(),
                        symbols.GetAddExprEvalCtx(method)))
                .DeclareVar<EventBean>(
                    "bean",
                    ExprDotMethod(eventBeanSvc, "AdapterForTypedMap", Ref("row"), typeMember))
                .MethodReturn(Ref("bean"));
            return LocalMethod(method);
        }
Exemplo n.º 9
0
        public override CodegenExpression EvaluateGetCollEventsCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.FilterExpr == null) {
                if (subselect.SelectClause == null) {
                    return symbols.GetAddMatchingEvents(parent);
                }
                else {
                    if (subselect.subselectMultirowType == null) {
                        var eval = ((ExprIdentNode) subselect.SelectClause[0]).ExprEvaluatorIdent;
                        var method = parent.MakeChild(
                            typeof(FlexCollection),
                            this.GetType(),
                            classScope);
                        method.Block.DeclareVar<ICollection<EventBean>>(
                            "events",
                            NewInstance<ArrayDeque<EventBean>>(
                                ExprDotName(symbols.GetAddMatchingEvents(method), "Count")));
                        var @foreach = method.Block.ForEach(
                            typeof(EventBean),
                            "@event",
                            symbols.GetAddMatchingEvents(method));
                        {
                            @foreach.DeclareVar<EventBean>(
                                    "fragment",
                                    CodegenLegoCast.CastSafeFromObjectType(
                                        typeof(EventBean),
                                        eval.Getter.EventBeanFragmentCodegen(Ref("@event"), method, classScope)))
                                .IfRefNull("fragment")
                                .BlockContinue()
                                .ExprDotMethod(Ref("events"), "Add", Ref("fragment"));
                        }
                        method.Block.MethodReturn(FlexWrap(Ref("events")));
                        return LocalMethod(method);
                    }

                    // when selecting a combined output row that contains multiple fields
                    var methodX = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);
                    var fieldEventType = classScope.AddDefaultFieldUnshared(
                        true,
                        typeof(EventType),
                        EventTypeUtility.ResolveTypeCodegen(
                            subselect.subselectMultirowType,
                            EPStatementInitServicesConstants.REF));
                    var eventBeanSvc =
                        classScope.AddOrGetDefaultFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE);

                    methodX.Block
                        .DeclareVar<ICollection<EventBean>>(
                            "result",
                            NewInstance<ArrayDeque<EventBean>>(
                                ExprDotName(symbols.GetAddMatchingEvents(methodX), "Count")))
                        .ApplyTri(DECLARE_EVENTS_SHIFTED, methodX, symbols);
                    var foreachX = methodX.Block.ForEach(
                        typeof(EventBean),
                        "@event",
                        symbols.GetAddMatchingEvents(methodX));
                    {
                        foreachX.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"))
                            .DeclareVar<IDictionary<string, object>>(
                                "row",
                                LocalMethod(
                                    subselect.EvaluateRowCodegen(methodX, classScope),
                                    REF_EVENTS_SHIFTED,
                                    ConstantTrue(),
                                    symbols.GetAddExprEvalCtx(methodX)))
                            .DeclareVar<EventBean>(
                                "rowEvent",
                                ExprDotMethod(eventBeanSvc, "AdapterForTypedMap", Ref("row"), fieldEventType))
                            .ExprDotMethod(Ref("result"), "Add", Ref("rowEvent"));
                    }
                    methodX.Block.MethodReturn(FlexWrap(Ref("result")));
                    return LocalMethod(methodX);
                }
            }

            if (subselect.SelectClause != null) {
                return ConstantNull();
            }

            // handle filtered
            var methodY = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);

            methodY.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, methodY, symbols);

            methodY.Block.DeclareVar<ArrayDeque<EventBean>>("filtered", ConstantNull());
            var foreachY = methodY.Block.ForEach(
                typeof(EventBean),
                "@event",
                symbols.GetAddMatchingEvents(methodY));
            {
                foreachY.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, methodY, classScope, true);
                CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                    foreachY,
                    typeof(bool?),
                    LocalMethod(
                        filter,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(methodY),
                        symbols.GetAddExprEvalCtx(methodY)));
                foreachY.IfCondition(EqualsNull(Ref("filtered")))
                    .AssignRef("filtered", NewInstance(typeof(ArrayDeque<EventBean>)))
                    .BlockEnd()
                    .ExprDotMethod(Ref("filtered"), "Add", Ref("@event"));
            }

            methodY.Block.MethodReturn(FlexWrap(Ref("filtered")));
            return LocalMethod(methodY);
        }
Exemplo n.º 10
0
        public CodegenExpression EvaluateTypableSinglerowCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause == null) {
                return ConstantNull(); // no select-clause
            }

            var method = parent.MakeChild(typeof(object[]), GetType(), classScope);
            if (subselect.FilterExpr == null) {
                method.Block
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols)
                    .AssignArrayElement(
                        REF_EVENTS_SHIFTED,
                        Constant(0),
                        StaticMethod(
                            typeof(EventBeanUtility),
                            "GetNonemptyFirstEvent",
                            symbols.GetAddMatchingEvents(method)));
            }
            else {
                var filter = ExprNodeUtilityCodegen.CodegenEvaluator(
                    subselect.FilterExpr,
                    method,
                    GetType(),
                    classScope);
                method.Block
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols)
                    .DeclareVar<EventBean>(
                        "subselectResult",
                        StaticMethod(
                            typeof(EventBeanUtility),
                            "EvaluateFilterExpectSingleMatch",
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddMatchingEvents(method),
                            symbols.GetAddExprEvalCtx(method),
                            filter))
                    .IfRefNullReturnNull("subselectResult")
                    .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("subselectResult"));
            }

            method.Block.DeclareVar<object[]>(
                "results",
                NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)));
            for (var i = 0; i < subselect.SelectClause.Length; i++) {
                var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                method.Block.AssignArrayElement(
                    "results",
                    Constant(i),
                    LocalMethod(
                        eval,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
            }

            method.Block.MethodReturn(Ref("results"));

            return LocalMethod(method);
        }
Exemplo n.º 11
0
        public CodegenExpression EvaluateTypableMultirowCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause == null) {
                return ConstantNull();
            }

            if (subselect.FilterExpr == null) {
                var method = parent.MakeChild(typeof(object[][]), GetType(), classScope);
                method.Block
                    .DeclareVar<object[][]>(
                        "rows",
                        NewArrayByLength(typeof(object[]), ExprDotName(symbols.GetAddMatchingEvents(method), "Count")))
                    .DeclareVar<int>("index", Constant(-1))
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols);
                var foreachEvent = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    foreachEvent
                        .IncrementRef("index")
                        .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"))
                        .DeclareVar<object[]>(
                            "results",
                            NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)))
                        .AssignArrayElement("rows", Ref("index"), Ref("results"));
                    for (var i = 0; i < subselect.SelectClause.Length; i++) {
                        var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                        foreachEvent.AssignArrayElement(
                            "results",
                            Constant(i),
                            LocalMethod(
                                eval,
                                REF_EVENTS_SHIFTED,
                                symbols.GetAddIsNewData(method),
                                symbols.GetAddExprEvalCtx(method)));
                    }
                }
                method.Block.MethodReturn(Ref("rows"));
                return LocalMethod(method);
            }
            else {
                var method = parent.MakeChild(typeof(object[][]), GetType(), classScope);
                method.Block
                    .DeclareVar<ArrayDeque<object[]>>("rows", NewInstance(typeof(ArrayDeque<object[]>)))
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols);
                var foreachEvent = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    foreachEvent.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));

                    var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                    CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                        foreachEvent,
                        typeof(bool?),
                        LocalMethod(
                            filter,
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddExprEvalCtx(method)));

                    foreachEvent
                        .DeclareVar<object[]>(
                            "results",
                            NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)))
                        .ExprDotMethod(Ref("rows"), "Add", Ref("results"));
                    for (var i = 0; i < subselect.SelectClause.Length; i++) {
                        var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                        foreachEvent.AssignArrayElement(
                            "results",
                            Constant(i),
                            LocalMethod(
                                eval,
                                REF_EVENTS_SHIFTED,
                                symbols.GetAddIsNewData(method),
                                symbols.GetAddExprEvalCtx(method)));
                    }
                }
                method.Block
                    .IfCondition(ExprDotMethod(Ref("rows"), "IsEmpty"))
                    .BlockReturn(EnumValue(typeof(CollectionUtil), "OBJECTARRAYARRAY_EMPTY"))
                    .MethodReturn(ExprDotMethod(Ref("rows"), "ToArray"));
                return LocalMethod(method);
            }
        }