Skip to content

Commit

Permalink
Merge pull request #262 from visualfc/types
Browse files Browse the repository at this point in the history
visit: exportedTypeHack for golang.org/x/tools v0.16
  • Loading branch information
visualfc authored Dec 12, 2023
2 parents 777d83d + af21347 commit c6e9482
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ require (
github.com/visualfc/gid v0.1.0
github.com/visualfc/goembed v0.3.2
github.com/visualfc/xtype v0.2.0
golang.org/x/mod v0.13.0
golang.org/x/mod v0.14.0
golang.org/x/tools v0.14.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
Expand Down Expand Up @@ -103,7 +104,6 @@ golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
39 changes: 32 additions & 7 deletions visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package igop

import (
"fmt"
"go/ast"
"go/token"
"go/types"
"log"
Expand Down Expand Up @@ -68,23 +69,23 @@ func (visit *visitor) program() {
chks[""] = true // anonymous struct embed named type
for pkg := range visit.pkgs {
chks[pkg.Pkg.Path()] = true
for _, mem := range pkg.Members {
if fn, ok := mem.(*ssa.Function); ok {
visit.function(fn)
}
}
}

isExtern := func(typ reflect.Type) bool {
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
return !chks[typ.PkgPath()]
}
for _, T := range visit.prog.RuntimeTypes() {

methodsOf := func(T types.Type) {
if types.IsInterface(T) {
return
}
typ := visit.intp.preToType(T)
// skip extern type
if isExtern(typ) {
continue
return
}
mmap := make(map[string]*ssa.Function)
mset := visit.prog.MethodSets.MethodSet(T)
Expand All @@ -101,6 +102,30 @@ func (visit *visitor) program() {
}
visit.intp.msets[typ] = mmap
}

exportedTypeHack := func(t *ssa.Type) {
if ast.IsExported(t.Name()) && !types.IsInterface(t.Type()) {
if named, ok := t.Type().(*types.Named); ok && !hasTypeParam(named) {
methodsOf(named) // T
methodsOf(types.NewPointer(named)) // *T
}
}
}

for pkg := range visit.pkgs {
for _, mem := range pkg.Members {
switch mem := mem.(type) {
case *ssa.Function:
visit.function(mem)
case *ssa.Type:
exportedTypeHack(mem)
}
}
}

for _, T := range visit.prog.RuntimeTypes() {
methodsOf(T)
}
}

func (visit *visitor) findLinkSym(fn *ssa.Function) (*load.LinkSym, bool) {
Expand Down

0 comments on commit c6e9482

Please sign in to comment.