public ExprLikeNodeFormNonconstEval( ExprLikeNodeForgeNonconst forge, ExprEvaluator lhsEval, ExprEvaluator patternEval, ExprEvaluator optionalEscapeEval) { _form = forge; this._lhsEval = lhsEval; this._patternEval = patternEval; this._optionalEscapeEval = optionalEscapeEval; }
public static CodegenMethod Codegen( ExprLikeNodeForgeNonconst forge, ExprNode lhs, ExprNode pattern, ExprNode optionalEscape, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { var methodNode = codegenMethodScope.MakeChild( typeof(bool?), typeof(ExprLikeNodeFormNonconstEval), codegenClassScope); var blockMethod = methodNode.Block .DeclareVar<string>( "pattern", pattern.Forge.EvaluateCodegen(typeof(string), methodNode, exprSymbol, codegenClassScope)) .IfRefNullReturnNull("pattern"); // initial like-setup blockMethod.DeclareVar<char>("es", Constant('\\')); if (optionalEscape != null) { blockMethod.DeclareVar<string>( "escapeString", optionalEscape.Forge.EvaluateCodegen(typeof(string), methodNode, exprSymbol, codegenClassScope)); blockMethod.IfCondition( And(NotEqualsNull(Ref("escapeString")), Not( StaticMethod<string>("IsNullOrEmpty", Ref("escapeString"))))) .AssignRef("es", ArrayAtIndex(Ref("escapeString"), Constant(0))); } blockMethod.DeclareVar<LikeUtil>( "likeUtil", NewInstance<LikeUtil>(Ref("pattern"), Ref("es"), Constant(false))); if (!forge.IsNumericValue) { blockMethod.DeclareVar<string>( "value", lhs.Forge.EvaluateCodegen(typeof(string), methodNode, exprSymbol, codegenClassScope)) .IfRefNullReturnNull("value") .MethodReturn(GetLikeCode(forge, Ref("likeUtil"), Ref("value"))); } else { blockMethod.DeclareVar<object>( "value", lhs.Forge.EvaluateCodegen(typeof(object), methodNode, exprSymbol, codegenClassScope)) .IfRefNullReturnNull("value") .MethodReturn(GetLikeCode(forge, Ref("likeUtil"), ExprDotMethod(Ref("value"), "ToString"))); } return methodNode; }