Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / go / callgraph / static / static.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/go/callgraph/static/static.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/go/callgraph/static/static.go
new file mode 100644 (file)
index 0000000..709bb7b
--- /dev/null
@@ -0,0 +1,35 @@
+// Package static computes the call graph of a Go program containing
+// only static call edges.
+package static // import "golang.org/x/tools/go/callgraph/static"
+
+import (
+       "golang.org/x/tools/go/callgraph"
+       "golang.org/x/tools/go/ssa"
+       "golang.org/x/tools/go/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
+}