Package callgraph
Overview ▹
Index ▹
func AddEdge ¶
func AddEdge(caller *Node, site ssa.CallInstruction, callee *Node)
AddEdge adds the edge (caller, site, callee) to the call graph. Elimination of duplicate edges is the caller's responsibility.
func CalleesOf ¶
func CalleesOf(caller *Node) map[*Node]bool
CalleesOf returns a new set containing all direct callees of the caller node.
func GraphVisitEdges ¶
func GraphVisitEdges(g *Graph, edge func(*Edge) error) error
GraphVisitEdges visits all the edges in graph g in depth-first order. The edge function is called for each edge in postorder. If it returns non-nil, visitation stops and GraphVisitEdges returns that value.
func PathSearch ¶
func PathSearch(start *Node, isEnd func(*Node) bool) []*Edge
PathSearch finds an arbitrary path starting at node start and ending at some node for which isEnd() returns true. On success, PathSearch returns the path as an ordered list of edges; on failure, it returns nil.
type Edge ¶
A Edge represents an edge in the call graph.
Site is nil for edges originating in synthetic or intrinsic functions, e.g. reflect.Call or the root of the call graph.
type Edge struct { Caller *Node Site ssa.CallInstruction Callee *Node }
func (Edge) Description ¶
func (e Edge) Description() string
func (Edge) Pos ¶
func (e Edge) Pos() token.Pos
func (Edge) String ¶
func (e Edge) String() string
type Graph ¶
A Graph represents a call graph.
A graph may contain nodes that are not reachable from the root. If the call graph is sound, such nodes indicate unreachable functions.
type Graph struct { Root *Node // the distinguished root node Nodes map[*ssa.Function]*Node // all nodes by function }
func New ¶
func New(root *ssa.Function) *Graph
New returns a new Graph with the specified root node.
func (*Graph) CreateNode ¶
func (g *Graph) CreateNode(fn *ssa.Function) *Node
CreateNode returns the Node for fn, creating it if not present.
func (*Graph) DeleteNode ¶
func (g *Graph) DeleteNode(n *Node)
DeleteNode removes node n and its edges from the graph g. (NB: not efficient for batch deletion.)
func (*Graph) DeleteSyntheticNodes ¶
func (g *Graph) DeleteSyntheticNodes()
DeleteSyntheticNodes removes from call graph g all nodes for synthetic functions (except g.Root and package initializers), preserving the topology. In effect, calls to synthetic wrappers are "inlined".
type Node ¶
A Node represents a node in a call graph.
type Node struct { Func *ssa.Function // the function this node represents ID int // 0-based sequence number In []*Edge // unordered set of incoming call edges (n.In[*].Callee == n) Out []*Edge // unordered set of outgoing call edges (n.Out[*].Caller == n) }
func (*Node) String ¶
func (n *Node) String() string
Subdirectories
Name | Synopsis |
---|---|
.. | |
cha | Package cha computes the call graph of a Go program using the Class Hierarchy Analysis (CHA) algorithm. |
rta | This package provides Rapid Type Analysis (RTA) for Go, a fast algorithm for call graph construction and discovery of reachable code (and hence dead code) and runtime types. |
static | Package static computes the call graph of a Go program containing only static call edges. |