@gtkx/gir 0.20.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 +2 -2
  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,440 +1,409 @@
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
1
  import { isIntrinsicType } from "../intrinsics.js";
10
- import { GirAlias, GirCallback, GirClass, GirConstant, GirConstructor, GirEnumeration, GirEnumerationMember, GirField, GirFunction, GirInterface, GirMethod, GirNamespace, GirParameter, GirProperty, GirRecord, GirSignal, GirType, parseDefaultValue, qualifiedName, } 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";
11
13
  /**
12
- * Normalizes a raw namespace into a normalized namespace.
14
+ * Converts raw parsed GIR data into model instances with fully qualified
15
+ * type names.
16
+ *
17
+ * Uses indexed lookups for O(1) type name resolution and strict error
18
+ * handling (throws on unresolvable type references).
13
19
  */
14
- export const normalizeNamespace = (raw, ctx) => {
15
- const nsName = raw.name;
16
- const classes = new Map();
17
- const interfaces = new Map();
18
- const records = new Map();
19
- const enumerations = new Map();
20
- const bitfields = new Map();
21
- const callbacks = new Map();
22
- const functions = new Map();
23
- const constants = new Map();
24
- const aliases = new Map();
25
- for (const rawClass of raw.classes) {
26
- const normalized = normalizeClass(rawClass, nsName, ctx);
27
- classes.set(normalized.name, normalized);
28
- }
29
- for (const rawInterface of raw.interfaces) {
30
- const normalized = normalizeInterface(rawInterface, nsName, ctx);
31
- interfaces.set(normalized.name, normalized);
20
+ export class GirNormalizer {
21
+ typeIndex = new Map();
22
+ /**
23
+ * Normalizes all raw namespaces into intermediate namespace data.
24
+ *
25
+ * @param rawNamespaces - Raw namespaces keyed by name, in dependency order
26
+ * @returns Intermediate namespace data keyed by name, in the same order
27
+ */
28
+ normalize(rawNamespaces) {
29
+ this.typeIndex = this.buildTypeIndex(rawNamespaces);
30
+ const result = new Map();
31
+ for (const [name, raw] of rawNamespaces) {
32
+ result.set(name, this.normalizeNamespace(raw));
33
+ }
34
+ return result;
32
35
  }
33
- for (const rawRecord of raw.records) {
34
- const normalized = normalizeRecord(rawRecord, nsName, ctx);
35
- records.set(normalized.name, normalized);
36
+ buildTypeIndex(rawNamespaces) {
37
+ const index = new Map();
38
+ for (const [nsName, raw] of rawNamespaces) {
39
+ const names = new Set();
40
+ for (const c of raw.classes)
41
+ names.add(c.name);
42
+ for (const i of raw.interfaces)
43
+ names.add(i.name);
44
+ for (const r of raw.records)
45
+ names.add(r.name);
46
+ for (const e of raw.enumerations)
47
+ names.add(e.name);
48
+ for (const b of raw.bitfields)
49
+ names.add(b.name);
50
+ for (const cb of raw.callbacks)
51
+ names.add(cb.name);
52
+ for (const a of raw.aliases)
53
+ names.add(a.name);
54
+ index.set(nsName, names);
55
+ }
56
+ return index;
36
57
  }
37
- for (const rawEnum of raw.enumerations) {
38
- const normalized = normalizeEnumeration(rawEnum, nsName);
39
- enumerations.set(normalized.name, normalized);
58
+ normalizeNamespace(raw) {
59
+ const nsName = raw.name;
60
+ const classes = new Map();
61
+ for (const rawClass of raw.classes) {
62
+ const data = this.normalizeClass(rawClass, nsName);
63
+ classes.set(data.name, data);
64
+ }
65
+ const interfaces = new Map();
66
+ for (const rawIface of raw.interfaces) {
67
+ const data = this.normalizeInterface(rawIface, nsName);
68
+ interfaces.set(data.name, data);
69
+ }
70
+ const records = new Map();
71
+ for (const rawRecord of raw.records) {
72
+ const record = this.normalizeRecord(rawRecord, nsName);
73
+ records.set(record.name, record);
74
+ }
75
+ const enumerations = new Map();
76
+ for (const rawEnum of raw.enumerations) {
77
+ const enumeration = this.normalizeEnumeration(rawEnum, nsName);
78
+ enumerations.set(enumeration.name, enumeration);
79
+ }
80
+ const bitfields = new Map();
81
+ for (const rawBitfield of raw.bitfields) {
82
+ const bitfield = this.normalizeEnumeration(rawBitfield, nsName);
83
+ bitfields.set(bitfield.name, bitfield);
84
+ }
85
+ const callbacks = new Map();
86
+ for (const rawCb of raw.callbacks) {
87
+ const cb = this.normalizeCallback(rawCb, nsName);
88
+ callbacks.set(cb.name, cb);
89
+ }
90
+ const functions = new Map();
91
+ for (const rawFunc of raw.functions) {
92
+ const func = this.normalizeFunction(rawFunc, nsName);
93
+ functions.set(func.name, func);
94
+ }
95
+ const constants = new Map();
96
+ for (const rawConst of raw.constants) {
97
+ const constant = this.normalizeConstant(rawConst, nsName);
98
+ constants.set(constant.name, constant);
99
+ }
100
+ const aliases = new Map();
101
+ for (const rawAlias of raw.aliases) {
102
+ const alias = this.normalizeAlias(rawAlias, nsName);
103
+ aliases.set(alias.name, alias);
104
+ }
105
+ return {
106
+ name: raw.name,
107
+ version: raw.version,
108
+ sharedLibrary: raw.sharedLibrary,
109
+ cPrefix: raw.cPrefix,
110
+ classes,
111
+ interfaces,
112
+ records,
113
+ enumerations,
114
+ bitfields,
115
+ callbacks,
116
+ functions,
117
+ constants,
118
+ aliases,
119
+ doc: raw.doc,
120
+ };
40
121
  }
41
- for (const rawBitfield of raw.bitfields) {
42
- const normalized = normalizeEnumeration(rawBitfield, nsName);
43
- bitfields.set(normalized.name, normalized);
122
+ qualifyTypeName(typeName, currentNamespace) {
123
+ if (isIntrinsicType(typeName))
124
+ return typeName;
125
+ if (typeName.includes("."))
126
+ return typeName;
127
+ if (this.typeIndex.get(currentNamespace)?.has(typeName)) {
128
+ return `${currentNamespace}.${typeName}`;
129
+ }
130
+ for (const [nsName, names] of this.typeIndex) {
131
+ if (nsName !== currentNamespace && names.has(typeName)) {
132
+ return `${nsName}.${typeName}`;
133
+ }
134
+ }
135
+ return `${currentNamespace}.${typeName}`;
44
136
  }
45
- for (const rawCallback of raw.callbacks) {
46
- const normalized = normalizeCallback(rawCallback, nsName, ctx);
47
- callbacks.set(normalized.name, normalized);
137
+ normalizeType(raw, currentNamespace) {
138
+ if (raw.containerType === "ghashtable") {
139
+ const typeParams = (raw.typeParameters ?? []).map((tp) => this.normalizeType(tp, currentNamespace));
140
+ return new GirType({
141
+ name: `GLib.HashTable`,
142
+ cType: raw.cType,
143
+ containerType: raw.containerType,
144
+ transferOwnership: raw.transferOwnership,
145
+ nullable: raw.nullable ?? false,
146
+ isArray: false,
147
+ elementType: typeParams[1] ?? null,
148
+ typeParameters: typeParams,
149
+ });
150
+ }
151
+ if (raw.containerType === "gptrarray" || raw.containerType === "garray") {
152
+ const typeParams = (raw.typeParameters ?? []).map((tp) => this.normalizeType(tp, currentNamespace));
153
+ const typeName = raw.containerType === "gptrarray" ? "PtrArray" : "Array";
154
+ return new GirType({
155
+ name: `GLib.${typeName}`,
156
+ cType: raw.cType,
157
+ containerType: raw.containerType,
158
+ transferOwnership: raw.transferOwnership,
159
+ nullable: raw.nullable ?? false,
160
+ isArray: true,
161
+ elementType: typeParams[0] ?? null,
162
+ typeParameters: typeParams,
163
+ });
164
+ }
165
+ if (raw.containerType === "gbytearray") {
166
+ const elementType = raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null;
167
+ return new GirType({
168
+ name: `GLib.ByteArray`,
169
+ cType: raw.cType,
170
+ containerType: raw.containerType,
171
+ transferOwnership: raw.transferOwnership,
172
+ nullable: raw.nullable ?? false,
173
+ isArray: true,
174
+ elementType,
175
+ });
176
+ }
177
+ if (raw.containerType === "glist" || raw.containerType === "gslist") {
178
+ const elementType = raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null;
179
+ return new GirType({
180
+ name: "array",
181
+ cType: raw.cType,
182
+ containerType: raw.containerType,
183
+ transferOwnership: raw.transferOwnership,
184
+ nullable: raw.nullable ?? false,
185
+ isArray: true,
186
+ elementType,
187
+ typeParameters: elementType ? [elementType] : [],
188
+ });
189
+ }
190
+ const isArray = raw.isArray === true || raw.name === "array";
191
+ if (isArray) {
192
+ return new GirType({
193
+ name: "array",
194
+ cType: raw.cType,
195
+ isArray: true,
196
+ elementType: raw.elementType ? this.normalizeType(raw.elementType, currentNamespace) : null,
197
+ transferOwnership: raw.transferOwnership,
198
+ nullable: raw.nullable ?? false,
199
+ sizeParamIndex: raw.sizeParamIndex,
200
+ zeroTerminated: raw.zeroTerminated,
201
+ fixedSize: raw.fixedSize,
202
+ });
203
+ }
204
+ return new GirType({
205
+ name: this.qualifyTypeName(raw.name, currentNamespace),
206
+ cType: raw.cType,
207
+ isArray: false,
208
+ elementType: null,
209
+ transferOwnership: raw.transferOwnership,
210
+ nullable: raw.nullable ?? false,
211
+ });
48
212
  }
49
- for (const rawFunction of raw.functions) {
50
- const normalized = normalizeFunction(rawFunction, nsName, ctx);
51
- functions.set(normalized.name, normalized);
213
+ normalizeClass(raw, currentNamespace) {
214
+ let parent = null;
215
+ if (raw.parent) {
216
+ const qualified = this.qualifyTypeName(raw.parent, currentNamespace);
217
+ if (qualified.includes(".")) {
218
+ parent = qualified;
219
+ }
220
+ }
221
+ return {
222
+ name: raw.name,
223
+ qualifiedName: `${currentNamespace}.${raw.name}`,
224
+ cType: raw.cType,
225
+ parent,
226
+ abstract: raw.abstract ?? false,
227
+ glibTypeName: raw.glibTypeName,
228
+ glibGetType: raw.glibGetType,
229
+ cSymbolPrefix: raw.cSymbolPrefix,
230
+ fundamental: raw.fundamental ?? false,
231
+ refFunc: raw.refFunc,
232
+ unrefFunc: raw.unrefFunc,
233
+ implements: raw.implements.map((impl) => this.qualifyTypeName(impl, currentNamespace)),
234
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
235
+ constructors: raw.constructors.map((c) => this.normalizeConstructor(c, currentNamespace)),
236
+ staticFunctions: raw.functions.map((f) => this.normalizeFunction(f, currentNamespace)),
237
+ properties: raw.properties.map((p) => this.normalizeProperty(p, currentNamespace)),
238
+ signals: raw.signals.map((s) => this.normalizeSignal(s, currentNamespace)),
239
+ doc: raw.doc,
240
+ };
52
241
  }
53
- for (const rawConstant of raw.constants) {
54
- const normalized = normalizeConstant(rawConstant, nsName, ctx);
55
- constants.set(normalized.name, normalized);
242
+ normalizeInterface(raw, currentNamespace) {
243
+ return {
244
+ name: raw.name,
245
+ qualifiedName: `${currentNamespace}.${raw.name}`,
246
+ cType: raw.cType,
247
+ glibTypeName: raw.glibTypeName,
248
+ prerequisites: raw.prerequisites.map((prereq) => this.qualifyTypeName(prereq, currentNamespace)),
249
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
250
+ properties: raw.properties.map((p) => this.normalizeProperty(p, currentNamespace)),
251
+ signals: raw.signals.map((s) => this.normalizeSignal(s, currentNamespace)),
252
+ doc: raw.doc,
253
+ };
56
254
  }
57
- for (const rawAlias of raw.aliases) {
58
- const normalized = normalizeAlias(rawAlias, nsName, ctx);
59
- aliases.set(normalized.name, normalized);
255
+ normalizeRecord(raw, currentNamespace) {
256
+ return new GirRecord({
257
+ name: raw.name,
258
+ qualifiedName: `${currentNamespace}.${raw.name}`,
259
+ cType: raw.cType,
260
+ opaque: raw.opaque ?? false,
261
+ disguised: raw.disguised ?? false,
262
+ glibTypeName: raw.glibTypeName,
263
+ glibGetType: raw.glibGetType,
264
+ isGtypeStructFor: raw.isGtypeStructFor,
265
+ copyFunction: raw.copyFunction,
266
+ freeFunction: raw.freeFunction,
267
+ fields: raw.fields.map((f) => this.normalizeField(f, currentNamespace)),
268
+ methods: raw.methods.map((m) => this.normalizeMethod(m, currentNamespace)),
269
+ constructors: raw.constructors.map((c) => this.normalizeConstructor(c, currentNamespace)),
270
+ staticFunctions: raw.functions.map((f) => this.normalizeFunction(f, currentNamespace)),
271
+ doc: raw.doc,
272
+ });
60
273
  }
61
- return new GirNamespace({
62
- name: raw.name,
63
- version: raw.version,
64
- sharedLibrary: raw.sharedLibrary,
65
- cPrefix: raw.cPrefix,
66
- classes,
67
- interfaces,
68
- records,
69
- enumerations,
70
- bitfields,
71
- callbacks,
72
- functions,
73
- constants,
74
- aliases,
75
- doc: raw.doc,
76
- });
77
- };
78
- /**
79
- * Normalizes a type reference, qualifying it with its namespace if not intrinsic.
80
- */
81
- const normalizeTypeName = (typeName, currentNamespace, ctx) => {
82
- if (isIntrinsicType(typeName)) {
83
- return typeName;
274
+ normalizeEnumeration(raw, currentNamespace) {
275
+ return new GirEnumeration({
276
+ name: raw.name,
277
+ qualifiedName: `${currentNamespace}.${raw.name}`,
278
+ cType: raw.cType,
279
+ members: raw.members.map((m) => new GirEnumerationMember({
280
+ name: m.name,
281
+ value: m.value,
282
+ cIdentifier: m.cIdentifier,
283
+ doc: m.doc,
284
+ })),
285
+ glibGetType: raw.glibGetType,
286
+ doc: raw.doc,
287
+ });
84
288
  }
85
- if (typeName.includes(".")) {
86
- return typeName;
289
+ normalizeCallback(raw, currentNamespace) {
290
+ return new GirCallback({
291
+ name: raw.name,
292
+ qualifiedName: `${currentNamespace}.${raw.name}`,
293
+ cType: raw.cType,
294
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
295
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
296
+ doc: raw.doc,
297
+ });
87
298
  }
88
- const currentNs = ctx.rawNamespaces.get(currentNamespace);
89
- if (currentNs && typeExistsInNamespace(typeName, currentNs)) {
90
- return qualifiedName(currentNamespace, typeName);
299
+ normalizeConstant(raw, currentNamespace) {
300
+ return new GirConstant({
301
+ name: raw.name,
302
+ qualifiedName: `${currentNamespace}.${raw.name}`,
303
+ cType: raw.cType,
304
+ value: raw.value,
305
+ type: this.normalizeType(raw.type, currentNamespace),
306
+ doc: raw.doc,
307
+ });
91
308
  }
92
- for (const [nsName, ns] of ctx.rawNamespaces) {
93
- if (nsName !== currentNamespace && typeExistsInNamespace(typeName, ns)) {
94
- return qualifiedName(nsName, typeName);
95
- }
309
+ normalizeAlias(raw, currentNamespace) {
310
+ return new GirAlias({
311
+ name: raw.name,
312
+ qualifiedName: `${currentNamespace}.${raw.name}`,
313
+ cType: raw.cType,
314
+ targetType: this.normalizeType(raw.targetType, currentNamespace),
315
+ doc: raw.doc,
316
+ });
96
317
  }
97
- return qualifiedName(currentNamespace, typeName);
98
- };
99
- /**
100
- * Checks if a type name exists in a namespace.
101
- */
102
- const typeExistsInNamespace = (typeName, ns) => {
103
- return (ns.classes.some((c) => c.name === typeName) ||
104
- ns.interfaces.some((i) => i.name === typeName) ||
105
- ns.records.some((r) => r.name === typeName) ||
106
- ns.enumerations.some((e) => e.name === typeName) ||
107
- ns.bitfields.some((b) => b.name === typeName) ||
108
- ns.callbacks.some((c) => c.name === typeName) ||
109
- ns.aliases.some((a) => a.name === typeName));
110
- };
111
- const buildContainerTypeBase = (raw) => ({
112
- cType: raw.cType,
113
- containerType: raw.containerType,
114
- transferOwnership: raw.transferOwnership,
115
- nullable: raw.nullable ?? false,
116
- });
117
- /**
118
- * Normalizes a raw type to a normalized type.
119
- */
120
- const normalizeType = (raw, currentNamespace, ctx) => {
121
- if (raw.containerType === "ghashtable") {
122
- const typeParams = (raw.typeParameters ?? []).map((tp) => normalizeType(tp, currentNamespace, ctx));
123
- return new GirType({
124
- ...buildContainerTypeBase(raw),
125
- name: qualifiedName("GLib", "HashTable"),
126
- isArray: false,
127
- elementType: typeParams[1] ?? null,
128
- typeParameters: typeParams,
318
+ normalizeMethod(raw, currentNamespace) {
319
+ return new GirMethod({
320
+ name: raw.name,
321
+ cIdentifier: raw.cIdentifier,
322
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
323
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
324
+ instanceParameter: raw.instanceParameter
325
+ ? this.normalizeParameter(raw.instanceParameter, currentNamespace)
326
+ : undefined,
327
+ throws: raw.throws ?? false,
328
+ doc: raw.doc,
329
+ returnDoc: raw.returnDoc,
330
+ finishFunc: raw.finishFunc,
331
+ shadows: raw.shadows,
332
+ shadowedBy: raw.shadowedBy,
129
333
  });
130
334
  }
131
- if (raw.containerType === "gptrarray" || raw.containerType === "garray") {
132
- const typeParams = (raw.typeParameters ?? []).map((tp) => normalizeType(tp, currentNamespace, ctx));
133
- const typeName = raw.containerType === "gptrarray" ? "PtrArray" : "Array";
134
- return new GirType({
135
- ...buildContainerTypeBase(raw),
136
- name: qualifiedName("GLib", typeName),
137
- isArray: true,
138
- elementType: typeParams[0] ?? null,
139
- typeParameters: typeParams,
335
+ normalizeConstructor(raw, currentNamespace) {
336
+ return new GirConstructor({
337
+ name: raw.name,
338
+ cIdentifier: raw.cIdentifier,
339
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
340
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
341
+ throws: raw.throws ?? false,
342
+ doc: raw.doc,
343
+ returnDoc: raw.returnDoc,
344
+ shadows: raw.shadows,
345
+ shadowedBy: raw.shadowedBy,
140
346
  });
141
347
  }
142
- if (raw.containerType === "glist" || raw.containerType === "gslist") {
143
- const elementType = raw.elementType ? normalizeType(raw.elementType, currentNamespace, ctx) : null;
144
- return new GirType({
145
- ...buildContainerTypeBase(raw),
146
- name: "array",
147
- isArray: true,
148
- elementType,
149
- typeParameters: elementType ? [elementType] : [],
348
+ normalizeFunction(raw, currentNamespace) {
349
+ return new GirFunction({
350
+ name: raw.name,
351
+ cIdentifier: raw.cIdentifier,
352
+ returnType: this.normalizeType(raw.returnType, currentNamespace),
353
+ parameters: raw.parameters.map((p) => this.normalizeParameter(p, currentNamespace)),
354
+ throws: raw.throws ?? false,
355
+ doc: raw.doc,
356
+ returnDoc: raw.returnDoc,
357
+ shadows: raw.shadows,
358
+ shadowedBy: raw.shadowedBy,
150
359
  });
151
360
  }
152
- const isArray = raw.isArray === true || raw.name === "array";
153
- if (isArray && raw.elementType) {
154
- return new GirType({
155
- name: "array",
156
- cType: raw.cType,
157
- isArray: true,
158
- elementType: normalizeType(raw.elementType, currentNamespace, ctx),
159
- transferOwnership: raw.transferOwnership,
361
+ normalizeParameter(raw, currentNamespace) {
362
+ return new GirParameter({
363
+ name: raw.name,
364
+ type: this.normalizeType(raw.type, currentNamespace),
365
+ direction: raw.direction ?? "in",
366
+ callerAllocates: raw.callerAllocates ?? false,
160
367
  nullable: raw.nullable ?? false,
161
- sizeParamIndex: raw.sizeParamIndex,
162
- zeroTerminated: raw.zeroTerminated,
163
- fixedSize: raw.fixedSize,
368
+ optional: raw.optional ?? false,
369
+ scope: raw.scope,
370
+ closure: raw.closure,
371
+ destroy: raw.destroy,
372
+ transferOwnership: raw.transferOwnership,
373
+ doc: raw.doc,
164
374
  });
165
375
  }
166
- if (isArray) {
167
- return new GirType({
168
- name: "array",
169
- cType: raw.cType,
170
- isArray: true,
171
- elementType: null,
172
- transferOwnership: raw.transferOwnership,
173
- nullable: raw.nullable ?? false,
174
- sizeParamIndex: raw.sizeParamIndex,
175
- zeroTerminated: raw.zeroTerminated,
176
- fixedSize: raw.fixedSize,
376
+ normalizeProperty(raw, currentNamespace) {
377
+ return new GirProperty({
378
+ name: raw.name,
379
+ type: this.normalizeType(raw.type, currentNamespace),
380
+ readable: raw.readable ?? true,
381
+ writable: raw.writable ?? false,
382
+ constructOnly: raw.constructOnly ?? false,
383
+ defaultValue: parseDefaultValue(raw.defaultValueRaw),
384
+ getter: raw.getter,
385
+ setter: raw.setter,
386
+ doc: raw.doc,
177
387
  });
178
388
  }
179
- return new GirType({
180
- name: normalizeTypeName(raw.name, currentNamespace, ctx),
181
- cType: raw.cType,
182
- isArray: false,
183
- elementType: null,
184
- transferOwnership: raw.transferOwnership,
185
- nullable: raw.nullable ?? false,
186
- });
187
- };
188
- /**
189
- * Normalizes a raw class to a normalized class.
190
- */
191
- const normalizeClass = (raw, currentNamespace, ctx) => {
192
- const qn = qualifiedName(currentNamespace, raw.name);
193
- let parent = null;
194
- if (raw.parent) {
195
- const normalizedParent = normalizeTypeName(raw.parent, currentNamespace, ctx);
196
- if (typeof normalizedParent !== "string" || normalizedParent.includes(".")) {
197
- parent = normalizedParent;
198
- }
389
+ normalizeSignal(raw, currentNamespace) {
390
+ return new GirSignal({
391
+ name: raw.name,
392
+ when: raw.when ?? "last",
393
+ returnType: raw.returnType ? this.normalizeType(raw.returnType, currentNamespace) : null,
394
+ parameters: (raw.parameters ?? []).map((p) => this.normalizeParameter(p, currentNamespace)),
395
+ doc: raw.doc,
396
+ });
199
397
  }
200
- const implementsRefs = raw.implements.map((impl) => {
201
- const normalized = normalizeTypeName(impl, currentNamespace, ctx);
202
- return normalized;
203
- });
204
- return new GirClass({
205
- name: raw.name,
206
- qualifiedName: qn,
207
- cType: raw.cType,
208
- parent,
209
- abstract: raw.abstract ?? false,
210
- glibTypeName: raw.glibTypeName,
211
- glibGetType: raw.glibGetType,
212
- cSymbolPrefix: raw.cSymbolPrefix,
213
- fundamental: raw.fundamental ?? false,
214
- refFunc: raw.refFunc,
215
- unrefFunc: raw.unrefFunc,
216
- implements: implementsRefs,
217
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
218
- constructors: raw.constructors.map((c) => normalizeConstructor(c, currentNamespace, ctx)),
219
- staticFunctions: raw.functions.map((f) => normalizeFunction(f, currentNamespace, ctx)),
220
- properties: raw.properties.map((p) => normalizeProperty(p, currentNamespace, ctx)),
221
- signals: raw.signals.map((s) => normalizeSignal(s, currentNamespace, ctx)),
222
- doc: raw.doc,
223
- });
224
- };
225
- /**
226
- * Normalizes a raw interface to a normalized interface.
227
- */
228
- const normalizeInterface = (raw, currentNamespace, ctx) => {
229
- const qn = qualifiedName(currentNamespace, raw.name);
230
- const prerequisites = raw.prerequisites.map((prereq) => {
231
- const normalized = normalizeTypeName(prereq, currentNamespace, ctx);
232
- return normalized;
233
- });
234
- return new GirInterface({
235
- name: raw.name,
236
- qualifiedName: qn,
237
- cType: raw.cType,
238
- glibTypeName: raw.glibTypeName,
239
- prerequisites,
240
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
241
- properties: raw.properties.map((p) => normalizeProperty(p, currentNamespace, ctx)),
242
- signals: raw.signals.map((s) => normalizeSignal(s, currentNamespace, ctx)),
243
- doc: raw.doc,
244
- });
245
- };
246
- /**
247
- * Normalizes a raw record to a normalized record.
248
- */
249
- const normalizeRecord = (raw, currentNamespace, ctx) => {
250
- const qn = qualifiedName(currentNamespace, raw.name);
251
- return new GirRecord({
252
- name: raw.name,
253
- qualifiedName: qn,
254
- cType: raw.cType,
255
- opaque: raw.opaque ?? false,
256
- disguised: raw.disguised ?? false,
257
- glibTypeName: raw.glibTypeName,
258
- glibGetType: raw.glibGetType,
259
- isGtypeStructFor: raw.isGtypeStructFor,
260
- copyFunction: raw.copyFunction,
261
- freeFunction: raw.freeFunction,
262
- fields: raw.fields.map((f) => normalizeField(f, currentNamespace, ctx)),
263
- methods: raw.methods.map((m) => normalizeMethod(m, currentNamespace, ctx)),
264
- constructors: raw.constructors.map((c) => normalizeConstructor(c, currentNamespace, ctx)),
265
- staticFunctions: raw.functions.map((f) => normalizeFunction(f, currentNamespace, ctx)),
266
- doc: raw.doc,
267
- });
268
- };
269
- /**
270
- * Normalizes a raw enumeration to a normalized enumeration.
271
- */
272
- const normalizeEnumeration = (raw, currentNamespace) => {
273
- const qn = qualifiedName(currentNamespace, raw.name);
274
- return new GirEnumeration({
275
- name: raw.name,
276
- qualifiedName: qn,
277
- cType: raw.cType,
278
- members: raw.members.map((m) => new GirEnumerationMember({
279
- name: m.name,
280
- value: m.value,
281
- cIdentifier: m.cIdentifier,
282
- doc: m.doc,
283
- })),
284
- glibGetType: raw.glibGetType,
285
- doc: raw.doc,
286
- });
287
- };
288
- /**
289
- * Normalizes a raw callback to a normalized callback.
290
- */
291
- const normalizeCallback = (raw, currentNamespace, ctx) => {
292
- const qn = qualifiedName(currentNamespace, raw.name);
293
- return new GirCallback({
294
- name: raw.name,
295
- qualifiedName: qn,
296
- cType: raw.cType,
297
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
298
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
299
- doc: raw.doc,
300
- });
301
- };
302
- /**
303
- * Normalizes a raw constant to a normalized constant.
304
- */
305
- const normalizeConstant = (raw, currentNamespace, ctx) => {
306
- const qn = qualifiedName(currentNamespace, raw.name);
307
- return new GirConstant({
308
- name: raw.name,
309
- qualifiedName: qn,
310
- cType: raw.cType,
311
- value: raw.value,
312
- type: normalizeType(raw.type, currentNamespace, ctx),
313
- doc: raw.doc,
314
- });
315
- };
316
- /**
317
- * Normalizes a raw alias to a normalized alias.
318
- */
319
- const normalizeAlias = (raw, currentNamespace, ctx) => {
320
- const qn = qualifiedName(currentNamespace, raw.name);
321
- return new GirAlias({
322
- name: raw.name,
323
- qualifiedName: qn,
324
- cType: raw.cType,
325
- targetType: normalizeType(raw.targetType, currentNamespace, ctx),
326
- doc: raw.doc,
327
- });
328
- };
329
- /**
330
- * Normalizes a raw method to a normalized method.
331
- */
332
- const normalizeMethod = (raw, currentNamespace, ctx) => {
333
- return new GirMethod({
334
- name: raw.name,
335
- cIdentifier: raw.cIdentifier,
336
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
337
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
338
- instanceParameter: raw.instanceParameter
339
- ? normalizeParameter(raw.instanceParameter, currentNamespace, ctx)
340
- : undefined,
341
- throws: raw.throws ?? false,
342
- doc: raw.doc,
343
- returnDoc: raw.returnDoc,
344
- finishFunc: raw.finishFunc,
345
- shadows: raw.shadows,
346
- shadowedBy: raw.shadowedBy,
347
- });
348
- };
349
- /**
350
- * Normalizes a raw constructor to a normalized constructor.
351
- */
352
- const normalizeConstructor = (raw, currentNamespace, ctx) => {
353
- return new GirConstructor({
354
- name: raw.name,
355
- cIdentifier: raw.cIdentifier,
356
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
357
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
358
- throws: raw.throws ?? false,
359
- doc: raw.doc,
360
- returnDoc: raw.returnDoc,
361
- shadows: raw.shadows,
362
- shadowedBy: raw.shadowedBy,
363
- });
364
- };
365
- /**
366
- * Normalizes a raw function to a normalized function.
367
- */
368
- const normalizeFunction = (raw, currentNamespace, ctx) => {
369
- return new GirFunction({
370
- name: raw.name,
371
- cIdentifier: raw.cIdentifier,
372
- returnType: normalizeType(raw.returnType, currentNamespace, ctx),
373
- parameters: raw.parameters.map((p) => normalizeParameter(p, currentNamespace, ctx)),
374
- throws: raw.throws ?? false,
375
- doc: raw.doc,
376
- returnDoc: raw.returnDoc,
377
- shadows: raw.shadows,
378
- shadowedBy: raw.shadowedBy,
379
- });
380
- };
381
- /**
382
- * Normalizes a raw parameter to a normalized parameter.
383
- */
384
- const normalizeParameter = (raw, currentNamespace, ctx) => {
385
- return new GirParameter({
386
- name: raw.name,
387
- type: normalizeType(raw.type, currentNamespace, ctx),
388
- direction: raw.direction ?? "in",
389
- callerAllocates: raw.callerAllocates ?? false,
390
- nullable: raw.nullable ?? false,
391
- optional: raw.optional ?? false,
392
- scope: raw.scope,
393
- closure: raw.closure,
394
- destroy: raw.destroy,
395
- transferOwnership: raw.transferOwnership,
396
- doc: raw.doc,
397
- });
398
- };
399
- /**
400
- * Normalizes a raw property to a normalized property.
401
- */
402
- const normalizeProperty = (raw, currentNamespace, ctx) => {
403
- return new GirProperty({
404
- name: raw.name,
405
- type: normalizeType(raw.type, currentNamespace, ctx),
406
- readable: raw.readable ?? true,
407
- writable: raw.writable ?? false,
408
- constructOnly: raw.constructOnly ?? false,
409
- defaultValue: parseDefaultValue(raw.defaultValueRaw),
410
- getter: raw.getter,
411
- setter: raw.setter,
412
- doc: raw.doc,
413
- });
414
- };
415
- /**
416
- * Normalizes a raw signal to a normalized signal.
417
- */
418
- const normalizeSignal = (raw, currentNamespace, ctx) => {
419
- return new GirSignal({
420
- name: raw.name,
421
- when: raw.when ?? "last",
422
- returnType: raw.returnType ? normalizeType(raw.returnType, currentNamespace, ctx) : null,
423
- parameters: (raw.parameters ?? []).map((p) => normalizeParameter(p, currentNamespace, ctx)),
424
- doc: raw.doc,
425
- });
426
- };
427
- /**
428
- * Normalizes a raw field to a normalized field.
429
- */
430
- const normalizeField = (raw, currentNamespace, ctx) => {
431
- return new GirField({
432
- name: raw.name,
433
- type: normalizeType(raw.type, currentNamespace, ctx),
434
- writable: raw.writable ?? false,
435
- readable: raw.readable ?? true,
436
- private: raw.private ?? false,
437
- doc: raw.doc,
438
- });
439
- };
398
+ normalizeField(raw, currentNamespace) {
399
+ return new GirField({
400
+ name: raw.name,
401
+ type: this.normalizeType(raw.type, currentNamespace),
402
+ writable: raw.writable ?? false,
403
+ readable: raw.readable ?? true,
404
+ private: raw.private ?? false,
405
+ doc: raw.doc,
406
+ });
407
+ }
408
+ }
440
409
  //# sourceMappingURL=normalizer.js.map