You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gosuv/vendor/github.com/gopherjs/gopherjs/compiler/analysis/break.go

33 lines
558 B

package analysis
import (
"go/ast"
"go/token"
)
func HasBreak(n ast.Node) bool {
v := hasBreakVisitor{}
ast.Walk(&v, n)
return v.hasBreak
}
type hasBreakVisitor struct {
hasBreak bool
}
func (v *hasBreakVisitor) Visit(node ast.Node) (w ast.Visitor) {
if v.hasBreak {
return nil
}
switch n := node.(type) {
case *ast.BranchStmt:
if n.Tok == token.BREAK && n.Label == nil {
v.hasBreak = true
return nil
}
case *ast.ForStmt, *ast.RangeStmt, *ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.SelectStmt, ast.Expr:
return nil
}
return v
}