callgraph

package
v0.0.0-...-312e67f Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MatchAny = "any"
	MatchAll = "all"
)

Variables

This section is empty.

Functions

func NewCallGraphPlugin

func NewCallGraphPlugin(callgraphCallback CallgraphCallback) *callgraphPlugin

func ValidateSignatures

func ValidateSignatures(signatures []*callgraphv1.Signature) error

Validates list of callgraphv1.Signature based on protovalidate specification

Types

type CallArgument

type CallArgument struct {
	// An argument may be resolved to multiple values (due to assignments)
	// For example, a function call may have an argument like `foo(a)` where
	// a was assigned to multiple values in the code previously
	// eg. `a = 1`, `a = 2`, `a = 3
	Nodes []*assignmentNode
}

Refers to one argument passed to a function call For example, in the function call `foo(a, b, c)`, there are three CallArgument instances, one for each of `a`, `b`, and `c

type CallGraph

type CallGraph struct {
	FileName string
	Nodes    map[string]*CallGraphNode
	RootNode *CallGraphNode
	Tree     core.ParseTree
	// contains filtered or unexported fields
}

func (*CallGraph) DFS

func (cg *CallGraph) DFS() []DfsResultItem

func (*CallGraph) PrintAssignmentGraph

func (cg *CallGraph) PrintAssignmentGraph() error

func (*CallGraph) PrintCallGraph

func (cg *CallGraph) PrintCallGraph() error

type CallGraphNode

type CallGraphNode struct {
	Namespace string
	CallsTo   []CallReference
	TreeNode  *sitter.Node
}

CallGraphNode represents a single node in the call graph

func (*CallGraphNode) Content

func (gn *CallGraphNode) Content(treeData *[]byte) (string, bool)

If tree sitter node is nil, it returns false indicating that the content details are not available else, it returns the content details and true

func (*CallGraphNode) Metadata

func (gn *CallGraphNode) Metadata() (TreeNodeMetadata, bool)

If tree sitter node is nil, it returns false indicating that the content details are not available else, it returns the content details and true

type CallReference

type CallReference struct {
	// Namespace of the called function or method
	CalleeNamespace string

	// Tree sitter node for the called function or method
	CalleeTreeNode *sitter.Node

	// Identifier keyword node which actually invokes the function call
	CallerIdentifier *sitter.Node

	// Arguments passed to the function call
	Arguments []CallArgument
}

type CallgraphCallback

type CallgraphCallback core.PluginCallback[*CallGraph]

type DfsResultItem

type DfsResultItem struct {
	Namespace        string
	Node             *CallGraphNode
	Caller           *CallGraphNode
	CallerIdentifier *sitter.Node // This is the identifier keyword node from which the fn call was made
	Arguments        []CallArgument
	Depth            int
	Terminal         bool
}

func (DfsResultItem) ToString

func (dri DfsResultItem) ToString() string

type EvidenceMetadata

type EvidenceMetadata struct {
	CallerNamespace string
	CallerMetadata  *TreeNodeMetadata

	CalleeNamespace string
	CalleeMetadata  *TreeNodeMetadata

	// Keyword / statement that caused the match
	CallerIdentifierContent  string
	CallerIdentifierMetadata *TreeNodeMetadata
}

Note - We're only providing content details for the caller identifier since its expected to be at most one line from the entire file, but callerNamespace is an entire scope (fn/class/module) which consumes a lot of repetitive memory

type MatchedCondition

type MatchedCondition struct {
	Condition *callgraphv1.Signature_LanguageMatcher_SignatureCondition
	Evidences []MatchedEvidence
}

type MatchedEvidence

type MatchedEvidence struct {
	Caller           *CallGraphNode
	Callee           *CallGraphNode
	CallerIdentifier *sitter.Node
	Arguments        []CallArgument
}

func (*MatchedEvidence) Metadata

func (evidence *MatchedEvidence) Metadata(treeData *[]byte) EvidenceMetadata

type SignatureMatchResult

type SignatureMatchResult struct {
	FilePath            string
	MatchedSignature    *callgraphv1.Signature
	MatchedLanguageCode core.LanguageCode
	MatchedConditions   []MatchedCondition
}

type SignatureMatcher

type SignatureMatcher struct {
	// contains filtered or unexported fields
}

func NewSignatureMatcher

func NewSignatureMatcher(targetSignatures []*callgraphv1.Signature) (*SignatureMatcher, error)

Creates a new SignatureMatcher instance with the provided target signatures. It validates the signatures using the ValidateSignatures function. If the validation fails, it returns an error.

func (*SignatureMatcher) MatchSignatures

func (sm *SignatureMatcher) MatchSignatures(cg *CallGraph) ([]SignatureMatchResult, error)

type TreeNodeMetadata

type TreeNodeMetadata struct {
	StartLine   uint32
	EndLine     uint32
	StartColumn uint32
	EndColumn   uint32
}

Jump to

Keyboard shortcuts

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