Golang go/ast.DeferStmt type, End() and Pos() functions examples

package go/ast

A DeferStmt node represents a defer statement.

Golang go/ast.DeferStmt type, End() and Pos() functions examples

Example 1:

 func NodeDescription(n ast.Node) string {
 switch n := n.(type) {
 case *ast.ArrayType:
 return "array type"
 case *ast.AssignStmt:
 return "assignment"
 case *ast.DeferStmt:
 return "defer statement"
 ...
 }

Example 2:

 func checkCurrentPosition(node ast.Node) string {
 n := node.(*ast.DeferStmt)
 endpos := n.End()
 pospos := n.Pos()

 if pospos != endpos {
 return "not yet"
 }
 }

References :

http://golang.org/pkg/go/ast/#DeferStmt

http://golang.org/pkg/go/ast/#DeferStmt.End

http://golang.org/pkg/go/ast/#DeferStmt.Pos

Advertisement