@idlizer/core 2.0.17 → 2.0.20
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.js +1 -1
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +1 -0
- package/build/lib/src/LanguageWriters/LanguageWriter.js +3 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +34 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +164 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +7 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +24 -3
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +13 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +118 -0
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +58 -0
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +274 -0
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +36 -0
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +186 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +27 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +173 -0
- package/build/lib/src/LanguageWriters/index.d.ts +3 -1
- package/build/lib/src/LanguageWriters/index.js +15 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +7 -4
- package/build/lib/src/LibraryInterface.d.ts +2 -0
- package/build/lib/src/config.d.ts +6 -0
- package/build/lib/src/config.js +27 -3
- package/build/lib/src/configMerge.d.ts +2 -0
- package/build/lib/src/configMerge.js +42 -0
- package/build/lib/src/from-idl/common.d.ts +1 -1
- package/build/lib/src/from-idl/common.js +20 -11
- package/build/lib/src/idl.d.ts +6 -3
- package/build/lib/src/idl.js +14 -10
- package/build/lib/src/idlize.d.ts +1 -1
- package/build/lib/src/idlize.js +57 -13
- package/build/lib/src/index.d.ts +8 -1
- package/build/lib/src/index.js +8 -1
- package/build/lib/src/options.d.ts +1 -0
- package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +2 -0
- package/build/lib/src/peer-generation/LanguageWriters/index.js +2 -0
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +25 -0
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +55 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +15 -0
- package/build/lib/src/peer-generation/LayoutManager.js +32 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +2 -0
- package/build/lib/src/peer-generation/Materialized.js +28 -0
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +53 -0
- package/build/lib/src/peer-generation/PeerLibrary.js +340 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +3 -0
- package/package.json +2 -2
- package/webidl2.js/LICENSE +0 -21
- package/webidl2.js/README.md +0 -827
- package/webidl2.js/dist/package.json +0 -3
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { generatorConfiguration } from '../../config';
|
|
16
|
+
import * as idl from '../../idl';
|
|
17
|
+
import { qualifiedName } from '../../peer-generation/idl/common';
|
|
18
|
+
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
|
+
import { capitalize } from '../../util';
|
|
20
|
+
import { maybeTransformManagedCallback } from '../ArgConvertors';
|
|
21
|
+
import { convertNode, convertType } from '../nameConvertor';
|
|
22
|
+
export class InteropConvertor {
|
|
23
|
+
constructor(resolver) {
|
|
24
|
+
this.resolver = resolver;
|
|
25
|
+
}
|
|
26
|
+
make(text, noPrefix = false) {
|
|
27
|
+
return { text, noPrefix };
|
|
28
|
+
}
|
|
29
|
+
convertNode(node) {
|
|
30
|
+
return convertNode(this, node);
|
|
31
|
+
}
|
|
32
|
+
convertNamespace(node) {
|
|
33
|
+
throw new Error("Internal error: namespaces are not allowed on the interop layer");
|
|
34
|
+
}
|
|
35
|
+
convertInterface(node) {
|
|
36
|
+
switch (node.subkind) {
|
|
37
|
+
case idl.IDLInterfaceSubkind.AnonymousInterface:
|
|
38
|
+
return node.name
|
|
39
|
+
? this.make(node.name)
|
|
40
|
+
: this.make(this.computeTargetTypeLiteralName(node), true);
|
|
41
|
+
case idl.IDLInterfaceSubkind.Interface:
|
|
42
|
+
case idl.IDLInterfaceSubkind.Class:
|
|
43
|
+
if (idl.hasExtAttribute(node, idl.IDLExtendedAttributes.Predefined)) {
|
|
44
|
+
return this.make(node.name, true);
|
|
45
|
+
}
|
|
46
|
+
return this.make(node.name);
|
|
47
|
+
case idl.IDLInterfaceSubkind.Tuple:
|
|
48
|
+
return node.name
|
|
49
|
+
? this.make(node.name)
|
|
50
|
+
: this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
convertEnum(node) {
|
|
54
|
+
return this.make(this.enumName(node));
|
|
55
|
+
}
|
|
56
|
+
convertTypedef(node) {
|
|
57
|
+
return this.make(node.name);
|
|
58
|
+
}
|
|
59
|
+
convertCallback(node) {
|
|
60
|
+
return this.make(generatorConfiguration().param("LibraryPrefix") + node.name, true);
|
|
61
|
+
}
|
|
62
|
+
convertMethod(node) {
|
|
63
|
+
return this.make(node.name);
|
|
64
|
+
}
|
|
65
|
+
convertConstant(node) {
|
|
66
|
+
return this.make(node.name);
|
|
67
|
+
}
|
|
68
|
+
/////////////////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
convertOptional(type) {
|
|
70
|
+
return this.convertNode(type.type);
|
|
71
|
+
}
|
|
72
|
+
convertUnion(type) {
|
|
73
|
+
return this.make(type.name, false);
|
|
74
|
+
}
|
|
75
|
+
convertContainer(type) {
|
|
76
|
+
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
77
|
+
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`);
|
|
78
|
+
}
|
|
79
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
80
|
+
if (type.elementType[0] === idl.IDLU8Type) {
|
|
81
|
+
return this.make(`uint8_t*`, true);
|
|
82
|
+
}
|
|
83
|
+
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
|
|
84
|
+
}
|
|
85
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
86
|
+
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
89
|
+
}
|
|
90
|
+
convertImport(type, _) {
|
|
91
|
+
return this.make(idl.IDLCustomObjectType.name);
|
|
92
|
+
}
|
|
93
|
+
convertTypeReference(type) {
|
|
94
|
+
var _a;
|
|
95
|
+
const refName = type.name;
|
|
96
|
+
switch (refName) {
|
|
97
|
+
case "object":
|
|
98
|
+
case "Object":
|
|
99
|
+
return this.make('CustomObject');
|
|
100
|
+
}
|
|
101
|
+
if (generatorConfiguration().paramArray("knownParameterized").includes(refName)) {
|
|
102
|
+
return this.make('CustomObject');
|
|
103
|
+
}
|
|
104
|
+
let decl = this.resolver.toDeclaration(type);
|
|
105
|
+
if (idl.isCallback(decl)) {
|
|
106
|
+
decl = (_a = maybeTransformManagedCallback(decl)) !== null && _a !== void 0 ? _a : decl;
|
|
107
|
+
}
|
|
108
|
+
if (idl.isType(decl)) {
|
|
109
|
+
if (idl.isReferenceType(decl)) {
|
|
110
|
+
return this.make(`${capitalize(decl.name)}`);
|
|
111
|
+
}
|
|
112
|
+
return this.convertNode(decl);
|
|
113
|
+
}
|
|
114
|
+
let res = this.convertNode(decl);
|
|
115
|
+
if (type.name === "Optional")
|
|
116
|
+
res = this.make("Opt_" + res.text, true);
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
convertTypeParameter(type) {
|
|
120
|
+
return this.make('CustomObject');
|
|
121
|
+
}
|
|
122
|
+
convertPrimitiveType(type) {
|
|
123
|
+
switch (type) {
|
|
124
|
+
case idl.IDLVoidType: return this.make('void', true);
|
|
125
|
+
case idl.IDLI8Type: return this.make(`Int8`);
|
|
126
|
+
case idl.IDLU8Type: return this.make(`UInt8`);
|
|
127
|
+
case idl.IDLI16Type: return this.make(`Int16`);
|
|
128
|
+
case idl.IDLU16Type: return this.make(`UInt16`);
|
|
129
|
+
case idl.IDLI32Type: return this.make(`Int32`);
|
|
130
|
+
case idl.IDLU32Type: return this.make(`UInt32`);
|
|
131
|
+
case idl.IDLI64Type: return this.make(`Int64`);
|
|
132
|
+
case idl.IDLU64Type: return this.make(`UInt64`);
|
|
133
|
+
case idl.IDLF32Type: return this.make(`Float32`);
|
|
134
|
+
case idl.IDLF64Type: return this.make(`Float64`);
|
|
135
|
+
case idl.IDLNumberType: return this.make(`Number`);
|
|
136
|
+
case idl.IDLStringType: return this.make(`String`);
|
|
137
|
+
case idl.IDLBooleanType: return this.make(`Boolean`);
|
|
138
|
+
case idl.IDLPointerType: return this.make('NativePointer');
|
|
139
|
+
case idl.IDLUnknownType:
|
|
140
|
+
case idl.IDLCustomObjectType:
|
|
141
|
+
case idl.IDLAnyType: return this.make(`CustomObject`);
|
|
142
|
+
case idl.IDLUndefinedType: return this.make(`Undefined`);
|
|
143
|
+
case idl.IDLLengthType: return this.make(`Length`);
|
|
144
|
+
case idl.IDLFunctionType: return this.make(`Function`);
|
|
145
|
+
case idl.IDLDate: return this.make(`Date`);
|
|
146
|
+
case idl.IDLBufferType: return this.make('Buffer');
|
|
147
|
+
case idl.IDLPointerType: return this.make('Pointer');
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
150
|
+
}
|
|
151
|
+
enumName(target) {
|
|
152
|
+
return qualifiedName(target, "_");
|
|
153
|
+
}
|
|
154
|
+
computeTargetTypeLiteralName(decl) {
|
|
155
|
+
const map = new Map();
|
|
156
|
+
for (const prop of decl.properties) {
|
|
157
|
+
const type = this.convertNode(prop.type);
|
|
158
|
+
const values = map.has(type.text) ? map.get(type.text) : [];
|
|
159
|
+
values.push(prop.name);
|
|
160
|
+
map.set(type.text, values);
|
|
161
|
+
}
|
|
162
|
+
const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
|
|
163
|
+
return `Literal_${names.join('_')}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export class InteropNameConvertor {
|
|
167
|
+
constructor(resolver) {
|
|
168
|
+
this.resolver = resolver;
|
|
169
|
+
this.interopConvertor = new InteropConvertor(resolver);
|
|
170
|
+
}
|
|
171
|
+
convert(node) {
|
|
172
|
+
return this.interopConvertor.convertNode(node).text;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export class InteropReturnTypeConvertor {
|
|
176
|
+
isVoid(method) {
|
|
177
|
+
return this.convert(method.returnType) === idl.IDLVoidType.name;
|
|
178
|
+
}
|
|
179
|
+
convert(type) {
|
|
180
|
+
return convertType(this, type);
|
|
181
|
+
}
|
|
182
|
+
convertContainer(type) {
|
|
183
|
+
if (idl.IDLContainerUtils.isSequence(type) || idl.IDLContainerUtils.isPromise(type)) {
|
|
184
|
+
// TODO return array by some way
|
|
185
|
+
return "void";
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
return PrimitiveTypesInstance.NativePointer.getText();
|
|
189
|
+
}
|
|
190
|
+
convertImport(type, importClause) {
|
|
191
|
+
throw new Error(`Cannot pass import type ${type.name} through interop`);
|
|
192
|
+
}
|
|
193
|
+
convertOptional(type) {
|
|
194
|
+
return this.convert(type.type);
|
|
195
|
+
}
|
|
196
|
+
convertPrimitiveType(type) {
|
|
197
|
+
switch (type) {
|
|
198
|
+
case idl.IDLI8Type:
|
|
199
|
+
case idl.IDLU8Type:
|
|
200
|
+
case idl.IDLI16Type:
|
|
201
|
+
case idl.IDLU16Type:
|
|
202
|
+
case idl.IDLI32Type:
|
|
203
|
+
case idl.IDLU32Type:
|
|
204
|
+
case idl.IDLI64Type:
|
|
205
|
+
case idl.IDLU64Type:
|
|
206
|
+
case idl.IDLF16Type:
|
|
207
|
+
case idl.IDLF32Type:
|
|
208
|
+
case idl.IDLF64Type:
|
|
209
|
+
case idl.IDLNumberType: return PrimitiveTypesInstance.Int32.getText();
|
|
210
|
+
case idl.IDLBooleanType: return PrimitiveTypesInstance.Boolean.getText();
|
|
211
|
+
case idl.IDLAnyType:
|
|
212
|
+
case idl.IDLBufferType:
|
|
213
|
+
case idl.IDLStringType:
|
|
214
|
+
case idl.IDLThisType:
|
|
215
|
+
case idl.IDLUndefinedType:
|
|
216
|
+
case idl.IDLUnknownType:
|
|
217
|
+
case idl.IDLVoidType: return idl.IDLVoidType.name;
|
|
218
|
+
case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
219
|
+
}
|
|
220
|
+
throw new Error(`Cannot pass primitive type ${type.name} through interop`);
|
|
221
|
+
}
|
|
222
|
+
convertTypeParameter(type) {
|
|
223
|
+
return idl.IDLVoidType.name;
|
|
224
|
+
}
|
|
225
|
+
convertTypeReference(type) {
|
|
226
|
+
if (type.name.endsWith("Attribute"))
|
|
227
|
+
return idl.IDLVoidType.name;
|
|
228
|
+
return PrimitiveTypesInstance.NativePointer.getText();
|
|
229
|
+
}
|
|
230
|
+
convertUnion(type) {
|
|
231
|
+
return PrimitiveTypesInstance.NativePointer.getText();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
export class InteropArgConvertor {
|
|
235
|
+
convert(type) {
|
|
236
|
+
return convertType(this, type);
|
|
237
|
+
}
|
|
238
|
+
convertContainer(type) {
|
|
239
|
+
throw new Error(`Cannot pass container types through interop`);
|
|
240
|
+
}
|
|
241
|
+
convertImport(type, importClause) {
|
|
242
|
+
throw new Error(`Cannot pass import types through interop`);
|
|
243
|
+
}
|
|
244
|
+
convertOptional(type) {
|
|
245
|
+
return "KNativePointer";
|
|
246
|
+
}
|
|
247
|
+
convertPrimitiveType(type) {
|
|
248
|
+
switch (type) {
|
|
249
|
+
case idl.IDLI32Type: return "KInt";
|
|
250
|
+
case idl.IDLNumberType: return 'number';
|
|
251
|
+
case idl.IDLBigintType: return 'bigint';
|
|
252
|
+
case idl.IDLBooleanType:
|
|
253
|
+
case idl.IDLFunctionType: return 'KInt';
|
|
254
|
+
case idl.IDLStringType: return 'KStringPtr';
|
|
255
|
+
case idl.IDLBufferType: return `ArrayBuffer`;
|
|
256
|
+
case idl.IDLLengthType: return 'Length';
|
|
257
|
+
case idl.IDLDate: return 'KLong';
|
|
258
|
+
case idl.IDLUndefinedType:
|
|
259
|
+
case idl.IDLVoidType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
260
|
+
case idl.IDLPointerType: return "KPointer"; //PrimitiveType.NativePointer.getText()
|
|
261
|
+
}
|
|
262
|
+
throw new Error(`Cannot pass primitive type ${type.name} through interop`);
|
|
263
|
+
}
|
|
264
|
+
convertTypeParameter(type) {
|
|
265
|
+
throw new Error("Cannot pass type parameters through interop");
|
|
266
|
+
}
|
|
267
|
+
convertTypeReference(type) {
|
|
268
|
+
throw new Error(`Cannot pass type references through interop`);
|
|
269
|
+
}
|
|
270
|
+
convertUnion(type) {
|
|
271
|
+
throw new Error("Cannot pass union types through interop");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=InteropConvertors.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as idl from '../../idl';
|
|
2
|
+
import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
|
|
3
|
+
import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
|
|
4
|
+
import { InteropArgConvertor } from './InteropConvertors';
|
|
5
|
+
export declare class JavaTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
|
|
6
|
+
private resolver;
|
|
7
|
+
constructor(resolver: ReferenceResolver);
|
|
8
|
+
protected solidConvertor: import("../../util").Lazy<JavaIdlNodeToSolidStringConvertor>;
|
|
9
|
+
convert(node: idl.IDLNode): string;
|
|
10
|
+
convertNamespace(node: idl.IDLNamespace): string;
|
|
11
|
+
convertInterface(node: idl.IDLInterface): string;
|
|
12
|
+
convertEnum(node: idl.IDLEnum): string;
|
|
13
|
+
convertTypedef(node: idl.IDLTypedef): string;
|
|
14
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
15
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
16
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
17
|
+
convertCallback(type: idl.IDLCallback): string;
|
|
18
|
+
convertMethod(type: idl.IDLMethod): string;
|
|
19
|
+
convertConstant(type: idl.IDLConstant): string;
|
|
20
|
+
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
21
|
+
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
22
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
23
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
24
|
+
private readonly javaPrimitiveToReferenceTypeMap;
|
|
25
|
+
protected maybeConvertPrimitiveType(javaType: string): string;
|
|
26
|
+
private mapTypeName;
|
|
27
|
+
}
|
|
28
|
+
declare class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
|
|
29
|
+
protected solidConvertor: import("../../util").Lazy<this>;
|
|
30
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
31
|
+
}
|
|
32
|
+
export declare class JavaInteropArgConvertor extends InteropArgConvertor {
|
|
33
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=JavaConvertors.d.ts.map
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import * as idl from '../../idl';
|
|
16
|
+
import { lazy } from '../../util';
|
|
17
|
+
import { convertNode, convertType } from '../nameConvertor';
|
|
18
|
+
import { InteropArgConvertor } from './InteropConvertors';
|
|
19
|
+
function convertJavaOptional(type) {
|
|
20
|
+
switch (type) {
|
|
21
|
+
case 'boolean': return 'Opt_Boolean';
|
|
22
|
+
case 'double': return 'Opt_Number';
|
|
23
|
+
}
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
export class JavaTypeNameConvertor {
|
|
27
|
+
constructor(resolver) {
|
|
28
|
+
this.resolver = resolver;
|
|
29
|
+
this.solidConvertor = lazy(() => new JavaIdlNodeToSolidStringConvertor(this.resolver));
|
|
30
|
+
this.javaPrimitiveToReferenceTypeMap = new Map([
|
|
31
|
+
['byte', 'Byte'],
|
|
32
|
+
['short', 'Short'],
|
|
33
|
+
['int', 'Integer'],
|
|
34
|
+
['float', 'Float'],
|
|
35
|
+
['double', 'Double'],
|
|
36
|
+
['boolean', 'Boolean'],
|
|
37
|
+
['char', 'Character'],
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
convert(node) {
|
|
41
|
+
const typeString = convertNode(this, node);
|
|
42
|
+
return this.mapTypeName(typeString);
|
|
43
|
+
}
|
|
44
|
+
convertNamespace(node) {
|
|
45
|
+
throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
|
|
46
|
+
}
|
|
47
|
+
convertInterface(node) {
|
|
48
|
+
if (node.subkind === idl.IDLInterfaceSubkind.Tuple) {
|
|
49
|
+
const javaTypeAliases = node.properties.map(it => convertType(this, idl.maybeOptional(it.type, it.isOptional)));
|
|
50
|
+
return `Tuple_${javaTypeAliases.join('_')}`;
|
|
51
|
+
}
|
|
52
|
+
return node.name;
|
|
53
|
+
}
|
|
54
|
+
convertEnum(node) {
|
|
55
|
+
return node.name;
|
|
56
|
+
}
|
|
57
|
+
convertTypedef(node) {
|
|
58
|
+
return node.name;
|
|
59
|
+
}
|
|
60
|
+
convertOptional(type) {
|
|
61
|
+
return convertJavaOptional(this.convert(type.type));
|
|
62
|
+
}
|
|
63
|
+
convertUnion(type) {
|
|
64
|
+
const aliases = type.types.map(it => convertType(this.solidConvertor.value, it));
|
|
65
|
+
return `Union_${aliases.join('_')}`;
|
|
66
|
+
}
|
|
67
|
+
convertContainer(type) {
|
|
68
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
69
|
+
const javaType = convertType(this, type.elementType[0]);
|
|
70
|
+
return `${javaType}[]`;
|
|
71
|
+
}
|
|
72
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
73
|
+
const javaTypes = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
|
|
74
|
+
return `Map<${javaTypes[0]}, ${javaTypes[1]}>`;
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
|
|
77
|
+
}
|
|
78
|
+
convertCallback(type) {
|
|
79
|
+
return `Callback`;
|
|
80
|
+
}
|
|
81
|
+
convertMethod(type) {
|
|
82
|
+
throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
|
|
83
|
+
}
|
|
84
|
+
convertConstant(type) {
|
|
85
|
+
throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
|
|
86
|
+
}
|
|
87
|
+
convertImport(type, importClause) {
|
|
88
|
+
return type.name;
|
|
89
|
+
}
|
|
90
|
+
convertTypeReference(type) {
|
|
91
|
+
const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
|
|
92
|
+
if (importAttr) {
|
|
93
|
+
return this.convertImport(type, importAttr);
|
|
94
|
+
}
|
|
95
|
+
const decl = this.resolver.resolveTypeReference(type);
|
|
96
|
+
if (decl) {
|
|
97
|
+
const declName = this.convert(decl);
|
|
98
|
+
return declName;
|
|
99
|
+
}
|
|
100
|
+
if (type.name === `Optional`) {
|
|
101
|
+
return convertJavaOptional(idl.printType(type.typeArguments[0]));
|
|
102
|
+
}
|
|
103
|
+
return type.name;
|
|
104
|
+
}
|
|
105
|
+
convertTypeParameter(type) {
|
|
106
|
+
// TODO
|
|
107
|
+
return type.name;
|
|
108
|
+
}
|
|
109
|
+
convertPrimitiveType(type) {
|
|
110
|
+
switch (type) {
|
|
111
|
+
case idl.IDLStringType: return 'String';
|
|
112
|
+
case idl.IDLNumberType: return 'double';
|
|
113
|
+
case idl.IDLBooleanType: return 'boolean';
|
|
114
|
+
case idl.IDLUndefinedType: return 'Ark_Undefined';
|
|
115
|
+
case idl.IDLI8Type: return 'byte';
|
|
116
|
+
case idl.IDLU8Type: return 'byte';
|
|
117
|
+
case idl.IDLI16Type: return 'short';
|
|
118
|
+
case idl.IDLU16Type: return 'short';
|
|
119
|
+
case idl.IDLI32Type: return 'int';
|
|
120
|
+
case idl.IDLU32Type: return 'int';
|
|
121
|
+
case idl.IDLI64Type: return 'long';
|
|
122
|
+
case idl.IDLU64Type: return 'long';
|
|
123
|
+
case idl.IDLF32Type: return 'float';
|
|
124
|
+
case idl.IDLF64Type: return 'double';
|
|
125
|
+
case idl.IDLPointerType: return 'long';
|
|
126
|
+
case idl.IDLVoidType: return 'void';
|
|
127
|
+
case idl.IDLDate: return 'Date';
|
|
128
|
+
case idl.IDLBufferType: return 'byte[]';
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
131
|
+
}
|
|
132
|
+
maybeConvertPrimitiveType(javaType) {
|
|
133
|
+
if (this.javaPrimitiveToReferenceTypeMap.has(javaType)) {
|
|
134
|
+
return this.javaPrimitiveToReferenceTypeMap.get(javaType);
|
|
135
|
+
}
|
|
136
|
+
return javaType;
|
|
137
|
+
}
|
|
138
|
+
mapTypeName(name) {
|
|
139
|
+
switch (name) {
|
|
140
|
+
case 'KPointer': return 'long';
|
|
141
|
+
case 'KBoolean': return 'boolean';
|
|
142
|
+
case 'KUInt': return 'int';
|
|
143
|
+
case 'int32':
|
|
144
|
+
case 'KInt': return 'int';
|
|
145
|
+
case 'int64':
|
|
146
|
+
case 'KLong': return 'long';
|
|
147
|
+
case 'float32':
|
|
148
|
+
case 'KFloat': return 'float';
|
|
149
|
+
case 'KUint8ArrayPtr': return 'byte[]';
|
|
150
|
+
case 'KInt32ArrayPtr': return 'int[]';
|
|
151
|
+
case 'KFloat32ArrayPtr': return 'float[]';
|
|
152
|
+
// case 'ArrayBuffer': return 'byte[]'
|
|
153
|
+
case 'KStringPtr': return 'String';
|
|
154
|
+
case 'string': return 'String';
|
|
155
|
+
}
|
|
156
|
+
return name;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
|
|
160
|
+
constructor() {
|
|
161
|
+
super(...arguments);
|
|
162
|
+
this.solidConvertor = lazy(() => this);
|
|
163
|
+
}
|
|
164
|
+
convertContainer(type) {
|
|
165
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
166
|
+
const javaTypeSolid = convertType(this, type.elementType[0]);
|
|
167
|
+
return `Array_${javaTypeSolid}`;
|
|
168
|
+
}
|
|
169
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
170
|
+
const javaTypeSolids = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
|
|
171
|
+
return `Map_${javaTypeSolids[0]}_${javaTypeSolids[1]}`;
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export class JavaInteropArgConvertor extends InteropArgConvertor {
|
|
177
|
+
convertPrimitiveType(type) {
|
|
178
|
+
switch (type) {
|
|
179
|
+
case idl.IDLNumberType: return "double";
|
|
180
|
+
case idl.IDLLengthType: return "String";
|
|
181
|
+
case idl.IDLBooleanType: return "boolean";
|
|
182
|
+
}
|
|
183
|
+
return super.convertPrimitiveType(type);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=JavaConvertors.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as idl from '../../idl';
|
|
2
|
+
import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
|
|
3
|
+
import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
|
|
4
|
+
export declare class TSTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
|
|
5
|
+
protected resolver: ReferenceResolver;
|
|
6
|
+
constructor(resolver: ReferenceResolver);
|
|
7
|
+
convert(node: idl.IDLNode): string;
|
|
8
|
+
convertNamespace(node: idl.IDLNamespace): string;
|
|
9
|
+
convertInterface(node: idl.IDLInterface): string;
|
|
10
|
+
convertEnum(node: idl.IDLEnum): string;
|
|
11
|
+
convertTypedef(node: idl.IDLTypedef): string;
|
|
12
|
+
convertCallback(node: idl.IDLCallback): string;
|
|
13
|
+
convertMethod(node: idl.IDLMethod): string;
|
|
14
|
+
convertConstant(node: idl.IDLConstant): string;
|
|
15
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
16
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
17
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
18
|
+
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
19
|
+
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
20
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
21
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
22
|
+
protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
|
|
23
|
+
protected mapCallback(decl: idl.IDLCallback): string;
|
|
24
|
+
protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
|
|
25
|
+
protected mapFunctionType(typeArgs: string[]): string;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=TSConvertors.d.ts.map
|