Skip to content

Commit

Permalink
Merge pull request #427 from visualfc/initgop
Browse files Browse the repository at this point in the history
add InitThisGopPkgEx for map overload name to position
  • Loading branch information
xushiwei authored Apr 24, 2024
2 parents 4d251e7 + 4bce01e commit 0d40138
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func isGopCommon(name string) bool {

// InitThisGopPkg initializes a Go+ package.
func InitThisGopPkg(pkg *types.Package) {
InitThisGopPkgEx(pkg, nil)
}

// InitThisGopPkg initializes a Go+ package. pos map overload name to postion.
func InitThisGopPkgEx(pkg *types.Package, pos map[string]token.Pos) {
scope := pkg.Scope()
gopos := make([]string, 0, 4)
overloads := make(map[omthd][]types.Object)
Expand Down Expand Up @@ -156,15 +161,15 @@ func InitThisGopPkg(pkg *types.Package) {
}
}
if len(fns) > 0 {
newOverload(pkg, scope, m, fns)
newOverload(pkg, scope, m, fns, pos)
}
delete(overloads, m)
}
}
for key, items := range overloads {
off := len(key.name) + 2
fns := overloadFuncs(off, items)
newOverload(pkg, scope, key, fns)
newOverload(pkg, scope, key, fns, pos)
}
for name, items := range onameds {
off := len(name) + 2
Expand Down Expand Up @@ -310,19 +315,19 @@ func checkOverloads(scope *types.Scope, gopoName string) (ret []string, exists b
return
}

func newOverload(pkg *types.Package, scope *types.Scope, m omthd, fns []types.Object) {
func newOverload(pkg *types.Package, scope *types.Scope, m omthd, fns []types.Object, pos map[string]token.Pos) {
if m.typ == nil {
if debugImport {
log.Println("==> NewOverloadFunc", m.name)
}
o := NewOverloadFunc(token.NoPos, pkg, m.name, fns...)
o := NewOverloadFunc(pos[m.name], pkg, m.name, fns...)
scope.Insert(o)
checkGoptsx(pkg, scope, m.name, o)
} else {
if debugImport {
log.Println("==> NewOverloadMethod", m.typ.Obj().Name(), m.name)
}
NewOverloadMethod(m.typ, token.NoPos, pkg, m.name, fns...)
NewOverloadMethod(m.typ, pos[m.typ.Obj().Name()+"."+m.name], pkg, m.name, fns...)
}
}

Expand Down

0 comments on commit 0d40138

Please sign in to comment.