Exemplo n.º 1
0
        public CodegenExpression EvaluateCodegen(
            Type requiredType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var enumValue = EnumValue(typeof(CronOperatorEnum), CronOperator.GetName());
            var defaultValue = NewInstance<CronParameter>(enumValue, ConstantNull());
            if (ChildNodes.Length == 0) {
                return defaultValue;
            }

            var forge = ChildNodes[0].Forge;
            var evaluationType = forge.EvaluationType;
            var methodNode = codegenMethodScope.MakeChild(
                typeof(CronParameter),
                typeof(ExprNumberSetCronParam),
                codegenClassScope);

            var block = methodNode.Block
                .DeclareVar(
                    evaluationType,
                    "value",
                    forge.EvaluateCodegen(requiredType, methodNode, exprSymbol, codegenClassScope));
            if (evaluationType.CanBeNull()) {
                block.IfRefNull("value")
                    .StaticMethod(typeof(ExprNumberSetCronParam), METHOD_HANDLENUMBERSETCRONPARAMNULLVALUE)
                    .BlockReturn(defaultValue);
            }

            block.MethodReturn(
                NewInstance<CronParameter>(
                    enumValue,
                    SimpleNumberCoercerFactory.CoercerInt.CodegenInt(Ref("value"), evaluationType)));
            return LocalMethod(methodNode);
        }