Repository navigation
feat: add C++ support to the C-family language plugins - #36
Merged
Merged
Conversation
…ally C owns `.h` outright, but a header in a project that also holds C++ files is C++. The dispatcher mapped each extension to exactly one plugin, so it had no way to express that. A plugin can now list `conditional_extensions` and decide per load, in `claims()`, whether it takes them. The dispatcher asks once per distinct extension, in registry order, and falls back to the unconditional owner when nobody claims it, so a load that has no claimant routes exactly as before.
…helpers The C++ plugin reuses these helpers, but a few C++ parameter and declarator shapes were invisible to them: default arguments, `&` and `&&` declarators, parameter packs and the bare `...` token. Teach `extract_params` and the declarator walkers about them; none of these nodes occur in a C tree, so the C plugin's output is unchanged. `walk_top_level` now uses a stack instead of recursion so deeply nested `#if` blocks cannot exhaust Python's recursion limit.
Reads `.cc .cpp .cxx .hpp .hh .hxx`, and claims `.h` when the picked root holds any of those, with tree-sitter-cpp and the C-family helpers. Functions are definitions with a body: free functions, in-class and out-of-class methods, constructors, destructors and operators, named by their scoped qualname, with a parameter-type suffix only for overloads that collide in one file. Calls resolve by C++'s own scoping (class and bases, namespaces, using declarations, then the C plugin's include-based visibility) and member calls by the receiver's declared type. When a type is not visible the call links only to the one loaded method of that name, and a tie never produces a guessed edge. Virtual calls link to the declared class's own method, never fanning out to overrides.
A small catalogue app in the same spirit as the other sample projects, written to exercise what the C++ plugin resolves: a namespace, a class with in-class and out-of-class methods, a constructor, destructor and operator, overloads, function and class templates, a lambda, a virtual call through a base reference, an `auto` receiver, and a `.h` header that is C++ because `.cpp` files sit beside it.
Registers the `cpp` language with its extensions, a badge color that keeps the dark monogram text above 4.5:1 contrast, and the Prism `cpp` grammar, and names C++ in the empty-state hints. `.h` stays on the C entry: the backend decides per project which plugin reads a header, and the frontend only displays the language each file carries.
Adds C++ to the supported-languages table, the sample projects and the backend tour, with the plugin's limits, and the C++ fixture to the analyzer regression check. Records the `.h` routing rule in CLAUDE.md and the C/C++ separation in the glossary, since neither is visible from reading a single plugin. Closes #34
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.
Closes #34
Summary
A new
cppLanguage plugin reads.cc .cpp .cxx .hpp .hh .hxx, and a plugin can now claim an extension conditionally, so.hgoes to C++ only when the picked root holds C++ files.Call resolution in
cpp.py:Calls inside a lambda belong to the enclosing Function,
foo<int>(x)andBox<T>::get()hit the template's single card, and overloads get a parameter-type suffix only when they collide in one file.Evidence
Before (
main):python -m backend.analyzer sample_cpp_projectreads onlymodels.h, as C: 1 file, 0 functions, 0 edges.After: 11 files, 29 functions, 49 edges, every file
cpp, including the.h.C-only projects unchanged: analyzer output for
sample_project,sample_rust_project,sample_typescript_project,sample_c_projectandsample_rust_nested_projectis byte-identical tomain..hstayscinsample_c_project.Each commit stands alone: every commit imports the backend, analyzes
sample_c_projectand builds the frontend.npm run lintpasses.Spot checks on the fixture and a scratch probe:
Merge Danger
Door: two-way. Additive, and reverting the squash commit restores the previous behavior.
Blast Radius: backend dependency
Adds
tree-sitter-cpptorequirements.txt, so the Render image needs a rebuild and the module is imported at startup; if the wheel were missing, the whole backend would fail to import, not just C++. I installed it under Python 3.11 in the backend image and/api/healthand/api/analyzework..hfiles in a mixed folder now show the C++ badge instead of C.Data members are typed from their declaration, so
items_.size()on astd::vectorlinks nothing instead of falling back to a unique loadedsize. The issue lists "a field" among the cases that use the fallback, so this deviates from it on purpose, to avoid false wires. Unparseable macro-heavy headers keep the functions tree-sitter recovered and are flagged, as in C.