Ejemplo n.º 1
0
 public EnumUnionForgeEval(
     EnumUnionForge forge,
     ExprEnumerationEval evaluator,
     bool scalar)
 {
     _forge = forge;
     _evaluator = evaluator;
     this.scalar = scalar;
 }
Ejemplo n.º 2
0
        public static CodegenExpression Codegen(
            EnumUnionForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var namedParams = EnumForgeCodegenNames.PARAMS;
            var returnType = typeof(FlexCollection);
            var listType = forge.scalar
                ? typeof(List<object>)
                : typeof(List<EventBean>);
            var subProperty = forge.scalar
                ? "ObjectCollection"
                : "EventBeanCollection";
            
            var scope = new ExprForgeCodegenSymbol(false, null);
            var methodNode = codegenMethodScope
                .MakeChildWithScope(returnType, typeof(EnumUnionForgeEval), scope, codegenClassScope)
                .AddParam(namedParams);

            var block = methodNode.Block;
            if (forge.scalar) {
                block.DeclareVar<FlexCollection>(
                    "other",
                    forge.evaluatorForge.EvaluateGetROCollectionScalarCodegen(methodNode, scope, codegenClassScope));
            }
            else {
                block.DeclareVar<FlexCollection>(
                    "other",
                    forge.evaluatorForge.EvaluateGetROCollectionEventsCodegen(methodNode, scope, codegenClassScope));
            }

            block.IfCondition(Or(EqualsNull(Ref("other")), ExprDotMethod(Ref("other"), "IsEmpty")))
                .BlockReturn(EnumForgeCodegenNames.REF_ENUMCOLL);
            block
                .DebugStack()
                .DeclareVar(listType, "result", NewInstance(listType))
                .Expression(ExprDotMethod(Ref("result"), "AddAll", 
                    ExprDotName(EnumForgeCodegenNames.REF_ENUMCOLL, subProperty)))
                .Expression(ExprDotMethod(Ref("result"), "AddAll",
                    ExprDotName(Ref("other"), subProperty)))
                .MethodReturn(FlexWrap(Ref("result")));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }