Skip to content

Commit 9ffeb58

Browse files
committed
chore: isolate code from x/tools
1 parent 64951cf commit 9ffeb58

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

pkg/goanalysis/runner_action.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ func (act *action) importObjectFact(obj types.Object, ptr analysis.Fact) bool {
194194
return false
195195
}
196196

197-
// exportObjectFact implements Pass.ExportObjectFact.
198-
func (act *action) exportObjectFact(obj types.Object, fact analysis.Fact) {
199-
if obj.Pkg() != act.pkg.Types {
200-
act.r.log.Panicf("internal error: in analysis %s of package %s: Fact.Set(%s, %T): can't set facts on objects belonging another package",
201-
act.a, act.pkg, obj, fact)
202-
}
203-
204-
key := objectFactKey{obj, act.factType(fact)}
205-
act.objectFacts[key] = fact // clobber any existing entry
206-
if isFactsExportDebug {
207-
objstr := types.ObjectString(obj, (*types.Package).Name)
208-
factsExportDebugf("%s: object %s has fact %s\n",
209-
act.pkg.Fset.Position(obj.Pos()), objstr, fact)
210-
}
211-
}
212-
213197
// importPackageFact implements Pass.ImportPackageFact.
214198
// Given a non-nil pointer ptr of type *T, where *T satisfies Fact,
215199
// fact copies the fact value to *ptr.

pkg/goanalysis/runner_base.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,29 @@
88
package goanalysis
99

1010
import (
11+
"go/types"
1112
"reflect"
1213

1314
"golang.org/x/tools/go/analysis"
1415
)
1516

17+
// NOTE(ldez) altered: removes code related to `act.pass.ExportPackageFact`; logger; `act.factType`.
18+
// exportObjectFact implements Pass.ExportObjectFact.
19+
func (act *action) exportObjectFact(obj types.Object, fact analysis.Fact) {
20+
if obj.Pkg() != act.pkg.Types {
21+
act.r.log.Panicf("internal error: in analysis %s of package %s: Fact.Set(%s, %T): can't set facts on objects belonging another package",
22+
act.a, act.pkg, obj, fact)
23+
}
24+
25+
key := objectFactKey{obj, act.factType(fact)}
26+
act.objectFacts[key] = fact // clobber any existing entry
27+
if isFactsExportDebug {
28+
objstr := types.ObjectString(obj, (*types.Package).Name)
29+
factsExportDebugf("%s: object %s has fact %s\n",
30+
act.pkg.Fset.Position(obj.Pos()), objstr, fact)
31+
}
32+
}
33+
1634
// NOTE(ldez) no alteration.
1735
func (act *action) allObjectFacts() []analysis.ObjectFact {
1836
out := make([]analysis.ObjectFact, 0, len(act.objectFacts))

0 commit comments

Comments
 (0)