1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:44:46 -07:00

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:
Alan Donovan 2013-08-29 21:36:59 -04:00
parent b43fa6fbda
commit a483497cf1
2 changed files with 21 additions and 16 deletions

View File

@ -87,7 +87,7 @@ func Main(args []string, mode, pos string, ptalog, out io.Writer, buildContext *
if mode == "" {
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

View File

@ -21,22 +21,10 @@ import (
// or the implicit receive in "for v := range ch".
//
func peers(o *oracle) (queryResult, error) {
// Determine the enclosing send/receive op for the specified position.
var arrowPos token.Pos
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
}
}
arrowPos := findArrow(o)
if arrowPos == token.NoPos {
return nil, o.errorf(o.queryPath[0], "there is no send/receive here")
found:
}
buildSSA(o)
@ -90,6 +78,23 @@ found:
}, 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.
type chanOp struct {
ch ssa.Value