2020-04-10 05:20:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
|
|
|
)
|
|
|
|
|
2020-04-12 02:42:01 +00:00
|
|
|
func normaliseAltCb(n_ *node.Node) error {
|
2020-04-10 05:20:54 +00:00
|
|
|
|
2020-04-10 05:37:59 +00:00
|
|
|
switch n := (*n_).(type) {
|
2020-04-10 05:20:54 +00:00
|
|
|
case *stmt.AltIf:
|
|
|
|
// Build replacement node
|
|
|
|
ifStmt := stmt.NewIf(n.Cond, n.Stmt, n.ElseIf, n.Else)
|
|
|
|
ifStmt.FreeFloating = n.FreeFloating
|
|
|
|
ifStmt.Position = n.Position
|
|
|
|
// ifStmt has no .Attributes prop
|
2020-04-10 05:37:59 +00:00
|
|
|
|
|
|
|
*n_ = ifStmt
|
2020-04-10 05:20:54 +00:00
|
|
|
|
|
|
|
case *stmt.AltElse:
|
|
|
|
elseStmt := stmt.NewElse(n.Stmt)
|
|
|
|
elseStmt.FreeFloating = n.FreeFloating
|
|
|
|
elseStmt.Position = n.Position
|
2020-04-10 05:37:59 +00:00
|
|
|
|
|
|
|
*n_ = elseStmt
|
2020-04-10 05:20:54 +00:00
|
|
|
|
|
|
|
case *stmt.AltElseIf:
|
|
|
|
elifStmt := stmt.NewElseIf(n.Cond, n.Stmt)
|
|
|
|
elifStmt.FreeFloating = n.FreeFloating
|
|
|
|
elifStmt.Position = n.Position
|
|
|
|
|
2020-04-10 05:37:59 +00:00
|
|
|
*n_ = elifStmt
|
2020-04-10 05:20:54 +00:00
|
|
|
|
2020-04-15 07:14:06 +00:00
|
|
|
case *stmt.AltFor:
|
|
|
|
forStmt := stmt.NewFor(n.Init, n.Cond, n.Loop, n.Stmt)
|
|
|
|
forStmt.FreeFloating = n.FreeFloating
|
|
|
|
forStmt.Position = n.Position
|
|
|
|
|
|
|
|
*n_ = forStmt
|
|
|
|
|
|
|
|
case *stmt.AltForeach:
|
|
|
|
feStmt := stmt.NewForeach(n.Expr, n.Key, n.Variable, n.Stmt)
|
|
|
|
feStmt.FreeFloating = n.FreeFloating
|
|
|
|
feStmt.Position = n.Position
|
|
|
|
|
|
|
|
*n_ = feStmt
|
|
|
|
|
|
|
|
case *stmt.AltSwitch:
|
|
|
|
swStmt := stmt.NewSwitch(n.Cond, n.CaseList)
|
|
|
|
swStmt.FreeFloating = n.FreeFloating
|
|
|
|
swStmt.Position = n.Position
|
|
|
|
|
|
|
|
*n_ = swStmt
|
|
|
|
|
|
|
|
case *stmt.AltWhile:
|
|
|
|
wStmt := stmt.NewWhile(n.Cond, n.Stmt)
|
|
|
|
wStmt.FreeFloating = n.FreeFloating
|
|
|
|
wStmt.Position = n.Position
|
|
|
|
|
|
|
|
*n_ = wStmt
|
|
|
|
|
2020-04-10 05:20:54 +00:00
|
|
|
default:
|
2020-04-12 02:42:01 +00:00
|
|
|
// no change
|
2020-04-10 05:20:54 +00:00
|
|
|
}
|
2020-04-12 02:42:01 +00:00
|
|
|
|
|
|
|
return nil // always
|
2020-04-10 05:20:54 +00:00
|
|
|
}
|