Exemplo n.º 1
0
        public CodegenMethod ProcessCodegen(
            CodegenMethod processMethod,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = processMethod.MakeChild(typeof(object[]), GetType(), codegenClassScope);
            var block = methodNode.Block
                .DeclareVar<object[]>(
                    "parameters",
                    NewArrayByLength(typeof(object), Constant(ExpressionForges.Length)));
            for (var i = 0; i < ExpressionForges.Length; i++) {
                block.AssignArrayElement(
                    "parameters",
                    Constant(i),
                    CodegenLegoMayVoid.ExpressionMayVoid(
                        typeof(object),
                        ExpressionForges[i],
                        methodNode,
                        exprSymbol,
                        codegenClassScope));
            }

            block.MethodReturn(Ref("parameters"));
            return methodNode;
        }
        public CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            CodegenMethod methodNode = codegenMethodScope.MakeChild(
                typeof(EventBean),
                this.GetType(),
                codegenClassScope);
            CodegenBlock block = methodNode.Block
                .DeclareVar<object[]>(
                    "props",
                    NewArrayByLength(typeof(object), Constant(this.context.ExprForges.Length)));
            for (int i = 0; i < this.context.ExprForges.Length; i++) {
                CodegenExpression expression = CodegenLegoMayVoid.ExpressionMayVoid(
                    typeof(object),
                    this.context.ExprForges[i],
                    methodNode,
                    exprSymbol,
                    codegenClassScope);
                block.AssignArrayElement("props", Constant(i), expression);
            }

            block.MethodReturn(
                ExprDotMethod(eventBeanFactory, "AdapterForTypedObjectArray", Ref("props"), resultEventType));
            return methodNode;
        }
Exemplo n.º 3
0
        public CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(
                typeof(EventBean),
                this.GetType(),
                codegenClassScope);
            var codegenPropsRef = Ref("props");

            methodNode.Block.DeclareVar<IDictionary<string, object>>(
                "props",
                NewInstance(typeof(HashMap<string, object>)));
            for (int i = 0; i < selectContext.ColumnNames.Length; i++) {
                var selectContextExprForge = selectContext.ExprForges[i];
                var expression = CodegenLegoMayVoid.ExpressionMayVoid(
                    typeof(object),
                    selectContextExprForge,
                    methodNode,
                    exprSymbol,
                    codegenClassScope);

                var codegenValue = Constant(selectContext.ColumnNames[i]);
                methodNode.Block.Expression(
                    ExprDotMethod(codegenPropsRef, "Put", codegenValue, expression));
            }

            methodNode.Block.MethodReturn(
                ExprDotMethod(eventBeanFactory, "AdapterForTypedMap", Ref("props"), resultEventType));
            return methodNode;
        }
        public override CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var size = ComputeSize();
            var methodNode = codegenMethodScope.MakeChild(typeof(EventBean), GetType(), codegenClassScope);
            var refEPS = exprSymbol.GetAddEPS(methodNode);

            var block = methodNode.Block
                .DeclareVar<object[]>("props", NewArrayByLength(typeof(object), Constant(size)));
            var count = 0;
            foreach (var forge in context.ExprForges) {
                block.AssignArrayElement(
                    Ref("props"),
                    Constant(count),
                    CodegenLegoMayVoid.ExpressionMayVoid(
                        typeof(object),
                        forge,
                        methodNode,
                        exprSymbol,
                        codegenClassScope));
                count++;
            }

            foreach (var element in namedStreams) {
                var theEvent = ArrayAtIndex(refEPS, Constant(element.StreamNumber));
                block.AssignArrayElement(Ref("props"), Constant(count), theEvent);
                count++;
            }

            if (isUsingWildcard && context.NumStreams > 1) {
                for (var i = 0; i < context.NumStreams; i++) {
                    block.AssignArrayElement(Ref("props"), Constant(count), ArrayAtIndex(refEPS, Constant(i)));
                    count++;
                }
            }

            block.MethodReturn(
                ProcessSpecificCodegen(resultEventType, eventBeanFactory, Ref("props"), codegenClassScope));
            return methodNode;
        }
Exemplo n.º 5
0
        public CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            CodegenMethod methodNode = codegenMethodScope.MakeChild(
                typeof(EventBean),
                this.GetType(),
                codegenClassScope);
            CodegenBlock block = methodNode.Block;
            if (this.context.ExprForges.Length == 0) {
                block.DeclareVar<IDictionary<string, object>>(
                    "props", StaticMethod(typeof(Collections), "GetEmptyMap", new[] { typeof(string), typeof(object) }));
            }
            else {
                block.DeclareVar<IDictionary<string, object>>(
                    "props", NewInstance(typeof(HashMap<string, object>)));
            }

            for (int i = 0; i < this.context.ColumnNames.Length; i++) {
                CodegenExpression expression = CodegenLegoMayVoid.ExpressionMayVoid(
                    typeof(object),
                    this.context.ExprForges[i],
                    methodNode,
                    exprSymbol,
                    codegenClassScope);
                block.Expression(
                    ExprDotMethod(Ref("props"), "Put", Constant(this.context.ColumnNames[i]), expression));
            }

            block.MethodReturn(
                ProcessSpecificCodegen(
                    resultEventType,
                    eventBeanFactory,
                    Ref("props"),
                    methodNode,
                    selectSymbol,
                    exprSymbol,
                    codegenClassScope));
            return methodNode;
        }
            public override CodegenMethod ProcessCodegen(
                CodegenExpression resultEventType,
                CodegenExpression eventBeanFactory,
                CodegenMethodScope codegenMethodScope,
                SelectExprProcessorCodegenSymbol selectSymbol,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var methodNode   = codegenMethodScope.MakeChild(typeof(EventBean), GetType(), codegenClassScope);
                var manufacturer = codegenClassScope.AddDefaultFieldUnshared(
                    true,
                    typeof(EventBeanManufacturer),
                    eventManufacturer.Make(methodNode.Block, codegenMethodScope, codegenClassScope));
                var block = methodNode.Block
                            .DeclareVar <object[]>(
                    "values",
                    CodegenExpressionBuilder.NewArrayByLength(
                        typeof(object),
                        CodegenExpressionBuilder.Constant(exprForges.Length)));

                for (var i = 0; i < exprForges.Length; i++)
                {
                    var expression = CodegenLegoMayVoid.ExpressionMayVoid(
                        typeof(object),
                        exprForges[i],
                        methodNode,
                        exprSymbol,
                        codegenClassScope);
                    block.AssignArrayElement("values", CodegenExpressionBuilder.Constant(i), expression);
                }

                block.MethodReturn(
                    CodegenExpressionBuilder.ExprDotMethod(
                        manufacturer,
                        "Make",
                        CodegenExpressionBuilder.Ref("values")));
                return(methodNode);
            }
Exemplo n.º 7
0
        public override CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var size = context.ExprForges.Length +
                       namedStreams.Count +
                       (isUsingWildcard && context.NumStreams > 1 ? context.NumStreams : 0);

            var methodNode = codegenMethodScope.MakeChild(typeof(EventBean), GetType(), codegenClassScope);
            var refEPS = exprSymbol.GetAddEPS(methodNode);
            var refIsNewData = exprSymbol.GetAddIsNewData(methodNode);
            var refExprEvalCtx = exprSymbol.GetAddExprEvalCtx(methodNode);

            var init = size == 0
                ? StaticMethod(typeof(Collections), "GetEmptyMap", new[] { typeof(string), typeof(object) })
                : NewInstance(typeof(HashMap<string, object>));
            var block = methodNode.Block
                .DeclareVar<IDictionary<string, object>>("props", init);
            var count = 0;
            foreach (var forge in context.ExprForges) {
                block.Expression(
                    ExprDotMethod(
                        Ref("props"),
                        "Put",
                        Constant(context.ColumnNames[count]),
                        CodegenLegoMayVoid.ExpressionMayVoid(
                            typeof(object),
                            forge,
                            methodNode,
                            exprSymbol,
                            codegenClassScope)));
                count++;
            }

            foreach (var element in namedStreams) {
                var theEvent = ArrayAtIndex(refEPS, Constant(element.StreamNumber));
                if (element.TableMetadata != null) {
                    var eventToPublic = TableDeployTimeResolver.MakeTableEventToPublicField(
                        element.TableMetadata,
                        codegenClassScope,
                        GetType());
                    theEvent = ExprDotMethod(eventToPublic, "Convert", theEvent, refEPS, refIsNewData, refExprEvalCtx);
                }

                block.Expression(ExprDotMethod(Ref("props"), "Put", Constant(context.ColumnNames[count]), theEvent));
                count++;
            }

            if (isUsingWildcard && context.NumStreams > 1) {
                for (var i = 0; i < context.NumStreams; i++) {
                    block.Expression(
                        ExprDotMethod(
                            Ref("props"),
                            "Put",
                            Constant(context.ColumnNames[count]),
                            ArrayAtIndex(refEPS, Constant(i))));
                    count++;
                }
            }

            block.MethodReturn(
                ProcessSpecificCodegen(
                    resultEventType,
                    eventBeanFactory,
                    Ref("props"),
                    methodNode,
                    exprSymbol,
                    codegenClassScope));
            return methodNode;
        }
Exemplo n.º 8
0
        public CodegenMethod ProcessCodegen(
            CodegenExpression resultEventType,
            CodegenExpression eventBeanFactory,
            CodegenMethodScope codegenMethodScope,
            SelectExprProcessorCodegenSymbol selectSymbol,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(typeof(EventBean), this.GetType(), codegenClassScope);

            methodNode.Block.DeclareVar(_jsonEventType.UnderlyingType, "und", NewInstanceInner(_jsonEventType.Detail.UnderlyingClassName));
            for (var i = 0; i < _selectContext.ColumnNames.Length; i++)
            {
                var columnName        = _selectContext.ColumnNames[i];
                var fieldClassBoxed   = Boxing.GetBoxedType(_jsonEventType.Detail.FieldDescriptors.Get(columnName).PropertyType);
                var propertyType      = _jsonEventType.Types.Get(columnName);
                var evalType          = _selectContext.ExprForges[i].EvaluationType;
                var field             = _jsonEventType.Detail.FieldDescriptors.Get(_selectContext.ColumnNames[i]);
                CodegenExpression rhs = null;

                // handle
                if (evalType == typeof(EventBean))
                {
                    var conversion = methodNode.MakeChild(fieldClassBoxed, this.GetType(), codegenClassScope).AddParam(typeof(object), "value");
                    conversion.Block
                    .IfRefNullReturnNull("value")
                    .MethodReturn(Cast(fieldClassBoxed, ExprDotName(Cast(typeof(EventBean), Ref("value")), "Underlying")));
                    rhs = LocalMethod(
                        conversion,
                        CodegenLegoMayVoid.ExpressionMayVoid(typeof(EventBean), _selectContext.ExprForges[i], methodNode, exprSymbol, codegenClassScope));
                }
                else if (propertyType is Type)
                {
                    rhs = CodegenLegoMayVoid.ExpressionMayVoid(fieldClassBoxed, _selectContext.ExprForges[i], methodNode, exprSymbol, codegenClassScope);
                }
                else if (propertyType is TypeBeanOrUnderlying)
                {
                    var underlyingType = ((TypeBeanOrUnderlying)propertyType).EventType.UnderlyingType;
                    var conversion     = methodNode.MakeChild(underlyingType, this.GetType(), codegenClassScope).AddParam(typeof(object), "value");
                    conversion.Block
                    .IfRefNullReturnNull("value")
                    .IfInstanceOf("value", typeof(EventBean))
                    .BlockReturn(Cast(underlyingType, ExprDotUnderlying(Cast(typeof(EventBean), Ref("value")))))
                    .MethodReturn(Cast(underlyingType, Ref("value")));
                    rhs = LocalMethod(
                        conversion,
                        CodegenLegoMayVoid.ExpressionMayVoid(typeof(object), _selectContext.ExprForges[i], methodNode, exprSymbol, codegenClassScope));
                }
                else if (propertyType is TypeBeanOrUnderlying[])
                {
                    var underlyingType      = ((TypeBeanOrUnderlying[])propertyType)[0].EventType.UnderlyingType;
                    var underlyingArrayType = TypeHelper.GetArrayType(underlyingType);
                    var conversion          = methodNode.MakeChild(underlyingArrayType, this.GetType(), codegenClassScope).AddParam(typeof(object), "value");
                    conversion.Block
                    .IfRefNullReturnNull("value")
                    .IfInstanceOf("value", underlyingArrayType)
                    .BlockReturn(Cast(underlyingArrayType, Ref("value")))
                    .DeclareVar <EventBean[]>("events", Cast(typeof(EventBean[]), Ref("value")))
                    .DeclareVar(underlyingArrayType, "array", NewArrayByLength(underlyingType, ArrayLength(Ref("events"))))
                    .ForLoopIntSimple("i", ArrayLength(Ref("events")))
                    .AssignArrayElement("array", Ref("i"), Cast(underlyingType, ExprDotUnderlying(ArrayAtIndex(Ref("events"), Ref("i")))))
                    .BlockEnd()
                    .MethodReturn(Ref("array"));
                    rhs = LocalMethod(
                        conversion,
                        CodegenLegoMayVoid.ExpressionMayVoid(typeof(object), _selectContext.ExprForges[i], methodNode, exprSymbol, codegenClassScope));
                }
                else if (propertyType == null)
                {
                    methodNode.Block.Expression(
                        CodegenLegoMayVoid.ExpressionMayVoid(typeof(object), _selectContext.ExprForges[i], methodNode, exprSymbol, codegenClassScope));
                }
                else
                {
                    throw new UnsupportedOperationException("Unrecognized property ");
                }

                if (rhs != null)
                {
                    if (field.PropertyType.IsPrimitive)
                    {
                        var tmp = "result_" + i;
                        methodNode.Block
                        .DeclareVar(fieldClassBoxed, tmp, rhs)
                        .IfRefNotNull(tmp)
                        .AssignRef(ExprDotName(Ref("und"), field.FieldName), Unbox(Ref(tmp), fieldClassBoxed))
                        .BlockEnd();
                    }
                    else
                    {
                        methodNode.Block.AssignRef(ExprDotName(Ref("und"), field.FieldName), rhs);
                    }
                }
            }

            methodNode.Block.MethodReturn(ExprDotMethod(eventBeanFactory, "AdapterForTypedJson", Ref("und"), resultEventType));
            return(methodNode);
        }
            public override CodegenMethod ProcessCodegen(
                CodegenExpression resultEventType,
                CodegenExpression eventBeanFactory,
                CodegenMethodScope codegenMethodScope,
                SelectExprProcessorCodegenSymbol selectSymbol,
                ExprForgeCodegenSymbol exprSymbol,
                CodegenClassScope codegenClassScope)
            {
                var methodNode   = codegenMethodScope.MakeChild(typeof(EventBean), GetType(), codegenClassScope);
                var manufacturer = codegenClassScope.AddDefaultFieldUnshared(
                    true,
                    typeof(EventBeanManufacturer),
                    eventManufacturer.Make(methodNode.Block, codegenMethodScope, codegenClassScope));
                var block = methodNode.Block
                            .DeclareVar <object[]>(
                    "values",
                    CodegenExpressionBuilder.NewArrayByLength(
                        typeof(object),
                        CodegenExpressionBuilder.Constant(exprForges.Length)));

                for (var i = 0; i < exprForges.Length; i++)
                {
                    var expression = CodegenLegoMayVoid.ExpressionMayVoid(
                        exprForges[i].EvaluationType,
                        exprForges[i],
                        methodNode,
                        exprSymbol,
                        codegenClassScope);
                    if (wideners[i] == null)
                    {
                        block.AssignArrayElement("values", CodegenExpressionBuilder.Constant(i), expression);
                    }
                    else
                    {
                        var refname = "evalResult" + i;
                        block.DeclareVar(exprForges[i].EvaluationType, refname, expression);
                        if (exprForges[i].EvaluationType.CanBeNull())
                        {
                            block.IfRefNotNull(refname)
                            .AssignArrayElement(
                                "values",
                                CodegenExpressionBuilder.Constant(i),
                                wideners[i]
                                .WidenCodegen(
                                    CodegenExpressionBuilder.Ref(refname),
                                    methodNode,
                                    codegenClassScope))
                            .BlockEnd();
                        }
                        else
                        {
                            block.AssignArrayElement(
                                "values",
                                CodegenExpressionBuilder.Constant(i),
                                wideners[i]
                                .WidenCodegen(
                                    CodegenExpressionBuilder.Ref(refname),
                                    methodNode,
                                    codegenClassScope));
                        }
                    }
                }

                block.MethodReturn(
                    CodegenExpressionBuilder.ExprDotMethod(
                        manufacturer,
                        "Make",
                        CodegenExpressionBuilder.Ref("values")));
                return(methodNode);
            }