Commit eca90561 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 5272a2cd
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment