fix(extraction): detect export-macro-annotated class in .h language check#1133
Open
luoyxy wants to merge 1 commit into
Open
fix(extraction): detect export-macro-annotated class in .h language check#1133luoyxy wants to merge 1 commit into
luoyxy wants to merge 1 commit into
Conversation
luoyxy
pushed a commit
to luoyxy/codegraph
that referenced
this pull request
Jul 2, 2026
…heck (colbymchenry#1133) A `.h` file defaults to C and is reclassified as C++ only when `looksLikeCpp` finds a C++-specific construct. Its class branch (`\bclass\s+\w+\s*[:{]`) couldn't see through an export/visibility macro: in `class ENGINE_API UFoo : public UObject` the macro sits between `class` and the type name, so `\w+` consumed the macro and the following `[:{]` guard failed. A lean Unreal-Engine header carrying only that macro-class plus `GENERATED_BODY()` — with no `public:` / `virtual` / `namespace` / `template` to fall back on — was therefore parsed as C. The C extractor has `classTypes: []` and no export-macro pre-parse, so the class definition and its inheritance edge silently vanished, undoing the macro-class recovery from colbymchenry#1061. Add a detection branch for a macro-annotated `class`/`struct` declaration, mirroring the shape `blankCppExportMacros` already recovers before parsing. The two-token `<keyword> <MACRO> <Name>` before a `[:{]` never occurs in valid C, so genuine C headers stay classified as C (covered by a new regression guard). Thanks @luoyxy for the report and root-cause analysis.
a5f5f50 to
2d7afb0
Compare
2 tasks
…heck (colbymchenry#1133) A `.h` file defaults to C and is reclassified as C++ only when `looksLikeCpp` finds a C++-specific construct. Its class branch (`\bclass\s+\w+\s*[:{]`) couldn't see through an export/visibility macro: in `class ENGINE_API UFoo : public UObject` the macro sits between `class` and the type name, so `\w+` consumed the macro and the following `[:{]` guard failed. A lean Unreal-Engine header carrying only that macro-class plus `GENERATED_BODY()` — with no `public:` / `virtual` / `namespace` / `template` to fall back on — was therefore parsed as C. The C extractor has `classTypes: []` and no export-macro pre-parse, so the class definition and its inheritance edge silently vanished, undoing the macro-class recovery from colbymchenry#1061. Add a detection branch for a macro-annotated `class`/`struct` declaration, mirroring the shape `blankCppExportMacros` already recovers before parsing. The two-token `<keyword> <MACRO> <Name>` before a `[:{]` never occurs in valid C, so genuine C headers stay classified as C (covered by a new regression guard). Thanks @luoyxy for the report and root-cause analysis.
2d7afb0 to
e2770b7
Compare
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
A
.hfile defaults to C and is only reclassified as C++ whenlooksLikeCppfinds a C++-specific construct. Its class branch (\bclass\s+\w+\s*[:{]) could not see through an export/visibility macro: inclass ENGINE_API UFoo : public UObjectthe macro sits betweenclassand the type name, so\w+consumed the macro and the trailing[:{]guard failed to match.A lean Unreal-Engine header carrying only that macro-annotated class plus
GENERATED_BODY()— with nopublic:/virtual/namespace/templateto fall back on — was therefore parsed as C. The C extractor hasclassTypes: []and no export-macro pre-parse, so the class definition and its inheritance edge silently vanished from the graph, quietly undoing the macro-class recovery from #1061.This is a language-detection gap, distinct from #1061 (which correctly blanks the macro after the file is already routed as C++) — the file never reached the C++ path in the first place.
Fix
Add a detection branch to
looksLikeCppfor a macro-annotatedclass/structdeclaration, mirroring the exact shapeblankCppExportMacrosalready recovers before parsing:The two-token
<keyword> <MACRO> <Name>before a[:{]never occurs in valid C, so genuine C headers are unaffected.Repro (verified)
class ENGINE_API UFoo : public UObject(no other C++ signal)c, 0 class nodescpp, 1 class nodepublic:presentcpp(already worked)cppTest plan
__tests__/extraction.test.ts(macro-class header detects ascpp; macro-struct with inheritance; plain C header still detects asc)npm run buildsucceedsextraction.test.tsThanks for CodeGraph! Follow-up to #1061.
Made with Cursor
Fixes #1159.