@idlizer/core 2.0.33 → 2.0.36
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 +11 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +3 -1
- package/build/lib/src/LanguageWriters/LanguageWriter.js +1 -1
- 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.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +7 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +3 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +6 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +7 -1
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +6 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +11 -2
- package/build/lib/src/from-idl/DtsPrinter.d.ts +2 -2
- package/build/lib/src/from-idl/DtsPrinter.js +8 -19
- 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 +25 -33
- package/build/lib/src/idl.js +37 -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 +4 -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/isMaterialized.d.ts +1 -0
- package/build/lib/src/peer-generation/isMaterialized.js +8 -0
- package/package.json +2 -2
- package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +0 -36
- package/build/lib/src/LanguageWriters/InteropConvertor.js +0 -174
- package/build/lib/src/configMerge.d.ts +0 -2
- package/build/lib/src/configMerge.js +0 -42
- package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +0 -2
- package/build/lib/src/peer-generation/LanguageWriters/index.js +0 -2
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +0 -25
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +0 -55
|
@@ -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<${generatorTypePrefix()}${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;
|
|
@@ -216,7 +216,7 @@ export declare abstract class LanguageWriter {
|
|
|
216
216
|
resolver: ReferenceResolver;
|
|
217
217
|
language: Language;
|
|
218
218
|
protected namespaceStack: string[];
|
|
219
|
-
constructor(printer: IndentedPrinter, resolver: ReferenceResolver, // TODO make protected again
|
|
219
|
+
constructor(printer: IndentedPrinter, resolver: ReferenceResolver, // TODO make protected again (or better rework LWs)
|
|
220
220
|
language: Language);
|
|
221
221
|
indentDepth(): number;
|
|
222
222
|
maybeSemicolon(): string;
|
|
@@ -235,6 +235,8 @@ export declare abstract class LanguageWriter {
|
|
|
235
235
|
abstract writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, superCall?: Method, modifiers?: MethodModifier[]): void;
|
|
236
236
|
abstract writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
237
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;
|
|
239
|
+
abstract writeConstant(constName: string, constType: idl.IDLType, constVal?: string): void;
|
|
238
240
|
abstract makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
|
|
239
241
|
abstract makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
|
|
240
242
|
abstract makeThrowError(message: string): LanguageStatement;
|
|
@@ -392,7 +392,7 @@ export class NamedMethodSignature extends MethodSignature {
|
|
|
392
392
|
// LANGUAGE WRITER //
|
|
393
393
|
////////////////////////////////////////////////////////////////
|
|
394
394
|
export class LanguageWriter {
|
|
395
|
-
constructor(printer, resolver, // TODO make protected again
|
|
395
|
+
constructor(printer, resolver, // TODO make protected again (or better rework LWs)
|
|
396
396
|
language) {
|
|
397
397
|
this.printer = printer;
|
|
398
398
|
this.resolver = resolver;
|
|
@@ -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) {
|
|
@@ -77,6 +77,7 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
77
77
|
case idl.IDLStringType: return 'string';
|
|
78
78
|
case idl.IDLFunctionType: return 'Object';
|
|
79
79
|
case idl.IDLBufferType: return 'NativeBuffer';
|
|
80
|
+
case idl.IDLBigintType: return 'long';
|
|
80
81
|
}
|
|
81
82
|
return super.convertPrimitiveType(type);
|
|
82
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
|
}
|
|
@@ -90,6 +90,8 @@ 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;
|
|
94
|
+
writeConstant(constName: string, constType: idl.IDLType, constVal?: string): void;
|
|
93
95
|
writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
94
96
|
writeCJForeign(op: (writer: CJLanguageWriter) => void): void;
|
|
95
97
|
private writeDeclaration;
|
|
@@ -373,6 +373,13 @@ 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
|
+
}
|
|
379
|
+
writeConstant(constName, constType, constVal) {
|
|
380
|
+
const namespacePrefix = this.namespaceStack.join('_');
|
|
381
|
+
this.print(`const ${namespacePrefix}${constName}: ${this.getNodeName(constType)} = ${constVal !== null && constVal !== void 0 ? constVal : ''}`);
|
|
382
|
+
}
|
|
376
383
|
writeMethodImplementation(method, op) {
|
|
377
384
|
this.writeDeclaration(method.name, method.signature, method.modifiers, " {");
|
|
378
385
|
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,8 @@ 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;
|
|
50
|
+
writeConstant(constName: string, constType: IDLType, constVal?: string): void;
|
|
49
51
|
/**
|
|
50
52
|
* Writes multiline comments decorated with stars
|
|
51
53
|
*/
|
|
@@ -220,6 +220,12 @@ 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
|
+
}
|
|
226
|
+
writeConstant(constName, constType, constVal) {
|
|
227
|
+
this.print(`${this.getNodeName(constType)} ${constName}${constVal ? ' = ' + constVal : ''};`);
|
|
228
|
+
}
|
|
223
229
|
/**
|
|
224
230
|
* Writes multiline comments decorated with stars
|
|
225
231
|
*/
|
|
@@ -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 {
|
|
@@ -41,6 +41,8 @@ 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;
|
|
45
|
+
writeConstant(constName: string, constType: idl.IDLType, constVal?: string): void;
|
|
44
46
|
makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean): LanguageStatement;
|
|
45
47
|
makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
|
|
46
48
|
makeReturn(expr: LanguageExpression): LanguageStatement;
|
|
@@ -152,6 +152,12 @@ 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
|
+
}
|
|
158
|
+
writeConstant(constName, constType, constVal) {
|
|
159
|
+
throw new Error("writeConstant for Java is not implemented yet.");
|
|
160
|
+
}
|
|
155
161
|
makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
|
|
156
162
|
return new JavaAssignStatement(variableName, type, expr, isDeclared, isConst);
|
|
157
163
|
}
|
|
@@ -54,6 +54,8 @@ 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;
|
|
58
|
+
writeConstant(constName: string, constType: idl.IDLType, constVal?: string): void;
|
|
57
59
|
private writeDeclaration;
|
|
58
60
|
makeNull(): LanguageExpression;
|
|
59
61
|
makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared?: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
|
|
@@ -234,16 +234,25 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
234
234
|
writeProperty(propName, propType) {
|
|
235
235
|
throw new Error("writeProperty for TS is not implemented yet.");
|
|
236
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
|
+
}
|
|
243
|
+
writeConstant(constName, constType, constVal) {
|
|
244
|
+
this.print(`export const ${constName}: ${this.getNodeName(constType)}${constVal ? ' = ' + constVal : ''}`);
|
|
245
|
+
}
|
|
237
246
|
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
238
247
|
var _a;
|
|
239
248
|
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
240
249
|
.filter(it => modifiers.includes(it))
|
|
241
250
|
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
242
251
|
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER)) {
|
|
243
|
-
prefix =
|
|
252
|
+
prefix = `${prefix} get`;
|
|
244
253
|
}
|
|
245
254
|
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) {
|
|
246
|
-
prefix =
|
|
255
|
+
prefix = `${prefix} set`;
|
|
247
256
|
needReturn = false;
|
|
248
257
|
}
|
|
249
258
|
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;
|
|
@@ -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,9 +13,8 @@
|
|
|
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";
|
|
20
19
|
import { warn } from "../util";
|
|
21
20
|
export class CustomPrintVisitor {
|
|
@@ -40,9 +39,6 @@ export class CustomPrintVisitor {
|
|
|
40
39
|
else if (isMethod(node) || isConstructor(node) || isCallable(node)) {
|
|
41
40
|
this.printMethod(node);
|
|
42
41
|
}
|
|
43
|
-
else if (isPackage(node)) {
|
|
44
|
-
this.printPackage(node);
|
|
45
|
-
}
|
|
46
42
|
else if (isImport(node)) {
|
|
47
43
|
this.printImport(node);
|
|
48
44
|
}
|
|
@@ -103,12 +99,6 @@ export class CustomPrintVisitor {
|
|
|
103
99
|
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, true)}`);
|
|
104
100
|
}
|
|
105
101
|
else {
|
|
106
|
-
// restore globalScope
|
|
107
|
-
if (hasExtAttribute(node, IDLExtendedAttributes.GlobalScope)) {
|
|
108
|
-
node.methods.map(it => this.printMethod(it, true));
|
|
109
|
-
node.constants.map(it => this.printConstant(it));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
102
|
let interfaces = node.inheritance;
|
|
113
103
|
let keyword = "extends";
|
|
114
104
|
if (node.subkind === IDLInterfaceSubkind.Class) {
|
|
@@ -124,8 +114,8 @@ export class CustomPrintVisitor {
|
|
|
124
114
|
this.currentInterface = node;
|
|
125
115
|
this.pushIndent();
|
|
126
116
|
node.constructors.map(it => this.visit(it));
|
|
127
|
-
node.properties.map(it => this.visit(it));
|
|
128
|
-
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));
|
|
129
119
|
node.callables.map(it => this.visit(it));
|
|
130
120
|
let verbatim = getVerbatimDts(node);
|
|
131
121
|
if (verbatim) {
|
|
@@ -244,7 +234,7 @@ export class CustomPrintVisitor {
|
|
|
244
234
|
this.print(`// import ${node.clause.join(".")}${node.name ? " as " : ""}${node.name || ""}`);
|
|
245
235
|
}
|
|
246
236
|
printPackage(node) {
|
|
247
|
-
this.print(`// package ${node.
|
|
237
|
+
this.print(`// package ${node.packageClause.join(".")}`);
|
|
248
238
|
}
|
|
249
239
|
checkVerbatim(node) {
|
|
250
240
|
let verbatim = getExtAttribute(node, IDLExtendedAttributes.VerbatimDts);
|
|
@@ -353,10 +343,9 @@ export class CustomPrintVisitor {
|
|
|
353
343
|
}
|
|
354
344
|
export function idlToDtsString(name, content) {
|
|
355
345
|
let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
.forEach(it => {
|
|
346
|
+
const idlFile = toIDLFile(name, content);
|
|
347
|
+
printer.printPackage(idlFile);
|
|
348
|
+
idlFile.entries.forEach(it => {
|
|
360
349
|
transformMethodsAsync2ReturnPromise(it);
|
|
361
350
|
printer.visit(it);
|
|
362
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
|
|
@@ -28,16 +28,13 @@ export function addSyntheticType(name, type) {
|
|
|
28
28
|
export function resolveSyntheticType(type) {
|
|
29
29
|
return syntheticTypes.get(type.name);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
function toIDLNode(file, node) {
|
|
32
32
|
return toIDLNodeForward(file, node);
|
|
33
33
|
}
|
|
34
34
|
function toIDLNodeForward(file, node) {
|
|
35
35
|
if (isEnum(node)) {
|
|
36
36
|
return toIDLEnum(file, node);
|
|
37
37
|
}
|
|
38
|
-
if (isPackage(node)) {
|
|
39
|
-
return toIDLPackage(node);
|
|
40
|
-
}
|
|
41
38
|
if (isImport(node)) {
|
|
42
39
|
return toIDLImport(node);
|
|
43
40
|
}
|
|
@@ -85,13 +82,6 @@ function isImport(node) {
|
|
|
85
82
|
function isCallable(node) {
|
|
86
83
|
return node.extAttrs.some(it => it.name == "Invoke");
|
|
87
84
|
}
|
|
88
|
-
function toIDLPackage(node) {
|
|
89
|
-
if (node.clause.startsWith('"')) { // TODO: remove after new schema formation
|
|
90
|
-
//node.clause = node.clause.substring(1, node.clause.length - 1)
|
|
91
|
-
throw new Error("Obsolete IDL-source syntax detected");
|
|
92
|
-
}
|
|
93
|
-
return idl.createPackage(node.clause.split("."));
|
|
94
|
-
}
|
|
95
85
|
function toIDLImport(node) {
|
|
96
86
|
// console.log(node)
|
|
97
87
|
return idl.createImport(node.clause.split("."), node.alias || undefined);
|
|
@@ -369,14 +359,22 @@ function findExtendedAttribute(extAttrs, name) {
|
|
|
369
359
|
const attr = extAttrs.find(it => it.name === name);
|
|
370
360
|
return attr ? toExtendedAttributeValue(attr) : undefined;
|
|
371
361
|
}
|
|
372
|
-
export function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
362
|
+
export function toIDLFile(fileName, content) {
|
|
363
|
+
if (undefined === content)
|
|
364
|
+
content = fs.readFileSync(fileName).toString();
|
|
365
|
+
let packageClause = [];
|
|
366
|
+
const entries = webidl2.parse(content)
|
|
367
|
+
.filter(it => {
|
|
368
|
+
if (!it.type)
|
|
369
|
+
return false;
|
|
370
|
+
if (isPackage(it)) {
|
|
371
|
+
packageClause = it.clause.split(".");
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
})
|
|
376
|
+
.map(it => toIDLNode(fileName, it));
|
|
377
|
+
const file = idl.createFile(entries, fileName, packageClause);
|
|
380
378
|
return idl.linkParentBack(file);
|
|
381
379
|
}
|
|
382
380
|
//# sourceMappingURL=deserialize.js.map
|
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
import { stringOrNone } from "./util";
|
|
2
2
|
export declare enum IDLKind {
|
|
3
3
|
Interface = 0,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
File = 22
|
|
4
|
+
Import = 1,
|
|
5
|
+
Callback = 2,
|
|
6
|
+
Const = 3,
|
|
7
|
+
Property = 4,
|
|
8
|
+
Parameter = 5,
|
|
9
|
+
Method = 6,
|
|
10
|
+
Callable = 7,
|
|
11
|
+
Constructor = 8,
|
|
12
|
+
Enum = 9,
|
|
13
|
+
EnumMember = 10,
|
|
14
|
+
Typedef = 11,
|
|
15
|
+
PrimitiveType = 12,
|
|
16
|
+
ContainerType = 13,
|
|
17
|
+
UnspecifiedGenericType = 14,
|
|
18
|
+
ReferenceType = 15,
|
|
19
|
+
UnionType = 16,
|
|
20
|
+
TypeParameterType = 17,
|
|
21
|
+
OptionalType = 18,
|
|
22
|
+
Version = 19,
|
|
23
|
+
Namespace = 20,
|
|
24
|
+
File = 21
|
|
26
25
|
}
|
|
27
26
|
export declare enum IDLEntity {
|
|
28
27
|
Class = "Class",
|
|
29
28
|
Interface = "Interface",
|
|
30
|
-
Package = "Package",
|
|
31
29
|
Import = "Import",
|
|
32
30
|
Intersection = "Intersection",
|
|
33
31
|
Literal = "Literal",
|
|
@@ -49,7 +47,6 @@ export declare enum IDLExtendedAttributes {
|
|
|
49
47
|
DtsName = "DtsName",
|
|
50
48
|
DtsTag = "DtsTag",
|
|
51
49
|
Entity = "Entity",
|
|
52
|
-
GlobalScope = "GlobalScope",
|
|
53
50
|
Import = "Import",
|
|
54
51
|
IndexSignature = "IndexSignature",
|
|
55
52
|
Interfaces = "Interfaces",
|
|
@@ -83,6 +80,7 @@ export interface IDLNode {
|
|
|
83
80
|
documentation?: string;
|
|
84
81
|
}
|
|
85
82
|
export interface IDLFile extends IDLNode {
|
|
83
|
+
packageClause: string[];
|
|
86
84
|
entries: IDLEntry[];
|
|
87
85
|
fileName?: string;
|
|
88
86
|
}
|
|
@@ -207,10 +205,6 @@ export interface IDLInterface extends IDLEntry {
|
|
|
207
205
|
methods: IDLMethod[];
|
|
208
206
|
callables: IDLCallable[];
|
|
209
207
|
}
|
|
210
|
-
export interface IDLPackage extends IDLEntry {
|
|
211
|
-
kind: IDLKind.Package;
|
|
212
|
-
clause: string[];
|
|
213
|
-
}
|
|
214
208
|
export interface IDLImport extends IDLEntry {
|
|
215
209
|
kind: IDLKind.Import;
|
|
216
210
|
clause: string[];
|
|
@@ -238,7 +232,6 @@ export declare function isEnumMember(type: IDLNode): type is IDLEnumMember;
|
|
|
238
232
|
export declare function isUnionType(type: IDLNode): type is IDLUnionType;
|
|
239
233
|
export declare function isTypeParameterType(type: IDLNode): type is IDLTypeParameterType;
|
|
240
234
|
export declare function isInterface(node: IDLNode): node is IDLInterface;
|
|
241
|
-
export declare function isPackage(type: IDLNode): type is IDLPackage;
|
|
242
235
|
export declare function isImport(type: IDLNode): type is IDLImport;
|
|
243
236
|
export declare function isCallable(node: IDLNode): node is IDLCallable;
|
|
244
237
|
export declare function isMethod(node: IDLNode): node is IDLMethod;
|
|
@@ -317,8 +310,7 @@ export declare function createUnspecifiedGenericType(name: string, typeArguments
|
|
|
317
310
|
export declare function entityToType(entity: IDLNode): IDLType;
|
|
318
311
|
export declare function createContainerType(container: IDLContainerKind, element: IDLType[]): IDLContainerType;
|
|
319
312
|
export declare function createUnionType(types: IDLType[], name?: string): IDLUnionType;
|
|
320
|
-
export declare function createFile(entries: IDLEntry[], fileName?: string): IDLFile;
|
|
321
|
-
export declare function createPackage(clause: string[]): IDLPackage;
|
|
313
|
+
export declare function createFile(entries: IDLEntry[], fileName?: string, packageClause?: string[]): IDLFile;
|
|
322
314
|
export declare function createImport(clause: string[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLImport;
|
|
323
315
|
export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
|
|
324
316
|
export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
|
|
@@ -361,7 +353,7 @@ export declare function printExtendedAttributes(idl: IDLNode, indentLevel: numbe
|
|
|
361
353
|
export declare const attributesToQuote: Set<IDLExtendedAttributes>;
|
|
362
354
|
export declare function printFunction(idl: IDLFunction): PrintedLine[];
|
|
363
355
|
export declare function printMethod(idl: IDLMethod): PrintedLine[];
|
|
364
|
-
export declare function printPackage(idl:
|
|
356
|
+
export declare function printPackage(idl: IDLFile): PrintedLine[];
|
|
365
357
|
export declare function printImport(idl: IDLImport): PrintedLine[];
|
|
366
358
|
export declare function printNamespace(idl: IDLNamespace): PrintedLine[];
|
|
367
359
|
export declare function printCallback(idl: IDLCallback): PrintedLine[];
|
|
@@ -378,7 +370,7 @@ export interface IDLPrintOptions {
|
|
|
378
370
|
disableEnumInitializers: boolean;
|
|
379
371
|
allowUnknownKinds: boolean;
|
|
380
372
|
}
|
|
381
|
-
export declare function toIDLString(
|
|
373
|
+
export declare function toIDLString(file: IDLFile, options: Partial<IDLPrintOptions>): string;
|
|
382
374
|
export declare function verifyIDLString(source: string): true;
|
|
383
375
|
export declare function hasExtAttribute(node: IDLNode, attribute: IDLExtendedAttributes): boolean;
|
|
384
376
|
export declare function getExtAttribute(node: IDLNode, name: IDLExtendedAttributes): stringOrNone;
|