@gtkx/codegen 0.21.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 (340) hide show
  1. package/LICENSE +373 -0
  2. package/dist/dsl/context.d.ts +104 -0
  3. package/dist/dsl/context.d.ts.map +1 -0
  4. package/dist/dsl/context.js +140 -0
  5. package/dist/dsl/context.js.map +1 -0
  6. package/dist/dsl/emit.d.ts +28 -0
  7. package/dist/dsl/emit.d.ts.map +1 -0
  8. package/dist/dsl/emit.js +41 -0
  9. package/dist/dsl/emit.js.map +1 -0
  10. package/dist/dsl/identifier.d.ts +28 -0
  11. package/dist/dsl/identifier.d.ts.map +1 -0
  12. package/dist/dsl/identifier.js +45 -0
  13. package/dist/dsl/identifier.js.map +1 -0
  14. package/dist/dsl/imports.d.ts +58 -0
  15. package/dist/dsl/imports.d.ts.map +1 -0
  16. package/dist/dsl/imports.js +107 -0
  17. package/dist/dsl/imports.js.map +1 -0
  18. package/dist/dsl/module.d.ts +53 -0
  19. package/dist/dsl/module.d.ts.map +1 -0
  20. package/dist/dsl/module.js +76 -0
  21. package/dist/dsl/module.js.map +1 -0
  22. package/dist/ffi/pipeline.d.ts +19 -0
  23. package/dist/ffi/pipeline.d.ts.map +1 -0
  24. package/dist/ffi/pipeline.js +107 -0
  25. package/dist/ffi/pipeline.js.map +1 -0
  26. package/dist/fingerprint.d.ts +30 -0
  27. package/dist/fingerprint.d.ts.map +1 -0
  28. package/dist/fingerprint.js +33 -0
  29. package/dist/fingerprint.js.map +1 -0
  30. package/dist/gi-store.d.ts +34 -0
  31. package/dist/gi-store.d.ts.map +1 -0
  32. package/dist/gi-store.js +154 -0
  33. package/dist/gi-store.js.map +1 -0
  34. package/dist/gir/boxed.d.ts +66 -0
  35. package/dist/gir/boxed.d.ts.map +1 -0
  36. package/dist/gir/boxed.js +49 -0
  37. package/dist/gir/boxed.js.map +1 -0
  38. package/dist/gir/callback.d.ts +15 -0
  39. package/dist/gir/callback.d.ts.map +1 -0
  40. package/dist/gir/callback.js +17 -0
  41. package/dist/gir/callback.js.map +1 -0
  42. package/dist/gir/class.d.ts +49 -0
  43. package/dist/gir/class.d.ts.map +1 -0
  44. package/dist/gir/class.js +42 -0
  45. package/dist/gir/class.js.map +1 -0
  46. package/dist/gir/enum.d.ts +39 -0
  47. package/dist/gir/enum.d.ts.map +1 -0
  48. package/dist/gir/enum.js +24 -0
  49. package/dist/gir/enum.js.map +1 -0
  50. package/dist/gir/field.d.ts +27 -0
  51. package/dist/gir/field.d.ts.map +1 -0
  52. package/dist/gir/field.js +19 -0
  53. package/dist/gir/field.js.map +1 -0
  54. package/dist/gir/function.d.ts +47 -0
  55. package/dist/gir/function.d.ts.map +1 -0
  56. package/dist/gir/function.js +28 -0
  57. package/dist/gir/function.js.map +1 -0
  58. package/dist/gir/namespace.d.ts +65 -0
  59. package/dist/gir/namespace.d.ts.map +1 -0
  60. package/dist/gir/namespace.js +60 -0
  61. package/dist/gir/namespace.js.map +1 -0
  62. package/dist/gir/parameter.d.ts +82 -0
  63. package/dist/gir/parameter.d.ts.map +1 -0
  64. package/dist/gir/parameter.js +66 -0
  65. package/dist/gir/parameter.js.map +1 -0
  66. package/dist/gir/parse.d.ts +78 -0
  67. package/dist/gir/parse.d.ts.map +1 -0
  68. package/dist/gir/parse.js +155 -0
  69. package/dist/gir/parse.js.map +1 -0
  70. package/dist/gir/primitives.d.ts +36 -0
  71. package/dist/gir/primitives.d.ts.map +1 -0
  72. package/dist/gir/primitives.js +109 -0
  73. package/dist/gir/primitives.js.map +1 -0
  74. package/dist/gir/property.d.ts +29 -0
  75. package/dist/gir/property.d.ts.map +1 -0
  76. package/dist/gir/property.js +16 -0
  77. package/dist/gir/property.js.map +1 -0
  78. package/dist/gir/qualified-name.d.ts +37 -0
  79. package/dist/gir/qualified-name.d.ts.map +1 -0
  80. package/dist/gir/qualified-name.js +39 -0
  81. package/dist/gir/qualified-name.js.map +1 -0
  82. package/dist/gir/qualify.d.ts +32 -0
  83. package/dist/gir/qualify.d.ts.map +1 -0
  84. package/dist/gir/qualify.js +60 -0
  85. package/dist/gir/qualify.js.map +1 -0
  86. package/dist/gir/repository.d.ts +82 -0
  87. package/dist/gir/repository.d.ts.map +1 -0
  88. package/dist/gir/repository.js +122 -0
  89. package/dist/gir/repository.js.map +1 -0
  90. package/dist/gir/signal.d.ts +22 -0
  91. package/dist/gir/signal.d.ts.map +1 -0
  92. package/dist/gir/signal.js +20 -0
  93. package/dist/gir/signal.js.map +1 -0
  94. package/dist/gir/size.d.ts +67 -0
  95. package/dist/gir/size.d.ts.map +1 -0
  96. package/dist/gir/size.js +87 -0
  97. package/dist/gir/size.js.map +1 -0
  98. package/dist/gir/type-ref.d.ts +79 -0
  99. package/dist/gir/type-ref.d.ts.map +1 -0
  100. package/dist/gir/type-ref.js +101 -0
  101. package/dist/gir/type-ref.js.map +1 -0
  102. package/dist/index.d.ts +12 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +12 -0
  105. package/dist/index.js.map +1 -0
  106. package/dist/jsx-store.d.ts +22 -0
  107. package/dist/jsx-store.d.ts.map +1 -0
  108. package/dist/jsx-store.js +40 -0
  109. package/dist/jsx-store.js.map +1 -0
  110. package/dist/react/compounds-meta.d.ts +18 -0
  111. package/dist/react/compounds-meta.d.ts.map +1 -0
  112. package/dist/react/compounds-meta.js +93 -0
  113. package/dist/react/compounds-meta.js.map +1 -0
  114. package/dist/react/compounds.d.ts +27 -0
  115. package/dist/react/compounds.d.ts.map +1 -0
  116. package/dist/react/compounds.js +164 -0
  117. package/dist/react/compounds.js.map +1 -0
  118. package/dist/react/internal.d.ts +14 -0
  119. package/dist/react/internal.d.ts.map +1 -0
  120. package/dist/react/internal.js +79 -0
  121. package/dist/react/internal.js.map +1 -0
  122. package/dist/react/jsx.d.ts +22 -0
  123. package/dist/react/jsx.d.ts.map +1 -0
  124. package/dist/react/jsx.js +134 -0
  125. package/dist/react/jsx.js.map +1 -0
  126. package/dist/react/pipeline.d.ts +13 -0
  127. package/dist/react/pipeline.d.ts.map +1 -0
  128. package/dist/react/pipeline.js +25 -0
  129. package/dist/react/pipeline.js.map +1 -0
  130. package/dist/react/props.d.ts +38 -0
  131. package/dist/react/props.d.ts.map +1 -0
  132. package/dist/react/props.js +231 -0
  133. package/dist/react/props.js.map +1 -0
  134. package/dist/react/slot-props.d.ts +10 -0
  135. package/dist/react/slot-props.d.ts.map +1 -0
  136. package/dist/react/slot-props.js +56 -0
  137. package/dist/react/slot-props.js.map +1 -0
  138. package/dist/react/widgets.d.ts +83 -0
  139. package/dist/react/widgets.d.ts.map +1 -0
  140. package/dist/react/widgets.js +152 -0
  141. package/dist/react/widgets.js.map +1 -0
  142. package/dist/runner.d.ts +55 -0
  143. package/dist/runner.d.ts.map +1 -0
  144. package/dist/runner.js +60 -0
  145. package/dist/runner.js.map +1 -0
  146. package/dist/store-fs.d.ts +109 -0
  147. package/dist/store-fs.d.ts.map +1 -0
  148. package/dist/store-fs.js +98 -0
  149. package/dist/store-fs.js.map +1 -0
  150. package/dist/transpile.d.ts +32 -0
  151. package/dist/transpile.d.ts.map +1 -0
  152. package/dist/transpile.js +63 -0
  153. package/dist/transpile.js.map +1 -0
  154. package/dist/typecheck-store.d.ts +41 -0
  155. package/dist/typecheck-store.d.ts.map +1 -0
  156. package/dist/typecheck-store.js +102 -0
  157. package/dist/typecheck-store.js.map +1 -0
  158. package/dist/writers/alias.d.ts +13 -0
  159. package/dist/writers/alias.d.ts.map +1 -0
  160. package/dist/writers/alias.js +17 -0
  161. package/dist/writers/alias.js.map +1 -0
  162. package/dist/writers/async.d.ts +22 -0
  163. package/dist/writers/async.d.ts.map +1 -0
  164. package/dist/writers/async.js +48 -0
  165. package/dist/writers/async.js.map +1 -0
  166. package/dist/writers/boxed-constructor.d.ts +26 -0
  167. package/dist/writers/boxed-constructor.d.ts.map +1 -0
  168. package/dist/writers/boxed-constructor.js +85 -0
  169. package/dist/writers/boxed-constructor.js.map +1 -0
  170. package/dist/writers/boxed-field-accessor.d.ts +18 -0
  171. package/dist/writers/boxed-field-accessor.d.ts.map +1 -0
  172. package/dist/writers/boxed-field-accessor.js +260 -0
  173. package/dist/writers/boxed-field-accessor.js.map +1 -0
  174. package/dist/writers/boxed-layout.d.ts +27 -0
  175. package/dist/writers/boxed-layout.d.ts.map +1 -0
  176. package/dist/writers/boxed-layout.js +128 -0
  177. package/dist/writers/boxed-layout.js.map +1 -0
  178. package/dist/writers/boxed.d.ts +20 -0
  179. package/dist/writers/boxed.d.ts.map +1 -0
  180. package/dist/writers/boxed.js +71 -0
  181. package/dist/writers/boxed.js.map +1 -0
  182. package/dist/writers/callables.d.ts +124 -0
  183. package/dist/writers/callables.d.ts.map +1 -0
  184. package/dist/writers/callables.js +283 -0
  185. package/dist/writers/callables.js.map +1 -0
  186. package/dist/writers/callback.d.ts +16 -0
  187. package/dist/writers/callback.d.ts.map +1 -0
  188. package/dist/writers/callback.js +38 -0
  189. package/dist/writers/callback.js.map +1 -0
  190. package/dist/writers/class-struct-record.d.ts +31 -0
  191. package/dist/writers/class-struct-record.d.ts.map +1 -0
  192. package/dist/writers/class-struct-record.js +67 -0
  193. package/dist/writers/class-struct-record.js.map +1 -0
  194. package/dist/writers/class-struct.d.ts +22 -0
  195. package/dist/writers/class-struct.d.ts.map +1 -0
  196. package/dist/writers/class-struct.js +85 -0
  197. package/dist/writers/class-struct.js.map +1 -0
  198. package/dist/writers/class.d.ts +16 -0
  199. package/dist/writers/class.d.ts.map +1 -0
  200. package/dist/writers/class.js +307 -0
  201. package/dist/writers/class.js.map +1 -0
  202. package/dist/writers/constant.d.ts +15 -0
  203. package/dist/writers/constant.d.ts.map +1 -0
  204. package/dist/writers/constant.js +23 -0
  205. package/dist/writers/constant.js.map +1 -0
  206. package/dist/writers/constants.d.ts +15 -0
  207. package/dist/writers/constants.d.ts.map +1 -0
  208. package/dist/writers/constants.js +23 -0
  209. package/dist/writers/constants.js.map +1 -0
  210. package/dist/writers/constructor-props.d.ts +32 -0
  211. package/dist/writers/constructor-props.d.ts.map +1 -0
  212. package/dist/writers/constructor-props.js +110 -0
  213. package/dist/writers/constructor-props.js.map +1 -0
  214. package/dist/writers/enum.d.ts +21 -0
  215. package/dist/writers/enum.d.ts.map +1 -0
  216. package/dist/writers/enum.js +48 -0
  217. package/dist/writers/enum.js.map +1 -0
  218. package/dist/writers/function.d.ts +40 -0
  219. package/dist/writers/function.d.ts.map +1 -0
  220. package/dist/writers/function.js +127 -0
  221. package/dist/writers/function.js.map +1 -0
  222. package/dist/writers/gtype-binding.d.ts +19 -0
  223. package/dist/writers/gtype-binding.d.ts.map +1 -0
  224. package/dist/writers/gtype-binding.js +40 -0
  225. package/dist/writers/gtype-binding.js.map +1 -0
  226. package/dist/writers/inheritance.d.ts +48 -0
  227. package/dist/writers/inheritance.d.ts.map +1 -0
  228. package/dist/writers/inheritance.js +90 -0
  229. package/dist/writers/inheritance.js.map +1 -0
  230. package/dist/writers/interface.d.ts +16 -0
  231. package/dist/writers/interface.d.ts.map +1 -0
  232. package/dist/writers/interface.js +155 -0
  233. package/dist/writers/interface.js.map +1 -0
  234. package/dist/writers/method.d.ts +150 -0
  235. package/dist/writers/method.d.ts.map +1 -0
  236. package/dist/writers/method.js +510 -0
  237. package/dist/writers/method.js.map +1 -0
  238. package/dist/writers/param-classify.d.ts +93 -0
  239. package/dist/writers/param-classify.d.ts.map +1 -0
  240. package/dist/writers/param-classify.js +163 -0
  241. package/dist/writers/param-classify.js.map +1 -0
  242. package/dist/writers/property-accessor.d.ts +19 -0
  243. package/dist/writers/property-accessor.d.ts.map +1 -0
  244. package/dist/writers/property-accessor.js +117 -0
  245. package/dist/writers/property-accessor.js.map +1 -0
  246. package/dist/writers/registration.d.ts +27 -0
  247. package/dist/writers/registration.d.ts.map +1 -0
  248. package/dist/writers/registration.js +30 -0
  249. package/dist/writers/registration.js.map +1 -0
  250. package/dist/writers/return-wrap.d.ts +39 -0
  251. package/dist/writers/return-wrap.d.ts.map +1 -0
  252. package/dist/writers/return-wrap.js +152 -0
  253. package/dist/writers/return-wrap.js.map +1 -0
  254. package/dist/writers/runtime-override.d.ts +18 -0
  255. package/dist/writers/runtime-override.d.ts.map +1 -0
  256. package/dist/writers/runtime-override.js +44 -0
  257. package/dist/writers/runtime-override.js.map +1 -0
  258. package/dist/writers/signal.d.ts +21 -0
  259. package/dist/writers/signal.d.ts.map +1 -0
  260. package/dist/writers/signal.js +260 -0
  261. package/dist/writers/signal.js.map +1 -0
  262. package/dist/writers/ts-type.d.ts +50 -0
  263. package/dist/writers/ts-type.d.ts.map +1 -0
  264. package/dist/writers/ts-type.js +75 -0
  265. package/dist/writers/ts-type.js.map +1 -0
  266. package/dist/writers/types-ts.d.ts +27 -0
  267. package/dist/writers/types-ts.d.ts.map +1 -0
  268. package/dist/writers/types-ts.js +97 -0
  269. package/dist/writers/types-ts.js.map +1 -0
  270. package/dist/writers/value.d.ts +89 -0
  271. package/dist/writers/value.d.ts.map +1 -0
  272. package/dist/writers/value.js +402 -0
  273. package/dist/writers/value.js.map +1 -0
  274. package/package.json +55 -0
  275. package/src/dsl/context.ts +146 -0
  276. package/src/dsl/emit.ts +42 -0
  277. package/src/dsl/identifier.ts +52 -0
  278. package/src/dsl/imports.ts +109 -0
  279. package/src/dsl/module.ts +75 -0
  280. package/src/ffi/pipeline.ts +113 -0
  281. package/src/fingerprint.ts +50 -0
  282. package/src/gi-store.ts +199 -0
  283. package/src/gir/boxed.ts +94 -0
  284. package/src/gir/callback.ts +26 -0
  285. package/src/gir/class.ts +79 -0
  286. package/src/gir/enum.ts +55 -0
  287. package/src/gir/field.ts +40 -0
  288. package/src/gir/function.ts +67 -0
  289. package/src/gir/namespace.ts +118 -0
  290. package/src/gir/parameter.ts +120 -0
  291. package/src/gir/parse.ts +171 -0
  292. package/src/gir/primitives.ts +137 -0
  293. package/src/gir/property.ts +39 -0
  294. package/src/gir/qualified-name.ts +55 -0
  295. package/src/gir/qualify.ts +64 -0
  296. package/src/gir/repository.ts +149 -0
  297. package/src/gir/signal.ts +36 -0
  298. package/src/gir/size.ts +129 -0
  299. package/src/gir/type-ref.ts +180 -0
  300. package/src/index.ts +16 -0
  301. package/src/jsx-store.ts +53 -0
  302. package/src/react/compounds-meta.ts +99 -0
  303. package/src/react/compounds.ts +204 -0
  304. package/src/react/internal.ts +91 -0
  305. package/src/react/jsx.ts +155 -0
  306. package/src/react/pipeline.ts +29 -0
  307. package/src/react/props.ts +307 -0
  308. package/src/react/slot-props.ts +57 -0
  309. package/src/react/widgets.ts +185 -0
  310. package/src/runner.ts +89 -0
  311. package/src/store-fs.ts +157 -0
  312. package/src/transpile.ts +80 -0
  313. package/src/typecheck-store.ts +136 -0
  314. package/src/writers/alias.ts +19 -0
  315. package/src/writers/async.ts +44 -0
  316. package/src/writers/boxed-constructor.ts +105 -0
  317. package/src/writers/boxed-field-accessor.ts +306 -0
  318. package/src/writers/boxed-layout.ts +166 -0
  319. package/src/writers/boxed.ts +77 -0
  320. package/src/writers/callables.ts +339 -0
  321. package/src/writers/callback.ts +40 -0
  322. package/src/writers/class-struct-record.ts +75 -0
  323. package/src/writers/class-struct.ts +96 -0
  324. package/src/writers/class.ts +384 -0
  325. package/src/writers/constant.ts +29 -0
  326. package/src/writers/constructor-props.ts +130 -0
  327. package/src/writers/enum.ts +53 -0
  328. package/src/writers/function.ts +136 -0
  329. package/src/writers/gtype-binding.ts +48 -0
  330. package/src/writers/inheritance.ts +104 -0
  331. package/src/writers/interface.ts +168 -0
  332. package/src/writers/method.ts +678 -0
  333. package/src/writers/param-classify.ts +178 -0
  334. package/src/writers/property-accessor.ts +139 -0
  335. package/src/writers/registration.ts +42 -0
  336. package/src/writers/return-wrap.ts +180 -0
  337. package/src/writers/runtime-override.ts +59 -0
  338. package/src/writers/signal.ts +318 -0
  339. package/src/writers/ts-type.ts +115 -0
  340. package/src/writers/value.ts +485 -0
@@ -0,0 +1,32 @@
1
+ import type { ModuleContext } from "../dsl/context.js";
2
+ import type { GirClass } from "../gir/class.js";
3
+ /**
4
+ * Renders the `export interface <Class>ConstructorProps` declaration.
5
+ *
6
+ * Each interface lists the camelCase, optional, nullable form of every
7
+ * property the class introduces and `extends` its parent's interface, so the
8
+ * full inherited prop set is available when typing `new <Class>(props)`.
9
+ *
10
+ * @param context - The module context
11
+ * @param klass - The class to render props for
12
+ * @param className - The local PascalCase class name
13
+ */
14
+ export declare const renderConstructorPropsInterface: (context: ModuleContext, klass: GirClass, className: string) => string;
15
+ /**
16
+ * Renders the constructor for a class, or `undefined` when none is needed.
17
+ *
18
+ * The parentless root of a GObject hierarchy gets the canonical base
19
+ * constructor that hands the assembled `GValue` record to
20
+ * `constructGObjectInstance`. A class that introduces constructable props gets
21
+ * a constructor that destructures and translates those props into `GValue`s,
22
+ * spreads the untranslated remainder, and forwards everything to `super`. A
23
+ * class that introduces no props gets no constructor and inherits its nearest
24
+ * typed ancestor's, keeping the chain free of redundant hops.
25
+ *
26
+ * @param context - The module context
27
+ * @param klass - The class being emitted
28
+ * @param className - The local PascalCase class name
29
+ * @param hasParent - Whether the class declares an `extends` clause
30
+ */
31
+ export declare const renderClassConstructor: (context: ModuleContext, klass: GirClass, className: string, hasParent: boolean) => string | undefined;
32
+ //# sourceMappingURL=constructor-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructor-props.d.ts","sourceRoot":"","sources":["../../src/writers/constructor-props.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAyChD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,aAAa,EAAE,OAAO,QAAQ,EAAE,WAAW,MAAM,KAAG,MAQ5G,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAC/B,SAAS,aAAa,EACtB,OAAO,QAAQ,EACf,WAAW,MAAM,EACjB,WAAW,OAAO,KACnB,MAAM,GAAG,SAKX,CAAC"}
@@ -0,0 +1,110 @@
1
+ import { quote, toCamelCase, toIdentifier, toPascalCase } from "@gtkx/utils";
2
+ import { indent } from "../dsl/emit.js";
3
+ import { splitQualifiedName } from "../gir/qualified-name.js";
4
+ import { collectInterfaceProperties } from "./inheritance.js";
5
+ import { renderTsType } from "./ts-type.js";
6
+ import { renderFfiType } from "./value.js";
7
+ /**
8
+ * Whether a property can be passed to a constructor: writable, construct, or
9
+ * construct-only properties only. Read-only properties cannot be set through
10
+ * `g_object_new_with_properties`.
11
+ *
12
+ * @param property - The GIR property
13
+ */
14
+ const isConstructable = (property) => property.writable || property.construct || property.constructOnly;
15
+ /**
16
+ * The constructable properties a class introduces: its own writable/construct
17
+ * properties plus those it inherits from directly-implemented interfaces,
18
+ * deduplicated by camelCase JS name (the class's own declaration wins).
19
+ *
20
+ * Ancestor class properties are intentionally excluded — each class translates
21
+ * only the props it introduces and forwards the rest up the `super(...)` chain.
22
+ *
23
+ * @param context - The module context
24
+ * @param klass - The class whose construct props to collect
25
+ */
26
+ const collectConstructableProps = (context, klass) => {
27
+ const all = [...klass.properties, ...collectInterfaceProperties(context, klass)].filter(isConstructable);
28
+ const seen = new Set();
29
+ const result = [];
30
+ for (const property of all) {
31
+ const jsName = toIdentifier(toCamelCase(property.name));
32
+ if (seen.has(jsName))
33
+ continue;
34
+ seen.add(jsName);
35
+ result.push(property);
36
+ }
37
+ return result;
38
+ };
39
+ /**
40
+ * Renders the `export interface <Class>ConstructorProps` declaration.
41
+ *
42
+ * Each interface lists the camelCase, optional, nullable form of every
43
+ * property the class introduces and `extends` its parent's interface, so the
44
+ * full inherited prop set is available when typing `new <Class>(props)`.
45
+ *
46
+ * @param context - The module context
47
+ * @param klass - The class to render props for
48
+ * @param className - The local PascalCase class name
49
+ */
50
+ export const renderConstructorPropsInterface = (context, klass, className) => {
51
+ const parentRef = resolveParentPropsReference(context, klass);
52
+ const extendsClause = parentRef === undefined ? "" : ` extends ${parentRef}`;
53
+ const lines = collectConstructableProps(context, klass).map((property) => `${toIdentifier(toCamelCase(property.name))}?: ${renderTsType(context, property.type, true)};`);
54
+ const body = lines.length === 0 ? "" : `\n${indent(lines.join("\n"), 1)}\n`;
55
+ return `export interface ${className}ConstructorProps${extendsClause} {${body}}`;
56
+ };
57
+ /**
58
+ * Renders the constructor for a class, or `undefined` when none is needed.
59
+ *
60
+ * The parentless root of a GObject hierarchy gets the canonical base
61
+ * constructor that hands the assembled `GValue` record to
62
+ * `constructGObjectInstance`. A class that introduces constructable props gets
63
+ * a constructor that destructures and translates those props into `GValue`s,
64
+ * spreads the untranslated remainder, and forwards everything to `super`. A
65
+ * class that introduces no props gets no constructor and inherits its nearest
66
+ * typed ancestor's, keeping the chain free of redundant hops.
67
+ *
68
+ * @param context - The module context
69
+ * @param klass - The class being emitted
70
+ * @param className - The local PascalCase class name
71
+ * @param hasParent - Whether the class declares an `extends` clause
72
+ */
73
+ export const renderClassConstructor = (context, klass, className, hasParent) => {
74
+ if (!hasParent)
75
+ return renderRootConstructor(context);
76
+ const props = collectConstructableProps(context, klass);
77
+ if (props.length === 0)
78
+ return undefined;
79
+ return renderTranslatingConstructor(context, props, className);
80
+ };
81
+ /** The forwarding record of marshalled `GValue`s a constructor hands to `super`. */
82
+ const GVALUE_RECORD = "Record<string, GValue | undefined>";
83
+ const renderRootConstructor = (context) => {
84
+ context.addConstructGObjectInstanceImport();
85
+ context.addRuntimeImport("GValue");
86
+ const body = "constructGObjectInstance(this, props);";
87
+ return `constructor(props: ${GVALUE_RECORD} = {}) {\n${indent(body, 1)}\n}`;
88
+ };
89
+ const renderTranslatingConstructor = (context, props, className) => {
90
+ context.addValueFromFfiOptionalImport();
91
+ context.addRuntimeImport("GValue");
92
+ const destructured = props.map((property) => toIdentifier(toCamelCase(property.name)));
93
+ const pattern = `{ ${[...destructured, "...rest"].join(", ")} }`;
94
+ const entries = props.map((property) => `${quote(property.name)}: valueFromFfiOptional(${renderFfiType(context, property.type, property.transferOwnership)}, ${toIdentifier(toCamelCase(property.name))}),`);
95
+ const recordLiteral = `{\n${indent(entries.join("\n"), 1)}\n}`;
96
+ const lines = [`const props: ${GVALUE_RECORD} = ${recordLiteral};`, "super({ ...props, ...rest });"];
97
+ const body = lines.join("\n");
98
+ return `constructor(${pattern}: ${className}ConstructorProps = {}) {\n${indent(body, 1)}\n}`;
99
+ };
100
+ const resolveParentPropsReference = (context, klass) => {
101
+ if (klass.parent === undefined)
102
+ return undefined;
103
+ const { namespaceName, typeName } = splitQualifiedName(klass.parent, context.namespace.name);
104
+ const propsName = `${toPascalCase(typeName)}ConstructorProps`;
105
+ if (namespaceName === context.namespace.name)
106
+ return propsName;
107
+ const alias = context.addCrossNamespaceImport(namespaceName);
108
+ return `${alias}.${propsName}`;
109
+ };
110
+ //# sourceMappingURL=constructor-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructor-props.js","sourceRoot":"","sources":["../../src/writers/constructor-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,QAAqB,EAAW,EAAE,CACvD,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,MAAM,yBAAyB,GAAG,CAAC,OAAsB,EAAE,KAAe,EAA0B,EAAE;IAClG,MAAM,GAAG,GAAG,CAA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AO,GAAG,KAAK,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { ModuleContext } from "../dsl/context.js";
2
+ import type { GirEnum } from "../gir/enum.js";
3
+ /**
4
+ * Emits the runtime declaration for an `<enumeration>` or `<bitfield>`.
5
+ *
6
+ * Two branches:
7
+ * - `glib:error-domain` present → `export type Name = number` plus
8
+ * `createErrorDomain(quark, members)` typed as `ErrorDomain<{ members }>`,
9
+ * since the domain object must stay `instanceof`-matchable.
10
+ * - GLib-registered enum/flags or C-only enum (no GLib registration) →
11
+ * a TypeScript `enum Name { members }` declaration.
12
+ *
13
+ * Member names are derived from the GIR `name` attribute, uppercased with
14
+ * hyphens normalized to underscores. Names that would start with a digit
15
+ * (e.g. `5_6_5` → `_5_6_5`) are prefixed with an underscore.
16
+ *
17
+ * @param context - The module context
18
+ * @param enumeration - The enum to emit
19
+ */
20
+ export declare const emitEnum: (context: ModuleContext, enumeration: GirEnum) => void;
21
+ //# sourceMappingURL=enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/writers/enum.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS,aAAa,EAAE,aAAa,OAAO,KAAG,IAkBvE,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { quote } from "@gtkx/utils";
2
+ /**
3
+ * Emits the runtime declaration for an `<enumeration>` or `<bitfield>`.
4
+ *
5
+ * Two branches:
6
+ * - `glib:error-domain` present → `export type Name = number` plus
7
+ * `createErrorDomain(quark, members)` typed as `ErrorDomain<{ members }>`,
8
+ * since the domain object must stay `instanceof`-matchable.
9
+ * - GLib-registered enum/flags or C-only enum (no GLib registration) →
10
+ * a TypeScript `enum Name { members }` declaration.
11
+ *
12
+ * Member names are derived from the GIR `name` attribute, uppercased with
13
+ * hyphens normalized to underscores. Names that would start with a digit
14
+ * (e.g. `5_6_5` → `_5_6_5`) are prefixed with an underscore.
15
+ *
16
+ * @param context - The module context
17
+ * @param enumeration - The enum to emit
18
+ */
19
+ export const emitEnum = (context, enumeration) => {
20
+ if (!enumeration.introspectable)
21
+ return;
22
+ const name = enumeration.name;
23
+ const memberKeys = enumeration.members.map((member) => memberKey(member.name));
24
+ if (enumeration.errorDomain !== undefined) {
25
+ const memberEntries = enumeration.members.map((member, index) => `${memberKeys[index]}: ${member.value}`);
26
+ const typeFields = memberKeys.map((key) => `readonly ${key}: number`).join("; ");
27
+ context.addRuntimeImport("createErrorDomain");
28
+ context.addRuntimeImport("ErrorDomain");
29
+ const quarkExpression = renderQuarkExpression(context, enumeration.errorDomain);
30
+ context.module.appendDeclaration(`export type ${name} = number;`);
31
+ context.module.appendDeclaration(`export const ${name}: ErrorDomain<{ ${typeFields} }> = createErrorDomain(${quarkExpression}, { ${memberEntries.join(", ")} });`);
32
+ return;
33
+ }
34
+ const memberDeclarations = enumeration.members.map((member, index) => `${memberKeys[index]} = ${member.value}`);
35
+ context.module.appendDeclaration(`export enum ${name} { ${memberDeclarations.join(", ")} }`);
36
+ };
37
+ const memberKey = (name) => {
38
+ const upper = name.toUpperCase().replaceAll("-", "_");
39
+ return /^[0-9]/.test(upper) ? `_${upper}` : upper;
40
+ };
41
+ const renderQuarkExpression = (context, errorDomain) => {
42
+ if (context.namespace.name === "GLib") {
43
+ return `() => quarkFromString(${quote(errorDomain)})`;
44
+ }
45
+ const alias = context.addCrossNamespaceImport("GLib");
46
+ return `() => ${alias}.quarkFromString(${quote(errorDomain)})`;
47
+ };
48
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/writers/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KA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C,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAChH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,eAAe,IAAI,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjG,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,OAAsB,EAAE,WAAmB,EAAU,EAAE;IAClF,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACpC,OAAO,yBAAyB,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC;IAC1D,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO,SAAS,KAAK,oBAAoB,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC;AACnE,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { ModuleContext } from "../dsl/context.js";
2
+ import type { GirFunction } from "../gir/function.js";
3
+ import type { GirNamespace } from "../gir/namespace.js";
4
+ /**
5
+ * Renders the `t.fn(library, symbol, args, returnType)` expression for a
6
+ * callable. Returns `undefined` when the callable cannot be bound (no C
7
+ * identifier or missing namespace shared-library).
8
+ *
9
+ * @param context - The module context
10
+ * @param fn - The callable
11
+ */
12
+ export declare const renderFnExpression: (context: ModuleContext, fn: GirFunction) => string | undefined;
13
+ /**
14
+ * Emits both the bound `const fooBinding = t.fn(...)` and the
15
+ * `export function camelName(...)` wrapper for a namespace-level callable.
16
+ *
17
+ * Silently skipped when {@link renderFnExpression} cannot bind the callable
18
+ * (e.g. macros, unintrospectable signatures) or when the GIR marks the
19
+ * callable as `introspectable="0"`.
20
+ *
21
+ * @param context - The module context
22
+ * @param fn - The callable
23
+ */
24
+ export declare const emitNamespaceFunction: (context: ModuleContext, fn: GirFunction) => void;
25
+ /**
26
+ * Emits a namespace's self-bootstrap statements as module-load side effects:
27
+ * a call to its zero-argument `init` entry point and a `whenStopped`
28
+ * registration for its zero-argument `finalize` entry point.
29
+ *
30
+ * GTK-style libraries expose top-level `init`/`finalize` functions (`gtk_init`,
31
+ * `adw_init`, `gtk_source_finalize`, …). Calling `init()` as the module is
32
+ * imported initializes the library's runtime before any of its types are
33
+ * touched — without it a `Gdk` display lookup can run before `gtk_init`.
34
+ * Deferring `finalize` to `whenStopped` runs it during shutdown.
35
+ *
36
+ * @param context - The module context
37
+ * @param namespace - The namespace being generated
38
+ */
39
+ export declare const emitNamespaceBootstrap: (context: ModuleContext, namespace: GirNamespace) => void;
40
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/writers/function.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAmDxD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,aAAa,EAAE,IAAI,WAAW,KAAG,MAAM,GAAG,SAarF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,aAAa,EAAE,IAAI,WAAW,KAAG,IAiB/E,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,aAAa,EAAE,WAAW,YAAY,KAAG,IAYxF,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { quote } from "@gtkx/utils";
2
+ import { arrayLiteral, indent, joinArgs } from "../dsl/emit.js";
3
+ import { namespaceFunctionExportName } from "../dsl/identifier.js";
4
+ import { callableReferencesClassStruct } from "./class-struct-record.js";
5
+ import { renderMethodBody, renderMethodReturnType, renderMethodSignature } from "./method.js";
6
+ import { closureAndDestroyIndices, needsRefArg } from "./param-classify.js";
7
+ import { renderFfiType, renderSelfFfiType, renderTrampolineType } from "./value.js";
8
+ /**
9
+ * Renders the FFI argument list for a callable, as a TypeScript array
10
+ * literal suitable as the third argument to `t.fn(...)`.
11
+ *
12
+ * Includes the instance parameter (if any), every regular parameter, and
13
+ * the implicit `GError**` ref when `throws=1`.
14
+ *
15
+ * @param context - The module context
16
+ * @param fn - The callable
17
+ */
18
+ const renderArgsLiteral = (context, fn) => {
19
+ const args = [];
20
+ const instanceOffset = fn.instance === undefined ? 0 : 1;
21
+ if (fn.instance !== undefined) {
22
+ context.addRuntimeImport("t");
23
+ args.push(`{ type: ${renderSelfFfiType(context, fn.instance)} }`);
24
+ }
25
+ const closureIndices = closureAndDestroyIndices(fn);
26
+ fn.parameters.forEach((parameter, index) => {
27
+ if (parameter.isVarargs)
28
+ return;
29
+ if (closureIndices.has(index))
30
+ return;
31
+ const optional = parameter.direction === "in" && (parameter.nullable || parameter.optional);
32
+ args.push(argLiteral(context, parameter, optional, instanceOffset));
33
+ });
34
+ if (fn.throws) {
35
+ context.addRuntimeImport("t");
36
+ args.push(`{ type: t.ref(t.boxed("GError", "full", "libgobject-2.0.so.0", "g_error_get_type")) }`);
37
+ }
38
+ return arrayLiteral(args);
39
+ };
40
+ const argLiteral = (context, parameter, optional, instanceOffset) => {
41
+ const trampoline = renderTrampolineType(context, parameter.type, parameter);
42
+ const inner = trampoline ?? renderFfiType(context, parameter.type, parameter.transferOwnership, instanceOffset);
43
+ const refWrapped = needsRefArg(context, parameter);
44
+ const expression = refWrapped ? `t.ref(${inner})` : inner;
45
+ return optional && !refWrapped ? `{ type: ${expression}, optional: true }` : `{ type: ${expression} }`;
46
+ };
47
+ /**
48
+ * Renders the `t.fn(library, symbol, args, returnType)` expression for a
49
+ * callable. Returns `undefined` when the callable cannot be bound (no C
50
+ * identifier or missing namespace shared-library).
51
+ *
52
+ * @param context - The module context
53
+ * @param fn - The callable
54
+ */
55
+ export const renderFnExpression = (context, fn) => {
56
+ if (fn.cIdentifier === undefined)
57
+ return undefined;
58
+ const library = context.namespace.sharedLibrary;
59
+ if (library === undefined)
60
+ return undefined;
61
+ context.addRuntimeImport("t");
62
+ const args = renderArgsLiteral(context, fn);
63
+ const returnType = renderFfiType(context, fn.returnValue.type, fn.returnValue.transferOwnership, fn.instance === undefined ? 0 : 1);
64
+ return `t.fn(${joinArgs([quote(library), quote(fn.cIdentifier), args, returnType])})`;
65
+ };
66
+ /**
67
+ * Emits both the bound `const fooBinding = t.fn(...)` and the
68
+ * `export function camelName(...)` wrapper for a namespace-level callable.
69
+ *
70
+ * Silently skipped when {@link renderFnExpression} cannot bind the callable
71
+ * (e.g. macros, unintrospectable signatures) or when the GIR marks the
72
+ * callable as `introspectable="0"`.
73
+ *
74
+ * @param context - The module context
75
+ * @param fn - The callable
76
+ */
77
+ export const emitNamespaceFunction = (context, fn) => {
78
+ if (!fn.introspectable)
79
+ return;
80
+ if (fn.shadowedBy !== undefined)
81
+ return;
82
+ if (callableReferencesClassStruct(context, fn))
83
+ return;
84
+ const expression = renderFnExpression(context, fn);
85
+ if (expression === undefined)
86
+ return;
87
+ const bindingName = fn.cIdentifier;
88
+ if (bindingName === undefined)
89
+ return;
90
+ context.module.appendBinding(`const ${bindingName} = ${expression};`, bindingName);
91
+ const exportName = namespaceFunctionExportName(bindingName, fn.name, context.namespace.cSymbolPrefixes);
92
+ const signature = renderMethodSignature(context, fn);
93
+ const returnType = renderMethodReturnType(context, fn);
94
+ const body = renderMethodBody(context, fn, { bindingExpression: bindingName, isStatic: true });
95
+ context.module.appendDeclaration(`export function ${exportName}(${signature}): ${returnType} {\n${indent(body, 1)}\n}`);
96
+ };
97
+ /**
98
+ * Emits a namespace's self-bootstrap statements as module-load side effects:
99
+ * a call to its zero-argument `init` entry point and a `whenStopped`
100
+ * registration for its zero-argument `finalize` entry point.
101
+ *
102
+ * GTK-style libraries expose top-level `init`/`finalize` functions (`gtk_init`,
103
+ * `adw_init`, `gtk_source_finalize`, …). Calling `init()` as the module is
104
+ * imported initializes the library's runtime before any of its types are
105
+ * touched — without it a `Gdk` display lookup can run before `gtk_init`.
106
+ * Deferring `finalize` to `whenStopped` runs it during shutdown.
107
+ *
108
+ * @param context - The module context
109
+ * @param namespace - The namespace being generated
110
+ */
111
+ export const emitNamespaceBootstrap = (context, namespace) => {
112
+ for (const fn of namespace.functions) {
113
+ if (fn.parameters.length > 0)
114
+ continue;
115
+ if (!fn.introspectable || fn.shadowedBy !== undefined || fn.cIdentifier === undefined)
116
+ continue;
117
+ const exportName = namespaceFunctionExportName(fn.cIdentifier, fn.name, context.namespace.cSymbolPrefixes);
118
+ if (fn.name === "init") {
119
+ context.module.appendRegistration(`${exportName}();`);
120
+ }
121
+ else if (fn.name === "finalize") {
122
+ context.module.imports.addNamed("@gtkx/ffi", "whenStopped");
123
+ context.module.appendRegistration(`whenStopped().then(${exportName});`);
124
+ }
125
+ }
126
+ };
127
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/writers/function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,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AI,EAAE,CAAC,CAAC;IAC/F,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAC5B,mBAAmB,UAAU,IAAI,SAAS,MAAM,UAAU,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CACxF,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAsB,EAAE,SAAuB,EAAQ,EAAE;IAC5F,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACnC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAAE,SAAS;QACvC,IAAI,CAAC,EAAE,CAAC,cAAc,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,CAAC,WAAW,KAAK,SAAS;YAAE,SAAS;QAChG,MAAM,UAAU,GAAG,2BAA2B,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAC3G,IAAI,EAAE,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACrB,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,UAAU,KAAK,CAAC,CAAC;QAC1D,CAAC;aAAM,IAAI,EAAE,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YAC5D,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,sBAAsB,UAAU,IAAI,CAAC,CAAC;QAC5E,CAAC;IACL,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ModuleContext } from "../dsl/context.js";
2
+ /**
3
+ * Renders the JS expression that resolves a class's `GType`, appending any
4
+ * required `t.fn` bindings to the module.
5
+ *
6
+ * For regular get-type symbols (`g_object_get_type`, `g_array_get_type`, …)
7
+ * the helper appends a `t.fn(...)` binding for the symbol and returns the bare
8
+ * function reference (`g_object_get_type`), which the runtime invokes once. For
9
+ * the GIR sentinel `"intern"` — used on `GVariant` and a few other types whose
10
+ * `GType` is registered intrinsically — it appends a binding for
11
+ * `g_type_from_name` and returns a `() => g_type_from_name("…")` thunk. Returns
12
+ * `undefined` when neither path is available.
13
+ *
14
+ * @param context - The module context
15
+ * @param getType - The C symbol name or the GIR sentinel `"intern"`
16
+ * @param glibTypeName - The GLib type name (for `"intern"` get-types)
17
+ */
18
+ export declare const renderGetTypeReference: (context: ModuleContext, getType: string, glibTypeName: string | undefined) => string | undefined;
19
+ //# sourceMappingURL=gtype-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gtype-binding.d.ts","sourceRoot":"","sources":["../../src/writers/gtype-binding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKvD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAC/B,SAAS,aAAa,EACtB,SAAS,MAAM,EACf,cAAc,MAAM,GAAG,SAAS,KACjC,MAAM,GAAG,SAQX,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { quote } from "@gtkx/utils";
2
+ const TYPE_FROM_NAME_BINDING = "g_type_from_name";
3
+ const TYPE_FROM_NAME_LIB = "libgobject-2.0.so.0";
4
+ /**
5
+ * Renders the JS expression that resolves a class's `GType`, appending any
6
+ * required `t.fn` bindings to the module.
7
+ *
8
+ * For regular get-type symbols (`g_object_get_type`, `g_array_get_type`, …)
9
+ * the helper appends a `t.fn(...)` binding for the symbol and returns the bare
10
+ * function reference (`g_object_get_type`), which the runtime invokes once. For
11
+ * the GIR sentinel `"intern"` — used on `GVariant` and a few other types whose
12
+ * `GType` is registered intrinsically — it appends a binding for
13
+ * `g_type_from_name` and returns a `() => g_type_from_name("…")` thunk. Returns
14
+ * `undefined` when neither path is available.
15
+ *
16
+ * @param context - The module context
17
+ * @param getType - The C symbol name or the GIR sentinel `"intern"`
18
+ * @param glibTypeName - The GLib type name (for `"intern"` get-types)
19
+ */
20
+ export const renderGetTypeReference = (context, getType, glibTypeName) => {
21
+ if (getType === "intern" || getType === "") {
22
+ if (glibTypeName === undefined)
23
+ return undefined;
24
+ appendGTypeFromNameBinding(context);
25
+ return `() => ${TYPE_FROM_NAME_BINDING}(${quote(glibTypeName)})`;
26
+ }
27
+ appendGetTypeBinding(context, getType);
28
+ return getType;
29
+ };
30
+ const appendGetTypeBinding = (context, getType) => {
31
+ const lib = context.namespace.sharedLibrary ?? "";
32
+ const expression = `t.fn(${quote(lib)}, ${quote(getType)}, [], t.uint64)`;
33
+ context.module.appendBinding(`const ${getType} = ${expression};`, getType);
34
+ };
35
+ const appendGTypeFromNameBinding = (context) => {
36
+ const expression = `t.fn(${quote(TYPE_FROM_NAME_LIB)}, ${quote(TYPE_FROM_NAME_BINDING)}, ` +
37
+ `[{ type: t.string("borrowed") }], t.uint64)`;
38
+ context.module.appendBinding(`const ${TYPE_FROM_NAME_BINDING} = ${expression};`, TYPE_FROM_NAME_BINDING);
39
+ };
40
+ //# sourceMappingURL=gtype-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gtype-binding.js","sourceRoot":"","sources":["../../src/writers/gtype-binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAClD,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,OAAsB,EACtB,OAAe,EACf,YAAgC,EACd,EAAE;IACpB,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACzC,IAAI,YAAY,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACjD,0BAA0B,CAAC,OAAO,CAAC,CAAC;QACpC,OAAO,SAAS,sBAAsB,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC;IACrE,CAAC;IACD,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,OAAsB,EAAE,OAAe,EAAQ,EAAE;IAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,aAAa,IAAI,EAAE,CAAC;IAClD,MAAM,UAAU,GAAG,QAAQ,KAAK,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC;IAC1E,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,OAAO,MAAM,UAAU,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,OAAsB,EAAQ,EAAE;IAChE,MAAM,UAAU,GACZ,QAAQ,KAAK,CAAC,kBAAkB,CAAC,KAAK,KAAK,CAAC,sBAAsB,CAAC,IAAI;QACvE,6CAA6C,CAAC;IAClD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,sBAAsB,MAAM,UAAU,GAAG,EAAE,sBAAsB,CAAC,CAAC;AAC7G,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { ModuleContext } from "../dsl/context.js";
2
+ import type { GirClass } from "../gir/class.js";
3
+ import type { GirProperty } from "../gir/property.js";
4
+ import { type ResolvedQualifiedClass } from "../gir/qualified-name.js";
5
+ /**
6
+ * A directly-implemented interface resolved to its declaration and the
7
+ * namespace that declares it.
8
+ */
9
+ export type ResolvedInterface = {
10
+ readonly klass: GirClass;
11
+ readonly namespaceName: string;
12
+ };
13
+ /**
14
+ * Resolves an `<implements>` entry to its `<interface>` declaration.
15
+ *
16
+ * Returns `undefined` when the name resolves to a non-interface entity or
17
+ * cannot be resolved at all.
18
+ *
19
+ * @param context - The module context
20
+ * @param name - The (possibly cross-namespace) interface name
21
+ */
22
+ export declare const resolveImplementedInterface: (context: ModuleContext, name: string, defaultNamespace?: string) => ResolvedInterface | undefined;
23
+ /**
24
+ * Invokes `visit` for each ancestor class of `klass`, nearest first.
25
+ *
26
+ * Walks the same-namespace and cross-namespace parent chain, stopping at the
27
+ * first unresolved parent or a cycle. Each ancestor is reported together with
28
+ * the namespace it was resolved through so callers can qualify its references.
29
+ *
30
+ * @param context - The module context
31
+ * @param klass - The class whose ancestors to visit
32
+ * @param visit - Callback invoked once per resolved ancestor
33
+ */
34
+ export declare const forEachAncestor: (context: ModuleContext, klass: GirClass, visit: (ancestor: ResolvedQualifiedClass) => void) => void;
35
+ /**
36
+ * Collects the properties contributed by a class's directly-implemented
37
+ * interfaces that are not already declared on the class itself or inherited
38
+ * from an ancestor (or an ancestor-implemented interface).
39
+ *
40
+ * Each returned property carries its references re-rooted to the interface's
41
+ * namespace so the class writer can emit its accessor and constructor prop
42
+ * as if the property had been authored on the class.
43
+ *
44
+ * @param context - The module context
45
+ * @param klass - The implementing class
46
+ */
47
+ export declare const collectInterfaceProperties: (context: ModuleContext, klass: GirClass) => readonly GirProperty[];
48
+ //# sourceMappingURL=inheritance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inheritance.d.ts","sourceRoot":"","sources":["../../src/writers/inheritance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,sBAAsB,EAA6C,MAAM,0BAA0B,CAAC;AAGlH;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACpC,SAAS,aAAa,EACtB,MAAM,MAAM,EACZ,mBAAkB,MAA+B,KAClD,iBAAiB,GAAG,SAKtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GACxB,SAAS,aAAa,EACtB,OAAO,QAAQ,EACf,OAAO,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,KAClD,IAeF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,SAAS,aAAa,EAAE,OAAO,QAAQ,KAAG,SAAS,WAAW,EAuBxG,CAAC"}
@@ -0,0 +1,90 @@
1
+ import { toCamelCase, toIdentifier } from "@gtkx/utils";
2
+ import { resolveQualifiedClass, splitQualifiedName } from "../gir/qualified-name.js";
3
+ import { qualifyTypeRef } from "../gir/qualify.js";
4
+ /**
5
+ * Resolves an `<implements>` entry to its `<interface>` declaration.
6
+ *
7
+ * Returns `undefined` when the name resolves to a non-interface entity or
8
+ * cannot be resolved at all.
9
+ *
10
+ * @param context - The module context
11
+ * @param name - The (possibly cross-namespace) interface name
12
+ */
13
+ export const resolveImplementedInterface = (context, name, defaultNamespace = context.namespace.name) => {
14
+ const { namespaceName, typeName } = splitQualifiedName(name, defaultNamespace);
15
+ const resolved = context.repository.resolveNamed(namespaceName, typeName);
16
+ if (resolved === undefined || resolved.kind !== "interface")
17
+ return undefined;
18
+ return { klass: resolved.value, namespaceName: resolved.namespace.name };
19
+ };
20
+ /**
21
+ * Invokes `visit` for each ancestor class of `klass`, nearest first.
22
+ *
23
+ * Walks the same-namespace and cross-namespace parent chain, stopping at the
24
+ * first unresolved parent or a cycle. Each ancestor is reported together with
25
+ * the namespace it was resolved through so callers can qualify its references.
26
+ *
27
+ * @param context - The module context
28
+ * @param klass - The class whose ancestors to visit
29
+ * @param visit - Callback invoked once per resolved ancestor
30
+ */
31
+ export const forEachAncestor = (context, klass, visit) => {
32
+ const visited = new Set();
33
+ let current = klass.parent === undefined ? undefined : { name: klass.parent, defaultNamespace: context.namespace.name };
34
+ while (current !== undefined) {
35
+ const resolved = resolveQualifiedClass(context.repository, current.name, current.defaultNamespace);
36
+ if (resolved === undefined)
37
+ break;
38
+ const key = `${resolved.namespaceName}.${resolved.klass.name}`;
39
+ if (visited.has(key))
40
+ break;
41
+ visited.add(key);
42
+ visit(resolved);
43
+ current = resolved.klass.parent
44
+ ? { name: resolved.klass.parent, defaultNamespace: resolved.namespaceName }
45
+ : undefined;
46
+ }
47
+ };
48
+ /**
49
+ * Collects the properties contributed by a class's directly-implemented
50
+ * interfaces that are not already declared on the class itself or inherited
51
+ * from an ancestor (or an ancestor-implemented interface).
52
+ *
53
+ * Each returned property carries its references re-rooted to the interface's
54
+ * namespace so the class writer can emit its accessor and constructor prop
55
+ * as if the property had been authored on the class.
56
+ *
57
+ * @param context - The module context
58
+ * @param klass - The implementing class
59
+ */
60
+ export const collectInterfaceProperties = (context, klass) => {
61
+ const seen = new Set();
62
+ for (const property of klass.properties)
63
+ seen.add(toIdentifier(toCamelCase(property.name)));
64
+ forEachAncestor(context, klass, (ancestor) => {
65
+ for (const property of ancestor.klass.properties)
66
+ seen.add(toIdentifier(toCamelCase(property.name)));
67
+ for (const implementName of ancestor.klass.implements) {
68
+ const iface = resolveImplementedInterface(context, implementName, ancestor.namespaceName);
69
+ if (iface === undefined)
70
+ continue;
71
+ for (const property of iface.klass.properties)
72
+ seen.add(toIdentifier(toCamelCase(property.name)));
73
+ }
74
+ });
75
+ const result = [];
76
+ for (const implementName of klass.implements) {
77
+ const iface = resolveImplementedInterface(context, implementName);
78
+ if (iface === undefined)
79
+ continue;
80
+ for (const property of iface.klass.properties) {
81
+ const name = toIdentifier(toCamelCase(property.name));
82
+ if (seen.has(name))
83
+ continue;
84
+ seen.add(name);
85
+ result.push({ ...property, type: qualifyTypeRef(property.type, iface.namespaceName) });
86
+ }
87
+ }
88
+ return result;
89
+ };
90
+ //#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