mirror of
https://github.com/golang/go
synced 2024-11-19 01:14:39 -07:00
cmd/compile: encapsulate Type.Nname
Generated by eg, manually fixed up. I’m not thrilled about having a setter, but given the variety of contexts in which this gets fiddled with, it is the cleanest available alternative. Change-Id: Ibdf23e638fe0bdabded014c9e59d557fab8c955f Reviewed-on: https://go-review.googlesource.com/21341 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
139891e815
commit
b83618f964
@ -481,14 +481,14 @@ func (p *exporter) typ(t *Type) {
|
|||||||
}
|
}
|
||||||
p.string(m.Sym.Name)
|
p.string(m.Sym.Name)
|
||||||
sig := m.Type
|
sig := m.Type
|
||||||
inlineable := p.isInlineable(sig.Nname)
|
inlineable := p.isInlineable(sig.Nname())
|
||||||
p.paramList(sig.Recvs(), inlineable)
|
p.paramList(sig.Recvs(), inlineable)
|
||||||
p.paramList(sig.Params(), inlineable)
|
p.paramList(sig.Params(), inlineable)
|
||||||
p.paramList(sig.Results(), inlineable)
|
p.paramList(sig.Results(), inlineable)
|
||||||
index := -1
|
index := -1
|
||||||
if inlineable {
|
if inlineable {
|
||||||
index = len(p.inlined)
|
index = len(p.inlined)
|
||||||
p.inlined = append(p.inlined, sig.Nname.Func)
|
p.inlined = append(p.inlined, sig.Nname().Func)
|
||||||
}
|
}
|
||||||
p.int(index)
|
p.int(index)
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ func (p *importer) typ() *Type {
|
|||||||
// (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
|
// (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
|
||||||
// out by typecheck's lookdot as this $$.ttype. So by providing
|
// out by typecheck's lookdot as this $$.ttype. So by providing
|
||||||
// this back link here we avoid special casing there.
|
// this back link here we avoid special casing there.
|
||||||
n.Type.Nname = n
|
n.Type.SetNname(n)
|
||||||
|
|
||||||
// parser.go:hidden_import
|
// parser.go:hidden_import
|
||||||
n.Func.Inl.Set(nil)
|
n.Func.Inl.Set(nil)
|
||||||
|
@ -875,8 +875,7 @@ func interfacefield(n *Node) *Field {
|
|||||||
// right now all we need is the name list.
|
// right now all we need is the name list.
|
||||||
// avoids cycles for recursive interface types.
|
// avoids cycles for recursive interface types.
|
||||||
n.Type = typ(TINTERMETH)
|
n.Type = typ(TINTERMETH)
|
||||||
|
n.Type.SetNname(n.Right)
|
||||||
n.Type.Nname = n.Right
|
|
||||||
n.Left.Type = n.Type
|
n.Left.Type = n.Type
|
||||||
queuemethod(n)
|
queuemethod(n)
|
||||||
|
|
||||||
|
@ -323,15 +323,15 @@ func dumpexporttype(t *Type) {
|
|||||||
if f.Nointerface {
|
if f.Nointerface {
|
||||||
exportf("\t//go:nointerface\n")
|
exportf("\t//go:nointerface\n")
|
||||||
}
|
}
|
||||||
if f.Type.Nname != nil && len(f.Type.Nname.Func.Inl.Slice()) != 0 { // nname was set by caninl
|
if f.Type.Nname() != nil && len(f.Type.Nname().Func.Inl.Slice()) != 0 { // nname was set by caninl
|
||||||
|
|
||||||
// when lazily typechecking inlined bodies, some re-exported ones may not have been typechecked yet.
|
// when lazily typechecking inlined bodies, some re-exported ones may not have been typechecked yet.
|
||||||
// currently that can leave unresolved ONONAMEs in import-dot-ed packages in the wrong package
|
// currently that can leave unresolved ONONAMEs in import-dot-ed packages in the wrong package
|
||||||
if Debug['l'] < 2 {
|
if Debug['l'] < 2 {
|
||||||
typecheckinl(f.Type.Nname)
|
typecheckinl(f.Type.Nname())
|
||||||
}
|
}
|
||||||
exportf("\tfunc %v %v %v { %v }\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp), Hconv(f.Type.Nname.Func.Inl, FmtSharp|FmtBody))
|
exportf("\tfunc %v %v %v { %v }\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp), Hconv(f.Type.Nname().Func.Inl, FmtSharp|FmtBody))
|
||||||
reexportdeplist(f.Type.Nname.Func.Inl)
|
reexportdeplist(f.Type.Nname().Func.Inl)
|
||||||
} else {
|
} else {
|
||||||
exportf("\tfunc %v %v %v\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp))
|
exportf("\tfunc %v %v %v\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp))
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func caninl(fn *Node) {
|
|||||||
|
|
||||||
// hack, TODO, check for better way to link method nodes back to the thing with the ->inl
|
// hack, TODO, check for better way to link method nodes back to the thing with the ->inl
|
||||||
// this is so export can find the body of a method
|
// this is so export can find the body of a method
|
||||||
fn.Type.Nname = fn.Func.Nname
|
fn.Type.SetNname(fn.Func.Nname)
|
||||||
|
|
||||||
if Debug['m'] > 1 {
|
if Debug['m'] > 1 {
|
||||||
fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(fn.Func.Nname, FmtSharp), Tconv(fn.Type, FmtSharp), Hconv(fn.Func.Nname.Func.Inl, FmtSharp))
|
fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(fn.Func.Nname, FmtSharp), Tconv(fn.Type, FmtSharp), Hconv(fn.Func.Nname.Func.Inl, FmtSharp))
|
||||||
@ -192,11 +192,11 @@ func ishairy(n *Node, budget *int) bool {
|
|||||||
if n.Left.Type == nil {
|
if n.Left.Type == nil {
|
||||||
Fatalf("no function type for [%p] %v\n", n.Left, Nconv(n.Left, FmtSign))
|
Fatalf("no function type for [%p] %v\n", n.Left, Nconv(n.Left, FmtSign))
|
||||||
}
|
}
|
||||||
if n.Left.Type.Nname == nil {
|
if n.Left.Type.Nname() == nil {
|
||||||
Fatalf("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, FmtSign))
|
Fatalf("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, FmtSign))
|
||||||
}
|
}
|
||||||
if len(n.Left.Type.Nname.Func.Inl.Slice()) != 0 {
|
if len(n.Left.Type.Nname().Func.Inl.Slice()) != 0 {
|
||||||
*budget -= int(n.Left.Type.Nname.Func.InlCost)
|
*budget -= int(n.Left.Type.Nname().Func.InlCost)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if Debug['l'] < 4 {
|
if Debug['l'] < 4 {
|
||||||
@ -471,11 +471,11 @@ func inlnode(n *Node) *Node {
|
|||||||
Fatalf("no function type for [%p] %v\n", n.Left, Nconv(n.Left, FmtSign))
|
Fatalf("no function type for [%p] %v\n", n.Left, Nconv(n.Left, FmtSign))
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Left.Type.Nname == nil {
|
if n.Left.Type.Nname() == nil {
|
||||||
Fatalf("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, FmtSign))
|
Fatalf("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, FmtSign))
|
||||||
}
|
}
|
||||||
|
|
||||||
n = mkinlcall(n, n.Left.Type.Nname, n.Isddd)
|
n = mkinlcall(n, n.Left.Type.Nname(), n.Isddd)
|
||||||
}
|
}
|
||||||
|
|
||||||
lineno = lno
|
lineno = lno
|
||||||
|
@ -2018,7 +2018,7 @@ func (p *parser) hidden_fndcl() *Node {
|
|||||||
// (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
|
// (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
|
||||||
// out by typecheck's lookdot as this $$.ttype. So by providing
|
// out by typecheck's lookdot as this $$.ttype. So by providing
|
||||||
// this back link here we avoid special casing there.
|
// this back link here we avoid special casing there.
|
||||||
ss.Type.Nname = ss
|
ss.Type.SetNname(ss)
|
||||||
return ss
|
return ss
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,9 +255,9 @@ func methodfunc(f *Type, receiver *Type) *Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := functype(nil, in, out)
|
t := functype(nil, in, out)
|
||||||
if f.Nname != nil {
|
if f.Nname() != nil {
|
||||||
// Link to name of original method function.
|
// Link to name of original method function.
|
||||||
t.Nname = f.Nname
|
t.SetNname(f.Nname())
|
||||||
}
|
}
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
@ -45,7 +45,7 @@ func init1(n *Node, out *[]*Node) {
|
|||||||
if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC {
|
if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC {
|
||||||
// Methods called as Type.Method(receiver, ...).
|
// Methods called as Type.Method(receiver, ...).
|
||||||
// Definitions for method expressions are stored in type->nname.
|
// Definitions for method expressions are stored in type->nname.
|
||||||
init1(n.Type.Nname, out)
|
init1(n.Type.Nname(), out)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Op != ONAME {
|
if n.Op != ONAME {
|
||||||
@ -216,7 +216,7 @@ func init2(n *Node, out *[]*Node) {
|
|||||||
init2list(n.Func.Closure.Nbody, out)
|
init2list(n.Func.Closure.Nbody, out)
|
||||||
}
|
}
|
||||||
if n.Op == ODOTMETH || n.Op == OCALLPART {
|
if n.Op == ODOTMETH || n.Op == OCALLPART {
|
||||||
init2(n.Type.Nname, out)
|
init2(n.Type.Nname(), out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ type Type struct {
|
|||||||
Vargen int32 // unique name for OTYPE/ONAME
|
Vargen int32 // unique name for OTYPE/ONAME
|
||||||
Lineno int32
|
Lineno int32
|
||||||
|
|
||||||
Nname *Node
|
nname *Node
|
||||||
Argwid int64
|
Argwid int64
|
||||||
|
|
||||||
// most nodes
|
// most nodes
|
||||||
@ -454,6 +454,12 @@ func (t *Type) wantEtype(et EType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Type) wantEtype2(et1, et2 EType) {
|
||||||
|
if t.Etype != et1 && t.Etype != et2 {
|
||||||
|
Fatalf("want %v or %v, but have %v", et1, et2, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Type) RecvsP() **Type {
|
func (t *Type) RecvsP() **Type {
|
||||||
t.wantEtype(TFUNC)
|
t.wantEtype(TFUNC)
|
||||||
return &t.Type
|
return &t.Type
|
||||||
@ -527,6 +533,18 @@ func (t *Type) Wrapped() *Type {
|
|||||||
return t.Type
|
return t.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nname returns the associated function's nname.
|
||||||
|
func (t *Type) Nname() *Node {
|
||||||
|
t.wantEtype2(TFUNC, TINTERMETH)
|
||||||
|
return t.nname
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nname sets the associated function's nname.
|
||||||
|
func (t *Type) SetNname(n *Node) {
|
||||||
|
t.wantEtype2(TFUNC, TINTERMETH)
|
||||||
|
t.nname = n
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Type) Methods() *Fields {
|
func (t *Type) Methods() *Fields {
|
||||||
// TODO(mdempsky): Validate t?
|
// TODO(mdempsky): Validate t?
|
||||||
return &t.methods
|
return &t.methods
|
||||||
|
@ -3418,7 +3418,7 @@ func typecheckfunc(n *Node) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
t.Nname = n.Func.Nname
|
t.SetNname(n.Func.Nname)
|
||||||
rcvr := t.Recv()
|
rcvr := t.Recv()
|
||||||
if rcvr != nil && n.Func.Shortname != nil {
|
if rcvr != nil && n.Func.Shortname != nil {
|
||||||
addmethod(n.Func.Shortname.Sym, t, nil, true, n.Func.Nname.Nointerface)
|
addmethod(n.Func.Shortname.Sym, t, nil, true, n.Func.Nname.Nointerface)
|
||||||
@ -3465,7 +3465,7 @@ var ntypecheckdeftype int
|
|||||||
var methodqueue []*Node
|
var methodqueue []*Node
|
||||||
|
|
||||||
func domethod(n *Node) {
|
func domethod(n *Node) {
|
||||||
nt := n.Type.Nname
|
nt := n.Type.Nname()
|
||||||
nt = typecheck(nt, Etype)
|
nt = typecheck(nt, Etype)
|
||||||
if nt.Type == nil {
|
if nt.Type == nil {
|
||||||
// type check failed; leave empty func
|
// type check failed; leave empty func
|
||||||
|
Loading…
Reference in New Issue
Block a user