@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/bin/codegraph.cmd +1 -1
  2. package/lib/dist/bin/codegraph.js +206 -44
  3. package/lib/dist/bin/codegraph.js.map +1 -1
  4. package/lib/dist/context/formatter.d.ts +7 -1
  5. package/lib/dist/context/formatter.d.ts.map +1 -1
  6. package/lib/dist/context/formatter.js +12 -6
  7. package/lib/dist/context/formatter.js.map +1 -1
  8. package/lib/dist/context/index.d.ts +12 -0
  9. package/lib/dist/context/index.d.ts.map +1 -1
  10. package/lib/dist/context/index.js +101 -25
  11. package/lib/dist/context/index.js.map +1 -1
  12. package/lib/dist/db/index.d.ts +179 -0
  13. package/lib/dist/db/index.d.ts.map +1 -1
  14. package/lib/dist/db/index.js +368 -7
  15. package/lib/dist/db/index.js.map +1 -1
  16. package/lib/dist/db/migrations.d.ts +1 -1
  17. package/lib/dist/db/migrations.d.ts.map +1 -1
  18. package/lib/dist/db/migrations.js +25 -1
  19. package/lib/dist/db/migrations.js.map +1 -1
  20. package/lib/dist/db/queries.d.ts +234 -5
  21. package/lib/dist/db/queries.d.ts.map +1 -1
  22. package/lib/dist/db/queries.js +687 -53
  23. package/lib/dist/db/queries.js.map +1 -1
  24. package/lib/dist/db/schema.sql +16 -3
  25. package/lib/dist/db/sqlite-adapter.d.ts +3 -1
  26. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  27. package/lib/dist/db/sqlite-adapter.js +22 -4
  28. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  29. package/lib/dist/db/wal-valve.d.ts +15 -2
  30. package/lib/dist/db/wal-valve.d.ts.map +1 -1
  31. package/lib/dist/db/wal-valve.js +88 -6
  32. package/lib/dist/db/wal-valve.js.map +1 -1
  33. package/lib/dist/directory.d.ts +29 -0
  34. package/lib/dist/directory.d.ts.map +1 -1
  35. package/lib/dist/directory.js +52 -0
  36. package/lib/dist/directory.js.map +1 -1
  37. package/lib/dist/extraction/extraction-version.d.ts +1 -1
  38. package/lib/dist/extraction/extraction-version.js +1 -1
  39. package/lib/dist/extraction/function-ref.d.ts.map +1 -1
  40. package/lib/dist/extraction/function-ref.js +6 -0
  41. package/lib/dist/extraction/function-ref.js.map +1 -1
  42. package/lib/dist/extraction/generated-detection.d.ts +48 -12
  43. package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
  44. package/lib/dist/extraction/generated-detection.js +176 -11
  45. package/lib/dist/extraction/generated-detection.js.map +1 -1
  46. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  47. package/lib/dist/extraction/grammars.js +101 -2
  48. package/lib/dist/extraction/grammars.js.map +1 -1
  49. package/lib/dist/extraction/index.d.ts +138 -3
  50. package/lib/dist/extraction/index.d.ts.map +1 -1
  51. package/lib/dist/extraction/index.js +518 -94
  52. package/lib/dist/extraction/index.js.map +1 -1
  53. package/lib/dist/extraction/kernel/decode.d.ts +9 -0
  54. package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
  55. package/lib/dist/extraction/kernel/decode.js +162 -0
  56. package/lib/dist/extraction/kernel/decode.js.map +1 -0
  57. package/lib/dist/extraction/kernel/index.d.ts +64 -0
  58. package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
  59. package/lib/dist/extraction/kernel/index.js +279 -0
  60. package/lib/dist/extraction/kernel/index.js.map +1 -0
  61. package/lib/dist/extraction/kernel/layout.d.ts +101 -0
  62. package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
  63. package/lib/dist/extraction/kernel/layout.js +104 -0
  64. package/lib/dist/extraction/kernel/layout.js.map +1 -0
  65. package/lib/dist/extraction/kernel/loader.d.ts +103 -0
  66. package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
  67. package/lib/dist/extraction/kernel/loader.js +146 -0
  68. package/lib/dist/extraction/kernel/loader.js.map +1 -0
  69. package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
  70. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  71. package/lib/dist/extraction/languages/c-cpp.js +868 -16
  72. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  73. package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
  74. package/lib/dist/extraction/languages/erlang.js +58 -22
  75. package/lib/dist/extraction/languages/erlang.js.map +1 -1
  76. package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
  77. package/lib/dist/extraction/languages/objc.js +4 -0
  78. package/lib/dist/extraction/languages/objc.js.map +1 -1
  79. package/lib/dist/extraction/languages/rust.d.ts +20 -0
  80. package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
  81. package/lib/dist/extraction/languages/rust.js +47 -20
  82. package/lib/dist/extraction/languages/rust.js.map +1 -1
  83. package/lib/dist/extraction/parse-pool.d.ts +15 -0
  84. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  85. package/lib/dist/extraction/parse-pool.js +35 -1
  86. package/lib/dist/extraction/parse-pool.js.map +1 -1
  87. package/lib/dist/extraction/parse-worker.js +35 -1
  88. package/lib/dist/extraction/parse-worker.js.map +1 -1
  89. package/lib/dist/extraction/store-worker.d.ts +24 -0
  90. package/lib/dist/extraction/store-worker.d.ts.map +1 -0
  91. package/lib/dist/extraction/store-worker.js +139 -0
  92. package/lib/dist/extraction/store-worker.js.map +1 -0
  93. package/lib/dist/extraction/store-writer.d.ts +63 -0
  94. package/lib/dist/extraction/store-writer.d.ts.map +1 -0
  95. package/lib/dist/extraction/store-writer.js +174 -0
  96. package/lib/dist/extraction/store-writer.js.map +1 -0
  97. package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
  98. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  99. package/lib/dist/extraction/tree-sitter.d.ts +27 -5
  100. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  101. package/lib/dist/extraction/tree-sitter.js +257 -56
  102. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  103. package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  104. package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  105. package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  106. package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  107. package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  108. package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  109. package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  110. package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  111. package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  112. package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  113. package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  114. package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  115. package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  116. package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  117. package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
  118. package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  119. package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
  120. package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
  121. package/lib/dist/graph/queries.d.ts.map +1 -1
  122. package/lib/dist/graph/queries.js +2 -0
  123. package/lib/dist/graph/queries.js.map +1 -1
  124. package/lib/dist/graph/traversal.js +1 -1
  125. package/lib/dist/graph/traversal.js.map +1 -1
  126. package/lib/dist/index.d.ts +36 -2
  127. package/lib/dist/index.d.ts.map +1 -1
  128. package/lib/dist/index.js +305 -11
  129. package/lib/dist/index.js.map +1 -1
  130. package/lib/dist/installer/beta-signup.d.ts +54 -0
  131. package/lib/dist/installer/beta-signup.d.ts.map +1 -0
  132. package/lib/dist/installer/beta-signup.js +178 -0
  133. package/lib/dist/installer/beta-signup.js.map +1 -0
  134. package/lib/dist/installer/index.d.ts +4 -3
  135. package/lib/dist/installer/index.d.ts.map +1 -1
  136. package/lib/dist/installer/index.js +19 -6
  137. package/lib/dist/installer/index.js.map +1 -1
  138. package/lib/dist/installer/targets/claude.d.ts.map +1 -1
  139. package/lib/dist/installer/targets/claude.js +37 -5
  140. package/lib/dist/installer/targets/claude.js.map +1 -1
  141. package/lib/dist/installer/targets/codex.d.ts +22 -8
  142. package/lib/dist/installer/targets/codex.d.ts.map +1 -1
  143. package/lib/dist/installer/targets/codex.js +65 -48
  144. package/lib/dist/installer/targets/codex.js.map +1 -1
  145. package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
  146. package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
  147. package/lib/dist/installer/targets/copilot-cli.js +209 -0
  148. package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
  149. package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
  150. package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
  151. package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
  152. package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
  153. package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
  154. package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
  155. package/lib/dist/installer/targets/copilot-vscode.js +219 -0
  156. package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
  157. package/lib/dist/installer/targets/registry.d.ts.map +1 -1
  158. package/lib/dist/installer/targets/registry.js +6 -0
  159. package/lib/dist/installer/targets/registry.js.map +1 -1
  160. package/lib/dist/installer/targets/toml.d.ts +6 -5
  161. package/lib/dist/installer/targets/toml.d.ts.map +1 -1
  162. package/lib/dist/installer/targets/toml.js +99 -20
  163. package/lib/dist/installer/targets/toml.js.map +1 -1
  164. package/lib/dist/installer/targets/types.d.ts +5 -5
  165. package/lib/dist/installer/targets/types.d.ts.map +1 -1
  166. package/lib/dist/mcp/daemon-manager.d.ts +1 -1
  167. package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
  168. package/lib/dist/mcp/daemon-manager.js +1 -1
  169. package/lib/dist/mcp/daemon-manager.js.map +1 -1
  170. package/lib/dist/mcp/daemon-paths.d.ts +6 -0
  171. package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
  172. package/lib/dist/mcp/daemon-paths.js +54 -0
  173. package/lib/dist/mcp/daemon-paths.js.map +1 -1
  174. package/lib/dist/mcp/daemon-registry.d.ts +10 -0
  175. package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
  176. package/lib/dist/mcp/daemon-registry.js +51 -3
  177. package/lib/dist/mcp/daemon-registry.js.map +1 -1
  178. package/lib/dist/mcp/daemon.d.ts +9 -6
  179. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  180. package/lib/dist/mcp/daemon.js +10 -8
  181. package/lib/dist/mcp/daemon.js.map +1 -1
  182. package/lib/dist/mcp/engine.d.ts +3 -0
  183. package/lib/dist/mcp/engine.d.ts.map +1 -1
  184. package/lib/dist/mcp/engine.js +45 -3
  185. package/lib/dist/mcp/engine.js.map +1 -1
  186. package/lib/dist/mcp/explore-dedup.d.ts +137 -0
  187. package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
  188. package/lib/dist/mcp/explore-dedup.js +236 -0
  189. package/lib/dist/mcp/explore-dedup.js.map +1 -0
  190. package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
  191. package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
  192. package/lib/dist/mcp/explore-diagnostics.js +558 -0
  193. package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
  194. package/lib/dist/mcp/explore-session-state.d.ts +217 -0
  195. package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
  196. package/lib/dist/mcp/explore-session-state.js +322 -0
  197. package/lib/dist/mcp/explore-session-state.js.map +1 -0
  198. package/lib/dist/mcp/index.d.ts +24 -0
  199. package/lib/dist/mcp/index.d.ts.map +1 -1
  200. package/lib/dist/mcp/index.js +67 -6
  201. package/lib/dist/mcp/index.js.map +1 -1
  202. package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  203. package/lib/dist/mcp/liveness-watchdog.js +3 -1
  204. package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
  205. package/lib/dist/mcp/proxy.d.ts.map +1 -1
  206. package/lib/dist/mcp/proxy.js +6 -1
  207. package/lib/dist/mcp/proxy.js.map +1 -1
  208. package/lib/dist/mcp/server-instructions.d.ts +2 -2
  209. package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
  210. package/lib/dist/mcp/server-instructions.js +8 -3
  211. package/lib/dist/mcp/server-instructions.js.map +1 -1
  212. package/lib/dist/mcp/session.d.ts +16 -0
  213. package/lib/dist/mcp/session.d.ts.map +1 -1
  214. package/lib/dist/mcp/session.js +36 -13
  215. package/lib/dist/mcp/session.js.map +1 -1
  216. package/lib/dist/mcp/tools.d.ts +276 -10
  217. package/lib/dist/mcp/tools.d.ts.map +1 -1
  218. package/lib/dist/mcp/tools.js +2425 -237
  219. package/lib/dist/mcp/tools.js.map +1 -1
  220. package/lib/dist/project-config.d.ts +23 -0
  221. package/lib/dist/project-config.d.ts.map +1 -1
  222. package/lib/dist/project-config.js +39 -2
  223. package/lib/dist/project-config.js.map +1 -1
  224. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
  225. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  226. package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
  227. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  228. package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
  229. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  230. package/lib/dist/resolution/callback-synthesizer.js +287 -167
  231. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  232. package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
  233. package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
  234. package/lib/dist/resolution/cooperative-yield.js +6 -4
  235. package/lib/dist/resolution/cooperative-yield.js.map +1 -1
  236. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
  237. package/lib/dist/resolution/frameworks/go.js +29 -6
  238. package/lib/dist/resolution/frameworks/go.js.map +1 -1
  239. package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
  240. package/lib/dist/resolution/frameworks/swift.js +11 -1
  241. package/lib/dist/resolution/frameworks/swift.js.map +1 -1
  242. package/lib/dist/resolution/import-resolver.d.ts +2 -3
  243. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  244. package/lib/dist/resolution/import-resolver.js +184 -9
  245. package/lib/dist/resolution/import-resolver.js.map +1 -1
  246. package/lib/dist/resolution/index.d.ts +87 -2
  247. package/lib/dist/resolution/index.d.ts.map +1 -1
  248. package/lib/dist/resolution/index.js +731 -134
  249. package/lib/dist/resolution/index.js.map +1 -1
  250. package/lib/dist/resolution/memory-budget.d.ts +48 -0
  251. package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
  252. package/lib/dist/resolution/memory-budget.js +162 -0
  253. package/lib/dist/resolution/memory-budget.js.map +1 -0
  254. package/lib/dist/resolution/name-matcher.d.ts +42 -1
  255. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  256. package/lib/dist/resolution/name-matcher.js +681 -99
  257. package/lib/dist/resolution/name-matcher.js.map +1 -1
  258. package/lib/dist/resolution/path-aliases.d.ts +6 -4
  259. package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
  260. package/lib/dist/resolution/path-aliases.js +125 -17
  261. package/lib/dist/resolution/path-aliases.js.map +1 -1
  262. package/lib/dist/resolution/resolver-pool.d.ts +106 -0
  263. package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
  264. package/lib/dist/resolution/resolver-pool.js +344 -0
  265. package/lib/dist/resolution/resolver-pool.js.map +1 -0
  266. package/lib/dist/resolution/resolver-worker.d.ts +17 -0
  267. package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
  268. package/lib/dist/resolution/resolver-worker.js +141 -0
  269. package/lib/dist/resolution/resolver-worker.js.map +1 -0
  270. package/lib/dist/resolution/types.d.ts +3 -0
  271. package/lib/dist/resolution/types.d.ts.map +1 -1
  272. package/lib/dist/search/identifier-segments.d.ts +10 -0
  273. package/lib/dist/search/identifier-segments.d.ts.map +1 -1
  274. package/lib/dist/search/identifier-segments.js +29 -0
  275. package/lib/dist/search/identifier-segments.js.map +1 -1
  276. package/lib/dist/search/query-paths.d.ts +57 -0
  277. package/lib/dist/search/query-paths.d.ts.map +1 -0
  278. package/lib/dist/search/query-paths.js +298 -0
  279. package/lib/dist/search/query-paths.js.map +1 -0
  280. package/lib/dist/search/query-utils.d.ts +1 -1
  281. package/lib/dist/search/query-utils.d.ts.map +1 -1
  282. package/lib/dist/search/query-utils.js +13 -3
  283. package/lib/dist/search/query-utils.js.map +1 -1
  284. package/lib/dist/sync/watcher.d.ts +47 -1
  285. package/lib/dist/sync/watcher.d.ts.map +1 -1
  286. package/lib/dist/sync/watcher.js +127 -8
  287. package/lib/dist/sync/watcher.js.map +1 -1
  288. package/lib/dist/types.d.ts +61 -3
  289. package/lib/dist/types.d.ts.map +1 -1
  290. package/lib/dist/types.js +27 -1
  291. package/lib/dist/types.js.map +1 -1
  292. package/lib/dist/ui/color.d.ts +21 -0
  293. package/lib/dist/ui/color.d.ts.map +1 -0
  294. package/lib/dist/ui/color.js +42 -0
  295. package/lib/dist/ui/color.js.map +1 -0
  296. package/lib/dist/ui/glyphs.d.ts +35 -10
  297. package/lib/dist/ui/glyphs.d.ts.map +1 -1
  298. package/lib/dist/ui/glyphs.js +59 -12
  299. package/lib/dist/ui/glyphs.js.map +1 -1
  300. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
  301. package/lib/dist/ui/shimmer-progress.js +78 -4
  302. package/lib/dist/ui/shimmer-progress.js.map +1 -1
  303. package/lib/dist/ui/shimmer-worker.js +25 -17
  304. package/lib/dist/ui/shimmer-worker.js.map +1 -1
  305. package/lib/dist/ui/types.d.ts +0 -2
  306. package/lib/dist/ui/types.d.ts.map +1 -1
  307. package/lib/dist/upgrade/index.d.ts +7 -0
  308. package/lib/dist/upgrade/index.d.ts.map +1 -1
  309. package/lib/dist/upgrade/index.js +18 -5
  310. package/lib/dist/upgrade/index.js.map +1 -1
  311. package/lib/kernel/codegraph-kernel.node +0 -0
  312. package/lib/node_modules/.package-lock.json +1 -1
  313. package/lib/package.json +6 -1
  314. package/package.json +6 -2
@@ -8,9 +8,23 @@ exports.blankCppInlineMacros = blankCppInlineMacros;
8
8
  exports.recoverMangledCppName = recoverMangledCppName;
9
9
  exports.blankMetalAttributes = blankMetalAttributes;
10
10
  exports.blankCppAnnotationMacroCalls = blankCppAnnotationMacroCalls;
11
+ exports.blankLoneMacroLines = blankLoneMacroLines;
11
12
  exports.blankCppApiPrefixMacros = blankCppApiPrefixMacros;
12
13
  exports.blankCppInlineAnnotationMacros = blankCppInlineAnnotationMacros;
13
14
  exports.blankCudaConstructs = blankCudaConstructs;
15
+ exports.blankCLeadingAttrMacros = blankCLeadingAttrMacros;
16
+ exports.blankCCplusplusGuardBodies = blankCCplusplusGuardBodies;
17
+ exports.blankCStatementMacroCalls = blankCStatementMacroCalls;
18
+ exports.blankCSandwichedAnnotations = blankCSandwichedAnnotations;
19
+ exports.blankCAutoInference = blankCAutoInference;
20
+ exports.blankCTrailingParamAttrMacros = blankCTrailingParamAttrMacros;
21
+ exports.blankCKernelAnnotations = blankCKernelAnnotations;
22
+ exports.blankCParameterizedAnnotationMacros = blankCParameterizedAnnotationMacros;
23
+ exports.blankCTypeKeywordArgs = blankCTypeKeywordArgs;
24
+ exports.blankCFileScopePrefixedDeclMacros = blankCFileScopePrefixedDeclMacros;
25
+ exports.rewriteCPrefixedDeclMacroInitializers = rewriteCPrefixedDeclMacroInitializers;
26
+ exports.blankCVaArgQualifiedTypeArgs = blankCVaArgQualifiedTypeArgs;
27
+ exports.blankCNamedVariadicDefineDots = blankCNamedVariadicDefineDots;
14
28
  const tree_sitter_helpers_1 = require("../tree-sitter-helpers");
15
29
  /**
16
30
  * Find the function NAME's `qualified_identifier` (`Foo::bar`) inside a
@@ -108,7 +122,16 @@ function extractCppReceiverType(node, source) {
108
122
  if (!qid)
109
123
  return undefined;
110
124
  const parts = (0, tree_sitter_helpers_1.getNodeText)(qid, source).trim().split('::').filter(Boolean);
111
- return parts.length > 1 ? parts.slice(0, -1).join('::') : undefined;
125
+ if (parts.length <= 1)
126
+ return undefined;
127
+ // An out-of-line template method definition carries the class's template
128
+ // parameter list in the qualifier (`template<typename T> T Box<T>::get()`),
129
+ // but the class node is indexed as bare `Box` — strip `<…>` so the receiver
130
+ // matches it, the same normalization #1043 applies to base-class refs.
131
+ // Multi-line parameter lists otherwise leak whole `<…>` blocks (newlines
132
+ // included) into qualified_name, which can exceed NAME_MAX (#1286).
133
+ const receiver = stripCppTemplateArgs(parts.slice(0, -1).join('::'));
134
+ return receiver || undefined;
112
135
  }
113
136
  /**
114
137
  * Built-in / non-class return types that can never be a method receiver. We
@@ -206,6 +229,9 @@ exports.cExtractor = {
206
229
  methodTypes: [],
207
230
  interfaceTypes: [],
208
231
  structTypes: ['struct_specifier'],
232
+ // A bodiless `union U;` is a forward declaration; the aggregate extractor
233
+ // applies the same body requirement it uses for C structs.
234
+ unionTypes: ['union_specifier'],
209
235
  enumTypes: ['enum_specifier'],
210
236
  enumMemberTypes: ['enumerator'],
211
237
  typeAliasTypes: ['type_definition'], // typedef
@@ -223,15 +249,20 @@ exports.cExtractor = {
223
249
  resolveTypeAliasKind: (node, _source) => {
224
250
  // C typedef: `typedef enum { ... } name;` or `typedef struct { ... } name;`
225
251
  // The inner enum_specifier/struct_specifier is anonymous, but we want the typedef name
226
- // to become the enum/struct node name.
252
+ // to become the enum/struct node name. `typedef union { ... } name;` takes the
253
+ // same route — otherwise the union body would mint a second, `<anonymous>` node
254
+ // beside the alias.
227
255
  for (let i = 0; i < node.namedChildCount; i++) {
228
256
  const child = node.namedChild(i);
229
257
  if (!child)
230
258
  continue;
231
259
  if (child.type === 'enum_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
232
260
  return 'enum';
233
- if (child.type === 'struct_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
261
+ if (child.type === 'struct_specifier' &&
262
+ (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
234
263
  return 'struct';
264
+ if (child.type === 'union_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
265
+ return 'union';
235
266
  }
236
267
  return undefined;
237
268
  },
@@ -544,6 +575,69 @@ function blankCppAnnotationMacroCalls(source) {
544
575
  }
545
576
  return chars.join('');
546
577
  }
578
+ /**
579
+ * Blank a macro that is the ONLY token on its line — no parens, no semicolon:
580
+ * namespace-management macros (`FMT_BEGIN_NAMESPACE`, `FMT_END_EXPORT`,
581
+ * `JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS`), Qt's `Q_OBJECT`, and friends. A
582
+ * bare identifier is not a statement or declaration in C or C++, so
583
+ * tree-sitter drops into error recovery at every one — and since the kernel
584
+ * path defers ANY erroring file to wasm, this single idiom deferred 13/73 fmt
585
+ * files and a comparable share of jemalloc, forfeiting the native-parse win
586
+ * on exactly the header-heavy trees it targets (the wasm path also mis-nests
587
+ * scopes around them today). Replacing the token with equal-length spaces
588
+ * preserves every byte offset and the surrounding declarations parse clean.
589
+ *
590
+ * Matched tightly so a real identifier can never be touched — ALL of:
591
+ * - the line consists of ONE ALL-CAPS token (≥4 chars, with `_`), optionally
592
+ * followed by a same-line comment — a lone lowercase identifier or any
593
+ * second token disqualifies;
594
+ * - the PREVIOUS non-blank line does not end in a continuation character
595
+ * (`=`, an operator, `,`, `(`, `?`, `:`, or a `\` macro-definition
596
+ * continuation) — so an ALL-CAPS operand split onto its own line inside a
597
+ * multi-line expression (`int x =\n SOME_CONST\n | OTHER;`) is left
598
+ * alone; and
599
+ * - the NEXT non-blank line starts like a declaration/scope token
600
+ * (letter, `_`, `#`, `{`, `}`, or `~`) or the file ends — an operator,
601
+ * string literal, or `;` continuation rejects the match.
602
+ * Shared by C and C++ (the idiom is identical in both).
603
+ */
604
+ const LONE_MACRO_LINE_RE = /^[ \t]*([A-Z][A-Z0-9_]{3,})[ \t]*(?:\/\/[^\n\r]*|\/\*[^\n\r]*\*\/[ \t]*)?\r?$/;
605
+ const LONE_MACRO_CONTINUATION_END_RE = /[=+\-*/%&|^<>?:,(\\]$/;
606
+ function blankLoneMacroLines(source) {
607
+ if (!/^[ \t]*[A-Z][A-Z0-9_]{3,}[ \t]*\r?$/m.test(source))
608
+ return source;
609
+ const lines = source.split('\n');
610
+ const content = (l) => l.replace(/\r$/, '').trim();
611
+ let changed = false;
612
+ for (let i = 0; i < lines.length; i++) {
613
+ const line = lines[i];
614
+ const m = LONE_MACRO_LINE_RE.exec(line);
615
+ if (!m)
616
+ continue;
617
+ // Underscore requirement rides the macro convention (FMT_BEGIN_NAMESPACE,
618
+ // Q_OBJECT); a solid all-caps word (`NDEBUG`-style) alone is too risky.
619
+ if (!m[1].includes('_'))
620
+ continue;
621
+ let prev = i - 1;
622
+ while (prev >= 0 && content(lines[prev]) === '')
623
+ prev--;
624
+ if (prev >= 0 && LONE_MACRO_CONTINUATION_END_RE.test(content(lines[prev])))
625
+ continue;
626
+ let next = i + 1;
627
+ while (next < lines.length && content(lines[next]) === '')
628
+ next++;
629
+ if (next < lines.length) {
630
+ const first = content(lines[next])[0];
631
+ if (!first || !/[A-Za-z_#{}~]/.test(first))
632
+ continue;
633
+ }
634
+ const start = line.indexOf(m[1]);
635
+ lines[i] =
636
+ line.slice(0, start) + ' '.repeat(m[1].length) + line.slice(start + m[1].length);
637
+ changed = true;
638
+ }
639
+ return changed ? lines.join('\n') : source;
640
+ }
547
641
  /**
548
642
  * Blank an export/visibility macro sitting in front of a *member* or *method*
549
643
  * declaration inside a class/namespace (`ENGINE_API virtual void Tick(…)`,
@@ -717,27 +811,778 @@ function looksLikeCudaSource(source) {
717
811
  source.indexOf('__constant__') !== -1 ||
718
812
  source.indexOf('cudaStream_t') !== -1);
719
813
  }
814
+ /**
815
+ * Restore preprocessor-directive lines to their original bytes after the
816
+ * blanking passes ran. The token-level blanks match on shape, not context, so
817
+ * a macro name that happens to sit inside a DIRECTIVE gets blanked too — and
818
+ * blanking the name position of `#define FMT_API FMT_VISIBILITY("default")`
819
+ * leaves a nameless `# define FMT_VISIBILITY(…)`, which is a parse
820
+ * ERROR (fmt's base.h carries several). Inside a directive the blanks were
821
+ * never useful anyway: tree-sitter stores `#define` bodies as raw
822
+ * preproc_arg text it doesn't parse, so blanking there can only ever break
823
+ * the directive itself. Copying the original directive lines back (including
824
+ * `\`-continuation lines of multi-line defines) is offset-preserving by
825
+ * construction and strictly reduces parse errors on both extraction arms.
826
+ */
827
+ function restoreDirectiveLines(original, blanked) {
828
+ if (blanked === original || original.indexOf('#') === -1)
829
+ return blanked;
830
+ const o = original.split('\n');
831
+ const b = blanked.split('\n');
832
+ let changed = false;
833
+ let continuation = false;
834
+ for (let i = 0; i < o.length && i < b.length; i++) {
835
+ const line = o[i];
836
+ const isDirective = continuation || /^[ \t]*#/.test(line);
837
+ if (isDirective && b[i] !== line) {
838
+ b[i] = line;
839
+ changed = true;
840
+ }
841
+ continuation = isDirective && /\\\s*$/.test(line.replace(/\r$/, ''));
842
+ }
843
+ return changed ? b.join('\n') : blanked;
844
+ }
720
845
  /** C/C++ source pre-processing before tree-sitter: recover macro-annotated class
721
846
  * definitions, macro-prefixed function definitions, macro-prefixed members, and
722
847
  * macro-decorated members (Unreal-Engine reflection markup) — plus the non-C++
723
848
  * surface of the dialects parsed with the C++ grammar: `.metal` MSL attribute
724
849
  * annotations, and CUDA specifiers + launch syntax (by `.cu`/`.cuh` extension
725
- * or by content, for CUDA living in `.h`/`.hpp` headers). Offset-preserving. */
850
+ * or by content, for CUDA living in `.h`/`.hpp` headers). Offset-preserving;
851
+ * directive lines are restored at the end (see restoreDirectiveLines). */
726
852
  function preParseCppSource(source, filePath) {
727
- const blanked = blankCppAnnotationMacroCalls(blankCppInlineAnnotationMacros(blankCppApiPrefixMacros(blankCppInlineMacros(blankCppExportMacros(source)))));
853
+ // blankCLeadingAttrMacros runs AFTER the api-prefix blank so a stacked
854
+ // `FMT_NORETURN FMT_API void f(…)` reduces to the `MACRO Ret name(` shape
855
+ // it matches (the _API token is already spaces by then).
856
+ let blanked = blankLoneMacroLines(blankCLeadingAttrMacros(blankCppAnnotationMacroCalls(blankCppInlineAnnotationMacros(blankCppApiPrefixMacros(blankCppInlineMacros(blankCppExportMacros(source)))))));
728
857
  const lower = filePath ? filePath.toLowerCase() : '';
729
- if (lower.endsWith('.metal'))
730
- return blankMetalAttributes(blanked);
731
- if (lower.endsWith('.cu') || lower.endsWith('.cuh') || looksLikeCudaSource(source)) {
732
- return blankCudaConstructs(blanked);
858
+ if (lower.endsWith('.metal')) {
859
+ blanked = blankMetalAttributes(blanked);
860
+ }
861
+ else if (lower.endsWith('.cu') || lower.endsWith('.cuh') || looksLikeCudaSource(source)) {
862
+ blanked = blankCudaConstructs(blanked);
863
+ }
864
+ return restoreDirectiveLines(source, blanked);
865
+ }
866
+ /**
867
+ * Blank an unknown attribute macro sitting in front of a C function
868
+ * definition's return type: `SEC_ATTR UINT32 LostName(VOID) { … }` (macro
869
+ * wrapping `__attribute__((…))`, common in embedded/kernel C). tree-sitter's
870
+ * C grammar reads the macro as the declaration's type, the real return type
871
+ * as the declarator, and stores the PARAMETER LIST as the function name —
872
+ * `LostName` indexes as `"(VOID)"` and is unfindable (#1211). The C++ grammar
873
+ * recovers this shape differently (glued name, salvaged post-hoc by
874
+ * `recoverMangledCppName`), but in C the real name never reaches the mangled
875
+ * string, so only a pre-parse blank can recover it.
876
+ *
877
+ * Attribute macros are project-specific (`SEC_ATTR`, `INIT_TEXT`, …), so this
878
+ * keys on structure, not a curated list, matched tightly:
879
+ * - line-leading (`^[ \t]*`) — declaration position, never an expression use;
880
+ * - ALL-CAPS token of ≥3 chars (`[A-Z][A-Z0-9_]{2,}`) — ordinary C types in
881
+ * definitions are rarely spelled this way, and when they are (`UINT32 f()`)
882
+ * they're followed by ONE identifier + `(`, which the lookahead rejects;
883
+ * - followed by TWO identifier tokens (return type, then name — `*` allowed
884
+ * for pointer returns) and then `(` — i.e. exactly the
885
+ * `MACRO Ret name(` definition shape. `MACRO name(` calls, `#define`
886
+ * lines (start with `#`), and multi-word builtin returns
887
+ * (`MACRO unsigned int f(` — where the C grammar already keeps the name)
888
+ * are all left untouched.
889
+ * Equal-length spaces preserve every byte offset, like the C++ blanks above.
890
+ */
891
+ const C_LEADING_ATTR_MACRO_RE = /^([ \t]*)([A-Z][A-Z0-9_]{2,})(?=\s+[A-Za-z_]\w*[\s*]+[A-Za-z_]\w*\s*\()/gm;
892
+ function blankCLeadingAttrMacros(source) {
893
+ return source.replace(C_LEADING_ATTR_MACRO_RE, (_m, ws, macro) => ws + ' '.repeat(macro.length));
894
+ }
895
+ /**
896
+ * Blank the body of `#ifdef __cplusplus … #endif` guard regions in C sources.
897
+ * The ubiquitous C-header compatibility idiom
898
+ *
899
+ * #ifdef __cplusplus
900
+ * extern "C" {
901
+ * #endif
902
+ *
903
+ * is NOT valid C — `extern "C" {` (and any other C++-only line under the
904
+ * guard) drops tree-sitter-c into error recovery, so effectively every public
905
+ * C header carries parse errors. The wasm path shrugs (recovery keeps the
906
+ * rest); the kernel path defers EVERY erroring file to wasm by policy — so
907
+ * this one idiom pushed C-header deferral to ~32% on redis (vs the <10%
908
+ * gate) and forfeited the native-parse win exactly where C repos have the
909
+ * most files. A C compiler never sees the guarded lines (`__cplusplus` is
910
+ * only defined for C++), so blanking the region BODY mirrors the
911
+ * preprocessor's own view of the file.
912
+ *
913
+ * Matched conservatively, line-based and offset-preserving:
914
+ * - the opener must be `#ifdef __cplusplus` / `#if defined(__cplusplus)`;
915
+ * - the body may contain NO other preprocessor directive (a nested `#if`,
916
+ * `#else`, or `#define` bails the whole region — those need real
917
+ * preprocessing, so the file keeps its current behavior);
918
+ * - the region must close with `#endif` within a few lines (guards are
919
+ * tiny; a giant region is something else).
920
+ * The `#ifdef`/`#endif` directive lines themselves are kept — an empty
921
+ * preproc_ifdef parses clean — and every blanked byte becomes a space with
922
+ * `\r` preserved, so offsets, lines, and columns survive on CRLF checkouts.
923
+ */
924
+ const C_CPLUSPLUS_GUARD_OPEN_RE = /^[ \t]*#[ \t]*(?:ifdef[ \t]+__cplusplus\b|if[ \t]+defined[ \t]*\(?[ \t]*__cplusplus[ \t]*\)?)/;
925
+ const C_PREPROC_DIRECTIVE_RE = /^[ \t]*#/;
926
+ const C_PREPROC_ENDIF_RE = /^[ \t]*#[ \t]*endif\b/;
927
+ const C_CPLUSPLUS_GUARD_MAX_BODY_LINES = 40;
928
+ function blankCCplusplusGuardBodies(source) {
929
+ if (source.indexOf('__cplusplus') === -1)
930
+ return source;
931
+ const lines = source.split('\n');
932
+ const stripCr = (l) => (l.endsWith('\r') ? l.slice(0, -1) : l);
933
+ let changed = false;
934
+ for (let i = 0; i < lines.length; i++) {
935
+ if (!C_CPLUSPLUS_GUARD_OPEN_RE.test(stripCr(lines[i])))
936
+ continue;
937
+ let end = -1;
938
+ for (let j = i + 1; j < lines.length && j - i - 1 <= C_CPLUSPLUS_GUARD_MAX_BODY_LINES; j++) {
939
+ const line = stripCr(lines[j]);
940
+ if (C_PREPROC_ENDIF_RE.test(line)) {
941
+ end = j;
942
+ break;
943
+ }
944
+ if (C_PREPROC_DIRECTIVE_RE.test(line))
945
+ break; // nested directive — bail
946
+ }
947
+ if (end < 0)
948
+ continue;
949
+ for (let k = i + 1; k < end; k++) {
950
+ lines[k] = lines[k].replace(/[^\r]/g, ' ');
951
+ }
952
+ changed = true;
953
+ i = end;
954
+ }
955
+ return changed ? lines.join('\n') : source;
956
+ }
957
+ /**
958
+ * Blank a C iterator-macro call in STATEMENT position — `ql_foreach(iter,
959
+ * &arena->tcache_ql, link) { … }` (jemalloc), `for_each_string_list_item(item,
960
+ * &list) { … }` (git), `list_for_each_entry(pos, head, member) { … }` (the
961
+ * Linux kernel's core iteration idiom). A call followed by a brace block is
962
+ * not a C statement, so tree-sitter-c drops into error recovery at every use —
963
+ * these macros are the single largest source of parse errors in macro-heavy C
964
+ * trees (git: ~39% of files error; the kernel path defers each one to wasm).
965
+ * Blanking JUST the macro call leaves the brace block as a bare compound
966
+ * statement — valid C — so the body's calls/locals extract normally on both
967
+ * arms instead of riding error recovery.
968
+ *
969
+ * C-ONLY, and matched tightly:
970
+ * - the call must be INDENTED (statement position; file-scope definitions
971
+ * start at column 0, and an unbraced file-scope `name(args) { }` is a
972
+ * valid implicit-int function definition that must not be touched);
973
+ * - lowercase-led identifier (iterator macros are lowercase by convention;
974
+ * this also excludes constructors if the file is really C++) that is not a
975
+ * control keyword;
976
+ * - the parens balance ON the line (string literals skipped), and after
977
+ * them only `{` or end-of-line may follow — a `;` (a real call statement),
978
+ * an operator, or any other token disqualifies;
979
+ * - when the line ends at `)`, the NEXT non-blank line must begin with `{`.
980
+ * C++ deliberately does NOT get this pass: an indented snake_case
981
+ * constructor (`basic_string_view(const Char* s) : … {`) is exactly this
982
+ * shape, and blanking it would corrupt every STL-style class.
983
+ */
984
+ const C_STMT_MACRO_KEYWORDS = new Set([
985
+ 'if', 'while', 'for', 'switch', 'return', 'do', 'else', 'sizeof',
986
+ ]);
987
+ function blankCStatementMacroCalls(source) {
988
+ const lines = source.split('\n');
989
+ let changed = false;
990
+ const content = (l) => l.replace(/\r$/, '').trim();
991
+ for (let i = 0; i < lines.length; i++) {
992
+ const line = lines[i];
993
+ const m = /^[ \t]+([a-z_][a-z0-9_]*)[ \t]*\(/.exec(line);
994
+ if (!m || C_STMT_MACRO_KEYWORDS.has(m[1]))
995
+ continue;
996
+ const open = line.indexOf('(', m[0].length - 1);
997
+ let depth = 0;
998
+ let close = -1;
999
+ for (let k = open; k < line.length; k++) {
1000
+ const ch = line[k];
1001
+ if (ch === '"' || ch === "'") {
1002
+ const quote = ch;
1003
+ k++;
1004
+ while (k < line.length && line[k] !== quote) {
1005
+ if (line[k] === '\\')
1006
+ k++;
1007
+ k++;
1008
+ }
1009
+ continue;
1010
+ }
1011
+ if (ch === '(')
1012
+ depth++;
1013
+ else if (ch === ')') {
1014
+ depth--;
1015
+ if (depth === 0) {
1016
+ close = k;
1017
+ break;
1018
+ }
1019
+ }
1020
+ }
1021
+ let endLine = i;
1022
+ if (close < 0) {
1023
+ // Parens don't balance on the head line — the kernel wraps iterator
1024
+ // macros (`hlist_for_each_entry_rcu(p, head, hlist,\n\t\t
1025
+ // lockdep_is_held(&kprobe_mutex)) {`). Continue the same
1026
+ // string-skipping paren scan over a few continuation lines. A `;` or
1027
+ // a brace anywhere in the span means a real statement or compound
1028
+ // literal — bail (missing a blank is safe; corrupting one is not).
1029
+ if (line.indexOf(';') !== -1)
1030
+ continue;
1031
+ for (let j = i + 1; j <= i + 5 && j < lines.length && close < 0; j++) {
1032
+ const cont = lines[j];
1033
+ let bail = false;
1034
+ for (let k = 0; k < cont.length; k++) {
1035
+ const ch = cont[k];
1036
+ if (ch === '"' || ch === "'") {
1037
+ const quote = ch;
1038
+ k++;
1039
+ while (k < cont.length && cont[k] !== quote) {
1040
+ if (cont[k] === '\\')
1041
+ k++;
1042
+ k++;
1043
+ }
1044
+ continue;
1045
+ }
1046
+ if (ch === ';' || ch === '{' || ch === '}') {
1047
+ bail = true;
1048
+ break;
1049
+ }
1050
+ if (ch === '(')
1051
+ depth++;
1052
+ else if (ch === ')') {
1053
+ depth--;
1054
+ if (depth === 0) {
1055
+ close = k;
1056
+ endLine = j;
1057
+ break;
1058
+ }
1059
+ }
1060
+ }
1061
+ if (bail)
1062
+ break;
1063
+ }
1064
+ if (close < 0)
1065
+ continue;
1066
+ }
1067
+ const endLineStr = lines[endLine];
1068
+ const after = endLineStr.slice(close + 1).replace(/\r$/, '').trim();
1069
+ if (after === '') {
1070
+ // Brace on the next line (`ql_foreach(…)\n{`) or a brace-less
1071
+ // single-statement body (`for_each_subsys(ss, i)\n\tstmt;` — blanking
1072
+ // leaves the bare statement, valid C). A next line starting with an
1073
+ // operator/string/`;` is an expression continuation — bail.
1074
+ let next = endLine + 1;
1075
+ while (next < lines.length && content(lines[next]) === '')
1076
+ next++;
1077
+ if (next >= lines.length)
1078
+ continue;
1079
+ const first = content(lines[next])[0];
1080
+ if (!first || !/[A-Za-z_{]/.test(first))
1081
+ continue;
1082
+ }
1083
+ else if (after !== '{') {
1084
+ continue;
1085
+ }
1086
+ const identStart = line.indexOf(m[1]);
1087
+ if (endLine === i) {
1088
+ lines[i] =
1089
+ line.slice(0, identStart) +
1090
+ ' '.repeat(close + 1 - identStart) +
1091
+ line.slice(close + 1);
1092
+ }
1093
+ else {
1094
+ lines[i] = line.slice(0, identStart) + line.slice(identStart).replace(/[^\r]/g, ' ');
1095
+ for (let j = i + 1; j < endLine; j++) {
1096
+ lines[j] = lines[j].replace(/[^\r]/g, ' ');
1097
+ }
1098
+ lines[endLine] =
1099
+ endLineStr.slice(0, close + 1).replace(/[^\r]/g, ' ') + endLineStr.slice(close + 1);
1100
+ i = endLine; // the blanked span can't host another head
1101
+ }
1102
+ changed = true;
1103
+ }
1104
+ return changed ? lines.join('\n') : source;
1105
+ }
1106
+ /**
1107
+ * Blank a lowercase compiler-annotation word SANDWICHED between a storage
1108
+ * class and the rest of a declaration — `static notrace void tick(…)`,
1109
+ * `static nokprobe_inline void arm(…)` (kernel compiler.h markers). The
1110
+ * dunder word-list can't carry these bare-word forms: `notrace` is a
1111
+ * plausible identifier. The sandwich IS the guard — the token counts only
1112
+ * when directly preceded by `static`/`extern`/`inline` AND followed by
1113
+ * another word, a position where it cannot be a variable name (an archaic
1114
+ * implicit-int `static notrace = 1;` fails the following-word requirement).
1115
+ * C-only.
1116
+ */
1117
+ const C_SANDWICHED_ANNOTATIONS = [
1118
+ 'noinline_for_stack', 'nokprobe_inline', 'noinline', 'notrace', 'noinstr',
1119
+ ];
1120
+ const C_SANDWICH_RE = new RegExp(`\\b(static|extern|inline)([ \\t]+)(${C_SANDWICHED_ANNOTATIONS.join('|')})\\b(?=[ \\t]+[A-Za-z_])`, 'g');
1121
+ function blankCSandwichedAnnotations(source) {
1122
+ C_SANDWICH_RE.lastIndex = 0;
1123
+ if (!C_SANDWICH_RE.test(source))
1124
+ return source;
1125
+ C_SANDWICH_RE.lastIndex = 0;
1126
+ return source.replace(C_SANDWICH_RE, (_m, storage, ws, ann) => storage + ws + ' '.repeat(ann.length));
1127
+ }
1128
+ /**
1129
+ * Blank a C23 `auto` type-inference keyword — `auto hb = hbr.hb;` (the
1130
+ * futex code; tree-sitter-c predates C23 auto and errors the enclosing
1131
+ * function). The old storage-class reading (`auto int x = 1;`) has a TYPE
1132
+ * between `auto` and the `=` and is untouched — the match requires
1133
+ * `auto IDENT =` directly, which only the C23 form exhibits. Blanking
1134
+ * leaves a plain assignment statement. C-only.
1135
+ */
1136
+ const C_AUTO_INFER_RE = /\bauto(?=[ \t]+[A-Za-z_]\w*[ \t]*=)/g;
1137
+ function blankCAutoInference(source) {
1138
+ C_AUTO_INFER_RE.lastIndex = 0;
1139
+ if (!C_AUTO_INFER_RE.test(source))
1140
+ return source;
1141
+ C_AUTO_INFER_RE.lastIndex = 0;
1142
+ return source.replace(C_AUTO_INFER_RE, () => ' ');
1143
+ }
1144
+ /**
1145
+ * Blank a trailing parameter-attribute macro — `int argc UNUSED,` /
1146
+ * `struct repository *repo UNUSED)` — git's house style for
1147
+ * `__attribute__((unused))` on nearly every callback parameter (and the same
1148
+ * shape as `MAYBE_UNUSED`/`G_GNUC_UNUSED` elsewhere). tree-sitter-c can't
1149
+ * parse a second identifier after the parameter name, so every such
1150
+ * SIGNATURE drops into error recovery — the single largest deferral bucket
1151
+ * on git (~150 files). Blanking the macro leaves an ordinary parameter.
1152
+ *
1153
+ * Matched tightly: an identifier, whitespace, then an ALL-CAPS ≥3-char token
1154
+ * immediately before `,` or `)`. Two juxtaposed identifiers in that position
1155
+ * have no other valid-C reading — in a CALL the would-be macro is preceded
1156
+ * by `,`/`(`, an operator, or a literal, never by a bare identifier. C-only:
1157
+ * C++ grammars accept more juxtapositions (user-defined suffixes, macro'd
1158
+ * `final`/`override`), so cpp keeps its existing recovery there.
1159
+ */
1160
+ const C_TRAILING_PARAM_ATTR_RE = /\b([A-Za-z_]\w*)([ \t]+)([A-Z][A-Z0-9_]{2,})(?=[ \t]*[,)])/g;
1161
+ function blankCTrailingParamAttrMacros(source) {
1162
+ if (!C_TRAILING_PARAM_ATTR_RE.test(source)) {
1163
+ C_TRAILING_PARAM_ATTR_RE.lastIndex = 0;
1164
+ return source;
1165
+ }
1166
+ C_TRAILING_PARAM_ATTR_RE.lastIndex = 0;
1167
+ return source.replace(C_TRAILING_PARAM_ATTR_RE, (_m, name, ws, macro) => name + ws + ' '.repeat(macro.length));
1168
+ }
1169
+ /**
1170
+ * Blank the Linux-kernel/sparse declaration-annotation macros — `static int
1171
+ * __init audit_init(void)`, `void __user *buf`, `__bpf_kfunc void f(…)`,
1172
+ * `int x __ro_after_init;`. These lowercase double-underscore annotations sit
1173
+ * between storage/type tokens and the declarator, a position tree-sitter-c
1174
+ * can't reconcile, and they blanket the Linux tree: measured on the kernel's
1175
+ * own `kernel/` + `mm/` subtrees, they are the largest single deferral cause
1176
+ * (the `__init` family alone heads ~37% of erroring files).
1177
+ *
1178
+ * A structural match is IMPOSSIBLE here: `__u32 count` (a real typedef) and
1179
+ * `__init foo` (an annotation) are byte-shape identical — so unlike the
1180
+ * shape-keyed blanks above, this is a CURATED list (the CPP_INLINE_MACROS
1181
+ * precedent) of well-known sparse/section/compiler annotations that are
1182
+ * reserved-namespace macros in every codebase that spells them. Whole-word,
1183
+ * equal-length spaces, C-only (the C++ grammar's kernel exposure is
1184
+ * negligible and cpp keeps its narrower blank set).
1185
+ */
1186
+ const C_KERNEL_ANNOTATIONS = [
1187
+ '__init', '__exit', '__initdata', '__initconst', '__exitdata',
1188
+ '__devinit', '__devexit', '__cpuinit', '__meminit', '__meminitdata',
1189
+ '__net_init', '__net_exit', '__net_initdata', '__init_or_module',
1190
+ '__user', '__kernel', '__iomem', '__percpu', '__rcu', '__force', '__nocast',
1191
+ '__must_check', '__maybe_unused', '__always_unused', '__used', '__cold',
1192
+ '__hot', '__weak', '__pure', '__sched', '__malloc', '__visible',
1193
+ '__deprecated', '__ro_after_init', '__read_mostly', '__refdata',
1194
+ '__latent_entropy', '__randomize_layout', '__no_randomize_layout',
1195
+ '__bpf_kfunc', '__function_aligned', '__always_inline', '__noreturn',
1196
+ // Round-2 additions, each measured heading first-error lines on the
1197
+ // v7.2-rc2 kernel/+mm/ census (2026-07-17): cacheline placement, sparse
1198
+ // lock/section markers, and bpf/typecheck annotations. Real dunder TYPES
1199
+ // (`__u32`, `__s64`) and operators (`__alignof__`) are deliberately absent.
1200
+ '__cacheline_aligned_in_smp', '__cacheline_aligned',
1201
+ '__cacheline_internodealigned_in_smp', '____cacheline_aligned_in_smp',
1202
+ '____cacheline_aligned', '____cacheline_internodealigned_in_smp',
1203
+ '__noclone', '__lockfunc', '__ref', '__private', '__bitwise',
1204
+ '__nosavedata', '__no_kcsan', '__cpuidle', '__ksym',
1205
+ '__initdata_memblock', '__initdata_or_meminfo',
1206
+ ];
1207
+ // `(?!\s*\()` keeps the parameterized annotations (`__printf(1, 2)`,
1208
+ // `__aligned(8)`, `__section("x")`) intact — blanking just their name would
1209
+ // strand the argument list as a floating parenthesis and CREATE an error.
1210
+ const C_KERNEL_ANNOTATION_RE = new RegExp(`\\b(${[...C_KERNEL_ANNOTATIONS].sort((a, b) => b.length - a.length).join('|')})\\b(?!\\s*\\()`, 'g');
1211
+ function blankCKernelAnnotations(source) {
1212
+ if (source.indexOf('__') === -1)
1213
+ return source;
1214
+ C_KERNEL_ANNOTATION_RE.lastIndex = 0;
1215
+ if (!C_KERNEL_ANNOTATION_RE.test(source))
1216
+ return source;
1217
+ let out = source.replace(C_KERNEL_ANNOTATION_RE, (m) => ' '.repeat(m.length));
1218
+ // `container_of(ptr, struct T, member)` — the type-keyword argument is the
1219
+ // one call shape tree-sitter-c cannot read (a macro taking a TYPE), and it
1220
+ // is pervasive across the Linux tree. Blanking just the `struct`/`union`
1221
+ // keyword leaves `container_of(ptr, T, member)` — a plain
1222
+ // identifier argument the grammar parses natively. Keyed to the macro name
1223
+ // so no other `struct` keyword anywhere is ever touched.
1224
+ if (out.indexOf('container_of') !== -1) {
1225
+ out = out.replace(/(\bcontainer_of\s*\([^;()]*?,\s*)(struct|union)(\s+)/g, (_m, head, kw, ws) => head + ' '.repeat(kw.length) + ws);
1226
+ }
1227
+ return out;
1228
+ }
1229
+ /**
1230
+ * Blank the PARAMETERIZED sparse/compiler annotations whole — name AND
1231
+ * argument list — `struct file *f __free(fput) = NULL;`, `static void
1232
+ * __printf(4, 0) log_it(…)`, `} owners[] __counted_by(count);`,
1233
+ * `__bpf_md_ptr(struct bpf_iter_meta *, meta);`. The word-list blank above
1234
+ * deliberately skips these via `(?!\s*\()` because blanking just the NAME
1235
+ * strands `(args)` as a floating parenthesis — so every such file kept
1236
+ * deferring (the v7.2-rc2 kernel/+mm/ census puts `__free`/`__printf`/
1237
+ * `__counted_by`/`__aligned` at the head of 39 first-error lines). Blanking
1238
+ * the whole `__name(args)` span leaves an ordinary declaration.
1239
+ *
1240
+ * CURATED for the same reason as the word list: `__aligned(8)` (annotation)
1241
+ * and `__hash(key)` (a real static helper call) are byte-shape identical, so
1242
+ * only reserved-namespace names that are annotations in every codebase that
1243
+ * spells them are listed. One nesting level of parens is allowed
1244
+ * (`__aligned(sizeof(struct x))`); newlines inside the span survive so byte
1245
+ * offsets are preserved. C-only.
1246
+ */
1247
+ const C_PARAMETERIZED_ANNOTATIONS = [
1248
+ '__free', '__printf', '__scanf', '__counted_by', '__counted_by_le',
1249
+ '__counted_by_be', '__guarded_by', '__pt_guarded_by', '__acquires',
1250
+ '__releases', '__must_hold', '__cleanup', '__aligned', '__section',
1251
+ '__bpf_md_ptr', '__assume_aligned',
1252
+ ];
1253
+ const C_PARAM_ANNOTATION_RE = new RegExp(`\\b(${[...C_PARAMETERIZED_ANNOTATIONS].sort((a, b) => b.length - a.length).join('|')})[ \\t]*\\((?:[^()]|\\([^()]*\\))*\\)`, 'g');
1254
+ function blankCParameterizedAnnotationMacros(source) {
1255
+ if (source.indexOf('__') === -1)
1256
+ return source;
1257
+ C_PARAM_ANNOTATION_RE.lastIndex = 0;
1258
+ if (!C_PARAM_ANNOTATION_RE.test(source))
1259
+ return source;
1260
+ C_PARAM_ANNOTATION_RE.lastIndex = 0;
1261
+ let result = '';
1262
+ let last = 0;
1263
+ let m;
1264
+ while ((m = C_PARAM_ANNOTATION_RE.exec(source)) !== null) {
1265
+ const start = m.index;
1266
+ let end = start + m[0].length;
1267
+ // Field-position form — `__bpf_md_ptr(struct bpf_iter_meta *, meta);` as
1268
+ // the whole line: a lone `;` field is ITSELF a parse error (measured;
1269
+ // an empty struct body is fine), so the semicolon blanks with it. A
1270
+ // mid-line match (`… __free(fput) = NULL;`) keeps its statement tail.
1271
+ const lineStart = source.lastIndexOf('\n', start - 1) + 1;
1272
+ if (/^[ \t]*$/.test(source.slice(lineStart, start))) {
1273
+ const after = /^[ \t]*;/.exec(source.slice(end));
1274
+ if (after)
1275
+ end += after[0].length;
1276
+ }
1277
+ result += source.slice(last, start) + source.slice(start, end).replace(/[^\n\r]/g, ' ');
1278
+ last = end;
1279
+ }
1280
+ return result + source.slice(last);
1281
+ }
1282
+ /**
1283
+ * Blank a bare `struct`/`union`/`enum` TYPE-keyword argument inside a macro
1284
+ * call — `kzalloc_obj(struct bpf_mount_opts)`, `alloc_percpu(struct irqstat)`,
1285
+ * `list_first_entry(&pending,\n\t\tstruct async_entry, domain_list)` — the
1286
+ * `container_of` disease generalized (that blank stays as the keyed
1287
+ * precedent). A bare type is never a valid C expression argument, so
1288
+ * tree-sitter drops into error recovery at every such call; removing just the
1289
+ * keyword leaves a plain identifier argument the grammar parses natively.
1290
+ * This single shape heads ~35 first-error lines on the kernel/+mm/ census
1291
+ * (kzalloc_obj/list_entry/alloc_percpu + multi-line continuations).
1292
+ *
1293
+ * Guarded three ways, because `f(struct T)` has VALID look-alikes:
1294
+ * - head exclusions: `sizeof(struct T)` / `offsetof(struct T, m)` /
1295
+ * `_Generic(x, struct T *: …)` all parse natively (probed) and must keep
1296
+ * their keyword; `va_arg` gets its own dedicated blank below.
1297
+ * - call-vs-declaration: in `int wf(struct a, struct b);` (a wrapped
1298
+ * prototype — valid C) the head is preceded by a TYPE, so any identifier
1299
+ * or `*` before the head rejects the match — except the word `return`,
1300
+ * which precedes real calls. Newline/`=`/`,`/`(`/`;`/`{`/`>` etc. accept.
1301
+ * - the keyword must OPEN a top-level argument and the argument must be
1302
+ * exactly `struct T` (optionally `struct T *`, whose stars blank too —
1303
+ * `DEFINE_PER_CPU(struct task_struct *, ksoftirqd)` leaves two plain
1304
+ * identifier arguments): a cast (`f((struct T *)p)`) opens a nested
1305
+ * group, and a declaration argument (`TP_PROTO(struct foo *bar)`) trails
1306
+ * an extra identifier — neither matches.
1307
+ * A hand-rolled bounded scanner rather than a nested-alternation regex:
1308
+ * preceding args may themselves contain calls
1309
+ * (`hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(&d->h)),\n
1310
+ * struct bpf_dtab_netdev, index_hlist)`), and lazy nested regex groups over
1311
+ * untrusted repo text invite catastrophic backtracking. C-only.
1312
+ */
1313
+ const C_TYPE_ARG_HEAD_EXCLUSIONS = new Set([
1314
+ 'sizeof', 'alignof', '_Alignof', 'typeof', '__typeof__', '__typeof',
1315
+ 'offsetof', '_Generic', 'va_arg', 'if', 'while', 'for', 'switch', 'case',
1316
+ ]);
1317
+ const C_TYPE_ARG_HEAD_RE = /\b([A-Za-z_]\w*)[ \t]*\(/g;
1318
+ const C_TYPE_ARG_OPENER_RE = /^(struct|union|enum)([ \t\r\n]+)([A-Za-z_]\w*)([ \t\r\n]*\*+)?(?=[ \t\r\n]*[,)])/;
1319
+ const C_TYPE_ARG_SCAN_CAP = 600;
1320
+ function blankCTypeKeywordArgs(source) {
1321
+ if (!/\b(?:struct|union|enum)[ \t\r\n]/.test(source))
1322
+ return source;
1323
+ let chars = null;
1324
+ C_TYPE_ARG_HEAD_RE.lastIndex = 0;
1325
+ let m;
1326
+ while ((m = C_TYPE_ARG_HEAD_RE.exec(source)) !== null) {
1327
+ const head = m[1];
1328
+ if (C_TYPE_ARG_HEAD_EXCLUSIONS.has(head))
1329
+ continue;
1330
+ // Reject declaration shapes: an identifier or `*` (a return/field type)
1331
+ // immediately before the head — unless that word is `return`.
1332
+ let j = m.index - 1;
1333
+ while (j >= 0 && (source[j] === ' ' || source[j] === '\t'))
1334
+ j--;
1335
+ const prev = j >= 0 ? source[j] : '';
1336
+ if (/[\w*]/.test(prev)) {
1337
+ let w = j;
1338
+ while (w >= 0 && /\w/.test(source[w]))
1339
+ w--;
1340
+ if (source.slice(w + 1, j + 1) !== 'return')
1341
+ continue;
1342
+ }
1343
+ const open = m.index + m[0].length - 1;
1344
+ let depth = 1;
1345
+ let atArgStart = true;
1346
+ for (let k = open + 1; k < source.length && k - open <= C_TYPE_ARG_SCAN_CAP; k++) {
1347
+ const ch = source[k];
1348
+ if (ch === '"' || ch === "'") {
1349
+ const quote = ch;
1350
+ k++;
1351
+ while (k < source.length && source[k] !== quote) {
1352
+ if (source[k] === '\\')
1353
+ k++;
1354
+ k++;
1355
+ }
1356
+ atArgStart = false;
1357
+ continue;
1358
+ }
1359
+ if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r')
1360
+ continue;
1361
+ if (ch === '(') {
1362
+ depth++;
1363
+ atArgStart = false;
1364
+ continue;
1365
+ }
1366
+ if (ch === ')') {
1367
+ depth--;
1368
+ if (depth === 0)
1369
+ break;
1370
+ atArgStart = false;
1371
+ continue;
1372
+ }
1373
+ if (ch === ';' || ch === '{' || ch === '}')
1374
+ break; // not an argument list
1375
+ if (ch === ',') {
1376
+ if (depth === 1)
1377
+ atArgStart = true;
1378
+ continue;
1379
+ }
1380
+ if (depth === 1 && atArgStart) {
1381
+ const opener = C_TYPE_ARG_OPENER_RE.exec(source.slice(k, k + 160));
1382
+ if (opener) {
1383
+ chars ??= [...source];
1384
+ const kw = opener[1];
1385
+ for (let b = k; b < k + kw.length; b++)
1386
+ chars[b] = ' ';
1387
+ if (opener[4]) {
1388
+ const tail = opener[4];
1389
+ const stars = /\*+$/.exec(tail)[0].length;
1390
+ const starsStart = k + kw.length + opener[2].length + opener[3].length + (tail.length - stars);
1391
+ for (let b = starsStart; b < starsStart + stars; b++)
1392
+ chars[b] = ' ';
1393
+ }
1394
+ k += opener[0].length - 1;
1395
+ }
1396
+ }
1397
+ atArgStart = false;
1398
+ }
1399
+ }
1400
+ return chars ? chars.join('') : source;
1401
+ }
1402
+ /**
1403
+ * Blank a file-scope `static`/`extern`-prefixed ALL-CAPS declaration macro —
1404
+ * `static DEFINE_PER_CPU(struct llist_head, rstat_backlog_list);`,
1405
+ * `static DECLARE_WORK(init_free_wq, do_free_init);`,
1406
+ * `static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);` — the single
1407
+ * largest deferral family on the kernel/+mm/ census (~45 first-error lines
1408
+ * across the DEFINE_/DECLARE_ variants). A storage-class specifier followed
1409
+ * by a call expression is never valid C, so every one errors; the whole line
1410
+ * blanks to spaces (the macro-declared variable was invisible to extraction
1411
+ * anyway, and the file's remaining symbols recover).
1412
+ *
1413
+ * The UNPREFIXED form (`EXPORT_SYMBOL(x);`, `DEFINE_MUTEX(lock);` at column
1414
+ * 0) parses natively as a K&R implicit-int declaration (probed) — extraction
1415
+ * ignores declarations, so those lines are left alone; the type-keyword-arg
1416
+ * blank above already recovers the `DEFINE_PER_CPU(struct T, x);` bare form.
1417
+ * Matched tightly: `static`/`extern` first on the line (indentation allowed —
1418
+ * `static DEFINE_RATELIMIT_STATE(…)` appears at BLOCK scope too, and the
1419
+ * storage-class-plus-call shape is invalid at every scope), CAPS macro name,
1420
+ * parens balancing ON the line (string literals skipped), then exactly `;`
1421
+ * to end of line. Initializer forms (`… ) = { …`) are deliberately not
1422
+ * matched — blanking the head would strand the brace block. C-only.
1423
+ */
1424
+ const C_PREFIXED_DECL_MACRO_RE = /^[ \t]*(?:static|extern)[ \t]+[A-Z][A-Z0-9_]{2,}[ \t]*\(/;
1425
+ function blankCFileScopePrefixedDeclMacros(source) {
1426
+ if (!/^[ \t]*(?:static|extern)[ \t]+[A-Z]/m.test(source))
1427
+ return source;
1428
+ const lines = source.split('\n');
1429
+ let changed = false;
1430
+ for (let i = 0; i < lines.length; i++) {
1431
+ const line = lines[i];
1432
+ const m = C_PREFIXED_DECL_MACRO_RE.exec(line);
1433
+ if (!m)
1434
+ continue;
1435
+ const open = line.indexOf('(', m[0].length - 1);
1436
+ let depth = 0;
1437
+ let close = -1;
1438
+ for (let k = open; k < line.length; k++) {
1439
+ const ch = line[k];
1440
+ if (ch === '"' || ch === "'") {
1441
+ const quote = ch;
1442
+ k++;
1443
+ while (k < line.length && line[k] !== quote) {
1444
+ if (line[k] === '\\')
1445
+ k++;
1446
+ k++;
1447
+ }
1448
+ continue;
1449
+ }
1450
+ if (ch === '(')
1451
+ depth++;
1452
+ else if (ch === ')') {
1453
+ depth--;
1454
+ if (depth === 0) {
1455
+ close = k;
1456
+ break;
1457
+ }
1458
+ }
1459
+ }
1460
+ if (close < 0)
1461
+ continue; // spans lines — leave for a future round
1462
+ if (line.slice(close + 1).replace(/\r$/, '').trim() !== ';')
1463
+ continue;
1464
+ lines[i] = line.replace(/[^\n\r]/g, ' ');
1465
+ changed = true;
1466
+ }
1467
+ return changed ? lines.join('\n') : source;
1468
+ }
1469
+ /**
1470
+ * REWRITE (the one non-blank pass in this family — it moves a token) a
1471
+ * 2-argument `static CAPS_MACRO(type, name) = {`-style initialized
1472
+ * declaration macro into the declaration it expands to — `static
1473
+ * DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state) = {` becomes `static
1474
+ * struct cpuhp_cpu_state cpuhp_state) …` → `static struct
1475
+ * cpuhp_cpu_state` + padding + `cpuhp_state` + padding + `= {`. The blank
1476
+ * family can't help here: blanking the head strands the brace block, and
1477
+ * dropping the whole span would discard the initializer's function
1478
+ * references (`.startup.single = bringup_cpu` — real cFnPtr wiring). The
1479
+ * NAME keeps its exact original column and the `= {` tail keeps its exact
1480
+ * offsets (`d`-flag group indices); only the TYPE token sits left of where
1481
+ * the macro name was, and type tokens contribute strings, not positions.
1482
+ * Only the two-argument `(<type-ish>, <ident>)` form with an `=` tail
1483
+ * matches; three-argument macros and `;`-terminated forms (the blank above)
1484
+ * never do. C-only.
1485
+ */
1486
+ const C_PREFIXED_DECL_MACRO_INIT_RE = /^([ \t]*)static[ \t]+[A-Z][A-Z0-9_]{2,}[ \t]*\(([^();'"]*?),[ \t]*([A-Za-z_]\w*)[ \t]*\)([ \t]*=[ \t]*\{?[ \t]*\r?)$/d;
1487
+ function rewriteCPrefixedDeclMacroInitializers(source) {
1488
+ if (!/^[ \t]*static[ \t]+[A-Z]/m.test(source))
1489
+ return source;
1490
+ const lines = source.split('\n');
1491
+ let changed = false;
1492
+ for (let i = 0; i < lines.length; i++) {
1493
+ const line = lines[i];
1494
+ const m = C_PREFIXED_DECL_MACRO_INIT_RE.exec(line);
1495
+ if (!m)
1496
+ continue;
1497
+ const indices = m.indices;
1498
+ const arg1 = m[2].trim().replace(/[ \t]+/g, ' ');
1499
+ if (!/^[A-Za-z_][\w \t*]*$/.test(arg1))
1500
+ continue; // a type-token run only
1501
+ const name = m[3];
1502
+ const nameStart = indices[3][0];
1503
+ const tailStart = indices[4][0];
1504
+ const prefix = m[1] + 'static ' + arg1;
1505
+ if (prefix.length + 1 > nameStart)
1506
+ continue; // rewrite must fit left of the name
1507
+ lines[i] =
1508
+ prefix +
1509
+ ' '.repeat(nameStart - prefix.length) +
1510
+ name +
1511
+ ' '.repeat(tailStart - nameStart - name.length) +
1512
+ line.slice(tailStart);
1513
+ changed = true;
1514
+ }
1515
+ return changed ? lines.join('\n') : source;
1516
+ }
1517
+ /**
1518
+ * Blank a QUALIFIED/POINTER type argument of `va_arg` — `va_arg(ap, const
1519
+ * char *)`, `va_arg(args, unsigned long)`. tree-sitter-c parses the
1520
+ * single-token forms (`va_arg(ap, int)`, `va_arg(ap, foo_t)`) natively
1521
+ * (probed), but multi-token type descriptors error the whole enclosing
1522
+ * function. Blanking the comma and the entire second argument leaves
1523
+ * `va_arg(ap )` — a one-argument call the grammar accepts.
1524
+ * Function-pointer types (`va_arg(ap, void (*)(int))`) contain parens and
1525
+ * are deliberately unmatched. C-only.
1526
+ */
1527
+ const C_VA_ARG_RE = /\bva_arg[ \t]*\(([^(),]+)(,[^()]*)\)/g;
1528
+ function blankCVaArgQualifiedTypeArgs(source) {
1529
+ if (source.indexOf('va_arg') === -1)
1530
+ return source;
1531
+ C_VA_ARG_RE.lastIndex = 0;
1532
+ return source.replace(C_VA_ARG_RE, (m, arg1, rest) => {
1533
+ if (/^,[ \t]*[A-Za-z_]\w*[ \t]*$/.test(rest))
1534
+ return m; // single token — parses natively
1535
+ return `va_arg(${arg1}${rest.replace(/[^\n\r]/g, ' ')})`;
1536
+ });
1537
+ }
1538
+ /**
1539
+ * Blank the DOTS of a GNU NAMED-variadic function-like `#define` parameter —
1540
+ * `#define verbose(env, fmt, args...) …` → `#define verbose(env, fmt,
1541
+ * args ) …`. The `ident...` parameter form (unlike standard `...`) errors
1542
+ * the DIRECTIVE itself (measured — and so does trailing whitespace after a
1543
+ * bare `#define NAME`, which is why the tail is NOT blanked wholesale); with
1544
+ * just the dots blanked the params parse as ordinary identifiers and the
1545
+ * body (`##args` included — the preproc body is opaque to the grammar) is
1546
+ * untouched. `restoreDirectiveLines` exists to keep directives out of the
1547
+ * other blanks' blast radius, so this pass runs AFTER the restore and edits
1548
+ * the directive deliberately. Multi-line bodies are fine — the params always
1549
+ * sit on the `#define` line. C-only (the census hits are the kernel's bpf
1550
+ * verifier headers).
1551
+ */
1552
+ const C_NAMED_VARIADIC_DEFINE_RE = /^([ \t]*#[ \t]*define[ \t]+[A-Za-z_]\w*\([^()\n]*?\b\w+)\.\.\./;
1553
+ function blankCNamedVariadicDefineDots(source) {
1554
+ if (source.indexOf('...') === -1)
1555
+ return source;
1556
+ const lines = source.split('\n');
1557
+ let changed = false;
1558
+ for (let i = 0; i < lines.length; i++) {
1559
+ const line = lines[i];
1560
+ const m = C_NAMED_VARIADIC_DEFINE_RE.exec(line);
1561
+ if (!m)
1562
+ continue;
1563
+ const keep = m[1];
1564
+ lines[i] = keep + ' ' + line.slice(keep.length + 3);
1565
+ changed = true;
733
1566
  }
734
- return blanked;
1567
+ return changed ? lines.join('\n') : source;
735
1568
  }
736
- /** C source pre-processing: C-detected headers in CUDA projects (llm.c keeps
737
- * `__device__` helpers and kernel prototypes in plain `.h`) get the same
738
- * content-gated CUDA blank as C++. */
1569
+ /** C source pre-processing: neutralize `#ifdef __cplusplus` compat-guard
1570
+ * bodies (invisible to a C compiler; `extern "C" {` otherwise errors every
1571
+ * public header), blank declaration-markup macro calls and lone macro lines
1572
+ * (`REDIS_NO_SANITIZE("bounds")` before a definition, jemalloc's diagnostic
1573
+ * toggles — the same structural shapes the C++ side already blanks), recover
1574
+ * functions hidden behind a leading attribute macro (#1211), then — for
1575
+ * C-detected headers in CUDA projects (llm.c keeps `__device__` helpers and
1576
+ * kernel prototypes in plain `.h`) — the same content-gated CUDA blank as
1577
+ * C++. Offset-preserving. */
739
1578
  function preParseCSource(source) {
740
- return looksLikeCudaSource(source) ? blankCudaConstructs(source) : source;
1579
+ const inner = blankCKernelAnnotations(blankCCplusplusGuardBodies(source));
1580
+ let blanked = blankCLeadingAttrMacros(blankLoneMacroLines(blankCStatementMacroCalls(blankCTrailingParamAttrMacros(blankCppAnnotationMacroCalls(rewriteCPrefixedDeclMacroInitializers(blankCFileScopePrefixedDeclMacros(blankCVaArgQualifiedTypeArgs(blankCTypeKeywordArgs(blankCParameterizedAnnotationMacros(blankCAutoInference(blankCSandwichedAnnotations(inner))))))))))));
1581
+ if (looksLikeCudaSource(blanked))
1582
+ blanked = blankCudaConstructs(blanked);
1583
+ // The named-variadic `#define` pass runs AFTER the directive restore — it
1584
+ // deliberately edits directive lines (see its doc comment).
1585
+ return blankCNamedVariadicDefineDots(restoreDirectiveLines(source, blanked));
741
1586
  }
742
1587
  exports.cppExtractor = {
743
1588
  // Recover macro-annotated class/struct definitions (`class MYMODULE_API Foo : Base`,
@@ -757,6 +1602,9 @@ exports.cppExtractor = {
757
1602
  methodTypes: ['function_definition'],
758
1603
  interfaceTypes: [],
759
1604
  structTypes: ['struct_specifier'],
1605
+ // C++ unions additionally carry member functions, which extract through the
1606
+ // same aggregate-body walk as structs while preserving their distinct kind.
1607
+ unionTypes: ['union_specifier'],
760
1608
  enumTypes: ['enum_specifier'],
761
1609
  enumMemberTypes: ['enumerator'],
762
1610
  typeAliasTypes: ['type_definition', 'alias_declaration'], // typedef and using
@@ -789,15 +1637,19 @@ exports.cppExtractor = {
789
1637
  return undefined;
790
1638
  },
791
1639
  resolveTypeAliasKind: (node, _source) => {
792
- // C++ typedef: `typedef enum { ... } name;` or `typedef struct { ... } name;`
1640
+ // C++ typedef: `typedef enum { ... } name;`, `typedef struct { ... } name;`,
1641
+ // or `typedef union { ... } name;` — see the C extractor.
793
1642
  for (let i = 0; i < node.namedChildCount; i++) {
794
1643
  const child = node.namedChild(i);
795
1644
  if (!child)
796
1645
  continue;
797
1646
  if (child.type === 'enum_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
798
1647
  return 'enum';
799
- if (child.type === 'struct_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
1648
+ if (child.type === 'struct_specifier' &&
1649
+ (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
800
1650
  return 'struct';
1651
+ if (child.type === 'union_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
1652
+ return 'union';
801
1653
  }
802
1654
  return undefined;
803
1655
  },