@gtkx/gir 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/index.d.ts +25 -12
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +21 -10
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/loader.d.ts +30 -0
  6. package/dist/internal/loader.d.ts.map +1 -0
  7. package/dist/internal/loader.js +109 -0
  8. package/dist/internal/loader.js.map +1 -0
  9. package/dist/internal/normalizer.d.ts +98 -15
  10. package/dist/internal/normalizer.d.ts.map +1 -1
  11. package/dist/internal/normalizer.js +381 -412
  12. package/dist/internal/normalizer.js.map +1 -1
  13. package/dist/internal/parser.d.ts +23 -31
  14. package/dist/internal/parser.d.ts.map +1 -1
  15. package/dist/internal/parser.js +228 -244
  16. package/dist/internal/parser.js.map +1 -1
  17. package/dist/internal/raw-types.d.ts +58 -109
  18. package/dist/internal/raw-types.d.ts.map +1 -1
  19. package/dist/internal/raw-types.js +0 -8
  20. package/dist/internal/raw-types.js.map +1 -1
  21. package/dist/intrinsics.d.ts.map +1 -1
  22. package/dist/intrinsics.js +7 -0
  23. package/dist/intrinsics.js.map +1 -1
  24. package/dist/model/alias.d.ts +21 -0
  25. package/dist/model/alias.d.ts.map +1 -0
  26. package/dist/model/alias.js +22 -0
  27. package/dist/model/alias.js.map +1 -0
  28. package/dist/model/callables.d.ts +102 -0
  29. package/dist/model/callables.d.ts.map +1 -0
  30. package/dist/model/callables.js +123 -0
  31. package/dist/model/callables.js.map +1 -0
  32. package/dist/model/callback.d.ts +22 -0
  33. package/dist/model/callback.d.ts.map +1 -0
  34. package/dist/model/callback.js +20 -0
  35. package/dist/model/callback.js.map +1 -0
  36. package/dist/model/class.d.ts +92 -0
  37. package/dist/model/class.d.ts.map +1 -0
  38. package/dist/model/class.js +171 -0
  39. package/dist/model/class.js.map +1 -0
  40. package/dist/model/constant.d.ts +21 -0
  41. package/dist/model/constant.d.ts.map +1 -0
  42. package/dist/model/constant.js +20 -0
  43. package/dist/model/constant.js.map +1 -0
  44. package/dist/model/enumeration.d.ts +41 -0
  45. package/dist/model/enumeration.d.ts.map +1 -0
  46. package/dist/model/enumeration.js +47 -0
  47. package/dist/model/enumeration.js.map +1 -0
  48. package/dist/model/field.d.ts +21 -0
  49. package/dist/model/field.d.ts.map +1 -0
  50. package/dist/model/field.js +20 -0
  51. package/dist/model/field.js.map +1 -0
  52. package/dist/model/interface.d.ts +44 -0
  53. package/dist/model/interface.d.ts.map +1 -0
  54. package/dist/model/interface.js +67 -0
  55. package/dist/model/interface.js.map +1 -0
  56. package/dist/model/namespace.d.ts +44 -0
  57. package/dist/model/namespace.d.ts.map +1 -0
  58. package/dist/model/namespace.js +36 -0
  59. package/dist/model/namespace.js.map +1 -0
  60. package/dist/model/parameter.d.ts +43 -0
  61. package/dist/model/parameter.d.ts.map +1 -0
  62. package/dist/model/parameter.js +54 -0
  63. package/dist/model/parameter.js.map +1 -0
  64. package/dist/model/property.d.ts +62 -0
  65. package/dist/model/property.d.ts.map +1 -0
  66. package/dist/model/property.js +69 -0
  67. package/dist/model/property.js.map +1 -0
  68. package/dist/model/record.d.ts +56 -0
  69. package/dist/model/record.d.ts.map +1 -0
  70. package/dist/model/record.js +70 -0
  71. package/dist/model/record.js.map +1 -0
  72. package/dist/model/repository-like.d.ts +19 -0
  73. package/dist/model/repository-like.d.ts.map +1 -0
  74. package/dist/model/repository-like.js +2 -0
  75. package/dist/model/repository-like.js.map +1 -0
  76. package/dist/model/signal.d.ts +22 -0
  77. package/dist/model/signal.d.ts.map +1 -0
  78. package/dist/model/signal.js +22 -0
  79. package/dist/model/signal.js.map +1 -0
  80. package/dist/model/type.d.ts +71 -0
  81. package/dist/model/type.d.ts.map +1 -0
  82. package/dist/model/type.js +112 -0
  83. package/dist/model/type.js.map +1 -0
  84. package/dist/repository.d.ts +92 -138
  85. package/dist/repository.d.ts.map +1 -1
  86. package/dist/repository.js +155 -219
  87. package/dist/repository.js.map +1 -1
  88. package/package.json +4 -3
  89. package/src/index.ts +25 -39
  90. package/src/internal/loader.ts +127 -0
  91. package/src/internal/normalizer.ts +451 -475
  92. package/src/internal/parser.ts +242 -284
  93. package/src/internal/raw-types.ts +65 -116
  94. package/src/intrinsics.ts +7 -0
  95. package/src/model/alias.ts +31 -0
  96. package/src/model/callables.ts +172 -0
  97. package/src/model/callback.ts +30 -0
  98. package/src/model/class.ts +215 -0
  99. package/src/model/constant.ts +29 -0
  100. package/src/model/enumeration.ts +64 -0
  101. package/src/model/field.ts +29 -0
  102. package/src/model/interface.ts +89 -0
  103. package/src/model/namespace.ts +60 -0
  104. package/src/model/parameter.ts +74 -0
  105. package/src/model/property.ts +97 -0
  106. package/src/model/record.ts +97 -0
  107. package/src/model/repository-like.ts +20 -0
  108. package/src/model/signal.ts +32 -0
  109. package/src/model/type.ts +143 -0
  110. package/src/repository.ts +197 -283
  111. package/dist/types.d.ts +0 -655
  112. package/dist/types.d.ts.map +0 -1
  113. package/dist/types.js +0 -879
  114. package/dist/types.js.map +0 -1
  115. package/src/types.ts +0 -1192
@@ -1,35 +1,15 @@
1
- /**
2
- * Normalizer that converts raw GIR types to normalized types.
3
- *
4
- * The key job is to qualify all type references with their namespace,
5
- * except for intrinsic types which remain unqualified.
6
- *
7
- * @internal
8
- */
9
-
10
1
  import { isIntrinsicType } from "../intrinsics.js";
11
- import {
12
- GirAlias,
13
- GirCallback,
14
- GirClass,
15
- GirConstant,
16
- GirConstructor,
17
- GirEnumeration,
18
- GirEnumerationMember,
19
- GirField,
20
- GirFunction,
21
- GirInterface,
22
- GirMethod,
23
- GirNamespace,
24
- GirParameter,
25
- GirProperty,
26
- GirRecord,
27
- GirSignal,
28
- GirType,
29
- parseDefaultValue,
30
- type QualifiedName,
31
- qualifiedName,
32
- } from "../types.js";
2
+ import { GirAlias } from "../model/alias.js";
3
+ import { GirConstructor, GirFunction, GirMethod } from "../model/callables.js";
4
+ import { GirCallback } from "../model/callback.js";
5
+ import { GirConstant } from "../model/constant.js";
6
+ import { GirEnumeration, GirEnumerationMember } from "../model/enumeration.js";
7
+ import { GirField } from "../model/field.js";
8
+ import { GirParameter } from "../model/parameter.js";
9
+ import { GirProperty, parseDefaultValue } from "../model/property.js";
10
+ import { GirRecord } from "../model/record.js";
11
+ import { GirSignal } from "../model/signal.js";
12
+ import { GirType } from "../model/type.js";
33
13
  import type {
34
14
  RawAlias,
35
15
  RawCallback,
@@ -49,503 +29,499 @@ import type {
49
29
  RawType,
50
30
  } from "./raw-types.js";
51
31
 
32
+ type TypeIndex = Map<string, Set<string>>;
33
+
52
34
  /**
53
- * Context for normalization - provides access to all loaded namespaces
54
- * for resolving cross-namespace references.
35
+ * Data produced for a class before the repository exists.
36
+ * Used to defer GirClass construction until the repo is available.
55
37
  */
56
- export type NormalizerContext = {
57
- /** All raw namespaces that have been loaded */
58
- rawNamespaces: Map<string, RawNamespace>;
38
+ export type GirClassData = {
39
+ name: string;
40
+ qualifiedName: string;
41
+ cType: string;
42
+ parent: string | null;
43
+ abstract: boolean;
44
+ glibTypeName?: string;
45
+ glibGetType?: string;
46
+ cSymbolPrefix?: string;
47
+ fundamental?: boolean;
48
+ refFunc?: string;
49
+ unrefFunc?: string;
50
+ implements: string[];
51
+ methods: GirMethod[];
52
+ constructors: GirConstructor[];
53
+ staticFunctions: GirFunction[];
54
+ properties: GirProperty[];
55
+ signals: GirSignal[];
56
+ doc?: string;
59
57
  };
60
58
 
61
59
  /**
62
- * Normalizes a raw namespace into a normalized namespace.
60
+ * Data produced for an interface before the repository exists.
63
61
  */
64
- export const normalizeNamespace = (raw: RawNamespace, ctx: NormalizerContext): GirNamespace => {
65
- const nsName = raw.name;
66
-
67
- const classes = new Map<string, GirClass>();
68
- const interfaces = new Map<string, GirInterface>();
69
- const records = new Map<string, GirRecord>();
70
- const enumerations = new Map<string, GirEnumeration>();
71
- const bitfields = new Map<string, GirEnumeration>();
72
- const callbacks = new Map<string, GirCallback>();
73
- const functions = new Map<string, GirFunction>();
74
- const constants = new Map<string, GirConstant>();
75
- const aliases = new Map<string, GirAlias>();
76
-
77
- for (const rawClass of raw.classes) {
78
- const normalized = normalizeClass(rawClass, nsName, ctx);
79
- classes.set(normalized.name, normalized);
80
- }
62
+ export type GirInterfaceData = {
63
+ name: string;
64
+ qualifiedName: string;
65
+ cType: string;
66
+ glibTypeName?: string;
67
+ prerequisites: string[];
68
+ methods: GirMethod[];
69
+ properties: GirProperty[];
70
+ signals: GirSignal[];
71
+ doc?: string;
72
+ };
81
73
 
82
- for (const rawInterface of raw.interfaces) {
83
- const normalized = normalizeInterface(rawInterface, nsName, ctx);
84
- interfaces.set(normalized.name, normalized);
85
- }
74
+ /**
75
+ * Intermediate namespace data produced by the normalizer.
76
+ *
77
+ * Classes and interfaces are stored as plain data because they need
78
+ * the repository reference at construction time (which doesn't exist yet).
79
+ * All other types are fully constructed model instances.
80
+ */
81
+ export type GirNamespaceIntermediate = {
82
+ name: string;
83
+ version: string;
84
+ sharedLibrary: string;
85
+ cPrefix: string;
86
+ classes: Map<string, GirClassData>;
87
+ interfaces: Map<string, GirInterfaceData>;
88
+ records: Map<string, GirRecord>;
89
+ enumerations: Map<string, GirEnumeration>;
90
+ bitfields: Map<string, GirEnumeration>;
91
+ callbacks: Map<string, GirCallback>;
92
+ functions: Map<string, GirFunction>;
93
+ constants: Map<string, GirConstant>;
94
+ aliases: Map<string, GirAlias>;
95
+ doc?: string;
96
+ };
86
97
 
87
- for (const rawRecord of raw.records) {
88
- const normalized = normalizeRecord(rawRecord, nsName, ctx);
89
- records.set(normalized.name, normalized);
98
+ /**
99
+ * Converts raw parsed GIR data into model instances with fully qualified
100
+ * type names.
101
+ *
102
+ * Uses indexed lookups for O(1) type name resolution and strict error
103
+ * handling (throws on unresolvable type references).
104
+ */
105
+ export class GirNormalizer {
106
+ private typeIndex: TypeIndex = new Map();
107
+
108
+ /**
109
+ * Normalizes all raw namespaces into intermediate namespace data.
110
+ *
111
+ * @param rawNamespaces - Raw namespaces keyed by name, in dependency order
112
+ * @returns Intermediate namespace data keyed by name, in the same order
113
+ */
114
+ normalize(rawNamespaces: Map<string, RawNamespace>): Map<string, GirNamespaceIntermediate> {
115
+ this.typeIndex = this.buildTypeIndex(rawNamespaces);
116
+
117
+ const result = new Map<string, GirNamespaceIntermediate>();
118
+ for (const [name, raw] of rawNamespaces) {
119
+ result.set(name, this.normalizeNamespace(raw));
120
+ }
121
+ return result;
90
122
  }
91
123
 
92
- for (const rawEnum of raw.enumerations) {
93
- const normalized = normalizeEnumeration(rawEnum, nsName);
94
- enumerations.set(normalized.name, normalized);
124
+ private buildTypeIndex(rawNamespaces: Map<string, RawNamespace>): TypeIndex {
125
+ const index: TypeIndex = new Map();
126
+ for (const [nsName, raw] of rawNamespaces) {
127
+ const names = new Set<string>();
128
+ for (const c of raw.classes) names.add(c.name);
129
+ for (const i of raw.interfaces) names.add(i.name);
130
+ for (const r of raw.records) names.add(r.name);
131
+ for (const e of raw.enumerations) names.add(e.name);
132
+ for (const b of raw.bitfields) names.add(b.name);
133
+ for (const cb of raw.callbacks) names.add(cb.name);
134
+ for (const a of raw.aliases) names.add(a.name);
135
+ index.set(nsName, names);
136
+ }
137
+ return index;
95
138
  }
96
139
 
97
- for (const rawBitfield of raw.bitfields) {
98
- const normalized = normalizeEnumeration(rawBitfield, nsName);
99
- bitfields.set(normalized.name, normalized);
100
- }
140
+ private normalizeNamespace(raw: RawNamespace): GirNamespaceIntermediate {
141
+ const nsName = raw.name;
101
142
 
102
- for (const rawCallback of raw.callbacks) {
103
- const normalized = normalizeCallback(rawCallback, nsName, ctx);
104
- callbacks.set(normalized.name, normalized);
105
- }
143
+ const classes = new Map<string, GirClassData>();
144
+ for (const rawClass of raw.classes) {
145
+ const data = this.normalizeClass(rawClass, nsName);
146
+ classes.set(data.name, data);
147
+ }
106
148
 
107
- for (const rawFunction of raw.functions) {
108
- const normalized = normalizeFunction(rawFunction, nsName, ctx);
109
- functions.set(normalized.name, normalized);
110
- }
149
+ const interfaces = new Map<string, GirInterfaceData>();
150
+ for (const rawIface of raw.interfaces) {
151
+ const data = this.normalizeInterface(rawIface, nsName);
152
+ interfaces.set(data.name, data);
153
+ }
111
154
 
112
- for (const rawConstant of raw.constants) {
113
- const normalized = normalizeConstant(rawConstant, nsName, ctx);
114
- constants.set(normalized.name, normalized);
115
- }
155
+ const records = new Map<string, GirRecord>();
156
+ for (const rawRecord of raw.records) {
157
+ const record = this.normalizeRecord(rawRecord, nsName);
158
+ records.set(record.name, record);
159
+ }
116
160
 
117
- for (const rawAlias of raw.aliases) {
118
- const normalized = normalizeAlias(rawAlias, nsName, ctx);
119
- aliases.set(normalized.name, normalized);
120
- }
161
+ const enumerations = new Map<string, GirEnumeration>();
162
+ for (const rawEnum of raw.enumerations) {
163
+ const enumeration = this.normalizeEnumeration(rawEnum, nsName);
164
+ enumerations.set(enumeration.name, enumeration);
165
+ }
121
166
 
122
- return new GirNamespace({
123
- name: raw.name,
124
- version: raw.version,
125
- sharedLibrary: raw.sharedLibrary,
126
- cPrefix: raw.cPrefix,
127
- classes,
128
- interfaces,
129
- records,
130
- enumerations,
131
- bitfields,
132
- callbacks,
133
- functions,
134
- constants,
135
- aliases,
136
- doc: raw.doc,
137
- });
138
- };
167
+ const bitfields = new Map<string, GirEnumeration>();
168
+ for (const rawBitfield of raw.bitfields) {
169
+ const bitfield = this.normalizeEnumeration(rawBitfield, nsName);
170
+ bitfields.set(bitfield.name, bitfield);
171
+ }
139
172
 
140
- /**
141
- * Normalizes a type reference, qualifying it with its namespace if not intrinsic.
142
- */
143
- const normalizeTypeName = (
144
- typeName: string,
145
- currentNamespace: string,
146
- ctx: NormalizerContext,
147
- ): QualifiedName | string => {
148
- if (isIntrinsicType(typeName)) {
149
- return typeName;
150
- }
173
+ const callbacks = new Map<string, GirCallback>();
174
+ for (const rawCb of raw.callbacks) {
175
+ const cb = this.normalizeCallback(rawCb, nsName);
176
+ callbacks.set(cb.name, cb);
177
+ }
151
178
 
152
- if (typeName.includes(".")) {
153
- return typeName as QualifiedName;
154
- }
179
+ const functions = new Map<string, GirFunction>();
180
+ for (const rawFunc of raw.functions) {
181
+ const func = this.normalizeFunction(rawFunc, nsName);
182
+ functions.set(func.name, func);
183
+ }
155
184
 
156
- const currentNs = ctx.rawNamespaces.get(currentNamespace);
157
- if (currentNs && typeExistsInNamespace(typeName, currentNs)) {
158
- return qualifiedName(currentNamespace, typeName);
159
- }
185
+ const constants = new Map<string, GirConstant>();
186
+ for (const rawConst of raw.constants) {
187
+ const constant = this.normalizeConstant(rawConst, nsName);
188
+ constants.set(constant.name, constant);
189
+ }
160
190
 
161
- for (const [nsName, ns] of ctx.rawNamespaces) {
162
- if (nsName !== currentNamespace && typeExistsInNamespace(typeName, ns)) {
163
- return qualifiedName(nsName, typeName);
191
+ const aliases = new Map<string, GirAlias>();
192
+ for (const rawAlias of raw.aliases) {
193
+ const alias = this.normalizeAlias(rawAlias, nsName);
194
+ aliases.set(alias.name, alias);
164
195
  }
196
+
197
+ return {
198
+ name: raw.name,
199
+ version: raw.version,
200
+ sharedLibrary: raw.sharedLibrary,
201
+ cPrefix: raw.cPrefix,
202
+ classes,
203
+ interfaces,
204
+ records,
205
+ enumerations,
206
+ bitfields,
207
+ callbacks,
208
+ functions,
209
+ constants,
210
+ aliases,
211
+ doc: raw.doc,
212
+ };
165
213
  }
166
214
 
167
- return qualifiedName(currentNamespace, typeName);
168
- };
215
+ private qualifyTypeName(typeName: string, currentNamespace: string): string {
216
+ if (isIntrinsicType(typeName)) return typeName;
217
+ if (typeName.includes(".")) return typeName;
169
218
 
170
- /**
171
- * Checks if a type name exists in a namespace.
172
- */
173
- const typeExistsInNamespace = (typeName: string, ns: RawNamespace): boolean => {
174
- return (
175
- ns.classes.some((c) => c.name === typeName) ||
176
- ns.interfaces.some((i) => i.name === typeName) ||
177
- ns.records.some((r) => r.name === typeName) ||
178
- ns.enumerations.some((e) => e.name === typeName) ||
179
- ns.bitfields.some((b) => b.name === typeName) ||
180
- ns.callbacks.some((c) => c.name === typeName) ||
181
- ns.aliases.some((a) => a.name === typeName)
182
- );
183
- };
219
+ if (this.typeIndex.get(currentNamespace)?.has(typeName)) {
220
+ return `${currentNamespace}.${typeName}`;
221
+ }
184
222
 
185
- const buildContainerTypeBase = (raw: RawType) => ({
186
- cType: raw.cType,
187
- containerType: raw.containerType,
188
- transferOwnership: raw.transferOwnership,
189
- nullable: raw.nullable ?? false,
190
- });
223
+ for (const [nsName, names] of this.typeIndex) {
224
+ if (nsName !== currentNamespace && names.has(typeName)) {
225
+ return `${nsName}.${typeName}`;
226
+ }
227
+ }
191
228
 
192
- /**
193
- * Normalizes a raw type to a normalized type.
194
- */
195
- const normalizeType = (raw: RawType, currentNamespace: string, ctx: NormalizerContext): GirType => {
196
- if (raw.containerType === "ghashtable") {
197
- const typeParams = (raw.typeParameters ?? []).map((tp) => normalizeType(tp, currentNamespace, ctx));
198
- return new GirType({
199
- ...buildContainerTypeBase(raw),
200
- name: qualifiedName("GLib", "HashTable"),
201
- isArray: false,
202
- elementType: typeParams[1] ?? null,
203
- typeParameters: typeParams,
204
- });
229
+ return `${currentNamespace}.${typeName}`;
205
230
  }
206
231
 
207
- if (raw.containerType === "gptrarray" || raw.containerType === "garray") {
208
- const typeParams = (raw.typeParameters ?? []).map((tp) => normalizeType(tp, currentNamespace, ctx));
209
- const typeName = raw.containerType === "gptrarray" ? "PtrArray" : "Array";
210
- return new GirType({
211
- ...buildContainerTypeBase(raw),
212
- name: qualifiedName("GLib", typeName),
213
- isArray: true,
214
- elementType: typeParams[0] ?? null,
215
- typeParameters: typeParams,
216
- });
217
- }
232
+ private normalizeType(raw: RawType, currentNamespace: string): GirType {
233
+ if (raw.containerType === "ghashtable") {
234
+ const typeParams = (raw.typeParameters ?? []).map((tp) => this.normalizeType(tp, currentNamespace));
235
+ return new GirType({
236
+ name: `GLib.HashTable`,
237
+ cType: raw.cType,
238
+ containerType: raw.containerType,
239
+ transferOwnership: raw.transferOwnership,
240
+ nullable: raw.nullable ?? false,
241
+ isArray: false,
242
+ elementType: typeParams[1] ?? null,
243
+ typeParameters: typeParams,
244
+ });
245
+ }
218
246
 
219
- if (raw.containerType === "glist" || raw.containerType === "gslist") {
220
- const elementType = raw.elementType ? normalizeType(raw.elementType, currentNamespace, ctx) : null;
221
- return new GirType({
222
- ...buildContainerTypeBase(raw),
223
- name: "array",
224
- isArray: true,
225
- elementType,
226
- typeParameters: elementType ? [elementType] : [],
227
- });
228
- }
247
+ if (raw.containerType === "gptrarray" || raw.containerType === "garray") {
248
+ const typeParams = (raw.typeParameters ?? []).map((tp) => this.normalizeType(tp, currentNamespace));
249
+ const typeName = raw.containerType === "gptrarray" ? "PtrArray" : "Array";
250
+ return new GirType({
251
+ name: `GLib.${typeName}`,
252
+ cType: raw.cType,
253
+ containerType: raw.containerType,
254
+ transferOwnership: raw.transferOwnership,
255
+ nullable: raw.nullable ?? false,
256
+ isArray: true,
257
+ elementType: typeParams[0] ?? null,
258
+ typeParameters: typeParams,
259
+ });
260
+ }
229
261
 
230
- const isArray = raw.isArray === true || raw.name === "array";
262
+ if (raw.containerType === "gbytearray") {
263
+ const elementType = raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null;
264
+ return new GirType({
265
+ name: `GLib.ByteArray`,
266
+ cType: raw.cType,
267
+ containerType: raw.containerType,
268
+ transferOwnership: raw.transferOwnership,
269
+ nullable: raw.nullable ?? false,
270
+ isArray: true,
271
+ elementType,
272
+ });
273
+ }
231
274
 
232
- if (isArray && raw.elementType) {
233
- return new GirType({
234
- name: "array",
235
- cType: raw.cType,
236
- isArray: true,
237
- elementType: normalizeType(raw.elementType, currentNamespace, ctx),
238
- transferOwnership: raw.transferOwnership,
239
- nullable: raw.nullable ?? false,
240
- sizeParamIndex: raw.sizeParamIndex,
241
- zeroTerminated: raw.zeroTerminated,
242
- fixedSize: raw.fixedSize,
243
- });
244
- }
275
+ if (raw.containerType === "glist" || raw.containerType === "gslist") {
276
+ const elementType = raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null;
277
+ return new GirType({
278
+ name: "array",
279
+ cType: raw.cType,
280
+ containerType: raw.containerType,
281
+ transferOwnership: raw.transferOwnership,
282
+ nullable: raw.nullable ?? false,
283
+ isArray: true,
284
+ elementType,
285
+ typeParameters: elementType ? [elementType] : [],
286
+ });
287
+ }
288
+
289
+ const isArray = raw.isArray === true || raw.name === "array";
290
+
291
+ if (isArray) {
292
+ return new GirType({
293
+ name: "array",
294
+ cType: raw.cType,
295
+ isArray: true,
296
+ elementType: raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null,
297
+ transferOwnership: raw.transferOwnership,
298
+ nullable: raw.nullable ?? false,
299
+ sizeParamIndex: raw.sizeParamIndex,
300
+ zeroTerminated: raw.zeroTerminated,
301
+ fixedSize: raw.fixedSize,
302
+ });
303
+ }
245
304
 
246
- if (isArray) {
247
305
  return new GirType({
248
- name: "array",
306
+ name: this.qualifyTypeName(raw.name, currentNamespace),
249
307
  cType: raw.cType,
250
- isArray: true,
308
+ isArray: false,
251
309
  elementType: null,
252
310
  transferOwnership: raw.transferOwnership,
253
311
  nullable: raw.nullable ?? false,
254
- sizeParamIndex: raw.sizeParamIndex,
255
- zeroTerminated: raw.zeroTerminated,
256
- fixedSize: raw.fixedSize,
257
312
  });
258
313
  }
259
314
 
260
- return new GirType({
261
- name: normalizeTypeName(raw.name, currentNamespace, ctx),
262
- cType: raw.cType,
263
- isArray: false,
264
- elementType: null,
265
- transferOwnership: raw.transferOwnership,
266
- nullable: raw.nullable ?? false,
267
- });
268
- };
269
-
270
- /**
271
- * Normalizes a raw class to a normalized class.
272
- */
273
- const normalizeClass = (raw: RawClass, currentNamespace: string, ctx: NormalizerContext): GirClass => {
274
- const qn = qualifiedName(currentNamespace, raw.name);
275
-
276
- let parent: QualifiedName | null = null;
277
- if (raw.parent) {
278
- const normalizedParent = normalizeTypeName(raw.parent, currentNamespace, ctx);
279
- if (typeof normalizedParent !== "string" || normalizedParent.includes(".")) {
280
- parent = normalizedParent as QualifiedName;
315
+ private normalizeClass(raw: RawClass, currentNamespace: string): GirClassData {
316
+ let parent: string | null = null;
317
+ if (raw.parent) {
318
+ const qualified = this.qualifyTypeName(raw.parent, currentNamespace);
319
+ if (qualified.includes(".")) {
320
+ parent = qualified;
321
+ }
281
322
  }
282
- }
283
323
 
284
- const implementsRefs = raw.implements.map((impl) => {
285
- const normalized = normalizeTypeName(impl, currentNamespace, ctx);
286
- return normalized as QualifiedName;
287
- });
288
-
289
- return new GirClass({
290
- name: raw.name,
291
- qualifiedName: qn,
292
- cType: raw.cType,
293
- parent,
294
- abstract: raw.abstract ?? false,
295
- glibTypeName: raw.glibTypeName,
296
- glibGetType: raw.glibGetType,
297
- cSymbolPrefix: raw.cSymbolPrefix,
298
- fundamental: raw.fundamental ?? false,
299
- refFunc: raw.refFunc,
300
- unrefFunc: raw.unrefFunc,
301
- implements: implementsRefs,
302
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
303
- constructors: raw.constructors.map((c) => normalizeConstructor(c, currentNamespace, ctx)),
304
- staticFunctions: raw.functions.map((f) => normalizeFunction(f, currentNamespace, ctx)),
305
- properties: raw.properties.map((p) => normalizeProperty(p, currentNamespace, ctx)),
306
- signals: raw.signals.map((s) => normalizeSignal(s, currentNamespace, ctx)),
307
- doc: raw.doc,
308
- });
309
- };
324
+ return {
325
+ name: raw.name,
326
+ qualifiedName: `${currentNamespace}.${raw.name}`,
327
+ cType: raw.cType,
328
+ parent,
329
+ abstract: raw.abstract ?? false,
330
+ glibTypeName: raw.glibTypeName,
331
+ glibGetType: raw.glibGetType,
332
+ cSymbolPrefix: raw.cSymbolPrefix,
333
+ fundamental: raw.fundamental ?? false,
334
+ refFunc: raw.refFunc,
335
+ unrefFunc: raw.unrefFunc,
336
+ implements: raw.implements.map((impl) => this.qualifyTypeName(impl, currentNamespace)),
337
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
338
+ constructors: raw.constructors.map((c) => this.normalizeConstructor(c, currentNamespace)),
339
+ staticFunctions: raw.functions.map((f) => this.normalizeFunction(f, currentNamespace)),
340
+ properties: raw.properties.map((p) => this.normalizeProperty(p, currentNamespace)),
341
+ signals: raw.signals.map((s) => this.normalizeSignal(s, currentNamespace)),
342
+ doc: raw.doc,
343
+ };
344
+ }
310
345
 
311
- /**
312
- * Normalizes a raw interface to a normalized interface.
313
- */
314
- const normalizeInterface = (raw: RawInterface, currentNamespace: string, ctx: NormalizerContext): GirInterface => {
315
- const qn = qualifiedName(currentNamespace, raw.name);
316
-
317
- const prerequisites = raw.prerequisites.map((prereq) => {
318
- const normalized = normalizeTypeName(prereq, currentNamespace, ctx);
319
- return normalized as QualifiedName;
320
- });
321
-
322
- return new GirInterface({
323
- name: raw.name,
324
- qualifiedName: qn,
325
- cType: raw.cType,
326
- glibTypeName: raw.glibTypeName,
327
- prerequisites,
328
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
329
- properties: raw.properties.map((p) => normalizeProperty(p, currentNamespace, ctx)),
330
- signals: raw.signals.map((s) => normalizeSignal(s, currentNamespace, ctx)),
331
- doc: raw.doc,
332
- });
333
- };
346
+ private normalizeInterface(raw: RawInterface, currentNamespace: string): GirInterfaceData {
347
+ return {
348
+ name: raw.name,
349
+ qualifiedName: `${currentNamespace}.${raw.name}`,
350
+ cType: raw.cType,
351
+ glibTypeName: raw.glibTypeName,
352
+ prerequisites: raw.prerequisites.map((prereq) => this.qualifyTypeName(prereq, currentNamespace)),
353
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
354
+ properties: raw.properties.map((p) => this.normalizeProperty(p, currentNamespace)),
355
+ signals: raw.signals.map((s) => this.normalizeSignal(s, currentNamespace)),
356
+ doc: raw.doc,
357
+ };
358
+ }
334
359
 
335
- /**
336
- * Normalizes a raw record to a normalized record.
337
- */
338
- const normalizeRecord = (raw: RawRecord, currentNamespace: string, ctx: NormalizerContext): GirRecord => {
339
- const qn = qualifiedName(currentNamespace, raw.name);
340
-
341
- return new GirRecord({
342
- name: raw.name,
343
- qualifiedName: qn,
344
- cType: raw.cType,
345
- opaque: raw.opaque ?? false,
346
- disguised: raw.disguised ?? false,
347
- glibTypeName: raw.glibTypeName,
348
- glibGetType: raw.glibGetType,
349
- isGtypeStructFor: raw.isGtypeStructFor,
350
- copyFunction: raw.copyFunction,
351
- freeFunction: raw.freeFunction,
352
- fields: raw.fields.map((f) => normalizeField(f, currentNamespace, ctx)),
353
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
354
- constructors: raw.constructors.map((c) => normalizeConstructor(c, currentNamespace, ctx)),
355
- staticFunctions: raw.functions.map((f) => normalizeFunction(f, currentNamespace, ctx)),
356
- doc: raw.doc,
357
- });
358
- };
360
+ private normalizeRecord(raw: RawRecord, currentNamespace: string): GirRecord {
361
+ return new GirRecord({
362
+ name: raw.name,
363
+ qualifiedName: `${currentNamespace}.${raw.name}`,
364
+ cType: raw.cType,
365
+ opaque: raw.opaque ?? false,
366
+ disguised: raw.disguised ?? false,
367
+ glibTypeName: raw.glibTypeName,
368
+ glibGetType: raw.glibGetType,
369
+ isGtypeStructFor: raw.isGtypeStructFor,
370
+ copyFunction: raw.copyFunction,
371
+ freeFunction: raw.freeFunction,
372
+ fields: raw.fields.map((f) => this.normalizeField(f, currentNamespace)),
373
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
374
+ constructors: raw.constructors.map((c) => this.normalizeConstructor(c, currentNamespace)),
375
+ staticFunctions: raw.functions.map((f) => this.normalizeFunction(f, currentNamespace)),
376
+ doc: raw.doc,
377
+ });
378
+ }
359
379
 
360
- /**
361
- * Normalizes a raw enumeration to a normalized enumeration.
362
- */
363
- const normalizeEnumeration = (raw: RawEnumeration, currentNamespace: string): GirEnumeration => {
364
- const qn = qualifiedName(currentNamespace, raw.name);
365
-
366
- return new GirEnumeration({
367
- name: raw.name,
368
- qualifiedName: qn,
369
- cType: raw.cType,
370
- members: raw.members.map(
371
- (m) =>
372
- new GirEnumerationMember({
373
- name: m.name,
374
- value: m.value,
375
- cIdentifier: m.cIdentifier,
376
- doc: m.doc,
377
- }),
378
- ),
379
- glibGetType: raw.glibGetType,
380
- doc: raw.doc,
381
- });
382
- };
380
+ private normalizeEnumeration(raw: RawEnumeration, currentNamespace: string): GirEnumeration {
381
+ return new GirEnumeration({
382
+ name: raw.name,
383
+ qualifiedName: `${currentNamespace}.${raw.name}`,
384
+ cType: raw.cType,
385
+ members: raw.members.map(
386
+ (m) =>
387
+ new GirEnumerationMember({
388
+ name: m.name,
389
+ value: m.value,
390
+ cIdentifier: m.cIdentifier,
391
+ doc: m.doc,
392
+ }),
393
+ ),
394
+ glibGetType: raw.glibGetType,
395
+ doc: raw.doc,
396
+ });
397
+ }
383
398
 
384
- /**
385
- * Normalizes a raw callback to a normalized callback.
386
- */
387
- const normalizeCallback = (raw: RawCallback, currentNamespace: string, ctx: NormalizerContext): GirCallback => {
388
- const qn = qualifiedName(currentNamespace, raw.name);
389
-
390
- return new GirCallback({
391
- name: raw.name,
392
- qualifiedName: qn,
393
- cType: raw.cType,
394
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
395
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
396
- doc: raw.doc,
397
- });
398
- };
399
+ private normalizeCallback(raw: RawCallback, currentNamespace: string): GirCallback {
400
+ return new GirCallback({
401
+ name: raw.name,
402
+ qualifiedName: `${currentNamespace}.${raw.name}`,
403
+ cType: raw.cType,
404
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
405
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
406
+ doc: raw.doc,
407
+ });
408
+ }
399
409
 
400
- /**
401
- * Normalizes a raw constant to a normalized constant.
402
- */
403
- const normalizeConstant = (raw: RawConstant, currentNamespace: string, ctx: NormalizerContext): GirConstant => {
404
- const qn = qualifiedName(currentNamespace, raw.name);
405
-
406
- return new GirConstant({
407
- name: raw.name,
408
- qualifiedName: qn,
409
- cType: raw.cType,
410
- value: raw.value,
411
- type: normalizeType(raw.type, currentNamespace, ctx),
412
- doc: raw.doc,
413
- });
414
- };
410
+ private normalizeConstant(raw: RawConstant, currentNamespace: string): GirConstant {
411
+ return new GirConstant({
412
+ name: raw.name,
413
+ qualifiedName: `${currentNamespace}.${raw.name}`,
414
+ cType: raw.cType,
415
+ value: raw.value,
416
+ type: this.normalizeType(raw.type, currentNamespace),
417
+ doc: raw.doc,
418
+ });
419
+ }
415
420
 
416
- /**
417
- * Normalizes a raw alias to a normalized alias.
418
- */
419
- const normalizeAlias = (raw: RawAlias, currentNamespace: string, ctx: NormalizerContext): GirAlias => {
420
- const qn = qualifiedName(currentNamespace, raw.name);
421
-
422
- return new GirAlias({
423
- name: raw.name,
424
- qualifiedName: qn,
425
- cType: raw.cType,
426
- targetType: normalizeType(raw.targetType, currentNamespace, ctx),
427
- doc: raw.doc,
428
- });
429
- };
421
+ private normalizeAlias(raw: RawAlias, currentNamespace: string): GirAlias {
422
+ return new GirAlias({
423
+ name: raw.name,
424
+ qualifiedName: `${currentNamespace}.${raw.name}`,
425
+ cType: raw.cType,
426
+ targetType: this.normalizeType(raw.targetType, currentNamespace),
427
+ doc: raw.doc,
428
+ });
429
+ }
430
430
 
431
- /**
432
- * Normalizes a raw method to a normalized method.
433
- */
434
- const normalizeMethod = (raw: RawMethod, currentNamespace: string, ctx: NormalizerContext): GirMethod => {
435
- return new GirMethod({
436
- name: raw.name,
437
- cIdentifier: raw.cIdentifier,
438
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
439
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
440
- instanceParameter: raw.instanceParameter
441
- ? normalizeParameter(raw.instanceParameter, currentNamespace, ctx)
442
- : undefined,
443
- throws: raw.throws ?? false,
444
- doc: raw.doc,
445
- returnDoc: raw.returnDoc,
446
- finishFunc: raw.finishFunc,
447
- shadows: raw.shadows,
448
- shadowedBy: raw.shadowedBy,
449
- });
450
- };
431
+ private normalizeMethod(raw: RawMethod, currentNamespace: string): GirMethod {
432
+ return new GirMethod({
433
+ name: raw.name,
434
+ cIdentifier: raw.cIdentifier,
435
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
436
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
437
+ instanceParameter: raw.instanceParameter
438
+ ? this.normalizeParameter(raw.instanceParameter, currentNamespace)
439
+ : undefined,
440
+ throws: raw.throws ?? false,
441
+ doc: raw.doc,
442
+ returnDoc: raw.returnDoc,
443
+ finishFunc: raw.finishFunc,
444
+ shadows: raw.shadows,
445
+ shadowedBy: raw.shadowedBy,
446
+ });
447
+ }
451
448
 
452
- /**
453
- * Normalizes a raw constructor to a normalized constructor.
454
- */
455
- const normalizeConstructor = (
456
- raw: RawConstructor,
457
- currentNamespace: string,
458
- ctx: NormalizerContext,
459
- ): GirConstructor => {
460
- return new GirConstructor({
461
- name: raw.name,
462
- cIdentifier: raw.cIdentifier,
463
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
464
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
465
- throws: raw.throws ?? false,
466
- doc: raw.doc,
467
- returnDoc: raw.returnDoc,
468
- shadows: raw.shadows,
469
- shadowedBy: raw.shadowedBy,
470
- });
471
- };
449
+ private normalizeConstructor(raw: RawConstructor, currentNamespace: string): GirConstructor {
450
+ return new GirConstructor({
451
+ name: raw.name,
452
+ cIdentifier: raw.cIdentifier,
453
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
454
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
455
+ throws: raw.throws ?? false,
456
+ doc: raw.doc,
457
+ returnDoc: raw.returnDoc,
458
+ shadows: raw.shadows,
459
+ shadowedBy: raw.shadowedBy,
460
+ });
461
+ }
472
462
 
473
- /**
474
- * Normalizes a raw function to a normalized function.
475
- */
476
- const normalizeFunction = (raw: RawFunction, currentNamespace: string, ctx: NormalizerContext): GirFunction => {
477
- return new GirFunction({
478
- name: raw.name,
479
- cIdentifier: raw.cIdentifier,
480
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
481
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
482
- throws: raw.throws ?? false,
483
- doc: raw.doc,
484
- returnDoc: raw.returnDoc,
485
- shadows: raw.shadows,
486
- shadowedBy: raw.shadowedBy,
487
- });
488
- };
463
+ private normalizeFunction(raw: RawFunction, currentNamespace: string): GirFunction {
464
+ return new GirFunction({
465
+ name: raw.name,
466
+ cIdentifier: raw.cIdentifier,
467
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
468
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
469
+ throws: raw.throws ?? false,
470
+ doc: raw.doc,
471
+ returnDoc: raw.returnDoc,
472
+ shadows: raw.shadows,
473
+ shadowedBy: raw.shadowedBy,
474
+ });
475
+ }
489
476
 
490
- /**
491
- * Normalizes a raw parameter to a normalized parameter.
492
- */
493
- const normalizeParameter = (raw: RawParameter, currentNamespace: string, ctx: NormalizerContext): GirParameter => {
494
- return new GirParameter({
495
- name: raw.name,
496
- type: normalizeType(raw.type, currentNamespace, ctx),
497
- direction: raw.direction ?? "in",
498
- callerAllocates: raw.callerAllocates ?? false,
499
- nullable: raw.nullable ?? false,
500
- optional: raw.optional ?? false,
501
- scope: raw.scope,
502
- closure: raw.closure,
503
- destroy: raw.destroy,
504
- transferOwnership: raw.transferOwnership,
505
- doc: raw.doc,
506
- });
507
- };
477
+ private normalizeParameter(raw: RawParameter, currentNamespace: string): GirParameter {
478
+ return new GirParameter({
479
+ name: raw.name,
480
+ type: this.normalizeType(raw.type, currentNamespace),
481
+ direction: raw.direction ?? "in",
482
+ callerAllocates: raw.callerAllocates ?? false,
483
+ nullable: raw.nullable ?? false,
484
+ optional: raw.optional ?? false,
485
+ scope: raw.scope,
486
+ closure: raw.closure,
487
+ destroy: raw.destroy,
488
+ transferOwnership: raw.transferOwnership,
489
+ doc: raw.doc,
490
+ });
491
+ }
508
492
 
509
- /**
510
- * Normalizes a raw property to a normalized property.
511
- */
512
- const normalizeProperty = (raw: RawProperty, currentNamespace: string, ctx: NormalizerContext): GirProperty => {
513
- return new GirProperty({
514
- name: raw.name,
515
- type: normalizeType(raw.type, currentNamespace, ctx),
516
- readable: raw.readable ?? true,
517
- writable: raw.writable ?? false,
518
- constructOnly: raw.constructOnly ?? false,
519
- defaultValue: parseDefaultValue(raw.defaultValueRaw),
520
- getter: raw.getter,
521
- setter: raw.setter,
522
- doc: raw.doc,
523
- });
524
- };
493
+ private normalizeProperty(raw: RawProperty, currentNamespace: string): GirProperty {
494
+ return new GirProperty({
495
+ name: raw.name,
496
+ type: this.normalizeType(raw.type, currentNamespace),
497
+ readable: raw.readable ?? true,
498
+ writable: raw.writable ?? false,
499
+ constructOnly: raw.constructOnly ?? false,
500
+ defaultValue: parseDefaultValue(raw.defaultValueRaw),
501
+ getter: raw.getter,
502
+ setter: raw.setter,
503
+ doc: raw.doc,
504
+ });
505
+ }
525
506
 
526
- /**
527
- * Normalizes a raw signal to a normalized signal.
528
- */
529
- const normalizeSignal = (raw: RawSignal, currentNamespace: string, ctx: NormalizerContext): GirSignal => {
530
- return new GirSignal({
531
- name: raw.name,
532
- when: raw.when ?? "last",
533
- returnType: raw.returnType ? normalizeType(raw.returnType, currentNamespace, ctx) : null,
534
- parameters: (raw.parameters ?? []).map((p) => normalizeParameter(p, currentNamespace, ctx)),
535
- doc: raw.doc,
536
- });
537
- };
507
+ private normalizeSignal(raw: RawSignal, currentNamespace: string): GirSignal {
508
+ return new GirSignal({
509
+ name: raw.name,
510
+ when: raw.when ?? "last",
511
+ returnType: raw.returnType ? this.normalizeType(raw.returnType, currentNamespace) : null,
512
+ parameters: (raw.parameters ?? []).map((p) => this.normalizeParameter(p, currentNamespace)),
513
+ doc: raw.doc,
514
+ });
515
+ }
538
516
 
539
- /**
540
- * Normalizes a raw field to a normalized field.
541
- */
542
- const normalizeField = (raw: RawField, currentNamespace: string, ctx: NormalizerContext): GirField => {
543
- return new GirField({
544
- name: raw.name,
545
- type: normalizeType(raw.type, currentNamespace, ctx),
546
- writable: raw.writable ?? false,
547
- readable: raw.readable ?? true,
548
- private: raw.private ?? false,
549
- doc: raw.doc,
550
- });
551
- };
517
+ private normalizeField(raw: RawField, currentNamespace: string): GirField {
518
+ return new GirField({
519
+ name: raw.name,
520
+ type: this.normalizeType(raw.type, currentNamespace),
521
+ writable: raw.writable ?? false,
522
+ readable: raw.readable ?? true,
523
+ private: raw.private ?? false,
524
+ doc: raw.doc,
525
+ });
526
+ }
527
+ }