@vizalice/codegraph 1.5.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.
- package/LICENSE +21 -0
- package/README.md +872 -0
- package/dist/bin/codegraph.d.ts +26 -0
- package/dist/bin/codegraph.d.ts.map +1 -0
- package/dist/bin/codegraph.js +2324 -0
- package/dist/bin/codegraph.js.map +1 -0
- package/dist/bin/command-supervision.d.ts +49 -0
- package/dist/bin/command-supervision.d.ts.map +1 -0
- package/dist/bin/command-supervision.js +95 -0
- package/dist/bin/command-supervision.js.map +1 -0
- package/dist/bin/fatal-handler.d.ts +20 -0
- package/dist/bin/fatal-handler.d.ts.map +1 -0
- package/dist/bin/fatal-handler.js +118 -0
- package/dist/bin/fatal-handler.js.map +1 -0
- package/dist/bin/node-version-check.d.ts +37 -0
- package/dist/bin/node-version-check.d.ts.map +1 -0
- package/dist/bin/node-version-check.js +79 -0
- package/dist/bin/node-version-check.js.map +1 -0
- package/dist/bin/uninstall.d.ts +14 -0
- package/dist/bin/uninstall.d.ts.map +1 -0
- package/dist/bin/uninstall.js +36 -0
- package/dist/bin/uninstall.js.map +1 -0
- package/dist/context/formatter.d.ts +36 -0
- package/dist/context/formatter.d.ts.map +1 -0
- package/dist/context/formatter.js +269 -0
- package/dist/context/formatter.js.map +1 -0
- package/dist/context/index.d.ts +119 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +1333 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/markers.d.ts +19 -0
- package/dist/context/markers.d.ts.map +1 -0
- package/dist/context/markers.js +22 -0
- package/dist/context/markers.js.map +1 -0
- package/dist/db/index.d.ts +378 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +831 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +236 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/queries.d.ts +705 -0
- package/dist/db/queries.d.ts.map +1 -0
- package/dist/db/queries.js +2435 -0
- package/dist/db/queries.js.map +1 -0
- package/dist/db/schema.sql +207 -0
- package/dist/db/sqlite-adapter.d.ts +55 -0
- package/dist/db/sqlite-adapter.d.ts.map +1 -0
- package/dist/db/sqlite-adapter.js +135 -0
- package/dist/db/sqlite-adapter.js.map +1 -0
- package/dist/db/wal-valve.d.ts +119 -0
- package/dist/db/wal-valve.d.ts.map +1 -0
- package/dist/db/wal-valve.js +290 -0
- package/dist/db/wal-valve.js.map +1 -0
- package/dist/directory.d.ts +183 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +797 -0
- package/dist/directory.js.map +1 -0
- package/dist/errors.d.ts +136 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +219 -0
- package/dist/errors.js.map +1 -0
- package/dist/extraction/astro-extractor.d.ts +79 -0
- package/dist/extraction/astro-extractor.d.ts.map +1 -0
- package/dist/extraction/astro-extractor.js +320 -0
- package/dist/extraction/astro-extractor.js.map +1 -0
- package/dist/extraction/cfml-extractor.d.ts +107 -0
- package/dist/extraction/cfml-extractor.d.ts.map +1 -0
- package/dist/extraction/cfml-extractor.js +494 -0
- package/dist/extraction/cfml-extractor.js.map +1 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/dfm-extractor.d.ts.map +1 -0
- package/dist/extraction/dfm-extractor.js +151 -0
- package/dist/extraction/dfm-extractor.js.map +1 -0
- package/dist/extraction/extraction-version.d.ts +25 -0
- package/dist/extraction/extraction-version.d.ts.map +1 -0
- package/dist/extraction/extraction-version.js +28 -0
- package/dist/extraction/extraction-version.js.map +1 -0
- package/dist/extraction/function-ref.d.ts +118 -0
- package/dist/extraction/function-ref.d.ts.map +1 -0
- package/dist/extraction/function-ref.js +733 -0
- package/dist/extraction/function-ref.js.map +1 -0
- package/dist/extraction/generated-detection.d.ts +66 -0
- package/dist/extraction/generated-detection.d.ts.map +1 -0
- package/dist/extraction/generated-detection.js +248 -0
- package/dist/extraction/generated-detection.js.map +1 -0
- package/dist/extraction/grammars.d.ts +138 -0
- package/dist/extraction/grammars.d.ts.map +1 -0
- package/dist/extraction/grammars.js +694 -0
- package/dist/extraction/grammars.js.map +1 -0
- package/dist/extraction/index.d.ts +308 -0
- package/dist/extraction/index.d.ts.map +1 -0
- package/dist/extraction/index.js +2711 -0
- package/dist/extraction/index.js.map +1 -0
- package/dist/extraction/kernel/decode.d.ts +9 -0
- package/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/dist/extraction/kernel/decode.js +162 -0
- package/dist/extraction/kernel/decode.js.map +1 -0
- package/dist/extraction/kernel/index.d.ts +64 -0
- package/dist/extraction/kernel/index.d.ts.map +1 -0
- package/dist/extraction/kernel/index.js +279 -0
- package/dist/extraction/kernel/index.js.map +1 -0
- package/dist/extraction/kernel/layout.d.ts +101 -0
- package/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/dist/extraction/kernel/layout.js +104 -0
- package/dist/extraction/kernel/layout.js.map +1 -0
- package/dist/extraction/kernel/loader.d.ts +103 -0
- package/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/dist/extraction/kernel/loader.js +146 -0
- package/dist/extraction/kernel/loader.js.map +1 -0
- package/dist/extraction/languages/arkts.d.ts +3 -0
- package/dist/extraction/languages/arkts.d.ts.map +1 -0
- package/dist/extraction/languages/arkts.js +127 -0
- package/dist/extraction/languages/arkts.js.map +1 -0
- package/dist/extraction/languages/c-cpp.d.ts +124 -0
- package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
- package/dist/extraction/languages/c-cpp.js +1689 -0
- package/dist/extraction/languages/c-cpp.js.map +1 -0
- package/dist/extraction/languages/cfquery.d.ts +12 -0
- package/dist/extraction/languages/cfquery.d.ts.map +1 -0
- package/dist/extraction/languages/cfquery.js +28 -0
- package/dist/extraction/languages/cfquery.js.map +1 -0
- package/dist/extraction/languages/cfscript.d.ts +3 -0
- package/dist/extraction/languages/cfscript.d.ts.map +1 -0
- package/dist/extraction/languages/cfscript.js +73 -0
- package/dist/extraction/languages/cfscript.js.map +1 -0
- package/dist/extraction/languages/cobol.d.ts +33 -0
- package/dist/extraction/languages/cobol.d.ts.map +1 -0
- package/dist/extraction/languages/cobol.js +499 -0
- package/dist/extraction/languages/cobol.js.map +1 -0
- package/dist/extraction/languages/csharp.d.ts +25 -0
- package/dist/extraction/languages/csharp.d.ts.map +1 -0
- package/dist/extraction/languages/csharp.js +175 -0
- package/dist/extraction/languages/csharp.js.map +1 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts.map +1 -0
- package/dist/extraction/languages/dart.js +374 -0
- package/dist/extraction/languages/dart.js.map +1 -0
- package/dist/extraction/languages/erlang.d.ts +3 -0
- package/dist/extraction/languages/erlang.d.ts.map +1 -0
- package/dist/extraction/languages/erlang.js +350 -0
- package/dist/extraction/languages/erlang.js.map +1 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts.map +1 -0
- package/dist/extraction/languages/go.js +111 -0
- package/dist/extraction/languages/go.js.map +1 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/index.d.ts.map +1 -0
- package/dist/extraction/languages/index.js +71 -0
- package/dist/extraction/languages/index.js.map +1 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/java.d.ts.map +1 -0
- package/dist/extraction/languages/java.js +315 -0
- package/dist/extraction/languages/java.js.map +1 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts.map +1 -0
- package/dist/extraction/languages/javascript.js +106 -0
- package/dist/extraction/languages/javascript.js.map +1 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts.map +1 -0
- package/dist/extraction/languages/kotlin.js +379 -0
- package/dist/extraction/languages/kotlin.js.map +1 -0
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts.map +1 -0
- package/dist/extraction/languages/lua.js +150 -0
- package/dist/extraction/languages/lua.js.map +1 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts.map +1 -0
- package/dist/extraction/languages/luau.js +37 -0
- package/dist/extraction/languages/luau.js.map +1 -0
- package/dist/extraction/languages/nix.d.ts +3 -0
- package/dist/extraction/languages/nix.d.ts.map +1 -0
- package/dist/extraction/languages/nix.js +294 -0
- package/dist/extraction/languages/nix.js.map +1 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts.map +1 -0
- package/dist/extraction/languages/objc.js +179 -0
- package/dist/extraction/languages/objc.js.map +1 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts.map +1 -0
- package/dist/extraction/languages/pascal.js +77 -0
- package/dist/extraction/languages/pascal.js.map +1 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts.map +1 -0
- package/dist/extraction/languages/php.js +196 -0
- package/dist/extraction/languages/php.js.map +1 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts.map +1 -0
- package/dist/extraction/languages/python.js +56 -0
- package/dist/extraction/languages/python.js.map +1 -0
- package/dist/extraction/languages/r.d.ts +3 -0
- package/dist/extraction/languages/r.d.ts.map +1 -0
- package/dist/extraction/languages/r.js +314 -0
- package/dist/extraction/languages/r.js.map +1 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts.map +1 -0
- package/dist/extraction/languages/ruby.js +149 -0
- package/dist/extraction/languages/ruby.js.map +1 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts.map +1 -0
- package/dist/extraction/languages/rust.js +145 -0
- package/dist/extraction/languages/rust.js.map +1 -0
- package/dist/extraction/languages/scala.d.ts +3 -0
- package/dist/extraction/languages/scala.d.ts.map +1 -0
- package/dist/extraction/languages/scala.js +209 -0
- package/dist/extraction/languages/scala.js.map +1 -0
- package/dist/extraction/languages/solidity.d.ts +3 -0
- package/dist/extraction/languages/solidity.d.ts.map +1 -0
- package/dist/extraction/languages/solidity.js +293 -0
- package/dist/extraction/languages/solidity.js.map +1 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts.map +1 -0
- package/dist/extraction/languages/swift.js +152 -0
- package/dist/extraction/languages/swift.js.map +1 -0
- package/dist/extraction/languages/terraform.d.ts +3 -0
- package/dist/extraction/languages/terraform.d.ts.map +1 -0
- package/dist/extraction/languages/terraform.js +641 -0
- package/dist/extraction/languages/terraform.js.map +1 -0
- package/dist/extraction/languages/typescript.d.ts +16 -0
- package/dist/extraction/languages/typescript.d.ts.map +1 -0
- package/dist/extraction/languages/typescript.js +167 -0
- package/dist/extraction/languages/typescript.js.map +1 -0
- package/dist/extraction/languages/vbnet.d.ts +11 -0
- package/dist/extraction/languages/vbnet.d.ts.map +1 -0
- package/dist/extraction/languages/vbnet.js +141 -0
- package/dist/extraction/languages/vbnet.js.map +1 -0
- package/dist/extraction/liquid-extractor.d.ts +59 -0
- package/dist/extraction/liquid-extractor.d.ts.map +1 -0
- package/dist/extraction/liquid-extractor.js +357 -0
- package/dist/extraction/liquid-extractor.js.map +1 -0
- package/dist/extraction/mybatis-extractor.d.ts +68 -0
- package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
- package/dist/extraction/mybatis-extractor.js +300 -0
- package/dist/extraction/mybatis-extractor.js.map +1 -0
- package/dist/extraction/parse-pool.d.ts +160 -0
- package/dist/extraction/parse-pool.d.ts.map +1 -0
- package/dist/extraction/parse-pool.js +402 -0
- package/dist/extraction/parse-pool.js.map +1 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/parse-worker.d.ts.map +1 -0
- package/dist/extraction/parse-worker.js +138 -0
- package/dist/extraction/parse-worker.js.map +1 -0
- package/dist/extraction/razor-extractor.d.ts +42 -0
- package/dist/extraction/razor-extractor.d.ts.map +1 -0
- package/dist/extraction/razor-extractor.js +285 -0
- package/dist/extraction/razor-extractor.js.map +1 -0
- package/dist/extraction/store-worker.d.ts +24 -0
- package/dist/extraction/store-worker.d.ts.map +1 -0
- package/dist/extraction/store-worker.js +139 -0
- package/dist/extraction/store-worker.js.map +1 -0
- package/dist/extraction/store-writer.d.ts +63 -0
- package/dist/extraction/store-writer.d.ts.map +1 -0
- package/dist/extraction/store-writer.js +174 -0
- package/dist/extraction/store-writer.js.map +1 -0
- package/dist/extraction/svelte-extractor.d.ts +56 -0
- package/dist/extraction/svelte-extractor.d.ts.map +1 -0
- package/dist/extraction/svelte-extractor.js +275 -0
- package/dist/extraction/svelte-extractor.js.map +1 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-helpers.js +153 -0
- package/dist/extraction/tree-sitter-helpers.js.map +1 -0
- package/dist/extraction/tree-sitter-types.d.ts +260 -0
- package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
- package/dist/extraction/tree-sitter-types.js +10 -0
- package/dist/extraction/tree-sitter-types.js.map +1 -0
- package/dist/extraction/tree-sitter.d.ts +728 -0
- package/dist/extraction/tree-sitter.d.ts.map +1 -0
- package/dist/extraction/tree-sitter.js +6676 -0
- package/dist/extraction/tree-sitter.js.map +1 -0
- package/dist/extraction/vue-extractor.d.ts +51 -0
- package/dist/extraction/vue-extractor.d.ts.map +1 -0
- package/dist/extraction/vue-extractor.js +254 -0
- package/dist/extraction/vue-extractor.js.map +1 -0
- package/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +53 -0
- package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
- package/dist/extraction/wasm-runtime-flags.js +130 -0
- package/dist/extraction/wasm-runtime-flags.js.map +1 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/queries.d.ts +106 -0
- package/dist/graph/queries.d.ts.map +1 -0
- package/dist/graph/queries.js +341 -0
- package/dist/graph/queries.js.map +1 -0
- package/dist/graph/traversal.d.ts +127 -0
- package/dist/graph/traversal.d.ts.map +1 -0
- package/dist/graph/traversal.js +599 -0
- package/dist/graph/traversal.js.map +1 -0
- package/dist/index.d.ts +677 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1718 -0
- package/dist/index.js.map +1 -0
- package/dist/installer/beta-signup.d.ts +54 -0
- package/dist/installer/beta-signup.d.ts.map +1 -0
- package/dist/installer/beta-signup.js +178 -0
- package/dist/installer/beta-signup.js.map +1 -0
- package/dist/installer/config-writer.d.ts +28 -0
- package/dist/installer/config-writer.d.ts.map +1 -0
- package/dist/installer/config-writer.js +91 -0
- package/dist/installer/config-writer.js.map +1 -0
- package/dist/installer/index.d.ts +144 -0
- package/dist/installer/index.d.ts.map +1 -0
- package/dist/installer/index.js +634 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/installer/instructions-template.d.ts +41 -0
- package/dist/installer/instructions-template.d.ts.map +1 -0
- package/dist/installer/instructions-template.js +53 -0
- package/dist/installer/instructions-template.js.map +1 -0
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/antigravity.d.ts.map +1 -0
- package/dist/installer/targets/antigravity.js +308 -0
- package/dist/installer/targets/antigravity.js.map +1 -0
- package/dist/installer/targets/claude.d.ts +62 -0
- package/dist/installer/targets/claude.d.ts.map +1 -0
- package/dist/installer/targets/claude.js +486 -0
- package/dist/installer/targets/claude.js.map +1 -0
- package/dist/installer/targets/codex.d.ts +18 -0
- package/dist/installer/targets/codex.d.ts.map +1 -0
- package/dist/installer/targets/codex.js +185 -0
- package/dist/installer/targets/codex.js.map +1 -0
- package/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/dist/installer/targets/copilot-cli.js +209 -0
- package/dist/installer/targets/copilot-cli.js.map +1 -0
- package/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/dist/installer/targets/copilot-vscode.js +219 -0
- package/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/dist/installer/targets/cursor.d.ts +35 -0
- package/dist/installer/targets/cursor.d.ts.map +1 -0
- package/dist/installer/targets/cursor.js +254 -0
- package/dist/installer/targets/cursor.js.map +1 -0
- package/dist/installer/targets/dsh.d.ts +97 -0
- package/dist/installer/targets/dsh.d.ts.map +1 -0
- package/dist/installer/targets/dsh.js +358 -0
- package/dist/installer/targets/dsh.js.map +1 -0
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/gemini.d.ts.map +1 -0
- package/dist/installer/targets/gemini.js +165 -0
- package/dist/installer/targets/gemini.js.map +1 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/hermes.d.ts.map +1 -0
- package/dist/installer/targets/hermes.js +359 -0
- package/dist/installer/targets/hermes.js.map +1 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/kiro.d.ts.map +1 -0
- package/dist/installer/targets/kiro.js +178 -0
- package/dist/installer/targets/kiro.js.map +1 -0
- package/dist/installer/targets/opencode.d.ts +38 -0
- package/dist/installer/targets/opencode.d.ts.map +1 -0
- package/dist/installer/targets/opencode.js +288 -0
- package/dist/installer/targets/opencode.js.map +1 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/registry.d.ts.map +1 -0
- package/dist/installer/targets/registry.js +101 -0
- package/dist/installer/targets/registry.js.map +1 -0
- package/dist/installer/targets/shared.d.ts +132 -0
- package/dist/installer/targets/shared.d.ts.map +1 -0
- package/dist/installer/targets/shared.js +314 -0
- package/dist/installer/targets/shared.js.map +1 -0
- package/dist/installer/targets/toml.d.ts +53 -0
- package/dist/installer/targets/toml.d.ts.map +1 -0
- package/dist/installer/targets/toml.js +226 -0
- package/dist/installer/targets/toml.js.map +1 -0
- package/dist/installer/targets/types.d.ts +109 -0
- package/dist/installer/targets/types.d.ts.map +1 -0
- package/dist/installer/targets/types.js +16 -0
- package/dist/installer/targets/types.js.map +1 -0
- package/dist/installer/targets/zcode.d.ts +106 -0
- package/dist/installer/targets/zcode.d.ts.map +1 -0
- package/dist/installer/targets/zcode.js +451 -0
- package/dist/installer/targets/zcode.js.map +1 -0
- package/dist/mcp/daemon-manager.d.ts +42 -0
- package/dist/mcp/daemon-manager.d.ts.map +1 -0
- package/dist/mcp/daemon-manager.js +129 -0
- package/dist/mcp/daemon-manager.js.map +1 -0
- package/dist/mcp/daemon-paths.d.ts +73 -0
- package/dist/mcp/daemon-paths.d.ts.map +1 -0
- package/dist/mcp/daemon-paths.js +165 -0
- package/dist/mcp/daemon-paths.js.map +1 -0
- package/dist/mcp/daemon-registry.d.ts +47 -0
- package/dist/mcp/daemon-registry.d.ts.map +1 -0
- package/dist/mcp/daemon-registry.js +233 -0
- package/dist/mcp/daemon-registry.js.map +1 -0
- package/dist/mcp/daemon.d.ts +290 -0
- package/dist/mcp/daemon.d.ts.map +1 -0
- package/dist/mcp/daemon.js +862 -0
- package/dist/mcp/daemon.js.map +1 -0
- package/dist/mcp/dynamic-boundaries.d.ts +41 -0
- package/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
- package/dist/mcp/dynamic-boundaries.js +360 -0
- package/dist/mcp/dynamic-boundaries.js.map +1 -0
- package/dist/mcp/early-ppid.d.ts +26 -0
- package/dist/mcp/early-ppid.d.ts.map +1 -0
- package/dist/mcp/early-ppid.js +29 -0
- package/dist/mcp/early-ppid.js.map +1 -0
- package/dist/mcp/engine.d.ts +122 -0
- package/dist/mcp/engine.d.ts.map +1 -0
- package/dist/mcp/engine.js +350 -0
- package/dist/mcp/engine.js.map +1 -0
- package/dist/mcp/explore-dedup.d.ts +137 -0
- package/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/dist/mcp/explore-dedup.js +236 -0
- package/dist/mcp/explore-dedup.js.map +1 -0
- package/dist/mcp/explore-diagnostics.d.ts +287 -0
- package/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/dist/mcp/explore-diagnostics.js +555 -0
- package/dist/mcp/explore-diagnostics.js.map +1 -0
- package/dist/mcp/explore-session-state.d.ts +217 -0
- package/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/dist/mcp/explore-session-state.js +322 -0
- package/dist/mcp/explore-session-state.js.map +1 -0
- package/dist/mcp/index.d.ts +137 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +554 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/liveness-watchdog.d.ts +35 -0
- package/dist/mcp/liveness-watchdog.d.ts.map +1 -0
- package/dist/mcp/liveness-watchdog.js +269 -0
- package/dist/mcp/liveness-watchdog.js.map +1 -0
- package/dist/mcp/ppid-watchdog.d.ts +62 -0
- package/dist/mcp/ppid-watchdog.d.ts.map +1 -0
- package/dist/mcp/ppid-watchdog.js +64 -0
- package/dist/mcp/ppid-watchdog.js.map +1 -0
- package/dist/mcp/proxy.d.ts +87 -0
- package/dist/mcp/proxy.d.ts.map +1 -0
- package/dist/mcp/proxy.js +672 -0
- package/dist/mcp/proxy.js.map +1 -0
- package/dist/mcp/query-pool.d.ts +108 -0
- package/dist/mcp/query-pool.d.ts.map +1 -0
- package/dist/mcp/query-pool.js +315 -0
- package/dist/mcp/query-pool.js.map +1 -0
- package/dist/mcp/query-worker.d.ts +24 -0
- package/dist/mcp/query-worker.d.ts.map +1 -0
- package/dist/mcp/query-worker.js +87 -0
- package/dist/mcp/query-worker.js.map +1 -0
- package/dist/mcp/server-instructions.d.ts +34 -0
- package/dist/mcp/server-instructions.d.ts.map +1 -0
- package/dist/mcp/server-instructions.js +111 -0
- package/dist/mcp/server-instructions.js.map +1 -0
- package/dist/mcp/session.d.ts +109 -0
- package/dist/mcp/session.d.ts.map +1 -0
- package/dist/mcp/session.js +375 -0
- package/dist/mcp/session.js.map +1 -0
- package/dist/mcp/startup-handshake.d.ts +44 -0
- package/dist/mcp/startup-handshake.d.ts.map +1 -0
- package/dist/mcp/startup-handshake.js +73 -0
- package/dist/mcp/startup-handshake.js.map +1 -0
- package/dist/mcp/stdin-teardown.d.ts +27 -0
- package/dist/mcp/stdin-teardown.d.ts.map +1 -0
- package/dist/mcp/stdin-teardown.js +49 -0
- package/dist/mcp/stdin-teardown.js.map +1 -0
- package/dist/mcp/tools.d.ts +862 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +6526 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/transport.d.ts +188 -0
- package/dist/mcp/transport.d.ts.map +1 -0
- package/dist/mcp/transport.js +377 -0
- package/dist/mcp/transport.js.map +1 -0
- package/dist/mcp/version.d.ts +19 -0
- package/dist/mcp/version.d.ts.map +1 -0
- package/dist/mcp/version.js +71 -0
- package/dist/mcp/version.js.map +1 -0
- package/dist/project-config.d.ts +94 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +374 -0
- package/dist/project-config.js.map +1 -0
- package/dist/prompt-hook-output.d.ts +23 -0
- package/dist/prompt-hook-output.d.ts.map +1 -0
- package/dist/prompt-hook-output.js +35 -0
- package/dist/prompt-hook-output.js.map +1 -0
- package/dist/resolution/c-fnptr-synthesizer.d.ts +6 -0
- package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -0
- package/dist/resolution/c-fnptr-synthesizer.js +1506 -0
- package/dist/resolution/c-fnptr-synthesizer.js.map +1 -0
- package/dist/resolution/callback-synthesizer.d.ts +59 -0
- package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
- package/dist/resolution/callback-synthesizer.js +4030 -0
- package/dist/resolution/callback-synthesizer.js.map +1 -0
- package/dist/resolution/cooperative-yield.d.ts +40 -0
- package/dist/resolution/cooperative-yield.d.ts.map +1 -0
- package/dist/resolution/cooperative-yield.js +44 -0
- package/dist/resolution/cooperative-yield.js.map +1 -0
- package/dist/resolution/frameworks/astro.d.ts +9 -0
- package/dist/resolution/frameworks/astro.d.ts.map +1 -0
- package/dist/resolution/frameworks/astro.js +169 -0
- package/dist/resolution/frameworks/astro.js.map +1 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
- package/dist/resolution/frameworks/cargo-workspace.js +225 -0
- package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
- package/dist/resolution/frameworks/cics.d.ts +20 -0
- package/dist/resolution/frameworks/cics.d.ts.map +1 -0
- package/dist/resolution/frameworks/cics.js +90 -0
- package/dist/resolution/frameworks/cics.js.map +1 -0
- package/dist/resolution/frameworks/csharp.d.ts +8 -0
- package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
- package/dist/resolution/frameworks/csharp.js +241 -0
- package/dist/resolution/frameworks/csharp.js.map +1 -0
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
- package/dist/resolution/frameworks/drupal.js +367 -0
- package/dist/resolution/frameworks/drupal.js.map +1 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
- package/dist/resolution/frameworks/expo-modules.js +148 -0
- package/dist/resolution/frameworks/expo-modules.js.map +1 -0
- package/dist/resolution/frameworks/express.d.ts +8 -0
- package/dist/resolution/frameworks/express.d.ts.map +1 -0
- package/dist/resolution/frameworks/express.js +308 -0
- package/dist/resolution/frameworks/express.js.map +1 -0
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
- package/dist/resolution/frameworks/fabric.js +354 -0
- package/dist/resolution/frameworks/fabric.js.map +1 -0
- package/dist/resolution/frameworks/go.d.ts +8 -0
- package/dist/resolution/frameworks/go.d.ts.map +1 -0
- package/dist/resolution/frameworks/go.js +184 -0
- package/dist/resolution/frameworks/go.js.map +1 -0
- package/dist/resolution/frameworks/goframe.d.ts +41 -0
- package/dist/resolution/frameworks/goframe.d.ts.map +1 -0
- package/dist/resolution/frameworks/goframe.js +112 -0
- package/dist/resolution/frameworks/goframe.js.map +1 -0
- package/dist/resolution/frameworks/index.d.ts +50 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -0
- package/dist/resolution/frameworks/index.js +175 -0
- package/dist/resolution/frameworks/index.js.map +1 -0
- package/dist/resolution/frameworks/java.d.ts +8 -0
- package/dist/resolution/frameworks/java.d.ts.map +1 -0
- package/dist/resolution/frameworks/java.js +517 -0
- package/dist/resolution/frameworks/java.js.map +1 -0
- package/dist/resolution/frameworks/laravel.d.ts +13 -0
- package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
- package/dist/resolution/frameworks/laravel.js +257 -0
- package/dist/resolution/frameworks/laravel.js.map +1 -0
- package/dist/resolution/frameworks/nestjs.d.ts +26 -0
- package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
- package/dist/resolution/frameworks/nestjs.js +698 -0
- package/dist/resolution/frameworks/nestjs.js.map +1 -0
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/play.d.ts.map +1 -0
- package/dist/resolution/frameworks/play.js +111 -0
- package/dist/resolution/frameworks/play.js.map +1 -0
- package/dist/resolution/frameworks/python.d.ts +10 -0
- package/dist/resolution/frameworks/python.d.ts.map +1 -0
- package/dist/resolution/frameworks/python.js +400 -0
- package/dist/resolution/frameworks/python.js.map +1 -0
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
- package/dist/resolution/frameworks/react-native.js +410 -0
- package/dist/resolution/frameworks/react-native.js.map +1 -0
- package/dist/resolution/frameworks/react.d.ts +8 -0
- package/dist/resolution/frameworks/react.d.ts.map +1 -0
- package/dist/resolution/frameworks/react.js +334 -0
- package/dist/resolution/frameworks/react.js.map +1 -0
- package/dist/resolution/frameworks/ruby.d.ts +8 -0
- package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
- package/dist/resolution/frameworks/ruby.js +302 -0
- package/dist/resolution/frameworks/ruby.js.map +1 -0
- package/dist/resolution/frameworks/rust.d.ts +8 -0
- package/dist/resolution/frameworks/rust.d.ts.map +1 -0
- package/dist/resolution/frameworks/rust.js +304 -0
- package/dist/resolution/frameworks/rust.js.map +1 -0
- package/dist/resolution/frameworks/svelte.d.ts +9 -0
- package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
- package/dist/resolution/frameworks/svelte.js +253 -0
- package/dist/resolution/frameworks/svelte.js.map +1 -0
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
- package/dist/resolution/frameworks/swift-objc.js +252 -0
- package/dist/resolution/frameworks/swift-objc.js.map +1 -0
- package/dist/resolution/frameworks/swift.d.ts +10 -0
- package/dist/resolution/frameworks/swift.d.ts.map +1 -0
- package/dist/resolution/frameworks/swift.js +400 -0
- package/dist/resolution/frameworks/swift.js.map +1 -0
- package/dist/resolution/frameworks/terraform.d.ts +38 -0
- package/dist/resolution/frameworks/terraform.d.ts.map +1 -0
- package/dist/resolution/frameworks/terraform.js +277 -0
- package/dist/resolution/frameworks/terraform.js.map +1 -0
- package/dist/resolution/frameworks/vue.d.ts +9 -0
- package/dist/resolution/frameworks/vue.d.ts.map +1 -0
- package/dist/resolution/frameworks/vue.js +303 -0
- package/dist/resolution/frameworks/vue.js.map +1 -0
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/go-module.d.ts.map +1 -0
- package/dist/resolution/go-module.js +78 -0
- package/dist/resolution/go-module.js.map +1 -0
- package/dist/resolution/goframe-synthesizer.d.ts +29 -0
- package/dist/resolution/goframe-synthesizer.d.ts.map +1 -0
- package/dist/resolution/goframe-synthesizer.js +163 -0
- package/dist/resolution/goframe-synthesizer.js.map +1 -0
- package/dist/resolution/import-resolver.d.ts +84 -0
- package/dist/resolution/import-resolver.d.ts.map +1 -0
- package/dist/resolution/import-resolver.js +2134 -0
- package/dist/resolution/import-resolver.js.map +1 -0
- package/dist/resolution/index.d.ts +343 -0
- package/dist/resolution/index.d.ts.map +1 -0
- package/dist/resolution/index.js +2339 -0
- package/dist/resolution/index.js.map +1 -0
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/lru-cache.d.ts.map +1 -0
- package/dist/resolution/lru-cache.js +62 -0
- package/dist/resolution/lru-cache.js.map +1 -0
- package/dist/resolution/memory-budget.d.ts +48 -0
- package/dist/resolution/memory-budget.d.ts.map +1 -0
- package/dist/resolution/memory-budget.js +162 -0
- package/dist/resolution/memory-budget.js.map +1 -0
- package/dist/resolution/name-matcher.d.ts +123 -0
- package/dist/resolution/name-matcher.d.ts.map +1 -0
- package/dist/resolution/name-matcher.js +2134 -0
- package/dist/resolution/name-matcher.js.map +1 -0
- package/dist/resolution/path-aliases.d.ts +68 -0
- package/dist/resolution/path-aliases.d.ts.map +1 -0
- package/dist/resolution/path-aliases.js +238 -0
- package/dist/resolution/path-aliases.js.map +1 -0
- package/dist/resolution/resolver-pool.d.ts +106 -0
- package/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/dist/resolution/resolver-pool.js +344 -0
- package/dist/resolution/resolver-pool.js.map +1 -0
- package/dist/resolution/resolver-worker.d.ts +17 -0
- package/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/dist/resolution/resolver-worker.js +141 -0
- package/dist/resolution/resolver-worker.js.map +1 -0
- package/dist/resolution/strip-comments.d.ts +27 -0
- package/dist/resolution/strip-comments.d.ts.map +1 -0
- package/dist/resolution/strip-comments.js +492 -0
- package/dist/resolution/strip-comments.js.map +1 -0
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
- package/dist/resolution/swift-objc-bridge.js +256 -0
- package/dist/resolution/swift-objc-bridge.js.map +1 -0
- package/dist/resolution/types.d.ts +265 -0
- package/dist/resolution/types.d.ts.map +1 -0
- package/dist/resolution/types.js +8 -0
- package/dist/resolution/types.js.map +1 -0
- package/dist/resolution/workspace-packages.d.ts +58 -0
- package/dist/resolution/workspace-packages.d.ts.map +1 -0
- package/dist/resolution/workspace-packages.js +346 -0
- package/dist/resolution/workspace-packages.js.map +1 -0
- package/dist/search/identifier-segments.d.ts +60 -0
- package/dist/search/identifier-segments.d.ts.map +1 -0
- package/dist/search/identifier-segments.js +176 -0
- package/dist/search/identifier-segments.js.map +1 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-parser.d.ts.map +1 -0
- package/dist/search/query-parser.js +177 -0
- package/dist/search/query-parser.js.map +1 -0
- package/dist/search/query-utils.d.ts +87 -0
- package/dist/search/query-utils.d.ts.map +1 -0
- package/dist/search/query-utils.js +450 -0
- package/dist/search/query-utils.js.map +1 -0
- package/dist/sync/git-hooks.d.ts +45 -0
- package/dist/sync/git-hooks.d.ts.map +1 -0
- package/dist/sync/git-hooks.js +227 -0
- package/dist/sync/git-hooks.js.map +1 -0
- package/dist/sync/index.d.ts +19 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +35 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/watch-policy.d.ts +48 -0
- package/dist/sync/watch-policy.d.ts.map +1 -0
- package/dist/sync/watch-policy.js +124 -0
- package/dist/sync/watch-policy.js.map +1 -0
- package/dist/sync/watcher.d.ts +379 -0
- package/dist/sync/watcher.d.ts.map +1 -0
- package/dist/sync/watcher.js +921 -0
- package/dist/sync/watcher.js.map +1 -0
- package/dist/sync/worktree.d.ts +63 -0
- package/dist/sync/worktree.d.ts.map +1 -0
- package/dist/sync/worktree.js +182 -0
- package/dist/sync/worktree.js.map +1 -0
- package/dist/telemetry/index.d.ts +143 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +541 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/types.d.ts +465 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +117 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/color.d.ts +21 -0
- package/dist/ui/color.d.ts.map +1 -0
- package/dist/ui/color.js +42 -0
- package/dist/ui/color.js.map +1 -0
- package/dist/ui/glyphs.d.ts +67 -0
- package/dist/ui/glyphs.d.ts.map +1 -0
- package/dist/ui/glyphs.js +125 -0
- package/dist/ui/glyphs.js.map +1 -0
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-progress.d.ts.map +1 -0
- package/dist/ui/shimmer-progress.js +164 -0
- package/dist/ui/shimmer-progress.js.map +1 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/shimmer-worker.d.ts.map +1 -0
- package/dist/ui/shimmer-worker.js +126 -0
- package/dist/ui/shimmer-worker.js.map +1 -0
- package/dist/ui/types.d.ts +15 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +3 -0
- package/dist/ui/types.js.map +1 -0
- package/dist/upgrade/index.d.ts +171 -0
- package/dist/upgrade/index.d.ts.map +1 -0
- package/dist/upgrade/index.js +659 -0
- package/dist/upgrade/index.js.map +1 -0
- package/dist/upgrade/remove-binary.d.ts +87 -0
- package/dist/upgrade/remove-binary.d.ts.map +1 -0
- package/dist/upgrade/remove-binary.js +289 -0
- package/dist/upgrade/remove-binary.js.map +1 -0
- package/dist/upgrade/update-check.d.ts +92 -0
- package/dist/upgrade/update-check.d.ts.map +1 -0
- package/dist/upgrade/update-check.js +258 -0
- package/dist/upgrade/update-check.js.map +1 -0
- package/dist/utils.d.ts +224 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +583 -0
- package/dist/utils.js.map +1 -0
- package/package.json +61 -0
- package/scripts/add-lang/bench.sh +60 -0
- package/scripts/add-lang/check-grammar.mjs +75 -0
- package/scripts/add-lang/dump-ast.mjs +103 -0
- package/scripts/add-lang/verify-extraction.mjs +70 -0
- package/scripts/agent-eval/ab-adoption.sh +91 -0
- package/scripts/agent-eval/ab-hook.sh +86 -0
- package/scripts/agent-eval/ab-impl.sh +78 -0
- package/scripts/agent-eval/ab-new-vs-baseline.sh +161 -0
- package/scripts/agent-eval/ab-sufficiency.sh +78 -0
- package/scripts/agent-eval/allocation-fixtures.json +344 -0
- package/scripts/agent-eval/arms-F.sh +21 -0
- package/scripts/agent-eval/arms-matrix.sh +37 -0
- package/scripts/agent-eval/audit.sh +68 -0
- package/scripts/agent-eval/bench-readme.sh +48 -0
- package/scripts/agent-eval/bench-why-repo.sh +22 -0
- package/scripts/agent-eval/block-read-hook.sh +19 -0
- package/scripts/agent-eval/compare-arms.mjs +209 -0
- package/scripts/agent-eval/diff-index-drift.mjs +102 -0
- package/scripts/agent-eval/hook-settings.json +15 -0
- package/scripts/agent-eval/itrun.sh +120 -0
- package/scripts/agent-eval/no-cli-shim.sh +96 -0
- package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
- package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
- package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
- package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
- package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
- package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
- package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
- package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
- package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
- package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
- package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
- package/scripts/agent-eval/offload-eval-setup.sh +24 -0
- package/scripts/agent-eval/offload-eval-styles.sh +72 -0
- package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
- package/scripts/agent-eval/offload-eval.md +76 -0
- package/scripts/agent-eval/parse-arms.mjs +116 -0
- package/scripts/agent-eval/parse-bench-readme.mjs +238 -0
- package/scripts/agent-eval/parse-run.mjs +1401 -0
- package/scripts/agent-eval/parse-session.mjs +130 -0
- package/scripts/agent-eval/probe-allocation.mjs +335 -0
- package/scripts/agent-eval/probe-context.mjs +21 -0
- package/scripts/agent-eval/probe-decl-only.mjs +198 -0
- package/scripts/agent-eval/probe-explore.mjs +40 -0
- package/scripts/agent-eval/probe-factory-closure.mjs +147 -0
- package/scripts/agent-eval/probe-file-spend.mjs +195 -0
- package/scripts/agent-eval/probe-named-symbol.mjs +163 -0
- package/scripts/agent-eval/probe-node.mjs +20 -0
- package/scripts/agent-eval/probe-suite-envelope.mjs +124 -0
- package/scripts/agent-eval/probe-sweep.mjs +119 -0
- package/scripts/agent-eval/probe-trace.mjs +20 -0
- package/scripts/agent-eval/redirect-read-hook.sh +38 -0
- package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
- package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
- package/scripts/agent-eval/run-agent.sh +34 -0
- package/scripts/agent-eval/run-all.sh +149 -0
- package/scripts/agent-eval/run-arms.sh +56 -0
- package/scripts/agent-eval/seq-matrix.mjs +137 -0
- package/scripts/build-bundle.sh +145 -0
- package/scripts/build-kernel.sh +87 -0
- package/scripts/dump-graph.mjs +57 -0
- package/scripts/extract-release-notes.mjs +130 -0
- package/scripts/kernel-parity.mjs +283 -0
- package/scripts/local-install.sh +41 -0
- package/scripts/npm-sdk.js +75 -0
- package/scripts/npm-shim.js +279 -0
- package/scripts/pack-npm.sh +123 -0
- package/scripts/prepare-release.mjs +270 -0
|
@@ -0,0 +1,1689 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cppExtractor = exports.cExtractor = void 0;
|
|
4
|
+
exports.normalizeCppReturnType = normalizeCppReturnType;
|
|
5
|
+
exports.stripCppTemplateArgs = stripCppTemplateArgs;
|
|
6
|
+
exports.blankCppExportMacros = blankCppExportMacros;
|
|
7
|
+
exports.blankCppInlineMacros = blankCppInlineMacros;
|
|
8
|
+
exports.recoverMangledCppName = recoverMangledCppName;
|
|
9
|
+
exports.blankMetalAttributes = blankMetalAttributes;
|
|
10
|
+
exports.blankCppAnnotationMacroCalls = blankCppAnnotationMacroCalls;
|
|
11
|
+
exports.blankLoneMacroLines = blankLoneMacroLines;
|
|
12
|
+
exports.blankCppApiPrefixMacros = blankCppApiPrefixMacros;
|
|
13
|
+
exports.blankCppInlineAnnotationMacros = blankCppInlineAnnotationMacros;
|
|
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;
|
|
28
|
+
const tree_sitter_helpers_1 = require("../tree-sitter-helpers");
|
|
29
|
+
/**
|
|
30
|
+
* Find the function NAME's `qualified_identifier` (`Foo::bar`) inside a
|
|
31
|
+
* declarator, skipping the `parameter_list` — a parameter with a qualified type
|
|
32
|
+
* (`const std::string& x`) must NOT be mistaken for the method name. Without the
|
|
33
|
+
* skip, a plain free function `std::string TableFileName(const std::string&...)`
|
|
34
|
+
* was named `string` (from the parameter type), so calls to it never resolved
|
|
35
|
+
* and its file looked like nothing depended on it.
|
|
36
|
+
*/
|
|
37
|
+
function findDeclaratorQualifiedId(declarator) {
|
|
38
|
+
const queue = [declarator];
|
|
39
|
+
while (queue.length > 0) {
|
|
40
|
+
const current = queue.shift();
|
|
41
|
+
if (current.type === 'qualified_identifier')
|
|
42
|
+
return current;
|
|
43
|
+
for (let i = 0; i < current.namedChildCount; i++) {
|
|
44
|
+
const child = current.namedChild(i);
|
|
45
|
+
// Don't descend into parameters or the trailing return type — their types
|
|
46
|
+
// (`const std::string&`, `-> std::string`) aren't the function name.
|
|
47
|
+
if (child && child.type !== 'parameter_list' && child.type !== 'trailing_return_type') {
|
|
48
|
+
queue.push(child);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Recover the real function name from the macro-definition idiom
|
|
56
|
+
* `MACRO_NAME(real_name, typed args…) { body }` — flash-attention's
|
|
57
|
+
* `DEFINE_FLASH_FORWARD_KERNEL(flash_fwd_kernel, bool Is_dropout, …) { … }`
|
|
58
|
+
* being the motivating case: tree-sitter parses the invocation as a
|
|
59
|
+
* function_definition NAMED after the macro, so every such kernel shared one
|
|
60
|
+
* name (`DEFINE_FLASH_FORWARD_KERNEL`) and the launch sites' calls to the real
|
|
61
|
+
* names (`flash_fwd_kernel<…><<<…>>>`) could never resolve.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately narrow so name-in-first-arg is unambiguous — ALL of:
|
|
64
|
+
* - the parsed name is macro-shaped: ALL-CAPS with at least one underscore
|
|
65
|
+
* (`TEST` never matches; K&R C definitions have lowercase names);
|
|
66
|
+
* - the first "parameter" is a LONE identifier (no type, no declarator)
|
|
67
|
+
* containing a lowercase letter — the name being defined;
|
|
68
|
+
* - at least one more parameter follows and NONE of them is another lone
|
|
69
|
+
* identifier — a second bare arg means the first isn't the name (gtest's
|
|
70
|
+
* `TEST_F(Fixture, Name)`, `PYBIND11_MODULE(ext, m)`,
|
|
71
|
+
* google-benchmark's `BENCHMARK_DEFINE_F(Fix, name)` all bail here).
|
|
72
|
+
*/
|
|
73
|
+
function recoverCppMacroDefinedName(node, source) {
|
|
74
|
+
if (node.type !== 'function_definition')
|
|
75
|
+
return undefined;
|
|
76
|
+
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
77
|
+
if (declarator?.type !== 'function_declarator')
|
|
78
|
+
return undefined;
|
|
79
|
+
const inner = (0, tree_sitter_helpers_1.getChildByField)(declarator, 'declarator');
|
|
80
|
+
if (inner?.type !== 'identifier')
|
|
81
|
+
return undefined;
|
|
82
|
+
const macroName = (0, tree_sitter_helpers_1.getNodeText)(inner, source);
|
|
83
|
+
if (!/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(macroName))
|
|
84
|
+
return undefined;
|
|
85
|
+
const params = (0, tree_sitter_helpers_1.getChildByField)(declarator, 'parameters');
|
|
86
|
+
if (!params || params.namedChildCount < 2)
|
|
87
|
+
return undefined;
|
|
88
|
+
const loneIdentText = (p) => p.type === 'parameter_declaration' &&
|
|
89
|
+
p.namedChildCount === 1 &&
|
|
90
|
+
p.namedChild(0)?.type === 'type_identifier'
|
|
91
|
+
? (0, tree_sitter_helpers_1.getNodeText)(p.namedChild(0), source)
|
|
92
|
+
: null;
|
|
93
|
+
const first = params.namedChild(0);
|
|
94
|
+
const name = first ? loneIdentText(first) : null;
|
|
95
|
+
if (!name || !/[a-z]/.test(name))
|
|
96
|
+
return undefined;
|
|
97
|
+
for (let i = 1; i < params.namedChildCount; i++) {
|
|
98
|
+
const p = params.namedChild(i);
|
|
99
|
+
if (p && loneIdentText(p) !== null)
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return name;
|
|
103
|
+
}
|
|
104
|
+
function extractCppQualifiedMethodName(node, source) {
|
|
105
|
+
const macroDefined = recoverCppMacroDefinedName(node, source);
|
|
106
|
+
if (macroDefined)
|
|
107
|
+
return macroDefined;
|
|
108
|
+
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
109
|
+
if (!declarator)
|
|
110
|
+
return undefined;
|
|
111
|
+
const qid = findDeclaratorQualifiedId(declarator);
|
|
112
|
+
if (!qid)
|
|
113
|
+
return undefined;
|
|
114
|
+
const parts = (0, tree_sitter_helpers_1.getNodeText)(qid, source).trim().split('::').filter(Boolean);
|
|
115
|
+
return parts[parts.length - 1];
|
|
116
|
+
}
|
|
117
|
+
function extractCppReceiverType(node, source) {
|
|
118
|
+
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
119
|
+
if (!declarator)
|
|
120
|
+
return undefined;
|
|
121
|
+
const qid = findDeclaratorQualifiedId(declarator);
|
|
122
|
+
if (!qid)
|
|
123
|
+
return undefined;
|
|
124
|
+
const parts = (0, tree_sitter_helpers_1.getNodeText)(qid, source).trim().split('::').filter(Boolean);
|
|
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;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Built-in / non-class return types that can never be a method receiver. We
|
|
138
|
+
* store no `returnType` for these so resolution never tries to resolve a method
|
|
139
|
+
* on `void` / `int` / etc.
|
|
140
|
+
*/
|
|
141
|
+
const CPP_NON_CLASS_RETURN = new Set([
|
|
142
|
+
'void', 'bool', 'char', 'short', 'int', 'long', 'float', 'double', 'unsigned',
|
|
143
|
+
'signed', 'size_t', 'ssize_t', 'auto', 'wchar_t', 'char8_t', 'char16_t',
|
|
144
|
+
'char32_t', 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 'uint16_t',
|
|
145
|
+
'uint32_t', 'uint64_t', 'intptr_t', 'uintptr_t', 'nullptr_t',
|
|
146
|
+
]);
|
|
147
|
+
/**
|
|
148
|
+
* Normalize a C++ return type to the bare class name a method could be called
|
|
149
|
+
* on. Unwraps smart-pointer / optional wrappers to their element type
|
|
150
|
+
* (`std::unique_ptr<Widget>` → `Widget`) so a factory's `->method()` resolves on
|
|
151
|
+
* the pointee. Strips cv-qualifiers, `&`/`*`, namespace qualifiers, and other
|
|
152
|
+
* template args. Returns undefined for primitives / void / `auto` / empty.
|
|
153
|
+
*/
|
|
154
|
+
function normalizeCppReturnType(raw) {
|
|
155
|
+
let t = raw.trim();
|
|
156
|
+
if (!t)
|
|
157
|
+
return undefined;
|
|
158
|
+
// Unwrap smart pointers / optional to their pointee (the thing you call `->` on).
|
|
159
|
+
const wrapper = t.match(/\b(?:std\s*::\s*)?(?:unique_ptr|shared_ptr|weak_ptr|optional)\s*<\s*([^,>]+?)\s*>/);
|
|
160
|
+
if (wrapper && wrapper[1])
|
|
161
|
+
t = wrapper[1];
|
|
162
|
+
t = t
|
|
163
|
+
.replace(/\b(?:const|volatile|typename|struct|class|enum)\b/g, ' ')
|
|
164
|
+
.replace(/<[^>]*>/g, ' ')
|
|
165
|
+
.replace(/[*&]+/g, ' ')
|
|
166
|
+
.replace(/\s+/g, ' ')
|
|
167
|
+
.trim();
|
|
168
|
+
if (!t)
|
|
169
|
+
return undefined;
|
|
170
|
+
const last = t.split('::').filter(Boolean).pop();
|
|
171
|
+
if (!last)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (CPP_NON_CLASS_RETURN.has(last))
|
|
174
|
+
return undefined;
|
|
175
|
+
if (!/^[A-Za-z_]\w*$/.test(last))
|
|
176
|
+
return undefined;
|
|
177
|
+
return last;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Strip C++ template arguments from a base-type reference name so it matches the
|
|
181
|
+
* bare class/struct the template was DEFINED as. `template<typename T> class
|
|
182
|
+
* Base { … }` is indexed as a node named `Base`, but a derived class
|
|
183
|
+
* `class D : public Base<int>` records its base as the full `Base<int>` (and
|
|
184
|
+
* `class Q : public ns::Tpl<int>` as `ns::Tpl<int>`) — neither name-matches
|
|
185
|
+
* `Base` / `ns::Tpl`, so the `extends` edge never resolves and the derived class
|
|
186
|
+
* looks like it inherits from nothing (#1043).
|
|
187
|
+
*
|
|
188
|
+
* Removes every balanced `<…>` group regardless of nesting or position, so
|
|
189
|
+
* `Base<int>` → `Base`, `ns::Tpl<Foo<int>>` → `ns::Tpl`, and the rare
|
|
190
|
+
* `Outer<int>::Inner` → `Outer::Inner`. The remaining qualified head is exactly
|
|
191
|
+
* what the non-templated base case already produces, so resolution treats them
|
|
192
|
+
* identically. A name with no template args passes through unchanged.
|
|
193
|
+
*/
|
|
194
|
+
function stripCppTemplateArgs(name) {
|
|
195
|
+
if (!name.includes('<'))
|
|
196
|
+
return name;
|
|
197
|
+
let out = '';
|
|
198
|
+
let depth = 0;
|
|
199
|
+
for (const ch of name) {
|
|
200
|
+
if (ch === '<')
|
|
201
|
+
depth++;
|
|
202
|
+
else if (ch === '>') {
|
|
203
|
+
if (depth > 0)
|
|
204
|
+
depth--;
|
|
205
|
+
}
|
|
206
|
+
else if (depth === 0)
|
|
207
|
+
out += ch;
|
|
208
|
+
}
|
|
209
|
+
return out.trim();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A function/method's return type lives in the `function_definition`'s `type`
|
|
213
|
+
* field (`Metrics& Metrics::instance()` → `Metrics`). Constructors, destructors,
|
|
214
|
+
* and conversion operators have no `type` field → undefined.
|
|
215
|
+
*/
|
|
216
|
+
function extractCppReturnType(node, source) {
|
|
217
|
+
const typeNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
|
|
218
|
+
if (!typeNode)
|
|
219
|
+
return undefined;
|
|
220
|
+
return normalizeCppReturnType((0, tree_sitter_helpers_1.getNodeText)(typeNode, source));
|
|
221
|
+
}
|
|
222
|
+
exports.cExtractor = {
|
|
223
|
+
// CUDA in C-detected headers (content-gated blank; see preParseCSource).
|
|
224
|
+
preParse: preParseCSource,
|
|
225
|
+
// Universal net: recover a real name from any macro-mangled function name.
|
|
226
|
+
recoverMangledName: recoverMangledCppName,
|
|
227
|
+
functionTypes: ['function_definition'],
|
|
228
|
+
classTypes: [],
|
|
229
|
+
methodTypes: [],
|
|
230
|
+
interfaceTypes: [],
|
|
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'],
|
|
235
|
+
enumTypes: ['enum_specifier'],
|
|
236
|
+
enumMemberTypes: ['enumerator'],
|
|
237
|
+
typeAliasTypes: ['type_definition'], // typedef
|
|
238
|
+
importTypes: ['preproc_include'],
|
|
239
|
+
callTypes: ['call_expression'],
|
|
240
|
+
variableTypes: ['declaration'],
|
|
241
|
+
nameField: 'declarator',
|
|
242
|
+
bodyField: 'body',
|
|
243
|
+
paramsField: 'parameters',
|
|
244
|
+
// A `const`/`static const` file-scope declaration carries a `type_qualifier`
|
|
245
|
+
// child reading "const" — extract those as `constant`, plain globals as
|
|
246
|
+
// `variable`.
|
|
247
|
+
isConst: (node) => node.namedChildren.some((c) => c.type === 'type_qualifier' && c.text === 'const'),
|
|
248
|
+
getReturnType: extractCppReturnType,
|
|
249
|
+
resolveTypeAliasKind: (node, _source) => {
|
|
250
|
+
// C typedef: `typedef enum { ... } name;` or `typedef struct { ... } name;`
|
|
251
|
+
// The inner enum_specifier/struct_specifier is anonymous, but we want the typedef 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.
|
|
255
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
256
|
+
const child = node.namedChild(i);
|
|
257
|
+
if (!child)
|
|
258
|
+
continue;
|
|
259
|
+
if (child.type === 'enum_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
260
|
+
return 'enum';
|
|
261
|
+
if (child.type === 'struct_specifier' &&
|
|
262
|
+
(0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
263
|
+
return 'struct';
|
|
264
|
+
if (child.type === 'union_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
265
|
+
return 'union';
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
},
|
|
269
|
+
extractImport: (node, source) => {
|
|
270
|
+
const importText = source.substring(node.startIndex, node.endIndex).trim();
|
|
271
|
+
// C includes: #include <stdio.h>, #include "myheader.h"
|
|
272
|
+
const systemLib = node.namedChildren.find((c) => c.type === 'system_lib_string');
|
|
273
|
+
if (systemLib) {
|
|
274
|
+
return { moduleName: (0, tree_sitter_helpers_1.getNodeText)(systemLib, source).replace(/^<|>$/g, ''), signature: importText };
|
|
275
|
+
}
|
|
276
|
+
const stringLiteral = node.namedChildren.find((c) => c.type === 'string_literal');
|
|
277
|
+
if (stringLiteral) {
|
|
278
|
+
const stringContent = stringLiteral.namedChildren.find((c) => c.type === 'string_content');
|
|
279
|
+
if (stringContent) {
|
|
280
|
+
return { moduleName: (0, tree_sitter_helpers_1.getNodeText)(stringContent, source), signature: importText };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Detect tree-sitter's misparse of a macro-annotated class/struct, e.g.
|
|
288
|
+
* `class MACRO Name { … }` or `class MACRO Name : public Base { … }` (#946).
|
|
289
|
+
* Not knowing `MACRO` is a macro, tree-sitter reads `class MACRO` as an
|
|
290
|
+
* *elaborated type specifier* (a bodyless `class_specifier`/`struct_specifier`
|
|
291
|
+
* whose "type name" is the macro) and the rest as a function: `Name` becomes the
|
|
292
|
+
* declarator and the `{ … }` a function body — so the whole declaration surfaces
|
|
293
|
+
* as a `function_definition` named after the class, with a line range spanning
|
|
294
|
+
* the entire class body. (A base clause, when present, additionally lands in an
|
|
295
|
+
* `ERROR` node, but it isn't required — the leading macro alone triggers this.)
|
|
296
|
+
*
|
|
297
|
+
* Two structural signals pin it down with no risk to genuine code:
|
|
298
|
+
* - the `type` field is a *bodyless* class/struct specifier — an elaborated
|
|
299
|
+
* type, not a real inline-defined return type like
|
|
300
|
+
* `struct P { int x; } makeP() { … }` (which carries a field list); and
|
|
301
|
+
* - the declarator is not a `function_declarator` — a real function definition
|
|
302
|
+
* always has one, which also leaves the legal-but-rare `class Foo f() { … }`
|
|
303
|
+
* (an elaborated return type on a genuine function) alone.
|
|
304
|
+
*
|
|
305
|
+
* The class body is mangled by the same misparse and is unrecoverable, so —
|
|
306
|
+
* matching how macro-prefixed C prototypes are handled — we drop the spurious
|
|
307
|
+
* node rather than mint a misleading whole-body `function` that pollutes
|
|
308
|
+
* callers/impact and skews kind statistics.
|
|
309
|
+
*/
|
|
310
|
+
function isMacroMisparsedTypeDecl(node) {
|
|
311
|
+
const typeNode = (0, tree_sitter_helpers_1.getChildByField)(node, 'type');
|
|
312
|
+
if (!typeNode)
|
|
313
|
+
return false;
|
|
314
|
+
if (typeNode.type !== 'class_specifier' && typeNode.type !== 'struct_specifier')
|
|
315
|
+
return false;
|
|
316
|
+
if (typeNode.namedChildren.some((c) => c.type === 'field_declaration_list'))
|
|
317
|
+
return false;
|
|
318
|
+
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
319
|
+
if (declarator && declarator.type === 'function_declarator')
|
|
320
|
+
return false;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Blank an export/visibility macro in a `class/struct EXPORT_MACRO Name …`
|
|
325
|
+
* *definition* header before parsing. Not knowing the macro, tree-sitter reads
|
|
326
|
+
* `class EXPORT_MACRO` as an elaborated type specifier and the rest as a
|
|
327
|
+
* function, so the whole class — its name, base clause, and members — drops out
|
|
328
|
+
* of the index (#946 catches the resulting phantom function but can't recover
|
|
329
|
+
* the class), which silently breaks type-hierarchy / inheritance-impact queries
|
|
330
|
+
* for effectively every Unreal-Engine (`*_API`), Qt/Boost (`*_EXPORT`), LLVM
|
|
331
|
+
* (`*_ABI`), … class. Replacing the macro with equal-length spaces preserves
|
|
332
|
+
* every byte offset (and thus line/column), so the declaration then parses as a
|
|
333
|
+
* normal class_specifier and the existing extraction emits the node, members,
|
|
334
|
+
* and `extends` edge. (#1061, follow-up to #946.)
|
|
335
|
+
*
|
|
336
|
+
* Matched tightly so it can't touch the same macro used as an ordinary value
|
|
337
|
+
* elsewhere (`int x = SOME_API;`): the macro is the ALL-CAPS token sitting
|
|
338
|
+
* *between* `class`/`struct` and the type name, and the trailing `[:{]`
|
|
339
|
+
* definition-guard fires only when a base clause or body follows — the only
|
|
340
|
+
* shape that misparses. That guard also leaves elaborated-type variable
|
|
341
|
+
* declarations (`struct FOO var;`, `class FOO obj = …`) untouched, since those
|
|
342
|
+
* end in `;` / `=` / `[`, never `:` / `{`. C++-only (wired into cppExtractor),
|
|
343
|
+
* so C's heavier use of `struct TAG var;` never reaches it.
|
|
344
|
+
*/
|
|
345
|
+
function blankCppExportMacros(source) {
|
|
346
|
+
if (source.indexOf('class') === -1 && source.indexOf('struct') === -1)
|
|
347
|
+
return source;
|
|
348
|
+
return source.replace(/\b(class|struct)(\s+)([A-Z][A-Z0-9_]+)(?=\s+[A-Za-z_]\w*(?:\s+final)?\s*[:{])/g, (_m, kw, ws, macro) => kw + ws + ' '.repeat(macro.length));
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Blank a known inline-specifier macro sitting in front of a function's return
|
|
352
|
+
* type (`FORCEINLINE FString GetName(…)`), before parsing. Not knowing the
|
|
353
|
+
* macro, tree-sitter can't reconcile `MACRO <return-type> <name>(` — an extra
|
|
354
|
+
* type-like token before the name — and drops into error recovery: the macro
|
|
355
|
+
* becomes the return type and, for a non-primitive return, the return type gets
|
|
356
|
+
* glued onto the name (`GetName` → `"FString GetName"`), so the function can't
|
|
357
|
+
* be found by name and its callers don't link. This is pervasive in Unreal
|
|
358
|
+
* Engine (`FORCEINLINE <ret> <name>(…)`) and in vendored third-party libraries
|
|
359
|
+
* that define their own inline macro (pugixml's `PUGI__FN`, Godot's
|
|
360
|
+
* `_FORCE_INLINE_`, Boost's `BOOST_FORCEINLINE`, …). Replacing the macro with
|
|
361
|
+
* equal-length spaces preserves every byte offset (so line/column stay exact)
|
|
362
|
+
* and the declaration then parses as an ordinary function — recovering the real
|
|
363
|
+
* name AND the return type — mirroring how `blankCppExportMacros` recovers
|
|
364
|
+
* macro-annotated classes (#946/#1061).
|
|
365
|
+
*
|
|
366
|
+
* Matched tightly so it can't touch an ordinary identifier: only the exact,
|
|
367
|
+
* curated inline-specifier tokens below (never an arbitrary all-caps token, so a
|
|
368
|
+
* real return type like `HRESULT DoIt()` is untouched), and only in specifier
|
|
369
|
+
* position — immediately followed by whitespace and the identifier that starts
|
|
370
|
+
* the return type or name. That lookahead leaves value/expression uses
|
|
371
|
+
* (`x = FORCEINLINE ? …`), string literals, and longer words
|
|
372
|
+
* (`FORCEINLINE_SOMETHINGELSE`, word-boundary) alone. To cover a new codebase's
|
|
373
|
+
* inline macro, add its exact token to the list.
|
|
374
|
+
*/
|
|
375
|
+
const CPP_INLINE_MACROS = [
|
|
376
|
+
// Unreal Engine
|
|
377
|
+
'FORCEINLINE_DEBUGGABLE', 'FORCENOINLINE', 'FORCEINLINE',
|
|
378
|
+
// pugixml (ubiquitous vendored XML parser): `#define PUGI__FN inline` before
|
|
379
|
+
// the return type, plus `PUGIXML_FUNCTION` (linkage macro) between the return
|
|
380
|
+
// type and the name — the blank mechanism handles both positions.
|
|
381
|
+
'PUGI__FN_NO_INLINE', 'PUGI__FN', 'PUGIXML_FUNCTION',
|
|
382
|
+
// Godot
|
|
383
|
+
'_ALWAYS_INLINE_', '_FORCE_INLINE_',
|
|
384
|
+
// Boost
|
|
385
|
+
'BOOST_FORCEINLINE', 'BOOST_NOINLINE',
|
|
386
|
+
// Qt (per-method markers + inline)
|
|
387
|
+
'Q_INVOKABLE', 'Q_SCRIPTABLE', 'Q_ALWAYS_INLINE', 'Q_SLOT', 'Q_SIGNAL',
|
|
388
|
+
// Folly / Abseil / LLVM / V8 / Eigen / rapidjson
|
|
389
|
+
'FOLLY_ALWAYS_INLINE', 'FOLLY_NOINLINE',
|
|
390
|
+
'ABSL_ATTRIBUTE_ALWAYS_INLINE', 'ABSL_ATTRIBUTE_NOINLINE',
|
|
391
|
+
'LLVM_ATTRIBUTE_ALWAYS_INLINE', 'LLVM_ATTRIBUTE_NOINLINE',
|
|
392
|
+
'V8_INLINE', 'V8_NOINLINE',
|
|
393
|
+
'EIGEN_STRONG_INLINE', 'EIGEN_ALWAYS_INLINE', 'EIGEN_DEVICE_FUNC',
|
|
394
|
+
'RAPIDJSON_FORCEINLINE',
|
|
395
|
+
// Mozilla / SpiderMonkey
|
|
396
|
+
'MOZ_ALWAYS_INLINE', 'MOZ_NEVER_INLINE',
|
|
397
|
+
// Protocol Buffers
|
|
398
|
+
'PROTOBUF_ALWAYS_INLINE', 'PROTOBUF_NOINLINE',
|
|
399
|
+
// {fmt} / spdlog
|
|
400
|
+
'FMT_CONSTEXPR20', 'FMT_CONSTEXPR', 'FMT_INLINE',
|
|
401
|
+
// Hedley + nlohmann/json (bundles Hedley)
|
|
402
|
+
'JSON_HEDLEY_ALWAYS_INLINE', 'JSON_HEDLEY_NEVER_INLINE',
|
|
403
|
+
'HEDLEY_ALWAYS_INLINE', 'HEDLEY_NEVER_INLINE',
|
|
404
|
+
// GLM (graphics math — pervasive in games/rendering)
|
|
405
|
+
'GLM_FUNC_QUALIFIER', 'GLM_FUNC_DECL', 'GLM_CONSTEXPR', 'GLM_INLINE',
|
|
406
|
+
// Bullet Physics / Skia / OpenCV / EASTL / Cocos2d-x / Chromium-WebKit
|
|
407
|
+
'SIMD_FORCE_INLINE',
|
|
408
|
+
'SK_ALWAYS_INLINE',
|
|
409
|
+
'CV_ALWAYS_INLINE', 'CV_INLINE',
|
|
410
|
+
'EA_FORCE_INLINE', 'EA_NOINLINE',
|
|
411
|
+
'CC_INLINE',
|
|
412
|
+
'NEVER_INLINE',
|
|
413
|
+
// C libraries: GLib, SQLite (internal linkage)
|
|
414
|
+
'G_INLINE_FUNC', 'SQLITE_PRIVATE', 'SQLITE_API',
|
|
415
|
+
// Windows calling conventions (linkage position — recover the return type; the
|
|
416
|
+
// name is salvaged regardless). Only the unambiguous, non-word-like ones.
|
|
417
|
+
'STDMETHODCALLTYPE', 'WINAPIV', 'WINAPI', 'APIENTRY',
|
|
418
|
+
// Common cross-ecosystem inline/attribute hints
|
|
419
|
+
'ALWAYS_INLINE', 'FORCE_INLINE', 'NOINLINE',
|
|
420
|
+
];
|
|
421
|
+
// One alternation, longest token first so a longer macro wins over a prefix.
|
|
422
|
+
const CPP_INLINE_MACRO_RE = new RegExp(`\\b(${[...CPP_INLINE_MACROS].sort((a, b) => b.length - a.length).join('|')})\\b(?=\\s+[A-Za-z_])`, 'g');
|
|
423
|
+
function blankCppInlineMacros(source) {
|
|
424
|
+
if (!CPP_INLINE_MACROS.some((m) => source.indexOf(m) !== -1))
|
|
425
|
+
return source;
|
|
426
|
+
return source.replace(CPP_INLINE_MACRO_RE, (m) => ' '.repeat(m.length));
|
|
427
|
+
}
|
|
428
|
+
// Bare C/C++ type/qualifier tokens that must never be taken as a recovered
|
|
429
|
+
// function name (guards `recoverMangledCppName` against the `Ret (name)` idiom,
|
|
430
|
+
// where the token before the params is the return type, not the name).
|
|
431
|
+
const CPP_PRIMITIVE_NAMES = new Set([
|
|
432
|
+
'bool', 'void', 'int', 'char', 'short', 'long', 'float', 'double', 'unsigned',
|
|
433
|
+
'signed', 'wchar_t', 'char8_t', 'char16_t', 'char32_t', 'char_t', 'size_t',
|
|
434
|
+
'auto', 'const', 'struct', 'class', 'enum', 'union', 'typename',
|
|
435
|
+
]);
|
|
436
|
+
/**
|
|
437
|
+
* Universal fallback (any macro, no list) for a C/C++ function name still mangled
|
|
438
|
+
* because a macro we don't blank sat in front of the return type: `MACRO Ret
|
|
439
|
+
* name(…)` / `Ret MACRO name(…)` misparse so the return type is glued onto the
|
|
440
|
+
* name ("Ret name", "char_t* to_str(double v)"). Recover the real identifier —
|
|
441
|
+
* the token immediately before the parameter list (or the last token). This runs
|
|
442
|
+
* AFTER the curated pre-parse blank, so it only ever sees the residual tail that
|
|
443
|
+
* blanking didn't already fix cleanly (which also recovers the return type).
|
|
444
|
+
*
|
|
445
|
+
* Safe by construction: only touches an ALREADY-mangled name — one with an
|
|
446
|
+
* internal space that isn't a legit `operator …`/destructor — so a well-formed
|
|
447
|
+
* name is returned unchanged. Guarded against the two ways it could mis-pick:
|
|
448
|
+
* the `Ret (name)` parenthesized-name idiom (left as-is, ambiguous), and a token
|
|
449
|
+
* that is a bare primitive/keyword rather than a real identifier.
|
|
450
|
+
*/
|
|
451
|
+
function recoverMangledCppName(name) {
|
|
452
|
+
if (!/\s/.test(name) || name.startsWith('operator') || name.startsWith('~'))
|
|
453
|
+
return name;
|
|
454
|
+
if (/^\S+\s+\([A-Za-z_]\w*\)/.test(name))
|
|
455
|
+
return name; // `Ret (name)` idiom — leave alone
|
|
456
|
+
const beforeParams = name.includes('(') ? name.slice(0, name.indexOf('(')) : name;
|
|
457
|
+
const tokens = beforeParams.trim().split(/\s+/);
|
|
458
|
+
const candidate = tokens[tokens.length - 1];
|
|
459
|
+
if (!candidate || !/^[A-Za-z_]\w*$/.test(candidate) || CPP_PRIMITIVE_NAMES.has(candidate))
|
|
460
|
+
return name;
|
|
461
|
+
return candidate;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Blank Metal Shading Language `[[attribute]]` annotations before parsing.
|
|
465
|
+
* MSL (≈ C++14) puts attributes AFTER the declarator — `float4 position
|
|
466
|
+
* [[position]];`, `constant Uniforms &u [[buffer(0)]]` — a position
|
|
467
|
+
* tree-sitter-cpp can't reconcile: a struct field with a trailing attribute
|
|
468
|
+
* misparses into a shape that emits a spurious `extends` reference from the
|
|
469
|
+
* struct to the field's *type* (`VertexIn extends float3`), which becomes a
|
|
470
|
+
* wrong inheritance edge whenever the repo defines that type itself (simd
|
|
471
|
+
* typedefs in a shared ShaderTypes.h are common). Replacing the attribute with
|
|
472
|
+
* equal-length spaces preserves every byte offset and lets fields and
|
|
473
|
+
* parameters parse as ordinary declarations, mirroring the macro blanks above.
|
|
474
|
+
*
|
|
475
|
+
* Matched tightly to the attribute shape — `[[ident]]`, `[[ident(args)]]`, and
|
|
476
|
+
* comma-separated lists (`[[buffer(0), raster_order_group(0)]]`) — so a
|
|
477
|
+
* subscripted lambda call (`arr[[]{ … }()]`, the only other way `[[` appears in
|
|
478
|
+
* C++-family source) can never match: after `[[` a lambda continues with `]`,
|
|
479
|
+
* never an identifier followed by `]]`. Applied ONLY to `.metal` files — in
|
|
480
|
+
* regular C++ the pre-declarator attribute position (`[[nodiscard]] int f()`)
|
|
481
|
+
* is legal syntax the grammar parses natively, and blanking it would be pure
|
|
482
|
+
* blast radius. (#1121)
|
|
483
|
+
*/
|
|
484
|
+
const METAL_ATTRIBUTE_RE = /\[\[\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?(?:\s*,\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?)*\s*\]\]/g;
|
|
485
|
+
function blankMetalAttributes(source) {
|
|
486
|
+
if (source.indexOf('[[') === -1)
|
|
487
|
+
return source;
|
|
488
|
+
return source.replace(METAL_ATTRIBUTE_RE, (m) => ' '.repeat(m.length));
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Blank annotation-style macro invocations that decorate a declaration but carry
|
|
492
|
+
* NO terminating semicolon — the pervasive Unreal-Engine reflection markup
|
|
493
|
+
* (`UPROPERTY(...)`, `UFUNCTION(...)`, `UCLASS(...)`, `GENERATED_BODY()`,
|
|
494
|
+
* `UE_DEPRECATED_FORGAME(...)`, `DECLARE_DELEGATE_*(...)`, …) that sits on its
|
|
495
|
+
* own line right before a member/type. tree-sitter's C++ grammar doesn't know
|
|
496
|
+
* these are macros, so each one drops into error recovery; in a big reflected
|
|
497
|
+
* class (`CharacterMovementComponent.h` has ~240 of them) the errors accumulate
|
|
498
|
+
* until the enclosing `class_specifier` can't close and collapses into an ERROR
|
|
499
|
+
* node — the whole class definition, its members, and its `extends` edges vanish
|
|
500
|
+
* from the graph. Neither `blankCppExportMacros` (class-header export macros) nor
|
|
501
|
+
* `blankCppInlineMacros` (return-type inline specifiers) touches these in-body
|
|
502
|
+
* markup macros. Replacing each with equal-length spaces preserves every byte
|
|
503
|
+
* offset (so line/column stay exact) and the class then parses normally.
|
|
504
|
+
*
|
|
505
|
+
* Deliberately name-list-FREE — UE alone has hundreds of such macros and projects
|
|
506
|
+
* add their own — so it keys on structure, not a curated list, matched tightly to
|
|
507
|
+
* avoid touching legitimate C++:
|
|
508
|
+
* - the macro must be the FIRST non-whitespace token on its line (`^[ \t]*`),
|
|
509
|
+
* which is where declaration markup lives — so a macro used inside an
|
|
510
|
+
* expression or condition (`if (CHECK(x))`, `x = MACRO(a) + b`) is never
|
|
511
|
+
* matched (it isn't line-leading);
|
|
512
|
+
* - the name must be ALL-CAPS (`[A-Z][A-Z0-9_]{2,}`), since ordinary
|
|
513
|
+
* function/type names called at line start are lower/mixed case;
|
|
514
|
+
* - the char after the balanced `(...)` must START A DECLARATION — a letter,
|
|
515
|
+
* `_`, `~` (destructor), or `#` (a following directive). Declaration markup is
|
|
516
|
+
* always followed by the thing it decorates (`UPROPERTY(...)\n float X;`,
|
|
517
|
+
* `UE_DEPRECATED(...) UPROPERTY(...)`), whereas a statement call is followed by
|
|
518
|
+
* `;` (`FOO(x);`), an init-list item by `,`/`{`, and an expression fragment by
|
|
519
|
+
* an operator (`MAKE(a) + 1`) — all rejected. String/char literals inside the
|
|
520
|
+
* args are skipped so an embedded `)` can't mis-close the balance.
|
|
521
|
+
*
|
|
522
|
+
* C++-only (wired into cppExtractor). A blanked macro inside a block comment is
|
|
523
|
+
* harmless (comments don't parse), and the rare line-leading no-semicolon
|
|
524
|
+
* ALL-CAPS call that isn't markup only loses that one annotation, never a whole
|
|
525
|
+
* class.
|
|
526
|
+
*/
|
|
527
|
+
function blankCppAnnotationMacroCalls(source) {
|
|
528
|
+
if (!/^[ \t]*[A-Z][A-Z0-9_]{2,}\s*\(/m.test(source))
|
|
529
|
+
return source;
|
|
530
|
+
const chars = source.split('');
|
|
531
|
+
const re = /^([ \t]*)([A-Z][A-Z0-9_]{2,})(\s*)\(/gm;
|
|
532
|
+
let m;
|
|
533
|
+
while ((m = re.exec(source)) !== null) {
|
|
534
|
+
const macroStart = m.index + (m[1] ?? '').length; // skip leading indent
|
|
535
|
+
let i = m.index + m[0].length - 1; // index of the opening '('
|
|
536
|
+
let depth = 0;
|
|
537
|
+
let end = -1;
|
|
538
|
+
for (; i < source.length; i++) {
|
|
539
|
+
const c = source[i];
|
|
540
|
+
if (c === '"' || c === "'") {
|
|
541
|
+
const quote = c;
|
|
542
|
+
i++;
|
|
543
|
+
while (i < source.length && source[i] !== quote) {
|
|
544
|
+
if (source[i] === '\\')
|
|
545
|
+
i++;
|
|
546
|
+
i++;
|
|
547
|
+
}
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (c === '(')
|
|
551
|
+
depth++;
|
|
552
|
+
else if (c === ')') {
|
|
553
|
+
depth--;
|
|
554
|
+
if (depth === 0) {
|
|
555
|
+
end = i + 1;
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (end < 0)
|
|
561
|
+
continue;
|
|
562
|
+
let j = end;
|
|
563
|
+
while (j < source.length && /\s/.test(source[j]))
|
|
564
|
+
j++;
|
|
565
|
+
const after = source[j];
|
|
566
|
+
// Only markup is followed by the declaration it decorates; a statement call
|
|
567
|
+
// (`;`), init-list item (`,`/`{`), or expression fragment (operator) is not.
|
|
568
|
+
if (!after || !/[A-Za-z_~#]/.test(after))
|
|
569
|
+
continue;
|
|
570
|
+
for (let k = macroStart; k < end; k++) {
|
|
571
|
+
if (chars[k] !== '\n' && chars[k] !== '\r')
|
|
572
|
+
chars[k] = ' ';
|
|
573
|
+
}
|
|
574
|
+
re.lastIndex = end;
|
|
575
|
+
}
|
|
576
|
+
return chars.join('');
|
|
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
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Blank an export/visibility macro sitting in front of a *member* or *method*
|
|
643
|
+
* declaration inside a class/namespace (`ENGINE_API virtual void Tick(…)`,
|
|
644
|
+
* `static ENGINE_API void AddReferencedObjects(…)`, `UE_API FVector GetVel()
|
|
645
|
+
* const`), before parsing. `blankCppExportMacros` only recovers the macro in a
|
|
646
|
+
* `class MACRO Name` *header*; the very same macro also prefixes almost every
|
|
647
|
+
* exported member of a big Unreal-Engine class, and tree-sitter — not knowing
|
|
648
|
+
* it's a macro — reads `MACRO <return-type> <name>(` as an extra type token and
|
|
649
|
+
* drops each such declaration into error recovery. In a heavily-exported header
|
|
650
|
+
* (`Actor.h`, `World.h`, …) hundreds of these accumulate: the return types pile
|
|
651
|
+
* up as orphan ERROR tokens and, combined with other markup, can still tip the
|
|
652
|
+
* enclosing class into collapse. Replacing the macro with equal-length spaces
|
|
653
|
+
* preserves every byte offset (line/column stay exact) and each member parses
|
|
654
|
+
* as an ordinary declaration.
|
|
655
|
+
*
|
|
656
|
+
* Matched tightly so it can't touch the same token used as a value
|
|
657
|
+
* (`int x = SOME_API;`, `if (mode == FOO_API)`): the token must be ALL-CAPS AND
|
|
658
|
+
* end in the conventional visibility-macro suffix `_API` / `_EXPORT` / `_ABI`
|
|
659
|
+
* (Unreal `*_API`, Qt/Boost `*_EXPORT`, LLVM `*_ABI`) — ordinary identifiers
|
|
660
|
+
* effectively never carry these suffixes — and must be immediately followed by
|
|
661
|
+
* whitespace then a declaration token (`\s+[A-Za-z_]`: a type, `virtual`,
|
|
662
|
+
* `static`, or the name). A value use is instead followed by `;`, `)`, `,`,
|
|
663
|
+
* `=`, `::`, or an operator, all of which fail the look-ahead. C++-only (wired
|
|
664
|
+
* into cppExtractor).
|
|
665
|
+
*/
|
|
666
|
+
const CPP_API_PREFIX_RE = /\b[A-Z][A-Z0-9_]*(?:_API|_EXPORT|_ABI)\b(?=\s+[A-Za-z_])/g;
|
|
667
|
+
function blankCppApiPrefixMacros(source) {
|
|
668
|
+
if (!/_(?:API|EXPORT|ABI)\b/.test(source))
|
|
669
|
+
return source;
|
|
670
|
+
return source.replace(CPP_API_PREFIX_RE, (m) => ' '.repeat(m.length));
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Blank an Unreal-Engine annotation macro that appears MID-LINE (not
|
|
674
|
+
* line-leading, so `blankCppAnnotationMacroCalls` never sees it) inside a
|
|
675
|
+
* declaration: an enum value's `UMETA(DisplayName="…")`, a parameter's
|
|
676
|
+
* `UPARAM(ref)`, or a deprecation tag wedged into a `using`/member declaration
|
|
677
|
+
* (`using FOnNetTick UE_DEPRECATED(5.5, "…") = TMulticastDelegate<void(float)>;`
|
|
678
|
+
* in `World.h`, which otherwise collapses `UWorld`). tree-sitter can't reconcile
|
|
679
|
+
* these embedded macro calls and drops into error recovery, and a mid-line one
|
|
680
|
+
* inside a big enum or a class-scope `using` can cascade into the whole enum /
|
|
681
|
+
* class being lost. Replacing the entire `MACRO(...)` (balanced parens, string
|
|
682
|
+
* literals skipped so an embedded `)` can't mis-close) with equal-length spaces
|
|
683
|
+
* preserves every byte offset and the declaration parses normally.
|
|
684
|
+
*
|
|
685
|
+
* Keyed on an explicit UE-only name list (`UMETA`, `UPARAM`, and the
|
|
686
|
+
* `UE_DEPRECATED*` family) — these identifiers are exclusive to Unreal's
|
|
687
|
+
* reflection layer and appear in no standard-C++ or other-library code, so
|
|
688
|
+
* blanking them is zero-risk to non-UE sources. (The line-LEADING forms of
|
|
689
|
+
* `UE_DEPRECATED(...)` are already handled by `blankCppAnnotationMacroCalls`;
|
|
690
|
+
* this covers the mid-line forms it structurally can't.) C++-only.
|
|
691
|
+
*/
|
|
692
|
+
const CPP_INLINE_ANNOTATION_RE = /\b(?:UMETA|UPARAM|UE_DEPRECATED\w*)\s*\(/g;
|
|
693
|
+
function blankCppInlineAnnotationMacros(source) {
|
|
694
|
+
if (!/\b(?:UMETA|UPARAM|UE_DEPRECATED)/.test(source))
|
|
695
|
+
return source;
|
|
696
|
+
const chars = source.split('');
|
|
697
|
+
const re = new RegExp(CPP_INLINE_ANNOTATION_RE.source, 'g');
|
|
698
|
+
let m;
|
|
699
|
+
while ((m = re.exec(source)) !== null) {
|
|
700
|
+
let i = m.index + m[0].length - 1; // index of the opening '('
|
|
701
|
+
let depth = 0;
|
|
702
|
+
let end = -1;
|
|
703
|
+
for (; i < source.length; i++) {
|
|
704
|
+
const c = source[i];
|
|
705
|
+
if (c === '"' || c === "'") {
|
|
706
|
+
const quote = c;
|
|
707
|
+
i++;
|
|
708
|
+
while (i < source.length && source[i] !== quote) {
|
|
709
|
+
if (source[i] === '\\')
|
|
710
|
+
i++;
|
|
711
|
+
i++;
|
|
712
|
+
}
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (c === '(')
|
|
716
|
+
depth++;
|
|
717
|
+
else if (c === ')') {
|
|
718
|
+
depth--;
|
|
719
|
+
if (depth === 0) {
|
|
720
|
+
end = i + 1;
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (end < 0)
|
|
726
|
+
continue;
|
|
727
|
+
for (let k = m.index; k < end; k++) {
|
|
728
|
+
if (chars[k] !== '\n' && chars[k] !== '\r')
|
|
729
|
+
chars[k] = ' ';
|
|
730
|
+
}
|
|
731
|
+
re.lastIndex = end;
|
|
732
|
+
}
|
|
733
|
+
return chars.join('');
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Blank CUDA-specific constructs before parsing `.cu`/`.cuh` files (parsed with
|
|
737
|
+
* the C++ grammar). Three shapes tree-sitter-cpp can't reconcile, each replaced
|
|
738
|
+
* with equal-length whitespace so every byte offset survives (#387):
|
|
739
|
+
*
|
|
740
|
+
* 1. Execution-space / storage specifiers: in `__global__ void step(…)` or
|
|
741
|
+
* `__shared__ float tile[256]` the specifier parses as the declaration's
|
|
742
|
+
* TYPE and shunts the real return/value type into an ERROR node — mangling
|
|
743
|
+
* signatures and, for `__shared__` arrays, the declared name itself. Blanked
|
|
744
|
+
* unconditionally (no following-token lookahead) so extended lambdas
|
|
745
|
+
* (`[=] __device__ (int i) { … }`) recover too. `__restrict__` is deliberately
|
|
746
|
+
* absent: the grammar already parses it natively as a type_qualifier.
|
|
747
|
+
* 2. `__launch_bounds__(…)` between specifier and declarator — same misparse.
|
|
748
|
+
* The parenthesized form is blanked first; a bare leftover token is caught
|
|
749
|
+
* by the specifier list.
|
|
750
|
+
* 3. Kernel-launch configs `step<<<grid, block, smem, stream>>>(args)`: the
|
|
751
|
+
* chevrons lex as shift operators around an empty-named template, so no
|
|
752
|
+
* call_expression exists and the host→kernel call edge — the main reason to
|
|
753
|
+
* index CUDA at all — is lost. Blanking the `<<<…>>>` span leaves
|
|
754
|
+
* `step (args)`, a plain call the grammar
|
|
755
|
+
* parses natively (templated launches `k<T, 256><<<…>>>(…)` included).
|
|
756
|
+
*
|
|
757
|
+
* The launch-config match is deliberately bounded — statement/brace characters
|
|
758
|
+
* excluded, span capped, newlines preserved by the replacer — so a stray `<<<`
|
|
759
|
+
* (a committed merge-conflict marker, a string literal) can never blank a run
|
|
760
|
+
* of real code: an unmatched launch degrades to the status quo for that call
|
|
761
|
+
* site (no call edge), never to corruption. Applied to `.cu`/`.cuh` files and —
|
|
762
|
+
* because much real CUDA lives in extension-less headers (cutlass launches the
|
|
763
|
+
* majority of its kernels from `.h`; flash-attention's launch templates are
|
|
764
|
+
* `.h`; llm.c keeps device helpers in C-detected `.h`) — to any C/C++-family
|
|
765
|
+
* file whose CONTENT carries a strong CUDA marker (`looksLikeCudaSource`).
|
|
766
|
+
* Unlike Metal's `[[attribute]]` (legal C++ syntax elsewhere, hence Metal's
|
|
767
|
+
* strict extension gate), no CUDA marker is valid C++ anywhere: `<<<` isn't
|
|
768
|
+
* legal syntax and the dunder specifiers are implementation-reserved names no
|
|
769
|
+
* real codebase defines — so a content-triggered blank on a non-CUDA file can
|
|
770
|
+
* only ever whitespace tokens inside comments or strings, which parse the same.
|
|
771
|
+
*/
|
|
772
|
+
const CUDA_LAUNCH_BOUNDS_RE = /\b__launch_bounds__\s*\([^()\n]*\)/g;
|
|
773
|
+
const CUDA_SPECIFIER_RE = /\b__(?:global|device|host|constant|shared|managed|grid_constant|forceinline|noinline|launch_bounds)__\b/g;
|
|
774
|
+
// `;` stays excluded (launch configs are expressions; a stray `<<<` spanning
|
|
775
|
+
// real statements always crosses one) and the span is capped. Braces are
|
|
776
|
+
// allowed through the regex — `k<<<dim3{1,1,1}, dim3{256,1,1}>>>(…)` is a real
|
|
777
|
+
// launch shape — but the replacer only blanks a BALANCED match: a merge
|
|
778
|
+
// conflict's `<<<<<<< … >>>>>>>` region that dodges every `;` still opens
|
|
779
|
+
// braces it never closes, so it fails the balance check and stays untouched.
|
|
780
|
+
const CUDA_LAUNCH_CONFIG_RE = /<<<[^;]{0,400}?>>>/g;
|
|
781
|
+
function blankCudaConstructs(source) {
|
|
782
|
+
let out = source;
|
|
783
|
+
if (out.indexOf('__') !== -1) {
|
|
784
|
+
out = out
|
|
785
|
+
.replace(CUDA_LAUNCH_BOUNDS_RE, (m) => ' '.repeat(m.length))
|
|
786
|
+
.replace(CUDA_SPECIFIER_RE, (m) => ' '.repeat(m.length));
|
|
787
|
+
}
|
|
788
|
+
if (out.indexOf('<<<') !== -1) {
|
|
789
|
+
out = out.replace(CUDA_LAUNCH_CONFIG_RE, (m) => {
|
|
790
|
+
let depth = 0;
|
|
791
|
+
for (let i = 0; i < m.length; i++) {
|
|
792
|
+
const ch = m.charCodeAt(i);
|
|
793
|
+
if (ch === 0x7b /* { */)
|
|
794
|
+
depth++;
|
|
795
|
+
else if (ch === 0x7d /* } */ && --depth < 0)
|
|
796
|
+
return m;
|
|
797
|
+
}
|
|
798
|
+
return depth === 0 ? m.replace(/[^\n]/g, ' ') : m;
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
return out;
|
|
802
|
+
}
|
|
803
|
+
/** Strong content markers for CUDA source in files without a CUDA extension
|
|
804
|
+
* (headers). The dunders are execution-space specifiers that only nvcc defines;
|
|
805
|
+
* `cudaStream_t` is the runtime's stream handle, pervasive in launcher headers
|
|
806
|
+
* that themselves declare no kernel. Deliberately excludes weak markers (`dim3`,
|
|
807
|
+
* `<<<`) that could plausibly appear in non-CUDA text. */
|
|
808
|
+
function looksLikeCudaSource(source) {
|
|
809
|
+
return (source.indexOf('__global__') !== -1 ||
|
|
810
|
+
source.indexOf('__device__') !== -1 ||
|
|
811
|
+
source.indexOf('__constant__') !== -1 ||
|
|
812
|
+
source.indexOf('cudaStream_t') !== -1);
|
|
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
|
+
}
|
|
845
|
+
/** C/C++ source pre-processing before tree-sitter: recover macro-annotated class
|
|
846
|
+
* definitions, macro-prefixed function definitions, macro-prefixed members, and
|
|
847
|
+
* macro-decorated members (Unreal-Engine reflection markup) — plus the non-C++
|
|
848
|
+
* surface of the dialects parsed with the C++ grammar: `.metal` MSL attribute
|
|
849
|
+
* annotations, and CUDA specifiers + launch syntax (by `.cu`/`.cuh` extension
|
|
850
|
+
* or by content, for CUDA living in `.h`/`.hpp` headers). Offset-preserving;
|
|
851
|
+
* directive lines are restored at the end (see restoreDirectiveLines). */
|
|
852
|
+
function preParseCppSource(source, filePath) {
|
|
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)))))));
|
|
857
|
+
const lower = filePath ? filePath.toLowerCase() : '';
|
|
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;
|
|
1566
|
+
}
|
|
1567
|
+
return changed ? lines.join('\n') : source;
|
|
1568
|
+
}
|
|
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. */
|
|
1578
|
+
function preParseCSource(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));
|
|
1586
|
+
}
|
|
1587
|
+
exports.cppExtractor = {
|
|
1588
|
+
// Recover macro-annotated class/struct definitions (`class MYMODULE_API Foo : Base`,
|
|
1589
|
+
// #1061/#946) and macro-prefixed functions (`FORCEINLINE FString Foo()`, #1093
|
|
1590
|
+
// follow-up) that tree-sitter otherwise misparses.
|
|
1591
|
+
preParse: preParseCppSource,
|
|
1592
|
+
// Universal net for any macro the curated blank list misses.
|
|
1593
|
+
recoverMangledName: recoverMangledCppName,
|
|
1594
|
+
functionTypes: ['function_definition'],
|
|
1595
|
+
classTypes: ['class_specifier'],
|
|
1596
|
+
// A bodiless `class_specifier` is a forward declaration (`class Foo;`) or an
|
|
1597
|
+
// elaborated type reference, not a definition. Skip it so dozens of forward
|
|
1598
|
+
// decls across headers don't mint phantom `class` nodes that crowd out — and
|
|
1599
|
+
// get picked as the blast-radius representative over — the single real
|
|
1600
|
+
// definition, exactly as bodiless struct/enum specifiers are already skipped. (#1093)
|
|
1601
|
+
skipBodilessClass: true,
|
|
1602
|
+
methodTypes: ['function_definition'],
|
|
1603
|
+
interfaceTypes: [],
|
|
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'],
|
|
1608
|
+
enumTypes: ['enum_specifier'],
|
|
1609
|
+
enumMemberTypes: ['enumerator'],
|
|
1610
|
+
typeAliasTypes: ['type_definition', 'alias_declaration'], // typedef and using
|
|
1611
|
+
importTypes: ['preproc_include'],
|
|
1612
|
+
callTypes: ['call_expression'],
|
|
1613
|
+
variableTypes: ['declaration'],
|
|
1614
|
+
nameField: 'declarator',
|
|
1615
|
+
bodyField: 'body',
|
|
1616
|
+
paramsField: 'parameters',
|
|
1617
|
+
resolveName: extractCppQualifiedMethodName,
|
|
1618
|
+
getReceiverType: extractCppReceiverType,
|
|
1619
|
+
getReturnType: extractCppReturnType,
|
|
1620
|
+
getVisibility: (node) => {
|
|
1621
|
+
// Check for access specifier in parent
|
|
1622
|
+
const parent = node.parent;
|
|
1623
|
+
if (parent) {
|
|
1624
|
+
for (let i = 0; i < parent.childCount; i++) {
|
|
1625
|
+
const child = parent.child(i);
|
|
1626
|
+
if (child?.type === 'access_specifier') {
|
|
1627
|
+
const text = child.text;
|
|
1628
|
+
if (text.includes('public'))
|
|
1629
|
+
return 'public';
|
|
1630
|
+
if (text.includes('private'))
|
|
1631
|
+
return 'private';
|
|
1632
|
+
if (text.includes('protected'))
|
|
1633
|
+
return 'protected';
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
return undefined;
|
|
1638
|
+
},
|
|
1639
|
+
resolveTypeAliasKind: (node, _source) => {
|
|
1640
|
+
// C++ typedef: `typedef enum { ... } name;`, `typedef struct { ... } name;`,
|
|
1641
|
+
// or `typedef union { ... } name;` — see the C extractor.
|
|
1642
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
1643
|
+
const child = node.namedChild(i);
|
|
1644
|
+
if (!child)
|
|
1645
|
+
continue;
|
|
1646
|
+
if (child.type === 'enum_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
1647
|
+
return 'enum';
|
|
1648
|
+
if (child.type === 'struct_specifier' &&
|
|
1649
|
+
(0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
1650
|
+
return 'struct';
|
|
1651
|
+
if (child.type === 'union_specifier' && (0, tree_sitter_helpers_1.getChildByField)(child, 'body'))
|
|
1652
|
+
return 'union';
|
|
1653
|
+
}
|
|
1654
|
+
return undefined;
|
|
1655
|
+
},
|
|
1656
|
+
isMisparsedFunction: (name, node) => {
|
|
1657
|
+
// C++ macros like NLOHMANN_JSON_NAMESPACE_BEGIN cause tree-sitter to misparse
|
|
1658
|
+
// namespace blocks as function_definitions (e.g. name = "namespace detail").
|
|
1659
|
+
// Also filter C++ keywords that tree-sitter occasionally misinterprets as
|
|
1660
|
+
// function/method names (e.g. switch statements inside macro-confused scopes).
|
|
1661
|
+
if (name.startsWith('namespace'))
|
|
1662
|
+
return true;
|
|
1663
|
+
const cppKeywords = ['switch', 'if', 'for', 'while', 'do', 'case', 'return'];
|
|
1664
|
+
if (cppKeywords.includes(name))
|
|
1665
|
+
return true;
|
|
1666
|
+
// `class MACRO Name : public Base { … }` misparses to a function_definition
|
|
1667
|
+
// named after the class. `blankCppExportMacros` (preParse) recovers the
|
|
1668
|
+
// common ALL-CAPS export-macro shape; this drop is the fallback for any
|
|
1669
|
+
// residual misparse it doesn't blank — still no phantom function (#1061/#946).
|
|
1670
|
+
return isMacroMisparsedTypeDecl(node);
|
|
1671
|
+
},
|
|
1672
|
+
extractImport: (node, source) => {
|
|
1673
|
+
const importText = source.substring(node.startIndex, node.endIndex).trim();
|
|
1674
|
+
// C++ includes: #include <iostream>, #include "myheader.h"
|
|
1675
|
+
const systemLib = node.namedChildren.find((c) => c.type === 'system_lib_string');
|
|
1676
|
+
if (systemLib) {
|
|
1677
|
+
return { moduleName: (0, tree_sitter_helpers_1.getNodeText)(systemLib, source).replace(/^<|>$/g, ''), signature: importText };
|
|
1678
|
+
}
|
|
1679
|
+
const stringLiteral = node.namedChildren.find((c) => c.type === 'string_literal');
|
|
1680
|
+
if (stringLiteral) {
|
|
1681
|
+
const stringContent = stringLiteral.namedChildren.find((c) => c.type === 'string_content');
|
|
1682
|
+
if (stringContent) {
|
|
1683
|
+
return { moduleName: (0, tree_sitter_helpers_1.getNodeText)(stringContent, source), signature: importText };
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return null;
|
|
1687
|
+
},
|
|
1688
|
+
};
|
|
1689
|
+
//# sourceMappingURL=c-cpp.js.map
|