]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: more consistent formatting of const/var decls
authorRobert Griesemer <gri@golang.org>
Tue, 16 Mar 2010 23:45:54 +0000 (16:45 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 16 Mar 2010 23:45:54 +0000 (16:45 -0700)
- 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

16 files changed:
src/cmd/godoc/main.go
src/pkg/go/ast/scope.go
src/pkg/go/parser/parser.go
src/pkg/go/printer/nodes.go
src/pkg/go/printer/printer.go
src/pkg/go/printer/testdata/comments.golden
src/pkg/go/printer/testdata/comments.input
src/pkg/go/printer/testdata/declarations.golden
src/pkg/go/printer/testdata/expressions.raw
src/pkg/go/scanner/errors.go
src/pkg/go/scanner/scanner.go
src/pkg/log/log.go
src/pkg/rand/rand_test.go
src/pkg/regexp/regexp.go
src/pkg/runtime/type.go
src/pkg/testing/regexp.go

index f7dc522f2f3da763e6131b485e13294bbb64ec19..f640029b12cbd970889a60150cc070aada144c24 100644 (file)
@@ -39,8 +39,8 @@ import (
 
 var (
        // periodic sync
-       syncCmd             = flag.String("sync", "", "sync command; disabled if empty")
-       syncMin             = flag.Int("sync_minutes", 0, "sync interval in minutes; disabled if <= 0")
+       syncCmd   = flag.String("sync", "", "sync command; disabled if empty")
+       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
 
        // server control
index 32b9d9d9f9b93276a00255920187027be180008c..b5a38484efaa9d77a45adde8028d01b287819085 100644 (file)
@@ -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
 )
 
 
index 9928496e6c8b172e1f52633b2de2d3ccd08ae1d6..2002d3818b44b266647de5365230c68c9303133e 100644 (file)
@@ -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
 )
 
 
index 9e2a8c8568723862f005571fb826acdb4eb72faf..8a6ac1a171e107bf40bcfc1923a77db10517eecc 100644 (file)
@@ -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)
-       }
 }
 
 
index 87db4f3e6bbd375e231bac7c8e5e779eb2fbe0f3..3bb51b466f6c50f8b3326ab89d34acdfeda109ff 100644 (file)
@@ -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
 )
 
 
index 0bd742bd11ded3fe20593bd60e4ddca3646e33be..f216b0b6440278b263a376a62f77e09b7d6c6968 100644 (file)
@@ -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{}
index 7a0245c7963ddfe2ec784f4ec856503f87a55466..8ed26c5ab1fd78e27da34da92240b7bdff1d2d79 100644 (file)
@@ -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 {}
index 2fe518e96b6165425325930e269a1cf6939a9ce1..9772e837f3d1fca3d02e6266023da353b0148ecd 100644 (file)
@@ -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
index 3f3b460bc2d0068d313e5e610f1863ea96be4c70..6ecfe13b56a7287cc01b1ed36da8e40e7e19f02a 100644 (file)
@@ -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
 )
 
 
index d1fdf2dcf4d96dcb6c5d55796559e02bce7c89a4..47e35a7107dece072825b7612a18f0bc3f6f8a60 100644 (file)
@@ -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
 )
 
 
index b12f9152a66227dfdb5aacec21125e3d5a5a8048..576b95a2896f919b15094dcc8f86772df1cafd90 100644 (file)
@@ -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
 )
 
 
index 83769be03974295a4358397dfe34b14189ffb2d7..28d6204eb68ecee3e5525f18eb2c584426253bf4 100644 (file)
@@ -30,10 +30,10 @@ const (
        // described in the comments).  A colon appears after these items:
        //      2009/0123 01:23:23.123123 /a/b/c/d.go:23: message
        Ldate         = 1 << iota // the date: 2009/0123
-       Ltime         // the time: 01:23:23
-       Lmicroseconds // microsecond resolution: 01:23:23.123123.  assumes Ltime.
-       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
+       Ltime                     // the time: 01:23:23
+       Lmicroseconds             // microsecond resolution: 01:23:23.123123.  assumes Ltime.
+       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
        lAllBits      = Ldate | Ltime | Lmicroseconds | Llongfile | Lshortfile
 )
 
index 786831517d101752f12c4243336bcec8adfee226..7ce3894db154399c04f34f3da947a35942a91bec 100644 (file)
@@ -197,7 +197,7 @@ func initNorm() (testKn []uint32, testWn, testFn []float32) {
        const m1 = 1 << 31
        var (
                dn float64 = rn
-               tn         = dn
+               tn = dn
                vn float64 = 9.91256303526217e-3
        )
 
@@ -226,7 +226,7 @@ func initExp() (testKe []uint32, testWe, testFe []float32) {
        const m2 = 1 << 32
        var (
                de float64 = re
-               te         = de
+               te = de
                ve float64 = 3.9496598225815571993e-3
        )
 
index 216e80516cf7d25551d43b93f27b8064c1f6aa1d..ecef271784f0f66e48be089f006be62d6db429e3 100644 (file)
@@ -82,17 +82,17 @@ type Regexp struct {
 
 const (
        _START     = iota // beginning of program
-       _END       // end of program: success
-       _BOT       // '^' beginning of text
-       _EOT       // '$' end of text
-       _CHAR      // 'a' regular character
-       _CHARCLASS // [a-z] character class
-       _ANY       // '.' any character including newline
-       _NOTNL     // [^\n] special case: any character but newline
-       _BRA       // '(' parenthesized expression
-       _EBRA      // ')'; end of '(' parenthesized expression
-       _ALT       // '|' alternation
-       _NOP       // do nothing; makes it easy to link without patching
+       _END              // end of program: success
+       _BOT              // '^' beginning of text
+       _EOT              // '$' end of text
+       _CHAR             // 'a' regular character
+       _CHARCLASS        // [a-z] character class
+       _ANY              // '.' any character including newline
+       _NOTNL            // [^\n] special case: any character but newline
+       _BRA              // '(' parenthesized expression
+       _EBRA             // ')'; end of '(' parenthesized expression
+       _ALT              // '|' alternation
+       _NOP              // do nothing; makes it easy to link without patching
 )
 
 // --- START start of program
index c37447718fffbb991a6051d44bad0081a428caac..70b0040c6ab6a38e64261382415f2471acf64800 100644 (file)
@@ -164,9 +164,9 @@ type SliceType struct {
 type ChanDir int
 
 const (
-       RecvDir ChanDir = 1 << iota // <-chan
-       SendDir         // chan<-
-       BothDir         = RecvDir | SendDir // chan
+       RecvDir ChanDir             = 1 << iota // <-chan
+       SendDir                                 // chan<-
+       BothDir = RecvDir | SendDir             // chan
 )
 
 // ChanType represents a channel type.
index a21d14e6b03c553f5cdd3953d071e501235a447a..6584d47c187f9945888f3ea1f4789ed07b4d6137 100644 (file)
@@ -77,17 +77,17 @@ type Regexp struct {
 
 const (
        _START     = iota // beginning of program
-       _END       // end of program: success
-       _BOT       // '^' beginning of text
-       _EOT       // '$' end of text
-       _CHAR      // 'a' regular character
-       _CHARCLASS // [a-z] character class
-       _ANY       // '.' any character including newline
-       _NOTNL     // [^\n] special case: any character but newline
-       _BRA       // '(' parenthesized expression
-       _EBRA      // ')'; end of '(' parenthesized expression
-       _ALT       // '|' alternation
-       _NOP       // do nothing; makes it easy to link without patching
+       _END              // end of program: success
+       _BOT              // '^' beginning of text
+       _EOT              // '$' end of text
+       _CHAR             // 'a' regular character
+       _CHARCLASS        // [a-z] character class
+       _ANY              // '.' any character including newline
+       _NOTNL            // [^\n] special case: any character but newline
+       _BRA              // '(' parenthesized expression
+       _EBRA             // ')'; end of '(' parenthesized expression
+       _ALT              // '|' alternation
+       _NOP              // do nothing; makes it easy to link without patching
 )
 
 // --- START start of program