C/C++ source pre-processing before tree-sitter: recover macro-annotated class * definitions, macro-prefixed function definitions, macro-prefixed members, and * macro-decorated members (Unreal-Engine reflection markup) — plus the non-C++ * surface of the dialects parsed with the C++ grammar: `.met
(source: string, filePath?: string)
| 785 | * or by content, for CUDA living in `.h`/`.hpp` headers). Offset-preserving; |
| 786 | * directive lines are restored at the end (see restoreDirectiveLines). */ |
| 787 | function preParseCppSource(source: string, filePath?: string): string { |
| 788 | // blankCLeadingAttrMacros runs AFTER the api-prefix blank so a stacked |
| 789 | // `FMT_NORETURN FMT_API void f(…)` reduces to the `MACRO Ret name(` shape |
| 790 | // it matches (the _API token is already spaces by then). |
| 791 | let blanked = blankLoneMacroLines( |
| 792 | blankCLeadingAttrMacros( |
| 793 | blankCppAnnotationMacroCalls( |
| 794 | blankCppInlineAnnotationMacros( |
| 795 | blankCppApiPrefixMacros(blankCppInlineMacros(blankCppExportMacros(source))) |
| 796 | ) |
| 797 | ) |
| 798 | ) |
| 799 | ); |
| 800 | const lower = filePath ? filePath.toLowerCase() : ''; |
| 801 | if (lower.endsWith('.metal')) { |
| 802 | blanked = blankMetalAttributes(blanked); |
| 803 | } else if (lower.endsWith('.cu') || lower.endsWith('.cuh') || looksLikeCudaSource(source)) { |
| 804 | blanked = blankCudaConstructs(blanked); |
| 805 | } |
| 806 | return restoreDirectiveLines(source, blanked); |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * Blank an unknown attribute macro sitting in front of a C function |
nothing calls this directly
no test coverage detected