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

Commit

Permalink
Get rid of "cache" type
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Mar 27, 2017
1 parent 7ee600f commit 7612dc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
30 changes: 10 additions & 20 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,25 @@ package interfacer
import (
"go/ast"
"go/types"

"golang.org/x/tools/go/loader"
)

type cache struct {
loader.Config

cur pkgCache
}

type pkgCache struct {
type pkgTypes struct {
ifaces map[string]string
funcs map[string]string
}

func (c *cache) isFuncType(t string) bool {
return c.cur.funcs[t] != ""
func (p *pkgTypes) isFuncType(t string) bool {
return p.funcs[t] != ""
}

func (c *cache) ifaceOf(t string) string {
return c.cur.ifaces[t]
func (p *pkgTypes) ifaceOf(t string) string {
return p.ifaces[t]
}

func (c *cache) fillCache(pkg *types.Package) {
func (p *pkgTypes) getTypes(pkg *types.Package) {
p.ifaces = make(map[string]string)
p.funcs = make(map[string]string)
path := pkg.Path()
c.cur = pkgCache{
ifaces: make(map[string]string),
funcs: make(map[string]string),
}
addTypes := func(impPath string, ifs, funs map[string]string, top bool) {
fullName := func(name string) string {
if !top {
Expand All @@ -45,12 +35,12 @@ func (c *cache) fillCache(pkg *types.Package) {
for iftype, name := range ifs {
// only suggest exported interfaces
if ast.IsExported(name) {
c.cur.ifaces[iftype] = fullName(name)
p.ifaces[iftype] = fullName(name)
}
}
for ftype, name := range funs {
// ignore non-exported func signatures too
c.cur.funcs[ftype] = fullName(name)
p.funcs[ftype] = fullName(name)
}
}
for _, imp := range pkg.Imports() {
Expand Down
8 changes: 3 additions & 5 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type funcDecl struct {
}

type visitor struct {
*cache
pkgTypes
*loader.PackageInfo

fset *token.FileSet
Expand Down Expand Up @@ -144,14 +144,12 @@ func (*Checker) Check(lprog *loader.Program, prog *ssa.Program) ([]lint.Issue, e
if err != nil {
return nil, err
}
c := &cache{}
v := &visitor{
cache: c,
fset: lprog.Fset,
fset: lprog.Fset,
}
var total []lint.Issue
for _, pkg := range pkgs {
c.fillCache(pkg)
v.getTypes(pkg)
total = append(total, v.checkPkg(lprog.AllPackages[pkg])...)
}
return total, nil
Expand Down

0 comments on commit 7612dc7

Please sign in to comment.