@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
|
@@ -19,7 +19,7 @@ import { RuntimeType } from "./common";
|
|
|
19
19
|
import { generatorTypePrefix } from "../config";
|
|
20
20
|
import { hashCodeFromString, warn } from "../util";
|
|
21
21
|
import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
|
|
22
|
-
import { InteropNameConvertor } from "./
|
|
22
|
+
import { InteropNameConvertor } from "./convertors/InteropConvertors";
|
|
23
23
|
import { createEmptyReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
24
24
|
import { CppInteropConvertor } from "./convertors/CppConvertors";
|
|
25
25
|
import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
|
|
@@ -273,6 +273,7 @@ export declare abstract class LanguageWriter {
|
|
|
273
273
|
writeStatement(stmt: LanguageStatement): void;
|
|
274
274
|
writeStatements(...statements: LanguageStatement[]): void;
|
|
275
275
|
writeExpressionStatement(smth: LanguageExpression): void;
|
|
276
|
+
writeExpressionStatements(statements: LanguageExpression[]): void;
|
|
276
277
|
writeStaticBlock(op: (writer: this) => void): void;
|
|
277
278
|
makeRef(type: idl.IDLType, _options?: MakeRefOptions): idl.IDLType;
|
|
278
279
|
makeThis(): LanguageExpression;
|
|
@@ -437,6 +437,9 @@ export class LanguageWriter {
|
|
|
437
437
|
writeExpressionStatement(smth) {
|
|
438
438
|
this.writeStatement(new ExpressionStatement(smth));
|
|
439
439
|
}
|
|
440
|
+
writeExpressionStatements(statements) {
|
|
441
|
+
statements.forEach(it => this.writeExpressionStatement(it));
|
|
442
|
+
}
|
|
440
443
|
writeStaticBlock(op) {
|
|
441
444
|
this.print("static {");
|
|
442
445
|
this.pushIndent();
|
|
@@ -0,0 +1,34 @@
|
|
|
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 CJTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
|
|
6
|
+
protected resolver: ReferenceResolver;
|
|
7
|
+
constructor(resolver: ReferenceResolver);
|
|
8
|
+
convert(node: idl.IDLNode): string;
|
|
9
|
+
/***** TypeConvertor<string> **********************************/
|
|
10
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
11
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
12
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
13
|
+
convertNamespace(node: idl.IDLNamespace): string;
|
|
14
|
+
convertInterface(node: idl.IDLInterface): string;
|
|
15
|
+
convertEnum(node: idl.IDLEnum): string;
|
|
16
|
+
convertTypedef(node: idl.IDLTypedef): string;
|
|
17
|
+
convertCallback(type: idl.IDLCallback): string;
|
|
18
|
+
convertMethod(node: idl.IDLMethod): string;
|
|
19
|
+
convertConstant(node: 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 callbackType;
|
|
25
|
+
private productType;
|
|
26
|
+
}
|
|
27
|
+
export declare class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
|
|
28
|
+
convert(type: idl.IDLNode): string;
|
|
29
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
30
|
+
}
|
|
31
|
+
export declare class CJInteropArgConvertor extends InteropArgConvertor {
|
|
32
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=CJConvertors.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
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 { convertNode, convertType } from '../nameConvertor';
|
|
17
|
+
import { InteropArgConvertor } from './InteropConvertors';
|
|
18
|
+
export class CJTypeNameConvertor {
|
|
19
|
+
constructor(resolver) {
|
|
20
|
+
this.resolver = resolver;
|
|
21
|
+
}
|
|
22
|
+
convert(node) {
|
|
23
|
+
return convertNode(this, node);
|
|
24
|
+
}
|
|
25
|
+
/***** TypeConvertor<string> **********************************/
|
|
26
|
+
convertOptional(type) {
|
|
27
|
+
return `Option<${this.convert(type.type)}>`;
|
|
28
|
+
}
|
|
29
|
+
convertUnion(type) {
|
|
30
|
+
return type.name;
|
|
31
|
+
}
|
|
32
|
+
convertContainer(type) {
|
|
33
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
34
|
+
return `ArrayList<${convertType(this, type.elementType[0])}>`;
|
|
35
|
+
}
|
|
36
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
37
|
+
const stringes = type.elementType.slice(0, 2).map(it => convertType(this, it));
|
|
38
|
+
return `Map<${stringes[0]}, ${stringes[1]}>`;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
|
|
41
|
+
}
|
|
42
|
+
convertNamespace(node) {
|
|
43
|
+
throw new Error('Method not implemented.');
|
|
44
|
+
}
|
|
45
|
+
convertInterface(node) {
|
|
46
|
+
return node.name;
|
|
47
|
+
}
|
|
48
|
+
convertEnum(node) {
|
|
49
|
+
return node.name;
|
|
50
|
+
}
|
|
51
|
+
convertTypedef(node) {
|
|
52
|
+
return node.name;
|
|
53
|
+
}
|
|
54
|
+
convertCallback(type) {
|
|
55
|
+
const params = type.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
|
|
56
|
+
return `\{(${params.join(", ")}) => ${this.convert(type.returnType)}\}`;
|
|
57
|
+
}
|
|
58
|
+
convertMethod(node) {
|
|
59
|
+
throw new Error('Method not implemented.');
|
|
60
|
+
}
|
|
61
|
+
convertConstant(node) {
|
|
62
|
+
throw new Error('Method not implemented.');
|
|
63
|
+
}
|
|
64
|
+
convertImport(type, importClause) {
|
|
65
|
+
return type.name;
|
|
66
|
+
}
|
|
67
|
+
convertTypeReference(type) {
|
|
68
|
+
if (type.name === "Object")
|
|
69
|
+
return "KPointer";
|
|
70
|
+
const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
|
|
71
|
+
if (importAttr) {
|
|
72
|
+
return this.convertImport(type, importAttr);
|
|
73
|
+
}
|
|
74
|
+
// resolve synthetic types
|
|
75
|
+
const decl = this.resolver.resolveTypeReference(type);
|
|
76
|
+
if (decl && idl.isSyntheticEntry(decl)) {
|
|
77
|
+
if (idl.isCallback(decl)) {
|
|
78
|
+
return this.callbackType(decl);
|
|
79
|
+
}
|
|
80
|
+
const entity = idl.getExtAttribute(decl, idl.IDLExtendedAttributes.Entity);
|
|
81
|
+
if (entity) {
|
|
82
|
+
const isTuple = entity === idl.IDLEntity.Tuple;
|
|
83
|
+
return this.productType(decl, isTuple, !isTuple);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return type.name;
|
|
87
|
+
}
|
|
88
|
+
convertTypeParameter(type) {
|
|
89
|
+
return type.name;
|
|
90
|
+
}
|
|
91
|
+
convertPrimitiveType(type) {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case idl.IDLStringType: return 'String';
|
|
94
|
+
case idl.IDLBooleanType: return 'Bool';
|
|
95
|
+
case idl.IDLNumberType: return 'Float64';
|
|
96
|
+
case idl.IDLUndefinedType: return 'Unit'; // might be wrong
|
|
97
|
+
case idl.IDLI8Type: return 'Int8';
|
|
98
|
+
case idl.IDLU8Type: return 'UInt8';
|
|
99
|
+
case idl.IDLI16Type: return 'Int16';
|
|
100
|
+
case idl.IDLU16Type: return 'UInt16';
|
|
101
|
+
case idl.IDLI32Type: return 'Int32';
|
|
102
|
+
case idl.IDLU32Type: return 'UInt32';
|
|
103
|
+
case idl.IDLI64Type: return 'Int64';
|
|
104
|
+
case idl.IDLU64Type: return 'UInt64';
|
|
105
|
+
case idl.IDLF32Type: return 'Float32';
|
|
106
|
+
case idl.IDLF64Type: return 'Float64';
|
|
107
|
+
case idl.IDLPointerType: return 'UInt64';
|
|
108
|
+
case idl.IDLVoidType: return 'Unit';
|
|
109
|
+
case idl.IDLBufferType: return 'ArrayList<UInt8>';
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
112
|
+
}
|
|
113
|
+
callbackType(decl) {
|
|
114
|
+
const params = decl.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
|
|
115
|
+
return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
|
|
116
|
+
}
|
|
117
|
+
productType(decl, isTuple, includeFieldNames) {
|
|
118
|
+
if (!isTuple)
|
|
119
|
+
throw new Error('Only tuples supported from IDL synthetic types for now');
|
|
120
|
+
return decl.name;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
|
|
124
|
+
convert(type) {
|
|
125
|
+
if (idl.isPrimitiveType(type)) {
|
|
126
|
+
switch (type) {
|
|
127
|
+
case idl.IDLStringType: return 'CString';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (idl.isContainerType(type)) {
|
|
131
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
132
|
+
return `CPointer<${this.convert(type.elementType[0])}>`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (idl.isReferenceType(type)) {
|
|
136
|
+
// Fix, actual mapping has to be due to IDLType
|
|
137
|
+
if (super.convert(type).startsWith('Array'))
|
|
138
|
+
return `CPointer<UInt8>`;
|
|
139
|
+
if (super.convert(type) == 'String' || super.convert(type) == 'KStringPtr') {
|
|
140
|
+
return `CString`;
|
|
141
|
+
}
|
|
142
|
+
if (super.convert(type) == 'Object') {
|
|
143
|
+
return `KPointer`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return super.convert(type);
|
|
147
|
+
}
|
|
148
|
+
convertPrimitiveType(type) {
|
|
149
|
+
switch (type) {
|
|
150
|
+
case idl.IDLBufferType: return 'CPointer<UInt8>';
|
|
151
|
+
}
|
|
152
|
+
return super.convertPrimitiveType(type);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export class CJInteropArgConvertor extends InteropArgConvertor {
|
|
156
|
+
convertPrimitiveType(type) {
|
|
157
|
+
switch (type) {
|
|
158
|
+
case idl.IDLNumberType: return "Float64";
|
|
159
|
+
case idl.IDLLengthType: return "Ark_Length";
|
|
160
|
+
}
|
|
161
|
+
return super.convertPrimitiveType(type);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=CJConvertors.js.map
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as idl from '../../idl';
|
|
2
2
|
import { IdlNameConvertor } from "../nameConvertor";
|
|
3
|
-
import { InteropConvertor } from '
|
|
3
|
+
import { InteropConvertor } from './InteropConvertors';
|
|
4
|
+
import { InteropArgConvertor } from './InteropConvertors';
|
|
4
5
|
export declare class CppInteropConvertor extends InteropConvertor implements IdlNameConvertor {
|
|
5
6
|
private unwrap;
|
|
6
7
|
convert(node: idl.IDLNode): string;
|
|
7
8
|
}
|
|
9
|
+
export declare class CppInteropArgConvertor extends InteropArgConvertor {
|
|
10
|
+
static INSTANCE: CppInteropArgConvertor;
|
|
11
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
12
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
13
|
+
}
|
|
8
14
|
//# sourceMappingURL=CppConvertors.d.ts.map
|
|
@@ -14,16 +14,18 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../../idl';
|
|
16
16
|
import { generatorConfiguration } from "../../config";
|
|
17
|
-
import { InteropConvertor } from '
|
|
17
|
+
import { InteropConvertor } from './InteropConvertors';
|
|
18
|
+
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
|
+
import { InteropArgConvertor } from './InteropConvertors';
|
|
18
20
|
export class CppInteropConvertor extends InteropConvertor {
|
|
19
21
|
unwrap(type, result) {
|
|
22
|
+
const conf = generatorConfiguration();
|
|
20
23
|
if (idl.isType(type) && idl.isOptionalType(type)) {
|
|
21
|
-
return
|
|
24
|
+
return `${conf.param("OptionalPrefix")}${result.text}`;
|
|
22
25
|
}
|
|
23
26
|
if (result.noPrefix) {
|
|
24
27
|
return result.text;
|
|
25
28
|
}
|
|
26
|
-
const conf = generatorConfiguration();
|
|
27
29
|
const typePrefix = conf.param("TypePrefix");
|
|
28
30
|
// TODO remove this ugly hack for CustomObject's
|
|
29
31
|
const convertedToCustomObject = result.text === idl.IDLCustomObjectType.name;
|
|
@@ -34,4 +36,23 @@ export class CppInteropConvertor extends InteropConvertor {
|
|
|
34
36
|
return this.unwrap(node, this.convertNode(node));
|
|
35
37
|
}
|
|
36
38
|
}
|
|
39
|
+
export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
40
|
+
convertOptional(type) {
|
|
41
|
+
return PrimitiveTypesInstance.NativePointer.getText();
|
|
42
|
+
}
|
|
43
|
+
convertPrimitiveType(type) {
|
|
44
|
+
switch (type) {
|
|
45
|
+
case idl.IDLBooleanType: return PrimitiveTypesInstance.Boolean.getText();
|
|
46
|
+
case idl.IDLI32Type: return PrimitiveTypesInstance.Int32.getText();
|
|
47
|
+
case idl.IDLNumberType: return "KInteropNumber";
|
|
48
|
+
case idl.IDLBufferType: return "Ark_Buffer";
|
|
49
|
+
case idl.IDLLengthType: return "KLength";
|
|
50
|
+
case idl.IDLFunctionType: return PrimitiveTypesInstance.Int32.getText();
|
|
51
|
+
case idl.IDLDate: return PrimitiveTypesInstance.Int64.getText();
|
|
52
|
+
case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
53
|
+
}
|
|
54
|
+
return super.convertPrimitiveType(type);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
CppInteropArgConvertor.INSTANCE = new CppInteropArgConvertor();
|
|
37
58
|
//# sourceMappingURL=CppConvertors.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as idl from "../../idl";
|
|
2
|
+
import { TSTypeNameConvertor } from "./TSConvertors";
|
|
3
|
+
export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
4
|
+
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
5
|
+
convertEnum(node: idl.IDLEnum): string;
|
|
6
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
7
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
8
|
+
protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
|
|
9
|
+
protected processTupleType(idlProperty: idl.IDLProperty): idl.IDLProperty;
|
|
10
|
+
protected mapCallback(decl: idl.IDLCallback): string;
|
|
11
|
+
protected mapFunctionType(typeArgs: string[]): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ETSConvertors.d.ts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
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 { Language } from "../../Language";
|
|
17
|
+
import { createDeclarationNameConvertor } from "../../peer-generation/idl/IdlNameConvertor";
|
|
18
|
+
import { convertDeclaration } from "../nameConvertor";
|
|
19
|
+
import { TSTypeNameConvertor } from "./TSConvertors";
|
|
20
|
+
export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
21
|
+
convertTypeReference(type) {
|
|
22
|
+
// Only to deal with namespaces. TODO: remove later
|
|
23
|
+
const decl = this.resolver.resolveTypeReference(type);
|
|
24
|
+
if (decl && idl.isEnum(decl)) {
|
|
25
|
+
return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
|
|
26
|
+
}
|
|
27
|
+
// TODO: Needs to be implemented properly
|
|
28
|
+
const types = type.name.split(".");
|
|
29
|
+
if (types.length > 1) {
|
|
30
|
+
// Takes only name without the namespace prefix
|
|
31
|
+
const decl = this.resolver.resolveTypeReference(idl.createReferenceType(types.slice(-1).join(), undefined, type));
|
|
32
|
+
if (decl !== undefined) {
|
|
33
|
+
return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const typeName = super.convertTypeReference(type);
|
|
37
|
+
// TODO: Fix for 'TypeError: Type 'Function<R>' is generic but type argument were not provided.'
|
|
38
|
+
if (typeName === "Function") {
|
|
39
|
+
return "Function<void>";
|
|
40
|
+
}
|
|
41
|
+
return typeName;
|
|
42
|
+
}
|
|
43
|
+
convertEnum(node) {
|
|
44
|
+
let ns = idl.getNamespaceName(node).split('.').join('_');
|
|
45
|
+
if (ns !== '') {
|
|
46
|
+
ns += '_';
|
|
47
|
+
}
|
|
48
|
+
return ns + node.name;
|
|
49
|
+
}
|
|
50
|
+
convertContainer(type) {
|
|
51
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
52
|
+
switch (type.elementType[0]) {
|
|
53
|
+
case idl.IDLU8Type: return 'KUint8ArrayPtr';
|
|
54
|
+
case idl.IDLI32Type: return 'KInt32ArrayPtr';
|
|
55
|
+
case idl.IDLF32Type: return 'KFloat32ArrayPtr';
|
|
56
|
+
}
|
|
57
|
+
return `Array<${this.convert(type.elementType[0])}>`;
|
|
58
|
+
}
|
|
59
|
+
return super.convertContainer(type);
|
|
60
|
+
}
|
|
61
|
+
convertPrimitiveType(type) {
|
|
62
|
+
switch (type) {
|
|
63
|
+
case idl.IDLAnyType: return "object";
|
|
64
|
+
case idl.IDLUnknownType: return "object";
|
|
65
|
+
case idl.IDLPointerType: return 'KPointer';
|
|
66
|
+
case idl.IDLVoidType: return 'void';
|
|
67
|
+
case idl.IDLBooleanType: return 'boolean';
|
|
68
|
+
case idl.IDLU8Type:
|
|
69
|
+
case idl.IDLI8Type:
|
|
70
|
+
case idl.IDLI16Type:
|
|
71
|
+
case idl.IDLU16Type:
|
|
72
|
+
case idl.IDLI32Type:
|
|
73
|
+
case idl.IDLU32Type:
|
|
74
|
+
return 'int32';
|
|
75
|
+
case idl.IDLI64Type:
|
|
76
|
+
case idl.IDLU64Type:
|
|
77
|
+
return 'int64';
|
|
78
|
+
case idl.IDLF32Type:
|
|
79
|
+
return 'float32';
|
|
80
|
+
case idl.IDLF64Type:
|
|
81
|
+
return 'float64';
|
|
82
|
+
case idl.IDLNumberType:
|
|
83
|
+
return 'number';
|
|
84
|
+
case idl.IDLStringType: return 'string';
|
|
85
|
+
case idl.IDLFunctionType: return 'Object';
|
|
86
|
+
case idl.IDLBufferType: return 'NativeBuffer';
|
|
87
|
+
}
|
|
88
|
+
return super.convertPrimitiveType(type);
|
|
89
|
+
}
|
|
90
|
+
productType(decl, isTuple, includeFieldNames) {
|
|
91
|
+
if (decl.subkind === idl.IDLInterfaceSubkind.AnonymousInterface) {
|
|
92
|
+
return decl.name;
|
|
93
|
+
}
|
|
94
|
+
return super.productType(decl, isTuple, includeFieldNames);
|
|
95
|
+
}
|
|
96
|
+
processTupleType(idlProperty) {
|
|
97
|
+
if (idlProperty.isOptional) {
|
|
98
|
+
return Object.assign(Object.assign({}, idlProperty), { isOptional: false, type: idl.createUnionType([idlProperty.type, idl.IDLUndefinedType]) });
|
|
99
|
+
}
|
|
100
|
+
return idlProperty;
|
|
101
|
+
}
|
|
102
|
+
mapCallback(decl) {
|
|
103
|
+
const params = decl.parameters.map(it => {
|
|
104
|
+
return `${it.name}${it.isOptional ? "?" : ""}: ${this.convert(it.type)}`;
|
|
105
|
+
});
|
|
106
|
+
return `((${params.join(",")}) => ${this.convert(decl.returnType)})`;
|
|
107
|
+
}
|
|
108
|
+
mapFunctionType(typeArgs) {
|
|
109
|
+
// Fix for "TypeError: Type 'Function<R>' is generic but type argument were not provided."
|
|
110
|
+
// Replace "Function" to "Function<void>"
|
|
111
|
+
// Use "FunctionN" for ts compatibility
|
|
112
|
+
if (typeArgs.length === 0) {
|
|
113
|
+
typeArgs = [this.convert(idl.IDLVoidType)];
|
|
114
|
+
}
|
|
115
|
+
return `Function${typeArgs.length - 1}<${typeArgs.join(",")}>`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ETSConvertors.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as idl from '../../idl';
|
|
2
|
+
import { PeerMethod } from '../../peer-generation/PeerMethod';
|
|
3
|
+
import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
|
|
4
|
+
import { IdlNameConvertor, NodeConvertor, TypeConvertor } from '../nameConvertor';
|
|
5
|
+
export interface ConvertResult {
|
|
6
|
+
text: string;
|
|
7
|
+
noPrefix: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class InteropConvertor implements NodeConvertor<ConvertResult> {
|
|
10
|
+
protected resolver: ReferenceResolver;
|
|
11
|
+
constructor(resolver: ReferenceResolver);
|
|
12
|
+
private make;
|
|
13
|
+
convertNode(node: idl.IDLNode): ConvertResult;
|
|
14
|
+
convertNamespace(node: idl.IDLNamespace): ConvertResult;
|
|
15
|
+
convertInterface(node: idl.IDLInterface): ConvertResult;
|
|
16
|
+
convertEnum(node: idl.IDLEnum): ConvertResult;
|
|
17
|
+
convertTypedef(node: idl.IDLTypedef): ConvertResult;
|
|
18
|
+
convertCallback(node: idl.IDLCallback): ConvertResult;
|
|
19
|
+
convertMethod(node: idl.IDLMethod): ConvertResult;
|
|
20
|
+
convertConstant(node: idl.IDLConstant): ConvertResult;
|
|
21
|
+
convertOptional(type: idl.IDLOptionalType): ConvertResult;
|
|
22
|
+
convertUnion(type: idl.IDLUnionType): ConvertResult;
|
|
23
|
+
convertContainer(type: idl.IDLContainerType): ConvertResult;
|
|
24
|
+
convertImport(type: idl.IDLReferenceType, _: string): ConvertResult;
|
|
25
|
+
convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
|
|
26
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
|
|
27
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
|
|
28
|
+
private enumName;
|
|
29
|
+
private computeTargetTypeLiteralName;
|
|
30
|
+
}
|
|
31
|
+
export declare class InteropNameConvertor implements IdlNameConvertor {
|
|
32
|
+
protected resolver: ReferenceResolver;
|
|
33
|
+
private readonly interopConvertor;
|
|
34
|
+
constructor(resolver: ReferenceResolver);
|
|
35
|
+
convert(node: idl.IDLNode): string;
|
|
36
|
+
}
|
|
37
|
+
export declare class InteropReturnTypeConvertor implements TypeConvertor<string> {
|
|
38
|
+
isVoid(method: PeerMethod): boolean;
|
|
39
|
+
convert(type: idl.IDLType): string;
|
|
40
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
41
|
+
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
42
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
43
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
44
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
45
|
+
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
46
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
47
|
+
}
|
|
48
|
+
export declare class InteropArgConvertor implements TypeConvertor<string> {
|
|
49
|
+
convert(type: idl.IDLType): string;
|
|
50
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
51
|
+
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
52
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
53
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
54
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
55
|
+
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
56
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=InteropConvertors.d.ts.map
|