feat: add C/C++ language support - #69
Open
kapelner wants to merge 2 commits into
Open
Conversation
One "cpp" grammar (tree-sitter-cpp) parses the whole C/C++ family uniformly. Extracts classes, structs, enums, and template classes/functions; resolves header-declared prototypes and their out-of-line `Class::method` definitions to a single node via declarator-chain unwrapping; tracks stateful access_specifier visibility (default private for class, public for struct); emits extends-only heritage (no interface keyword in C++); and captures member/qualified call edges plus #include edges for both local and system forms. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Needed to install tree-sitter-cpp and run ad-hoc grammar-inspection scripts while building C++ support. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
acelan
added a commit
to acelan/agent-codebase-bench
that referenced
this pull request
Aug 11, 2026
graff's npm package bundles only Go/Python/TypeScript tree-sitter grammars (no tree-sitter-c), so it cannot index the kernel's C code: builds return 0 C cards and ask() returns unrelated Python matches for i915. Set graft.enabled: false and drop its broken run data/report row. Re-enable when the C/C++ parser lands (NanoNets/Graft#69).
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 C/C++ language support to graft's Tier-1 extraction, following the same pattern established for the other supported languages (Go, Python, TS). One
"cpp"grammar (tree-sitter-cpp) parses the whole C/C++ family —.c/.h/.cpp/.hpp/.cc/.cxx/.hh/.hxx— uniformly, the same approach clangd and most polyglot tooling take. No separate.c-only language for v1 (documented limitation below).class_specifier/struct_specifier/enum_specifierall carry anamefield;template_declarationspans are attributed back to the templated class/function so the card doesn't cut off thetemplate<typename T>line).describeCpp():function_definitioncarries nonamefield at all — it's buried in a declarator chain that can be a plain identifier, an out-of-classClass::methodqualifier, a destructor (~Class), or an operator overload (operator==). A header-declared prototype and its.cppout-of-line definition resolve to exactly one node, not two or zero — the single most important case to get right for a header/source-split codebase.access_specifiertoken (public:/private:/protected:) applies to every subsequent class member until the next one (defaultprivateforclass,publicforstruct) — unlike every other supported language's per-node exported check, which needed new plumbing (ctx.cppAccessthreaded through the walk).: public Base) always emitsextends— C++ has nointerfacekeyword, so no "first = extends, rest = implements" heuristic is needed (simpler than the analogous C#-style precedent this was modeled on)../->), qualified (Class::static_method,ns::fn) resolved via a directrecvTypesupply (bypassing the bindings-lookup path, since the qualifier already IS the type name).#includeedges capture both"local.h"and<system>forms.Known limitations (documented in code + CHANGELOG)
#include "local.h"(no./prefix) only resolves to an in-repo file when it happens to match a real repo-relative path — C's directory-relative-without-prefix include convention isn't specially handled byresolve.ts's existing import resolver.Test plan
tsc --noEmitcleannpm run buildcleantest/graph-cpp.test.ts— 7 tests covering classes/structs/enums/templates, the header/source-split single-node guarantee, access-specifier visibility, heritage, member/qualified calls,#includeedges, and contains edgesgraft buildagainst a real header/source-split C++ fixture🤖 Generated with Claude Code