cmd/compile: convert cgen/gen/pgen and friends to nodeListSeq
Added Seq method to nodeListIterator. Added new functions nodeSeqLen,
nodeSeqFirst, nodeSeqSecond. Allow nil as source argument to setNodeSeq.
Change-Id: Ifc1cd4d7207b7a125b3830c92c4d6d6f00eedd54
Reviewed-on: https://go-review.googlesource.com/20195
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go
index 92ee2ae..a978e1af 100644
--- a/src/cmd/compile/internal/gc/gen.go
+++ b/src/cmd/compile/internal/gc/gen.go
@@ -215,15 +215,9 @@
}
// compile statements
-func Genlist(l *NodeList) {
- for ; l != nil; l = l.Next {
- gen(l.N)
- }
-}
-
-func Genslice(l []*Node) {
- for _, n := range l {
- gen(n)
+func Genlist(l nodesOrNodeList) {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
+ gen(it.N())
}
}
@@ -445,8 +439,8 @@
call := Nod(OCALLFUNC, fn, nil)
r1.Type = byteptr
r2.Type = byteptr
- call.List = list(list(list1(&r1), &r2), typename(n.Left.Type))
- call.List = ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List, 0, nil)
+ setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List, 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
@@ -531,8 +525,8 @@
fn := syslook("panicdottype", 0)
dowidth(fn.Type)
call := Nod(OCALLFUNC, fn, nil)
- call.List = list(list(list1(&r1), &r2), typename(n.Left.Type))
- call.List = ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List, 0, nil)
+ setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List, 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
@@ -644,7 +638,7 @@
goto ret
}
- if n.Ninit != nil {
+ if nodeSeqLen(n.Ninit) > 0 {
Genlist(n.Ninit)
}
@@ -779,7 +773,7 @@
gen(n.Right) // contin: incr
Patch(p1, Pc) // test:
Bgen(n.Left, false, -1, breakpc) // if(!test) goto break
- Genslice(n.Nbody.Slice()) // body
+ Genlist(n.Nbody) // body
gjmp(continpc)
Patch(breakpc, Pc) // done:
continpc = scontin
@@ -794,7 +788,7 @@
p2 := gjmp(nil) // p2: goto else
Patch(p1, Pc) // test:
Bgen(n.Left, false, int(-n.Likely), p2) // if(!test) goto p2
- Genslice(n.Nbody.Slice()) // then
+ Genlist(n.Nbody) // then
p3 := gjmp(nil) // goto done
Patch(p2, Pc) // else:
Genlist(n.Rlist) // else
@@ -811,9 +805,9 @@
lab.Breakpc = breakpc
}
- Patch(p1, Pc) // test:
- Genslice(n.Nbody.Slice()) // switch(test) body
- Patch(breakpc, Pc) // done:
+ Patch(p1, Pc) // test:
+ Genlist(n.Nbody) // switch(test) body
+ Patch(breakpc, Pc) // done:
breakpc = sbreak
if lab != nil {
lab.Breakpc = nil
@@ -830,9 +824,9 @@
lab.Breakpc = breakpc
}
- Patch(p1, Pc) // test:
- Genslice(n.Nbody.Slice()) // select() body
- Patch(breakpc, Pc) // done:
+ Patch(p1, Pc) // test:
+ Genlist(n.Nbody) // select() body
+ Patch(breakpc, Pc) // done:
breakpc = sbreak
if lab != nil {
lab.Breakpc = nil
@@ -851,7 +845,7 @@
Cgen_as_wb(n.Left, n.Right, true)
case OAS2DOTTYPE:
- cgen_dottype(n.Rlist.N, n.List.N, n.List.Next.N, needwritebarrier(n.List.N, n.Rlist.N))
+ cgen_dottype(nodeSeqFirst(n.Rlist), nodeSeqFirst(n.List), nodeSeqSecond(n.List), needwritebarrier(nodeSeqFirst(n.List), nodeSeqFirst(n.Rlist)))
case OCALLMETH:
cgen_callmeth(n, 0)