cmd/vet: remove dependency on go/ast/astutil
This package was only imported for the trivial Unparen function. Change-Id: I0ead916a7fdb469a26b4fe99c6964a8ed1438c49 Reviewed-on: https://go-review.googlesource.com/8566 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
0770aced4f
commit
48e2a5be44
|
@ -9,8 +9,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
|
||||||
"golang.org/x/tools/go/ast/astutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -164,7 +162,7 @@ func hasSideEffects(e ast.Expr) bool {
|
||||||
// split returns []{d, c, b, a}.
|
// split returns []{d, c, b, a}.
|
||||||
func (op boolOp) split(e ast.Expr) (exprs []ast.Expr) {
|
func (op boolOp) split(e ast.Expr) (exprs []ast.Expr) {
|
||||||
for {
|
for {
|
||||||
e = astutil.Unparen(e)
|
e = unparen(e)
|
||||||
if b, ok := e.(*ast.BinaryExpr); ok && b.Op == op.tok {
|
if b, ok := e.(*ast.BinaryExpr); ok && b.Op == op.tok {
|
||||||
exprs = append(exprs, op.split(b.Y)...)
|
exprs = append(exprs, op.split(b.Y)...)
|
||||||
e = b.X
|
e = b.X
|
||||||
|
@ -175,3 +173,14 @@ func (op boolOp) split(e ast.Expr) (exprs []ast.Expr) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unparen returns e with any enclosing parentheses stripped.
|
||||||
|
func unparen(e ast.Expr) ast.Expr {
|
||||||
|
for {
|
||||||
|
p, ok := e.(*ast.ParenExpr)
|
||||||
|
if !ok {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
e = p.X
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue