@ts-for-gir/lib 4.0.0-beta.4 → 4.0.0-beta.40
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 +17 -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 +1521 -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 +184 -0
- package/src/gir/signal.ts +246 -0
- package/src/gir-module.ts +759 -0
- package/src/gir.ts +893 -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 +707 -0
- package/src/injections/glib.ts +275 -0
- package/src/injections/gobject.ts +901 -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 +53 -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 +58 -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 +627 -0
- package/src/utils/documentation.ts +61 -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 +243 -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 +247 -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
package/lib/gir/class.js
DELETED
|
@@ -1,1131 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../logger.js";
|
|
2
|
-
import { NativeType, TypeIdentifier, NeverType, ArrayType, ClosureType, BinaryType, PromiseType, VoidType, TupleType, BooleanType, Generic, GenericType, GenerifiedTypeIdentifier, AnyType, ConflictType, TypeConflict } from "../gir.js";
|
|
3
|
-
import { IntrospectedNamespaceMember } from "./base.js";
|
|
4
|
-
import { GirDirection, ClassStructTypeIdentifier } from "../index.js";
|
|
5
|
-
import { IntrospectedClassFunction, IntrospectedVirtualClassFunction, IntrospectedStaticClassFunction, IntrospectedConstructor, IntrospectedFunctionParameter, IntrospectedClassCallback } from "./function.js";
|
|
6
|
-
import { IntrospectedProperty, IntrospectedField } from "./property.js";
|
|
7
|
-
import { sanitizeIdentifierName, parseTypeIdentifier, isSubtypeOf, resolveTypeIdentifier, parseDoc, parseMetadata } from "./util.js";
|
|
8
|
-
import { IntrospectedSignal } from "./signal.js";
|
|
9
|
-
import { GenericNameGenerator } from "./generics.js";
|
|
10
|
-
import { findMap } from "../util.js";
|
|
11
|
-
export var FilterBehavior;
|
|
12
|
-
(function (FilterBehavior) {
|
|
13
|
-
FilterBehavior[FilterBehavior["DELETE"] = 0] = "DELETE";
|
|
14
|
-
FilterBehavior[FilterBehavior["PRESERVE"] = 1] = "PRESERVE";
|
|
15
|
-
})(FilterBehavior || (FilterBehavior = {}));
|
|
16
|
-
const log = new Logger(true, "gir/class");
|
|
17
|
-
export function filterConflicts(ns, c, elements, behavior = FilterBehavior.PRESERVE) {
|
|
18
|
-
const filtered = [...elements.filter(p => p && p.name)];
|
|
19
|
-
const prev = [];
|
|
20
|
-
const thisType = c.getType();
|
|
21
|
-
for (const next of filtered) {
|
|
22
|
-
const field_conflicts = c.findParentMap(resolved_parent => {
|
|
23
|
-
return findMap([...resolved_parent.fields], p => {
|
|
24
|
-
if (p.name && p.name == next.name) {
|
|
25
|
-
if (next instanceof IntrospectedProperty) {
|
|
26
|
-
return ConflictType.ACCESSOR_PROPERTY_CONFLICT;
|
|
27
|
-
}
|
|
28
|
-
if (next instanceof IntrospectedField &&
|
|
29
|
-
!isSubtypeOf(ns, thisType, resolved_parent.getType(), next.type, p.type)) {
|
|
30
|
-
return ConflictType.FIELD_NAME_CONFLICT;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
const prop_conflicts = !field_conflicts
|
|
37
|
-
? c.findParentMap(resolved_parent => {
|
|
38
|
-
return findMap([...resolved_parent.props], p => {
|
|
39
|
-
if (p.name && p.name == next.name) {
|
|
40
|
-
// TODO: This is very TypeScript-specific but until we include which parent
|
|
41
|
-
// a conflict originates from in the return, we have to handle this here
|
|
42
|
-
// and not in the generator...
|
|
43
|
-
//
|
|
44
|
-
// Classes can override parent interface accessors with properties _but_
|
|
45
|
-
// classes cannot override parent class accessors with properties without
|
|
46
|
-
// an error occuring.
|
|
47
|
-
if (p.parent instanceof IntrospectedClass && next instanceof IntrospectedField) {
|
|
48
|
-
return ConflictType.PROPERTY_ACCESSOR_CONFLICT;
|
|
49
|
-
}
|
|
50
|
-
if (next instanceof IntrospectedProperty &&
|
|
51
|
-
!isSubtypeOf(ns, thisType, resolved_parent.getType(), next.type, p.type)) {
|
|
52
|
-
log.warn(`>> Conflict in ${next.parent?.name}.${next.name} with ${p.parent?.name}.${p.name}.`);
|
|
53
|
-
return ConflictType.PROPERTY_NAME_CONFLICT;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
});
|
|
58
|
-
})
|
|
59
|
-
: undefined;
|
|
60
|
-
const function_conflicts = !field_conflicts && !prop_conflicts
|
|
61
|
-
? c.findParentMap(resolved_parent => findMap([...resolved_parent.constructors, ...resolved_parent.members], p => {
|
|
62
|
-
if (p.name && p.name == next.name) {
|
|
63
|
-
if (!(next instanceof IntrospectedClassFunction) ||
|
|
64
|
-
isConflictingFunction(ns, thisType, next, resolved_parent.getType(), p)) {
|
|
65
|
-
return ConflictType.FUNCTION_NAME_CONFLICT;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}))
|
|
70
|
-
: undefined;
|
|
71
|
-
const conflict = field_conflicts || prop_conflicts || function_conflicts;
|
|
72
|
-
if (conflict) {
|
|
73
|
-
if (behavior === FilterBehavior.PRESERVE) {
|
|
74
|
-
if (next instanceof IntrospectedField || next instanceof IntrospectedProperty) {
|
|
75
|
-
prev.push(next.copy({
|
|
76
|
-
type: new TypeConflict(next.type, conflict)
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
prev.push(next);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
prev.push(next);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return prev;
|
|
89
|
-
}
|
|
90
|
-
function isConflictingFunction(namespace, childThis, child, parentThis, parent) {
|
|
91
|
-
if (!parent.isIntrospectable || !child.isIntrospectable)
|
|
92
|
-
return false;
|
|
93
|
-
if (child instanceof IntrospectedConstructor && parent instanceof IntrospectedConstructor) {
|
|
94
|
-
return (child.parameters.length > parent.parameters.length ||
|
|
95
|
-
!isSubtypeOf(namespace, childThis, parentThis, child.return(), parent.return()) ||
|
|
96
|
-
child.parameters.some((p, i) => !isSubtypeOf(namespace, childThis, parentThis, p.type, parent.parameters[i].type)));
|
|
97
|
-
}
|
|
98
|
-
else if (child instanceof IntrospectedConstructor || parent instanceof IntrospectedConstructor) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
// This occurs if two functions of the same name are passed but they
|
|
102
|
-
// are different types (e.g. GirStaticClassFunction vs GirClassFunction)
|
|
103
|
-
if (Object.getPrototypeOf(child) !== Object.getPrototypeOf(parent)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return (child.parameters.length > parent.parameters.length ||
|
|
107
|
-
child.output_parameters.length !== parent.output_parameters.length ||
|
|
108
|
-
!isSubtypeOf(namespace, childThis, parentThis, child.return(), parent.return()) ||
|
|
109
|
-
child.parameters.some((np, i) => !isSubtypeOf(namespace, childThis, parentThis, np.type, parent.parameters[i].type)) ||
|
|
110
|
-
child.output_parameters.some((np, i) => !isSubtypeOf(namespace, childThis, parentThis, np.type, parent.output_parameters[i].type)));
|
|
111
|
-
}
|
|
112
|
-
export function filterFunctionConflict(ns, base, elements, conflict_ids) {
|
|
113
|
-
const nextType = base.getType();
|
|
114
|
-
return elements
|
|
115
|
-
.filter(m => m.name)
|
|
116
|
-
.reduce((prev, next) => {
|
|
117
|
-
// TODO This should catch most of them.
|
|
118
|
-
let msg = null;
|
|
119
|
-
let conflicts = conflict_ids.includes(next.name) ||
|
|
120
|
-
base.someParent(resolved_parent => {
|
|
121
|
-
const parentType = resolved_parent.getType();
|
|
122
|
-
return [...resolved_parent.constructors, ...resolved_parent.members].some(p => {
|
|
123
|
-
if (p.name && p.name == next.name) {
|
|
124
|
-
const conflicting = isConflictingFunction(ns, nextType, next, parentType, p);
|
|
125
|
-
if (conflicting) {
|
|
126
|
-
msg = `// Conflicted with ${resolved_parent.namespace.namespace}.${resolved_parent.name}.${p.name}`;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
return conflicting;
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
// Check if the method name conflicts with any props or fields either on
|
|
135
|
-
// the class or in the parent...
|
|
136
|
-
const field_conflicts = [...base.props, ...base.fields].some(p => p.name && p.name === next.name) ||
|
|
137
|
-
base.someParent(resolved_parent => [...resolved_parent.props, ...resolved_parent.fields].some(p => p.name && p.name === next.name));
|
|
138
|
-
const isGObject = base.someParent(p => p.namespace.namespace === "GObject" && p.name === "Object");
|
|
139
|
-
if (isGObject) {
|
|
140
|
-
conflicts = conflicts || ["connect", "connect_after", "emit"].includes(next.name);
|
|
141
|
-
}
|
|
142
|
-
if (conflicts) {
|
|
143
|
-
let never;
|
|
144
|
-
const never_param = new IntrospectedFunctionParameter({
|
|
145
|
-
name: "args",
|
|
146
|
-
direction: GirDirection.In,
|
|
147
|
-
isVarArgs: true,
|
|
148
|
-
type: new ArrayType(NeverType)
|
|
149
|
-
});
|
|
150
|
-
const neverOptions = {
|
|
151
|
-
name: next.name,
|
|
152
|
-
parent: base,
|
|
153
|
-
parameters: [never_param],
|
|
154
|
-
return_type: AnyType
|
|
155
|
-
};
|
|
156
|
-
if (next instanceof IntrospectedConstructor) {
|
|
157
|
-
never = new IntrospectedConstructor(neverOptions);
|
|
158
|
-
}
|
|
159
|
-
else if (next instanceof IntrospectedStaticClassFunction) {
|
|
160
|
-
never = new IntrospectedStaticClassFunction({ ...neverOptions, parent: next.parent });
|
|
161
|
-
}
|
|
162
|
-
else if (next instanceof IntrospectedVirtualClassFunction &&
|
|
163
|
-
next.parent instanceof IntrospectedClass) {
|
|
164
|
-
never = new IntrospectedVirtualClassFunction({ ...neverOptions, parent: next.parent });
|
|
165
|
-
}
|
|
166
|
-
else if (next instanceof IntrospectedClassFunction) {
|
|
167
|
-
never = new IntrospectedClassFunction({ ...neverOptions, parent: next.parent });
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
const parent = Object.getPrototypeOf(next);
|
|
171
|
-
throw new Error(`Unknown function type ${parent?.name} encountered.`);
|
|
172
|
-
}
|
|
173
|
-
if (msg)
|
|
174
|
-
never.setWarning(msg);
|
|
175
|
-
prev.push(next, never);
|
|
176
|
-
}
|
|
177
|
-
else if (field_conflicts) {
|
|
178
|
-
log.warn(`Omitting ${next.name} due to field or property conflict.`);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
prev.push(next);
|
|
182
|
-
}
|
|
183
|
-
return prev;
|
|
184
|
-
}, []);
|
|
185
|
-
}
|
|
186
|
-
export function promisifyFunctions(functions) {
|
|
187
|
-
return functions
|
|
188
|
-
.map(node => {
|
|
189
|
-
if (node.parameters.length > 0) {
|
|
190
|
-
const last_param = node.parameters[node.parameters.length - 1];
|
|
191
|
-
if (last_param) {
|
|
192
|
-
const last_param_unwrapped = last_param.type.unwrap();
|
|
193
|
-
if (last_param_unwrapped instanceof ClosureType) {
|
|
194
|
-
const internal = last_param_unwrapped.type;
|
|
195
|
-
if (internal instanceof TypeIdentifier && internal.is("Gio", "AsyncReadyCallback")) {
|
|
196
|
-
const parent = node.parent;
|
|
197
|
-
const interfaceParent = node.interfaceParent;
|
|
198
|
-
if (parent instanceof IntrospectedBaseClass) {
|
|
199
|
-
const async_res = (node instanceof IntrospectedStaticClassFunction
|
|
200
|
-
? [
|
|
201
|
-
...parent.constructors,
|
|
202
|
-
...parent.members.filter(m => m instanceof IntrospectedStaticClassFunction)
|
|
203
|
-
]
|
|
204
|
-
: [
|
|
205
|
-
...(interfaceParent instanceof IntrospectedInterface
|
|
206
|
-
? [...interfaceParent.members]
|
|
207
|
-
: []),
|
|
208
|
-
...parent.members.filter(m => !(m instanceof IntrospectedStaticClassFunction))
|
|
209
|
-
]).find(m => m.name === `${node.name.replace(/_async$/, "")}_finish` ||
|
|
210
|
-
m.name === `${node.name}_finish`);
|
|
211
|
-
if (async_res) {
|
|
212
|
-
const async_parameters = node.parameters
|
|
213
|
-
.slice(0, -1)
|
|
214
|
-
.map(p => p.copy({ parent: null }));
|
|
215
|
-
const sync_parameters = node.parameters.map(p => p.copy({ isOptional: false }));
|
|
216
|
-
const output_parameters = async_res instanceof IntrospectedConstructor ? [] : async_res.output_parameters;
|
|
217
|
-
let async_return = new PromiseType(async_res.return());
|
|
218
|
-
if (output_parameters.length > 0) {
|
|
219
|
-
const raw_return = async_res.return();
|
|
220
|
-
if (raw_return.equals(VoidType) || raw_return.equals(BooleanType)) {
|
|
221
|
-
const [output_type, ...output_types] = output_parameters.map(op => op.type);
|
|
222
|
-
async_return = new PromiseType(new TupleType(output_type, ...output_types));
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
const [...output_types] = output_parameters.map(op => op.type);
|
|
226
|
-
async_return = new PromiseType(new TupleType(raw_return, ...output_types));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return [
|
|
230
|
-
node.copy({
|
|
231
|
-
parameters: async_parameters,
|
|
232
|
-
returnType: async_return
|
|
233
|
-
}),
|
|
234
|
-
node.copy({
|
|
235
|
-
parameters: sync_parameters
|
|
236
|
-
}),
|
|
237
|
-
node.copy({
|
|
238
|
-
returnType: new BinaryType(async_return, node.return())
|
|
239
|
-
})
|
|
240
|
-
];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return node;
|
|
248
|
-
})
|
|
249
|
-
.flat(1);
|
|
250
|
-
}
|
|
251
|
-
export class IntrospectedBaseClass extends IntrospectedNamespaceMember {
|
|
252
|
-
/**
|
|
253
|
-
* Used to add a TypeScript index signature to a class
|
|
254
|
-
*
|
|
255
|
-
* NOTE: This should probably be migrated into the TypeScript generator itself.
|
|
256
|
-
*/
|
|
257
|
-
__ts__indexSignature;
|
|
258
|
-
superType;
|
|
259
|
-
mainConstructor;
|
|
260
|
-
constructors;
|
|
261
|
-
members;
|
|
262
|
-
props;
|
|
263
|
-
fields;
|
|
264
|
-
callbacks;
|
|
265
|
-
// Generics support
|
|
266
|
-
generics = [];
|
|
267
|
-
constructor(options) {
|
|
268
|
-
const { name, namespace, superType = null, mainConstructor = null, constructors = [], members = [], props = [], fields = [], callbacks = [], ...args } = options;
|
|
269
|
-
super(name, namespace, { ...args });
|
|
270
|
-
this.superType = superType;
|
|
271
|
-
this.mainConstructor = mainConstructor?.copy({ parent: this }) ?? null;
|
|
272
|
-
this.constructors = [...constructors.map(c => c.copy({ parent: this }))];
|
|
273
|
-
this.members = [...members.map(m => m.copy({ parent: this }))];
|
|
274
|
-
this.props = [...props.map(p => p.copy({ parent: this }))];
|
|
275
|
-
this.fields = [...fields.map(f => f.copy({ parent: this }))];
|
|
276
|
-
this.callbacks = [...callbacks.map(c => c.copy({ parent: this }))];
|
|
277
|
-
}
|
|
278
|
-
getGenericName = GenericNameGenerator.new();
|
|
279
|
-
addGeneric(definition) {
|
|
280
|
-
const param = new Generic(new GenericType(this.getGenericName(), definition.constraint), definition.default, definition.deriveFrom, definition.constraint, definition.propagate);
|
|
281
|
-
this.generics.push(param);
|
|
282
|
-
}
|
|
283
|
-
getType() {
|
|
284
|
-
return new TypeIdentifier(this.name, this.namespace.namespace);
|
|
285
|
-
}
|
|
286
|
-
static fromXML(
|
|
287
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
288
|
-
element,
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
290
|
-
ns,
|
|
291
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
292
|
-
options) {
|
|
293
|
-
throw new Error("fromXML is not implemented on GirBaseClass");
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
export class IntrospectedClass extends IntrospectedBaseClass {
|
|
297
|
-
signals = [];
|
|
298
|
-
interfaces = [];
|
|
299
|
-
isAbstract = false;
|
|
300
|
-
mainConstructor = null;
|
|
301
|
-
_staticDefinition = null;
|
|
302
|
-
constructor(name, namespace) {
|
|
303
|
-
super({ name, namespace });
|
|
304
|
-
}
|
|
305
|
-
accept(visitor) {
|
|
306
|
-
const node = this.copy({
|
|
307
|
-
signals: this.signals.map(s => s.accept(visitor)),
|
|
308
|
-
constructors: this.constructors.map(c => c.accept(visitor)),
|
|
309
|
-
members: this.members.map(m => m.accept(visitor)),
|
|
310
|
-
props: this.props.map(p => p.accept(visitor)),
|
|
311
|
-
fields: this.fields.map(f => f.accept(visitor)),
|
|
312
|
-
callbacks: this.callbacks.map(c => c.accept(visitor))
|
|
313
|
-
});
|
|
314
|
-
return visitor.visitClass?.(node) ?? node;
|
|
315
|
-
}
|
|
316
|
-
hasInstanceSymbol(s) {
|
|
317
|
-
return (this.members.some(p => s.name === p.name && !(p instanceof IntrospectedStaticClassFunction)) ||
|
|
318
|
-
this.props.some(p => s.name === p.name) ||
|
|
319
|
-
this.fields.some(p => s.name === p.name));
|
|
320
|
-
}
|
|
321
|
-
someParent(predicate) {
|
|
322
|
-
const resolution = this.resolveParents();
|
|
323
|
-
const parent = resolution.extends();
|
|
324
|
-
if (parent) {
|
|
325
|
-
if (predicate(parent.node))
|
|
326
|
-
return true;
|
|
327
|
-
const some = parent.node.someParent(predicate);
|
|
328
|
-
if (some)
|
|
329
|
-
return some;
|
|
330
|
-
}
|
|
331
|
-
return (resolution
|
|
332
|
-
.implements()
|
|
333
|
-
.map(i => i.node)
|
|
334
|
-
.some(n => predicate(n)) || resolution.implements().some(i => i.node.someParent(predicate)));
|
|
335
|
-
}
|
|
336
|
-
findParent(predicate) {
|
|
337
|
-
const resolution = this.resolveParents();
|
|
338
|
-
const parent = resolution.extends();
|
|
339
|
-
if (parent) {
|
|
340
|
-
if (predicate(parent.node))
|
|
341
|
-
return this;
|
|
342
|
-
const found = parent.node.findParent(predicate);
|
|
343
|
-
if (found)
|
|
344
|
-
return found;
|
|
345
|
-
}
|
|
346
|
-
const interfaces = resolution.implements().map(i => i.node);
|
|
347
|
-
return interfaces.find(n => predicate(n)) || interfaces.find(n => n.findParent(predicate));
|
|
348
|
-
}
|
|
349
|
-
findParentMap(predicate) {
|
|
350
|
-
const resolution = this.resolveParents();
|
|
351
|
-
const parent = resolution.extends();
|
|
352
|
-
if (parent) {
|
|
353
|
-
let found = predicate(parent.node);
|
|
354
|
-
if (found !== undefined)
|
|
355
|
-
return found;
|
|
356
|
-
found = parent.node.findParentMap(predicate);
|
|
357
|
-
if (found !== undefined)
|
|
358
|
-
return found;
|
|
359
|
-
}
|
|
360
|
-
const interfaces = resolution.implements().map(i => i.node);
|
|
361
|
-
const result = findMap(interfaces, i => predicate(i));
|
|
362
|
-
if (result !== undefined)
|
|
363
|
-
return result;
|
|
364
|
-
return findMap(interfaces, i => i.findParentMap(predicate));
|
|
365
|
-
}
|
|
366
|
-
implementedProperties(potentialConflicts = []) {
|
|
367
|
-
const resolution = this.resolveParents();
|
|
368
|
-
const implemented_on_parent = [...(resolution.extends() ?? [])]
|
|
369
|
-
.map(r => r.implements())
|
|
370
|
-
.flat()
|
|
371
|
-
.map(i => i.identifier);
|
|
372
|
-
const properties = new Map();
|
|
373
|
-
const validateProp = (prop) => !this.hasInstanceSymbol(prop) &&
|
|
374
|
-
!properties.has(prop.name) &&
|
|
375
|
-
potentialConflicts.every(p => prop.name !== p.name);
|
|
376
|
-
for (const implemented of resolution.implements()) {
|
|
377
|
-
if (implemented.node instanceof IntrospectedClass)
|
|
378
|
-
continue;
|
|
379
|
-
if (implemented_on_parent.some(p => p.equals(implemented.identifier)))
|
|
380
|
-
continue;
|
|
381
|
-
for (const prop of implemented.node.props) {
|
|
382
|
-
if (!validateProp(prop)) {
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
properties.set(prop.name, prop.copy({ parent: this }));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
for (const implemented of resolution.implements()) {
|
|
389
|
-
[...implemented].forEach(e => {
|
|
390
|
-
if (e.node instanceof IntrospectedClass)
|
|
391
|
-
return;
|
|
392
|
-
if (implemented_on_parent.some(p => p.equals(e.identifier)))
|
|
393
|
-
return;
|
|
394
|
-
for (const prop of e.node.props) {
|
|
395
|
-
if (!validateProp(prop)) {
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
properties.set(prop.name, prop.copy({ parent: this }));
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
// If an interface inherits from a class (such as Gtk.Widget)
|
|
403
|
-
// we need to pull in every method from that class...
|
|
404
|
-
for (const implemented of resolution.implements()) {
|
|
405
|
-
const extended = implemented.extends();
|
|
406
|
-
if (extended?.node instanceof IntrospectedClass) {
|
|
407
|
-
for (const prop of extended.node.props) {
|
|
408
|
-
if (!validateProp(prop))
|
|
409
|
-
continue;
|
|
410
|
-
properties.set(prop.name, prop);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return [...properties.values()];
|
|
415
|
-
}
|
|
416
|
-
implementedMethods(potentialConflicts = []) {
|
|
417
|
-
const resolution = this.resolveParents();
|
|
418
|
-
const implementedOnParent = [...(resolution.extends() ?? [])].map(r => r.implements()).flat();
|
|
419
|
-
const methods = new Map();
|
|
420
|
-
const validateMethod = (method) => !(method instanceof IntrospectedStaticClassFunction) &&
|
|
421
|
-
!this.hasInstanceSymbol(method) &&
|
|
422
|
-
!methods.has(method.name) &&
|
|
423
|
-
potentialConflicts.every(m => method.name !== m.name);
|
|
424
|
-
for (const implemented of resolution.implements()) {
|
|
425
|
-
if (implemented.node instanceof IntrospectedClass)
|
|
426
|
-
continue;
|
|
427
|
-
if (implementedOnParent.find(p => p.identifier.equals(implemented.identifier))?.node?.generics?.length === 0)
|
|
428
|
-
continue;
|
|
429
|
-
for (const member of implemented.node.members) {
|
|
430
|
-
if (!validateMethod(member))
|
|
431
|
-
continue;
|
|
432
|
-
methods.set(member.name, member);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
for (const implemented of resolution.implements()) {
|
|
436
|
-
[...implemented].forEach(e => {
|
|
437
|
-
if (e.node instanceof IntrospectedClass)
|
|
438
|
-
return;
|
|
439
|
-
if (implementedOnParent.find(p => p.identifier.equals(e.identifier))?.node.generics.length === 0)
|
|
440
|
-
return;
|
|
441
|
-
for (const member of e.node.members) {
|
|
442
|
-
if (!validateMethod(member))
|
|
443
|
-
continue;
|
|
444
|
-
methods.set(member.name, member);
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
// If an interface inherits from a class (such as Gtk.Widget)
|
|
449
|
-
// we need to pull in every method from that class...
|
|
450
|
-
for (const implemented of resolution.implements()) {
|
|
451
|
-
const extended = implemented.extends();
|
|
452
|
-
if (extended?.node instanceof IntrospectedClass) {
|
|
453
|
-
for (const member of extended.node.members) {
|
|
454
|
-
if (!validateMethod(member))
|
|
455
|
-
continue;
|
|
456
|
-
methods.set(member.name, member);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return [...methods.values()].map(f => {
|
|
461
|
-
const mapping = new Map();
|
|
462
|
-
if (f.parent instanceof IntrospectedBaseClass) {
|
|
463
|
-
const inter = this.interfaces.find(i => i.equals(f.parent.getType()));
|
|
464
|
-
if (inter instanceof GenerifiedTypeIdentifier) {
|
|
465
|
-
f.parent.generics.forEach((g, i) => {
|
|
466
|
-
if (inter.generics.length > i) {
|
|
467
|
-
mapping.set(g.type.identifier, inter.generics[i]);
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
const unwrapped = f.return().deepUnwrap();
|
|
473
|
-
let modifiedReturn = f.return();
|
|
474
|
-
if (unwrapped instanceof GenericType && mapping.has(unwrapped.identifier)) {
|
|
475
|
-
const mapped = mapping.get(unwrapped.identifier);
|
|
476
|
-
if (mapped) {
|
|
477
|
-
modifiedReturn = f.return().rewrap(mapped);
|
|
478
|
-
}
|
|
479
|
-
// Handles the case where a class implements an interface and thus copies its virtual methods.
|
|
480
|
-
}
|
|
481
|
-
else if (unwrapped.equals(this.getType())) {
|
|
482
|
-
modifiedReturn = f.return().rewrap(this.getType());
|
|
483
|
-
}
|
|
484
|
-
return f.copy({
|
|
485
|
-
parent: this,
|
|
486
|
-
interfaceParent: f.parent,
|
|
487
|
-
parameters: f.parameters.map(p => {
|
|
488
|
-
const t = p.type.deepUnwrap();
|
|
489
|
-
if (t instanceof GenericType && mapping.has(t.identifier)) {
|
|
490
|
-
const iden = mapping.get(t.identifier);
|
|
491
|
-
if (iden) {
|
|
492
|
-
return p.copy({ type: p.type.rewrap(iden) });
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
return p;
|
|
496
|
-
}),
|
|
497
|
-
outputParameters: f.output_parameters.map(p => {
|
|
498
|
-
const t = p.type.deepUnwrap();
|
|
499
|
-
if (t instanceof GenericType && mapping.has(t.identifier)) {
|
|
500
|
-
const iden = mapping.get(t.identifier);
|
|
501
|
-
if (iden) {
|
|
502
|
-
return p.copy({ type: p.type.rewrap(iden) });
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
return p;
|
|
506
|
-
}),
|
|
507
|
-
returnType: modifiedReturn
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
resolveParents() {
|
|
512
|
-
const { namespace, superType, interfaces } = this;
|
|
513
|
-
return {
|
|
514
|
-
*[Symbol.iterator]() {
|
|
515
|
-
let current = this.extends();
|
|
516
|
-
while (current !== undefined) {
|
|
517
|
-
yield current;
|
|
518
|
-
current = current.extends();
|
|
519
|
-
}
|
|
520
|
-
},
|
|
521
|
-
implements() {
|
|
522
|
-
const z = interfaces
|
|
523
|
-
.map(i => resolveTypeIdentifier(namespace, i))
|
|
524
|
-
.filter((i) => i instanceof IntrospectedInterface)
|
|
525
|
-
.map(i => i.resolveParents());
|
|
526
|
-
return z;
|
|
527
|
-
},
|
|
528
|
-
extends() {
|
|
529
|
-
const parentType = superType;
|
|
530
|
-
const resolved_parent = parentType && resolveTypeIdentifier(namespace, parentType);
|
|
531
|
-
if (resolved_parent instanceof IntrospectedClass)
|
|
532
|
-
return resolved_parent.resolveParents();
|
|
533
|
-
return undefined;
|
|
534
|
-
},
|
|
535
|
-
node: this,
|
|
536
|
-
identifier: this.getType()
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
copy(options = {}) {
|
|
540
|
-
const { name, namespace, superType, interfaces, members, constructors, props, fields, callbacks, isAbstract, mainConstructor, signals, generics, _staticDefinition } = this;
|
|
541
|
-
const clazz = new IntrospectedClass(name, namespace);
|
|
542
|
-
clazz._copyBaseProperties(this);
|
|
543
|
-
if (superType) {
|
|
544
|
-
clazz.superType = superType;
|
|
545
|
-
}
|
|
546
|
-
clazz._staticDefinition = _staticDefinition;
|
|
547
|
-
clazz.signals = (options.signals ?? signals).map(s => s.copy({ parent: clazz }));
|
|
548
|
-
clazz.interfaces = [...interfaces];
|
|
549
|
-
clazz.props = (options.props ?? props).map(p => p.copy({ parent: clazz }));
|
|
550
|
-
clazz.fields = (options.fields ?? fields).map(f => f.copy({ parent: clazz }));
|
|
551
|
-
clazz.callbacks = (options.callbacks ?? callbacks).map(c => c.copy({ parent: clazz }));
|
|
552
|
-
clazz.isAbstract = isAbstract;
|
|
553
|
-
clazz.mainConstructor = mainConstructor;
|
|
554
|
-
clazz.constructors = (options.constructors ?? constructors).map(c => c.copy({ parent: clazz }));
|
|
555
|
-
clazz.members = (options.members ?? members).map(m => m.copy({ parent: clazz }));
|
|
556
|
-
clazz.generics = [...generics];
|
|
557
|
-
// Ensure the generic iteration resumes
|
|
558
|
-
clazz.getGenericName = GenericNameGenerator.at(this.getGenericName());
|
|
559
|
-
return clazz;
|
|
560
|
-
}
|
|
561
|
-
get staticDefinition() {
|
|
562
|
-
return this._staticDefinition;
|
|
563
|
-
}
|
|
564
|
-
static fromXML(element, ns, options) {
|
|
565
|
-
const name = sanitizeIdentifierName(ns.namespace, element.$.name);
|
|
566
|
-
if (options.verbose) {
|
|
567
|
-
log.debug(` >> GirClass: Parsing definition ${element.$.name} (${name})...`);
|
|
568
|
-
}
|
|
569
|
-
const clazz = new IntrospectedClass(name, ns);
|
|
570
|
-
if (options.loadDocs) {
|
|
571
|
-
clazz.doc = parseDoc(element);
|
|
572
|
-
clazz.metadata = parseMetadata(element);
|
|
573
|
-
}
|
|
574
|
-
if (element.$["glib:type-name"]) {
|
|
575
|
-
clazz.resolve_names.push(element.$["glib:type-name"]);
|
|
576
|
-
ns.registerResolveName(element.$["glib:type-name"], ns.namespace, name);
|
|
577
|
-
}
|
|
578
|
-
if (element.$["glib:type-struct"]) {
|
|
579
|
-
clazz.resolve_names.push();
|
|
580
|
-
ns.registerResolveName(element.$["glib:type-struct"], ns.namespace, name);
|
|
581
|
-
}
|
|
582
|
-
if (element.$["c:type"]) {
|
|
583
|
-
clazz.resolve_names.push(element.$["c:type"]);
|
|
584
|
-
ns.registerResolveName(element.$["c:type"], ns.namespace, name);
|
|
585
|
-
}
|
|
586
|
-
const typeStruct = element.$["glib:type-struct"];
|
|
587
|
-
if (typeStruct) {
|
|
588
|
-
clazz.registerStaticDefinition(typeStruct);
|
|
589
|
-
clazz.resolve_names.push(typeStruct);
|
|
590
|
-
ns.registerResolveName(typeStruct, ns.namespace, name);
|
|
591
|
-
}
|
|
592
|
-
try {
|
|
593
|
-
// Setup parent type if this is an interface or class.
|
|
594
|
-
if (element.$.parent) {
|
|
595
|
-
clazz.superType = parseTypeIdentifier(ns.namespace, element.$.parent);
|
|
596
|
-
}
|
|
597
|
-
if (element.$.abstract) {
|
|
598
|
-
clazz.isAbstract = true;
|
|
599
|
-
}
|
|
600
|
-
if (Array.isArray(element.constructor)) {
|
|
601
|
-
clazz.constructors.push(...element.constructor.map(constructor => IntrospectedConstructor.fromXML(constructor, clazz, options)));
|
|
602
|
-
}
|
|
603
|
-
if (element["glib:signal"]) {
|
|
604
|
-
clazz.signals.push(...element["glib:signal"].map(signal => IntrospectedSignal.fromXML(signal, clazz, options)));
|
|
605
|
-
}
|
|
606
|
-
// Properties
|
|
607
|
-
if (element.property) {
|
|
608
|
-
element.property.forEach(prop => {
|
|
609
|
-
const property = IntrospectedProperty.fromXML(prop, clazz, options);
|
|
610
|
-
switch (options.propertyCase) {
|
|
611
|
-
case "both":
|
|
612
|
-
clazz.props.push(property);
|
|
613
|
-
const camelCase = property.toCamelCase();
|
|
614
|
-
// Ensure we don't duplicate properties like 'show'
|
|
615
|
-
if (property.name !== camelCase.name) {
|
|
616
|
-
clazz.props.push(camelCase);
|
|
617
|
-
}
|
|
618
|
-
break;
|
|
619
|
-
case "camel":
|
|
620
|
-
clazz.props.push(property.toCamelCase());
|
|
621
|
-
break;
|
|
622
|
-
case "underscore":
|
|
623
|
-
clazz.props.push(property);
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
// Instance Methods
|
|
629
|
-
if (element.method) {
|
|
630
|
-
clazz.members.push(...element.method.map(method => IntrospectedClassFunction.fromXML(method, clazz, options)));
|
|
631
|
-
}
|
|
632
|
-
// Fields
|
|
633
|
-
if (element.field) {
|
|
634
|
-
element.field
|
|
635
|
-
.filter(field => !("callback" in field))
|
|
636
|
-
.forEach(field => {
|
|
637
|
-
const f = IntrospectedField.fromXML(field, clazz);
|
|
638
|
-
clazz.fields.push(f);
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
if (element.implements) {
|
|
642
|
-
element.implements.forEach(implementee => {
|
|
643
|
-
const name = implementee.$.name;
|
|
644
|
-
const type = parseTypeIdentifier(ns.namespace, name);
|
|
645
|
-
if (type) {
|
|
646
|
-
clazz.interfaces.push(type);
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
// Callback Types
|
|
651
|
-
if (element.callback) {
|
|
652
|
-
clazz.callbacks.push(...element.callback.map(callback => {
|
|
653
|
-
if (options.verbose) {
|
|
654
|
-
log.debug(`Adding callback ${callback.$.name} for ${ns.namespace}`);
|
|
655
|
-
}
|
|
656
|
-
return IntrospectedClassCallback.fromXML(callback, clazz, options);
|
|
657
|
-
}));
|
|
658
|
-
}
|
|
659
|
-
// Virtual Methods
|
|
660
|
-
if (element["virtual-method"]) {
|
|
661
|
-
clazz.members.push(...element["virtual-method"].map(method => IntrospectedVirtualClassFunction.fromXML(method, clazz, options)));
|
|
662
|
-
}
|
|
663
|
-
// Static methods (functions)
|
|
664
|
-
if (element.function) {
|
|
665
|
-
clazz.members.push(...element.function.map(func => IntrospectedStaticClassFunction.fromXML(func, clazz, options)));
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
catch (e) {
|
|
669
|
-
log.error(`Failed to parse class: ${clazz.name} in ${ns.namespace}.`, e);
|
|
670
|
-
}
|
|
671
|
-
return clazz;
|
|
672
|
-
}
|
|
673
|
-
registerStaticDefinition(typeStruct) {
|
|
674
|
-
this._staticDefinition = typeStruct;
|
|
675
|
-
}
|
|
676
|
-
asString(generator) {
|
|
677
|
-
return generator.generateClass(this);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
export class IntrospectedRecord extends IntrospectedBaseClass {
|
|
681
|
-
_isForeign = false;
|
|
682
|
-
_structFor = null;
|
|
683
|
-
_isSimple = null;
|
|
684
|
-
_isSimpleWithoutPointers = null;
|
|
685
|
-
isForeign() {
|
|
686
|
-
return this._isForeign;
|
|
687
|
-
}
|
|
688
|
-
get structFor() {
|
|
689
|
-
return this._structFor;
|
|
690
|
-
}
|
|
691
|
-
getType() {
|
|
692
|
-
if (this._structFor) {
|
|
693
|
-
return this._structFor;
|
|
694
|
-
}
|
|
695
|
-
return new TypeIdentifier(this.name, this.namespace.namespace);
|
|
696
|
-
}
|
|
697
|
-
someParent(predicate) {
|
|
698
|
-
const resolution = this.resolveParents();
|
|
699
|
-
const parent = resolution.extends();
|
|
700
|
-
return !!parent && (predicate(parent.node) || parent.node.someParent(predicate));
|
|
701
|
-
}
|
|
702
|
-
findParent(predicate) {
|
|
703
|
-
const resolution = this.resolveParents();
|
|
704
|
-
const parent = resolution.extends();
|
|
705
|
-
if (parent) {
|
|
706
|
-
if (predicate(parent.node))
|
|
707
|
-
return parent.node;
|
|
708
|
-
const found = parent.node.findParent(predicate);
|
|
709
|
-
if (found)
|
|
710
|
-
return found;
|
|
711
|
-
}
|
|
712
|
-
return undefined;
|
|
713
|
-
}
|
|
714
|
-
findParentMap(predicate) {
|
|
715
|
-
const resolution = this.resolveParents();
|
|
716
|
-
const parent = resolution.extends();
|
|
717
|
-
if (parent) {
|
|
718
|
-
const result = predicate(parent.node);
|
|
719
|
-
if (result !== undefined)
|
|
720
|
-
return result;
|
|
721
|
-
return parent.node.findParentMap(predicate);
|
|
722
|
-
}
|
|
723
|
-
return undefined;
|
|
724
|
-
}
|
|
725
|
-
accept(visitor) {
|
|
726
|
-
const node = this.copy({
|
|
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.visitRecord?.(node) ?? node;
|
|
734
|
-
}
|
|
735
|
-
resolveParents() {
|
|
736
|
-
const { namespace, superType } = this;
|
|
737
|
-
return {
|
|
738
|
-
*[Symbol.iterator]() {
|
|
739
|
-
let current = this.extends();
|
|
740
|
-
while (current !== undefined) {
|
|
741
|
-
yield current;
|
|
742
|
-
current = current.extends();
|
|
743
|
-
}
|
|
744
|
-
},
|
|
745
|
-
extends() {
|
|
746
|
-
const resolved_parent = superType ? resolveTypeIdentifier(namespace, superType) : undefined;
|
|
747
|
-
if (resolved_parent instanceof IntrospectedRecord)
|
|
748
|
-
return resolved_parent.resolveParents();
|
|
749
|
-
return undefined;
|
|
750
|
-
},
|
|
751
|
-
node: this,
|
|
752
|
-
identifier: this.getType()
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
copy(options = {}) {
|
|
756
|
-
const { name, namespace, superType, members, constructors, _isForeign, _structFor, props, fields, callbacks, generics, mainConstructor } = this;
|
|
757
|
-
const clazz = new IntrospectedRecord({ name, namespace });
|
|
758
|
-
clazz._copyBaseProperties(this);
|
|
759
|
-
if (superType) {
|
|
760
|
-
clazz.superType;
|
|
761
|
-
}
|
|
762
|
-
clazz._structFor = _structFor;
|
|
763
|
-
clazz._isForeign = _isForeign;
|
|
764
|
-
clazz.props = (options.props ?? props).map(p => p.copy({ parent: clazz }));
|
|
765
|
-
clazz.fields = (options.fields ?? fields).map(f => f.copy({ parent: clazz }));
|
|
766
|
-
clazz.callbacks = (options.callbacks ?? callbacks).map(c => c.copy({ parent: clazz }));
|
|
767
|
-
clazz.mainConstructor = mainConstructor?.copy({ parent: clazz }) ?? null;
|
|
768
|
-
clazz.constructors = (options.constructors ?? constructors).map(c => c.copy({ parent: clazz }));
|
|
769
|
-
clazz.members = (options.members ?? members).map(m => m.copy({ parent: clazz }));
|
|
770
|
-
clazz.generics = [...generics];
|
|
771
|
-
return clazz;
|
|
772
|
-
}
|
|
773
|
-
static foreign(name, namespace) {
|
|
774
|
-
const foreignRecord = new IntrospectedRecord({ name, namespace });
|
|
775
|
-
foreignRecord._isForeign = true;
|
|
776
|
-
return foreignRecord;
|
|
777
|
-
}
|
|
778
|
-
static fromXML(element, namespace, options) {
|
|
779
|
-
if (!element.$.name) {
|
|
780
|
-
throw new Error("Invalid GIR File: No name provided for union.");
|
|
781
|
-
}
|
|
782
|
-
const name = sanitizeIdentifierName(namespace.namespace, element.$.name);
|
|
783
|
-
if (options.verbose) {
|
|
784
|
-
log.debug(` >> GirRecord: Parsing definition ${element.$.name} (${name})...`);
|
|
785
|
-
}
|
|
786
|
-
const clazz = new IntrospectedRecord({ name, namespace });
|
|
787
|
-
clazz.setPrivate(element.$.name.startsWith("_") ||
|
|
788
|
-
("disguised" in element.$ && element.$.disguised === "1") ||
|
|
789
|
-
("opaque" in element.$ && element.$.opaque === "1"));
|
|
790
|
-
if (typeof element.$["glib:is-gtype-struct-for"] === "string" && !!element.$["glib:is-gtype-struct-for"]) {
|
|
791
|
-
const structFor = parseTypeIdentifier(namespace.namespace, element.$["glib:is-gtype-struct-for"]);
|
|
792
|
-
// This let's replace these references when generating.
|
|
793
|
-
clazz._structFor = new ClassStructTypeIdentifier(structFor.name, structFor.namespace);
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
if (element.$["glib:type-name"]) {
|
|
797
|
-
clazz.resolve_names.push(element.$["glib:type-name"]);
|
|
798
|
-
namespace.registerResolveName(element.$["glib:type-name"], namespace.namespace, name);
|
|
799
|
-
}
|
|
800
|
-
if (element.$["c:type"]) {
|
|
801
|
-
clazz.resolve_names.push(element.$["c:type"]);
|
|
802
|
-
namespace.registerResolveName(element.$["c:type"], namespace.namespace, name);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
if (options.loadDocs) {
|
|
806
|
-
clazz.doc = parseDoc(element);
|
|
807
|
-
clazz.metadata = parseMetadata(element);
|
|
808
|
-
}
|
|
809
|
-
try {
|
|
810
|
-
// Instance Methods
|
|
811
|
-
if (element.method) {
|
|
812
|
-
clazz.members.push(...element.method.map(method => IntrospectedClassFunction.fromXML(method, clazz, options)));
|
|
813
|
-
}
|
|
814
|
-
// Constructors
|
|
815
|
-
if (Array.isArray(element.constructor)) {
|
|
816
|
-
element.constructor.forEach(constructor => {
|
|
817
|
-
const c = IntrospectedConstructor.fromXML(constructor, clazz, options);
|
|
818
|
-
clazz.constructors.push(c);
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
// Static methods (functions)
|
|
822
|
-
if (element.function) {
|
|
823
|
-
clazz.members.push(...element.function.map(func => IntrospectedStaticClassFunction.fromXML(func, clazz, options)));
|
|
824
|
-
}
|
|
825
|
-
// Is this a foreign type? (don't allow construction if foreign)
|
|
826
|
-
clazz._isForeign = "foreign" in element.$ && element.$.foreign === "1";
|
|
827
|
-
// Fields (for "non-class" records)
|
|
828
|
-
if (element.field) {
|
|
829
|
-
clazz.fields.push(...element.field
|
|
830
|
-
.filter(field => !("callback" in field))
|
|
831
|
-
.map(field => IntrospectedField.fromXML(field, clazz)));
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
catch (e) {
|
|
835
|
-
log.error(`Failed to parse record: ${clazz.name}.`, e);
|
|
836
|
-
}
|
|
837
|
-
return clazz;
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Calculate if a type expression is "simple" without pointers
|
|
841
|
-
*/
|
|
842
|
-
isSimpleTypeWithoutPointers(typeContainer) {
|
|
843
|
-
if (!this.isSimpleType(typeContainer)) {
|
|
844
|
-
return false;
|
|
845
|
-
}
|
|
846
|
-
if (typeContainer.isPointer) {
|
|
847
|
-
return false;
|
|
848
|
-
}
|
|
849
|
-
// Primitive types can be directly allocated.
|
|
850
|
-
if (typeContainer instanceof NativeType) {
|
|
851
|
-
return true;
|
|
852
|
-
}
|
|
853
|
-
if (typeContainer instanceof ArrayType) {
|
|
854
|
-
if (typeContainer.type.equals(this.getType())) {
|
|
855
|
-
return true;
|
|
856
|
-
}
|
|
857
|
-
return this.isSimpleTypeWithoutPointers(typeContainer.type);
|
|
858
|
-
}
|
|
859
|
-
if (typeContainer instanceof TypeIdentifier) {
|
|
860
|
-
const type = typeContainer;
|
|
861
|
-
const child_ns = this.namespace.assertInstalledImport(type.namespace);
|
|
862
|
-
const alias = child_ns.getAlias(type.name);
|
|
863
|
-
if (alias) {
|
|
864
|
-
return this.isSimpleTypeWithoutPointers(alias.type);
|
|
865
|
-
}
|
|
866
|
-
const child = child_ns.getClass(type.name);
|
|
867
|
-
if (child === this) {
|
|
868
|
-
return false;
|
|
869
|
-
}
|
|
870
|
-
if (child instanceof IntrospectedRecord) {
|
|
871
|
-
return child.isSimpleWithoutPointers() !== null;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
return false;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Calculate if a type expression is "simple"
|
|
878
|
-
*/
|
|
879
|
-
isSimpleType(typeContainer) {
|
|
880
|
-
// Primitive types can be directly allocated.
|
|
881
|
-
if (typeContainer instanceof NativeType) {
|
|
882
|
-
return true;
|
|
883
|
-
}
|
|
884
|
-
if (typeContainer instanceof ArrayType) {
|
|
885
|
-
if (typeContainer.type.equals(this.getType())) {
|
|
886
|
-
return true;
|
|
887
|
-
}
|
|
888
|
-
return this.isSimpleType(typeContainer.type);
|
|
889
|
-
}
|
|
890
|
-
if (typeContainer instanceof TypeIdentifier) {
|
|
891
|
-
const type = typeContainer;
|
|
892
|
-
const child_ns = this.namespace.assertInstalledImport(type.namespace);
|
|
893
|
-
const alias = child_ns.getAlias(type.name);
|
|
894
|
-
if (alias) {
|
|
895
|
-
return this.isSimpleType(alias.type);
|
|
896
|
-
}
|
|
897
|
-
const child = child_ns.getClass(type.name);
|
|
898
|
-
if (child === this) {
|
|
899
|
-
return false;
|
|
900
|
-
}
|
|
901
|
-
if (child instanceof IntrospectedRecord) {
|
|
902
|
-
return child.isSimple();
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Check if a record is "simple" and can be constructed by GJS
|
|
909
|
-
*/
|
|
910
|
-
isSimple() {
|
|
911
|
-
// Records with no fields are not
|
|
912
|
-
// constructable.
|
|
913
|
-
if (this.fields.length === 0) {
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
// Because we may have to recursively check
|
|
917
|
-
// if types are instantiable we cache whether
|
|
918
|
-
// or not a given Record is simple.
|
|
919
|
-
if (this._isSimple !== null) {
|
|
920
|
-
return this._isSimple;
|
|
921
|
-
}
|
|
922
|
-
const isSimple = this.fields.every(f => this.isSimpleType(f.type));
|
|
923
|
-
this._isSimple = isSimple;
|
|
924
|
-
return isSimple;
|
|
925
|
-
}
|
|
926
|
-
isSimpleWithoutPointers() {
|
|
927
|
-
// Records which are "simple without pointers" is a subset of
|
|
928
|
-
// "simple" records.
|
|
929
|
-
if (!this.isSimple()) {
|
|
930
|
-
return null;
|
|
931
|
-
("not simple");
|
|
932
|
-
}
|
|
933
|
-
// Because we may have to recursively check
|
|
934
|
-
// if types are instantiable we cache whether
|
|
935
|
-
// or not a given Record is simple.
|
|
936
|
-
if (this._isSimpleWithoutPointers !== null) {
|
|
937
|
-
return this._isSimpleWithoutPointers;
|
|
938
|
-
}
|
|
939
|
-
const isSimpleWithoutPointers = this.fields.find(f => {
|
|
940
|
-
return !this.isSimpleTypeWithoutPointers(f.type);
|
|
941
|
-
});
|
|
942
|
-
if (!isSimpleWithoutPointers)
|
|
943
|
-
this._isSimpleWithoutPointers = "all fields good";
|
|
944
|
-
else
|
|
945
|
-
this._isSimpleWithoutPointers = null;
|
|
946
|
-
return this._isSimpleWithoutPointers;
|
|
947
|
-
}
|
|
948
|
-
asString(generator) {
|
|
949
|
-
return generator.generateRecord(this);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
export class GirComplexRecord extends IntrospectedRecord {
|
|
953
|
-
isSimple() {
|
|
954
|
-
return false;
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
export class IntrospectedInterface extends IntrospectedBaseClass {
|
|
958
|
-
noParent = false;
|
|
959
|
-
mainConstructor = null;
|
|
960
|
-
copy(options = {}) {
|
|
961
|
-
const { name, namespace, superType, noParent, members, constructors, props, fields, callbacks, mainConstructor, generics } = this;
|
|
962
|
-
const clazz = new IntrospectedInterface({ name, namespace });
|
|
963
|
-
clazz._copyBaseProperties(this);
|
|
964
|
-
clazz.noParent = noParent;
|
|
965
|
-
if (superType) {
|
|
966
|
-
clazz.superType = superType;
|
|
967
|
-
}
|
|
968
|
-
clazz.props = (options.props ?? props).map(p => p.copy({ parent: clazz }));
|
|
969
|
-
clazz.fields = (options.fields ?? fields).map(f => f.copy({ parent: clazz }));
|
|
970
|
-
clazz.callbacks = (options.callbacks ?? callbacks).map(c => c.copy({ parent: clazz }));
|
|
971
|
-
clazz.mainConstructor = mainConstructor?.copy({ parent: clazz }) ?? null;
|
|
972
|
-
clazz.constructors = (options.constructors ?? constructors).map(c => c.copy({ parent: clazz }));
|
|
973
|
-
clazz.members = (options.members ?? members).map(m => m.copy({ parent: clazz }));
|
|
974
|
-
clazz.generics = [...generics];
|
|
975
|
-
return clazz;
|
|
976
|
-
}
|
|
977
|
-
someParent(predicate) {
|
|
978
|
-
const resolution = this.resolveParents();
|
|
979
|
-
const parent = resolution.extends();
|
|
980
|
-
return !!parent && (predicate(parent.node) || parent.node.someParent(predicate));
|
|
981
|
-
}
|
|
982
|
-
findParent(predicate) {
|
|
983
|
-
const resolution = this.resolveParents();
|
|
984
|
-
const parent = resolution.extends();
|
|
985
|
-
if (parent) {
|
|
986
|
-
if (predicate(parent.node))
|
|
987
|
-
return parent.node;
|
|
988
|
-
const found = parent.node.findParent(predicate);
|
|
989
|
-
if (found)
|
|
990
|
-
return found;
|
|
991
|
-
}
|
|
992
|
-
return undefined;
|
|
993
|
-
}
|
|
994
|
-
findParentMap(predicate) {
|
|
995
|
-
const resolution = this.resolveParents();
|
|
996
|
-
const parent = resolution.extends();
|
|
997
|
-
if (parent) {
|
|
998
|
-
const result = predicate(parent.node);
|
|
999
|
-
if (result !== undefined)
|
|
1000
|
-
return result;
|
|
1001
|
-
return parent.node.findParentMap(predicate);
|
|
1002
|
-
}
|
|
1003
|
-
return undefined;
|
|
1004
|
-
}
|
|
1005
|
-
resolveParents() {
|
|
1006
|
-
const { namespace, superType } = this;
|
|
1007
|
-
return {
|
|
1008
|
-
*[Symbol.iterator]() {
|
|
1009
|
-
let current = this.extends();
|
|
1010
|
-
while (current !== undefined) {
|
|
1011
|
-
yield current;
|
|
1012
|
-
current = current.extends();
|
|
1013
|
-
}
|
|
1014
|
-
},
|
|
1015
|
-
extends() {
|
|
1016
|
-
if (!superType)
|
|
1017
|
-
return undefined;
|
|
1018
|
-
const resolved = resolveTypeIdentifier(namespace, superType);
|
|
1019
|
-
if (resolved && (resolved instanceof IntrospectedClass || resolved instanceof IntrospectedInterface))
|
|
1020
|
-
return resolved.resolveParents();
|
|
1021
|
-
return undefined;
|
|
1022
|
-
},
|
|
1023
|
-
node: this,
|
|
1024
|
-
identifier: this.getType()
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
accept(visitor) {
|
|
1028
|
-
const node = this.copy({
|
|
1029
|
-
constructors: this.constructors.map(c => c.accept(visitor)),
|
|
1030
|
-
members: this.members.map(m => m.accept(visitor)),
|
|
1031
|
-
props: this.props.map(p => p.accept(visitor)),
|
|
1032
|
-
fields: this.fields.map(f => f.accept(visitor)),
|
|
1033
|
-
callbacks: this.callbacks.map(c => c.accept(visitor))
|
|
1034
|
-
});
|
|
1035
|
-
return visitor.visitInterface?.(node) ?? node;
|
|
1036
|
-
}
|
|
1037
|
-
static fromXML(element, namespace, options) {
|
|
1038
|
-
const name = sanitizeIdentifierName(namespace.namespace, element.$.name);
|
|
1039
|
-
if (options.verbose) {
|
|
1040
|
-
log.debug(` >> GirInterface: Parsing definition ${element.$.name} (${name})...`);
|
|
1041
|
-
}
|
|
1042
|
-
const clazz = new IntrospectedInterface({ name, namespace });
|
|
1043
|
-
if (options.loadDocs) {
|
|
1044
|
-
clazz.doc = parseDoc(element);
|
|
1045
|
-
clazz.metadata = parseMetadata(element);
|
|
1046
|
-
}
|
|
1047
|
-
if (element.$["glib:type-name"]) {
|
|
1048
|
-
clazz.resolve_names.push(element.$["glib:type-name"]);
|
|
1049
|
-
namespace.registerResolveName(element.$["glib:type-name"], namespace.namespace, name);
|
|
1050
|
-
}
|
|
1051
|
-
if (element.$["glib:type-struct"]) {
|
|
1052
|
-
clazz.resolve_names.push();
|
|
1053
|
-
namespace.registerResolveName(element.$["glib:type-struct"], namespace.namespace, name);
|
|
1054
|
-
}
|
|
1055
|
-
if (element.$["c:type"]) {
|
|
1056
|
-
clazz.resolve_names.push(element.$["c:type"]);
|
|
1057
|
-
namespace.registerResolveName(element.$["c:type"], namespace.namespace, name);
|
|
1058
|
-
}
|
|
1059
|
-
try {
|
|
1060
|
-
// Setup the "parent" (prerequisite) for this interface.
|
|
1061
|
-
if (element.prerequisite && element.prerequisite[0]) {
|
|
1062
|
-
const [prerequisite] = element.prerequisite;
|
|
1063
|
-
if (prerequisite.$.name) {
|
|
1064
|
-
clazz.superType = parseTypeIdentifier(namespace.namespace, prerequisite.$.name);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
if (Array.isArray(element.constructor)) {
|
|
1068
|
-
for (const constructor of element.constructor) {
|
|
1069
|
-
clazz.constructors.push(IntrospectedConstructor.fromXML(constructor, clazz, options));
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
// Properties
|
|
1073
|
-
if (element.property) {
|
|
1074
|
-
clazz.props.push(...element.property
|
|
1075
|
-
.map(prop => IntrospectedProperty.fromXML(prop, clazz, options))
|
|
1076
|
-
.map(prop => {
|
|
1077
|
-
switch (options.propertyCase) {
|
|
1078
|
-
case "both":
|
|
1079
|
-
const camelCase = prop.toCamelCase();
|
|
1080
|
-
// Ensure we don't duplicate properties like 'show'
|
|
1081
|
-
if (prop.name !== camelCase.name) {
|
|
1082
|
-
return [prop, prop.toCamelCase()];
|
|
1083
|
-
}
|
|
1084
|
-
return [prop];
|
|
1085
|
-
case "camel":
|
|
1086
|
-
return [prop.toCamelCase()];
|
|
1087
|
-
case "underscore":
|
|
1088
|
-
return [prop];
|
|
1089
|
-
}
|
|
1090
|
-
})
|
|
1091
|
-
.flat(1));
|
|
1092
|
-
}
|
|
1093
|
-
// Instance Methods
|
|
1094
|
-
if (element.method) {
|
|
1095
|
-
for (const method of element.method) {
|
|
1096
|
-
const m = IntrospectedClassFunction.fromXML(method, clazz, options);
|
|
1097
|
-
clazz.members.push(m);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
// Virtual Methods
|
|
1101
|
-
if (element["virtual-method"]) {
|
|
1102
|
-
for (const method of element["virtual-method"]) {
|
|
1103
|
-
clazz.members.push(IntrospectedVirtualClassFunction.fromXML(method, clazz, options));
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
// Callback Types
|
|
1107
|
-
if (element.callback) {
|
|
1108
|
-
for (const callback of element.callback) {
|
|
1109
|
-
if (options.verbose) {
|
|
1110
|
-
log.debug(`Adding callback ${callback.$.name} for ${namespace.namespace}`);
|
|
1111
|
-
}
|
|
1112
|
-
clazz.callbacks.push(IntrospectedClassCallback.fromXML(callback, clazz, options));
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
// Static methods (functions)
|
|
1116
|
-
if (element.function) {
|
|
1117
|
-
for (const func of element.function) {
|
|
1118
|
-
clazz.members.push(IntrospectedStaticClassFunction.fromXML(func, clazz, options));
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
catch (e) {
|
|
1123
|
-
log.error(`Failed to parse interface: ${clazz.name}.`, e);
|
|
1124
|
-
}
|
|
1125
|
-
return clazz;
|
|
1126
|
-
}
|
|
1127
|
-
asString(generator) {
|
|
1128
|
-
return generator.generateInterface(this);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
//# sourceMappingURL=class.js.map
|