@idlizer/core 2.1.0 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +15 -2
- package/build/lib/src/LanguageWriters/ArgConvertors.js +93 -33
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +34 -14
- package/build/lib/src/LanguageWriters/LanguageWriter.js +29 -52
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -5
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +25 -15
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +7 -18
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +13 -3
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +49 -29
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
- package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +21 -10
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +56 -65
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +16 -10
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +18 -27
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +14 -9
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +18 -21
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +11 -7
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +42 -18
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +14 -6
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +49 -44
- package/build/lib/src/LibraryInterface.d.ts +1 -5
- package/build/lib/src/config.d.ts +1029 -66
- package/build/lib/src/config.js +15 -2
- package/build/lib/src/configDescriber.d.ts +30 -3
- package/build/lib/src/configDescriber.js +99 -1
- package/build/lib/src/from-idl/DtsPrinter.js +32 -20
- package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
- package/build/lib/src/from-idl/IDLLinter.js +211 -25
- package/build/lib/src/from-idl/common.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +4 -1
- package/build/lib/src/from-idl/deserialize.js +434 -346
- package/build/lib/src/idl.d.ts +28 -18
- package/build/lib/src/idl.js +376 -111
- package/build/lib/src/idlize.d.ts +3 -1
- package/build/lib/src/idlize.js +85 -28
- package/build/lib/src/index.d.ts +6 -3
- package/build/lib/src/index.js +5 -2
- package/build/lib/src/options.d.ts +1 -1
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
- package/build/lib/src/peer-generation/BuilderClass.js +0 -8
- package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
- package/build/lib/src/peer-generation/LayoutManager.js +3 -2
- package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.js +2 -2
- package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
- package/build/lib/src/peer-generation/PeerClass.js +0 -1
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
- package/build/lib/src/peer-generation/PeerFile.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -9
- package/build/lib/src/peer-generation/PeerLibrary.js +136 -71
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
- package/build/lib/src/peer-generation/idl/common.d.ts +2 -1
- package/build/lib/src/peer-generation/idl/common.js +13 -2
- package/build/lib/src/peer-generation/isEnumType.d.ts +5 -0
- package/build/lib/src/peer-generation/isEnumType.js +29 -0
- package/build/lib/src/peer-generation/isMaterialized.js +25 -8
- package/build/lib/src/peer-generation/modules.d.ts +10 -0
- package/build/lib/src/peer-generation/modules.js +38 -0
- package/build/lib/src/peer-generation/unions.d.ts +3 -2
- package/build/lib/src/peer-generation/unions.js +6 -2
- package/build/lib/src/resolveNamedNode.d.ts +3 -0
- package/build/lib/src/resolveNamedNode.js +105 -0
- package/build/lib/src/util.d.ts +7 -0
- package/build/lib/src/util.js +39 -0
- package/build/lib/src/visitor.d.ts +0 -1
- package/build/lib/src/visitor.js +1 -7
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +35 -7
- package/build/lib/src/configMerge.d.ts +0 -2
- package/build/lib/src/configMerge.js +0 -42
|
@@ -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 `
|
|
43
|
+
return `HashMap<${stringes[0]}, ${stringes[1]}>`;
|
|
39
44
|
}
|
|
40
45
|
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
41
46
|
return `Any`;
|
|
@@ -56,7 +61,7 @@ export class CJTypeNameConvertor {
|
|
|
56
61
|
}
|
|
57
62
|
convertCallback(type) {
|
|
58
63
|
const params = type.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
|
|
59
|
-
return
|
|
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
|
|
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.
|
|
84
|
+
return this.convertTypeReferenceAsImport(type, importAttr);
|
|
76
85
|
}
|
|
77
86
|
// resolve synthetic types
|
|
78
87
|
const decl = this.resolver.resolveTypeReference(type);
|
|
@@ -112,6 +121,8 @@ export class CJTypeNameConvertor {
|
|
|
112
121
|
case idl.IDLBufferType: return 'Array<UInt8>';
|
|
113
122
|
case idl.IDLInteropReturnBufferType: return 'Array<UInt8>';
|
|
114
123
|
case idl.IDLBigintType: return 'Int64';
|
|
124
|
+
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
125
|
+
case idl.IDLAnyType: return 'Any';
|
|
115
126
|
}
|
|
116
127
|
throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
117
128
|
}
|
|
@@ -131,6 +142,7 @@ export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
|
|
|
131
142
|
switch (type) {
|
|
132
143
|
case idl.IDLStringType: return 'CString';
|
|
133
144
|
case idl.IDLInteropReturnBufferType: return 'KInteropReturnBuffer';
|
|
145
|
+
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
148
|
if (idl.isContainerType(type)) {
|
|
@@ -162,7 +174,6 @@ export class CJInteropArgConvertor extends InteropArgConvertor {
|
|
|
162
174
|
convertPrimitiveType(type) {
|
|
163
175
|
switch (type) {
|
|
164
176
|
case idl.IDLNumberType: return "Float64";
|
|
165
|
-
case idl.IDLLengthType: return "Ark_Length";
|
|
166
177
|
}
|
|
167
178
|
return super.convertPrimitiveType(type);
|
|
168
179
|
}
|
|
@@ -21,7 +21,8 @@ export declare class GenericCppConvertor implements NodeConvertor<ConvertResult>
|
|
|
21
21
|
convertOptional(type: idl.IDLOptionalType): ConvertResult;
|
|
22
22
|
convertUnion(type: idl.IDLUnionType): ConvertResult;
|
|
23
23
|
convertContainer(type: idl.IDLContainerType): ConvertResult;
|
|
24
|
-
convertImport(type: idl.
|
|
24
|
+
convertImport(type: idl.IDLImport): ConvertResult;
|
|
25
|
+
convertTypeReferenceAsImport(type: idl.IDLReferenceType, _: string): ConvertResult;
|
|
25
26
|
convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
|
|
26
27
|
convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
|
|
27
28
|
convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
|
|
@@ -51,7 +52,8 @@ export declare class CppReturnTypeConvertor implements TypeConvertor<string> {
|
|
|
51
52
|
isVoid(returnType: idl.IDLType): boolean;
|
|
52
53
|
convert(type: idl.IDLType): string;
|
|
53
54
|
convertContainer(type: idl.IDLContainerType): string;
|
|
54
|
-
convertImport(type: idl.
|
|
55
|
+
convertImport(type: idl.IDLImport): string;
|
|
56
|
+
convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
55
57
|
convertOptional(type: idl.IDLOptionalType): string;
|
|
56
58
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
57
59
|
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
@@ -70,7 +70,7 @@ export class GenericCppConvertor {
|
|
|
70
70
|
}
|
|
71
71
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
72
72
|
convertOptional(type) {
|
|
73
|
-
return this.convertNode(type.type);
|
|
73
|
+
return { text: generatorConfiguration().OptionalPrefix + this.convertNode(type.type).text, noPrefix: true };
|
|
74
74
|
}
|
|
75
75
|
convertUnion(type) {
|
|
76
76
|
return this.make(type.name, false);
|
|
@@ -90,16 +90,21 @@ export class GenericCppConvertor {
|
|
|
90
90
|
}
|
|
91
91
|
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
92
92
|
}
|
|
93
|
-
convertImport(type
|
|
93
|
+
convertImport(type) {
|
|
94
|
+
console.warn("Imports are not implemented yet");
|
|
94
95
|
return this.make(idl.IDLCustomObjectType.name);
|
|
95
96
|
}
|
|
97
|
+
convertTypeReferenceAsImport(type, _) {
|
|
98
|
+
return this.convertTypeReference(type);
|
|
99
|
+
}
|
|
96
100
|
convertTypeReference(type) {
|
|
97
101
|
var _a;
|
|
98
102
|
const refName = type.name;
|
|
99
103
|
switch (refName) {
|
|
100
104
|
case "object":
|
|
101
105
|
case "Object":
|
|
102
|
-
|
|
106
|
+
// treat object as interop resource
|
|
107
|
+
return this.make('Object');
|
|
103
108
|
}
|
|
104
109
|
if (generatorConfiguration().parameterized.includes(refName)) {
|
|
105
110
|
return this.make('CustomObject');
|
|
@@ -138,22 +143,22 @@ export class GenericCppConvertor {
|
|
|
138
143
|
case idl.IDLNumberType: return this.make(`Number`);
|
|
139
144
|
case idl.IDLStringType: return this.make(`String`);
|
|
140
145
|
case idl.IDLBooleanType: return this.make(`Boolean`);
|
|
141
|
-
case idl.IDLBigintType: return this.make(`
|
|
146
|
+
case idl.IDLBigintType: return this.make(`Int64`); // TODO add arbitrary precision numeric type
|
|
142
147
|
case idl.IDLPointerType: return this.make('NativePointer');
|
|
148
|
+
case idl.IDLCustomObjectType: return this.make('CustomObject');
|
|
143
149
|
case idl.IDLUnknownType:
|
|
144
|
-
case idl.
|
|
145
|
-
case idl.IDLAnyType: return this.make(`CustomObject`);
|
|
150
|
+
case idl.IDLAnyType: return this.make(`Object`);
|
|
146
151
|
case idl.IDLUndefinedType: return this.make(`Undefined`);
|
|
147
|
-
case idl.IDLLengthType: return this.make(`Length`);
|
|
148
152
|
case idl.IDLFunctionType: return this.make(`Function`);
|
|
149
153
|
case idl.IDLDate: return this.make(`Date`);
|
|
150
154
|
case idl.IDLBufferType: return this.make('Buffer');
|
|
151
155
|
case idl.IDLPointerType: return this.make('Pointer');
|
|
156
|
+
case idl.IDLSerializerBuffer: return { text: 'KSerializerBuffer', noPrefix: true };
|
|
152
157
|
}
|
|
153
158
|
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
154
159
|
}
|
|
155
160
|
qualifiedName(target) {
|
|
156
|
-
return qualifiedName(target, "_");
|
|
161
|
+
return qualifiedName(target, "_", "namespace.name");
|
|
157
162
|
}
|
|
158
163
|
computeTargetTypeLiteralName(decl) {
|
|
159
164
|
const map = new Map();
|
|
@@ -170,9 +175,6 @@ export class GenericCppConvertor {
|
|
|
170
175
|
export class CppConvertor extends GenericCppConvertor {
|
|
171
176
|
unwrap(type, result) {
|
|
172
177
|
const conf = generatorConfiguration();
|
|
173
|
-
if (idl.isType(type) && idl.isOptionalType(type)) {
|
|
174
|
-
return `${conf.OptionalPrefix}${result.text}`;
|
|
175
|
-
}
|
|
176
178
|
if (result.noPrefix) {
|
|
177
179
|
return result.text;
|
|
178
180
|
}
|
|
@@ -186,12 +188,16 @@ export class CppConvertor extends GenericCppConvertor {
|
|
|
186
188
|
if (!idl.isType(type))
|
|
187
189
|
return false;
|
|
188
190
|
const { resolver } = this;
|
|
191
|
+
const seen = new Set;
|
|
189
192
|
while (type && idl.isReferenceType(type)) {
|
|
190
193
|
const resolved = resolver.resolveTypeReference(type);
|
|
191
194
|
if (!resolved)
|
|
192
195
|
return false;
|
|
193
196
|
if (!idl.isTypedef(resolved))
|
|
194
197
|
break;
|
|
198
|
+
if (seen.has(resolved))
|
|
199
|
+
return false;
|
|
200
|
+
seen.add(resolved);
|
|
195
201
|
type = resolved.type;
|
|
196
202
|
}
|
|
197
203
|
return idl.isPrimitiveType(type);
|
|
@@ -218,8 +224,8 @@ export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
|
218
224
|
case idl.IDLBooleanType: return PrimitiveTypesInstance.Boolean.getText();
|
|
219
225
|
case idl.IDLI32Type: return PrimitiveTypesInstance.Int32.getText();
|
|
220
226
|
case idl.IDLNumberType: return "KInteropNumber";
|
|
221
|
-
case idl.
|
|
222
|
-
case idl.
|
|
227
|
+
case idl.IDLSerializerBuffer: return "KSerializerBuffer";
|
|
228
|
+
case idl.IDLBufferType: return "KInteropBuffer";
|
|
223
229
|
case idl.IDLFunctionType: return PrimitiveTypesInstance.Int32.getText();
|
|
224
230
|
case idl.IDLDate: return PrimitiveTypesInstance.Int64.getText();
|
|
225
231
|
case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
@@ -245,7 +251,11 @@ export class CppReturnTypeConvertor {
|
|
|
245
251
|
return 'void';
|
|
246
252
|
return this.convertor.convert(type);
|
|
247
253
|
}
|
|
248
|
-
convertImport(type
|
|
254
|
+
convertImport(type) {
|
|
255
|
+
console.warn("Imports are not implemented yet");
|
|
256
|
+
return "void";
|
|
257
|
+
}
|
|
258
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
249
259
|
return this.convertor.convert(type);
|
|
250
260
|
}
|
|
251
261
|
convertOptional(type) {
|
|
@@ -262,7 +272,7 @@ export class CppReturnTypeConvertor {
|
|
|
262
272
|
convertTypeReference(type) {
|
|
263
273
|
const decl = this.resolver.resolveTypeReference(type);
|
|
264
274
|
if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
|
|
265
|
-
return generatorTypePrefix() + qualifiedName(decl, "_");
|
|
275
|
+
return generatorTypePrefix() + qualifiedName(decl, "_", "namespace.name");
|
|
266
276
|
}
|
|
267
277
|
return this.convertor.convert(type);
|
|
268
278
|
}
|
|
@@ -13,27 +13,16 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from "../../idl";
|
|
16
|
-
import {
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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>";
|
|
@@ -76,8 +65,8 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
76
65
|
return 'number';
|
|
77
66
|
case idl.IDLStringType: return 'string';
|
|
78
67
|
case idl.IDLFunctionType: return 'Object';
|
|
79
|
-
case idl.IDLBufferType: return 'NativeBuffer';
|
|
80
68
|
case idl.IDLBigintType: return 'long';
|
|
69
|
+
case idl.IDLCustomObjectType: return 'object';
|
|
81
70
|
}
|
|
82
71
|
return super.convertPrimitiveType(type);
|
|
83
72
|
}
|
|
@@ -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.
|
|
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.
|
|
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
|
|
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
|
}
|
|
@@ -88,6 +91,9 @@ export class InteropReturnTypeConvertor {
|
|
|
88
91
|
}
|
|
89
92
|
return KInteropReturnBuffer;
|
|
90
93
|
}
|
|
94
|
+
if (idl.isEnum(decl)) {
|
|
95
|
+
return PrimitiveTypesInstance.Int32.getText();
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
return "void";
|
|
93
99
|
}
|
|
@@ -102,7 +108,10 @@ export class InteropArgConvertor {
|
|
|
102
108
|
convertContainer(type) {
|
|
103
109
|
throw new Error(`Cannot pass container types through interop`);
|
|
104
110
|
}
|
|
105
|
-
convertImport(type
|
|
111
|
+
convertImport(type) {
|
|
112
|
+
throw new Error(`Cannot pass import types through interop`);
|
|
113
|
+
}
|
|
114
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
106
115
|
throw new Error(`Cannot pass import types through interop`);
|
|
107
116
|
}
|
|
108
117
|
convertOptional(type) {
|
|
@@ -113,14 +122,15 @@ export class InteropArgConvertor {
|
|
|
113
122
|
case idl.IDLI64Type: return "KLong";
|
|
114
123
|
case idl.IDLU64Type: return "KLong";
|
|
115
124
|
case idl.IDLI32Type: return "KInt";
|
|
125
|
+
case idl.IDLU32Type: return "KInt";
|
|
116
126
|
case idl.IDLF32Type: return "KFloat";
|
|
117
127
|
case idl.IDLNumberType: return 'KInteropNumber';
|
|
118
128
|
case idl.IDLBigintType: return 'KLong';
|
|
129
|
+
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
119
130
|
case idl.IDLBooleanType:
|
|
120
131
|
case idl.IDLFunctionType: return 'KInt';
|
|
121
132
|
case idl.IDLStringType: return 'KStringPtr';
|
|
122
133
|
case idl.IDLBufferType: return `KInteropBuffer`;
|
|
123
|
-
case idl.IDLLengthType: return 'Length';
|
|
124
134
|
case idl.IDLDate: return 'KLong';
|
|
125
135
|
case idl.IDLUndefinedType:
|
|
126
136
|
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.
|
|
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
|
|
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.
|
|
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,7 +15,8 @@ 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.
|
|
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;
|
|
@@ -27,10 +28,11 @@ export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNa
|
|
|
27
28
|
export declare class TSInteropArgConvertor implements TypeConvertor<string> {
|
|
28
29
|
convert(type: idl.IDLType): string;
|
|
29
30
|
convertContainer(type: idl.IDLContainerType): string;
|
|
30
|
-
convertImport(type: idl.
|
|
31
|
+
convertImport(type: idl.IDLImport): string;
|
|
31
32
|
convertOptional(type: idl.IDLOptionalType): string;
|
|
32
33
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
33
34
|
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
35
|
+
convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
34
36
|
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
35
37
|
convertUnion(type: idl.IDLUnionType): string;
|
|
36
38
|
}
|
|
@@ -25,16 +25,18 @@ export class TSTypeNameConvertor {
|
|
|
25
25
|
return node.name;
|
|
26
26
|
}
|
|
27
27
|
convertInterface(node) {
|
|
28
|
-
return idl.
|
|
28
|
+
return idl.getQualifiedName(node, "namespace.name");
|
|
29
29
|
}
|
|
30
30
|
convertEnum(node) {
|
|
31
|
-
return idl.
|
|
31
|
+
return idl.getQualifiedName(node, "namespace.name");
|
|
32
32
|
}
|
|
33
33
|
convertTypedef(node) {
|
|
34
34
|
return node.name;
|
|
35
35
|
}
|
|
36
36
|
convertCallback(node) {
|
|
37
|
-
return node
|
|
37
|
+
return idl.isSyntheticEntry(node)
|
|
38
|
+
? this.mapCallback(node)
|
|
39
|
+
: node.name;
|
|
38
40
|
}
|
|
39
41
|
convertMethod(node) {
|
|
40
42
|
return node.name;
|
|
@@ -72,11 +74,23 @@ export class TSTypeNameConvertor {
|
|
|
72
74
|
}
|
|
73
75
|
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
74
76
|
}
|
|
75
|
-
convertImport(type
|
|
77
|
+
convertImport(type) {
|
|
78
|
+
console.warn("Imports are not implemented yet");
|
|
76
79
|
return type.name;
|
|
77
80
|
}
|
|
81
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
82
|
+
var _a;
|
|
83
|
+
const maybeTypeArguments = ((_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) ? `<${type.typeArguments.join(', ')}>` : "";
|
|
84
|
+
let decl = this.resolver.resolveTypeReference(type);
|
|
85
|
+
if (decl)
|
|
86
|
+
return `${decl.name}${maybeTypeArguments}`;
|
|
87
|
+
return `${type.name}${maybeTypeArguments}`;
|
|
88
|
+
}
|
|
78
89
|
convertTypeReference(type) {
|
|
79
90
|
var _a, _b;
|
|
91
|
+
if (type.name === idl.IDLObjectType.name) {
|
|
92
|
+
return type.name;
|
|
93
|
+
}
|
|
80
94
|
let decl = this.resolver.resolveTypeReference(type);
|
|
81
95
|
if (decl) {
|
|
82
96
|
if (idl.isSyntheticEntry(decl)) {
|
|
@@ -89,39 +103,42 @@ export class TSTypeNameConvertor {
|
|
|
89
103
|
return this.productType(decl, isTuple, !isTuple);
|
|
90
104
|
}
|
|
91
105
|
}
|
|
106
|
+
// FIXME: isEnumMember is not TYPE!
|
|
107
|
+
if (decl && idl.isEnumMember(decl) && decl.parent) {
|
|
108
|
+
// when `interface A { field?: MyEnum.Value1 }` is generated, it is not possible
|
|
109
|
+
// to deserialize A, because there is no such type information in declaration target
|
|
110
|
+
// (can not cast MyEnum to exact MyEnum.Value1)
|
|
111
|
+
decl = decl.parent;
|
|
112
|
+
}
|
|
113
|
+
let typeSpec = type.name;
|
|
114
|
+
let typeArgs = (_b = (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.convert(it))) !== null && _b !== void 0 ? _b : [];
|
|
115
|
+
if (typeSpec === `Optional`)
|
|
116
|
+
return `${typeArgs} | undefined`;
|
|
117
|
+
if (typeSpec === `Function`)
|
|
118
|
+
return this.mapFunctionType(typeArgs);
|
|
119
|
+
const maybeTypeArguments = !(typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) ? '' : `<${typeArgs.join(', ')}>`;
|
|
120
|
+
if (decl) {
|
|
121
|
+
const path = idl.getNamespacesPathFor(decl).map(it => it.name);
|
|
122
|
+
path.push(decl.name);
|
|
123
|
+
return `${path.join(".")}${maybeTypeArguments}`;
|
|
124
|
+
}
|
|
125
|
+
return `${type.name}${maybeTypeArguments}`;
|
|
92
126
|
}
|
|
93
|
-
|
|
94
|
-
if (decl && idl.isEnumMember(decl) && decl.parent) {
|
|
95
|
-
// when `interface A { field?: MyEnum.Value1 }` is generated, it is not possible
|
|
96
|
-
// to deserialize A, because there is no such type information in declaration target
|
|
97
|
-
// (can not cast MyEnum to exact MyEnum.Value1)
|
|
98
|
-
decl = decl.parent;
|
|
99
|
-
}
|
|
100
|
-
let typeSpec = type.name;
|
|
101
|
-
let typeArgs = (_b = (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it))) !== null && _b !== void 0 ? _b : [];
|
|
102
|
-
if (typeSpec === `Optional`)
|
|
103
|
-
return `${typeArgs} | undefined`;
|
|
104
|
-
if (typeSpec === `Function`)
|
|
105
|
-
return this.mapFunctionType(typeArgs);
|
|
106
|
-
const maybeTypeArguments = !(typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) ? '' : `<${typeArgs.join(', ')}>`;
|
|
107
|
-
if (decl) {
|
|
108
|
-
const path = idl.getNamespacesPathFor(decl).map(it => it.name);
|
|
109
|
-
path.push(decl.name);
|
|
110
|
-
return `${path.join(".")}${maybeTypeArguments}`;
|
|
111
|
-
}
|
|
112
|
-
return `${type.name}${maybeTypeArguments}`;
|
|
127
|
+
return this.convert(idl.IDLCustomObjectType);
|
|
113
128
|
}
|
|
114
129
|
convertTypeParameter(type) {
|
|
115
130
|
return type.name;
|
|
116
131
|
}
|
|
117
132
|
convertPrimitiveType(type) {
|
|
118
133
|
switch (type) {
|
|
134
|
+
case idl.IDLFunctionType: return 'Function';
|
|
119
135
|
case idl.IDLUnknownType:
|
|
120
136
|
case idl.IDLCustomObjectType: return 'unknown';
|
|
121
137
|
case idl.IDLThisType: return 'this';
|
|
122
138
|
case idl.IDLAnyType: return 'any';
|
|
123
139
|
case idl.IDLUndefinedType: return 'undefined';
|
|
124
140
|
case idl.IDLPointerType: return 'KPointer';
|
|
141
|
+
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
125
142
|
case idl.IDLVoidType: return 'void';
|
|
126
143
|
case idl.IDLBooleanType: return 'boolean';
|
|
127
144
|
case idl.IDLI32Type:
|
|
@@ -145,7 +162,7 @@ export class TSTypeNameConvertor {
|
|
|
145
162
|
case idl.IDLDate:
|
|
146
163
|
return 'Date';
|
|
147
164
|
case idl.IDLBufferType:
|
|
148
|
-
return
|
|
165
|
+
return 'NativeBuffer';
|
|
149
166
|
case idl.IDLInteropReturnBufferType:
|
|
150
167
|
return `KInteropReturnBuffer`;
|
|
151
168
|
}
|
|
@@ -155,7 +172,7 @@ export class TSTypeNameConvertor {
|
|
|
155
172
|
return idlProperty;
|
|
156
173
|
}
|
|
157
174
|
mapCallback(decl) {
|
|
158
|
-
const params = decl.parameters.map(it => `${it.isVariadic ? "..." : ""}${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}`);
|
|
175
|
+
const params = decl.parameters.map(it => `${it.isVariadic ? "..." : ""}${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}${it.isVariadic ? "[]" : ""}`);
|
|
159
176
|
return `((${params.join(", ")}) => ${this.convert(decl.returnType)})`;
|
|
160
177
|
}
|
|
161
178
|
productType(decl, isTuple, includeFieldNames) {
|
|
@@ -180,7 +197,7 @@ export class TSInteropArgConvertor {
|
|
|
180
197
|
convertContainer(type) {
|
|
181
198
|
throw new Error(`Cannot pass container types through interop`);
|
|
182
199
|
}
|
|
183
|
-
convertImport(type
|
|
200
|
+
convertImport(type) {
|
|
184
201
|
throw new Error(`Cannot pass import types through interop`);
|
|
185
202
|
}
|
|
186
203
|
convertOptional(type) {
|
|
@@ -191,14 +208,14 @@ export class TSInteropArgConvertor {
|
|
|
191
208
|
case idl.IDLI64Type: return "KLong";
|
|
192
209
|
case idl.IDLU64Type: return "KLong";
|
|
193
210
|
case idl.IDLI32Type: return "KInt";
|
|
211
|
+
case idl.IDLU32Type: return "KInt";
|
|
194
212
|
case idl.IDLF32Type: return "KFloat";
|
|
195
213
|
case idl.IDLNumberType: return 'number';
|
|
196
214
|
case idl.IDLBigintType: return 'bigint';
|
|
197
215
|
case idl.IDLBooleanType:
|
|
198
216
|
case idl.IDLFunctionType: return 'KInt';
|
|
199
217
|
case idl.IDLStringType: return 'KStringPtr';
|
|
200
|
-
case idl.IDLBufferType: return
|
|
201
|
-
case idl.IDLLengthType: return 'Length';
|
|
218
|
+
case idl.IDLBufferType: return 'ArrayBuffer';
|
|
202
219
|
case idl.IDLDate: return 'number';
|
|
203
220
|
case idl.IDLUndefinedType:
|
|
204
221
|
case idl.IDLVoidType:
|
|
@@ -209,6 +226,9 @@ export class TSInteropArgConvertor {
|
|
|
209
226
|
convertTypeParameter(type) {
|
|
210
227
|
throw new Error("Cannot pass type parameters through interop");
|
|
211
228
|
}
|
|
229
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
230
|
+
throw new Error(`Cannot pass import types through interop`);
|
|
231
|
+
}
|
|
212
232
|
convertTypeReference(type) {
|
|
213
233
|
throw new Error(`Cannot pass type references through interop`);
|
|
214
234
|
}
|
|
@@ -6,13 +6,15 @@ export interface TypeConvertor<T> {
|
|
|
6
6
|
convertOptional(type: idl.IDLOptionalType): T;
|
|
7
7
|
convertUnion(type: idl.IDLUnionType): T;
|
|
8
8
|
convertContainer(type: idl.IDLContainerType): T;
|
|
9
|
-
convertImport(type: idl.
|
|
9
|
+
convertImport(type: idl.IDLImport): T;
|
|
10
|
+
convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): T;
|
|
10
11
|
convertTypeReference(type: idl.IDLReferenceType): T;
|
|
11
12
|
convertTypeParameter(type: idl.IDLTypeParameterType): T;
|
|
12
13
|
convertPrimitiveType(type: idl.IDLPrimitiveType): T;
|
|
13
14
|
}
|
|
14
15
|
export declare function convertType<T>(convertor: TypeConvertor<T>, type: idl.IDLType): T;
|
|
15
16
|
export interface DeclarationConvertor<T> {
|
|
17
|
+
convertImport(node: idl.IDLImport): T;
|
|
16
18
|
convertNamespace(node: idl.IDLNamespace): T;
|
|
17
19
|
convertInterface(node: idl.IDLInterface): T;
|
|
18
20
|
convertEnum(node: idl.IDLEnum): T;
|
|
@@ -20,10 +20,12 @@ export function convertType(convertor, type) {
|
|
|
20
20
|
return convertor.convertUnion(type);
|
|
21
21
|
if (idl.isContainerType(type))
|
|
22
22
|
return convertor.convertContainer(type);
|
|
23
|
+
if (idl.isImport(type))
|
|
24
|
+
return convertor.convertImport(type);
|
|
23
25
|
if (idl.isReferenceType(type)) {
|
|
24
26
|
const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
|
|
25
27
|
return importAttr
|
|
26
|
-
? convertor.
|
|
28
|
+
? convertor.convertTypeReferenceAsImport(type, importAttr)
|
|
27
29
|
: convertor.convertTypeReference(type);
|
|
28
30
|
}
|
|
29
31
|
if (idl.isTypeParameterType(type))
|
|
@@ -33,6 +35,8 @@ export function convertType(convertor, type) {
|
|
|
33
35
|
throw new Error(`Unknown type ${idl.IDLKind[type.kind]}`);
|
|
34
36
|
}
|
|
35
37
|
export function convertDeclaration(convertor, decl) {
|
|
38
|
+
if (idl.isImport(decl))
|
|
39
|
+
return convertor.convertImport(decl);
|
|
36
40
|
if (idl.isNamespace(decl))
|
|
37
41
|
return convertor.convertNamespace(decl);
|
|
38
42
|
if (idl.isInterface(decl))
|