@gtkx/codegen 1.0.0-rc.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/analysis/descriptor-render.d.ts +8 -1
- package/dist/analysis/descriptor-render.d.ts.map +1 -1
- package/dist/analysis/descriptor-render.js +37 -24
- package/dist/analysis/descriptor-render.js.map +1 -1
- package/dist/analysis/descriptor.d.ts +1 -1
- package/dist/analysis/descriptor.d.ts.map +1 -1
- package/dist/analysis/descriptor.js.map +1 -1
- package/dist/analysis/inheritance.d.ts +1 -2
- package/dist/analysis/inheritance.d.ts.map +1 -1
- package/dist/analysis/inheritance.js +25 -22
- package/dist/analysis/inheritance.js.map +1 -1
- package/dist/analysis/nul-terminated-bytes.d.ts +5 -0
- package/dist/analysis/nul-terminated-bytes.d.ts.map +1 -0
- package/dist/analysis/nul-terminated-bytes.js +18 -0
- package/dist/analysis/nul-terminated-bytes.js.map +1 -0
- package/dist/analysis/param-capability.d.ts +5 -0
- package/dist/analysis/param-capability.d.ts.map +1 -0
- package/dist/analysis/param-capability.js +130 -0
- package/dist/analysis/param-capability.js.map +1 -0
- package/dist/analysis/param-structure.d.ts +11 -4
- package/dist/analysis/param-structure.d.ts.map +1 -1
- package/dist/analysis/param-structure.js +40 -14
- package/dist/analysis/param-structure.js.map +1 -1
- package/dist/analysis/type-shape.d.ts +8 -0
- package/dist/analysis/type-shape.d.ts.map +1 -0
- package/dist/analysis/type-shape.js +12 -0
- package/dist/analysis/type-shape.js.map +1 -0
- package/dist/compile.d.ts +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js.map +1 -1
- package/dist/docs/api-reference.d.ts +2 -2
- package/dist/docs/api-reference.d.ts.map +1 -1
- package/dist/docs/api-reference.js +7 -14
- package/dist/docs/api-reference.js.map +1 -1
- package/dist/docs/element-page.d.ts +4 -4
- package/dist/docs/element-page.d.ts.map +1 -1
- package/dist/docs/element-page.js +32 -20
- package/dist/docs/element-page.js.map +1 -1
- package/dist/docs/handwritten-props.d.ts +9 -0
- package/dist/docs/handwritten-props.d.ts.map +1 -0
- package/dist/docs/handwritten-props.js +149 -0
- package/dist/docs/handwritten-props.js.map +1 -0
- package/dist/docs/pipeline.js +2 -2
- package/dist/docs/pipeline.js.map +1 -1
- package/dist/docs/render.d.ts +25 -5
- package/dist/docs/render.d.ts.map +1 -1
- package/dist/docs/render.js +84 -22
- package/dist/docs/render.js.map +1 -1
- package/dist/docs/symbol-page.d.ts +17 -0
- package/dist/docs/symbol-page.d.ts.map +1 -1
- package/dist/docs/symbol-page.js +128 -43
- package/dist/docs/symbol-page.js.map +1 -1
- package/dist/fingerprint.d.ts +1 -1
- package/dist/fingerprint.d.ts.map +1 -1
- package/dist/fingerprint.js.map +1 -1
- package/dist/gir/ancestry.d.ts +2 -2
- package/dist/gir/ancestry.d.ts.map +1 -1
- package/dist/gir/ancestry.js +11 -1
- package/dist/gir/ancestry.js.map +1 -1
- package/dist/gir/annotations.d.ts +22 -0
- package/dist/gir/annotations.d.ts.map +1 -0
- package/dist/gir/annotations.js +15 -0
- package/dist/gir/annotations.js.map +1 -0
- package/dist/gir/callback.d.ts +1 -0
- package/dist/gir/callback.d.ts.map +1 -1
- package/dist/gir/callback.js +1 -0
- package/dist/gir/callback.js.map +1 -1
- package/dist/gir/class.d.ts +32 -1
- package/dist/gir/class.d.ts.map +1 -1
- package/dist/gir/class.js +8 -3
- package/dist/gir/class.js.map +1 -1
- package/dist/gir/enum.d.ts +21 -1
- package/dist/gir/enum.d.ts.map +1 -1
- package/dist/gir/enum.js +9 -9
- package/dist/gir/enum.js.map +1 -1
- package/dist/gir/field.d.ts +19 -3
- package/dist/gir/field.d.ts.map +1 -1
- package/dist/gir/field.js +7 -8
- package/dist/gir/field.js.map +1 -1
- package/dist/gir/function.d.ts +15 -0
- package/dist/gir/function.d.ts.map +1 -1
- package/dist/gir/function.js.map +1 -1
- package/dist/gir/libraries.d.ts +1 -3
- package/dist/gir/libraries.d.ts.map +1 -1
- package/dist/gir/libraries.js +0 -1
- package/dist/gir/libraries.js.map +1 -1
- package/dist/gir/library.d.ts +36 -0
- package/dist/gir/library.d.ts.map +1 -1
- package/dist/gir/library.js +34 -0
- package/dist/gir/library.js.map +1 -1
- package/dist/gir/namespace.d.ts +38 -0
- package/dist/gir/namespace.d.ts.map +1 -1
- package/dist/gir/namespace.js +4 -5
- package/dist/gir/namespace.js.map +1 -1
- package/dist/gir/parameter.d.ts +39 -0
- package/dist/gir/parameter.d.ts.map +1 -1
- package/dist/gir/parameter.js +7 -3
- package/dist/gir/parameter.js.map +1 -1
- package/dist/gir/parse.d.ts +3 -1
- package/dist/gir/parse.d.ts.map +1 -1
- package/dist/gir/parse.js +6 -3
- package/dist/gir/parse.js.map +1 -1
- package/dist/gir/primitives.d.ts +1 -0
- package/dist/gir/primitives.d.ts.map +1 -1
- package/dist/gir/primitives.js.map +1 -1
- package/dist/gir/property.d.ts +16 -0
- package/dist/gir/property.d.ts.map +1 -1
- package/dist/gir/property.js +3 -3
- package/dist/gir/property.js.map +1 -1
- package/dist/gir/record.d.ts +22 -0
- package/dist/gir/record.d.ts.map +1 -1
- package/dist/gir/record.js +3 -2
- package/dist/gir/record.js.map +1 -1
- package/dist/gir/size.d.ts +5 -4
- package/dist/gir/size.d.ts.map +1 -1
- package/dist/gir/size.js.map +1 -1
- package/dist/gir/type-id.d.ts +35 -0
- package/dist/gir/type-id.d.ts.map +1 -1
- package/dist/gir/type-id.js +1 -0
- package/dist/gir/type-id.js.map +1 -1
- package/dist/gir/type-ref.d.ts.map +1 -1
- package/dist/gir/type-ref.js +1 -0
- package/dist/gir/type-ref.js.map +1 -1
- package/dist/gir/type.d.ts +20 -0
- package/dist/gir/type.d.ts.map +1 -1
- package/dist/gir/type.js.map +1 -1
- package/dist/khronos/args.d.ts +7 -6
- package/dist/khronos/args.d.ts.map +1 -1
- package/dist/khronos/args.js +28 -6
- package/dist/khronos/args.js.map +1 -1
- package/dist/khronos/doc-context.d.ts +29 -0
- package/dist/khronos/doc-context.d.ts.map +1 -0
- package/dist/khronos/doc-context.js +29 -0
- package/dist/khronos/doc-context.js.map +1 -0
- package/dist/khronos/extensions.d.ts +13 -0
- package/dist/khronos/extensions.d.ts.map +1 -0
- package/dist/khronos/extensions.js +49 -0
- package/dist/khronos/extensions.js.map +1 -0
- package/dist/khronos/jsdoc.d.ts +17 -11
- package/dist/khronos/jsdoc.d.ts.map +1 -1
- package/dist/khronos/jsdoc.js +104 -46
- package/dist/khronos/jsdoc.js.map +1 -1
- package/dist/khronos/model.d.ts +42 -3
- package/dist/khronos/model.d.ts.map +1 -1
- package/dist/khronos/model.js +218 -63
- package/dist/khronos/model.js.map +1 -1
- package/dist/khronos/modules.d.ts +9 -6
- package/dist/khronos/modules.d.ts.map +1 -1
- package/dist/khronos/modules.js +96 -26
- package/dist/khronos/modules.js.map +1 -1
- package/dist/khronos/notes.d.ts +19 -0
- package/dist/khronos/notes.d.ts.map +1 -0
- package/dist/khronos/notes.js +35 -0
- package/dist/khronos/notes.js.map +1 -0
- package/dist/khronos/param-pair.d.ts +1 -1
- package/dist/khronos/param-pair.d.ts.map +1 -1
- package/dist/khronos/param-pair.js.map +1 -1
- package/dist/khronos/pipeline.d.ts +3 -1
- package/dist/khronos/pipeline.d.ts.map +1 -1
- package/dist/khronos/pipeline.js +58 -27
- package/dist/khronos/pipeline.js.map +1 -1
- package/dist/khronos/plan.d.ts +3 -3
- package/dist/khronos/plan.d.ts.map +1 -1
- package/dist/khronos/plan.js +2 -2
- package/dist/khronos/plan.js.map +1 -1
- package/dist/khronos/render.d.ts +8 -6
- package/dist/khronos/render.d.ts.map +1 -1
- package/dist/khronos/render.js +35 -26
- package/dist/khronos/render.js.map +1 -1
- package/dist/khronos/select.d.ts +21 -4
- package/dist/khronos/select.d.ts.map +1 -1
- package/dist/khronos/select.js +47 -34
- package/dist/khronos/select.js.map +1 -1
- package/dist/react/element-config.d.ts +2 -2
- package/dist/react/element-config.d.ts.map +1 -1
- package/dist/react/element-config.js.map +1 -1
- package/dist/runner.d.ts +1 -7
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js.map +1 -1
- package/dist/store/compile-store.d.ts +1 -1
- package/dist/store/compile-store.d.ts.map +1 -1
- package/dist/store/compile-store.js.map +1 -1
- package/dist/store/gi/callable-doc.d.ts +11 -0
- package/dist/store/gi/callable-doc.d.ts.map +1 -0
- package/dist/store/gi/callable-doc.js +62 -0
- package/dist/store/gi/callable-doc.js.map +1 -0
- package/dist/store/gi/callables.d.ts +3 -1
- package/dist/store/gi/callables.d.ts.map +1 -1
- package/dist/store/gi/callables.js +12 -12
- package/dist/store/gi/callables.js.map +1 -1
- package/dist/store/gi/callback.d.ts.map +1 -1
- package/dist/store/gi/callback.js +2 -2
- package/dist/store/gi/callback.js.map +1 -1
- package/dist/store/gi/class.d.ts.map +1 -1
- package/dist/store/gi/class.js +5 -3
- package/dist/store/gi/class.js.map +1 -1
- package/dist/store/gi/closure-invocation.d.ts +4 -0
- package/dist/store/gi/closure-invocation.d.ts.map +1 -0
- package/dist/store/gi/closure-invocation.js +22 -0
- package/dist/store/gi/closure-invocation.js.map +1 -0
- package/dist/store/gi/constant.d.ts.map +1 -1
- package/dist/store/gi/constant.js +3 -2
- package/dist/store/gi/constant.js.map +1 -1
- package/dist/store/gi/constructor-props.d.ts.map +1 -1
- package/dist/store/gi/constructor-props.js +18 -20
- package/dist/store/gi/constructor-props.js.map +1 -1
- package/dist/store/gi/doc-spec.d.ts +14 -0
- package/dist/store/gi/doc-spec.d.ts.map +1 -0
- package/dist/store/gi/doc-spec.js +23 -0
- package/dist/store/gi/doc-spec.js.map +1 -0
- package/dist/store/gi/enum.d.ts.map +1 -1
- package/dist/store/gi/enum.js +29 -16
- package/dist/store/gi/enum.js.map +1 -1
- package/dist/store/gi/function.d.ts.map +1 -1
- package/dist/store/gi/function.js +27 -12
- package/dist/store/gi/function.js.map +1 -1
- package/dist/store/gi/interface.d.ts.map +1 -1
- package/dist/store/gi/interface.js +130 -16
- package/dist/store/gi/interface.js.map +1 -1
- package/dist/store/gi/item-comparators.d.ts.map +1 -1
- package/dist/store/gi/item-comparators.js +3 -5
- package/dist/store/gi/item-comparators.js.map +1 -1
- package/dist/store/gi/method.d.ts +9 -1
- package/dist/store/gi/method.d.ts.map +1 -1
- package/dist/store/gi/method.js +69 -26
- package/dist/store/gi/method.js.map +1 -1
- package/dist/store/gi/param-marshal.d.ts +4 -1
- package/dist/store/gi/param-marshal.d.ts.map +1 -1
- package/dist/store/gi/param-marshal.js +5 -1
- package/dist/store/gi/param-marshal.js.map +1 -1
- package/dist/store/gi/pipeline.d.ts.map +1 -1
- package/dist/store/gi/pipeline.js +3 -2
- package/dist/store/gi/pipeline.js.map +1 -1
- package/dist/store/gi/properties.d.ts.map +1 -1
- package/dist/store/gi/properties.js +2 -2
- package/dist/store/gi/properties.js.map +1 -1
- package/dist/store/gi/property-accessor.d.ts +3 -1
- package/dist/store/gi/property-accessor.d.ts.map +1 -1
- package/dist/store/gi/property-accessor.js +6 -5
- package/dist/store/gi/property-accessor.js.map +1 -1
- package/dist/store/gi/record-constructor.d.ts.map +1 -1
- package/dist/store/gi/record-constructor.js +3 -1
- package/dist/store/gi/record-constructor.js.map +1 -1
- package/dist/store/gi/record-field-accessor.d.ts +3 -1
- package/dist/store/gi/record-field-accessor.d.ts.map +1 -1
- package/dist/store/gi/record-field-accessor.js +3 -2
- package/dist/store/gi/record-field-accessor.js.map +1 -1
- package/dist/store/gi/record-layout.js +1 -1
- package/dist/store/gi/record-layout.js.map +1 -1
- package/dist/store/gi/record.d.ts.map +1 -1
- package/dist/store/gi/record.js +3 -2
- package/dist/store/gi/record.js.map +1 -1
- package/dist/store/gi/registration.d.ts +1 -1
- package/dist/store/gi/registration.js +2 -2
- package/dist/store/gi/registration.js.map +1 -1
- package/dist/store/gi/runtime-override.d.ts +2 -1
- package/dist/store/gi/runtime-override.d.ts.map +1 -1
- package/dist/store/gi/runtime-override.js +8 -5
- package/dist/store/gi/runtime-override.js.map +1 -1
- package/dist/store/gi/signal.d.ts.map +1 -1
- package/dist/store/gi/signal.js +14 -15
- package/dist/store/gi/signal.js.map +1 -1
- package/dist/store/gi/value-marshalable.d.ts +1 -2
- package/dist/store/gi/value-marshalable.d.ts.map +1 -1
- package/dist/store/gi/value-marshalable.js +1 -1
- package/dist/store/gi/value-marshalable.js.map +1 -1
- package/dist/store/gi/vtable.d.ts +16 -1
- package/dist/store/gi/vtable.d.ts.map +1 -1
- package/dist/store/gi/vtable.js +214 -51
- package/dist/store/gi/vtable.js.map +1 -1
- package/dist/store/jsx/element-components.d.ts +1 -1
- package/dist/store/jsx/element-components.d.ts.map +1 -1
- package/dist/store/jsx/element-components.js +6 -4
- package/dist/store/jsx/element-components.js.map +1 -1
- package/dist/store/jsx/element-prop-imports.d.ts +1 -3
- package/dist/store/jsx/element-prop-imports.d.ts.map +1 -1
- package/dist/store/jsx/element-prop-imports.js.map +1 -1
- package/dist/store/jsx/element-prop-types.d.ts +3 -0
- package/dist/store/jsx/element-prop-types.d.ts.map +1 -1
- package/dist/store/jsx/element-prop-types.js +7 -1
- package/dist/store/jsx/element-prop-types.js.map +1 -1
- package/dist/store/jsx/intrinsic-elements.d.ts +4 -0
- package/dist/store/jsx/intrinsic-elements.d.ts.map +1 -1
- package/dist/store/jsx/intrinsic-elements.js.map +1 -1
- package/dist/store/jsx/jsx.d.ts.map +1 -1
- package/dist/store/jsx/jsx.js +7 -6
- package/dist/store/jsx/jsx.js.map +1 -1
- package/dist/store/jsx/metadata.js +2 -2
- package/dist/store/jsx/metadata.js.map +1 -1
- package/dist/store/jsx/pipeline.d.ts +1 -1
- package/dist/store/jsx/pipeline.d.ts.map +1 -1
- package/dist/store/jsx/pipeline.js.map +1 -1
- package/dist/store/jsx/props.d.ts +1 -7
- package/dist/store/jsx/props.d.ts.map +1 -1
- package/dist/store/jsx/props.js +14 -6
- package/dist/store/jsx/props.js.map +1 -1
- package/dist/writer/context.d.ts +2 -1
- package/dist/writer/context.d.ts.map +1 -1
- package/dist/writer/context.js +3 -0
- package/dist/writer/context.js.map +1 -1
- package/dist/writer/doc-tags.d.ts +21 -0
- package/dist/writer/doc-tags.d.ts.map +1 -0
- package/dist/writer/doc-tags.js +38 -0
- package/dist/writer/doc-tags.js.map +1 -0
- package/dist/writer/doc.d.ts +3 -1
- package/dist/writer/doc.d.ts.map +1 -1
- package/dist/writer/doc.js +19 -6
- package/dist/writer/doc.js.map +1 -1
- package/dist/writer/gtk-doc.d.ts +1 -1
- package/dist/writer/gtk-doc.d.ts.map +1 -1
- package/dist/writer/gtk-doc.js +64 -15
- package/dist/writer/gtk-doc.js.map +1 -1
- package/dist/writer/module.d.ts +8 -2
- package/dist/writer/module.d.ts.map +1 -1
- package/dist/writer/module.js +13 -1
- package/dist/writer/module.js.map +1 -1
- package/overrides/gdk/rgba.ts.ejs +26 -0
- package/overrides/gobject/object.ts.ejs +48 -3
- package/overrides/gobject/value.ts.ejs +7 -0
- package/overrides/graphene/structs.ts.ejs +55 -0
- package/package.json +4 -4
- package/src/analysis/descriptor-render.ts +47 -28
- package/src/analysis/descriptor.ts +0 -3
- package/src/analysis/inheritance.ts +35 -34
- package/src/analysis/nul-terminated-bytes.ts +31 -0
- package/src/analysis/param-capability.ts +172 -0
- package/src/analysis/param-structure.ts +83 -23
- package/src/analysis/type-shape.ts +24 -0
- package/src/compile.ts +1 -1
- package/src/docs/api-reference.ts +36 -25
- package/src/docs/element-page.ts +53 -47
- package/src/docs/handwritten-props.ts +230 -0
- package/src/docs/pipeline.ts +2 -2
- package/src/docs/render.ts +146 -32
- package/src/docs/symbol-page.ts +224 -79
- package/src/fingerprint.ts +0 -1
- package/src/gir/ancestry.ts +15 -1
- package/src/gir/annotations.ts +37 -0
- package/src/gir/callback.ts +2 -0
- package/src/gir/class.ts +42 -4
- package/src/gir/enum.ts +30 -10
- package/src/gir/field.ts +24 -9
- package/src/gir/function.ts +15 -0
- package/src/gir/libraries.ts +11 -3
- package/src/gir/library.ts +51 -2
- package/src/gir/namespace.ts +41 -5
- package/src/gir/parameter.ts +47 -3
- package/src/gir/parse.ts +8 -2
- package/src/gir/primitives.ts +1 -0
- package/src/gir/property.ts +18 -3
- package/src/gir/record.ts +24 -2
- package/src/gir/size.ts +8 -3
- package/src/gir/type-id.ts +49 -3
- package/src/gir/type-ref.ts +1 -0
- package/src/gir/type.ts +50 -6
- package/src/khronos/args.ts +36 -13
- package/src/khronos/doc-context.ts +62 -0
- package/src/khronos/extensions.ts +85 -0
- package/src/khronos/jsdoc.ts +152 -56
- package/src/khronos/model.ts +314 -69
- package/src/khronos/modules.ts +134 -40
- package/src/khronos/notes.ts +74 -0
- package/src/khronos/param-pair.ts +1 -1
- package/src/khronos/pipeline.ts +94 -41
- package/src/khronos/plan.ts +4 -5
- package/src/khronos/render.ts +62 -50
- package/src/khronos/select.ts +91 -50
- package/src/react/element-config.ts +2 -2
- package/src/runner.ts +1 -8
- package/src/store/compile-store.ts +1 -1
- package/src/store/gi/callable-doc.ts +102 -0
- package/src/store/gi/callables.ts +18 -12
- package/src/store/gi/callback.ts +3 -2
- package/src/store/gi/class.ts +6 -3
- package/src/store/gi/closure-invocation.ts +26 -0
- package/src/store/gi/constant.ts +3 -4
- package/src/store/gi/constructor-props.ts +19 -23
- package/src/store/gi/doc-spec.ts +38 -0
- package/src/store/gi/enum.ts +55 -20
- package/src/store/gi/function.ts +43 -21
- package/src/store/gi/interface.ts +214 -26
- package/src/store/gi/item-comparators.ts +3 -5
- package/src/store/gi/method.ts +98 -42
- package/src/store/gi/param-marshal.ts +15 -1
- package/src/store/gi/pipeline.ts +7 -2
- package/src/store/gi/properties.ts +3 -2
- package/src/store/gi/property-accessor.ts +9 -4
- package/src/store/gi/record-constructor.ts +6 -1
- package/src/store/gi/record-field-accessor.ts +5 -3
- package/src/store/gi/record-layout.ts +1 -1
- package/src/store/gi/record.ts +8 -2
- package/src/store/gi/registration.ts +3 -3
- package/src/store/gi/runtime-override.ts +13 -6
- package/src/store/gi/signal.ts +19 -20
- package/src/store/gi/value-marshalable.ts +1 -1
- package/src/store/gi/vtable.ts +361 -60
- package/src/store/jsx/element-components.ts +8 -5
- package/src/store/jsx/element-prop-imports.ts +1 -3
- package/src/store/jsx/element-prop-types.ts +10 -1
- package/src/store/jsx/intrinsic-elements.ts +4 -0
- package/src/store/jsx/jsx.ts +8 -6
- package/src/store/jsx/metadata.ts +2 -2
- package/src/store/jsx/pipeline.ts +1 -1
- package/src/store/jsx/props.ts +20 -7
- package/src/writer/context.ts +5 -1
- package/src/writer/doc-tags.ts +70 -0
- package/src/writer/doc.ts +29 -6
- package/src/writer/gtk-doc.ts +82 -15
- package/src/writer/module.ts +25 -2
package/src/store/gi/vtable.ts
CHANGED
|
@@ -1,46 +1,112 @@
|
|
|
1
|
-
import { pascalCase, sourceStringLiteral
|
|
1
|
+
import { pascalCase, sourceStringLiteral } from "@gtkx/utils";
|
|
2
2
|
import type { GirCallback } from "../../gir/callback.js";
|
|
3
|
-
import type { GirClass } from "../../gir/class.js";
|
|
3
|
+
import type { GirClass, GirVirtualMethod } from "../../gir/class.js";
|
|
4
4
|
import type { GirField } from "../../gir/field.js";
|
|
5
5
|
import type { GirParameter } from "../../gir/parameter.js";
|
|
6
|
+
import type { GirRecord } from "../../gir/record.js";
|
|
7
|
+
import type { TypeId } from "../../gir/type-id.js";
|
|
6
8
|
import type { ModuleContext } from "../../writer/context.js";
|
|
9
|
+
import type { JsDocSpec } from "../../writer/doc.js";
|
|
7
10
|
import {
|
|
8
11
|
isInlineCallbackRef,
|
|
9
12
|
isScalarRef,
|
|
10
13
|
renderDescriptor,
|
|
11
14
|
renderParamDescriptor,
|
|
12
15
|
} from "../../analysis/descriptor-render.js";
|
|
13
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
foldedLengthParameters,
|
|
18
|
+
handlerParameters,
|
|
19
|
+
parameterIdentifier,
|
|
20
|
+
renamesWithInstance,
|
|
21
|
+
renderHandlerParameters,
|
|
22
|
+
renderHandlerResultType,
|
|
23
|
+
} from "../../analysis/param-structure.js";
|
|
24
|
+
import { renderTsType } from "../../analysis/ts-type.js";
|
|
25
|
+
import { ancestorChain, type ResolvedAncestor, resolveInterfaces } from "../../gir/ancestry.js";
|
|
26
|
+
import { renderJsDoc } from "../../writer/doc.js";
|
|
27
|
+
import { renderBlock, renderBraced } from "../../writer/emit.js";
|
|
28
|
+
import { handlerSpec, THROWS_TEXT } from "./doc-spec.js";
|
|
14
29
|
import { computeRecordFieldSlots } from "./record-layout.js";
|
|
15
30
|
|
|
16
31
|
type VtableKind = "class" | "interface";
|
|
32
|
+
type VfuncMemberMode = "implementation" | "requirement" | "signature";
|
|
17
33
|
|
|
18
|
-
type
|
|
34
|
+
type VtableSlot = {
|
|
19
35
|
key: string;
|
|
20
|
-
structName: string;
|
|
21
|
-
kind: VtableKind;
|
|
22
36
|
field: GirField;
|
|
23
37
|
callback: GirCallback;
|
|
38
|
+
vfunc: GirVirtualMethod | undefined;
|
|
24
39
|
byteOffset: number;
|
|
25
|
-
vtableSize: number;
|
|
26
40
|
};
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
type VfuncMemberOptions = {
|
|
43
|
+
context: ModuleContext;
|
|
44
|
+
ownerRef: string;
|
|
45
|
+
slot: VtableSlot;
|
|
46
|
+
mode: VfuncMemberMode;
|
|
47
|
+
isProtected: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type VfuncMembersOptions = {
|
|
51
|
+
context: ModuleContext;
|
|
52
|
+
klass: GirClass;
|
|
53
|
+
mode: VfuncMemberMode;
|
|
54
|
+
};
|
|
32
55
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
type VfuncSignature = {
|
|
57
|
+
header: string;
|
|
58
|
+
returnType: string;
|
|
59
|
+
};
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
type VfuncEntry = {
|
|
62
|
+
name: string;
|
|
63
|
+
signature: string;
|
|
64
|
+
doc: string | undefined;
|
|
65
|
+
};
|
|
40
66
|
|
|
41
|
-
|
|
67
|
+
type Vtable = {
|
|
68
|
+
structName: string;
|
|
69
|
+
kind: VtableKind;
|
|
70
|
+
vtableSize: number;
|
|
71
|
+
slots: VtableSlot[];
|
|
42
72
|
};
|
|
43
73
|
|
|
74
|
+
const PADDING_FIELD_NAME = /^(?:reserved|padding)\d*$/i;
|
|
75
|
+
|
|
76
|
+
const UNCALLABLE_SLOT_KEYS: Set<string> = new Set([
|
|
77
|
+
"vfuncDispose",
|
|
78
|
+
"vfuncFinalize",
|
|
79
|
+
"vfuncGetProperty",
|
|
80
|
+
"vfuncSetProperty",
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
const PROTECTED_SLOT_NOTE = "It is `protected`, so only a subclass chaining up reaches it.";
|
|
84
|
+
const PUBLIC_SLOT_NOTE = "Calling it from anywhere else re-enters the slot on a live instance.";
|
|
85
|
+
|
|
86
|
+
const vfuncMemberName = (fieldName: string): string => `vfunc${pascalCase(fieldName)}`;
|
|
87
|
+
|
|
88
|
+
const vfuncOverrideNote = (slot: VtableSlot, isProtected: boolean): string =>
|
|
89
|
+
[
|
|
90
|
+
`Invokes the \`${slot.field.name}\` vtable slot. Override it on a class passed to \`registerClass\``,
|
|
91
|
+
`and chain up with \`super.${slot.key}()\`.`,
|
|
92
|
+
isProtected ? PROTECTED_SLOT_NOTE : PUBLIC_SLOT_NOTE,
|
|
93
|
+
].join("\n");
|
|
94
|
+
|
|
95
|
+
const vfuncRequirementNote = (slot: VtableSlot, ownerRef: string): string =>
|
|
96
|
+
[
|
|
97
|
+
`Fills the \`${slot.field.name}\` vtable slot. Declare it on a class passed to \`registerClass\``,
|
|
98
|
+
`with \`${ownerRef}\` in \`implements\`, which installs it in the interface vtable. Leaving it out`,
|
|
99
|
+
"keeps whatever the interface installs by default, the way it does for a C implementer.",
|
|
100
|
+
].join("\n");
|
|
101
|
+
|
|
102
|
+
const vfuncMemberNote = (options: VfuncMemberOptions): string =>
|
|
103
|
+
options.mode === "requirement"
|
|
104
|
+
? vfuncRequirementNote(options.slot, options.ownerRef)
|
|
105
|
+
: vfuncOverrideNote(options.slot, options.isProtected);
|
|
106
|
+
|
|
107
|
+
const isPaddingField = (field: GirField): boolean =>
|
|
108
|
+
field.name.startsWith("_") || PADDING_FIELD_NAME.test(field.name);
|
|
109
|
+
|
|
44
110
|
const vtableCallbackType = (context: ModuleContext, field: GirField): GirCallback | undefined => {
|
|
45
111
|
if (field.type === undefined) {
|
|
46
112
|
return undefined;
|
|
@@ -60,15 +126,19 @@ const vtableSlotEntry = (
|
|
|
60
126
|
field: GirField,
|
|
61
127
|
claimedNames: Set<string>,
|
|
62
128
|
): { key: string; callback: GirCallback } | undefined => {
|
|
129
|
+
if (field.name === "constructor" || isPaddingField(field)) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
63
133
|
const callback = vtableCallbackType(context, field);
|
|
64
134
|
|
|
65
135
|
if (callback === undefined) {
|
|
66
136
|
return undefined;
|
|
67
137
|
}
|
|
68
138
|
|
|
69
|
-
const key =
|
|
139
|
+
const key = vfuncMemberName(field.name);
|
|
70
140
|
|
|
71
|
-
if (
|
|
141
|
+
if (claimedNames.has(key)) {
|
|
72
142
|
return undefined;
|
|
73
143
|
}
|
|
74
144
|
|
|
@@ -79,53 +149,271 @@ const vtableSlotEntry = (
|
|
|
79
149
|
return { key, callback };
|
|
80
150
|
};
|
|
81
151
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const { slots, size } = computeRecordFieldSlots(context, resolved.value.fields, resolved.value.isUnion);
|
|
90
|
-
const entries: string[] = [];
|
|
152
|
+
const collectVtableSlots = (
|
|
153
|
+
context: ModuleContext,
|
|
154
|
+
fields: GirField[],
|
|
155
|
+
isUnion: boolean,
|
|
156
|
+
): { slots: VtableSlot[]; vtableSize: number } => {
|
|
157
|
+
const { slots, size } = computeRecordFieldSlots(context, fields, isUnion);
|
|
158
|
+
const entries: VtableSlot[] = [];
|
|
91
159
|
const claimedNames: Set<string> = new Set();
|
|
92
160
|
|
|
93
161
|
for (const { field, slot } of slots) {
|
|
94
162
|
const entry = vtableSlotEntry(context, field, claimedNames);
|
|
95
163
|
|
|
96
|
-
if (entry
|
|
97
|
-
|
|
164
|
+
if (entry !== undefined) {
|
|
165
|
+
claimedNames.add(entry.key);
|
|
166
|
+
entries.push({ ...entry, field, vfunc: undefined, byteOffset: slot.byteOffset });
|
|
98
167
|
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { slots: entries, vtableSize: size };
|
|
171
|
+
};
|
|
99
172
|
|
|
100
|
-
|
|
173
|
+
const resolveVtableRecord = (
|
|
174
|
+
context: ModuleContext,
|
|
175
|
+
namespaceName: string,
|
|
176
|
+
klass: GirClass,
|
|
177
|
+
): { typeStruct: string; record: GirRecord } | undefined => {
|
|
178
|
+
const typeStruct = klass.glibTypeStruct;
|
|
179
|
+
const resolved = typeStruct === undefined ? undefined : context.library.resolveType(namespaceName, typeStruct);
|
|
101
180
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
key: entry.key,
|
|
105
|
-
structName,
|
|
106
|
-
kind,
|
|
107
|
-
field,
|
|
108
|
-
callback: entry.callback,
|
|
109
|
-
byteOffset: slot.byteOffset,
|
|
110
|
-
vtableSize: size,
|
|
111
|
-
}),
|
|
112
|
-
);
|
|
181
|
+
if (typeStruct === undefined || resolved?.kind !== "record" || resolved.value.fields.length === 0) {
|
|
182
|
+
return undefined;
|
|
113
183
|
}
|
|
114
184
|
|
|
115
|
-
return
|
|
185
|
+
return { typeStruct, record: resolved.value };
|
|
116
186
|
};
|
|
117
187
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
188
|
+
const attachVirtualMethods = (slots: VtableSlot[], klass: GirClass): VtableSlot[] => {
|
|
189
|
+
const byKey: Map<string, GirVirtualMethod> = new Map(
|
|
190
|
+
klass.vfuncs.map((vfunc) => [vfuncMemberName(vfunc.name), vfunc]),
|
|
191
|
+
);
|
|
122
192
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
193
|
+
return slots.map((slot) => ({ ...slot, vfunc: byKey.get(slot.key) }));
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const collectVtable = (context: ModuleContext, namespaceName: string, klass: GirClass): Vtable | undefined => {
|
|
197
|
+
const resolved = resolveVtableRecord(context, namespaceName, klass);
|
|
198
|
+
|
|
199
|
+
if (resolved === undefined) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const { slots, vtableSize } = collectVtableSlots(context, resolved.record.fields, resolved.record.isUnion);
|
|
204
|
+
|
|
205
|
+
if (slots.length === 0) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
structName: pascalCase(resolved.typeStruct),
|
|
211
|
+
kind: klass.isInterface ? "interface" : "class",
|
|
212
|
+
vtableSize,
|
|
213
|
+
slots: attachVirtualMethods(slots, klass),
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const vfuncMemberNames = (context: ModuleContext, namespaceName: string, klass: GirClass): string[] =>
|
|
218
|
+
collectVtable(context, namespaceName, klass)?.slots.map((slot) => slot.key) ?? [];
|
|
219
|
+
|
|
220
|
+
const renderVfuncMetadata = (context: ModuleContext, klass: GirClass): string | undefined => {
|
|
221
|
+
const vtable = collectVtable(context, context.namespace.name, klass);
|
|
222
|
+
|
|
223
|
+
if (vtable === undefined) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const entries = vtable.slots.map((slot) => renderVtableSlotDescriptor(context, vtable, slot));
|
|
228
|
+
|
|
229
|
+
return renderBraced(entries.join("\n"));
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const slotIdentity = (slot: VtableSlot): string => `${slot.key}:${String(slot.byteOffset)}`;
|
|
233
|
+
|
|
234
|
+
const inheritedSlotIdentities = (context: ModuleContext, namespaceName: string, klass: GirClass): Set<string> => {
|
|
235
|
+
const identities: Set<string> = new Set();
|
|
236
|
+
const [, ...ancestors] = [...ancestorChain(context.library, klass, namespaceName)];
|
|
237
|
+
|
|
238
|
+
for (const ancestor of ancestors) {
|
|
239
|
+
const vtable = collectVtable(context, ancestor.namespaceName, ancestor.klass);
|
|
240
|
+
const slots = vtable?.slots ?? [];
|
|
241
|
+
|
|
242
|
+
for (const slot of slots) {
|
|
243
|
+
identities.add(slotIdentity(slot));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return identities;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const addInterfaceSlotKeys = (
|
|
251
|
+
context: ModuleContext,
|
|
252
|
+
iface: ResolvedAncestor,
|
|
253
|
+
keys: Set<string>,
|
|
254
|
+
seen: Set<string>,
|
|
255
|
+
): void => {
|
|
256
|
+
const identity = `${iface.namespaceName}.${iface.klass.name}`;
|
|
257
|
+
|
|
258
|
+
if (seen.has(identity)) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
seen.add(identity);
|
|
263
|
+
|
|
264
|
+
for (const key of vfuncMemberNames(context, iface.namespaceName, iface.klass)) {
|
|
265
|
+
keys.add(key);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
for (const ref of resolveInterfaces(context.library, iface.namespaceName, iface.klass.prerequisites)) {
|
|
269
|
+
addInterfaceSlotKeys(context, ref, keys, seen);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const implementedSlotKeys = (context: ModuleContext, namespaceName: string, klass: GirClass): Set<string> => {
|
|
274
|
+
const keys: Set<string> = new Set();
|
|
275
|
+
const seen: Set<string> = new Set();
|
|
276
|
+
|
|
277
|
+
for (const ancestor of ancestorChain(context.library, klass, namespaceName)) {
|
|
278
|
+
for (const ref of resolveInterfaces(context.library, ancestor.namespaceName, ancestor.klass.implements)) {
|
|
279
|
+
addInterfaceSlotKeys(context, ref, keys, seen);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return keys;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const protectedSlotKeys = (options: VfuncMembersOptions, slots: VtableSlot[]): Set<string> => {
|
|
287
|
+
const { context, klass } = options;
|
|
288
|
+
|
|
289
|
+
if (klass.isInterface) {
|
|
290
|
+
return new Set();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const shared = implementedSlotKeys(context, context.namespace.name, klass);
|
|
294
|
+
|
|
295
|
+
return new Set(slots.map((slot) => slot.key).filter((key) => !shared.has(key)));
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const callableVfuncSlots = (context: ModuleContext, namespaceName: string, klass: GirClass): VtableSlot[] => {
|
|
299
|
+
const vtable = collectVtable(context, namespaceName, klass);
|
|
300
|
+
|
|
301
|
+
if (vtable === undefined) {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const inherited = inheritedSlotIdentities(context, namespaceName, klass);
|
|
306
|
+
|
|
307
|
+
return vtable.slots.filter((slot) => isCallableSlot(context, slot) && !inherited.has(slotIdentity(slot)));
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const hasCallableVfuncSlots = (context: ModuleContext, namespaceName: string, klass: GirClass): boolean =>
|
|
311
|
+
callableVfuncSlots(context, namespaceName, klass).length > 0;
|
|
312
|
+
|
|
313
|
+
const slotDoc = (slot: VtableSlot): string | undefined => slot.vfunc?.doc ?? slot.field.doc ?? slot.callback.doc;
|
|
314
|
+
|
|
315
|
+
const slotDocParameters = (slot: VtableSlot): GirParameter[] => {
|
|
316
|
+
const [, ...parameters] = slot.callback.parameters;
|
|
317
|
+
const vfuncParameters = slot.vfunc?.parameters ?? [];
|
|
318
|
+
|
|
319
|
+
return parameters.map((parameter, index) => ({ ...parameter, doc: vfuncParameters[index]?.doc ?? parameter.doc }));
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const slotDocSpec = (slot: VtableSlot): JsDocSpec => {
|
|
323
|
+
const parameters = slotDocParameters(slot);
|
|
324
|
+
const source = slot.vfunc ?? slot.callback;
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
...handlerSpec(source, parameters, renamesWithInstance(parameters, slot.callback.parameters[0])),
|
|
328
|
+
returns: slot.vfunc?.returnValue.doc ?? slot.callback.returnValue.doc,
|
|
329
|
+
throws: slot.callback.throws ? THROWS_TEXT : undefined,
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const vfuncEntries = (context: ModuleContext, namespaceName: string, klass: GirClass): VfuncEntry[] =>
|
|
334
|
+
callableVfuncSlots(context, namespaceName, klass).map((slot) => ({
|
|
335
|
+
name: slot.key,
|
|
336
|
+
signature: vfuncSlotSignature(context, slot).header,
|
|
337
|
+
doc: slotDoc(slot),
|
|
338
|
+
}));
|
|
339
|
+
|
|
340
|
+
const renderVfuncMembers = (options: VfuncMembersOptions): string[] => {
|
|
341
|
+
const { context, klass, mode } = options;
|
|
342
|
+
const ownerRef = pascalCase(klass.name);
|
|
343
|
+
const slots = callableVfuncSlots(context, context.namespace.name, klass);
|
|
344
|
+
|
|
345
|
+
if (slots.length === 0) {
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (mode === "implementation") {
|
|
350
|
+
context.addRuntimeImport("callVfunc");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const protectedKeys = protectedSlotKeys(options, slots);
|
|
354
|
+
|
|
355
|
+
return slots.map((slot) =>
|
|
356
|
+
renderVfuncMember({ context, ownerRef, slot, mode, isProtected: protectedKeys.has(slot.key) }));
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const hasUnannotatedPointerParam = (context: ModuleContext, slot: VtableSlot): boolean => {
|
|
360
|
+
const [, ...parameters] = slot.callback.parameters;
|
|
361
|
+
|
|
362
|
+
return parameters.some(
|
|
363
|
+
(parameter) =>
|
|
364
|
+
parameter.direction === "in" &&
|
|
365
|
+
parameter.cType?.endsWith("*") === true &&
|
|
366
|
+
isScalarRef(context.library, parameter.type),
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const isCallableSlot = (context: ModuleContext, slot: VtableSlot): boolean =>
|
|
371
|
+
!UNCALLABLE_SLOT_KEYS.has(slot.key) && !hasUnannotatedPointerParam(context, slot);
|
|
372
|
+
|
|
373
|
+
const vfuncSlotSignature = (context: ModuleContext, slot: VtableSlot, isOptional = false): VfuncSignature => {
|
|
374
|
+
const [, ...parameters] = slot.callback.parameters;
|
|
375
|
+
|
|
376
|
+
const renderType = (ref: TypeId | undefined, isNullable: boolean): string =>
|
|
377
|
+
renderTsType(context, ref, isNullable);
|
|
378
|
+
|
|
379
|
+
const signature = renderHandlerParameters(parameters, renderType).join(", ");
|
|
380
|
+
const folded = foldedLengthParameters(context.library, slot.callback);
|
|
381
|
+
|
|
382
|
+
const returnType = renderHandlerResultType({
|
|
383
|
+
library: context.library,
|
|
384
|
+
signal: { ...slot.callback, parameters },
|
|
385
|
+
renderType,
|
|
386
|
+
shouldIncludeCallerAllocated: true,
|
|
387
|
+
isOptOut: false,
|
|
388
|
+
shouldExcludeOut: (parameter) => folded.has(parameter),
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
return { header: `${slot.key}${isOptional ? "?" : ""}(${signature}): ${returnType}`, returnType };
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const renderVfuncMember = (options: VfuncMemberOptions): string => {
|
|
395
|
+
const { context, ownerRef, slot, mode, isProtected } = options;
|
|
396
|
+
const { header, returnType } = vfuncSlotSignature(context, slot, mode === "requirement");
|
|
397
|
+
const declaration = `${isProtected ? "protected " : ""}${header}`;
|
|
398
|
+
const doc = renderJsDoc(slotDoc(slot), vfuncMemberNote(options), slotDocSpec(slot));
|
|
399
|
+
|
|
400
|
+
if (mode !== "implementation") {
|
|
401
|
+
return `${doc}${declaration};`;
|
|
126
402
|
}
|
|
127
403
|
|
|
128
|
-
|
|
404
|
+
const [, ...parameters] = slot.callback.parameters;
|
|
405
|
+
|
|
406
|
+
const inputs = handlerParameters(parameters).map((parameter, index) =>
|
|
407
|
+
parameterIdentifier(parameter, index));
|
|
408
|
+
|
|
409
|
+
const call = `callVfunc(${ownerRef}, ${sourceStringLiteral(slot.key)}, this, [${inputs.join(", ")}])`;
|
|
410
|
+
const body = returnType === "void" ? `${call};` : `return ${call} as ${returnType};`;
|
|
411
|
+
|
|
412
|
+
return `${doc}${renderBlock(declaration, body)}`;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
const isEligibleVtableParam = (context: ModuleContext, param: GirParameter): boolean => {
|
|
416
|
+
if (param.isVarargs) {
|
|
129
417
|
return false;
|
|
130
418
|
}
|
|
131
419
|
|
|
@@ -146,8 +434,8 @@ const isVtableSlotEligible = (context: ModuleContext, callback: GirCallback): bo
|
|
|
146
434
|
return !isInlineCallbackRef(context.library, callback.returnValue.type);
|
|
147
435
|
};
|
|
148
436
|
|
|
149
|
-
const renderVtableSlotDescriptor = (context: ModuleContext,
|
|
150
|
-
const { key,
|
|
437
|
+
const renderVtableSlotDescriptor = (context: ModuleContext, vtable: Vtable, slot: VtableSlot): string => {
|
|
438
|
+
const { key, field, callback, byteOffset } = slot;
|
|
151
439
|
|
|
152
440
|
const argDescriptors = callback.parameters
|
|
153
441
|
.map((param) => renderParamDescriptor(context, param, param.type))
|
|
@@ -160,16 +448,29 @@ const renderVtableSlotDescriptor = (context: ModuleContext, options: RenderVtabl
|
|
|
160
448
|
);
|
|
161
449
|
|
|
162
450
|
const lines = [
|
|
163
|
-
`
|
|
164
|
-
`className: ${sourceStringLiteral(structName)},`,
|
|
451
|
+
`className: ${sourceStringLiteral(vtable.structName)},`,
|
|
165
452
|
`vfuncName: ${sourceStringLiteral(field.name)},`,
|
|
166
453
|
`byteOffset: ${String(byteOffset)},`,
|
|
167
|
-
`vtableSize: ${String(vtableSize)},`,
|
|
168
|
-
`argDescriptors: [${argDescriptors}],`,
|
|
169
|
-
`returnDescriptor: ${returnDescriptor},`,
|
|
170
454
|
];
|
|
171
455
|
|
|
456
|
+
if (vtable.kind === "interface") {
|
|
457
|
+
lines.push(`vtableSize: ${String(vtable.vtableSize)},`);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
lines.push(`argDescriptors: [${argDescriptors}],`, `returnDescriptor: ${returnDescriptor},`);
|
|
461
|
+
|
|
462
|
+
if (callback.throws) {
|
|
463
|
+
lines.push("canThrow: true,");
|
|
464
|
+
}
|
|
465
|
+
|
|
172
466
|
return `${key}: ${renderBraced(lines.join("\n"))},`;
|
|
173
467
|
};
|
|
174
468
|
|
|
175
|
-
export {
|
|
469
|
+
export {
|
|
470
|
+
hasCallableVfuncSlots,
|
|
471
|
+
renderVfuncMembers,
|
|
472
|
+
renderVfuncMetadata,
|
|
473
|
+
vfuncEntries,
|
|
474
|
+
vfuncMemberNames,
|
|
475
|
+
type VfuncMemberMode,
|
|
476
|
+
};
|
|
@@ -3,7 +3,7 @@ import type { Library } from "../../gir/library.js";
|
|
|
3
3
|
import type { GirNamespace } from "../../gir/namespace.js";
|
|
4
4
|
import type { ImportsBuilder } from "../../writer/imports.js";
|
|
5
5
|
import type { LazyElementSpec } from "./element-prop-types.js";
|
|
6
|
-
import {
|
|
6
|
+
import { getDoc } from "../gi/doc-spec.js";
|
|
7
7
|
import { ancestorGlibNames, type GlibNamedClass } from "./intrinsic-elements.js";
|
|
8
8
|
|
|
9
9
|
type ElementComponent = { module: string; export: string };
|
|
@@ -91,10 +91,11 @@ const collectLazyElementExports = (collector: ExportCollector, lazyElements: Laz
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
const renderLazyElementExport = (spec: LazyElementSpec): string => {
|
|
94
|
+
const doc = getDoc(spec);
|
|
94
95
|
const factory = `createElementComponent(${sourceStringLiteral(spec.element)})`;
|
|
95
|
-
const component =
|
|
96
|
+
const component = `${doc}export const ${spec.element}: (props: ${spec.typeName}) => ReactNode = ${factory};`;
|
|
96
97
|
|
|
97
|
-
return `${spec.typeSource}\n\n${component}`;
|
|
98
|
+
return `${doc}${spec.typeSource}\n\n${component}`;
|
|
98
99
|
};
|
|
99
100
|
|
|
100
101
|
const renderCandidateExport = (
|
|
@@ -113,7 +114,9 @@ const renderCandidateExport = (
|
|
|
113
114
|
imports.addNamed(component.module, component.export, false);
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
const doc = getDoc(klass);
|
|
118
|
+
|
|
119
|
+
return `${doc}${renderElementComponentExport(glibName, component)}`;
|
|
117
120
|
};
|
|
118
121
|
|
|
119
122
|
const resolveElementComponent = (
|
|
@@ -143,4 +146,4 @@ const renderElementComponentExport = (glibName: string, component: ElementCompon
|
|
|
143
146
|
return `export const ${glibName}: ${annotation} = ${component.export}(${factoryCall});`;
|
|
144
147
|
};
|
|
145
148
|
|
|
146
|
-
export { generateElementComponentsSection, type
|
|
149
|
+
export { generateElementComponentsSection, type ElementComponentOverrides };
|
|
@@ -2,9 +2,7 @@ type ElementPropTypeRef = { type: string; module: string; export: string };
|
|
|
2
2
|
|
|
3
3
|
/** Base props interface each element extends, keyed by GLib type name (the module exports it). */
|
|
4
4
|
type ElementProps = Record<string, {
|
|
5
|
-
/** Specifier the props interface is imported from. */
|
|
6
5
|
module: string;
|
|
7
|
-
/** Identifier the module exports it under. */
|
|
8
6
|
export: string;
|
|
9
7
|
}>;
|
|
10
8
|
|
|
@@ -24,4 +22,4 @@ const elementPropTypeFor = (glibName: string): ElementPropTypeRef | undefined =>
|
|
|
24
22
|
return ref === undefined ? undefined : { type: glibName, module: ref.module, export: ref.export };
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
export { setElementProps, elementPropTypeFor, type
|
|
25
|
+
export { setElementProps, elementPropTypeFor, type ElementProps };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toCamelIdentifier } from "@gtkx/utils";
|
|
2
|
+
import type { GirAnnotations } from "../../gir/annotations.js";
|
|
2
3
|
import type { GirClass } from "../../gir/class.js";
|
|
3
4
|
import { getChain, type GirIndex, type GirTypeEntry } from "./gir-index.js";
|
|
4
5
|
import { getGlibName } from "./intrinsic-elements.js";
|
|
@@ -7,6 +8,8 @@ type LazyElementSpec = {
|
|
|
7
8
|
element: string;
|
|
8
9
|
typeName: string;
|
|
9
10
|
typeSource: string;
|
|
11
|
+
doc: string | undefined;
|
|
12
|
+
annotations: GirAnnotations;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
const appendConstructOnlyNames = (klass: GirClass, names: string[]): void => {
|
|
@@ -34,7 +37,13 @@ const createLazyElementSpec = (context: GirIndex, element: string, entry: GirTyp
|
|
|
34
37
|
const omitUnion = omitted.map((name) => JSON.stringify(name)).join(" | ");
|
|
35
38
|
const base = omitted.length === 0 ? `${baseName}Props` : `Omit<${baseName}Props, ${omitUnion}>`;
|
|
36
39
|
|
|
37
|
-
return {
|
|
40
|
+
return {
|
|
41
|
+
element,
|
|
42
|
+
typeName,
|
|
43
|
+
typeSource: `export type ${typeName} = ${base} & { children?: ReactNode };`,
|
|
44
|
+
doc: entry.klass.doc,
|
|
45
|
+
annotations: entry.klass.annotations,
|
|
46
|
+
};
|
|
38
47
|
};
|
|
39
48
|
|
|
40
49
|
const lazyElementSpecs = (context: GirIndex, lazyElements: string[]): Map<string, LazyElementSpec[]> => {
|
|
@@ -4,9 +4,13 @@ import type { Library } from "../../gir/library.js";
|
|
|
4
4
|
import type { GirNamespace } from "../../gir/namespace.js";
|
|
5
5
|
import { ancestorChain } from "../../gir/ancestry.js";
|
|
6
6
|
|
|
7
|
+
/** A GIR class paired with the GLib type name it is bound under. */
|
|
7
8
|
type GlibNamedClass = {
|
|
9
|
+
/** GLib type name, such as `"GtkButton"`, falling back to the C type when the GIR declares none. */
|
|
8
10
|
glibName: string;
|
|
11
|
+
/** Parsed class the name belongs to. */
|
|
9
12
|
klass: GirClass;
|
|
13
|
+
/** Namespace declaring the class. */
|
|
10
14
|
namespace: GirNamespace;
|
|
11
15
|
};
|
|
12
16
|
|
package/src/store/jsx/jsx.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { GirClass } from "../../gir/class.js";
|
|
|
3
3
|
import type { Library } from "../../gir/library.js";
|
|
4
4
|
import type { GirNamespace } from "../../gir/namespace.js";
|
|
5
5
|
import type { ImportsBuilder } from "../../writer/imports.js";
|
|
6
|
-
import { renderJsDoc } from "../../writer/doc.js";
|
|
7
6
|
import { renderBlock } from "../../writer/emit.js";
|
|
7
|
+
import { getDoc } from "../gi/doc-spec.js";
|
|
8
8
|
import { elementPropTypeFor } from "./element-prop-imports.js";
|
|
9
9
|
import {
|
|
10
10
|
collectInterfacePropsClasses,
|
|
@@ -97,7 +97,9 @@ const generateJsxSection = (
|
|
|
97
97
|
const intrinsicElementConsts = namespaceElements.filter((entry) => !excludeNames.has(entry.glibName));
|
|
98
98
|
|
|
99
99
|
const constLines = intrinsicElementConsts.map(
|
|
100
|
-
(entry) =>
|
|
100
|
+
(entry) =>
|
|
101
|
+
`${getDoc(entry.klass)}export const ${entry.glibName} = ` +
|
|
102
|
+
`${sourceStringLiteral(entry.glibName)} as const;`,
|
|
101
103
|
);
|
|
102
104
|
|
|
103
105
|
const isIntrinsicElementAncestor = (candidate: GirClass): boolean => {
|
|
@@ -135,7 +137,7 @@ const generateJsxSection = (
|
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
const source = [
|
|
138
|
-
constLines.join("\n"),
|
|
140
|
+
constLines.join("\n\n"),
|
|
139
141
|
"",
|
|
140
142
|
propBlocks.join("\n\n"),
|
|
141
143
|
"",
|
|
@@ -285,7 +287,7 @@ const renderInterfacePropsBlock = (
|
|
|
285
287
|
addGiNamespace(imports, iface.namespace.name, giNamespaceAlias(iface.namespace.name));
|
|
286
288
|
const selfDefault = `${giNamespaceAlias(iface.namespace.name)}.${iface.klass.name}`;
|
|
287
289
|
const signature = `export interface ${glib}Props<Self = ${selfDefault}>${extendsClause}`;
|
|
288
|
-
const block = `${
|
|
290
|
+
const block = `${getDoc(iface.klass)}${renderBlock(signature, ownerLines.join("\n"))}`;
|
|
289
291
|
|
|
290
292
|
return { block, objectPropNames };
|
|
291
293
|
};
|
|
@@ -293,7 +295,7 @@ const renderInterfacePropsBlock = (
|
|
|
293
295
|
const renderJsxAugmentation = (namespaceElements: GlibNamedClass[]): string => {
|
|
294
296
|
const elementLines = namespaceElements
|
|
295
297
|
.filter((entry) => !entry.klass.isAbstract)
|
|
296
|
-
.map((entry) => `${entry.glibName}: ${entry.glibName}Props;`)
|
|
298
|
+
.map((entry) => `${getDoc(entry.klass)}${entry.glibName}: ${entry.glibName}Props;`)
|
|
297
299
|
.join("\n");
|
|
298
300
|
|
|
299
301
|
const intrinsicInterface = renderBlock("interface IntrinsicElements", elementLines);
|
|
@@ -324,7 +326,7 @@ const renderPropBlock = (
|
|
|
324
326
|
const extendsClause = extendsList.length === 0 ? "" : ` extends ${extendsList.join(", ")}`;
|
|
325
327
|
const selfDefault = `${giNamespaceAlias(entry.namespace.name)}.${entry.klass.name}`;
|
|
326
328
|
|
|
327
|
-
const block = `${
|
|
329
|
+
const block = `${getDoc(entry.klass)}${renderBlock(
|
|
328
330
|
`export interface ${entry.glibName}Props<Self = ${selfDefault}>${extendsClause}`,
|
|
329
331
|
ownerLines.join("\n"),
|
|
330
332
|
)}`;
|
|
@@ -362,9 +362,9 @@ const primitiveDefaultLiteral = (category: PrimitiveCategory, raw: string): stri
|
|
|
362
362
|
};
|
|
363
363
|
|
|
364
364
|
const bigintDefaultLiteral = (raw: string): string | undefined => {
|
|
365
|
-
const
|
|
365
|
+
const integer = integerDefaultLiteral(raw);
|
|
366
366
|
|
|
367
|
-
return
|
|
367
|
+
return integer === undefined ? undefined : `${integer}n`;
|
|
368
368
|
};
|
|
369
369
|
|
|
370
370
|
const enumDefaultLiteral = (enumType: GirEnum, raw: string): string | undefined => {
|