Commit d20b92e0 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: replace more unnecessary **Type with *Type

Also, more lazy variable declarations, and make Dijkstra happy by
replacing "goto loop" with a for loop.

Change-Id: Idf2cd779a92eb3f33bd3394e12c9a0be72002ff4
Reviewed-on: https://go-review.googlesource.com/20496Reviewed-by: default avatarDave Cheney <dave@cheney.net>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 9d77ad8d
...@@ -440,7 +440,7 @@ func cgen_dottype(n *Node, res, resok *Node, wb bool) { ...@@ -440,7 +440,7 @@ func cgen_dottype(n *Node, res, resok *Node, wb bool) {
r1.Type = byteptr r1.Type = byteptr
r2.Type = byteptr r2.Type = byteptr
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type))) setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil)) call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.Params(), call.List.Slice(), 0, nil))
gen(call) gen(call)
Regfree(&r1) Regfree(&r1)
Regfree(&r2) Regfree(&r2)
...@@ -526,7 +526,7 @@ func Cgen_As2dottype(n, res, resok *Node) { ...@@ -526,7 +526,7 @@ func Cgen_As2dottype(n, res, resok *Node) {
dowidth(fn.Type) dowidth(fn.Type)
call := Nod(OCALLFUNC, fn, nil) call := Nod(OCALLFUNC, fn, nil)
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type))) setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil)) call.List.Set(ascompatte(OCALLFUNC, call, false, fn.Type.Params(), call.List.Slice(), 0, nil))
gen(call) gen(call)
Regfree(&r1) Regfree(&r1)
Regfree(&r2) Regfree(&r2)
......
...@@ -328,7 +328,7 @@ func walkstmt(np **Node) { ...@@ -328,7 +328,7 @@ func walkstmt(np **Node) {
break break
} }
ll := ascompatte(n.Op, nil, false, Curfn.Type.ResultsP(), n.List.Slice(), 1, &n.Ninit) ll := ascompatte(n.Op, nil, false, Curfn.Type.Results(), n.List.Slice(), 1, &n.Ninit)
n.List.Set(ll) n.List.Set(ll)
case ORETJMP: case ORETJMP:
...@@ -638,7 +638,7 @@ opswitch: ...@@ -638,7 +638,7 @@ opswitch:
} }
walkexpr(&n.Left, init) walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init) walkexprlist(n.List.Slice(), init)
ll := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init) ll := ascompatte(n.Op, n, n.Isddd, t.Params(), n.List.Slice(), 0, init)
n.List.Set(reorder1(ll)) n.List.Set(reorder1(ll))
case OCALLFUNC: case OCALLFUNC:
...@@ -685,7 +685,7 @@ opswitch: ...@@ -685,7 +685,7 @@ opswitch:
} }
} }
ll := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init) ll := ascompatte(n.Op, n, n.Isddd, t.Params(), n.List.Slice(), 0, init)
n.List.Set(reorder1(ll)) n.List.Set(reorder1(ll))
case OCALLMETH: case OCALLMETH:
...@@ -695,8 +695,8 @@ opswitch: ...@@ -695,8 +695,8 @@ opswitch:
} }
walkexpr(&n.Left, init) walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init) walkexprlist(n.List.Slice(), init)
ll := ascompatte(n.Op, n, false, t.RecvP(), []*Node{n.Left.Left}, 0, init) ll := ascompatte(n.Op, n, false, t.Recv(), []*Node{n.Left.Left}, 0, init)
lr := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init) lr := ascompatte(n.Op, n, n.Isddd, t.Params(), n.List.Slice(), 0, init)
ll = append(ll, lr...) ll = append(ll, lr...)
n.Left.Left = nil n.Left.Left = nil
ullmancalc(n.Left) ullmancalc(n.Left)
...@@ -803,7 +803,7 @@ opswitch: ...@@ -803,7 +803,7 @@ opswitch:
walkexprlistsafe(n.List.Slice(), init) walkexprlistsafe(n.List.Slice(), init)
walkexpr(&r, init) walkexpr(&r, init)
ll := ascompatet(n.Op, n.List, &r.Type, 0, init) ll := ascompatet(n.Op, n.List, r.Type, 0, init)
for i, n := range ll { for i, n := range ll {
ll[i] = applywritebarrier(n) ll[i] = applywritebarrier(n)
} }
...@@ -1701,25 +1701,20 @@ func fncall(l *Node, rt *Type) bool { ...@@ -1701,25 +1701,20 @@ func fncall(l *Node, rt *Type) bool {
return true return true
} }
func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node { // check assign type list to
var l *Node // a expression list. called in
var tmp *Node // expr-list = func()
var a *Node func ascompatet(op Op, nl Nodes, nr *Type, fp int, init *Nodes) []*Node {
r, saver := IterFields(nr)
// check assign type list to var nn, mm []*Node
// a expression list. called in var ullmanOverflow bool
// expr-list = func()
r, saver := IterFields(*nr)
var nn []*Node
var mm []*Node
ucount := 0
var i int var i int
for i = 0; i < nl.Len(); i++ { for i = 0; i < nl.Len(); i++ {
if r == nil { if r == nil {
break break
} }
l = nl.Index(i) l := nl.Index(i)
if isblank(l) { if isblank(l) {
r = saver.Next() r = saver.Next()
continue continue
...@@ -1729,20 +1724,20 @@ func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node { ...@@ -1729,20 +1724,20 @@ func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node {
// deferred until all the return arguments // deferred until all the return arguments
// have been pulled from the output arguments // have been pulled from the output arguments
if fncall(l, r.Type) { if fncall(l, r.Type) {
tmp = temp(r.Type) tmp := temp(r.Type)
typecheck(&tmp, Erv) typecheck(&tmp, Erv)
a = Nod(OAS, l, tmp) a := Nod(OAS, l, tmp)
a = convas(a, init) a = convas(a, init)
mm = append(mm, a) mm = append(mm, a)
l = tmp l = tmp
} }
a = Nod(OAS, l, nodarg(r, fp)) a := Nod(OAS, l, nodarg(r, fp))
a = convas(a, init) a = convas(a, init)
ullmancalc(a) ullmancalc(a)
if a.Ullman >= UINF { if a.Ullman >= UINF {
Dump("ascompatet ucount", a) Dump("ascompatet ucount", a)
ucount++ ullmanOverflow = true
} }
nn = append(nn, a) nn = append(nn, a)
...@@ -1750,10 +1745,10 @@ func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node { ...@@ -1750,10 +1745,10 @@ func ascompatet(op Op, nl Nodes, nr **Type, fp int, init *Nodes) []*Node {
} }
if i < nl.Len() || r != nil { if i < nl.Len() || r != nil {
Yyerror("ascompatet: assignment count mismatch: %d = %d", nl.Len(), structcount(*nr)) Yyerror("ascompatet: assignment count mismatch: %d = %d", nl.Len(), structcount(nr))
} }
if ucount != 0 { if ullmanOverflow {
Fatalf("ascompatet: too many function calls evaluating parameters") Fatalf("ascompatet: too many function calls evaluating parameters")
} }
return append(nn, mm...) return append(nn, mm...)
...@@ -1794,53 +1789,41 @@ func mkdotargslice(lr0, nn []*Node, l *Type, fp int, init *Nodes, ddd *Node) []* ...@@ -1794,53 +1789,41 @@ func mkdotargslice(lr0, nn []*Node, l *Type, fp int, init *Nodes, ddd *Node) []*
} }
// helpers for shape errors // helpers for shape errors
func dumptypes(nl **Type, what string) string { func dumptypes(nl *Type, what string) string {
fmt_ := "" s := ""
fmt_ += "\t" for l, it := IterFields(nl); l != nil; l = it.Next() {
first := 1 if s != "" {
for l, it := IterFields(*nl); l != nil; l = it.Next() { s += ", "
if first != 0 {
first = 0
} else {
fmt_ += ", "
} }
fmt_ += Tconv(l, 0) s += Tconv(l, 0)
} }
if s == "" {
if first != 0 { s = fmt.Sprintf("[no arguments %s]", what)
fmt_ += fmt.Sprintf("[no arguments %s]", what)
} }
return fmt_ return s
} }
func dumpnodetypes(l []*Node, what string) string { func dumpnodetypes(l []*Node, what string) string {
var r *Node s := ""
for _, r := range l {
fmt_ := "" if s != "" {
fmt_ += "\t" s += ", "
first := 1
for _, r = range l {
if first != 0 {
first = 0
} else {
fmt_ += ", "
} }
fmt_ += Tconv(r.Type, 0) s += Tconv(r.Type, 0)
} }
if s == "" {
if first != 0 { s = fmt.Sprintf("[no arguments %s]", what)
fmt_ += fmt.Sprintf("[no arguments %s]", what)
} }
return fmt_ return s
} }
// check assign expression list to // check assign expression list to
// a type list. called in // a type list. called in
// return expr-list // return expr-list
// func(expr-list) // func(expr-list)
func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, init *Nodes) []*Node { func ascompatte(op Op, call *Node, isddd bool, nl *Type, lr []*Node, fp int, init *Nodes) []*Node {
lr0 := lr lr0 := lr
l, savel := IterFields(*nl) l, savel := IterFields(nl)
var r *Node var r *Node
if nodeSeqLen(lr) > 0 { if nodeSeqLen(lr) > 0 {
r = nodeSeqFirst(lr) r = nodeSeqFirst(lr)
...@@ -1848,17 +1831,13 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in ...@@ -1848,17 +1831,13 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in
var nn []*Node var nn []*Node
// f(g()) where g has multiple return values // f(g()) where g has multiple return values
var a *Node
var l2 string
var ll *Type
var l1 string
if r != nil && nodeSeqLen(lr) <= 1 && r.Type.Etype == TSTRUCT && r.Type.Funarg { if r != nil && nodeSeqLen(lr) <= 1 && r.Type.Etype == TSTRUCT && r.Type.Funarg {
// optimization - can do block copy // optimization - can do block copy
if eqtypenoname(r.Type, *nl) { if eqtypenoname(r.Type, nl) {
a := nodarg(*nl, fp) arg := nodarg(nl, fp)
r = Nod(OCONVNOP, r, nil) r = Nod(OCONVNOP, r, nil)
r.Type = a.Type r.Type = arg.Type
nn = []*Node{convas(Nod(OAS, a, r), init)} nn = []*Node{convas(Nod(OAS, arg, r), init)}
goto ret goto ret
} }
...@@ -1867,11 +1846,11 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in ...@@ -1867,11 +1846,11 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in
var alist []*Node var alist []*Node
for l, it := IterFields(r.Type); l != nil; l = it.Next() { for l, it := IterFields(r.Type); l != nil; l = it.Next() {
a = temp(l.Type) tmp := temp(l.Type)
alist = append(alist, a) alist = append(alist, tmp)
} }
a = Nod(OAS2, nil, nil) a := Nod(OAS2, nil, nil)
a.List.Set(alist) a.List.Set(alist)
a.Rlist.Set(lr) a.Rlist.Set(lr)
typecheck(&a, Etop) typecheck(&a, Etop)
...@@ -1879,62 +1858,62 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in ...@@ -1879,62 +1858,62 @@ func ascompatte(op Op, call *Node, isddd bool, nl **Type, lr []*Node, fp int, in
init.Append(a) init.Append(a)
lr = alist lr = alist
r = nodeSeqFirst(lr) r = nodeSeqFirst(lr)
l, savel = IterFields(*nl) l, savel = IterFields(nl)
} }
loop: for {
if l != nil && l.Isddd { if l != nil && l.Isddd {
// the ddd parameter must be last // the ddd parameter must be last
ll = savel.Next() ll := savel.Next()
if ll != nil { if ll != nil {
Yyerror("... must be last argument") Yyerror("... must be last argument")
} }
// special case -- // special case --
// only if we are assigning a single ddd // only if we are assigning a single ddd
// argument to a ddd parameter then it is // argument to a ddd parameter then it is
// passed thru unencapsulated // passed thru unencapsulated
if r != nil && len(lr) <= 1 && isddd && Eqtype(l.Type, r.Type) { if r != nil && len(lr) <= 1 && isddd && Eqtype(l.Type, r.Type) {
a = Nod(OAS, nodarg(l, fp), r) a := Nod(OAS, nodarg(l, fp), r)
a = convas(a, init) a = convas(a, init)
nn = append(nn, a) nn = append(nn, a)
goto ret break
} }
// normal case -- make a slice of all // normal case -- make a slice of all
// remaining arguments and pass it to // remaining arguments and pass it to
// the ddd parameter. // the ddd parameter.
nn = mkdotargslice(lr, nn, l, fp, init, call.Right) nn = mkdotargslice(lr, nn, l, fp, init, call.Right)
goto ret break
} }
if l == nil || r == nil { if l == nil || r == nil {
if l != nil || r != nil { if l != nil || r != nil {
l1 = dumptypes(nl, "expected") l1 := dumptypes(nl, "expected")
l2 = dumpnodetypes(lr0, "given") l2 := dumpnodetypes(lr0, "given")
if l != nil { if l != nil {
Yyerror("not enough arguments to %v\n%s\n%s", Oconv(op, 0), l1, l2) Yyerror("not enough arguments to %v\n\t%s\n\t%s", Oconv(op, 0), l1, l2)
} else { } else {
Yyerror("too many arguments to %v\n%s\n%s", Oconv(op, 0), l1, l2) Yyerror("too many arguments to %v\n\t%s\n\t%s", Oconv(op, 0), l1, l2)
}
} }
}
goto ret break
} }
a = Nod(OAS, nodarg(l, fp), r) a := Nod(OAS, nodarg(l, fp), r)
a = convas(a, init) a = convas(a, init)
nn = append(nn, a) nn = append(nn, a)
l = savel.Next() l = savel.Next()
r = nil r = nil
lr = lr[1:] lr = lr[1:]
if len(lr) > 0 { if len(lr) > 0 {
r = lr[0] r = lr[0]
}
} }
goto loop
ret: ret:
for _, n := range nn { for _, n := range nn {
......
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