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
...@@ -39,8 +39,8 @@ import ( ...@@ -39,8 +39,8 @@ import (
var ( var (
// periodic sync // periodic sync
syncCmd = flag.String("sync", "", "sync command; disabled if empty") syncCmd = flag.String("sync", "", "sync command; disabled if empty")
syncMin = flag.Int("sync_minutes", 0, "sync interval in minutes; disabled if <= 0") syncMin = flag.Int("sync_minutes", 0, "sync interval in minutes; disabled if <= 0")
syncDelay delayTime // actual sync delay in minutes; usually syncDelay == syncMin, but delay may back off exponentially syncDelay delayTime // actual sync delay in minutes; usually syncDelay == syncMin, but delay may back off exponentially
// server control // server control
......
...@@ -11,11 +11,11 @@ type ObjKind int ...@@ -11,11 +11,11 @@ type ObjKind int
// The list of possible Object kinds. // The list of possible Object kinds.
const ( const (
Err ObjKind = iota // object kind unknown (forward reference or error) Err ObjKind = iota // object kind unknown (forward reference or error)
Pkg // package Pkg // package
Con // constant Con // constant
Typ // type Typ // type
Var // variable Var // variable
Fun // function or method Fun // function or method
) )
......
...@@ -28,9 +28,9 @@ var noPos token.Position ...@@ -28,9 +28,9 @@ var noPos token.Position
// //
const ( const (
PackageClauseOnly uint = 1 << iota // parsing stops after package clause PackageClauseOnly uint = 1 << iota // parsing stops after package clause
ImportsOnly // parsing stops after import declarations ImportsOnly // parsing stops after import declarations
ParseComments // parse comments and add them to AST ParseComments // parse comments and add them to AST
Trace // print a trace of parsed productions Trace // print a trace of parsed productions
) )
......
...@@ -85,10 +85,10 @@ type exprListMode uint ...@@ -85,10 +85,10 @@ type exprListMode uint
const ( const (
blankStart exprListMode = 1 << iota // print a blank before a non-empty list blankStart exprListMode = 1 << iota // print a blank before a non-empty list
blankEnd // print a blank after a non-empty list blankEnd // print a blank after a non-empty list
commaSep // elements are separated by commas commaSep // elements are separated by commas
commaTerm // list is optionally terminated by a comma commaTerm // list is optionally terminated by a comma
noIndent // no extra indentation in multi-line lists noIndent // no extra indentation in multi-line lists
) )
...@@ -1105,11 +1105,6 @@ const ( ...@@ -1105,11 +1105,6 @@ const (
// multiLine to true if the spec spans multiple lines. // multiLine to true if the spec spans multiple lines.
// //
func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, multiLine *bool) { 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) { switch s := spec.(type) {
case *ast.ImportSpec: case *ast.ImportSpec:
p.setComment(s.Doc) p.setComment(s.Doc)
...@@ -1118,7 +1113,7 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m ...@@ -1118,7 +1113,7 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(blank) p.print(blank)
} }
p.expr(s.Path, multiLine) p.expr(s.Path, multiLine)
comment = s.Comment p.setComment(s.Comment)
case *ast.ValueSpec: case *ast.ValueSpec:
p.setComment(s.Doc) p.setComment(s.Doc)
...@@ -1132,23 +1127,27 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m ...@@ -1132,23 +1127,27 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(blank, token.ASSIGN) p.print(blank, token.ASSIGN)
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos) p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
} }
p.setComment(s.Comment)
} else { } else {
extraTabs = 2 extraTabs := 3
if s.Type != nil || s.Values != nil {
p.print(vtab)
}
if s.Type != nil { if s.Type != nil {
p.print(vtab)
p.expr(s.Type, multiLine) p.expr(s.Type, multiLine)
extraTabs = 1 extraTabs--
} }
if s.Values != nil { if s.Values != nil {
p.print(vtab) p.print(vtab, token.ASSIGN)
p.print(token.ASSIGN)
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos) 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: case *ast.TypeSpec:
p.setComment(s.Doc) p.setComment(s.Doc)
...@@ -1159,18 +1158,11 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m ...@@ -1159,18 +1158,11 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
p.print(vtab) p.print(vtab)
} }
p.expr(s.Type, multiLine) p.expr(s.Type, multiLine)
comment = s.Comment p.setComment(s.Comment)
default: default:
panic("unreachable") panic("unreachable")
} }
if comment != nil {
for ; extraTabs > 0; extraTabs-- {
p.print(vtab)
}
p.setComment(comment)
}
} }
......
...@@ -932,9 +932,9 @@ func (p *trimmer) Write(data []byte) (n int, err os.Error) { ...@@ -932,9 +932,9 @@ func (p *trimmer) Write(data []byte) (n int, err os.Error) {
// General printing is controlled with these Config.Mode flags. // General printing is controlled with these Config.Mode flags.
const ( const (
GenHTML uint = 1 << iota // generate HTML GenHTML uint = 1 << iota // generate HTML
RawFormat // do not use a tabwriter; if set, UseSpaces is ignored RawFormat // do not use a tabwriter; if set, UseSpaces is ignored
TabIndent // use tabs for indentation independent of UseSpaces TabIndent // use tabs for indentation independent of UseSpaces
UseSpaces // use spaces instead of tabs for alignment UseSpaces // use spaces instead of tabs for alignment
) )
......
...@@ -11,9 +11,38 @@ import "fmt" // fmt ...@@ -11,9 +11,38 @@ import "fmt" // fmt
const c0 = 0 // zero const c0 = 0 // zero
const ( const (
c1 = iota // c1 c1 = iota // c1
c2 // c2 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. // The SZ struct; it is empty.
type SZ struct{} type SZ struct{}
......
...@@ -14,6 +14,35 @@ const ( ...@@ -14,6 +14,35 @@ const (
c2 // c2 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. // The SZ struct; it is empty.
type SZ struct {} type SZ struct {}
......
...@@ -282,11 +282,11 @@ func _() { ...@@ -282,11 +282,11 @@ func _() {
) )
// some entries have a type // some entries have a type
const ( const (
xxxxxx = 1 xxxxxx = 1
x = 2 x = 2
xxx = 3 xxx = 3
yyyyyyyy float = iota yyyyyyyy float = iota
yyyy = "bar" yyyy = "bar"
yyy yyy
yy = 2 yy = 2
) )
...@@ -316,15 +316,15 @@ func _() { ...@@ -316,15 +316,15 @@ func _() {
xxx string xxx string
yyyyyyyy int = 1234 yyyyyyyy int = 1234
y float = 3.14 y float = 3.14
yyyy = "bar" yyyy = "bar"
yyy string = "foo" yyy string = "foo"
) )
// mixed entries - all comments should be aligned // mixed entries - all comments should be aligned
var ( var (
a, b, c int a, b, c int
x = 10 x = 10
d int // comment d int // comment
y = 20 // comment y = 20 // comment
f, ff, fff, ffff int = 0, 1, 2, 3 // comment f, ff, fff, ffff int = 0, 1, 2, 3 // comment
) )
// respect original line breaks // respect original line breaks
......
...@@ -289,12 +289,12 @@ func _() { ...@@ -289,12 +289,12 @@ func _() {
// Alignment after overlong lines // Alignment after overlong lines
const ( const (
_ = "991" _ = "991"
_ = "2432902008176640000" // 20! _ = "2432902008176640000" // 20!
_ = "933262154439441526816992388562667004907159682643816214685929" + _ = "933262154439441526816992388562667004907159682643816214685929" +
"638952175999932299156089414639761565182862536979208272237582" + "638952175999932299156089414639761565182862536979208272237582" +
"51185210916864000000000000000000000000" // 100! "51185210916864000000000000000000000000" // 100!
_ = "170141183460469231731687303715884105727" // prime _ = "170141183460469231731687303715884105727" // prime
) )
......
...@@ -112,8 +112,8 @@ func (p ErrorList) String() string { ...@@ -112,8 +112,8 @@ func (p ErrorList) String() string {
// //
const ( const (
Raw = iota // leave error list unchanged Raw = iota // leave error list unchanged
Sorted // sort error list by file, line, and column number Sorted // sort error list by file, line, and column number
NoMultiples // sort error list and leave only the first error per line NoMultiples // sort error list and leave only the first error per line
) )
......
...@@ -76,8 +76,8 @@ func (S *Scanner) next() { ...@@ -76,8 +76,8 @@ func (S *Scanner) next() {
// //
const ( const (
ScanComments = 1 << iota // return comments as COMMENT tokens ScanComments = 1 << iota // return comments as COMMENT tokens
AllowIllegalChars // do not report an error for illegal chars AllowIllegalChars // do not report an error for illegal chars
InsertSemis // automatically insert semicolons InsertSemis // automatically insert semicolons
) )
......
...@@ -30,10 +30,10 @@ const ( ...@@ -30,10 +30,10 @@ const (
// described in the comments). A colon appears after these items: // described in the comments). A colon appears after these items:
// 2009/0123 01:23:23.123123 /a/b/c/d.go:23: message // 2009/0123 01:23:23.123123 /a/b/c/d.go:23: message
Ldate = 1 << iota // the date: 2009/0123 Ldate = 1 << iota // the date: 2009/0123
Ltime // the time: 01:23:23 Ltime // the time: 01:23:23
Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime.
Llongfile // full file name and line number: /a/b/c/d.go:23 Llongfile // full file name and line number: /a/b/c/d.go:23
Lshortfile // final file name element and line number: d.go:23. overrides Llongfile Lshortfile // final file name element and line number: d.go:23. overrides Llongfile
lAllBits = Ldate | Ltime | Lmicroseconds | Llongfile | Lshortfile lAllBits = Ldate | Ltime | Lmicroseconds | Llongfile | Lshortfile
) )
......
...@@ -197,7 +197,7 @@ func initNorm() (testKn []uint32, testWn, testFn []float32) { ...@@ -197,7 +197,7 @@ func initNorm() (testKn []uint32, testWn, testFn []float32) {
const m1 = 1 << 31 const m1 = 1 << 31
var ( var (
dn float64 = rn dn float64 = rn
tn = dn tn = dn
vn float64 = 9.91256303526217e-3 vn float64 = 9.91256303526217e-3
) )
...@@ -226,7 +226,7 @@ func initExp() (testKe []uint32, testWe, testFe []float32) { ...@@ -226,7 +226,7 @@ func initExp() (testKe []uint32, testWe, testFe []float32) {
const m2 = 1 << 32 const m2 = 1 << 32
var ( var (
de float64 = re de float64 = re
te = de te = de
ve float64 = 3.9496598225815571993e-3 ve float64 = 3.9496598225815571993e-3
) )
......
...@@ -82,17 +82,17 @@ type Regexp struct { ...@@ -82,17 +82,17 @@ type Regexp struct {
const ( const (
_START = iota // beginning of program _START = iota // beginning of program
_END // end of program: success _END // end of program: success
_BOT // '^' beginning of text _BOT // '^' beginning of text
_EOT // '$' end of text _EOT // '$' end of text
_CHAR // 'a' regular character _CHAR // 'a' regular character
_CHARCLASS // [a-z] character class _CHARCLASS // [a-z] character class
_ANY // '.' any character including newline _ANY // '.' any character including newline
_NOTNL // [^\n] special case: any character but newline _NOTNL // [^\n] special case: any character but newline
_BRA // '(' parenthesized expression _BRA // '(' parenthesized expression
_EBRA // ')'; end of '(' parenthesized expression _EBRA // ')'; end of '(' parenthesized expression
_ALT // '|' alternation _ALT // '|' alternation
_NOP // do nothing; makes it easy to link without patching _NOP // do nothing; makes it easy to link without patching
) )
// --- START start of program // --- START start of program
......
...@@ -164,9 +164,9 @@ type SliceType struct { ...@@ -164,9 +164,9 @@ type SliceType struct {
type ChanDir int type ChanDir int
const ( const (
RecvDir ChanDir = 1 << iota // <-chan RecvDir ChanDir = 1 << iota // <-chan
SendDir // chan<- SendDir // chan<-
BothDir = RecvDir | SendDir // chan BothDir = RecvDir | SendDir // chan
) )
// ChanType represents a channel type. // ChanType represents a channel type.
......
...@@ -77,17 +77,17 @@ type Regexp struct { ...@@ -77,17 +77,17 @@ type Regexp struct {
const ( const (
_START = iota // beginning of program _START = iota // beginning of program
_END // end of program: success _END // end of program: success
_BOT // '^' beginning of text _BOT // '^' beginning of text
_EOT // '$' end of text _EOT // '$' end of text
_CHAR // 'a' regular character _CHAR // 'a' regular character
_CHARCLASS // [a-z] character class _CHARCLASS // [a-z] character class
_ANY // '.' any character including newline _ANY // '.' any character including newline
_NOTNL // [^\n] special case: any character but newline _NOTNL // [^\n] special case: any character but newline
_BRA // '(' parenthesized expression _BRA // '(' parenthesized expression
_EBRA // ')'; end of '(' parenthesized expression _EBRA // ')'; end of '(' parenthesized expression
_ALT // '|' alternation _ALT // '|' alternation
_NOP // do nothing; makes it easy to link without patching _NOP // do nothing; makes it easy to link without patching
) )
// --- START start of program // --- START start of program
......
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