Commit 3a89065c authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: replace nod(ONAME) with newname

Passes toolstash-check -all.

Change-Id: Ib9f969e5ecc1537b7eab186dc4fd504a50f800f2
Reviewed-on: https://go-review.googlesource.com/38586
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent e67d881b
...@@ -623,13 +623,10 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node { ...@@ -623,13 +623,10 @@ func makepartialcall(fn *Node, t0 *Type, meth *Sym) *Node {
if int(cv.Type.Align) > Widthptr { if int(cv.Type.Align) > Widthptr {
cv.Xoffset = int64(cv.Type.Align) cv.Xoffset = int64(cv.Type.Align)
} }
ptr := nod(ONAME, nil, nil) ptr := newname(lookup("rcvr"))
ptr.Sym = lookup("rcvr")
ptr.Class = PAUTO ptr.Class = PAUTO
ptr.SetAddable(true)
ptr.SetUsed(true) ptr.SetUsed(true)
ptr.Name.Curfn = xfunc ptr.Name.Curfn = xfunc
ptr.Xoffset = 0
xfunc.Func.Dcl = append(xfunc.Func.Dcl, ptr) xfunc.Func.Dcl = append(xfunc.Func.Dcl, ptr)
var body []*Node var body []*Node
if rcvrtype.IsPtr() || rcvrtype.IsInterface() { if rcvrtype.IsPtr() || rcvrtype.IsInterface() {
......
...@@ -283,18 +283,6 @@ func variter(vl []*Node, t *Node, el []*Node) []*Node { ...@@ -283,18 +283,6 @@ func variter(vl []*Node, t *Node, el []*Node) []*Node {
return init return init
} }
// newname returns a new ONAME Node associated with symbol s.
func newname(s *Sym) *Node {
if s == nil {
Fatalf("newname nil")
}
n := nod(ONAME, nil, nil)
n.Sym = s
n.SetAddable(true)
n.Xoffset = 0
return n
}
// newnoname returns a new ONONAME Node associated with symbol s. // newnoname returns a new ONONAME Node associated with symbol s.
func newnoname(s *Sym) *Node { func newnoname(s *Sym) *Node {
if s == nil { if s == nil {
...@@ -366,8 +354,7 @@ func oldname(s *Sym) *Node { ...@@ -366,8 +354,7 @@ func oldname(s *Sym) *Node {
c := n.Name.Param.Innermost c := n.Name.Param.Innermost
if c == nil || c.Name.Funcdepth != funcdepth { if c == nil || c.Name.Funcdepth != funcdepth {
// Do not have a closure var for the active closure yet; make one. // Do not have a closure var for the active closure yet; make one.
c = nod(ONAME, nil, nil) c = newname(s)
c.Sym = s
c.Class = PAUTOHEAP c.Class = PAUTOHEAP
c.SetIsClosureVar(true) c.SetIsClosureVar(true)
c.SetIsddd(n.Isddd()) c.SetIsddd(n.Isddd())
...@@ -380,7 +367,6 @@ func oldname(s *Sym) *Node { ...@@ -380,7 +367,6 @@ func oldname(s *Sym) *Node {
c.Name.Param.Outer = n.Name.Param.Innermost c.Name.Param.Outer = n.Name.Param.Innermost
n.Name.Param.Innermost = c n.Name.Param.Innermost = c
c.Xoffset = 0
Curfn.Func.Cvars.Append(c) Curfn.Func.Cvars.Append(c)
} }
......
...@@ -1440,9 +1440,9 @@ func (e *EscState) initEscRetval(call *Node, fntype *Type) { ...@@ -1440,9 +1440,9 @@ func (e *EscState) initEscRetval(call *Node, fntype *Type) {
cE := e.nodeEscState(call) cE := e.nodeEscState(call)
cE.Retval.Set(nil) // Suspect this is not nil for indirect calls. cE.Retval.Set(nil) // Suspect this is not nil for indirect calls.
for i, f := range fntype.Results().Fields().Slice() { for i, f := range fntype.Results().Fields().Slice() {
ret := nod(ONAME, nil, nil)
buf := fmt.Sprintf(".out%d", i) buf := fmt.Sprintf(".out%d", i)
ret.Sym = lookup(buf) ret := newname(lookup(buf))
ret.SetAddable(false) // TODO(mdempsky): Seems suspicious.
ret.Type = f.Type ret.Type = f.Type
ret.Class = PAUTO ret.Class = PAUTO
ret.Name.Curfn = Curfn ret.Name.Curfn = Curfn
......
...@@ -133,8 +133,8 @@ func moveToHeap(n *Node) { ...@@ -133,8 +133,8 @@ func moveToHeap(n *Node) {
// Preserve a copy so we can still write code referring to the original, // Preserve a copy so we can still write code referring to the original,
// and substitute that copy into the function declaration list // and substitute that copy into the function declaration list
// so that analyses of the local (on-stack) variables use it. // so that analyses of the local (on-stack) variables use it.
stackcopy := nod(ONAME, nil, nil) stackcopy := newname(n.Sym)
stackcopy.Sym = n.Sym stackcopy.SetAddable(false)
stackcopy.Type = n.Type stackcopy.Type = n.Type
stackcopy.Xoffset = n.Xoffset stackcopy.Xoffset = n.Xoffset
stackcopy.Class = n.Class stackcopy.Class = n.Class
...@@ -200,19 +200,16 @@ func tempname(nn *Node, t *Type) { ...@@ -200,19 +200,16 @@ func tempname(nn *Node, t *Type) {
// Add a preceding . to avoid clash with legal names. // Add a preceding . to avoid clash with legal names.
s := lookupN(".autotmp_", statuniqgen) s := lookupN(".autotmp_", statuniqgen)
statuniqgen++ statuniqgen++
n := nod(ONAME, nil, nil) n := newname(s)
n.Sym = s
s.Def = n s.Def = n
n.Type = t n.Type = t
n.Class = PAUTO n.Class = PAUTO
n.SetAddable(true)
n.Esc = EscNever n.Esc = EscNever
n.Name.Curfn = Curfn n.Name.Curfn = Curfn
n.Name.SetAutoTemp(true) n.Name.SetAutoTemp(true)
Curfn.Func.Dcl = append(Curfn.Func.Dcl, n) Curfn.Func.Dcl = append(Curfn.Func.Dcl, n)
dowidth(t) dowidth(t)
n.Xoffset = 0
*nn = *n *nn = *n
} }
......
...@@ -226,8 +226,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -226,8 +226,7 @@ func nodarg(t interface{}, fp int) *Node {
funarg = t.StructType().Funarg funarg = t.StructType().Funarg
// Build fake variable name for whole arg struct. // Build fake variable name for whole arg struct.
n = nod(ONAME, nil, nil) n = newname(lookup(".args"))
n.Sym = lookup(".args")
n.Type = t n.Type = t
first := t.Field(0) first := t.Field(0)
if first == nil { if first == nil {
...@@ -237,7 +236,6 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -237,7 +236,6 @@ func nodarg(t interface{}, fp int) *Node {
Fatalf("nodarg: offset not computed for %v", t) Fatalf("nodarg: offset not computed for %v", t)
} }
n.Xoffset = first.Offset n.Xoffset = first.Offset
n.SetAddable(true)
case *Field: case *Field:
funarg = t.Funarg funarg = t.Funarg
...@@ -275,14 +273,12 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -275,14 +273,12 @@ func nodarg(t interface{}, fp int) *Node {
// Build fake name for individual variable. // Build fake name for individual variable.
// This is safe because if there was a real declared name // This is safe because if there was a real declared name
// we'd have used it above. // we'd have used it above.
n = nod(ONAME, nil, nil) n = newname(lookup("__"))
n.Type = t.Type n.Type = t.Type
n.Sym = t.Sym
if t.Offset == BADWIDTH { if t.Offset == BADWIDTH {
Fatalf("nodarg: offset not computed for %v", t) Fatalf("nodarg: offset not computed for %v", t)
} }
n.Xoffset = t.Offset n.Xoffset = t.Offset
n.SetAddable(true)
n.Orig = t.Nname n.Orig = t.Nname
} }
......
...@@ -332,7 +332,11 @@ func importdot(opkg *Pkg, pack *Node) { ...@@ -332,7 +332,11 @@ func importdot(opkg *Pkg, pack *Node) {
} }
} }
func nod(op Op, nleft *Node, nright *Node) *Node { func nod(op Op, nleft, nright *Node) *Node {
return nodl(lineno, op, nleft, nright)
}
func nodl(pos src.XPos, op Op, nleft, nright *Node) *Node {
var n *Node var n *Node
switch op { switch op {
case OCLOSURE, ODCLFUNC: case OCLOSURE, ODCLFUNC:
...@@ -343,14 +347,7 @@ func nod(op Op, nleft *Node, nright *Node) *Node { ...@@ -343,14 +347,7 @@ func nod(op Op, nleft *Node, nright *Node) *Node {
n = &x.Node n = &x.Node
n.Func = &x.Func n.Func = &x.Func
case ONAME: case ONAME:
var x struct { Fatalf("use newname instead")
Node
Name
Param
}
n = &x.Node
n.Name = &x.Name
n.Name.Param = &x.Param
case OLABEL, OPACK: case OLABEL, OPACK:
var x struct { var x struct {
Node Node
...@@ -364,12 +361,34 @@ func nod(op Op, nleft *Node, nright *Node) *Node { ...@@ -364,12 +361,34 @@ func nod(op Op, nleft *Node, nright *Node) *Node {
n.Op = op n.Op = op
n.Left = nleft n.Left = nleft
n.Right = nright n.Right = nright
n.Pos = lineno n.Pos = pos
n.Xoffset = BADWIDTH n.Xoffset = BADWIDTH
n.Orig = n n.Orig = n
if n.Name != nil { return n
n.Name.Curfn = Curfn }
// newname returns a new ONAME Node associated with symbol s.
func newname(s *Sym) *Node {
if s == nil {
Fatalf("newname nil")
}
var x struct {
Node
Name
Param
} }
n := &x.Node
n.Name = &x.Name
n.Name.Param = &x.Param
n.Op = ONAME
n.Pos = lineno
n.Name.Curfn = Curfn
n.Orig = n
n.Sym = s
n.SetAddable(true)
return n return n
} }
......
...@@ -102,15 +102,13 @@ func lexinit() { ...@@ -102,15 +102,13 @@ func lexinit() {
for _, s := range builtinFuncs { for _, s := range builtinFuncs {
// TODO(marvin): Fix Node.EType type union. // TODO(marvin): Fix Node.EType type union.
s2 := Pkglookup(s.name, builtinpkg) s2 := Pkglookup(s.name, builtinpkg)
s2.Def = nod(ONAME, nil, nil) s2.Def = newname(s2)
s2.Def.Sym = s2
s2.Def.Etype = EType(s.op) s2.Def.Etype = EType(s.op)
} }
for _, s := range unsafeFuncs { for _, s := range unsafeFuncs {
s2 := Pkglookup(s.name, unsafepkg) s2 := Pkglookup(s.name, unsafepkg)
s2.Def = nod(ONAME, nil, nil) s2.Def = newname(s2)
s2.Def.Sym = s2
s2.Def.Etype = EType(s.op) s2.Def.Etype = EType(s.op)
} }
...@@ -132,16 +130,14 @@ func lexinit() { ...@@ -132,16 +130,14 @@ func lexinit() {
s = lookup("_") s = lookup("_")
s.Block = -100 s.Block = -100
s.Def = nod(ONAME, nil, nil) s.Def = newname(s)
s.Def.Sym = s
Types[TBLANK] = typ(TBLANK) Types[TBLANK] = typ(TBLANK)
s.Def.Type = Types[TBLANK] s.Def.Type = Types[TBLANK]
nblank = s.Def nblank = s.Def
s = Pkglookup("_", builtinpkg) s = Pkglookup("_", builtinpkg)
s.Block = -100 s.Block = -100
s.Def = nod(ONAME, nil, nil) s.Def = newname(s)
s.Def.Sym = s
Types[TBLANK] = typ(TBLANK) Types[TBLANK] = typ(TBLANK)
s.Def.Type = Types[TBLANK] s.Def.Type = Types[TBLANK]
...@@ -464,9 +460,7 @@ func finishUniverse() { ...@@ -464,9 +460,7 @@ func finishUniverse() {
s1.Block = s.Block s1.Block = s.Block
} }
nodfp = nod(ONAME, nil, nil) nodfp = newname(lookup(".fp"))
nodfp.Type = Types[TINT32] nodfp.Type = Types[TINT32]
nodfp.Xoffset = 0
nodfp.Class = PPARAM nodfp.Class = PPARAM
nodfp.Sym = lookup(".fp")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment