fix(extraction): index C functions decorated with a leading export macro (#515)
Summary
Fixes #515. A C function written as EXPORT_MACRO ReturnType Name(...) — a leading export/visibility macro in front of a project-defined (typedef'd) return type — was indexed under the garbage name (params) instead of its real name, so it couldn't be searched or navigated to. This pattern is ubiquitous in vendor SDKs, e.g. the Axera SoC SDK from the report: AX_VIN_GLB_API AX_S32 AX_VIN_Init(AX_VOID).
Root cause
Both the macro and the typedef'd return type are unknown identifiers in type position, so tree-sitter-c peels MACRO RET off as a separate (broken) declaration and parses the real function with its name absorbed as the type field and the parameter list wrapped in a bare parenthesized_declarator instead of a function_declarator:
function_definition
type: type_identifier "AX_VIN_Init" <- the real name
declarator: parenthesized_declarator <- the params
identifier "AX_VOID"
body: compound_statement
extractName then falls through to getNodeText(parenthesized_declarator) → "(AX_VOID)".
Fix
recoverMacroDecoratedFunctionName (wired only into the C extractor's resolveName): when a function_definition's declarator field is directly a parenthesized_declarator, take the name from the type field instead. That shape is one valid C never produces.
Tests
__tests__/extraction.test.ts → new C/C++ Extraction block:
- recovers
AX_VIN_Initfrom the macro-decorated definition (and is not named(AX_VOID)) - plain
int compute(int a)is unaffected int (foo)(void)(redundant parens — keeps afunction_declarator) does not misfire and is not renamed toint
Full suite green locally: npm run build clean, 1097 passed | 2 skipped (+3 new).
Scope
Deliberately narrow — verified against the real grammars with parse dumps before/after:
- Macro + primitive return (
AX_API int F(...)), macro + pointer return (AX_API char* F(...)), and all C++ forms already parse to afunction_declaratorand extract correctly onmain— they don't reach this recovery and aren't touched (noresolveNamechange for the C++ extractor). - Bare prototypes in headers (
AX_API AX_S32 AX_VIN_Init(void);) are reparsed by tree-sitter as a top-level call expression. Recovering a symbol from that would risk synthesizing symbols from genuine call sites, so it's left as a follow-up. The definition site (this fix) is where the symbol lives, which makes it searchable.
No node-count change — resolveName only renames; it cannot add or drop nodes.
@colbymchenry friendly ping — #515 is still open and this one's self-contained: it recovers C functions whose signature is preceded by a leading export macro (e.g. EXPORT void foo(void)), which the extraction pass currently skips. No overlap with the recent extraction merges (#956/#980 are about file/repo discovery, not the C symbol scanner). Happy to rebase if it's drifted — any feedback welcome!