@@ -14,6 +14,29 @@ import (
14
14
"golang.org/x/tools/go/analysis"
15
15
)
16
16
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
+
17
40
// NOTE(ldez) altered: logger; `act.factType`
18
41
// importObjectFact implements Pass.ImportObjectFact.
19
42
// Given a non-nil pointer ptr of type *T, where *T satisfies Fact,
0 commit comments