Skip to content

fix(extraction): C extractor blanks macro attributes before typedef return types#1223

Open
fengshao1227 wants to merge 1 commit into
colbymchenry:mainfrom
fengshao1227:fix/c-extractor-macro-attr-preparse
Open

fix(extraction): C extractor blanks macro attributes before typedef return types#1223
fengshao1227 wants to merge 1 commit into
colbymchenry:mainfrom
fengshao1227:fix/c-extractor-macro-attr-preparse

Conversation

@fengshao1227

Copy link
Copy Markdown

Summary

Fixes #1211 — C functions with a macro attribute + typedef'd return type (e.g. SEC_ATTR UINT32 LostName(VOID)) were indexed under their parameter list (VOID) instead of their real name.

Root cause: preParseCSource only handled CUDA constructs. Unlike the C++ extractor, it did not blank macro tokens before parsing, so tree-sitter-c couldn't reconcile an unknown macro before a typedef'd return type and misparsed the function name.

Fix: Two additions to preParseCSource:

  • blankCLeadingMacros — blanks arbitrary ALL_CAPS tokens sitting before a known C return type at line start. Handles project-specific macros (SEC_ATTR, LITE_OS_SEC_TEXT_INIT) that no curated list can cover. Matched tightly: ALL_CAPS only, line-start only, must precede a known primitive/typedef type.
  • Wire in blankCppInlineMacros — reuses the curated inline-specifier macro list already maintained for C++ (SQLITE_API, WINAPI, G_INLINE_FUNC, etc.), which are equally common in C codebases.

Impact: Fixes pervasive misindexing in embedded/kernel C projects (OpenHarmony LiteOS-M, firmware using section macros, etc.) where function names were lost and call edges broken.

Closes #1211

Test plan

  • 3 new tests in extraction.test.ts:
    • SEC_ATTR UINT32 LostName(VOID) — recovers LostName, not (VOID)
    • Multiple leading macros (LITE_OS_SEC_TEXT_INIT UINT32)
    • Regression guard: normal mixed-case functions unaffected
  • All 39 existing macro-related tests pass (zero regressions)
  • Full extraction test suite (582 tests) passes

…ef return types (colbymchenry#1211)

tree-sitter-c can't reconcile an unknown macro token before a typedef'd
return type — `SEC_ATTR UINT32 LostName(VOID)` misparsed the function name
as `(VOID)` instead of `LostName`. This affected all C projects using
section/placement macros (OpenHarmony LiteOS-M, embedded firmware, etc.).

Two additions to preParseCSource:

1. blankCLeadingMacros — blanks arbitrary ALL_CAPS tokens sitting before a
   known C return type at line start (handles project-specific macros like
   SEC_ATTR, LITE_OS_SEC_TEXT_INIT that no curated list can cover).

2. Wire in blankCppInlineMacros — catches known inline-specifier macros
   already curated for C++ (SQLITE_API, WINAPI, G_INLINE_FUNC, etc.) that
   are equally common in C codebases.

Closes colbymchenry#1211
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 functions with a macro attribute + a typedef'd return type are indexed under their parameter list

1 participant