lint: return *Pkg from NodePkg
@@ -50,7 +50,7 @@ type Program struct {
GoVersion int
tokenFileMap map[*token.File]*ast.File
- astFileMap map[*ast.File]*ssa.Package
+ astFileMap map[*ast.File]*Pkg
}
type Func func(*Job)
@@ -137,6 +137,7 @@ func (ps byPosition) Swap(i int, j int) {
func (l *Linter) Lint(lprog *loader.Program) []Problem {
ssaprog := ssautil.CreateProgram(lprog, ssa.GlobalDebug)
ssaprog.Build()
+ pkgMap := map[*ssa.Package]*Pkg{}
var pkgs []*Pkg
for _, pkginfo := range lprog.InitialPackages() {
ssapkg := ssaprog.Package(pkginfo.Pkg)
@@ -144,6 +145,7 @@ func (l *Linter) Lint(lprog *loader.Program) []Problem {
Package: ssapkg,
Info: pkginfo,
}
+ pkgMap[ssapkg] = pkg
pkgs = append(pkgs, pkg)
}
prog := &Program{
@@ -160,7 +162,7 @@ func (l *Linter) Lint(lprog *loader.Program) []Problem {
},
GoVersion: l.GoVersion,
tokenFileMap: map[*token.File]*ast.File{},
- astFileMap: map[*ast.File]*ssa.Package{},
+ astFileMap: map[*ast.File]*Pkg{},
}
for fn := range ssautil.AllFunctions(ssaprog) {
prog.AllFunctions = append(prog.AllFunctions, fn)
@@ -182,7 +184,7 @@ func (l *Linter) Lint(lprog *loader.Program) []Problem {
for _, f := range pkginfo.Files {
tf := lprog.Fset.File(f.Pos())
prog.tokenFileMap[tf] = f
- prog.astFileMap[f] = ssapkg
+ prog.astFileMap[f] = pkgMap[ssapkg]
}
}
for _, pkginfo := range lprog.InitialPackages() {
@@ -377,7 +379,7 @@ func (j *Job) ExprToString(expr ast.Expr) (string, bool) {
return constant.StringVal(val), true
}
-func (j *Job) NodePackage(node Positioner) *ssa.Package {
+func (j *Job) NodePackage(node Positioner) *Pkg {
f := j.File(node)
return j.Program.astFileMap[f]
}
@@ -386,7 +388,7 @@ func (j *Job) EnclosingSSAFunction(node Positioner) *ssa.Function {
f := j.File(node)
path, _ := astutil.PathEnclosingInterval(f, node.Pos(), node.Pos())
pkg := j.Program.astFileMap[f]
- return ssa.EnclosingFunction(pkg, path)
+ return ssa.EnclosingFunction(pkg.Package, path)
}
func IsGenerated(f *ast.File) bool {
