php-parser/node/expr/closure.go

68 lines
1.3 KiB
Go
Raw Normal View History

2017-12-16 20:45:05 +00:00
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
2017-12-27 17:55:58 +00:00
func (n Closure) Name() string {
return "Closure"
}
2017-12-16 20:45:05 +00:00
type Closure struct {
2017-12-27 17:55:58 +00:00
name string
2017-12-16 20:45:05 +00:00
params []node.Node
uses []node.Node
returnType node.Node
stmts []node.Node
isReturnRef bool
isStatic bool
}
func NewClosure(params []node.Node, uses []node.Node, returnType node.Node, stmts []node.Node, isStatic bool, isReturnRef bool) node.Node {
return Closure{
2017-12-27 17:55:58 +00:00
"Closure",
2017-12-16 20:45:05 +00:00
params,
uses,
returnType,
stmts,
isReturnRef,
isStatic,
}
}
func (n Closure) Print(out io.Writer, indent string) {
2017-12-27 17:55:58 +00:00
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.name)
2017-12-16 20:45:05 +00:00
fmt.Fprintf(out, "\n%vis static: %t", indent+" ", n.isStatic)
fmt.Fprintf(out, "\n%vis return 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.uses != nil {
fmt.Fprintf(out, "\n%vuses:", indent+" ")
for _, nn := range n.uses {
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+" ")
}
}
}