-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use standard
golang.org/x/tools/go/callgraph
package (#24)
* Delete `callgraph` package in favor of standard one * Add `callgraphutil` package * Add comments to test other algorithms
- Loading branch information
Showing
14 changed files
with
483 additions
and
327 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package callgraphutil | ||
|
||
import "golang.org/x/tools/go/callgraph" | ||
|
||
// Nodes is a handy alias for a slice of callgraph.Nodes. | ||
type Nodes = []*callgraph.Node | ||
|
||
// Edges is a handy alias for a slice of callgraph.Edges. | ||
type Edges = []*callgraph.Edge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package callgraphutil | ||
|
||
import "golang.org/x/tools/go/callgraph" | ||
|
||
// CalleesOf returns nodes that are called by the caller node. | ||
func CalleesOf(caller *callgraph.Node) Nodes { | ||
calleesMap := make(map[*callgraph.Node]bool) | ||
for _, e := range caller.Out { | ||
calleesMap[e.Callee] = true | ||
} | ||
|
||
// Convert map to slice. | ||
calleesSlice := make([]*callgraph.Node, 0, len(calleesMap)) | ||
for callee := range calleesMap { | ||
calleesSlice = append(calleesSlice, callee) | ||
} | ||
|
||
return calleesSlice | ||
} | ||
|
||
// CallersOf returns nodes that call the callee node. | ||
func CallersOf(callee *callgraph.Node) Nodes { | ||
uniqCallers := make(map[*callgraph.Node]bool) | ||
for _, e := range callee.In { | ||
uniqCallers[e.Caller] = true | ||
} | ||
|
||
// Convert map to slice. | ||
callersSlice := make(Nodes, 0, len(uniqCallers)) | ||
for caller := range uniqCallers { | ||
callersSlice = append(callersSlice, caller) | ||
} | ||
|
||
return callersSlice | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package callgraphutil implements utilities for golang.org/x/tools/go/callgraph | ||
// including path searching, graph construction, printing, and more. | ||
package callgraphutil |
Oops, something went wrong.