]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: minor init handling cleanup
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 14:38:46 +0000 (07:38 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 17:06:55 +0000 (17:06 +0000)
Place comments correctly.
Simplify control flow.
Reduce variable scope.

Passes toolstash-check.

Change-Id: Iea47ed3502c15491c2ca6db8149fe0949b8849aa
Reviewed-on: https://go-review.googlesource.com/38914
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 0ebbffd83aca4e410e39c572cb609d778eebfd28..7ce8383dbc6f195d653a20042f6b868d0b8bc038 100644 (file)
@@ -17,35 +17,15 @@ func renameinit() *Sym {
        return lookupN("init.", renameinit_initgen)
 }
 
-// hand-craft the following initialization code
-//      var initdone· uint8                             (1)
-//      func init() {                                   (2)
-//              if initdone· > 1 {                      (3)
-//                      return                          (3a)
-//              }
-//              if initdone· == 1 {                     (4)
-//                      throw()                         (4a)
-//              }
-//              initdone· = 1                           (5)
-//              // over all matching imported symbols
-//                      <pkg>.init()                    (6)
-//              { <init stmts> }                        (7)
-//              init.<n>() // if any                    (8)
-//              initdone· = 2                           (9)
-//              return                                  (10)
-//      }
+// anyinit reports whether there any interesting init statements.
 func anyinit(n []*Node) bool {
-       // are there any interesting init statements
        for _, ln := range n {
                switch ln.Op {
                case ODCLFUNC, ODCLCONST, ODCLTYPE, OEMPTY:
-                       break
-
                case OAS:
-                       if isblank(ln.Left) && candiscard(ln.Right) {
-                               break
+                       if !isblank(ln.Left) || !candiscard(ln.Right) {
+                               return true
                        }
-                       fallthrough
                default:
                        return true
                }
@@ -57,9 +37,7 @@ func anyinit(n []*Node) bool {
        }
 
        // is there an explicit init function
-       s := lookup("init.1")
-
-       if s.Def != nil {
+       if s := lookup("init.1"); s.Def != nil {
                return true
        }
 
@@ -74,6 +52,24 @@ func anyinit(n []*Node) bool {
        return false
 }
 
+// fninit hand-crafts package initialization code.
+//
+//      var initdone· uint8                             (1)
+//      func init() {                                   (2)
+//              if initdone· > 1 {                      (3)
+//                      return                          (3a)
+//              }
+//              if initdone· == 1 {                     (4)
+//                      throw()                         (4a)
+//              }
+//              initdone· = 1                           (5)
+//              // over all matching imported symbols
+//                      <pkg>.init()                    (6)
+//              { <init stmts> }                        (7)
+//              init.<n>() // if any                    (8)
+//              initdone· = 2                           (9)
+//              return                                  (10)
+//      }
 func fninit(n []*Node) {
        lineno = autogeneratedPos
        nf := initfix(n)