Skip to content
This repository has been archived by the owner on Sep 1, 2018. It is now read-only.

Commit

Permalink
Walk func bodies alone instead of files
Browse files Browse the repository at this point in the history
To get a tiny bit closer to what SSA would do.
  • Loading branch information
mvdan committed Apr 6, 2017
1 parent 158ea12 commit 22c5166
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,37 +156,39 @@ func (c *Checker) Check() ([]lint.Issue, error) {
for _, pinfo := range c.lprog.InitialPackages() {
pkg := pinfo.Pkg
c.getTypes(pkg)
total = append(total, c.checkPkg(c.lprog.AllPackages[pkg])...)
c.PackageInfo = c.lprog.AllPackages[pkg]
total = append(total, c.checkPkg()...)
}
return total, nil
}

func (c *Checker) checkPkg(info *loader.PackageInfo) []lint.Issue {
c.PackageInfo = info
func (c *Checker) checkPkg() []lint.Issue {
c.discardFuncs = make(map[*types.Signature]struct{})
c.vars = make(map[*types.Var]*varUsage)
for _, f := range info.Files {
ast.Inspect(f, func(node ast.Node) bool {
decl, ok := node.(*ast.FuncDecl)
if !ok {
return true
}
ssaFn := c.ssaByPos[decl.Name.Pos()]
if ssaFn == nil {
return true
}
fd := &funcDecl{
astDecl: decl,
ssaFn: ssaFn,
}
if c.funcSigns[signString(fd.ssaFn.Signature)] {
// implements interface
return true
}
c.funcs = append(c.funcs, fd)
c.funcs = c.funcs[:0]
findFuncs := func(node ast.Node) bool {
decl, ok := node.(*ast.FuncDecl)
if !ok {
return true
})
ast.Walk(c, f)
}
ssaFn := c.ssaByPos[decl.Name.Pos()]
if ssaFn == nil {
return true
}
fd := &funcDecl{
astDecl: decl,
ssaFn: ssaFn,
}
if c.funcSigns[signString(fd.ssaFn.Signature)] {
// implements interface
return true
}
c.funcs = append(c.funcs, fd)
ast.Walk(c, decl.Body)
return true
}
for _, f := range c.Files {
ast.Inspect(f, findFuncs)
}
return c.packageIssues()
}
Expand Down

0 comments on commit 22c5166

Please sign in to comment.