Skip to content

feat: add C support via a language plugin - #35

Merged
MCR-3 merged 7 commits into
mainfrom
33-c-language-support
Oct 11, 2026
Merged

MCR-3 merged 7 commits into
mainfrom
33-c-language-support

Conversation

@MCR-3

@MCR-3 MCR-3 commented Oct 10, 2026

Copy link
Copy Markdown
Member

Closes #33

What

Adds C as a Language plugin (.c, .h), built on the shared bookkeeping from #31.

  • backend/languages/cfamily.py: tree-sitter helpers meant to be reused by the C++ plugin (declarators, parameters, comment blocks, #include resolution).
  • backend/languages/c.py: the plugin. Only definitions are Functions; a header prototype never is, but its comment documents a definition that has none.
  • Calls resolve by name in C's visibility order: same file, then quoted #include chain (and the .c implementing an included header, non-static only), then the one non-static definition in the picked root. Two or more candidates at the step that finds any mean no wire. A call through a parameter or local variable is treated as indirect and never linked.
  • Frontend: c entry in languages.ts, prism-c highlighting, and the empty-state hints now name every supported language (TypeScript and JavaScript were missing).
  • sample_c_project/, plus the README table row, Backend bullet and the verification line in CLAUDE.md.

Decisions worth a look

  • Include resolution falls back to a unique path suffix when a quoted path doesn't resolve relative to the including file or the picked root. It stands in for the unread -I paths. Not in the issue; documented in the plugin docstring.
  • The implementing .c for a header prefers the header's own directory before other directories with the same stem.
  • Parameter and local names are collected across the whole function body, with no block scoping. A name declared as a local in one block also suppresses a direct call to a same-named function elsewhere in that function (conservative).
  • unannotatedReturn: null for C, so a missing return type never renders as None.

Verification

  • python -m backend.analyzer on sample_project, sample_rust_project, sample_typescript_project and sample_rust_nested_project gives identical function, edge and file counts before and after (16/17, 8/6, 21/18, 2/1).
  • sample_c_project: 11 functions, 9 edges, no parse errors.
  • npm run build and npm run lint pass in frontend/; GET /api/health returns ok.
  • Each commit imports the backend and passes npm run build on its own.
  • 22 ad-hoc analyzer checks covering each acceptance criterion and resolution rule (the repo has no test suite, so they are not committed).
  • Python's own Include/ directory (283 macro-heavy headers) analyzes in about 2s, with the 247 files tree-sitter can't fully parse flagged and the functions it recovered kept.

Not verified

  • A real zlib tree was not run; the macro-heavy case was exercised with Python's headers and crafted zlib-style files.
  • The badge contrast in both themes was reasoned from the fixed dark badge text on #a8b9cc, not checked in a browser.

MCR-3 added 7 commits October 10, 2026 10:55
Declarator names, parameters, comment blocks above a node and #include
resolution read the same way in C and C++, so they live in one module the
C plugin uses now and a C++ plugin can reuse later.
Reads .c and .h with tree-sitter-c. Only definitions are Functions.
Calls resolve by name in C's own visibility order (same file, quoted
#include chain and the implementing .c file, then the one non-static
definition), and two or more candidates mean no wire rather than a guess.
The hints still listed only Python and Rust, so TypeScript and JavaScript
were missing before C joined them.
Headers with prototypes and doc comments, a static helper, and a
function-pointer parameter that must not draw a wire.
The call collector walked each body with a stack and popped children
last-first, so a function's calls came out in reverse source order. The
canvas stacks callee cards in that order, which put them upside down and
made every wire from a caller cross the others. Push children reversed so
the walk visits them in source order, as the Rust plugin's recursion does.
@MCR-3
MCR-3 merged commit 44f9b21 into main Oct 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add C support via a language plugin

1 participant