public EnumMostLeastFrequentEventForgeEval( EnumMostLeastFrequentEventForge forge, ExprEvaluator innerExpression) { this.forge = forge; this.innerExpression = innerExpression; }
public static CodegenExpression Codegen( EnumMostLeastFrequentEventForge forge, EnumForgeCodegenParams args, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var returnType = Boxing.GetBoxedType(forge.InnerExpression.EvaluationType); var scope = new ExprForgeCodegenSymbol(false, null); var methodNode = codegenMethodScope.MakeChildWithScope( returnType, typeof(EnumMostLeastFrequentEventForgeEval), scope, codegenClassScope) .AddParam(EnumForgeCodegenNames.PARAMS); var block = methodNode.Block .IfCondition(ExprDotMethod(EnumForgeCodegenNames.REF_ENUMCOLL, "IsEmpty")) .BlockReturn(ConstantNull()) .DeclareVar<IDictionary<object, int>>( "items", NewInstance(typeof(HashMap<object, int>))); var forEach = block .ForEach(typeof(EventBean), "next", EnumForgeCodegenNames.REF_ENUMCOLL) .AssignArrayElement(EnumForgeCodegenNames.REF_EPS, Constant(forge.StreamNumLambda), Ref("next")) .DeclareVar<object>( // type erasure issue "item", forge.InnerExpression.EvaluateCodegen(typeof(object), methodNode, scope, codegenClassScope)) .DeclareVar<int?>( "existing", ExprDotMethod(Ref("items"), "GetBoxed", Ref("item"))) .IfCondition(EqualsNull(Ref("existing"))) .AssignRef("existing", Constant(1)) .IfElse() .Increment("existing") .BlockEnd() .ExprDotMethod(Ref("items"), "Put", Ref("item"), Unbox(Ref("existing"))); block.MethodReturn( Cast( returnType, StaticMethod( typeof(EnumMostLeastFrequentEventForgeEval), "GetEnumMostLeastFrequentResult", Ref("items"), Constant(forge.isMostFrequent)))); return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx); }