// Public Methods public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { if (_returnValue == null) writer.WriteLn("return;"); else writer.WriteLnF("return {0};", _returnValue.GetPhpCode(style)); }
// Public Methods public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { var s = style == null ? EmitStyleCompression.Beauty : style.Compression; if (s == EmitStyleCompression.NearCrypto) writer.Write("continue;"); else writer.WriteLn("continue;"); }
// Public Methods public void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { if (_isConst) { // const CONSTANT = 'constant value'; writer.WriteLnF("const {0} = {1};", Name, _constValue.GetPhpCode(style)); return; } var a = string.Format("{0}{1} ${2}", _visibility.ToString().ToLower(), _isStatic ? " static" : "", Name ); if (_constValue != null) a += " = " + _constValue.GetPhpCode(style); writer.WriteLn(a + ";"); }
// Public Methods public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { style = PhpEmitStyle.xClone(style); if (!style.AsIncrementor) if (_expression is PhpMethodCallExpression) { var methodCallExpression = _expression as PhpMethodCallExpression; if (methodCallExpression.CallType == MethodCallStyles.Procedural && methodCallExpression.Name == "echo") if (EmitInlineHtml(writer, style)) return; } var code = _expression.GetPhpCode(style); if (style.AsIncrementor) { writer.Write(code); } else writer.WriteLn(code + ";"); }
public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { writer.WriteLn("break;"); }
public void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { var nsManager = new PhpModuleNamespaceManager(); style.CurrentNamespace = null; if (!string.IsNullOrEmpty(_topComments)) { writer.WriteLn("/*\r\n" + _topComments.Trim() + "\r\n*/"); } var module = this; { // var noBracketStyle = PhpEmitStyle.xClone(style, ShowBracketsEnum.Never); #region Top code { // top code var collectedTopCodeBlock = new PhpCodeBlock(); collectedTopCodeBlock.Statements.AddRange(ConvertRequestedToCode()); collectedTopCodeBlock.Statements.AddRange(ConvertDefinedConstToCode()); if (_topCode != null) { collectedTopCodeBlock.Statements.AddRange(_topCode.Statements); } nsManager.Add(collectedTopCodeBlock.Statements); } #endregion { var classesGbNamespace = module.Classes.GroupBy(u => u.Name.Namespace); foreach (var classesInNamespace in classesGbNamespace.OrderBy(i => !i.Key.IsRoot)) { foreach (var c in classesInNamespace) { nsManager.Add(c); } } } if (_bottomCode != null) { nsManager.Add(_bottomCode.Statements); } if (!nsManager.Container.Any()) { return; } if (nsManager.OnlyOneRootStatement) { foreach (var cl in nsManager.Container[0].Items) { cl.Emit(emiter, writer, style); } } else { foreach (var ns in nsManager.Container) { EmitWithNamespace(ns.Name, emiter, writer, style, ns.Items); } } } }
bool EmitInlineHtml(PhpSourceCodeWriter writer, PhpEmitStyle style) { // return false; var values = GetEchoItems(style); //if (Values.Length == 1) // return false; #region Emisja { foreach (var i in values) { if (i.PlainHtml) throw new NotSupportedException(); writer.WriteLn("echo " + i.Code + ";"); } return true; } #if VERSION1 { { if (Values.Length == 1) { if (!Values[0].PlainHtml) { return false; } } } bool isHtml = false; int iii = Values.Length; bool isFirst = true; foreach (var i in Values) { bool isLast = --iii == 0; try { var code = i.Code; if (isFirst && !i.PlainHtml) { writer.WriteLn("echo " + code + ";"); continue; } if (!i.PlainHtml) code = "<?= " + code + " ?>"; if (!isHtml) { code = "?>" + code; isHtml = true; } if (isLast && isHtml) code += "<?php"; if (!isFirst) writer.SkipIndent = true; if (isHtml && !isLast) writer.Write(code); else writer.WriteLn(code); } finally { isFirst = false; } } } #endif #endregion }
public void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) { var nsManager = new PhpModuleNamespaceManager(); style.CurrentNamespace = null; if (!string.IsNullOrEmpty(_topComments)) writer.WriteLn("/*\r\n" + _topComments.Trim() + "\r\n*/"); var module = this; { // var noBracketStyle = PhpEmitStyle.xClone(style, ShowBracketsEnum.Never); #region Top code { // top code var collectedTopCodeBlock = new PhpCodeBlock(); collectedTopCodeBlock.Statements.AddRange(ConvertRequestedToCode()); collectedTopCodeBlock.Statements.AddRange(ConvertDefinedConstToCode()); if (_topCode != null) collectedTopCodeBlock.Statements.AddRange(_topCode.Statements); nsManager.Add(collectedTopCodeBlock.Statements); } #endregion { var classesGbNamespace = module.Classes.GroupBy(u => u.Name.Namespace); foreach (var classesInNamespace in classesGbNamespace.OrderBy(i => !i.Key.IsRoot)) foreach (var c in classesInNamespace) nsManager.Add(c); } if (_bottomCode != null) nsManager.Add(_bottomCode.Statements); if (!nsManager.Container.Any()) return; if (nsManager.OnlyOneRootStatement) foreach (var cl in nsManager.Container[0].Items) cl.Emit(emiter, writer, style); else foreach (var ns in nsManager.Container) EmitWithNamespace(ns.Name, emiter, writer, style, ns.Items); } }