@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-7

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 (104) hide show
  1. package/build/lib/src/Language.js +1 -1
  2. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +16 -6
  3. package/build/lib/src/LanguageWriters/ArgConvertors.js +80 -92
  4. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +8 -7
  5. package/build/lib/src/LanguageWriters/LanguageWriter.js +35 -22
  6. package/build/lib/src/LanguageWriters/common.d.ts +1 -0
  7. package/build/lib/src/LanguageWriters/common.js +2 -1
  8. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +7 -1
  9. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +53 -15
  10. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
  11. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
  12. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
  13. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +26 -14
  14. package/build/lib/src/LanguageWriters/index.d.ts +4 -3
  15. package/build/lib/src/LanguageWriters/index.js +9 -11
  16. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
  18. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
  19. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -22
  20. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +34 -113
  21. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -0
  22. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -9
  23. package/build/lib/src/config.d.ts +2 -1461
  24. package/build/lib/src/config.js +16 -32
  25. package/build/lib/src/configMerge.d.ts +3 -0
  26. package/build/lib/src/configMerge.js +63 -0
  27. package/build/lib/src/diagnostictypes.d.ts +1 -5
  28. package/build/lib/src/diagnostictypes.js +1 -27
  29. package/build/lib/src/from-idl/DtsPrinter.js +12 -5
  30. package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
  31. package/build/lib/src/from-idl/IDLLinter.js +30 -32
  32. package/build/lib/src/from-idl/deserialize.d.ts +3 -4
  33. package/build/lib/src/from-idl/deserialize.js +29 -641
  34. package/build/lib/src/from-idl/parser.d.ts +20 -2
  35. package/build/lib/src/from-idl/parser.js +97 -29
  36. package/build/lib/src/idl/builders.d.ts +43 -0
  37. package/build/lib/src/idl/builders.js +135 -0
  38. package/build/lib/src/idl/discriminators.d.ts +53 -0
  39. package/build/lib/src/idl/discriminators.js +232 -0
  40. package/build/lib/src/idl/dump.d.ts +48 -0
  41. package/build/lib/src/idl/dump.js +327 -0
  42. package/build/lib/src/idl/index.d.ts +9 -0
  43. package/build/lib/src/idl/index.js +23 -0
  44. package/build/lib/src/idl/keywords.d.ts +2 -0
  45. package/build/lib/src/{options.js → idl/keywords.js} +7 -3
  46. package/build/lib/src/idl/node.d.ts +233 -0
  47. package/build/lib/src/idl/node.js +103 -0
  48. package/build/lib/src/idl/stdlib.d.ts +34 -0
  49. package/build/lib/src/idl/stdlib.js +54 -0
  50. package/build/lib/src/idl/utils.d.ts +44 -0
  51. package/build/lib/src/idl/utils.js +215 -0
  52. package/build/lib/src/idl/visitors.d.ts +15 -0
  53. package/build/lib/src/idl/visitors.js +593 -0
  54. package/build/lib/src/index.d.ts +4 -2
  55. package/build/lib/src/index.js +5 -3
  56. package/build/lib/src/inputPaths.d.ts +11 -0
  57. package/build/lib/src/inputPaths.js +81 -0
  58. package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
  59. package/build/lib/src/languageSpecificKeywords.js +0 -5
  60. package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
  61. package/build/lib/src/peer-generation/Materialized.d.ts +8 -2
  62. package/build/lib/src/peer-generation/Materialized.js +24 -12
  63. package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -15
  64. package/build/lib/src/peer-generation/PeerLibrary.js +35 -215
  65. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
  66. package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
  67. package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
  68. package/build/lib/src/peer-generation/idl/common.js +7 -7
  69. package/build/lib/src/peer-generation/isMaterialized.js +2 -3
  70. package/build/lib/src/peer-generation/modules.js +2 -0
  71. package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
  72. package/build/lib/src/peer-generation/toDeclaration.js +53 -0
  73. package/build/lib/src/peer-generation/unions.d.ts +1 -1
  74. package/build/lib/src/peer-generation/unions.js +15 -7
  75. package/build/lib/src/resolveNamedNode.d.ts +1 -0
  76. package/build/lib/src/resolveNamedNode.js +7 -0
  77. package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
  78. package/build/lib/src/transformers/FqnTransformer.js +20 -12
  79. package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
  80. package/build/lib/src/transformers/GenericTransformer.js +252 -158
  81. package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
  82. package/build/lib/src/transformers/IdlTransformer.js +7 -0
  83. package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
  84. package/build/lib/src/transformers/NullTransformer.js +27 -21
  85. package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
  86. package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
  87. package/build/lib/src/util.d.ts +5 -0
  88. package/build/lib/src/util.js +25 -0
  89. package/package.json +6 -7
  90. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
  91. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
  92. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -85
  93. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -306
  94. package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
  95. package/build/lib/src/from-idl/webidl2-utils.js +0 -87
  96. package/build/lib/src/idl.d.ts +0 -444
  97. package/build/lib/src/idl.js +0 -1385
  98. package/build/lib/src/idlize.d.ts +0 -25
  99. package/build/lib/src/idlize.js +0 -198
  100. package/build/lib/src/options.d.ts +0 -13
  101. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
  102. package/build/lib/src/peer-generation/BuilderClass.js +0 -68
  103. package/webidl2.js/dist/webidl2.js +0 -4622
  104. package/webidl2.js/package.json +0 -55
@@ -36,7 +36,7 @@ export class Language {
36
36
  }
37
37
  Language.TS = new Language("TS", ".ts");
38
38
  Language.ARKTS = new Language("ArkTS", ".ts"); // using .ts for ArkTS until we get rit of tsc preprocessing
39
- Language.CPP = new Language("C++", ".cc");
39
+ Language.CPP = new Language("C++", ".cpp");
40
40
  Language.CJ = new Language("CangJie", ".cj");
41
41
  Language.KOTLIN = new Language("Kotlin", ".kt");
42
42
  //# sourceMappingURL=Language.js.map
@@ -1,12 +1,11 @@
1
1
  import * as idl from "../idl";
2
2
  import { Language } from "../Language";
3
- import { ExpressionAssigner, LanguageExpression, LanguageStatement, LanguageWriter, Method } from "./LanguageWriter";
3
+ import { BranchStatement, ExpressionAssigner, LanguageExpression, LanguageStatement, LanguageWriter } from "./LanguageWriter";
4
4
  import { NativeModuleType, RuntimeType } from "./common";
5
5
  import { LibraryInterface } from "../LibraryInterface";
6
6
  import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
7
7
  import { PeerLibrary } from "../peer-generation/PeerLibrary";
8
- import { PeerMethodSignature } from "../peer-generation/PeerMethod";
9
- export declare function getSerializerName(library: LibraryInterface, language: Language, declaration: idl.IDLEntry): string;
8
+ export declare function getSerializerName(_library: LibraryInterface, _language: Language, declaration: idl.IDLEntry): string;
10
9
  export interface ArgConvertor {
11
10
  param: string;
12
11
  idlType: idl.IDLType;
@@ -26,9 +25,6 @@ export interface ArgConvertor {
26
25
  getMembers(): string[];
27
26
  getObjectAccessor(languge: Language, value: string, args?: Record<string, string>, writer?: LanguageWriter): string;
28
27
  }
29
- export declare function isDirectConvertedType(originalType: idl.IDLType | undefined, library: PeerLibrary): boolean;
30
- export declare function isVMContextMethod(method: Method | PeerMethodSignature): boolean;
31
- export declare function isDirectMethod(method: Method, library: PeerLibrary): boolean;
32
28
  export declare abstract class BaseArgConvertor implements ArgConvertor {
33
29
  idlType: idl.IDLType;
34
30
  runtimeTypes: RuntimeType[];
@@ -278,6 +274,13 @@ export declare class OptionConvertor extends BaseArgConvertor {
278
274
  isPointerType(): boolean;
279
275
  getObjectAccessor(language: Language, value: string, args?: Record<string, string>): string;
280
276
  }
277
+ declare class ConvertorItem {
278
+ convertor: ArgConvertor;
279
+ index: number;
280
+ type: idl.IDLType;
281
+ elemName?: string | undefined;
282
+ constructor(convertor: ArgConvertor, index: number, type: idl.IDLType, elemName?: string | undefined);
283
+ }
281
284
  export declare class UnionConvertor extends BaseArgConvertor {
282
285
  private library;
283
286
  private type;
@@ -285,7 +288,13 @@ export declare class UnionConvertor extends BaseArgConvertor {
285
288
  private unionChecker;
286
289
  constructor(library: LibraryInterface, param: string, type: idl.IDLUnionType);
287
290
  convertorArg(param: string, writer: LanguageWriter): string;
291
+ isSequence(type: idl.IDLType): boolean;
292
+ isIndexedDiscriminator(writer: LanguageWriter): boolean;
288
293
  convertorSerialize(param: string, value: string, printer: LanguageWriter): LanguageStatement;
294
+ makeStoreSelector(param: string, index: number, printer: LanguageWriter): LanguageStatement;
295
+ makeBranch(param: string, value: string, printer: LanguageWriter, convertorItem: ConvertorItem): BranchStatement;
296
+ makeArrayBranch(param: string, value: string, printer: LanguageWriter, arrayConvertorItems: ConvertorItem[]): BranchStatement[];
297
+ convertorSerializeMultiBranch(param: string, value: string, printer: LanguageWriter, convertors: ConvertorItem[]): LanguageStatement;
289
298
  convertorDeserialize(bufferName: string, deserializerName: string, assigneer: ExpressionAssigner, writer: LanguageWriter): LanguageStatement;
290
299
  nativeType(): idl.IDLType;
291
300
  interopType(): idl.IDLType;
@@ -357,4 +366,5 @@ export declare class TransformOnSerializeConvertor extends BaseArgConvertor {
357
366
  convertorDeserialize(bufferName: string, deserializerName: string, assigneer: ExpressionAssigner, writer: LanguageWriter): LanguageStatement;
358
367
  }
359
368
  export declare function createOutArgConvertor(library: PeerLibrary, type: idl.IDLType | undefined, otherParams: string[]): ArgConvertor | undefined;
369
+ export {};
360
370
  //# sourceMappingURL=ArgConvertors.d.ts.map
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import * as idl from "../idl";
16
16
  import { Language } from "../Language";
17
- import { BlockStatement, PrintHint, StringExpression, MethodModifier, NamedMethodSignature, ProxyStatement, ExpressionStatement } from "./LanguageWriter";
17
+ import { BlockStatement, PrintHint, StringExpression, NamedMethodSignature, ProxyStatement, ExpressionStatement } from "./LanguageWriter";
18
18
  import { RuntimeType } from "./common";
19
19
  import { generatorConfiguration, generatorTypePrefix } from "../config";
20
20
  import { capitalize, getExtractor, getTransformer, hashCodeFromString, throwException, warn } from "../util";
@@ -22,77 +22,9 @@ import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
22
22
  import { CppConvertor, CppNameConvertor } from "./convertors/CppConvertors";
23
23
  import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
24
24
  import { LayoutNodeRole } from "../peer-generation/LayoutManager";
25
- import { PeerMethodSignature } from "../peer-generation/PeerMethod";
26
25
  import { isInExternalModule } from "../peer-generation/modules";
27
- import { isTopLevelConflicted } from "../peer-generation/ConflictingDeclarations";
28
- export function getSerializerName(library, language, declaration) {
29
- const qualifier = isTopLevelConflicted(library, language, declaration)
30
- ? "package.namespace.name" : "namespace.name";
31
- return `${idl.getQualifiedName(declaration, qualifier).split('.').join('_')}_serializer`;
32
- }
33
- export function isDirectConvertedType(originalType, library) {
34
- const debug = false;
35
- if (originalType == undefined)
36
- return true; // TODO: is it correct?
37
- if (debug)
38
- console.log(`IDL type ${idl.DebugUtils.debugPrintType(originalType)}`);
39
- if (originalType == idl.IDLInteropReturnBufferType)
40
- return false;
41
- if (originalType == idl.IDLThisType)
42
- return true; /* Because this type for native is pointer, right? */
43
- if (originalType == idl.IDLSerializerBuffer)
44
- return true;
45
- let convertor = library.typeConvertor("x", originalType, false);
46
- // Resolve aliases.
47
- while (convertor instanceof TypeAliasConvertor) {
48
- convertor = convertor.convertor;
49
- }
50
- if (convertor instanceof ArrayConvertor ||
51
- convertor instanceof CustomTypeConvertor ||
52
- convertor instanceof UnionConvertor ||
53
- convertor instanceof CallbackConvertor ||
54
- convertor instanceof MapConvertor ||
55
- convertor instanceof TupleConvertor ||
56
- convertor instanceof AggregateConvertor ||
57
- convertor instanceof OptionConvertor ||
58
- convertor instanceof ImportTypeConvertor) {
59
- // try { console.log(`convertor is ${convertor.constructor.name} for ${JSON.stringify(originalType)}`) } catch (e) {}
60
- return false;
61
- }
62
- let type = convertor.interopType();
63
- if (debug)
64
- console.log(`converted type ${idl.DebugUtils.debugPrintType(originalType)}`);
65
- let result = type == idl.IDLI8Type || type == idl.IDLU8Type
66
- || type == idl.IDLI16Type || type == idl.IDLU16Type
67
- || type == idl.IDLI32Type || type == idl.IDLU32Type
68
- || type == idl.IDLF32Type
69
- || type == idl.IDLI64Type || type == idl.IDLU64Type
70
- || type == idl.IDLPointerType
71
- || type == idl.IDLBooleanType
72
- || type == idl.IDLVoidType
73
- || type == idl.IDLUndefinedType
74
- || type == idl.IDLSerializerBuffer
75
- || type == idl.IDLNumberType;
76
- if (!result && debug)
77
- console.log(`type ${idl.DebugUtils.debugPrintType(type)} is not direct`);
78
- return result;
79
- }
80
- export function isVMContextMethod(method) {
81
- var _a, _b;
82
- const isPromise = !!idl.asPromise(method instanceof PeerMethodSignature ? method.returnType : method.signature.returnType);
83
- return isPromise ||
84
- !!((_a = method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.THROWS)) ||
85
- !!((_b = method.modifiers) === null || _b === void 0 ? void 0 : _b.includes(MethodModifier.FORCE_CONTEXT)) ||
86
- generatorConfiguration().forceContext.includes(method.name);
87
- }
88
- export function isDirectMethod(method, library) {
89
- if (isVMContextMethod(method)) {
90
- return false;
91
- }
92
- let result = isDirectConvertedType(method.signature.returnType, library) &&
93
- method.signature.args.every((arg) => isDirectConvertedType(arg, library));
94
- // if (!result) console.log(`method ${method.name} is not direct`)
95
- return result;
26
+ export function getSerializerName(_library, _language, declaration) {
27
+ return `${idl.getQualifiedName(declaration, "package.namespace.name").split('.').map(capitalize).join('')}SerializerImpl`;
96
28
  }
97
29
  export class BaseArgConvertor {
98
30
  constructor(idlType, runtimeTypes, isScoped, useArray, param) {
@@ -370,7 +302,7 @@ export class ObjectConvertor extends BaseArgConvertor {
370
302
  return assigneer(writer.makeCast(writer.makeMethodCall(deserializerName, 'readObject', []), this.idlType, { optional: false }));
371
303
  }
372
304
  holdResource(name, holder, writer) {
373
- writer.writeStatement(writer.makeAssign(name, idl.createReferenceType(`CallbackResource`), writer.makeString(`{${this.param}.resource.resourceId, holdManagedCallbackResource, releaseManagedCallbackResource}`), true));
305
+ writer.writeStatement(writer.makeAssign(name, idl.createReferenceType(`idlize.stdlib.CallbackResource`), writer.makeString(`{${this.param}.resource.resourceId, holdManagedCallbackResource, releaseManagedCallbackResource}`), true));
374
306
  writer.writeExpressionStatement(writer.makeMethodCall(holder, 'holdCallbackResource', [
375
307
  writer.makeString('&' + name)
376
308
  ]));
@@ -543,8 +475,8 @@ export class TupleConvertor extends AggregateConvertor {
543
475
  convertorSerialize(param, value, printer) {
544
476
  const stmts = this.memberConvertors.flatMap((it, index) => {
545
477
  return [
546
- printer.makeAssign(`${value}_${index}`, undefined, printer.makeTupleAccess(value, index), true),
547
- it.convertorSerialize(param, `${value}_${index}`, printer)
478
+ printer.makeAssign(`${value}N${index}`, undefined, printer.makeTupleAccess(value, index), true),
479
+ it.convertorSerialize(param, `${value}N${index}`, printer)
548
480
  ];
549
481
  });
550
482
  return printer.makeBlock(stmts, false);
@@ -884,7 +816,7 @@ export class OptionConvertor extends BaseArgConvertor {
884
816
  throw new Error("Must never be used");
885
817
  }
886
818
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
887
- const runtimeBufferName = `${bufferName}_runtimeType`;
819
+ const runtimeBufferName = `${bufferName}RuntimeType`;
888
820
  const statements = [];
889
821
  statements.push(writer.makeAssign(runtimeBufferName, undefined, writer.makeCast(writer.makeString(`${deserializerName}.readInt8()`), writer.getRuntimeType()), true));
890
822
  const bufferType = this.nativeType();
@@ -914,6 +846,14 @@ export class OptionConvertor extends BaseArgConvertor {
914
846
  return language === Language.CPP ? `${value}.value` : value;
915
847
  }
916
848
  }
849
+ class ConvertorItem {
850
+ constructor(convertor, index, type, elemName) {
851
+ this.convertor = convertor;
852
+ this.index = index;
853
+ this.type = type;
854
+ this.elemName = elemName;
855
+ }
856
+ }
917
857
  export class UnionConvertor extends BaseArgConvertor {
918
858
  constructor(library, param, type) {
919
859
  super(idl.IDLObjectType, [], false, true, param);
@@ -927,20 +867,68 @@ export class UnionConvertor extends BaseArgConvertor {
927
867
  convertorArg(param, writer) {
928
868
  throw new Error("Do not use for union");
929
869
  }
870
+ isSequence(type) {
871
+ return idl.isContainerType(type) && idl.IDLContainerUtils.isSequence(type);
872
+ }
873
+ isIndexedDiscriminator(writer) {
874
+ // Indexed discriminator is only used in CPP
875
+ // All other languages check the first array element type for arrays discrimination
876
+ if (writer.language == Language.CPP)
877
+ return true;
878
+ return false;
879
+ }
930
880
  convertorSerialize(param, value, printer) {
931
- const branches = this.memberConvertors.map((it, index) => {
932
- const discriminator = this.unionChecker.makeDiscriminator(value, index, printer);
933
- const statements = [];
934
- statements.push(printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, "writeInt8", [printer.makeString(printer.castToInt(index.toString(), 8))])));
935
- if (!(it instanceof UndefinedConvertor)) {
936
- const varName = `${value}ForIdx${index}`;
937
- statements.push(printer.makeAssign(varName, undefined, printer.makeUnionVariantCast(it.getObjectAccessor(printer.language, value), printer.getNodeName(it.idlType), it, index), true));
938
- statements.push(it.convertorSerialize(param, varName, printer));
939
- }
940
- const stmt = new BlockStatement(statements, false);
941
- return { expr: discriminator, stmt };
942
- });
943
- return printer.makeMultiBranchCondition(branches);
881
+ const convertorItems = this.memberConvertors.map((it, index) => new ConvertorItem(it, index, it.idlType));
882
+ if (this.isIndexedDiscriminator(printer))
883
+ return printer.makeMultiBranchCondition(convertorItems.map(it => this.makeBranch(param, value, printer, it)));
884
+ // Make arrays type descrimination
885
+ return this.convertorSerializeMultiBranch(param, value, printer, convertorItems);
886
+ }
887
+ makeStoreSelector(param, index, printer) {
888
+ return printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, "writeInt8", [printer.makeString(printer.castToInt(index.toString(), 8))]));
889
+ }
890
+ makeBranch(param, value, printer, convertorItem) {
891
+ var _a;
892
+ const convertor = convertorItem.convertor;
893
+ const index = convertorItem.index;
894
+ const type = convertorItem.type;
895
+ const discriminator = this.unionChecker.makeDiscriminator((_a = convertorItem.elemName) !== null && _a !== void 0 ? _a : value, index, printer, this.library, type);
896
+ const statements = [];
897
+ statements.push(this.makeStoreSelector(param, index, printer));
898
+ if (!(convertor instanceof UndefinedConvertor)) {
899
+ const varName = `${value}ForIdx${index}`;
900
+ statements.push(printer.makeAssign(varName, undefined, printer.makeUnionVariantCast(convertor.getObjectAccessor(printer.language, value), printer.getNodeName(convertor.idlType), convertor, index), true));
901
+ statements.push(convertor.convertorSerialize(param, varName, printer));
902
+ }
903
+ const stmt = new BlockStatement(statements, false);
904
+ return { expr: discriminator, stmt };
905
+ }
906
+ makeArrayBranch(param, value, printer, arrayConvertorItems) {
907
+ if (arrayConvertorItems.length == 0)
908
+ return [];
909
+ const arrayConvertorItem = arrayConvertorItems[0];
910
+ const elemName = `${value}Elem`;
911
+ const elemAccess = printer.makeString(`${value}[0]`);
912
+ const checkZeroArray = printer.makeCondition(printer.makeString(`${value}.length == 0`), new BlockStatement([
913
+ this.makeStoreSelector(param, arrayConvertorItem.index, printer),
914
+ printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, "writeInt32", [printer.makeString("0")]))
915
+ ], true, false), new BlockStatement([
916
+ printer.makeAssign(elemName, undefined, elemAccess, true, true),
917
+ this.convertorSerializeMultiBranch(param, value, printer, arrayConvertorItems.map(it => new ConvertorItem(it.convertor, it.index, it.type.elementType[0], elemName)))
918
+ ], true, false));
919
+ const arrayMultiBranch = {
920
+ expr: this.unionChecker.makeDiscriminator(value, arrayConvertorItems[0].index, printer, this.library, arrayConvertorItem.type),
921
+ stmt: checkZeroArray
922
+ };
923
+ return [arrayMultiBranch];
924
+ }
925
+ convertorSerializeMultiBranch(param, value, printer, convertors) {
926
+ return printer.makeMultiBranchCondition([
927
+ ...convertors
928
+ .filter(it => !this.isSequence(it.type))
929
+ .map(it => this.makeBranch(param, value, printer, it)),
930
+ ...this.makeArrayBranch(param, value, printer, convertors.filter(it => this.isSequence(it.type)))
931
+ ]);
944
932
  }
945
933
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
946
934
  const statements = [];
@@ -985,7 +973,7 @@ export class UnionConvertor extends BaseArgConvertor {
985
973
  return language === Language.CPP && (args === null || args === void 0 ? void 0 : args.index) ? `${value}.value${args.index}` : value;
986
974
  }
987
975
  unionDiscriminator(value, index, writer, duplicates) {
988
- return writer.makeNaryOp("||", this.memberConvertors.map((_, n) => this.unionChecker.makeDiscriminator(value, n, writer)));
976
+ return writer.makeNaryOp("||", this.memberConvertors.map((_, n) => this.unionChecker.makeDiscriminator(value, n, writer, this.library)));
989
977
  }
990
978
  }
991
979
  export class FunctionConvertor extends BaseArgConvertor {
@@ -1145,7 +1133,7 @@ export class CallbackConvertor extends BaseArgConvertor {
1145
1133
  const continuationValueName = bufferName + "BufContinuationValue";
1146
1134
  const continuationCallbackName = bufferName + "BufContinuationCallback";
1147
1135
  const statements = [];
1148
- statements.push(writer.makeAssign(resourceName, idl.createReferenceType("CallbackResource"), writer.makeMethodCall(deserializerName, 'readCallbackResource', []), true));
1136
+ statements.push(writer.makeAssign(resourceName, idl.createReferenceType("idlize.stdlib.CallbackResource"), writer.makeMethodCall(deserializerName, 'readCallbackResource', []), true));
1149
1137
  statements.push(writer.makeAssign(callName, idl.IDLPointerType, writer.makeMethodCall(deserializerName, `readPointer`, []), true));
1150
1138
  statements.push(writer.makeAssign(callSyncName, idl.IDLPointerType, writer.makeMethodCall(deserializerName, 'readPointer', []), true));
1151
1139
  const callbackSignature = new NamedMethodSignature(this.decl.returnType, this.decl.parameters.map(it => idl.maybeOptional(it.type, it.isOptional)), this.decl.parameters.map(it => it.name));
@@ -1171,7 +1159,7 @@ export class CallbackConvertor extends BaseArgConvertor {
1171
1159
  ];
1172
1160
  }
1173
1161
  const result = writer.makeLambda(callbackSignature, [
1174
- writer.makeAssign(`${argsSerializer}Serializer`, idl.createReferenceType('SerializerBase'), writer.makeMethodCall('SerializerBase', 'hold', []), true),
1162
+ writer.makeAssign(`${argsSerializer}Serializer`, idl.createReferenceType('idlize.internal.SerializerBase'), writer.makeMethodCall('SerializerBase', 'hold', []), true),
1175
1163
  new ExpressionStatement(writer.makeMethodCall(`${argsSerializer}Serializer`, `writeInt32`, [writer.makeString(`${resourceName}.resourceId`)])),
1176
1164
  new ExpressionStatement(writer.makeMethodCall(`${argsSerializer}Serializer`, `writePointer`, [writer.makeString(callName)])),
1177
1165
  new ExpressionStatement(writer.makeMethodCall(`${argsSerializer}Serializer`, `writePointer`, [writer.makeString(callSyncName)])),
@@ -1254,7 +1242,7 @@ export function generateCallbackAPIArguments(library, callback) {
1254
1242
  }
1255
1243
  export function maybeTransformManagedCallback(callback, library) {
1256
1244
  if (callback.name === "CustomBuilder")
1257
- return library.resolveTypeReference(idl.createReferenceType("CustomNodeBuilder"));
1245
+ return library.resolveTypeReference(idl.createReferenceType("arkui.component.idlize.CustomNodeBuilder"));
1258
1246
  return undefined;
1259
1247
  }
1260
1248
  class PromiseOutArgConvertor extends BaseArgConvertor {
@@ -109,6 +109,12 @@ export declare class MultiBranchIfStatement implements LanguageStatement {
109
109
  constructor(statements: BranchStatement[], elseStatement: LanguageStatement | undefined);
110
110
  write(writer: LanguageWriter): void;
111
111
  }
112
+ export type EnumMember = {
113
+ name: string;
114
+ alias?: string;
115
+ stringId: string | undefined;
116
+ numberId: number;
117
+ };
112
118
  export declare class TsEnumEntityStatement implements LanguageStatement {
113
119
  private readonly enumEntity;
114
120
  private readonly options;
@@ -117,7 +123,6 @@ export declare class TsEnumEntityStatement implements LanguageStatement {
117
123
  isDeclare: boolean;
118
124
  });
119
125
  write(writer: LanguageWriter): void;
120
- private maybeQuoted;
121
126
  }
122
127
  export declare class ReturnStatement implements LanguageStatement {
123
128
  expression?: LanguageExpression | undefined;
@@ -150,6 +155,7 @@ export declare enum FieldModifier {
150
155
  GET = 9,
151
156
  SET = 10
152
157
  }
158
+ export declare const ACCESS_MODIFIERS_SET: Set<FieldModifier>;
153
159
  export declare enum MethodModifier {
154
160
  PUBLIC = 0,
155
161
  PRIVATE = 1,
@@ -258,12 +264,7 @@ export declare abstract class LanguageWriter {
258
264
  addFeature(feature: string, module: string): void;
259
265
  abstract get interopModule(): string;
260
266
  abstract writeClass(name: string, op: (writer: this) => void, superClass?: string, interfaces?: string[], generics?: string[], isDeclared?: boolean, isExport?: boolean): void;
261
- abstract writeEnum(name: string, members: {
262
- name: string;
263
- alias?: string;
264
- stringId: string | undefined;
265
- numberId: number;
266
- }[], options: {
267
+ abstract writeEnum(name: string, members: EnumMember[], options: {
267
268
  isExport: boolean;
268
269
  isDeclare?: boolean;
269
270
  }, op?: (writer: this) => void): void;
@@ -12,9 +12,12 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
+ import { Language } from "../Language";
15
16
  import * as idl from "../idl";
16
17
  import * as fs from "fs";
17
18
  import { RuntimeType } from "./common";
19
+ import { convertDeclaration, withInsideInstanceof } from "./nameConvertor";
20
+ import { createDeclarationNameConvertor } from "../peer-generation/idl/IdlNameConvertor";
18
21
  export class TernaryExpression {
19
22
  constructor(condition, trueExpression, falseExpression) {
20
23
  this.condition = condition;
@@ -234,28 +237,33 @@ export class TsEnumEntityStatement {
234
237
  this.options = options;
235
238
  }
236
239
  write(writer) {
237
- // writer.print(this.enumEntity.comment)
238
- writer.print(`${this.options.isExport ? "export " : ""}${this.options.isDeclare ? "declare " : ""}enum ${this.enumEntity.name} {`);
239
- writer.pushIndent();
240
+ let enumName = convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), this.enumEntity);
241
+ enumName = enumName.split('.').at(-1);
242
+ const correctStyleNames = [];
243
+ const originalStyleNames = [];
240
244
  this.enumEntity.elements.forEach((member, index) => {
241
- // writer.print(member.comment)
242
- const initValue = member.initializer
243
- ? ` = ${this.maybeQuoted(member.initializer)}` : ``;
244
- writer.print(`${member.name}${initValue},`);
245
- let originalName = idl.getExtAttribute(member, idl.IDLExtendedAttributes.OriginalEnumMemberName);
246
- if (originalName) {
247
- const initValue = ` = ${member.name}`;
248
- writer.print(`${originalName}${initValue},`);
249
- }
245
+ var _a;
246
+ const initText = (_a = member.initializer) !== null && _a !== void 0 ? _a : index;
247
+ const isTypeString = typeof initText !== "number";
248
+ const originalName = idl.getExtAttribute(member, idl.IDLExtendedAttributes.OriginalEnumMemberName);
249
+ correctStyleNames.push({
250
+ name: originalName ? member.name : `${member.name}_DUMMY`,
251
+ alias: undefined,
252
+ stringId: isTypeString ? initText : undefined,
253
+ numberId: initText
254
+ });
255
+ originalStyleNames.push({
256
+ name: originalName !== null && originalName !== void 0 ? originalName : member.name,
257
+ alias: undefined,
258
+ stringId: isTypeString ? initText : undefined,
259
+ numberId: initText
260
+ });
250
261
  });
251
- writer.popIndent();
252
- writer.print(`}`);
253
- }
254
- maybeQuoted(value) {
255
- if (typeof value == "string")
256
- return `"${value}"`;
257
- else
258
- return `${value}`;
262
+ let members = originalStyleNames;
263
+ if (this.enumEntity.elements.some(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.OriginalEnumMemberName))) {
264
+ members = members.concat(correctStyleNames);
265
+ }
266
+ writer.writeEnum(enumName, members, { isExport: this.options.isExport, isDeclare: this.options.isDeclare });
259
267
  }
260
268
  }
261
269
  export class ReturnStatement {
@@ -310,6 +318,11 @@ export var FieldModifier;
310
318
  FieldModifier[FieldModifier["GET"] = 9] = "GET";
311
319
  FieldModifier[FieldModifier["SET"] = 10] = "SET";
312
320
  })(FieldModifier || (FieldModifier = {}));
321
+ export const ACCESS_MODIFIERS_SET = new Set([
322
+ FieldModifier.PRIVATE,
323
+ FieldModifier.PROTECTED,
324
+ FieldModifier.PUBLIC
325
+ ]);
313
326
  export var MethodModifier;
314
327
  (function (MethodModifier) {
315
328
  MethodModifier[MethodModifier["PUBLIC"] = 0] = "PUBLIC";
@@ -685,11 +698,11 @@ export class LanguageWriter {
685
698
  op(this);
686
699
  }
687
700
  instanceOf(value, type) {
688
- return this.makeString(`${value} instanceof ${this.getNodeName(type)}`);
701
+ return this.makeString(`${value} instanceof ${withInsideInstanceof(true, () => this.getNodeName(type))}`);
689
702
  }
690
703
  // The version of instanceOf() which does not use ArgConvertors
691
704
  typeInstanceOf(type, value, members) {
692
- return this.makeString(`${value} instanceof ${this.getNodeName(type)}`);
705
+ return this.makeString(`${value} instanceof ${withInsideInstanceof(true, () => this.getNodeName(type))}`);
693
706
  }
694
707
  /**
695
708
  * Writes `namespace <namespace> {` and adds extra indent
@@ -14,4 +14,5 @@ export declare class NativeModuleType {
14
14
  name: string;
15
15
  constructor(name: string);
16
16
  }
17
+ export declare const InteropModuleType: NativeModuleType;
17
18
  //# sourceMappingURL=common.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
2
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3
3
  * Licensed under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License.
5
5
  * You may obtain a copy of the License at
@@ -30,4 +30,5 @@ export class NativeModuleType {
30
30
  this.name = name;
31
31
  }
32
32
  }
33
+ export const InteropModuleType = new NativeModuleType("InteropNativeModule");
33
34
  //# sourceMappingURL=common.js.map
@@ -10,7 +10,7 @@ export interface ConvertResult {
10
10
  export declare class GenericCppConvertor implements NodeConvertor<ConvertResult> {
11
11
  protected library: LibraryInterface;
12
12
  constructor(library: LibraryInterface);
13
- private make;
13
+ protected make(text: string, resolvedType: idl.IDLType, noPrefix?: boolean): ConvertResult;
14
14
  convertNode(node: idl.IDLNode): ConvertResult;
15
15
  convertNamespace(node: idl.IDLNamespace): ConvertResult;
16
16
  convertInterface(node: idl.IDLInterface): ConvertResult;
@@ -29,6 +29,8 @@ export declare class GenericCppConvertor implements NodeConvertor<ConvertResult>
29
29
  convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
30
30
  private qualifiedName;
31
31
  private computeTargetTypeLiteralName;
32
+ protected isInsideStructure: boolean;
33
+ protected insideStructure<T>(cb: () => T): T;
32
34
  }
33
35
  export declare class CppConvertor extends GenericCppConvertor implements IdlNameConvertor {
34
36
  private unwrap;
@@ -41,6 +43,10 @@ export declare class CppNameConvertor implements IdlNameConvertor {
41
43
  constructor(library: LibraryInterface);
42
44
  convert(node: idl.IDLNode): string;
43
45
  }
46
+ export declare class StructureNameConvertor extends CppConvertor {
47
+ constructor(library: LibraryInterface);
48
+ convert(node: idl.IDLNode): string;
49
+ }
44
50
  export declare class CppInteropArgConvertor extends InteropArgConvertor {
45
51
  static INSTANCE: CppInteropArgConvertor;
46
52
  convertOptional(type: idl.IDLOptionalType): string;
@@ -37,6 +37,7 @@ function isSubtypeTopLevelConflicted(library, node) {
37
37
  export class GenericCppConvertor {
38
38
  constructor(library) {
39
39
  this.library = library;
40
+ this.isInsideStructure = false;
40
41
  }
41
42
  make(text, resolvedType, noPrefix = false) {
42
43
  return { text, noPrefix, resolvedType };
@@ -90,28 +91,29 @@ export class GenericCppConvertor {
90
91
  return this.make(prefix + converted.text, type, true);
91
92
  }
92
93
  convertUnion(type) {
93
- if (isSubtypeTopLevelConflicted(this.library, type)) {
94
+ return this.insideStructure(() => {
94
95
  if (type.parent && idl.isTypedef(type.parent)) {
95
96
  return this.make(type.parent.name, type, false);
96
97
  }
97
98
  return this.make('Union_' + type.types.map(it => convertType(this, it).text).join("_"), type, false);
98
- }
99
- return this.make(type.name, type, false);
99
+ });
100
100
  }
101
101
  convertContainer(type) {
102
- if (idl.IDLContainerUtils.isPromise(type)) {
103
- return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`, type);
104
- }
105
- if (idl.IDLContainerUtils.isSequence(type)) {
106
- if (type.elementType[0] === idl.IDLU8Type) {
107
- return this.make(`uint8_t*`, type, true);
102
+ return this.insideStructure(() => {
103
+ if (idl.IDLContainerUtils.isPromise(type)) {
104
+ return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`, type);
108
105
  }
109
- return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, type, true);
110
- }
111
- if (idl.IDLContainerUtils.isRecord(type)) {
112
- return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, type, true);
113
- }
114
- throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
106
+ if (idl.IDLContainerUtils.isSequence(type)) {
107
+ if (type.elementType[0] === idl.IDLU8Type) {
108
+ return this.make(`uint8_t*`, type, true);
109
+ }
110
+ return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, type, true);
111
+ }
112
+ if (idl.IDLContainerUtils.isRecord(type)) {
113
+ return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, type, true);
114
+ }
115
+ throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
116
+ });
115
117
  }
116
118
  convertImport(type) {
117
119
  console.warn("Imports are not implemented yet");
@@ -142,6 +144,26 @@ export class GenericCppConvertor {
142
144
  return this.make('CustomObject', idl.IDLCustomObjectType);
143
145
  }
144
146
  convertPrimitiveType(type) {
147
+ if (this.isInsideStructure) {
148
+ switch (type) {
149
+ case idl.IDLVoidType:
150
+ return this.make(`Void`, type);
151
+ case idl.IDLI32Type:
152
+ return this.make('I32', type);
153
+ case idl.IDLU32Type:
154
+ return this.make('U32', type);
155
+ case idl.IDLF32Type:
156
+ return this.make('F32', type);
157
+ case idl.IDLI64Type:
158
+ return this.make('I64', type);
159
+ case idl.IDLU64Type:
160
+ return this.make('U64', type);
161
+ case idl.IDLF64Type:
162
+ return this.make('F64', type);
163
+ case idl.IDLPointerType:
164
+ return this.make('Pointer', type);
165
+ }
166
+ }
145
167
  switch (type) {
146
168
  case idl.IDLThisType: // maybe fix it in another level?
147
169
  case idl.IDLVoidType: return this.make('void', type, true);
@@ -190,6 +212,13 @@ export class GenericCppConvertor {
190
212
  const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
191
213
  return `Literal_${names.join('_')}`;
192
214
  }
215
+ insideStructure(cb) {
216
+ const prevIsInsideScructure = this.isInsideStructure;
217
+ this.isInsideStructure = true;
218
+ const result = cb();
219
+ this.isInsideStructure = prevIsInsideScructure;
220
+ return result;
221
+ }
193
222
  }
194
223
  export class CppConvertor extends GenericCppConvertor {
195
224
  unwrap(type, result) {
@@ -234,6 +263,15 @@ export class CppNameConvertor {
234
263
  return this.cppConvertor.convertNode(node).text;
235
264
  }
236
265
  }
266
+ export class StructureNameConvertor extends CppConvertor {
267
+ constructor(library) {
268
+ super(library);
269
+ this.isInsideStructure = true;
270
+ }
271
+ convert(node) {
272
+ return this.convertNode(node).text;
273
+ }
274
+ }
237
275
  export class CppInteropArgConvertor extends InteropArgConvertor {
238
276
  convertOptional(type) {
239
277
  return PrimitiveTypesInstance.NativePointer.getText();
@@ -10,5 +10,6 @@ export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
10
10
  protected mapFunctionType(typeArgs: string[]): string;
11
11
  }
12
12
  export declare class ETSInteropArgConvertor extends TSInteropArgConvertor {
13
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
13
14
  }
14
15
  //# sourceMappingURL=ETSConvertors.d.ts.map