mirror of
https://github.com/golang/go
synced 2024-11-24 01:50:11 -07:00
cmd/compile: simplify noding for struct embedding
Since golang.org/cl/31670, we've stopped using the 'embedded' function for handling struct embeddings within package export data. Now the only remaining use is for Go source files, which allows for some substantial simplifications: 1. CenterDot never appears within Go source files, so that logic can simply be removed. 2. The field name will always be declared in the local package. Passes toolstash-check. Change-Id: I59505f62824206dd5de0782918f98fbef6e93224 Reviewed-on: https://go-review.googlesource.com/58790 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
a9f832a6ae
commit
180bfc4bd4
@ -760,33 +760,6 @@ func tointerface0(t *types.Type, l []*Node) *types.Type {
|
||||
return t
|
||||
}
|
||||
|
||||
func embedded(s *types.Sym, pkg *types.Pkg) *Node {
|
||||
const (
|
||||
CenterDot = 0xB7
|
||||
)
|
||||
// Names sometimes have disambiguation junk
|
||||
// appended after a center dot. Discard it when
|
||||
// making the name for the embedded struct field.
|
||||
name := s.Name
|
||||
|
||||
if i := strings.Index(s.Name, string(CenterDot)); i >= 0 {
|
||||
name = s.Name[:i]
|
||||
}
|
||||
|
||||
var n *Node
|
||||
if exportname(name) {
|
||||
n = newname(lookup(name))
|
||||
} else if s.Pkg == builtinpkg {
|
||||
// The name of embedded builtins belongs to pkg.
|
||||
n = newname(pkg.Lookup(name))
|
||||
} else {
|
||||
n = newname(s.Pkg.Lookup(name))
|
||||
}
|
||||
n = nod(ODCLFIELD, n, oldname(s))
|
||||
n.SetEmbedded(true)
|
||||
return n
|
||||
}
|
||||
|
||||
func fakeRecv() *Node {
|
||||
return anonfield(types.FakeRecvType())
|
||||
}
|
||||
|
@ -689,7 +689,11 @@ func (p *noder) embedded(typ syntax.Expr) *Node {
|
||||
}
|
||||
typ = op.X
|
||||
}
|
||||
n := embedded(p.packname(typ), localpkg)
|
||||
|
||||
sym := p.packname(typ)
|
||||
n := nod(ODCLFIELD, newname(lookup(sym.Name)), oldname(sym))
|
||||
n.SetEmbedded(true)
|
||||
|
||||
if isStar {
|
||||
n.Right = p.nod(op, OIND, n.Right, nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user