Curfn = fn
fn.Func.Dupok = true
typecheck(&fn, Etop)
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typechecklist(fn.Nbody, Etop)
Curfn = nil
// Disable safemode while compiling this code: the code we
Curfn = fn
fn.Func.Dupok = true
typecheck(&fn, Etop)
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typechecklist(fn.Nbody, Etop)
Curfn = nil
// Disable safemode while compiling this code: the code we
Curfn = func_
olddd := decldepth
decldepth = 1
- typecheckslice(func_.Nbody.Slice(), Etop)
+ typechecklist(func_.Nbody, Etop)
decldepth = olddd
Curfn = oldfn
}
savefn := Curfn
Curfn = fn
- typecheckslice(fn.Func.Inl.Slice(), Etop)
+ typechecklist(fn.Func.Inl, Etop)
Curfn = savefn
safemode = save_safemode
Curfn = l.N
decldepth = 1
saveerrors()
- typecheckslice(l.N.Nbody.Slice(), Etop)
+ typechecklist(l.N.Nbody, Etop)
checkreturn(l.N)
if nerrors != 0 {
l.N.Nbody.Set(nil) // type errors; do not compile
}
decldepth++
- typecheckslice(n.Nbody.Slice(), Etop)
+ typechecklist(n.Nbody, Etop)
decldepth--
}
n.Nbody.Append(v1)
typecheck(&n.Left, Erv)
- typecheckslice(n.Nbody.Slice(), Etop)
+ typechecklist(n.Nbody, Etop)
walkstmt(&n)
return true
}
}
}
- typecheckslice(ncase.Nbody.Slice(), Etop)
+ typechecklist(ncase.Nbody, Etop)
}
sel.Xoffset = int64(count)
fn.Func.Dupok = true
}
typecheck(&fn, Etop)
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typechecklist(fn.Nbody, Etop)
inlcalls(fn)
escAnalyze([]*Node{fn}, false)
}
}
- typecheckslice(ncase.Nbody.Slice(), Etop)
+ typechecklist(ncase.Nbody, Etop)
}
lineno = lno
}
}
}
+
+// nodeSeqIterator is an interface used to iterate over a sequence of nodes.
+// TODO(iant): Remove after conversion from NodeList to Nodes is complete.
+type nodeSeqIterator interface {
+ // Return whether iteration is complete.
+ Done() bool
+ // Advance to the next node.
+ Next()
+ // Return the current node.
+ N() *Node
+ // Return the address of the current node.
+ P() **Node
+}
+
+// nodeListIterator is a type that implements nodeSeqIterator using a
+// *NodeList.
+type nodeListIterator struct {
+ l *NodeList
+}
+
+func (nli *nodeListIterator) Done() bool {
+ return nli.l == nil
+}
+
+func (nli *nodeListIterator) Next() {
+ nli.l = nli.l.Next
+}
+
+func (nli *nodeListIterator) N() *Node {
+ return nli.l.N
+}
+
+func (nli *nodeListIterator) P() **Node {
+ return &nli.l.N
+}
+
+// nodesIterator implements nodeSeqIterator using a Nodes.
+type nodesIterator struct {
+ n Nodes
+ i int
+}
+
+func (ni *nodesIterator) Done() bool {
+ return ni.i >= len(ni.n.Slice())
+}
+
+func (ni *nodesIterator) Next() {
+ ni.i++
+}
+
+func (ni *nodesIterator) N() *Node {
+ return ni.n.Slice()[ni.i]
+}
+
+func (ni *nodesIterator) P() **Node {
+ return &ni.n.Slice()[ni.i]
+}
+
+// nodeSeqIterate returns an iterator over either a *Nodelist or a *Nodes.
+func nodeSeqIterate(ns interface{}) nodeSeqIterator {
+ switch ns := ns.(type) {
+ case *NodeList:
+ return &nodeListIterator{ns}
+ case Nodes:
+ return &nodesIterator{ns, 0}
+ default:
+ panic("can't happen")
+ }
+}
return n
}
-func typechecklist(l *NodeList, top int) {
- for ; l != nil; l = l.Next {
- typecheck(&l.N, top)
+func typechecklist(l interface{}, top int) {
+ for it := nodeSeqIterate(l); !it.Done(); it.Next() {
+ typecheck(it.P(), top)
}
}
}
}
typecheck(&n.Right, Etop)
- typecheckslice(n.Nbody.Slice(), Etop)
+ typechecklist(n.Nbody, Etop)
decldepth--
break OpSwitch
Yyerror("non-bool %v used as if condition", Nconv(n.Left, obj.FmtLong))
}
}
- typecheckslice(n.Nbody.Slice(), Etop)
+ typechecklist(n.Nbody, Etop)
typechecklist(n.Rlist, Etop)
break OpSwitch
case OXCASE:
ok |= Etop
typechecklist(n.List, Erv)
- typecheckslice(n.Nbody.Slice(), Etop)
+ typechecklist(n.Nbody, Etop)
break OpSwitch
case ODCLFUNC:
funcbody(fn)
typecheck(&fn, Etop)
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typechecklist(fn.Nbody, Etop)
xtop = list(xtop, fn)
Curfn = oldfn