Exemplo n.º 1
0
        private static void GenerateInstrumentedProcessView(
            ResultSetProcessorFactoryForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            if (!classScope.IsInstrumented) {
                forge.ProcessViewResultCodegen(classScope, method, instance);
                return;
            }

            var instrumented = method.MakeChild(typeof(UniformPair<EventBean[]>), forge.GetType(), classScope)
                .AddParam(typeof(EventBean[]), NAME_NEWDATA)
                .AddParam(typeof(EventBean[]), NAME_OLDDATA)
                .AddParam(typeof(bool), NAME_ISSYNTHESIZE);
            forge.ProcessViewResultCodegen(classScope, instrumented, instance);

            method.Block
                .DebugStack()
                .Apply(InstrumentationCode.Instblock(classScope, "q" + forge.InstrumentedQName))
                .DeclareVar<UniformPair<EventBean[]>>(
                    "pair",
                    LocalMethod(instrumented, REF_NEWDATA, REF_OLDDATA, REF_ISSYNTHESIZE))
                .Apply(InstrumentationCode.Instblock(classScope, "a" + forge.InstrumentedQName, Ref("pair")))
                .MethodReturn(Ref("pair"));
        }
Exemplo n.º 2
0
        public static CodegenExpression Codegen(
            ExprDotNodeForgeRootChild forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var innerType = forge.innerForge.TypeInfo.GetCodegenReturnType().GetBoxedType();
            var evaluationType = forge.EvaluationType.GetBoxedType();
            var methodNode = codegenMethodScope.MakeChild(
                evaluationType,
                typeof(ExprDotNodeForgeRootChildEval),
                codegenClassScope);

            var innerValue = forge.innerForge.CodegenEvaluate(methodNode, exprSymbol, codegenClassScope);
            if (innerType == typeof(FlexCollection)) {
                innerValue = FlexWrap(innerValue);
            }
            
            var block = methodNode.Block.DeclareVar(innerType, "inner", innerValue);
            if (innerType.CanBeNull() && evaluationType != typeof(void)) {
                block.IfRefNullReturnNull("inner");
            }

            var typeInformation = ConstantNull();
            if (codegenClassScope.IsInstrumented) {
                typeInformation = codegenClassScope.AddOrGetDefaultFieldSharable(
                    new EPTypeCodegenSharable(forge.innerForge.TypeInfo, codegenClassScope));
            }

            block.Apply(
                InstrumentationCode.Instblock(
                    codegenClassScope,
                    "qExprDotChain",
                    typeInformation,
                    Ref("inner"),
                    Constant(forge.forgesUnpacking.Length)));
            var expression = ExprDotNodeUtility.EvaluateChainCodegen(
                methodNode,
                exprSymbol,
                codegenClassScope,
                Ref("inner"),
                innerType,
                forge.forgesUnpacking,
                null);
            if (evaluationType == typeof(void)) {
                block.Expression(expression)
                    .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                    .MethodEnd();
            }
            else {
                block.DeclareVar(evaluationType, "result", expression)
                    .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                    .MethodReturn(Ref("result"));
            }

            return LocalMethod(methodNode);
        }
Exemplo n.º 3
0
        public static CodegenExpression Codegen(
            ExprDotNodeForgeVariable forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope classScope)
        {
            var variableReader =
                classScope.AddOrGetDefaultFieldSharable(new VariableReaderCodegenFieldSharable(forge.Variable));

            Type variableType;
            VariableMetaData metaData = forge.Variable;
            if (metaData.EventType != null) {
                variableType = typeof(EventBean);
            }
            else {
                variableType = metaData.Type;
            }

            CodegenMethod methodNode = codegenMethodScope.MakeChild(
                forge.EvaluationType,
                typeof(ExprDotNodeForgeVariableEval),
                classScope);

            CodegenExpression typeInformation = ConstantNull();
            if (classScope.IsInstrumented) {
                typeInformation = classScope.AddOrGetDefaultFieldSharable(
                    new EPTypeCodegenSharable(new ClassEPType(variableType), classScope));
            }

            CodegenBlock block = methodNode.Block
                .DeclareVar(variableType, "result", Cast(variableType, ExprDotName(variableReader, "Value")))
                .Apply(
                    InstrumentationCode.Instblock(
                        classScope,
                        "qExprDotChain",
                        typeInformation,
                        Ref("result"),
                        Constant(forge.ChainForge.Length)));
            CodegenExpression chain = ExprDotNodeUtility.EvaluateChainCodegen(
                methodNode,
                exprSymbol,
                classScope,
                Ref("result"),
                variableType,
                forge.ChainForge,
                forge.ResultWrapLambda);
            block.DeclareVar(forge.EvaluationType, "returned", chain)
                .Apply(InstrumentationCode.Instblock(classScope, "aExprDotChain"))
                .MethodReturn(Ref("returned"));
            return LocalMethod(methodNode);
        }
Exemplo n.º 4
0
        public static CodegenExpression CodegenEvaluateGetROCollectionScalar(
            ExprDotNodeForgeRootChild forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(
                forge.EvaluationType,
                typeof(ExprDotNodeForgeRootChildEval),
                codegenClassScope);

            var typeInformation = ConstantNull();
            if (codegenClassScope.IsInstrumented) {
                typeInformation = codegenClassScope.AddOrGetDefaultFieldSharable(
                    new EPTypeCodegenSharable(forge.innerForge.TypeInfo, codegenClassScope));
            }

            methodNode.Block
                .DeclareVar<FlexCollection>(
                    "inner",
                    forge.innerForge.EvaluateGetROCollectionScalarCodegen(
                        methodNode,
                        exprSymbol,
                        codegenClassScope))
                .Apply(
                    InstrumentationCode.Instblock(
                        codegenClassScope,
                        "qExprDotChain",
                        typeInformation,
                        Ref("inner"),
                        Constant(forge.forgesUnpacking.Length)))
                .IfRefNull("inner")
                .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                .BlockReturn(ConstantNull())
                .DeclareVar(
                    forge.EvaluationType,
                    "result",
                    ExprDotNodeUtility.EvaluateChainCodegen(
                        methodNode,
                        exprSymbol,
                        codegenClassScope,
                        Ref("inner"),
                        typeof(ICollection<object>),
                        forge.forgesIteratorEventBean,
                        null))
                .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                .MethodReturn(Ref("result"));
            
            return LocalMethod(methodNode);
        }
Exemplo n.º 5
0
        public static CodegenExpression Codegen(
            ExprDotNodeForgeStream forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            CodegenMethod methodNode = codegenMethodScope.MakeChild(
                forge.EvaluationType,
                typeof(ExprDotNodeForgeStreamEvalEventBean),
                codegenClassScope);
            CodegenExpressionRef refEPS = exprSymbol.GetAddEPS(methodNode);

            CodegenExpression typeInformation = ConstantNull();
            if (codegenClassScope.IsInstrumented) {
                typeInformation =
                    codegenClassScope.AddOrGetDefaultFieldSharable(
                        new EPTypeCodegenSharable(EPTypeHelper.SingleEvent(forge.EventType), codegenClassScope));
            }

            methodNode.Block
                .DeclareVar<EventBean>("@event", ArrayAtIndex(refEPS, Constant(forge.StreamNumber)))
                .Apply(
                    InstrumentationCode.Instblock(
                        codegenClassScope,
                        "qExprDotChain",
                        typeInformation,
                        Ref("@event"),
                        Constant(forge.Evaluators.Length)))
                .IfRefNull("@event")
                .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                .BlockReturn(ConstantNull())
                .DeclareVar(
                    forge.EvaluationType,
                    "result",
                    ExprDotNodeUtility.EvaluateChainCodegen(
                        methodNode,
                        exprSymbol,
                        codegenClassScope,
                        Ref("@event"),
                        typeof(EventBean),
                        forge.Evaluators,
                        null))
                .Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                .MethodReturn(Ref("result"));
            return LocalMethod(methodNode);
        }
        public static CodegenExpression CodegenExprEval(
            ExprDotNodeForgeStaticMethod forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            CodegenExpression isCachedMember = null;
            CodegenExpression cachedResultMember = null;
            if (forge.IsConstantParameters) {
                isCachedMember = codegenClassScope.AddDefaultFieldUnshared(false, typeof(bool), ConstantFalse());
                cachedResultMember = codegenClassScope.AddDefaultFieldUnshared(false, typeof(object), ConstantNull());
            }

            var returnType = forge.StaticMethod.ReturnType;

            var methodNode = codegenMethodScope.MakeChild(
                forge.EvaluationType,
                typeof(ExprDotNodeForgeStaticMethodEval),
                codegenClassScope);

            var block = methodNode.Block;

            // check cached
            if (forge.IsConstantParameters) {
                var ifCached = block.IfCondition(isCachedMember);
                if (returnType == typeof(void)) {
                    ifCached.BlockReturnNoValue();
                }
                else {
                    ifCached.BlockReturn(Cast(forge.EvaluationType, cachedResultMember));
                }
            }

            // generate args
            var args = AllArgumentExpressions(
                forge.ChildForges,
                forge.StaticMethod,
                methodNode,
                exprSymbol,
                codegenClassScope);
            AppendArgExpressions(args, methodNode.Block);

            // try block
            var tryBlock = block.TryCatch();
            var invoke = CodegenInvokeExpression(
                forge.TargetObject,
                forge.StaticMethod,
                args,
                codegenClassScope);
            if (returnType == typeof(void)) {
                tryBlock.Expression(invoke);
                if (forge.IsConstantParameters) {
                    tryBlock.AssignRef(isCachedMember, ConstantTrue());
                }

                tryBlock.BlockReturnNoValue();
            }
            else {
                tryBlock.DeclareVar(returnType, "result", invoke);

                if (forge.ChainForges.Length == 0) {
                    var typeInformation = ConstantNull();
                    if (codegenClassScope.IsInstrumented) {
                        typeInformation = codegenClassScope.AddOrGetDefaultFieldSharable(
                            new EPTypeCodegenSharable(new ClassEPType(forge.EvaluationType), codegenClassScope));
                    }

                    tryBlock.Apply(
                        InstrumentationCode.Instblock(
                            codegenClassScope,
                            "qExprDotChain",
                            typeInformation,
                            Ref("result"),
                            Constant(0)));
                    if (forge.IsConstantParameters) {
                        tryBlock.AssignRef(cachedResultMember, Ref("result"));
                        tryBlock.AssignRef(isCachedMember, ConstantTrue());
                    }

                    tryBlock.Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                        .BlockReturn(Ref("result"));
                }
                else {
                    EPType typeInfo;
                    if (forge.ResultWrapLambda != null) {
                        typeInfo = forge.ResultWrapLambda.TypeInfo;
                    }
                    else {
                        typeInfo = new ClassEPType(typeof(object));
                    }

                    var typeInformation = ConstantNull();
                    if (codegenClassScope.IsInstrumented) {
                        typeInformation = codegenClassScope.AddOrGetDefaultFieldSharable(
                            new EPTypeCodegenSharable(typeInfo, codegenClassScope));
                    }

                    tryBlock.Apply(
                            InstrumentationCode.Instblock(
                                codegenClassScope,
                                "qExprDotChain",
                                typeInformation,
                                Ref("result"),
                                Constant(forge.ChainForges.Length)))
                        .DeclareVar(
                            forge.EvaluationType,
                            "chain",
                            ExprDotNodeUtility.EvaluateChainCodegen(
                                methodNode,
                                exprSymbol,
                                codegenClassScope,
                                Ref("result"),
                                returnType,
                                forge.ChainForges,
                                forge.ResultWrapLambda));
                    if (forge.IsConstantParameters) {
                        tryBlock.AssignRef(cachedResultMember, Ref("chain"));
                        tryBlock.AssignRef(isCachedMember, ConstantTrue());
                    }

                    tryBlock.Apply(InstrumentationCode.Instblock(codegenClassScope, "aExprDotChain"))
                        .BlockReturn(Ref("chain"));
                }
            }

            // exception handling
            AppendCatch(
                tryBlock,
                forge.StaticMethod,
                forge.OptionalStatementName,
                forge.ClassOrPropertyName,
                forge.IsRethrowExceptions,
                args);

            // end method
            if (returnType == typeof(void)) {
                block.MethodEnd();
            }
            else {
                block.MethodReturn(ConstantNull());
            }

            return LocalMethod(methodNode);
        }
Exemplo n.º 7
0
        private static CodegenInnerClass MakeSelectExprProcessor(
            string className,
            string classNameParent,
            CodegenClassScope classScope,
            SelectExprProcessorForge forge)
        {
            var exprSymbol = new ExprForgeCodegenSymbol(true, null);
            var selectEnv = new SelectExprProcessorCodegenSymbol();
            CodegenSymbolProvider symbolProvider = new ProxyCodegenSymbolProvider {
                ProcProvide = symbols => {
                    exprSymbol.Provide(symbols);
                    selectEnv.Provide(symbols);
                }
            };

            IList<CodegenTypedParam> members = new List<CodegenTypedParam>(2);
            members.Add(new CodegenTypedParam(classScope.NamespaceScope.FieldsClassName, NAME_STATEMENT_FIELDS));
            members.Add(new CodegenTypedParam(typeof(EventBeanTypedEventFactory), "factory"));

            IList<CodegenTypedParam> ctorParams = new List<CodegenTypedParam>(2);
            ctorParams.Add(new CodegenTypedParam(classNameParent, "o"));
            ctorParams.Add(
                new CodegenTypedParam(
                    typeof(EPStatementInitServices),
                    EPStatementInitServicesConstants.REF.Ref,
                    false));

            var ctor = new CodegenCtor(typeof(StmtClassForgableRSPFactoryProvider), classScope, ctorParams);
            ctor.Block.AssignRef(
                NAME_STATEMENT_FIELDS,
                ExprDotName(Ref("o"), NAME_STATEMENT_FIELDS));
            ctor.Block.AssignRef(
                "factory",
                ExprDotName(EPStatementInitServicesConstants.REF, "EventBeanTypedEventFactory"));

            var processMethod = CodegenMethod.MakeMethod(
                    typeof(EventBean),
                    typeof(StmtClassForgableRSPFactoryProvider),
                    symbolProvider,
                    classScope)
                .AddParam(typeof(EventBean[]), NAME_EPS)
                .AddParam(typeof(bool), ExprForgeCodegenNames.NAME_ISNEWDATA)
                .AddParam(typeof(bool), SelectExprProcessorCodegenSymbol.NAME_ISSYNTHESIZE)
                .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT);

            processMethod.Block.Apply(
                InstrumentationCode.Instblock(
                    classScope,
                    "qSelectClause",
                    REF_EPS,
                    ResultSetProcessorCodegenNames.REF_ISNEWDATA,
                    REF_ISSYNTHESIZE,
                    REF_EXPREVALCONTEXT));
            var performMethod = forge.ProcessCodegen(
                Ref("o." + MEMBERNAME_RESULTEVENTTYPE),
                Ref("factory"),
                processMethod,
                selectEnv,
                exprSymbol,
                classScope);
            exprSymbol.DerivedSymbolsCodegen(processMethod, processMethod.Block, classScope);
            processMethod.Block
                .DeclareVar<EventBean>("@out", LocalMethod(performMethod))
                .Apply(
                    InstrumentationCode.Instblock(
                        classScope,
                        "aSelectClause",
                        ResultSetProcessorCodegenNames.REF_ISNEWDATA,
                        Ref("@out"),
                        ConstantNull()))
                .MethodReturn(Ref("@out"));

            var allProperties = new CodegenClassProperties();
            var allMethods = new CodegenClassMethods();
            CodegenStackGenerator.RecursiveBuildStack(
                processMethod, "Process", allMethods, allProperties);

            return new CodegenInnerClass(
                className,
                typeof(SelectExprProcessor),
                ctor,
                members,
                allMethods,
                allProperties);
        }
Exemplo n.º 8
0
        private CodegenExpression MakeInstrumentationProvider(
            CodegenMethod method,
            CodegenClassScope classScope)
        {
            if (!_instrumented) {
                return ConstantNull();
            }

            var instrumentation = Ref("instrumentation");
            method.Block.AssignRef(instrumentation, NewInstance<ProxyInstrumentationCommon>());
            
            //var anonymousClass = NewAnonymousClass(
            //    method.Block,
            //    typeof(InstrumentationCommon));

            //var activated = CodegenMethod.MakeMethod(typeof(bool), GetType(), classScope);
            //activated.Block.MethodReturn(ConstantTrue());

            method.Block.SetProperty(
                instrumentation,
                "ProcActivated",
                new CodegenExpressionLambda(method.Block)
                    .WithBody(
                        block => block.BlockReturn(
                            ConstantTrue())));

            foreach (var forwarded in typeof(InstrumentationCommon).GetMethods()) {
                if (forwarded.DeclaringType == typeof(object)) {
                    continue;
                }

                if (forwarded.Name == "Activated") {
                    continue;
                }

                IList<CodegenNamedParam> @params = new List<CodegenNamedParam>();
                var forwardedParameters = forwarded.GetParameters();
                var expressions = new CodegenExpression[forwardedParameters.Length];

                var num = 0;
                foreach (var param in forwardedParameters) {
                    @params.Add(new CodegenNamedParam(param.ParameterType, param.Name));
                    expressions[num] = Ref(param.Name);
                    num++;
                }

                //var m = CodegenMethod.MakeMethod(typeof(void), GetType(), classScope)
                //    .AddParam(@params);

                // Now we need a lambda to associate with the instrumentation and tie them together
                var proc = $"Proc{forwarded.Name}";

                method.Block.SetProperty(
                    instrumentation,
                    "ProcActivated",
                    new CodegenExpressionLambda(method.Block)
                        .WithParams(@params)
                        .WithBody(
                            block => block
                                .Apply(
                                    InstrumentationCode.Instblock(
                                        classScope,
                                        forwarded.Name,
                                        expressions))));

                //instrumentation.AddMethod(forwarded.Name, m);
            }

            return instrumentation;
        }