1
0
mirror of https://github.com/golang/go synced 2024-11-18 02:44:48 -07:00

cmd/compile: convert externdecl to []*Node

This one of a set of changes to make the transition away from NodeList
easier by removing cases in which NodeList doesn't act semi-trivially like a
[]*Node.

This CL was originally prepared by Josh Bleecher Snyder <josharian@gmail.com>.

This change passes go build -toolexec 'toolstash -cmp' -a std.

Change-Id: Ifd73501e06e8ea5efd028b6d473b3e5d1b07a5ac
Reviewed-on: https://go-review.googlesource.com/14570
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Dave Cheney 2015-09-10 15:57:39 +10:00
parent 1fd78e1f60
commit d5fe165ca0
6 changed files with 29 additions and 36 deletions

View File

@ -182,7 +182,7 @@ func declare(n *Node, ctxt uint8) {
gen := 0 gen := 0
if ctxt == PEXTERN { if ctxt == PEXTERN {
externdcl = list(externdcl, n) externdcl = append(externdcl, n)
if dflag() { if dflag() {
fmt.Printf("\t%v global decl %v %p\n", Ctxt.Line(int(lineno)), s, n) fmt.Printf("\t%v global decl %v %p\n", Ctxt.Line(int(lineno)), s, n)
} }

View File

@ -584,7 +584,7 @@ var maxfltval [NTYPE]*Mpflt
var xtop *NodeList var xtop *NodeList
var externdcl *NodeList var externdcl []*Node
var exportlist []*Node var exportlist []*Node

View File

@ -464,9 +464,9 @@ func Main() {
} }
// Phase 9: Check external declarations. // Phase 9: Check external declarations.
for l := externdcl; l != nil; l = l.Next { for i, n := range externdcl {
if l.N.Op == ONAME { if n.Op == ONAME {
typecheck(&l.N, Erv) typecheck(&externdcl[i], Erv)
} }
} }

View File

@ -72,10 +72,7 @@ func dumpobj() {
fmt.Fprintf(bout, "\n!\n") fmt.Fprintf(bout, "\n!\n")
var externs *NodeList externs := len(externdcl)
if externdcl != nil {
externs = externdcl.End
}
dumpglobls() dumpglobls()
dumptypestructs() dumptypestructs()
@ -83,8 +80,8 @@ func dumpobj() {
// Dump extra globals. // Dump extra globals.
tmp := externdcl tmp := externdcl
if externs != nil { if externdcl != nil {
externdcl = externs.Next externdcl = externdcl[externs:]
} }
dumpglobls() dumpglobls()
externdcl = tmp externdcl = tmp
@ -110,8 +107,7 @@ func dumpglobls() {
var n *Node var n *Node
// add globals // add globals
for l := externdcl; l != nil; l = l.Next { for _, n := range externdcl {
n = l.N
if n.Op != ONAME { if n.Op != ONAME {
continue continue
} }
@ -126,7 +122,6 @@ func dumpglobls() {
continue continue
} }
dowidth(n.Type) dowidth(n.Type)
ggloblnod(n) ggloblnod(n)
} }

View File

@ -1317,8 +1317,7 @@ func dumptypestructs() {
var n *Node var n *Node
// copy types from externdcl list to signatlist // copy types from externdcl list to signatlist
for l := externdcl; l != nil; l = l.Next { for _, n := range externdcl {
n = l.N
if n.Op != OTYPE { if n.Op != OTYPE {
continue continue
} }

View File

@ -1584,33 +1584,32 @@ func Ptrto(t *Type) *Type {
} }
func frame(context int) { func frame(context int) {
var l *NodeList
if context != 0 { if context != 0 {
fmt.Printf("--- external frame ---\n") fmt.Printf("--- external frame ---\n")
l = externdcl for _, n := range externdcl {
} else if Curfn != nil { printframenode(n)
fmt.Printf("--- %v frame ---\n", Curfn.Func.Nname.Sym) }
l = Curfn.Func.Dcl
} else {
return return
} }
var n *Node if Curfn != nil {
var w int64 fmt.Printf("--- %v frame ---\n", Curfn.Func.Nname.Sym)
for ; l != nil; l = l.Next { for l := Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N printframenode(l.N)
w = -1
if n.Type != nil {
w = n.Type.Width
} }
switch n.Op { }
case ONAME: }
fmt.Printf("%v %v G%d %v width=%d\n", Oconv(int(n.Op), 0), n.Sym, n.Name.Vargen, n.Type, w)
case OTYPE: func printframenode(n *Node) {
fmt.Printf("%v %v width=%d\n", Oconv(int(n.Op), 0), n.Type, w) w := int64(-1)
} if n.Type != nil {
w = n.Type.Width
}
switch n.Op {
case ONAME:
fmt.Printf("%v %v G%d %v width=%d\n", Oconv(int(n.Op), 0), n.Sym, n.Name.Vargen, n.Type, w)
case OTYPE:
fmt.Printf("%v %v width=%d\n", Oconv(int(n.Op), 0), n.Type, w)
} }
} }