Skip to content

feat(callgraph): C/C++ module registry and include resolution#672

Open
shivasurya wants to merge 1 commit intoshiva/cpp-parserfrom
shiva/cpp-module-registry
Open

feat(callgraph): C/C++ module registry and include resolution#672
shivasurya wants to merge 1 commit intoshiva/cpp-parserfrom
shiva/cpp-module-registry

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

Summary

Adds the FQN foundation for the C/C++ call-graph builder.

  • graph/callgraph/core/c_module_types.goCModuleRegistry (file-prefix, includes, function index) and CppModuleRegistry (embeds C registry plus namespace and class indices).
  • graph/callgraph/registry/c_module.goBuildCModuleRegistry, BuildCppModuleRegistry, and BuildCIncludeMap walk the parsed CodeGraph and produce read-only registries.

FQN format

Shape Example
C function src/net/socket.c::connect_to_server
C++ free function (namespaced) src/utils.cpp::mylib::process
C++ class method src/socket.cpp::mylib::Socket::connect
C++ class method (no namespace) src/app.cpp::App::run
C++ free function (no namespace) src/main.cpp::main

Include resolution order

For #include \"...\", first match wins:

  1. Directory of the source file
  2. <projectRoot>/include/<header>
  3. <projectRoot>/src/<header>
  4. <projectRoot>/<header>

System includes (#include <...>) are skipped — they are owned by a future stdlib registry.

Design notes

  • Method-to-class association uses byte-range containment within the same file. The registry never reads parser-internal context state, so it stays composable across future parser refactors.
  • Files outside the project root (..-prefixed relative paths) are dropped at registry-build time.
  • FunctionIndex deliberately preserves duplicates across header and source files so the call-graph builder can choose between declaration and definition.
  • appendUnique dedupes 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 issues
  • Coverage: core 94.3%, registry 91.7% on the new files
  • 9 spec test cases covered: empty graph, files+functions, duplicate across files, duplicate same file, outside project root, namespace+class index, method-without-namespace, on-disk include resolution (4 search dirs + system + missing), language filter, plus defensive paths (orphan method, empty header name, directory-named-as-header).

Stacked on

shiva/cpp-parser (#671)

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>
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels May 2, 2026
@shivasurya shivasurya self-assigned this May 2, 2026
@safedep
Copy link
Copy Markdown

safedep Bot commented May 2, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 4
Rules 205

Powered by Code Pathfinder

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

❌ Patch coverage is 87.28324% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.18%. Comparing base (1a773d0) to head (b9a6ef5).

Files with missing lines Patch % Lines
sast-engine/graph/callgraph/registry/c_module.go 86.41% 11 Missing and 11 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           shiva/cpp-parser     #672      +/-   ##
====================================================
+ Coverage             85.17%   85.18%   +0.01%     
====================================================
  Files                   178      180       +2     
  Lines                 26064    26237     +173     
====================================================
+ Hits                  22199    22351     +152     
- Misses                 3015     3024       +9     
- Partials                850      862      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant