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.
Files changed (356) hide show
  1. package/README.md +37 -12
  2. package/build/index.js +2 -2
  3. package/build/src/acceptance.d.ts +10 -0
  4. package/build/src/acceptance.d.ts.map +1 -1
  5. package/build/src/acceptance.js +24 -5
  6. package/build/src/backends/c-runtime.d.ts +3 -0
  7. package/build/src/backends/c-runtime.d.ts.map +1 -0
  8. package/build/src/backends/c-runtime.js +151 -0
  9. package/build/src/backends/c-validation.d.ts +12 -0
  10. package/build/src/backends/c-validation.d.ts.map +1 -0
  11. package/build/src/backends/c-validation.js +85 -0
  12. package/build/src/backends/c.d.ts +31 -0
  13. package/build/src/backends/c.d.ts.map +1 -0
  14. package/build/src/backends/c.js +308 -0
  15. package/build/src/backends/cpp-runtime.d.ts +3 -0
  16. package/build/src/backends/cpp-runtime.d.ts.map +1 -0
  17. package/build/src/backends/cpp-runtime.js +99 -0
  18. package/build/src/backends/cpp-validation.d.ts +9 -0
  19. package/build/src/backends/cpp-validation.d.ts.map +1 -0
  20. package/build/src/backends/cpp-validation.js +74 -0
  21. package/build/src/backends/cpp.d.ts +16 -0
  22. package/build/src/backends/cpp.d.ts.map +1 -0
  23. package/build/src/backends/cpp.js +285 -0
  24. package/build/src/backends/csharp.d.ts +20 -0
  25. package/build/src/backends/csharp.d.ts.map +1 -0
  26. package/build/src/backends/csharp.js +259 -0
  27. package/build/src/backends/go.d.ts +20 -0
  28. package/build/src/backends/go.d.ts.map +1 -0
  29. package/build/src/backends/go.js +374 -0
  30. package/build/src/backends/identifiers.d.ts +12 -0
  31. package/build/src/backends/identifiers.d.ts.map +1 -1
  32. package/build/src/backends/identifiers.js +71 -2
  33. package/build/src/backends/index.d.ts.map +1 -1
  34. package/build/src/backends/index.js +9 -1
  35. package/build/src/backends/native-validation.d.ts +9 -0
  36. package/build/src/backends/native-validation.d.ts.map +1 -0
  37. package/build/src/backends/native-validation.js +59 -0
  38. package/build/src/backends/ordered-expressions.d.ts +74 -0
  39. package/build/src/backends/ordered-expressions.d.ts.map +1 -0
  40. package/build/src/backends/ordered-expressions.js +159 -0
  41. package/build/src/backends/scalars.d.ts.map +1 -1
  42. package/build/src/backends/scalars.js +7 -2
  43. package/build/src/backends/shared.d.ts.map +1 -1
  44. package/build/src/backends/shared.js +59 -14
  45. package/build/src/frontends/c-parser.d.ts +20 -0
  46. package/build/src/frontends/c-parser.d.ts.map +1 -0
  47. package/build/src/frontends/c-parser.js +14 -0
  48. package/build/src/frontends/c.d.ts +220 -0
  49. package/build/src/frontends/c.d.ts.map +1 -0
  50. package/build/src/frontends/c.js +750 -0
  51. package/build/src/frontends/cpp-parser.d.ts +11 -0
  52. package/build/src/frontends/cpp-parser.d.ts.map +1 -0
  53. package/build/src/frontends/cpp-parser.js +15 -0
  54. package/build/src/frontends/cpp.d.ts +227 -0
  55. package/build/src/frontends/cpp.d.ts.map +1 -0
  56. package/build/src/frontends/cpp.js +784 -0
  57. package/build/src/frontends/csharp.d.ts +14 -0
  58. package/build/src/frontends/csharp.d.ts.map +1 -0
  59. package/build/src/frontends/csharp.js +708 -0
  60. package/build/src/frontends/go.d.ts +15 -0
  61. package/build/src/frontends/go.d.ts.map +1 -0
  62. package/build/src/frontends/go.js +712 -0
  63. package/build/src/frontends/scalars.d.ts.map +1 -1
  64. package/build/src/frontends/scalars.js +16 -1
  65. package/build/src/language-registry.d.ts.map +1 -1
  66. package/build/src/language-registry.js +51 -2
  67. package/build/src/mapping.js +2 -2
  68. package/build/src/semantic/provenance.js +3 -3
  69. package/build/src/semantic/types.d.ts +4 -4
  70. package/build/src/semantic/types.d.ts.map +1 -1
  71. package/build/src/semantic/types.js +3 -3
  72. package/build/src/subprocess.d.ts +10 -1
  73. package/build/src/subprocess.d.ts.map +1 -1
  74. package/build/src/subprocess.js +29 -3
  75. package/build/src/toolchains.d.ts +24 -0
  76. package/build/src/toolchains.d.ts.map +1 -1
  77. package/build/src/toolchains.js +6 -2
  78. package/docs/architecture.md +20 -6
  79. package/docs/c.md +60 -0
  80. package/docs/cpp.md +61 -0
  81. package/docs/goals.md +4 -2
  82. package/docs/language-support.md +27 -8
  83. package/docs/parser-qualification.md +153 -4
  84. package/docs/plans/2026-09-05-standard-library-portability.md +46 -0
  85. package/docs/source-maps.md +11 -5
  86. package/docs/standard-library-portability.md +190 -0
  87. package/docs/testing.md +113 -4
  88. package/index.js +1 -1
  89. package/node_modules/node-addon-api/LICENSE.md +9 -0
  90. package/node_modules/node-addon-api/README.md +95 -0
  91. package/node_modules/node-addon-api/common.gypi +21 -0
  92. package/node_modules/node-addon-api/except.gypi +25 -0
  93. package/node_modules/node-addon-api/index.js +14 -0
  94. package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
  95. package/node_modules/node-addon-api/napi-inl.h +7250 -0
  96. package/node_modules/node-addon-api/napi.h +3463 -0
  97. package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
  98. package/node_modules/node-addon-api/node_api.gyp +9 -0
  99. package/node_modules/node-addon-api/noexcept.gypi +26 -0
  100. package/node_modules/node-addon-api/nothing.c +0 -0
  101. package/node_modules/node-addon-api/package-support.json +21 -0
  102. package/node_modules/node-addon-api/package.json +481 -0
  103. package/node_modules/node-addon-api/tools/README.md +73 -0
  104. package/node_modules/node-addon-api/tools/check-napi.js +99 -0
  105. package/node_modules/node-addon-api/tools/clang-format.js +71 -0
  106. package/node_modules/node-addon-api/tools/conversion.js +301 -0
  107. package/node_modules/node-gyp-build/LICENSE +21 -0
  108. package/node_modules/node-gyp-build/README.md +58 -0
  109. package/node_modules/node-gyp-build/SECURITY.md +5 -0
  110. package/node_modules/node-gyp-build/bin.js +84 -0
  111. package/node_modules/node-gyp-build/build-test.js +19 -0
  112. package/node_modules/node-gyp-build/index.js +6 -0
  113. package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
  114. package/node_modules/node-gyp-build/optional.js +7 -0
  115. package/node_modules/node-gyp-build/package.json +43 -0
  116. package/node_modules/semantifold-tree-sitter-legacy-internal/LICENSE +15 -0
  117. package/node_modules/semantifold-tree-sitter-legacy-internal/README.md +7 -0
  118. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/LICENSE +21 -0
  119. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/README.md +90 -0
  120. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/binding.gyp +79 -0
  121. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/index.js +895 -0
  122. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/package.json +62 -0
  123. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
  124. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
  125. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
  126. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
  127. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/addon_data.h +47 -0
  128. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/binding.cc +35 -0
  129. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.cc +140 -0
  130. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/conversions.h +22 -0
  131. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.cc +106 -0
  132. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/language.h +17 -0
  133. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.cc +70 -0
  134. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/logger.h +19 -0
  135. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
  136. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
  137. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.cc +1056 -0
  138. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/node.h +30 -0
  139. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.cc +298 -0
  140. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/parser.h +35 -0
  141. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.cc +383 -0
  142. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/query.h +39 -0
  143. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.cc +307 -0
  144. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree.h +45 -0
  145. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
  146. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/src/tree_cursor.h +52 -0
  147. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/tree-sitter.d.ts +211 -0
  148. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1266 -0
  149. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
  150. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
  151. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +290 -0
  152. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
  153. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
  154. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
  155. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
  156. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
  157. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
  158. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +221 -0
  159. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +299 -0
  160. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
  161. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +419 -0
  162. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
  163. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +14 -0
  164. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +774 -0
  165. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2151 -0
  166. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +230 -0
  167. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
  168. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4134 -0
  169. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
  170. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
  171. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
  172. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
  173. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1060 -0
  174. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +382 -0
  175. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +165 -0
  176. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
  177. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +714 -0
  178. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
  179. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
  180. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
  181. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
  182. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
  183. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
  184. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
  185. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
  186. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
  187. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
  188. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +50 -0
  189. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +23 -0
  190. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
  191. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1294 -0
  192. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1823 -0
  193. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
  194. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/LICENSE +21 -0
  195. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/README.md +18 -0
  196. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/binding.gyp +29 -0
  197. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding.cc +20 -0
  198. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/binding_test.js +9 -0
  199. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.d.ts +28 -0
  200. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/bindings/node/index.js +11 -0
  201. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/grammar.js +1470 -0
  202. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/package.json +60 -0
  203. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-arm64/tree-sitter-c.node +0 -0
  204. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/darwin-x64/tree-sitter-c.node +0 -0
  205. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-arm64/tree-sitter-c.node +0 -0
  206. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/linux-x64/tree-sitter-c.node +0 -0
  207. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-arm64/tree-sitter-c.node +0 -0
  208. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/prebuilds/win32-x64/tree-sitter-c.node +0 -0
  209. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/highlights.scm +81 -0
  210. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/queries/tags.scm +9 -0
  211. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/grammar.json +9735 -0
  212. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/node-types.json +4614 -0
  213. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/parser.c +119615 -0
  214. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/alloc.h +54 -0
  215. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/array.h +290 -0
  216. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/src/tree_sitter/parser.h +266 -0
  217. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter-c.wasm +0 -0
  218. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-c/tree-sitter.json +43 -0
  219. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/LICENSE +21 -0
  220. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/README.md +22 -0
  221. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/binding.gyp +30 -0
  222. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding.cc +20 -0
  223. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/binding_test.js +9 -0
  224. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.d.ts +28 -0
  225. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/bindings/node/index.js +11 -0
  226. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/grammar.js +1436 -0
  227. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/package.json +61 -0
  228. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-arm64/tree-sitter-cpp.node +0 -0
  229. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/darwin-x64/tree-sitter-cpp.node +0 -0
  230. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-arm64/tree-sitter-cpp.node +0 -0
  231. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/linux-x64/tree-sitter-cpp.node +0 -0
  232. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-arm64/tree-sitter-cpp.node +0 -0
  233. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/prebuilds/win32-x64/tree-sitter-cpp.node +0 -0
  234. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/highlights.scm +70 -0
  235. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/injections.scm +3 -0
  236. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/queries/tags.scm +15 -0
  237. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/grammar.json +17084 -0
  238. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/node-types.json +7997 -0
  239. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/parser.c +530368 -0
  240. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/scanner.c +148 -0
  241. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/alloc.h +54 -0
  242. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/array.h +290 -0
  243. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/src/tree_sitter/parser.h +266 -0
  244. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter-cpp.wasm +0 -0
  245. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-cpp/tree-sitter.json +55 -0
  246. package/node_modules/semantifold-tree-sitter-legacy-internal/package.json +22 -0
  247. package/node_modules/semantifold-tree-sitter-legacy-internal/src/c.js +152 -0
  248. package/node_modules/tree-sitter/LICENSE +21 -0
  249. package/node_modules/tree-sitter/README.md +128 -0
  250. package/node_modules/tree-sitter/binding.gyp +88 -0
  251. package/node_modules/tree-sitter/index.js +950 -0
  252. package/node_modules/tree-sitter/package.json +76 -0
  253. package/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
  254. package/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
  255. package/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
  256. package/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
  257. package/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
  258. package/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
  259. package/node_modules/tree-sitter/src/addon_data.h +47 -0
  260. package/node_modules/tree-sitter/src/binding.cc +35 -0
  261. package/node_modules/tree-sitter/src/conversions.cc +140 -0
  262. package/node_modules/tree-sitter/src/conversions.h +22 -0
  263. package/node_modules/tree-sitter/src/language.cc +105 -0
  264. package/node_modules/tree-sitter/src/language.h +17 -0
  265. package/node_modules/tree-sitter/src/logger.cc +70 -0
  266. package/node_modules/tree-sitter/src/logger.h +19 -0
  267. package/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
  268. package/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
  269. package/node_modules/tree-sitter/src/node.cc +1088 -0
  270. package/node_modules/tree-sitter/src/node.h +30 -0
  271. package/node_modules/tree-sitter/src/parser.cc +332 -0
  272. package/node_modules/tree-sitter/src/parser.h +35 -0
  273. package/node_modules/tree-sitter/src/query.cc +425 -0
  274. package/node_modules/tree-sitter/src/query.h +40 -0
  275. package/node_modules/tree-sitter/src/tree.cc +316 -0
  276. package/node_modules/tree-sitter/src/tree.h +45 -0
  277. package/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
  278. package/node_modules/tree-sitter/src/tree_cursor.h +52 -0
  279. package/node_modules/tree-sitter/tree-sitter.d.ts +1083 -0
  280. package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1478 -0
  281. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
  282. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
  283. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
  284. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
  285. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
  286. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
  287. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +523 -0
  288. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
  289. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
  290. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +293 -0
  291. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +293 -0
  292. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
  293. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +483 -0
  294. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +54 -0
  295. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
  296. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +875 -0
  297. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2297 -0
  298. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +286 -0
  299. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +48 -0
  300. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +241 -0
  301. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4347 -0
  302. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
  303. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
  304. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +912 -0
  305. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
  306. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1034 -0
  307. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
  308. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
  309. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
  310. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +716 -0
  311. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
  312. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
  313. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
  314. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
  315. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
  316. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
  317. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
  318. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
  319. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
  320. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
  321. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
  322. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +75 -0
  323. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
  324. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +137 -0
  325. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1314 -0
  326. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1937 -0
  327. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
  328. package/package.json +21 -5
  329. package/src/acceptance.js +25 -4
  330. package/src/backends/c-runtime.js +151 -0
  331. package/src/backends/c-validation.js +83 -0
  332. package/src/backends/c.js +308 -0
  333. package/src/backends/cpp-runtime.js +99 -0
  334. package/src/backends/cpp-validation.js +70 -0
  335. package/src/backends/cpp.js +285 -0
  336. package/src/backends/csharp.js +270 -0
  337. package/src/backends/go.js +383 -0
  338. package/src/backends/identifiers.js +72 -1
  339. package/src/backends/index.js +7 -0
  340. package/src/backends/native-validation.js +64 -0
  341. package/src/backends/ordered-expressions.js +161 -0
  342. package/src/backends/scalars.js +7 -1
  343. package/src/backends/shared.js +56 -12
  344. package/src/frontends/c-parser.js +17 -0
  345. package/src/frontends/c.js +780 -0
  346. package/src/frontends/cpp-parser.js +18 -0
  347. package/src/frontends/cpp.js +816 -0
  348. package/src/frontends/csharp.js +759 -0
  349. package/src/frontends/go.js +770 -0
  350. package/src/frontends/scalars.js +15 -0
  351. package/src/language-registry.js +52 -1
  352. package/src/mapping.js +1 -1
  353. package/src/semantic/provenance.js +2 -2
  354. package/src/semantic/types.js +2 -2
  355. package/src/subprocess.js +31 -2
  356. package/src/toolchains.js +5 -1
@@ -0,0 +1,285 @@
1
+ // @ts-check
2
+
3
+ import {unsupportedCapability} from "../diagnostic.js"
4
+ import {statementSignature, planNativeModule} from "./ordered-expressions.js"
5
+ import {cppRuntime} from "./cpp-runtime.js"
6
+ import {maximumCppSourceLength, validateCppValues} from "./cpp-validation.js"
7
+ import {emitScalarType} from "./scalars.js"
8
+ import {SourceWriter} from "./writer.js"
9
+
10
+ /** @typedef {import("../semantic/types.js").SemanticModule} SemanticModule */
11
+ /** @typedef {import("../semantic/types.js").SemanticNode} SemanticNode */
12
+ /** @typedef {import("../semantic/types.js").Statement} Statement */
13
+ /** @typedef {import("../semantic/types.js").Block} Block */
14
+ /** @typedef {import("./ordered-expressions.js").PlannedValue} PlannedValue */
15
+ /** @typedef {import("./ordered-expressions.js").PlannedStep} PlannedStep */
16
+ /** @typedef {import("./ordered-expressions.js").StatementPlan} StatementPlan */
17
+
18
+ const binaryTokens = new Map([
19
+ ["IntegerAdd", "semantifold_integer_add"], ["IntegerSubtract", "semantifold_integer_subtract"],
20
+ ["IntegerMultiply", "semantifold_integer_multiply"], ["StringConcat", "semantifold_string_concat"],
21
+ ["StringEqual", "semantifold_string_equal"], ["StringNotEqual", "semantifold_string_not_equal"],
22
+ ["IntegerEqual", "=="], ["IntegerNotEqual", "!="], ["BooleanEqual", "=="], ["BooleanNotEqual", "!="],
23
+ ["IntegerLessThan", "<"], ["IntegerLessThanOrEqual", "<="],
24
+ ["IntegerGreaterThan", ">"], ["IntegerGreaterThanOrEqual", ">="]
25
+ ])
26
+
27
+ /**
28
+ * Emits the one fully validated C++20 translation unit with owned by-value strings.
29
+ * @param {SemanticModule} module - Shared validated semantics.
30
+ * @param {SourceWriter} [writer] - Optional caller-owned provenance writer.
31
+ * @returns {string} Deterministic source for public generation or same-language CST validation.
32
+ */
33
+ export function generateCpp(module, writer) {
34
+ validateCppValues(module)
35
+ const plans = planNativeModule(module, "cpp")
36
+
37
+ new CppEmitter(undefined, plans, module.location).program(module)
38
+ const output = writer ?? new SourceWriter({filename: "program.cpp", language: "cpp", module})
39
+
40
+ new CppEmitter(output, plans, module.location).program(module)
41
+ return output.finish().generated.content
42
+ }
43
+
44
+ /** Writes only target syntax from validated semantic occurrences and private plans. */
45
+ class CppEmitter {
46
+ /**
47
+ * Binds the writer and complete plan.
48
+ * @param {SourceWriter | undefined} writer - Provenance writer; omitted for exact size preflight.
49
+ * @param {Map<string, StatementPlan>} plans - Validated occurrence plans.
50
+ * @param {import("../semantic/types.js").SourceLocation} location - Root diagnostic location.
51
+ */
52
+ constructor(writer, plans, location) {
53
+ this.writer = writer
54
+ this.plans = plans
55
+ this.location = location
56
+ this.length = 0
57
+ }
58
+
59
+ /**
60
+ * Writes generated scaffold with a related semantic origin.
61
+ * @param {string} text - C++ syntax.
62
+ * @param {SemanticNode} node - Related node.
63
+ * @param {string} path - Occurrence path.
64
+ * @returns {void}
65
+ */
66
+ synthetic(text, node, path) {
67
+ this.checkSize(text, node)
68
+ this.writer?.synthetic(text, "C++20 ordered-expression and lifetime scaffold", [node], [path])
69
+ }
70
+
71
+ /**
72
+ * Writes an original semantic token or anchor.
73
+ * @param {string} text - Target token.
74
+ * @param {SemanticNode} node - Original node.
75
+ * @param {string} path - Occurrence path.
76
+ * @param {string} [role] - Parser token role.
77
+ * @returns {void}
78
+ */
79
+ mapped(text, node, path, role) {
80
+ this.checkSize(text, node)
81
+ this.writer?.mapped(text, {mappingKind: role ? "exact" : "anchor", node, path, ...(role ? {role} : {})})
82
+ }
83
+
84
+ /**
85
+ * Bounds private emission before any artifact can escape the parser's proven input profile.
86
+ * @param {string} text - Next exact output chunk.
87
+ * @param {SemanticNode} node - Related semantic occurrence.
88
+ * @returns {void}
89
+ */
90
+ checkSize(text, node) {
91
+ this.length += text.length
92
+ if (this.length > maximumCppSourceLength) unsupportedCapability("cpp", "generated program exceeds the frozen CPP parser's 32767 UTF-16 input limit",
93
+ "location" in node ? node.location : this.location)
94
+ }
95
+
96
+ /**
97
+ * Emits canonical prototypes, definitions, and the parameterless main.
98
+ * @param {SemanticModule} module - Semantic module.
99
+ * @returns {void}
100
+ */
101
+ program(module) {
102
+ this.synthetic("/* semantifold:program:cpp:v1 */\n" + cppRuntime + "\n", module, "")
103
+ module.functions.forEach((declaration, index) => {
104
+ const parameters = declaration.parameters.map((parameter) => `${emitScalarType("cpp", parameter.type)} ${parameter.name}`).join(", ")
105
+
106
+ this.synthetic(`${emitScalarType("cpp", declaration.returnType)} ${declaration.name}(${parameters});\n`, declaration, `/functions/${index}`)
107
+ })
108
+ module.functions.forEach((declaration, index) => {
109
+ const path = `/functions/${index}`
110
+
111
+ this.synthetic("\n", declaration, path)
112
+ this.mapped(emitScalarType("cpp", declaration.returnType), declaration.returnType, `${path}/returnType`, "type")
113
+ this.synthetic(" ", declaration, path)
114
+ this.mapped(declaration.name, declaration, path, "name")
115
+ this.synthetic("(", declaration, path)
116
+ declaration.parameters.forEach((parameter, parameterIndex) => {
117
+ const parameterPath = `${path}/parameters/${parameterIndex}`
118
+
119
+ if (parameterIndex) this.synthetic(", ", parameter, parameterPath)
120
+ this.mapped(emitScalarType("cpp", parameter.type), parameter.type, `${parameterPath}/type`, "type")
121
+ this.synthetic(" ", parameter, parameterPath)
122
+ this.mapped(parameter.name, parameter, parameterPath, "name")
123
+ })
124
+ this.synthetic(") {\n", declaration, path)
125
+ declaration.parameters.forEach((parameter, parameterIndex) => this.synthetic(` (void)${parameter.name};\n`, parameter, `${path}/parameters/${parameterIndex}`))
126
+ this.block(declaration.body, `${path}/body`, " ")
127
+ this.synthetic("}\n", declaration, path)
128
+ })
129
+ this.synthetic("\nint main() {\n", module.entryPoint, "/entryPoint")
130
+ this.block(module.entryPoint.body, "/entryPoint/body", " ")
131
+ this.synthetic(" return 0;\n}\n", module.entryPoint, "/entryPoint")
132
+ }
133
+
134
+ /**
135
+ * Emits statements in semantic source order.
136
+ * @param {Block} block - Semantic block.
137
+ * @param {string} path - Occurrence path.
138
+ * @param {string} indent - Current indentation.
139
+ * @returns {void}
140
+ */
141
+ block(block, path, indent) {
142
+ block.statements.forEach((statement, index) => this.statement(statement, `${path}/statements/${index}`, indent))
143
+ }
144
+
145
+ /**
146
+ * Emits one paired region with a pure final consumer.
147
+ * @param {Statement} statement - Original statement.
148
+ * @param {string} path - Occurrence path.
149
+ * @param {string} indent - Current indentation.
150
+ * @returns {void}
151
+ */
152
+ statement(statement, path, indent) {
153
+ const plan = this.plans.get(path)
154
+
155
+ if (!plan) throw new Error("Missing validated C++ statement plan.")
156
+ const marker = `semantifold:ordered-expression:cpp:v1`
157
+ const signature = statementSignature(statement)
158
+
159
+ this.synthetic(`${indent}/* ${marker} begin ${plan.id} ${signature} */\n`, statement, path)
160
+ this.steps(plan.steps, indent)
161
+ this.synthetic(indent, statement, path)
162
+ if (statement.kind == "LocalDeclaration") {
163
+ if (!statement.mutable) this.synthetic("const ", statement, path)
164
+ this.mapped(emitScalarType("cpp", statement.type), statement.type, `${path}/type`, "type")
165
+ this.synthetic(" ", statement, path)
166
+ this.mapped(statement.name, statement, path, "name")
167
+ this.synthetic(" ", statement, path)
168
+ this.mapped("=", statement, path, "operator")
169
+ this.synthetic(" ", statement, path)
170
+ } else if (statement.kind == "AssignmentStatement") {
171
+ this.mapped(statement.target.name, statement.target, `${path}/target`, "name")
172
+ this.synthetic(" ", statement, path)
173
+ this.mapped("=", statement, path, "operator")
174
+ this.synthetic(" ", statement, path)
175
+ } else if (statement.kind == "ReturnStatement") this.mapped("return ", statement, path)
176
+ else if (statement.kind == "PrintStatement") this.mapped(`semantifold_print_${plan.value.type}(`, statement, path)
177
+ else this.mapped("if (", statement, path)
178
+ this.value(plan.value)
179
+ if (statement.kind == "IfStatement") {
180
+ this.synthetic(") {\n", statement, path)
181
+ this.block(statement.consequent, `${path}/consequent`, `${indent} `)
182
+ this.synthetic(`${indent}}`, statement, path)
183
+ if (statement.alternate) {
184
+ this.mapped(" else ", statement, path)
185
+ this.synthetic("{\n", statement, path)
186
+ this.block(statement.alternate, `${path}/alternate`, `${indent} `)
187
+ this.synthetic(`${indent}}`, statement, path)
188
+ }
189
+ this.synthetic("\n", statement, path)
190
+ } else {
191
+ this.synthetic(`${statement.kind == "PrintStatement" ? ")" : ""};\n`, statement, path)
192
+ if (statement.kind == "LocalDeclaration") this.synthetic(`${indent}(void)${statement.name};\n`, statement, path)
193
+ }
194
+ this.synthetic(`${indent}/* ${marker} end ${plan.id} ${signature} */\n`, statement, path)
195
+ }
196
+
197
+ /**
198
+ * Emits each eager step or conditional RHS at its planned location.
199
+ * @param {PlannedStep[]} steps - Ordered private steps.
200
+ * @param {string} indent - Current indentation.
201
+ * @returns {void}
202
+ */
203
+ steps(steps, indent) {
204
+ for (const step of steps) {
205
+ const {result, operands, rightSteps} = step
206
+ const {expression, path, name} = result
207
+ const type = emitScalarType("cpp", {kind: "TypeReference", name: result.type})
208
+
209
+ this.synthetic(`${indent}${type} ${name} = `, expression, path)
210
+ if (rightSteps) {
211
+ this.value(operands[0])
212
+ this.synthetic(`;\n${indent}if (`, expression, path)
213
+ if (expression.kind != "BinaryExpression") throw new Error("Invalid conditional C++ plan.")
214
+ this.synthetic(`${expression.operation == "BooleanOr" ? "!" : ""}${name}) {\n`, expression, path)
215
+ this.steps(rightSteps, `${indent} `)
216
+ this.synthetic(`${indent} ${name} = (${name} `, expression, path)
217
+ this.mapped(expression.operation == "BooleanOr" ? "||" : "&&", expression, path, "operator")
218
+ this.synthetic(" ", expression, path)
219
+ this.value(operands[1])
220
+ this.synthetic(`);\n${indent}}\n`, expression, path)
221
+ } else {
222
+ this.operation(step)
223
+ this.synthetic(";\n", expression, path)
224
+ }
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Emits one nontrivial operation with pure operands.
230
+ * @param {PlannedStep} step - Eager step.
231
+ * @returns {void}
232
+ */
233
+ operation({result: {expression, path}, operands}) {
234
+ if (expression.kind == "CallExpression") {
235
+ this.mapped(expression.callee, expression, path, "callee")
236
+ this.synthetic("(", expression, path)
237
+ operands.forEach((operand, index) => {
238
+ if (index) this.synthetic(", ", expression, path)
239
+ this.value(operand)
240
+ })
241
+ this.synthetic(")", expression, path)
242
+ } else if (expression.kind == "UnaryExpression") {
243
+ this.mapped(expression.operation == "IntegerNegate" ? "semantifold_integer_negate" : "!", expression, path, "operator")
244
+ this.synthetic("(", expression, path)
245
+ this.value(operands[0])
246
+ this.synthetic(")", expression, path)
247
+ } else if (expression.kind == "BinaryExpression") {
248
+ const token = binaryTokens.get(expression.operation)
249
+
250
+ if (!token) throw new Error("Unsupported operation passed C++ planning.")
251
+ const helper = token.startsWith("semantifold_")
252
+
253
+ if (helper) this.mapped(token, expression, path, "operator")
254
+ this.synthetic("(", expression, path)
255
+ this.value(operands[0])
256
+ if (helper) this.synthetic(", ", expression, path)
257
+ else {
258
+ this.synthetic(" ", expression, path)
259
+ this.mapped(token, expression, path, "operator")
260
+ this.synthetic(" ", expression, path)
261
+ }
262
+ this.value(operands[1])
263
+ this.synthetic(")", expression, path)
264
+ } else throw new Error("Pure expression was scheduled as a CPP operation.")
265
+ }
266
+
267
+ /**
268
+ * Emits a pure operand with original token provenance or a synthetic temporary use.
269
+ * @param {PlannedValue} value - Planned pure operand.
270
+ * @returns {void}
271
+ */
272
+ value({expression, path, name}) {
273
+ if (name) return this.synthetic(name, expression, path)
274
+ if (expression.kind == "IdentifierExpression") return this.mapped(expression.name, expression, path, "name")
275
+ if (expression.kind == "BooleanLiteral") return this.mapped(String(expression.value), expression, path, "literal")
276
+ if (expression.kind == "IntegerLiteral") return this.mapped(`std::int64_t(${expression.value})`, expression, path, "literal")
277
+ if (expression.kind == "StringLiteral") {
278
+ const bytes = new TextEncoder().encode(expression.value)
279
+ const literal = Array.from(bytes, (byte) => `\\${byte.toString(8).padStart(3, "0")}`).join("")
280
+
281
+ return this.mapped(`std::string("${literal}", ${bytes.length})`, expression, path, "literal")
282
+ }
283
+ throw new Error("Unsequenced expression passed C++ planning.")
284
+ }
285
+ }
@@ -0,0 +1,270 @@
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 project = `<Project Sdk="Microsoft.NET.Sdk">
10
+ <PropertyGroup>
11
+ <OutputType>Exe</OutputType>
12
+ <TargetFramework>net10.0</TargetFramework>
13
+ <LangVersion>14.0</LangVersion>
14
+ <Nullable>enable</Nullable>
15
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
16
+ <WarningLevel>10</WarningLevel>
17
+ <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
18
+ <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
19
+ <ImplicitUsings>disable</ImplicitUsings>
20
+ <EnableNETAnalyzers>false</EnableNETAnalyzers>
21
+ <InvariantGlobalization>true</InvariantGlobalization>
22
+ <PredefinedCulturesOnly>true</PredefinedCulturesOnly>
23
+ <Deterministic>true</Deterministic>
24
+ <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
25
+ <DebugType>none</DebugType>
26
+ <UseAppHost>false</UseAppHost>
27
+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
28
+ <AssemblyName>Semantifold</AssemblyName>
29
+ <RootNamespace>Semantifold.Generated</RootNamespace>
30
+ <StartupObject>Semantifold.Generated.Program</StartupObject>
31
+ <PathMap>$(MSBuildProjectDirectory)=/_/</PathMap>
32
+ </PropertyGroup>
33
+ <ItemGroup>
34
+ <Compile Include="Program.cs" />
35
+ </ItemGroup>
36
+ </Project>
37
+ `
38
+
39
+ /**
40
+ * Emits one deterministic two-file C# project candidate.
41
+ * @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.
42
+ * @returns {{artifacts: import("../semantic/types.js").GeneratedSetArtifact[], target: string}} Candidate artifact set.
43
+ */
44
+ export function generateCSharpProject({filename, mapDirective, module, sourceMapFilename, sources}) {
45
+ validateBackendModule(module, "csharp")
46
+ if (filename !== undefined && filename != "Program.cs") {
47
+ unsupportedCapability("csharp", "artifact filename other than Program.cs", module.location)
48
+ }
49
+ if (mapDirective !== undefined || sourceMapFilename !== undefined) {
50
+ unsupportedCapability("csharp", "source-map filename or directive option", module.location)
51
+ }
52
+ const writer = new SourceWriter({filename: "Program.cs", language: "csharp", module, sources})
53
+
54
+ emitProgram(module, writer)
55
+ const mapping = finalizeMapping(writer.finish())
56
+ const root = mapping.nodes.find(({path}) => path == "")
57
+
58
+ if (!root) throw new Error("Validated C# module omitted its canonical root provenance.")
59
+ return {
60
+ artifacts: [{
61
+ content: mapping.generated.content,
62
+ contentKind: "text",
63
+ mediaType: "text/x-csharp",
64
+ ownership: "generated",
65
+ path: "Program.cs",
66
+ provenance: {kind: "text", mapping, sourceMap: toSourceMapV3(mapping)},
67
+ role: "entry"
68
+ }, {
69
+ content: project,
70
+ contentKind: "text",
71
+ mediaType: "application/xml",
72
+ ownership: "generated",
73
+ path: "Semantifold.csproj",
74
+ provenance: {kind: "synthetic", reason: "Deterministic .NET 10 project manifest for the generated C# module.",
75
+ relatedOrigins: relatedRootOrigins(root)},
76
+ role: "manifest"
77
+ }],
78
+ target: "csharp"
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Emits the fixed C# file scaffold and semantic bodies.
84
+ * @param {import("../semantic/types.js").SemanticModule} module - Validated module.
85
+ * @param {SourceWriter} writer - Source-aware writer.
86
+ * @returns {void}
87
+ */
88
+ function emitProgram(module, writer) {
89
+ writer.synthetic("#nullable enable\n\nnamespace Semantifold.Generated;\n\ninternal static class Program\n{\n",
90
+ "C# nullable, namespace, and Program scaffolding", [module])
91
+ module.functions.forEach((declaration, index) => {
92
+ if (index > 0) writer.synthetic("\n", "declaration separator", [declaration])
93
+ emitFunction(writer, declaration, index)
94
+ })
95
+ writer.synthetic("\n", "entry-point separator", [module.entryPoint])
96
+ writer.synthetic(" ", "indentation", [module.entryPoint])
97
+ writer.mapped("private static void Main", {mappingKind: "anchor", node: module.entryPoint})
98
+ writer.mapped("()", {mappingKind: "anchor", node: module.entryPoint})
99
+ writer.synthetic("\n ", "line break and indentation", [module.entryPoint])
100
+ writer.mapped("{", {mappingKind: "anchor", node: module.entryPoint})
101
+ writer.synthetic("\n", "line break", [module.entryPoint])
102
+ emitBlock(writer, module.entryPoint.body, " ", "/entryPoint/body")
103
+ writer.synthetic(" ", "indentation", [module.entryPoint])
104
+ writer.mapped("}", {mappingKind: "anchor", node: module.entryPoint})
105
+ writer.synthetic("\n}\n", "C# Program scaffolding", [module])
106
+ }
107
+
108
+ /**
109
+ * Emits one private static semantic method.
110
+ * @param {SourceWriter} writer - Source-aware writer.
111
+ * @param {import("../semantic/types.js").FunctionDeclaration} declaration - Function declaration.
112
+ * @param {number} index - Function index.
113
+ * @returns {void}
114
+ */
115
+ function emitFunction(writer, declaration, index) {
116
+ const path = `/functions/${index}`
117
+
118
+ writer.synthetic(" ", "indentation", [declaration], [path])
119
+ writer.mapped("private static", {mappingKind: "anchor", node: declaration, path})
120
+ writer.synthetic(" ", "method spacing", [declaration], [path])
121
+ writer.mapped(emitScalarType("csharp", declaration.returnType), {
122
+ mappingKind: "exact", node: declaration.returnType, path: `${path}/returnType`, role: "type"
123
+ })
124
+ writer.synthetic(" ", "method spacing", [declaration], [path])
125
+ writer.mapped(declaration.name, {mappingKind: "exact", node: declaration, path, role: "name"})
126
+ writer.mapped("(", {mappingKind: "anchor", node: declaration, path})
127
+ declaration.parameters.forEach((parameter, parameterIndex) => {
128
+ const parameterPath = `${path}/parameters/${parameterIndex}`
129
+
130
+ if (parameterIndex > 0) writer.synthetic(", ", "parameter separator", [declaration], [path])
131
+ writer.mapped(emitScalarType("csharp", parameter.type), {
132
+ mappingKind: "exact", node: parameter.type, path: `${parameterPath}/type`, role: "type"
133
+ })
134
+ writer.synthetic(" ", "parameter spacing", [parameter], [parameterPath])
135
+ writer.mapped(parameter.name, {mappingKind: "exact", node: parameter, path: parameterPath, role: "name"})
136
+ })
137
+ writer.mapped(")", {mappingKind: "anchor", node: declaration, path})
138
+ writer.synthetic("\n ", "line break and indentation", [declaration], [path])
139
+ writer.mapped("{", {mappingKind: "anchor", node: declaration.body, path: `${path}/body`})
140
+ writer.synthetic("\n", "line break", [declaration], [path])
141
+ emitBlock(writer, declaration.body, " ", `${path}/body`)
142
+ writer.synthetic(" ", "indentation", [declaration], [path])
143
+ writer.mapped("}", {mappingKind: "anchor", node: declaration, path})
144
+ writer.synthetic("\n", "line break", [declaration], [path])
145
+ }
146
+
147
+ /**
148
+ * Emits one ordered semantic block.
149
+ * @param {SourceWriter} writer - Source-aware writer.
150
+ * @param {import("../semantic/types.js").Block} block - Semantic block.
151
+ * @param {string} indent - Current indentation.
152
+ * @param {string} path - Exact semantic path.
153
+ * @returns {void}
154
+ */
155
+ function emitBlock(writer, block, indent, path) {
156
+ block.statements.forEach((statement, index) => emitStatement(writer, statement, indent, `${path}/statements/${index}`))
157
+ }
158
+
159
+ /**
160
+ * Emits one supported C# statement.
161
+ * @param {SourceWriter} writer - Source-aware writer.
162
+ * @param {import("../semantic/types.js").Statement} statement - Semantic statement.
163
+ * @param {string} indent - Current indentation.
164
+ * @param {string} path - Exact semantic path.
165
+ * @returns {void}
166
+ */
167
+ function emitStatement(writer, statement, indent, path) {
168
+ if (statement.kind == "LocalDeclaration" || statement.kind == "AssignmentStatement") {
169
+ return emitLocal(writer, statement, indent, path)
170
+ }
171
+ writer.synthetic(indent, "indentation", [statement], [path])
172
+ if (statement.kind == "ReturnStatement") {
173
+ writer.mapped("return", {mappingKind: "anchor", node: statement, path})
174
+ writer.synthetic(" ", "return spacing", [statement], [path])
175
+ emitExpression(writer, statement.expression, `${path}/expression`, "csharp", identity)
176
+ writer.mapped(";", {mappingKind: "anchor", node: statement, path})
177
+ writer.synthetic("\n", "line break", [statement], [path])
178
+ return
179
+ }
180
+ if (statement.kind == "PrintStatement") {
181
+ writer.mapped("System.Console.WriteLine", {mappingKind: "anchor", node: statement, path})
182
+ writer.mapped("(", {mappingKind: "anchor", node: statement, path})
183
+ emitExpression(writer, statement.expression, `${path}/expression`, "csharp", identity)
184
+ writer.mapped(");", {mappingKind: "anchor", node: statement, path})
185
+ writer.synthetic("\n", "line break", [statement], [path])
186
+ return
187
+ }
188
+ writer.mapped("if", {mappingKind: "anchor", node: statement, path})
189
+ writer.synthetic(" ", "conditional spacing", [statement], [path])
190
+ writer.mapped("(", {mappingKind: "anchor", node: statement, path})
191
+ emitExpression(writer, statement.condition, `${path}/condition`, "csharp", identity)
192
+ writer.mapped(")", {mappingKind: "anchor", node: statement, path})
193
+ writer.synthetic("\n", "line break", [statement], [path])
194
+ writer.synthetic(indent, "indentation", [statement], [path])
195
+ writer.mapped("{", {mappingKind: "anchor", node: statement.consequent, path: `${path}/consequent`})
196
+ writer.synthetic("\n", "line break", [statement], [path])
197
+ emitBlock(writer, statement.consequent, `${indent} `, `${path}/consequent`)
198
+ writer.synthetic(indent, "indentation", [statement], [path])
199
+ writer.mapped("}", {mappingKind: "anchor", node: statement.consequent, path: `${path}/consequent`})
200
+ if (statement.alternate) {
201
+ writer.synthetic("\n", "line break", [statement], [path])
202
+ writer.synthetic(indent, "indentation", [statement], [path])
203
+ writer.mapped("else", {mappingKind: "anchor", node: statement, path})
204
+ writer.synthetic("\n", "line break", [statement], [path])
205
+ writer.synthetic(indent, "indentation", [statement], [path])
206
+ writer.mapped("{", {mappingKind: "anchor", node: statement.alternate, path: `${path}/alternate`})
207
+ writer.synthetic("\n", "line break", [statement], [path])
208
+ emitBlock(writer, statement.alternate, `${indent} `, `${path}/alternate`)
209
+ writer.synthetic(indent, "indentation", [statement], [path])
210
+ writer.mapped("}", {mappingKind: "anchor", node: statement.alternate, path: `${path}/alternate`})
211
+ }
212
+ writer.synthetic("\n", "line break", [statement], [path])
213
+ }
214
+
215
+ /**
216
+ * Emits one local declaration or assignment.
217
+ * @param {SourceWriter} writer - Source-aware writer.
218
+ * @param {import("../semantic/types.js").LocalStatement} statement - Local statement.
219
+ * @param {string} indent - Current indentation.
220
+ * @param {string} path - Exact semantic path.
221
+ * @returns {void}
222
+ */
223
+ function emitLocal(writer, statement, indent, path) {
224
+ if (statement.kind == "LocalDeclaration" && !statement.mutable) {
225
+ writer.synthetic(`${indent}// @semantifold-immutable\n`, "C# immutable-local carrier", [statement], [path])
226
+ }
227
+ writer.synthetic(indent, "indentation", [statement], [path])
228
+ if (statement.kind == "AssignmentStatement") {
229
+ writer.mapped(statement.target.name, {mappingKind: "exact", node: statement.target, path: `${path}/target`, role: "name"})
230
+ writer.synthetic(" ", "assignment spacing", [statement], [path])
231
+ writer.mapped("=", {mappingKind: "exact", node: statement, path, role: "operator"})
232
+ writer.synthetic(" ", "assignment spacing", [statement], [path])
233
+ emitExpression(writer, statement.expression, `${path}/expression`, "csharp", identity)
234
+ } else {
235
+ writer.mapped(emitScalarType("csharp", statement.type), {
236
+ mappingKind: "exact", node: statement.type, path: `${path}/type`, role: "type"
237
+ })
238
+ writer.synthetic(" ", "declaration spacing", [statement], [path])
239
+ writer.mapped(statement.name, {mappingKind: "exact", node: statement, path, role: "name"})
240
+ writer.synthetic(" ", "assignment spacing", [statement], [path])
241
+ writer.mapped("=", {mappingKind: "exact", node: statement, path, role: "operator"})
242
+ writer.synthetic(" ", "assignment spacing", [statement], [path])
243
+ emitExpression(writer, statement.initializer, `${path}/initializer`, "csharp", identity)
244
+ }
245
+ writer.mapped(";", {mappingKind: "anchor", node: statement, path})
246
+ writer.synthetic("\n", "line break", [statement], [path])
247
+ }
248
+
249
+ /**
250
+ * Converts canonical module-root provenance to artifact-level related origins.
251
+ * @param {import("../semantic/types.js").SemanticNodeProvenance} root - Canonical root provenance.
252
+ * @returns {import("../semantic/types.js").RelatedOrigin[]} Related module origins.
253
+ */
254
+ function relatedRootOrigins(root) {
255
+ if (root.origin.kind == "source") {
256
+ return [{location: root.origin.location, nodeId: root.id, role: "module", sourceId: root.origin.sourceId}]
257
+ }
258
+ const origins = root.origin.kind == "derived" ? root.origin.origins : root.origin.relatedOrigins
259
+
260
+ return origins.map((origin) => ({...origin, nodeId: origin.nodeId ?? root.id, role: origin.role ?? "module"}))
261
+ }
262
+
263
+ /**
264
+ * Preserves an already validated C# identifier spelling.
265
+ * @param {string} name - Identifier.
266
+ * @returns {string} Unchanged identifier.
267
+ */
268
+ function identity(name) {
269
+ return name
270
+ }