@idlizer/core 2.1.2 → 2.1.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 (80) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +3 -4
  2. package/build/lib/src/LanguageWriters/ArgConvertors.js +43 -32
  3. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +35 -17
  4. package/build/lib/src/LanguageWriters/LanguageWriter.js +30 -56
  5. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +3 -1
  6. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +32 -11
  7. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +5 -2
  8. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +71 -62
  9. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
  10. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +9 -19
  11. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
  12. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -3
  13. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
  14. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
  15. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +8 -4
  16. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +87 -33
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +19 -11
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +34 -47
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +9 -9
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +15 -24
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +17 -8
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +48 -23
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +4 -6
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +15 -14
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +13 -8
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -52
  31. package/build/lib/src/LibraryInterface.d.ts +1 -4
  32. package/build/lib/src/config.d.ts +813 -110
  33. package/build/lib/src/config.js +25 -3
  34. package/build/lib/src/configDescriber.d.ts +31 -4
  35. package/build/lib/src/configDescriber.js +101 -3
  36. package/build/lib/src/from-idl/DtsPrinter.js +31 -18
  37. package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
  38. package/build/lib/src/from-idl/IDLLinter.js +211 -25
  39. package/build/lib/src/from-idl/common.js +1 -1
  40. package/build/lib/src/from-idl/deserialize.d.ts +10 -1
  41. package/build/lib/src/from-idl/deserialize.js +486 -352
  42. package/build/lib/src/idl.d.ts +29 -19
  43. package/build/lib/src/idl.js +404 -119
  44. package/build/lib/src/idlize.d.ts +2 -1
  45. package/build/lib/src/idlize.js +82 -26
  46. package/build/lib/src/index.d.ts +4 -3
  47. package/build/lib/src/index.js +3 -2
  48. package/build/lib/src/options.d.ts +1 -1
  49. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
  50. package/build/lib/src/peer-generation/BuilderClass.js +0 -8
  51. package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
  52. package/build/lib/src/peer-generation/LayoutManager.js +3 -2
  53. package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
  54. package/build/lib/src/peer-generation/Materialized.js +3 -3
  55. package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
  56. package/build/lib/src/peer-generation/PeerClass.js +0 -1
  57. package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
  58. package/build/lib/src/peer-generation/PeerFile.js +1 -1
  59. package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -7
  60. package/build/lib/src/peer-generation/PeerLibrary.js +131 -67
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
  65. package/build/lib/src/peer-generation/idl/common.d.ts +3 -1
  66. package/build/lib/src/peer-generation/idl/common.js +21 -4
  67. package/build/lib/src/peer-generation/isMaterialized.js +28 -7
  68. package/build/lib/src/peer-generation/unions.d.ts +3 -2
  69. package/build/lib/src/peer-generation/unions.js +7 -3
  70. package/build/lib/src/resolveNamedNode.d.ts +3 -0
  71. package/build/lib/src/resolveNamedNode.js +105 -0
  72. package/build/lib/src/util.d.ts +8 -1
  73. package/build/lib/src/util.js +41 -3
  74. package/build/lib/src/visitor.d.ts +2 -1
  75. package/build/lib/src/visitor.js +109 -7
  76. package/package.json +2 -2
  77. package/webidl2.js/LICENSE +21 -0
  78. package/webidl2.js/README.md +827 -0
  79. package/webidl2.js/dist/package.json +3 -0
  80. package/webidl2.js/dist/webidl2.js +93 -19
@@ -20,6 +20,11 @@ export class CJTypeNameConvertor {
20
20
  this.resolver = resolver;
21
21
  }
22
22
  convert(node) {
23
+ if (idl.isType(node) && idl.isReferenceType(node)) {
24
+ if (node.name.startsWith('%TEXT%:')) {
25
+ return node.name.substring(7);
26
+ }
27
+ }
23
28
  return convertNode(this, node);
24
29
  }
25
30
  /***** TypeConvertor<string> **********************************/
@@ -35,7 +40,7 @@ export class CJTypeNameConvertor {
35
40
  }
36
41
  if (idl.IDLContainerUtils.isRecord(type)) {
37
42
  const stringes = type.elementType.slice(0, 2).map(it => convertType(this, it));
38
- return `Map<${stringes[0]}, ${stringes[1]}>`;
43
+ return `HashMap<${stringes[0]}, ${stringes[1]}>`;
39
44
  }
40
45
  if (idl.IDLContainerUtils.isPromise(type)) {
41
46
  return `Any`;
@@ -43,20 +48,20 @@ export class CJTypeNameConvertor {
43
48
  throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
44
49
  }
45
50
  convertNamespace(node) {
46
- throw new Error('Method not implemented.');
51
+ return node.name;
47
52
  }
48
53
  convertInterface(node) {
49
- return node.name;
54
+ return removePoints(idl.getNamespaceName(node).concat(node.name));
50
55
  }
51
56
  convertEnum(node) {
52
- return node.name;
57
+ return removePoints(idl.getNamespaceName(node).concat(node.name));
53
58
  }
54
59
  convertTypedef(node) {
55
60
  return node.name;
56
61
  }
57
62
  convertCallback(type) {
58
63
  const params = type.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
59
- return `\{(${params.join(", ")}) => ${this.convert(type.returnType)}\}`;
64
+ return `(${params.join(", ")}) -> ${this.convert(type.returnType)}`;
60
65
  }
61
66
  convertMethod(node) {
62
67
  throw new Error('Method not implemented.');
@@ -64,7 +69,11 @@ export class CJTypeNameConvertor {
64
69
  convertConstant(node) {
65
70
  throw new Error('Method not implemented.');
66
71
  }
67
- convertImport(type, importClause) {
72
+ convertImport(type) {
73
+ console.warn("Imports are not implemented yet");
74
+ return type.name;
75
+ }
76
+ convertTypeReferenceAsImport(type, importClause) {
68
77
  return type.name;
69
78
  }
70
79
  convertTypeReference(type) {
@@ -72,7 +81,7 @@ export class CJTypeNameConvertor {
72
81
  return "KPointer";
73
82
  const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
74
83
  if (importAttr) {
75
- return this.convertImport(type, importAttr);
84
+ return this.convertTypeReferenceAsImport(type, importAttr);
76
85
  }
77
86
  // resolve synthetic types
78
87
  const decl = this.resolver.resolveTypeReference(type);
@@ -86,13 +95,18 @@ export class CJTypeNameConvertor {
86
95
  return this.productType(decl, isTuple, !isTuple);
87
96
  }
88
97
  }
89
- return type.name;
98
+ let name = type.name.split('.');
99
+ if (decl) {
100
+ return idl.getNamespacesPathFor(decl).map(ns => ns.name).join().concat(name[name.length - 1]);
101
+ }
102
+ return name[name.length - 1];
90
103
  }
91
104
  convertTypeParameter(type) {
92
105
  return type.name;
93
106
  }
94
107
  convertPrimitiveType(type) {
95
108
  switch (type) {
109
+ case idl.IDLThisType: return 'this';
96
110
  case idl.IDLStringType: return 'String';
97
111
  case idl.IDLBooleanType: return 'Bool';
98
112
  case idl.IDLNumberType: return 'Float64';
@@ -112,6 +126,12 @@ export class CJTypeNameConvertor {
112
126
  case idl.IDLBufferType: return 'Array<UInt8>';
113
127
  case idl.IDLInteropReturnBufferType: return 'Array<UInt8>';
114
128
  case idl.IDLBigintType: return 'Int64';
129
+ case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
130
+ case idl.IDLAnyType: return 'Any';
131
+ case idl.IDLDate: return 'DateTime';
132
+ case idl.IDLUnknownType:
133
+ case idl.IDLFunctionType:
134
+ case idl.IDLCustomObjectType: return 'Any';
115
135
  }
116
136
  throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
117
137
  }
@@ -120,8 +140,6 @@ export class CJTypeNameConvertor {
120
140
  return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
121
141
  }
122
142
  productType(decl, isTuple, includeFieldNames) {
123
- if (!isTuple)
124
- throw new Error('Only tuples supported from IDL synthetic types for now');
125
143
  return decl.name;
126
144
  }
127
145
  }
@@ -131,6 +149,7 @@ export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
131
149
  switch (type) {
132
150
  case idl.IDLStringType: return 'CString';
133
151
  case idl.IDLInteropReturnBufferType: return 'KInteropReturnBuffer';
152
+ case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
134
153
  }
135
154
  }
136
155
  if (idl.isContainerType(type)) {
@@ -162,9 +181,11 @@ export class CJInteropArgConvertor extends InteropArgConvertor {
162
181
  convertPrimitiveType(type) {
163
182
  switch (type) {
164
183
  case idl.IDLNumberType: return "Float64";
165
- case idl.IDLLengthType: return "Ark_Length";
166
184
  }
167
185
  return super.convertPrimitiveType(type);
168
186
  }
169
187
  }
188
+ export function removePoints(s) {
189
+ return s.split(/[\.\-]/g).join('_');
190
+ }
170
191
  //# 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;
@@ -21,7 +22,8 @@ export declare class GenericCppConvertor implements NodeConvertor<ConvertResult>
21
22
  convertOptional(type: idl.IDLOptionalType): ConvertResult;
22
23
  convertUnion(type: idl.IDLUnionType): ConvertResult;
23
24
  convertContainer(type: idl.IDLContainerType): ConvertResult;
24
- convertImport(type: idl.IDLReferenceType, _: string): ConvertResult;
25
+ convertImport(type: idl.IDLImport): ConvertResult;
26
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, _: string): ConvertResult;
25
27
  convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
26
28
  convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
27
29
  convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
@@ -51,7 +53,8 @@ export declare class CppReturnTypeConvertor implements TypeConvertor<string> {
51
53
  isVoid(returnType: idl.IDLType): boolean;
52
54
  convert(type: idl.IDLType): string;
53
55
  convertContainer(type: idl.IDLContainerType): string;
54
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
56
+ convertImport(type: idl.IDLImport): string;
57
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
55
58
  convertOptional(type: idl.IDLOptionalType): string;
56
59
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
57
60
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
@@ -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,70 +39,74 @@ 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 this.convertNode(type.type);
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
- convertImport(type, _) {
94
- return this.make(idl.IDLCustomObjectType.name);
98
+ convertImport(type) {
99
+ console.warn("Imports are not implemented yet");
100
+ return this.make(idl.IDLCustomObjectType.name, idl.IDLCustomObjectType);
101
+ }
102
+ convertTypeReferenceAsImport(type, _) {
103
+ return this.convertTypeReference(type);
95
104
  }
96
105
  convertTypeReference(type) {
97
106
  var _a;
98
107
  const refName = type.name;
99
- switch (refName) {
100
- case "object":
101
- case "Object":
102
- return this.make('CustomObject');
103
- }
104
108
  if (generatorConfiguration().parameterized.includes(refName)) {
105
- return this.make('CustomObject');
109
+ return this.make('CustomObject', idl.IDLCustomObjectType);
106
110
  }
107
111
  let decl = this.resolver.toDeclaration(type);
108
112
  if (idl.isCallback(decl)) {
@@ -110,51 +114,52 @@ export class GenericCppConvertor {
110
114
  }
111
115
  if (idl.isType(decl)) {
112
116
  if (idl.isReferenceType(decl)) {
113
- return this.make(`${capitalize(decl.name)}`);
117
+ return this.make(`${capitalize(decl.name)}`, decl);
114
118
  }
115
119
  return this.convertNode(decl);
116
120
  }
117
121
  let res = this.convertNode(decl);
118
122
  if (type.name === "Optional")
119
- res = this.make("Opt_" + res.text, true);
123
+ res = this.make("Opt_" + res.text, idl.createOptionalType(type.typeArguments[0]), true);
120
124
  return res;
121
125
  }
122
126
  convertTypeParameter(type) {
123
- return this.make('CustomObject');
127
+ return this.make('CustomObject', idl.IDLCustomObjectType);
124
128
  }
125
129
  convertPrimitiveType(type) {
126
130
  switch (type) {
127
- case idl.IDLVoidType: return this.make('void', true);
128
- case idl.IDLI8Type: return this.make(`Int8`);
129
- case idl.IDLU8Type: return this.make(`UInt8`);
130
- case idl.IDLI16Type: return this.make(`Int16`);
131
- case idl.IDLU16Type: return this.make(`UInt16`);
132
- case idl.IDLI32Type: return this.make(`Int32`);
133
- case idl.IDLU32Type: return this.make(`UInt32`);
134
- case idl.IDLI64Type: return this.make(`Int64`);
135
- case idl.IDLU64Type: return this.make(`UInt64`);
136
- case idl.IDLF32Type: return this.make(`Float32`);
137
- case idl.IDLF64Type: return this.make(`Float64`);
138
- case idl.IDLNumberType: return this.make(`Number`);
139
- case idl.IDLStringType: return this.make(`String`);
140
- case idl.IDLBooleanType: return this.make(`Boolean`);
141
- case idl.IDLBigintType: return this.make(`UInt64`); // TODO add arbitrary precision numeric type
142
- case idl.IDLPointerType: return this.make('NativePointer');
143
- 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);
144
149
  case idl.IDLUnknownType:
145
- case idl.IDLAnyType: return this.make(`Object`);
146
- case idl.IDLUndefinedType: return this.make(`Undefined`);
147
- case idl.IDLLengthType: return this.make(`Length`);
148
- case idl.IDLFunctionType: return this.make(`Function`);
149
- case idl.IDLDate: return this.make(`Date`);
150
- case idl.IDLBufferType: return this.make('Buffer');
151
- case idl.IDLPointerType: return this.make('Pointer');
152
- 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);
153
158
  }
154
159
  throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
155
160
  }
156
161
  qualifiedName(target) {
157
- return qualifiedName(target, "_");
162
+ return qualifiedName(target, "_", "namespace.name");
158
163
  }
159
164
  computeTargetTypeLiteralName(decl) {
160
165
  const map = new Map();
@@ -171,9 +176,6 @@ export class GenericCppConvertor {
171
176
  export class CppConvertor extends GenericCppConvertor {
172
177
  unwrap(type, result) {
173
178
  const conf = generatorConfiguration();
174
- if (idl.isType(type) && idl.isOptionalType(type)) {
175
- return `${conf.OptionalPrefix}${result.text}`;
176
- }
177
179
  if (result.noPrefix) {
178
180
  return result.text;
179
181
  }
@@ -187,12 +189,16 @@ export class CppConvertor extends GenericCppConvertor {
187
189
  if (!idl.isType(type))
188
190
  return false;
189
191
  const { resolver } = this;
192
+ const seen = new Set;
190
193
  while (type && idl.isReferenceType(type)) {
191
194
  const resolved = resolver.resolveTypeReference(type);
192
195
  if (!resolved)
193
196
  return false;
194
197
  if (!idl.isTypedef(resolved))
195
198
  break;
199
+ if (seen.has(resolved))
200
+ return false;
201
+ seen.add(resolved);
196
202
  type = resolved.type;
197
203
  }
198
204
  return idl.isPrimitiveType(type);
@@ -221,7 +227,6 @@ export class CppInteropArgConvertor extends InteropArgConvertor {
221
227
  case idl.IDLNumberType: return "KInteropNumber";
222
228
  case idl.IDLSerializerBuffer: return "KSerializerBuffer";
223
229
  case idl.IDLBufferType: return "KInteropBuffer";
224
- case idl.IDLLengthType: return "KLength";
225
230
  case idl.IDLFunctionType: return PrimitiveTypesInstance.Int32.getText();
226
231
  case idl.IDLDate: return PrimitiveTypesInstance.Int64.getText();
227
232
  case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
@@ -247,7 +252,11 @@ export class CppReturnTypeConvertor {
247
252
  return 'void';
248
253
  return this.convertor.convert(type);
249
254
  }
250
- convertImport(type, importClause) {
255
+ convertImport(type) {
256
+ console.warn("Imports are not implemented yet");
257
+ return "void";
258
+ }
259
+ convertTypeReferenceAsImport(type, importClause) {
251
260
  return this.convertor.convert(type);
252
261
  }
253
262
  convertOptional(type) {
@@ -264,7 +273,7 @@ export class CppReturnTypeConvertor {
264
273
  convertTypeReference(type) {
265
274
  const decl = this.resolver.resolveTypeReference(type);
266
275
  if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
267
- return generatorTypePrefix() + qualifiedName(decl, "_");
276
+ return generatorTypePrefix() + qualifiedName(decl, "_", "namespace.name");
268
277
  }
269
278
  return this.convertor.convert(type);
270
279
  }
@@ -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;
@@ -13,27 +13,16 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import * as idl from "../../idl";
16
- import { Language } from "../../Language";
17
- import { createDeclarationNameConvertor } from "../../peer-generation/idl/IdlNameConvertor";
18
- import { convertDeclaration } from "../nameConvertor";
16
+ import { LanguageWriter } from "../LanguageWriter";
19
17
  import { TSInteropArgConvertor, TSTypeNameConvertor } from "./TSConvertors";
20
18
  export class ETSTypeNameConvertor extends TSTypeNameConvertor {
21
19
  convertTypeReference(type) {
22
- // Only to deal with namespaces. TODO: remove later
23
- const decl = this.resolver.resolveTypeReference(type);
24
- if (decl && idl.isEnum(decl)) {
25
- return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
20
+ let typeName = super.convertTypeReference(type);
21
+ if (LanguageWriter.isReferenceRelativeToNamespaces && idl.isReferenceType(type)) {
22
+ const namespacesPath = idl.getNamespacesPathFor(type).map(it => `${it.name}.`).join("");
23
+ if (typeName.startsWith(namespacesPath))
24
+ typeName = typeName.substring(namespacesPath.length);
26
25
  }
27
- // TODO: Needs to be implemented properly
28
- const types = type.name.split(".");
29
- if (types.length > 1) {
30
- // Takes only name without the namespace prefix
31
- const decl = this.resolver.resolveTypeReference(idl.createReferenceType(types.slice(-1).join()));
32
- if (decl !== undefined) {
33
- return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
34
- }
35
- }
36
- const typeName = super.convertTypeReference(type);
37
26
  // TODO: Fix for 'TypeError: Type 'Function<R>' is generic but type argument were not provided.'
38
27
  if (typeName === "Function") {
39
28
  return "Function<void>";
@@ -77,14 +66,15 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
77
66
  case idl.IDLStringType: return 'string';
78
67
  case idl.IDLFunctionType: return 'Object';
79
68
  case idl.IDLBigintType: return 'long';
69
+ case idl.IDLCustomObjectType: return 'object';
80
70
  }
81
71
  return super.convertPrimitiveType(type);
82
72
  }
83
- productType(decl, isTuple, includeFieldNames) {
73
+ productType(decl, args, isTuple, includeFieldNames) {
84
74
  if (decl.subkind === idl.IDLInterfaceSubkind.AnonymousInterface) {
85
75
  return decl.name;
86
76
  }
87
- return super.productType(decl, isTuple, includeFieldNames);
77
+ return super.productType(decl, args, isTuple, includeFieldNames);
88
78
  }
89
79
  processTupleType(idlProperty) {
90
80
  if (idlProperty.isOptional) {
@@ -9,7 +9,8 @@ export declare class InteropReturnTypeConvertor implements TypeConvertor<string>
9
9
  isReturnInteropBuffer(type: idl.IDLType): boolean;
10
10
  convert(type: idl.IDLType): string;
11
11
  convertContainer(type: idl.IDLContainerType): string;
12
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
12
+ convertImport(type: idl.IDLImport): string;
13
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
13
14
  convertOptional(type: idl.IDLOptionalType): string;
14
15
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
15
16
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
@@ -19,7 +20,8 @@ export declare class InteropReturnTypeConvertor implements TypeConvertor<string>
19
20
  export declare class InteropArgConvertor implements TypeConvertor<string> {
20
21
  convert(type: idl.IDLType): string;
21
22
  convertContainer(type: idl.IDLContainerType): string;
22
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
23
+ convertImport(type: idl.IDLImport): string;
24
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
23
25
  convertOptional(type: idl.IDLOptionalType): string;
24
26
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
25
27
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
@@ -37,9 +37,12 @@ export class InteropReturnTypeConvertor {
37
37
  }
38
38
  return KInteropReturnBuffer;
39
39
  }
40
- convertImport(type, importClause) {
40
+ convertImport(type) {
41
41
  throw new Error(`Cannot pass import type ${type.name} through interop`);
42
42
  }
43
+ convertTypeReferenceAsImport(type, importClause) {
44
+ return this.convertTypeReference(type);
45
+ }
43
46
  convertOptional(type) {
44
47
  return KInteropReturnBuffer;
45
48
  }
@@ -63,6 +66,7 @@ export class InteropReturnTypeConvertor {
63
66
  case idl.IDLThisType:
64
67
  case idl.IDLUndefinedType:
65
68
  case idl.IDLUnknownType:
69
+ case idl.IDLObjectType:
66
70
  case idl.IDLVoidType: return idl.IDLVoidType.name;
67
71
  case idl.IDLBufferType: return KInteropReturnBuffer; /* ArkTS can not return buffer as language object yet */
68
72
  case idl.IDLStringType: return PrimitiveTypesInstance.String.getText();
@@ -105,7 +109,10 @@ export class InteropArgConvertor {
105
109
  convertContainer(type) {
106
110
  throw new Error(`Cannot pass container types through interop`);
107
111
  }
108
- convertImport(type, importClause) {
112
+ convertImport(type) {
113
+ throw new Error(`Cannot pass import types through interop`);
114
+ }
115
+ convertTypeReferenceAsImport(type, importClause) {
109
116
  throw new Error(`Cannot pass import types through interop`);
110
117
  }
111
118
  convertOptional(type) {
@@ -116,6 +123,7 @@ export class InteropArgConvertor {
116
123
  case idl.IDLI64Type: return "KLong";
117
124
  case idl.IDLU64Type: return "KLong";
118
125
  case idl.IDLI32Type: return "KInt";
126
+ case idl.IDLU32Type: return "KInt";
119
127
  case idl.IDLF32Type: return "KFloat";
120
128
  case idl.IDLNumberType: return 'KInteropNumber';
121
129
  case idl.IDLBigintType: return 'KLong';
@@ -124,7 +132,6 @@ export class InteropArgConvertor {
124
132
  case idl.IDLFunctionType: return 'KInt';
125
133
  case idl.IDLStringType: return 'KStringPtr';
126
134
  case idl.IDLBufferType: return `KInteropBuffer`;
127
- case idl.IDLLengthType: return 'Length';
128
135
  case idl.IDLDate: return 'KLong';
129
136
  case idl.IDLUndefinedType:
130
137
  case idl.IDLVoidType:
@@ -17,7 +17,8 @@ export declare class JavaTypeNameConvertor implements NodeConvertor<string>, Idl
17
17
  convertCallback(type: idl.IDLCallback): string;
18
18
  convertMethod(type: idl.IDLMethod): string;
19
19
  convertConstant(type: idl.IDLConstant): string;
20
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
20
+ convertImport(type: idl.IDLImport): string;
21
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
21
22
  convertTypeReference(type: idl.IDLReferenceType): string;
22
23
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
23
24
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
@@ -84,13 +84,17 @@ export class JavaTypeNameConvertor {
84
84
  convertConstant(type) {
85
85
  throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
86
86
  }
87
- convertImport(type, importClause) {
87
+ convertImport(type) {
88
+ console.warn("Imports are not implemented yet");
89
+ return type.name;
90
+ }
91
+ convertTypeReferenceAsImport(type, importClause) {
88
92
  return type.name;
89
93
  }
90
94
  convertTypeReference(type) {
91
95
  const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
92
96
  if (importAttr) {
93
- return this.convertImport(type, importAttr);
97
+ return this.convertTypeReferenceAsImport(type, importAttr);
94
98
  }
95
99
  const decl = this.resolver.resolveTypeReference(type);
96
100
  if (decl) {
@@ -127,6 +131,9 @@ export class JavaTypeNameConvertor {
127
131
  case idl.IDLDate: return 'Date';
128
132
  case idl.IDLBufferType: return 'byte[]';
129
133
  case idl.IDLInteropReturnBufferType: return 'byte[]';
134
+ case idl.IDLSerializerBuffer: return 'long';
135
+ case idl.IDLAnyType: return 'Ark_Object';
136
+ case idl.IDLUnknownType: return 'Ark_Object';
130
137
  }
131
138
  throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
132
139
  }
@@ -154,7 +161,7 @@ export class JavaTypeNameConvertor {
154
161
  case 'KStringPtr': return 'String';
155
162
  case 'string': return 'String';
156
163
  }
157
- return name;
164
+ return name.split(".").at(-1);
158
165
  }
159
166
  }
160
167
  class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
@@ -178,8 +185,21 @@ export class JavaInteropArgConvertor extends InteropArgConvertor {
178
185
  convertPrimitiveType(type) {
179
186
  switch (type) {
180
187
  case idl.IDLNumberType: return "double";
181
- case idl.IDLLengthType: return "String";
182
188
  case idl.IDLBooleanType: return "boolean";
189
+ case idl.IDLI64Type: return "long";
190
+ case idl.IDLU64Type: return "long";
191
+ case idl.IDLI32Type: return "int";
192
+ case idl.IDLU32Type: return "int";
193
+ case idl.IDLF32Type: return "float";
194
+ case idl.IDLBigintType: return "long";
195
+ case idl.IDLSerializerBuffer: return "long";
196
+ case idl.IDLFunctionType: return "int";
197
+ case idl.IDLStringType: return "String";
198
+ case idl.IDLBufferType: return "byte[]";
199
+ case idl.IDLDate: return "long";
200
+ case idl.IDLVoidType: return "void";
201
+ case idl.IDLUndefinedType: return "long";
202
+ case idl.IDLPointerType: return "long"; // return PrimitiveTypesInstance.NativePointer.getText()
183
203
  }
184
204
  return super.convertPrimitiveType(type);
185
205
  }
@@ -15,22 +15,26 @@ export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNa
15
15
  convertOptional(type: idl.IDLOptionalType): string;
16
16
  convertUnion(type: idl.IDLUnionType): string;
17
17
  convertContainer(type: idl.IDLContainerType): string;
18
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
18
+ convertImport(type: idl.IDLImport): string;
19
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
19
20
  convertTypeReference(type: idl.IDLReferenceType): string;
20
21
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
21
22
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
22
23
  protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
23
- protected mapCallback(decl: idl.IDLCallback): string;
24
- protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
24
+ protected createTypeSubstitution(parameters: string[] | undefined, args: idl.IDLType[] | undefined): Map<string, idl.IDLType>;
25
+ protected applySubstitution(subst: Map<string, idl.IDLType>, type: idl.IDLType): idl.IDLType;
26
+ protected mapCallback(decl: idl.IDLCallback, args?: idl.IDLType[]): string;
27
+ protected productType(decl: idl.IDLInterface, args: idl.IDLType[] | undefined, isTuple: boolean, includeFieldNames: boolean): string;
25
28
  protected mapFunctionType(typeArgs: string[]): string;
26
29
  }
27
30
  export declare class TSInteropArgConvertor implements TypeConvertor<string> {
28
31
  convert(type: idl.IDLType): string;
29
32
  convertContainer(type: idl.IDLContainerType): string;
30
- convertImport(type: idl.IDLReferenceType, importClause: string): string;
33
+ convertImport(type: idl.IDLImport): string;
31
34
  convertOptional(type: idl.IDLOptionalType): string;
32
35
  convertPrimitiveType(type: idl.IDLPrimitiveType): string;
33
36
  convertTypeParameter(type: idl.IDLTypeParameterType): string;
37
+ convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
34
38
  convertTypeReference(type: idl.IDLReferenceType): string;
35
39
  convertUnion(type: idl.IDLUnionType): string;
36
40
  }