php-parser/node/stmt/function.go

59 lines
1.2 KiB
Go
Raw Normal View History

2017-12-07 16:39:34 +00:00
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
2017-12-27 17:55:58 +00:00
func(n Function) Name() string {
return "Function"
}
2017-12-07 16:39:34 +00:00
type Function struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-07 16:39:34 +00:00
token token.Token
isReturnRef bool
params []node.Node
returnType node.Node
stmts []node.Node
}
func NewFunction(token token.Token, isReturnRef bool, params []node.Node, returnType node.Node, stmts []node.Node) node.Node {
return Function{
2017-12-27 17:55:58 +00:00
"Function",
2017-12-07 16:39:34 +00:00
token,
isReturnRef,
params,
returnType,
stmts,
}
}
func (n Function) Print(out io.Writer, indent string) {
2017-12-27 17:55:58 +00:00
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value)
2017-12-07 16:39:34 +00:00
fmt.Fprintf(out, "\n%vreturn ref: %t", indent+" ", n.isReturnRef)
if n.params != nil {
fmt.Fprintf(out, "\n%vparams:", indent+" ")
for _, nn := range n.params {
nn.Print(out, indent+" ")
}
}
if n.returnType != nil {
fmt.Fprintf(out, "\n%vreturn type:", indent+" ")
n.returnType.Print(out, indent+" ")
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
}
}