@idlizer/core 2.1.5 → 2.1.9-arktscgen-4

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 (75) hide show
  1. package/build/lib/src/IndentedPrinter.js +2 -0
  2. package/build/lib/src/Language.d.ts +1 -0
  3. package/build/lib/src/Language.js +3 -0
  4. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -4
  5. package/build/lib/src/LanguageWriters/ArgConvertors.js +162 -26
  6. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +38 -8
  7. package/build/lib/src/LanguageWriters/LanguageWriter.js +46 -4
  8. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
  9. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +37 -14
  10. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
  11. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
  12. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
  13. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
  14. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
  15. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.d.ts +24 -0
  16. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.js +69 -0
  17. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +25 -0
  18. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +128 -0
  19. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
  20. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
  21. package/build/lib/src/LanguageWriters/index.js +4 -0
  22. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +12 -7
  23. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +43 -27
  24. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +1 -1
  25. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +11 -2
  26. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +43 -10
  27. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +5 -2
  28. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +45 -11
  29. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -2
  30. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -3
  31. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +149 -0
  32. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +495 -0
  33. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +8 -5
  34. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -13
  35. package/build/lib/src/LibraryInterface.d.ts +2 -0
  36. package/build/lib/src/config.d.ts +673 -44
  37. package/build/lib/src/config.js +20 -0
  38. package/build/lib/src/configDescriber.d.ts +2 -2
  39. package/build/lib/src/configDescriber.js +3 -3
  40. package/build/lib/src/from-idl/DtsPrinter.js +12 -8
  41. package/build/lib/src/from-idl/IDLLinter.d.ts +0 -1
  42. package/build/lib/src/from-idl/IDLLinter.js +1 -7
  43. package/build/lib/src/from-idl/deserialize.d.ts +7 -1
  44. package/build/lib/src/from-idl/deserialize.js +72 -40
  45. package/build/lib/src/idl.d.ts +8 -15
  46. package/build/lib/src/idl.js +69 -72
  47. package/build/lib/src/idlize.js +2 -0
  48. package/build/lib/src/index.d.ts +2 -0
  49. package/build/lib/src/index.js +2 -0
  50. package/build/lib/src/peer-generation/LayoutManager.d.ts +4 -1
  51. package/build/lib/src/peer-generation/LayoutManager.js +5 -1
  52. package/build/lib/src/peer-generation/Materialized.d.ts +7 -3
  53. package/build/lib/src/peer-generation/Materialized.js +18 -4
  54. package/build/lib/src/peer-generation/PeerLibrary.d.ts +5 -2
  55. package/build/lib/src/peer-generation/PeerLibrary.js +30 -10
  56. package/build/lib/src/peer-generation/PeerMethod.d.ts +1 -1
  57. package/build/lib/src/peer-generation/getSuperType.d.ts +5 -0
  58. package/build/lib/src/peer-generation/getSuperType.js +55 -0
  59. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +4 -0
  60. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +7 -0
  61. package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
  62. package/build/lib/src/peer-generation/idl/common.js +9 -3
  63. package/build/lib/src/peer-generation/isExternalType.d.ts +4 -0
  64. package/build/lib/src/peer-generation/isExternalType.js +15 -0
  65. package/build/lib/src/peer-generation/isMaterialized.js +18 -6
  66. package/build/lib/src/peer-generation/unions.js +1 -1
  67. package/build/lib/src/util.d.ts +4 -1
  68. package/build/lib/src/util.js +25 -10
  69. package/build/lib/src/visitor.d.ts +2 -0
  70. package/build/lib/src/visitor.js +108 -1
  71. package/package.json +2 -2
  72. package/webidl2.js/dist/webidl2.js +62 -16
  73. package/webidl2.js/LICENSE +0 -21
  74. package/webidl2.js/README.md +0 -827
  75. package/webidl2.js/dist/package.json +0 -3
@@ -73,6 +73,18 @@ export class MethodCallExpression extends FunctionCallExpression {
73
73
  return `${this.receiver}${this.nullable ? "?" : ""}.${super.asString()}`;
74
74
  }
75
75
  }
76
+ export class MethodStaticCallExpression extends MethodCallExpression {
77
+ constructor(receiver, method, params, nullable = false) {
78
+ super(receiver, method, params, nullable);
79
+ this.receiver = receiver;
80
+ this.nullable = nullable;
81
+ }
82
+ }
83
+ export class ThisCallExpression extends FunctionCallExpression {
84
+ constructor(params) {
85
+ super("this", params);
86
+ }
87
+ }
76
88
  export class FieldAccessExpression {
77
89
  constructor(receiver, field, nullable = false) {
78
90
  this.receiver = receiver;
@@ -283,6 +295,9 @@ export class LambdaExpression {
283
295
  stmt.write(writer);
284
296
  }
285
297
  }
298
+ writer.features.forEach(([feature, module]) => {
299
+ this.originalWriter.addFeature(feature, module);
300
+ });
286
301
  return (this.body ? ((_a = this.body) === null || _a === void 0 ? void 0 : _a.length) > 1 ? '\n' : '' : '').concat(writer.getOutput()
287
302
  .filter(line => line !== "")
288
303
  .map(line => indentedBy(line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line};`, 1))
@@ -320,6 +335,7 @@ export var MethodModifier;
320
335
  MethodModifier[MethodModifier["THROWS"] = 8] = "THROWS";
321
336
  MethodModifier[MethodModifier["FREE"] = 9] = "FREE";
322
337
  MethodModifier[MethodModifier["FORCE_CONTEXT"] = 10] = "FORCE_CONTEXT";
338
+ MethodModifier[MethodModifier["OVERRIDE"] = 11] = "OVERRIDE";
323
339
  })(MethodModifier || (MethodModifier = {}));
324
340
  export var ClassModifier;
325
341
  (function (ClassModifier) {
@@ -327,6 +343,11 @@ export var ClassModifier;
327
343
  ClassModifier[ClassModifier["PRIVATE"] = 1] = "PRIVATE";
328
344
  ClassModifier[ClassModifier["PROTECTED"] = 2] = "PROTECTED";
329
345
  })(ClassModifier || (ClassModifier = {}));
346
+ export var DelegationType;
347
+ (function (DelegationType) {
348
+ DelegationType[DelegationType["THIS"] = 0] = "THIS";
349
+ DelegationType[DelegationType["SUPER"] = 1] = "SUPER";
350
+ })(DelegationType || (DelegationType = {}));
330
351
  export class Field {
331
352
  constructor(name, type, modifiers = []) {
332
353
  this.name = name;
@@ -355,6 +376,7 @@ PrintHint.AsPointer = new PrintHint('AsPointer');
355
376
  PrintHint.AsConstPointer = new PrintHint('AsConstPointer');
356
377
  PrintHint.AsValue = new PrintHint('AsValue');
357
378
  PrintHint.AsConstReference = new PrintHint('AsConstReference');
379
+ PrintHint.AsReference = new PrintHint('AsReference');
358
380
  export class MethodSignature {
359
381
  constructor(returnType, args, defaults = undefined, argsModifiers = undefined, printHints, argNames) {
360
382
  this.returnType = returnType;
@@ -410,11 +432,15 @@ export class LanguageWriter {
410
432
  this.resolver = resolver;
411
433
  this.language = language;
412
434
  this.namespaceStack = [];
435
+ this.features = [];
413
436
  }
414
437
  indentDepth() {
415
438
  return this.printer.indentDepth();
416
439
  }
417
440
  maybeSemicolon() { return ";"; }
441
+ addFeature(feature, module) {
442
+ this.features.push([feature, module]);
443
+ }
418
444
  // version of makeCast which uses TypeCheck.typeCast<T>(value) call for ETS language writer
419
445
  // Use it only if TypeChecker class is added as import to the generated file
420
446
  makeTypeCast(value, type, options) {
@@ -441,12 +467,17 @@ export class LanguageWriter {
441
467
  var _a;
442
468
  this.writeMethodImplementation(new Method(method.name, method.signature, [MethodModifier.SETTER].concat((_a = method.modifiers) !== null && _a !== void 0 ? _a : [])), op);
443
469
  }
470
+ // Deprecated
471
+ // Use instead declarationCall parameter in writeConstructorImplementation(...)
444
472
  writeSuperCall(params) {
445
473
  this.printer.print(`super(${params.join(", ")})${this.maybeSemicolon()}`);
446
474
  }
447
475
  writeMethodCall(receiver, method, params, nullable = false) {
448
476
  this.printer.print(`${receiver}${nullable ? "?" : ""}.${method}(${params.join(", ")})`);
449
477
  }
478
+ writeStaticMethodCall(receiver, method, params, nullable = false) {
479
+ this.writeMethodCall(receiver, method, params, nullable);
480
+ }
450
481
  writeStatement(stmt) {
451
482
  stmt.write(this);
452
483
  }
@@ -497,6 +528,14 @@ export class LanguageWriter {
497
528
  makeMethodCall(receiver, method, params, nullable) {
498
529
  return new MethodCallExpression(receiver, method, params, nullable);
499
530
  }
531
+ // Deprecated
532
+ // Use instead declarationCall parameter in writeConstructorImplementation(...) with DelegationType.THIS
533
+ makeThisCall(params) {
534
+ return new ThisCallExpression(params);
535
+ }
536
+ makeStaticMethodCall(receiver, method, params, nullable) {
537
+ return new MethodStaticCallExpression(receiver, method, params, nullable);
538
+ }
500
539
  makeFieldAccess(receiver, method, nullable) {
501
540
  return new FieldAccessExpression(receiver, method, nullable);
502
541
  }
@@ -678,6 +717,9 @@ export class LanguageWriter {
678
717
  makeCallIsObject(value) {
679
718
  return this.makeString(`typeof ${value} === "object"`);
680
719
  }
720
+ makeStaticBlock(op) {
721
+ op(this);
722
+ }
681
723
  instanceOf(convertor, value, _duplicateMembers) {
682
724
  return this.makeString(`${value} instanceof ${this.getNodeName(convertor.idlType)}`);
683
725
  }
@@ -694,17 +736,17 @@ export class LanguageWriter {
694
736
  * Writes `namespace <namespace> {` and adds extra indent
695
737
  * @param namespace Namespace to begin
696
738
  */
697
- pushNamespace(namespace, ident = true) {
739
+ pushNamespace(namespace, options) {
698
740
  this.print(`namespace ${namespace} {`);
699
- if (ident)
741
+ if (options.ident)
700
742
  this.pushIndent();
701
743
  }
702
744
  /**
703
745
  * Writes closing brace of namespace block and removes one level of indent
704
746
  */
705
- popNamespace(ident = true) {
747
+ popNamespace(options) {
706
748
  this.namespaceStack.pop();
707
- if (ident)
749
+ if (options.ident)
708
750
  this.popIndent();
709
751
  this.print(`}`);
710
752
  }
@@ -32,4 +32,5 @@ export declare class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvert
32
32
  export declare class CJInteropArgConvertor extends InteropArgConvertor {
33
33
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
34
34
  }
35
+ export declare function removePoints(s: string): string;
35
36
  //# sourceMappingURL=CJConvertors.d.ts.map
@@ -13,6 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import * as idl from '../../idl';
16
+ import { CJKeywords } from '../../languageSpecificKeywords';
16
17
  import { convertNode, convertType } from '../nameConvertor';
17
18
  import { InteropArgConvertor } from './InteropConvertors';
18
19
  export class CJTypeNameConvertor {
@@ -40,6 +41,12 @@ export class CJTypeNameConvertor {
40
41
  }
41
42
  if (idl.IDLContainerUtils.isRecord(type)) {
42
43
  const stringes = type.elementType.slice(0, 2).map(it => convertType(this, it));
44
+ if (idl.isReferenceType(type.elementType[0])) {
45
+ const keyValueType = this.resolver.resolveTypeReference(type.elementType[0]);
46
+ if (idl.isInterface(keyValueType) || idl.isEnum(keyValueType)) {
47
+ return `HashMap<Int64, ${stringes[1]}>`;
48
+ }
49
+ }
43
50
  return `HashMap<${stringes[0]}, ${stringes[1]}>`;
44
51
  }
45
52
  if (idl.IDLContainerUtils.isPromise(type)) {
@@ -48,19 +55,19 @@ export class CJTypeNameConvertor {
48
55
  throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
49
56
  }
50
57
  convertNamespace(node) {
51
- throw new Error('Method not implemented.');
58
+ return node.name;
52
59
  }
53
60
  convertInterface(node) {
54
- return node.name;
61
+ return removePoints(idl.getNamespaceName(node).concat(node.name));
55
62
  }
56
63
  convertEnum(node) {
57
- return node.name;
64
+ return removePoints(idl.getNamespaceName(node).concat(node.name));
58
65
  }
59
66
  convertTypedef(node) {
60
67
  return node.name;
61
68
  }
62
69
  convertCallback(type) {
63
- const params = type.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
70
+ const params = type.parameters.map(it => `${CJKeywords.has(it.name) ? it.name.concat("_") : it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
64
71
  return `(${params.join(", ")}) -> ${this.convert(type.returnType)}`;
65
72
  }
66
73
  convertMethod(node) {
@@ -74,15 +81,17 @@ export class CJTypeNameConvertor {
74
81
  return type.name;
75
82
  }
76
83
  convertTypeReferenceAsImport(type, importClause) {
77
- return type.name;
84
+ var _a;
85
+ const maybeTypeArguments = ((_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) ? `<${type.typeArguments.join(', ')}>` : "";
86
+ let decl = this.resolver.resolveTypeReference(type);
87
+ if (decl)
88
+ return `${decl.name}${maybeTypeArguments}`;
89
+ return this.convert(idl.IDLCustomObjectType);
78
90
  }
79
91
  convertTypeReference(type) {
80
- if (type.name === "Object")
92
+ var _a, _b;
93
+ if (type.name === idl.IDLObjectType.name)
81
94
  return "KPointer";
82
- const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
83
- if (importAttr) {
84
- return this.convertTypeReferenceAsImport(type, importAttr);
85
- }
86
95
  // resolve synthetic types
87
96
  const decl = this.resolver.resolveTypeReference(type);
88
97
  if (decl && idl.isSyntheticEntry(decl)) {
@@ -95,13 +104,20 @@ export class CJTypeNameConvertor {
95
104
  return this.productType(decl, isTuple, !isTuple);
96
105
  }
97
106
  }
98
- return type.name;
107
+ let name = type.name.split('.');
108
+ let typeArgs = (_b = (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.convert(it))) !== null && _b !== void 0 ? _b : [];
109
+ const maybeTypeArguments = !(typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) ? '' : `<${typeArgs.join(', ')}>`;
110
+ if (decl) {
111
+ return idl.getNamespacesPathFor(decl).map(ns => ns.name).join().concat(name[name.length - 1].concat(maybeTypeArguments));
112
+ }
113
+ return this.convert(idl.IDLCustomObjectType);
99
114
  }
100
115
  convertTypeParameter(type) {
101
116
  return type.name;
102
117
  }
103
118
  convertPrimitiveType(type) {
104
119
  switch (type) {
120
+ case idl.IDLThisType: return 'this';
105
121
  case idl.IDLStringType: return 'String';
106
122
  case idl.IDLBooleanType: return 'Bool';
107
123
  case idl.IDLNumberType: return 'Float64';
@@ -123,16 +139,19 @@ export class CJTypeNameConvertor {
123
139
  case idl.IDLBigintType: return 'Int64';
124
140
  case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
125
141
  case idl.IDLAnyType: return 'Any';
142
+ case idl.IDLDate: return 'DateTime';
143
+ case idl.IDLObjectType: return 'Any';
144
+ case idl.IDLUnknownType:
145
+ case idl.IDLFunctionType:
146
+ case idl.IDLCustomObjectType: return 'Any';
126
147
  }
127
148
  throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
128
149
  }
129
150
  callbackType(decl) {
130
- const params = decl.parameters.map(it => `${it.name}: ${this.convert(it.type)}`);
151
+ const params = decl.parameters.map(it => `${CJKeywords.has(it.name) ? it.name.concat("_") : it.name}: ${this.convert(it.type)}`);
131
152
  return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
132
153
  }
133
154
  productType(decl, isTuple, includeFieldNames) {
134
- if (!isTuple)
135
- throw new Error('Only tuples supported from IDL synthetic types for now');
136
155
  return decl.name;
137
156
  }
138
157
  }
@@ -143,6 +162,7 @@ export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
143
162
  case idl.IDLStringType: return 'CString';
144
163
  case idl.IDLInteropReturnBufferType: return 'KInteropReturnBuffer';
145
164
  case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
165
+ case idl.IDLObjectType: return 'Unit';
146
166
  }
147
167
  }
148
168
  if (idl.isContainerType(type)) {
@@ -178,4 +198,7 @@ export class CJInteropArgConvertor extends InteropArgConvertor {
178
198
  return super.convertPrimitiveType(type);
179
199
  }
180
200
  }
201
+ export function removePoints(s) {
202
+ return s.split(/[\.\-]/g).join('_');
203
+ }
181
204
  //# sourceMappingURL=CJConvertors.js.map
@@ -5,6 +5,7 @@ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
5
5
  export interface ConvertResult {
6
6
  text: string;
7
7
  noPrefix: boolean;
8
+ resolvedType: idl.IDLType;
8
9
  }
9
10
  export declare class GenericCppConvertor implements NodeConvertor<ConvertResult> {
10
11
  protected resolver: ReferenceResolver;
@@ -26,8 +26,8 @@ export class GenericCppConvertor {
26
26
  constructor(resolver) {
27
27
  this.resolver = resolver;
28
28
  }
29
- make(text, noPrefix = false) {
30
- return { text, noPrefix };
29
+ make(text, resolvedType, noPrefix = false) {
30
+ return { text, noPrefix, resolvedType };
31
31
  }
32
32
  convertNode(node) {
33
33
  return convertNode(this, node);
@@ -39,60 +39,65 @@ export class GenericCppConvertor {
39
39
  switch (node.subkind) {
40
40
  case idl.IDLInterfaceSubkind.AnonymousInterface:
41
41
  return node.name
42
- ? this.make(this.qualifiedName(node))
43
- : this.make(this.computeTargetTypeLiteralName(node), true);
42
+ ? this.make(this.qualifiedName(node), idl.createReferenceType(node))
43
+ : this.make(this.computeTargetTypeLiteralName(node), idl.createReferenceType(node), true);
44
44
  case idl.IDLInterfaceSubkind.Interface:
45
45
  case idl.IDLInterfaceSubkind.Class:
46
46
  if (isInIdlizeInternal(node)) {
47
- return this.make(this.qualifiedName(node), true);
47
+ return this.make(this.qualifiedName(node), idl.createReferenceType(node), true);
48
48
  }
49
- return this.make(this.qualifiedName(node));
49
+ return this.make(this.qualifiedName(node), idl.createReferenceType(node));
50
50
  case idl.IDLInterfaceSubkind.Tuple:
51
51
  return node.name
52
- ? this.make(this.qualifiedName(node))
53
- : this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
52
+ ? this.make(this.qualifiedName(node), idl.createReferenceType(node))
53
+ : this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, idl.createReferenceType(node), true);
54
54
  }
55
55
  }
56
56
  convertEnum(node) {
57
- return this.make(this.qualifiedName(node));
57
+ return this.make(this.qualifiedName(node), idl.createReferenceType(node));
58
58
  }
59
59
  convertTypedef(node) {
60
- return this.make(this.qualifiedName(node));
60
+ return this.make(this.qualifiedName(node), idl.createReferenceType(node));
61
61
  }
62
62
  convertCallback(node) {
63
- return this.make(generatorConfiguration().LibraryPrefix + this.qualifiedName(node), true);
63
+ return this.make(generatorConfiguration().LibraryPrefix + this.qualifiedName(node), idl.createReferenceType(node), true);
64
64
  }
65
65
  convertMethod(node) {
66
- return this.make(node.name);
66
+ return this.make(node.name, idl.createReferenceType(node));
67
67
  }
68
68
  convertConstant(node) {
69
- return this.make(this.qualifiedName(node));
69
+ return this.make(this.qualifiedName(node), idl.createReferenceType(node));
70
70
  }
71
71
  /////////////////////////////////////////////////////////////////////////////////////////
72
72
  convertOptional(type) {
73
- return { text: generatorConfiguration().OptionalPrefix + this.convertNode(type.type).text, noPrefix: true };
73
+ const converted = this.convertNode(type.type);
74
+ const prefix = generatorConfiguration().OptionalPrefix;
75
+ if (idl.isOptionalType(converted.resolvedType)) {
76
+ return converted;
77
+ }
78
+ return this.make(prefix + converted.text, type, true);
74
79
  }
75
80
  convertUnion(type) {
76
- return this.make(type.name, false);
81
+ return this.make(type.name, type, false);
77
82
  }
78
83
  convertContainer(type) {
79
84
  if (idl.IDLContainerUtils.isPromise(type)) {
80
- return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`);
85
+ return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`, type);
81
86
  }
82
87
  if (idl.IDLContainerUtils.isSequence(type)) {
83
88
  if (type.elementType[0] === idl.IDLU8Type) {
84
- return this.make(`uint8_t*`, true);
89
+ return this.make(`uint8_t*`, type, true);
85
90
  }
86
- return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
91
+ return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, type, true);
87
92
  }
88
93
  if (idl.IDLContainerUtils.isRecord(type)) {
89
- return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
94
+ return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, type, true);
90
95
  }
91
96
  throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
92
97
  }
93
98
  convertImport(type) {
94
99
  console.warn("Imports are not implemented yet");
95
- return this.make(idl.IDLCustomObjectType.name);
100
+ return this.make(idl.IDLCustomObjectType.name, idl.IDLCustomObjectType);
96
101
  }
97
102
  convertTypeReferenceAsImport(type, _) {
98
103
  return this.convertTypeReference(type);
@@ -100,14 +105,8 @@ export class GenericCppConvertor {
100
105
  convertTypeReference(type) {
101
106
  var _a;
102
107
  const refName = type.name;
103
- switch (refName) {
104
- case "object":
105
- case "Object":
106
- // treat object as interop resource
107
- return this.make('Object');
108
- }
109
108
  if (generatorConfiguration().parameterized.includes(refName)) {
110
- return this.make('CustomObject');
109
+ return this.make('CustomObject', idl.IDLCustomObjectType);
111
110
  }
112
111
  let decl = this.resolver.toDeclaration(type);
113
112
  if (idl.isCallback(decl)) {
@@ -115,45 +114,47 @@ export class GenericCppConvertor {
115
114
  }
116
115
  if (idl.isType(decl)) {
117
116
  if (idl.isReferenceType(decl)) {
118
- return this.make(`${capitalize(decl.name)}`);
117
+ return this.make(`${capitalize(decl.name)}`, decl);
119
118
  }
120
119
  return this.convertNode(decl);
121
120
  }
122
121
  let res = this.convertNode(decl);
123
122
  if (type.name === "Optional")
124
- res = this.make("Opt_" + res.text, true);
123
+ res = this.make("Opt_" + res.text, idl.createOptionalType(type.typeArguments[0]), true);
125
124
  return res;
126
125
  }
127
126
  convertTypeParameter(type) {
128
- return this.make('CustomObject');
127
+ return this.make('CustomObject', idl.IDLCustomObjectType);
129
128
  }
130
129
  convertPrimitiveType(type) {
131
130
  switch (type) {
132
- case idl.IDLVoidType: return this.make('void', true);
133
- case idl.IDLI8Type: return this.make(`Int8`);
134
- case idl.IDLU8Type: return this.make(`UInt8`);
135
- case idl.IDLI16Type: return this.make(`Int16`);
136
- case idl.IDLU16Type: return this.make(`UInt16`);
137
- case idl.IDLI32Type: return this.make(`Int32`);
138
- case idl.IDLU32Type: return this.make(`UInt32`);
139
- case idl.IDLI64Type: return this.make(`Int64`);
140
- case idl.IDLU64Type: return this.make(`UInt64`);
141
- case idl.IDLF32Type: return this.make(`Float32`);
142
- case idl.IDLF64Type: return this.make(`Float64`);
143
- case idl.IDLNumberType: return this.make(`Number`);
144
- case idl.IDLStringType: return this.make(`String`);
145
- case idl.IDLBooleanType: return this.make(`Boolean`);
146
- case idl.IDLBigintType: return this.make(`Int64`); // TODO add arbitrary precision numeric type
147
- case idl.IDLPointerType: return this.make('NativePointer');
148
- case idl.IDLCustomObjectType: return this.make('CustomObject');
131
+ case idl.IDLThisType: // maybe fix it in another level?
132
+ case idl.IDLVoidType: return this.make('void', type, true);
133
+ case idl.IDLI8Type: return this.make(`Int8`, type);
134
+ case idl.IDLU8Type: return this.make(`UInt8`, type);
135
+ case idl.IDLI16Type: return this.make(`Int16`, type);
136
+ case idl.IDLU16Type: return this.make(`UInt16`, type);
137
+ case idl.IDLI32Type: return this.make(`Int32`, type);
138
+ case idl.IDLU32Type: return this.make(`UInt32`, type);
139
+ case idl.IDLI64Type: return this.make(`Int64`, type);
140
+ case idl.IDLU64Type: return this.make(`UInt64`, type);
141
+ case idl.IDLF32Type: return this.make(`Float32`, type);
142
+ case idl.IDLF64Type: return this.make(`Float64`, type);
143
+ case idl.IDLNumberType: return this.make(`Number`, type);
144
+ case idl.IDLStringType: return this.make(`String`, type);
145
+ case idl.IDLBooleanType: return this.make(`Boolean`, type);
146
+ case idl.IDLBigintType: return this.make(`Int64`, type); // TODO add arbitrary precision numeric type
147
+ case idl.IDLPointerType: return this.make('NativePointer', type);
148
+ case idl.IDLCustomObjectType: return this.make('CustomObject', type);
149
149
  case idl.IDLUnknownType:
150
- case idl.IDLAnyType: return this.make(`Object`);
151
- case idl.IDLUndefinedType: return this.make(`Undefined`);
152
- case idl.IDLFunctionType: return this.make(`Function`);
153
- case idl.IDLDate: return this.make(`Date`);
154
- case idl.IDLBufferType: return this.make('Buffer');
155
- case idl.IDLPointerType: return this.make('Pointer');
156
- case idl.IDLSerializerBuffer: return { text: 'KSerializerBuffer', noPrefix: true };
150
+ case idl.IDLObjectType:
151
+ case idl.IDLAnyType: return this.make(`Object`, type);
152
+ case idl.IDLUndefinedType: return this.make(`Undefined`, type);
153
+ case idl.IDLFunctionType: return this.make(`Function`, type);
154
+ case idl.IDLDate: return this.make(`Date`, type);
155
+ case idl.IDLBufferType: return this.make('Buffer', type);
156
+ case idl.IDLPointerType: return this.make('Pointer', type);
157
+ case idl.IDLSerializerBuffer: return this.make('KSerializerBuffer', type, true);
157
158
  }
158
159
  throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
159
160
  }
@@ -4,7 +4,7 @@ export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
4
4
  convertTypeReference(type: idl.IDLReferenceType): string;
5
5
  convertContainer(type: idl.IDLContainerType): string;
6
6
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
7
- protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
7
+ protected productType(decl: idl.IDLInterface, args: idl.IDLType[] | undefined, isTuple: boolean, includeFieldNames: boolean): string;
8
8
  protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
9
9
  protected mapCallback(decl: idl.IDLCallback): string;
10
10
  protected mapFunctionType(typeArgs: string[]): string;
@@ -70,11 +70,11 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
70
70
  }
71
71
  return super.convertPrimitiveType(type);
72
72
  }
73
- productType(decl, isTuple, includeFieldNames) {
73
+ productType(decl, args, isTuple, includeFieldNames) {
74
74
  if (decl.subkind === idl.IDLInterfaceSubkind.AnonymousInterface) {
75
75
  return decl.name;
76
76
  }
77
- return super.productType(decl, isTuple, includeFieldNames);
77
+ return super.productType(decl, args, isTuple, includeFieldNames);
78
78
  }
79
79
  processTupleType(idlProperty) {
80
80
  if (idlProperty.isOptional) {
@@ -66,6 +66,7 @@ export class InteropReturnTypeConvertor {
66
66
  case idl.IDLThisType:
67
67
  case idl.IDLUndefinedType:
68
68
  case idl.IDLUnknownType:
69
+ case idl.IDLObjectType:
69
70
  case idl.IDLVoidType: return idl.IDLVoidType.name;
70
71
  case idl.IDLBufferType: return KInteropReturnBuffer; /* ArkTS can not return buffer as language object yet */
71
72
  case idl.IDLStringType: return PrimitiveTypesInstance.String.getText();
@@ -0,0 +1,24 @@
1
+ import * as idl from '../../idl';
2
+ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
+ import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
+ export declare class KotlinTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
5
+ protected resolver: ReferenceResolver;
6
+ constructor(resolver: ReferenceResolver);
7
+ convert(node: idl.IDLNode): string;
8
+ convertNamespace(node: idl.IDLNamespace): string;
9
+ convertInterface(node: idl.IDLInterface): string;
10
+ convertEnum(node: idl.IDLEnum): string;
11
+ convertTypedef(node: idl.IDLTypedef): string;
12
+ convertCallback(node: idl.IDLCallback): string;
13
+ convertMethod(node: idl.IDLMethod): string;
14
+ convertConstant(node: idl.IDLConstant): string;
15
+ convertOptional(type: idl.IDLOptionalType): string;
16
+ convertUnion(type: idl.IDLUnionType): string;
17
+ convertContainer(type: idl.IDLContainerType): string;
18
+ convertImport(type: idl.IDLImport): string;
19
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
20
+ convertTypeReference(type: idl.IDLReferenceType): string;
21
+ convertTypeParameter(type: idl.IDLTypeParameterType): string;
22
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
23
+ }
24
+ //# sourceMappingURL=KotlinConvertor.d.ts.map
@@ -0,0 +1,69 @@
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 { convertNode } from '../nameConvertor';
16
+ export class KotlinTypeNameConvertor {
17
+ constructor(resolver) {
18
+ this.resolver = resolver;
19
+ }
20
+ convert(node) {
21
+ return convertNode(this, node);
22
+ }
23
+ convertNamespace(node) {
24
+ throw new Error("Not implemented");
25
+ }
26
+ convertInterface(node) {
27
+ throw new Error("Not implemented");
28
+ }
29
+ convertEnum(node) {
30
+ throw new Error("Not implemented");
31
+ }
32
+ convertTypedef(node) {
33
+ throw new Error("Not implemented");
34
+ }
35
+ convertCallback(node) {
36
+ throw new Error("Not implemented");
37
+ }
38
+ convertMethod(node) {
39
+ throw new Error("Not implemented");
40
+ }
41
+ convertConstant(node) {
42
+ throw new Error("Not implemented");
43
+ }
44
+ convertOptional(type) {
45
+ throw new Error("Not implemented");
46
+ }
47
+ convertUnion(type) {
48
+ throw new Error("Not implemented");
49
+ }
50
+ convertContainer(type) {
51
+ throw new Error("Not implemented");
52
+ }
53
+ convertImport(type) {
54
+ throw new Error("Not implemented");
55
+ }
56
+ convertTypeReferenceAsImport(type, importClause) {
57
+ throw new Error("Not implemented");
58
+ }
59
+ convertTypeReference(type) {
60
+ throw new Error("Not implemented");
61
+ }
62
+ convertTypeParameter(type) {
63
+ throw new Error("Not implemented");
64
+ }
65
+ convertPrimitiveType(type) {
66
+ throw new Error("Not implemented");
67
+ }
68
+ }
69
+ //# sourceMappingURL=KotlinConvertor.js.map
@@ -0,0 +1,25 @@
1
+ import * as idl from '../../idl';
2
+ import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
+ import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
+ export declare class KotlinTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
5
+ protected resolver: ReferenceResolver;
6
+ constructor(resolver: ReferenceResolver);
7
+ convert(node: idl.IDLNode): string;
8
+ convertNamespace(node: idl.IDLNamespace): string;
9
+ convertInterface(node: idl.IDLInterface): string;
10
+ convertEnum(node: idl.IDLEnum): string;
11
+ convertTypedef(node: idl.IDLTypedef): string;
12
+ convertCallback(node: idl.IDLCallback): string;
13
+ convertMethod(node: idl.IDLMethod): string;
14
+ convertConstant(node: idl.IDLConstant): string;
15
+ convertOptional(type: idl.IDLOptionalType): string;
16
+ convertUnion(type: idl.IDLUnionType): string;
17
+ convertContainer(type: idl.IDLContainerType): string;
18
+ convertImport(type: idl.IDLImport): string;
19
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
20
+ convertTypeReference(type: idl.IDLReferenceType): string;
21
+ convertTypeParameter(type: idl.IDLTypeParameterType): string;
22
+ convertPrimitiveType(type: idl.IDLPrimitiveType): string;
23
+ private callbackType;
24
+ }
25
+ //# sourceMappingURL=KotlinConvertors.d.ts.map