2018-07-02 17:48:55 +00:00
|
|
|
package printer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
"github.com/z7zmey/php-parser/pkg/ast"
|
2018-07-02 17:48:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PrettyPrinter struct {
|
|
|
|
w io.Writer
|
|
|
|
indentStr string
|
|
|
|
indentDepth int
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPrettyPrinter - Constructor for PrettyPrinter
|
|
|
|
func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter {
|
|
|
|
return &PrettyPrinter{
|
|
|
|
w: w,
|
|
|
|
indentStr: indentStr,
|
|
|
|
indentDepth: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) Print(n ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNode(n)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) joinPrint(glue string, nn []ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
for k, n := range nn {
|
|
|
|
if k > 0 {
|
|
|
|
io.WriteString(p.w, glue)
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodes(nn []ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
p.indentDepth++
|
|
|
|
l := len(nn) - 1
|
|
|
|
for k, n := range nn {
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(n)
|
|
|
|
if k < l {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrettyPrinter) printIndent() {
|
|
|
|
for i := 0; i < p.indentDepth; i++ {
|
|
|
|
io.WriteString(p.w, p.indentStr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNode(n ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
switch n.(type) {
|
|
|
|
|
|
|
|
// node
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.Root:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodeRoot(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.Identifier:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodeIdentifier(n)
|
2020-07-05 19:47:46 +00:00
|
|
|
case *ast.Reference:
|
|
|
|
p.printNodeReference(n)
|
|
|
|
case *ast.Variadic:
|
|
|
|
p.printNodeVariadic(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.Parameter:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodeParameter(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.Nullable:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodeNullable(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.Argument:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodeArgument(n)
|
|
|
|
|
|
|
|
// name
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.NameNamePart:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNameNamePart(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.NameName:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNameName(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.NameFullyQualified:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNameFullyQualified(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.NameRelative:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNameRelative(n)
|
|
|
|
|
|
|
|
// scalar
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarLnumber:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarLNumber(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarDnumber:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarDNumber(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarString:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarString(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarEncapsedStringPart:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarEncapsedStringPart(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarEncapsed:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarEncapsed(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarHeredoc:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarHeredoc(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarMagicConstant:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printScalarMagicConstant(n)
|
|
|
|
|
|
|
|
// assign
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssign:
|
|
|
|
p.printAssignAssign(n)
|
|
|
|
case *ast.ExprAssignReference:
|
|
|
|
p.printAssignReference(n)
|
|
|
|
case *ast.ExprAssignBitwiseAnd:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignBitwiseAnd(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignBitwiseOr:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignBitwiseOr(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignBitwiseXor:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignBitwiseXor(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignConcat:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignConcat(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignDiv:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignDiv(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignMinus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignMinus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignMod:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignMod(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignMul:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignMul(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignPlus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignPlus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignPow:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignPow(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignShiftLeft:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignShiftLeft(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprAssignShiftRight:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printAssignShiftRight(n)
|
|
|
|
|
|
|
|
// binary
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryBitwiseAnd:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryBitwiseAnd(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryBitwiseOr:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryBitwiseOr(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryBitwiseXor:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryBitwiseXor(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryBooleanAnd:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryBooleanAnd(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryBooleanOr:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryBooleanOr(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryCoalesce:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryCoalesce(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryConcat:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryConcat(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryDiv:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryDiv(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryEqual:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryEqual(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryGreaterOrEqual:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryGreaterOrEqual(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryGreater:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryGreater(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryIdentical:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryIdentical(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryLogicalAnd:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryLogicalAnd(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryLogicalOr:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryLogicalOr(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryLogicalXor:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryLogicalXor(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryMinus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryMinus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryMod:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryMod(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryMul:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryMul(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryNotEqual:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryNotEqual(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryNotIdentical:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryNotIdentical(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryPlus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryPlus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryPow:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryPow(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryShiftLeft:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryShiftLeft(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinaryShiftRight:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinaryShiftRight(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinarySmallerOrEqual:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinarySmallerOrEqual(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinarySmaller:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinarySmaller(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBinarySpaceship:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBinarySpaceship(n)
|
|
|
|
|
|
|
|
// cast
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastArray:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printArray(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastBool:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printBool(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastDouble:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printDouble(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastInt:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printInt(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastObject:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printObject(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastString:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printString(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprCastUnset:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printUnset(n)
|
|
|
|
|
|
|
|
// expr
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprArrayDimFetch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprArrayDimFetch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprArrayItem:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprArrayItem(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprArray:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprArray(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBitwiseNot:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprBitwiseNot(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprBooleanNot:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprBooleanNot(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprClassConstFetch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprClassConstFetch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprClone:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprClone(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprClosureUse:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprClosureUse(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprClosure:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprClosure(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprConstFetch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprConstFetch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprEmpty:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprEmpty(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprErrorSuppress:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprErrorSuppress(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprEval:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprEval(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprExit:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprExit(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprFunctionCall:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprFunctionCall(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprInclude:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprInclude(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprIncludeOnce:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprIncludeOnce(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprInstanceOf:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprInstanceOf(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprIsset:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprIsset(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprList:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprList(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprMethodCall:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprMethodCall(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprNew:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprNew(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPostDec:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPostDec(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPostInc:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPostInc(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPreDec:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPreDec(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPreInc:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPreInc(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPrint:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPrint(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprPropertyFetch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprPropertyFetch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprReference:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprReference(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprRequire:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprRequire(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprRequireOnce:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprRequireOnce(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprShellExec:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprShellExec(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprShortArray:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprShortArray(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprShortList:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprShortList(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprStaticCall:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprStaticCall(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprStaticPropertyFetch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprStaticPropertyFetch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprTernary:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprTernary(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprUnaryMinus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprUnaryMinus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprUnaryPlus:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprUnaryPlus(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprVariable:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprVariable(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprYieldFrom:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprYieldFrom(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ExprYield:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printExprYield(n)
|
|
|
|
|
|
|
|
// stmt
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtAltForeach:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtAltForeach(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtAltSwitch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtAltSwitch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtBreak:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtBreak(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtCase:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtCase(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtCatch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtCatch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtClassMethod:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtClassMethod(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtClass:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtClass(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtClassConstList:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtClassConstList(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtConstant:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtConstant(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtContinue:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtContinue(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtDeclare:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtDeclare(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtDefault:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtDefault(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtDo:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtDo(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtEcho:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtEcho(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtElseIf:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtElseif(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtElse:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtElse(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtExpression:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtExpression(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtFinally:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtFinally(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtFor:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtFor(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtForeach:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtForeach(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtFunction:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtFunction(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtGlobal:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtGlobal(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtGoto:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtGoto(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtHaltCompiler:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtHaltCompiler(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtIf:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtIf(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtInlineHtml:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtInlineHTML(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtInterface:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtInterface(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtLabel:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtLabel(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNamespace:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtNamespace(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtNop(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtPropertyList:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtPropertyList(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtProperty:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtProperty(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtReturn:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtReturn(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStaticVar:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtStaticVar(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStatic:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtStatic(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtStmtList(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtSwitch:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtSwitch(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtThrow:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtThrow(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTraitMethodRef:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTraitMethodRef(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTraitUseAlias:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTraitUseAlias(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTraitUsePrecedence:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTraitUsePrecedence(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTraitUse:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTraitUse(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTrait:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTrait(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtTry:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtTry(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtUnset:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtUnset(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtUse:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtUse(n)
|
2020-08-22 13:59:26 +00:00
|
|
|
case *ast.StmtGroupUse:
|
|
|
|
p.printStmtGroupUse(n)
|
2020-08-03 19:22:53 +00:00
|
|
|
case *ast.StmtUseDeclaration:
|
|
|
|
p.printStmtUseDeclaration(n)
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtWhile:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printStmtWhile(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// node
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodeRoot(n ast.Vertex) {
|
2020-07-29 20:23:44 +00:00
|
|
|
var stmts []ast.Vertex
|
2020-05-17 19:56:32 +00:00
|
|
|
v := n.(*ast.Root)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if len(v.Stmts) > 0 {
|
|
|
|
firstStmt := v.Stmts[0]
|
2020-07-10 07:50:09 +00:00
|
|
|
stmts = v.Stmts[1:]
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
switch fs := firstStmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtInlineHtml:
|
|
|
|
io.WriteString(p.w, string(fs.Value))
|
2018-07-02 17:48:55 +00:00
|
|
|
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--
|
2020-07-10 07:50:09 +00:00
|
|
|
p.printNodes(stmts)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodeIdentifier(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.Identifier).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-07-05 19:47:46 +00:00
|
|
|
func (p *PrettyPrinter) printNodeReference(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.Reference)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "&")
|
|
|
|
p.Print(nn.Var)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrettyPrinter) printNodeVariadic(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.Variadic)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "...")
|
|
|
|
p.Print(nn.Var)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodeParameter(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.Parameter)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
if nn.Type != nil {
|
|
|
|
p.Print(nn.Type)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.DefaultValue != nil {
|
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.DefaultValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodeNullable(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.Nullable)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "?")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNodeArgument(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.Argument)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.IsReference {
|
|
|
|
io.WriteString(p.w, "&")
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Variadic {
|
|
|
|
io.WriteString(p.w, "...")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// name
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNameNamePart(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.NameNamePart).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNameName(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.NameName)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
for k, part := range nn.Parts {
|
|
|
|
if k > 0 {
|
|
|
|
io.WriteString(p.w, "\\")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNameFullyQualified(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.NameFullyQualified)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
for _, part := range nn.Parts {
|
|
|
|
io.WriteString(p.w, "\\")
|
|
|
|
p.Print(part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printNameRelative(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.NameRelative)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "namespace")
|
|
|
|
for _, part := range nn.Parts {
|
|
|
|
io.WriteString(p.w, "\\")
|
|
|
|
p.Print(part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scalar
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarLNumber(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.ScalarLnumber).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarDNumber(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.ScalarDnumber).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarString(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.ScalarString).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarEncapsedStringPart(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.ScalarEncapsedStringPart).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarEncapsed(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ScalarEncapsed)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "\"")
|
|
|
|
|
2018-07-09 19:04:18 +00:00
|
|
|
for _, part := range nn.Parts {
|
|
|
|
switch part.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarEncapsedStringPart:
|
2018-07-09 19:04:18 +00:00
|
|
|
p.Print(part)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "{")
|
|
|
|
p.Print(part)
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\"")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarHeredoc(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ScalarHeredoc)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
io.WriteString(p.w, string(nn.Label))
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2018-07-09 19:04:18 +00:00
|
|
|
for _, part := range nn.Parts {
|
|
|
|
switch part.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarEncapsedStringPart:
|
2018-07-09 19:04:18 +00:00
|
|
|
p.Print(part)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "{")
|
|
|
|
p.Print(part)
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
io.WriteString(p.w, strings.Trim(string(nn.Label), "<\"'\n"))
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printScalarMagicConstant(n ast.Vertex) {
|
|
|
|
v := string(n.(*ast.ScalarMagicConstant).Value)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignAssign(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssign)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " = ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignReference(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignReference)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " =& ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignBitwiseAnd(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignBitwiseAnd)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " &= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignBitwiseOr(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignBitwiseOr)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " |= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignBitwiseXor(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignBitwiseXor)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ^= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignConcat(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignConcat)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " .= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignDiv(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignDiv)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " /= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignMinus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignMinus)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " -= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignMod(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignMod)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " %= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignMul(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignMul)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " *= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignPlus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignPlus)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " += ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignPow(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignPow)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " **= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignShiftLeft(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignShiftLeft)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " <<= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printAssignShiftRight(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprAssignShiftRight)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " >>= ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Expr)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// binary
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryBitwiseAnd(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryBitwiseAnd)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " & ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryBitwiseOr(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryBitwiseOr)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " | ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryBitwiseXor(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryBitwiseXor)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " ^ ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryBooleanAnd(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryBooleanAnd)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " && ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryBooleanOr(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryBooleanOr)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " || ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryCoalesce(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryCoalesce)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " ?? ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryConcat(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryConcat)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " . ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryDiv(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryDiv)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " / ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryEqual(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryEqual)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " == ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryGreaterOrEqual(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryGreaterOrEqual)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " >= ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryGreater(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryGreater)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " > ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryIdentical(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryIdentical)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " === ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryLogicalAnd(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryLogicalAnd)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " and ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryLogicalOr(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryLogicalOr)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " or ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryLogicalXor(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryLogicalXor)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " xor ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryMinus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryMinus)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " - ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryMod(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryMod)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " % ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryMul(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryMul)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " * ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryNotEqual(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryNotEqual)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " != ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryNotIdentical(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryNotIdentical)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " !== ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryPlus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryPlus)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " + ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryPow(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryPow)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " ** ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryShiftLeft(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryShiftLeft)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " << ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinaryShiftRight(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinaryShiftRight)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " >> ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinarySmallerOrEqual(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinarySmallerOrEqual)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " <= ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinarySmaller(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinarySmaller)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " < ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBinarySpaceship(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBinarySpaceship)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Left)
|
|
|
|
io.WriteString(p.w, " <=> ")
|
|
|
|
p.Print(nn.Right)
|
|
|
|
}
|
|
|
|
|
|
|
|
// cast
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printArray(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastArray)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(array)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printBool(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastBool)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(bool)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printDouble(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastDouble)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(float)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printInt(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastInt)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(int)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printObject(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastObject)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(object)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printString(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastString)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(string)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printUnset(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprCastUnset)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "(unset)")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// expr
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprArrayDimFetch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprArrayDimFetch)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "[")
|
|
|
|
p.Print(nn.Dim)
|
|
|
|
io.WriteString(p.w, "]")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprArrayItem(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprArrayItem)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Key != nil {
|
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(nn.Val)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprArray(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprArray)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "array(")
|
|
|
|
p.joinPrint(", ", nn.Items)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprBitwiseNot(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBitwiseNot)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "~")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprBooleanNot(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprBooleanNot)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "!")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprClassConstFetch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprClassConstFetch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Class)
|
|
|
|
io.WriteString(p.w, "::")
|
2020-05-17 19:56:32 +00:00
|
|
|
io.WriteString(p.w, string(nn.ConstantName.(*ast.Identifier).Value))
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprClone(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprClone)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "clone ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprClosureUse(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprClosureUse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "use (")
|
|
|
|
p.joinPrint(", ", nn.Uses)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprClosure(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprClosure)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Static {
|
|
|
|
io.WriteString(p.w, "static ")
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "function ")
|
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
|
|
|
io.WriteString(p.w, "&")
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
if nn.ClosureUse != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.ClosureUse)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprConstFetch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprConstFetch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Const)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprEmpty(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprEmpty)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "empty(")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprErrorSuppress(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprErrorSuppress)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "@")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprEval(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprEval)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "eval(")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprExit(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprExit)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2018-07-09 21:51:02 +00:00
|
|
|
if nn.Die {
|
|
|
|
io.WriteString(p.w, "die(")
|
|
|
|
} else {
|
|
|
|
io.WriteString(p.w, "exit(")
|
|
|
|
}
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprFunctionCall(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprFunctionCall)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Function)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprInclude(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprInclude)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "include ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprIncludeOnce(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprIncludeOnce)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "include_once ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprInstanceOf(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprInstanceOf)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, " instanceof ")
|
|
|
|
p.Print(nn.Class)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprIsset(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprIsset)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "isset(")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.joinPrint(", ", nn.Vars)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprList(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprList)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "list(")
|
|
|
|
p.joinPrint(", ", nn.Items)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprMethodCall(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprMethodCall)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "->")
|
|
|
|
p.Print(nn.Method)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprNew(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprNew)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "new ")
|
|
|
|
p.Print(nn.Class)
|
|
|
|
|
|
|
|
if nn.ArgumentList != nil {
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPostDec(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPostDec)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "--")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPostInc(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPostInc)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "++")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPreDec(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPreDec)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "--")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPreInc(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPreInc)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "++")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPrint(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPrint)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "print(")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprPropertyFetch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprPropertyFetch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "->")
|
|
|
|
p.Print(nn.Property)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprReference(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprReference)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "&")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprRequire(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprRequire)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "require ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprRequireOnce(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprRequireOnce)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "require_once ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprShellExec(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprShellExec)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "`")
|
|
|
|
for _, part := range nn.Parts {
|
2018-07-09 19:04:18 +00:00
|
|
|
switch part.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.ScalarEncapsedStringPart:
|
2018-07-09 19:04:18 +00:00
|
|
|
p.Print(part)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "{")
|
|
|
|
p.Print(part)
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
io.WriteString(p.w, "`")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprShortArray(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprShortArray)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "[")
|
|
|
|
p.joinPrint(", ", nn.Items)
|
|
|
|
io.WriteString(p.w, "]")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprShortList(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprShortList)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "[")
|
|
|
|
p.joinPrint(", ", nn.Items)
|
|
|
|
io.WriteString(p.w, "]")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprStaticCall(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprStaticCall)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Class)
|
|
|
|
io.WriteString(p.w, "::")
|
|
|
|
p.Print(nn.Call)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprStaticPropertyFetch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprStaticPropertyFetch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Class)
|
|
|
|
io.WriteString(p.w, "::")
|
|
|
|
p.Print(nn.Property)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprTernary(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprTernary)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Condition)
|
|
|
|
io.WriteString(p.w, " ?")
|
|
|
|
|
|
|
|
if nn.IfTrue != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.IfTrue)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.IfFalse)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprUnaryMinus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprUnaryMinus)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "-")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprUnaryPlus(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprUnaryPlus)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "+")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprVariable(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprVariable)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "$")
|
2018-07-29 08:44:38 +00:00
|
|
|
p.Print(nn.VarName)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprYieldFrom(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprYieldFrom)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "yield from ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printExprYield(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.ExprYield)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "yield ")
|
|
|
|
|
|
|
|
if nn.Key != nil {
|
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(nn.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// smtm
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltElseIf(n ast.Vertex) {
|
2020-09-03 19:18:06 +00:00
|
|
|
nn := n.(*ast.StmtElseIf)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "elseif (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ") :")
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
if s := nn.Stmt.(*ast.StmtStmtList).Stmts; len(s) > 0 {
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printNodes(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltElse(n ast.Vertex) {
|
2020-09-03 19:18:06 +00:00
|
|
|
nn := n.(*ast.StmtElse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "else :")
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
if s := nn.Stmt.(*ast.StmtStmtList).Stmts; len(s) > 0 {
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printNodes(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltForeach(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtAltForeach)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "foreach (")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, " as ")
|
|
|
|
|
|
|
|
if nn.Key != nil {
|
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, ") :\n")
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
s := nn.Stmt.(*ast.StmtStmtList)
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodes(s.Stmts)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "endforeach;")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltIf(n ast.Vertex) {
|
2020-09-03 19:18:06 +00:00
|
|
|
nn := n.(*ast.StmtIf)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "if (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ") :\n")
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
s := nn.Stmt.(*ast.StmtStmtList)
|
2018-07-02 17:48:55 +00:00
|
|
|
p.printNodes(s.Stmts)
|
|
|
|
|
|
|
|
for _, elseif := range nn.ElseIf {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(elseif)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Else != nil {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(nn.Else)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "endif;")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltSwitch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtAltSwitch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "switch (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ") :\n")
|
|
|
|
|
|
|
|
s := nn.CaseList.Cases
|
|
|
|
p.printNodes(s)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "endswitch;")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtBreak(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtBreak)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "break")
|
|
|
|
if nn.Expr != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtCase(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtCase)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "case ")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ":")
|
|
|
|
|
|
|
|
if len(nn.Stmts) > 0 {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtCatch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtCatch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "catch (")
|
|
|
|
p.joinPrint(" | ", nn.Types)
|
|
|
|
io.WriteString(p.w, " ")
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, ") {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtClassMethod(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtClassMethod)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Modifiers != nil {
|
|
|
|
p.joinPrint(" ", nn.Modifiers)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
io.WriteString(p.w, "function ")
|
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
|
|
|
io.WriteString(p.w, "&")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(nn.MethodName)
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "{\n")
|
|
|
|
p.printNodes(s.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
default:
|
|
|
|
p.Print(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtClass(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtClass)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Modifiers != nil {
|
|
|
|
p.joinPrint(" ", nn.Modifiers)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
io.WriteString(p.w, "class")
|
|
|
|
|
|
|
|
if nn.ClassName != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.ClassName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ArgumentList != nil {
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Extends != nil {
|
|
|
|
io.WriteString(p.w, " extends ")
|
|
|
|
p.Print(nn.Extends.ClassName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Implements != nil {
|
|
|
|
io.WriteString(p.w, " implements ")
|
|
|
|
p.joinPrint(", ", nn.Implements.InterfaceNames)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "{\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtClassConstList(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtClassConstList)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Modifiers != nil {
|
|
|
|
p.joinPrint(" ", nn.Modifiers)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
io.WriteString(p.w, "const ")
|
|
|
|
|
|
|
|
p.joinPrint(", ", nn.Consts)
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtConstant(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtConstant)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-08-24 20:28:44 +00:00
|
|
|
p.Print(nn.Name)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtContinue(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtContinue)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "continue")
|
|
|
|
if nn.Expr != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtDeclare(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtDeclare)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "declare(")
|
|
|
|
p.joinPrint(", ", nn.Consts)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtDefault(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtDefault)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "default:")
|
|
|
|
|
|
|
|
if len(nn.Stmts) > 0 {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtDo(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtDo)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "do")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "while (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ");")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtEcho(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtEcho)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "echo ")
|
|
|
|
p.joinPrint(", ", nn.Exprs)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtElseif(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtElseIf)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-09-03 19:18:06 +00:00
|
|
|
if nn.Alt {
|
|
|
|
p.printStmtAltElseIf(nn)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "elseif (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtElse(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtElse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-09-03 19:18:06 +00:00
|
|
|
if nn.Alt {
|
|
|
|
p.printStmtAltElse(nn)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "else")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtExpression(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtExpression)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtFinally(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtFinally)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "finally {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtFor(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtFor)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-09-04 08:37:17 +00:00
|
|
|
if nn.Alt {
|
|
|
|
p.printStmtAltFor(nn)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +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) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 08:37:17 +00:00
|
|
|
func (p *PrettyPrinter) printStmtAltFor(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtFor)
|
|
|
|
|
|
|
|
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.(*ast.StmtStmtList)
|
|
|
|
p.printNodes(s.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
|
|
|
|
io.WriteString(p.w, "endfor;")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtForeach(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtForeach)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "foreach (")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, " as ")
|
|
|
|
|
|
|
|
if nn.Key != nil {
|
|
|
|
p.Print(nn.Key)
|
|
|
|
io.WriteString(p.w, " => ")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtFunction(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtFunction)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "function ")
|
|
|
|
|
|
|
|
if nn.ReturnsRef {
|
|
|
|
io.WriteString(p.w, "&")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Print(nn.FunctionName)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "(")
|
|
|
|
p.joinPrint(", ", nn.Params)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
if nn.ReturnType != nil {
|
|
|
|
io.WriteString(p.w, ": ")
|
|
|
|
p.Print(nn.ReturnType)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtGlobal(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtGlobal)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "global ")
|
|
|
|
p.joinPrint(", ", nn.Vars)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtGoto(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtGoto)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "goto ")
|
|
|
|
p.Print(nn.Label)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtHaltCompiler(n ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "__halt_compiler();")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtIf(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtIf)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-09-03 19:18:06 +00:00
|
|
|
if nn.Alt {
|
|
|
|
p.printStmtAltIf(nn)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "if (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.ElseIf != nil {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth--
|
|
|
|
p.printNodes(nn.ElseIf)
|
|
|
|
p.indentDepth++
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Else != nil {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(nn.Else)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtInlineHTML(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtInlineHtml)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "?>")
|
2020-05-17 19:56:32 +00:00
|
|
|
io.WriteString(p.w, string(nn.Value))
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "<?php")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtInterface(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtInterface)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "interface")
|
|
|
|
|
|
|
|
if nn.InterfaceName != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.InterfaceName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Extends != nil {
|
|
|
|
io.WriteString(p.w, " extends ")
|
|
|
|
p.joinPrint(", ", nn.Extends.InterfaceNames)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "{\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtLabel(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtLabel)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.LabelName)
|
|
|
|
io.WriteString(p.w, ":")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtNamespace(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtNamespace)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "namespace")
|
|
|
|
|
2020-08-24 11:20:20 +00:00
|
|
|
if nn.Name != nil {
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
2020-08-24 11:20:20 +00:00
|
|
|
p.Print(nn.Name)
|
2018-07-02 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Stmts != nil {
|
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
} else {
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtNop(n ast.Vertex) {
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtPropertyList(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtPropertyList)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.joinPrint(" ", nn.Modifiers)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.joinPrint(", ", nn.Properties)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtProperty(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtProperty)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Expr != nil {
|
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtReturn(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtReturn)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "return ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtStaticVar(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtStaticVar)
|
|
|
|
p.Print(nn.Var)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
if nn.Expr != nil {
|
|
|
|
io.WriteString(p.w, " = ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtStatic(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtStatic)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "static ")
|
|
|
|
p.joinPrint(", ", nn.Vars)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtStmtList(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtStmtList)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "{\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtSwitch(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtSwitch)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "switch (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(nn.CaseList.Cases)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtThrow(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtThrow)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "throw ")
|
|
|
|
p.Print(nn.Expr)
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTraitMethodRef(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTraitMethodRef)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Trait)
|
|
|
|
io.WriteString(p.w, "::")
|
|
|
|
p.Print(nn.Method)
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTraitUseAlias(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTraitUseAlias)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Ref)
|
|
|
|
io.WriteString(p.w, " as")
|
|
|
|
|
|
|
|
if nn.Modifier != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Modifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Alias != nil {
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(nn.Alias)
|
|
|
|
}
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTraitUsePrecedence(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTraitUsePrecedence)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
p.Print(nn.Ref)
|
|
|
|
io.WriteString(p.w, " insteadof ")
|
|
|
|
p.joinPrint(", ", nn.Insteadof)
|
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTraitUse(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTraitUse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "use ")
|
|
|
|
p.joinPrint(", ", nn.Traits)
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
if adaptationList, ok := nn.TraitAdaptationList.(*ast.StmtTraitAdaptationList); ok {
|
2018-07-02 17:48:55 +00:00
|
|
|
adaptations := adaptationList.Adaptations
|
|
|
|
io.WriteString(p.w, " {\n")
|
|
|
|
p.printNodes(adaptations)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
} else {
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTrait(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTrait)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "trait ")
|
|
|
|
p.Print(nn.TraitName)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "{\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtTry(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtTry)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "try {\n")
|
|
|
|
p.printNodes(nn.Stmts)
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "}")
|
|
|
|
|
|
|
|
if nn.Catches != nil {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth--
|
|
|
|
p.printNodes(nn.Catches)
|
|
|
|
p.indentDepth++
|
|
|
|
}
|
|
|
|
|
|
|
|
if nn.Finally != nil {
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(nn.Finally)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtUnset(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtUnset)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "unset(")
|
|
|
|
p.joinPrint(", ", nn.Vars)
|
|
|
|
io.WriteString(p.w, ");")
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:22:53 +00:00
|
|
|
func (p *PrettyPrinter) printStmtUse(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtUse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, "use ")
|
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
if nn.Type != nil {
|
|
|
|
p.Print(nn.Type)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
p.joinPrint(", ", nn.UseDeclarations)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
|
|
|
io.WriteString(p.w, ";")
|
|
|
|
}
|
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
func (p *PrettyPrinter) printStmtGroupUse(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtGroupUse)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
io.WriteString(p.w, "use ")
|
2020-08-03 19:22:53 +00:00
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
if nn.Type != nil {
|
|
|
|
p.Print(nn.Type)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
2020-08-03 19:22:53 +00:00
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
p.Print(nn.Prefix)
|
2020-08-03 19:22:53 +00:00
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
io.WriteString(p.w, "\\{")
|
2020-08-03 19:22:53 +00:00
|
|
|
p.joinPrint(", ", nn.UseDeclarations)
|
2020-08-22 13:59:26 +00:00
|
|
|
io.WriteString(p.w, "}")
|
2020-08-03 19:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PrettyPrinter) printStmtUseDeclaration(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtUseDeclaration)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-08-22 13:59:26 +00:00
|
|
|
if nn.Type != nil {
|
|
|
|
p.Print(nn.Type)
|
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(nn.Use)
|
|
|
|
|
|
|
|
if nn.Alias != nil {
|
|
|
|
io.WriteString(p.w, " as ")
|
|
|
|
p.Print(nn.Alias)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 19:56:32 +00:00
|
|
|
func (p *PrettyPrinter) printStmtWhile(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtWhile)
|
2018-07-02 17:48:55 +00:00
|
|
|
|
2020-09-04 07:33:47 +00:00
|
|
|
if nn.Alt {
|
|
|
|
p.printStmtAltWhile(nn)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, "while (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ")")
|
|
|
|
|
|
|
|
switch s := nn.Stmt.(type) {
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtNop:
|
2018-07-02 17:48:55 +00:00
|
|
|
p.Print(s)
|
|
|
|
break
|
2020-05-17 19:56:32 +00:00
|
|
|
case *ast.StmtStmtList:
|
2018-07-02 17:48:55 +00:00
|
|
|
io.WriteString(p.w, " ")
|
|
|
|
p.Print(s)
|
|
|
|
default:
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.indentDepth++
|
|
|
|
p.printIndent()
|
|
|
|
p.Print(s)
|
|
|
|
p.indentDepth--
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 07:33:47 +00:00
|
|
|
|
|
|
|
func (p *PrettyPrinter) printStmtAltWhile(n ast.Vertex) {
|
|
|
|
nn := n.(*ast.StmtWhile)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "while (")
|
|
|
|
p.Print(nn.Cond)
|
|
|
|
io.WriteString(p.w, ") :\n")
|
|
|
|
|
|
|
|
s := nn.Stmt.(*ast.StmtStmtList)
|
|
|
|
p.printNodes(s.Stmts)
|
|
|
|
|
|
|
|
io.WriteString(p.w, "\n")
|
|
|
|
p.printIndent()
|
|
|
|
io.WriteString(p.w, "endwhile;")
|
|
|
|
}
|