feat(callgraph): C/C++ module registry and include resolution#672
Merged
shivasurya merged 1 commit intomainfrom May 3, 2026
Merged
feat(callgraph): C/C++ module registry and include resolution#672shivasurya merged 1 commit intomainfrom
shivasurya merged 1 commit intomainfrom
Conversation
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 @@
## main #672 +/- ##
==========================================
+ Coverage 85.18% 85.19% +0.01%
==========================================
Files 178 180 +2
Lines 26064 26237 +173
==========================================
+ Hits 22202 22353 +151
- Misses 3012 3023 +11
- Partials 850 861 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced May 2, 2026
Owner
Author
This was referenced May 3, 2026
Owner
Author
Merge activity
|
Add CModuleRegistry and CppModuleRegistry types under callgraph/core plus build helpers under callgraph/registry. The registries map source files to project-relative FQN prefixes, index every function under its bare name for cross-file resolution, and resolve project-local #include "..." directives via a fixed search order (same dir, include/, src/, project root). C++ adds namespace-qualified and class-qualified indices, with method-to-class association via byte-range containment so the registry stays decoupled from parser-internal context tracking. Establishes the FQN foundation for the C/C++ call-graph builder: PR-07 (C) and PR-08 (C++) consume FunctionIndex, NamespaceIndex, ClassIndex, and Includes to compute caller/callee FQNs and follow header-to-source edges. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
b9a6ef5 to
7a98308
Compare
shivasurya
added a commit
that referenced
this pull request
May 3, 2026
## Summary Adds the explicit type-tracking foundation for C/C++ call-graph resolution. - **`graph/callgraph/resolution/c_types.go`** — `CTypeInferenceEngine`, `CFunctionScope`, `CVariableBinding`. Tracks return types and per-function variable scopes drawn directly from source declarations. - **`graph/callgraph/resolution/cpp_types.go`** — `CppTypeInferenceEngine` embeds the C engine and adds class method / class field indices, plus `auto` handling. ### TypeInfo contract | Source | Confidence | Used for | |---|---|---| | `declaration` | 1.0 | Explicit types from source — return types, variable decls, class members | | `unresolved_auto` | 0.0 | C++ `auto x = ...` placeholders awaiting Phase 2 deduction | ### Design notes - **Embedding**: `CppTypeInferenceEngine` embeds `CTypeInferenceEngine` by value, so every C-engine method (`ExtractReturnType`, `GetScope`, `GetVariable`, etc.) is callable on the C++ engine. The embedded `Registry` field aliases the C++ registry's `CModuleRegistry` facet so updates propagate. - **Reassignment**: each variable name keeps a slice of bindings; `GetVariable` returns the latest. `GetAllBindings` exposes the history for future flow analysis. - **`auto` detection**: exact equality on `\"auto\"`. Modifiers like `auto*` and `auto&` are concrete types and keep full confidence — they survive the override branch and route through the C engine unchanged. - **Void returns**: explicitly dropped at registration so void functions never pollute downstream lookups (which gate on `GetReturnType != nil`). - **Thread safety**: four `sync.RWMutex` instances guard `Scopes`, `ReturnTypes`, `ClassMethods`, `ClassFields`. Snapshot accessors (`GetAllReturnTypes`, `GetAllScopes`) return defensive copies. - **Lazy scope creation**: `ExtractVariableType` creates the scope on first use; callers do not need to call `AddScope` before the first variable. ## Test plan - [x] `go build ./...` - [x] `go test ./...` — full suite green (25 packages) - [x] `go test -race ./graph/callgraph/resolution/...` — clean - [x] `go vet ./...` - [x] `golangci-lint run ./graph/callgraph/resolution/` — 0 issues - [x] Coverage on changed lines: `c_types.go` 100%, `cpp_types.go` 100% - [x] Spec test cases covered: NewC*Engine, ExtractReturnType (success + void), AddReturnType, ExtractVariableType (basic + reassignment), GetScope miss, AddScope, concurrent access (-race), embedded methods, RegisterClassMethod (success + void/empty drops + redeclaration), RegisterClassField (success + empty drops), `auto` zero-confidence, `auto*`/`auto&` exact-match, complex C types (pointer/const/struct), complex C++ types (templates / refs / nested templates). ## Stacked on `shiva/cpp-module-registry` (#672)
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 the FQN foundation for the C/C++ call-graph builder.
graph/callgraph/core/c_module_types.go—CModuleRegistry(file-prefix, includes, function index) andCppModuleRegistry(embeds C registry plus namespace and class indices).graph/callgraph/registry/c_module.go—BuildCModuleRegistry,BuildCppModuleRegistry, andBuildCIncludeMapwalk the parsedCodeGraphand produce read-only registries.FQN format
src/net/socket.c::connect_to_serversrc/utils.cpp::mylib::processsrc/socket.cpp::mylib::Socket::connectsrc/app.cpp::App::runsrc/main.cpp::mainInclude resolution order
For
#include \"...\", first match wins:<projectRoot>/include/<header><projectRoot>/src/<header><projectRoot>/<header>System includes (
#include <...>) are skipped — they are owned by a future stdlib registry.Design notes
..-prefixed relative paths) are dropped at registry-build time.FunctionIndexdeliberately preserves duplicates across header and source files so the call-graph builder can choose between declaration and definition.appendUniquededupes per-key entries within a single file (defensive against repeated graph visits).Test plan
go build ./...go test ./...— full suite green (25 packages)go vet ./...golangci-lint run ./graph/callgraph/registry/ ./graph/callgraph/core/— 0 issuescore94.3%,registry91.7% on the new filesStacked on
shiva/cpp-parser(#671)