diff options
author | Robert Griesemer <gri@golang.org> | 2011-03-15 17:45:16 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2011-03-15 17:45:16 -0700 |
commit | bcd6c733b2f0f83d72b938150ea67bde0af97e4f (patch) | |
tree | a19876ebf59212bd2d9b3497a970cebbf40a8d69 | |
parent | 0463bd6cd73d72537e819b0fec9867fe915a8e02 (diff) | |
download | go-bcd6c733b2f0f83d72b938150ea67bde0af97e4f.tar.gz go-bcd6c733b2f0f83d72b938150ea67bde0af97e4f.zip |
go/printer: output tuning for gofix
If braces don't have position information for a composite
literal, don't assume alignment of key:value pairs under
the (wrong) assumption that there may be multiple lines.
R=rsc
CC=golang-dev
https://golang.org/cl/4297043
-rw-r--r-- | src/pkg/go/printer/nodes.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index 7933c2f182..8ccd63612a 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -204,17 +204,21 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp // the key and the node size into the decision process useFF := true - // determine size + // determine element size: all bets are off if we don't have + // position information for the previous and next token (likely + // generated code - simply ignore the size in this case by setting + // it to 0) prevSize := size const infinity = 1e6 // larger than any source line size = p.nodeSize(x, infinity) pair, isPair := x.(*ast.KeyValueExpr) - if size <= infinity { + if size <= infinity && prev.IsValid() && next.IsValid() { // x fits on a single line if isPair { size = p.nodeSize(pair.Key, infinity) // size <= infinity } } else { + // size too large or we don't have good layout information size = 0 } @@ -244,7 +248,6 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp // lines are broken using newlines so comments remain aligned // unless forceFF is set or there are multiple expressions on // the same line in which case formfeed is used - // broken with a formfeed if p.linebreak(line, linebreakMin, ws, useFF || prevBreak+1 < i) { ws = ignore *multiLine = true |