]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: encapsulate Type.Nname
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 30 Mar 2016 23:59:53 +0000 (16:59 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 31 Mar 2016 15:38:34 +0000 (15:38 +0000)
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>
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/parser.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index 22de0a64bf09186aa4162af1daf9d65b364b2c11..95762caec85d99b2c7c61ba2e111b6328e7e6f3d 100644 (file)
@@ -481,14 +481,14 @@ func (p *exporter) typ(t *Type) {
                        }
                        p.string(m.Sym.Name)
                        sig := m.Type
-                       inlineable := p.isInlineable(sig.Nname)
+                       inlineable := p.isInlineable(sig.Nname())
                        p.paramList(sig.Recvs(), inlineable)
                        p.paramList(sig.Params(), inlineable)
                        p.paramList(sig.Results(), inlineable)
                        index := -1
                        if inlineable {
                                index = len(p.inlined)
-                               p.inlined = append(p.inlined, sig.Nname.Func)
+                               p.inlined = append(p.inlined, sig.Nname().Func)
                        }
                        p.int(index)
                }
index 65eec96c69784c3d4bf9c3d71e3b132057a2f7a7..52b9b44a6954690d778ba76cc4ed4b04ed80b0de 100644 (file)
@@ -261,7 +261,7 @@ func (p *importer) typ() *Type {
                        // (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
                        // out by typecheck's lookdot as this $$.ttype. So by providing
                        // this back link here we avoid special casing there.
-                       n.Type.Nname = n
+                       n.Type.SetNname(n)
 
                        // parser.go:hidden_import
                        n.Func.Inl.Set(nil)
index 6e45231c1a16cb160a1cdac1452445cf7f5ba56f..a1a481f24375313fd318fc69280f91d53f0ef4e5 100644 (file)
@@ -875,8 +875,7 @@ func interfacefield(n *Node) *Field {
                        // right now all we need is the name list.
                        // avoids cycles for recursive interface types.
                        n.Type = typ(TINTERMETH)
-
-                       n.Type.Nname = n.Right
+                       n.Type.SetNname(n.Right)
                        n.Left.Type = n.Type
                        queuemethod(n)
 
index ce86fa097d5201b8ea12a36271e35439990cd445..09f048b75804fae0204058df1c51e75fe0a0b3ef 100644 (file)
@@ -323,15 +323,15 @@ func dumpexporttype(t *Type) {
                if f.Nointerface {
                        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.
                        // currently that can leave unresolved ONONAMEs in import-dot-ed packages in the wrong package
                        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))
-                       reexportdeplist(f.Type.Nname.Func.Inl)
+                       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)
                } else {
                        exportf("\tfunc %v %v %v\n", Tconv(f.Type.Recvs(), FmtSharp), Sconv(f.Sym, FmtShort|FmtByte|FmtSharp), Tconv(f.Type, FmtShort|FmtSharp))
                }
index 292113a631ddc77f8ebc5eb19a107980be911477..c21af77f04d68967bbf17e26837660703bd81a4c 100644 (file)
@@ -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
        // 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 {
                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 {
                        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))
                }
-               if len(n.Left.Type.Nname.Func.Inl.Slice()) != 0 {
-                       *budget -= int(n.Left.Type.Nname.Func.InlCost)
+               if len(n.Left.Type.Nname().Func.Inl.Slice()) != 0 {
+                       *budget -= int(n.Left.Type.Nname().Func.InlCost)
                        break
                }
                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))
                }
 
-               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))
                }
 
-               n = mkinlcall(n, n.Left.Type.Nname, n.Isddd)
+               n = mkinlcall(n, n.Left.Type.Nname(), n.Isddd)
        }
 
        lineno = lno
index ba300610412620cc9ce8d57dc010753cc656d8a5..3627461099110543c9217030271032b3e405b8de 100644 (file)
@@ -2018,7 +2018,7 @@ func (p *parser) hidden_fndcl() *Node {
                // (dotmeth's type).Nname.Inl, and dotmeth's type has been pulled
                // out by typecheck's lookdot as this $$.ttype. So by providing
                // this back link here we avoid special casing there.
-               ss.Type.Nname = ss
+               ss.Type.SetNname(ss)
                return ss
        }
 }
index 636ef9cf3f677f9ba490362f78db889521fb97f4..da7bd56afe4ffb4d8ca16d2eb0f8f995b8c0abb7 100644 (file)
@@ -255,9 +255,9 @@ func methodfunc(f *Type, receiver *Type) *Type {
        }
 
        t := functype(nil, in, out)
-       if f.Nname != nil {
+       if f.Nname() != nil {
                // Link to name of original method function.
-               t.Nname = f.Nname
+               t.SetNname(f.Nname())
        }
 
        return t
index 2901e59d715b68a4180f65c52a72ce8f18edcc98..e3bc46ac0690ef8c0db6deb27c3b1e6ba2106e07 100644 (file)
@@ -45,7 +45,7 @@ func init1(n *Node, out *[]*Node) {
        if n.Left != nil && n.Type != nil && n.Left.Op == OTYPE && n.Class == PFUNC {
                // Methods called as Type.Method(receiver, ...).
                // Definitions for method expressions are stored in type->nname.
-               init1(n.Type.Nname, out)
+               init1(n.Type.Nname(), out)
        }
 
        if n.Op != ONAME {
@@ -216,7 +216,7 @@ func init2(n *Node, out *[]*Node) {
                init2list(n.Func.Closure.Nbody, out)
        }
        if n.Op == ODOTMETH || n.Op == OCALLPART {
-               init2(n.Type.Nname, out)
+               init2(n.Type.Nname(), out)
        }
 }
 
index a910b105efbfff996de8b40e62ea6f5c28eaaf45..765b2059a3c58ec4fb14641048999f706802f903 100644 (file)
@@ -128,7 +128,7 @@ type Type struct {
        Vargen int32 // unique name for OTYPE/ONAME
        Lineno int32
 
-       Nname  *Node
+       nname  *Node
        Argwid int64
 
        // 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 {
        t.wantEtype(TFUNC)
        return &t.Type
@@ -527,6 +533,18 @@ func (t *Type) Wrapped() *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 {
        // TODO(mdempsky): Validate t?
        return &t.methods
index 9102f5b39b4baf87df50424acd837766206e673d..260f410275eda0069ea057f21390c95c32a28d49 100644 (file)
@@ -3418,7 +3418,7 @@ func typecheckfunc(n *Node) {
                return
        }
        n.Type = t
-       t.Nname = n.Func.Nname
+       t.SetNname(n.Func.Nname)
        rcvr := t.Recv()
        if rcvr != nil && n.Func.Shortname != nil {
                addmethod(n.Func.Shortname.Sym, t, nil, true, n.Func.Nname.Nointerface)
@@ -3465,7 +3465,7 @@ var ntypecheckdeftype int
 var methodqueue []*Node
 
 func domethod(n *Node) {
-       nt := n.Type.Nname
+       nt := n.Type.Nname()
        nt = typecheck(nt, Etype)
        if nt.Type == nil {
                // type check failed; leave empty func