Commit bcd6c733 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 0463bd6c
...@@ -204,17 +204,21 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp ...@@ -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 // the key and the node size into the decision process
useFF := true 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 prevSize := size
const infinity = 1e6 // larger than any source line const infinity = 1e6 // larger than any source line
size = p.nodeSize(x, infinity) size = p.nodeSize(x, infinity)
pair, isPair := x.(*ast.KeyValueExpr) pair, isPair := x.(*ast.KeyValueExpr)
if size <= infinity { if size <= infinity && prev.IsValid() && next.IsValid() {
// x fits on a single line // x fits on a single line
if isPair { if isPair {
size = p.nodeSize(pair.Key, infinity) // size <= infinity size = p.nodeSize(pair.Key, infinity) // size <= infinity
} }
} else { } else {
// size too large or we don't have good layout information
size = 0 size = 0
} }
...@@ -244,7 +248,6 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp ...@@ -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 // lines are broken using newlines so comments remain aligned
// unless forceFF is set or there are multiple expressions on // unless forceFF is set or there are multiple expressions on
// the same line in which case formfeed is used // the same line in which case formfeed is used
// broken with a formfeed
if p.linebreak(line, linebreakMin, ws, useFF || prevBreak+1 < i) { if p.linebreak(line, linebreakMin, ws, useFF || prevBreak+1 < i) {
ws = ignore ws = ignore
*multiLine = true *multiLine = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment