]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: count init functions from 0, not 1
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 23 Apr 2017 23:34:35 +0000 (16:34 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 24 Apr 2017 00:58:49 +0000 (00:58 +0000)
While we're here, do minor style cleanup.
Also, since we know exactly how many init
functions there are, use that knowledge.

This is cleanup prior to a more substantive CL.

Change-Id: I2bba60b3c051c852590f798f45e8268f8bc54ca8
Reviewed-on: https://go-review.googlesource.com/41499
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/init.go

index df2d70fcafb1760aeb0aaad56b603e3e0b80d20e..7dee46a17c521793b27093802de11c2b4852b5b8 100644 (file)
@@ -6,17 +6,16 @@ package gc
 
 import "cmd/compile/internal/types"
 
-// a function named init is a special case.
-// it is called by the initialization before
-// main is run. to make it unique within a
-// package and also uncallable, the name,
-// normally "pkg.init", is altered to "pkg.init.1".
-
-var renameinit_initgen int
+// A function named init is a special case.
+// It is called by the initialization before main is run.
+// To make it unique within a package and also uncallable,
+// the name, normally "pkg.init", is altered to "pkg.init.0".
+var renameinitgen int
 
 func renameinit() *types.Sym {
-       renameinit_initgen++
-       return lookupN("init.", renameinit_initgen)
+       s := lookupN("init.", renameinitgen)
+       renameinitgen++
+       return s
 }
 
 // anyinit reports whether there any interesting init statements.
@@ -39,7 +38,7 @@ func anyinit(n []*Node) bool {
        }
 
        // is there an explicit init function
-       if s := lookup("init.1"); s.Def != nil {
+       if renameinitgen > 0 {
                return true
        }
 
@@ -126,11 +125,8 @@ func fninit(n []*Node) {
 
        // (8)
        // could check that it is fn of no args/returns
-       for i := 1; ; i++ {
+       for i := 0; i < renameinitgen; i++ {
                s := lookupN("init.", i)
-               if s.Def == nil {
-                       break
-               }
                a = nod(OCALL, asNode(s.Def), nil)
                r = append(r, a)
        }