]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: more int to bool cleanups
authorDave Cheney <dave@cheney.net>
Fri, 6 Mar 2015 07:42:58 +0000 (18:42 +1100)
committerDave Cheney <dave@cheney.net>
Fri, 6 Mar 2015 23:47:18 +0000 (23:47 +0000)
- make paramoutheap return a bool
- convert Node.Assigned to a bool
- convert Node.Captured to a bool
- convert Node.Byval to a bool
- convert Node.Dupok to a bool
- convert Node.Wrapper to a bool
- convert Node.Reslice to a bool

Change-Id: I5b57c019f936c31d53db4db14459fb2b0aa72305
Reviewed-on: https://go-review.googlesource.com/7030
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Dave Cheney <dave@cheney.net>

src/cmd/internal/gc/closure.go
src/cmd/internal/gc/esc.go
src/cmd/internal/gc/fmt.go
src/cmd/internal/gc/pgen.go
src/cmd/internal/gc/popt.go
src/cmd/internal/gc/subr.go
src/cmd/internal/gc/syntax.go
src/cmd/internal/gc/typecheck.go
src/cmd/internal/gc/walk.go

index 1f47547a7de68df603ddc61fad8515262f1c0d47..56b418985bd5ea4d2e915a95623be00f31ab5c2b 100644 (file)
@@ -84,8 +84,8 @@ func typecheckclosure(func_ *Node, top int) {
 
        for l := func_.Cvars; l != nil; l = l.Next {
                n = l.N.Closure
-               if n.Captured == 0 {
-                       n.Captured = 1
+               if !n.Captured {
+                       n.Captured = true
                        if n.Decldepth == 0 {
                                Fatal("typecheckclosure: var %v does not have decldepth assigned", Nconv(n, obj.FmtShort))
                        }
@@ -93,7 +93,7 @@ func typecheckclosure(func_ *Node, top int) {
                        // Ignore assignments to the variable in straightline code
                        // preceding the first capturing by a closure.
                        if n.Decldepth == decldepth {
-                               n.Assigned = 0
+                               n.Assigned = false
                        }
                }
        }
@@ -254,8 +254,8 @@ func capturevars(xfunc *Node) {
                v.Outerexpr = nil
 
                // out parameters will be assigned to implicitly upon return.
-               if outer.Class != PPARAMOUT && !v.Closure.Addrtaken && v.Closure.Assigned == 0 && v.Type.Width <= 128 {
-                       v.Byval = 1
+               if outer.Class != PPARAMOUT && !v.Closure.Addrtaken && !v.Closure.Assigned && v.Type.Width <= 128 {
+                       v.Byval = true
                } else {
                        v.Closure.Addrtaken = true
                        outer = Nod(OADDR, outer, nil)
@@ -267,10 +267,10 @@ func capturevars(xfunc *Node) {
                                name = v.Curfn.Nname.Sym
                        }
                        how := "ref"
-                       if v.Byval != 0 {
+                       if v.Byval {
                                how = "value"
                        }
-                       Warnl(int(v.Lineno), "%v capturing by %s: %v (addr=%d assign=%d width=%d)", Sconv(name, 0), how, Sconv(v.Sym, 0), v.Closure.Addrtaken, v.Closure.Assigned, int32(v.Type.Width))
+                       Warnl(int(v.Lineno), "%v capturing by %s: %v (addr=%v assign=%v width=%d)", Sconv(name, 0), how, Sconv(v.Sym, 0), v.Closure.Addrtaken, v.Closure.Assigned, int32(v.Type.Width))
                }
 
                typecheck(&outer, Erv)
@@ -322,7 +322,7 @@ func transformclosure(xfunc *Node) {
                        }
                        fld = typ(TFIELD)
                        fld.Funarg = 1
-                       if v.Byval != 0 {
+                       if v.Byval {
                                // If v is captured by value, we merely downgrade it to PPARAM.
                                v.Class = PPARAM
 
@@ -378,14 +378,14 @@ func transformclosure(xfunc *Node) {
                        cv = Nod(OCLOSUREVAR, nil, nil)
 
                        cv.Type = v.Type
-                       if v.Byval == 0 {
+                       if !v.Byval {
                                cv.Type = Ptrto(v.Type)
                        }
                        offset = Rnd(offset, int64(cv.Type.Align))
                        cv.Xoffset = offset
                        offset += cv.Type.Width
 
-                       if v.Byval != 0 && v.Type.Width <= int64(2*Widthptr) && Thearch.Thechar == '6' {
+                       if v.Byval && v.Type.Width <= int64(2*Widthptr) && Thearch.Thechar == '6' {
                                //  If it is a small variable captured by value, downgrade it to PAUTO.
                                // This optimization is currently enabled only for amd64, see:
                                // https://github.com/golang/go/issues/9865
@@ -406,7 +406,7 @@ func transformclosure(xfunc *Node) {
                                addr.Curfn = xfunc
                                xfunc.Dcl = list(xfunc.Dcl, addr)
                                v.Heapaddr = addr
-                               if v.Byval != 0 {
+                               if v.Byval {
                                        cv = Nod(OADDR, cv, nil)
                                }
                                body = list(body, Nod(OAS, addr, cv))
@@ -453,7 +453,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
                        continue
                }
                typ1 = typenod(v.Type)
-               if v.Byval == 0 {
+               if !v.Byval {
                        typ1 = Nod(OIND, typ1, nil)
                }
                typ.List = list(typ.List, Nod(ODCLFIELD, newname(v.Sym), typ1))
@@ -588,7 +588,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
 
        xtype.Rlist = l
 
-       xfunc.Dupok = 1
+       xfunc.Dupok = true
        xfunc.Nname = newname(sym)
        xfunc.Nname.Sym.Flags |= SymExported // disable export
        xfunc.Nname.Ntype = xtype
index 8b5430b7413931f1b401f639898ab8f124b379b0..0714f9c599cf533f6abe0df7369105a3ef05edd9 100644 (file)
@@ -719,7 +719,7 @@ func esc(e *EscState, n *Node, up *Node) {
                                continue
                        }
                        a = v.Closure
-                       if v.Byval == 0 {
+                       if !v.Byval {
                                a = Nod(OADDR, a, nil)
                                a.Lineno = v.Lineno
                                a.Escloopdepth = e.loopdepth
index 6124ae5096cc530494064a65ebf6c40e785bf347..43ffb80e0d0f8105051d82dcc04774bf63b6117f 100644 (file)
@@ -285,7 +285,7 @@ func Jconv(n *Node, flag int) string {
                fp += " addrtaken"
        }
 
-       if n.Assigned != 0 {
+       if n.Assigned {
                fp += " assigned"
        }
 
index abfc53386ee77c1f9df405f0f2aa8fa4a84067e8..ef6e9c1d8f0012ddd01c07cfb7fd7a471fab69f1 100644 (file)
@@ -442,10 +442,10 @@ func compile(fn *Node) {
                nam = nil
        }
        ptxt = Thearch.Gins(obj.ATEXT, nam, &nod1)
-       if fn.Dupok != 0 {
+       if fn.Dupok {
                ptxt.From3.Offset |= obj.DUPOK
        }
-       if fn.Wrapper != 0 {
+       if fn.Wrapper {
                ptxt.From3.Offset |= obj.WRAPPER
        }
        if fn.Needctxt {
index 813f24af3c936b6c4a25191147c2f2d2f466691d..46f844e08cd5dac5cc049ef2e428e5de8df8aa9d 100644 (file)
@@ -893,7 +893,7 @@ func mergetemp(firstp *obj.Prog) {
                for j = nfree; j < len(var_); j++ {
                        v1 = inuse[j]
                        if debugmerge > 0 && Debug['v'] != 0 {
-                               fmt.Printf("consider %v: maybe %v: type=%v,%v addrtaken=%d,%d\n", Nconv(v.node, obj.FmtSharp), Nconv(v1.node, obj.FmtSharp), Tconv(t, 0), Tconv(v1.node.Type, 0), v.node.Addrtaken, v1.node.Addrtaken)
+                               fmt.Printf("consider %v: maybe %v: type=%v,%v addrtaken=%v,%v\n", Nconv(v.node, obj.FmtSharp), Nconv(v1.node, obj.FmtSharp), Tconv(t, 0), Tconv(v1.node.Type, 0), v.node.Addrtaken, v1.node.Addrtaken)
                        }
 
                        // Require the types to match but also require the addrtaken bits to match.
index ef043a78199e4b996fa232c56739fe319769a95d..e678a98bb417cad584e11469c816efbb0c861188 100644 (file)
@@ -2474,7 +2474,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
                n.Left = newname(methodsym(method.Sym, methodrcvr, 0))
                fn.Nbody = list(fn.Nbody, n)
        } else {
-               fn.Wrapper = 1 // ignore frame for panic+recover matching
+               fn.Wrapper = true // ignore frame for panic+recover matching
                call := Nod(OCALL, dot, nil)
                call.List = args
                call.Isddd = uint8(isddd)
@@ -2496,7 +2496,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
 
        // wrappers where T is anonymous (struct or interface) can be duplicated.
        if rcvr.Etype == TSTRUCT || rcvr.Etype == TINTER || Isptr[rcvr.Etype] && rcvr.Type.Etype == TSTRUCT {
-               fn.Dupok = 1
+               fn.Dupok = true
        }
        typecheck(&fn, Etop)
        typechecklist(fn.Nbody, Etop)
@@ -2751,7 +2751,7 @@ func genhash(sym *Sym, t *Type) {
 
        funcbody(fn)
        Curfn = fn
-       fn.Dupok = 1
+       fn.Dupok = true
        typecheck(&fn, Etop)
        typechecklist(fn.Nbody, Etop)
        Curfn = nil
@@ -2971,7 +2971,7 @@ func geneq(sym *Sym, t *Type) {
 
        funcbody(fn)
        Curfn = fn
-       fn.Dupok = 1
+       fn.Dupok = true
        typecheck(&fn, Etop)
        typechecklist(fn.Nbody, Etop)
        Curfn = nil
index a81f8420cf00491af0d94c00155aad24310ec0c5..3a52130de33bc5f4090cb069641ca8b53622988d 100644 (file)
@@ -47,18 +47,18 @@ type Node struct {
        Isddd          uint8
        Readonly       bool
        Implicit       uint8
-       Addrtaken      bool  // address taken, even if not moved to heap
-       Assigned       uint8 // is the variable ever assigned to
-       Captured       uint8 // is the variable captured by a closure
-       Byval          uint8 // is the variable captured by value or by reference
-       Dupok          uint8 // duplicate definitions ok (for func)
-       Wrapper        uint8 // is method wrapper (for func)
-       Reslice        uint8 // this is a reslice x = x[0:y] or x = append(x, ...)
-       Likely         int8  // likeliness of if statement
-       Hasbreak       bool  // has break statement
-       Needzero       bool  // if it contains pointers, needs to be zeroed on function entry
-       Needctxt       bool  // function uses context register (has closure variables)
-       Esc            uint  // EscXXX
+       Addrtaken      bool // address taken, even if not moved to heap
+       Assigned       bool // is the variable ever assigned to
+       Captured       bool // is the variable captured by a closure
+       Byval          bool // is the variable captured by value or by reference
+       Dupok          bool // duplicate definitions ok (for func)
+       Wrapper        bool // is method wrapper (for func)
+       Reslice        bool // this is a reslice x = x[0:y] or x = append(x, ...)
+       Likely         int8 // likeliness of if statement
+       Hasbreak       bool // has break statement
+       Needzero       bool // if it contains pointers, needs to be zeroed on function entry
+       Needctxt       bool // function uses context register (has closure variables)
+       Esc            uint // EscXXX
        Funcdepth      int
 
        // most nodes
index f6d51d641830869e6361e1c4338d31a874b9c682..cee081729b0b9ccf81085192bbf8122df516f2b2 100644 (file)
@@ -3258,15 +3258,15 @@ func checkassign(stmt *Node, n *Node) {
                r := outervalue(n)
                var l *Node
                for l = n; l != r; l = l.Left {
-                       l.Assigned = 1
+                       l.Assigned = true
                        if l.Closure != nil {
-                               l.Closure.Assigned = 1
+                               l.Closure.Assigned = true
                        }
                }
 
-               l.Assigned = 1
+               l.Assigned = true
                if l.Closure != nil {
-                       l.Closure.Assigned = 1
+                       l.Closure.Assigned = true
                }
        }
 
@@ -3370,7 +3370,7 @@ func typecheckas(n *Node) {
                        OSLICE3,
                        OSLICESTR:
                        if false && samesafeexpr(n.Left, n.Right.Left) && (n.Right.Right.Left == nil || iszero(n.Right.Right.Left)) {
-                               n.Right.Reslice = 1
+                               n.Right.Reslice = true
                        }
 
                        // For x = append(x, ...), x can be updated in place when there is capacity,
@@ -3379,7 +3379,7 @@ func typecheckas(n *Node) {
                // TODO(rsc): Reenable once the emitted code does update the pointer.
                case OAPPEND:
                        if false && n.Right.List != nil && samesafeexpr(n.Left, n.Right.List.N) {
-                               n.Right.Reslice = 1
+                               n.Right.Reslice = true
                        }
                }
        }
index 7ba66b044f30ab70fddfcd4d75a94690cca87492..48146886a17730ecbb3f1e2455df95f2ba10c8d6 100644 (file)
@@ -91,21 +91,21 @@ func samelist(a *NodeList, b *NodeList) bool {
        return a == b
 }
 
-func paramoutheap(fn *Node) int {
+func paramoutheap(fn *Node) bool {
        for l := fn.Dcl; l != nil; l = l.Next {
                switch l.N.Class {
                case PPARAMOUT,
                        PPARAMOUT | PHEAP:
-                       return bool2int(l.N.Addrtaken)
+                       return l.N.Addrtaken
 
                        // stop early - parameters are over
                case PAUTO,
                        PAUTO | PHEAP:
-                       return 0
+                       return false
                }
        }
 
-       return 0
+       return false
 }
 
 // adds "adjust" to all the argument locations for the call n.
@@ -284,7 +284,7 @@ func walkstmt(np **Node) {
                if n.List == nil {
                        break
                }
-               if (Curfn.Type.Outnamed != 0 && count(n.List) > 1) || paramoutheap(Curfn) != 0 {
+               if (Curfn.Type.Outnamed != 0 && count(n.List) > 1) || paramoutheap(Curfn) {
                        // assign to the function out parameters,
                        // so that reorder3 can fix up conflicts
                        var rl *NodeList
@@ -2174,7 +2174,7 @@ func needwritebarrier(l *Node, r *Node) bool {
        // generate the write barrier directly in that case.
        // (It does not yet, but the cost of the write barrier will be
        // small compared to the cost of the allocation.)
-       if r.Reslice != 0 {
+       if r.Reslice {
                switch r.Op {
                case OSLICE,
                        OSLICE3,