@idlizer/core 2.1.5 → 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.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +8 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -4
- package/build/lib/src/LanguageWriters/LanguageWriter.js +4 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -6
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +7 -2
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +24 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +32 -7
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +6 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +11 -9
- package/build/lib/src/config.d.ts +607 -44
- package/build/lib/src/config.js +18 -0
- package/build/lib/src/configDescriber.d.ts +1 -1
- package/build/lib/src/configDescriber.js +2 -2
- package/build/lib/src/from-idl/DtsPrinter.js +3 -2
- package/build/lib/src/from-idl/IDLLinter.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +7 -1
- package/build/lib/src/from-idl/deserialize.js +79 -33
- package/build/lib/src/idl.d.ts +4 -2
- package/build/lib/src/idl.js +64 -33
- package/build/lib/src/peer-generation/Materialized.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +4 -4
- package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/common.js +8 -2
- package/build/lib/src/peer-generation/isMaterialized.js +4 -0
- package/build/lib/src/peer-generation/unions.js +1 -1
- package/build/lib/src/util.d.ts +2 -1
- package/build/lib/src/util.js +8 -3
- package/build/lib/src/visitor.d.ts +2 -0
- package/build/lib/src/visitor.js +108 -0
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +62 -16
|
@@ -263,7 +263,6 @@ export declare class CustomTypeConvertor extends BaseArgConvertor {
|
|
|
263
263
|
isPointerType(): boolean;
|
|
264
264
|
}
|
|
265
265
|
export declare class OptionConvertor extends BaseArgConvertor {
|
|
266
|
-
private library;
|
|
267
266
|
type: idl.IDLType;
|
|
268
267
|
private readonly typeConvertor;
|
|
269
268
|
constructor(library: LibraryInterface, param: string, type: idl.IDLType);
|
|
@@ -47,7 +47,6 @@ export function isDirectConvertedType(originalType, library) {
|
|
|
47
47
|
convertor instanceof MapConvertor ||
|
|
48
48
|
convertor instanceof TupleConvertor ||
|
|
49
49
|
convertor instanceof AggregateConvertor ||
|
|
50
|
-
convertor instanceof UnionConvertor ||
|
|
51
50
|
convertor instanceof OptionConvertor ||
|
|
52
51
|
convertor instanceof ImportTypeConvertor) {
|
|
53
52
|
// try { console.log(`convertor is ${convertor.constructor.name} for ${JSON.stringify(originalType)}`) } catch (e) {}
|
|
@@ -809,12 +808,18 @@ export class OptionConvertor extends BaseArgConvertor {
|
|
|
809
808
|
// TODO: be smarter here, and for smth like Length|undefined or number|undefined pass without serializer.
|
|
810
809
|
constructor(library, param, type) {
|
|
811
810
|
let conv = library.typeConvertor(param, type);
|
|
811
|
+
let currentConv = conv;
|
|
812
|
+
while (currentConv instanceof ProxyConvertor) {
|
|
813
|
+
currentConv = currentConv.convertor;
|
|
814
|
+
}
|
|
815
|
+
if (currentConv instanceof OptionConvertor) {
|
|
816
|
+
conv = currentConv.typeConvertor;
|
|
817
|
+
}
|
|
812
818
|
let runtimeTypes = conv.runtimeTypes;
|
|
813
819
|
if (!runtimeTypes.includes(RuntimeType.UNDEFINED)) {
|
|
814
820
|
runtimeTypes.push(RuntimeType.UNDEFINED);
|
|
815
821
|
}
|
|
816
822
|
super(idl.createOptionalType(conv.idlType), runtimeTypes, conv.isScoped, true, param);
|
|
817
|
-
this.library = library;
|
|
818
823
|
this.type = type;
|
|
819
824
|
this.typeConvertor = conv;
|
|
820
825
|
}
|
|
@@ -940,7 +945,7 @@ export class UnionConvertor extends BaseArgConvertor {
|
|
|
940
945
|
return { expr, stmt };
|
|
941
946
|
});
|
|
942
947
|
statements.push(writer.makeMultiBranchCondition(branches, writer.makeThrowError(`One of the branches for ${bufferName} has to be chosen through deserialisation.`)));
|
|
943
|
-
statements.push(assigneer(writer.makeCast(writer.makeString(bufferName), this.
|
|
948
|
+
statements.push(assigneer(writer.makeCast(writer.makeString(bufferName), this.nativeType())));
|
|
944
949
|
return new BlockStatement(statements, false);
|
|
945
950
|
}
|
|
946
951
|
nativeType() {
|
|
@@ -242,8 +242,8 @@ export declare abstract class LanguageWriter {
|
|
|
242
242
|
}, op?: (writer: this) => void): void;
|
|
243
243
|
abstract writeInterface(name: string, op: (writer: this) => void, superInterfaces?: string[], generics?: string[], isDeclared?: boolean): void;
|
|
244
244
|
abstract writeFieldDeclaration(name: string, type: idl.IDLType, modifiers: FieldModifier[] | undefined, optional: boolean, initExpr?: LanguageExpression): void;
|
|
245
|
-
abstract writeFunctionDeclaration(name: string, signature: MethodSignature): void;
|
|
246
|
-
abstract writeFunctionImplementation(name: string, signature: MethodSignature, op: (writer: this) => void): void;
|
|
245
|
+
abstract writeFunctionDeclaration(name: string, signature: MethodSignature, generics?: string[]): void;
|
|
246
|
+
abstract writeFunctionImplementation(name: string, signature: MethodSignature, op: (writer: this) => void, generics?: string[]): void;
|
|
247
247
|
abstract writeMethodDeclaration(name: string, signature: MethodSignature, modifiers?: MethodModifier[]): void;
|
|
248
248
|
abstract writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
249
249
|
abstract writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
@@ -377,11 +377,16 @@ export declare abstract class LanguageWriter {
|
|
|
377
377
|
* Writes `namespace <namespace> {` and adds extra indent
|
|
378
378
|
* @param namespace Namespace to begin
|
|
379
379
|
*/
|
|
380
|
-
pushNamespace(namespace: string,
|
|
380
|
+
pushNamespace(namespace: string, options: {
|
|
381
|
+
ident: boolean;
|
|
382
|
+
isDeclared?: boolean;
|
|
383
|
+
}): void;
|
|
381
384
|
/**
|
|
382
385
|
* Writes closing brace of namespace block and removes one level of indent
|
|
383
386
|
*/
|
|
384
|
-
popNamespace(
|
|
387
|
+
popNamespace(options: {
|
|
388
|
+
ident: boolean;
|
|
389
|
+
}): void;
|
|
385
390
|
static _isReferenceRelativeToNamespaces: boolean;
|
|
386
391
|
static get isReferenceRelativeToNamespaces(): boolean;
|
|
387
392
|
static relativeReferences<T>(isRelative: boolean, op: () => T): T;
|
|
@@ -694,17 +694,17 @@ export class LanguageWriter {
|
|
|
694
694
|
* Writes `namespace <namespace> {` and adds extra indent
|
|
695
695
|
* @param namespace Namespace to begin
|
|
696
696
|
*/
|
|
697
|
-
pushNamespace(namespace,
|
|
697
|
+
pushNamespace(namespace, options) {
|
|
698
698
|
this.print(`namespace ${namespace} {`);
|
|
699
|
-
if (ident)
|
|
699
|
+
if (options.ident)
|
|
700
700
|
this.pushIndent();
|
|
701
701
|
}
|
|
702
702
|
/**
|
|
703
703
|
* Writes closing brace of namespace block and removes one level of indent
|
|
704
704
|
*/
|
|
705
|
-
popNamespace(
|
|
705
|
+
popNamespace(options) {
|
|
706
706
|
this.namespaceStack.pop();
|
|
707
|
-
if (ident)
|
|
707
|
+
if (options.ident)
|
|
708
708
|
this.popIndent();
|
|
709
709
|
this.print(`}`);
|
|
710
710
|
}
|
|
@@ -32,4 +32,5 @@ export declare class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvert
|
|
|
32
32
|
export declare class CJInteropArgConvertor extends InteropArgConvertor {
|
|
33
33
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
34
34
|
}
|
|
35
|
+
export declare function removePoints(s: string): string;
|
|
35
36
|
//# sourceMappingURL=CJConvertors.d.ts.map
|
|
@@ -48,13 +48,13 @@ export class CJTypeNameConvertor {
|
|
|
48
48
|
throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
|
|
49
49
|
}
|
|
50
50
|
convertNamespace(node) {
|
|
51
|
-
|
|
51
|
+
return node.name;
|
|
52
52
|
}
|
|
53
53
|
convertInterface(node) {
|
|
54
|
-
return node.name;
|
|
54
|
+
return removePoints(idl.getNamespaceName(node).concat(node.name));
|
|
55
55
|
}
|
|
56
56
|
convertEnum(node) {
|
|
57
|
-
return node.name;
|
|
57
|
+
return removePoints(idl.getNamespaceName(node).concat(node.name));
|
|
58
58
|
}
|
|
59
59
|
convertTypedef(node) {
|
|
60
60
|
return node.name;
|
|
@@ -95,13 +95,18 @@ export class CJTypeNameConvertor {
|
|
|
95
95
|
return this.productType(decl, isTuple, !isTuple);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
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];
|
|
99
103
|
}
|
|
100
104
|
convertTypeParameter(type) {
|
|
101
105
|
return type.name;
|
|
102
106
|
}
|
|
103
107
|
convertPrimitiveType(type) {
|
|
104
108
|
switch (type) {
|
|
109
|
+
case idl.IDLThisType: return 'this';
|
|
105
110
|
case idl.IDLStringType: return 'String';
|
|
106
111
|
case idl.IDLBooleanType: return 'Bool';
|
|
107
112
|
case idl.IDLNumberType: return 'Float64';
|
|
@@ -123,6 +128,10 @@ export class CJTypeNameConvertor {
|
|
|
123
128
|
case idl.IDLBigintType: return 'Int64';
|
|
124
129
|
case idl.IDLSerializerBuffer: return 'KSerializerBuffer';
|
|
125
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';
|
|
126
135
|
}
|
|
127
136
|
throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
128
137
|
}
|
|
@@ -131,8 +140,6 @@ export class CJTypeNameConvertor {
|
|
|
131
140
|
return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
|
|
132
141
|
}
|
|
133
142
|
productType(decl, isTuple, includeFieldNames) {
|
|
134
|
-
if (!isTuple)
|
|
135
|
-
throw new Error('Only tuples supported from IDL synthetic types for now');
|
|
136
143
|
return decl.name;
|
|
137
144
|
}
|
|
138
145
|
}
|
|
@@ -178,4 +185,7 @@ export class CJInteropArgConvertor extends InteropArgConvertor {
|
|
|
178
185
|
return super.convertPrimitiveType(type);
|
|
179
186
|
}
|
|
180
187
|
}
|
|
188
|
+
export function removePoints(s) {
|
|
189
|
+
return s.split(/[\.\-]/g).join('_');
|
|
190
|
+
}
|
|
181
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;
|
|
@@ -26,8 +26,8 @@ export class GenericCppConvertor {
|
|
|
26
26
|
constructor(resolver) {
|
|
27
27
|
this.resolver = resolver;
|
|
28
28
|
}
|
|
29
|
-
make(text, noPrefix = false) {
|
|
30
|
-
return { text, noPrefix };
|
|
29
|
+
make(text, resolvedType, noPrefix = false) {
|
|
30
|
+
return { text, noPrefix, resolvedType };
|
|
31
31
|
}
|
|
32
32
|
convertNode(node) {
|
|
33
33
|
return convertNode(this, node);
|
|
@@ -39,60 +39,65 @@ export class GenericCppConvertor {
|
|
|
39
39
|
switch (node.subkind) {
|
|
40
40
|
case idl.IDLInterfaceSubkind.AnonymousInterface:
|
|
41
41
|
return node.name
|
|
42
|
-
? this.make(this.qualifiedName(node))
|
|
43
|
-
: this.make(this.computeTargetTypeLiteralName(node), true);
|
|
42
|
+
? this.make(this.qualifiedName(node), idl.createReferenceType(node))
|
|
43
|
+
: this.make(this.computeTargetTypeLiteralName(node), idl.createReferenceType(node), true);
|
|
44
44
|
case idl.IDLInterfaceSubkind.Interface:
|
|
45
45
|
case idl.IDLInterfaceSubkind.Class:
|
|
46
46
|
if (isInIdlizeInternal(node)) {
|
|
47
|
-
return this.make(this.qualifiedName(node), true);
|
|
47
|
+
return this.make(this.qualifiedName(node), idl.createReferenceType(node), true);
|
|
48
48
|
}
|
|
49
|
-
return this.make(this.qualifiedName(node));
|
|
49
|
+
return this.make(this.qualifiedName(node), idl.createReferenceType(node));
|
|
50
50
|
case idl.IDLInterfaceSubkind.Tuple:
|
|
51
51
|
return node.name
|
|
52
|
-
? this.make(this.qualifiedName(node))
|
|
53
|
-
: this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
|
|
52
|
+
? this.make(this.qualifiedName(node), idl.createReferenceType(node))
|
|
53
|
+
: this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, idl.createReferenceType(node), true);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
convertEnum(node) {
|
|
57
|
-
return this.make(this.qualifiedName(node));
|
|
57
|
+
return this.make(this.qualifiedName(node), idl.createReferenceType(node));
|
|
58
58
|
}
|
|
59
59
|
convertTypedef(node) {
|
|
60
|
-
return this.make(this.qualifiedName(node));
|
|
60
|
+
return this.make(this.qualifiedName(node), idl.createReferenceType(node));
|
|
61
61
|
}
|
|
62
62
|
convertCallback(node) {
|
|
63
|
-
return this.make(generatorConfiguration().LibraryPrefix + this.qualifiedName(node), true);
|
|
63
|
+
return this.make(generatorConfiguration().LibraryPrefix + this.qualifiedName(node), idl.createReferenceType(node), true);
|
|
64
64
|
}
|
|
65
65
|
convertMethod(node) {
|
|
66
|
-
return this.make(node.name);
|
|
66
|
+
return this.make(node.name, idl.createReferenceType(node));
|
|
67
67
|
}
|
|
68
68
|
convertConstant(node) {
|
|
69
|
-
return this.make(this.qualifiedName(node));
|
|
69
|
+
return this.make(this.qualifiedName(node), idl.createReferenceType(node));
|
|
70
70
|
}
|
|
71
71
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
72
72
|
convertOptional(type) {
|
|
73
|
-
|
|
73
|
+
const converted = this.convertNode(type.type);
|
|
74
|
+
const prefix = generatorConfiguration().OptionalPrefix;
|
|
75
|
+
if (idl.isOptionalType(converted.resolvedType)) {
|
|
76
|
+
return converted;
|
|
77
|
+
}
|
|
78
|
+
return this.make(prefix + converted.text, type, true);
|
|
74
79
|
}
|
|
75
80
|
convertUnion(type) {
|
|
76
|
-
return this.make(type.name, false);
|
|
81
|
+
return this.make(type.name, type, false);
|
|
77
82
|
}
|
|
78
83
|
convertContainer(type) {
|
|
79
84
|
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
80
|
-
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}
|
|
85
|
+
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`, type);
|
|
81
86
|
}
|
|
82
87
|
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
83
88
|
if (type.elementType[0] === idl.IDLU8Type) {
|
|
84
|
-
return this.make(`uint8_t*`, true);
|
|
89
|
+
return this.make(`uint8_t*`, type, true);
|
|
85
90
|
}
|
|
86
|
-
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
|
|
91
|
+
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, type, true);
|
|
87
92
|
}
|
|
88
93
|
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
89
|
-
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
|
|
94
|
+
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, type, true);
|
|
90
95
|
}
|
|
91
96
|
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
92
97
|
}
|
|
93
98
|
convertImport(type) {
|
|
94
99
|
console.warn("Imports are not implemented yet");
|
|
95
|
-
return this.make(idl.IDLCustomObjectType.name);
|
|
100
|
+
return this.make(idl.IDLCustomObjectType.name, idl.IDLCustomObjectType);
|
|
96
101
|
}
|
|
97
102
|
convertTypeReferenceAsImport(type, _) {
|
|
98
103
|
return this.convertTypeReference(type);
|
|
@@ -100,14 +105,8 @@ export class GenericCppConvertor {
|
|
|
100
105
|
convertTypeReference(type) {
|
|
101
106
|
var _a;
|
|
102
107
|
const refName = type.name;
|
|
103
|
-
switch (refName) {
|
|
104
|
-
case "object":
|
|
105
|
-
case "Object":
|
|
106
|
-
// treat object as interop resource
|
|
107
|
-
return this.make('Object');
|
|
108
|
-
}
|
|
109
108
|
if (generatorConfiguration().parameterized.includes(refName)) {
|
|
110
|
-
return this.make('CustomObject');
|
|
109
|
+
return this.make('CustomObject', idl.IDLCustomObjectType);
|
|
111
110
|
}
|
|
112
111
|
let decl = this.resolver.toDeclaration(type);
|
|
113
112
|
if (idl.isCallback(decl)) {
|
|
@@ -115,45 +114,47 @@ export class GenericCppConvertor {
|
|
|
115
114
|
}
|
|
116
115
|
if (idl.isType(decl)) {
|
|
117
116
|
if (idl.isReferenceType(decl)) {
|
|
118
|
-
return this.make(`${capitalize(decl.name)}
|
|
117
|
+
return this.make(`${capitalize(decl.name)}`, decl);
|
|
119
118
|
}
|
|
120
119
|
return this.convertNode(decl);
|
|
121
120
|
}
|
|
122
121
|
let res = this.convertNode(decl);
|
|
123
122
|
if (type.name === "Optional")
|
|
124
|
-
res = this.make("Opt_" + res.text, true);
|
|
123
|
+
res = this.make("Opt_" + res.text, idl.createOptionalType(type.typeArguments[0]), true);
|
|
125
124
|
return res;
|
|
126
125
|
}
|
|
127
126
|
convertTypeParameter(type) {
|
|
128
|
-
return this.make('CustomObject');
|
|
127
|
+
return this.make('CustomObject', idl.IDLCustomObjectType);
|
|
129
128
|
}
|
|
130
129
|
convertPrimitiveType(type) {
|
|
131
130
|
switch (type) {
|
|
132
|
-
case idl.
|
|
133
|
-
case idl.
|
|
134
|
-
case idl.
|
|
135
|
-
case idl.
|
|
136
|
-
case idl.
|
|
137
|
-
case idl.
|
|
138
|
-
case idl.
|
|
139
|
-
case idl.
|
|
140
|
-
case idl.
|
|
141
|
-
case idl.
|
|
142
|
-
case idl.
|
|
143
|
-
case idl.
|
|
144
|
-
case idl.
|
|
145
|
-
case idl.
|
|
146
|
-
case idl.
|
|
147
|
-
case idl.
|
|
148
|
-
case idl.
|
|
131
|
+
case idl.IDLThisType: // maybe fix it in another level?
|
|
132
|
+
case idl.IDLVoidType: return this.make('void', type, true);
|
|
133
|
+
case idl.IDLI8Type: return this.make(`Int8`, type);
|
|
134
|
+
case idl.IDLU8Type: return this.make(`UInt8`, type);
|
|
135
|
+
case idl.IDLI16Type: return this.make(`Int16`, type);
|
|
136
|
+
case idl.IDLU16Type: return this.make(`UInt16`, type);
|
|
137
|
+
case idl.IDLI32Type: return this.make(`Int32`, type);
|
|
138
|
+
case idl.IDLU32Type: return this.make(`UInt32`, type);
|
|
139
|
+
case idl.IDLI64Type: return this.make(`Int64`, type);
|
|
140
|
+
case idl.IDLU64Type: return this.make(`UInt64`, type);
|
|
141
|
+
case idl.IDLF32Type: return this.make(`Float32`, type);
|
|
142
|
+
case idl.IDLF64Type: return this.make(`Float64`, type);
|
|
143
|
+
case idl.IDLNumberType: return this.make(`Number`, type);
|
|
144
|
+
case idl.IDLStringType: return this.make(`String`, type);
|
|
145
|
+
case idl.IDLBooleanType: return this.make(`Boolean`, type);
|
|
146
|
+
case idl.IDLBigintType: return this.make(`Int64`, type); // TODO add arbitrary precision numeric type
|
|
147
|
+
case idl.IDLPointerType: return this.make('NativePointer', type);
|
|
148
|
+
case idl.IDLCustomObjectType: return this.make('CustomObject', type);
|
|
149
149
|
case idl.IDLUnknownType:
|
|
150
|
-
case idl.
|
|
151
|
-
case idl.
|
|
152
|
-
case idl.
|
|
153
|
-
case idl.
|
|
154
|
-
case idl.
|
|
155
|
-
case idl.
|
|
156
|
-
case idl.
|
|
150
|
+
case idl.IDLObjectType:
|
|
151
|
+
case idl.IDLAnyType: return this.make(`Object`, type);
|
|
152
|
+
case idl.IDLUndefinedType: return this.make(`Undefined`, type);
|
|
153
|
+
case idl.IDLFunctionType: return this.make(`Function`, type);
|
|
154
|
+
case idl.IDLDate: return this.make(`Date`, type);
|
|
155
|
+
case idl.IDLBufferType: return this.make('Buffer', type);
|
|
156
|
+
case idl.IDLPointerType: return this.make('Pointer', type);
|
|
157
|
+
case idl.IDLSerializerBuffer: return this.make('KSerializerBuffer', type, true);
|
|
157
158
|
}
|
|
158
159
|
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
159
160
|
}
|
|
@@ -4,7 +4,7 @@ export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
4
4
|
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
5
5
|
convertContainer(type: idl.IDLContainerType): string;
|
|
6
6
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
7
|
-
protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
|
|
7
|
+
protected productType(decl: idl.IDLInterface, args: idl.IDLType[] | undefined, isTuple: boolean, includeFieldNames: boolean): string;
|
|
8
8
|
protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
|
|
9
9
|
protected mapCallback(decl: idl.IDLCallback): string;
|
|
10
10
|
protected mapFunctionType(typeArgs: string[]): string;
|
|
@@ -70,11 +70,11 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
70
70
|
}
|
|
71
71
|
return super.convertPrimitiveType(type);
|
|
72
72
|
}
|
|
73
|
-
productType(decl, isTuple, includeFieldNames) {
|
|
73
|
+
productType(decl, args, isTuple, includeFieldNames) {
|
|
74
74
|
if (decl.subkind === idl.IDLInterfaceSubkind.AnonymousInterface) {
|
|
75
75
|
return decl.name;
|
|
76
76
|
}
|
|
77
|
-
return super.productType(decl, isTuple, includeFieldNames);
|
|
77
|
+
return super.productType(decl, args, isTuple, includeFieldNames);
|
|
78
78
|
}
|
|
79
79
|
processTupleType(idlProperty) {
|
|
80
80
|
if (idlProperty.isOptional) {
|
|
@@ -66,6 +66,7 @@ export class InteropReturnTypeConvertor {
|
|
|
66
66
|
case idl.IDLThisType:
|
|
67
67
|
case idl.IDLUndefinedType:
|
|
68
68
|
case idl.IDLUnknownType:
|
|
69
|
+
case idl.IDLObjectType:
|
|
69
70
|
case idl.IDLVoidType: return idl.IDLVoidType.name;
|
|
70
71
|
case idl.IDLBufferType: return KInteropReturnBuffer; /* ArkTS can not return buffer as language object yet */
|
|
71
72
|
case idl.IDLStringType: return PrimitiveTypesInstance.String.getText();
|
|
@@ -21,8 +21,10 @@ export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNa
|
|
|
21
21
|
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
22
22
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
23
23
|
protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
|
|
24
|
-
protected
|
|
25
|
-
protected
|
|
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;
|
|
26
28
|
protected mapFunctionType(typeArgs: string[]): string;
|
|
27
29
|
}
|
|
28
30
|
export declare class TSInteropArgConvertor implements TypeConvertor<string> {
|
|
@@ -88,19 +88,16 @@ export class TSTypeNameConvertor {
|
|
|
88
88
|
}
|
|
89
89
|
convertTypeReference(type) {
|
|
90
90
|
var _a, _b;
|
|
91
|
-
if (type.name === idl.IDLObjectType.name) {
|
|
92
|
-
return type.name;
|
|
93
|
-
}
|
|
94
91
|
let decl = this.resolver.resolveTypeReference(type);
|
|
95
92
|
if (decl) {
|
|
96
93
|
if (idl.isSyntheticEntry(decl)) {
|
|
97
94
|
if (idl.isCallback(decl)) {
|
|
98
|
-
return this.mapCallback(decl);
|
|
95
|
+
return this.mapCallback(decl, type.typeArguments);
|
|
99
96
|
}
|
|
100
97
|
const entity = idl.getExtAttribute(decl, idl.IDLExtendedAttributes.Entity);
|
|
101
98
|
if (entity) {
|
|
102
99
|
const isTuple = entity === idl.IDLEntity.Tuple;
|
|
103
|
-
return this.productType(decl, isTuple, !isTuple);
|
|
100
|
+
return this.productType(decl, type.typeArguments, isTuple, !isTuple);
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
// FIXME: isEnumMember is not TYPE!
|
|
@@ -133,8 +130,9 @@ export class TSTypeNameConvertor {
|
|
|
133
130
|
switch (type) {
|
|
134
131
|
case idl.IDLFunctionType: return 'Function';
|
|
135
132
|
case idl.IDLUnknownType:
|
|
136
|
-
case idl.IDLCustomObjectType: return '
|
|
133
|
+
case idl.IDLCustomObjectType: return 'any';
|
|
137
134
|
case idl.IDLThisType: return 'this';
|
|
135
|
+
case idl.IDLObjectType: return 'Object';
|
|
138
136
|
case idl.IDLAnyType: return 'any';
|
|
139
137
|
case idl.IDLUndefinedType: return 'undefined';
|
|
140
138
|
case idl.IDLPointerType: return 'KPointer';
|
|
@@ -171,13 +169,50 @@ export class TSTypeNameConvertor {
|
|
|
171
169
|
processTupleType(idlProperty) {
|
|
172
170
|
return idlProperty;
|
|
173
171
|
}
|
|
174
|
-
|
|
175
|
-
const
|
|
172
|
+
createTypeSubstitution(parameters, args) {
|
|
173
|
+
const subst = new Map();
|
|
174
|
+
if (args && parameters) {
|
|
175
|
+
for (let i = 0; i < args.length && i < parameters.length; ++i) {
|
|
176
|
+
subst.set(parameters[i], args[i]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return subst;
|
|
180
|
+
}
|
|
181
|
+
applySubstitution(subst, type) {
|
|
182
|
+
var _a;
|
|
183
|
+
if (idl.isContainerType(type)) {
|
|
184
|
+
return idl.createContainerType(type.containerKind, type.elementType.map(it => this.applySubstitution(subst, it)));
|
|
185
|
+
}
|
|
186
|
+
if (idl.isReferenceType(type)) {
|
|
187
|
+
return idl.createReferenceType(type.name, (_a = type.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.applySubstitution(subst, it)));
|
|
188
|
+
}
|
|
189
|
+
if (idl.isTypeParameterType(type)) {
|
|
190
|
+
const record = subst.get(type.name);
|
|
191
|
+
if (record) {
|
|
192
|
+
return record;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return type;
|
|
196
|
+
}
|
|
197
|
+
mapCallback(decl, args) {
|
|
198
|
+
const subst = this.createTypeSubstitution(decl.typeParameters, args);
|
|
199
|
+
const parameters = decl.parameters.map(it => {
|
|
200
|
+
const param = idl.clone(it);
|
|
201
|
+
param.type = this.applySubstitution(subst, param.type);
|
|
202
|
+
return param;
|
|
203
|
+
});
|
|
204
|
+
const params = parameters.map(it => `${it.isVariadic ? "..." : ""}${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}${it.isVariadic ? "[]" : ""}`);
|
|
176
205
|
return `((${params.join(", ")}) => ${this.convert(decl.returnType)})`;
|
|
177
206
|
}
|
|
178
|
-
productType(decl, isTuple, includeFieldNames) {
|
|
207
|
+
productType(decl, args, isTuple, includeFieldNames) {
|
|
208
|
+
const subst = this.createTypeSubstitution(decl.typeParameters, args);
|
|
179
209
|
const name = `${isTuple ? "[" : "{"} ${decl.properties
|
|
180
210
|
.map(it => isTuple ? this.processTupleType(it) : it)
|
|
211
|
+
.map(it => {
|
|
212
|
+
const prop = idl.clone(it);
|
|
213
|
+
prop.type = this.applySubstitution(subst, prop.type);
|
|
214
|
+
return prop;
|
|
215
|
+
})
|
|
181
216
|
.map(it => {
|
|
182
217
|
const type = this.convert(it.type);
|
|
183
218
|
return it.isOptional
|
|
@@ -155,8 +155,13 @@ export declare class CJLanguageWriter extends LanguageWriter {
|
|
|
155
155
|
makeEquals(args: LanguageExpression[]): LanguageExpression;
|
|
156
156
|
runtimeType(param: ArgConvertor, valueType: string, value: string): void;
|
|
157
157
|
escapeKeyword(word: string): string;
|
|
158
|
-
pushNamespace(namespace: string,
|
|
159
|
-
|
|
158
|
+
pushNamespace(namespace: string, options: {
|
|
159
|
+
ident: boolean;
|
|
160
|
+
isDeclared?: boolean;
|
|
161
|
+
}): void;
|
|
162
|
+
popNamespace(options: {
|
|
163
|
+
ident: boolean;
|
|
164
|
+
}): void;
|
|
160
165
|
castToInt(value: string, bitness: 8 | 32): string;
|
|
161
166
|
castToBoolean(value: string): string;
|
|
162
167
|
}
|
|
@@ -267,8 +267,7 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
267
267
|
}
|
|
268
268
|
getNodeName(type) {
|
|
269
269
|
// rework for proper namespace logic
|
|
270
|
-
|
|
271
|
-
return name[name.length - 1];
|
|
270
|
+
return this.typeConvertor.convert(type);
|
|
272
271
|
}
|
|
273
272
|
writeClass(name, op, superClass, interfaces, generics) {
|
|
274
273
|
let extendsClause = superClass ? `${superClass}` : undefined;
|
|
@@ -320,13 +319,13 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
320
319
|
if (nullable) {
|
|
321
320
|
if (receiver == 'this') {
|
|
322
321
|
this.printer.print('let thisObj = this');
|
|
323
|
-
super.writeMethodCall('thisObj', method, params, false);
|
|
322
|
+
super.writeMethodCall('thisObj', this.escapeKeyword(method), params, false);
|
|
324
323
|
return;
|
|
325
324
|
}
|
|
326
325
|
this.printer.print(`if (let Some(${receiver}) <- ${receiver}) { ${receiver}.${method}(${params.join(", ")}) }`);
|
|
327
326
|
}
|
|
328
327
|
else {
|
|
329
|
-
super.writeMethodCall(receiver, method, params, nullable);
|
|
328
|
+
super.writeMethodCall(receiver, this.escapeKeyword(method), params, nullable);
|
|
330
329
|
}
|
|
331
330
|
}
|
|
332
331
|
writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
|
|
@@ -339,7 +338,22 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
339
338
|
this.writeDeclaration(name, signature, modifiers);
|
|
340
339
|
}
|
|
341
340
|
writeConstructorImplementation(className, signature, op, superCall, modifiers) {
|
|
342
|
-
|
|
341
|
+
var _a;
|
|
342
|
+
let i = 1;
|
|
343
|
+
while (signature.isArgOptional(signature.args.length - i)) {
|
|
344
|
+
let smallerSignature = signature.args.slice(0, -i);
|
|
345
|
+
this.printer.print(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') + ' ' : ''}init (${smallerSignature.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}`).join(", ")}) {`);
|
|
346
|
+
this.pushIndent();
|
|
347
|
+
let smallerArgs = (_a = signature.args) === null || _a === void 0 ? void 0 : _a.slice(0, -i).map((_, i) => signature.argName(i)).join(', ');
|
|
348
|
+
for (let idx = 0; idx < i; idx++) {
|
|
349
|
+
smallerArgs = smallerArgs.concat(`${i == signature.args.length && idx == 0 ? '' : ', '}Option.None`);
|
|
350
|
+
}
|
|
351
|
+
this.print(`${className}(${smallerArgs})`);
|
|
352
|
+
this.popIndent();
|
|
353
|
+
this.printer.print(`}`);
|
|
354
|
+
i += 1;
|
|
355
|
+
}
|
|
356
|
+
this.printer.print(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') + ' ' : ''}${className}(${signature.args.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(idl.maybeOptional(it, signature.isArgOptional(index)))}`).join(", ")}) {`);
|
|
343
357
|
this.pushIndent();
|
|
344
358
|
if (superCall) {
|
|
345
359
|
this.print(`super(${superCall.signature.args.map((_, i) => superCall === null || superCall === void 0 ? void 0 : superCall.signature.argName(i)).join(", ")})`);
|
|
@@ -416,8 +430,8 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
416
430
|
}
|
|
417
431
|
writeDeclaration(name, signature, modifiers, postfix) {
|
|
418
432
|
let prefix = modifiers === null || modifiers === void 0 ? void 0 : modifiers.filter(it => this.supportedModifiers.includes(it)).map(it => this.mapMethodModifier(it)).join(" ");
|
|
419
|
-
prefix = prefix ? prefix + " " : "";
|
|
420
|
-
this.print(`${prefix}${((modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) || (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER))) ? '' : '
|
|
433
|
+
prefix = prefix ? prefix + " " : "public ";
|
|
434
|
+
this.print(`${prefix}${((modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) || (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER))) ? '' : `${((modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.STATIC)) || (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.PRIVATE))) ? '' : 'open '}func `}${this.escapeKeyword(name)}(${signature.args.map((it, index) => `${this.escapeKeyword(signature.argName(index))}: ${this.getNodeName(idl.maybeOptional(it, signature.isArgOptional(index)))}`).join(", ")})${this.getNodeName(signature.returnType) == 'this' ? '' : `: ${this.getNodeName(signature.returnType)}`}${postfix !== null && postfix !== void 0 ? postfix : ""}`);
|
|
421
435
|
}
|
|
422
436
|
writeNativeFunctionCall(printer, name, signature) {
|
|
423
437
|
printer.print(`return unsafe { ${name}(${signature.args.map((it, index) => `${signature.argName(index)}`).join(", ")}) }`);
|
|
@@ -570,10 +584,10 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
570
584
|
this.writeStatement(this.makeAssign(valueType, undefined, this.makeRuntimeTypeGetterCall(value), false));
|
|
571
585
|
}
|
|
572
586
|
escapeKeyword(word) {
|
|
573
|
-
return CJKeywords.has(word) ? word
|
|
587
|
+
return CJKeywords.has(word) ? word.concat("_") : word;
|
|
574
588
|
}
|
|
575
|
-
pushNamespace(namespace,
|
|
576
|
-
popNamespace(
|
|
589
|
+
pushNamespace(namespace, options) { }
|
|
590
|
+
popNamespace(options) { }
|
|
577
591
|
castToInt(value, bitness) {
|
|
578
592
|
return `Int${bitness}(${value})`;
|
|
579
593
|
}
|
|
@@ -73,6 +73,9 @@ export declare class ETSLanguageWriter extends TSLanguageWriter {
|
|
|
73
73
|
typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
|
|
74
74
|
makeTypeCast(value: LanguageExpression, type: idl.IDLType, options?: MakeCastOptions): LanguageExpression;
|
|
75
75
|
makeCast(value: LanguageExpression, node: idl.IDLNode, options?: MakeCastOptions): LanguageExpression;
|
|
76
|
+
static _isUseTypeChecker: boolean;
|
|
77
|
+
static get isUseTypeChecker(): boolean;
|
|
78
|
+
static useTypeChecker<T>(isUseTypeChecker: boolean, op: () => T): T;
|
|
76
79
|
}
|
|
77
80
|
export declare function makeEnumTypeCheckerCall(valueAccessor: string, enumName: string, writer: LanguageWriter): LanguageExpression;
|
|
78
81
|
//# sourceMappingURL=ETSLanguageWriter.d.ts.map
|