@idlizer/core 2.1.10-arktscgen-4 → 2.1.10-arktscgen-6
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/Language.d.ts +0 -1
- package/build/lib/src/Language.js +1 -3
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -7
- package/build/lib/src/LanguageWriters/ArgConvertors.js +95 -103
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +13 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -2
- package/build/lib/src/LanguageWriters/common.d.ts +1 -0
- package/build/lib/src/LanguageWriters/common.js +2 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -3
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +14 -8
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +88 -36
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +9 -5
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +98 -44
- package/build/lib/src/LanguageWriters/index.d.ts +5 -4
- package/build/lib/src/LanguageWriters/index.js +8 -15
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +13 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +8 -2
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +52 -92
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +8 -0
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +75 -27
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +5 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +58 -18
- package/build/lib/src/LibraryInterface.d.ts +0 -1
- package/build/lib/src/config.d.ts +2 -1461
- package/build/lib/src/config.js +16 -32
- package/build/lib/src/configMerge.d.ts +3 -0
- package/build/lib/src/configMerge.js +63 -0
- package/build/lib/src/diagnostictypes.d.ts +1 -5
- package/build/lib/src/diagnostictypes.js +1 -27
- package/build/lib/src/from-idl/DtsPrinter.js +13 -6
- package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
- package/build/lib/src/from-idl/IDLLinter.js +30 -32
- package/build/lib/src/from-idl/deserialize.d.ts +3 -4
- package/build/lib/src/from-idl/deserialize.js +30 -642
- package/build/lib/src/from-idl/parser.d.ts +20 -2
- package/build/lib/src/from-idl/parser.js +97 -29
- package/build/lib/src/idl/builders.d.ts +43 -0
- package/build/lib/src/idl/builders.js +135 -0
- package/build/lib/src/idl/discriminators.d.ts +53 -0
- package/build/lib/src/idl/discriminators.js +232 -0
- package/build/lib/src/idl/dump.d.ts +48 -0
- package/build/lib/src/idl/dump.js +327 -0
- package/build/lib/src/idl/index.d.ts +9 -0
- package/build/lib/src/idl/index.js +23 -0
- package/build/lib/src/idl/keywords.d.ts +2 -0
- package/build/lib/src/{options.js → idl/keywords.js} +7 -3
- package/build/lib/src/idl/node.d.ts +233 -0
- package/build/lib/src/idl/node.js +103 -0
- package/build/lib/src/idl/stdlib.d.ts +34 -0
- package/build/lib/src/idl/stdlib.js +54 -0
- package/build/lib/src/idl/utils.d.ts +44 -0
- package/build/lib/src/idl/utils.js +215 -0
- package/build/lib/src/idl/visitors.d.ts +15 -0
- package/build/lib/src/idl/visitors.js +593 -0
- package/build/lib/src/index.d.ts +5 -6
- package/build/lib/src/index.js +6 -7
- package/build/lib/src/inheritance.d.ts +0 -2
- package/build/lib/src/inheritance.js +0 -17
- package/build/lib/src/inputPaths.d.ts +11 -0
- package/build/lib/src/inputPaths.js +81 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
- package/build/lib/src/languageSpecificKeywords.js +0 -5
- package/build/lib/src/peer-generation/ConflictingDeclarations.d.ts +6 -0
- package/build/lib/src/peer-generation/ConflictingDeclarations.js +43 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +3 -1
- package/build/lib/src/peer-generation/LayoutManager.js +15 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +8 -0
- package/build/lib/src/peer-generation/Materialized.js +26 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -18
- package/build/lib/src/peer-generation/PeerLibrary.js +63 -227
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +6 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +15 -3
- package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
- package/build/lib/src/peer-generation/idl/common.js +7 -7
- package/build/lib/src/peer-generation/isMaterialized.js +2 -3
- package/build/lib/src/peer-generation/modules.js +2 -0
- package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
- package/build/lib/src/peer-generation/toDeclaration.js +53 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +15 -7
- package/build/lib/src/resolveNamedNode.d.ts +1 -0
- package/build/lib/src/resolveNamedNode.js +7 -0
- package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
- package/build/lib/src/transformers/FqnTransformer.js +20 -12
- package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
- package/build/lib/src/transformers/GenericTransformer.js +252 -158
- package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
- package/build/lib/src/transformers/IdlTransformer.js +7 -0
- package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
- package/build/lib/src/transformers/NullTransformer.js +27 -21
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
- package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
- package/build/lib/src/util.d.ts +9 -39
- package/build/lib/src/util.js +65 -369
- package/package.json +44 -49
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -83
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -295
- package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
- package/build/lib/src/from-idl/webidl2-utils.js +0 -87
- package/build/lib/src/idl.d.ts +0 -439
- package/build/lib/src/idl.js +0 -1367
- package/build/lib/src/idlize.d.ts +0 -25
- package/build/lib/src/idlize.js +0 -198
- package/build/lib/src/options.d.ts +0 -13
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
- package/build/lib/src/peer-generation/BuilderClass.js +0 -68
- package/webidl2.js/dist/webidl2.js +0 -4622
- package/webidl2.js/package.json +0 -55
|
@@ -13,18 +13,31 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../../idl';
|
|
16
|
-
import { generatorConfiguration
|
|
16
|
+
import { generatorConfiguration } from "../../config";
|
|
17
17
|
import { convertNode, convertType } from "../nameConvertor";
|
|
18
18
|
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
19
|
import { InteropArgConvertor } from './InteropConvertors';
|
|
20
20
|
import { maybeTransformManagedCallback } from '../ArgConvertors';
|
|
21
21
|
import { qualifiedName } from '../../peer-generation/idl/common';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
22
|
+
import { isInIdlizeInternal } from '../../idl';
|
|
23
|
+
import { isTopLevelConflicted } from '../../peer-generation/ConflictingDeclarations';
|
|
24
|
+
import { Language } from '../../Language';
|
|
25
|
+
function isSubtypeTopLevelConflicted(library, node) {
|
|
26
|
+
let hasConflicts = false;
|
|
27
|
+
idl.forEachChild(node, (child) => {
|
|
28
|
+
if (idl.isReferenceType(child)) {
|
|
29
|
+
const decl = library.resolveTypeReference(child);
|
|
30
|
+
if (decl) {
|
|
31
|
+
hasConflicts || (hasConflicts = isTopLevelConflicted(library, Language.CPP, decl));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return hasConflicts;
|
|
36
|
+
}
|
|
25
37
|
export class GenericCppConvertor {
|
|
26
|
-
constructor(
|
|
27
|
-
this.
|
|
38
|
+
constructor(library) {
|
|
39
|
+
this.library = library;
|
|
40
|
+
this.isInsideStructure = false;
|
|
28
41
|
}
|
|
29
42
|
make(text, resolvedType, noPrefix = false) {
|
|
30
43
|
return { text, noPrefix, resolvedType };
|
|
@@ -78,22 +91,29 @@ export class GenericCppConvertor {
|
|
|
78
91
|
return this.make(prefix + converted.text, type, true);
|
|
79
92
|
}
|
|
80
93
|
convertUnion(type) {
|
|
81
|
-
return this.
|
|
94
|
+
return this.insideStructure(() => {
|
|
95
|
+
if (type.parent && idl.isTypedef(type.parent)) {
|
|
96
|
+
return this.make(type.parent.name, type, false);
|
|
97
|
+
}
|
|
98
|
+
return this.make('Union_' + type.types.map(it => convertType(this, it).text).join("_"), type, false);
|
|
99
|
+
});
|
|
82
100
|
}
|
|
83
101
|
convertContainer(type) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
88
|
-
if (type.elementType[0] === idl.IDLU8Type) {
|
|
89
|
-
return this.make(`uint8_t*`, type, true);
|
|
102
|
+
return this.insideStructure(() => {
|
|
103
|
+
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
104
|
+
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`, type);
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
107
|
+
if (type.elementType[0] === idl.IDLU8Type) {
|
|
108
|
+
return this.make(`uint8_t*`, type, true);
|
|
109
|
+
}
|
|
110
|
+
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, type, true);
|
|
111
|
+
}
|
|
112
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
113
|
+
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, type, true);
|
|
114
|
+
}
|
|
115
|
+
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
116
|
+
});
|
|
97
117
|
}
|
|
98
118
|
convertImport(type) {
|
|
99
119
|
console.warn("Imports are not implemented yet");
|
|
@@ -108,14 +128,11 @@ export class GenericCppConvertor {
|
|
|
108
128
|
if (generatorConfiguration().parameterized.includes(refName)) {
|
|
109
129
|
return this.make('CustomObject', idl.IDLCustomObjectType);
|
|
110
130
|
}
|
|
111
|
-
let decl = this.
|
|
131
|
+
let decl = this.library.toDeclaration(type);
|
|
112
132
|
if (idl.isCallback(decl)) {
|
|
113
|
-
decl = (_a = maybeTransformManagedCallback(decl, this.
|
|
133
|
+
decl = (_a = maybeTransformManagedCallback(decl, this.library)) !== null && _a !== void 0 ? _a : decl;
|
|
114
134
|
}
|
|
115
135
|
if (idl.isType(decl)) {
|
|
116
|
-
if (idl.isReferenceType(decl)) {
|
|
117
|
-
return this.make(`${capitalize(decl.name)}`, decl);
|
|
118
|
-
}
|
|
119
136
|
return this.convertNode(decl);
|
|
120
137
|
}
|
|
121
138
|
let res = this.convertNode(decl);
|
|
@@ -127,6 +144,26 @@ export class GenericCppConvertor {
|
|
|
127
144
|
return this.make('CustomObject', idl.IDLCustomObjectType);
|
|
128
145
|
}
|
|
129
146
|
convertPrimitiveType(type) {
|
|
147
|
+
if (this.isInsideStructure) {
|
|
148
|
+
switch (type) {
|
|
149
|
+
case idl.IDLVoidType:
|
|
150
|
+
return this.make(`Void`, type);
|
|
151
|
+
case idl.IDLI32Type:
|
|
152
|
+
return this.make('I32', type);
|
|
153
|
+
case idl.IDLU32Type:
|
|
154
|
+
return this.make('U32', type);
|
|
155
|
+
case idl.IDLF32Type:
|
|
156
|
+
return this.make('F32', type);
|
|
157
|
+
case idl.IDLI64Type:
|
|
158
|
+
return this.make('I64', type);
|
|
159
|
+
case idl.IDLU64Type:
|
|
160
|
+
return this.make('U64', type);
|
|
161
|
+
case idl.IDLF64Type:
|
|
162
|
+
return this.make('F64', type);
|
|
163
|
+
case idl.IDLPointerType:
|
|
164
|
+
return this.make('Pointer', type);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
130
167
|
switch (type) {
|
|
131
168
|
case idl.IDLThisType: // maybe fix it in another level?
|
|
132
169
|
case idl.IDLVoidType: return this.make('void', type, true);
|
|
@@ -159,6 +196,9 @@ export class GenericCppConvertor {
|
|
|
159
196
|
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
160
197
|
}
|
|
161
198
|
qualifiedName(target) {
|
|
199
|
+
if (idl.isEntry(target) && isTopLevelConflicted(this.library, Language.CPP, target)) {
|
|
200
|
+
return qualifiedName(target, "_", "package.namespace.name");
|
|
201
|
+
}
|
|
162
202
|
return qualifiedName(target, "_", "namespace.name");
|
|
163
203
|
}
|
|
164
204
|
computeTargetTypeLiteralName(decl) {
|
|
@@ -172,6 +212,13 @@ export class GenericCppConvertor {
|
|
|
172
212
|
const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
|
|
173
213
|
return `Literal_${names.join('_')}`;
|
|
174
214
|
}
|
|
215
|
+
insideStructure(cb) {
|
|
216
|
+
const prevIsInsideScructure = this.isInsideStructure;
|
|
217
|
+
this.isInsideStructure = true;
|
|
218
|
+
const result = cb();
|
|
219
|
+
this.isInsideStructure = prevIsInsideScructure;
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
175
222
|
}
|
|
176
223
|
export class CppConvertor extends GenericCppConvertor {
|
|
177
224
|
unwrap(type, result) {
|
|
@@ -188,10 +235,10 @@ export class CppConvertor extends GenericCppConvertor {
|
|
|
188
235
|
isPrimitiveOrPrimitiveAlias(type) {
|
|
189
236
|
if (!idl.isType(type))
|
|
190
237
|
return false;
|
|
191
|
-
const {
|
|
238
|
+
const { library } = this;
|
|
192
239
|
const seen = new Set;
|
|
193
240
|
while (type && idl.isReferenceType(type)) {
|
|
194
|
-
const resolved =
|
|
241
|
+
const resolved = library.resolveTypeReference(type);
|
|
195
242
|
if (!resolved)
|
|
196
243
|
return false;
|
|
197
244
|
if (!idl.isTypedef(resolved))
|
|
@@ -208,14 +255,23 @@ export class CppConvertor extends GenericCppConvertor {
|
|
|
208
255
|
}
|
|
209
256
|
}
|
|
210
257
|
export class CppNameConvertor {
|
|
211
|
-
constructor(
|
|
212
|
-
this.
|
|
213
|
-
this.cppConvertor = new GenericCppConvertor(
|
|
258
|
+
constructor(library) {
|
|
259
|
+
this.library = library;
|
|
260
|
+
this.cppConvertor = new GenericCppConvertor(library);
|
|
214
261
|
}
|
|
215
262
|
convert(node) {
|
|
216
263
|
return this.cppConvertor.convertNode(node).text;
|
|
217
264
|
}
|
|
218
265
|
}
|
|
266
|
+
export class StructureNameConvertor extends CppConvertor {
|
|
267
|
+
constructor(library) {
|
|
268
|
+
super(library);
|
|
269
|
+
this.isInsideStructure = true;
|
|
270
|
+
}
|
|
271
|
+
convert(node) {
|
|
272
|
+
return this.convertNode(node).text;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
219
275
|
export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
220
276
|
convertOptional(type) {
|
|
221
277
|
return PrimitiveTypesInstance.NativePointer.getText();
|
|
@@ -236,9 +292,9 @@ export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
|
236
292
|
}
|
|
237
293
|
CppInteropArgConvertor.INSTANCE = new CppInteropArgConvertor();
|
|
238
294
|
export class CppReturnTypeConvertor {
|
|
239
|
-
constructor(
|
|
240
|
-
this.
|
|
241
|
-
this.convertor = new CppConvertor(
|
|
295
|
+
constructor(library) {
|
|
296
|
+
this.library = library;
|
|
297
|
+
this.convertor = new CppConvertor(library);
|
|
242
298
|
}
|
|
243
299
|
isVoid(returnType) {
|
|
244
300
|
return this.convert(returnType) == 'void';
|
|
@@ -271,10 +327,6 @@ export class CppReturnTypeConvertor {
|
|
|
271
327
|
return this.convertor.convert(type);
|
|
272
328
|
}
|
|
273
329
|
convertTypeReference(type) {
|
|
274
|
-
const decl = this.resolver.resolveTypeReference(type);
|
|
275
|
-
if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
|
|
276
|
-
return generatorTypePrefix() + qualifiedName(decl, "_", "namespace.name");
|
|
277
|
-
}
|
|
278
330
|
return this.convertor.convert(type);
|
|
279
331
|
}
|
|
280
332
|
convertUnion(type) {
|
|
@@ -10,5 +10,6 @@ export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
10
10
|
protected mapFunctionType(typeArgs: string[]): string;
|
|
11
11
|
}
|
|
12
12
|
export declare class ETSInteropArgConvertor extends TSInteropArgConvertor {
|
|
13
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=ETSConvertors.d.ts.map
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from "../../idl";
|
|
16
16
|
import { LanguageWriter } from "../LanguageWriter";
|
|
17
|
+
import { isInsideInstanceof } from "../nameConvertor";
|
|
17
18
|
import { TSInteropArgConvertor, TSTypeNameConvertor } from "./TSConvertors";
|
|
18
19
|
export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
19
20
|
convertTypeReference(type) {
|
|
@@ -25,18 +26,13 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
25
26
|
}
|
|
26
27
|
// TODO: Fix for 'TypeError: Type 'Function<R>' is generic but type argument were not provided.'
|
|
27
28
|
if (typeName === "Function") {
|
|
28
|
-
return "Function<void>";
|
|
29
|
+
return isInsideInstanceof() ? "Function" : "Function<void>";
|
|
29
30
|
}
|
|
30
31
|
return typeName;
|
|
31
32
|
}
|
|
32
33
|
convertContainer(type) {
|
|
33
34
|
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
34
|
-
|
|
35
|
-
case idl.IDLU8Type: return 'KUint8ArrayPtr';
|
|
36
|
-
case idl.IDLI32Type: return 'KInt32ArrayPtr';
|
|
37
|
-
case idl.IDLF32Type: return 'KFloat32ArrayPtr';
|
|
38
|
-
}
|
|
39
|
-
return `Array<${this.convert(type.elementType[0])}>`;
|
|
35
|
+
return isInsideInstanceof() ? `Array` : `Array<${this.convert(type.elementType[0])}>`;
|
|
40
36
|
}
|
|
41
37
|
return super.convertContainer(type);
|
|
42
38
|
}
|
|
@@ -95,9 +91,15 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
95
91
|
if (typeArgs.length === 0) {
|
|
96
92
|
typeArgs = [this.convert(idl.IDLVoidType)];
|
|
97
93
|
}
|
|
98
|
-
return `Function${typeArgs.length - 1}<${typeArgs.join(",")}>`;
|
|
94
|
+
return isInsideInstanceof() ? `Function${typeArgs.length - 1}` : `Function${typeArgs.length - 1}<${typeArgs.join(",")}>`;
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
export class ETSInteropArgConvertor extends TSInteropArgConvertor {
|
|
98
|
+
convertPrimitiveType(type) {
|
|
99
|
+
switch (type) {
|
|
100
|
+
case idl.IDLBigintType: return 'long';
|
|
101
|
+
}
|
|
102
|
+
return super.convertPrimitiveType(type);
|
|
103
|
+
}
|
|
102
104
|
}
|
|
103
105
|
//# sourceMappingURL=ETSConvertors.js.map
|
|
@@ -84,7 +84,7 @@ export class InteropReturnTypeConvertor {
|
|
|
84
84
|
if (decl) {
|
|
85
85
|
// Callbacks and array types return by value
|
|
86
86
|
if (idl.isCallback(this.resolver.toDeclaration(type))) {
|
|
87
|
-
return
|
|
87
|
+
return KInteropReturnBuffer;
|
|
88
88
|
}
|
|
89
89
|
if (idl.isInterface(decl)) {
|
|
90
90
|
if (isMaterialized(decl, this.resolver)) {
|
|
@@ -16,7 +16,7 @@ import * as idl from '../../idl';
|
|
|
16
16
|
import { generateSyntheticIdlNodeName } from '../../peer-generation/idl/common';
|
|
17
17
|
import { isMaterialized } from '../../peer-generation/isMaterialized';
|
|
18
18
|
import { convertNode, convertType } from '../nameConvertor';
|
|
19
|
-
import { removePoints } from '
|
|
19
|
+
import { removePoints } from '../../util';
|
|
20
20
|
import { InteropReturnTypeConvertor } from './InteropConvertors';
|
|
21
21
|
export class KotlinTypeNameConvertor {
|
|
22
22
|
constructor(resolver) {
|
|
@@ -55,6 +55,11 @@ export class KotlinTypeNameConvertor {
|
|
|
55
55
|
}
|
|
56
56
|
convertContainer(type) {
|
|
57
57
|
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
58
|
+
switch (type.elementType[0]) {
|
|
59
|
+
case idl.IDLU8Type: return "UByteArray";
|
|
60
|
+
case idl.IDLI32Type: return "IntArray";
|
|
61
|
+
case idl.IDLF32Type: return "FloatArray";
|
|
62
|
+
}
|
|
58
63
|
return `ArrayList<${convertType(this, type.elementType[0])}>`;
|
|
59
64
|
}
|
|
60
65
|
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
@@ -93,7 +98,7 @@ export class KotlinTypeNameConvertor {
|
|
|
93
98
|
case idl.IDLUnknownType:
|
|
94
99
|
case idl.IDLCustomObjectType: return 'Any';
|
|
95
100
|
case idl.IDLThisType: return 'this';
|
|
96
|
-
case idl.IDLObjectType: return '
|
|
101
|
+
case idl.IDLObjectType: return 'Any';
|
|
97
102
|
case idl.IDLAnyType: return 'Any';
|
|
98
103
|
case idl.IDLUndefinedType: return 'Nothing?';
|
|
99
104
|
case idl.IDLPointerType: return 'KPointer';
|
|
@@ -135,7 +140,6 @@ const KLong = "KLong";
|
|
|
135
140
|
const KFloat = "KFloat";
|
|
136
141
|
const KDouble = "KDouble";
|
|
137
142
|
const KNativePointer = "KNativePointer";
|
|
138
|
-
const KInteropNumber = "KInteropNumber";
|
|
139
143
|
const KStringPtr = "KStringPtr";
|
|
140
144
|
const KInteropReturnBuffer = "KInteropReturnBuffer";
|
|
141
145
|
const KInteropBuffer = "KInteropBuffer";
|
|
@@ -154,7 +158,7 @@ export class KotlinCInteropReturnTypeConvertor extends InteropReturnTypeConverto
|
|
|
154
158
|
case idl.IDLF16Type:
|
|
155
159
|
case idl.IDLF32Type:
|
|
156
160
|
case idl.IDLF64Type: return KInt;
|
|
157
|
-
case idl.IDLNumberType: return
|
|
161
|
+
case idl.IDLNumberType: return KDouble;
|
|
158
162
|
case idl.IDLBooleanType: return KBoolean;
|
|
159
163
|
case idl.IDLBigintType: return KLong;
|
|
160
164
|
case idl.IDLAnyType:
|
|
@@ -218,7 +222,7 @@ export class KotlinCInteropArgConvertor {
|
|
|
218
222
|
case idl.IDLU32Type: return KInt;
|
|
219
223
|
case idl.IDLF32Type: return KFloat;
|
|
220
224
|
case idl.IDLF64Type: return KDouble;
|
|
221
|
-
case idl.IDLNumberType: return
|
|
225
|
+
case idl.IDLNumberType: return KDouble;
|
|
222
226
|
case idl.IDLBigintType: return KLong;
|
|
223
227
|
case idl.IDLSerializerBuffer: return KSerializerBuffer;
|
|
224
228
|
case idl.IDLBooleanType:
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as idl from '../../idl';
|
|
2
|
-
import {
|
|
2
|
+
import { LibraryInterface } from '../../LibraryInterface';
|
|
3
3
|
import { IdlNameConvertor, NodeConvertor, TypeConvertor } from '../nameConvertor';
|
|
4
4
|
export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
|
|
5
|
-
protected
|
|
6
|
-
constructor(
|
|
5
|
+
protected library: LibraryInterface;
|
|
6
|
+
constructor(library: LibraryInterface);
|
|
7
|
+
protected mangleTopLevel(decl: idl.IDLEntry): string | undefined;
|
|
7
8
|
convert(node: idl.IDLNode): string;
|
|
8
9
|
convertNamespace(node: idl.IDLNamespace): string;
|
|
9
10
|
convertInterface(node: idl.IDLInterface): string;
|
|
@@ -22,7 +23,6 @@ export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNa
|
|
|
22
23
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
23
24
|
protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
|
|
24
25
|
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
26
|
protected mapCallback(decl: idl.IDLCallback, args?: idl.IDLType[]): string;
|
|
27
27
|
protected productType(decl: idl.IDLInterface, args: idl.IDLType[] | undefined, isTuple: boolean, includeFieldNames: boolean): string;
|
|
28
28
|
protected mapFunctionType(typeArgs: string[]): string;
|
|
@@ -13,11 +13,26 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../../idl';
|
|
16
|
+
import { Language } from '../../Language';
|
|
17
|
+
import { isTopLevelConflicted } from '../../peer-generation/ConflictingDeclarations';
|
|
18
|
+
import { isDeclaredInCurrentFile, LayoutNodeRole } from '../../peer-generation/LayoutManager';
|
|
16
19
|
import { maybeRestoreGenerics } from '../../transformers/GenericTransformer';
|
|
17
|
-
import { convertNode, convertType } from '../nameConvertor';
|
|
20
|
+
import { convertNode, convertType, isInsideInstanceof } from '../nameConvertor';
|
|
18
21
|
export class TSTypeNameConvertor {
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
22
|
+
constructor(library) {
|
|
23
|
+
this.library = library;
|
|
24
|
+
}
|
|
25
|
+
mangleTopLevel(decl) {
|
|
26
|
+
if (!isDeclaredInCurrentFile(this.library.layout, { node: decl, role: LayoutNodeRole.INTERFACE }) && isTopLevelConflicted(this.library, Language.TS, decl)) {
|
|
27
|
+
const namespaces = idl.getNamespacesPathFor(decl);
|
|
28
|
+
if (namespaces.length === 0) {
|
|
29
|
+
return idl.getQualifiedName(decl, "package.namespace.name").replaceAll('.', '_');
|
|
30
|
+
}
|
|
31
|
+
const [rootNamespace, ...otherNamespaces] = idl.getNamespacesPathFor(decl);
|
|
32
|
+
const mangledRoot = idl.getQualifiedName(rootNamespace, "package.namespace.name").replaceAll('.', '_');
|
|
33
|
+
return [mangledRoot, ...otherNamespaces, decl.name].join(".");
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
21
36
|
}
|
|
22
37
|
convert(node) {
|
|
23
38
|
return convertNode(this, node);
|
|
@@ -26,18 +41,24 @@ export class TSTypeNameConvertor {
|
|
|
26
41
|
return node.name;
|
|
27
42
|
}
|
|
28
43
|
convertInterface(node) {
|
|
29
|
-
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = this.mangleTopLevel(node)) !== null && _a !== void 0 ? _a : idl.getQualifiedName(node, "namespace.name");
|
|
30
46
|
}
|
|
31
47
|
convertEnum(node) {
|
|
32
|
-
|
|
48
|
+
var _a;
|
|
49
|
+
return (_a = this.mangleTopLevel(node)) !== null && _a !== void 0 ? _a : idl.getQualifiedName(node, "namespace.name");
|
|
33
50
|
}
|
|
34
51
|
convertTypedef(node) {
|
|
35
|
-
|
|
52
|
+
var _a;
|
|
53
|
+
if (idl.isSyntheticEntry(node))
|
|
54
|
+
return this.convert(node.type);
|
|
55
|
+
return (_a = this.mangleTopLevel(node)) !== null && _a !== void 0 ? _a : idl.getQualifiedName(node, "namespace.name");
|
|
36
56
|
}
|
|
37
57
|
convertCallback(node) {
|
|
58
|
+
var _a;
|
|
38
59
|
return idl.isSyntheticEntry(node)
|
|
39
60
|
? this.mapCallback(node)
|
|
40
|
-
: node.name;
|
|
61
|
+
: (_a = this.mangleTopLevel(node)) !== null && _a !== void 0 ? _a : node.name;
|
|
41
62
|
}
|
|
42
63
|
convertMethod(node) {
|
|
43
64
|
return node.name;
|
|
@@ -68,18 +89,13 @@ export class TSTypeNameConvertor {
|
|
|
68
89
|
}
|
|
69
90
|
convertContainer(type) {
|
|
70
91
|
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
71
|
-
|
|
72
|
-
case idl.IDLU8Type: return 'Uint8Array'; // should be changed to Array
|
|
73
|
-
case idl.IDLI32Type: return 'Int32Array'; // should be changed to Array
|
|
74
|
-
case idl.IDLF32Type: return 'KFloat32ArrayPtr'; // should be changed to Array
|
|
75
|
-
default: return `Array<${this.convert(type.elementType[0])}>`;
|
|
76
|
-
}
|
|
92
|
+
return isInsideInstanceof() ? `Array` : `Array<${this.convert(type.elementType[0])}>`;
|
|
77
93
|
}
|
|
78
94
|
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
79
|
-
return `Map<${this.convert(type.elementType[0])}, ${this.convert(type.elementType[1])}>`;
|
|
95
|
+
return isInsideInstanceof() ? `Map` : `Map<${this.convert(type.elementType[0])}, ${this.convert(type.elementType[1])}>`;
|
|
80
96
|
}
|
|
81
97
|
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
82
|
-
return `Promise<${this.convert(type.elementType[0])}>`;
|
|
98
|
+
return isInsideInstanceof() ? `Promise` : `Promise<${this.convert(type.elementType[0])}>`;
|
|
83
99
|
}
|
|
84
100
|
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
85
101
|
}
|
|
@@ -89,20 +105,23 @@ export class TSTypeNameConvertor {
|
|
|
89
105
|
}
|
|
90
106
|
convertTypeReferenceAsImport(type, importClause) {
|
|
91
107
|
var _a;
|
|
92
|
-
const maybeTypeArguments = ((_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) ? `<${type.typeArguments.join(', ')}>` : "";
|
|
93
|
-
let decl = this.
|
|
108
|
+
const maybeTypeArguments = ((_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) && !isInsideInstanceof() ? `<${type.typeArguments.join(', ')}>` : "";
|
|
109
|
+
let decl = this.library.resolveTypeReference(type);
|
|
94
110
|
if (decl)
|
|
95
111
|
return `${decl.name}${maybeTypeArguments}`;
|
|
96
112
|
return `${type.name}${maybeTypeArguments}`;
|
|
97
113
|
}
|
|
98
114
|
convertTypeReference(type) {
|
|
99
|
-
var _a, _b;
|
|
100
|
-
let decl = this.
|
|
115
|
+
var _a, _b, _c;
|
|
116
|
+
let decl = this.library.resolveTypeReference(type);
|
|
101
117
|
if (decl) {
|
|
102
118
|
if (idl.isSyntheticEntry(decl)) {
|
|
103
119
|
if (idl.isCallback(decl)) {
|
|
104
120
|
return this.mapCallback(decl, type.typeArguments);
|
|
105
121
|
}
|
|
122
|
+
if (idl.isTypedef(decl)) {
|
|
123
|
+
return this.convert(decl.type);
|
|
124
|
+
}
|
|
106
125
|
const entity = idl.getExtAttribute(decl, idl.IDLExtendedAttributes.Entity);
|
|
107
126
|
if (entity) {
|
|
108
127
|
const isTuple = entity === idl.IDLEntity.Tuple;
|
|
@@ -116,13 +135,15 @@ export class TSTypeNameConvertor {
|
|
|
116
135
|
// (can not cast MyEnum to exact MyEnum.Value1)
|
|
117
136
|
decl = decl.parent;
|
|
118
137
|
}
|
|
119
|
-
let maybeRestoredGeneric = maybeRestoreGenerics(type, this.
|
|
138
|
+
let maybeRestoredGeneric = maybeRestoreGenerics(type, this.library);
|
|
120
139
|
if (maybeRestoredGeneric) {
|
|
121
140
|
type = maybeRestoredGeneric;
|
|
122
|
-
decl = this.
|
|
141
|
+
decl = this.library.resolveTypeReference(maybeRestoredGeneric);
|
|
123
142
|
}
|
|
124
143
|
let typeSpec = type.name;
|
|
125
|
-
let typeArgs = (
|
|
144
|
+
let typeArgs = !isInsideInstanceof() || decl && idl.isCallback(decl)
|
|
145
|
+
? (_b = (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.convert(it))) !== null && _b !== void 0 ? _b : []
|
|
146
|
+
: [];
|
|
126
147
|
if (typeSpec === `Optional`)
|
|
127
148
|
return `${typeArgs} | undefined`;
|
|
128
149
|
if (typeSpec === `Function`)
|
|
@@ -131,7 +152,7 @@ export class TSTypeNameConvertor {
|
|
|
131
152
|
if (decl) {
|
|
132
153
|
const path = idl.getNamespacesPathFor(decl).map(it => it.name);
|
|
133
154
|
path.push(decl.name);
|
|
134
|
-
return `${path.join(".")}${maybeTypeArguments}`;
|
|
155
|
+
return `${(_c = this.mangleTopLevel(decl)) !== null && _c !== void 0 ? _c : path.join(".")}${maybeTypeArguments}`;
|
|
135
156
|
}
|
|
136
157
|
return `${type.name}${maybeTypeArguments}`;
|
|
137
158
|
}
|
|
@@ -192,27 +213,16 @@ export class TSTypeNameConvertor {
|
|
|
192
213
|
}
|
|
193
214
|
return subst;
|
|
194
215
|
}
|
|
195
|
-
applySubstitution(subst, type) {
|
|
196
|
-
var _a;
|
|
197
|
-
if (idl.isContainerType(type)) {
|
|
198
|
-
return idl.createContainerType(type.containerKind, type.elementType.map(it => this.applySubstitution(subst, it)));
|
|
199
|
-
}
|
|
200
|
-
if (idl.isReferenceType(type)) {
|
|
201
|
-
return idl.createReferenceType(type.name, (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.applySubstitution(subst, it)));
|
|
202
|
-
}
|
|
203
|
-
if (idl.isTypeParameterType(type)) {
|
|
204
|
-
const record = subst.get(type.name);
|
|
205
|
-
if (record) {
|
|
206
|
-
return record;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return type;
|
|
210
|
-
}
|
|
211
216
|
mapCallback(decl, args) {
|
|
212
217
|
const subst = this.createTypeSubstitution(decl.typeParameters, args);
|
|
213
218
|
const parameters = decl.parameters.map(it => {
|
|
219
|
+
if (subst.size == 0)
|
|
220
|
+
return it;
|
|
214
221
|
const param = idl.clone(it);
|
|
215
|
-
param.
|
|
222
|
+
param.parent = it.parent;
|
|
223
|
+
const type = applySubstitution(subst, param.type);
|
|
224
|
+
updateParent(param, type);
|
|
225
|
+
param.type = type;
|
|
216
226
|
return param;
|
|
217
227
|
});
|
|
218
228
|
const params = parameters.map(it => `${it.isVariadic ? "..." : ""}${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}${it.isVariadic ? "[]" : ""}`);
|
|
@@ -223,8 +233,13 @@ export class TSTypeNameConvertor {
|
|
|
223
233
|
const name = `${isTuple ? "[" : "{"} ${decl.properties
|
|
224
234
|
.map(it => isTuple ? this.processTupleType(it) : it)
|
|
225
235
|
.map(it => {
|
|
236
|
+
if (subst.size == 0)
|
|
237
|
+
return it;
|
|
226
238
|
const prop = idl.clone(it);
|
|
227
|
-
prop.
|
|
239
|
+
prop.parent = it.parent;
|
|
240
|
+
const type = applySubstitution(subst, prop.type);
|
|
241
|
+
updateParent(prop, type);
|
|
242
|
+
prop.type = type;
|
|
228
243
|
return prop;
|
|
229
244
|
})
|
|
230
245
|
.map(it => {
|
|
@@ -236,7 +251,7 @@ export class TSTypeNameConvertor {
|
|
|
236
251
|
return name;
|
|
237
252
|
}
|
|
238
253
|
mapFunctionType(typeArgs) {
|
|
239
|
-
return `Function${typeArgs.length ? `<${typeArgs.join(",")}>` : ''}`;
|
|
254
|
+
return isInsideInstanceof() ? `Function` : `Function${typeArgs.length ? `<${typeArgs.join(",")}>` : ''}`;
|
|
240
255
|
}
|
|
241
256
|
}
|
|
242
257
|
export class TSInteropArgConvertor {
|
|
@@ -244,6 +259,11 @@ export class TSInteropArgConvertor {
|
|
|
244
259
|
return convertType(this, type);
|
|
245
260
|
}
|
|
246
261
|
convertContainer(type) {
|
|
262
|
+
switch (type.elementType[0]) {
|
|
263
|
+
case idl.IDLU8Type: return 'KUint8ArrayPtr';
|
|
264
|
+
case idl.IDLI32Type: return 'KInt32ArrayPtr';
|
|
265
|
+
case idl.IDLF32Type: return 'KFloat32ArrayPtr';
|
|
266
|
+
}
|
|
247
267
|
throw new Error(`Cannot pass container types through interop`);
|
|
248
268
|
}
|
|
249
269
|
convertImport(type) {
|
|
@@ -263,13 +283,17 @@ export class TSInteropArgConvertor {
|
|
|
263
283
|
case idl.IDLF64Type: return "KDouble";
|
|
264
284
|
case idl.IDLNumberType: return 'number';
|
|
265
285
|
case idl.IDLBigintType: return 'bigint';
|
|
266
|
-
case idl.IDLBooleanType:
|
|
286
|
+
case idl.IDLBooleanType: return 'boolean';
|
|
267
287
|
case idl.IDLFunctionType: return 'KInt';
|
|
268
288
|
case idl.IDLStringType: return 'KStringPtr';
|
|
269
289
|
case idl.IDLBufferType: return 'ArrayBuffer';
|
|
290
|
+
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
291
|
+
case idl.IDLInteropReturnBufferType: return `KInteropReturnBuffer`;
|
|
292
|
+
case idl.IDLObjectType: return 'Object';
|
|
293
|
+
case idl.IDLAnyType: return "Object";
|
|
270
294
|
case idl.IDLDate: return 'number';
|
|
295
|
+
case idl.IDLVoidType: return 'void';
|
|
271
296
|
case idl.IDLUndefinedType:
|
|
272
|
-
case idl.IDLVoidType:
|
|
273
297
|
case idl.IDLPointerType: return 'KPointer';
|
|
274
298
|
}
|
|
275
299
|
throw new Error(`Cannot pass primitive type ${type.name} through interop`);
|
|
@@ -287,4 +311,34 @@ export class TSInteropArgConvertor {
|
|
|
287
311
|
throw new Error("Cannot pass union types through interop");
|
|
288
312
|
}
|
|
289
313
|
}
|
|
314
|
+
function applySubstitution(subst, type) {
|
|
315
|
+
var _a;
|
|
316
|
+
if (idl.isContainerType(type)) {
|
|
317
|
+
return idl.createContainerType(type.containerKind, type.elementType.map(it => applySubstitution(subst, it)));
|
|
318
|
+
}
|
|
319
|
+
if (idl.isReferenceType(type)) {
|
|
320
|
+
return idl.createReferenceType(type.name, (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => applySubstitution(subst, it)));
|
|
321
|
+
}
|
|
322
|
+
if (idl.isTypeParameterType(type)) {
|
|
323
|
+
const record = subst.get(type.name);
|
|
324
|
+
if (record) {
|
|
325
|
+
return record;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return type;
|
|
329
|
+
}
|
|
330
|
+
// Update parents to properly find a file for conflicted types
|
|
331
|
+
function updateParent(parent, type) {
|
|
332
|
+
type.parent = parent;
|
|
333
|
+
if (idl.isOptionalType(type))
|
|
334
|
+
updateParent(type, type.type);
|
|
335
|
+
if (idl.isUnionType(type))
|
|
336
|
+
updateParents(type, type.types);
|
|
337
|
+
if (idl.isContainerType(type))
|
|
338
|
+
updateParents(type, type.elementType);
|
|
339
|
+
}
|
|
340
|
+
function updateParents(parent, types) {
|
|
341
|
+
for (const type of types)
|
|
342
|
+
updateParent(parent, type);
|
|
343
|
+
}
|
|
290
344
|
//# sourceMappingURL=TSConvertors.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Language } from "../Language";
|
|
2
|
-
import {
|
|
2
|
+
import { LibraryInterface } from "../LibraryInterface";
|
|
3
|
+
import { PeerLibrary } from "../peer-generation/PeerLibrary";
|
|
3
4
|
import { LanguageWriter } from "./LanguageWriter";
|
|
4
|
-
import {
|
|
5
|
+
import { IdlNameConvertor } from "./nameConvertor";
|
|
5
6
|
export * from "./nameConvertor";
|
|
6
|
-
export declare function createLanguageWriter(language: Language,
|
|
7
|
-
export declare function createInteropArgConvertor(language: Language):
|
|
7
|
+
export declare function createLanguageWriter(language: Language, library: LibraryInterface, nameConvertor?: IdlNameConvertor): LanguageWriter;
|
|
8
|
+
export declare function createInteropArgConvertor(language: Language, library: PeerLibrary): IdlNameConvertor;
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|