protected override IPhpValue VisitPhpMethodCallExpression(PhpMethodCallExpression node) { if (node.Name == "_urlencode_" || node.Name == "_htmlspecialchars_") { if (node.Arguments[0].Expression is PhpConstValue) { var cv = (node.Arguments[0].Expression as PhpConstValue).Value; if (cv == null) { return(Simplify(node.Arguments[0].Expression)); } if (cv is int) { cv = cv.ToString(); } else if (cv is string) { if (node.Name == "_urlencode_") { cv = HttpUtility.UrlEncode(cv as string); } else { cv = HttpUtility.HtmlEncode(cv as string); } } else { throw new NotSupportedException(); } return(Simplify(new PhpConstValue(cv))); } } { var list1 = node.Arguments.Select(Simplify).Cast <PhpMethodInvokeValue>().ToList(); var to = node.TargetObject == null ? null : Simplify(node.TargetObject); if (PhpSourceBase.EqualCode_List(list1, node.Arguments) && PhpSourceBase.EqualCode(to, node.TargetObject)) { return(node); } var xx = new PhpMethodCallExpression(node.Name) { Arguments = list1, DontIncludeClass = node.DontIncludeClass, TargetObject = to }; xx.SetClassName(node.ClassName, node.TranslationInfo); return(xx); } return(node); }
protected override IPhpStatement VisitPhpCodeBlock(PhpCodeBlock node) { var newNode = new PhpCodeBlock(); foreach (var i in node.GetPlain()) { newNode.Statements.Add(Simplify(i)); } #region Łączenie kolejnych echo if (op.JoinEchoStatements) { //newNode.Statements.Clear(); { for (var i = 1; i < newNode.Statements.Count; i++) { var e1 = GetPhpNativeMethodCall(newNode.Statements[i - 1], "echo"); if (e1 == null) { continue; } var e2 = GetPhpNativeMethodCall(newNode.Statements[i], "echo"); if (e2 == null) { continue; } Func <IPhpValue, IPhpValue> AddBracketsIfNecessary = (ee) => { if (ee is PhpParenthesizedExpression || ee is PhpConstValue || ee is PhpPropertyAccessExpression) { return(ee); } if (ee is PhpBinaryOperatorExpression && ((PhpBinaryOperatorExpression)ee).Operator == ".") { return(ee); } return(new PhpParenthesizedExpression(ee)); }; var a1 = AddBracketsIfNecessary(e1.Arguments[0].Expression); var a2 = AddBracketsIfNecessary(e2.Arguments[0].Expression); IPhpValue e = new PhpBinaryOperatorExpression(".", a1, a2); e = Simplify(e); IPhpValue echo = new PhpMethodCallExpression("echo", e); newNode.Statements[i - 1] = new PhpExpressionStatement(echo); newNode.Statements.RemoveAt(i); i--; } for (var i = 0; i < newNode.Statements.Count; i++) { var a = newNode.Statements[i]; if (a is PhpSourceBase) { newNode.Statements[i] = Visit(a as PhpSourceBase); } } } } #endregion return(PhpSourceBase.EqualCode_List(node.Statements, newNode.Statements) ? node : newNode); }