Skip to content

Commit 41d6435

Browse files
committed
chore: isolate code from x/tools
1 parent 2f93c09 commit 41d6435

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

pkg/goanalysis/runner_base.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ import (
1414
"golang.org/x/tools/go/analysis"
1515
)
1616

17+
// NOTE(ldez) no alteration.
18+
// exportedFrom reports whether obj may be visible to a package that imports pkg.
19+
// This includes not just the exported members of pkg, but also unexported
20+
// constants, types, fields, and methods, perhaps belonging to other packages,
21+
// that find there way into the API.
22+
// This is an over-approximation of the more accurate approach used by
23+
// gc export data, which walks the type graph, but it's much simpler.
24+
//
25+
// TODO(adonovan): do more accurate filtering by walking the type graph.
26+
func exportedFrom(obj types.Object, pkg *types.Package) bool {
27+
switch obj := obj.(type) {
28+
case *types.Func:
29+
return obj.Exported() && obj.Pkg() == pkg ||
30+
obj.Type().(*types.Signature).Recv() != nil
31+
case *types.Var:
32+
return obj.Exported() && obj.Pkg() == pkg ||
33+
obj.IsField()
34+
case *types.TypeName, *types.Const:
35+
return true
36+
}
37+
return false // Nil, Builtin, Label, or PkgName
38+
}
39+
1740
// NOTE(ldez) altered: logger; `act.factType`
1841
// importObjectFact implements Pass.ImportObjectFact.
1942
// Given a non-nil pointer ptr of type *T, where *T satisfies Fact,

pkg/goanalysis/runner_facts.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,3 @@ func codeFact(fact analysis.Fact) (analysis.Fact, error) {
9696
}
9797
return newFact, nil
9898
}
99-
100-
// exportedFrom reports whether obj may be visible to a package that imports pkg.
101-
// This includes not just the exported members of pkg, but also unexported
102-
// constants, types, fields, and methods, perhaps belonging to other packages,
103-
// that find there way into the API.
104-
// This is an over-approximation of the more accurate approach used by
105-
// gc export data, which walks the type graph, but it's much simpler.
106-
//
107-
// TODO(adonovan): do more accurate filtering by walking the type graph.
108-
func exportedFrom(obj types.Object, pkg *types.Package) bool {
109-
switch obj := obj.(type) {
110-
case *types.Func:
111-
return obj.Exported() && obj.Pkg() == pkg ||
112-
obj.Type().(*types.Signature).Recv() != nil
113-
case *types.Var:
114-
return obj.Exported() && obj.Pkg() == pkg ||
115-
obj.IsField()
116-
case *types.TypeName, *types.Const:
117-
return true
118-
}
119-
return false // Nil, Builtin, Label, or PkgName
120-
}

0 commit comments

Comments
 (0)