callgraph

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

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

View Source
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

func MakeMethodID(filePath, className, methodName string) string

MakeMethodID creates a node ID for a class method

func MakeNodeID

func MakeNodeID(filePath, funcName string) string

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 NewManager

func NewManager() *Manager

NewManager creates a new call graph manager

func (*Manager) AddEdge

func (m *Manager) AddEdge(edge *Edge)

AddEdge adds a call edge to the graph

func (*Manager) AddNode

func (m *Manager) AddNode(node *Node)

AddNode adds a function node to the graph

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

func (m *Manager) GetCallees(callerID string) []*Node

GetCallees returns all functions called by the given function

func (*Manager) GetCallers

func (m *Manager) GetCallers(calleeID string) []*Node

GetCallers returns all functions that call the given function

func (*Manager) GetDistance

func (m *Manager) GetDistance(fromID, toID string) int

GetDistance returns the shortest distance between two nodes Uses caching for performance

func (*Manager) GetEntryPoints

func (m *Manager) GetEntryPoints() []*Node

GetEntryPoints returns all entry point nodes

func (*Manager) GetNode

func (m *Manager) GetNode(id string) *Node

GetNode retrieves a node by ID

func (*Manager) GetShortestPath

func (m *Manager) GetShortestPath(fromID, toID string) []*Node

GetShortestPath finds the shortest call path between two functions Returns nil if no path exists

func (*Manager) Stats

func (m *Manager) Stats() map[string]int

Stats returns statistics about the call graph

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL