Repository navigation
fix(parsers): extract C/C++ functions returning a pointer or reference - #1582
Merged
Merged
Conversation
#1524) The queries nested `pointer_declarator` inside `function_declarator`. The real AST is the reverse — a pointer return type wraps the function declarator from the outside: char* f() { } function_definition > pointer_declarator > function_declarator > identifier So the second alternative in c.py matched nothing, and cpp.py had no alternative at all. No function returning T*, T** or T& was extracted. `pre_scan_c` and `pre_scan_cpp` carried their own copies of the same inverted shape, so these functions were also missing from the cross-file name map — invisible as call targets, not merely absent as nodes. Both copies are fixed here, which is the half that restores resolution. Covered forms: T*, T**, T& (C++), and the qualified out-of-line method `char* Buf::data()`, whose class context survives the extra wrap. Accessors returning T*/T&, factory functions and operator[] are pervasive in C and C++, so this was a large silent gap. No golden moved. The only pointer-returning function in the C/C++ fixtures is `const char* get_color_name` in tough_macros.c, which sits inside an X-macro region tree-sitter cannot parse (ERROR node at line 79) — so it is unreachable for reasons unrelated to this fix. Co-Authored-By: Claude Fable 5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ |
Contributor
🔍 PR Code Graph Analysisfix(parsers): extract C/C++ functions returning a pointer or reference (#1582) 📊 Interactive VisualizationView the blast radius graph: PR Reviewer Dashboard 📦 ArtifactsThe graph JSON has been uploaded as a build artifact: Generated by CodeGraphContext using FalkorDB Lite |
Shashankss1205
added a commit
that referenced
this pull request
Aug 8, 2026
Ten PRs since 0.5.6 — mostly parser correctness, all with regression tests. Parsers - Ruby nested classes no longer delete their parent; method parameters extracted at all (#1523, #1527, #1581) - C/C++ functions returning a pointer or reference are extracted, and registered in pre_scan so they resolve as call targets (#1524, #1582) - C# fields and locals parsed, restoring receiver-type inference for `var x = new T(); x.M();` (#1525, #1584) - JavaScript destructured, array and rest parameters extracted, recording the binding names rather than a placeholder (#1527, #1591) Queries and analysis - Five defects that returned wrong answers without erroring: inflated repository stats, misattributed callers, discarded graph_name, count(*) after OPTIONAL MATCH, an ignored tool argument (#1577) - Dead-code detection made correct and self-consistent, including the JS module-level false positive (#600, #1559, #1578) Indexing - add_package_to_graph on a flat module no longer indexes the whole virtualenv (#1528, #1586) - SCIP job progress no longer exceeds 100% (#1535, #1583) Docs and tests - Database Options table columns realigned (#1590) - MCP tool definition contract validation (#1580) Co-authored-by: Claude Fable 5 <[email protected]>
This branch was successfully deployed
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.
Fixes #1524. Full suite: 1139 passed, 7 skipped, no failures.
The bug
Both queries nested
pointer_declaratorinsidefunction_declarator. The real AST is the reverse — a pointer return type wraps the function declarator from the outside:Verified against the grammar:
So
c.py's second alternative matched nothing, andcpp.pyhad no alternative at all.The half that mattered more
pre_scan_candpre_scan_cppcarry their own copies of the same inverted shape. That is the cross-file name map, so these functions weren't just missing as nodes — they were missing as call targets, and every call to them stayed unresolved. Both copies are fixed here.Accessors returning
T*/T&, factory functions andoperator[]are pervasive in C and C++, so this was a large silent gap.Covered forms
T*,T**,T&(C++ only), and the qualified out-of-line methodchar* Buf::data()— whoseclass_contextsurvives the extra wrap, which is asserted separately since that is the case most likely to break.Tests
tests/unit/parsers/test_c_cpp_pointer_returns.py— 11 tests. Reverting the source changes fails 9 of 11; the 2 that still pass are the plain-intcontrol cases, which is the correct behaviour.Why no golden moved
Worth stating, since an unchanged golden usually means a change didn't apply. The only pointer-returning function in the C/C++ fixtures is
const char* get_color_nameintough_macros.c, and it sits inside an X-macro region tree-sitter cannot parse:Line 79 is that function. It is unreachable for reasons unrelated to this fix, so the goldens are correctly unchanged. A fixture exercising a plain
T*return would be a reasonable follow-up.🤖 Generated with Claude Code