diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-03-30 07:38:46 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-03-30 17:06:55 +0000 |
commit | eca90561c39d4d8cc587fbcc70baa9d90f3f0707 (patch) | |
tree | 40b050930846b8a07112afff885df5361c86f0e6 /src/cmd/compile/internal/gc/init.go | |
parent | 5272a2cdc551c041a9f744ede72506be5f622196 (diff) | |
download | go-git-eca90561c39d4d8cc587fbcc70baa9d90f3f0707.tar.gz |
cmd/compile: minor init handling cleanup
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>
Diffstat (limited to 'src/cmd/compile/internal/gc/init.go')
-rw-r--r-- | src/cmd/compile/internal/gc/init.go | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/cmd/compile/internal/gc/init.go b/src/cmd/compile/internal/gc/init.go index 0ebbffd83a..7ce8383dbc 100644 --- a/src/cmd/compile/internal/gc/init.go +++ b/src/cmd/compile/internal/gc/init.go @@ -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) |