]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove NodeList type
authorIan Lance Taylor <iant@golang.org>
Thu, 10 Mar 2016 18:00:29 +0000 (10:00 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 10 Mar 2016 18:22:07 +0000 (18:22 +0000)
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>

src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/pgen_test.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/typecheck.go

index a8867ff4b504f9bd3dd54013cb5a18b01bfdf4d5..91c7ec863c85119e686792b9c15dda1d905da1f0 100644 (file)
@@ -43,7 +43,7 @@ import (
 //                     '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 ';'
 //
@@ -1698,19 +1698,11 @@ func Nconv(n *Node, flag int) string {
        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 {
index 58ed41f92341f12064df3f60428c295bdd0c37ac..fcb8bfa0c237529cf7b0f6edbef517e08882d341 100644 (file)
@@ -119,22 +119,6 @@ func TestCmpstackvar(t *testing.T) {
        }
 }
 
-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{}},
index f2ad9e7efc579b31c93224967c4768b699e7710b..0679853cec6d626fcd170324b2feecc3d7431e28 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 // runtime interface and reflection data structures
-var signatlist *NodeList
+var signatlist []*Node
 
 // byMethodNameAndPackagePath sorts method signatures by name, then package path.
 type byMethodNameAndPackagePath []*Sig
@@ -863,7 +863,7 @@ func typenamesym(t *Type) *Sym {
                n.Typecheck = 1
                s.Def = n
 
-               signatlist = list(signatlist, typenod(t))
+               signatlist = append(signatlist, typenod(t))
        }
 
        return s.Def.Sym
@@ -1235,24 +1235,22 @@ ok:
 }
 
 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))
index 7a31ce9d7a00cf2d5831130a1ea80ba51082e5e1..1c38c43ff7dd69864fc7d6afd451248066e6154d 100644 (file)
@@ -360,60 +360,6 @@ const (
        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.
index 22fd9e4d2bb33186ec0179c2507378f053d14b93..6d52ece21abcf121bb30bfdea559ed5f388001d6 100644 (file)
@@ -3478,7 +3478,7 @@ func stringtoarraylit(np **Node) {
 
 var ntypecheckdeftype int
 
-var methodqueue *NodeList
+var methodqueue []*Node
 
 func domethod(n *Node) {
        nt := n.Type.Nname
@@ -3511,7 +3511,7 @@ func domethod(n *Node) {
        checkwidth(n.Type)
 }
 
-var mapqueue *NodeList
+var mapqueue []*Node
 
 func copytype(n *Node, t *Type) {
        if t.Etype == TFORW {
@@ -3561,7 +3561,7 @@ func copytype(n *Node, t *Type) {
        // 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)
        }
 }
 
@@ -3597,21 +3597,20 @@ ret:
        // try to resolve the method types for the interfaces
        // we just read.
        if ntypecheckdeftype == 1 {
-               var l *NodeList
                for {
-                       = 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
@@ -3626,7 +3625,7 @@ func queuemethod(n *Node) {
                return
        }
 
-       methodqueue = list(methodqueue, n)
+       methodqueue = append(methodqueue, n)
 }
 
 func typecheckdef(n *Node) *Node {
@@ -3902,18 +3901,6 @@ func markbreaklist(l Nodes, implicit *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 {