Commit 53f3d073 authored by Robert Griesemer's avatar Robert Griesemer

gofmt: more consistent formatting of const/var decls

- gofmt -w src misc
- only manually modified file: src/pkg/go/printer/nodes.go

R=rsc
CC=golang-dev, r
https://golang.org/cl/606041
parent 74fac99d
......@@ -1105,11 +1105,6 @@ const (
// multiLine to true if the spec spans multiple lines.
//
func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, multiLine *bool) {
var (
comment *ast.CommentGroup // a line comment, if any
extraTabs int // number of extra tabs before comment, if any
)
switch s := spec.(type) {
case *ast.ImportSpec:
p.setComment(s.Doc)
......@@ -1118,7 +1113,7 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(blank)
}
p.expr(s.Path, multiLine)
comment = s.Comment
p.setComment(s.Comment)
case *ast.ValueSpec:
p.setComment(s.Doc)
......@@ -1132,23 +1127,27 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(blank, token.ASSIGN)
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
}
p.setComment(s.Comment)
} else {
extraTabs = 2
if s.Type != nil || s.Values != nil {
p.print(vtab)
}
extraTabs := 3
if s.Type != nil {
p.print(vtab)
p.expr(s.Type, multiLine)
extraTabs = 1
extraTabs--
}
if s.Values != nil {
p.print(vtab)
p.print(token.ASSIGN)
p.print(vtab, token.ASSIGN)
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
extraTabs = 0
extraTabs--
}
if s.Comment != nil {
for ; extraTabs > 0; extraTabs-- {
p.print(vtab)
}
p.setComment(s.Comment)
}
}
comment = s.Comment
case *ast.TypeSpec:
p.setComment(s.Doc)
......@@ -1159,18 +1158,11 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(vtab)
}
p.expr(s.Type, multiLine)
comment = s.Comment
p.setComment(s.Comment)
default:
panic("unreachable")
}
if comment != nil {
for ; extraTabs > 0; extraTabs-- {
p.print(vtab)
}
p.setComment(comment)
}
}
......
......@@ -14,6 +14,35 @@ const (
c2 // c2
)
// Alignment of comments in declarations>
const (
_ T = iota // comment
_ // comment
_ // comment
_ = iota + 10
_ // comments
_ = 10 // comment
_ T = 20 // comment
)
const (
_____ = iota // foo
_ // bar
_ = 0 // bal
_ // bat
)
const (
_ T = iota // comment
_ // comment
_ // comment
_ = iota + 10
_ // comment
_ = 10
_ = 20 // comment
_ T = 0 // comment
)
// The SZ struct; it is empty.
type SZ struct{}
......
......@@ -14,6 +14,35 @@ const (
c2 // c2
)
// Alignment of comments in declarations>
const (
_ T = iota // comment
_ // comment
_ // comment
_ = iota+10
_ // comments
_ = 10 // comment
_ T = 20 // comment
)
const (
_____ = iota // foo
_ // bar
_ = 0 // bal
_ // bat
)
const (
_ T = iota // comment
_ // comment
_ // comment
_ = iota + 10
_ // comment
_ = 10
_ = 20 // comment
_ T = 0 // comment
)
// The SZ struct; it is empty.
type SZ struct {}
......
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