That was easy.
Fixes #14473.
Change-Id: I9d1d20a5c5a9b1423e6c72c0460ee4a78130864f
Reviewed-on: https://go-review.googlesource.com/20521
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
// 'h' (only in +/debug mode) suppress recursion
// 'l' (only in Error mode) print "foo (type Bar)"
//
-// %H NodeList* NodeLists
+// %H Nodes Nodes
// Flags: those of %N
// ',' separate items with ',' instead of ';'
//
return str
}
-func (l *NodeList) String() string {
- var n Nodes
- for ll := l; ll != nil; ll = ll.Next {
- n.Append(ll.N)
- }
- return Hconv(n, 0)
-}
-
func (n Nodes) String() string {
return Hconv(n, 0)
}
-// Fmt '%H': NodeList.
+// Fmt '%H': Nodes.
// Flags: all those of %N plus ',': separate with comma's instead of semicolons.
func Hconv(l Nodes, flag int) string {
if l.Len() == 0 && fmtmode == FDbg {
}
}
-func slice2nodelist(s []*Node) *NodeList {
- var nl *NodeList
- for _, n := range s {
- nl = list(nl, n)
- }
- return nl
-}
-
-func nodelist2slice(nl *NodeList) []*Node {
- var s []*Node
- for l := nl; l != nil; l = l.Next {
- s = append(s, l.N)
- }
- return s
-}
-
func TestStackvarSort(t *testing.T) {
inp := []*Node{
{Class: PFUNC, Type: &Type{}, Name: &Name{}, Sym: &Sym{}},
)
// runtime interface and reflection data structures
-var signatlist *NodeList
+var signatlist []*Node
// byMethodNameAndPackagePath sorts method signatures by name, then package path.
type byMethodNameAndPackagePath []*Sig
n.Typecheck = 1
s.Def = n
- signatlist = list(signatlist, typenod(t))
+ signatlist = append(signatlist, typenod(t))
}
return s.Def.Sym
}
func dumptypestructs() {
- var n *Node
-
// copy types from externdcl list to signatlist
for _, n := range externdcl {
if n.Op != OTYPE {
continue
}
- signatlist = list(signatlist, n)
+ signatlist = append(signatlist, n)
}
- // process signatlist
- var t *Type
- for l := signatlist; l != nil; l = l.Next {
- n = l.N
+ // Process signatlist. This can't use range, as entries are
+ // added to the list while it is being processed.
+ for i := 0; i < len(signatlist); i++ {
+ n := signatlist[i]
if n.Op != OTYPE {
continue
}
- t = n.Type
+ t := n.Type
dtypesym(t)
if t.Sym != nil {
dtypesym(Ptrto(t))
OEND
)
-// A NodeList is a linked list of nodes.
-// TODO(rsc): Some uses of NodeList should be made into slices.
-// The remaining ones probably just need a simple linked list,
-// not one with concatenation support.
-type NodeList struct {
- N *Node
- Next *NodeList
- End *NodeList
-}
-
-// concat returns the concatenation of the lists a and b.
-// The storage taken by both is reused for the result.
-func concat(a *NodeList, b *NodeList) *NodeList {
- if a == nil {
- return b
- }
- if b == nil {
- return a
- }
-
- a.End.Next = b
- a.End = b.End
- b.End = nil
- return a
-}
-
-// list1 returns a one-element list containing n.
-func list1(n *Node) *NodeList {
- if n == nil {
- return nil
- }
- l := new(NodeList)
- l.N = n
- l.End = l
- return l
-}
-
-// list returns the result of appending n to l.
-func list(l *NodeList, n *Node) *NodeList {
- return concat(l, list1(n))
-}
-
-// count returns the length of the list l.
-func count(l *NodeList) int {
- n := int64(0)
- for ; l != nil; l = l.Next {
- n++
- }
- if int64(int(n)) != n { // Overflow.
- Yyerror("too many elements in list")
- }
- return int(n)
-}
-
// Nodes is a pointer to a slice of *Node.
// For fields that are not used in most nodes, this is used instead of
// a slice to save space.
var ntypecheckdeftype int
-var methodqueue *NodeList
+var methodqueue []*Node
func domethod(n *Node) {
nt := n.Type.Nname
checkwidth(n.Type)
}
-var mapqueue *NodeList
+var mapqueue []*Node
func copytype(n *Node, t *Type) {
if t.Etype == TFORW {
// Queue check for map until all the types are done settling.
if maplineno != 0 {
t.Maplineno = int32(maplineno)
- mapqueue = list(mapqueue, n)
+ mapqueue = append(mapqueue, n)
}
}
// try to resolve the method types for the interfaces
// we just read.
if ntypecheckdeftype == 1 {
- var l *NodeList
for {
- l = methodqueue
- if l == nil {
+ s := methodqueue
+ if len(s) == 0 {
break
}
methodqueue = nil
- for ; l != nil; l = l.Next {
- domethod(l.N)
+ for _, n := range s {
+ domethod(n)
}
}
- for l := mapqueue; l != nil; l = l.Next {
- lineno = l.N.Type.Maplineno
- maptype(l.N.Type, Types[TBOOL])
+ for _, n := range mapqueue {
+ lineno = n.Type.Maplineno
+ maptype(n.Type, Types[TBOOL])
}
lineno = lno
return
}
- methodqueue = list(methodqueue, n)
+ methodqueue = append(methodqueue, n)
}
func typecheckdef(n *Node) *Node {
}
}
-// Isterminating returns whether the NodeList l ends with a
-// terminating statement.
-func (l *NodeList) isterminating() bool {
- if l == nil {
- return false
- }
- for l.Next != nil {
- l = l.Next
- }
- return l.N.isterminating()
-}
-
// Isterminating whether the Nodes list ends with a terminating
// statement.
func (l Nodes) isterminating() bool {