Exemple #1
0
        public static void AsDoubleNullReturnNull(
            CodegenBlock block,
            string variable,
            ExprForge forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var type = forge.EvaluationType;
            if (type == typeof(double)) {
                block.DeclareVar(
                    type,
                    variable,
                    forge.EvaluateCodegen(type, codegenMethodScope, exprSymbol, codegenClassScope));
                return;
            }

            string holder = variable + "_";
            block.DeclareVar(
                type,
                holder,
                forge.EvaluateCodegen(type, codegenMethodScope, exprSymbol, codegenClassScope));
            if (type.CanBeNull()) {
                block.IfRefNullReturnNull(holder);
            }

            block.DeclareVar<double>(
                variable,
                SimpleNumberCoercerFactory.CoercerDouble.CodegenDouble(Ref(holder), type));
        }
        private static void CodegenBooleanEval(
            CodegenBlock block,
            string variable,
            bool? preset,
            ExprForge forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            if (preset != null) {
                block.DeclareVar<bool>(variable, Constant(preset));
                return;
            }

            if (forge.EvaluationType == typeof(bool)) {
                block.DeclareVar<bool>(
                    variable,
                    forge.EvaluateCodegen(typeof(bool), codegenMethodScope, exprSymbol, codegenClassScope));
                return;
            }

            var refname = variable + "Obj";
            block.DeclareVar<bool?>(refname, forge.EvaluateCodegen(typeof(bool?), codegenMethodScope, exprSymbol, codegenClassScope))
                .IfRefNullReturnNull(refname)
                .DeclareVar<bool>(variable, Unbox<bool?>(Ref(refname)));
        }
        public static CodegenMethod CodegenExpression(
            ExprForge forge,
            CodegenMethod parent,
            CodegenClassScope classScope,
            bool returnMissingValueAsNull)
        {
            var evaluationType = forge.EvaluationType;
            if (returnMissingValueAsNull) {
                evaluationType = evaluationType.GetBoxedType();
            }
            
            var exprSymbol = new ExprForgeCodegenSymbol(true, null);
            var exprMethod = parent
                .MakeChildWithScope(evaluationType, typeof(CodegenLegoMethodExpression), exprSymbol, classScope)
                .AddParam(ExprForgeCodegenNames.PARAMS);

            exprMethod.Block.DebugStack();
            
            var expression = forge.EvaluateCodegen(evaluationType, exprMethod, exprSymbol, classScope);
            exprSymbol.DerivedSymbolsCodegen(parent, exprMethod.Block, classScope);

            if (evaluationType != typeof(void)) {
                exprMethod.Block.MethodReturn(expression);
                //CodegenLegoCast.CastSafeFromObjectType(evaluationType, expression);
            }
            else {
                exprMethod.Block.Expression(expression);
            }

            return exprMethod;
        }
        private static CodegenMethod CodegenBooleanExpressionBoxedToPrimitive(
            ExprForge forge,
            CodegenMethod parent,
            CodegenClassScope classScope)
        {
            var evaluationType = forge.EvaluationType;
            var exprSymbol = new ExprForgeCodegenSymbol(true, null);
            var exprMethod = parent
                .MakeChildWithScope(typeof(bool), typeof(CodegenLegoMethodExpression), exprSymbol, classScope)
                .AddParam(ExprForgeCodegenNames.PARAMS);

            var expression = forge.EvaluateCodegen(evaluationType, exprMethod, exprSymbol, classScope);
            exprSymbol.DerivedSymbolsCodegen(parent, exprMethod.Block, classScope);

            if (evaluationType.CanNotBeNull()) {
                exprMethod.Block.MethodReturn(expression);
            }
            else {
                exprMethod.Block
                    .DeclareVar(evaluationType, PASS_NAME, expression)
                    .IfRefNull(PASS_NAME)
                    .BlockReturn(ConstantFalse())
                    .MethodReturn(ExprDotName(Ref(PASS_NAME), "Value"));
            }

            return exprMethod;
        }
            public CodegenExpression EvaluateCodegen(
                Type requiredType,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var arrayType = TypeHelper.GetArrayType(componentReturnType);
                var methodNode = codegenMethodScope.MakeChild(
                    arrayType,
                    typeof(InstanceManufacturerForgeArray),
                    codegenClassScope);

                methodNode.Block
                    .DeclareVar<object>(
                        "result",
                        innerForge.EvaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope))
                    .IfCondition(Not(InstanceOf(Ref("result"), typeof(EventBean[]))))
                    .BlockReturn(ConstantNull())
                    .DeclareVar<EventBean[]>("events", Cast(typeof(EventBean[]), Ref("result")))
                    .DeclareVar(arrayType, "values", NewArrayByLength(componentReturnType, ArrayLength(Ref("events"))))
                    .ForLoopIntSimple("i", ArrayLength(Ref("events")))
                    .AssignArrayElement(
                        "values",
                        Ref("i"),
                        Cast(
                            componentReturnType,
                            ExprDotName(ArrayAtIndex(Ref("events"), Ref("i")), "Underlying")))
                    .BlockEnd()
                    .MethodReturn(Ref("values"));
                return LocalMethod(methodNode);
            }
Exemple #6
0
        public static void SortingCode <T>(
            CodegenBlock block,
            Type innerBoxedType,
            ExprForge innerExpression,
            CodegenMethod methodNode,
            ExprForgeCodegenSymbol scope,
            CodegenClassScope codegenClassScope)
        {
            var componentType  = typeof(T);
            var collectionType = typeof(ICollection <>).MakeGenericType(componentType);
            var dequeType      = typeof(ArrayDeque <>).MakeGenericType(componentType);

            block
            .DeclareVar(innerBoxedType, "value", innerExpression.EvaluateCodegen(innerBoxedType, methodNode, scope, codegenClassScope))
            .DeclareVar(collectionType, "entry", ExprDotMethod(Ref("sort"), "Get", Ref("value")))

            .IfCondition(EqualsNull(Ref("entry")))
            .AssignRef("entry", NewInstance(dequeType))
            .ExprDotMethod(Ref("entry"), "Add", Ref("next"))
            .Expression(ExprDotMethod(Ref("sort"), "Put", Ref("value"), Ref("entry")))
            .BlockContinue()

            .ExprDotMethod(Ref("entry"), "Add", Ref("next"))
            .BlockEnd();
        }
Exemple #7
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);
        }
Exemple #8
0
        /// <summary>
        ///     Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            if (invocation.Method == TARGET_EVALUATECODEGEN) {
                var args = invocation.Arguments;
                var evaluationType = forge.EvaluationType;
                var requiredType = (Type) args[args.Length - 4];
                var parent = (CodegenMethodScope) args[args.Length - 3];
                var symbols = (ExprForgeCodegenSymbol) args[args.Length - 2];
                var codegenClassScope = (CodegenClassScope) args[args.Length - 1];

                if (evaluationType == null) {
                    invocation.ReturnValue = forge.EvaluateCodegen(requiredType, parent, symbols, codegenClassScope);
                    return;
                }

                var method = parent.MakeChild(evaluationType, typeof(ExprForgeProxy), codegenClassScope);
                if (evaluationType == typeof(void)) {
                    method.Block
                        .Expression(forge.EvaluateCodegen(requiredType, method, symbols, codegenClassScope))
                        .DebugStack()
                        .Expression(
                            ExprDotMethodChain(symbols.GetAddExprEvalCtx(method))
                                .Get("AuditProvider")
                                .Add("Expression", Constant(expressionToString), Constant("(void)"), symbols.GetAddExprEvalCtx(method)))
                        .MethodEnd();
                }
                else {
                    method.Block
                        .DebugStack()
                        .DeclareVar(
                            evaluationType,
                            "result",
                            forge.EvaluateCodegen(evaluationType, method, symbols, codegenClassScope))
                        .Expression(
                            ExprDotMethodChain(symbols.GetAddExprEvalCtx(method))
                                .Get("AuditProvider")
                                .Add("Expression", Constant(expressionToString), Ref("result"), symbols.GetAddExprEvalCtx(method)))
                        .MethodReturn(Ref("result"));
                }

                invocation.ReturnValue = LocalMethod(method);
                return;
            }

            invocation.ReturnValue = invocation.Method.Invoke(forge, invocation.Arguments);
        }
Exemple #9
0
        public static CodegenExpression ExpressionMayVoid(
            Type requiredType,
            ExprForge forge,
            CodegenMethod parentNode,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            if (forge.EvaluationType != typeof(void)) {
                return forge.EvaluateCodegen(requiredType, parentNode, exprSymbol, codegenClassScope);
            }

            CodegenMethod methodNode = parentNode.MakeChild(
                typeof(object),
                typeof(CodegenLegoMayVoid),
                codegenClassScope);
            methodNode.Block.Expression(forge.EvaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope))
                .MethodReturn(ConstantNull());
            return LocalMethod(methodNode);
        }
Exemple #10
0
 public static CodegenExpression CodegenExpressionMayCoerce(
     ExprForge forge, 
     Type targetType,
     CodegenMethod exprMethod,
     ExprForgeCodegenSymbol exprSymbol,
     CodegenClassScope classScope)
 {
     CodegenExpression expr = forge.EvaluateCodegen(forge.EvaluationType, exprMethod, exprSymbol, classScope);
     return ExprNodeUtilityCodegen.CodegenCoerce(expr, forge.EvaluationType, targetType, false);
 }
Exemple #11
0
        public override CodegenExpression Codegen(
            EnumForgeCodegenParams premade,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var resultTypeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(typeof(ObjectArrayEventType), EventTypeUtility.ResolveTypeCodegen(_resultEventType, EPStatementInitServicesConstants.REF)));

            var scope      = new ExprForgeCodegenSymbol(false, null);
            var methodNode = codegenMethodScope
                             .MakeChildWithScope(typeof(IDictionary <object, object>), typeof(EnumToMapScalar), scope, codegenClassScope)
                             .AddParam(EnumForgeCodegenNames.PARAMS);
            var hasIndex = _numParameters >= 2;
            var hasSize  = _numParameters >= 3;

            var block = methodNode.Block
                        .IfCondition(ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty"))
                        .BlockReturn(EnumValue(typeof(EmptyDictionary <object, object>), "Instance"));

            block.DeclareVar <IDictionary <object, object> >("map", NewInstance(typeof(NullableDictionary <object, object>)))
            .DeclareVar(
                typeof(ObjectArrayEventBean),
                "resultEvent",
                NewInstance(typeof(ObjectArrayEventBean), NewArrayByLength(typeof(object), Constant(_numParameters)), resultTypeMember))
            .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(StreamNumLambda), Ref("resultEvent"))
            .DeclareVar <object[]>("props", ExprDotName(Ref("resultEvent"), "Properties"));
            if (hasIndex)
            {
                block.DeclareVar <int>("count", Constant(-1));
            }

            if (hasSize)
            {
                block.AssignArrayElement(Ref("props"), Constant(2), ExprDotName(REF_ENUMCOLL, "Count"));
            }

            var forEach = block
                          .ForEach(typeof(object), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
                          .AssignArrayElement("props", Constant(0), Ref("next"));

            if (hasIndex)
            {
                forEach.IncrementRef("count").AssignArrayElement("props", Constant(1), Ref("count"));
            }

            forEach
            .DeclareVar <object>("key", InnerExpression.EvaluateCodegen(typeof(object), methodNode, scope, codegenClassScope))
            .DeclareVar <object>("value", _secondExpression.EvaluateCodegen(typeof(object), methodNode, scope, codegenClassScope))
            .Expression(ExprDotMethod(Ref("map"), "Put", Ref("key"), Ref("value")));

            block.MethodReturn(Ref("map"));
            return(LocalMethod(methodNode, premade.Eps, premade.Enumcoll, premade.IsNewData, premade.ExprCtx));
        }
 public CodegenExpression EvaluateCodegen(
     Type requiredType,
     CodegenMethodScope codegenMethodScope,
     ExprForgeCodegenSymbol exprSymbol,
     CodegenClassScope codegenClassScope)
 {
     return _widener.WidenCodegen(
         _forge.EvaluateCodegen(requiredType, codegenMethodScope, exprSymbol, codegenClassScope),
         codegenMethodScope,
         codegenClassScope);
 }
Exemple #13
0
        public CodegenExpression EvaluateCodegenUninstrumented(
            Type requiredType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            ExprForge child = ChildNodes[0].Forge;
            if (child.EvaluationType == typeof(bool)) {
                Not(child.EvaluateCodegen(requiredType, codegenMethodScope, exprSymbol, codegenClassScope));
            }

            CodegenMethod methodNode = codegenMethodScope.MakeChild(
                typeof(bool?),
                typeof(ExprNotNode),
                codegenClassScope);
            methodNode.Block
                .DeclareVar<bool?>("b", child.EvaluateCodegen(typeof(bool?), methodNode, exprSymbol, codegenClassScope))
                .IfRefNullReturnNull("b")
                .MethodReturn(Not(Ref("b")));
            return LocalMethod(methodNode);
        }
Exemple #14
0
 public CodegenExpression EvaluateCodegen(
     Type requiredType,
     CodegenMethodScope codegenMethodScope,
     ExprForgeCodegenSymbol exprSymbol,
     CodegenClassScope codegenClassScope)
 {
     var schema = codegenClassScope.AddOrGetDefaultFieldSharable(new AvroSchemaFieldSharable(_inner));
     return CodegenExpressionBuilder.StaticMethod(
         typeof(SelectExprProcessorEvalAvroMapToAvro),
         "SelectExprProcessAvroMap",
         _forge.EvaluateCodegen(requiredType, codegenMethodScope, exprSymbol, codegenClassScope),
         schema);
 }
        public static CodegenMethod Codegen(
            ExprEqualsNodeForgeNC forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope,
            ExprForge lhs,
            ExprForge rhs)
        {
            var lhsType = lhs.EvaluationType;
            var rhsType = rhs.EvaluationType;

            var methodNode = codegenMethodScope.MakeChild(typeof(bool?), typeof(ExprEqualsNodeForgeNCForgeEquals), codegenClassScope);
            var block = methodNode.Block
                .DeclareVar(lhsType, "left", lhs.EvaluateCodegen(lhsType, methodNode, exprSymbol, codegenClassScope))
                .DeclareVar(rhsType, "right", rhs.EvaluateCodegen(rhsType, methodNode, exprSymbol, codegenClassScope));

            if (!lhsType.IsPrimitive) {
                block.IfRefNullReturnNull("left");
            }

            if (!rhsType.IsPrimitive) {
                block.IfRefNullReturnNull("right");
            }

            CodegenExpression compare;
            if (!lhsType.IsArray) {
                compare = CodegenEqualsNonNullNoCoerce(Ref("left"), lhsType, Ref("right"), rhsType);
            }
            else {
                if (!MultiKeyPlanner.RequiresDeepEquals(lhsType.GetElementType())) {
                    compare = StaticMethod(typeof(Arrays), "AreEqual", Ref("left"), Ref("right"));
                }
                else {
                    compare = StaticMethod(typeof(Arrays), "DeepEquals", Ref("left"), Ref("right"));
                }
            }

            if (!forge.ForgeRenderable.IsNotEquals) {
                block.MethodReturn(compare);
            }
            else {
                block.MethodReturn(Not(compare));
            }

            return methodNode;
        }
Exemple #16
0
        public static void PrefixWithFilterCheck(
            ExprForge filterForge,
            CodegenMethod method,
            ExprForgeCodegenSymbol symbols,
            CodegenClassScope classScope)
        {
            var filterType = filterForge.EvaluationType;
            method.Block.DeclareVar(
                filterType.GetBoxedType(),
                "pass",
                filterForge.EvaluateCodegen(filterType, method, symbols, classScope));
            if (filterType.CanBeNull()) {
                method.Block.IfRefNull("pass").BlockReturnNoValue();
            }

            method.Block.IfCondition(Not(Unbox(Ref("pass")))).BlockReturnNoValue();
        }
Exemple #17
0
            public static CodegenExpression Codegen(
                CodegenExpression input,
                ExprForge dateFormatForge,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope,
                TimeZoneInfo timeZone)
            {
                CodegenExpression timeZoneField =
                    codegenClassScope.AddOrGetDefaultFieldSharable(RuntimeSettingsTimeZoneField.INSTANCE);
                var method = codegenMethodScope.MakeChild(
                    typeof(DateTimeEx),
                    typeof(StringToDateTimeExWExprFormatComputerEval),
                    codegenClassScope)
                             .AddParam(typeof(object), "input");
                CodegenExpression format;

                if (dateFormatForge.ForgeConstantType.IsConstant)
                {
                    format = FormatFieldExpr(typeof(DateFormat), dateFormatForge, codegenClassScope);
                }
                else
                {
                    method.Block
                    .DeclareVar <object>(
                        "format",
                        dateFormatForge.EvaluateCodegen(typeof(object), method, exprSymbol, codegenClassScope))
                    .DeclareVar <DateFormat>(
                        "dateFormat",
                        CodegenExpressionBuilder.StaticMethod(
                            typeof(ExprCastNode),
                            "StringToSimpleDateFormatSafe",
                            CodegenExpressionBuilder.Ref("format")));
                    format = CodegenExpressionBuilder.Ref("dateFormat");
                }

                method.Block.MethodReturn(
                    CodegenExpressionBuilder.StaticMethod(
                        typeof(StringToDateTimExWStaticFormatComputer),
                        "StringToDtxWStaticFormatParse",
                        format,
                        CodegenExpressionBuilder.Ref("input"),
                        timeZoneField));
                return(CodegenExpressionBuilder.LocalMethod(method, input));
            }
            public static CodegenExpression Codegen(
                CodegenExpression input,
                ExprForge dateFormatForge,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var methodNode = codegenMethodScope.MakeChild(
                    typeof(DateTime),
                    typeof(StringToDateTimeWExprFormatComputerEval),
                    codegenClassScope)
                                 .AddParam(typeof(string), "input");
                CodegenExpression format;

                if (dateFormatForge.ForgeConstantType.IsConstant)
                {
                    format = FormatFieldExpr(typeof(DateFormat), dateFormatForge, codegenClassScope);
                }
                else
                {
                    methodNode.Block
                    .DeclareVar <DateFormat>(
                        "formatter",
                        CodegenExpressionBuilder.StaticMethod(
                            typeof(ExprCastNode),
                            "StringToDateTimeFormatterSafe",
                            dateFormatForge.EvaluateCodegen(
                                typeof(object),
                                methodNode,
                                exprSymbol,
                                codegenClassScope)));
                    format = CodegenExpressionBuilder.Ref("formatter");
                }

                methodNode.Block.MethodReturn(
                    CodegenExpressionBuilder.StaticMethod(
                        typeof(StringToDateTimeWStaticFormatComputer),
                        "StringToDateTimeWStaticFormatParse",
                        CodegenExpressionBuilder.Ref("input"),
                        format));
                return(CodegenExpressionBuilder.LocalMethod(methodNode, input));
            }
Exemple #19
0
            public virtual CodegenExpression Codegen(
                CodegenExpression start,
                CodegenExpression end,
                CodegenExpression parameter,
                Type parameterType,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var methodNode = codegenMethodScope
                    .MakeChild(typeof(bool?), typeof(IntervalOpForgeDateWithEndBase), codegenClassScope)
                    .AddParam(typeof(long), "startTs")
                    .AddParam(typeof(long), "endTs")
                    .AddParam(parameterType, "paramStartTs");

                var evaluationType = forgeEndTimestamp.EvaluationType;
                methodNode.Block
                    .DeclareVar(
                        evaluationType,
                        "paramEndTs",
                        forgeEndTimestamp.EvaluateCodegen(
                            evaluationType,
                            methodNode,
                            exprSymbol,
                            codegenClassScope));
                
                if (evaluationType.CanBeNull()) {
                    methodNode.Block.IfRefNullReturnNull("paramEndTs");
                }

                var expression = CodegenEvaluate(
                    Ref("startTs"),
                    Ref("endTs"),
                    Unbox(Ref("paramStartTs"), parameterType),
                    Unbox(Ref("paramEndTs"), evaluationType),
                    methodNode,
                    exprSymbol,
                    codegenClassScope);
                methodNode.Block.MethodReturn(expression);
                
                return LocalMethod(methodNode, start, end, parameter);
            }
        public CodegenExpression EvaluateMatchesCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpression aggService = classScope.NamespaceScope.AddOrGetDefaultFieldWellKnown(
                new CodegenFieldNameSubqueryAgg(subselect.SubselectNumber),
                typeof(AggregationResultFuture));

            var method = parent.MakeChild(typeof(bool), GetType(), classScope);
            var evalCtx = symbols.GetAddExprEvalCtx(method);

            method.Block
                .ApplyTri(new ReturnIfNoMatch(ConstantFalse(), ConstantFalse()), method, symbols)
                .DeclareVar<int>("cpid", ExprDotName(evalCtx, "AgentInstanceId"))
                .DeclareVar<AggregationService>(
                    "aggregationService",
                    ExprDotMethod(aggService, "GetContextPartitionAggregationService", Ref("cpid")))
                .DeclareVar<ICollection<object>>(
                    "groupKeys",
                    ExprDotMethod(Ref("aggregationService"), "GetGroupKeys", evalCtx));
            method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

            var forEach = method.Block.ForEach(typeof(object), "groupKey", Ref("groupKeys"));
            {
                forEach.ExprDotMethod(
                    Ref("aggregationService"),
                    "SetCurrentAccess",
                    Ref("groupKey"),
                    Ref("cpid"),
                    ConstantNull());
                CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                    forEach,
                    havingEval.EvaluationType,
                    havingEval.EvaluateCodegen(havingEval.EvaluationType, method, symbols, classScope));
                forEach.BlockReturn(ConstantTrue());
            }
            method.Block.MethodReturn(ConstantFalse());

            return LocalMethod(method);
        }
            public CodegenExpression EvaluateCodegen(
                Type requiredType,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var methodNode = codegenMethodScope.MakeChild(
                    EvaluationType,
                    typeof(InstanceManufacturerForgeNonArray),
                    codegenClassScope);

                methodNode.Block
                    .DeclareVar<EventBean>(
                        "@event",
                        Cast(
                            typeof(EventBean),
                            innerForge.EvaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope)))
                    .IfRefNullReturnNull("@event")
                    .MethodReturn(Cast(EvaluationType, ExprDotUnderlying(Ref("@event"))));
                return LocalMethod(methodNode);
            }
Exemple #22
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);
        }
Exemple #23
0
        public override CodegenExpression Codegen(
            EnumForgeCodegenParams premade,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var scope      = new ExprForgeCodegenSymbol(false, null);
            var methodNode = codegenMethodScope
                             .MakeChildWithScope(typeof(IDictionary <object, object>), typeof(EnumToMapEvent), scope, codegenClassScope)
                             .AddParam(EnumForgeCodegenNames.PARAMS);

            var block = methodNode.Block
                        .IfCondition(ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty"))
                        .BlockReturn(EnumValue(typeof(EmptyDictionary <object, object>), "Instance"));

            block.DeclareVar(typeof(IDictionary <object, object>), "map", NewInstance(typeof(NullableDictionary <object, object>)));
            block.ForEach(typeof(EventBean), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
            .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(StreamNumLambda), Ref("next"))
            .DeclareVar <object>("key", InnerExpression.EvaluateCodegen(typeof(object), methodNode, scope, codegenClassScope))
            .DeclareVar <object>("value", secondExpression.EvaluateCodegen(typeof(object), methodNode, scope, codegenClassScope))
            .Expression(ExprDotMethod(Ref("map"), "Put", Ref("key"), Ref("value")));
            block.MethodReturn(Ref("map"));
            return(LocalMethod(methodNode, premade.Eps, premade.Enumcoll, premade.IsNewData, premade.ExprCtx));
        }
        public static CodegenMethod Codegen(
            ExprEqualsNodeForgeNC forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope,
            ExprForge lhs,
            ExprForge rhs)
        {
            var lhsType = lhs.EvaluationType;
            var rhsType = rhs.EvaluationType;

            var methodNode = codegenMethodScope.MakeChild(
                typeof(bool?),
                typeof(ExprEqualsNodeForgeNCEvalEquals),
                codegenClassScope);
            var block = methodNode.Block
                .DeclareVar(lhsType, "left", lhs.EvaluateCodegen(lhsType, methodNode, exprSymbol, codegenClassScope))
                .DeclareVar(rhsType, "right", rhs.EvaluateCodegen(rhsType, methodNode, exprSymbol, codegenClassScope));

            if (lhsType.CanBeNull()) {
                block.IfRefNullReturnNull("left");
            }

            if (rhsType.CanBeNull()) {
                block.IfRefNullReturnNull("right");
            }

            var compare = CodegenEqualsNonNullNoCoerce(Ref("left"), lhsType, Ref("right"), rhsType);
            if (!forge.ForgeRenderable.IsNotEquals) {
                block.MethodReturn(compare);
            }
            else {
                block.MethodReturn(Not(compare));
            }

            return methodNode;
        }
        public static CodegenMethod Codegen(
            ExprEqualsNodeForgeNC forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope,
            ExprForge lhs,
            ExprForge rhs)
        {
            var methodNode = codegenMethodScope.MakeChild(
                typeof(bool),
                typeof(ExprEqualsNodeForgeNCEvalIs),
                codegenClassScope);
            var block = methodNode.Block
                .DeclareVar<object>(
                    "left",
                    lhs.EvaluateCodegen(typeof(object), methodNode, exprSymbol, codegenClassScope))
                .DeclareVar<object>(
                    "right",
                    rhs.EvaluateCodegen(typeof(object), methodNode, exprSymbol, codegenClassScope));
            block.DeclareVarNoInit(typeof(bool), "result")
                .IfRefNull("left")
                .AssignRef("result", EqualsNull(Ref("right")))
                .IfElse()
                .AssignRef(
                    "result",
                    And(NotEqualsNull(Ref("right")), StaticMethod<object>("Equals", Ref("left"), Ref("right"))))
                .BlockEnd();
            if (!forge.ForgeRenderable.IsNotEquals) {
                block.MethodReturn(Ref("result"));
            }
            else {
                block.MethodReturn(Not(Ref("result")));
            }

            return methodNode;
        }
Exemple #26
0
 public CodegenMethod ProcessCodegen(
     CodegenExpression resultEventType,
     CodegenExpression eventBeanFactory,
     CodegenMethodScope codegenMethodScope,
     SelectExprProcessorCodegenSymbol selectSymbol,
     ExprForgeCodegenSymbol exprSymbol,
     CodegenClassScope codegenClassScope)
 {
     CodegenMethod methodNode = codegenMethodScope.MakeChild(
         typeof(EventBean),
         this.GetType(),
         codegenClassScope);
     ExprForge first = selectExprForgeContext.ExprForges[0];
     Type evaluationType = first.EvaluationType;
     methodNode.Block.MethodReturn(
         ProcessFirstColCodegen(
             evaluationType,
             first.EvaluateCodegen(evaluationType, methodNode, exprSymbol, codegenClassScope),
             resultEventType,
             eventBeanFactory,
             methodNode,
             codegenClassScope));
     return methodNode;
 }
Exemple #27
0
            public CodegenExpression EvaluateCodegen(
                Type requiredType,
                CodegenMethodScope codegenMethodScope,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var arrayType  = TypeHelper.GetArrayType(componentReturnType);
                var methodNode = codegenMethodScope.MakeChild(arrayType, GetType(), codegenClassScope);

                methodNode.Block
                .DeclareVar <EventBean[]>(
                    "events",
                    CodegenExpressionBuilder.Cast(
                        typeof(EventBean[]),
                        inner.EvaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope)))
                .IfRefNullReturnNull("events")
                .DeclareVar(
                    arrayType,
                    "values",
                    CodegenExpressionBuilder.NewArrayByLength(
                        componentReturnType,
                        CodegenExpressionBuilder.ArrayLength(CodegenExpressionBuilder.Ref("events"))))
                .ForLoopIntSimple("i", CodegenExpressionBuilder.ArrayLength(CodegenExpressionBuilder.Ref("events")))
                .AssignArrayElement(
                    "values",
                    CodegenExpressionBuilder.Ref("i"),
                    CodegenExpressionBuilder.Cast(
                        componentReturnType,
                        CodegenExpressionBuilder.ExprDotUnderlying(
                            CodegenExpressionBuilder.ArrayAtIndex(
                                CodegenExpressionBuilder.Ref("events"),
                                CodegenExpressionBuilder.Ref("i")))))
                .BlockEnd()
                .MethodReturn(CodegenExpressionBuilder.Ref("values"));
                return(CodegenExpressionBuilder.LocalMethod(methodNode));
            }
Exemple #28
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);
        }
Exemple #29
0
        protected override CodegenExpression ProcessSpecificCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenExpression props,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope
                .MakeChild(typeof(EventBean), typeof(SelectEvalStreamWUnderlying), codegenClassScope)
                .AddParam(typeof(IDictionary<string, object>), "props");
            var wrapperUndType = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(EventType),
                EventTypeUtility.ResolveTypeCodegen(
                    wrapperEventType.UnderlyingEventType,
                    EPStatementInitServicesConstants.REF));

            var refEPS = exprSymbol.GetAddEPS(methodNode);
            var refIsNewData = exprSymbol.GetAddIsNewData(methodNode);
            var refExprEvalCtx = exprSymbol.GetAddExprEvalCtx(methodNode);

            var block = methodNode.Block;
            if (singleStreamWrapper) {
                block.DeclareVar<DecoratingEventBean>(
                        "wrapper",
                        Cast(typeof(DecoratingEventBean), ArrayAtIndex(refEPS, Constant(0))))
                    .IfRefNotNull("wrapper")
                    .ExprDotMethod(props, "PutAll", ExprDotName(Ref("wrapper"), "DecoratingProperties"))
                    .BlockEnd();
            }

            if (underlyingIsFragmentEvent) {
                var fragment = ((EventTypeSPI) eventTypes[underlyingStreamNumber])
                    .GetGetterSPI(unnamedStreams[0].StreamSelected.StreamName)
                    .EventBeanFragmentCodegen(
                        Ref("eventBean"),
                        methodNode,
                        codegenClassScope);
                block.DeclareVar<EventBean>("eventBean", ArrayAtIndex(refEPS, Constant(underlyingStreamNumber)))
                    .DeclareVar<EventBean>("theEvent", Cast(typeof(EventBean), fragment));
            }
            else if (underlyingPropertyEventGetter != null) {
                block.DeclareVar<EventBean>("theEvent", ConstantNull())
                    .DeclareVar<object>(
                        "value",
                        underlyingPropertyEventGetter.EventBeanGetCodegen(
                            ArrayAtIndex(refEPS, Constant(underlyingStreamNumber)),
                            methodNode,
                            codegenClassScope))
                    .IfRefNotNull("value")
                    .AssignRef(
                        "theEvent",
                        ExprDotMethod(eventBeanFactory, "AdapterForTypedObject", Ref("value"), wrapperUndType))
                    .BlockEnd();
            }
            else if (underlyingExprForge != null) {
                block.DeclareVar<EventBean>("theEvent", ConstantNull())
                    .DeclareVar<object>(
                        "value",
                        underlyingExprForge.EvaluateCodegen(typeof(object), methodNode, exprSymbol, codegenClassScope))
                    .IfRefNotNull("value")
                    .AssignRef(
                        "theEvent",
                        ExprDotMethod(eventBeanFactory, "AdapterForTypedObject", Ref("value"), wrapperUndType))
                    .BlockEnd();
            }
            else {
                block.DeclareVar<EventBean>("theEvent", ArrayAtIndex(refEPS, Constant(underlyingStreamNumber)));
                if (tableMetadata != null) {
                    var eventToPublic = TableDeployTimeResolver.MakeTableEventToPublicField(
                        tableMetadata,
                        codegenClassScope,
                        GetType());
                    block.IfRefNotNull("theEvent")
                        .AssignRef(
                            "theEvent",
                            ExprDotMethod(
                                eventToPublic,
                                "Convert",
                                Ref("theEvent"),
                                refEPS,
                                refIsNewData,
                                refExprEvalCtx))
                        .BlockEnd();
                }
            }

            block.MethodReturn(
                ExprDotMethod(
                    eventBeanFactory,
                    "AdapterForTypedWrapper",
                    Ref("theEvent"),
                    Ref("props"),
                    resultEventType));
            return LocalMethod(methodNode, props);
        }
Exemple #30
0
        public override CodegenExpression Codegen(
            EnumForgeCodegenParams premade,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var typeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(typeof(ObjectArrayEventType), EventTypeUtility.ResolveTypeCodegen(_eventType, EPStatementInitServicesConstants.REF)));

            var innerType = _innerExpression.EvaluationType;
            var initType  = _initialization.EvaluationType;

            if (initType != innerType && initType.GetBoxedType() == innerType)
            {
                initType = innerType;
            }

            var scope      = new ExprForgeCodegenSymbol(false, null);
            var methodNode = codegenMethodScope
                             .MakeChildWithScope(initType, typeof(EnumAggregateEvent), scope, codegenClassScope)
                             .AddParam(EnumForgeCodegenNames.PARAMS);

            var block = methodNode.Block;

            block
            .DeclareVar(initType, "value", _initialization.EvaluateCodegen(initType, methodNode, scope, codegenClassScope))
            .IfCondition(ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty"))
            .BlockReturn(Ref("value"));
            block
            .DeclareVar <ObjectArrayEventBean>("resultEvent", NewInstance(typeof(ObjectArrayEventBean), NewArrayByLength(typeof(object), Constant(_numParameters - 1)), typeMember))
            .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(StreamNumLambda), Ref("resultEvent"))
            .DeclareVar <object[]>("props", ExprDotName(Ref("resultEvent"), "Properties"));
            if (_numParameters > 3)
            {
                block.AssignArrayElement("props", Constant(2), ExprDotName(EnumForgeCodegenNames.REF_ENUMCOLL, "Count"));
            }

            if (_numParameters > 2)
            {
                block.DeclareVar <int>("count", Constant(-1));
            }

            var forEach = block
                          .ForEach(typeof(EventBean), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
                          .AssignArrayElement("props", Constant(0), Ref("value"));

            if (_numParameters > 2)
            {
                forEach
                .IncrementRef("count")
                .AssignArrayElement("props", Constant(1), Ref("count"));
            }

            var innerCodegen = _innerExpression.EvaluateCodegen(innerType, methodNode, scope, codegenClassScope);

            forEach
            .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(StreamNumLambda + 1), Ref("next"))
            .AssignRef("value", innerCodegen)
            .BlockEnd();

            block.MethodReturn(Ref("value"));
            return(LocalMethod(methodNode, premade.Eps, premade.Enumcoll, premade.IsNewData, premade.ExprCtx));
        }