public EnumAverageScalarLambdaForgeEval( EnumAverageScalarLambdaForge forge, ExprEvaluator innerExpression) { _forge = forge; _innerExpression = innerExpression; }
public static CodegenExpression Codegen( EnumAverageScalarLambdaForge forge, EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var innerType = forge.InnerExpression.EvaluationType; 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( typeof(double?), typeof(EnumAverageEventsForgeEval), scope, codegenClassScope) .AddParam(EnumForgeCodegenNames.PARAMS); var block = methodNode.Block .DeclareVar<double>("sum", Constant(0d)) .DeclareVar<int>("count", Constant(0)) .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( 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); }