@ts-for-gir/lib 4.0.0-beta.4 → 4.0.0-beta.41
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 +13 -1
- package/package.json +18 -31
- package/src/constants.ts +152 -0
- package/src/dependency-manager.ts +445 -0
- package/src/formatters/default.ts +7 -0
- package/src/formatters/formatter.ts +3 -0
- package/src/formatters/index.ts +3 -0
- package/src/formatters/json.ts +7 -0
- package/src/generators/generator.ts +65 -0
- package/src/generators/index.ts +2 -0
- package/src/generics/clutter.ts +80 -0
- package/src/generics/generify.ts +101 -0
- package/src/generics/gio.ts +91 -0
- package/src/generics/glib.ts +31 -0
- package/src/generics/gtk.ts +99 -0
- package/src/generics/meta.ts +50 -0
- package/src/generics/st.ts +206 -0
- package/src/generics/visitor.ts +484 -0
- package/src/gir/alias.ts +73 -0
- package/src/gir/callback.ts +79 -0
- package/src/gir/const.ts +73 -0
- package/src/gir/constructor.ts +91 -0
- package/src/gir/data.ts +12 -0
- package/src/gir/dependency-resolver.ts +81 -0
- package/src/gir/direct-allocation-constructor.ts +65 -0
- package/src/gir/enum-member.ts +51 -0
- package/src/gir/enum.ts +129 -0
- package/src/gir/error.ts +89 -0
- package/src/gir/function.ts +296 -0
- package/src/gir/generics.ts +66 -0
- package/src/gir/gir-complex-record.ts +7 -0
- package/src/gir/index.ts +25 -0
- package/src/gir/introspected-base.ts +104 -0
- package/src/gir/introspected-class-member.ts +15 -0
- package/src/gir/introspected-classes.ts +1484 -0
- package/src/gir/introspected-namespace-member.ts +24 -0
- package/src/gir/namespace.ts +76 -0
- package/src/gir/parameter.ts +199 -0
- package/src/gir/promisify.ts +209 -0
- package/src/gir/property.ts +203 -0
- package/src/gir/record.ts +488 -0
- package/src/gir/registry.ts +183 -0
- package/src/gir/signal.ts +278 -0
- package/src/gir-module.ts +719 -0
- package/src/gir.ts +869 -0
- package/src/index.ts +16 -0
- package/src/injections/gee08.ts +89 -0
- package/src/injections/gee1.ts +35 -0
- package/src/injections/gio.ts +720 -0
- package/src/injections/glib.ts +280 -0
- package/src/injections/gobject.ts +906 -0
- package/src/injections/gtk4.ts +23 -0
- package/src/injections/inject.ts +49 -0
- package/src/injections/shell.ts +49 -0
- package/src/injections/tracker1.ts +42 -0
- package/src/library-version.ts +50 -0
- package/src/logger.ts +104 -0
- package/src/messages.ts +57 -0
- package/src/templates/index.ts +1 -0
- package/src/templates/template-engine.ts +178 -0
- package/src/types/answer-version.ts +4 -0
- package/src/types/any-introspected-type.ts +5 -0
- package/src/types/class-function-types.ts +57 -0
- package/src/types/class-member.ts +5 -0
- package/src/types/class-parent.ts +14 -0
- package/src/types/class.ts +43 -0
- package/src/types/config-flags.ts +5 -0
- package/src/types/construct-name.ts +13 -0
- package/src/types/dependency-map.ts +4 -0
- package/src/types/dependency.ts +49 -0
- package/src/types/file-info.ts +14 -0
- package/src/types/format.ts +1 -0
- package/src/types/generator-constructor.ts +7 -0
- package/src/types/generics-config.ts +90 -0
- package/src/types/gir-any-element.ts +35 -0
- package/src/types/gir-module-interface.ts +22 -0
- package/src/types/gir-module-resolved.ts +32 -0
- package/src/types/gir-type-name.ts +20 -0
- package/src/types/index.ts +92 -0
- package/{lib/types/inheritance-table.d.ts → src/types/inheritance-table.ts} +1 -1
- package/src/types/introspected.ts +18 -0
- package/src/types/local-name-check.ts +5 -0
- package/src/types/local-name-type.ts +1 -0
- package/src/types/local-name.ts +8 -0
- package/src/types/local-names.ts +5 -0
- package/src/types/metadata.ts +6 -0
- package/src/types/ns-loader.ts +6 -0
- package/src/types/options-base.ts +8 -0
- package/src/types/options-generation.ts +65 -0
- package/src/types/options-load.ts +6 -0
- package/src/types/options-transform.ts +5 -0
- package/src/types/output-format.ts +1 -0
- package/src/types/package-data-parsed.ts +28 -0
- package/src/types/package-data.ts +24 -0
- package/src/types/package-section-parsed.ts +9 -0
- package/src/types/parsed-gir.ts +5 -0
- package/src/types/parsed-package-data.ts +7 -0
- package/src/types/property-case.ts +1 -0
- package/src/types/resolve-type.ts +4 -0
- package/src/types/template-data.ts +8 -0
- package/src/types/template-options.ts +33 -0
- package/src/types/transformation-case.ts +9 -0
- package/src/types/transformations.ts +5 -0
- package/{lib/types/ts-doc-tag.d.ts → src/types/ts-doc-tag.ts} +14 -12
- package/src/types/ts-doc.ts +18 -0
- package/{lib/types/type-gir-alias.d.ts → src/types/type-gir-alias.ts} +1 -1
- package/src/types/type-gir-class.ts +2 -0
- package/src/types/type-gir-element.ts +25 -0
- package/src/types/type-gir-enumeration-member.ts +2 -0
- package/{lib/types/type-gir-enumeration.d.ts → src/types/type-gir-enumeration.ts} +1 -1
- package/src/types/type-gir-function.ts +8 -0
- package/{lib/types/type-gir-interface.d.ts → src/types/type-gir-interface.ts} +1 -1
- package/src/types/type-gir-method.ts +2 -0
- package/src/types/type-gir-parameter.ts +1 -0
- package/{lib/types/type-gir-property.d.ts → src/types/type-gir-property.ts} +1 -1
- package/src/types/type-gir-variable.ts +1 -0
- package/src/types/type-ts-element.ts +13 -0
- package/{lib/types/type-ts-enumeration-member.d.ts → src/types/type-ts-enumeration-member.ts} +1 -1
- package/src/types/type-ts-function.ts +1 -0
- package/src/types/type-ts-property.ts +1 -0
- package/src/types/user-config-load-result.ts +6 -0
- package/src/types/user-config.ts +70 -0
- package/src/util.ts +84 -0
- package/src/utils/conflicts/conflict-resolver.ts +122 -0
- package/src/utils/conflicts/function-conflict-detector.ts +139 -0
- package/src/utils/conflicts/index.ts +2 -0
- package/src/utils/conflicts.ts +593 -0
- package/src/utils/documentation.ts +471 -0
- package/src/utils/files.ts +71 -0
- package/src/utils/function-type-guards.ts +61 -0
- package/src/utils/generation.ts +69 -0
- package/src/utils/gir-parsing.ts +262 -0
- package/src/utils/girs.ts +113 -0
- package/src/utils/index.ts +14 -0
- package/src/utils/naming.ts +188 -0
- package/src/utils/numbers.ts +8 -0
- package/src/utils/objects.ts +129 -0
- package/src/utils/path.ts +7 -0
- package/src/utils/registry.ts +5 -0
- package/src/utils/strings.ts +134 -0
- package/src/utils/type-resolution.ts +116 -0
- package/src/utils/types.ts +249 -0
- package/src/validators/class.ts +324 -0
- package/src/validators/function-parameters.ts +52 -0
- package/src/validators/interface.ts +20 -0
- package/src/visitor.ts +58 -0
- package/lib/constants.d.ts +0 -26
- package/lib/constants.js +0 -28
- package/lib/constants.js.map +0 -1
- package/lib/dependency-manager.d.ts +0 -183
- package/lib/dependency-manager.js +0 -401
- package/lib/dependency-manager.js.map +0 -1
- package/lib/formatters/default.d.ts +0 -4
- package/lib/formatters/default.js +0 -7
- package/lib/formatters/default.js.map +0 -1
- package/lib/formatters/formatter.d.ts +0 -3
- package/lib/formatters/formatter.js +0 -3
- package/lib/formatters/formatter.js.map +0 -1
- package/lib/formatters/json.d.ts +0 -4
- package/lib/formatters/json.js +0 -7
- package/lib/formatters/json.js.map +0 -1
- package/lib/generators/dts/glib.d.ts +0 -2
- package/lib/generators/dts/glib.js +0 -514
- package/lib/generators/dts/glib.js.map +0 -1
- package/lib/generators/dts/gobject.d.ts +0 -2
- package/lib/generators/dts/gobject.js +0 -117
- package/lib/generators/dts/gobject.js.map +0 -1
- package/lib/generators/dts-inline.d.ts +0 -8
- package/lib/generators/dts-inline.js +0 -59
- package/lib/generators/dts-inline.js.map +0 -1
- package/lib/generators/dts-modules.d.ts +0 -8
- package/lib/generators/dts-modules.js +0 -100
- package/lib/generators/dts-modules.js.map +0 -1
- package/lib/generators/dts.d.ts +0 -45
- package/lib/generators/dts.js +0 -682
- package/lib/generators/dts.js.map +0 -1
- package/lib/generators/generator.d.ts +0 -45
- package/lib/generators/generator.js +0 -9
- package/lib/generators/generator.js.map +0 -1
- package/lib/generators/index.d.ts +0 -5
- package/lib/generators/index.js +0 -6
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/json.d.ts +0 -256
- package/lib/generators/json.js +0 -869
- package/lib/generators/json.js.map +0 -1
- package/lib/generics/clutter.d.ts +0 -26
- package/lib/generics/clutter.js +0 -49
- package/lib/generics/clutter.js.map +0 -1
- package/lib/generics/generify.d.ts +0 -2
- package/lib/generics/generify.js +0 -39
- package/lib/generics/generify.js.map +0 -1
- package/lib/generics/gio.d.ts +0 -7
- package/lib/generics/gio.js +0 -51
- package/lib/generics/gio.js.map +0 -1
- package/lib/generics/glib.d.ts +0 -7
- package/lib/generics/glib.js +0 -18
- package/lib/generics/glib.js.map +0 -1
- package/lib/generics/meta.d.ts +0 -21
- package/lib/generics/meta.js +0 -26
- package/lib/generics/meta.js.map +0 -1
- package/lib/generics/st.d.ts +0 -16
- package/lib/generics/st.js +0 -92
- package/lib/generics/st.js.map +0 -1
- package/lib/generics/visitor.d.ts +0 -20
- package/lib/generics/visitor.js +0 -255
- package/lib/generics/visitor.js.map +0 -1
- package/lib/gir/alias.d.ts +0 -24
- package/lib/gir/alias.js +0 -43
- package/lib/gir/alias.js.map +0 -1
- package/lib/gir/base.d.ts +0 -62
- package/lib/gir/base.js +0 -95
- package/lib/gir/base.js.map +0 -1
- package/lib/gir/class.d.ts +0 -189
- package/lib/gir/class.js +0 -1131
- package/lib/gir/class.js.map +0 -1
- package/lib/gir/const.d.ts +0 -25
- package/lib/gir/const.js +0 -43
- package/lib/gir/const.js.map +0 -1
- package/lib/gir/enum.d.ts +0 -45
- package/lib/gir/enum.js +0 -164
- package/lib/gir/enum.js.map +0 -1
- package/lib/gir/function.d.ts +0 -199
- package/lib/gir/function.js +0 -683
- package/lib/gir/function.js.map +0 -1
- package/lib/gir/generics.d.ts +0 -5
- package/lib/gir/generics.js +0 -57
- package/lib/gir/generics.js.map +0 -1
- package/lib/gir/namespace.d.ts +0 -21
- package/lib/gir/namespace.js +0 -57
- package/lib/gir/namespace.js.map +0 -1
- package/lib/gir/nodes.d.ts +0 -11
- package/lib/gir/nodes.js +0 -12
- package/lib/gir/nodes.js.map +0 -1
- package/lib/gir/property.d.ts +0 -60
- package/lib/gir/property.js +0 -128
- package/lib/gir/property.js.map +0 -1
- package/lib/gir/registry.d.ts +0 -51
- package/lib/gir/registry.js +0 -144
- package/lib/gir/registry.js.map +0 -1
- package/lib/gir/signal.d.ts +0 -33
- package/lib/gir/signal.js +0 -165
- package/lib/gir/signal.js.map +0 -1
- package/lib/gir/util.d.ts +0 -49
- package/lib/gir/util.js +0 -559
- package/lib/gir/util.js.map +0 -1
- package/lib/gir-module.d.ts +0 -112
- package/lib/gir-module.js +0 -570
- package/lib/gir-module.js.map +0 -1
- package/lib/gir.d.ts +0 -253
- package/lib/gir.js +0 -642
- package/lib/gir.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.js +0 -17
- package/lib/index.js.map +0 -1
- package/lib/injections/gee08.d.ts +0 -7
- package/lib/injections/gee08.js +0 -68
- package/lib/injections/gee08.js.map +0 -1
- package/lib/injections/gee1.d.ts +0 -7
- package/lib/injections/gee1.js +0 -28
- package/lib/injections/gee1.js.map +0 -1
- package/lib/injections/gio.d.ts +0 -7
- package/lib/injections/gio.js +0 -431
- package/lib/injections/gio.js.map +0 -1
- package/lib/injections/glib.d.ts +0 -7
- package/lib/injections/glib.js +0 -204
- package/lib/injections/glib.js.map +0 -1
- package/lib/injections/gobject.d.ts +0 -7
- package/lib/injections/gobject.js +0 -479
- package/lib/injections/gobject.js.map +0 -1
- package/lib/injections/inject.d.ts +0 -4
- package/lib/injections/inject.js +0 -28
- package/lib/injections/inject.js.map +0 -1
- package/lib/injections/tracker1.d.ts +0 -7
- package/lib/injections/tracker1.js +0 -30
- package/lib/injections/tracker1.js.map +0 -1
- package/lib/library-version.d.ts +0 -10
- package/lib/library-version.js +0 -45
- package/lib/library-version.js.map +0 -1
- package/lib/logger.d.ts +0 -36
- package/lib/logger.js +0 -134
- package/lib/logger.js.map +0 -1
- package/lib/messages.d.ts +0 -26
- package/lib/messages.js +0 -42
- package/lib/messages.js.map +0 -1
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -12
- package/lib/registry.js.map +0 -1
- package/lib/transformation.d.ts +0 -181
- package/lib/transformation.js +0 -480
- package/lib/transformation.js.map +0 -1
- package/lib/types/answer-version.d.ts +0 -4
- package/lib/types/answer-version.js +0 -2
- package/lib/types/answer-version.js.map +0 -1
- package/lib/types/class-parent.d.ts +0 -13
- package/lib/types/class-parent.js +0 -2
- package/lib/types/class-parent.js.map +0 -1
- package/lib/types/config-flags.d.ts +0 -4
- package/lib/types/config-flags.js +0 -2
- package/lib/types/config-flags.js.map +0 -1
- package/lib/types/construct-name.d.ts +0 -1
- package/lib/types/construct-name.js +0 -2
- package/lib/types/construct-name.js.map +0 -1
- package/lib/types/dependency-map.d.ts +0 -4
- package/lib/types/dependency-map.js +0 -2
- package/lib/types/dependency-map.js.map +0 -1
- package/lib/types/dependency.d.ts +0 -42
- package/lib/types/dependency.js +0 -2
- package/lib/types/dependency.js.map +0 -1
- package/lib/types/file-info.d.ts +0 -14
- package/lib/types/file-info.js +0 -2
- package/lib/types/file-info.js.map +0 -1
- package/lib/types/format.d.ts +0 -1
- package/lib/types/format.js +0 -2
- package/lib/types/format.js.map +0 -1
- package/lib/types/gir-alias-element.d.ts +0 -4
- package/lib/types/gir-alias-element.js +0 -2
- package/lib/types/gir-alias-element.js.map +0 -1
- package/lib/types/gir-annotation.d.ts +0 -9
- package/lib/types/gir-annotation.js +0 -2
- package/lib/types/gir-annotation.js.map +0 -1
- package/lib/types/gir-any-element.d.ts +0 -2
- package/lib/types/gir-any-element.js +0 -2
- package/lib/types/gir-any-element.js.map +0 -1
- package/lib/types/gir-bitfield-element.d.ts +0 -6
- package/lib/types/gir-bitfield-element.js +0 -2
- package/lib/types/gir-bitfield-element.js.map +0 -1
- package/lib/types/gir-callable-param-element.d.ts +0 -4
- package/lib/types/gir-callable-param-element.js +0 -2
- package/lib/types/gir-callable-param-element.js.map +0 -1
- package/lib/types/gir-callable-params.d.ts +0 -7
- package/lib/types/gir-callable-params.js +0 -2
- package/lib/types/gir-callable-params.js.map +0 -1
- package/lib/types/gir-callable-return.d.ts +0 -5
- package/lib/types/gir-callable-return.js +0 -2
- package/lib/types/gir-callable-return.js.map +0 -1
- package/lib/types/gir-callback-element.d.ts +0 -6
- package/lib/types/gir-callback-element.js +0 -2
- package/lib/types/gir-callback-element.js.map +0 -1
- package/lib/types/gir-class-element.d.ts +0 -17
- package/lib/types/gir-class-element.js +0 -2
- package/lib/types/gir-class-element.js.map +0 -1
- package/lib/types/gir-constant-element.d.ts +0 -4
- package/lib/types/gir-constant-element.js +0 -2
- package/lib/types/gir-constant-element.js.map +0 -1
- package/lib/types/gir-constructor-element.d.ts +0 -6
- package/lib/types/gir-constructor-element.js +0 -2
- package/lib/types/gir-constructor-element.js.map +0 -1
- package/lib/types/gir-enum-element.d.ts +0 -6
- package/lib/types/gir-enum-element.js +0 -2
- package/lib/types/gir-enum-element.js.map +0 -1
- package/lib/types/gir-field-element.d.ts +0 -5
- package/lib/types/gir-field-element.js +0 -2
- package/lib/types/gir-field-element.js.map +0 -1
- package/lib/types/gir-function-element.d.ts +0 -6
- package/lib/types/gir-function-element.js +0 -2
- package/lib/types/gir-function-element.js.map +0 -1
- package/lib/types/gir-instance-parameter.d.ts +0 -8
- package/lib/types/gir-instance-parameter.js +0 -2
- package/lib/types/gir-instance-parameter.js.map +0 -1
- package/lib/types/gir-interface-element.d.ts +0 -16
- package/lib/types/gir-interface-element.js +0 -2
- package/lib/types/gir-interface-element.js.map +0 -1
- package/lib/types/gir-member-element.d.ts +0 -5
- package/lib/types/gir-member-element.js +0 -2
- package/lib/types/gir-member-element.js.map +0 -1
- package/lib/types/gir-method-element.d.ts +0 -7
- package/lib/types/gir-method-element.js +0 -2
- package/lib/types/gir-method-element.js.map +0 -1
- package/lib/types/gir-module-resolved-by.d.ts +0 -15
- package/lib/types/gir-module-resolved-by.js +0 -2
- package/lib/types/gir-module-resolved-by.js.map +0 -1
- package/lib/types/gir-modules-grouped-map.d.ts +0 -4
- package/lib/types/gir-modules-grouped-map.js +0 -2
- package/lib/types/gir-modules-grouped-map.js.map +0 -1
- package/lib/types/gir-modules-grouped.d.ts +0 -12
- package/lib/types/gir-modules-grouped.js +0 -2
- package/lib/types/gir-modules-grouped.js.map +0 -1
- package/lib/types/gir-namespace.d.ts +0 -27
- package/lib/types/gir-namespace.js +0 -2
- package/lib/types/gir-namespace.js.map +0 -1
- package/lib/types/gir-property-element.d.ts +0 -4
- package/lib/types/gir-property-element.js +0 -2
- package/lib/types/gir-property-element.js.map +0 -1
- package/lib/types/gir-record-element.d.ts +0 -10
- package/lib/types/gir-record-element.js +0 -2
- package/lib/types/gir-record-element.js.map +0 -1
- package/lib/types/gir-repository.d.ts +0 -5
- package/lib/types/gir-repository.js +0 -2
- package/lib/types/gir-repository.js.map +0 -1
- package/lib/types/gir-signal.d.ts +0 -10
- package/lib/types/gir-signal.js +0 -2
- package/lib/types/gir-signal.js.map +0 -1
- package/lib/types/gir-type-name.d.ts +0 -2
- package/lib/types/gir-type-name.js +0 -2
- package/lib/types/gir-type-name.js.map +0 -1
- package/lib/types/gir-union-element.d.ts +0 -9
- package/lib/types/gir-union-element.js +0 -2
- package/lib/types/gir-union-element.js.map +0 -1
- package/lib/types/gir-unparsed-number.d.ts +0 -2
- package/lib/types/gir-unparsed-number.js +0 -2
- package/lib/types/gir-unparsed-number.js.map +0 -1
- package/lib/types/gir-virtual-method.d.ts +0 -6
- package/lib/types/gir-virtual-method.js +0 -2
- package/lib/types/gir-virtual-method.js.map +0 -1
- package/lib/types/index.d.ts +0 -79
- package/lib/types/index.js +0 -80
- package/lib/types/index.js.map +0 -1
- package/lib/types/inheritance-table.js +0 -2
- package/lib/types/inheritance-table.js.map +0 -1
- package/lib/types/local-name-check.d.ts +0 -4
- package/lib/types/local-name-check.js +0 -2
- package/lib/types/local-name-check.js.map +0 -1
- package/lib/types/local-name-type.d.ts +0 -1
- package/lib/types/local-name-type.js +0 -2
- package/lib/types/local-name-type.js.map +0 -1
- package/lib/types/local-name.d.ts +0 -7
- package/lib/types/local-name.js +0 -2
- package/lib/types/local-name.js.map +0 -1
- package/lib/types/local-names.d.ts +0 -4
- package/lib/types/local-names.js +0 -2
- package/lib/types/local-names.js.map +0 -1
- package/lib/types/metadata.d.ts +0 -8
- package/lib/types/metadata.js +0 -2
- package/lib/types/metadata.js.map +0 -1
- package/lib/types/options-base.d.ts +0 -4
- package/lib/types/options-base.js +0 -2
- package/lib/types/options-base.js.map +0 -1
- package/lib/types/options-generation.d.ts +0 -33
- package/lib/types/options-generation.js +0 -2
- package/lib/types/options-generation.js.map +0 -1
- package/lib/types/options-load.d.ts +0 -5
- package/lib/types/options-load.js +0 -2
- package/lib/types/options-load.js.map +0 -1
- package/lib/types/options-transform.d.ts +0 -4
- package/lib/types/options-transform.js +0 -2
- package/lib/types/options-transform.js.map +0 -1
- package/lib/types/output-format.d.ts +0 -1
- package/lib/types/output-format.js +0 -2
- package/lib/types/output-format.js.map +0 -1
- package/lib/types/package-data-parsed.d.ts +0 -28
- package/lib/types/package-data-parsed.js +0 -2
- package/lib/types/package-data-parsed.js.map +0 -1
- package/lib/types/package-data.d.ts +0 -23
- package/lib/types/package-data.js +0 -2
- package/lib/types/package-data.js.map +0 -1
- package/lib/types/package-section-parsed.d.ts +0 -8
- package/lib/types/package-section-parsed.js +0 -2
- package/lib/types/package-section-parsed.js.map +0 -1
- package/lib/types/parsed-gir.d.ts +0 -5
- package/lib/types/parsed-gir.js +0 -2
- package/lib/types/parsed-gir.js.map +0 -1
- package/lib/types/parsed-package-data.d.ts +0 -6
- package/lib/types/parsed-package-data.js +0 -2
- package/lib/types/parsed-package-data.js.map +0 -1
- package/lib/types/part-of-class.d.ts +0 -7
- package/lib/types/part-of-class.js +0 -2
- package/lib/types/part-of-class.js.map +0 -1
- package/lib/types/part-of-module.d.ts +0 -6
- package/lib/types/part-of-module.js +0 -2
- package/lib/types/part-of-module.js.map +0 -1
- package/lib/types/property-case.d.ts +0 -1
- package/lib/types/property-case.js +0 -2
- package/lib/types/property-case.js.map +0 -1
- package/lib/types/resolve-type.d.ts +0 -4
- package/lib/types/resolve-type.js +0 -6
- package/lib/types/resolve-type.js.map +0 -1
- package/lib/types/template-data.d.ts +0 -7
- package/lib/types/template-data.js +0 -2
- package/lib/types/template-data.js.map +0 -1
- package/lib/types/transformation-case.d.ts +0 -1
- package/lib/types/transformation-case.js +0 -2
- package/lib/types/transformation-case.js.map +0 -1
- package/lib/types/transformations.d.ts +0 -4
- package/lib/types/transformations.js +0 -2
- package/lib/types/transformations.js.map +0 -1
- package/lib/types/ts-doc-tag.js +0 -2
- package/lib/types/ts-doc-tag.js.map +0 -1
- package/lib/types/ts-doc.d.ts +0 -16
- package/lib/types/ts-doc.js +0 -2
- package/lib/types/ts-doc.js.map +0 -1
- package/lib/types/type-gir-alias.js +0 -2
- package/lib/types/type-gir-alias.js.map +0 -1
- package/lib/types/type-gir-class.d.ts +0 -2
- package/lib/types/type-gir-class.js +0 -2
- package/lib/types/type-gir-class.js.map +0 -1
- package/lib/types/type-gir-element.d.ts +0 -3
- package/lib/types/type-gir-element.js +0 -2
- package/lib/types/type-gir-element.js.map +0 -1
- package/lib/types/type-gir-enumeration-member.d.ts +0 -2
- package/lib/types/type-gir-enumeration-member.js +0 -2
- package/lib/types/type-gir-enumeration-member.js.map +0 -1
- package/lib/types/type-gir-enumeration.js +0 -2
- package/lib/types/type-gir-enumeration.js.map +0 -1
- package/lib/types/type-gir-function.d.ts +0 -1
- package/lib/types/type-gir-function.js +0 -2
- package/lib/types/type-gir-function.js.map +0 -1
- package/lib/types/type-gir-interface.js +0 -2
- package/lib/types/type-gir-interface.js.map +0 -1
- package/lib/types/type-gir-method.d.ts +0 -2
- package/lib/types/type-gir-method.js +0 -2
- package/lib/types/type-gir-method.js.map +0 -1
- package/lib/types/type-gir-parameter.d.ts +0 -1
- package/lib/types/type-gir-parameter.js +0 -2
- package/lib/types/type-gir-parameter.js.map +0 -1
- package/lib/types/type-gir-property.js +0 -2
- package/lib/types/type-gir-property.js.map +0 -1
- package/lib/types/type-gir-variable.d.ts +0 -1
- package/lib/types/type-gir-variable.js +0 -2
- package/lib/types/type-gir-variable.js.map +0 -1
- package/lib/types/type-ts-element.d.ts +0 -3
- package/lib/types/type-ts-element.js +0 -2
- package/lib/types/type-ts-element.js.map +0 -1
- package/lib/types/type-ts-enumeration-member.js +0 -2
- package/lib/types/type-ts-enumeration-member.js.map +0 -1
- package/lib/types/type-ts-function.d.ts +0 -1
- package/lib/types/type-ts-function.js +0 -2
- package/lib/types/type-ts-function.js.map +0 -1
- package/lib/types/type-ts-property.d.ts +0 -1
- package/lib/types/type-ts-property.js +0 -2
- package/lib/types/type-ts-property.js.map +0 -1
- package/lib/types/user-config-load-result.d.ts +0 -6
- package/lib/types/user-config-load-result.js +0 -2
- package/lib/types/user-config-load-result.js.map +0 -1
- package/lib/types/user-config.d.ts +0 -35
- package/lib/types/user-config.js +0 -2
- package/lib/types/user-config.js.map +0 -1
- package/lib/util.d.ts +0 -20
- package/lib/util.js +0 -67
- package/lib/util.js.map +0 -1
- package/lib/utils.d.ts +0 -268
- package/lib/utils.js +0 -417
- package/lib/utils.js.map +0 -1
- package/lib/validators/class.d.ts +0 -7
- package/lib/validators/class.js +0 -217
- package/lib/validators/class.js.map +0 -1
- package/lib/validators/interface.d.ts +0 -5
- package/lib/validators/interface.js +0 -16
- package/lib/validators/interface.js.map +0 -1
- package/lib/visitor.d.ts +0 -35
- package/lib/visitor.js +0 -29
- package/lib/visitor.js.map +0 -1
|
@@ -0,0 +1,1484 @@
|
|
|
1
|
+
import { ConsoleReporter } from "@ts-for-gir/reporter";
|
|
2
|
+
import type { FormatGenerator } from "../generators/generator.ts";
|
|
3
|
+
import {
|
|
4
|
+
FunctionType,
|
|
5
|
+
Generic,
|
|
6
|
+
GenericType,
|
|
7
|
+
GenerifiedTypeIdentifier,
|
|
8
|
+
type TypeExpression,
|
|
9
|
+
TypeIdentifier,
|
|
10
|
+
UnknownType,
|
|
11
|
+
} from "../gir.ts";
|
|
12
|
+
import type {
|
|
13
|
+
GirCallbackElement,
|
|
14
|
+
GirClassElement,
|
|
15
|
+
GirFunctionElement,
|
|
16
|
+
GirInterfaceElement,
|
|
17
|
+
GirMethodElement,
|
|
18
|
+
GirRecordElement,
|
|
19
|
+
GirVirtualMethodElement,
|
|
20
|
+
} from "../index.ts";
|
|
21
|
+
import type {
|
|
22
|
+
ClassDefinition,
|
|
23
|
+
ClassMember,
|
|
24
|
+
ClassResolution,
|
|
25
|
+
InterfaceResolution,
|
|
26
|
+
IntrospectedOptions,
|
|
27
|
+
OptionsLoad,
|
|
28
|
+
RecordResolution,
|
|
29
|
+
} from "../types/index.ts";
|
|
30
|
+
import { findMap } from "../util.ts";
|
|
31
|
+
import { parseDoc, parseMetadata } from "../utils/gir-parsing.ts";
|
|
32
|
+
import { sanitizeIdentifierName } from "../utils/naming.ts";
|
|
33
|
+
import { resolveTypeIdentifier } from "../utils/type-resolution.ts";
|
|
34
|
+
import { parseTypeIdentifier } from "../utils/types.ts";
|
|
35
|
+
import type { GirVisitor } from "../visitor.ts";
|
|
36
|
+
import { IntrospectedConstructor } from "./constructor.ts";
|
|
37
|
+
import type { IntrospectedDirectAllocationConstructor } from "./direct-allocation-constructor.ts";
|
|
38
|
+
import type { IntrospectedEnum } from "./enum.ts";
|
|
39
|
+
import { IntrospectedFunction } from "./function.ts";
|
|
40
|
+
import { createGenericNameGenerator, createGenericNameGeneratorAt } from "./generics.ts";
|
|
41
|
+
import { IntrospectedBase } from "./introspected-base.ts";
|
|
42
|
+
import { IntrospectedNamespaceMember } from "./introspected-namespace-member.ts";
|
|
43
|
+
import type { IntrospectedNamespace } from "./namespace.ts";
|
|
44
|
+
import type { IntrospectedFunctionParameter } from "./parameter.ts";
|
|
45
|
+
import { IntrospectedField, IntrospectedProperty } from "./property.ts";
|
|
46
|
+
import { IntrospectedSignal } from "./signal.ts";
|
|
47
|
+
|
|
48
|
+
const log = new ConsoleReporter(true, "gir/introspected-classes", true);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Represents a signal with metadata
|
|
52
|
+
*/
|
|
53
|
+
export interface SignalDescriptor {
|
|
54
|
+
name: string;
|
|
55
|
+
signal?: IntrospectedSignal;
|
|
56
|
+
isNotifySignal?: boolean;
|
|
57
|
+
isDetailSignal?: boolean;
|
|
58
|
+
parameterTypes?: string[];
|
|
59
|
+
returnType?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Base class for all class functions
|
|
64
|
+
*/
|
|
65
|
+
export class IntrospectedClassFunction<
|
|
66
|
+
Parent extends IntrospectedBaseClass | IntrospectedEnum = IntrospectedBaseClass | IntrospectedEnum,
|
|
67
|
+
> extends IntrospectedBase<Parent> {
|
|
68
|
+
readonly parameters: IntrospectedFunctionParameter[];
|
|
69
|
+
protected readonly return_type: TypeExpression;
|
|
70
|
+
readonly output_parameters: IntrospectedFunctionParameter[];
|
|
71
|
+
protected _anyify: boolean = false;
|
|
72
|
+
protected _generify: boolean = false;
|
|
73
|
+
interfaceParent: IntrospectedBaseClass | IntrospectedEnum | null = null;
|
|
74
|
+
returnTypeDoc?: string | null;
|
|
75
|
+
/** If this function was generated from a signal, stores the signal name. */
|
|
76
|
+
signalOrigin?: string;
|
|
77
|
+
|
|
78
|
+
generics: Generic[] = [];
|
|
79
|
+
|
|
80
|
+
constructor({
|
|
81
|
+
name,
|
|
82
|
+
parameters = [],
|
|
83
|
+
output_parameters = [],
|
|
84
|
+
return_type = UnknownType,
|
|
85
|
+
parent,
|
|
86
|
+
doc,
|
|
87
|
+
...args
|
|
88
|
+
}: IntrospectedOptions<{
|
|
89
|
+
name: string;
|
|
90
|
+
parameters?: IntrospectedFunctionParameter[];
|
|
91
|
+
output_parameters?: IntrospectedFunctionParameter[];
|
|
92
|
+
return_type?: TypeExpression;
|
|
93
|
+
parent: Parent;
|
|
94
|
+
originalParent?: Parent | null;
|
|
95
|
+
doc?: string | null;
|
|
96
|
+
}>) {
|
|
97
|
+
super(name, parent, { ...args });
|
|
98
|
+
|
|
99
|
+
this.parameters = parameters.map((p) => p.copy({ parent: this }));
|
|
100
|
+
this.output_parameters = output_parameters.map((p) => p.copy({ parent: this }));
|
|
101
|
+
this.return_type = return_type;
|
|
102
|
+
this.doc = doc;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get namespace() {
|
|
106
|
+
return this.parent.namespace;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getCallbackParameters() {
|
|
110
|
+
const { name, parent, output_parameters, parameters, return_type } = this;
|
|
111
|
+
return {
|
|
112
|
+
name,
|
|
113
|
+
parent,
|
|
114
|
+
output_parameters,
|
|
115
|
+
parameters,
|
|
116
|
+
return_type,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
copy({
|
|
121
|
+
parent = this.parent,
|
|
122
|
+
name,
|
|
123
|
+
interfaceParent,
|
|
124
|
+
parameters,
|
|
125
|
+
outputParameters,
|
|
126
|
+
returnType,
|
|
127
|
+
}: {
|
|
128
|
+
parent?: Parent;
|
|
129
|
+
name?: string;
|
|
130
|
+
interfaceParent?: IntrospectedBaseClass | IntrospectedEnum;
|
|
131
|
+
parameters?: IntrospectedFunctionParameter[];
|
|
132
|
+
outputParameters?: IntrospectedFunctionParameter[];
|
|
133
|
+
returnType?: TypeExpression;
|
|
134
|
+
} = {}): IntrospectedClassFunction<Parent> {
|
|
135
|
+
const fn = new IntrospectedClassFunction<Parent>({
|
|
136
|
+
name: name ?? this.name,
|
|
137
|
+
parent,
|
|
138
|
+
output_parameters: outputParameters ?? this.output_parameters,
|
|
139
|
+
parameters: parameters ?? this.parameters,
|
|
140
|
+
return_type: returnType ?? this.return_type,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
fn.generics = [...this.generics];
|
|
144
|
+
fn.returnTypeDoc = this.returnTypeDoc;
|
|
145
|
+
|
|
146
|
+
if (interfaceParent) {
|
|
147
|
+
fn.interfaceParent = interfaceParent;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return fn._copyBaseProperties(this);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
accept(visitor: GirVisitor): IntrospectedClassFunction<Parent> {
|
|
154
|
+
const node = this.copy({
|
|
155
|
+
parameters: this.parameters.map((p) => {
|
|
156
|
+
return p.accept(visitor);
|
|
157
|
+
}),
|
|
158
|
+
outputParameters: this.output_parameters.map((p) => {
|
|
159
|
+
return p.accept(visitor);
|
|
160
|
+
}),
|
|
161
|
+
returnType: visitor.visitType?.(this.return_type),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const fn = visitor.visitClassFunction?.(node);
|
|
165
|
+
|
|
166
|
+
return fn ?? node;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static fromXML(
|
|
170
|
+
element: GirFunctionElement | GirMethodElement,
|
|
171
|
+
parent: IntrospectedBaseClass | IntrospectedEnum,
|
|
172
|
+
options: OptionsLoad,
|
|
173
|
+
): IntrospectedClassFunction {
|
|
174
|
+
const fn = IntrospectedFunction.fromXML(element, parent.namespace, options);
|
|
175
|
+
|
|
176
|
+
// Convert the function to a class function
|
|
177
|
+
const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
|
|
178
|
+
|
|
179
|
+
const classFn = new IntrospectedClassFunction({
|
|
180
|
+
parent,
|
|
181
|
+
name,
|
|
182
|
+
output_parameters,
|
|
183
|
+
parameters,
|
|
184
|
+
return_type,
|
|
185
|
+
doc,
|
|
186
|
+
isIntrospectable,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
classFn.returnTypeDoc = fn.returnTypeDoc;
|
|
190
|
+
classFn.generics = [...fn.generics];
|
|
191
|
+
|
|
192
|
+
return classFn;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
anyify(): this {
|
|
196
|
+
this._anyify = true;
|
|
197
|
+
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
shouldAnyify() {
|
|
202
|
+
return this._anyify;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return(): TypeExpression {
|
|
206
|
+
return this.return_type;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClassFunction"]> {
|
|
210
|
+
return generator.generateClassFunction(this) as ReturnType<T["generateClassFunction"]>;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Virtual class function
|
|
216
|
+
*/
|
|
217
|
+
export class IntrospectedVirtualClassFunction extends IntrospectedClassFunction<IntrospectedBaseClass> {
|
|
218
|
+
constructor({
|
|
219
|
+
name,
|
|
220
|
+
parameters = [],
|
|
221
|
+
output_parameters = [],
|
|
222
|
+
return_type = UnknownType,
|
|
223
|
+
parent,
|
|
224
|
+
doc,
|
|
225
|
+
...args
|
|
226
|
+
}: IntrospectedOptions<{
|
|
227
|
+
name: string;
|
|
228
|
+
parameters: IntrospectedFunctionParameter[];
|
|
229
|
+
output_parameters?: IntrospectedFunctionParameter[];
|
|
230
|
+
return_type?: TypeExpression;
|
|
231
|
+
parent: IntrospectedBaseClass;
|
|
232
|
+
doc?: string | null;
|
|
233
|
+
}>) {
|
|
234
|
+
super({
|
|
235
|
+
parent,
|
|
236
|
+
name: name.startsWith("vfunc_") ? name : `vfunc_${name}`,
|
|
237
|
+
parameters,
|
|
238
|
+
output_parameters,
|
|
239
|
+
return_type,
|
|
240
|
+
doc,
|
|
241
|
+
...args,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
copy({
|
|
246
|
+
parent = this.parent,
|
|
247
|
+
interfaceParent,
|
|
248
|
+
parameters,
|
|
249
|
+
outputParameters,
|
|
250
|
+
returnType,
|
|
251
|
+
}: {
|
|
252
|
+
parent?: IntrospectedBaseClass;
|
|
253
|
+
interfaceParent?: IntrospectedBaseClass | IntrospectedEnum | undefined;
|
|
254
|
+
parameters?: IntrospectedFunctionParameter[] | undefined;
|
|
255
|
+
outputParameters?: IntrospectedFunctionParameter[] | undefined;
|
|
256
|
+
returnType?: TypeExpression | undefined;
|
|
257
|
+
}): IntrospectedVirtualClassFunction {
|
|
258
|
+
const fn = new IntrospectedVirtualClassFunction({
|
|
259
|
+
name: this.name,
|
|
260
|
+
parent,
|
|
261
|
+
output_parameters: outputParameters ?? this.output_parameters,
|
|
262
|
+
parameters: parameters ?? this.parameters,
|
|
263
|
+
return_type: returnType ?? this.return_type,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
fn.generics = [...this.generics];
|
|
267
|
+
fn.returnTypeDoc = this.returnTypeDoc;
|
|
268
|
+
|
|
269
|
+
if (interfaceParent) {
|
|
270
|
+
fn.interfaceParent = interfaceParent;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return fn._copyBaseProperties(this);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
accept(visitor: GirVisitor): IntrospectedVirtualClassFunction {
|
|
277
|
+
const node = this.copy({
|
|
278
|
+
parameters: this.parameters.map((p) => {
|
|
279
|
+
return p.accept(visitor);
|
|
280
|
+
}),
|
|
281
|
+
outputParameters: this.output_parameters.map((p) => {
|
|
282
|
+
return p.accept(visitor);
|
|
283
|
+
}),
|
|
284
|
+
returnType: visitor.visitType?.(this.return_type),
|
|
285
|
+
});
|
|
286
|
+
return visitor.visitVirtualClassFunction?.(node) ?? node;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
static fromXML(
|
|
290
|
+
m: GirVirtualMethodElement,
|
|
291
|
+
parent: IntrospectedBaseClass,
|
|
292
|
+
options: OptionsLoad,
|
|
293
|
+
): IntrospectedVirtualClassFunction {
|
|
294
|
+
const fn = IntrospectedFunction.fromXML(m, parent.namespace, options);
|
|
295
|
+
|
|
296
|
+
// Convert the function to a virtual class function
|
|
297
|
+
const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
|
|
298
|
+
|
|
299
|
+
return new IntrospectedVirtualClassFunction({
|
|
300
|
+
parent,
|
|
301
|
+
name,
|
|
302
|
+
output_parameters,
|
|
303
|
+
parameters,
|
|
304
|
+
return_type,
|
|
305
|
+
doc,
|
|
306
|
+
isIntrospectable,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateVirtualClassFunction"]> {
|
|
311
|
+
return generator.generateVirtualClassFunction(this) as ReturnType<T["generateVirtualClassFunction"]>;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Static class function
|
|
317
|
+
*/
|
|
318
|
+
export class IntrospectedStaticClassFunction extends IntrospectedClassFunction {
|
|
319
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateStaticClassFunction"]> {
|
|
320
|
+
return generator.generateStaticClassFunction(this) as ReturnType<T["generateStaticClassFunction"]>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
copy({
|
|
324
|
+
parent = this.parent,
|
|
325
|
+
interfaceParent,
|
|
326
|
+
parameters,
|
|
327
|
+
outputParameters,
|
|
328
|
+
returnType,
|
|
329
|
+
}: {
|
|
330
|
+
parent?: IntrospectedBaseClass | IntrospectedEnum;
|
|
331
|
+
interfaceParent?: IntrospectedBaseClass | IntrospectedEnum | undefined;
|
|
332
|
+
parameters?: IntrospectedFunctionParameter[] | undefined;
|
|
333
|
+
outputParameters?: IntrospectedFunctionParameter[] | undefined;
|
|
334
|
+
returnType?: TypeExpression | undefined;
|
|
335
|
+
} = {}): IntrospectedStaticClassFunction {
|
|
336
|
+
const fn = new IntrospectedStaticClassFunction({
|
|
337
|
+
name: this.name,
|
|
338
|
+
parent,
|
|
339
|
+
output_parameters: outputParameters ?? this.output_parameters,
|
|
340
|
+
parameters: parameters ?? this.parameters,
|
|
341
|
+
return_type: returnType ?? this.return_type,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
fn.generics = [...this.generics];
|
|
345
|
+
fn.returnTypeDoc = this.returnTypeDoc;
|
|
346
|
+
|
|
347
|
+
if (interfaceParent) {
|
|
348
|
+
fn.interfaceParent = interfaceParent;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return fn._copyBaseProperties(this);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
accept(visitor: GirVisitor): IntrospectedStaticClassFunction {
|
|
355
|
+
const node = this.copy({
|
|
356
|
+
parent: this.parent,
|
|
357
|
+
parameters: this.parameters.map((p) => {
|
|
358
|
+
return p.accept(visitor);
|
|
359
|
+
}),
|
|
360
|
+
outputParameters: this.output_parameters.map((p) => {
|
|
361
|
+
return p.accept(visitor);
|
|
362
|
+
}),
|
|
363
|
+
returnType: visitor.visitType?.(this.return_type),
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
return visitor.visitStaticClassFunction?.(node) ?? node;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
asClassFunction(parent: IntrospectedBaseClass): IntrospectedClassFunction {
|
|
370
|
+
const { name, output_parameters, parameters, return_type, doc, isIntrospectable } = this;
|
|
371
|
+
|
|
372
|
+
const fn = new IntrospectedClassFunction({
|
|
373
|
+
parent,
|
|
374
|
+
name,
|
|
375
|
+
output_parameters,
|
|
376
|
+
parameters,
|
|
377
|
+
return_type,
|
|
378
|
+
doc,
|
|
379
|
+
isIntrospectable,
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
fn.returnTypeDoc = this.returnTypeDoc;
|
|
383
|
+
fn.generics = [...this.generics];
|
|
384
|
+
|
|
385
|
+
return fn;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
static fromXML(
|
|
389
|
+
m: GirFunctionElement,
|
|
390
|
+
parent: IntrospectedBaseClass | IntrospectedEnum,
|
|
391
|
+
options: OptionsLoad,
|
|
392
|
+
): IntrospectedStaticClassFunction {
|
|
393
|
+
const fn = IntrospectedFunction.fromXML(m, parent.namespace, options);
|
|
394
|
+
|
|
395
|
+
// Convert the function to a static class function
|
|
396
|
+
const { raw_name: name, output_parameters, parameters, return_type, doc, isIntrospectable } = fn;
|
|
397
|
+
|
|
398
|
+
return new IntrospectedStaticClassFunction({
|
|
399
|
+
parent,
|
|
400
|
+
name,
|
|
401
|
+
output_parameters,
|
|
402
|
+
parameters,
|
|
403
|
+
return_type,
|
|
404
|
+
doc,
|
|
405
|
+
isIntrospectable,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Class callback function
|
|
412
|
+
*/
|
|
413
|
+
export class IntrospectedClassCallback extends IntrospectedClassFunction {
|
|
414
|
+
asFunctionType(): FunctionType {
|
|
415
|
+
return new FunctionType(
|
|
416
|
+
Object.fromEntries(this.parameters.map((p) => [p.name, p.type] as const)),
|
|
417
|
+
this.return_type,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
copy({
|
|
422
|
+
parameters,
|
|
423
|
+
returnType,
|
|
424
|
+
outputParameters,
|
|
425
|
+
parent,
|
|
426
|
+
}: {
|
|
427
|
+
parent?: IntrospectedBaseClass;
|
|
428
|
+
parameters?: IntrospectedFunctionParameter[];
|
|
429
|
+
outputParameters?: IntrospectedFunctionParameter[];
|
|
430
|
+
returnType?: TypeExpression;
|
|
431
|
+
} = {}): IntrospectedClassCallback {
|
|
432
|
+
const cb = new IntrospectedClassCallback({
|
|
433
|
+
name: this.name,
|
|
434
|
+
return_type: returnType ?? this.return_type,
|
|
435
|
+
parameters: parameters ?? this.parameters,
|
|
436
|
+
output_parameters: outputParameters ?? this.output_parameters,
|
|
437
|
+
parent: parent ?? this.parent,
|
|
438
|
+
})._copyBaseProperties(this);
|
|
439
|
+
|
|
440
|
+
cb.generics = [...this.generics];
|
|
441
|
+
|
|
442
|
+
return cb;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
accept(visitor: GirVisitor): IntrospectedClassCallback {
|
|
446
|
+
const node = this.copy({
|
|
447
|
+
parameters: this.parameters.map((p) => {
|
|
448
|
+
return p.accept(visitor);
|
|
449
|
+
}),
|
|
450
|
+
outputParameters: this.output_parameters.map((p) => {
|
|
451
|
+
return p.accept(visitor);
|
|
452
|
+
}),
|
|
453
|
+
returnType: visitor.visitType?.(this.return_type),
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
return visitor.visitClassCallback?.(node) ?? node;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static fromXML(
|
|
460
|
+
element: GirCallbackElement,
|
|
461
|
+
parent: IntrospectedBaseClass,
|
|
462
|
+
options: OptionsLoad,
|
|
463
|
+
): IntrospectedClassCallback {
|
|
464
|
+
const ns = parent.namespace;
|
|
465
|
+
const cb = new IntrospectedClassCallback(
|
|
466
|
+
IntrospectedClassFunction.fromXML(element, parent, options).getCallbackParameters(),
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
const glibTypeName = element.$["glib:type-name"];
|
|
470
|
+
if (typeof glibTypeName === "string" && element.$["glib:type-name"]) {
|
|
471
|
+
cb.resolve_names.push(glibTypeName);
|
|
472
|
+
|
|
473
|
+
ns.registerResolveName(glibTypeName, ns.namespace, cb.name);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (element.$["c:type"]) {
|
|
477
|
+
cb.resolve_names.push(element.$["c:type"]);
|
|
478
|
+
|
|
479
|
+
ns.registerResolveName(element.$["c:type"], ns.namespace, cb.name);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return cb;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClassCallback"]> {
|
|
486
|
+
return generator.generateClassCallback(this) as ReturnType<T["generateClassCallback"]>;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Abstract base class for classes and interfaces
|
|
492
|
+
*/
|
|
493
|
+
export abstract class IntrospectedBaseClass extends IntrospectedNamespaceMember {
|
|
494
|
+
/**
|
|
495
|
+
* Used to add a TypeScript index signature to a class
|
|
496
|
+
*
|
|
497
|
+
* NOTE: This should probably be migrated into the TypeScript generator itself.
|
|
498
|
+
*/
|
|
499
|
+
__ts__indexSignature?: string;
|
|
500
|
+
superType: TypeIdentifier | null;
|
|
501
|
+
|
|
502
|
+
mainConstructor: null | IntrospectedConstructor | IntrospectedDirectAllocationConstructor;
|
|
503
|
+
constructors: IntrospectedConstructor[];
|
|
504
|
+
members: IntrospectedClassFunction[];
|
|
505
|
+
props: IntrospectedProperty[];
|
|
506
|
+
fields: IntrospectedField[];
|
|
507
|
+
callbacks: IntrospectedClassCallback[];
|
|
508
|
+
|
|
509
|
+
// Generics support
|
|
510
|
+
generics: Generic[] = [];
|
|
511
|
+
|
|
512
|
+
constructor(
|
|
513
|
+
options: IntrospectedOptions<{
|
|
514
|
+
name: string;
|
|
515
|
+
namespace: IntrospectedNamespace;
|
|
516
|
+
}> &
|
|
517
|
+
Partial<ClassDefinition>,
|
|
518
|
+
) {
|
|
519
|
+
const {
|
|
520
|
+
name,
|
|
521
|
+
namespace,
|
|
522
|
+
superType = null,
|
|
523
|
+
mainConstructor = null,
|
|
524
|
+
constructors = [],
|
|
525
|
+
members = [],
|
|
526
|
+
props = [],
|
|
527
|
+
fields = [],
|
|
528
|
+
callbacks = [],
|
|
529
|
+
...args
|
|
530
|
+
} = options;
|
|
531
|
+
|
|
532
|
+
super(name, namespace, { ...args });
|
|
533
|
+
|
|
534
|
+
this.superType = superType;
|
|
535
|
+
|
|
536
|
+
this.mainConstructor = mainConstructor?.copy({ parent: this }) ?? null;
|
|
537
|
+
this.constructors = [...constructors.map((c) => c.copy({ parent: this }))];
|
|
538
|
+
this.members = [...members.map((m) => m.copy({ parent: this }))];
|
|
539
|
+
this.props = [...props.map((p) => p.copy({ parent: this }))];
|
|
540
|
+
this.fields = [...fields.map((f) => f.copy({ parent: this }))];
|
|
541
|
+
this.callbacks = [...callbacks.map((c) => c.copy({ parent: this }))];
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
abstract accept(visitor: GirVisitor): IntrospectedBaseClass;
|
|
545
|
+
|
|
546
|
+
abstract copy(options?: {
|
|
547
|
+
parent?: undefined;
|
|
548
|
+
constructors?: IntrospectedConstructor[];
|
|
549
|
+
members?: IntrospectedClassFunction[];
|
|
550
|
+
props?: IntrospectedProperty[];
|
|
551
|
+
fields?: IntrospectedField[];
|
|
552
|
+
callbacks?: IntrospectedClassCallback[];
|
|
553
|
+
}): IntrospectedBaseClass;
|
|
554
|
+
|
|
555
|
+
getGenericName = createGenericNameGenerator();
|
|
556
|
+
|
|
557
|
+
abstract resolveParents(): RecordResolution | InterfaceResolution | ClassResolution;
|
|
558
|
+
abstract someParent(predicate: (b: IntrospectedBaseClass) => boolean): boolean;
|
|
559
|
+
abstract findParent(predicate: (b: IntrospectedBaseClass) => boolean): IntrospectedBaseClass | undefined;
|
|
560
|
+
abstract findParentMap<K>(predicate: (b: IntrospectedBaseClass) => K | undefined): K | undefined;
|
|
561
|
+
|
|
562
|
+
addGeneric(definition: {
|
|
563
|
+
deriveFrom?: TypeIdentifier;
|
|
564
|
+
default?: TypeExpression;
|
|
565
|
+
constraint?: TypeExpression;
|
|
566
|
+
propagate?: boolean;
|
|
567
|
+
}) {
|
|
568
|
+
const param = new Generic(
|
|
569
|
+
new GenericType(this.getGenericName(), definition.constraint),
|
|
570
|
+
definition.default,
|
|
571
|
+
definition.deriveFrom,
|
|
572
|
+
definition.constraint,
|
|
573
|
+
definition.propagate,
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
this.generics.push(param);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
getType(): TypeIdentifier {
|
|
580
|
+
return new TypeIdentifier(this.name, this.namespace.namespace);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
static fromXML(
|
|
584
|
+
_element: GirClassElement | GirInterfaceElement | GirRecordElement,
|
|
585
|
+
_ns: IntrospectedNamespace,
|
|
586
|
+
_options: OptionsLoad,
|
|
587
|
+
): IntrospectedBaseClass {
|
|
588
|
+
throw new Error("fromXML is not implemented on GirBaseClass");
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
abstract asString<T = string>(generator: FormatGenerator<T>): T;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Represents a GIR class
|
|
596
|
+
*/
|
|
597
|
+
export class IntrospectedClass extends IntrospectedBaseClass {
|
|
598
|
+
signals: IntrospectedSignal[] = [];
|
|
599
|
+
interfaces: TypeIdentifier[] = [];
|
|
600
|
+
isAbstract: boolean = false;
|
|
601
|
+
mainConstructor: null | IntrospectedConstructor = null;
|
|
602
|
+
private _staticDefinition: string | null = null;
|
|
603
|
+
|
|
604
|
+
constructor(name: string, namespace: IntrospectedNamespace) {
|
|
605
|
+
super({ name, namespace });
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
get gtype() {
|
|
609
|
+
return this.name;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
getAllSignals(): SignalDescriptor[] {
|
|
613
|
+
const allSignals = this.getBaseSignals();
|
|
614
|
+
|
|
615
|
+
if (this.hasGObjectSupport()) {
|
|
616
|
+
this.addNotifySignals(allSignals);
|
|
617
|
+
this.addDetailedSignals(allSignals);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return allSignals;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
private getBaseSignals() {
|
|
624
|
+
return this.signals.map((signal) => ({
|
|
625
|
+
name: signal.name,
|
|
626
|
+
signal: signal,
|
|
627
|
+
isNotifySignal: false,
|
|
628
|
+
isDetailSignal: false,
|
|
629
|
+
}));
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private hasGObjectSupport(): boolean {
|
|
633
|
+
const isGObjectObject = this.isGObjectObject();
|
|
634
|
+
const hasNotifySignal = this.hasExplicitNotifySignal();
|
|
635
|
+
const hasGObjectParent = this.hasGObjectParent();
|
|
636
|
+
|
|
637
|
+
return isGObjectObject || hasNotifySignal || hasGObjectParent;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
private isGObjectObject(): boolean {
|
|
641
|
+
return this.name === "Object" && this.namespace.namespace === "GObject";
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
private hasExplicitNotifySignal(): boolean {
|
|
645
|
+
return this.signals.some((signal) => signal.name === "notify");
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
private hasGObjectParent(): boolean {
|
|
649
|
+
return this.someParent(
|
|
650
|
+
(p: IntrospectedClass | IntrospectedInterface) => p.namespace.namespace === "GObject" && p.name === "Object",
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private addNotifySignals(allSignals: SignalDescriptor[]): void {
|
|
655
|
+
const propertyNames = this.getUniquePropertyNames();
|
|
656
|
+
|
|
657
|
+
propertyNames.forEach((propertyName) => {
|
|
658
|
+
allSignals.push({
|
|
659
|
+
name: `notify::${propertyName}`,
|
|
660
|
+
isNotifySignal: true,
|
|
661
|
+
isDetailSignal: false,
|
|
662
|
+
parameterTypes: ["GObject.ParamSpec"],
|
|
663
|
+
returnType: "void",
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
private addDetailedSignals(allSignals: SignalDescriptor[]): void {
|
|
669
|
+
const propertyNames = this.getUniquePropertyNames();
|
|
670
|
+
|
|
671
|
+
this.signals.forEach((signal) => {
|
|
672
|
+
if (signal.detailed) {
|
|
673
|
+
propertyNames.forEach((propertyName) => {
|
|
674
|
+
allSignals.push({
|
|
675
|
+
name: `${signal.name}::${propertyName}`,
|
|
676
|
+
signal: signal,
|
|
677
|
+
isNotifySignal: false,
|
|
678
|
+
isDetailSignal: true,
|
|
679
|
+
parameterTypes: signal.parameters.map((p) => this.getPropertyTypeString(p.type)),
|
|
680
|
+
returnType: this.getPropertyTypeString(signal.return_type),
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private getUniquePropertyNames(): Set<string> {
|
|
688
|
+
const allProperties = this.getAllProperties();
|
|
689
|
+
return new Set(
|
|
690
|
+
allProperties.map((prop) =>
|
|
691
|
+
prop.name
|
|
692
|
+
.replace(/_/g, "-")
|
|
693
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
694
|
+
.toLowerCase(),
|
|
695
|
+
),
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
private getPropertyTypeString(type: TypeExpression): string {
|
|
700
|
+
// Simple type conversion - this might need to be adjusted based on actual type structure
|
|
701
|
+
if (typeof type === "string") return type;
|
|
702
|
+
if (type?.toString) return type.toString();
|
|
703
|
+
return "any";
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
private getAllProperties(): IntrospectedProperty[] {
|
|
707
|
+
const allProperties = [...this.props];
|
|
708
|
+
let currentClass = this as IntrospectedClass;
|
|
709
|
+
while (currentClass) {
|
|
710
|
+
const parentResolution = currentClass.resolveParents().extends();
|
|
711
|
+
if (parentResolution && parentResolution.node instanceof IntrospectedClass) {
|
|
712
|
+
const parentClass = parentResolution.node as IntrospectedClass;
|
|
713
|
+
allProperties.push(...parentClass.props);
|
|
714
|
+
currentClass = parentClass;
|
|
715
|
+
} else {
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const implementedProps = this.implementedProperties();
|
|
720
|
+
allProperties.push(...implementedProps);
|
|
721
|
+
return allProperties;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
accept(visitor: GirVisitor): IntrospectedClass {
|
|
725
|
+
const node = this.copy({
|
|
726
|
+
signals: this.signals.map((s) => s.accept(visitor)),
|
|
727
|
+
constructors: this.constructors.map((c) => c.accept(visitor)),
|
|
728
|
+
members: this.members.map((m) => m.accept(visitor)),
|
|
729
|
+
props: this.props.map((p) => p.accept(visitor)),
|
|
730
|
+
fields: this.fields.map((f) => f.accept(visitor)),
|
|
731
|
+
callbacks: this.callbacks.map((c) => c.accept(visitor)),
|
|
732
|
+
});
|
|
733
|
+
return visitor.visitClass?.(node) ?? node;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
hasInstanceSymbol<S extends { name: string }>(s: S): boolean {
|
|
737
|
+
return (
|
|
738
|
+
this.members.some((p) => s.name === p.name && !(p instanceof IntrospectedStaticClassFunction)) ||
|
|
739
|
+
this.props.some((p) => s.name === p.name) ||
|
|
740
|
+
this.fields.some((p) => s.name === p.name)
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
someParent(predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean): boolean {
|
|
745
|
+
const resolution = this.resolveParents();
|
|
746
|
+
const parent = resolution.extends();
|
|
747
|
+
|
|
748
|
+
if (parent) {
|
|
749
|
+
if (predicate(parent.node as IntrospectedClass | IntrospectedInterface)) return true;
|
|
750
|
+
const some = parent.node.someParent(predicate);
|
|
751
|
+
if (some) return some;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return resolution
|
|
755
|
+
.implements()
|
|
756
|
+
.map((i) => i.node)
|
|
757
|
+
.some(
|
|
758
|
+
(i) =>
|
|
759
|
+
predicate(i) ||
|
|
760
|
+
i.someParent(
|
|
761
|
+
(p: IntrospectedBaseClass) =>
|
|
762
|
+
(p instanceof IntrospectedClass || p instanceof IntrospectedInterface) && predicate(p),
|
|
763
|
+
),
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
findParent(
|
|
768
|
+
predicate: (p: IntrospectedClass | IntrospectedInterface) => boolean,
|
|
769
|
+
): IntrospectedClass | IntrospectedInterface | undefined {
|
|
770
|
+
return this.findParentMap((parent) => {
|
|
771
|
+
if (predicate(parent)) {
|
|
772
|
+
return parent;
|
|
773
|
+
}
|
|
774
|
+
return undefined;
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
findParentMap<K>(predicate: (p: IntrospectedClass | IntrospectedInterface) => K | undefined): K | undefined {
|
|
779
|
+
const resolution = this.resolveParents();
|
|
780
|
+
const parent = resolution.extends();
|
|
781
|
+
|
|
782
|
+
if (parent) {
|
|
783
|
+
const value = predicate(parent.node as IntrospectedClass | IntrospectedInterface);
|
|
784
|
+
if (value) return value;
|
|
785
|
+
const parentMap = parent.node.findParentMap(predicate);
|
|
786
|
+
if (parentMap) return parentMap;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
return findMap(
|
|
790
|
+
resolution.implements().map((i) => i.node),
|
|
791
|
+
(i) =>
|
|
792
|
+
predicate(i) ||
|
|
793
|
+
i.findParentMap((p: IntrospectedBaseClass) =>
|
|
794
|
+
p instanceof IntrospectedClass || p instanceof IntrospectedInterface ? predicate(p) : undefined,
|
|
795
|
+
),
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private collectImplementedItems<T extends { name: string }>(
|
|
800
|
+
getItems: (node: IntrospectedBaseClass) => T[],
|
|
801
|
+
validate: (item: T) => boolean,
|
|
802
|
+
): Map<string, T> {
|
|
803
|
+
const resolution = this.resolveParents();
|
|
804
|
+
const implementedOnParent = [...(resolution.extends() ?? [])].flatMap((r) => r.implements());
|
|
805
|
+
const items = new Map<string, T>();
|
|
806
|
+
|
|
807
|
+
for (const implemented of resolution.implements()) {
|
|
808
|
+
if (implemented.node instanceof IntrospectedClass) continue;
|
|
809
|
+
if (implementedOnParent.find((p) => p.identifier.equals(implemented.identifier))?.node?.generics?.length === 0)
|
|
810
|
+
continue;
|
|
811
|
+
for (const item of getItems(implemented.node)) {
|
|
812
|
+
if (items.has(item.name) || !validate(item)) continue;
|
|
813
|
+
items.set(item.name, item);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
for (const implemented of resolution.implements()) {
|
|
818
|
+
[...implemented].forEach((e) => {
|
|
819
|
+
if (e.node instanceof IntrospectedClass) return;
|
|
820
|
+
if (implementedOnParent.find((p) => p.identifier.equals(e.identifier))?.node.generics.length === 0) return;
|
|
821
|
+
for (const item of getItems(e.node)) {
|
|
822
|
+
if (items.has(item.name) || !validate(item)) continue;
|
|
823
|
+
items.set(item.name, item);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// If an interface inherits from a class (such as Gtk.Widget)
|
|
829
|
+
// we need to pull in every item from that class...
|
|
830
|
+
for (const implemented of resolution.implements()) {
|
|
831
|
+
const extended = implemented.extends();
|
|
832
|
+
if (extended?.node instanceof IntrospectedClass) {
|
|
833
|
+
for (const item of getItems(extended.node)) {
|
|
834
|
+
if (items.has(item.name) || !validate(item)) continue;
|
|
835
|
+
items.set(item.name, item);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
return items;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
implementedProperties(potentialConflicts: IntrospectedBase<never>[] = []) {
|
|
844
|
+
const properties = this.collectImplementedItems(
|
|
845
|
+
(node) => node.props,
|
|
846
|
+
(prop) => !this.hasInstanceSymbol(prop) && potentialConflicts.every((p) => prop.name !== p.name),
|
|
847
|
+
);
|
|
848
|
+
return [...properties.values()];
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
implementedMethods(potentialConflicts: ClassMember[] = []) {
|
|
852
|
+
const methods = this.collectImplementedItems(
|
|
853
|
+
(node) => node.members,
|
|
854
|
+
(method) =>
|
|
855
|
+
!(method instanceof IntrospectedStaticClassFunction) &&
|
|
856
|
+
!this.hasInstanceSymbol(method) &&
|
|
857
|
+
potentialConflicts.every((m) => method.name !== m.name),
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
return [...methods.values()].map((f) => {
|
|
861
|
+
const mapping = new Map<string, TypeExpression>();
|
|
862
|
+
if (f.parent instanceof IntrospectedBaseClass) {
|
|
863
|
+
const inter = this.interfaces.find((i) => i.equals(f.parent.getType()));
|
|
864
|
+
|
|
865
|
+
if (inter instanceof GenerifiedTypeIdentifier) {
|
|
866
|
+
f.parent.generics.forEach((g, i) => {
|
|
867
|
+
if (inter.generics.length > i) {
|
|
868
|
+
mapping.set(g.type.identifier, inter.generics[i]);
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
const unwrapped = f.return().deepUnwrap();
|
|
875
|
+
let modifiedReturn = f.return();
|
|
876
|
+
|
|
877
|
+
if (unwrapped instanceof GenericType && mapping.has(unwrapped.identifier)) {
|
|
878
|
+
const mapped = mapping.get(unwrapped.identifier);
|
|
879
|
+
|
|
880
|
+
if (mapped) {
|
|
881
|
+
modifiedReturn = f.return().rewrap(mapped);
|
|
882
|
+
}
|
|
883
|
+
// Handles the case where a class implements an interface and thus copies its virtual methods.
|
|
884
|
+
} else if (unwrapped.equals(this.getType())) {
|
|
885
|
+
modifiedReturn = f.return().rewrap(this.getType());
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return f.copy({
|
|
889
|
+
parent: this,
|
|
890
|
+
interfaceParent: f.parent,
|
|
891
|
+
parameters: f.parameters.map((p) => {
|
|
892
|
+
const t = p.type.deepUnwrap();
|
|
893
|
+
if (t instanceof GenericType && mapping.has(t.identifier)) {
|
|
894
|
+
const iden = mapping.get(t.identifier);
|
|
895
|
+
|
|
896
|
+
if (iden) {
|
|
897
|
+
return p.copy({ type: p.type.rewrap(iden) });
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
return p;
|
|
902
|
+
}),
|
|
903
|
+
outputParameters: f.output_parameters.map((p) => {
|
|
904
|
+
const t = p.type.deepUnwrap();
|
|
905
|
+
if (t instanceof GenericType && mapping.has(t.identifier)) {
|
|
906
|
+
const iden = mapping.get(t.identifier);
|
|
907
|
+
|
|
908
|
+
if (iden) {
|
|
909
|
+
return p.copy({ type: p.type.rewrap(iden) });
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
return p;
|
|
914
|
+
}),
|
|
915
|
+
returnType: modifiedReturn,
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
resolveParents(): ClassResolution {
|
|
921
|
+
const self = this;
|
|
922
|
+
return {
|
|
923
|
+
*[Symbol.iterator]() {
|
|
924
|
+
let current = this.extends();
|
|
925
|
+
while (current !== undefined) {
|
|
926
|
+
yield current;
|
|
927
|
+
current = current.extends();
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
extends(): ClassResolution | undefined {
|
|
931
|
+
const resolved_parent = self.superType ? resolveTypeIdentifier(self.namespace, self.superType) : undefined;
|
|
932
|
+
if (resolved_parent instanceof IntrospectedClass) {
|
|
933
|
+
return resolved_parent.resolveParents();
|
|
934
|
+
}
|
|
935
|
+
return undefined;
|
|
936
|
+
},
|
|
937
|
+
implements(): InterfaceResolution[] {
|
|
938
|
+
return self.interfaces
|
|
939
|
+
.map((iface) => {
|
|
940
|
+
const resolved = resolveTypeIdentifier(self.namespace, iface);
|
|
941
|
+
if (resolved instanceof IntrospectedInterface) {
|
|
942
|
+
return resolved.resolveParents();
|
|
943
|
+
}
|
|
944
|
+
throw new Error(`Interface ${iface.name} not found`);
|
|
945
|
+
})
|
|
946
|
+
.filter((res): res is InterfaceResolution => res !== undefined);
|
|
947
|
+
},
|
|
948
|
+
node: self,
|
|
949
|
+
identifier: self.getType(),
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
copy(
|
|
954
|
+
options: {
|
|
955
|
+
parent?: undefined;
|
|
956
|
+
signals?: IntrospectedSignal[];
|
|
957
|
+
constructors?: IntrospectedConstructor[];
|
|
958
|
+
members?: IntrospectedClassFunction[];
|
|
959
|
+
props?: IntrospectedProperty[];
|
|
960
|
+
fields?: IntrospectedField[];
|
|
961
|
+
callbacks?: IntrospectedClassCallback[];
|
|
962
|
+
} = {},
|
|
963
|
+
): IntrospectedClass {
|
|
964
|
+
const klass = new IntrospectedClass(this.name, this.namespace);
|
|
965
|
+
klass.interfaces = [...this.interfaces];
|
|
966
|
+
klass.superType = this.superType;
|
|
967
|
+
klass.isAbstract = this.isAbstract;
|
|
968
|
+
klass.doc = this.doc;
|
|
969
|
+
klass.generics = [...this.generics];
|
|
970
|
+
klass._staticDefinition = this._staticDefinition;
|
|
971
|
+
|
|
972
|
+
const {
|
|
973
|
+
signals = this.signals,
|
|
974
|
+
constructors = this.constructors,
|
|
975
|
+
members = this.members,
|
|
976
|
+
props = this.props,
|
|
977
|
+
fields = this.fields,
|
|
978
|
+
callbacks = this.callbacks,
|
|
979
|
+
} = options;
|
|
980
|
+
|
|
981
|
+
klass.signals = [...signals.map((s) => s.copy({ parent: klass }))];
|
|
982
|
+
klass.constructors = [...constructors.map((c) => c.copy({ parent: klass }))];
|
|
983
|
+
klass.members = [...members.map((m) => m.copy({ parent: klass }))];
|
|
984
|
+
klass.props = [...props.map((p) => p.copy({ parent: klass }))];
|
|
985
|
+
klass.fields = [...fields.map((f) => f.copy({ parent: klass }))];
|
|
986
|
+
klass.callbacks = [...callbacks.map((c) => c.copy({ parent: klass }))];
|
|
987
|
+
|
|
988
|
+
if (this.mainConstructor) {
|
|
989
|
+
klass.mainConstructor = this.mainConstructor.copy({ parent: klass });
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
klass.getGenericName = createGenericNameGeneratorAt(this.getGenericName());
|
|
993
|
+
return klass._copyBaseProperties(this);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
get staticDefinition() {
|
|
997
|
+
return this._staticDefinition;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
static fromXML(element: GirClassElement, ns: IntrospectedNamespace, options: OptionsLoad): IntrospectedClass {
|
|
1001
|
+
const name = sanitizeIdentifierName(ns.namespace, element.$.name);
|
|
1002
|
+
if (options.verbose) {
|
|
1003
|
+
log.debug(` >> GirClass: Parsing definition ${element.$.name} (${name})...`);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
const clazz = new IntrospectedClass(name, ns);
|
|
1007
|
+
|
|
1008
|
+
IntrospectedClass.parseBasicProperties(element, clazz, ns, options);
|
|
1009
|
+
IntrospectedClass.parseResolveNames(element, clazz, ns, name);
|
|
1010
|
+
IntrospectedClass.parseInheritanceAndMembers(element, clazz, ns, options);
|
|
1011
|
+
|
|
1012
|
+
return clazz;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
private static parseBasicProperties(
|
|
1016
|
+
element: GirClassElement,
|
|
1017
|
+
clazz: IntrospectedClass,
|
|
1018
|
+
ns: IntrospectedNamespace,
|
|
1019
|
+
options: OptionsLoad,
|
|
1020
|
+
): void {
|
|
1021
|
+
if (options.loadDocs) {
|
|
1022
|
+
clazz.doc = parseDoc(element);
|
|
1023
|
+
clazz.metadata = parseMetadata(element);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (element.$.parent) {
|
|
1027
|
+
clazz.superType = parseTypeIdentifier(ns.namespace, element.$.parent);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
if (element.$.abstract) {
|
|
1031
|
+
clazz.isAbstract = true;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
private static parseResolveNames(
|
|
1036
|
+
element: GirClassElement,
|
|
1037
|
+
clazz: IntrospectedClass,
|
|
1038
|
+
ns: IntrospectedNamespace,
|
|
1039
|
+
name: string,
|
|
1040
|
+
): void {
|
|
1041
|
+
if (element.$["glib:type-name"]) {
|
|
1042
|
+
clazz.resolve_names.push(element.$["glib:type-name"]);
|
|
1043
|
+
ns.registerResolveName(element.$["glib:type-name"], ns.namespace, name);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (element.$["c:type"]) {
|
|
1047
|
+
clazz.resolve_names.push(element.$["c:type"]);
|
|
1048
|
+
ns.registerResolveName(element.$["c:type"], ns.namespace, name);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
const typeStruct = element.$["glib:type-struct"];
|
|
1052
|
+
if (typeStruct) {
|
|
1053
|
+
clazz.registerStaticDefinition(typeStruct);
|
|
1054
|
+
clazz.resolve_names.push(typeStruct);
|
|
1055
|
+
ns.registerResolveName(typeStruct, ns.namespace, name);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
private static parseInheritanceAndMembers(
|
|
1060
|
+
element: GirClassElement,
|
|
1061
|
+
clazz: IntrospectedClass,
|
|
1062
|
+
ns: IntrospectedNamespace,
|
|
1063
|
+
options: OptionsLoad,
|
|
1064
|
+
): void {
|
|
1065
|
+
try {
|
|
1066
|
+
IntrospectedClass.parseConstructors(element, clazz, options);
|
|
1067
|
+
IntrospectedClass.parseSignals(element, clazz, options);
|
|
1068
|
+
IntrospectedClass.parseProperties(element, clazz, options);
|
|
1069
|
+
IntrospectedClass.parseMethods(element, clazz, options);
|
|
1070
|
+
IntrospectedClass.parseFields(element, clazz);
|
|
1071
|
+
IntrospectedClass.parseInterfaces(element, clazz, ns);
|
|
1072
|
+
IntrospectedClass.parseCallbacks(element, clazz, ns, options);
|
|
1073
|
+
IntrospectedClass.parseVirtualMethods(element, clazz, options);
|
|
1074
|
+
IntrospectedClass.parseStaticFunctions(element, clazz, options);
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
log.reportParsingFailure(clazz.name, "class", ns.namespace, e as Error);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
private static parseConstructors(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1081
|
+
if (Array.isArray(element.constructor)) {
|
|
1082
|
+
clazz.constructors.push(
|
|
1083
|
+
...element.constructor.map((constructorElement) =>
|
|
1084
|
+
IntrospectedConstructor.fromXML(constructorElement, clazz, options),
|
|
1085
|
+
),
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
private static parseSignals(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1091
|
+
if (element["glib:signal"]) {
|
|
1092
|
+
clazz.signals.push(...element["glib:signal"].map((signal) => IntrospectedSignal.fromXML(signal, clazz, options)));
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
private static parseProperties(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1097
|
+
if (!element.property) return;
|
|
1098
|
+
|
|
1099
|
+
element.property.forEach((prop) => {
|
|
1100
|
+
const property = IntrospectedProperty.fromXML(prop, clazz, options);
|
|
1101
|
+
switch (options.propertyCase) {
|
|
1102
|
+
case "both": {
|
|
1103
|
+
clazz.props.push(property);
|
|
1104
|
+
const camelCase = property.toCamelCase();
|
|
1105
|
+
if (property.name !== camelCase.name) {
|
|
1106
|
+
clazz.props.push(camelCase);
|
|
1107
|
+
}
|
|
1108
|
+
break;
|
|
1109
|
+
}
|
|
1110
|
+
case "camel":
|
|
1111
|
+
clazz.props.push(property.toCamelCase());
|
|
1112
|
+
break;
|
|
1113
|
+
case "underscore":
|
|
1114
|
+
clazz.props.push(property);
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
private static parseMethods(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1121
|
+
if (element.method) {
|
|
1122
|
+
clazz.members.push(...element.method.map((method) => IntrospectedClassFunction.fromXML(method, clazz, options)));
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
private static parseFields(element: GirClassElement, clazz: IntrospectedClass): void {
|
|
1127
|
+
if (element.field) {
|
|
1128
|
+
element.field
|
|
1129
|
+
.filter((field) => !("callback" in field))
|
|
1130
|
+
.forEach((field) => {
|
|
1131
|
+
const f = IntrospectedField.fromXML(field, clazz);
|
|
1132
|
+
clazz.fields.push(f);
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
private static parseInterfaces(element: GirClassElement, clazz: IntrospectedClass, ns: IntrospectedNamespace): void {
|
|
1138
|
+
if (element.implements) {
|
|
1139
|
+
element.implements.forEach((implementee) => {
|
|
1140
|
+
const name = implementee.$.name;
|
|
1141
|
+
const type = parseTypeIdentifier(ns.namespace, name);
|
|
1142
|
+
if (type) {
|
|
1143
|
+
clazz.interfaces.push(type);
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
private static parseCallbacks(
|
|
1150
|
+
element: GirClassElement,
|
|
1151
|
+
clazz: IntrospectedClass,
|
|
1152
|
+
ns: IntrospectedNamespace,
|
|
1153
|
+
options: OptionsLoad,
|
|
1154
|
+
): void {
|
|
1155
|
+
if (element.callback) {
|
|
1156
|
+
if (options.verbose) {
|
|
1157
|
+
element.callback.forEach((callback) => {
|
|
1158
|
+
log.debug(`Adding callback ${callback.$.name} for ${ns.namespace}`);
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
clazz.callbacks.push(
|
|
1162
|
+
...element.callback.map((callback) => IntrospectedClassCallback.fromXML(callback, clazz, options)),
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
private static parseVirtualMethods(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1168
|
+
if (element["virtual-method"]) {
|
|
1169
|
+
clazz.members.push(
|
|
1170
|
+
...element["virtual-method"].map((method) => IntrospectedVirtualClassFunction.fromXML(method, clazz, options)),
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
private static parseStaticFunctions(element: GirClassElement, clazz: IntrospectedClass, options: OptionsLoad): void {
|
|
1176
|
+
if (element.function) {
|
|
1177
|
+
clazz.members.push(
|
|
1178
|
+
...element.function.map((func) => IntrospectedStaticClassFunction.fromXML(func, clazz, options)),
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
registerStaticDefinition(typeStruct: string) {
|
|
1184
|
+
this._staticDefinition = typeStruct;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateClass"]> {
|
|
1188
|
+
return generator.generateClass(this) as ReturnType<T["generateClass"]>;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Represents a GIR interface
|
|
1194
|
+
*/
|
|
1195
|
+
export class IntrospectedInterface extends IntrospectedBaseClass {
|
|
1196
|
+
interfaces: TypeIdentifier[] = [];
|
|
1197
|
+
noParent: boolean = false;
|
|
1198
|
+
|
|
1199
|
+
accept(visitor: GirVisitor): IntrospectedInterface {
|
|
1200
|
+
const node = this.copy({
|
|
1201
|
+
constructors: this.constructors.map((c) => c.accept(visitor)),
|
|
1202
|
+
members: this.members.map((m) => m.accept(visitor)),
|
|
1203
|
+
props: this.props.map((p) => p.accept(visitor)),
|
|
1204
|
+
fields: this.fields.map((f) => f.accept(visitor)),
|
|
1205
|
+
callbacks: this.callbacks.map((c) => c.accept(visitor)),
|
|
1206
|
+
});
|
|
1207
|
+
return visitor.visitInterface?.(node) ?? node;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
someParent(predicate: (b: IntrospectedBaseClass) => boolean): boolean {
|
|
1211
|
+
const resolution = this.resolveParents();
|
|
1212
|
+
const parent = resolution.extends();
|
|
1213
|
+
return !!parent && (predicate(parent.node) || parent.node.someParent(predicate));
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
findParent(predicate: (b: IntrospectedBaseClass) => boolean): IntrospectedBaseClass | undefined {
|
|
1217
|
+
return this.findParentMap((parent) => {
|
|
1218
|
+
if (predicate(parent)) {
|
|
1219
|
+
return parent;
|
|
1220
|
+
}
|
|
1221
|
+
return undefined;
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
findParentMap<K>(predicate: (b: IntrospectedBaseClass) => K | undefined): K | undefined {
|
|
1226
|
+
const resolution = this.resolveParents();
|
|
1227
|
+
const parent = resolution.extends();
|
|
1228
|
+
|
|
1229
|
+
if (parent) {
|
|
1230
|
+
const result = predicate(parent.node);
|
|
1231
|
+
if (result !== undefined) return result;
|
|
1232
|
+
return parent.node.findParentMap(predicate);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
return undefined;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
resolveParents(): InterfaceResolution {
|
|
1239
|
+
const self = this;
|
|
1240
|
+
return {
|
|
1241
|
+
*[Symbol.iterator]() {
|
|
1242
|
+
const parentResolution = this.extends();
|
|
1243
|
+
if (parentResolution) {
|
|
1244
|
+
yield parentResolution;
|
|
1245
|
+
yield* parentResolution;
|
|
1246
|
+
}
|
|
1247
|
+
},
|
|
1248
|
+
extends(): InterfaceResolution | ClassResolution | undefined {
|
|
1249
|
+
// For interfaces, superType would be the prerequisite
|
|
1250
|
+
const resolved_parent = self.superType ? resolveTypeIdentifier(self.namespace, self.superType) : undefined;
|
|
1251
|
+
if (resolved_parent instanceof IntrospectedInterface) {
|
|
1252
|
+
return resolved_parent.resolveParents();
|
|
1253
|
+
}
|
|
1254
|
+
if (resolved_parent instanceof IntrospectedClass) {
|
|
1255
|
+
return resolved_parent.resolveParents();
|
|
1256
|
+
}
|
|
1257
|
+
return undefined;
|
|
1258
|
+
},
|
|
1259
|
+
node: self,
|
|
1260
|
+
identifier: self.getType(),
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
copy(
|
|
1265
|
+
options: {
|
|
1266
|
+
parent?: undefined;
|
|
1267
|
+
constructors?: IntrospectedConstructor[];
|
|
1268
|
+
members?: IntrospectedClassFunction[];
|
|
1269
|
+
props?: IntrospectedProperty[];
|
|
1270
|
+
fields?: IntrospectedField[];
|
|
1271
|
+
callbacks?: IntrospectedClassCallback[];
|
|
1272
|
+
} = {},
|
|
1273
|
+
): IntrospectedInterface {
|
|
1274
|
+
const iface = new IntrospectedInterface({ name: this.name, namespace: this.namespace });
|
|
1275
|
+
|
|
1276
|
+
iface.interfaces = [...this.interfaces];
|
|
1277
|
+
iface.superType = this.superType;
|
|
1278
|
+
iface.doc = this.doc;
|
|
1279
|
+
iface.generics = [...this.generics];
|
|
1280
|
+
|
|
1281
|
+
const {
|
|
1282
|
+
constructors = this.constructors,
|
|
1283
|
+
members = this.members,
|
|
1284
|
+
props = this.props,
|
|
1285
|
+
fields = this.fields,
|
|
1286
|
+
callbacks = this.callbacks,
|
|
1287
|
+
} = options;
|
|
1288
|
+
|
|
1289
|
+
iface.constructors = [...constructors.map((c) => c.copy({ parent: iface }))];
|
|
1290
|
+
iface.members = [...members.map((m) => m.copy({ parent: iface }))];
|
|
1291
|
+
iface.props = [...props.map((p) => p.copy({ parent: iface }))];
|
|
1292
|
+
iface.fields = [...fields.map((f) => f.copy({ parent: iface }))];
|
|
1293
|
+
iface.callbacks = [...callbacks.map((c) => c.copy({ parent: iface }))];
|
|
1294
|
+
|
|
1295
|
+
if (this.mainConstructor) {
|
|
1296
|
+
iface.mainConstructor = this.mainConstructor.copy({ parent: iface });
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
return iface._copyBaseProperties(this);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
static fromXML(
|
|
1303
|
+
element: GirInterfaceElement,
|
|
1304
|
+
namespace: IntrospectedNamespace,
|
|
1305
|
+
options: OptionsLoad,
|
|
1306
|
+
): IntrospectedInterface {
|
|
1307
|
+
const name = sanitizeIdentifierName(namespace.namespace, element.$.name);
|
|
1308
|
+
if (options.verbose) {
|
|
1309
|
+
log.debug(` >> GirInterface: Parsing definition ${element.$.name} (${name})...`);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
const iface = new IntrospectedInterface({ name, namespace });
|
|
1313
|
+
|
|
1314
|
+
IntrospectedInterface.parseInterfaceBasicProperties(element, iface, namespace, options);
|
|
1315
|
+
IntrospectedInterface.parseInterfaceResolveNames(element, iface, namespace, name);
|
|
1316
|
+
IntrospectedInterface.parseInterfaceMembers(element, iface, namespace, options);
|
|
1317
|
+
|
|
1318
|
+
return iface;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
private static parseInterfaceBasicProperties(
|
|
1322
|
+
element: GirInterfaceElement,
|
|
1323
|
+
iface: IntrospectedInterface,
|
|
1324
|
+
namespace: IntrospectedNamespace,
|
|
1325
|
+
options: OptionsLoad,
|
|
1326
|
+
): void {
|
|
1327
|
+
if (options.loadDocs) {
|
|
1328
|
+
iface.doc = parseDoc(element);
|
|
1329
|
+
iface.metadata = parseMetadata(element);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
if (element.prerequisite?.[0]) {
|
|
1333
|
+
const [prerequisite] = element.prerequisite;
|
|
1334
|
+
if (prerequisite.$.name) {
|
|
1335
|
+
iface.superType = parseTypeIdentifier(namespace.namespace, prerequisite.$.name);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
private static parseInterfaceResolveNames(
|
|
1341
|
+
element: GirInterfaceElement,
|
|
1342
|
+
iface: IntrospectedInterface,
|
|
1343
|
+
namespace: IntrospectedNamespace,
|
|
1344
|
+
name: string,
|
|
1345
|
+
): void {
|
|
1346
|
+
if (element.$["glib:type-name"]) {
|
|
1347
|
+
iface.resolve_names.push(element.$["glib:type-name"]);
|
|
1348
|
+
namespace.registerResolveName(element.$["glib:type-name"], namespace.namespace, name);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
if (element.$["c:type"]) {
|
|
1352
|
+
iface.resolve_names.push(element.$["c:type"]);
|
|
1353
|
+
namespace.registerResolveName(element.$["c:type"], namespace.namespace, name);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
private static parseInterfaceMembers(
|
|
1358
|
+
element: GirInterfaceElement,
|
|
1359
|
+
iface: IntrospectedInterface,
|
|
1360
|
+
namespace: IntrospectedNamespace,
|
|
1361
|
+
options: OptionsLoad,
|
|
1362
|
+
): void {
|
|
1363
|
+
try {
|
|
1364
|
+
IntrospectedInterface.parseInterfaceConstructors(element, iface, options);
|
|
1365
|
+
IntrospectedInterface.parseInterfaceProperties(element, iface, options);
|
|
1366
|
+
IntrospectedInterface.parseInterfaceMethods(element, iface, options);
|
|
1367
|
+
IntrospectedInterface.parseInterfaceFields(element, iface);
|
|
1368
|
+
IntrospectedInterface.parseInterfaceCallbacks(element, iface, namespace, options);
|
|
1369
|
+
IntrospectedInterface.parseInterfaceVirtualMethods(element, iface, options);
|
|
1370
|
+
IntrospectedInterface.parseInterfaceStaticFunctions(element, iface, options);
|
|
1371
|
+
} catch (e) {
|
|
1372
|
+
log.reportParsingFailure(iface.name, "interface", namespace.namespace, e as Error);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
private static parseInterfaceConstructors(
|
|
1377
|
+
element: GirInterfaceElement,
|
|
1378
|
+
iface: IntrospectedInterface,
|
|
1379
|
+
options: OptionsLoad,
|
|
1380
|
+
): void {
|
|
1381
|
+
if (Array.isArray(element.constructor)) {
|
|
1382
|
+
iface.constructors.push(
|
|
1383
|
+
...element.constructor.map((constructorElement) =>
|
|
1384
|
+
IntrospectedConstructor.fromXML(constructorElement, iface, options),
|
|
1385
|
+
),
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
private static parseInterfaceProperties(
|
|
1391
|
+
element: GirInterfaceElement,
|
|
1392
|
+
iface: IntrospectedInterface,
|
|
1393
|
+
options: OptionsLoad,
|
|
1394
|
+
): void {
|
|
1395
|
+
if (!element.property) return;
|
|
1396
|
+
|
|
1397
|
+
element.property.forEach((prop) => {
|
|
1398
|
+
const property = IntrospectedProperty.fromXML(prop, iface, options);
|
|
1399
|
+
switch (options.propertyCase) {
|
|
1400
|
+
case "both": {
|
|
1401
|
+
iface.props.push(property);
|
|
1402
|
+
const camelCase = property.toCamelCase();
|
|
1403
|
+
if (property.name !== camelCase.name) {
|
|
1404
|
+
iface.props.push(camelCase);
|
|
1405
|
+
}
|
|
1406
|
+
break;
|
|
1407
|
+
}
|
|
1408
|
+
case "camel":
|
|
1409
|
+
iface.props.push(property.toCamelCase());
|
|
1410
|
+
break;
|
|
1411
|
+
case "underscore":
|
|
1412
|
+
iface.props.push(property);
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
private static parseInterfaceMethods(
|
|
1419
|
+
element: GirInterfaceElement,
|
|
1420
|
+
iface: IntrospectedInterface,
|
|
1421
|
+
options: OptionsLoad,
|
|
1422
|
+
): void {
|
|
1423
|
+
if (element.method) {
|
|
1424
|
+
iface.members.push(...element.method.map((method) => IntrospectedClassFunction.fromXML(method, iface, options)));
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
private static parseInterfaceFields(element: GirInterfaceElement, iface: IntrospectedInterface): void {
|
|
1429
|
+
if (element.field) {
|
|
1430
|
+
element.field
|
|
1431
|
+
.filter((field) => !("callback" in field))
|
|
1432
|
+
.forEach((field) => {
|
|
1433
|
+
const f = IntrospectedField.fromXML(field, iface);
|
|
1434
|
+
iface.fields.push(f);
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
private static parseInterfaceCallbacks(
|
|
1440
|
+
element: GirInterfaceElement,
|
|
1441
|
+
iface: IntrospectedInterface,
|
|
1442
|
+
namespace: IntrospectedNamespace,
|
|
1443
|
+
options: OptionsLoad,
|
|
1444
|
+
): void {
|
|
1445
|
+
if (element.callback) {
|
|
1446
|
+
if (options.verbose) {
|
|
1447
|
+
element.callback.forEach((callback) => {
|
|
1448
|
+
log.debug(`Adding callback ${callback.$.name} for ${namespace.namespace}`);
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
iface.callbacks.push(
|
|
1452
|
+
...element.callback.map((callback) => IntrospectedClassCallback.fromXML(callback, iface, options)),
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
private static parseInterfaceVirtualMethods(
|
|
1458
|
+
element: GirInterfaceElement,
|
|
1459
|
+
iface: IntrospectedInterface,
|
|
1460
|
+
options: OptionsLoad,
|
|
1461
|
+
): void {
|
|
1462
|
+
if (element["virtual-method"]) {
|
|
1463
|
+
iface.members.push(
|
|
1464
|
+
...element["virtual-method"].map((method) => IntrospectedVirtualClassFunction.fromXML(method, iface, options)),
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
private static parseInterfaceStaticFunctions(
|
|
1470
|
+
element: GirInterfaceElement,
|
|
1471
|
+
iface: IntrospectedInterface,
|
|
1472
|
+
options: OptionsLoad,
|
|
1473
|
+
): void {
|
|
1474
|
+
if (element.function) {
|
|
1475
|
+
iface.members.push(
|
|
1476
|
+
...element.function.map((func) => IntrospectedStaticClassFunction.fromXML(func, iface, options)),
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
asString<T extends FormatGenerator<unknown>>(generator: T): ReturnType<T["generateInterface"]> {
|
|
1482
|
+
return generator.generateInterface(this) as ReturnType<T["generateInterface"]>;
|
|
1483
|
+
}
|
|
1484
|
+
}
|