/** * @fileoverview Call Graph Builder - Build function call relationships for interprocedural analysis * @module @nahisaho/musubix-security/analysis/interprocedural/call-graph-builder * @trace REQ-SEC-001 (EARS: WHEN analyzing code, THE system SHALL perform interprocedural analysis) */ /** * Node in call graph representing a function/method */ export interface CallGraphNode { /** Unique ID for this node */ id: string; /** Function/method name */ name: string; /** Fully qualified name (including class/namespace) */ qualifiedName: string; /** Source file path */ filePath: string; /** Line number of definition */ line: number; /** Column number of definition */ column: number; /** Whether this is a method (vs standalone function) */ isMethod: boolean; /** Class name if method */ className?: string; /** Parameter names */ parameters: string[]; /** Whether function is async */ isAsync: boolean; /** Whether function is a generator */ isGenerator: boolean; /** Whether function is exported */ isExported: boolean; } /** * Edge in call graph representing a function call */ export interface CallGraphEdge { /** ID of the edge */ id: string; /** Caller node ID */ callerId: string; /** Callee node ID */ calleeId: string; /** Call site file path */ filePath: string; /** Call site line number */ line: number; /** Call site column number */ column: number; /** Arguments passed at call site (expressions as strings) */ arguments: string[]; /** Whether call is conditional (inside if/ternary) */ isConditional: boolean; /** Whether call is in a loop */ isInLoop: boolean; /** Whether call is in a try block */ isInTry: boolean; /** Whether this is a callback/async call */ isCallback: boolean; } /** * Complete call graph structure */ export interface CallGraph { /** All function/method nodes */ nodes: Map; /** All call edges */ edges: CallGraphEdge[]; /** Mapping from node ID to outgoing edges */ outgoingEdges: Map; /** Mapping from node ID to incoming edges */ incomingEdges: Map; /** Entry points (functions called from outside) */ entryPoints: string[]; /** External calls (to unknown functions) */ externalCalls: ExternalCall[]; } /** * External call to unknown function */ export interface ExternalCall { /** Caller node ID */ callerId: string; /** Name of external function */ name: string; /** Module/package if known */ module?: string; /** Call site location */ filePath: string; line: number; column: number; arguments: string[]; } /** * Options for call graph building */ export interface CallGraphBuilderOptions { /** Include node_modules */ includeNodeModules?: boolean; /** Include type definitions */ includeTypeDefs?: boolean; /** Maximum depth for recursive analysis */ maxDepth?: number; /** Track callback/async calls */ trackCallbacks?: boolean; /** Include anonymous functions */ includeAnonymous?: boolean; } /** * Call Graph Builder - Builds interprocedural call graph from TypeScript/JavaScript source * @trace REQ-SEC-001 */ export declare class CallGraphBuilder { private project; private options; private nodeCounter; private edgeCounter; private nodeMap; private signatureToNodeId; constructor(options?: CallGraphBuilderOptions); /** * Build call graph from source files */ buildFromFiles(filePaths: string[]): CallGraph; /** * Build call graph from source code strings */ buildFromSources(sources: Array<{ filePath: string; content: string; }>): CallGraph; /** * Build call graph from project directory */ buildFromDirectory(dirPath: string, pattern?: string): CallGraph; private buildGraph; private shouldIncludeFile; private collectFunctionDeclarations; private collectCallEdges; private processCallExpression; private findEnclosingFunction; private getCalleeName; private resolveCalleeSignature; private getModuleFromExpression; private isInConditional; private isInLoop; private isInTry; private isCallbackCall; private createFunctionNode; private getNodeSignature; private registerNode; /** * Get all functions that can reach a given function */ getCallers(graph: CallGraph, nodeId: string, depth?: number): string[]; /** * Get all functions called by a given function */ getCallees(graph: CallGraph, nodeId: string, depth?: number): string[]; /** * Find all paths between two functions */ findPaths(graph: CallGraph, sourceId: string, targetId: string, maxLength?: number): string[][]; /** * Get call graph statistics */ getStatistics(graph: CallGraph): CallGraphStatistics; } /** * Call graph statistics */ export interface CallGraphStatistics { nodes: { total: number; functions: number; methods: number; async: number; exported: number; }; edges: { total: number; conditional: number; inLoop: number; inTry: number; callback: number; }; entryPoints: number; externalCalls: number; avgOutDegree: number; } //# sourceMappingURL=call-graph-builder.d.ts.map