@idlizer/core 2.0.15 → 2.0.19

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 (57) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.js +17 -5
  2. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +1 -0
  3. package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -4
  4. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +30 -0
  5. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +154 -0
  6. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +5 -3
  7. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +13 -0
  8. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +118 -0
  9. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +32 -0
  10. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +175 -0
  11. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +27 -0
  12. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +173 -0
  13. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +1 -1
  14. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
  15. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +5 -1
  16. package/build/lib/src/LibraryInterface.d.ts +2 -0
  17. package/build/lib/src/config.js +14 -0
  18. package/build/lib/src/configMerge.d.ts +2 -0
  19. package/build/lib/src/configMerge.js +42 -0
  20. package/build/lib/src/from-idl/common.d.ts +1 -1
  21. package/build/lib/src/from-idl/common.js +20 -11
  22. package/build/lib/src/idl.d.ts +6 -3
  23. package/build/lib/src/idl.js +15 -11
  24. package/build/lib/src/idlize.d.ts +1 -1
  25. package/build/lib/src/idlize.js +57 -13
  26. package/build/lib/src/index.d.ts +12 -0
  27. package/build/lib/src/index.js +12 -0
  28. package/build/lib/src/languageSpecificKeywords.js +1 -1
  29. package/build/lib/src/options.d.ts +1 -0
  30. package/build/lib/src/peer-generation/BuilderClass.d.ts +22 -0
  31. package/build/lib/src/peer-generation/BuilderClass.js +76 -0
  32. package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +2 -0
  33. package/build/lib/src/peer-generation/LanguageWriters/index.js +2 -0
  34. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +25 -0
  35. package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +55 -0
  36. package/build/lib/src/peer-generation/LayoutManager.d.ts +15 -0
  37. package/build/lib/src/peer-generation/LayoutManager.js +32 -0
  38. package/build/lib/src/peer-generation/Materialized.d.ts +60 -0
  39. package/build/lib/src/peer-generation/Materialized.js +178 -0
  40. package/build/lib/src/peer-generation/PeerClass.d.ts +29 -0
  41. package/build/lib/src/peer-generation/PeerClass.js +44 -0
  42. package/build/lib/src/peer-generation/PeerFile.d.ts +13 -0
  43. package/build/lib/src/peer-generation/PeerFile.js +38 -0
  44. package/build/lib/src/peer-generation/PeerLibrary.d.ts +53 -0
  45. package/build/lib/src/peer-generation/PeerLibrary.js +340 -0
  46. package/build/lib/src/peer-generation/PeerMethod.d.ts +35 -0
  47. package/build/lib/src/peer-generation/PeerMethod.js +108 -0
  48. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  49. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +4 -1
  50. package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
  51. package/build/lib/src/peer-generation/idl/common.js +5 -0
  52. package/build/lib/src/util.d.ts +8 -0
  53. package/build/lib/src/util.js +16 -0
  54. package/package.json +3 -7
  55. package/webidl2.js/LICENSE +0 -21
  56. package/webidl2.js/README.md +0 -827
  57. package/webidl2.js/dist/package.json +0 -3
@@ -0,0 +1,340 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { warn } from 'console';
16
+ import * as idl from '../idl';
17
+ import { Language } from '../Language';
18
+ import { InteropNameConvertor } from '../LanguageWriters';
19
+ import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, } from "../LanguageWriters/ArgConvertors";
20
+ import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
21
+ import { CppInteropConvertor } from '../LanguageWriters/convertors/CppConvertors';
22
+ import { ETSTypeNameConvertor } from '../LanguageWriters/convertors/ETSConvertors';
23
+ import { JavaTypeNameConvertor } from '../LanguageWriters/convertors/JavaConvertors';
24
+ import { TSTypeNameConvertor } from '../LanguageWriters/convertors/TSConvertors';
25
+ import { generateSyntheticFunctionName, isImportAttr } from './idl/common';
26
+ import { isMaterialized } from './Materialized';
27
+ import { LayoutManager } from './LayoutManager';
28
+ export class PeerLibrary {
29
+ /** @deprecated PeerLibrary should contain only SDK entries */
30
+ get syntheticEntries() {
31
+ return this._syntheticEntries;
32
+ }
33
+ initSyntheticEntries(entries) {
34
+ this._syntheticEntries = entries;
35
+ }
36
+ get buildersToGenerate() {
37
+ return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
38
+ }
39
+ get materializedToGenerate() {
40
+ return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated);
41
+ }
42
+ constructor(language) {
43
+ this.language = language;
44
+ this.layout = LayoutManager.Empty();
45
+ this._syntheticEntries = [];
46
+ this.files = [];
47
+ this.builderClasses = new Map();
48
+ this.materializedClasses = new Map();
49
+ this.predefinedDeclarations = [];
50
+ this.globalScopeInterfaces = [];
51
+ this.name = "";
52
+ this.customComponentMethods = [];
53
+ this.targetNameConvertorInstance = this.createTypeNameConvertor(this.language);
54
+ this.interopNameConvertorInstance = new InteropNameConvertor(this);
55
+ }
56
+ createTypeNameConvertor(language) {
57
+ switch (language) {
58
+ case Language.TS: return new TSTypeNameConvertor(this);
59
+ case Language.ARKTS: return new ETSTypeNameConvertor(this);
60
+ case Language.JAVA: return new JavaTypeNameConvertor(this);
61
+ case Language.CJ: return new CJTypeNameConvertor(this);
62
+ case Language.CPP: return new CppInteropConvertor(this);
63
+ }
64
+ throw new Error(`IdlNameConvertor for ${language} is not implemented`);
65
+ }
66
+ get libraryPrefix() {
67
+ return this.name ? this.name + "_" : "";
68
+ }
69
+ createContinuationParameters(continuationType) {
70
+ const continuationParameters = [];
71
+ if (idl.isContainerType(continuationType) && idl.IDLContainerUtils.isPromise(continuationType)) {
72
+ const errorType = idl.createOptionalType(idl.createContainerType("sequence", [idl.IDLStringType]));
73
+ continuationParameters.push(idl.createParameter("error", errorType, true));
74
+ const promise = continuationType;
75
+ if (!idl.isVoidType(promise.elementType[0])) {
76
+ const valueType = idl.createOptionalType(promise.elementType[0]);
77
+ continuationParameters.unshift(idl.createParameter("value", valueType, true));
78
+ }
79
+ }
80
+ else if (!idl.isVoidType(continuationType))
81
+ continuationParameters.push(idl.createParameter('value', continuationType));
82
+ return continuationParameters;
83
+ }
84
+ createContinuationCallbackReference(continuationType) {
85
+ const continuationParameters = this.createContinuationParameters(continuationType);
86
+ const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType);
87
+ return idl.createReferenceType(syntheticName, undefined, continuationType);
88
+ }
89
+ getCurrentContext() {
90
+ return this.context;
91
+ }
92
+ setCurrentContext(context) {
93
+ this.context = context;
94
+ }
95
+ findFileByOriginalFilename(filename) {
96
+ return this.files.find(it => it.originalFilename === filename);
97
+ }
98
+ mapType(type) {
99
+ return this.targetNameConvertorInstance.convert(type);
100
+ }
101
+ resolveTypeReference(type, pointOfView, rootEntries) {
102
+ const entry = this.syntheticEntries.find(it => it.name === type.name);
103
+ if (entry)
104
+ return entry;
105
+ const qualifiedName = type.name.split(".");
106
+ pointOfView !== null && pointOfView !== void 0 ? pointOfView : (pointOfView = type.namespace);
107
+ let pointOfViewNamespace = !pointOfView || idl.isNamespace(pointOfView)
108
+ ? pointOfView
109
+ : pointOfView.namespace;
110
+ rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
111
+ if (1 === qualifiedName.length) {
112
+ const predefined = rootEntries.filter(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Predefined));
113
+ predefined.push(...this.predefinedDeclarations);
114
+ const found = predefined.find(it => it.name === qualifiedName[0]);
115
+ if (found)
116
+ return found;
117
+ }
118
+ let doWork = true;
119
+ while (doWork) {
120
+ doWork = !!pointOfViewNamespace;
121
+ let entries = pointOfViewNamespace
122
+ ? [...pointOfViewNamespace.members]
123
+ : [...rootEntries];
124
+ for (let qualifiedNamePart = 0; qualifiedNamePart < qualifiedName.length; ++qualifiedNamePart) {
125
+ const candidates = entries.filter(it => it.name === qualifiedName[qualifiedNamePart]);
126
+ if (!candidates.length)
127
+ break;
128
+ if (qualifiedNamePart === qualifiedName.length - 1) {
129
+ return candidates.length == 1
130
+ ? candidates[0]
131
+ : candidates.find(it => !idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Import)); // probably the wrong logic here
132
+ }
133
+ entries = [];
134
+ for (const candidate of candidates) {
135
+ if (idl.isNamespace(candidate))
136
+ entries.push(...candidate.members);
137
+ else if (idl.isEnum(candidate))
138
+ entries.push(...candidate.elements);
139
+ else if (idl.isInterface(candidate))
140
+ entries.push(...candidate.constants, ...candidate.properties, ...candidate.methods);
141
+ }
142
+ }
143
+ pointOfViewNamespace = pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.namespace;
144
+ }
145
+ // TODO: remove the next block after namespaces out of quarantine
146
+ if (!pointOfView) {
147
+ const resolveds = [];
148
+ const traverseNamespaces = (entry) => {
149
+ if (entry && idl.isNamespace(entry) && entry.members.length) {
150
+ //console.log(`Try alien namespace '${idl.getNamespacesPathFor(entry.members[0]).map(obj => obj.name).join(".")}' to resolve name '${type.name}'`)
151
+ const resolved = this.resolveTypeReference(type, entry, rootEntries);
152
+ if (resolved)
153
+ resolveds.push(resolved);
154
+ entry.members.forEach(traverseNamespaces);
155
+ }
156
+ };
157
+ this.files.forEach(file => file.entries.forEach(traverseNamespaces));
158
+ if (resolveds.length)
159
+ console.log(`WARNING: Type reference '${type.name}' is not resolved without own namespace/pointOfView but resolved within some other namespace: '${idl.getNamespacesPathFor(resolveds[0]).map(obj => obj.name).join(".")}'`);
160
+ } // end of block to remove
161
+ return undefined; // empty result
162
+ }
163
+ typeConvertor(param, type, isOptionalParam = false) {
164
+ if (isOptionalParam) {
165
+ return new OptionConvertor(this, param, idl.maybeUnwrapOptionalType(type));
166
+ }
167
+ if (idl.isOptionalType(type)) {
168
+ return new OptionConvertor(this, param, type.type);
169
+ }
170
+ if (idl.isPrimitiveType(type)) {
171
+ switch (type) {
172
+ case idl.IDLI8Type: return new NumericConvertor(param, type);
173
+ case idl.IDLU8Type: return new NumericConvertor(param, type);
174
+ case idl.IDLI16Type: return new NumericConvertor(param, type);
175
+ case idl.IDLU16Type: return new NumericConvertor(param, type);
176
+ case idl.IDLI32Type: return new NumericConvertor(param, type);
177
+ case idl.IDLU32Type: return new NumericConvertor(param, type);
178
+ case idl.IDLI64Type: return new NumericConvertor(param, type);
179
+ case idl.IDLU64Type: return new NumericConvertor(param, type);
180
+ case idl.IDLF16Type: return new NumericConvertor(param, type);
181
+ case idl.IDLF32Type: return new NumericConvertor(param, type);
182
+ case idl.IDLF64Type: return new NumericConvertor(param, type);
183
+ case idl.IDLPointerType: return new PointerConvertor(param);
184
+ case idl.IDLBufferType: return new BufferConvertor(param);
185
+ case idl.IDLBooleanType: return new BooleanConvertor(param);
186
+ case idl.IDLStringType: return new StringConvertor(param);
187
+ case idl.IDLNumberType: return new NumberConvertor(param);
188
+ case idl.IDLUndefinedType: return new UndefinedConvertor(param);
189
+ case idl.IDLVoidType: return new VoidConvertor(param);
190
+ case idl.IDLUnknownType:
191
+ case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any");
192
+ default: throw new Error(`Unconverted primitive ${idl.DebugUtils.debugPrintType(type)}`);
193
+ }
194
+ }
195
+ if (idl.isReferenceType(type)) {
196
+ if (isImportAttr(type))
197
+ return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
198
+ const decl = this.resolveTypeReference(type);
199
+ return this.declarationConvertor(param, type, decl);
200
+ }
201
+ if (idl.isUnionType(type)) {
202
+ return new UnionConvertor(this, param, type);
203
+ }
204
+ if (idl.isContainerType(type)) {
205
+ if (idl.IDLContainerUtils.isSequence(type))
206
+ return new ArrayConvertor(this, param, type, type.elementType[0]);
207
+ if (idl.IDLContainerUtils.isRecord(type))
208
+ return new MapConvertor(this, param, type, type.elementType[0], type.elementType[1]);
209
+ }
210
+ if (idl.isTypeParameterType(type)) {
211
+ // TODO: unlikely correct.
212
+ return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true);
213
+ }
214
+ throw new Error(`Cannot convert: ${type.kind}`);
215
+ }
216
+ declarationConvertor(param, type, declaration) {
217
+ let customConv = this.customConvertor(param, type.name, type);
218
+ if (customConv)
219
+ return customConv;
220
+ if (!declaration)
221
+ return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), false, this.targetNameConvertorInstance.convert(type)); // assume some predefined type
222
+ const declarationName = declaration.name;
223
+ if (isImportAttr(declaration)) {
224
+ return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
225
+ }
226
+ if (idl.isEnum(declaration)) {
227
+ return new EnumConvertor(param, declaration);
228
+ }
229
+ if (idl.isEnumMember(declaration)) {
230
+ return new EnumConvertor(param, declaration.parent);
231
+ }
232
+ if (idl.isCallback(declaration)) {
233
+ return new CallbackConvertor(this, param, declaration);
234
+ }
235
+ if (idl.isTypedef(declaration)) {
236
+ if (isCyclicTypeDef(declaration)) {
237
+ warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
238
+ return new CustomTypeConvertor(param, declaration.name, false, declaration.name);
239
+ }
240
+ return new TypeAliasConvertor(this, param, declaration);
241
+ }
242
+ if (idl.isInterface(declaration)) {
243
+ if (isMaterialized(declaration, this)) {
244
+ return new MaterializedClassConvertor(param, declaration);
245
+ }
246
+ switch (declaration.subkind) {
247
+ case idl.IDLInterfaceSubkind.Interface:
248
+ return new InterfaceConvertor(this, declarationName, param, declaration);
249
+ case idl.IDLInterfaceSubkind.Class:
250
+ return new ClassConvertor(this, declarationName, param, declaration);
251
+ case idl.IDLInterfaceSubkind.AnonymousInterface:
252
+ return new AggregateConvertor(this, param, type, declaration);
253
+ case idl.IDLInterfaceSubkind.Tuple:
254
+ return new TupleConvertor(this, param, type, declaration);
255
+ }
256
+ }
257
+ throw new Error(`Unknown decl ${declarationName} of kind ${declaration.kind}`);
258
+ }
259
+ customConvertor(param, typeName, type) {
260
+ switch (typeName) {
261
+ case `Object`:
262
+ return new CustomTypeConvertor(param, "Object");
263
+ case `Date`:
264
+ return new DateConvertor(param);
265
+ case `Function`:
266
+ return new FunctionConvertor(this, param, type);
267
+ case `Record`:
268
+ return new CustomTypeConvertor(param, "Record", false, "Record<string, string>");
269
+ case `Optional`:
270
+ return new OptionConvertor(this, param, type.typeArguments[0]);
271
+ }
272
+ return undefined;
273
+ }
274
+ getInteropName(node) {
275
+ return this.interopNameConvertorInstance.convert(node);
276
+ }
277
+ toDeclaration(type) {
278
+ switch (type) {
279
+ case idl.IDLAnyType: return ArkCustomObject;
280
+ case idl.IDLVoidType: return idl.IDLVoidType;
281
+ case idl.IDLUndefinedType: return idl.IDLUndefinedType;
282
+ case idl.IDLUnknownType: return ArkCustomObject;
283
+ case idl.IDLObjectType: return ArkCustomObject;
284
+ }
285
+ const typeName = idl.isNamedNode(type) ? type.name : undefined;
286
+ switch (typeName) {
287
+ case "object":
288
+ case "Object": return ArkCustomObject;
289
+ }
290
+ if (isImportAttr(type)) {
291
+ return ArkCustomObject;
292
+ }
293
+ if (idl.isReferenceType(type)) {
294
+ // TODO: remove all this!
295
+ if (type.name === 'Dimension' || type.name === 'Length') {
296
+ return ArkLength;
297
+ }
298
+ if (type.name === 'Date') {
299
+ return ArkDate;
300
+ }
301
+ if (type.name === 'AnimationRange' || type.name === 'ContentModifier') {
302
+ return ArkCustomObject;
303
+ }
304
+ if (type.name === 'Function') {
305
+ return ArkFunction;
306
+ }
307
+ if (type.name === 'Optional') {
308
+ return this.toDeclaration(type.typeArguments[0]);
309
+ }
310
+ const decl = this.resolveTypeReference(type);
311
+ if (!decl) {
312
+ warn(`undeclared type ${idl.DebugUtils.debugPrintType(type)}`);
313
+ }
314
+ if (decl && idl.isTypedef(decl) && isCyclicTypeDef(decl)) {
315
+ warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
316
+ return ArkCustomObject;
317
+ }
318
+ return !decl ? ArkCustomObject // assume some builtin type
319
+ : idl.isTypedef(decl) ? this.toDeclaration(decl.type)
320
+ : decl;
321
+ }
322
+ return type;
323
+ }
324
+ setFileLayout(strategy) {
325
+ this.layout = new LayoutManager(strategy);
326
+ }
327
+ }
328
+ export const ArkInt32 = idl.IDLI32Type;
329
+ export const ArkInt64 = idl.IDLI64Type;
330
+ export const ArkFunction = idl.IDLFunctionType;
331
+ export const ArkLength = idl.IDLLengthType;
332
+ export const ArkDate = idl.IDLDate;
333
+ export const ArkCustomObject = idl.IDLCustomObjectType;
334
+ export function cleanPrefix(name, prefix) {
335
+ return name.replace(prefix, "");
336
+ }
337
+ function isCyclicTypeDef(decl) {
338
+ return idl.isReferenceType(decl.type) && idl.isNamedNode(decl.type) && decl.type.name == decl.name;
339
+ }
340
+ //# sourceMappingURL=PeerLibrary.js.map
@@ -0,0 +1,35 @@
1
+ import { IDLType } from "../idl";
2
+ import { IdlNameConvertor } from "../LanguageWriters";
3
+ import { ArgConvertor } from "../LanguageWriters/ArgConvertors";
4
+ import { Method } from "../LanguageWriters/LanguageWriter";
5
+ export declare class PeerMethod {
6
+ originalParentName: string;
7
+ argConvertors: ArgConvertor[];
8
+ returnType: IDLType;
9
+ isCallSignature: boolean;
10
+ method: Method;
11
+ outArgConvertor?: ArgConvertor | undefined;
12
+ private overloadIndex?;
13
+ constructor(originalParentName: string, argConvertors: ArgConvertor[], returnType: IDLType, isCallSignature: boolean, method: Method, outArgConvertor?: ArgConvertor | undefined);
14
+ get overloadedName(): string;
15
+ get fullMethodName(): string;
16
+ get peerMethodName(): string;
17
+ get implNamespaceName(): string;
18
+ get implName(): string;
19
+ get toStringName(): string;
20
+ get dummyReturnValue(): string | undefined;
21
+ get receiverType(): string;
22
+ get apiCall(): string;
23
+ get apiKind(): string;
24
+ get argAndOutConvertors(): ArgConvertor[];
25
+ hasReceiver(): boolean;
26
+ generateAPIParameters(converter: IdlNameConvertor): string[];
27
+ generateReceiver(): {
28
+ argName: string;
29
+ argType: string;
30
+ } | undefined;
31
+ getImplementationName(): string;
32
+ static markAndGroupOverloads(methods: PeerMethod[]): PeerMethod[];
33
+ setSameOverloadIndex(copyFrom: PeerMethod): void;
34
+ }
35
+ //# sourceMappingURL=PeerMethod.d.ts.map
@@ -0,0 +1,108 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { mangleMethodName, MethodModifier } from "../LanguageWriters/LanguageWriter";
16
+ import { capitalize, isDefined } from "../util";
17
+ import { PrimitiveTypesInstance } from "./PrimitiveType";
18
+ export class PeerMethod {
19
+ constructor(originalParentName, argConvertors, returnType, isCallSignature, method, outArgConvertor) {
20
+ this.originalParentName = originalParentName;
21
+ this.argConvertors = argConvertors;
22
+ this.returnType = returnType;
23
+ this.isCallSignature = isCallSignature;
24
+ this.method = method;
25
+ this.outArgConvertor = outArgConvertor;
26
+ }
27
+ get overloadedName() {
28
+ return mangleMethodName(this.method, this.overloadIndex);
29
+ }
30
+ get fullMethodName() {
31
+ return this.isCallSignature ? this.overloadedName : this.peerMethodName;
32
+ }
33
+ get peerMethodName() {
34
+ const name = this.overloadedName;
35
+ if (!this.hasReceiver())
36
+ return name;
37
+ if (name.startsWith("set") ||
38
+ name.startsWith("get"))
39
+ return name;
40
+ return `set${capitalize(name)}`;
41
+ }
42
+ get implNamespaceName() {
43
+ return `${capitalize(this.originalParentName)}Modifier`;
44
+ }
45
+ get implName() {
46
+ return `${capitalize(this.overloadedName)}Impl`;
47
+ }
48
+ get toStringName() {
49
+ return this.method.name;
50
+ }
51
+ get dummyReturnValue() {
52
+ return undefined;
53
+ }
54
+ get receiverType() {
55
+ return "Ark_NodeHandle";
56
+ }
57
+ get apiCall() {
58
+ return "GetNodeModifiers()";
59
+ }
60
+ get apiKind() {
61
+ return "Modifier";
62
+ }
63
+ get argAndOutConvertors() {
64
+ var _a;
65
+ return this.argConvertors.concat((_a = this.outArgConvertor) !== null && _a !== void 0 ? _a : []);
66
+ }
67
+ hasReceiver() {
68
+ var _a;
69
+ return !((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.STATIC));
70
+ }
71
+ generateAPIParameters(converter) {
72
+ const args = this.argAndOutConvertors.map(it => {
73
+ let isPointer = it.isPointerType();
74
+ return `${isPointer ? "const " : ""}${converter.convert(it.nativeType())}${isPointer ? "*" : ""} ${it.param}`;
75
+ });
76
+ const receiver = this.generateReceiver();
77
+ if (receiver)
78
+ return [`${receiver.argType} ${receiver.argName}`, ...args];
79
+ return args;
80
+ }
81
+ generateReceiver() {
82
+ if (!this.hasReceiver())
83
+ return undefined;
84
+ return {
85
+ argName: "node",
86
+ argType: PrimitiveTypesInstance.NativePointer.getText()
87
+ };
88
+ }
89
+ getImplementationName() {
90
+ return this.originalParentName;
91
+ }
92
+ static markAndGroupOverloads(methods) {
93
+ let groupedMethods = [];
94
+ for (const peerMethod of methods) {
95
+ if (isDefined(peerMethod.overloadIndex))
96
+ continue;
97
+ const sameNamedMethods = methods.filter(it => it.method.name === peerMethod.method.name);
98
+ if (sameNamedMethods.length > 1)
99
+ sameNamedMethods.forEach((it, index) => it.overloadIndex = index);
100
+ groupedMethods = groupedMethods.concat(sameNamedMethods);
101
+ }
102
+ return groupedMethods;
103
+ }
104
+ setSameOverloadIndex(copyFrom) {
105
+ this.overloadIndex = copyFrom.overloadIndex;
106
+ }
107
+ }
108
+ //# sourceMappingURL=PeerMethod.js.map
@@ -16,6 +16,7 @@ export declare class TSFeatureNameConvertor extends DeclarationNameConvertor {
16
16
  static readonly I: TSFeatureNameConvertor;
17
17
  }
18
18
  export declare class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
19
+ convertInterface(decl: idl.IDLInterface): string;
19
20
  convertEnum(decl: idl.IDLEnum): string;
20
21
  static readonly I: ETSDeclarationNameConvertor;
21
22
  }
@@ -46,6 +46,9 @@ export class TSFeatureNameConvertor extends DeclarationNameConvertor {
46
46
  }
47
47
  TSFeatureNameConvertor.I = new TSFeatureNameConvertor();
48
48
  export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
49
+ convertInterface(decl) {
50
+ return idl.getFQName(decl);
51
+ }
49
52
  convertEnum(decl) {
50
53
  const namespace = idl.getNamespacesPathFor(decl).map(it => it.name).join('_');
51
54
  return `${namespace ? `${namespace}_` : ``}${decl.name}`;
@@ -54,7 +57,7 @@ export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
54
57
  ETSDeclarationNameConvertor.I = new ETSDeclarationNameConvertor();
55
58
  export class ETSFeatureNameConvertor extends DeclarationNameConvertor {
56
59
  convertEnum(decl) {
57
- const namespace = idl.getNamespacesPathFor(decl).join('');
60
+ const namespace = idl.getNamespacesPathFor(decl).map(it => it.name).join('');
58
61
  return `${namespace ? `${namespace}_` : ``}${decl.name}`;
59
62
  }
60
63
  }
@@ -5,5 +5,6 @@ export declare function qualifiedName(decl: idl.IDLNode, languageOrDelimiter: La
5
5
  export declare function typeOrUnion(types: idl.IDLType[], name?: string): idl.IDLType;
6
6
  export declare function generifiedTypeName(refType: idl.IDLReferenceType | undefined, refName?: string): string | undefined;
7
7
  export declare function generateSyntheticUnionName(types: idl.IDLType[]): string;
8
+ export declare function generateSyntheticFunctionName(parameters: idl.IDLParameter[], returnType: idl.IDLType, isAsync?: boolean): string;
8
9
  export declare function isImportAttr(decl: idl.IDLNode): boolean;
9
10
  //# sourceMappingURL=common.d.ts.map
@@ -64,6 +64,11 @@ export function generifiedTypeName(refType, refName) {
64
64
  export function generateSyntheticUnionName(types) {
65
65
  return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_")}`;
66
66
  }
67
+ export function generateSyntheticFunctionName(parameters, returnType, isAsync = false) {
68
+ let prefix = isAsync ? "AsyncCallback" : "Callback";
69
+ const names = parameters.map(it => `${generateSyntheticIdlNodeName(it.type)}`).concat(generateSyntheticIdlNodeName(returnType));
70
+ return `${prefix}_${names.join("_").replaceAll(".", "_")}`;
71
+ }
67
72
  export function isImportAttr(decl) {
68
73
  return idl.hasExtAttribute(decl, idl.IDLExtendedAttributes.Import);
69
74
  }
@@ -72,4 +72,12 @@ export declare function hashCodeFromString(value: string): number;
72
72
  export declare function forceWriteFile(filePath: string, content: string): void;
73
73
  export declare function findVersion(): any;
74
74
  export declare function zipMany<T>(...xs: T[][]): Array<Array<T | undefined>>;
75
+ export declare class Lazy<T> {
76
+ private readonly factory;
77
+ constructor(factory: () => T);
78
+ private instantiated;
79
+ private instance;
80
+ get value(): T;
81
+ }
82
+ export declare function lazy<T>(factory: () => T): Lazy<T>;
75
83
  //# sourceMappingURL=util.d.ts.map
@@ -619,4 +619,20 @@ export function zipMany(...xs) {
619
619
  }
620
620
  return result;
621
621
  }
622
+ export class Lazy {
623
+ constructor(factory) {
624
+ this.instantiated = false;
625
+ this.factory = factory;
626
+ }
627
+ get value() {
628
+ if (!this.instantiated) {
629
+ this.instance = this.factory();
630
+ this.instantiated = true;
631
+ }
632
+ return this.instance;
633
+ }
634
+ }
635
+ export function lazy(factory) {
636
+ return new Lazy(factory);
637
+ }
622
638
  //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.0.15",
3
+ "version": "2.0.19",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {
@@ -34,13 +34,9 @@
34
34
  },
35
35
  "keywords": [],
36
36
  "dependencies": {
37
- "@koalaui/interop": "2.0.15",
37
+ "@koalaui/interop": "1.4.6",
38
38
  "typescript": "4.9.5",
39
- "@types/node": "^18.0.0",
40
- "commander": "^10.0.0",
41
- "comment-parser": "^1.4.1",
42
- "cross-env": "^7.0.3",
43
- "minimist": "^1.2.8"
39
+ "@types/node": "^18.0.0"
44
40
  },
45
41
  "scripts": {
46
42
  "clean": "rimraf -g build",
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Robin Berjon
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.