Exemplo n.º 1
0
 public EnumAggregateScalarForgeEval(
     EnumAggregateScalarForge forge,
     ExprEvaluator initialization,
     ExprEvaluator innerExpression)
 {
     _forge = forge;
     _initialization = initialization;
     _innerExpression = innerExpression;
 }
Exemplo n.º 2
0
        public static CodegenExpression Codegen(
            EnumAggregateScalarForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var resultTypeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(
                    typeof(ObjectArrayEventType),
                    EventTypeUtility.ResolveTypeCodegen(forge.ResultEventType, EPStatementInitServicesConstants.REF)));
            var evalTypeMember = codegenClassScope.AddDefaultFieldUnshared(
                true,
                typeof(ObjectArrayEventType),
                Cast(
                    typeof(ObjectArrayEventType),
                    EventTypeUtility.ResolveTypeCodegen(forge.EvalEventType, EPStatementInitServicesConstants.REF)));

            var paramTypes = EnumForgeCodegenNames.PARAMS;

            var initializationEvalType = forge.Initialization.EvaluationType.GetBoxedType();
            var innerEvalType = forge.Initialization.EvaluationType;

            var scope = new ExprForgeCodegenSymbol(false, null);
            var methodNode = codegenMethodScope.MakeChildWithScope(
                    initializationEvalType,
                    typeof(EnumAggregateScalarForgeEval),
                    scope,
                    codegenClassScope)
                .AddParam(paramTypes);

            var block = methodNode.Block;
            
            block.DeclareVar(
                    initializationEvalType,
                    "value",
                    forge.Initialization.EvaluateCodegen(
                        initializationEvalType,
                        methodNode,
                        scope,
                        codegenClassScope))
                .IfCondition(ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty"))
                .BlockReturn(Ref("value"));
            
            block.DeclareVar<ObjectArrayEventBean>(
                    "resultEvent",
                    NewInstance<ObjectArrayEventBean>(
                        NewArrayByLength(typeof(object), Constant(1)),
                        resultTypeMember))
                .DeclareVar<ObjectArrayEventBean>(
                    "evalEvent",
                    NewInstance<ObjectArrayEventBean>(
                        NewArrayByLength(typeof(object), Constant(1)),
                        evalTypeMember))
                .AssignArrayElement(
                    EnumForgeCodegenNames.REF_EPS,
                    Constant(forge.StreamNumLambda),
                    Ref("resultEvent"))
                .AssignArrayElement(
                    EnumForgeCodegenNames.REF_EPS,
                    Constant(forge.StreamNumLambda + 1),
                    Ref("evalEvent"))
                .DeclareVar<object[]>(
                    "resultProps",
                    ExprDotName(Ref("resultEvent"), "Properties"))
                .DeclareVar<object[]>(
                    "evalProps",
                    ExprDotName(Ref("evalEvent"), "Properties"));

            block.ForEach(
                    typeof(object),
                    "next",
                    EnumForgeCodegenNames.REF_ENUMCOLL)
                .AssignArrayElement(
                    "resultProps",
                    Constant(0),
                    Ref("value"))
                .AssignArrayElement(
                    "evalProps",
                    Constant(0),
                    Ref("next"))
                .AssignRef(
                    "value",
                    forge.InnerExpression.EvaluateCodegen(
                        innerEvalType,
                        methodNode,
                        scope,
                        codegenClassScope))
                .BlockEnd();
            
            block.MethodReturn(Ref("value"));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }