@idlizer/core 2.0.32 → 2.0.35
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 +12 -4
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +11 -8
- package/build/lib/src/LanguageWriters/LanguageWriter.js +11 -8
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +2 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +0 -2
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +1 -7
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +1 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +3 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +3 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +12 -2
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +1 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -3
- package/build/lib/src/from-idl/DtsPrinter.d.ts +3 -3
- package/build/lib/src/from-idl/DtsPrinter.js +18 -26
- package/build/lib/src/from-idl/common.d.ts +2 -2
- package/build/lib/src/from-idl/common.js +2 -8
- package/build/lib/src/from-idl/deserialize.d.ts +1 -4
- package/build/lib/src/from-idl/deserialize.js +17 -19
- package/build/lib/src/idl.d.ts +26 -33
- package/build/lib/src/idl.js +38 -56
- package/build/lib/src/index.d.ts +1 -1
- package/build/lib/src/index.js +1 -1
- package/build/lib/src/library.d.ts +1 -2
- package/build/lib/src/library.js +1 -4
- package/build/lib/src/peer-generation/Materialized.d.ts +3 -1
- package/build/lib/src/peer-generation/Materialized.js +8 -1
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -1
- package/build/lib/src/peer-generation/PeerFile.js +3 -11
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -5
- package/build/lib/src/peer-generation/PeerLibrary.js +31 -4
- package/build/lib/src/peer-generation/PeerMethod.js +5 -1
- package/build/lib/src/peer-generation/PrimitiveType.d.ts +2 -0
- package/build/lib/src/peer-generation/PrimitiveType.js +4 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +5 -4
- package/build/lib/src/peer-generation/isMaterialized.d.ts +1 -0
- package/build/lib/src/peer-generation/isMaterialized.js +8 -0
- package/package.json +2 -2
|
@@ -16,7 +16,7 @@ import * as idl from "../idl";
|
|
|
16
16
|
import { Language } from "../Language";
|
|
17
17
|
import { PrintHint, BlockStatement, StringExpression } from "./LanguageWriter";
|
|
18
18
|
import { RuntimeType } from "./common";
|
|
19
|
-
import { generatorTypePrefix } from "../config";
|
|
19
|
+
import { generatorConfiguration, generatorTypePrefix } from "../config";
|
|
20
20
|
import { hashCodeFromString, warn } from "../util";
|
|
21
21
|
import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
|
|
22
22
|
import { CppNameConvertor } from "./convertors/CppConvertors";
|
|
@@ -888,11 +888,19 @@ export class FunctionConvertor extends BaseArgConvertor {
|
|
|
888
888
|
}
|
|
889
889
|
export class MaterializedClassConvertor extends BaseArgConvertor {
|
|
890
890
|
constructor(param, declaration) {
|
|
891
|
-
super(idl.createReferenceType(declaration), [RuntimeType.OBJECT], false,
|
|
891
|
+
super(idl.createReferenceType(declaration), [RuntimeType.OBJECT], false, false, param);
|
|
892
892
|
this.declaration = declaration;
|
|
893
893
|
}
|
|
894
894
|
convertorArg(param, writer) {
|
|
895
|
-
|
|
895
|
+
switch (writer.language) {
|
|
896
|
+
case Language.CPP:
|
|
897
|
+
return `static_cast<${generatorConfiguration().TypePrefix}${this.declaration.name}>(${param})`;
|
|
898
|
+
case Language.JAVA:
|
|
899
|
+
case Language.CJ:
|
|
900
|
+
return `MaterializedBase.toPeerPtr(${param})`;
|
|
901
|
+
default:
|
|
902
|
+
return `toPeerPtr(${param})`;
|
|
903
|
+
}
|
|
896
904
|
}
|
|
897
905
|
convertorSerialize(param, value, printer) {
|
|
898
906
|
printer.writeStatement(printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, `write${this.declaration.name}`, [
|
|
@@ -907,7 +915,7 @@ export class MaterializedClassConvertor extends BaseArgConvertor {
|
|
|
907
915
|
return idl.createReferenceType(this.declaration);
|
|
908
916
|
}
|
|
909
917
|
interopType() {
|
|
910
|
-
|
|
918
|
+
return idl.IDLPointerType;
|
|
911
919
|
}
|
|
912
920
|
isPointerType() {
|
|
913
921
|
return false;
|
|
@@ -147,13 +147,14 @@ export declare enum FieldModifier {
|
|
|
147
147
|
export declare enum MethodModifier {
|
|
148
148
|
PUBLIC = 0,
|
|
149
149
|
PRIVATE = 1,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
PROTECTED = 2,
|
|
151
|
+
STATIC = 3,
|
|
152
|
+
NATIVE = 4,
|
|
153
|
+
INLINE = 5,
|
|
154
|
+
GETTER = 6,
|
|
155
|
+
SETTER = 7,
|
|
156
|
+
THROWS = 8,
|
|
157
|
+
FREE = 9
|
|
157
158
|
}
|
|
158
159
|
export declare enum ClassModifier {
|
|
159
160
|
PUBLIC = 0,
|
|
@@ -214,7 +215,8 @@ export declare abstract class LanguageWriter {
|
|
|
214
215
|
printer: IndentedPrinter;
|
|
215
216
|
resolver: ReferenceResolver;
|
|
216
217
|
language: Language;
|
|
217
|
-
|
|
218
|
+
protected namespaceStack: string[];
|
|
219
|
+
constructor(printer: IndentedPrinter, resolver: ReferenceResolver, // TODO make protected again (or better rework LWs)
|
|
218
220
|
language: Language);
|
|
219
221
|
indentDepth(): number;
|
|
220
222
|
maybeSemicolon(): string;
|
|
@@ -233,6 +235,7 @@ export declare abstract class LanguageWriter {
|
|
|
233
235
|
abstract writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
234
236
|
abstract writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
235
237
|
abstract writeProperty(propName: string, propType: idl.IDLType, mutable?: boolean, getterLambda?: (writer: this) => void, setterLambda?: (writer: this) => void): void;
|
|
238
|
+
abstract writeTypeDeclaration(decl: idl.IDLTypedef): void;
|
|
236
239
|
abstract makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
|
|
237
240
|
abstract makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
|
|
238
241
|
abstract makeThrowError(message: string): LanguageStatement;
|
|
@@ -309,13 +309,14 @@ export var MethodModifier;
|
|
|
309
309
|
(function (MethodModifier) {
|
|
310
310
|
MethodModifier[MethodModifier["PUBLIC"] = 0] = "PUBLIC";
|
|
311
311
|
MethodModifier[MethodModifier["PRIVATE"] = 1] = "PRIVATE";
|
|
312
|
-
MethodModifier[MethodModifier["
|
|
313
|
-
MethodModifier[MethodModifier["
|
|
314
|
-
MethodModifier[MethodModifier["
|
|
315
|
-
MethodModifier[MethodModifier["
|
|
316
|
-
MethodModifier[MethodModifier["
|
|
317
|
-
MethodModifier[MethodModifier["
|
|
318
|
-
MethodModifier[MethodModifier["
|
|
312
|
+
MethodModifier[MethodModifier["PROTECTED"] = 2] = "PROTECTED";
|
|
313
|
+
MethodModifier[MethodModifier["STATIC"] = 3] = "STATIC";
|
|
314
|
+
MethodModifier[MethodModifier["NATIVE"] = 4] = "NATIVE";
|
|
315
|
+
MethodModifier[MethodModifier["INLINE"] = 5] = "INLINE";
|
|
316
|
+
MethodModifier[MethodModifier["GETTER"] = 6] = "GETTER";
|
|
317
|
+
MethodModifier[MethodModifier["SETTER"] = 7] = "SETTER";
|
|
318
|
+
MethodModifier[MethodModifier["THROWS"] = 8] = "THROWS";
|
|
319
|
+
MethodModifier[MethodModifier["FREE"] = 9] = "FREE";
|
|
319
320
|
})(MethodModifier || (MethodModifier = {}));
|
|
320
321
|
export var ClassModifier;
|
|
321
322
|
(function (ClassModifier) {
|
|
@@ -391,11 +392,12 @@ export class NamedMethodSignature extends MethodSignature {
|
|
|
391
392
|
// LANGUAGE WRITER //
|
|
392
393
|
////////////////////////////////////////////////////////////////
|
|
393
394
|
export class LanguageWriter {
|
|
394
|
-
constructor(printer, resolver, // TODO make protected again
|
|
395
|
+
constructor(printer, resolver, // TODO make protected again (or better rework LWs)
|
|
395
396
|
language) {
|
|
396
397
|
this.printer = printer;
|
|
397
398
|
this.resolver = resolver;
|
|
398
399
|
this.language = language;
|
|
400
|
+
this.namespaceStack = [];
|
|
399
401
|
}
|
|
400
402
|
indentDepth() {
|
|
401
403
|
return this.printer.indentDepth();
|
|
@@ -731,6 +733,7 @@ export class LanguageWriter {
|
|
|
731
733
|
* Writes closing brace of namespace block and removes one level of indent
|
|
732
734
|
*/
|
|
733
735
|
popNamespace(ident = true) {
|
|
736
|
+
this.namespaceStack.pop();
|
|
734
737
|
if (ident)
|
|
735
738
|
this.popIndent();
|
|
736
739
|
this.print(`}`);
|
|
@@ -106,7 +106,8 @@ export class CJTypeNameConvertor {
|
|
|
106
106
|
case idl.IDLF64Type: return 'Float64';
|
|
107
107
|
case idl.IDLPointerType: return 'UInt64';
|
|
108
108
|
case idl.IDLVoidType: return 'Unit';
|
|
109
|
-
case idl.IDLBufferType:
|
|
109
|
+
case idl.IDLBufferType:
|
|
110
|
+
case idl.IDLInteropReturnBufferType: return 'Array<UInt8>';
|
|
110
111
|
}
|
|
111
112
|
throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
112
113
|
}
|
|
@@ -239,8 +239,6 @@ export class CppReturnTypeConvertor {
|
|
|
239
239
|
convertPrimitiveType(type) {
|
|
240
240
|
if (type == idl.IDLUndefinedType)
|
|
241
241
|
return 'void';
|
|
242
|
-
if (type == idl.IDLNumberType)
|
|
243
|
-
return generatorConfiguration().TypePrefix + 'Int32'; // :(
|
|
244
242
|
return this.convertor.convert(type);
|
|
245
243
|
}
|
|
246
244
|
convertTypeParameter(type) {
|
|
@@ -2,7 +2,6 @@ import * as idl from "../../idl";
|
|
|
2
2
|
import { TSTypeNameConvertor } from "./TSConvertors";
|
|
3
3
|
export declare class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
4
4
|
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
5
|
-
convertEnum(node: idl.IDLEnum): string;
|
|
6
5
|
convertContainer(type: idl.IDLContainerType): string;
|
|
7
6
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
8
7
|
protected productType(decl: idl.IDLInterface, isTuple: boolean, includeFieldNames: boolean): string;
|
|
@@ -40,13 +40,6 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
40
40
|
}
|
|
41
41
|
return typeName;
|
|
42
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
43
|
convertContainer(type) {
|
|
51
44
|
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
52
45
|
switch (type.elementType[0]) {
|
|
@@ -84,6 +77,7 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
84
77
|
case idl.IDLStringType: return 'string';
|
|
85
78
|
case idl.IDLFunctionType: return 'Object';
|
|
86
79
|
case idl.IDLBufferType: return 'NativeBuffer';
|
|
80
|
+
case idl.IDLBigintType: return 'long';
|
|
87
81
|
}
|
|
88
82
|
return super.convertPrimitiveType(type);
|
|
89
83
|
}
|
|
@@ -35,13 +35,13 @@ export class InteropReturnTypeConvertor {
|
|
|
35
35
|
// TODO return array by some way
|
|
36
36
|
return "void";
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return KInteropReturnBuffer;
|
|
39
39
|
}
|
|
40
40
|
convertImport(type, importClause) {
|
|
41
41
|
throw new Error(`Cannot pass import type ${type.name} through interop`);
|
|
42
42
|
}
|
|
43
43
|
convertOptional(type) {
|
|
44
|
-
return
|
|
44
|
+
return KInteropReturnBuffer;
|
|
45
45
|
}
|
|
46
46
|
convertPrimitiveType(type) {
|
|
47
47
|
switch (type) {
|
|
@@ -55,8 +55,8 @@ export class InteropReturnTypeConvertor {
|
|
|
55
55
|
case idl.IDLU64Type:
|
|
56
56
|
case idl.IDLF16Type:
|
|
57
57
|
case idl.IDLF32Type:
|
|
58
|
-
case idl.IDLF64Type:
|
|
59
|
-
case idl.IDLNumberType: return PrimitiveTypesInstance.
|
|
58
|
+
case idl.IDLF64Type: return PrimitiveTypesInstance.Int32.getText();
|
|
59
|
+
case idl.IDLNumberType: return PrimitiveTypesInstance.Number.getText();
|
|
60
60
|
case idl.IDLBooleanType: return PrimitiveTypesInstance.Boolean.getText();
|
|
61
61
|
case idl.IDLBigintType: return PrimitiveTypesInstance.Int64.getText();
|
|
62
62
|
case idl.IDLAnyType:
|
|
@@ -64,8 +64,8 @@ export class InteropReturnTypeConvertor {
|
|
|
64
64
|
case idl.IDLThisType:
|
|
65
65
|
case idl.IDLUndefinedType:
|
|
66
66
|
case idl.IDLUnknownType:
|
|
67
|
-
case idl.IDLStringType:
|
|
68
67
|
case idl.IDLVoidType: return idl.IDLVoidType.name;
|
|
68
|
+
case idl.IDLStringType: return PrimitiveTypesInstance.String.getText();
|
|
69
69
|
case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
70
70
|
}
|
|
71
71
|
throw new Error(`Cannot pass primitive type ${type.name} through interop`);
|
|
@@ -110,10 +110,12 @@ export class InteropArgConvertor {
|
|
|
110
110
|
}
|
|
111
111
|
convertPrimitiveType(type) {
|
|
112
112
|
switch (type) {
|
|
113
|
+
case idl.IDLI64Type: return "KLong";
|
|
114
|
+
case idl.IDLU64Type: return "KLong";
|
|
113
115
|
case idl.IDLI32Type: return "KInt";
|
|
114
116
|
case idl.IDLF32Type: return "KFloat";
|
|
115
|
-
case idl.IDLNumberType: return 'number';
|
|
116
|
-
case idl.IDLBigintType: return 'bigint';
|
|
117
|
+
case idl.IDLNumberType: return 'number'; // should be removed! It is KInteropNumber or smth
|
|
118
|
+
case idl.IDLBigintType: return 'bigint'; // should be removed! It is KLong or smth
|
|
117
119
|
case idl.IDLBooleanType:
|
|
118
120
|
case idl.IDLFunctionType: return 'KInt';
|
|
119
121
|
case idl.IDLStringType: return 'KStringPtr';
|
|
@@ -122,7 +124,7 @@ export class InteropArgConvertor {
|
|
|
122
124
|
case idl.IDLDate: return 'KLong';
|
|
123
125
|
case idl.IDLUndefinedType:
|
|
124
126
|
case idl.IDLVoidType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
125
|
-
case idl.IDLPointerType: return
|
|
127
|
+
case idl.IDLPointerType: return 'KPointer'; // return PrimitiveTypesInstance.NativePointer.getText()
|
|
126
128
|
}
|
|
127
129
|
throw new Error(`Cannot pass primitive type ${type.name} through interop`);
|
|
128
130
|
}
|
|
@@ -25,10 +25,10 @@ export class TSTypeNameConvertor {
|
|
|
25
25
|
return node.name;
|
|
26
26
|
}
|
|
27
27
|
convertInterface(node) {
|
|
28
|
-
return node
|
|
28
|
+
return idl.getFQName(node);
|
|
29
29
|
}
|
|
30
30
|
convertEnum(node) {
|
|
31
|
-
return node
|
|
31
|
+
return idl.getFQName(node);
|
|
32
32
|
}
|
|
33
33
|
convertTypedef(node) {
|
|
34
34
|
return node.name;
|
|
@@ -90,6 +90,7 @@ export declare class CJLanguageWriter extends LanguageWriter {
|
|
|
90
90
|
writeMethodDeclaration(name: string, signature: MethodSignature, modifiers?: MethodModifier[]): void;
|
|
91
91
|
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
92
92
|
writeProperty(propName: string, propType: idl.IDLType, mutable?: boolean, getterLambda?: (writer: this) => void, setterLambda?: (writer: this) => void): void;
|
|
93
|
+
writeTypeDeclaration(decl: idl.IDLTypedef): void;
|
|
93
94
|
writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
94
95
|
writeCJForeign(op: (writer: CJLanguageWriter) => void): void;
|
|
95
96
|
private writeDeclaration;
|
|
@@ -373,6 +373,9 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
373
373
|
this.popIndent();
|
|
374
374
|
this.print(`}`);
|
|
375
375
|
}
|
|
376
|
+
writeTypeDeclaration(decl) {
|
|
377
|
+
throw new Error(`writeTypeDeclaration not implemented`);
|
|
378
|
+
}
|
|
376
379
|
writeMethodImplementation(method, op) {
|
|
377
380
|
this.writeDeclaration(method.name, method.signature, method.modifiers, " {");
|
|
378
381
|
this.pushIndent();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDLContainerType, IDLEnum, IDLNode, IDLType } from '../../idl';
|
|
1
|
+
import { IDLContainerType, IDLEnum, IDLNode, IDLType, IDLTypedef } from '../../idl';
|
|
2
2
|
import { ArgConvertor, BaseArgConvertor } from "../ArgConvertors";
|
|
3
3
|
import { PrimitiveTypeList } from "../../peer-generation/PrimitiveType";
|
|
4
4
|
import { AssignStatement, FieldModifier, LanguageExpression, LanguageStatement, LanguageWriter, MakeAssignOptions, MakeCastOptions, MakeRefOptions, Method, PrintHint, MethodModifier, MethodSignature, NamedMethodSignature, ObjectArgs } from "../LanguageWriter";
|
|
@@ -46,6 +46,7 @@ export declare class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
46
46
|
writeFieldDeclaration(name: string, type: IDLType, modifiers: FieldModifier[] | undefined, optional: boolean, initExpr?: LanguageExpression): void;
|
|
47
47
|
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
48
48
|
writeProperty(propName: string, propType: IDLType, mutable?: boolean): void;
|
|
49
|
+
writeTypeDeclaration(decl: IDLTypedef): void;
|
|
49
50
|
/**
|
|
50
51
|
* Writes multiline comments decorated with stars
|
|
51
52
|
*/
|
|
@@ -220,6 +220,9 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
220
220
|
writeProperty(propName, propType, mutable = true) {
|
|
221
221
|
throw new Error("writeProperty for c++ is not implemented yet.");
|
|
222
222
|
}
|
|
223
|
+
writeTypeDeclaration(decl) {
|
|
224
|
+
throw new Error(`writeTypeDeclaration not implemented`);
|
|
225
|
+
}
|
|
223
226
|
/**
|
|
224
227
|
* Writes multiline comments decorated with stars
|
|
225
228
|
*/
|
|
@@ -54,7 +54,13 @@ class ArkTSMapForEachStatement {
|
|
|
54
54
|
this.op = op;
|
|
55
55
|
}
|
|
56
56
|
write(writer) {
|
|
57
|
-
writer.print(
|
|
57
|
+
writer.print(`for (const pair of ${this.map}) {`);
|
|
58
|
+
writer.pushIndent();
|
|
59
|
+
writer.print(`const ${this.key} = pair[0]`);
|
|
60
|
+
writer.print(`const ${this.value} = pair[1]`);
|
|
61
|
+
this.op();
|
|
62
|
+
writer.popIndent();
|
|
63
|
+
writer.print(`}`);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
export class ArkTSEnumEntityStatement {
|
|
@@ -63,7 +69,8 @@ export class ArkTSEnumEntityStatement {
|
|
|
63
69
|
this.isExport = isExport;
|
|
64
70
|
}
|
|
65
71
|
write(writer) {
|
|
66
|
-
|
|
72
|
+
let enumName = convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), this.enumEntity);
|
|
73
|
+
enumName = enumName.split('.').at(-1);
|
|
67
74
|
const members = this.enumEntity.elements
|
|
68
75
|
.flatMap((member, index) => {
|
|
69
76
|
var _a;
|
|
@@ -93,7 +100,10 @@ export class ArkTSEnumEntityStatement {
|
|
|
93
100
|
}
|
|
94
101
|
return res;
|
|
95
102
|
});
|
|
103
|
+
const nss = idl.getNamespacesPathFor(this.enumEntity);
|
|
104
|
+
nss.forEach(it => writer.pushNamespace(it.name));
|
|
96
105
|
writer.writeEnum(enumName, members);
|
|
106
|
+
nss.forEach(() => writer.popNamespace());
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
109
|
export class ETSLambdaExpression extends LambdaExpression {
|
|
@@ -41,6 +41,7 @@ export declare class JavaLanguageWriter extends CLikeLanguageWriter {
|
|
|
41
41
|
writeNativeMethodDeclaration(name: string, signature: MethodSignature): void;
|
|
42
42
|
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
43
43
|
writeProperty(propName: string, propType: idl.IDLType): void;
|
|
44
|
+
writeTypeDeclaration(decl: idl.IDLTypedef): void;
|
|
44
45
|
makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean): LanguageStatement;
|
|
45
46
|
makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
|
|
46
47
|
makeReturn(expr: LanguageExpression): LanguageStatement;
|
|
@@ -152,6 +152,9 @@ export class JavaLanguageWriter extends CLikeLanguageWriter {
|
|
|
152
152
|
writeProperty(propName, propType) {
|
|
153
153
|
throw new Error("writeProperty for Java is not implemented yet.");
|
|
154
154
|
}
|
|
155
|
+
writeTypeDeclaration(decl) {
|
|
156
|
+
throw new Error(`Type declarations do not exist in Java, use something else`);
|
|
157
|
+
}
|
|
155
158
|
makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
|
|
156
159
|
return new JavaAssignStatement(variableName, type, expr, isDeclared, isConst);
|
|
157
160
|
}
|
|
@@ -54,6 +54,7 @@ export declare class TSLanguageWriter extends LanguageWriter {
|
|
|
54
54
|
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
55
55
|
writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
56
56
|
writeProperty(propName: string, propType: idl.IDLType): void;
|
|
57
|
+
writeTypeDeclaration(decl: idl.IDLTypedef): void;
|
|
57
58
|
private writeDeclaration;
|
|
58
59
|
makeNull(): LanguageExpression;
|
|
59
60
|
makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared?: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
|
|
@@ -124,6 +124,7 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
124
124
|
}
|
|
125
125
|
maybeSemicolon() { return ""; }
|
|
126
126
|
pushNamespace(namespace, ident = true) {
|
|
127
|
+
this.namespaceStack.push(namespace);
|
|
127
128
|
this.print(`export namespace ${namespace} {`);
|
|
128
129
|
if (ident)
|
|
129
130
|
this.pushIndent();
|
|
@@ -133,7 +134,14 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
133
134
|
return new TSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
|
|
134
135
|
}
|
|
135
136
|
getNodeName(type) {
|
|
136
|
-
|
|
137
|
+
// just stub.
|
|
138
|
+
// language writers and name convertors are subject to rework for namespaces
|
|
139
|
+
const row = this.typeConvertor.convert(type);
|
|
140
|
+
const nsPrefix = this.namespaceStack.join('.') + '.';
|
|
141
|
+
if (row.startsWith(nsPrefix)) {
|
|
142
|
+
return row.substring(nsPrefix.length);
|
|
143
|
+
}
|
|
144
|
+
return row;
|
|
137
145
|
}
|
|
138
146
|
writeClass(name, op, superClass, interfaces, generics, isDeclared, isAbstract) {
|
|
139
147
|
let extendsClause = superClass ? ` extends ${superClass}` : '';
|
|
@@ -226,16 +234,22 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
226
234
|
writeProperty(propName, propType) {
|
|
227
235
|
throw new Error("writeProperty for TS is not implemented yet.");
|
|
228
236
|
}
|
|
237
|
+
writeTypeDeclaration(decl) {
|
|
238
|
+
var _a;
|
|
239
|
+
const type = this.getNodeName(decl.type);
|
|
240
|
+
const typeParams = ((_a = decl.typeParameters) === null || _a === void 0 ? void 0 : _a.length) ? `<${decl.typeParameters.join(",").replace("[]", "")}>` : "";
|
|
241
|
+
this.print(`export type ${decl.name}${typeParams} = ${type};`);
|
|
242
|
+
}
|
|
229
243
|
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
230
244
|
var _a;
|
|
231
245
|
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
232
246
|
.filter(it => modifiers.includes(it))
|
|
233
247
|
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
234
248
|
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER)) {
|
|
235
|
-
prefix =
|
|
249
|
+
prefix = `${prefix} get`;
|
|
236
250
|
}
|
|
237
251
|
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) {
|
|
238
|
-
prefix =
|
|
252
|
+
prefix = `${prefix} set`;
|
|
239
253
|
needReturn = false;
|
|
240
254
|
}
|
|
241
255
|
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.FREE)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stringOrNone } from "../util";
|
|
2
|
-
import { IDLCallback, IDLConstructor, IDLEntry, IDLEnum, IDLInterface, IDLMethod, IDLParameter, IDLProperty, IDLTypedef, IDLNamespace,
|
|
2
|
+
import { IDLCallback, IDLConstructor, IDLEntry, IDLEnum, IDLInterface, IDLMethod, IDLParameter, IDLProperty, IDLTypedef, IDLNamespace, IDLFile, IDLImport, IDLReferenceType, IDLCallable, IDLConstant, SignatureTag, IDLVersion } from "../idl";
|
|
3
3
|
import { Language } from "../Language";
|
|
4
4
|
export declare class CustomPrintVisitor {
|
|
5
5
|
private resolver;
|
|
@@ -11,7 +11,7 @@ export declare class CustomPrintVisitor {
|
|
|
11
11
|
printMetadata(node: IDLEnum): void;
|
|
12
12
|
printConstant(node: IDLConstant): void;
|
|
13
13
|
printInterface(node: IDLInterface): void;
|
|
14
|
-
printMethod(node: IDLMethod | IDLConstructor | IDLCallable,
|
|
14
|
+
printMethod(node: IDLMethod | IDLConstructor | IDLCallable, forceAsFree?: boolean): void;
|
|
15
15
|
paramText(paramOrTag: IDLParameter | SignatureTag): string;
|
|
16
16
|
printProperty(node: IDLProperty): void;
|
|
17
17
|
printEnum(node: IDLEnum): void;
|
|
@@ -19,7 +19,7 @@ export declare class CustomPrintVisitor {
|
|
|
19
19
|
printVersion(node: IDLVersion): void;
|
|
20
20
|
printNamespace(node: IDLNamespace): void;
|
|
21
21
|
printImport(node: IDLImport): void;
|
|
22
|
-
printPackage(node:
|
|
22
|
+
printPackage(node: IDLFile): void;
|
|
23
23
|
checkVerbatim(node: IDLEntry): void;
|
|
24
24
|
private indent;
|
|
25
25
|
indented(input: string): string;
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { indentedBy, isInNamespace } from "../util";
|
|
16
|
-
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType,
|
|
17
|
-
import
|
|
18
|
-
import { resolveSyntheticType, toIDLNode } from "./deserialize";
|
|
16
|
+
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType } from "../idl";
|
|
17
|
+
import { resolveSyntheticType, toIDLFile } from "./deserialize";
|
|
19
18
|
import { Language } from "../Language";
|
|
19
|
+
import { warn } from "../util";
|
|
20
20
|
export class CustomPrintVisitor {
|
|
21
21
|
constructor(resolver, language) {
|
|
22
22
|
this.resolver = resolver;
|
|
@@ -39,9 +39,6 @@ export class CustomPrintVisitor {
|
|
|
39
39
|
else if (isMethod(node) || isConstructor(node) || isCallable(node)) {
|
|
40
40
|
this.printMethod(node);
|
|
41
41
|
}
|
|
42
|
-
else if (isPackage(node)) {
|
|
43
|
-
this.printPackage(node);
|
|
44
|
-
}
|
|
45
42
|
else if (isImport(node)) {
|
|
46
43
|
this.printImport(node);
|
|
47
44
|
}
|
|
@@ -102,12 +99,6 @@ export class CustomPrintVisitor {
|
|
|
102
99
|
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, true)}`);
|
|
103
100
|
}
|
|
104
101
|
else {
|
|
105
|
-
// restore globalScope
|
|
106
|
-
if (hasExtAttribute(node, IDLExtendedAttributes.GlobalScope)) {
|
|
107
|
-
node.methods.map(it => this.printMethod(it, true));
|
|
108
|
-
node.constants.map(it => this.printConstant(it));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
102
|
let interfaces = node.inheritance;
|
|
112
103
|
let keyword = "extends";
|
|
113
104
|
if (node.subkind === IDLInterfaceSubkind.Class) {
|
|
@@ -123,8 +114,8 @@ export class CustomPrintVisitor {
|
|
|
123
114
|
this.currentInterface = node;
|
|
124
115
|
this.pushIndent();
|
|
125
116
|
node.constructors.map(it => this.visit(it));
|
|
126
|
-
node.properties.map(it => this.visit(it));
|
|
127
|
-
node.methods.map(it => this.visit(it));
|
|
117
|
+
node.properties.filter(it => !it.isStatic).map(it => this.visit(it));
|
|
118
|
+
node.methods.filter(it => !it.isStatic).map(it => this.visit(it));
|
|
128
119
|
node.callables.map(it => this.visit(it));
|
|
129
120
|
let verbatim = getVerbatimDts(node);
|
|
130
121
|
if (verbatim) {
|
|
@@ -136,8 +127,7 @@ export class CustomPrintVisitor {
|
|
|
136
127
|
this.print("}");
|
|
137
128
|
}
|
|
138
129
|
}
|
|
139
|
-
|
|
140
|
-
printMethod(node, isGlobal = false) {
|
|
130
|
+
printMethod(node, forceAsFree = false) {
|
|
141
131
|
const returnType = node.returnType && !(isConstructor(node) && this.currentInterface.subkind === IDLInterfaceSubkind.Class)
|
|
142
132
|
? `: ${this.printTypeForTS(node.returnType, true)}` : "";
|
|
143
133
|
const name = isConstructor(node)
|
|
@@ -146,12 +136,14 @@ export class CustomPrintVisitor {
|
|
|
146
136
|
const typeParams = (node.typeParameters && node.typeParameters.length > 0) ? `<${node.typeParameters.join(",")}>` : "";
|
|
147
137
|
let preamble = "";
|
|
148
138
|
if (!isCallable(node)) {
|
|
149
|
-
|
|
139
|
+
let isStatic = isMethod(node) && node.isStatic;
|
|
150
140
|
const isProtected = hasExtAttribute(node, IDLExtendedAttributes.Protected);
|
|
151
141
|
const isOptional = isMethod(node) && node.isOptional;
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
|
|
142
|
+
let isFree = isMethod(node) && node.isFree;
|
|
143
|
+
if (forceAsFree) {
|
|
144
|
+
isStatic = false;
|
|
145
|
+
isFree = true;
|
|
146
|
+
}
|
|
155
147
|
const inNamespace = getNamespacesPathFor(node).length > 0;
|
|
156
148
|
preamble = `${isFree ? `${isInNamespace(node) ? "" : "declare "}function ` : ""}${isProtected ? "protected " : ""}${isStatic ? "static " : ""}${name}${isOptional ? "?" : ""}`;
|
|
157
149
|
}
|
|
@@ -209,7 +201,8 @@ export class CustomPrintVisitor {
|
|
|
209
201
|
let definition = this.resolver(createReferenceType(node));
|
|
210
202
|
// TODO: handle namespace case better!
|
|
211
203
|
// TODO: namespace-related-to-rework
|
|
212
|
-
throw new Error("not implemented yet")
|
|
204
|
+
//throw new Error("not implemented yet")
|
|
205
|
+
warn("Typedef-with-Import is not implemented yet");
|
|
213
206
|
// if (definition && !isTypedef(definition) && !hasExtAttribute(definition, IDLExtendedAttributes.Namespace)) {
|
|
214
207
|
// console.log(`Has better definition for ${node.name}: ${definition.fileName} ${definition.kind}`)
|
|
215
208
|
// return
|
|
@@ -241,7 +234,7 @@ export class CustomPrintVisitor {
|
|
|
241
234
|
this.print(`// import ${node.clause.join(".")}${node.name ? " as " : ""}${node.name || ""}`);
|
|
242
235
|
}
|
|
243
236
|
printPackage(node) {
|
|
244
|
-
this.print(`// package ${node.
|
|
237
|
+
this.print(`// package ${node.packageClause.join(".")}`);
|
|
245
238
|
}
|
|
246
239
|
checkVerbatim(node) {
|
|
247
240
|
let verbatim = getExtAttribute(node, IDLExtendedAttributes.VerbatimDts);
|
|
@@ -350,10 +343,9 @@ export class CustomPrintVisitor {
|
|
|
350
343
|
}
|
|
351
344
|
export function idlToDtsString(name, content) {
|
|
352
345
|
let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.forEach(it => {
|
|
346
|
+
const idlFile = toIDLFile(name, content);
|
|
347
|
+
printer.printPackage(idlFile);
|
|
348
|
+
idlFile.entries.forEach(it => {
|
|
357
349
|
transformMethodsAsync2ReturnPromise(it);
|
|
358
350
|
printer.visit(it);
|
|
359
351
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDLFile } from "../idl";
|
|
2
2
|
export declare function fromIDL(inputDirs: string | string[], inputFiles: string | string[] | undefined, outputDir: string, extension: string, verbose: boolean, transform: (name: string, content: string) => string): void;
|
|
3
|
-
export declare function scanIDL(inputDir: string, inputFile: string | undefined):
|
|
3
|
+
export declare function scanIDL(inputDir: string, inputFile: string | undefined): IDLFile[];
|
|
4
4
|
export declare const licence = "/*\n * Copyright (c) 2024 Huawei Device Co., Ltd.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n";
|
|
5
5
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as fs from "fs";
|
|
16
16
|
import * as path from "path";
|
|
17
|
-
import
|
|
18
|
-
import { toIDLNode } from "./deserialize";
|
|
17
|
+
import { toIDLFile } from "./deserialize";
|
|
19
18
|
import { zip } from "../util";
|
|
20
19
|
function getFilesRecursive(dirPath, arrayOfFiles = []) {
|
|
21
20
|
let files = fs.readdirSync(dirPath);
|
|
@@ -66,12 +65,7 @@ export function scanIDL(inputDir, inputFile) {
|
|
|
66
65
|
? [path.join(inputDir, inputFile)]
|
|
67
66
|
: fs.readdirSync(inputDir)
|
|
68
67
|
.map((elem) => path.join(inputDir, elem));
|
|
69
|
-
return files
|
|
70
|
-
.map((file) => {
|
|
71
|
-
let content = fs.readFileSync(file).toString();
|
|
72
|
-
let parsed = webidl2.parse(content);
|
|
73
|
-
return parsed.filter(it => !!it.type).map(it => toIDLNode(file, it));
|
|
74
|
-
});
|
|
68
|
+
return files.map(it => toIDLFile(it));
|
|
75
69
|
}
|
|
76
70
|
export const licence = `/*
|
|
77
71
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as webidl2 from "webidl2";
|
|
2
1
|
import * as idl from "../idl";
|
|
3
2
|
export declare function addSyntheticType(name: string, type: idl.IDLEntry): void;
|
|
4
3
|
export declare function resolveSyntheticType(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function toIDL(file: string): idl.IDLEntry[];
|
|
7
|
-
export declare function toIDLFile(fileName: string): idl.IDLFile;
|
|
4
|
+
export declare function toIDLFile(fileName: string, content?: string): idl.IDLFile;
|
|
8
5
|
//# sourceMappingURL=deserialize.d.ts.map
|