Documentation
¶
Overview ¶
Package callgraph provides sophisticated call graph management with distance computation for input flow analysis. Unlike simple caller->callee mappings, this package provides: - Bidirectional graph traversal (caller->callee and callee->caller) - Distance computation from entry points (HTTP handlers, main, etc.) - Shortest path computation between functions - LRU caching for expensive computations
Index ¶
- Constants
- func MakeMethodID(filePath, className, methodName string) string
- func MakeNodeID(filePath, funcName string) string
- type Edge
- type Manager
- func (m *Manager) AddEdge(edge *Edge)
- func (m *Manager) AddNode(node *Node)
- func (m *Manager) ComputeDistanceFromEntryPoints()
- func (m *Manager) GetCallees(callerID string) []*Node
- func (m *Manager) GetCallers(calleeID string) []*Node
- func (m *Manager) GetDistance(fromID, toID string) int
- func (m *Manager) GetEntryPoints() []*Node
- func (m *Manager) GetNode(id string) *Node
- func (m *Manager) GetShortestPath(fromID, toID string) []*Node
- func (m *Manager) Stats() map[string]int
- type Node
- type NodeType
Constants ¶
const ( NodeTypeRegular = constants.CGNodeTypeRegular NodeTypeEntryPoint = constants.CGNodeTypeEntryPoint NodeTypeSource = constants.CGNodeTypeSource )
Re-export NodeType constants for backward compatibility
Variables ¶
This section is empty.
Functions ¶
func MakeMethodID ¶
MakeMethodID creates a node ID for a class method
func MakeNodeID ¶
MakeNodeID creates a standard node ID from file path and function name
Types ¶
type Edge ¶
type Edge struct {
CallerID string `json:"caller_id"`
CalleeID string `json:"callee_id"`
Line int `json:"line"` // Line of the call site
Column int `json:"column"`
FilePath string `json:"file_path"`
// Call metadata
ArgumentCount int `json:"argument_count"`
IsConditional bool `json:"is_conditional"` // Inside if/switch
InLoop bool `json:"in_loop"` // Inside loop
BranchDepth int `json:"branch_depth"` // Nesting level
}
Edge represents a call relationship
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides sophisticated call graph operations
func (*Manager) ComputeDistanceFromEntryPoints ¶
func (m *Manager) ComputeDistanceFromEntryPoints()
ComputeDistanceFromEntryPoints uses BFS to compute distances from all entry points This is the ATLANTIS-inspired approach for prioritizing analysis
func (*Manager) GetCallees ¶
GetCallees returns all functions called by the given function
func (*Manager) GetCallers ¶
GetCallers returns all functions that call the given function
func (*Manager) GetDistance ¶
GetDistance returns the shortest distance between two nodes Uses caching for performance
func (*Manager) GetEntryPoints ¶
GetEntryPoints returns all entry point nodes
func (*Manager) GetShortestPath ¶
GetShortestPath finds the shortest call path between two functions Returns nil if no path exists
type Node ¶
type Node struct {
ID string `json:"id"` // Unique identifier (usually "filepath:funcname")
Name string `json:"name"` // Function name
FilePath string `json:"file_path"`
Line int `json:"line"`
Type NodeType `json:"type"`
Language string `json:"language"`
ClassName string `json:"class_name,omitempty"` // For methods
IsPublic bool `json:"is_public"` // Visibility
Signature string `json:"signature,omitempty"` // Full function signature
// Distance metrics (computed lazily)
DistanceFromEntry int `json:"distance_from_entry"` // -1 if unreachable
}
Node represents a function in the call graph
type NodeType ¶
type NodeType = constants.CallGraphNodeType
NodeType represents the type of a call graph node Re-exported from pkg/sources/constants for backward compatibility