go.tools/oracle: address reviewer suggestions from CL 9502043
(I made these changes in the wrong workspace.) R=crawshaw CC=golang-dev https://golang.org/cl/13328044
This commit is contained in:
parent
b43fa6fbda
commit
a483497cf1
|
|
@ -87,7 +87,7 @@ func Main(args []string, mode, pos string, ptalog, out io.Writer, buildContext *
|
||||||
if mode == "" {
|
if mode == "" {
|
||||||
return errors.New("You must specify a -mode to perform.")
|
return errors.New("You must specify a -mode to perform.")
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Invalid mode type '%s'.", mode)
|
return fmt.Errorf("Invalid mode type: %q.", mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var loader importer.SourceLoader
|
var loader importer.SourceLoader
|
||||||
|
|
|
||||||
|
|
@ -21,22 +21,10 @@ import (
|
||||||
// or the implicit receive in "for v := range ch".
|
// or the implicit receive in "for v := range ch".
|
||||||
//
|
//
|
||||||
func peers(o *oracle) (queryResult, error) {
|
func peers(o *oracle) (queryResult, error) {
|
||||||
// Determine the enclosing send/receive op for the specified position.
|
arrowPos := findArrow(o)
|
||||||
var arrowPos token.Pos
|
if arrowPos == token.NoPos {
|
||||||
for _, n := range o.queryPath {
|
|
||||||
switch n := n.(type) {
|
|
||||||
case *ast.UnaryExpr:
|
|
||||||
if n.Op == token.ARROW {
|
|
||||||
arrowPos = n.OpPos
|
|
||||||
goto found
|
|
||||||
}
|
|
||||||
case *ast.SendStmt:
|
|
||||||
arrowPos = n.Arrow
|
|
||||||
goto found
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, o.errorf(o.queryPath[0], "there is no send/receive here")
|
return nil, o.errorf(o.queryPath[0], "there is no send/receive here")
|
||||||
found:
|
}
|
||||||
|
|
||||||
buildSSA(o)
|
buildSSA(o)
|
||||||
|
|
||||||
|
|
@ -90,6 +78,23 @@ found:
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findArrow returns the position of the enclosing send/receive op
|
||||||
|
// (<-) for the query position, or token.NoPos if not found.
|
||||||
|
//
|
||||||
|
func findArrow(o *oracle) token.Pos {
|
||||||
|
for _, n := range o.queryPath {
|
||||||
|
switch n := n.(type) {
|
||||||
|
case *ast.UnaryExpr:
|
||||||
|
if n.Op == token.ARROW {
|
||||||
|
return n.OpPos
|
||||||
|
}
|
||||||
|
case *ast.SendStmt:
|
||||||
|
return n.Arrow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token.NoPos
|
||||||
|
}
|
||||||
|
|
||||||
// chanOp abstracts an ssa.Send, ssa.Unop(ARROW), or a SelectState.
|
// chanOp abstracts an ssa.Send, ssa.Unop(ARROW), or a SelectState.
|
||||||
type chanOp struct {
|
type chanOp struct {
|
||||||
ch ssa.Value
|
ch ssa.Value
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue