Example #1
0
 public ExprRegexpNodeForgeNonconstEval(
     ExprRegexpNodeForgeNonconst forge,
     ExprEvaluator lhsEval,
     ExprEvaluator patternEval)
 {
     this.forge = forge;
     this.lhsEval = lhsEval;
     this.patternEval = patternEval;
 }
Example #2
0
        public static CodegenMethod Codegen(
            ExprRegexpNodeForgeNonconst forge,
            ExprNode lhs,
            ExprNode pattern,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(
                typeof(bool?),
                typeof(ExprRegexpNodeForgeNonconstEval),
                codegenClassScope);
            var blockMethod = methodNode.Block
                .DeclareVar<string>(
                    "patternText",
                    pattern.Forge.EvaluateCodegen(typeof(string), methodNode, exprSymbol, codegenClassScope))
                .IfRefNullReturnNull("patternText");

            // initial like-setup
            blockMethod.DeclareVar<Regex>(
                "pattern",
                StaticMethod(
                    typeof(ExprRegexpNodeForgeNonconstEval),
                    "ExprRegexNodeCompilePattern",
                    Ref("patternText")));

            if (!forge.IsNumericValue) {
                blockMethod.DeclareVar<string>(
                        "value",
                        lhs.Forge.EvaluateCodegen(typeof(string), methodNode, exprSymbol, codegenClassScope))
                    .IfRefNullReturnNull("value")
                    .MethodReturn(GetRegexpCode(forge, Ref("pattern"), Ref("value")));
            }
            else {
                blockMethod.DeclareVar<object>(
                        "value",
                        lhs.Forge.EvaluateCodegen(typeof(object), methodNode, exprSymbol, codegenClassScope))
                    .IfRefNullReturnNull("value")
                    .MethodReturn(GetRegexpCode(forge, Ref("pattern"), ExprDotMethod(Ref("value"), "ToString")));
            }

            return methodNode;
        }