Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.14
go-version: 1.16
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.14
go-version: 1.16
- name: Restore cache
uses: actions/cache@v1
with:
Expand Down
99 changes: 99 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package goone

import (
"go/token"
"golang.org/x/tools/go/analysis"
"strconv"
"sync"
)

type ReportCache struct {
sync.Mutex
reportMemo map[string]bool
}

func NewReportCache() *ReportCache {
return &ReportCache{
reportMemo: make(map[string]bool),
}
}
func (m *ReportCache) toKey(pass *analysis.Pass, pos token.Pos) (key string) {
posn := pass.Fset.Position(pos)
fileName, lineNum := posn.Filename, posn.Line
key = fileName + strconv.Itoa(lineNum)
return
}
func (m *ReportCache) Set(pass *analysis.Pass, pos token.Pos, value bool) {
key := m.toKey(pass, pos)
m.reportMemo[key] = value
}

func (m *ReportCache) Get(pass *analysis.Pass, pos token.Pos) bool {
key := m.toKey(pass, pos)
value := m.reportMemo[key]
return value
}

type FuncCache struct {
sync.Mutex
funcMemo map[token.Pos]bool
}

func NewFuncCache() *FuncCache {
return &FuncCache{
funcMemo: make(map[token.Pos]bool),
}
}

func (m *FuncCache) Set(key token.Pos, value bool) {
m.Lock()
m.funcMemo[key] = value
m.Unlock()
}


func (m *FuncCache) Get(key token.Pos) (bool,bool) {
m.Lock()
value, ok := m.funcMemo[key]
m.Unlock()
if !ok {
return false, false
}
return value, true
}

type PkgCache struct {
sync.Mutex
pkgMemo map[string]bool
}

func NewPkgCache() *PkgCache {
return &PkgCache{
pkgMemo: make(map[string]bool),
}
}

func (m *PkgCache) Set(name string, value bool) {
m.pkgMemo[name] = value
}

func (m *PkgCache) Get(name string) bool {
value := m.pkgMemo[name]
return value
}

func (m *PkgCache) Exists(key string) bool {
m.Lock()
_, exist := m.pkgMemo[key]
m.Unlock()
return exist
}

// pkgCache contains pkg AST
var pkgCache *PkgCache

// reportCache manages whether if this line already reported
var reportCache *ReportCache

// funcCache manages whether if this function contains queries
var funcCache *FuncCache
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/masibw/goone

go 1.14
go 1.16

require (
github.com/gostaticanalysis/analysisutil v0.6.1
// idk why, but we need this indirect dependency to pass the test github.com/masibw/goone_test v0.0.0-20210112093021-7d2e0b363db0
github.com/masibw/goone_test v0.0.0-20210112093021-7d2e0b363db0 // indirect
golang.org/x/tools v0.0.0-20210111221946-d33bae441459
gopkg.in/yaml.v2 v2.4.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/gostaticanalysis/analysisutil v0.6.1 h1:/1JkoHe4DVxur+0wPvi26FoQfe1E3
github.com/gostaticanalysis/analysisutil v0.6.1/go.mod h1:18U/DLpRgIUd459wGxVHE0fRgmo1UgHDcbw7F5idXu0=
github.com/gostaticanalysis/comment v1.4.1 h1:xHopR5L2lRz6OsjH4R2HG5wRhW9ySl3FsHIvi5pcXwc=
github.com/gostaticanalysis/comment v1.4.1/go.mod h1:ih6ZxzTHLdadaiSnF5WY3dxUoXfXAlTaRzuaNDlSado=
github.com/masibw/goone_test v0.0.0-20210112093021-7d2e0b363db0 h1:PEBlkDmuNQMxcBaznRvs2sP0UqVPoXsNx5oWWK3MmX0=
github.com/masibw/goone_test v0.0.0-20210112093021-7d2e0b363db0/go.mod h1:yBWoicU1E30NC++4C6bor5y7dCFrobTb0jGVEPpH98Q=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1 h1:ruQGxdhGHe7FWOJPT0mKs5+pD2Xs1Bm/kdGlHO04FmM=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
Loading