@gtkx/gir 0.18.0 → 0.18.2
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/normalizer.d.ts +1 -0
- package/dist/internal/normalizer.d.ts.map +1 -0
- package/dist/internal/normalizer.js +1 -0
- package/dist/internal/normalizer.js.map +1 -0
- package/dist/internal/parser.d.ts +1 -0
- package/dist/internal/parser.d.ts.map +1 -0
- package/dist/internal/parser.js +1 -0
- package/dist/internal/parser.js.map +1 -0
- package/dist/internal/raw-types.d.ts +1 -0
- package/dist/internal/raw-types.d.ts.map +1 -0
- package/dist/internal/raw-types.js +1 -0
- package/dist/internal/raw-types.js.map +1 -0
- package/dist/intrinsics.d.ts +1 -0
- package/dist/intrinsics.d.ts.map +1 -0
- package/dist/intrinsics.js +1 -0
- package/dist/intrinsics.js.map +1 -0
- package/dist/repository.d.ts +1 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +1 -0
- package/dist/repository.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/package.json +4 -2
- package/src/index.ts +64 -0
- package/src/internal/normalizer.ts +551 -0
- package/src/internal/parser.ts +633 -0
- package/src/internal/raw-types.ts +268 -0
- package/src/intrinsics.ts +129 -0
- package/src/repository.ts +406 -0
- package/src/types.ts +1192 -0
- package/src/utils.ts +12 -0
|
@@ -0,0 +1,551 @@
|
|
|
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
|
+
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";
|
|
33
|
+
import type {
|
|
34
|
+
RawAlias,
|
|
35
|
+
RawCallback,
|
|
36
|
+
RawClass,
|
|
37
|
+
RawConstant,
|
|
38
|
+
RawConstructor,
|
|
39
|
+
RawEnumeration,
|
|
40
|
+
RawField,
|
|
41
|
+
RawFunction,
|
|
42
|
+
RawInterface,
|
|
43
|
+
RawMethod,
|
|
44
|
+
RawNamespace,
|
|
45
|
+
RawParameter,
|
|
46
|
+
RawProperty,
|
|
47
|
+
RawRecord,
|
|
48
|
+
RawSignal,
|
|
49
|
+
RawType,
|
|
50
|
+
} from "./raw-types.js";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Context for normalization - provides access to all loaded namespaces
|
|
54
|
+
* for resolving cross-namespace references.
|
|
55
|
+
*/
|
|
56
|
+
export type NormalizerContext = {
|
|
57
|
+
/** All raw namespaces that have been loaded */
|
|
58
|
+
rawNamespaces: Map<string, RawNamespace>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes a raw namespace into a normalized namespace.
|
|
63
|
+
*/
|
|
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
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const rawInterface of raw.interfaces) {
|
|
83
|
+
const normalized = normalizeInterface(rawInterface, nsName, ctx);
|
|
84
|
+
interfaces.set(normalized.name, normalized);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const rawRecord of raw.records) {
|
|
88
|
+
const normalized = normalizeRecord(rawRecord, nsName, ctx);
|
|
89
|
+
records.set(normalized.name, normalized);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const rawEnum of raw.enumerations) {
|
|
93
|
+
const normalized = normalizeEnumeration(rawEnum, nsName);
|
|
94
|
+
enumerations.set(normalized.name, normalized);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const rawBitfield of raw.bitfields) {
|
|
98
|
+
const normalized = normalizeEnumeration(rawBitfield, nsName);
|
|
99
|
+
bitfields.set(normalized.name, normalized);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const rawCallback of raw.callbacks) {
|
|
103
|
+
const normalized = normalizeCallback(rawCallback, nsName, ctx);
|
|
104
|
+
callbacks.set(normalized.name, normalized);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const rawFunction of raw.functions) {
|
|
108
|
+
const normalized = normalizeFunction(rawFunction, nsName, ctx);
|
|
109
|
+
functions.set(normalized.name, normalized);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const rawConstant of raw.constants) {
|
|
113
|
+
const normalized = normalizeConstant(rawConstant, nsName, ctx);
|
|
114
|
+
constants.set(normalized.name, normalized);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const rawAlias of raw.aliases) {
|
|
118
|
+
const normalized = normalizeAlias(rawAlias, nsName, ctx);
|
|
119
|
+
aliases.set(normalized.name, normalized);
|
|
120
|
+
}
|
|
121
|
+
|
|
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
|
+
};
|
|
139
|
+
|
|
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
|
+
}
|
|
151
|
+
|
|
152
|
+
if (typeName.includes(".")) {
|
|
153
|
+
return typeName as QualifiedName;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const currentNs = ctx.rawNamespaces.get(currentNamespace);
|
|
157
|
+
if (currentNs && typeExistsInNamespace(typeName, currentNs)) {
|
|
158
|
+
return qualifiedName(currentNamespace, typeName);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
for (const [nsName, ns] of ctx.rawNamespaces) {
|
|
162
|
+
if (nsName !== currentNamespace && typeExistsInNamespace(typeName, ns)) {
|
|
163
|
+
return qualifiedName(nsName, typeName);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return qualifiedName(currentNamespace, typeName);
|
|
168
|
+
};
|
|
169
|
+
|
|
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
|
+
};
|
|
184
|
+
|
|
185
|
+
const buildContainerTypeBase = (raw: RawType) => ({
|
|
186
|
+
cType: raw.cType,
|
|
187
|
+
containerType: raw.containerType,
|
|
188
|
+
transferOwnership: raw.transferOwnership,
|
|
189
|
+
nullable: raw.nullable ?? false,
|
|
190
|
+
});
|
|
191
|
+
|
|
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
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
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
|
+
}
|
|
218
|
+
|
|
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
|
+
}
|
|
229
|
+
|
|
230
|
+
const isArray = raw.isArray === true || raw.name === "array";
|
|
231
|
+
|
|
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
|
+
}
|
|
245
|
+
|
|
246
|
+
if (isArray) {
|
|
247
|
+
return new GirType({
|
|
248
|
+
name: "array",
|
|
249
|
+
cType: raw.cType,
|
|
250
|
+
isArray: true,
|
|
251
|
+
elementType: null,
|
|
252
|
+
transferOwnership: raw.transferOwnership,
|
|
253
|
+
nullable: raw.nullable ?? false,
|
|
254
|
+
sizeParamIndex: raw.sizeParamIndex,
|
|
255
|
+
zeroTerminated: raw.zeroTerminated,
|
|
256
|
+
fixedSize: raw.fixedSize,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
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;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
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
|
+
};
|
|
310
|
+
|
|
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
|
+
};
|
|
334
|
+
|
|
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
|
+
};
|
|
359
|
+
|
|
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
|
+
};
|
|
383
|
+
|
|
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
|
+
|
|
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
|
+
};
|
|
415
|
+
|
|
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
|
+
};
|
|
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
|
+
};
|
|
451
|
+
|
|
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
|
+
};
|
|
472
|
+
|
|
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
|
+
};
|
|
489
|
+
|
|
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
|
+
};
|
|
508
|
+
|
|
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
|
+
};
|
|
525
|
+
|
|
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
|
+
};
|
|
538
|
+
|
|
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
|
+
};
|