codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

fix(cpp): resolve callers for typed pointer method calls

Open thismilktea opened this issue 6 months ago • 0 comments

Summary

Fix C++ caller resolution for typed member-pointer calls like m_cpAlg->Processing().

Problem

CodeGraph could miss calls/callers edges for common C++ member-pointer calls. In cases like:

CDetect* m_cpAlg; m_cpAlg->Processing();

the call was not reliably resolved to CDetect::Processing, so queries like codegraph callers CDetect::Processing could incorrectly return no callers.

There were two underlying gaps:

  1. ptr->method() calls were not consistently extracted as receiver-qualified references.
  2. Out-of-line C++ method definitions like int CDetect::Processing() were not reliably surfaced as class methods with the right qualified identity.

Fix

This PR makes a narrow C++-specific fix across extraction and resolution:

  • extend call extraction to treat C/C++ field_expression member calls as receiver-qualified calls, so m_cpAlg->Processing() is preserved as a receiver-aware reference
  • improve C++ method extraction for qualified definitions like CDetect::Processing() so they resolve as proper method nodes
  • add a conservative C++ receiver-type inference step in method-call resolution:
    • infer the receiver type from explicit declarations in the same .cpp or matching header
    • normalize common wrappers like const, *, &, and namespaces
    • resolve receiver.method against that inferred class type before falling back to broader heuristics

This keeps the scope small while fixing the missing caller/callee linkage.

Tests

Added an end-to-end C++ regression test covering:

  • a typed member pointer declaration (CDetect* m_cpAlg)
  • multiple calls through m_cpAlg->Processing()
  • an out-of-line method definition int CDetect::Processing()

Assertions verify that:

  • CDetect::Processing is indexed as a method node
  • getCallers(CDetect::Processing) includes CDetector::Run and CDetector::Flush
  • getCallees(CDetector::Run) includes CDetect::Processing

Targeted test run:

npx vitest run tests/frameworks-integration.test.ts -t "resolves callers through typed object pointers"

Closes #445

thismilktea avatar May 26 '26 13:05 thismilktea