
Also do following improvements: - show proper sublinter name for megacheck sublinters - refactor and make more simple and robust megacheck merging/optimizing - improve handling of unknown linter names in //nolint directives - minimize diff of our megacheck version from the upstream, https://github.com/golang/go/issues/29612 blocks usage of the upstream version - support the new `stylecheck` linter - improve tests coverage for megacheck and nolint related cases - update and use upstream versions of unparam and interfacer instead of forked ones - don't use golangci/tools repo anymore - fix newly found issues after updating linters Also should be noted that megacheck works much faster and consumes less memory in the newest release, therefore golangci-lint works noticeably faster and consumes less memory for large repos. Relates: #314
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
// Package static computes the call graph of a Go program containing
|
|
// only static call edges.
|
|
package static // import "github.com/golangci/go-tools/callgraph/static"
|
|
|
|
import (
|
|
"github.com/golangci/go-tools/callgraph"
|
|
"github.com/golangci/go-tools/ssa"
|
|
"github.com/golangci/go-tools/ssa/ssautil"
|
|
)
|
|
|
|
// CallGraph computes the call graph of the specified program
|
|
// considering only static calls.
|
|
//
|
|
func CallGraph(prog *ssa.Program) *callgraph.Graph {
|
|
cg := callgraph.New(nil) // TODO(adonovan) eliminate concept of rooted callgraph
|
|
|
|
// TODO(adonovan): opt: use only a single pass over the ssa.Program.
|
|
// TODO(adonovan): opt: this is slower than RTA (perhaps because
|
|
// the lower precision means so many edges are allocated)!
|
|
for f := range ssautil.AllFunctions(prog) {
|
|
fnode := cg.CreateNode(f)
|
|
for _, b := range f.Blocks {
|
|
for _, instr := range b.Instrs {
|
|
if site, ok := instr.(ssa.CallInstruction); ok {
|
|
if g := site.Common().StaticCallee(); g != nil {
|
|
gnode := cg.CreateNode(g)
|
|
callgraph.AddEdge(fnode, site, gnode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return cg
|
|
}
|