semantifold 0.2.0 → 0.3.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/README.md +37 -12
- package/build/index.js +2 -2
- package/build/src/acceptance.d.ts +10 -0
- package/build/src/acceptance.d.ts.map +1 -1
- package/build/src/acceptance.js +24 -5
- package/build/src/backends/c-runtime.d.ts +3 -0
- package/build/src/backends/c-runtime.d.ts.map +1 -0
- package/build/src/backends/c-runtime.js +151 -0
- package/build/src/backends/c-validation.d.ts +12 -0
- package/build/src/backends/c-validation.d.ts.map +1 -0
- package/build/src/backends/c-validation.js +85 -0
- package/build/src/backends/c.d.ts +31 -0
- package/build/src/backends/c.d.ts.map +1 -0
- package/build/src/backends/c.js +308 -0
- package/build/src/backends/cpp-runtime.d.ts +3 -0
- package/build/src/backends/cpp-runtime.d.ts.map +1 -0
- package/build/src/backends/cpp-runtime.js +99 -0
- package/build/src/backends/cpp-validation.d.ts +9 -0
- package/build/src/backends/cpp-validation.d.ts.map +1 -0
- package/build/src/backends/cpp-validation.js +74 -0
- package/build/src/backends/cpp.d.ts +16 -0
- package/build/src/backends/cpp.d.ts.map +1 -0
- package/build/src/backends/cpp.js +285 -0
- package/build/src/backends/csharp.d.ts +20 -0
- package/build/src/backends/csharp.d.ts.map +1 -0
- package/build/src/backends/csharp.js +259 -0
- package/build/src/backends/go.d.ts +20 -0
- package/build/src/backends/go.d.ts.map +1 -0
- package/build/src/backends/go.js +374 -0
- package/build/src/backends/identifiers.d.ts +12 -0
- package/build/src/backends/identifiers.d.ts.map +1 -1
- package/build/src/backends/identifiers.js +71 -2
- package/build/src/backends/index.d.ts.map +1 -1
- package/build/src/backends/index.js +9 -1
- package/build/src/backends/native-validation.d.ts +9 -0
- package/build/src/backends/native-validation.d.ts.map +1 -0
- package/build/src/backends/native-validation.js +59 -0
- package/build/src/backends/ordered-expressions.d.ts +74 -0
- package/build/src/backends/ordered-expressions.d.ts.map +1 -0
- package/build/src/backends/ordered-expressions.js +159 -0
- package/build/src/backends/scalars.d.ts.map +1 -1
- package/build/src/backends/scalars.js +7 -2
- package/build/src/backends/shared.d.ts.map +1 -1
- package/build/src/backends/shared.js +59 -14
- package/build/src/frontends/c-parser.d.ts +20 -0
- package/build/src/frontends/c-parser.d.ts.map +1 -0
- package/build/src/frontends/c-parser.js +14 -0
- package/build/src/frontends/c.d.ts +220 -0
- package/build/src/frontends/c.d.ts.map +1 -0
- package/build/src/frontends/c.js +750 -0
- package/build/src/frontends/cpp-parser.d.ts +11 -0
- package/build/src/frontends/cpp-parser.d.ts.map +1 -0
- package/build/src/frontends/cpp-parser.js +15 -0
- package/build/src/frontends/cpp.d.ts +227 -0
- package/build/src/frontends/cpp.d.ts.map +1 -0
- package/build/src/frontends/cpp.js +784 -0
- package/build/src/frontends/csharp.d.ts +14 -0
- package/build/src/frontends/csharp.d.ts.map +1 -0
- package/build/src/frontends/csharp.js +708 -0
- package/build/src/frontends/go.d.ts +15 -0
- package/build/src/frontends/go.d.ts.map +1 -0
- package/build/src/frontends/go.js +712 -0
- package/build/src/frontends/scalars.d.ts.map +1 -1
- package/build/src/frontends/scalars.js +16 -1
- package/build/src/language-registry.d.ts.map +1 -1
- package/build/src/language-registry.js +51 -2
- package/build/src/mapping.js +2 -2
- package/build/src/semantic/provenance.js +3 -3
- package/build/src/semantic/types.d.ts +4 -4
- package/build/src/semantic/types.d.ts.map +1 -1
- package/build/src/semantic/types.js +3 -3
- package/build/src/subprocess.d.ts +10 -1
- package/build/src/subprocess.d.ts.map +1 -1
- package/build/src/subprocess.js +29 -3
- package/build/src/toolchains.d.ts +24 -0
- package/build/src/toolchains.d.ts.map +1 -1
- package/build/src/toolchains.js +6 -2
- package/docs/architecture.md +20 -6
- package/docs/c.md +60 -0
- package/docs/cpp.md +61 -0
- package/docs/goals.md +4 -2
- package/docs/language-support.md +27 -8
- package/docs/parser-qualification.md +153 -4
- package/docs/plans/2026-09-05-standard-library-portability.md +46 -0
- package/docs/source-maps.md +11 -5
- package/docs/standard-library-portability.md +190 -0
- package/docs/testing.md +113 -4
- package/index.js +1 -1
- package/node_modules/node-addon-api/LICENSE.md +9 -0
- package/node_modules/node-addon-api/README.md +95 -0
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +14 -0
- package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/node-addon-api/napi-inl.h +7250 -0
- package/node_modules/node-addon-api/napi.h +3463 -0
- package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +481 -0
- package/node_modules/node-addon-api/tools/README.md +73 -0
- package/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/node_modules/node-gyp-build/LICENSE +21 -0
- package/node_modules/node-gyp-build/README.md +58 -0
- package/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/node_modules/node-gyp-build/bin.js +84 -0
- package/node_modules/node-gyp-build/build-test.js +19 -0
- package/node_modules/node-gyp-build/index.js +6 -0
- package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/node_modules/node-gyp-build/optional.js +7 -0
- package/node_modules/node-gyp-build/package.json +43 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/LICENSE +15 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/README.md +7 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/README.md +90 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/binding.gyp +79 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/index.js +895 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/package.json +62 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.cc +106 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.cc +1056 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.cc +298 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.cc +383 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.h +39 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.cc +307 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/tree-sitter.d.ts +211 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +221 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +299 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +419 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +14 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +774 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2151 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +230 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4134 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1060 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +382 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +165 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +714 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +50 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +23 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1294 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1823 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/README.md +18 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/binding.gyp +29 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding.cc +20 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding_test.js +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.d.ts +28 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.js +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/grammar.js +1470 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/package.json +60 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-arm64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-x64/tree-sitter-c.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/highlights.scm +81 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/tags.scm +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/grammar.json +9735 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/node-types.json +4614 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/parser.c +119615 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/alloc.h +54 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter-c.wasm +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter.json +43 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/README.md +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/binding.gyp +30 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding.cc +20 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding_test.js +9 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.d.ts +28 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.js +11 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/grammar.js +1436 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/package.json +61 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-arm64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-x64/tree-sitter-cpp.node +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/highlights.scm +70 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/injections.scm +3 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/tags.scm +15 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/grammar.json +17084 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/node-types.json +7997 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/parser.c +530368 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/scanner.c +148 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/alloc.h +54 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/array.h +290 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter-cpp.wasm +0 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter.json +55 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/package.json +22 -0
- package/node_modules/semantifold-tree-sitter-legacy-internal/src/c.js +152 -0
- package/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/tree-sitter/README.md +128 -0
- package/node_modules/tree-sitter/binding.gyp +88 -0
- package/node_modules/tree-sitter/index.js +950 -0
- package/node_modules/tree-sitter/package.json +76 -0
- package/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/tree-sitter/src/language.cc +105 -0
- package/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/tree-sitter/src/node.cc +1088 -0
- package/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/tree-sitter/src/parser.cc +332 -0
- package/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/tree-sitter/src/query.cc +425 -0
- package/node_modules/tree-sitter/src/query.h +40 -0
- package/node_modules/tree-sitter/src/tree.cc +316 -0
- package/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/tree-sitter/tree-sitter.d.ts +1083 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1478 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +523 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +483 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +54 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +875 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2297 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +286 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +241 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4347 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +912 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1034 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +716 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +75 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +137 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1314 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1937 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/package.json +21 -5
- package/src/acceptance.js +25 -4
- package/src/backends/c-runtime.js +151 -0
- package/src/backends/c-validation.js +83 -0
- package/src/backends/c.js +308 -0
- package/src/backends/cpp-runtime.js +99 -0
- package/src/backends/cpp-validation.js +70 -0
- package/src/backends/cpp.js +285 -0
- package/src/backends/csharp.js +270 -0
- package/src/backends/go.js +383 -0
- package/src/backends/identifiers.js +72 -1
- package/src/backends/index.js +7 -0
- package/src/backends/native-validation.js +64 -0
- package/src/backends/ordered-expressions.js +161 -0
- package/src/backends/scalars.js +7 -1
- package/src/backends/shared.js +56 -12
- package/src/frontends/c-parser.js +17 -0
- package/src/frontends/c.js +780 -0
- package/src/frontends/cpp-parser.js +18 -0
- package/src/frontends/cpp.js +816 -0
- package/src/frontends/csharp.js +759 -0
- package/src/frontends/go.js +770 -0
- package/src/frontends/scalars.js +15 -0
- package/src/language-registry.js +52 -1
- package/src/mapping.js +1 -1
- package/src/semantic/provenance.js +2 -2
- package/src/semantic/types.js +2 -2
- package/src/subprocess.js +31 -2
- package/src/toolchains.js +5 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {unsupportedCapability} from "../diagnostic.js"
|
|
4
|
+
import {finalizeMapping, toSourceMapV3} from "../mapping.js"
|
|
5
|
+
import {validateBackendModule, emitExpression} from "./shared.js"
|
|
6
|
+
import {emitScalarType} from "./scalars.js"
|
|
7
|
+
import {SourceWriter} from "./writer.js"
|
|
8
|
+
|
|
9
|
+
const manifest = "module example.com/semantifold/generated\n\ngo 1.26.0\n"
|
|
10
|
+
const binarySyntax = Object.freeze({
|
|
11
|
+
BooleanAnd: "&&", BooleanEqual: "==", BooleanNotEqual: "!=", BooleanOr: "||",
|
|
12
|
+
IntegerAdd: "+", IntegerEqual: "==", IntegerGreaterThan: ">", IntegerGreaterThanOrEqual: ">=",
|
|
13
|
+
IntegerLessThan: "<", IntegerLessThanOrEqual: "<=", IntegerMultiply: "*", IntegerNotEqual: "!=",
|
|
14
|
+
IntegerSubtract: "-", StringConcat: "+", StringEqual: "==", StringNotEqual: "!="
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Emits one deterministic manifest-first Go module candidate.
|
|
19
|
+
* @param {{filename?: string, mapDirective?: unknown, module: import("../semantic/types.js").SemanticModule, sourceMapFilename?: unknown, sources?: {filename: string, content: string, language?: import("../semantic/types.js").SemanticLanguage}[]}} input Backend request.
|
|
20
|
+
* @returns {{artifacts: import("../semantic/types.js").GeneratedSetArtifact[], target: string}} Candidate artifact set.
|
|
21
|
+
*/
|
|
22
|
+
export function generateGoModule({filename, mapDirective, module, sourceMapFilename, sources}) {
|
|
23
|
+
validateBackendModule(module, "go")
|
|
24
|
+
if (filename !== undefined && filename != "main.go") {
|
|
25
|
+
unsupportedCapability("go", "artifact filename other than main.go", module.location)
|
|
26
|
+
}
|
|
27
|
+
if (mapDirective !== undefined || sourceMapFilename !== undefined) {
|
|
28
|
+
unsupportedCapability("go", "source-map filename or directive option", module.location)
|
|
29
|
+
}
|
|
30
|
+
validateRoundTripMutability(module)
|
|
31
|
+
validateLocalReads(module)
|
|
32
|
+
const writer = new SourceWriter({filename: "main.go", language: "go", module, sources})
|
|
33
|
+
|
|
34
|
+
emitProgram(module, writer)
|
|
35
|
+
const mapping = finalizeMapping(writer.finish())
|
|
36
|
+
const root = mapping.nodes.find(({path}) => path == "")
|
|
37
|
+
|
|
38
|
+
if (!root) throw new Error("Validated Go module omitted its canonical root provenance.")
|
|
39
|
+
return {
|
|
40
|
+
artifacts: [{
|
|
41
|
+
content: manifest,
|
|
42
|
+
contentKind: "text",
|
|
43
|
+
mediaType: "text/plain",
|
|
44
|
+
ownership: "generated",
|
|
45
|
+
path: "go.mod",
|
|
46
|
+
provenance: {
|
|
47
|
+
kind: "synthetic",
|
|
48
|
+
reason: "Fixed example.com/semantifold/generated module identity and Go 1.26.0 configuration.",
|
|
49
|
+
relatedOrigins: relatedRootOrigins(root)
|
|
50
|
+
},
|
|
51
|
+
role: "manifest"
|
|
52
|
+
}, {
|
|
53
|
+
content: mapping.generated.content,
|
|
54
|
+
contentKind: "text",
|
|
55
|
+
mediaType: "text/x-go",
|
|
56
|
+
ownership: "generated",
|
|
57
|
+
path: "main.go",
|
|
58
|
+
provenance: {kind: "text", mapping, sourceMap: toSourceMapV3(mapping)},
|
|
59
|
+
role: "entry"
|
|
60
|
+
}],
|
|
61
|
+
target: "go"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Validates assignment-derived mutability before writer construction.
|
|
67
|
+
* @param {import("../semantic/types.js").SemanticModule} module Semantic module.
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
function validateRoundTripMutability(module) {
|
|
71
|
+
for (const root of [...module.functions.map(({body}) => body), module.entryPoint.body]) {
|
|
72
|
+
const assigned = new Set()
|
|
73
|
+
|
|
74
|
+
visitStatements(root, (statement) => {
|
|
75
|
+
if (statement.kind == "AssignmentStatement") assigned.add(statement.target.name)
|
|
76
|
+
})
|
|
77
|
+
visitStatements(root, (statement) => {
|
|
78
|
+
if (statement.kind == "LocalDeclaration" && statement.mutable && !assigned.has(statement.name)) {
|
|
79
|
+
unsupportedCapability("go", "mutable local without a later syntactic assignment", statement.location)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Rejects locals that Go would reject as declared but never read.
|
|
87
|
+
* @param {import("../semantic/types.js").SemanticModule} module Semantic module.
|
|
88
|
+
* @returns {void}
|
|
89
|
+
*/
|
|
90
|
+
function validateLocalReads(module) {
|
|
91
|
+
for (const root of [...module.functions.map(({body}) => body), module.entryPoint.body]) {
|
|
92
|
+
/** @type {import("../semantic/types.js").LocalDeclaration[]} */
|
|
93
|
+
const declarations = []
|
|
94
|
+
const reads = new Set()
|
|
95
|
+
|
|
96
|
+
visitStatements(root, (statement) => {
|
|
97
|
+
if (statement.kind == "LocalDeclaration") {
|
|
98
|
+
declarations.push(statement)
|
|
99
|
+
collectIdentifierReads(statement.initializer, reads)
|
|
100
|
+
} else if (statement.kind == "IfStatement") collectIdentifierReads(statement.condition, reads)
|
|
101
|
+
else collectIdentifierReads(statement.expression, reads)
|
|
102
|
+
})
|
|
103
|
+
for (const declaration of declarations) {
|
|
104
|
+
if (!reads.has(declaration.name)) {
|
|
105
|
+
unsupportedCapability("go", `local '${declaration.name}' is never read`, declaration.location)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Collects genuine identifier reads recursively from one validated expression.
|
|
113
|
+
* @param {import("../semantic/types.js").Expression} expression Semantic expression.
|
|
114
|
+
* @param {Set<string>} reads Collected names.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
function collectIdentifierReads(expression, reads) {
|
|
118
|
+
if (expression.kind == "IdentifierExpression") reads.add(expression.name)
|
|
119
|
+
else if (expression.kind == "CallExpression") {
|
|
120
|
+
for (const argument of expression.arguments) collectIdentifierReads(argument, reads)
|
|
121
|
+
} else if (expression.kind == "UnaryExpression") collectIdentifierReads(expression.operand, reads)
|
|
122
|
+
else if (expression.kind == "BinaryExpression") {
|
|
123
|
+
collectIdentifierReads(expression.left, reads)
|
|
124
|
+
collectIdentifierReads(expression.right, reads)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Visits nested statements in semantic order.
|
|
130
|
+
* @param {import("../semantic/types.js").Block} block Semantic block.
|
|
131
|
+
* @param {(statement: import("../semantic/types.js").Statement) => void} callback Visitor.
|
|
132
|
+
* @returns {void}
|
|
133
|
+
*/
|
|
134
|
+
function visitStatements(block, callback) {
|
|
135
|
+
for (const statement of block.statements) {
|
|
136
|
+
callback(statement)
|
|
137
|
+
if (statement.kind == "IfStatement") {
|
|
138
|
+
visitStatements(statement.consequent, callback)
|
|
139
|
+
if (statement.alternate) visitStatements(statement.alternate, callback)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Reports whether any print statement requires fmt.
|
|
146
|
+
* @param {import("../semantic/types.js").SemanticModule} module Semantic module.
|
|
147
|
+
* @returns {boolean} Print presence.
|
|
148
|
+
*/
|
|
149
|
+
function hasPrint(module) {
|
|
150
|
+
let found = false
|
|
151
|
+
|
|
152
|
+
for (const root of [...module.functions.map(({body}) => body), module.entryPoint.body]) {
|
|
153
|
+
visitStatements(root, (statement) => {
|
|
154
|
+
if (statement.kind == "PrintStatement") found = true
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
return found
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Emits the fixed Go file scaffold and semantic bodies.
|
|
162
|
+
* @param {import("../semantic/types.js").SemanticModule} module Semantic module.
|
|
163
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
164
|
+
* @returns {void}
|
|
165
|
+
*/
|
|
166
|
+
function emitProgram(module, writer) {
|
|
167
|
+
writer.synthetic("package main\n", "Go package scaffold", [module])
|
|
168
|
+
if (hasPrint(module)) writer.synthetic('\nimport "fmt"\n', "Go fmt print scaffold", [module])
|
|
169
|
+
module.functions.forEach((declaration, index) => {
|
|
170
|
+
writer.synthetic("\n", "declaration separator", [declaration])
|
|
171
|
+
emitFunction(writer, declaration, index)
|
|
172
|
+
})
|
|
173
|
+
writer.synthetic("\n", "entry-point separator", [module.entryPoint])
|
|
174
|
+
writer.mapped("func main", {mappingKind: "anchor", node: module.entryPoint, path: "/entryPoint"})
|
|
175
|
+
writer.mapped("()", {mappingKind: "anchor", node: module.entryPoint, path: "/entryPoint"})
|
|
176
|
+
writer.synthetic(" ", "entry-point spacing", [module.entryPoint], ["/entryPoint"])
|
|
177
|
+
writer.mapped("{", {mappingKind: "anchor", node: module.entryPoint.body, path: "/entryPoint/body"})
|
|
178
|
+
writer.synthetic("\n", "line break", [module.entryPoint], ["/entryPoint"])
|
|
179
|
+
emitBlock(writer, module.entryPoint.body, "\t", "/entryPoint/body")
|
|
180
|
+
writer.mapped("}", {mappingKind: "anchor", node: module.entryPoint, path: "/entryPoint"})
|
|
181
|
+
writer.synthetic("\n", "line break", [module.entryPoint], ["/entryPoint"])
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Emits one semantic function.
|
|
186
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
187
|
+
* @param {import("../semantic/types.js").FunctionDeclaration} declaration Function declaration.
|
|
188
|
+
* @param {number} index Function index.
|
|
189
|
+
* @returns {void}
|
|
190
|
+
*/
|
|
191
|
+
function emitFunction(writer, declaration, index) {
|
|
192
|
+
const path = "/functions/" + index
|
|
193
|
+
|
|
194
|
+
writer.mapped("func", {mappingKind: "anchor", node: declaration, path})
|
|
195
|
+
writer.synthetic(" ", "function spacing", [declaration], [path])
|
|
196
|
+
writer.mapped(declaration.name, {mappingKind: "exact", node: declaration, path, role: "name"})
|
|
197
|
+
writer.mapped("(", {mappingKind: "anchor", node: declaration, path})
|
|
198
|
+
declaration.parameters.forEach((parameter, parameterIndex) => {
|
|
199
|
+
const parameterPath = path + "/parameters/" + parameterIndex
|
|
200
|
+
|
|
201
|
+
if (parameterIndex > 0) writer.synthetic(", ", "parameter separator", [declaration], [path])
|
|
202
|
+
writer.mapped(parameter.name, {mappingKind: "exact", node: parameter, path: parameterPath, role: "name"})
|
|
203
|
+
writer.synthetic(" ", "parameter spacing", [parameter], [parameterPath])
|
|
204
|
+
writer.mapped(emitScalarType("go", parameter.type), {
|
|
205
|
+
mappingKind: "exact", node: parameter.type, path: parameterPath + "/type", role: "type"
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
writer.mapped(")", {mappingKind: "anchor", node: declaration, path})
|
|
209
|
+
writer.synthetic(" ", "result spacing", [declaration], [path])
|
|
210
|
+
writer.mapped(emitScalarType("go", declaration.returnType), {
|
|
211
|
+
mappingKind: "exact", node: declaration.returnType, path: path + "/returnType", role: "type"
|
|
212
|
+
})
|
|
213
|
+
writer.synthetic(" ", "body spacing", [declaration], [path])
|
|
214
|
+
writer.mapped("{", {mappingKind: "anchor", node: declaration.body, path: path + "/body"})
|
|
215
|
+
writer.synthetic("\n", "line break", [declaration], [path])
|
|
216
|
+
emitBlock(writer, declaration.body, "\t", path + "/body")
|
|
217
|
+
writer.mapped("}", {mappingKind: "anchor", node: declaration, path})
|
|
218
|
+
writer.synthetic("\n", "line break", [declaration], [path])
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Emits an ordered block.
|
|
223
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
224
|
+
* @param {import("../semantic/types.js").Block} block Semantic block.
|
|
225
|
+
* @param {string} indent Current indentation.
|
|
226
|
+
* @param {string} path Semantic path.
|
|
227
|
+
* @returns {void}
|
|
228
|
+
*/
|
|
229
|
+
function emitBlock(writer, block, indent, path) {
|
|
230
|
+
block.statements.forEach((statement, index) => emitStatement(writer, statement, indent, path + "/statements/" + index))
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Emits one supported statement.
|
|
235
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
236
|
+
* @param {import("../semantic/types.js").Statement} statement Semantic statement.
|
|
237
|
+
* @param {string} indent Current indentation.
|
|
238
|
+
* @param {string} path Semantic path.
|
|
239
|
+
* @returns {void}
|
|
240
|
+
*/
|
|
241
|
+
function emitStatement(writer, statement, indent, path) {
|
|
242
|
+
if (statement.kind == "LocalDeclaration" || statement.kind == "AssignmentStatement") {
|
|
243
|
+
return emitLocal(writer, statement, indent, path)
|
|
244
|
+
}
|
|
245
|
+
if (statement.kind == "IfStatement") return emitIf(writer, statement, indent, path, true)
|
|
246
|
+
writer.synthetic(indent, "indentation", [statement], [path])
|
|
247
|
+
if (statement.kind == "ReturnStatement") {
|
|
248
|
+
writer.mapped("return", {mappingKind: "anchor", node: statement, path})
|
|
249
|
+
writer.synthetic(" ", "return spacing", [statement], [path])
|
|
250
|
+
emitExpression(writer, statement.expression, path + "/expression", "go", identity)
|
|
251
|
+
} else {
|
|
252
|
+
writer.mapped("fmt.Println", {mappingKind: "anchor", node: statement, path})
|
|
253
|
+
writer.mapped("(", {mappingKind: "anchor", node: statement, path})
|
|
254
|
+
emitExpression(writer, statement.expression, path + "/expression", "go", identity)
|
|
255
|
+
writer.mapped(")", {mappingKind: "anchor", node: statement, path})
|
|
256
|
+
}
|
|
257
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Emits a conditional, using direct else-if for the canonical nested shape.
|
|
262
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
263
|
+
* @param {import("../semantic/types.js").IfStatement} statement Conditional.
|
|
264
|
+
* @param {string} indent Current indentation.
|
|
265
|
+
* @param {string} path Semantic path.
|
|
266
|
+
* @param {boolean} includeIndent Whether to emit leading indentation.
|
|
267
|
+
* @returns {void}
|
|
268
|
+
*/
|
|
269
|
+
function emitIf(writer, statement, indent, path, includeIndent) {
|
|
270
|
+
if (includeIndent) writer.synthetic(indent, "indentation", [statement], [path])
|
|
271
|
+
writer.mapped("if", {mappingKind: "anchor", node: statement, path})
|
|
272
|
+
writer.synthetic(" ", "conditional spacing", [statement], [path])
|
|
273
|
+
emitCondition(writer, statement.condition, path + "/condition")
|
|
274
|
+
writer.synthetic(" ", "conditional spacing", [statement], [path])
|
|
275
|
+
writer.mapped("{", {mappingKind: "anchor", node: statement.consequent, path: path + "/consequent"})
|
|
276
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
277
|
+
emitBlock(writer, statement.consequent, indent + "\t", path + "/consequent")
|
|
278
|
+
writer.synthetic(indent, "indentation", [statement], [path])
|
|
279
|
+
writer.mapped("}", {mappingKind: "anchor", node: statement.consequent, path: path + "/consequent"})
|
|
280
|
+
if (statement.alternate) {
|
|
281
|
+
writer.synthetic(" ", "alternate spacing", [statement], [path])
|
|
282
|
+
writer.mapped("else", {mappingKind: "anchor", node: statement, path})
|
|
283
|
+
writer.synthetic(" ", "alternate spacing", [statement], [path])
|
|
284
|
+
const nested = statement.alternate.statements.length == 1 && statement.alternate.statements[0].kind == "IfStatement"
|
|
285
|
+
|
|
286
|
+
if (nested) {
|
|
287
|
+
emitIf(writer, /** @type {import("../semantic/types.js").IfStatement} */ (statement.alternate.statements[0]),
|
|
288
|
+
indent, path + "/alternate/statements/0", false)
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
writer.mapped("{", {mappingKind: "anchor", node: statement.alternate, path: path + "/alternate"})
|
|
292
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
293
|
+
emitBlock(writer, statement.alternate, indent + "\t", path + "/alternate")
|
|
294
|
+
writer.synthetic(indent, "indentation", [statement], [path])
|
|
295
|
+
writer.mapped("}", {mappingKind: "anchor", node: statement.alternate, path: path + "/alternate"})
|
|
296
|
+
}
|
|
297
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Emits a condition without the one redundant outer pair removed by gofmt.
|
|
302
|
+
* Child operations stay parenthesized so the semantic tree round-trips exactly.
|
|
303
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
304
|
+
* @param {import("../semantic/types.js").Expression} expression Condition expression.
|
|
305
|
+
* @param {string} path Semantic path.
|
|
306
|
+
* @returns {void}
|
|
307
|
+
*/
|
|
308
|
+
function emitCondition(writer, expression, path) {
|
|
309
|
+
if (expression.kind == "BinaryExpression") {
|
|
310
|
+
emitExpression(writer, expression.left, path + "/left", "go", identity)
|
|
311
|
+
writer.synthetic(" ", "operator spacing", [expression], [path])
|
|
312
|
+
writer.mapped(binarySyntax[expression.operation], {mappingKind: "exact", node: expression, path, role: "operator"})
|
|
313
|
+
writer.synthetic(" ", "operator spacing", [expression], [path])
|
|
314
|
+
emitExpression(writer, expression.right, path + "/right", "go", identity)
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
if (expression.kind == "UnaryExpression") {
|
|
318
|
+
writer.mapped(expression.operation == "BooleanNot" ? "!" : "-", {
|
|
319
|
+
mappingKind: "exact", node: expression, path, role: "operator"
|
|
320
|
+
})
|
|
321
|
+
emitExpression(writer, expression.operand, path + "/operand", "go", identity)
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
emitExpression(writer, expression, path, "go", identity)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Emits a local declaration or assignment.
|
|
329
|
+
* @param {SourceWriter} writer Source-aware writer.
|
|
330
|
+
* @param {import("../semantic/types.js").LocalStatement} statement Local statement.
|
|
331
|
+
* @param {string} indent Current indentation.
|
|
332
|
+
* @param {string} path Semantic path.
|
|
333
|
+
* @returns {void}
|
|
334
|
+
*/
|
|
335
|
+
function emitLocal(writer, statement, indent, path) {
|
|
336
|
+
if (statement.kind == "LocalDeclaration" && !statement.mutable) {
|
|
337
|
+
writer.synthetic(indent + "// @semantifold-immutable\n", "Go immutable-local carrier", [statement], [path])
|
|
338
|
+
}
|
|
339
|
+
writer.synthetic(indent, "indentation", [statement], [path])
|
|
340
|
+
if (statement.kind == "AssignmentStatement") {
|
|
341
|
+
writer.mapped(statement.target.name, {mappingKind: "exact", node: statement.target, path: path + "/target", role: "name"})
|
|
342
|
+
writer.synthetic(" ", "assignment spacing", [statement], [path])
|
|
343
|
+
writer.mapped("=", {mappingKind: "exact", node: statement, path, role: "operator"})
|
|
344
|
+
writer.synthetic(" ", "assignment spacing", [statement], [path])
|
|
345
|
+
emitExpression(writer, statement.expression, path + "/expression", "go", identity)
|
|
346
|
+
} else {
|
|
347
|
+
writer.mapped("var", {mappingKind: "anchor", node: statement, path})
|
|
348
|
+
writer.synthetic(" ", "declaration spacing", [statement], [path])
|
|
349
|
+
writer.mapped(statement.name, {mappingKind: "exact", node: statement, path, role: "name"})
|
|
350
|
+
writer.synthetic(" ", "declaration spacing", [statement], [path])
|
|
351
|
+
writer.mapped(emitScalarType("go", statement.type), {
|
|
352
|
+
mappingKind: "exact", node: statement.type, path: path + "/type", role: "type"
|
|
353
|
+
})
|
|
354
|
+
writer.synthetic(" ", "assignment spacing", [statement], [path])
|
|
355
|
+
writer.mapped("=", {mappingKind: "exact", node: statement, path, role: "operator"})
|
|
356
|
+
writer.synthetic(" ", "assignment spacing", [statement], [path])
|
|
357
|
+
emitExpression(writer, statement.initializer, path + "/initializer", "go", identity)
|
|
358
|
+
}
|
|
359
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Converts root provenance to artifact-level related origins.
|
|
364
|
+
* @param {import("../semantic/types.js").SemanticNodeProvenance} root Root provenance.
|
|
365
|
+
* @returns {import("../semantic/types.js").RelatedOrigin[]} Related roots.
|
|
366
|
+
*/
|
|
367
|
+
function relatedRootOrigins(root) {
|
|
368
|
+
if (root.origin.kind == "source") {
|
|
369
|
+
return [{location: root.origin.location, nodeId: root.id, role: "module", sourceId: root.origin.sourceId}]
|
|
370
|
+
}
|
|
371
|
+
const origins = root.origin.kind == "derived" ? root.origin.origins : root.origin.relatedOrigins
|
|
372
|
+
|
|
373
|
+
return origins.map((origin) => ({...origin, nodeId: origin.nodeId ?? root.id, role: origin.role ?? "module"}))
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Preserves an already validated Go identifier.
|
|
378
|
+
* @param {string} name Identifier.
|
|
379
|
+
* @returns {string} Unchanged spelling.
|
|
380
|
+
*/
|
|
381
|
+
function identity(name) {
|
|
382
|
+
return name
|
|
383
|
+
}
|
|
@@ -4,6 +4,10 @@ import {unsupportedCapability} from "../diagnostic.js"
|
|
|
4
4
|
|
|
5
5
|
/** @type {Record<import("../semantic/types.js").SemanticLanguage, RegExp>} */
|
|
6
6
|
const identifierPatterns = {
|
|
7
|
+
cpp: /^[A-Za-z][A-Za-z0-9_]*$/u,
|
|
8
|
+
c: /^[A-Za-z][A-Za-z0-9_]*$/u,
|
|
9
|
+
csharp: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
10
|
+
go: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
7
11
|
java: /^[A-Za-z_$][A-Za-z0-9_$]*$/u,
|
|
8
12
|
javascript: /^[A-Za-z_$][A-Za-z0-9_$]*$/u,
|
|
9
13
|
php: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
@@ -14,6 +18,51 @@ const identifierPatterns = {
|
|
|
14
18
|
|
|
15
19
|
/** @type {Record<import("../semantic/types.js").SemanticLanguage, Set<string>>} */
|
|
16
20
|
const reservedWords = {
|
|
21
|
+
cpp: new Set([
|
|
22
|
+
"alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "std", "string", "numeric_limits",
|
|
23
|
+
// The qualified libstdc++ <string> include chain also exposes these global names.
|
|
24
|
+
"WEOF", "wint_t"
|
|
25
|
+
]),
|
|
26
|
+
c: new Set([
|
|
27
|
+
"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern",
|
|
28
|
+
"float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short", "signed",
|
|
29
|
+
"sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while",
|
|
30
|
+
"bool", "true", "false", "TRUE", "FALSE", "int64_t", "uint64_t", "size_t", "ptrdiff_t", "main", "NULL", "INT64_C", "UINT64_C",
|
|
31
|
+
"INT64_MIN", "INT64_MAX", "PTRDIFF_MAX", "CHAR_BIT", "stdin", "stdout", "stderr", "malloc", "free", "exit",
|
|
32
|
+
"fwrite", "fflush", "memcpy", "memcmp", "FILE", "fpos_t", "div_t", "ldiv_t", "lldiv_t", "wchar_t", "max_align_t",
|
|
33
|
+
"offsetof", "alignas", "alignof", "noreturn", "true", "false", "assert", "static_assert", "errno",
|
|
34
|
+
"EOF", "BUFSIZ", "FOPEN_MAX", "FILENAME_MAX", "L_tmpnam", "SEEK_CUR", "SEEK_END", "SEEK_SET", "TMP_MAX",
|
|
35
|
+
"EXIT_FAILURE", "EXIT_SUCCESS", "MB_CUR_MAX", "MB_LEN_MAX", "RAND_MAX",
|
|
36
|
+
"remove", "rename", "tmpfile", "tmpnam", "fclose", "fopen", "freopen", "setbuf", "setvbuf",
|
|
37
|
+
"fprintf", "fscanf", "printf", "scanf", "snprintf", "sprintf", "sscanf", "vfprintf", "vfscanf", "vprintf",
|
|
38
|
+
"vscanf", "vsnprintf", "vsprintf", "vsscanf", "fgetc", "fgets", "fputc", "fputs", "getc", "getchar",
|
|
39
|
+
"putc", "putchar", "puts", "ungetc", "fread", "fgetpos", "fseek", "fsetpos", "ftell", "rewind", "clearerr",
|
|
40
|
+
"feof", "ferror", "perror", "atof", "atoi", "atol", "atoll", "strtod", "strtof", "strtold", "strtol",
|
|
41
|
+
"strtoll", "strtoul", "strtoull", "rand", "srand", "aligned_alloc", "calloc", "realloc", "abort", "atexit",
|
|
42
|
+
"at_quick_exit", "quick_exit", "getenv", "system", "bsearch", "qsort", "abs", "labs", "llabs", "div", "ldiv",
|
|
43
|
+
"lldiv", "mblen", "mbtowc", "wctomb", "mbstowcs", "wcstombs", "memmove", "strcpy", "strncpy", "strcat",
|
|
44
|
+
"strncat", "strcmp", "strcoll", "strncmp", "strxfrm", "memchr", "strchr", "strcspn", "strpbrk", "strrchr",
|
|
45
|
+
"strspn", "strstr", "strtok", "memset", "strerror", "strlen"
|
|
46
|
+
]),
|
|
47
|
+
csharp: new Set([
|
|
48
|
+
"__arglist", "__makeref", "__reftype", "__refvalue", "abstract", "add", "alias", "allows", "and", "as",
|
|
49
|
+
"ascending", "async", "await", "base", "bool", "break",
|
|
50
|
+
"by", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default",
|
|
51
|
+
"delegate", "descending", "do", "double", "dynamic", "else", "enum", "equals", "event", "explicit", "extension", "extern",
|
|
52
|
+
"false", "field", "file", "finally", "fixed", "float", "for", "foreach", "from", "get", "global", "goto",
|
|
53
|
+
"group", "if", "implicit", "in", "init", "int", "interface", "internal", "into", "is", "join", "let", "lock",
|
|
54
|
+
"long", "managed", "nameof", "namespace", "new", "nint", "not", "notnull", "null", "nuint", "object", "on",
|
|
55
|
+
"operator", "or", "orderby", "out", "override", "params", "partial", "private", "protected", "public", "readonly",
|
|
56
|
+
"record", "ref", "remove", "required", "return", "sbyte", "scoped", "sealed", "select", "set", "short", "sizeof",
|
|
57
|
+
"stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong",
|
|
58
|
+
"unchecked", "unmanaged", "unsafe", "ushort", "using", "value", "var", "virtual", "void", "volatile", "when",
|
|
59
|
+
"where", "while", "with", "yield"
|
|
60
|
+
]),
|
|
61
|
+
go: new Set([
|
|
62
|
+
"_", "break", "default", "func", "interface", "select", "case", "defer", "go", "map", "struct", "chan",
|
|
63
|
+
"else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", "continue", "for",
|
|
64
|
+
"import", "return", "var"
|
|
65
|
+
]),
|
|
17
66
|
java: new Set([
|
|
18
67
|
"_", "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
|
|
19
68
|
"default", "do", "double", "else", "enum", "exports", "extends", "false", "final", "finally", "float", "for",
|
|
@@ -81,11 +130,24 @@ export function validateTargetIdentifier(language, name, role, location) {
|
|
|
81
130
|
const reservedName = language == "php" ? name.toLowerCase() : name
|
|
82
131
|
|
|
83
132
|
if (!identifierPatterns[language].test(name) || reservedWords[language].has(reservedName) ||
|
|
84
|
-
language == "python" && name.normalize("NFKC") != name
|
|
133
|
+
language == "python" && name.normalize("NFKC") != name ||
|
|
134
|
+
language == "c" && !isCIdentifier(name) ||
|
|
135
|
+
language == "cpp" && !isCppIdentifier(name)) {
|
|
85
136
|
unsupportedCapability(language, `${role} identifier '${name}'`, location)
|
|
86
137
|
}
|
|
87
138
|
}
|
|
88
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Protects the exact C header environment and implementation-reserved namespace in either direction.
|
|
142
|
+
* @param {string} name - Caller identifier.
|
|
143
|
+
* @returns {boolean} Whether the spelling is safe in the canonical translation unit.
|
|
144
|
+
*/
|
|
145
|
+
export function isCIdentifier(name) {
|
|
146
|
+
return identifierPatterns.c.test(name) && !reservedWords.c.has(name) &&
|
|
147
|
+
!/^(?:semantifold_|SEMANTIFOLD_|Semantifold|atomic_|INT[0-9_A-Z]|UINT[0-9_A-Z]|INTMAX_|UINTMAX_|SIZE_|PTRDIFF_|SIG_ATOMIC_|WCHAR_|WINT_|CHAR_|SCHAR_|UCHAR_|SHRT_|USHRT_|LONG_|ULONG_|LLONG_|ULLONG_)/u.test(name) &&
|
|
148
|
+
!/^(?:u?int(?:8|16|32|64|max|ptr|_least[0-9]+|_fast[0-9]+)_t)$/u.test(name)
|
|
149
|
+
}
|
|
150
|
+
|
|
89
151
|
/**
|
|
90
152
|
* Validates a binding identifier against target restrictions beyond general identifier syntax.
|
|
91
153
|
* @param {import("../semantic/types.js").SemanticLanguage} language - Target language.
|
|
@@ -107,3 +169,12 @@ export function validateTargetBindingIdentifier(language, name, role, location)
|
|
|
107
169
|
unsupportedCapability(language, `${role} identifier '${name}'`, location)
|
|
108
170
|
}
|
|
109
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Protects C++ keywords, the actual included C library names/macros and the scaffold namespace.
|
|
175
|
+
* @param {string} name - Caller scalar binding or function name.
|
|
176
|
+
* @returns {boolean} Whether a canonical C++20 translation unit can represent the name.
|
|
177
|
+
*/
|
|
178
|
+
export function isCppIdentifier(name) {
|
|
179
|
+
return isCIdentifier(name) && !name.includes("__") && !reservedWords.cpp.has(name)
|
|
180
|
+
}
|
package/src/backends/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {unsupportedCapability, unsupportedRole} from "../diagnostic.js"
|
|
4
4
|
import {isValidFilenameMetadata} from "../artifact-path.js"
|
|
5
5
|
import {languageRegistry} from "../language-registry.js"
|
|
6
|
+
import {validateNativeGraph} from "./native-validation.js"
|
|
6
7
|
import {validateBackendModule} from "./shared.js"
|
|
7
8
|
import {SourceWriter} from "./writer.js"
|
|
8
9
|
import {finalizeMapping, toSourceMapV3} from "../mapping.js"
|
|
@@ -37,14 +38,20 @@ export function generateArtifactSource({language, filename, mapDirective = "none
|
|
|
37
38
|
if (record.artifactMultiplicity != "single") unsupportedRole(language, "single-text backend", module?.location)
|
|
38
39
|
if (filename === undefined) filename = record.defaultFilename
|
|
39
40
|
if (sourceMapFilename === undefined) sourceMapFilename = `${filename}.map`
|
|
41
|
+
if (language == "cpp") validateNativeGraph(module, "cpp")
|
|
40
42
|
validateBackendModule(module, language)
|
|
41
43
|
|
|
44
|
+
if (language == "cpp" && (mapDirective != "none" || sourceMapFilename != "program.cpp.map")) {
|
|
45
|
+
unsupportedCapability(language, "CPP map directive or alternate source-map filename", module.location)
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
if (!isValidFilenameMetadata(filename)) {
|
|
43
49
|
throw new TypeError("Generated filename must be a non-empty single-line string.")
|
|
44
50
|
}
|
|
45
51
|
if (!isValidFilenameMetadata(sourceMapFilename)) {
|
|
46
52
|
throw new TypeError("Source map filename must be a non-empty single-line string.")
|
|
47
53
|
}
|
|
54
|
+
if (language == "cpp" && filename != "program.cpp") unsupportedCapability(language, "artifact filename other than program.cpp", module.location)
|
|
48
55
|
if (language == "java" && filename.split(/[\\/]/u).at(-1) != "Main.java") {
|
|
49
56
|
unsupportedCapability(language, "artifact filename basename other than Main.java", module.location)
|
|
50
57
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {unsupportedCapability} from "../diagnostic.js"
|
|
4
|
+
|
|
5
|
+
/** @typedef {import("../semantic/types.js").SourceLocation} SourceLocation */
|
|
6
|
+
|
|
7
|
+
const semanticEdges = new Set(["functions", "entryPoint", "body", "parameters", "returnType", "statements", "condition",
|
|
8
|
+
"consequent", "alternate", "type", "target", "initializer", "expression", "operand", "left", "right", "arguments"])
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Bounds a native occurrence plan and rejects cycles before recursive shared validation.
|
|
12
|
+
* @param {unknown} module - Untrusted backend request.
|
|
13
|
+
* @param {"c" | "cpp"} [language] - Native backend diagnostic language.
|
|
14
|
+
* @returns {void}
|
|
15
|
+
*/
|
|
16
|
+
export function validateNativeGraph(module, language = "c") {
|
|
17
|
+
const active = new Set()
|
|
18
|
+
const weights = new Map()
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Counts expanded semantic occurrences while memoizing shared objects.
|
|
22
|
+
* @param {unknown} value - Candidate semantic value.
|
|
23
|
+
* @param {number} depth - Traversal depth.
|
|
24
|
+
* @returns {number} Bounded expanded weight.
|
|
25
|
+
*/
|
|
26
|
+
function visit(value, depth) {
|
|
27
|
+
if (!value || typeof value != "object") return 0
|
|
28
|
+
const location = /** @type {{location?: SourceLocation}} */ (value).location
|
|
29
|
+
const kind = /** @type {{kind?: string}} */ (value).kind
|
|
30
|
+
|
|
31
|
+
if (!Array.isArray(value) && (kind != "TypeReference" || "location" in value) && !validLocation(location)) {
|
|
32
|
+
unsupportedCapability(language, "missing or invalid semantic location", undefined)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (depth > 512 || active.has(value)) unsupportedCapability(language, "cyclic or excessively nested semantic graph", location)
|
|
36
|
+
if (weights.has(value)) return weights.get(value)
|
|
37
|
+
active.add(value)
|
|
38
|
+
let size = 1
|
|
39
|
+
const children = Array.isArray(value) ? value : Object.entries(value).filter(([key]) => semanticEdges.has(key)).map(([, child]) => child)
|
|
40
|
+
|
|
41
|
+
for (const child of children) {
|
|
42
|
+
size += visit(child, depth + 1)
|
|
43
|
+
if (size > 999999) unsupportedCapability(language, "expanded native occurrence plan exceeds six-digit capacity", location)
|
|
44
|
+
}
|
|
45
|
+
active.delete(value)
|
|
46
|
+
weights.set(value, size)
|
|
47
|
+
return size
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
visit(module, 0)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checks required semantic coordinates before the provenance writer reads them.
|
|
55
|
+
* @param {SourceLocation | undefined} location - Candidate origin.
|
|
56
|
+
* @returns {boolean} Whether it is a complete ordered UTF-16 range.
|
|
57
|
+
*/
|
|
58
|
+
function validLocation(location) {
|
|
59
|
+
return Boolean(location && typeof location.filename == "string" && location.filename.length > 0 &&
|
|
60
|
+
[location.start, location.end].every((point) => point && Number.isSafeInteger(point.offset) && point.offset >= 0 &&
|
|
61
|
+
Number.isSafeInteger(point.line) && point.line >= 1 && Number.isSafeInteger(point.column) && point.column >= 1) &&
|
|
62
|
+
location.end.offset >= location.start.offset && location.end.line >= location.start.line &&
|
|
63
|
+
(location.end.line != location.start.line || location.end.column >= location.start.column))
|
|
64
|
+
}
|