feat(callgraph): C call graph builder#674
Open
shivasurya wants to merge 1 commit intoshiva/cpp-type-inferencefrom
Open
feat(callgraph): C call graph builder#674shivasurya wants to merge 1 commit intoshiva/cpp-type-inferencefrom
shivasurya wants to merge 1 commit intoshiva/cpp-type-inferencefrom
Conversation
Add BuildCCallGraph — a four-pass algorithm that produces a
*core.CallGraph for C projects:
Pass 1 Index every C function_definition under "<relpath>::<name>"
and ensure the FQN appears in the module registry's
FunctionIndex for cross-file resolution.
Pass 2 Register explicit return types with the type engine
(skipping void) and emit ParameterSymbol entries for every
named parameter.
Pass 3 Walk the parser-emitted edges (function_definition →
call_expression) to extract one CallSiteInternal per call,
deterministically and without a second AST traversal.
Pass 4 Resolve targets in a definition-preferring order:
same-file definition → global definition → same-file
declaration → declaration reachable through #include "...".
Resolved sites add an edge; unresolved sites are recorded
as CallSite{Resolved:false} so external/stdlib calls remain
visible to rule writers.
The result merges cleanly into a unified graph via the existing
MergeCallGraphs since C FQNs ("src/main.c::main") share no namespace
with Python, Go, or Java.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## shiva/cpp-type-inference #674 +/- ##
============================================================
+ Coverage 85.28% 85.30% +0.01%
============================================================
Files 182 183 +1
Lines 26399 26545 +146
============================================================
+ Hits 22515 22644 +129
- Misses 3023 3034 +11
- Partials 861 867 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds
BuildCCallGraph— a four-pass algorithm that produces a*core.CallGraphfor C projects, ready to merge into the unified graph alongside Python/Go.function_definitionunder\"<relpath>::<name>\"and ensure the FQN is also inregistry.FunctionIndexvoid) and emitParameterSymbolentries for every named parameterfunction_definition → call_expression) to extract oneCallSiteInternalper call — no second AST traversalCallSiterecordsResolution order (Pass 4)
.c); deterministic and independent of include state.registry.FunctionIndex[name]for an FQN whose call-graph entry is a definition. Handles cross-.ccalls.#include— last resort so externs handed off to another translation unit still surface as edges.Calls that don't match any source produce a
CallSite{Resolved: false, FailureReason: \"external_or_unresolved\"}— stdlib calls (printf,malloc) and unknown function pointers remain visible to rule writers without polluting the edge set.Design notes
parseCCallExpressionadds an edge from the enclosing function to the call node. The builder walksOutgoingEdgesof each indexed function instead of doing byte-range containment, keeping Pass 3 deterministic and trivially testable.Metadata[\"is_declaration\"]=trueon prototype/extern decls.isDeclaration()reads that key with a typed assertion so non-declaration nodes (no metadata) fall through correctly.process → process) are emitted as-is; the call graph already deduplicates viaAddEdge..cfiles map to disjoint FQNs.FunctionIndexso callingBuildCCallGraphafterBuildCModuleRegistryis idempotent.Test plan
go build ./...go test ./...— full suite greengo vet ./...golangci-lint run ./graph/callgraph/builder/— 0 issuesc_builder.golines: ~89.6%main()→add()edge.cdefinition preferred over.hdeclaration#includefallbackprintf(stdlib) recorded asResolved:falsewith failure reason.cfiles (file-scope statics)voidreturns dropped.cglobal lookup works without an#includeStacked on
shiva/cpp-type-inference(#673)