public EnumAverageEventsForgeEval( EnumAverageEventsForge forge, ExprEvaluator innerExpression) { _forge = forge; _innerExpression = innerExpression; }
public static CodegenExpression Codegen( EnumAverageEventsForge forge, EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var innerType = forge.InnerExpression.EvaluationType; var scope = new ExprForgeCodegenSymbol(false, null); var methodNode = codegenMethodScope.MakeChildWithScope( typeof(double?), typeof(EnumAverageEventsForgeEval), scope, codegenClassScope) .AddParam(EnumForgeCodegenNames.PARAMS); var block = methodNode.Block .DeclareVar<double>("sum", Constant(0d)) .DeclareVar<int>("count", Constant(0)); 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.Increment("count") .AssignRef("sum", Op(Ref("sum"), "+", SimpleNumberCoercerFactory.CoercerDouble.CodegenDouble(Ref("num"), innerType))) .BlockEnd(); block.IfCondition(EqualsIdentity(Ref("count"), Constant(0))) .BlockReturn(ConstantNull()) .MethodReturn(Op(Ref("sum"), "/", Ref("count"))); return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx); }