Пример #1
0
 public EnumAverageDecimalEventsForgeEval(
     EnumAverageDecimalEventsForge forge,
     ExprEvaluator innerExpression)
 {
     _forge = forge;
     _innerExpression = innerExpression;
 }
Пример #2
0
        public static CodegenExpression Codegen(
            EnumAverageDecimalEventsForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var innerType = forge.InnerExpression.EvaluationType;

            CodegenExpression math =
                codegenClassScope.AddOrGetDefaultFieldSharable(new MathContextCodegenField(forge.optionalMathContext));

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

            var block = methodNode.Block;
            block.DeclareVar<AggregatorAvgDecimal>(
                "agg",
                NewInstance<AggregatorAvgDecimal>(math));
            var forEach = block.ForEach(typeof(EventBean), "next", EnumForgeCodegenNames.REF_ENUMCOLL)
                .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(forge.StreamNumLambda), Ref("next"))
                .DeclareVar(
                    innerType,
                    "num",
                    forge.InnerExpression.EvaluateCodegen(innerType, methodNode, scope, codegenClassScope));
            if (innerType.CanBeNull()) {
                forEach.IfRefNull("num").BlockContinue();
            }

            forEach.Expression(ExprDotMethod(Ref("agg"), "Enter", Ref("num")))
                .BlockEnd();
            block.MethodReturn(ExprDotName(Ref("agg"), "Value"));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }