fix(extraction): C extractor blanks macro attributes before typedef return types#1223
Open
fengshao1227 wants to merge 1 commit into
Open
Conversation
…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
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.
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:
preParseCSourceonly 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.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
extraction.test.ts:SEC_ATTR UINT32 LostName(VOID)— recoversLostName, not(VOID)LITE_OS_SEC_TEXT_INIT UINT32)