Skip to content

fix: extract correct function name for C++ scoped definitions#403

Open
yetf1025-dev wants to merge 1 commit intotirth8205:mainfrom
yetf1025-dev:fix/cpp-scoped-function-name
Open

fix: extract correct function name for C++ scoped definitions#403
yetf1025-dev wants to merge 1 commit intotirth8205:mainfrom
yetf1025-dev:fix/cpp-scoped-function-name

Conversation

@yetf1025-dev
Copy link
Copy Markdown

Summary

  • Fix C++ function name extraction for scoped definitions (ClassName::method_name) where the return type is a non-primitive type. Previously, the return type was incorrectly extracted as the function name.
  • Add field_identifier to the generic name loop for C++ class member function declarations.

Problem

std::string OSDMap::get_pool_name(int64_t pool_id) const { ... }
bufferlist OSDService::get_inc_map(epoch_t e) { ... }
string RGWDedupProcessor::get_obj_fingerprint(const rgw_obj& obj) { ... }
Function Before After
std::string OSDMap::get_pool_name(...) OSDMap get_pool_name
bufferlist OSDService::get_inc_map(...) bufferlist get_inc_map
string RGWDedupProcessor::get_obj_fingerprint(...) string get_obj_fingerprint
int OSD::handle_osd_map(...) handle_osd_map handle_osd_map

Root Cause

_get_name recurses into function_declarator for C++, but qualified_identifier nodes (used for scoped names like Foo::bar) are not handled by the generic identifier loop. The recursion returns None and the outer loop matches the return type's type_identifier first.

Fix

Detect qualified_identifier inside function_declarator and take the rightmost identifier/field_identifier (the actual method name after the last ::).

Test plan

  • 5 new regression tests in TestCppScopedFunctionName covering scoped functions with type_identifier, qualified_identifier, primitive_type return types, and unscoped functions
  • All existing C++ parsing tests pass (test_multilang.py, test_parser.py, test_visualization.cpp)

Closes #395

🤖 Generated with Claude Code

When a C++ function definition uses a qualified name (e.g.
`ClassName::method_name`) and has a non-primitive return type
(`std::string`, custom types like `bufferlist`, etc.), the parser
incorrectly extracts the return type as the function name.

Root cause: `_get_name` recurses into `function_declarator` for C++,
but `qualified_identifier` nodes (used for scoped names) are not
handled by the generic identifier loop. The recursion returns None
and the outer loop matches the return type's `type_identifier` first.

Fix: detect `qualified_identifier` inside `function_declarator` and
take the rightmost `identifier`/`field_identifier` (the actual method
name after the last `::`). Also add `field_identifier` to the generic
name loop for C++ class member function declarations.

Closes tirth8205#395

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
dpesch added a commit to 11com7/code-review-graph that referenced this pull request May 3, 2026
Adds field_identifier to the node types checked when extracting
function names, so C++ class member functions defined with scoped
declarators (e.g. virtual std::string get_name() = 0) are now
correctly indexed.
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.

C++ scoped function definitions with non-primitive return types extract return type as function name

2 participants