2018-03-18 20:27:34 +00:00
|
|
|
package printer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2018-04-05 21:39:04 +00:00
|
|
|
"strings"
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-03-19 20:50:07 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
|
|
|
|
2018-03-18 20:27:34 +00:00
|
|
|
"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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Printer) Print(n node.Node) {
|
|
|
|
p.printNode(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Printer) joinPrint(glue string, nn []node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
for k, n := range nn {
|
|
|
|
if k > 0 {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, glue)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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++
|
2018-04-02 19:50:36 +00:00
|
|
|
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)
|
2018-04-02 19:50:36 +00:00
|
|
|
if k < l {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
2018-04-02 19:50:36 +00:00
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNode(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
switch n.(type) {
|
|
|
|
|
|
|
|
// node
|
|
|
|
|
|
|
|
case *node.Identifier:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodeIdentifier(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *node.Parameter:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodeParameter(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *node.Nullable:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodeNullable(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *node.Argument:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodeArgument(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
// name
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
case *name.NamePart:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNameNamePart(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *name.Name:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNameName(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *name.FullyQualified:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNameFullyQualified(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *name.Relative:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNameRelative(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
// scalar
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
case *scalar.Lnumber:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printScalarLNumber(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *scalar.Dnumber:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printScalarDNumber(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *scalar.String:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printScalarString(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *scalar.EncapsedStringPart:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printScalarEncapsedStringPart(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
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)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *scalar.MagicConstant:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printScalarMagicConstant(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
// assign
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
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)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.BitwiseAnd:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignBitwiseAnd(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.BitwiseOr:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignBitwiseOr(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.BitwiseXor:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignBitwiseXor(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Concat:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignConcat(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Div:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignDiv(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Minus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignMinus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Mod:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignMod(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Mul:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignMul(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Plus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignPlus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.Pow:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignPow(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.ShiftLeft:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignShiftLeft(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *assign.ShiftRight:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printAssignShiftRight(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
// binary
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
case *binary.BitwiseAnd:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryBitwiseAnd(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.BitwiseOr:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryBitwiseOr(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.BitwiseXor:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryBitwiseXor(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.BooleanAnd:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryBooleanAnd(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.BooleanOr:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryBooleanOr(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Coalesce:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryCoalesce(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Concat:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryConcat(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Div:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryDiv(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Equal:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryEqual(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.GreaterOrEqual:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryGreaterOrEqual(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Greater:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryGreater(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Identical:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryIdentical(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.LogicalAnd:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryLogicalAnd(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.LogicalOr:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryLogicalOr(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.LogicalXor:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryLogicalXor(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Minus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryMinus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Mod:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryMod(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Mul:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryMul(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.NotEqual:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryNotEqual(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.NotIdentical:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryNotIdentical(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Plus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryPlus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Pow:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryPow(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.ShiftLeft:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryShiftLeft(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.ShiftRight:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinaryShiftRight(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.SmallerOrEqual:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinarySmallerOrEqual(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Smaller:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinarySmaller(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *binary.Spaceship:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printBinarySpaceship(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
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
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
case *expr.ArrayDimFetch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprArrayDimFetch(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ArrayItem:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprArrayItem(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Array:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprArray(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.BitwiseNot:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprBitwiseNot(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.BooleanNot:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprBooleanNot(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ClassConstFetch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprClassConstFetch(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Clone:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprClone(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ClosureUse:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprClosureUse(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Closure:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprClosure(n)
|
2018-03-20 17:48:55 +00:00
|
|
|
case *expr.ConstFetch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprConstFetch(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Die:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprDie(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Empty:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprEmpty(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ErrorSuppress:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprErrorSuppress(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Eval:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprEval(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Exit:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprExit(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.FunctionCall:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprFunctionCall(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Include:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprInclude(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.IncludeOnce:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprIncludeOnce(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.InstanceOf:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprInstanceOf(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Isset:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprIsset(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.List:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprList(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.MethodCall:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprMethodCall(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.New:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprNew(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.PostDec:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPostDec(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.PostInc:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPostInc(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.PreDec:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPreDec(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.PreInc:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPreInc(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Print:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPrint(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.PropertyFetch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprPropertyFetch(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Require:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprRequire(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.RequireOnce:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprRequireOnce(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ShellExec:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprShellExec(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ShortArray:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprShortArray(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.ShortList:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprShortList(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.StaticCall:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprStaticCall(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.StaticPropertyFetch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprStaticPropertyFetch(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Ternary:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprTernary(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.UnaryMinus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprUnaryMinus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.UnaryPlus:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprUnaryPlus(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Variable:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprVariable(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.YieldFrom:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprYieldFrom(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
case *expr.Yield:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printExprYield(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
// stmt
|
2018-03-19 20:50:07 +00:00
|
|
|
|
|
|
|
case *stmt.AltElseIf:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltElseIf(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltElse:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltElse(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltFor:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltFor(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltForeach:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltForeach(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltIf:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltIf(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltSwitch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltSwitch(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.AltWhile:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtAltWhile(n)
|
2018-03-20 10:21:21 +00:00
|
|
|
case *stmt.Break:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtBreak(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.Case:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtCase(n)
|
2018-03-20 10:21:21 +00:00
|
|
|
case *stmt.Catch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtCatch(n)
|
2018-03-20 17:48:55 +00:00
|
|
|
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)
|
2018-03-20 10:21:21 +00:00
|
|
|
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)
|
2018-03-31 11:08:56 +00:00
|
|
|
case *stmt.Echo:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtEcho(n)
|
2018-03-31 11:08:56 +00:00
|
|
|
case *stmt.ElseIf:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtElseif(n)
|
2018-03-31 11:08:56 +00:00
|
|
|
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)
|
2018-03-31 11:49:29 +00:00
|
|
|
case *stmt.For:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtFor(n)
|
2018-03-31 11:49:29 +00:00
|
|
|
case *stmt.Foreach:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtForeach(n)
|
2018-03-31 11:49:29 +00:00
|
|
|
case *stmt.Function:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtFunction(n)
|
2018-04-01 12:58:45 +00:00
|
|
|
case *stmt.Global:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtGlobal(n)
|
2018-04-01 12:58:45 +00:00
|
|
|
case *stmt.Goto:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtGoto(n)
|
2018-04-01 12:58:45 +00:00
|
|
|
case *stmt.GroupUse:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtGroupUse(n)
|
2018-04-01 12:58:45 +00:00
|
|
|
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)
|
2018-04-01 21:28:01 +00:00
|
|
|
case *stmt.Interface:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtInterface(n)
|
2018-04-01 21:28:01 +00:00
|
|
|
case *stmt.Label:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtLabel(n)
|
2018-04-01 21:28:01 +00:00
|
|
|
case *stmt.Namespace:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtNamespace(n)
|
2018-04-01 21:43:27 +00:00
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtNop(n)
|
2018-04-01 21:43:27 +00:00
|
|
|
case *stmt.PropertyList:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtPropertyList(n)
|
2018-04-01 21:43:27 +00:00
|
|
|
case *stmt.Property:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtProperty(n)
|
2018-04-01 21:43:27 +00:00
|
|
|
case *stmt.Return:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtReturn(n)
|
2018-04-01 21:59:31 +00:00
|
|
|
case *stmt.StaticVar:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtStaticVar(n)
|
2018-04-01 21:59:31 +00:00
|
|
|
case *stmt.Static:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtStatic(n)
|
2018-03-19 20:50:07 +00:00
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtStmtList(n)
|
2018-04-01 21:59:31 +00:00
|
|
|
case *stmt.Switch:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtSwitch(n)
|
2018-04-01 22:29:24 +00:00
|
|
|
case *stmt.Throw:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtThrow(n)
|
2018-04-01 22:29:24 +00:00
|
|
|
case *stmt.TraitMethodRef:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTraitMethodRef(n)
|
2018-04-01 22:29:24 +00:00
|
|
|
case *stmt.TraitUseAlias:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTraitUseAlias(n)
|
2018-04-01 22:29:24 +00:00
|
|
|
case *stmt.TraitUsePrecedence:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTraitUsePrecedence(n)
|
2018-04-01 22:29:24 +00:00
|
|
|
case *stmt.TraitUse:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTraitUse(n)
|
2018-04-02 09:41:47 +00:00
|
|
|
case *stmt.Trait:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTrait(n)
|
2018-04-02 09:41:47 +00:00
|
|
|
case *stmt.Try:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtTry(n)
|
2018-04-02 09:41:47 +00:00
|
|
|
case *stmt.Unset:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtUnset(n)
|
2018-04-02 09:41:47 +00:00
|
|
|
case *stmt.UseList:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtUseList(n)
|
2018-04-01 12:58:45 +00:00
|
|
|
case *stmt.Use:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtUse(n)
|
2018-04-02 09:41:47 +00:00
|
|
|
case *stmt.While:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printStmtWhile(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// node
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNodeIdentifier(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*node.Identifier).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNodeParameter(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*node.Parameter)
|
|
|
|
|
|
|
|
if nn.VariableType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.VariableType)
|
|
|
|
io.WriteString(p.w, " ")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ByRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Variadic {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "...")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if nn.DefaultValue != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.DefaultValue)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNodeNullable(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*node.Nullable)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "?")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNodeArgument(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*node.Argument)
|
|
|
|
|
|
|
|
if nn.IsReference {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Variadic {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "...")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// name
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNameNamePart(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*name.NamePart).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNameName(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(part)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNameFullyQualified(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printNameRelative(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*name.Relative)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "namespace")
|
2018-03-18 20:27:34 +00:00
|
|
|
for _, part := range nn.Parts {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "\\")
|
|
|
|
p.Print(part)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scalar
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printScalarLNumber(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*scalar.Lnumber).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printScalarDNumber(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*scalar.Dnumber).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printScalarString(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*scalar.String).Value
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printScalarEncapsedStringPart(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*scalar.EncapsedStringPart).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printScalarEncapsed(n node.Node) {
|
|
|
|
io.WriteString(p.w, "\"")
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
for _, nn := range n.(*scalar.Encapsed).Parts {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "\"")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2018-03-18 20:27:34 +00:00
|
|
|
v := n.(*scalar.MagicConstant).Value
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, v)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assign
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssign(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignBitwiseAnd(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignBitwiseOr(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignBitwiseXor(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignConcat(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignDiv(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignMinus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignMod(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignMul(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignPlus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignPow(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignShiftLeft(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printAssignShiftRight(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*assign.ShiftRight)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
|
|
|
io.WriteString(p.w, " >>= ")
|
|
|
|
p.Print(nn.Expression)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// binary
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryBitwiseAnd(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryBitwiseOr(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryBitwiseXor(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryBooleanAnd(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryBooleanOr(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryCoalesce(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryConcat(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryDiv(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryEqual(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryGreaterOrEqual(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryGreater(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryIdentical(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryLogicalAnd(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryLogicalOr(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryLogicalXor(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryMinus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryMod(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryMul(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryNotEqual(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryNotIdentical(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryPlus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryPow(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryShiftLeft(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinaryShiftRight(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinarySmallerOrEqual(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinarySmaller(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printBinarySpaceship(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*binary.Spaceship)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " <=> ")
|
|
|
|
p.Print(nn.Right)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cast
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printArray(n node.Node) {
|
|
|
|
nn := n.(*cast.Array)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(array)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printBool(n node.Node) {
|
|
|
|
nn := n.(*cast.Bool)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(bool)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printDouble(n node.Node) {
|
|
|
|
nn := n.(*cast.Double)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(float)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printInt(n node.Node) {
|
|
|
|
nn := n.(*cast.Int)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(int)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printObject(n node.Node) {
|
|
|
|
nn := n.(*cast.Object)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(object)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printString(n node.Node) {
|
|
|
|
nn := n.(*cast.String)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(string)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 08:59:29 +00:00
|
|
|
func (p *Printer) printUnset(n node.Node) {
|
|
|
|
nn := n.(*cast.Unset)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(unset)")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// expr
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprArrayDimFetch(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprArrayItem(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.ArrayItem)
|
|
|
|
|
|
|
|
if nn.Key != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ByRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Val)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprArray(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprBitwiseNot(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.BitwiseNot)
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "~")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprBooleanNot(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.BooleanNot)
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "!")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprClassConstFetch(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprClone(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Clone)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "clone ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprClosureUse(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.ClosureUse)
|
|
|
|
|
|
|
|
if nn.ByRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprClosure(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Closure)
|
|
|
|
|
|
|
|
if nn.Static {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "static ")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "function ")
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
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, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprConstFetch(n node.Node) {
|
2018-03-20 17:48:55 +00:00
|
|
|
nn := n.(*expr.ConstFetch)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Constant)
|
2018-03-20 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprDie(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprEmpty(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprErrorSuppress(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.ErrorSuppress)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "@")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprEval(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprExit(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprFunctionCall(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.FunctionCall)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Function)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprInclude(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Include)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "include ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprIncludeOnce(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.IncludeOnce)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "include_once ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprInstanceOf(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprIsset(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprList(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprMethodCall(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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, "(")
|
|
|
|
p.joinPrint(", ", nn.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprNew(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.New)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "new ")
|
|
|
|
p.Print(nn.Class)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if nn.Arguments != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPostDec(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.PostDec)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
|
|
|
io.WriteString(p.w, "--")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPostInc(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.PostInc)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
|
|
|
io.WriteString(p.w, "++")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPreDec(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.PreDec)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "--")
|
|
|
|
p.Print(nn.Variable)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPreInc(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.PreInc)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "++")
|
|
|
|
p.Print(nn.Variable)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPrint(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprPropertyFetch(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprRequire(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Require)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "require ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprRequireOnce(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.RequireOnce)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "require_once ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprShellExec(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.ShellExec)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "`")
|
2018-03-18 20:27:34 +00:00
|
|
|
for _, part := range nn.Parts {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(part)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "`")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprShortArray(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprShortList(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprStaticCall(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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, "(")
|
|
|
|
p.joinPrint(", ", nn.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprStaticPropertyFetch(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprTernary(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Ternary)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Condition)
|
|
|
|
io.WriteString(p.w, " ?")
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-04-03 16:59:20 +00:00
|
|
|
if nn.IfTrue != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
2018-04-03 16:59:20 +00:00
|
|
|
p.Print(nn.IfTrue)
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ": ")
|
2018-04-03 16:59:20 +00:00
|
|
|
p.Print(nn.IfFalse)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprUnaryMinus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.UnaryMinus)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "-")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprUnaryPlus(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.UnaryPlus)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "+")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
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-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprYieldFrom(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.YieldFrom)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "yield from ")
|
|
|
|
p.Print(nn.Expr)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printExprYield(n node.Node) {
|
2018-03-18 20:27:34 +00:00
|
|
|
nn := n.(*expr.Yield)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "yield ")
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if nn.Key != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Value)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
|
|
|
|
// smtm
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltElseIf(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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, ") :")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-04-02 19:50:36 +00:00
|
|
|
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 19:50:36 +00:00
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltElse(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
nn := n.(*stmt.AltElse)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "else :")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-04-02 19:50:36 +00:00
|
|
|
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 19:50:36 +00:00
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltFor(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-03-28 20:15:45 +00:00
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "endfor;")
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltForeach(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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 ")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
|
|
|
if nn.Key != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ByRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ") :\n")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-03-28 20:15:45 +00:00
|
|
|
s := nn.Stmt.(*stmt.StmtList)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodes(s.Stmts)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltIf(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-03-28 20:15:45 +00:00
|
|
|
s := nn.Stmt.(*stmt.StmtList)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodes(s.Stmts)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
|
|
|
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)
|
2018-03-19 20:50: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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltSwitch(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
|
2018-03-28 20:15:45 +00:00
|
|
|
s := nn.Cases
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodes(s)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtAltWhile(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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")
|
2018-03-19 20:50:07 +00:00
|
|
|
|
2018-03-28 20:15:45 +00:00
|
|
|
s := nn.Stmt.(*stmt.StmtList)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.printNodes(s.Stmts)
|
2018-03-19 20:50:07 +00:00
|
|
|
|
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-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtBreak(n node.Node) {
|
2018-03-20 10:21:21 +00:00
|
|
|
nn := n.(*stmt.Break)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "break")
|
2018-03-20 10:21:21 +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 10:21:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-03-20 10:21:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtCase(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
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, ":")
|
2018-04-02 19:50:36 +00:00
|
|
|
|
|
|
|
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 19:50:36 +00:00
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtCatch(n node.Node) {
|
2018-03-20 10:21:21 +00:00
|
|
|
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-03-20 10:21:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtClassMethod(n node.Node) {
|
2018-03-20 17:48:55 +00:00
|
|
|
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-03-20 17:48:55 +00:00
|
|
|
}
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "function ")
|
2018-03-20 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-20 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.MethodName)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-20 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
2018-03-20 17:48:55 +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 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Args != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Args)
|
|
|
|
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) {
|
2018-03-20 10:21:21 +00:00
|
|
|
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-03-20 10:21:21 +00:00
|
|
|
}
|
|
|
|
|
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:")
|
2018-04-02 19:50:36 +00:00
|
|
|
|
|
|
|
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 19:50:36 +00:00
|
|
|
}
|
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) {
|
2018-03-31 11:08:56 +00:00
|
|
|
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-03-31 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtElseif(n node.Node) {
|
2018-03-31 11:08:56 +00:00
|
|
|
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, ")")
|
2018-03-31 11:08:56 +00:00
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(s)
|
2018-03-31 11:08:56 +00:00
|
|
|
break
|
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
2018-03-31 11:08:56 +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 11:08:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtElse(n node.Node) {
|
2018-03-31 11:08:56 +00:00
|
|
|
nn := n.(*stmt.Else)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "else")
|
2018-03-31 11:08:56 +00:00
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(s)
|
2018-03-31 11:08:56 +00:00
|
|
|
break
|
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
2018-03-31 11:08:56 +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 11:08:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtExpression(n node.Node) {
|
2018-03-19 20:50:07 +00:00
|
|
|
nn := n.(*stmt.Expression)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-03-20 10:21:21 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-03-19 20:50:07 +00:00
|
|
|
}
|
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) {
|
2018-03-31 11:49:29 +00:00
|
|
|
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, ")")
|
2018-03-31 11:49:29 +00:00
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(s)
|
2018-03-31 11:49:29 +00:00
|
|
|
break
|
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
2018-03-31 11:49:29 +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 11:49:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtForeach(n node.Node) {
|
2018-03-31 11:49:29 +00:00
|
|
|
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 ")
|
2018-03-31 11:49:29 +00:00
|
|
|
|
|
|
|
if nn.Key != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
2018-03-31 11:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ByRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-31 11:49:29 +00:00
|
|
|
}
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-31 11:49:29 +00:00
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(s)
|
2018-03-31 11:49:29 +00:00
|
|
|
break
|
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
2018-03-31 11:49:29 +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 11:49:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtFunction(n node.Node) {
|
2018-03-31 11:49:29 +00:00
|
|
|
nn := n.(*stmt.Function)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "function ")
|
2018-03-31 11:49:29 +00:00
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "&")
|
2018-03-31 11:49:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.FunctionName)
|
2018-03-31 11:49:29 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
2018-03-31 11:49:29 +00:00
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
2018-03-31 11:49:29 +00:00
|
|
|
}
|
|
|
|
|
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-03-31 11:49:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtGlobal(n node.Node) {
|
2018-04-01 12:58:45 +00:00
|
|
|
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-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtGoto(n node.Node) {
|
2018-04-01 12:58:45 +00:00
|
|
|
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-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtGroupUse(n node.Node) {
|
2018-04-01 12:58:45 +00:00
|
|
|
nn := n.(*stmt.GroupUse)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "use ")
|
2018-04-01 12:58:45 +00:00
|
|
|
|
|
|
|
if nn.UseType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.UseType)
|
|
|
|
io.WriteString(p.w, " ")
|
2018-04-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
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-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtHaltCompiler(n node.Node) {
|
|
|
|
io.WriteString(p.w, "__halt_compiler();")
|
2018-04-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2018-04-01 21:28:01 +00:00
|
|
|
nn := n.(*stmt.Interface)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "interface")
|
2018-04-01 21:28:01 +00:00
|
|
|
|
|
|
|
if nn.InterfaceName != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.InterfaceName)
|
2018-04-01 21:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Extends != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " extends ")
|
|
|
|
p.joinPrint(", ", nn.Extends)
|
2018-04-01 21:28:01 +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-04-01 21:28:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtLabel(n node.Node) {
|
2018-04-01 21:28:01 +00:00
|
|
|
nn := n.(*stmt.Label)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.LabelName)
|
|
|
|
io.WriteString(p.w, ":")
|
2018-04-01 21:28:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtNamespace(n node.Node) {
|
2018-04-01 21:28:01 +00:00
|
|
|
nn := n.(*stmt.Namespace)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "namespace")
|
2018-04-02 19:50:36 +00:00
|
|
|
|
|
|
|
if nn.NamespaceName != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.NamespaceName)
|
2018-04-02 19:50:36 +00:00
|
|
|
}
|
2018-04-01 21:28:01 +00:00
|
|
|
|
|
|
|
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, "}")
|
2018-04-01 21:28:01 +00:00
|
|
|
} else {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-04-01 21:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtNop(n node.Node) {
|
|
|
|
io.WriteString(p.w, ";")
|
2018-04-01 21:43:27 +00:00
|
|
|
}
|
2018-03-31 11:17:05 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtPropertyList(n node.Node) {
|
2018-04-01 21:43:27 +00:00
|
|
|
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) {
|
2018-04-01 21:43:27 +00:00
|
|
|
nn := n.(*stmt.Property)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
2018-04-01 21:43:27 +00:00
|
|
|
|
|
|
|
if nn.Expr != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.Expr)
|
2018-04-01 21:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtReturn(n node.Node) {
|
2018-04-01 21:43:27 +00:00
|
|
|
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-01 12:58:45 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtStaticVar(n node.Node) {
|
2018-04-01 21:59:31 +00:00
|
|
|
nn := n.(*stmt.StaticVar)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Variable)
|
2018-04-01 21:59:31 +00:00
|
|
|
|
|
|
|
if nn.Expr != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.Expr)
|
2018-04-01 21:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtStatic(n node.Node) {
|
2018-04-01 21:59:31 +00:00
|
|
|
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-01 21:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtStmtList(n node.Node) {
|
2018-04-01 21:43:27 +00:00
|
|
|
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-01 21:43:27 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtSwitch(n node.Node) {
|
2018-04-01 21:59:31 +00:00
|
|
|
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-01 21:59:31 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.Cases)
|
2018-04-03 16:20:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
2018-04-01 21:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtThrow(n node.Node) {
|
2018-04-01 22:29:24 +00:00
|
|
|
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-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTraitMethodRef(n node.Node) {
|
2018-04-01 22:29:24 +00:00
|
|
|
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-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTraitUseAlias(n node.Node) {
|
2018-04-01 22:29:24 +00:00
|
|
|
nn := n.(*stmt.TraitUseAlias)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Ref)
|
|
|
|
io.WriteString(p.w, " as")
|
2018-04-01 22:29:24 +00:00
|
|
|
|
|
|
|
if nn.Modifier != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Modifier)
|
2018-04-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Alias != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Alias)
|
2018-04-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-04-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTraitUsePrecedence(n node.Node) {
|
2018-04-01 22:29:24 +00:00
|
|
|
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-01 22:29:24 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-04-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTraitUse(n node.Node) {
|
2018-04-01 22:29:24 +00:00
|
|
|
nn := n.(*stmt.TraitUse)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "use ")
|
|
|
|
p.joinPrint(", ", nn.Traits)
|
2018-04-01 22:29:24 +00:00
|
|
|
|
|
|
|
if nn.Adaptations != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.Adaptations)
|
2018-04-03 16:20:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
2018-04-01 22:29:24 +00:00
|
|
|
} else {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, ";")
|
2018-04-01 22:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTrait(n node.Node) {
|
2018-04-02 09:41:47 +00:00
|
|
|
nn := n.(*stmt.Trait)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "trait ")
|
|
|
|
p.Print(nn.TraitName)
|
2018-04-02 09:41:47 +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-04-02 09:41:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtTry(n node.Node) {
|
2018-04-02 09:41:47 +00:00
|
|
|
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, "}")
|
2018-04-02 09:41:47 +00:00
|
|
|
|
2018-04-02 19:50:36 +00:00
|
|
|
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++
|
2018-04-02 19:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 19:50:36 +00:00
|
|
|
}
|
2018-04-02 09:41:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtUnset(n node.Node) {
|
2018-04-02 09:41:47 +00:00
|
|
|
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 09:41:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtUseList(n node.Node) {
|
2018-04-02 09:41:47 +00:00
|
|
|
nn := n.(*stmt.UseList)
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, "use ")
|
2018-04-02 09:41:47 +00:00
|
|
|
|
|
|
|
if nn.UseType != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.UseType)
|
|
|
|
io.WriteString(p.w, " ")
|
2018-04-02 09:41:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.joinPrint(", ", nn.Uses)
|
|
|
|
io.WriteString(p.w, ";")
|
2018-04-02 09:41:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtUse(n node.Node) {
|
2018-04-01 12:58:45 +00:00
|
|
|
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-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(nn.Use)
|
2018-04-01 12:58:45 +00:00
|
|
|
|
|
|
|
if nn.Alias != nil {
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " as ")
|
|
|
|
p.Print(nn.Alias)
|
2018-04-01 12:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-02 09:41:47 +00:00
|
|
|
|
2018-04-02 20:57:22 +00:00
|
|
|
func (p *Printer) printStmtWhile(n node.Node) {
|
2018-04-02 09:41:47 +00:00
|
|
|
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, ")")
|
2018-04-02 09:41:47 +00:00
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
|
|
|
case *stmt.Nop:
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(s)
|
2018-04-02 09:41:47 +00:00
|
|
|
break
|
|
|
|
case *stmt.StmtList:
|
2018-04-02 20:57:22 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
2018-04-02 09:41:47 +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 09:41:47 +00:00
|
|
|
}
|
|
|
|
}
|