From a483497cf1fa1b73664a32c5e60fad477379a747 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 29 Aug 2013 21:36:59 -0400 Subject: [PATCH] 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 --- oracle/oracle.go | 2 +- oracle/peers.go | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/oracle/oracle.go b/oracle/oracle.go index c1e2ca20..37f95ccb 100644 --- a/oracle/oracle.go +++ b/oracle/oracle.go @@ -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 diff --git a/oracle/peers.go b/oracle/peers.go index d27dce98..cae7e461 100644 --- a/oracle/peers.go +++ b/oracle/peers.go @@ -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") } - 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