Skip to content

feat(graph): C/C++ file detection and tree-sitter parsing foundation#668

Open
shivasurya wants to merge 1 commit intomainfrom
claude/review-techspec-pr-docs-7jawU
Open

feat(graph): C/C++ file detection and tree-sitter parsing foundation#668
shivasurya wants to merge 1 commit intomainfrom
claude/review-techspec-pr-docs-7jawU

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

@shivasurya shivasurya commented May 2, 2026

Summary

Foundation for C/C++ language support — file discovery and tree-sitter
grammar selection only. No AST → Node dispatch yet, so Java/Python/Go
behavior is unchanged.

  • Route .c, .cpp, .cc, .cxx, .h, .hpp, .hh, .hxx files to
    the C and C++ tree-sitter grammars
  • Exclude common C/C++ build artifact directories from getFiles():
    build/, cmake-build-*, third_party/, external/, obj/, bin/,
    dist/, .cache/
  • Disambiguate .h headers as C vs C++ via a best-effort heuristic
    (first ~100 lines scanned for class , namespace , template<,
    access specifiers, ::)
  • Cache header classification in a sync.Map populated once per file in
    the initialize.go worker before AST traversal — keeps the per-node
    IsCSourceFile / IsCppSourceFile lookups zero-I/O

Package layout

C/C++ helpers live in a new graph/clike/ subpackage that sits alongside
the existing language siblings:

sast-engine/graph/
├── clike/         ← NEW: shared C/C++ helpers (detection now, parsers next)
│   ├── detection.go
│   └── detection_test.go
├── docker/
├── golang/
├── java/
└── python/

Subsequent PRs will add graph/clike/parser.go, type-string extraction,
and parameter extraction in the same package, mirroring the layout of
graph/golang/.

Test plan

  • go build ./... — clean
  • go vet ./... — clean
  • golangci-lint run ./graph/... — 0 issues
  • go test ./graph/... -count=1 — passes (no Java/Python/Go regressions)
  • New unit tests in graph/clike/detection_test.go:
    • TestIsCSourceFile / TestIsCppSourceFile — every extension + cached/uncached .h
    • TestDetectCppInHeader — pure C, class, namespace, template, ::, extern "C", empty, missing-file
  • Updated graph/utils_test.go::TestGetFilesIncludesCAndCpp — verifies inclusion of C/C++ extensions and exclusion of all build/artifact dirs

@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

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@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 5
Rules 205

Powered by Code Pathfinder

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

❌ Patch coverage is 91.83673% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.07%. Comparing base (99ecf1e) to head (0f553a6).

Files with missing lines Patch % Lines
sast-engine/graph/initialize.go 60.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #668   +/-   ##
=======================================
  Coverage   85.06%   85.07%           
=======================================
  Files         172      173    +1     
  Lines       25027    25070   +43     
=======================================
+ Hits        21290    21329   +39     
- Misses       2941     2944    +3     
- Partials      796      797    +1     

☔ 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.

@shivasurya shivasurya force-pushed the claude/review-techspec-pr-docs-7jawU branch from 9690595 to caf0fec Compare May 2, 2026 12:59
@shivasurya shivasurya changed the title feat(graph): C/C++ file detection and tree-sitter parsing foundation (PR-01) feat(graph): C/C++ file detection and tree-sitter parsing foundation May 2, 2026
@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
Route .c/.cpp/.cc/.cxx/.h/.hpp/.hh/.hxx files to the C and C++ tree-sitter
grammars and exclude common C/C++ build artifact directories
(build/, cmake-build-*, third_party/, external/, obj/, bin/, dist/, .cache/)
during file discovery.

Header files share the .h extension between C and C++. A best-effort
heuristic scans the first 100 lines for C++-only indicators (class,
namespace, template, access specifiers, ::) and the result is cached in a
sync.Map populated once per file in the initialize.go worker before AST
traversal, so the per-AST-node IsCSourceFile / IsCppSourceFile lookups
stay zero-I/O.

The C/C++ detection helpers live in a new graph/clike/ subpackage that
sits alongside the existing graph/golang, graph/python, graph/java, and
graph/docker packages. graph/clike will accumulate the shared C/C++
extraction primitives in subsequent PRs (parser, type strings, parameter
extraction); this PR introduces detection only.

This is parsing-pipeline groundwork only — no AST → Node dispatch yet, so
existing Java/Python/Go behavior is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
@shivasurya shivasurya force-pushed the claude/review-techspec-pr-docs-7jawU branch from caf0fec to 0f553a6 Compare May 2, 2026 13:06
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.

3 participants