Example #1
0
        public static CodegenExpression Codegen(
            EnumTakeForge forge,
            EnumForgeCodegenParams args,
            CodegenMethodScope codegenMethodScope,
            CodegenClassScope codegenClassScope)
        {
            var scope = new ExprForgeCodegenSymbol(false, null);
            var returnType = typeof(FlexCollection);
            var paramTypes = EnumForgeCodegenNames.PARAMS;
            var methodNode = codegenMethodScope.MakeChildWithScope(
                    typeof(FlexCollection),
                    typeof(EnumTakeForgeEval),
                    scope,
                    codegenClassScope)
                .AddParam(paramTypes);

            var sizeType = forge.SizeEval.EvaluationType;
            var block = methodNode.Block
                .DebugStack()
                .DeclareVar(
                    sizeType,
                    "size",
                    forge.SizeEval.EvaluateCodegen(sizeType, methodNode, scope, codegenClassScope));
            if (sizeType.CanBeNull()) {
                block.IfRefNullReturnNull("size");
            }

            block.MethodReturn(
                StaticMethod(
                    typeof(EnumTakeForgeEval),
                    "EvaluateEnumTakeMethod",
                    EnumForgeCodegenNames.REF_ENUMCOLL,
                    SimpleNumberCoercerFactory.CoercerInt.CodegenInt(Ref("size"), sizeType)));
            return LocalMethod(methodNode, args.Eps, args.Enumcoll, args.IsNewData, args.ExprCtx);
        }
            public EnumForgeDesc MakeEnumForgeDesc(
                IList<ExprDotEvalParam> bodiesAndParameters,
                int streamCountIncoming,
                StatementCompileTimeServices services)
            {
                ExprForge sizeEval = bodiesAndParameters[0].BodyForge;
                EnumForge forge;
                if (_enumMethod == EnumMethodEnum.TAKE) {
                    forge = new EnumTakeForge(sizeEval, streamCountIncoming, _isScalar);
                }
                else {
                    forge = new EnumTakeLastForge(sizeEval, streamCountIncoming, _isScalar);
                }

                return new EnumForgeDesc(_type, forge);
            }