Ejemplo n.º 1
0
        public CodegenExpression Codegen(CodegenExpression inner, Type innerType, CodegenMethodScope parent, ExprForgeCodegenSymbol symbols, CodegenClassScope classScope)
        {
            Type          type   = EPTypeHelper.GetCodegenReturnType(_returnType);
            CodegenMethod method = parent
                                   .MakeChild(type, typeof(ExprDotForgeProperty), classScope)
                                   .AddParam(innerType, "target").AddParam(typeof(int?), "index");

            var arrayExpr = CastSafeFromObjectType(_arrayType, _getter.EventBeanGetCodegen(Cast(typeof(EventBean), Ref("target")), method, classScope));

            method.Block
            .IfNotInstanceOf("target", typeof(EventBean))
            .BlockReturn(ConstantNull())
            .DeclareVar(_arrayType, "array", arrayExpr)
            .IfRefNullReturnNull("index")
            .IfCondition(Relational(Ref("index"), CodegenExpressionRelational.CodegenRelational.GE, ArrayLength(Ref("array"))))
            .BlockThrow(
                NewInstance <EPException>(
                    Concat(
                        Constant("Array length "),
                        ArrayLength(Ref("array")),
                        Constant(" less than index "),
                        Ref("index"),
                        Constant(" for property '" + _propertyName + "'"))))
            .MethodReturn(CastSafeFromObjectType(type, ArrayAtIndex(Ref("array"), ExprDotMethod(Ref("index"), "AsInt32"))));

            return(LocalMethod(method, inner, _indexExpression.Forge.EvaluateCodegen(typeof(int?), method, symbols, classScope)));
        }
        public static CodegenExpression Codegen(
            ExprDotForgeGetCollection forge,
            CodegenExpression inner,
            Type innerType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(
                forge.TypeInfo.GetNormalizedClass(),
                typeof(ExprDotForgeGetCollectionEval),
                codegenClassScope)
                             .AddParam(innerType, "target");

            var block = methodNode.Block;

            if (!innerType.IsPrimitive)
            {
                block.IfRefNullReturnNull("target");
            }

            var targetType = EPTypeHelper.GetCodegenReturnType(forge.TypeInfo);

            block.DeclareVar <int>("index", forge.IndexExpression.EvaluateCodegen(typeof(int), methodNode, exprSymbol, codegenClassScope))
            .MethodReturn(
                CodegenLegoCast.CastSafeFromObjectType(
                    targetType,
                    StaticMethod(
                        typeof(ExprDotForgeGetCollectionEval),
                        "CollectionElementAt",
                        Ref("target"),
                        Ref("index"))));
            return(LocalMethod(methodNode, inner));
        }
Ejemplo n.º 3
0
        public override CodegenExpression Codegen(
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var innerTypeBoxed = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(_resultType));

            var paramTypes = EnumForgeCodegenNames.PARAMS;
            var block = codegenMethodScope
                .MakeChild(innerTypeBoxed, typeof(EnumMinMaxEventsForgeEval), codegenClassScope)
                .AddParam(paramTypes)
                .Block
                .DeclareVar(innerTypeBoxed, "minKey", ConstantNull());

            var forEach = block.ForEach(typeof(object), "value", EnumForgeCodegenNames.REF_ENUMCOLL)
                .IfRefNull("value")
                .BlockContinue();

            forEach.IfCondition(EqualsNull(Ref("minKey")))
                .AssignRef("minKey", Cast(innerTypeBoxed, Ref("value")))
                .IfElse()
                .IfCondition(
                    Relational(ExprDotMethod(Unbox(Ref("minKey"), innerTypeBoxed), "CompareTo", Ref("value")), _max ? LT : GT, Constant(0)))
                .AssignRef("minKey", Cast(innerTypeBoxed, Ref("value")));

            var method = block.MethodReturn(Ref("minKey"));
            return LocalMethod(method, args.Expressions);
        }
Ejemplo n.º 4
0
        public static CodegenExpression Codegen(
            EnumMinMaxByScalarLambdaForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var innerType = forge.InnerExpression.EvaluationType;
            var innerTypeBoxed = Boxing.GetBoxedType(innerType);
            var resultTypeBoxed = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(forge.resultType));
            var resultTypeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(
                    typeof(ObjectArrayEventType),
                    EventTypeUtility.ResolveTypeCodegen(forge.resultEventType, EPStatementInitServicesConstants.REF)));

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

            var block = methodNode.Block
                .DeclareVar(innerTypeBoxed, "minKey", ConstantNull())
                .DeclareVar(resultTypeBoxed, "result", ConstantNull())
                .DeclareVar<ObjectArrayEventBean>(
                    "resultEvent",
                    NewInstance<ObjectArrayEventBean>(NewArrayByLength(typeof(object), Constant(1)), resultTypeMember))
                .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(forge.StreamNumLambda), Ref("resultEvent"))
                .DeclareVar<object[]>("props", ExprDotName(Ref("resultEvent"), "Properties"));

            var forEach = block.ForEach(typeof(object), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
                .AssignArrayElement("props", Constant(0), Ref("next"))
                .DeclareVar(
                    innerTypeBoxed,
                    "value",
                    forge.InnerExpression.EvaluateCodegen(innerTypeBoxed, methodNode, scope, codegenClassScope))
                .IfRefNull("value")
                .BlockContinue();

            forEach.IfCondition(EqualsNull(Ref("minKey")))
                .AssignRef("minKey", Ref("value"))
                .AssignRef("result", Cast(resultTypeBoxed, Ref("next")))
                .IfElse()
                .IfCondition(
                    Relational(
                        ExprDotMethod(Unbox(Ref("minKey"), innerTypeBoxed), "CompareTo", Ref("value")),
                        forge.max ? LT : GT,
                        Constant(0)))
                .AssignRef("minKey", Ref("value"))
                .AssignRef("result", Cast(resultTypeBoxed, Ref("next")));

            block.MethodReturn(Ref("result"));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }
Ejemplo n.º 5
0
 public EnumMinMaxByScalar(
     ExprDotEvalParamLambda lambda,
     ObjectArrayEventType fieldEventType,
     int numParameters,
     bool max,
     EPType resultType) : base(lambda, fieldEventType, numParameters)
 {
     this._max             = max;
     this._resultType      = resultType;
     this._innerTypeBoxed  = Boxing.GetBoxedType(InnerExpression.EvaluationType);
     this._resultTypeBoxed = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(resultType));
 }
Ejemplo n.º 6
0
        public CodegenExpression Codegen(
            CodegenExpression inner,
            Type innerType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            Type resultType = EPTypeHelper.GetCodegenReturnType(returnType);
            CodegenMethod methodNode = codegenMethodScope
                .MakeChild(resultType, typeof(ExprDotForgeUnpackBean), codegenClassScope)
                .AddParam(innerType, "target");

            methodNode.Block
                .IfRefNullReturnNull("target")
                .MethodReturn(Cast(resultType, ExprDotUnderlying(Cast(typeof(EventBean), Ref("target")))));
            return LocalMethod(methodNode, inner);
        }
Ejemplo n.º 7
0
 public override CodegenExpression Codegen(
     EnumForgeCodegenParams args,
     CodegenMethodScope codegenMethodScope,
     CodegenClassScope codegenClassScope)
 {
     var type = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(_resultType));
     var paramTypes = EnumForgeCodegenNames.PARAMS;
     
     var method = codegenMethodScope
         .MakeChild(type, typeof(EnumLastOfNoPredicateForge), codegenClassScope)
         .AddParam(paramTypes)
         .Block
         .DeclareVar<object>("result", ConstantNull())
         .ForEach(typeof(object), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
         .AssignRef("result", Ref("next"))
         .BlockEnd()
         .MethodReturn(Cast(type, Ref("result")));
     return LocalMethod(method, args.Expressions);
 }
Ejemplo n.º 8
0
 public override CodegenExpression Codegen(
     EnumForgeCodegenParams args,
     CodegenMethodScope codegenMethodScope,
     CodegenClassScope codegenClassScope)
 {
     var type = EPTypeHelper.GetCodegenReturnType(_resultType);
     var paramTypes = EnumForgeCodegenNames.PARAMS;
     
     var method = codegenMethodScope
         .MakeChild(type, typeof(EnumFirstOfNoPredicateForge), codegenClassScope)
         .AddParam(paramTypes)
         .Block
         .IfCondition(
             Or(
                 EqualsNull(EnumForgeCodegenNames.REF_ENUMCOLL),
                 ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty")))
         .BlockReturn(ConstantNull())
         .MethodReturn(
             Cast(type, ExprDotMethodChain(EnumForgeCodegenNames.REF_ENUMCOLL).Add("First")));
     return LocalMethod(method, args.Expressions);
 }
Ejemplo n.º 9
0
        public static CodegenExpression Codegen(
            EnumLastOfPredicateScalarForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var typeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(
                    typeof(ObjectArrayEventType),
                    EventTypeUtility.ResolveTypeCodegen(forge.type, EPStatementInitServicesConstants.REF)));

            var resultType = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(forge.resultType));
            var paramsType = EnumForgeCodegenNames.PARAMS;
            var scope = new ExprForgeCodegenSymbol(false, null);
            
            var methodNode = codegenMethodScope
                .MakeChildWithScope(resultType, typeof(EnumLastOfPredicateScalarForgeEval), scope, codegenClassScope)
                .AddParam(paramsType);

            CodegenBlock block;
            block = methodNode.Block
                .DeclareVar<object>("result", ConstantNull())
                .DeclareVar<ObjectArrayEventBean>(
                    "evalEvent",
                    NewInstance<ObjectArrayEventBean>(NewArrayByLength(typeof(object), Constant(1)), typeMember))
                .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(forge.StreamNumLambda), Ref("evalEvent"))
                .DeclareVar<object[]>("props", ExprDotName(Ref("evalEvent"), "Properties"));
            var forEach = block
                .ForEach(typeof(object), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
                .AssignArrayElement("props", Constant(0), Ref("next"));
            CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                forEach,
                forge.InnerExpression.EvaluationType,
                forge.InnerExpression.EvaluateCodegen(typeof(bool?), methodNode, scope, codegenClassScope));
            forEach.AssignRef("result", Ref("next"));
            block.MethodReturn(Cast(resultType, Ref("result")));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }
Ejemplo n.º 10
0
        public CodegenExpression Codegen(
            CodegenExpression inner,
            Type innerType,
            CodegenMethodScope parent,
            ExprForgeCodegenSymbol symbols,
            CodegenClassScope classScope)
        {
            var type = EPTypeHelper.GetCodegenReturnType(_returnType);

            if (innerType == typeof(EventBean))
            {
                return(CodegenLegoCast.CastSafeFromObjectType(type, _getter.EventBeanFragmentCodegen(inner, parent, classScope)));
            }

            var methodNode = parent.MakeChild(type, typeof(ExprDotForgePropertyFragment), classScope).AddParam(innerType, "target");

            methodNode.Block
            .IfInstanceOf("target", typeof(EventBean))
            .BlockReturn(
                CodegenLegoCast.CastSafeFromObjectType(type, _getter.EventBeanFragmentCodegen(Cast(typeof(EventBean), inner), methodNode, classScope)))
            .MethodReturn(ConstantNull());
            return(LocalMethod(methodNode, inner));
        }
Ejemplo n.º 11
0
        public override CodegenExpression Codegen(
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            Type innerTypeBoxed = Boxing.GetBoxedType(EPTypeHelper.GetCodegenReturnType(_resultType));

            CodegenBlock block = codegenMethodScope
                                 .MakeChild(innerTypeBoxed, typeof(EnumMinMaxScalarNoParam), codegenClassScope)
                                 .AddParam(EnumForgeCodegenNames.PARAMS)
                                 .Block
                                 .DeclareVar(innerTypeBoxed, "minKey", ConstantNull());

            CodegenBlock forEach = block
                                   .ForEach(innerTypeBoxed, "value", EnumForgeCodegenNames.REF_ENUMCOLL)
                                   .IfRefNull("value")
                                   .BlockContinue();

            var compareTo =
                StaticMethod(
                    typeof(SmartCompare),
                    "Compare",
                    Ref("minKey"),
                    Ref("value"));

            forEach
            .IfCondition(EqualsNull(Ref("minKey")))
            .AssignRef("minKey", FlexCast(innerTypeBoxed, Ref("value")))
            .IfElse()
            .IfCondition(Relational(compareTo, _max ? LT : GT, Constant(0)))
            .AssignRef("minKey", FlexCast(innerTypeBoxed, Ref("value")));

            CodegenMethod method = block.MethodReturn(Ref("minKey"));

            return(LocalMethod(method, args.Expressions));
        }
Ejemplo n.º 12
0
        public static CodegenExpression Codegen(
            ExprDotForgeEnumMethodBase forge,
            CodegenExpression inner,
            Type innerType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var returnType = EPTypeHelper.GetCodegenReturnType(forge.TypeInfo);
            var methodNode = codegenMethodScope
                .MakeChild(returnType, typeof(ExprDotForgeEnumMethodEval), codegenClassScope)
                .AddParam(innerType, "param");

            methodNode.Block.DebugStack();

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

            var forgeMember = codegenClassScope.AddDefaultFieldUnshared(
                true, typeof(object), NewInstance(typeof(object)));
            var block = methodNode.Block;

            //block.Debug("param: {0}", ExprDotMethod(Ref("param"), "RenderAny"));

            if (innerType == typeof(EventBean)) {
                block.DeclareVar<FlexCollection>("coll", FlexEvent(Ref("param")));
            }
            else if (innerType == typeof(object[])) {
                block.DeclareVar<FlexCollection>("coll", FlexWrap(Ref("param")));
            }
            else if (innerType.IsGenericCollection()) {
                block.DeclareVar(innerType, "coll", Ref("param"));
            }
            else {
                throw new IllegalStateException("invalid type presented for unwrapping");
            }

            block.DeclareVar<ExpressionResultCacheForEnumerationMethod>(
                "cache",
                ExprDotMethodChain(refExprEvalCtx)
                    .Get("ExpressionResultCacheService")
                    .Get("AllocateEnumerationMethod"));
            
            var premade = new EnumForgeCodegenParams(
                Ref("eventsLambda"),
                Ref("coll"),
                innerType,
                refIsNewData,
                refExprEvalCtx);
            
            if (forge.IsCache) {
                block
                    .DeclareVar<ExpressionResultCacheEntryLongArrayAndObj>(
                        "cacheValue",
                        ExprDotMethod(Ref("cache"), "GetEnumerationMethodLastValue", forgeMember))
                    .IfCondition(NotEqualsNull(Ref("cacheValue")))
                    .BlockReturn(Cast(returnType, ExprDotName(Ref("cacheValue"), "Result")))
                    .IfRefNullReturnNull("coll")
                    .DeclareVar<EventBean[]>(
                        "eventsLambda",
                        StaticMethod(
                            typeof(ExprDotForgeEnumMethodEval),
                            "AllocateCopyEventLambda",
                            refEPS,
                            Constant(forge.EnumEvalNumRequiredEvents)))
                    .DeclareVar(
                        EPTypeHelper.GetCodegenReturnType(forge.TypeInfo),
                        "result",
                        forge.EnumForge.Codegen(premade, methodNode, codegenClassScope))
                    .Expression(
                        ExprDotMethod(Ref("cache"), "SaveEnumerationMethodLastValue", forgeMember, Ref("result")))
                    .MethodReturn(Ref("result"));
            }
            else {
                var contextNumberMember = codegenClassScope.AddDefaultFieldUnshared(
                    true,
                    typeof(AtomicLong),
                    NewInstance(typeof(AtomicLong)));

                var returnInvocation = forge.EnumForge.Codegen(premade, methodNode, codegenClassScope);
                
                block
                    .DeclareVar<long>("contextNumber", ExprDotMethod(contextNumberMember, "GetAndIncrement"))
                    .TryCatch()
                    .Expression(ExprDotMethod(Ref("cache"), "PushContext", Ref("contextNumber")))
                    .IfRefNullReturnNull("coll")
                    .DeclareVar<EventBean[]>(
                        "eventsLambda",
                        StaticMethod(
                            typeof(ExprDotForgeEnumMethodEval),
                            "AllocateCopyEventLambda",
                            refEPS,
                            Constant(forge.EnumEvalNumRequiredEvents)))
                    .TryReturn(CodegenLegoCast.CastSafeFromObjectType(returnType, returnInvocation))
                    .TryFinally()
                    .Expression(ExprDotMethod(Ref("cache"), "PopContext"))
                    .BlockEnd()
                    .MethodEnd();
            }

            return LocalMethod(methodNode, inner);
        }
Ejemplo n.º 13
0
        public static CodegenExpression EvaluateChainCodegen(
            CodegenMethod parent,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope,
            CodegenExpression inner,
            Type innerType,
            ExprDotForge[] forges,
            ExprDotStaticMethodWrap optionalResultWrapLambda)
        {
            if (forges.Length == 0) {
                return inner;
            }

            var last = forges[forges.Length - 1];
            var lastType = EPTypeHelper.GetCodegenReturnType(last.TypeInfo).GetBoxedType();
            var methodNode = parent
                .MakeChild(lastType, typeof(ExprDotNodeUtility), codegenClassScope)
                .AddParam(innerType, "inner");

            var block = methodNode.Block.DebugStack();

            var currentTarget = "wrapped";
            Type currentTargetType;
            if (optionalResultWrapLambda != null) {
                currentTargetType = EPTypeHelper.GetCodegenReturnType(optionalResultWrapLambda.TypeInfo);

                var wrapped = optionalResultWrapLambda.CodegenConvertNonNull(Ref("inner"), methodNode, codegenClassScope);
                if (currentTargetType == typeof(FlexCollection)) {
                    wrapped = FlexWrap(wrapped);
                }
                
                block
                    .IfRefNullReturnNull("inner")
                    .DeclareVar(currentTargetType, "wrapped", wrapped);
            }
            else if (innerType == typeof(FlexCollection)) {
                block.DeclareVar(innerType, "wrapped", FlexWrap(Ref("inner")));
                currentTargetType = innerType;
            }
            else {
                block.DeclareVar(innerType, "wrapped", Ref("inner"));
                currentTargetType = innerType;
            }

            string refname = null;
            var instrumentationName = new ExprDotEvalVisitorImpl();
            for (var i = 0; i < forges.Length; i++) {
                refname = "r" + i;
                forges[i].Visit(instrumentationName);
                block.Apply(
                    Instblock(
                        codegenClassScope,
                        "qExprDotChainElement",
                        Constant(i),
                        Constant(instrumentationName.MethodType),
                        Constant(instrumentationName.MethodName)));

                var typeInformation = ConstantNull();
                if (codegenClassScope.IsInstrumented) {
                    typeInformation = codegenClassScope.AddOrGetDefaultFieldSharable(
                        new EPTypeCodegenSharable(forges[i].TypeInfo, codegenClassScope));
                }

                var reftype = forges[i].TypeInfo.GetCodegenReturnType().GetBoxedType();
                if (reftype == typeof(void)) {
                    block.Expression(
                            forges[i]
                                .Codegen(
                                    Ref(currentTarget),
                                    currentTargetType,
                                    methodNode,
                                    exprSymbol,
                                    codegenClassScope))
                        .Apply(Instblock(codegenClassScope, "aExprDotChainElement", typeInformation, ConstantNull()));
                }
                else {
                    var invocation = forges[i]
                        .Codegen(
                            Ref(currentTarget),
                            currentTargetType,
                            methodNode,
                            exprSymbol,
                            codegenClassScope);

                    // We can't assume anything about the return type.  Unfortunately, we do not know the resultant type
                    // of the forge... I must fix this. - TBD
                    invocation = CodegenLegoCast.CastSafeFromObjectType(reftype, invocation);
                    
                    block.DeclareVar(reftype, refname, invocation);
                    currentTarget = refname;
                    currentTargetType = reftype;
                    if (reftype.CanBeNull()) {
                        block.IfRefNull(refname)
                            .Apply(
                                Instblock(codegenClassScope, "aExprDotChainElement", typeInformation, ConstantNull()))
                            .BlockReturn(ConstantNull());
                    }

                    block.Apply(Instblock(codegenClassScope, "aExprDotChainElement", typeInformation, Ref(refname)));
                }
            }

            if (lastType == typeof(void)) {
                block.MethodEnd();
            }
            else {
                block.MethodReturn(Ref(refname));
            }

            return LocalMethod(methodNode, inner);
        }