Skip to content

Commit

Permalink
support load mixed go/gop project
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Mar 9, 2024
1 parent cdaa65d commit 2ac1f5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
EnableNoStrict // Enable no strict mode
ExperimentalSupportGC // experimental support runtime.GC
SupportMultipleInterp // Support multiple interp, must manual release interp reflectx icall.
CheckGopOverloadFunc // Check and skip gop overload func
)

// Loader types loader interface
Expand Down
6 changes: 4 additions & 2 deletions gopbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (p *Package) ToAst() *goast.File {
type Context struct {
ctx *igop.Context
fset *token.FileSet
imp *igop.Importer
gop igop.Loader
}

Expand Down Expand Up @@ -174,7 +175,8 @@ func NewContext(ctx *igop.Context) *Context {
if ctx.IsEvalMode() {
ctx = igop.NewContext(0)
}
return &Context{ctx: ctx, fset: token.NewFileSet(), gop: igop.NewTypesLoader(ctx, 0)}
ctx.Mode |= igop.CheckGopOverloadFunc
return &Context{ctx: ctx, imp: igop.NewImporter(ctx), fset: token.NewFileSet(), gop: igop.NewTypesLoader(ctx, 0)}
}

func isGopPackage(path string) bool {
Expand All @@ -190,7 +192,7 @@ func (c *Context) Import(path string) (*types.Package, error) {
if isGopPackage(path) {
return c.gop.Import(path)
}
return c.ctx.Loader.Import(path)
return c.imp.Import(path)
}

func (c *Context) ParseDir(dir string) (*Package, error) {
Expand Down
9 changes: 7 additions & 2 deletions visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ func (visit *visitor) program() {
sel := mset.At(i)
obj := sel.Obj()
// skip embed extern type method
if pkg := obj.Pkg(); pkg != nil && !chks[pkg.Path()] {
continue
if pkg := obj.Pkg(); pkg != nil {
if !chks[pkg.Path()] {
continue
}
if visit.intp.ctx.Mode&CheckGopOverloadFunc != 0 && obj.Pos() == token.NoPos {
continue
}
}
fn := visit.prog.MethodValue(sel)
mmap[obj.Name()] = fn
Expand Down

0 comments on commit 2ac1f5b

Please sign in to comment.