Commit d328756a authored by Dave Cheney's avatar Dave Cheney

cmd/internal/gc: make Node.Isddd boolean

Convert Node.Isddd to a boolean and simplify usage.

- Node.Isddd converted to bool
- Type.Isddd converted to bool
- mkinlcall converted to take isddd as a bool
- typecheckaste converted to take isddd as a bool
- ascompatte converted to take isddd as a bool

Change-Id: I52586145619c44182bb0c2c5d80a0a3fe3e50a07
Reviewed-on: https://go-review.googlesource.com/7172Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 402f71a8
......@@ -551,7 +551,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
i := 0
var l *NodeList
var callargs *NodeList
ddd := 0
ddd := false
xfunc := Nod(ODCLFUNC, nil, nil)
Curfn = xfunc
var fld *Node
......@@ -564,9 +564,9 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
xfunc.Dcl = list(xfunc.Dcl, n)
callargs = list(callargs, n)
fld = Nod(ODCLFIELD, n, typenod(t.Type))
if t.Isddd != 0 {
fld.Isddd = 1
ddd = 1
if t.Isddd {
fld.Isddd = true
ddd = true
}
l = list(l, fld)
......@@ -623,7 +623,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
call := Nod(OCALL, Nod(OXDOT, ptr, meth), nil)
call.List = callargs
call.Isddd = uint8(ddd)
call.Isddd = ddd
if t0.Outtuple == 0 {
body = list(body, call)
} else {
......
......@@ -1150,9 +1150,9 @@ func checkarglist(all *NodeList, input int) *NodeList {
n.Right.Op = OTARRAY
n.Right.Right = n.Right.Left
n.Right.Left = nil
n.Isddd = 1
n.Isddd = true
if n.Left != nil {
n.Left.Isddd = 1
n.Left.Isddd = true
}
}
......
......@@ -648,7 +648,7 @@ func esc(e *EscState, n *Node, up *Node) {
escassign(e, &e.theSink, n.Left)
case OAPPEND:
if n.Isddd == 0 {
if !n.Isddd {
for ll = n.List.Next; ll != nil; ll = ll.Next {
escassign(e, &e.theSink, ll.N) // lose track of assign to dereference
}
......@@ -1045,7 +1045,7 @@ func esccall(e *EscState, n *Node, up *Node) {
var src *Node
for lr = fn.Ntype.List; ll != nil && lr != nil; (func() { ll = ll.Next; lr = lr.Next })() {
src = ll.N
if lr.N.Isddd != 0 && n.Isddd == 0 {
if lr.N.Isddd && !n.Isddd {
// Introduce ODDDARG node to represent ... allocation.
src = Nod(ODDDARG, nil, nil)
......@@ -1114,7 +1114,7 @@ func esccall(e *EscState, n *Node, up *Node) {
var a *Node
for t := getinargx(fntype).Type; ll != nil; ll = ll.Next {
src = ll.N
if t.Isddd != 0 && n.Isddd == 0 {
if t.Isddd && !n.Isddd {
// Introduce ODDDARG node to represent ... allocation.
src = Nod(ODDDARG, nil, nil)
......
......@@ -269,8 +269,8 @@ func Jconv(n *Node, flag int) string {
fp += fmt.Sprintf(" dd(%d)", n.Dodata)
}
if n.Isddd != 0 {
fp += fmt.Sprintf(" isddd(%d)", n.Isddd)
if n.Isddd {
fp += fmt.Sprintf(" isddd(%v)", n.Isddd)
}
if n.Implicit {
......@@ -749,7 +749,7 @@ func typefmt(t *Type, flag int) string {
}
}
if t.Isddd != 0 {
if t.Isddd {
fp += fmt.Sprintf("...%v", Tconv(t.Type.Type, 0))
} else {
fp += fmt.Sprintf("%v", Tconv(t.Type, 0))
......@@ -1435,7 +1435,7 @@ func exprfmt(n *Node, prec int) string {
if n.Left != nil {
return fmt.Sprintf("%v(%v)", Oconv(int(n.Op), obj.FmtSharp), Nconv(n.Left, 0))
}
if n.Isddd != 0 {
if n.Isddd {
return fmt.Sprintf("%v(%v...)", Oconv(int(n.Op), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
}
var f string
......@@ -1448,7 +1448,7 @@ func exprfmt(n *Node, prec int) string {
OCALLMETH:
var f string
f += exprfmt(n.Left, nprec)
if n.Isddd != 0 {
if n.Isddd {
f += fmt.Sprintf("(%v...)", Hconv(n.List, obj.FmtComma))
return f
}
......
......@@ -143,7 +143,7 @@ type Type struct {
Local uint8 // created in this file
Deferwidth uint8
Broke uint8 // broken type definition.
Isddd uint8 // TFIELD is ... argument
Isddd bool // TFIELD is ... argument
Align uint8
Haspointers uint8 // 0 unknown, 1 no, 2 yes
......
......@@ -935,7 +935,7 @@ pseudocall:
{
$$ = Nod(OCALL, $1, nil);
$$.List = $3;
$$.Isddd = 1;
$$.Isddd = true;
}
pexpr_no_paren:
......@@ -2103,7 +2103,7 @@ hidden_funarg:
if $1 != nil {
$$.Left = newname($1);
}
$$.Isddd = 1;
$$.Isddd = true;
$$.Val = $4;
}
......
......@@ -118,7 +118,7 @@ func caninl(fn *Node) {
// can't handle ... args yet
if Debug['l'] < 3 {
for t := fn.Type.Type.Down.Down.Type; t != nil; t = t.Down {
if t.Isddd != 0 {
if t.Isddd {
return
}
}
......@@ -466,10 +466,10 @@ func inlnode(np **Node) {
fmt.Printf("%v:call to func %v\n", n.Line(), Nconv(n.Left, obj.FmtSign))
}
if n.Left.Inl != nil { // normal case
mkinlcall(np, n.Left, int(n.Isddd))
mkinlcall(np, n.Left, n.Isddd)
} else if n.Left.Op == ONAME && n.Left.Left != nil && n.Left.Left.Op == OTYPE && n.Left.Right != nil && n.Left.Right.Op == ONAME { // methods called as functions
if n.Left.Sym.Def != nil {
mkinlcall(np, n.Left.Sym.Def, int(n.Isddd))
mkinlcall(np, n.Left.Sym.Def, n.Isddd)
}
}
......@@ -487,13 +487,13 @@ func inlnode(np **Node) {
Fatal("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, obj.FmtSign))
}
mkinlcall(np, n.Left.Type.Nname, int(n.Isddd))
mkinlcall(np, n.Left.Type.Nname, n.Isddd)
}
lineno = int32(lno)
}
func mkinlcall(np **Node, fn *Node, isddd int) {
func mkinlcall(np **Node, fn *Node, isddd bool) {
save_safemode := safemode
// imported functions may refer to unsafe as long as the
......@@ -525,7 +525,7 @@ var inlgen int
// On return ninit has the parameter assignments, the nbody is the
// inlined function body and list, rlist contain the input, output
// parameters.
func mkinlcall1(np **Node, fn *Node, isddd int) {
func mkinlcall1(np **Node, fn *Node, isddd bool) {
// For variadic fn.
if fn.Inl == nil {
return
......@@ -631,14 +631,14 @@ func mkinlcall1(np **Node, fn *Node, isddd int) {
var varargtype *Type
varargcount := 0
for t := fn.Type.Type.Down.Down.Type; t != nil; t = t.Down {
if t.Isddd != 0 {
if t.Isddd {
variadic = true
varargtype = t.Type
}
}
// but if argument is dotted too forget about variadicity.
if variadic && isddd != 0 {
if variadic && isddd {
variadic = false
}
......@@ -700,7 +700,7 @@ func mkinlcall1(np **Node, fn *Node, isddd int) {
// 0 or 1 expression on RHS.
var i int
for t := getinargx(fn.Type).Type; t != nil; t = t.Down {
if variadic && t.Isddd != 0 {
if variadic && t.Isddd {
vararg = tinlvar(t)
for i = 0; i < varargcount && ll != nil; i++ {
m = argvar(varargtype, i)
......@@ -720,7 +720,7 @@ func mkinlcall1(np **Node, fn *Node, isddd int) {
if ll == nil {
break
}
if variadic && t.Isddd != 0 {
if variadic && t.Isddd {
break
}
as.List = list(as.List, tinlvar(t))
......@@ -729,7 +729,7 @@ func mkinlcall1(np **Node, fn *Node, isddd int) {
}
// match varargcount arguments with variadic parameters.
if variadic && t != nil && t.Isddd != 0 {
if variadic && t != nil && t.Isddd {
vararg = tinlvar(t)
var i int
for i = 0; i < varargcount && ll != nil; i++ {
......
......@@ -1051,9 +1051,9 @@ ok:
for t1 = getthisx(t).Type; t1 != nil; t1 = t1.Down {
dtypesym(t1.Type)
}
isddd := 0
isddd := false
for t1 = getinargx(t).Type; t1 != nil; t1 = t1.Down {
isddd = int(t1.Isddd)
isddd = t1.Isddd
dtypesym(t1.Type)
}
......@@ -1063,7 +1063,7 @@ ok:
ot = dcommontype(s, ot, t)
xt = ot - 3*Widthptr
ot = duint8(s, ot, uint8(isddd))
ot = duint8(s, ot, uint8(bool2int(isddd)))
// two slice headers: in and out.
ot = int(Rnd(int64(ot), int64(Widthptr)))
......
......@@ -2425,10 +2425,10 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
// arg list
var args *NodeList
isddd := 0
isddd := false
for l := in; l != nil; l = l.Next {
args = list(args, l.N.Left)
isddd = int(l.N.Left.Isddd)
isddd = l.N.Left.Isddd
}
methodrcvr := getthisx(method.Type).Type.Type
......@@ -2477,7 +2477,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
fn.Wrapper = true // ignore frame for panic+recover matching
call := Nod(OCALL, dot, nil)
call.List = args
call.Isddd = uint8(isddd)
call.Isddd = isddd
if method.Type.Outtuple > 0 {
n := Nod(ORETURN, nil, nil)
n.List = list1(call)
......
......@@ -44,7 +44,7 @@ type Node struct {
Dodata uint8
Initorder uint8
Used bool
Isddd uint8
Isddd bool // is the argument variadic
Readonly bool
Implicit bool
Addrtaken bool // address taken, even if not moved to heap
......
......@@ -1272,7 +1272,7 @@ OpSwitch:
if l.Op == ONAME {
r := unsafenmagic(n)
if r != nil {
if n.Isddd != 0 {
if n.Isddd {
Yyerror("invalid use of ... with builtin %v", Nconv(l, 0))
}
n = r
......@@ -1285,7 +1285,7 @@ OpSwitch:
n.Diag |= n.Left.Diag
l = n.Left
if l.Op == ONAME && l.Etype != 0 {
if n.Isddd != 0 && l.Etype != OAPPEND {
if n.Isddd && l.Etype != OAPPEND {
Yyerror("invalid use of ... with builtin %v", Nconv(l, 0))
}
......@@ -1301,7 +1301,7 @@ OpSwitch:
defaultlit(&n.Left, nil)
l = n.Left
if l.Op == OTYPE {
if n.Isddd != 0 || l.Type.Bound == -100 {
if n.Isddd || l.Type.Bound == -100 {
if l.Type.Broke == 0 {
Yyerror("invalid use of ... in type conversion", l)
}
......@@ -1324,7 +1324,7 @@ OpSwitch:
return
}
if count(n.List) == 1 && n.Isddd == 0 {
if count(n.List) == 1 && !n.Isddd {
typecheck(&n.List.N, Erv|Efnstruct)
} else {
typechecklist(n.List, Erv)
......@@ -1364,7 +1364,7 @@ OpSwitch:
descbuf := fmt.Sprintf("argument to %v", Nconv(n.Left, 0))
desc := descbuf
typecheckaste(OCALL, n.Left, int(n.Isddd), getinargx(t), n.List, desc)
typecheckaste(OCALL, n.Left, n.Isddd, getinargx(t), n.List, desc)
ok |= Etop
if t.Outtuple == 0 {
break OpSwitch
......@@ -1617,7 +1617,7 @@ OpSwitch:
return
}
if count(args) == 1 && n.Isddd == 0 {
if count(args) == 1 && !n.Isddd {
typecheck(&args.N, Erv|Efnstruct)
} else {
typechecklist(args, Erv)
......@@ -1650,7 +1650,7 @@ OpSwitch:
return
}
if n.Isddd != 0 {
if n.Isddd {
if args.Next == nil {
Yyerror("cannot use ... on first argument to append")
n.Type = nil
......@@ -2127,7 +2127,7 @@ OpSwitch:
if Curfn.Type.Outnamed != 0 && n.List == nil {
break OpSwitch
}
typecheckaste(ORETURN, nil, 0, getoutargx(Curfn.Type), n.List, "return argument")
typecheckaste(ORETURN, nil, false, getoutargx(Curfn.Type), n.List, "return argument")
break OpSwitch
case ORETJMP:
......@@ -2584,7 +2584,7 @@ func nokeys(l *NodeList) bool {
func hasddd(t *Type) bool {
for tl := t.Type; tl != nil; tl = tl.Down {
if tl.Isddd != 0 {
if tl.Isddd {
return true
}
}
......@@ -2604,7 +2604,7 @@ func downcount(t *Type) int {
/*
* typecheck assignment: type list = expression list
*/
func typecheckaste(op int, call *Node, isddd int, tstruct *Type, nl *NodeList, desc string) {
func typecheckaste(op int, call *Node, isddd bool, tstruct *Type, nl *NodeList, desc string) {
var t *Type
var n *Node
var n1 int
......@@ -2635,7 +2635,7 @@ func typecheckaste(op int, call *Node, isddd int, tstruct *Type, nl *NodeList, d
tn := n.Type.Type
var why string
for tl := tstruct.Type; tl != nil; tl = tl.Down {
if tl.Isddd != 0 {
if tl.Isddd {
for ; tn != nil; tn = tn.Down {
if assignop(tn.Type, tl.Type.Type, &why) == 0 {
if call != nil {
......@@ -2681,7 +2681,7 @@ func typecheckaste(op int, call *Node, isddd int, tstruct *Type, nl *NodeList, d
goto notenough
}
} else {
if isddd == 0 {
if !isddd {
if n2 < n1-1 {
goto notenough
}
......@@ -2697,8 +2697,8 @@ func typecheckaste(op int, call *Node, isddd int, tstruct *Type, nl *NodeList, d
for tl := tstruct.Type; tl != nil; tl = tl.Down {
t = tl.Type
if tl.Isddd != 0 {
if isddd != 0 {
if tl.Isddd {
if isddd {
if nl == nil {
goto notenough
}
......@@ -2738,7 +2738,7 @@ func typecheckaste(op int, call *Node, isddd int, tstruct *Type, nl *NodeList, d
if nl != nil {
goto toomany
}
if isddd != 0 {
if isddd {
if call != nil {
Yyerror("invalid use of ... in call to %v", Nconv(call, 0))
} else {
......
......@@ -326,7 +326,7 @@ func walkstmt(np **Node) {
break
}
ll := ascompatte(int(n.Op), nil, 0, Getoutarg(Curfn.Type), n.List, 1, &n.Ninit)
ll := ascompatte(int(n.Op), nil, false, Getoutarg(Curfn.Type), n.List, 1, &n.Ninit)
n.List = ll
case ORETJMP:
......@@ -594,7 +594,7 @@ func walkexpr(np **Node, init **NodeList) {
}
walkexpr(&n.Left, init)
walkexprlist(n.List, init)
ll := ascompatte(int(n.Op), n, int(n.Isddd), getinarg(t), n.List, 0, init)
ll := ascompatte(int(n.Op), n, n.Isddd, getinarg(t), n.List, 0, init)
n.List = reorder1(ll)
goto ret
......@@ -632,7 +632,7 @@ func walkexpr(np **Node, init **NodeList) {
walkexpr(&n.Left, init)
walkexprlist(n.List, init)
ll := ascompatte(int(n.Op), n, int(n.Isddd), getinarg(t), n.List, 0, init)
ll := ascompatte(int(n.Op), n, n.Isddd, getinarg(t), n.List, 0, init)
n.List = reorder1(ll)
goto ret
......@@ -643,8 +643,8 @@ func walkexpr(np **Node, init **NodeList) {
}
walkexpr(&n.Left, init)
walkexprlist(n.List, init)
ll := ascompatte(int(n.Op), n, 0, getthis(t), list1(n.Left.Left), 0, init)
lr := ascompatte(int(n.Op), n, int(n.Isddd), getinarg(t), n.List, 0, init)
ll := ascompatte(int(n.Op), n, false, getthis(t), list1(n.Left.Left), 0, init)
lr := ascompatte(int(n.Op), n, n.Isddd, getinarg(t), n.List, 0, init)
ll = concat(ll, lr)
n.Left.Left = nil
ullmancalc(n.Left)
......@@ -1370,7 +1370,7 @@ func walkexpr(np **Node, init **NodeList) {
goto ret
case OAPPEND:
if n.Isddd != 0 {
if n.Isddd {
n = appendslice(n, init) // also works for append(slice, string).
} else {
n = walkappend(n, init)
......@@ -1841,7 +1841,7 @@ func dumpnodetypes(l *NodeList, what string) string {
* return expr-list
* func(expr-list)
*/
func ascompatte(op int, call *Node, isddd int, nl **Type, lr *NodeList, fp int, init **NodeList) *NodeList {
func ascompatte(op int, call *Node, isddd bool, nl **Type, lr *NodeList, fp int, init **NodeList) *NodeList {
var savel Iter
lr0 := lr
......@@ -1888,7 +1888,7 @@ func ascompatte(op int, call *Node, isddd int, nl **Type, lr *NodeList, fp int,
}
loop:
if l != nil && l.Isddd != 0 {
if l != nil && l.Isddd {
// the ddd parameter must be last
ll = structnext(&savel)
......@@ -1900,7 +1900,7 @@ loop:
// only if we are assigning a single ddd
// argument to a ddd parameter then it is
// passed thru unencapsulated
if r != nil && lr.Next == nil && isddd != 0 && Eqtype(l.Type, r.Type) {
if r != nil && lr.Next == nil && isddd && Eqtype(l.Type, r.Type) {
a = Nod(OAS, nodarg(l, fp), r)
a = convas(a, init)
nn = list(nn, a)
......
......@@ -2052,7 +2052,7 @@ yydefault:
{
yyVAL.node = Nod(OCALL, yyDollar[1].node, nil)
yyVAL.node.List = yyDollar[3].list
yyVAL.node.Isddd = 1
yyVAL.node.Isddd = true
}
case 126:
yyDollar = yyS[yypt-1 : yypt+1]
......@@ -3379,7 +3379,7 @@ yydefault:
if yyDollar[1].sym != nil {
yyVAL.node.Left = newname(yyDollar[1].sym)
}
yyVAL.node.Isddd = 1
yyVAL.node.Isddd = true
yyVAL.node.Val = yyDollar[4].val
}
case 332:
......
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