diff options
author | Robert Griesemer <gri@golang.org> | 2010-03-16 16:45:54 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2010-03-16 16:45:54 -0700 |
commit | 415f42078b59ba05f26ecd34a94a9dee8d6a604c (patch) | |
tree | 0f252e0f7443fd1cc8d8101f5b780a26b5f756b9 /src/pkg/go | |
parent | 9460e8b0f8eb51248726193c2807b9229c4f269f (diff) | |
download | golang-415f42078b59ba05f26ecd34a94a9dee8d6a604c.tar.gz |
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
http://codereview.appspot.com/606041
Diffstat (limited to 'src/pkg/go')
-rw-r--r-- | src/pkg/go/ast/scope.go | 10 | ||||
-rw-r--r-- | src/pkg/go/parser/parser.go | 6 | ||||
-rw-r--r-- | src/pkg/go/printer/nodes.go | 46 | ||||
-rw-r--r-- | src/pkg/go/printer/printer.go | 6 | ||||
-rw-r--r-- | src/pkg/go/printer/testdata/comments.golden | 31 | ||||
-rw-r--r-- | src/pkg/go/printer/testdata/comments.input | 29 | ||||
-rw-r--r-- | src/pkg/go/printer/testdata/declarations.golden | 16 | ||||
-rw-r--r-- | src/pkg/go/printer/testdata/expressions.raw | 8 | ||||
-rw-r--r-- | src/pkg/go/scanner/errors.go | 4 | ||||
-rw-r--r-- | src/pkg/go/scanner/scanner.go | 4 |
10 files changed, 105 insertions, 55 deletions
diff --git a/src/pkg/go/ast/scope.go b/src/pkg/go/ast/scope.go index 32b9d9d9f..b5a38484e 100644 --- a/src/pkg/go/ast/scope.go +++ b/src/pkg/go/ast/scope.go @@ -11,11 +11,11 @@ type ObjKind int // The list of possible Object kinds. const ( Err ObjKind = iota // object kind unknown (forward reference or error) - Pkg // package - Con // constant - Typ // type - Var // variable - Fun // function or method + Pkg // package + Con // constant + Typ // type + Var // variable + Fun // function or method ) diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go index 9928496e6..2002d3818 100644 --- a/src/pkg/go/parser/parser.go +++ b/src/pkg/go/parser/parser.go @@ -28,9 +28,9 @@ var noPos token.Position // const ( PackageClauseOnly uint = 1 << iota // parsing stops after package clause - ImportsOnly // parsing stops after import declarations - ParseComments // parse comments and add them to AST - Trace // print a trace of parsed productions + ImportsOnly // parsing stops after import declarations + ParseComments // parse comments and add them to AST + Trace // print a trace of parsed productions ) diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index 9e2a8c856..8a6ac1a17 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -85,10 +85,10 @@ type exprListMode uint const ( blankStart exprListMode = 1 << iota // print a blank before a non-empty list - blankEnd // print a blank after a non-empty list - commaSep // elements are separated by commas - commaTerm // list is optionally terminated by a comma - noIndent // no extra indentation in multi-line lists + blankEnd // print a blank after a non-empty list + commaSep // elements are separated by commas + commaTerm // list is optionally terminated by a comma + noIndent // no extra indentation in multi-line lists ) @@ -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) - } } diff --git a/src/pkg/go/printer/printer.go b/src/pkg/go/printer/printer.go index 87db4f3e6..3bb51b466 100644 --- a/src/pkg/go/printer/printer.go +++ b/src/pkg/go/printer/printer.go @@ -932,9 +932,9 @@ func (p *trimmer) Write(data []byte) (n int, err os.Error) { // General printing is controlled with these Config.Mode flags. const ( GenHTML uint = 1 << iota // generate HTML - RawFormat // do not use a tabwriter; if set, UseSpaces is ignored - TabIndent // use tabs for indentation independent of UseSpaces - UseSpaces // use spaces instead of tabs for alignment + RawFormat // do not use a tabwriter; if set, UseSpaces is ignored + TabIndent // use tabs for indentation independent of UseSpaces + UseSpaces // use spaces instead of tabs for alignment ) diff --git a/src/pkg/go/printer/testdata/comments.golden b/src/pkg/go/printer/testdata/comments.golden index 0bd742bd1..f216b0b64 100644 --- a/src/pkg/go/printer/testdata/comments.golden +++ b/src/pkg/go/printer/testdata/comments.golden @@ -11,9 +11,38 @@ import "fmt" // fmt const c0 = 0 // zero const ( 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. type SZ struct{} diff --git a/src/pkg/go/printer/testdata/comments.input b/src/pkg/go/printer/testdata/comments.input index 7a0245c79..8ed26c5ab 100644 --- a/src/pkg/go/printer/testdata/comments.input +++ b/src/pkg/go/printer/testdata/comments.input @@ -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 {} diff --git a/src/pkg/go/printer/testdata/declarations.golden b/src/pkg/go/printer/testdata/declarations.golden index 2fe518e96..9772e837f 100644 --- a/src/pkg/go/printer/testdata/declarations.golden +++ b/src/pkg/go/printer/testdata/declarations.golden @@ -282,11 +282,11 @@ func _() { ) // some entries have a type const ( - xxxxxx = 1 - x = 2 - xxx = 3 + xxxxxx = 1 + x = 2 + xxx = 3 yyyyyyyy float = iota - yyyy = "bar" + yyyy = "bar" yyy yy = 2 ) @@ -316,15 +316,15 @@ func _() { xxx string yyyyyyyy int = 1234 y float = 3.14 - yyyy = "bar" + yyyy = "bar" yyy string = "foo" ) // mixed entries - all comments should be aligned var ( a, b, c int - x = 10 - d int // comment - y = 20 // comment + x = 10 + d int // comment + y = 20 // comment f, ff, fff, ffff int = 0, 1, 2, 3 // comment ) // respect original line breaks diff --git a/src/pkg/go/printer/testdata/expressions.raw b/src/pkg/go/printer/testdata/expressions.raw index 3f3b460bc..6ecfe13b5 100644 --- a/src/pkg/go/printer/testdata/expressions.raw +++ b/src/pkg/go/printer/testdata/expressions.raw @@ -289,12 +289,12 @@ func _() { // Alignment after overlong lines const ( - _ = "991" - _ = "2432902008176640000" // 20! - _ = "933262154439441526816992388562667004907159682643816214685929" + + _ = "991" + _ = "2432902008176640000" // 20! + _ = "933262154439441526816992388562667004907159682643816214685929" + "638952175999932299156089414639761565182862536979208272237582" + "51185210916864000000000000000000000000" // 100! - _ = "170141183460469231731687303715884105727" // prime + _ = "170141183460469231731687303715884105727" // prime ) diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go index d1fdf2dcf..47e35a710 100644 --- a/src/pkg/go/scanner/errors.go +++ b/src/pkg/go/scanner/errors.go @@ -112,8 +112,8 @@ func (p ErrorList) String() string { // const ( Raw = iota // leave error list unchanged - Sorted // sort error list by file, line, and column number - NoMultiples // sort error list and leave only the first error per line + Sorted // sort error list by file, line, and column number + NoMultiples // sort error list and leave only the first error per line ) diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index b12f9152a..576b95a28 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -76,8 +76,8 @@ func (S *Scanner) next() { // const ( ScanComments = 1 << iota // return comments as COMMENT tokens - AllowIllegalChars // do not report an error for illegal chars - InsertSemis // automatically insert semicolons + AllowIllegalChars // do not report an error for illegal chars + InsertSemis // automatically insert semicolons ) |