php-parser/printer/printer.go

2179 lines
41 KiB
Go
Raw Normal View History

package printer
import (
"io"
2018-04-05 21:39:04 +00:00
"strings"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/node/expr/cast"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
)
2018-04-02 20:57:22 +00:00
type Printer struct {
w io.Writer
indentStr string
indentDepth int
}
2018-04-02 20:57:22 +00:00
// NewPrinter - Constructor for Printer
func NewPrinter(w io.Writer, indentStr string) *Printer {
return &Printer{
w: w,
indentStr: indentStr,
indentDepth: 0,
}
}
2018-04-05 21:59:22 +00:00
func (p *Printer) PrintFile(n *stmt.StmtList) {
if len(n.Stmts) > 0 {
firstStmt := n.Stmts[0]
n.Stmts = n.Stmts[1:]
switch fs := firstStmt.(type) {
case *stmt.InlineHtml:
io.WriteString(p.w, fs.Value)
io.WriteString(p.w, "<?php\n")
default:
io.WriteString(p.w, "<?php\n")
p.printIndent()
p.Print(fs)
io.WriteString(p.w, "\n")
}
}
p.indentDepth--
p.printNodes(n.Stmts)
io.WriteString(p.w, "\n")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) Print(n node.Node) {
p.printNode(n)
}
func (p *Printer) joinPrint(glue string, nn []node.Node) {
for k, n := range nn {
if k > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, glue)
}
2018-04-02 20:57:22 +00:00
p.Print(n)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodes(nn []node.Node) {
2018-04-03 16:20:55 +00:00
p.indentDepth++
l := len(nn) - 1
for k, n := range nn {
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(n)
if k < l {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
}
}
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
func (p *Printer) printIndent() {
for i := 0; i < p.indentDepth; i++ {
io.WriteString(p.w, p.indentStr)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNode(n node.Node) {
switch n.(type) {
// node
case *node.Identifier:
2018-04-02 20:57:22 +00:00
p.printNodeIdentifier(n)
case *node.Parameter:
2018-04-02 20:57:22 +00:00
p.printNodeParameter(n)
case *node.Nullable:
2018-04-02 20:57:22 +00:00
p.printNodeNullable(n)
case *node.Argument:
2018-04-02 20:57:22 +00:00
p.printNodeArgument(n)
2018-04-05 08:59:29 +00:00
// name
case *name.NamePart:
2018-04-02 20:57:22 +00:00
p.printNameNamePart(n)
case *name.Name:
2018-04-02 20:57:22 +00:00
p.printNameName(n)
case *name.FullyQualified:
2018-04-02 20:57:22 +00:00
p.printNameFullyQualified(n)
case *name.Relative:
2018-04-02 20:57:22 +00:00
p.printNameRelative(n)
2018-04-05 08:59:29 +00:00
// scalar
case *scalar.Lnumber:
2018-04-02 20:57:22 +00:00
p.printScalarLNumber(n)
case *scalar.Dnumber:
2018-04-02 20:57:22 +00:00
p.printScalarDNumber(n)
case *scalar.String:
2018-04-02 20:57:22 +00:00
p.printScalarString(n)
case *scalar.EncapsedStringPart:
2018-04-02 20:57:22 +00:00
p.printScalarEncapsedStringPart(n)
case *scalar.Encapsed:
2018-04-02 20:57:22 +00:00
p.printScalarEncapsed(n)
2018-04-05 21:39:04 +00:00
case *scalar.Heredoc:
p.printScalarHeredoc(n)
case *scalar.MagicConstant:
2018-04-02 20:57:22 +00:00
p.printScalarMagicConstant(n)
2018-04-05 08:59:29 +00:00
// assign
case *assign.Assign:
2018-04-02 20:57:22 +00:00
p.printAssign(n)
2018-04-05 09:03:32 +00:00
case *assign.Reference:
p.printReference(n)
case *assign.BitwiseAnd:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseAnd(n)
case *assign.BitwiseOr:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseOr(n)
case *assign.BitwiseXor:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseXor(n)
case *assign.Concat:
2018-04-02 20:57:22 +00:00
p.printAssignConcat(n)
case *assign.Div:
2018-04-02 20:57:22 +00:00
p.printAssignDiv(n)
case *assign.Minus:
2018-04-02 20:57:22 +00:00
p.printAssignMinus(n)
case *assign.Mod:
2018-04-02 20:57:22 +00:00
p.printAssignMod(n)
case *assign.Mul:
2018-04-02 20:57:22 +00:00
p.printAssignMul(n)
case *assign.Plus:
2018-04-02 20:57:22 +00:00
p.printAssignPlus(n)
case *assign.Pow:
2018-04-02 20:57:22 +00:00
p.printAssignPow(n)
case *assign.ShiftLeft:
2018-04-02 20:57:22 +00:00
p.printAssignShiftLeft(n)
case *assign.ShiftRight:
2018-04-02 20:57:22 +00:00
p.printAssignShiftRight(n)
2018-04-05 08:59:29 +00:00
// binary
case *binary.BitwiseAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseAnd(n)
case *binary.BitwiseOr:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseOr(n)
case *binary.BitwiseXor:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseXor(n)
case *binary.BooleanAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryBooleanAnd(n)
case *binary.BooleanOr:
2018-04-02 20:57:22 +00:00
p.printBinaryBooleanOr(n)
case *binary.Coalesce:
2018-04-02 20:57:22 +00:00
p.printBinaryCoalesce(n)
case *binary.Concat:
2018-04-02 20:57:22 +00:00
p.printBinaryConcat(n)
case *binary.Div:
2018-04-02 20:57:22 +00:00
p.printBinaryDiv(n)
case *binary.Equal:
2018-04-02 20:57:22 +00:00
p.printBinaryEqual(n)
case *binary.GreaterOrEqual:
2018-04-02 20:57:22 +00:00
p.printBinaryGreaterOrEqual(n)
case *binary.Greater:
2018-04-02 20:57:22 +00:00
p.printBinaryGreater(n)
case *binary.Identical:
2018-04-02 20:57:22 +00:00
p.printBinaryIdentical(n)
case *binary.LogicalAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalAnd(n)
case *binary.LogicalOr:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalOr(n)
case *binary.LogicalXor:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalXor(n)
case *binary.Minus:
2018-04-02 20:57:22 +00:00
p.printBinaryMinus(n)
case *binary.Mod:
2018-04-02 20:57:22 +00:00
p.printBinaryMod(n)
case *binary.Mul:
2018-04-02 20:57:22 +00:00
p.printBinaryMul(n)
case *binary.NotEqual:
2018-04-02 20:57:22 +00:00
p.printBinaryNotEqual(n)
case *binary.NotIdentical:
2018-04-02 20:57:22 +00:00
p.printBinaryNotIdentical(n)
case *binary.Plus:
2018-04-02 20:57:22 +00:00
p.printBinaryPlus(n)
case *binary.Pow:
2018-04-02 20:57:22 +00:00
p.printBinaryPow(n)
case *binary.ShiftLeft:
2018-04-02 20:57:22 +00:00
p.printBinaryShiftLeft(n)
case *binary.ShiftRight:
2018-04-02 20:57:22 +00:00
p.printBinaryShiftRight(n)
case *binary.SmallerOrEqual:
2018-04-02 20:57:22 +00:00
p.printBinarySmallerOrEqual(n)
case *binary.Smaller:
2018-04-02 20:57:22 +00:00
p.printBinarySmaller(n)
case *binary.Spaceship:
2018-04-02 20:57:22 +00:00
p.printBinarySpaceship(n)
2018-04-05 08:59:29 +00:00
// cast
case *cast.Array:
p.printArray(n)
case *cast.Bool:
p.printBool(n)
case *cast.Double:
p.printDouble(n)
case *cast.Int:
p.printInt(n)
case *cast.Object:
p.printObject(n)
case *cast.String:
p.printString(n)
case *cast.Unset:
p.printUnset(n)
// expr
case *expr.ArrayDimFetch:
2018-04-02 20:57:22 +00:00
p.printExprArrayDimFetch(n)
case *expr.ArrayItem:
2018-04-02 20:57:22 +00:00
p.printExprArrayItem(n)
case *expr.Array:
2018-04-02 20:57:22 +00:00
p.printExprArray(n)
case *expr.BitwiseNot:
2018-04-02 20:57:22 +00:00
p.printExprBitwiseNot(n)
case *expr.BooleanNot:
2018-04-02 20:57:22 +00:00
p.printExprBooleanNot(n)
case *expr.ClassConstFetch:
2018-04-02 20:57:22 +00:00
p.printExprClassConstFetch(n)
case *expr.Clone:
2018-04-02 20:57:22 +00:00
p.printExprClone(n)
case *expr.ClosureUse:
2018-04-02 20:57:22 +00:00
p.printExprClosureUse(n)
case *expr.Closure:
2018-04-02 20:57:22 +00:00
p.printExprClosure(n)
case *expr.ConstFetch:
2018-04-02 20:57:22 +00:00
p.printExprConstFetch(n)
case *expr.Die:
2018-04-02 20:57:22 +00:00
p.printExprDie(n)
case *expr.Empty:
2018-04-02 20:57:22 +00:00
p.printExprEmpty(n)
case *expr.ErrorSuppress:
2018-04-02 20:57:22 +00:00
p.printExprErrorSuppress(n)
case *expr.Eval:
2018-04-02 20:57:22 +00:00
p.printExprEval(n)
case *expr.Exit:
2018-04-02 20:57:22 +00:00
p.printExprExit(n)
case *expr.FunctionCall:
2018-04-02 20:57:22 +00:00
p.printExprFunctionCall(n)
case *expr.Include:
2018-04-02 20:57:22 +00:00
p.printExprInclude(n)
case *expr.IncludeOnce:
2018-04-02 20:57:22 +00:00
p.printExprIncludeOnce(n)
case *expr.InstanceOf:
2018-04-02 20:57:22 +00:00
p.printExprInstanceOf(n)
case *expr.Isset:
2018-04-02 20:57:22 +00:00
p.printExprIsset(n)
case *expr.List:
2018-04-02 20:57:22 +00:00
p.printExprList(n)
case *expr.MethodCall:
2018-04-02 20:57:22 +00:00
p.printExprMethodCall(n)
case *expr.New:
2018-04-02 20:57:22 +00:00
p.printExprNew(n)
case *expr.PostDec:
2018-04-02 20:57:22 +00:00
p.printExprPostDec(n)
case *expr.PostInc:
2018-04-02 20:57:22 +00:00
p.printExprPostInc(n)
case *expr.PreDec:
2018-04-02 20:57:22 +00:00
p.printExprPreDec(n)
case *expr.PreInc:
2018-04-02 20:57:22 +00:00
p.printExprPreInc(n)
case *expr.Print:
2018-04-02 20:57:22 +00:00
p.printExprPrint(n)
case *expr.PropertyFetch:
2018-04-02 20:57:22 +00:00
p.printExprPropertyFetch(n)
case *expr.Require:
2018-04-02 20:57:22 +00:00
p.printExprRequire(n)
case *expr.RequireOnce:
2018-04-02 20:57:22 +00:00
p.printExprRequireOnce(n)
case *expr.ShellExec:
2018-04-02 20:57:22 +00:00
p.printExprShellExec(n)
case *expr.ShortArray:
2018-04-02 20:57:22 +00:00
p.printExprShortArray(n)
case *expr.ShortList:
2018-04-02 20:57:22 +00:00
p.printExprShortList(n)
case *expr.StaticCall:
2018-04-02 20:57:22 +00:00
p.printExprStaticCall(n)
case *expr.StaticPropertyFetch:
2018-04-02 20:57:22 +00:00
p.printExprStaticPropertyFetch(n)
case *expr.Ternary:
2018-04-02 20:57:22 +00:00
p.printExprTernary(n)
case *expr.UnaryMinus:
2018-04-02 20:57:22 +00:00
p.printExprUnaryMinus(n)
case *expr.UnaryPlus:
2018-04-02 20:57:22 +00:00
p.printExprUnaryPlus(n)
case *expr.Variable:
2018-04-02 20:57:22 +00:00
p.printExprVariable(n)
case *expr.YieldFrom:
2018-04-02 20:57:22 +00:00
p.printExprYieldFrom(n)
case *expr.Yield:
2018-04-02 20:57:22 +00:00
p.printExprYield(n)
2018-04-05 08:59:29 +00:00
// stmt
case *stmt.AltElseIf:
2018-04-02 20:57:22 +00:00
p.printStmtAltElseIf(n)
case *stmt.AltElse:
2018-04-02 20:57:22 +00:00
p.printStmtAltElse(n)
case *stmt.AltFor:
2018-04-02 20:57:22 +00:00
p.printStmtAltFor(n)
case *stmt.AltForeach:
2018-04-02 20:57:22 +00:00
p.printStmtAltForeach(n)
case *stmt.AltIf:
2018-04-02 20:57:22 +00:00
p.printStmtAltIf(n)
case *stmt.AltSwitch:
2018-04-02 20:57:22 +00:00
p.printStmtAltSwitch(n)
case *stmt.AltWhile:
2018-04-02 20:57:22 +00:00
p.printStmtAltWhile(n)
case *stmt.Break:
2018-04-02 20:57:22 +00:00
p.printStmtBreak(n)
case *stmt.Case:
2018-04-02 20:57:22 +00:00
p.printStmtCase(n)
case *stmt.Catch:
2018-04-02 20:57:22 +00:00
p.printStmtCatch(n)
case *stmt.ClassMethod:
2018-04-02 20:57:22 +00:00
p.printStmtClassMethod(n)
2018-03-20 18:06:56 +00:00
case *stmt.Class:
2018-04-02 20:57:22 +00:00
p.printStmtClass(n)
2018-03-20 18:37:55 +00:00
case *stmt.ClassConstList:
2018-04-02 20:57:22 +00:00
p.printStmtClassConstList(n)
case *stmt.Constant:
2018-04-02 20:57:22 +00:00
p.printStmtConstant(n)
2018-03-20 18:37:55 +00:00
case *stmt.Continue:
2018-04-02 20:57:22 +00:00
p.printStmtContinue(n)
2018-03-28 20:44:02 +00:00
case *stmt.Declare:
2018-04-02 20:57:22 +00:00
p.printStmtDeclare(n)
2018-03-28 21:04:09 +00:00
case *stmt.Default:
2018-04-02 20:57:22 +00:00
p.printStmtDefault(n)
2018-03-28 21:04:09 +00:00
case *stmt.Do:
2018-04-02 20:57:22 +00:00
p.printStmtDo(n)
case *stmt.Echo:
2018-04-02 20:57:22 +00:00
p.printStmtEcho(n)
case *stmt.ElseIf:
2018-04-02 20:57:22 +00:00
p.printStmtElseif(n)
case *stmt.Else:
2018-04-02 20:57:22 +00:00
p.printStmtElse(n)
2018-03-31 11:17:05 +00:00
case *stmt.Expression:
2018-04-02 20:57:22 +00:00
p.printStmtExpression(n)
2018-03-31 11:17:05 +00:00
case *stmt.Finally:
2018-04-02 20:57:22 +00:00
p.printStmtFinally(n)
case *stmt.For:
2018-04-02 20:57:22 +00:00
p.printStmtFor(n)
case *stmt.Foreach:
2018-04-02 20:57:22 +00:00
p.printStmtForeach(n)
case *stmt.Function:
2018-04-02 20:57:22 +00:00
p.printStmtFunction(n)
case *stmt.Global:
2018-04-02 20:57:22 +00:00
p.printStmtGlobal(n)
case *stmt.Goto:
2018-04-02 20:57:22 +00:00
p.printStmtGoto(n)
case *stmt.GroupUse:
2018-04-02 20:57:22 +00:00
p.printStmtGroupUse(n)
case *stmt.HaltCompiler:
2018-04-02 20:57:22 +00:00
p.printStmtHaltCompiler(n)
2018-04-01 14:07:07 +00:00
case *stmt.If:
2018-04-02 20:57:22 +00:00
p.printStmtIf(n)
2018-04-01 14:07:07 +00:00
case *stmt.InlineHtml:
2018-04-02 20:57:22 +00:00
p.printStmtInlineHTML(n)
case *stmt.Interface:
2018-04-02 20:57:22 +00:00
p.printStmtInterface(n)
case *stmt.Label:
2018-04-02 20:57:22 +00:00
p.printStmtLabel(n)
case *stmt.Namespace:
2018-04-02 20:57:22 +00:00
p.printStmtNamespace(n)
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.printStmtNop(n)
case *stmt.PropertyList:
2018-04-02 20:57:22 +00:00
p.printStmtPropertyList(n)
case *stmt.Property:
2018-04-02 20:57:22 +00:00
p.printStmtProperty(n)
case *stmt.Return:
2018-04-02 20:57:22 +00:00
p.printStmtReturn(n)
case *stmt.StaticVar:
2018-04-02 20:57:22 +00:00
p.printStmtStaticVar(n)
case *stmt.Static:
2018-04-02 20:57:22 +00:00
p.printStmtStatic(n)
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
p.printStmtStmtList(n)
case *stmt.Switch:
2018-04-02 20:57:22 +00:00
p.printStmtSwitch(n)
case *stmt.Throw:
2018-04-02 20:57:22 +00:00
p.printStmtThrow(n)
case *stmt.TraitMethodRef:
2018-04-02 20:57:22 +00:00
p.printStmtTraitMethodRef(n)
case *stmt.TraitUseAlias:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUseAlias(n)
case *stmt.TraitUsePrecedence:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUsePrecedence(n)
case *stmt.TraitUse:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUse(n)
case *stmt.Trait:
2018-04-02 20:57:22 +00:00
p.printStmtTrait(n)
case *stmt.Try:
2018-04-02 20:57:22 +00:00
p.printStmtTry(n)
case *stmt.Unset:
2018-04-02 20:57:22 +00:00
p.printStmtUnset(n)
case *stmt.UseList:
2018-04-02 20:57:22 +00:00
p.printStmtUseList(n)
case *stmt.Use:
2018-04-02 20:57:22 +00:00
p.printStmtUse(n)
case *stmt.While:
2018-04-02 20:57:22 +00:00
p.printStmtWhile(n)
}
}
// node
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeIdentifier(n node.Node) {
v := n.(*node.Identifier).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeParameter(n node.Node) {
nn := n.(*node.Parameter)
if nn.VariableType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.VariableType)
io.WriteString(p.w, " ")
}
if nn.ByRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
if nn.Variadic {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "...")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.DefaultValue != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " = ")
p.Print(nn.DefaultValue)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeNullable(n node.Node) {
nn := n.(*node.Nullable)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "?")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeArgument(n node.Node) {
nn := n.(*node.Argument)
if nn.IsReference {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
if nn.Variadic {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "...")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
}
// name
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameNamePart(n node.Node) {
v := n.(*name.NamePart).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameName(n node.Node) {
nn := n.(*name.Name)
for k, part := range nn.Parts {
if k > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
}
2018-04-02 20:57:22 +00:00
p.Print(part)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameFullyQualified(n node.Node) {
nn := n.(*name.FullyQualified)
for _, part := range nn.Parts {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
p.Print(part)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameRelative(n node.Node) {
nn := n.(*name.Relative)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "namespace")
for _, part := range nn.Parts {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
p.Print(part)
}
}
// scalar
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarLNumber(n node.Node) {
v := n.(*scalar.Lnumber).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarDNumber(n node.Node) {
v := n.(*scalar.Dnumber).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarString(n node.Node) {
v := n.(*scalar.String).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarEncapsedStringPart(n node.Node) {
v := n.(*scalar.EncapsedStringPart).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarEncapsed(n node.Node) {
io.WriteString(p.w, "\"")
for _, nn := range n.(*scalar.Encapsed).Parts {
2018-04-02 20:57:22 +00:00
p.Print(nn)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\"")
}
2018-04-05 21:39:04 +00:00
func (p *Printer) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, nn := range nn.Parts {
p.Print(nn)
}
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarMagicConstant(n node.Node) {
v := n.(*scalar.MagicConstant).Value
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, v)
}
// Assign
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssign(n node.Node) {
nn := n.(*assign.Assign)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " = ")
p.Print(nn.Expression)
}
2018-04-05 09:03:32 +00:00
func (p *Printer) printReference(n node.Node) {
nn := n.(*assign.Reference)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " =& ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseAnd(n node.Node) {
nn := n.(*assign.BitwiseAnd)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " &= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseOr(n node.Node) {
nn := n.(*assign.BitwiseOr)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " |= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseXor(n node.Node) {
nn := n.(*assign.BitwiseXor)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " ^= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignConcat(n node.Node) {
nn := n.(*assign.Concat)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " .= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignDiv(n node.Node) {
nn := n.(*assign.Div)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " /= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMinus(n node.Node) {
nn := n.(*assign.Minus)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " -= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMod(n node.Node) {
nn := n.(*assign.Mod)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " %= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMul(n node.Node) {
nn := n.(*assign.Mul)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " *= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignPlus(n node.Node) {
nn := n.(*assign.Plus)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " += ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignPow(n node.Node) {
nn := n.(*assign.Pow)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " **= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignShiftLeft(n node.Node) {
nn := n.(*assign.ShiftLeft)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " <<= ")
p.Print(nn.Expression)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignShiftRight(n node.Node) {
nn := n.(*assign.ShiftRight)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, " >>= ")
p.Print(nn.Expression)
}
// binary
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseAnd(n node.Node) {
nn := n.(*binary.BitwiseAnd)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " & ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseOr(n node.Node) {
nn := n.(*binary.BitwiseOr)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " | ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseXor(n node.Node) {
nn := n.(*binary.BitwiseXor)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " ^ ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBooleanAnd(n node.Node) {
nn := n.(*binary.BooleanAnd)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " && ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBooleanOr(n node.Node) {
nn := n.(*binary.BooleanOr)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " || ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryCoalesce(n node.Node) {
nn := n.(*binary.Coalesce)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " ?? ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryConcat(n node.Node) {
nn := n.(*binary.Concat)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " . ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryDiv(n node.Node) {
nn := n.(*binary.Div)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " / ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryEqual(n node.Node) {
nn := n.(*binary.Equal)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " == ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryGreaterOrEqual(n node.Node) {
nn := n.(*binary.GreaterOrEqual)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " >= ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryGreater(n node.Node) {
nn := n.(*binary.Greater)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " > ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryIdentical(n node.Node) {
nn := n.(*binary.Identical)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " === ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalAnd(n node.Node) {
nn := n.(*binary.LogicalAnd)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " and ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalOr(n node.Node) {
nn := n.(*binary.LogicalOr)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " or ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalXor(n node.Node) {
nn := n.(*binary.LogicalXor)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " xor ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMinus(n node.Node) {
nn := n.(*binary.Minus)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " - ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMod(n node.Node) {
nn := n.(*binary.Mod)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " % ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMul(n node.Node) {
nn := n.(*binary.Mul)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " * ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryNotEqual(n node.Node) {
nn := n.(*binary.NotEqual)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " != ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryNotIdentical(n node.Node) {
nn := n.(*binary.NotIdentical)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " !== ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryPlus(n node.Node) {
nn := n.(*binary.Plus)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " + ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryPow(n node.Node) {
nn := n.(*binary.Pow)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " ** ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryShiftLeft(n node.Node) {
nn := n.(*binary.ShiftLeft)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " << ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryShiftRight(n node.Node) {
nn := n.(*binary.ShiftRight)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " >> ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySmallerOrEqual(n node.Node) {
nn := n.(*binary.SmallerOrEqual)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " <= ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySmaller(n node.Node) {
nn := n.(*binary.Smaller)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " < ")
p.Print(nn.Right)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySpaceship(n node.Node) {
nn := n.(*binary.Spaceship)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
io.WriteString(p.w, " <=> ")
p.Print(nn.Right)
}
// cast
2018-04-05 08:59:29 +00:00
func (p *Printer) printArray(n node.Node) {
nn := n.(*cast.Array)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(array)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printBool(n node.Node) {
nn := n.(*cast.Bool)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(bool)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printDouble(n node.Node) {
nn := n.(*cast.Double)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(float)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printInt(n node.Node) {
nn := n.(*cast.Int)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(int)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printObject(n node.Node) {
nn := n.(*cast.Object)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(object)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printString(n node.Node) {
nn := n.(*cast.String)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(string)")
p.Print(nn.Expr)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printUnset(n node.Node) {
nn := n.(*cast.Unset)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(unset)")
p.Print(nn.Expr)
}
// expr
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArrayDimFetch(n node.Node) {
nn := n.(*expr.ArrayDimFetch)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, "[")
p.Print(nn.Dim)
io.WriteString(p.w, "]")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArrayItem(n node.Node) {
nn := n.(*expr.ArrayItem)
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
io.WriteString(p.w, " => ")
}
if nn.ByRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Val)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArray(n node.Node) {
nn := n.(*expr.Array)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "array(")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprBitwiseNot(n node.Node) {
nn := n.(*expr.BitwiseNot)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "~")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprBooleanNot(n node.Node) {
nn := n.(*expr.BooleanNot)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "!")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClassConstFetch(n node.Node) {
nn := n.(*expr.ClassConstFetch)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
io.WriteString(p.w, "::")
io.WriteString(p.w, nn.ConstantName.(*node.Identifier).Value)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClone(n node.Node) {
nn := n.(*expr.Clone)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "clone ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClosureUse(n node.Node) {
nn := n.(*expr.ClosureUse)
if nn.ByRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClosure(n node.Node) {
nn := n.(*expr.Closure)
if nn.Static {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "static ")
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "function ")
if nn.ReturnsRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(", ", nn.Params)
io.WriteString(p.w, ")")
if nn.Uses != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " use (")
p.joinPrint(", ", nn.Uses)
io.WriteString(p.w, ")")
}
if nn.ReturnType != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ": ")
p.Print(nn.ReturnType)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprConstFetch(n node.Node) {
nn := n.(*expr.ConstFetch)
2018-04-02 20:57:22 +00:00
p.Print(nn.Constant)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprDie(n node.Node) {
nn := n.(*expr.Die)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "die(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprEmpty(n node.Node) {
nn := n.(*expr.Empty)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "empty(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprErrorSuppress(n node.Node) {
nn := n.(*expr.ErrorSuppress)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "@")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprEval(n node.Node) {
nn := n.(*expr.Eval)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "eval(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprExit(n node.Node) {
nn := n.(*expr.Exit)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "exit(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprFunctionCall(n node.Node) {
nn := n.(*expr.FunctionCall)
2018-04-02 20:57:22 +00:00
p.Print(nn.Function)
io.WriteString(p.w, "(")
2018-04-29 16:58:49 +00:00
p.joinPrint(", ", nn.ArgumentList.Arguments)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprInclude(n node.Node) {
nn := n.(*expr.Include)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "include ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprIncludeOnce(n node.Node) {
nn := n.(*expr.IncludeOnce)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "include_once ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprInstanceOf(n node.Node) {
nn := n.(*expr.InstanceOf)
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
io.WriteString(p.w, " instanceof ")
p.Print(nn.Class)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprIsset(n node.Node) {
nn := n.(*expr.Isset)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "isset(")
p.joinPrint(", ", nn.Variables)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprList(n node.Node) {
nn := n.(*expr.List)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "list(")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprMethodCall(n node.Node) {
nn := n.(*expr.MethodCall)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, "->")
p.Print(nn.Method)
io.WriteString(p.w, "(")
2018-04-29 16:58:49 +00:00
p.joinPrint(", ", nn.ArgumentList.Arguments)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprNew(n node.Node) {
nn := n.(*expr.New)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "new ")
p.Print(nn.Class)
2018-04-29 16:58:49 +00:00
if nn.ArgumentList != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
2018-04-29 16:58:49 +00:00
p.joinPrint(", ", nn.ArgumentList.Arguments)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPostDec(n node.Node) {
nn := n.(*expr.PostDec)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, "--")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPostInc(n node.Node) {
nn := n.(*expr.PostInc)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, "++")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPreDec(n node.Node) {
nn := n.(*expr.PreDec)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "--")
p.Print(nn.Variable)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPreInc(n node.Node) {
nn := n.(*expr.PreInc)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "++")
p.Print(nn.Variable)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPrint(n node.Node) {
nn := n.(*expr.Print)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "print(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPropertyFetch(n node.Node) {
nn := n.(*expr.PropertyFetch)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, "->")
p.Print(nn.Property)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprRequire(n node.Node) {
nn := n.(*expr.Require)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "require ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprRequireOnce(n node.Node) {
nn := n.(*expr.RequireOnce)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "require_once ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShellExec(n node.Node) {
nn := n.(*expr.ShellExec)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "`")
for _, part := range nn.Parts {
2018-04-02 20:57:22 +00:00
p.Print(part)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "`")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShortArray(n node.Node) {
nn := n.(*expr.ShortArray)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "[")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, "]")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShortList(n node.Node) {
nn := n.(*expr.ShortList)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "[")
p.joinPrint(", ", nn.Items)
io.WriteString(p.w, "]")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprStaticCall(n node.Node) {
nn := n.(*expr.StaticCall)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
io.WriteString(p.w, "::")
p.Print(nn.Call)
io.WriteString(p.w, "(")
2018-04-29 16:58:49 +00:00
p.joinPrint(", ", nn.ArgumentList.Arguments)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprStaticPropertyFetch(n node.Node) {
nn := n.(*expr.StaticPropertyFetch)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
io.WriteString(p.w, "::")
p.Print(nn.Property)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprTernary(n node.Node) {
nn := n.(*expr.Ternary)
2018-04-02 20:57:22 +00:00
p.Print(nn.Condition)
io.WriteString(p.w, " ?")
if nn.IfTrue != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.IfTrue)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ": ")
p.Print(nn.IfFalse)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprUnaryMinus(n node.Node) {
nn := n.(*expr.UnaryMinus)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "-")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprUnaryPlus(n node.Node) {
nn := n.(*expr.UnaryPlus)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "+")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprVariable(n node.Node) {
io.WriteString(p.w, "$")
p.Print(n.(*expr.Variable).VarName)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprYieldFrom(n node.Node) {
nn := n.(*expr.YieldFrom)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "yield from ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprYield(n node.Node) {
nn := n.(*expr.Yield)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "yield ")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
io.WriteString(p.w, " => ")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Value)
}
// smtm
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltElseIf(n node.Node) {
nn := n.(*stmt.AltElseIf)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "elseif (")
p.Print(nn.Cond)
io.WriteString(p.w, ") :")
if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
p.printNodes(s)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltElse(n node.Node) {
nn := n.(*stmt.AltElse)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "else :")
if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
p.printNodes(s)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltFor(n node.Node) {
nn := n.(*stmt.AltFor)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "for (")
p.joinPrint(", ", nn.Init)
io.WriteString(p.w, "; ")
p.joinPrint(", ", nn.Cond)
io.WriteString(p.w, "; ")
p.joinPrint(", ", nn.Loop)
io.WriteString(p.w, ") :\n")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "endfor;")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltForeach(n node.Node) {
nn := n.(*stmt.AltForeach)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "foreach (")
p.Print(nn.Expr)
io.WriteString(p.w, " as ")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
io.WriteString(p.w, " => ")
}
if nn.ByRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ") :\n")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "endforeach;")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltIf(n node.Node) {
nn := n.(*stmt.AltIf)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "if (")
p.Print(nn.Cond)
io.WriteString(p.w, ") :\n")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
for _, elseif := range nn.ElseIf {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(elseif)
}
if nn.Else != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(nn.Else)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "endif;")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltSwitch(n node.Node) {
nn := n.(*stmt.AltSwitch)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "switch (")
p.Print(nn.Cond)
io.WriteString(p.w, ") :\n")
2018-04-29 20:10:56 +00:00
s := nn.CaseList.Cases
2018-04-02 20:57:22 +00:00
p.printNodes(s)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "endswitch;")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltWhile(n node.Node) {
nn := n.(*stmt.AltWhile)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "while (")
p.Print(nn.Cond)
io.WriteString(p.w, ") :\n")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "endwhile;")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtBreak(n node.Node) {
nn := n.(*stmt.Break)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "break")
if nn.Expr != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtCase(n node.Node) {
nn := n.(*stmt.Case)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "case ")
p.Print(nn.Cond)
io.WriteString(p.w, ":")
if len(nn.Stmts) > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
p.printNodes(nn.Stmts)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtCatch(n node.Node) {
nn := n.(*stmt.Catch)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "catch (")
p.joinPrint(" | ", nn.Types)
io.WriteString(p.w, " ")
p.Print(nn.Variable)
io.WriteString(p.w, ") {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClassMethod(n node.Node) {
nn := n.(*stmt.ClassMethod)
if nn.Modifiers != nil {
2018-04-02 20:57:22 +00:00
p.joinPrint(" ", nn.Modifiers)
io.WriteString(p.w, " ")
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "function ")
if nn.ReturnsRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.MethodName)
io.WriteString(p.w, "(")
p.joinPrint(", ", nn.Params)
io.WriteString(p.w, ")")
if nn.ReturnType != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ": ")
p.Print(nn.ReturnType)
}
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "{\n")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClass(n node.Node) {
2018-03-20 18:06:56 +00:00
nn := n.(*stmt.Class)
if nn.Modifiers != nil {
2018-04-02 20:57:22 +00:00
p.joinPrint(" ", nn.Modifiers)
io.WriteString(p.w, " ")
2018-03-20 18:06:56 +00:00
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "class")
2018-03-20 18:06:56 +00:00
if nn.ClassName != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.ClassName)
2018-03-20 18:06:56 +00:00
}
2018-04-29 16:58:49 +00:00
if nn.ArgumentList != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
2018-04-29 16:58:49 +00:00
p.joinPrint(", ", nn.ArgumentList.Arguments)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
2018-03-20 18:06:56 +00:00
}
if nn.Extends != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " extends ")
p.Print(nn.Extends)
2018-03-20 18:06:56 +00:00
}
if nn.Implements != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " implements ")
p.joinPrint(", ", nn.Implements)
2018-03-20 18:06:56 +00:00
}
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "{\n")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
2018-03-20 18:06:56 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClassConstList(n node.Node) {
2018-03-20 18:37:55 +00:00
nn := n.(*stmt.ClassConstList)
if nn.Modifiers != nil {
2018-04-02 20:57:22 +00:00
p.joinPrint(" ", nn.Modifiers)
io.WriteString(p.w, " ")
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "const ")
2018-03-20 18:37:55 +00:00
2018-04-02 20:57:22 +00:00
p.joinPrint(", ", nn.Consts)
2018-03-20 18:37:55 +00:00
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtConstant(n node.Node) {
nn := n.(*stmt.Constant)
2018-04-02 20:57:22 +00:00
p.Print(nn.ConstantName)
io.WriteString(p.w, " = ")
p.Print(nn.Expr)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtContinue(n node.Node) {
2018-03-20 18:37:55 +00:00
nn := n.(*stmt.Continue)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "continue")
2018-03-20 18:37:55 +00:00
if nn.Expr != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.Expr)
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDeclare(n node.Node) {
2018-03-28 20:44:02 +00:00
nn := n.(*stmt.Declare)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "declare(")
p.joinPrint(", ", nn.Consts)
io.WriteString(p.w, ")")
2018-03-31 10:50:35 +00:00
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-03-31 10:50:35 +00:00
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
2018-03-31 10:50:35 +00:00
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
2018-03-31 10:50:35 +00:00
}
2018-03-28 20:44:02 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDefault(n node.Node) {
2018-03-28 21:04:09 +00:00
nn := n.(*stmt.Default)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "default:")
if len(nn.Stmts) > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
p.printNodes(nn.Stmts)
}
2018-03-28 21:04:09 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDo(n node.Node) {
2018-03-28 21:04:09 +00:00
nn := n.(*stmt.Do)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "do")
2018-03-28 21:04:09 +00:00
switch s := nn.Stmt.(type) {
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
io.WriteString(p.w, " ")
2018-03-28 21:04:09 +00:00
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-03-28 21:04:09 +00:00
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "while (")
p.Print(nn.Cond)
io.WriteString(p.w, ");")
2018-03-28 21:04:09 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtEcho(n node.Node) {
nn := n.(*stmt.Echo)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "echo ")
p.joinPrint(", ", nn.Exprs)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtElseif(n node.Node) {
nn := n.(*stmt.ElseIf)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "elseif (")
p.Print(nn.Cond)
io.WriteString(p.w, ")")
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtElse(n node.Node) {
nn := n.(*stmt.Else)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "else")
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtExpression(n node.Node) {
nn := n.(*stmt.Expression)
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
2018-03-28 20:44:02 +00:00
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFinally(n node.Node) {
2018-03-31 11:17:05 +00:00
nn := n.(*stmt.Finally)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "finally {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
2018-03-31 11:17:05 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFor(n node.Node) {
nn := n.(*stmt.For)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "for (")
p.joinPrint(", ", nn.Init)
io.WriteString(p.w, "; ")
p.joinPrint(", ", nn.Cond)
io.WriteString(p.w, "; ")
p.joinPrint(", ", nn.Loop)
io.WriteString(p.w, ")")
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtForeach(n node.Node) {
nn := n.(*stmt.Foreach)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "foreach (")
p.Print(nn.Expr)
io.WriteString(p.w, " as ")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
io.WriteString(p.w, " => ")
}
if nn.ByRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
io.WriteString(p.w, ")")
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFunction(n node.Node) {
nn := n.(*stmt.Function)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "function ")
if nn.ReturnsRef {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.FunctionName)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(", ", nn.Params)
io.WriteString(p.w, ")")
if nn.ReturnType != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ": ")
p.Print(nn.ReturnType)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGlobal(n node.Node) {
nn := n.(*stmt.Global)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "global ")
p.joinPrint(", ", nn.Vars)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGoto(n node.Node) {
nn := n.(*stmt.Goto)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "goto ")
p.Print(nn.Label)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGroupUse(n node.Node) {
nn := n.(*stmt.GroupUse)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "use ")
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
io.WriteString(p.w, " ")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Prefix)
io.WriteString(p.w, "\\{")
p.joinPrint(", ", nn.UseList)
io.WriteString(p.w, "};")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtHaltCompiler(n node.Node) {
io.WriteString(p.w, "__halt_compiler();")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtIf(n node.Node) {
2018-04-01 14:07:07 +00:00
nn := n.(*stmt.If)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "if (")
p.Print(nn.Cond)
io.WriteString(p.w, ")")
2018-04-01 14:07:07 +00:00
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-01 14:07:07 +00:00
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
2018-04-01 14:07:07 +00:00
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
2018-04-01 14:07:07 +00:00
}
if nn.ElseIf != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth--
2018-04-02 20:57:22 +00:00
p.printNodes(nn.ElseIf)
2018-04-03 16:20:55 +00:00
p.indentDepth++
2018-04-01 14:07:07 +00:00
}
if nn.Else != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(nn.Else)
2018-04-01 14:07:07 +00:00
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtInlineHTML(n node.Node) {
2018-04-01 14:07:07 +00:00
nn := n.(*stmt.InlineHtml)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "?>")
io.WriteString(p.w, nn.Value)
io.WriteString(p.w, "<?php")
2018-04-01 14:07:07 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtInterface(n node.Node) {
nn := n.(*stmt.Interface)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "interface")
if nn.InterfaceName != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.InterfaceName)
}
if nn.Extends != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " extends ")
p.joinPrint(", ", nn.Extends)
}
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "{\n")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtLabel(n node.Node) {
nn := n.(*stmt.Label)
2018-04-02 20:57:22 +00:00
p.Print(nn.LabelName)
io.WriteString(p.w, ":")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtNamespace(n node.Node) {
nn := n.(*stmt.Namespace)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "namespace")
if nn.NamespaceName != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.NamespaceName)
}
if nn.Stmts != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
} else {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtNop(n node.Node) {
io.WriteString(p.w, ";")
}
2018-03-31 11:17:05 +00:00
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtPropertyList(n node.Node) {
nn := n.(*stmt.PropertyList)
2018-04-02 20:57:22 +00:00
p.joinPrint(" ", nn.Modifiers)
io.WriteString(p.w, " ")
p.joinPrint(", ", nn.Properties)
io.WriteString(p.w, ";")
2018-03-31 11:17:05 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtProperty(n node.Node) {
nn := n.(*stmt.Property)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.Expr != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " = ")
p.Print(nn.Expr)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtReturn(n node.Node) {
nn := n.(*stmt.Return)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "return ")
p.Print(nn.Expr)
io.WriteString(p.w, ";")
2018-03-28 20:44:02 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStaticVar(n node.Node) {
nn := n.(*stmt.StaticVar)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.Expr != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " = ")
p.Print(nn.Expr)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStatic(n node.Node) {
nn := n.(*stmt.Static)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "static ")
p.joinPrint(", ", nn.Vars)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStmtList(n node.Node) {
nn := n.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "{\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtSwitch(n node.Node) {
nn := n.(*stmt.Switch)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "switch (")
p.Print(nn.Cond)
io.WriteString(p.w, ")")
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " {\n")
2018-04-29 20:10:56 +00:00
p.printNodes(nn.CaseList.Cases)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtThrow(n node.Node) {
nn := n.(*stmt.Throw)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "throw ")
p.Print(nn.Expr)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitMethodRef(n node.Node) {
nn := n.(*stmt.TraitMethodRef)
2018-04-02 20:57:22 +00:00
p.Print(nn.Trait)
io.WriteString(p.w, "::")
p.Print(nn.Method)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUseAlias(n node.Node) {
nn := n.(*stmt.TraitUseAlias)
2018-04-02 20:57:22 +00:00
p.Print(nn.Ref)
io.WriteString(p.w, " as")
if nn.Modifier != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.Modifier)
}
if nn.Alias != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(nn.Alias)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUsePrecedence(n node.Node) {
nn := n.(*stmt.TraitUsePrecedence)
2018-04-02 20:57:22 +00:00
p.Print(nn.Ref)
io.WriteString(p.w, " insteadof ")
p.joinPrint(", ", nn.Insteadof)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUse(n node.Node) {
nn := n.(*stmt.TraitUse)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "use ")
p.joinPrint(", ", nn.Traits)
2018-04-29 19:34:24 +00:00
if nn.TraitAdaptationList != nil {
adaptations := nn.TraitAdaptationList.Adaptations
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " {\n")
2018-04-29 19:34:24 +00:00
p.printNodes(adaptations)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
} else {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTrait(n node.Node) {
nn := n.(*stmt.Trait)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "trait ")
p.Print(nn.TraitName)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "{\n")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTry(n node.Node) {
nn := n.(*stmt.Try)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "try {\n")
p.printNodes(nn.Stmts)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "\n")
p.printIndent()
io.WriteString(p.w, "}")
if nn.Catches != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth--
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Catches)
2018-04-03 16:20:55 +00:00
p.indentDepth++
}
if nn.Finally != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(nn.Finally)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUnset(n node.Node) {
nn := n.(*stmt.Unset)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "unset(")
p.joinPrint(", ", nn.Vars)
io.WriteString(p.w, ");")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUseList(n node.Node) {
nn := n.(*stmt.UseList)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "use ")
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
io.WriteString(p.w, " ")
}
2018-04-02 20:57:22 +00:00
p.joinPrint(", ", nn.Uses)
io.WriteString(p.w, ";")
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUse(n node.Node) {
nn := n.(*stmt.Use)
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
io.WriteString(p.w, " ")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Use)
if nn.Alias != nil {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " as ")
p.Print(nn.Alias)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtWhile(n node.Node) {
nn := n.(*stmt.While)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "while (")
p.Print(nn.Cond)
io.WriteString(p.w, ")")
switch s := nn.Stmt.(type) {
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.Print(s)
break
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, " ")
p.Print(s)
default:
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\n")
2018-04-03 16:20:55 +00:00
p.indentDepth++
p.printIndent()
2018-04-02 20:57:22 +00:00
p.Print(s)
2018-04-03 16:20:55 +00:00
p.indentDepth--
}
}