@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.
- package/LICENSE +373 -0
- package/dist/dsl/context.d.ts +104 -0
- package/dist/dsl/context.d.ts.map +1 -0
- package/dist/dsl/context.js +140 -0
- package/dist/dsl/context.js.map +1 -0
- package/dist/dsl/emit.d.ts +28 -0
- package/dist/dsl/emit.d.ts.map +1 -0
- package/dist/dsl/emit.js +41 -0
- package/dist/dsl/emit.js.map +1 -0
- package/dist/dsl/identifier.d.ts +28 -0
- package/dist/dsl/identifier.d.ts.map +1 -0
- package/dist/dsl/identifier.js +45 -0
- package/dist/dsl/identifier.js.map +1 -0
- package/dist/dsl/imports.d.ts +58 -0
- package/dist/dsl/imports.d.ts.map +1 -0
- package/dist/dsl/imports.js +107 -0
- package/dist/dsl/imports.js.map +1 -0
- package/dist/dsl/module.d.ts +53 -0
- package/dist/dsl/module.d.ts.map +1 -0
- package/dist/dsl/module.js +76 -0
- package/dist/dsl/module.js.map +1 -0
- package/dist/ffi/pipeline.d.ts +19 -0
- package/dist/ffi/pipeline.d.ts.map +1 -0
- package/dist/ffi/pipeline.js +107 -0
- package/dist/ffi/pipeline.js.map +1 -0
- package/dist/fingerprint.d.ts +30 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +33 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/gi-store.d.ts +34 -0
- package/dist/gi-store.d.ts.map +1 -0
- package/dist/gi-store.js +154 -0
- package/dist/gi-store.js.map +1 -0
- package/dist/gir/boxed.d.ts +66 -0
- package/dist/gir/boxed.d.ts.map +1 -0
- package/dist/gir/boxed.js +49 -0
- package/dist/gir/boxed.js.map +1 -0
- package/dist/gir/callback.d.ts +15 -0
- package/dist/gir/callback.d.ts.map +1 -0
- package/dist/gir/callback.js +17 -0
- package/dist/gir/callback.js.map +1 -0
- package/dist/gir/class.d.ts +49 -0
- package/dist/gir/class.d.ts.map +1 -0
- package/dist/gir/class.js +42 -0
- package/dist/gir/class.js.map +1 -0
- package/dist/gir/enum.d.ts +39 -0
- package/dist/gir/enum.d.ts.map +1 -0
- package/dist/gir/enum.js +24 -0
- package/dist/gir/enum.js.map +1 -0
- package/dist/gir/field.d.ts +27 -0
- package/dist/gir/field.d.ts.map +1 -0
- package/dist/gir/field.js +19 -0
- package/dist/gir/field.js.map +1 -0
- package/dist/gir/function.d.ts +47 -0
- package/dist/gir/function.d.ts.map +1 -0
- package/dist/gir/function.js +28 -0
- package/dist/gir/function.js.map +1 -0
- package/dist/gir/namespace.d.ts +65 -0
- package/dist/gir/namespace.d.ts.map +1 -0
- package/dist/gir/namespace.js +60 -0
- package/dist/gir/namespace.js.map +1 -0
- package/dist/gir/parameter.d.ts +82 -0
- package/dist/gir/parameter.d.ts.map +1 -0
- package/dist/gir/parameter.js +66 -0
- package/dist/gir/parameter.js.map +1 -0
- package/dist/gir/parse.d.ts +78 -0
- package/dist/gir/parse.d.ts.map +1 -0
- package/dist/gir/parse.js +155 -0
- package/dist/gir/parse.js.map +1 -0
- package/dist/gir/primitives.d.ts +36 -0
- package/dist/gir/primitives.d.ts.map +1 -0
- package/dist/gir/primitives.js +109 -0
- package/dist/gir/primitives.js.map +1 -0
- package/dist/gir/property.d.ts +29 -0
- package/dist/gir/property.d.ts.map +1 -0
- package/dist/gir/property.js +16 -0
- package/dist/gir/property.js.map +1 -0
- package/dist/gir/qualified-name.d.ts +37 -0
- package/dist/gir/qualified-name.d.ts.map +1 -0
- package/dist/gir/qualified-name.js +39 -0
- package/dist/gir/qualified-name.js.map +1 -0
- package/dist/gir/qualify.d.ts +32 -0
- package/dist/gir/qualify.d.ts.map +1 -0
- package/dist/gir/qualify.js +60 -0
- package/dist/gir/qualify.js.map +1 -0
- package/dist/gir/repository.d.ts +82 -0
- package/dist/gir/repository.d.ts.map +1 -0
- package/dist/gir/repository.js +122 -0
- package/dist/gir/repository.js.map +1 -0
- package/dist/gir/signal.d.ts +22 -0
- package/dist/gir/signal.d.ts.map +1 -0
- package/dist/gir/signal.js +20 -0
- package/dist/gir/signal.js.map +1 -0
- package/dist/gir/size.d.ts +67 -0
- package/dist/gir/size.d.ts.map +1 -0
- package/dist/gir/size.js +87 -0
- package/dist/gir/size.js.map +1 -0
- package/dist/gir/type-ref.d.ts +79 -0
- package/dist/gir/type-ref.d.ts.map +1 -0
- package/dist/gir/type-ref.js +101 -0
- package/dist/gir/type-ref.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-store.d.ts +22 -0
- package/dist/jsx-store.d.ts.map +1 -0
- package/dist/jsx-store.js +40 -0
- package/dist/jsx-store.js.map +1 -0
- package/dist/react/compounds-meta.d.ts +18 -0
- package/dist/react/compounds-meta.d.ts.map +1 -0
- package/dist/react/compounds-meta.js +93 -0
- package/dist/react/compounds-meta.js.map +1 -0
- package/dist/react/compounds.d.ts +27 -0
- package/dist/react/compounds.d.ts.map +1 -0
- package/dist/react/compounds.js +164 -0
- package/dist/react/compounds.js.map +1 -0
- package/dist/react/internal.d.ts +14 -0
- package/dist/react/internal.d.ts.map +1 -0
- package/dist/react/internal.js +79 -0
- package/dist/react/internal.js.map +1 -0
- package/dist/react/jsx.d.ts +22 -0
- package/dist/react/jsx.d.ts.map +1 -0
- package/dist/react/jsx.js +134 -0
- package/dist/react/jsx.js.map +1 -0
- package/dist/react/pipeline.d.ts +13 -0
- package/dist/react/pipeline.d.ts.map +1 -0
- package/dist/react/pipeline.js +25 -0
- package/dist/react/pipeline.js.map +1 -0
- package/dist/react/props.d.ts +38 -0
- package/dist/react/props.d.ts.map +1 -0
- package/dist/react/props.js +231 -0
- package/dist/react/props.js.map +1 -0
- package/dist/react/slot-props.d.ts +10 -0
- package/dist/react/slot-props.d.ts.map +1 -0
- package/dist/react/slot-props.js +56 -0
- package/dist/react/slot-props.js.map +1 -0
- package/dist/react/widgets.d.ts +83 -0
- package/dist/react/widgets.d.ts.map +1 -0
- package/dist/react/widgets.js +152 -0
- package/dist/react/widgets.js.map +1 -0
- package/dist/runner.d.ts +55 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +60 -0
- package/dist/runner.js.map +1 -0
- package/dist/store-fs.d.ts +109 -0
- package/dist/store-fs.d.ts.map +1 -0
- package/dist/store-fs.js +98 -0
- package/dist/store-fs.js.map +1 -0
- package/dist/transpile.d.ts +32 -0
- package/dist/transpile.d.ts.map +1 -0
- package/dist/transpile.js +63 -0
- package/dist/transpile.js.map +1 -0
- package/dist/typecheck-store.d.ts +41 -0
- package/dist/typecheck-store.d.ts.map +1 -0
- package/dist/typecheck-store.js +102 -0
- package/dist/typecheck-store.js.map +1 -0
- package/dist/writers/alias.d.ts +13 -0
- package/dist/writers/alias.d.ts.map +1 -0
- package/dist/writers/alias.js +17 -0
- package/dist/writers/alias.js.map +1 -0
- package/dist/writers/async.d.ts +22 -0
- package/dist/writers/async.d.ts.map +1 -0
- package/dist/writers/async.js +48 -0
- package/dist/writers/async.js.map +1 -0
- package/dist/writers/boxed-constructor.d.ts +26 -0
- package/dist/writers/boxed-constructor.d.ts.map +1 -0
- package/dist/writers/boxed-constructor.js +85 -0
- package/dist/writers/boxed-constructor.js.map +1 -0
- package/dist/writers/boxed-field-accessor.d.ts +18 -0
- package/dist/writers/boxed-field-accessor.d.ts.map +1 -0
- package/dist/writers/boxed-field-accessor.js +260 -0
- package/dist/writers/boxed-field-accessor.js.map +1 -0
- package/dist/writers/boxed-layout.d.ts +27 -0
- package/dist/writers/boxed-layout.d.ts.map +1 -0
- package/dist/writers/boxed-layout.js +128 -0
- package/dist/writers/boxed-layout.js.map +1 -0
- package/dist/writers/boxed.d.ts +20 -0
- package/dist/writers/boxed.d.ts.map +1 -0
- package/dist/writers/boxed.js +71 -0
- package/dist/writers/boxed.js.map +1 -0
- package/dist/writers/callables.d.ts +124 -0
- package/dist/writers/callables.d.ts.map +1 -0
- package/dist/writers/callables.js +283 -0
- package/dist/writers/callables.js.map +1 -0
- package/dist/writers/callback.d.ts +16 -0
- package/dist/writers/callback.d.ts.map +1 -0
- package/dist/writers/callback.js +38 -0
- package/dist/writers/callback.js.map +1 -0
- package/dist/writers/class-struct-record.d.ts +31 -0
- package/dist/writers/class-struct-record.d.ts.map +1 -0
- package/dist/writers/class-struct-record.js +67 -0
- package/dist/writers/class-struct-record.js.map +1 -0
- package/dist/writers/class-struct.d.ts +22 -0
- package/dist/writers/class-struct.d.ts.map +1 -0
- package/dist/writers/class-struct.js +85 -0
- package/dist/writers/class-struct.js.map +1 -0
- package/dist/writers/class.d.ts +16 -0
- package/dist/writers/class.d.ts.map +1 -0
- package/dist/writers/class.js +307 -0
- package/dist/writers/class.js.map +1 -0
- package/dist/writers/constant.d.ts +15 -0
- package/dist/writers/constant.d.ts.map +1 -0
- package/dist/writers/constant.js +23 -0
- package/dist/writers/constant.js.map +1 -0
- package/dist/writers/constants.d.ts +15 -0
- package/dist/writers/constants.d.ts.map +1 -0
- package/dist/writers/constants.js +23 -0
- package/dist/writers/constants.js.map +1 -0
- package/dist/writers/constructor-props.d.ts +32 -0
- package/dist/writers/constructor-props.d.ts.map +1 -0
- package/dist/writers/constructor-props.js +110 -0
- package/dist/writers/constructor-props.js.map +1 -0
- package/dist/writers/enum.d.ts +21 -0
- package/dist/writers/enum.d.ts.map +1 -0
- package/dist/writers/enum.js +48 -0
- package/dist/writers/enum.js.map +1 -0
- package/dist/writers/function.d.ts +40 -0
- package/dist/writers/function.d.ts.map +1 -0
- package/dist/writers/function.js +127 -0
- package/dist/writers/function.js.map +1 -0
- package/dist/writers/gtype-binding.d.ts +19 -0
- package/dist/writers/gtype-binding.d.ts.map +1 -0
- package/dist/writers/gtype-binding.js +40 -0
- package/dist/writers/gtype-binding.js.map +1 -0
- package/dist/writers/inheritance.d.ts +48 -0
- package/dist/writers/inheritance.d.ts.map +1 -0
- package/dist/writers/inheritance.js +90 -0
- package/dist/writers/inheritance.js.map +1 -0
- package/dist/writers/interface.d.ts +16 -0
- package/dist/writers/interface.d.ts.map +1 -0
- package/dist/writers/interface.js +155 -0
- package/dist/writers/interface.js.map +1 -0
- package/dist/writers/method.d.ts +150 -0
- package/dist/writers/method.d.ts.map +1 -0
- package/dist/writers/method.js +510 -0
- package/dist/writers/method.js.map +1 -0
- package/dist/writers/param-classify.d.ts +93 -0
- package/dist/writers/param-classify.d.ts.map +1 -0
- package/dist/writers/param-classify.js +163 -0
- package/dist/writers/param-classify.js.map +1 -0
- package/dist/writers/property-accessor.d.ts +19 -0
- package/dist/writers/property-accessor.d.ts.map +1 -0
- package/dist/writers/property-accessor.js +117 -0
- package/dist/writers/property-accessor.js.map +1 -0
- package/dist/writers/registration.d.ts +27 -0
- package/dist/writers/registration.d.ts.map +1 -0
- package/dist/writers/registration.js +30 -0
- package/dist/writers/registration.js.map +1 -0
- package/dist/writers/return-wrap.d.ts +39 -0
- package/dist/writers/return-wrap.d.ts.map +1 -0
- package/dist/writers/return-wrap.js +152 -0
- package/dist/writers/return-wrap.js.map +1 -0
- package/dist/writers/runtime-override.d.ts +18 -0
- package/dist/writers/runtime-override.d.ts.map +1 -0
- package/dist/writers/runtime-override.js +44 -0
- package/dist/writers/runtime-override.js.map +1 -0
- package/dist/writers/signal.d.ts +21 -0
- package/dist/writers/signal.d.ts.map +1 -0
- package/dist/writers/signal.js +260 -0
- package/dist/writers/signal.js.map +1 -0
- package/dist/writers/ts-type.d.ts +50 -0
- package/dist/writers/ts-type.d.ts.map +1 -0
- package/dist/writers/ts-type.js +75 -0
- package/dist/writers/ts-type.js.map +1 -0
- package/dist/writers/types-ts.d.ts +27 -0
- package/dist/writers/types-ts.d.ts.map +1 -0
- package/dist/writers/types-ts.js +97 -0
- package/dist/writers/types-ts.js.map +1 -0
- package/dist/writers/value.d.ts +89 -0
- package/dist/writers/value.d.ts.map +1 -0
- package/dist/writers/value.js +402 -0
- package/dist/writers/value.js.map +1 -0
- package/package.json +55 -0
- package/src/dsl/context.ts +146 -0
- package/src/dsl/emit.ts +42 -0
- package/src/dsl/identifier.ts +52 -0
- package/src/dsl/imports.ts +109 -0
- package/src/dsl/module.ts +75 -0
- package/src/ffi/pipeline.ts +113 -0
- package/src/fingerprint.ts +50 -0
- package/src/gi-store.ts +199 -0
- package/src/gir/boxed.ts +94 -0
- package/src/gir/callback.ts +26 -0
- package/src/gir/class.ts +79 -0
- package/src/gir/enum.ts +55 -0
- package/src/gir/field.ts +40 -0
- package/src/gir/function.ts +67 -0
- package/src/gir/namespace.ts +118 -0
- package/src/gir/parameter.ts +120 -0
- package/src/gir/parse.ts +171 -0
- package/src/gir/primitives.ts +137 -0
- package/src/gir/property.ts +39 -0
- package/src/gir/qualified-name.ts +55 -0
- package/src/gir/qualify.ts +64 -0
- package/src/gir/repository.ts +149 -0
- package/src/gir/signal.ts +36 -0
- package/src/gir/size.ts +129 -0
- package/src/gir/type-ref.ts +180 -0
- package/src/index.ts +16 -0
- package/src/jsx-store.ts +53 -0
- package/src/react/compounds-meta.ts +99 -0
- package/src/react/compounds.ts +204 -0
- package/src/react/internal.ts +91 -0
- package/src/react/jsx.ts +155 -0
- package/src/react/pipeline.ts +29 -0
- package/src/react/props.ts +307 -0
- package/src/react/slot-props.ts +57 -0
- package/src/react/widgets.ts +185 -0
- package/src/runner.ts +89 -0
- package/src/store-fs.ts +157 -0
- package/src/transpile.ts +80 -0
- package/src/typecheck-store.ts +136 -0
- package/src/writers/alias.ts +19 -0
- package/src/writers/async.ts +44 -0
- package/src/writers/boxed-constructor.ts +105 -0
- package/src/writers/boxed-field-accessor.ts +306 -0
- package/src/writers/boxed-layout.ts +166 -0
- package/src/writers/boxed.ts +77 -0
- package/src/writers/callables.ts +339 -0
- package/src/writers/callback.ts +40 -0
- package/src/writers/class-struct-record.ts +75 -0
- package/src/writers/class-struct.ts +96 -0
- package/src/writers/class.ts +384 -0
- package/src/writers/constant.ts +29 -0
- package/src/writers/constructor-props.ts +130 -0
- package/src/writers/enum.ts +53 -0
- package/src/writers/function.ts +136 -0
- package/src/writers/gtype-binding.ts +48 -0
- package/src/writers/inheritance.ts +104 -0
- package/src/writers/interface.ts +168 -0
- package/src/writers/method.ts +678 -0
- package/src/writers/param-classify.ts +178 -0
- package/src/writers/property-accessor.ts +139 -0
- package/src/writers/registration.ts +42 -0
- package/src/writers/return-wrap.ts +180 -0
- package/src/writers/runtime-override.ts +59 -0
- package/src/writers/signal.ts +318 -0
- package/src/writers/ts-type.ts +115 -0
- package/src/writers/value.ts +485 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { toCamelCase, toIdentifier } from "@gtkx/utils";
|
|
2
|
+
import { isCallerAllocatedOut, isOutParameter } from "../gir/parameter.js";
|
|
3
|
+
/**
|
|
4
|
+
* The input parameters a callable's TypeScript signature exposes.
|
|
5
|
+
*
|
|
6
|
+
* Drops `<varargs>` slots, out-only and caller-allocated-out parameters,
|
|
7
|
+
* array-length parameters computed from a sibling array, and the
|
|
8
|
+
* `user_data`/`GDestroyNotify` slots folded into a callback descriptor. Each
|
|
9
|
+
* surviving parameter keeps its original index so callers can recover argument
|
|
10
|
+
* names.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - The callable
|
|
13
|
+
*/
|
|
14
|
+
export const inputParameters = (fn) => {
|
|
15
|
+
const lengthIndices = arrayLengthIndices(fn);
|
|
16
|
+
const closureIndices = closureAndDestroyIndices(fn);
|
|
17
|
+
const result = [];
|
|
18
|
+
fn.parameters.forEach((parameter, index) => {
|
|
19
|
+
if (parameter.isVarargs)
|
|
20
|
+
return;
|
|
21
|
+
if (isOutParameter(parameter))
|
|
22
|
+
return;
|
|
23
|
+
if (isCallerAllocatedOut(parameter))
|
|
24
|
+
return;
|
|
25
|
+
if (lengthIndices.has(index))
|
|
26
|
+
return;
|
|
27
|
+
if (closureIndices.has(index))
|
|
28
|
+
return;
|
|
29
|
+
result.push({ parameter, index });
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Indices of the `gpointer user_data` and `GDestroyNotify` parameters paired
|
|
35
|
+
* to a callback parameter. These slots are folded into the callback's
|
|
36
|
+
* trampoline descriptor and are not emitted as standalone FFI arguments.
|
|
37
|
+
*
|
|
38
|
+
* @param fn - The callable
|
|
39
|
+
*/
|
|
40
|
+
export const closureAndDestroyIndices = (fn) => {
|
|
41
|
+
const indices = new Set();
|
|
42
|
+
for (const parameter of fn.parameters) {
|
|
43
|
+
if (parameter.closureIndex !== undefined)
|
|
44
|
+
indices.add(parameter.closureIndex);
|
|
45
|
+
if (parameter.destroyIndex !== undefined)
|
|
46
|
+
indices.add(parameter.destroyIndex);
|
|
47
|
+
}
|
|
48
|
+
return indices;
|
|
49
|
+
};
|
|
50
|
+
const arrayLengthIndices = (fn) => {
|
|
51
|
+
const map = arrayLengthSources(fn);
|
|
52
|
+
return new Set(map.keys());
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Maps each array-length parameter's index to the array parameter whose
|
|
56
|
+
* `.length` supplies it.
|
|
57
|
+
*
|
|
58
|
+
* @param fn - The callable
|
|
59
|
+
*/
|
|
60
|
+
export const arrayLengthSources = (fn) => {
|
|
61
|
+
const map = new Map();
|
|
62
|
+
fn.parameters.forEach((parameter, index) => {
|
|
63
|
+
if (parameter.type?.kind !== "array")
|
|
64
|
+
return;
|
|
65
|
+
const lengthIndex = parameter.type.lengthParameterIndex;
|
|
66
|
+
if (lengthIndex === undefined)
|
|
67
|
+
return;
|
|
68
|
+
map.set(lengthIndex, index);
|
|
69
|
+
});
|
|
70
|
+
return map;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Indices of parameters consumed as the length of the return array (and so
|
|
74
|
+
* dropped from the return tuple).
|
|
75
|
+
*
|
|
76
|
+
* @param fn - The callable
|
|
77
|
+
*/
|
|
78
|
+
export const returnArrayLengthIndices = (fn) => {
|
|
79
|
+
if (fn.returnValue.type?.kind !== "array")
|
|
80
|
+
return new Set();
|
|
81
|
+
const lengthIndex = fn.returnValue.type.lengthParameterIndex;
|
|
82
|
+
if (lengthIndex === undefined)
|
|
83
|
+
return new Set();
|
|
84
|
+
return new Set([lengthIndex]);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Whether a parameter is passed to the FFI binding as a `t.ref(...)` cell.
|
|
88
|
+
*
|
|
89
|
+
* Pure out parameters marshal through a `{ value }` ref cell the native layer
|
|
90
|
+
* writes into. Inout parameters do too — except handle-passing ones
|
|
91
|
+
* (objects, interfaces, boxed), which are passed by their existing handle
|
|
92
|
+
* and mutated in place, not through a pointer-to-pointer cell.
|
|
93
|
+
* Caller-allocated outs pass a pre-built handle and are excluded.
|
|
94
|
+
*
|
|
95
|
+
* @param context - The module context
|
|
96
|
+
* @param parameter - The parameter to test
|
|
97
|
+
*/
|
|
98
|
+
export const needsRefArg = (context, parameter) => {
|
|
99
|
+
if (parameter.direction !== "out" && parameter.direction !== "inout")
|
|
100
|
+
return false;
|
|
101
|
+
const passesHandleDirectly = (parameter.callerAllocates || parameter.direction === "inout") &&
|
|
102
|
+
parameter.type !== undefined &&
|
|
103
|
+
isHandlePassing(context, parameter.type);
|
|
104
|
+
return !passesHandleDirectly;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Whether a caller-allocated-out parameter is one the body can materialize and
|
|
108
|
+
* collect into the return — a boxed record or class the runtime can allocate
|
|
109
|
+
* via its wrapper constructor. Array and other caller-out buffers cannot be
|
|
110
|
+
* allocated here, so they are excluded from both the body and the return type.
|
|
111
|
+
*
|
|
112
|
+
* @param context - The module context
|
|
113
|
+
* @param parameter - The parameter to test
|
|
114
|
+
*/
|
|
115
|
+
export const isCollectibleCallerOut = (context, parameter) => {
|
|
116
|
+
if (parameter.type === undefined || parameter.type.kind !== "named")
|
|
117
|
+
return false;
|
|
118
|
+
const resolved = context.repository.resolveNamed(parameter.type.namespaceName ?? context.namespace.name, parameter.type.typeName);
|
|
119
|
+
return resolved?.kind === "boxed" || resolved?.kind === "class";
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Whether a value of `ref` is passed across the FFI boundary as a native
|
|
123
|
+
* handle (object, interface, boxed, or an alias to one) instead of by value.
|
|
124
|
+
*
|
|
125
|
+
* @param context - The module context
|
|
126
|
+
* @param ref - The type reference to test
|
|
127
|
+
*/
|
|
128
|
+
export const isHandlePassing = (context, ref) => {
|
|
129
|
+
if (ref.kind !== "named")
|
|
130
|
+
return false;
|
|
131
|
+
const owner = ref.namespaceName ?? context.namespace.name;
|
|
132
|
+
const resolved = context.repository.resolveNamed(owner, ref.typeName);
|
|
133
|
+
if (resolved === undefined)
|
|
134
|
+
return true;
|
|
135
|
+
switch (resolved.kind) {
|
|
136
|
+
case "class":
|
|
137
|
+
case "interface":
|
|
138
|
+
case "boxed":
|
|
139
|
+
return true;
|
|
140
|
+
case "alias": {
|
|
141
|
+
const target = resolved.targetRef;
|
|
142
|
+
if (target === undefined || target.kind !== "named")
|
|
143
|
+
return false;
|
|
144
|
+
return isHandlePassing(context, target);
|
|
145
|
+
}
|
|
146
|
+
case "enum":
|
|
147
|
+
case "callback":
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The JavaScript identifier for a parameter: the camelCased GIR name, or
|
|
153
|
+
* `arg<index>` for an unnamed position.
|
|
154
|
+
*
|
|
155
|
+
* @param parameter - The GIR parameter
|
|
156
|
+
* @param index - The parameter's position in the callable
|
|
157
|
+
*/
|
|
158
|
+
export const parameterIdentifier = (parameter, index) => {
|
|
159
|
+
if (parameter.name.length === 0)
|
|
160
|
+
return `arg${index}`;
|
|
161
|
+
return toIdentifier(toCamelCase(parameter.name));
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=param-classify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param-classify.js","sourceRoot":"","sources":["../../src/writers/param-classify.ts"],"names":[],"mappings":"AAAA,O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SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC;QACb,KAAK,WAAW,CAAC;QACjB,KAAK,OAAO;YACR,OAAO,IAAI,CAAC;QAChB,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC;YAClC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAO,KAAK,CAAC;YAClE,OAAO,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU;YACX,OAAO,KAAK,CAAC;IACrB,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAuB,EAAE,KAAa,EAAU,EAAE;IAClF,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,KAAK,EAAE,CAAC;IACtD,OAAO,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModuleContext } from "../dsl/context.js";
|
|
2
|
+
import type { GirFunction } from "../gir/function.js";
|
|
3
|
+
import type { GirProperty } from "../gir/property.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders the `get` / `set` accessor pair for a single GObject property
|
|
6
|
+
* on a class declaration.
|
|
7
|
+
*
|
|
8
|
+
* Read-only properties get only a getter; readonly + non-writable
|
|
9
|
+
* properties are skipped entirely. Properties whose name has already
|
|
10
|
+
* been claimed by an emitted method (its camelCase form clashes) are
|
|
11
|
+
* skipped, since the method takes precedence — the runtime accessor is
|
|
12
|
+
* always reachable via `this.getProperty(girName)` in that case.
|
|
13
|
+
*
|
|
14
|
+
* @param context - The module context
|
|
15
|
+
* @param property - The property to surface
|
|
16
|
+
* @param claimedNames - Names already used by emitted methods
|
|
17
|
+
*/
|
|
18
|
+
export declare const renderPropertyAccessor: (context: ModuleContext, property: GirProperty, claimedNames: ReadonlySet<string>, methodByName: ReadonlyMap<string, GirFunction>) => string | undefined;
|
|
19
|
+
//# sourceMappingURL=property-accessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-accessor.d.ts","sourceRoot":"","sources":["../../src/writers/property-accessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA2BtD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,GAC/B,SAAS,aAAa,EACtB,UAAU,WAAW,EACrB,cAAc,WAAW,CAAC,MAAM,CAAC,EACjC,cAAc,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,KAC/C,MAAM,GAAG,SAiCX,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { quote, toCamelCase, toIdentifier } from "@gtkx/utils";
|
|
2
|
+
import { indent } from "../dsl/emit.js";
|
|
3
|
+
import { renderMethodReturnType } from "./method.js";
|
|
4
|
+
import { renderTsType } from "./ts-type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Whether a GObject property of `type` can hold `null`.
|
|
7
|
+
*
|
|
8
|
+
* Reference values — objects, boxed records, interfaces, and containers —
|
|
9
|
+
* marshal to `null` when unset; scalar value types (numbers, booleans,
|
|
10
|
+
* strings, `unichar`, enums) are surfaced non-null to match their typed
|
|
11
|
+
* setters. Aliases resolve to their target.
|
|
12
|
+
*
|
|
13
|
+
* @param context - The module context
|
|
14
|
+
* @param type - The property's value type
|
|
15
|
+
*/
|
|
16
|
+
const isNullablePropertyType = (context, type) => {
|
|
17
|
+
if (type === undefined)
|
|
18
|
+
return false;
|
|
19
|
+
if (type.kind === "primitive")
|
|
20
|
+
return false;
|
|
21
|
+
if (type.kind !== "named")
|
|
22
|
+
return true;
|
|
23
|
+
const resolved = context.repository.resolveNamed(type.namespaceName ?? context.namespace.name, type.typeName);
|
|
24
|
+
if (resolved === undefined)
|
|
25
|
+
return true;
|
|
26
|
+
if (resolved.kind === "enum")
|
|
27
|
+
return false;
|
|
28
|
+
if (resolved.kind === "alias")
|
|
29
|
+
return isNullablePropertyType(context, resolved.targetRef);
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Renders the `get` / `set` accessor pair for a single GObject property
|
|
34
|
+
* on a class declaration.
|
|
35
|
+
*
|
|
36
|
+
* Read-only properties get only a getter; readonly + non-writable
|
|
37
|
+
* properties are skipped entirely. Properties whose name has already
|
|
38
|
+
* been claimed by an emitted method (its camelCase form clashes) are
|
|
39
|
+
* skipped, since the method takes precedence — the runtime accessor is
|
|
40
|
+
* always reachable via `this.getProperty(girName)` in that case.
|
|
41
|
+
*
|
|
42
|
+
* @param context - The module context
|
|
43
|
+
* @param property - The property to surface
|
|
44
|
+
* @param claimedNames - Names already used by emitted methods
|
|
45
|
+
*/
|
|
46
|
+
export const renderPropertyAccessor = (context, property, claimedNames, methodByName) => {
|
|
47
|
+
const jsName = toIdentifier(toCamelCase(property.name));
|
|
48
|
+
if (claimedNames.has(jsName))
|
|
49
|
+
return undefined;
|
|
50
|
+
if (jsName === "constructor")
|
|
51
|
+
return undefined;
|
|
52
|
+
const writable = property.writable || property.construct || property.constructOnly;
|
|
53
|
+
const getterMember = delegateMember(property.getter, jsName, claimedNames);
|
|
54
|
+
const getMethod = getterMember !== undefined && property.getter !== undefined ? methodByName.get(property.getter) : undefined;
|
|
55
|
+
const setterMember = writable ? delegateMember(property.setter, jsName, claimedNames) : undefined;
|
|
56
|
+
const setMethod = setterMember !== undefined && property.setter !== undefined ? methodByName.get(property.setter) : undefined;
|
|
57
|
+
const setParam = setMethod?.parameters[0];
|
|
58
|
+
const tsType = setParam !== undefined
|
|
59
|
+
? renderTsType(context, setParam.type, setParam.nullable || setParam.optional)
|
|
60
|
+
: getMethod !== undefined
|
|
61
|
+
? renderMethodReturnType(context, getMethod)
|
|
62
|
+
: renderTsType(context, property.type, isNullablePropertyType(context, property.type));
|
|
63
|
+
const blocks = [];
|
|
64
|
+
const getBody = renderGetterBody({ context, property, getterMember, getMethod, tsType });
|
|
65
|
+
blocks.push(`get ${jsName}(): ${tsType} {\n${indent(getBody, 1)}\n}`);
|
|
66
|
+
if (writable) {
|
|
67
|
+
const setBody = setterMember !== undefined
|
|
68
|
+
? `this.${setterMember}(value);`
|
|
69
|
+
: `this.setProperty(${quote(property.name)}, value);`;
|
|
70
|
+
blocks.push(`set ${jsName}(value: ${tsType}) {\n${indent(setBody, 1)}\n}`);
|
|
71
|
+
}
|
|
72
|
+
return blocks.join("\n\n");
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Renders a property getter body.
|
|
76
|
+
*
|
|
77
|
+
* The property type follows the setter's parameter (what callers may assign),
|
|
78
|
+
* so a getter whose own GIR nullability differs is narrowed to it with a single
|
|
79
|
+
* assertion; matching nullability needs no cast. Properties with no typed
|
|
80
|
+
* getter read through the generic `getProperty` GValue path.
|
|
81
|
+
*
|
|
82
|
+
* @param options - {@link GetterBodyOptions}
|
|
83
|
+
*/
|
|
84
|
+
const renderGetterBody = (options) => {
|
|
85
|
+
const { context, property, getterMember, getMethod, tsType } = options;
|
|
86
|
+
if (getterMember === undefined)
|
|
87
|
+
return `return this.getProperty(${quote(property.name)}) as ${tsType};`;
|
|
88
|
+
if (getMethod === undefined)
|
|
89
|
+
return `return this.${getterMember}() as ${tsType};`;
|
|
90
|
+
const getType = renderMethodReturnType(context, getMethod);
|
|
91
|
+
return getType === tsType ? `return this.${getterMember}();` : `return this.${getterMember}() as ${tsType};`;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Resolves a property's GIR `getter`/`setter` method name to the camelCase
|
|
95
|
+
* member to delegate the accessor to, or `undefined` to fall back to the
|
|
96
|
+
* generic `getProperty`/`setProperty` GValue path.
|
|
97
|
+
*
|
|
98
|
+
* Delegation is used only when the named method was actually emitted on the
|
|
99
|
+
* class (so object, interface, and boxed values marshal through their typed
|
|
100
|
+
* setter rather than the GValue `valueFromJS` path) and the member name does
|
|
101
|
+
* not collide with the accessor itself, which would recurse.
|
|
102
|
+
*
|
|
103
|
+
* @param accessorName - The accessor's own camelCase member name
|
|
104
|
+
* @param attribute - The GIR `getter`/`setter` attribute, if present
|
|
105
|
+
* @param claimedNames - Names already emitted as methods on the class
|
|
106
|
+
*/
|
|
107
|
+
const delegateMember = (attribute, accessorName, claimedNames) => {
|
|
108
|
+
if (attribute === undefined)
|
|
109
|
+
return undefined;
|
|
110
|
+
const member = toCamelCase(attribute);
|
|
111
|
+
if (member === accessorName)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (!claimedNames.has(member))
|
|
114
|
+
return undefined;
|
|
115
|
+
return member;
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=property-accessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-accessor.js","sourceRoot":"","sources":["../../src/writers/property-accessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,sBAAsB,GAAG,CAAC,OAAsB,EAAE,IAA4B,EAAW,EAAE;IAC7F,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrC,IAAI,IAA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type { ModuleContext } from "../dsl/context.js";
|
|
2
|
+
/**
|
|
3
|
+
* The pre-rendered pieces of a single `registerNativeClass(...)` descriptor.
|
|
4
|
+
*
|
|
5
|
+
* Each metadata field is the already-rendered object-literal fragment for that
|
|
6
|
+
* descriptor key, or `undefined` when the type contributes nothing for it.
|
|
7
|
+
*/
|
|
8
|
+
export type NativeClassRegistration = {
|
|
9
|
+
readonly className: string;
|
|
10
|
+
readonly role: "class" | "interface" | "boxed";
|
|
11
|
+
readonly getTypeRef?: string | undefined;
|
|
12
|
+
readonly construction?: string | undefined;
|
|
13
|
+
readonly vfuncs?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Appends the single `registerNativeClass(Class, { … })` registration that
|
|
17
|
+
* collapses a type's GType, construction, and vfunc metadata into one
|
|
18
|
+
* module-load call.
|
|
19
|
+
*
|
|
20
|
+
* Emits nothing when the registration carries no metadata at all, so callers
|
|
21
|
+
* can pass the result of optional sub-renderers without pre-checking.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The module context
|
|
24
|
+
* @param registration - The pre-rendered descriptor pieces
|
|
25
|
+
*/
|
|
26
|
+
export declare const appendNativeClassRegistration: (context: ModuleContext, registration: NativeClassRegistration) => void;
|
|
27
|
+
//# sourceMappingURL=registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/writers/registration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,6BAA6B,GAAI,SAAS,aAAa,EAAE,cAAc,uBAAuB,KAAG,IAY7G,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { quote } from "@gtkx/utils";
|
|
2
|
+
import { indent } from "../dsl/emit.js";
|
|
3
|
+
/**
|
|
4
|
+
* Appends the single `registerNativeClass(Class, { … })` registration that
|
|
5
|
+
* collapses a type's GType, construction, and vfunc metadata into one
|
|
6
|
+
* module-load call.
|
|
7
|
+
*
|
|
8
|
+
* Emits nothing when the registration carries no metadata at all, so callers
|
|
9
|
+
* can pass the result of optional sub-renderers without pre-checking.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The module context
|
|
12
|
+
* @param registration - The pre-rendered descriptor pieces
|
|
13
|
+
*/
|
|
14
|
+
export const appendNativeClassRegistration = (context, registration) => {
|
|
15
|
+
const { className, role, getTypeRef, construction, vfuncs } = registration;
|
|
16
|
+
if (getTypeRef === undefined && construction === undefined && vfuncs === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
context.addRuntimeImport("registerNativeClass");
|
|
20
|
+
const lines = [`role: ${quote(role)},`];
|
|
21
|
+
if (getTypeRef !== undefined)
|
|
22
|
+
lines.push(`gtype: ${getTypeRef},`);
|
|
23
|
+
if (construction !== undefined)
|
|
24
|
+
lines.push(`construction: ${construction},`);
|
|
25
|
+
if (vfuncs !== undefined)
|
|
26
|
+
lines.push(`vfuncs: ${vfuncs},`);
|
|
27
|
+
const body = lines.map((line) => indent(line, 1)).join("\n");
|
|
28
|
+
context.module.appendRegistration(`registerNativeClass(${className}, {\n${body}\n});`);
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/writers/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAgBxC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,OAAsB,EAAE,YAAqC,EAAQ,EAAE;IACjH,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IAC3E,IAAI,UAAU,KAAK,SAAS,IAAI,YAAY,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACjF,OAAO;IACX,CAAC;IACD,OAAO,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAChD,MAAM,KAAK,GAAa,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,UAAU,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,UAAU,UAAU,GAAG,CAAC,CAAC;IAClE,IAAI,YAAY,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,YAAY,GAAG,CAAC,CAAC;IAC7E,IAAI,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,GAAG,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,SAAS,QAAQ,IAAI,OAAO,CAAC,CAAC;AAC3F,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ModuleContext } from "../dsl/context.js";
|
|
2
|
+
import type { ParameterTransfer } from "../gir/parameter.js";
|
|
3
|
+
import type { GirTypeRef } from "../gir/type-ref.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lifting raw FFI call results into their typed JavaScript form: objects to
|
|
6
|
+
* their runtime-registered wrappers, boxed values to typed wrappers,
|
|
7
|
+
* collections per element, and primitives with the appropriate coercion.
|
|
8
|
+
* Shared by method-body return handling, signal/callback argument marshalling,
|
|
9
|
+
* and boxed field accessors.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Casts a raw FFI call result to a native handle so the registry wrappers
|
|
13
|
+
* (`getNativeObject` / `getNativeObjectAsInterface`) accept it. The cast widens
|
|
14
|
+
* to `NativeHandle | null` for a GIR-nullable value so the wrapper result type
|
|
15
|
+
* stays nullable, matching the declared return.
|
|
16
|
+
*/
|
|
17
|
+
export declare const handleCast: (context: ModuleContext, valueExpression: string, nullable: boolean) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Inputs for {@link wrapReturnValue}.
|
|
20
|
+
*/
|
|
21
|
+
export type WrapReturnOptions = {
|
|
22
|
+
readonly ref: GirTypeRef | undefined;
|
|
23
|
+
readonly transfer: ParameterTransfer;
|
|
24
|
+
readonly nullable: boolean;
|
|
25
|
+
readonly valueExpression: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Wraps a raw FFI value into its typed JavaScript form.
|
|
29
|
+
*
|
|
30
|
+
* Objects resolve to their runtime-registered wrapper, interfaces to the
|
|
31
|
+
* interface wrapper, boxed values to a typed wrapper, collections recurse per
|
|
32
|
+
* element, and primitives pass through with the appropriate coercion. Shared
|
|
33
|
+
* by return-value handling and signal-handler argument marshalling.
|
|
34
|
+
*
|
|
35
|
+
* @param context - The module context
|
|
36
|
+
* @param options - {@link WrapReturnOptions}
|
|
37
|
+
*/
|
|
38
|
+
export declare const wrapReturnValue: (context: ModuleContext, options: WrapReturnOptions) => string;
|
|
39
|
+
//# sourceMappingURL=return-wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"return-wrap.d.ts","sourceRoot":"","sources":["../../src/writers/return-wrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAkC,MAAM,oBAAoB,CAAC;AAGrF;;;;;;GAMG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,aAAa,EAAE,iBAAiB,MAAM,EAAE,UAAU,OAAO,KAAG,MAG/F,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,aAAa,EAAE,SAAS,iBAAiB,KAAG,MAsBpF,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { renderTsType } from "./ts-type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Lifting raw FFI call results into their typed JavaScript form: objects to
|
|
4
|
+
* their runtime-registered wrappers, boxed values to typed wrappers,
|
|
5
|
+
* collections per element, and primitives with the appropriate coercion.
|
|
6
|
+
* Shared by method-body return handling, signal/callback argument marshalling,
|
|
7
|
+
* and boxed field accessors.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Casts a raw FFI call result to a native handle so the registry wrappers
|
|
11
|
+
* (`getNativeObject` / `getNativeObjectAsInterface`) accept it. The cast widens
|
|
12
|
+
* to `NativeHandle | null` for a GIR-nullable value so the wrapper result type
|
|
13
|
+
* stays nullable, matching the declared return.
|
|
14
|
+
*/
|
|
15
|
+
export const handleCast = (context, valueExpression, nullable) => {
|
|
16
|
+
context.addNativeTypeImport("NativeHandle");
|
|
17
|
+
return `${valueExpression} as NativeHandle${nullable ? " | null" : ""}`;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wraps a raw FFI value into its typed JavaScript form.
|
|
21
|
+
*
|
|
22
|
+
* Objects resolve to their runtime-registered wrapper, interfaces to the
|
|
23
|
+
* interface wrapper, boxed values to a typed wrapper, collections recurse per
|
|
24
|
+
* element, and primitives pass through with the appropriate coercion. Shared
|
|
25
|
+
* by return-value handling and signal-handler argument marshalling.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The module context
|
|
28
|
+
* @param options - {@link WrapReturnOptions}
|
|
29
|
+
*/
|
|
30
|
+
export const wrapReturnValue = (context, options) => {
|
|
31
|
+
const { ref, nullable, valueExpression } = options;
|
|
32
|
+
if (ref === undefined)
|
|
33
|
+
return valueExpression;
|
|
34
|
+
switch (ref.kind) {
|
|
35
|
+
case "primitive":
|
|
36
|
+
return wrapPrimitive(ref, nullable, valueExpression);
|
|
37
|
+
case "named":
|
|
38
|
+
return wrapNamed(context, ref, valueExpression, nullable);
|
|
39
|
+
case "array":
|
|
40
|
+
return wrapCollection(context, ref.element, valueExpression, nullable);
|
|
41
|
+
case "list":
|
|
42
|
+
return ref.flavor === "gbytearray"
|
|
43
|
+
? `(${valueExpression} as number[]${nullable ? " | null" : ""})`
|
|
44
|
+
: wrapCollection(context, ref.element, valueExpression, nullable);
|
|
45
|
+
case "hashtable":
|
|
46
|
+
return nullable
|
|
47
|
+
? `(${valueExpression} === null ? null : new globalThis.Map(${valueExpression} as Iterable<readonly [unknown, unknown]>))`
|
|
48
|
+
: `new globalThis.Map(${valueExpression} as Iterable<readonly [unknown, unknown]>)`;
|
|
49
|
+
case "callback":
|
|
50
|
+
case "varargs":
|
|
51
|
+
return `(${valueExpression} as unknown[])`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Wraps a collection return value, mapping each element through the runtime
|
|
56
|
+
* wrapper its type requires.
|
|
57
|
+
*
|
|
58
|
+
* The native layer hands collection returns back as arrays of raw element
|
|
59
|
+
* values; object, interface, and boxed elements must be lifted into their
|
|
60
|
+
* typed JavaScript wrappers (matching the per-element wrapping a scalar
|
|
61
|
+
* return of the same type receives) while primitive and enum elements pass
|
|
62
|
+
* through untouched.
|
|
63
|
+
*/
|
|
64
|
+
const wrapCollection = (context, element, valueExpression, nullable) => {
|
|
65
|
+
const itemExpression = collectionItemWrap(context, element);
|
|
66
|
+
if (itemExpression === undefined) {
|
|
67
|
+
const elementTs = element === undefined ? "unknown" : renderTsType(context, element, false);
|
|
68
|
+
return `(${valueExpression} as ${elementTs}[]${nullable ? " | null" : ""})`;
|
|
69
|
+
}
|
|
70
|
+
return nullable
|
|
71
|
+
? `((${valueExpression} as unknown[] | null)?.map((item) => ${itemExpression}) ?? null)`
|
|
72
|
+
: `(${valueExpression} as unknown[]).map((item) => ${itemExpression})`;
|
|
73
|
+
};
|
|
74
|
+
const collectionItemWrap = (context, element) => {
|
|
75
|
+
if (element === undefined || element.kind !== "named")
|
|
76
|
+
return undefined;
|
|
77
|
+
const owner = element.namespaceName ?? context.namespace.name;
|
|
78
|
+
const resolved = context.repository.resolveNamed(owner, element.typeName);
|
|
79
|
+
if (resolved === undefined) {
|
|
80
|
+
context.addRuntimeImport("getNativeObject");
|
|
81
|
+
return `getNativeObject(${handleCast(context, "item", false)})`;
|
|
82
|
+
}
|
|
83
|
+
switch (resolved.kind) {
|
|
84
|
+
case "class":
|
|
85
|
+
case "boxed":
|
|
86
|
+
context.addRuntimeImport("getNativeObject");
|
|
87
|
+
return `getNativeObject(${handleCast(context, "item", false)})`;
|
|
88
|
+
case "interface": {
|
|
89
|
+
context.addRuntimeImport("getNativeObjectAsInterface");
|
|
90
|
+
return `getNativeObjectAsInterface(${handleCast(context, "item", false)}, ${context.qualify(owner, element.typeName)})`;
|
|
91
|
+
}
|
|
92
|
+
case "alias":
|
|
93
|
+
return resolved.target === undefined
|
|
94
|
+
? undefined
|
|
95
|
+
: collectionItemWrap(context, {
|
|
96
|
+
kind: "named",
|
|
97
|
+
namespaceName: resolved.namespace.name,
|
|
98
|
+
typeName: resolved.target,
|
|
99
|
+
cType: undefined,
|
|
100
|
+
});
|
|
101
|
+
case "enum":
|
|
102
|
+
case "callback":
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const wrapPrimitive = (ref, nullable, valueExpression) => {
|
|
107
|
+
const category = ref.category;
|
|
108
|
+
if (category === "void")
|
|
109
|
+
return valueExpression;
|
|
110
|
+
if (category === "string")
|
|
111
|
+
return `(${valueExpression} as ${nullable ? "string | null" : "string"})`;
|
|
112
|
+
if (category === "boolean")
|
|
113
|
+
return `Boolean(${valueExpression})`;
|
|
114
|
+
return `(${valueExpression} as number)`;
|
|
115
|
+
};
|
|
116
|
+
const wrapNamed = (context, ref, valueExpression, nullable) => {
|
|
117
|
+
const owner = ref.namespaceName ?? context.namespace.name;
|
|
118
|
+
const resolved = context.repository.resolveNamed(owner, ref.typeName);
|
|
119
|
+
if (resolved === undefined) {
|
|
120
|
+
context.addRuntimeImport("getNativeObject");
|
|
121
|
+
return `getNativeObject(${handleCast(context, valueExpression, nullable)})`;
|
|
122
|
+
}
|
|
123
|
+
return wrapResolved(context, resolved, { namespaceName: owner, typeName: ref.typeName, valueExpression, nullable });
|
|
124
|
+
};
|
|
125
|
+
const wrapResolved = (context, resolved, options) => {
|
|
126
|
+
const { namespaceName, typeName, valueExpression, nullable } = options;
|
|
127
|
+
switch (resolved.kind) {
|
|
128
|
+
case "class": {
|
|
129
|
+
context.addRuntimeImport("getNativeObject");
|
|
130
|
+
return `getNativeObject(${handleCast(context, valueExpression, nullable)})`;
|
|
131
|
+
}
|
|
132
|
+
case "interface": {
|
|
133
|
+
const classExpression = context.qualify(namespaceName, typeName);
|
|
134
|
+
context.addRuntimeImport("getNativeObjectAsInterface");
|
|
135
|
+
return `getNativeObjectAsInterface(${handleCast(context, valueExpression, nullable)}, ${classExpression})`;
|
|
136
|
+
}
|
|
137
|
+
case "boxed": {
|
|
138
|
+
const classExpression = context.qualify(namespaceName, typeName);
|
|
139
|
+
context.addRuntimeImport("getNativeObject");
|
|
140
|
+
return `getNativeObject(${handleCast(context, valueExpression, nullable)}, ${classExpression})`;
|
|
141
|
+
}
|
|
142
|
+
case "enum":
|
|
143
|
+
return `(${valueExpression} as number)`;
|
|
144
|
+
case "callback":
|
|
145
|
+
return valueExpression;
|
|
146
|
+
case "alias":
|
|
147
|
+
return resolved.targetRef === undefined
|
|
148
|
+
? valueExpression
|
|
149
|
+
: wrapReturnValue(context, { ref: resolved.targetRef, transfer: "full", nullable, valueExpression });
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=return-wrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"return-wrap.js","sourceRoot":"","sources":["../../src/writers/return-wrap.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAsB,EAAE,eAAuB,EAAE,QAAiB,EAAU,EAAE;IACrG,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC5C,OAAO,GAAG,eAAe,mBAAmB,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC5E,CAAC,CAAC;AAYF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAsB,EAAE,OAA0B,EAAU,EAAE;IAC1F,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACnD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;I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AK,UAAU;YACX,OAAO,eAAe,CAAC;QAC3B,KAAK,OAAO;YACR,OAAO,QAAQ,CAAC,SAAS,KAAK,SAAS;gBACnC,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC;IACjH,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GirFunction } from "../gir/function.js";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the method body for a callable whose marshaling is provided by a
|
|
4
|
+
* hand-written runtime override.
|
|
5
|
+
*
|
|
6
|
+
* `gpointer` exchanges (`GValue` boxed accessors and similar) cannot be
|
|
7
|
+
* marshaled from GIR alone; the FFI runtime replaces them on the prototype
|
|
8
|
+
* at module load. The codegen emits a stub with the override's signature
|
|
9
|
+
* so the consumer types resolve to the runtime shape and the runtime's
|
|
10
|
+
* `prototype` assignment type-checks.
|
|
11
|
+
*
|
|
12
|
+
* Returns `undefined` for callables without a registered override.
|
|
13
|
+
*
|
|
14
|
+
* @param callable - The callable to consider
|
|
15
|
+
* @param memberName - The camelCase JS method name
|
|
16
|
+
*/
|
|
17
|
+
export declare const renderRuntimeOverride: (callable: GirFunction, memberName: string) => string | undefined;
|
|
18
|
+
//# sourceMappingURL=runtime-override.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-override.d.ts","sourceRoot":"","sources":["../../src/writers/runtime-override.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqCtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,WAAW,EAAE,YAAY,MAAM,KAAG,MAAM,GAAG,SAM1F,CAAC"}
|