2017-12-18 22:55:57 +00:00
|
|
|
package stmt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/token"
|
|
|
|
)
|
|
|
|
|
2017-12-27 23:23:32 +00:00
|
|
|
func (n AltIf) Name() string {
|
2017-12-27 17:55:58 +00:00
|
|
|
return "AltIf"
|
|
|
|
}
|
|
|
|
|
2017-12-18 22:55:57 +00:00
|
|
|
type AltIf struct {
|
2017-12-27 23:23:32 +00:00
|
|
|
name string
|
|
|
|
token token.Token
|
|
|
|
cond node.Node
|
|
|
|
stmt node.Node
|
|
|
|
elseIf []node.Node
|
|
|
|
_else node.Node
|
2017-12-18 22:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewAltIf(token token.Token, cond node.Node, stmt node.Node) node.Node {
|
|
|
|
return AltIf{
|
2017-12-27 17:55:58 +00:00
|
|
|
"AltIf",
|
|
|
|
token,
|
|
|
|
cond,
|
|
|
|
stmt,
|
|
|
|
nil,
|
|
|
|
nil,
|
2017-12-18 22:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-27 23:23:32 +00:00
|
|
|
func (n AltIf) AddElseIf(elseIf node.Node) node.Node {
|
|
|
|
if n.elseIf == nil {
|
|
|
|
n.elseIf = make([]node.Node, 0)
|
2017-12-18 22:55:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 23:23:32 +00:00
|
|
|
n.elseIf = append(n.elseIf, elseIf)
|
2017-12-18 22:55:57 +00:00
|
|
|
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n AltIf) SetElse(_else node.Node) node.Node {
|
|
|
|
n._else = _else
|
|
|
|
|
|
|
|
return n
|
|
|
|
}
|
2017-12-27 17:55:58 +00:00
|
|
|
|
2017-12-27 23:23:32 +00:00
|
|
|
func (n AltIf) Walk(v node.Visitor) {
|
|
|
|
if v.Visit(n) == false {
|
|
|
|
return
|
|
|
|
}
|
2017-12-27 17:55:58 +00:00
|
|
|
|
|
|
|
if n.cond != nil {
|
2017-12-27 23:23:32 +00:00
|
|
|
vv := v.Children("cond")
|
|
|
|
n.cond.Walk(vv)
|
2017-12-27 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if n.stmt != nil {
|
2017-12-27 23:23:32 +00:00
|
|
|
vv := v.Children("stmt")
|
|
|
|
n.stmt.Walk(vv)
|
2017-12-27 17:55:58 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 23:23:32 +00:00
|
|
|
if n.elseIf != nil {
|
|
|
|
vv := v.Children("elseIf")
|
|
|
|
for _, nn := range n.elseIf {
|
|
|
|
nn.Walk(vv)
|
2017-12-27 17:55:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-27 23:23:32 +00:00
|
|
|
|
2017-12-27 17:55:58 +00:00
|
|
|
if n._else != nil {
|
2017-12-27 23:23:32 +00:00
|
|
|
vv := v.Children("else")
|
|
|
|
n._else.Walk(vv)
|
2017-12-27 17:55:58 +00:00
|
|
|
}
|
|
|
|
}
|