Ejemplo n.º 1
0
        public static CodegenMethod ComputeMultiKeyCodegen(
            int idNumber,
            ExprForge[] partitionForges,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            var exprSymbol = new ExprForgeCodegenSymbol(true, null);
            Consumer<CodegenMethod> code = method => {
                if (partitionForges.Length == 1) {
                    CodegenExpression expression = partitionForges[0]
                        .EvaluateCodegen(
                            typeof(object),
                            method,
                            exprSymbol,
                            classScope);
                    exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope);
                    method.Block.MethodReturn(expression);
                }
                else {
                    var expressions = new CodegenExpression[partitionForges.Length];
                    for (var i = 0; i < partitionForges.Length; i++) {
                        expressions[i] = partitionForges[i]
                            .EvaluateCodegen(
                                typeof(object),
                                method,
                                exprSymbol,
                                classScope);
                    }

                    exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope);
                    method.Block.DeclareVar<object[]>(
                        "keys",
                        NewArrayByLength(typeof(object), Constant(partitionForges.Length)));
                    for (var i = 0; i < expressions.Length; i++) {
                        method.Block.AssignArrayElement("keys", Constant(i), expressions[i]);
                    }

                    method.Block.MethodReturn(NewInstance<HashableMultiKey>(Ref("keys")));
                }
            };

            return namedMethods.AddMethodWithSymbols(
                typeof(object),
                "ComputeKeyArrayCodegen_" + idNumber,
                CodegenNamedParam.From(
                    typeof(EventBean[]),
                    NAME_EPS,
                    typeof(bool),
                    NAME_ISNEWDATA,
                    typeof(ExprEvaluatorContext),
                    NAME_EXPREVALCONTEXT),
                typeof(AggregationServiceCodegenUtil),
                classScope,
                code,
                exprSymbol);
        }
        public static CodegenMethod ComputeMultiKeyCodegen(
            int idNumber,
            ExprNode[] partitionForges,
            MultiKeyClassRef optionalMultiKey,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            var exprSymbol = new ExprForgeCodegenSymbol(true, null);
            Consumer<CodegenMethod> code = method => {
                if (optionalMultiKey == null || optionalMultiKey.ClassNameMK == null) {
                    var expression = partitionForges[0].Forge.EvaluateCodegen(typeof(object), method, exprSymbol, classScope);
                    exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope);
                    method.Block.MethodReturn(expression);
                    return;
                }
                
                var expressions = new CodegenExpression[partitionForges.Length];
                for (var i = 0; i < partitionForges.Length; i++) {
                    expressions[i] = partitionForges[i].Forge
                        .EvaluateCodegen(
                            typeof(object),
                            method,
                            exprSymbol,
                            classScope);
                }

                var instance = optionalMultiKey.ClassNameMK.Type != null
                    ? NewInstance(optionalMultiKey.ClassNameMK.Type, expressions)
                    : NewInstanceInner(optionalMultiKey.ClassNameMK.Name, expressions);

                exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope);
                method.Block.MethodReturn(instance);
            };

            return namedMethods.AddMethodWithSymbols(
                typeof(object),
                "ComputeKeyArrayCodegen_" + idNumber,
                CodegenNamedParam.From(
                    typeof(EventBean[]),
                    NAME_EPS,
                    typeof(bool),
                    NAME_ISNEWDATA,
                    typeof(ExprEvaluatorContext),
                    NAME_EXPREVALCONTEXT),
                typeof(AggregationServiceCodegenUtil),
                classScope,
                code,
                exprSymbol);
        }