@@ -23,23 +23,21 @@ import (
23
23
24
24
"golang.org/x/tools/go/callgraph"
25
25
"golang.org/x/tools/go/callgraph/cha"
26
- "golang.org/x/tools/go/callgraph/rta"
27
26
"golang.org/x/tools/go/packages"
28
27
"golang.org/x/tools/go/ssa"
29
28
"golang.org/x/tools/go/ssa/ssautil"
30
29
)
31
30
32
31
// UnusedParams returns a list of human-readable issues that point out unused
33
32
// function parameters.
34
- func UnusedParams (tests bool , algo string , exported , debug bool , args ... string ) ([]string , error ) {
33
+ func UnusedParams (tests bool , exported , debug bool , args ... string ) ([]string , error ) {
35
34
wd , err := os .Getwd ()
36
35
if err != nil {
37
36
return nil , err
38
37
}
39
38
c := & Checker {
40
39
wd : wd ,
41
40
tests : tests ,
42
- algo : algo ,
43
41
exported : exported ,
44
42
}
45
43
if debug {
@@ -59,7 +57,6 @@ type Checker struct {
59
57
wd string
60
58
61
59
tests bool
62
- algo string
63
60
exported bool
64
61
debugLog io.Writer
65
62
@@ -143,11 +140,6 @@ func (c *Checker) ProgramSSA(prog *ssa.Program) {
143
140
c .prog = prog
144
141
}
145
142
146
- // CallgraphAlgorithm supplies Checker with the call graph construction algorithm.
147
- func (c * Checker ) CallgraphAlgorithm (algo string ) {
148
- c .algo = algo
149
- }
150
-
151
143
// CheckExportedFuncs sets whether to inspect exported functions
152
144
func (c * Checker ) CheckExportedFuncs (exported bool ) {
153
145
c .exported = exported
@@ -213,23 +205,7 @@ func (c *Checker) Check() ([]Issue, error) {
213
205
})
214
206
}
215
207
}
216
- switch c .algo {
217
- case "cha" :
218
- c .graph = cha .CallGraph (c .prog )
219
- case "rta" :
220
- mains , err := mainPackages (c .prog , wantPkg )
221
- if err != nil {
222
- return nil , err
223
- }
224
- var roots []* ssa.Function
225
- for _ , main := range mains {
226
- roots = append (roots , main .Func ("init" ), main .Func ("main" ))
227
- }
228
- result := rta .Analyze (roots , true )
229
- c .graph = result .CallGraph
230
- default :
231
- return nil , fmt .Errorf ("unknown call graph construction algorithm: %q" , c .algo )
232
- }
208
+ c .graph = cha .CallGraph (c .prog )
233
209
c .graph .DeleteSyntheticNodes ()
234
210
235
211
allFuncs := ssautil .AllFunctions (c .prog )
@@ -461,21 +437,6 @@ resLoop:
461
437
}
462
438
}
463
439
464
- // mainPackages returns the subset of main packages within pkgSet.
465
- func mainPackages (prog * ssa.Program , pkgSet map [* types.Package ]* packages.Package ) ([]* ssa.Package , error ) {
466
- mains := make ([]* ssa.Package , 0 , len (pkgSet ))
467
- for tpkg := range pkgSet {
468
- pkg := prog .Package (tpkg )
469
- if tpkg .Name () == "main" && pkg .Func ("main" ) != nil {
470
- mains = append (mains , pkg )
471
- }
472
- }
473
- if len (mains ) == 0 {
474
- return nil , fmt .Errorf ("no main packages" )
475
- }
476
- return mains , nil
477
- }
478
-
479
440
// calledInReturn reports whether any of a function's inbound calls happened
480
441
// directly as a return statement. That is, if function "foo" was used via
481
442
// "return foo()". This means that the result parameters of the function cannot
0 commit comments