@idlizer/core 2.0.33 → 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 +2 -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 +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 +7 -1
- 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 +8 -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/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
|
@@ -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;
|
|
@@ -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,7 @@ 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;
|
|
238
239
|
abstract makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
|
|
239
240
|
abstract makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
|
|
240
241
|
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,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 {
|
|
@@ -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;
|
|
@@ -234,16 +234,22 @@ 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
|
+
}
|
|
237
243
|
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
238
244
|
var _a;
|
|
239
245
|
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
240
246
|
.filter(it => modifiers.includes(it))
|
|
241
247
|
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
242
248
|
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER)) {
|
|
243
|
-
prefix =
|
|
249
|
+
prefix = `${prefix} get`;
|
|
244
250
|
}
|
|
245
251
|
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) {
|
|
246
|
-
prefix =
|
|
252
|
+
prefix = `${prefix} set`;
|
|
247
253
|
needReturn = false;
|
|
248
254
|
}
|
|
249
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;
|
|
@@ -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;
|
package/build/lib/src/idl.js
CHANGED
|
@@ -19,34 +19,32 @@ import { IDLKeywords } from "./languageSpecificKeywords";
|
|
|
19
19
|
export var IDLKind;
|
|
20
20
|
(function (IDLKind) {
|
|
21
21
|
IDLKind[IDLKind["Interface"] = 0] = "Interface";
|
|
22
|
-
IDLKind[IDLKind["
|
|
23
|
-
IDLKind[IDLKind["
|
|
24
|
-
IDLKind[IDLKind["
|
|
25
|
-
IDLKind[IDLKind["
|
|
26
|
-
IDLKind[IDLKind["
|
|
27
|
-
IDLKind[IDLKind["
|
|
28
|
-
IDLKind[IDLKind["
|
|
29
|
-
IDLKind[IDLKind["
|
|
30
|
-
IDLKind[IDLKind["
|
|
31
|
-
IDLKind[IDLKind["
|
|
32
|
-
IDLKind[IDLKind["
|
|
33
|
-
IDLKind[IDLKind["
|
|
34
|
-
IDLKind[IDLKind["
|
|
35
|
-
IDLKind[IDLKind["
|
|
36
|
-
IDLKind[IDLKind["
|
|
37
|
-
IDLKind[IDLKind["
|
|
38
|
-
IDLKind[IDLKind["
|
|
39
|
-
IDLKind[IDLKind["
|
|
40
|
-
IDLKind[IDLKind["
|
|
41
|
-
IDLKind[IDLKind["
|
|
42
|
-
IDLKind[IDLKind["
|
|
43
|
-
IDLKind[IDLKind["File"] = 22] = "File";
|
|
22
|
+
IDLKind[IDLKind["Import"] = 1] = "Import";
|
|
23
|
+
IDLKind[IDLKind["Callback"] = 2] = "Callback";
|
|
24
|
+
IDLKind[IDLKind["Const"] = 3] = "Const";
|
|
25
|
+
IDLKind[IDLKind["Property"] = 4] = "Property";
|
|
26
|
+
IDLKind[IDLKind["Parameter"] = 5] = "Parameter";
|
|
27
|
+
IDLKind[IDLKind["Method"] = 6] = "Method";
|
|
28
|
+
IDLKind[IDLKind["Callable"] = 7] = "Callable";
|
|
29
|
+
IDLKind[IDLKind["Constructor"] = 8] = "Constructor";
|
|
30
|
+
IDLKind[IDLKind["Enum"] = 9] = "Enum";
|
|
31
|
+
IDLKind[IDLKind["EnumMember"] = 10] = "EnumMember";
|
|
32
|
+
IDLKind[IDLKind["Typedef"] = 11] = "Typedef";
|
|
33
|
+
IDLKind[IDLKind["PrimitiveType"] = 12] = "PrimitiveType";
|
|
34
|
+
IDLKind[IDLKind["ContainerType"] = 13] = "ContainerType";
|
|
35
|
+
IDLKind[IDLKind["UnspecifiedGenericType"] = 14] = "UnspecifiedGenericType";
|
|
36
|
+
IDLKind[IDLKind["ReferenceType"] = 15] = "ReferenceType";
|
|
37
|
+
IDLKind[IDLKind["UnionType"] = 16] = "UnionType";
|
|
38
|
+
IDLKind[IDLKind["TypeParameterType"] = 17] = "TypeParameterType";
|
|
39
|
+
IDLKind[IDLKind["OptionalType"] = 18] = "OptionalType";
|
|
40
|
+
IDLKind[IDLKind["Version"] = 19] = "Version";
|
|
41
|
+
IDLKind[IDLKind["Namespace"] = 20] = "Namespace";
|
|
42
|
+
IDLKind[IDLKind["File"] = 21] = "File";
|
|
44
43
|
})(IDLKind || (IDLKind = {}));
|
|
45
44
|
export var IDLEntity;
|
|
46
45
|
(function (IDLEntity) {
|
|
47
46
|
IDLEntity["Class"] = "Class";
|
|
48
47
|
IDLEntity["Interface"] = "Interface";
|
|
49
|
-
IDLEntity["Package"] = "Package";
|
|
50
48
|
IDLEntity["Import"] = "Import";
|
|
51
49
|
IDLEntity["Intersection"] = "Intersection";
|
|
52
50
|
IDLEntity["Literal"] = "Literal";
|
|
@@ -69,7 +67,6 @@ export var IDLExtendedAttributes;
|
|
|
69
67
|
IDLExtendedAttributes["DtsName"] = "DtsName";
|
|
70
68
|
IDLExtendedAttributes["DtsTag"] = "DtsTag";
|
|
71
69
|
IDLExtendedAttributes["Entity"] = "Entity";
|
|
72
|
-
IDLExtendedAttributes["GlobalScope"] = "GlobalScope";
|
|
73
70
|
IDLExtendedAttributes["Import"] = "Import";
|
|
74
71
|
IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
|
|
75
72
|
IDLExtendedAttributes["Interfaces"] = "Interfaces";
|
|
@@ -171,7 +168,6 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
171
168
|
case IDLKind.ReferenceType:
|
|
172
169
|
case IDLKind.TypeParameterType:
|
|
173
170
|
case IDLKind.EnumMember:
|
|
174
|
-
case IDLKind.Package:
|
|
175
171
|
case IDLKind.Import:
|
|
176
172
|
case IDLKind.PrimitiveType:
|
|
177
173
|
case IDLKind.Version:
|
|
@@ -228,9 +224,6 @@ export function isTypeParameterType(type) {
|
|
|
228
224
|
export function isInterface(node) {
|
|
229
225
|
return node.kind === IDLKind.Interface;
|
|
230
226
|
}
|
|
231
|
-
export function isPackage(type) {
|
|
232
|
-
return type.kind == IDLKind.Package;
|
|
233
|
-
}
|
|
234
227
|
export function isImport(type) {
|
|
235
228
|
return type.kind == IDLKind.Import;
|
|
236
229
|
}
|
|
@@ -400,13 +393,7 @@ export function isEqualByQualifedName(a, b) {
|
|
|
400
393
|
}
|
|
401
394
|
export function getPackageClause(entry) {
|
|
402
395
|
let file = getFileFor(entry);
|
|
403
|
-
|
|
404
|
-
return [];
|
|
405
|
-
for (const child of file.entries)
|
|
406
|
-
if (isPackage(child))
|
|
407
|
-
return child.clause;
|
|
408
|
-
// console.warn("Expected to have one IDLPackage inside IDLFile. Using empty package name")
|
|
409
|
-
return [];
|
|
396
|
+
return (file === null || file === void 0 ? void 0 : file.packageClause) || [];
|
|
410
397
|
}
|
|
411
398
|
export function getPackageName(entry) {
|
|
412
399
|
return getPackageClause(entry).join(".");
|
|
@@ -499,24 +486,15 @@ export function createUnionType(types, name) {
|
|
|
499
486
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
500
487
|
};
|
|
501
488
|
}
|
|
502
|
-
export function createFile(entries, fileName) {
|
|
489
|
+
export function createFile(entries, fileName, packageClause = []) {
|
|
503
490
|
return {
|
|
504
491
|
kind: IDLKind.File,
|
|
492
|
+
packageClause,
|
|
505
493
|
entries: entries,
|
|
506
494
|
fileName,
|
|
507
495
|
_idlNodeBrand: innerIdlSymbol,
|
|
508
496
|
};
|
|
509
497
|
}
|
|
510
|
-
export function createPackage(clause) {
|
|
511
|
-
return {
|
|
512
|
-
kind: IDLKind.Package,
|
|
513
|
-
name: "",
|
|
514
|
-
clause,
|
|
515
|
-
_idlNodeBrand: innerIdlSymbol,
|
|
516
|
-
_idlEntryBrand: innerIdlSymbol,
|
|
517
|
-
_idlNamedNodeBrand: innerIdlSymbol,
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
498
|
export function createImport(clause, name, nodeInitializer) {
|
|
521
499
|
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
522
500
|
}
|
|
@@ -754,10 +732,10 @@ export function printMethod(idl) {
|
|
|
754
732
|
];
|
|
755
733
|
}
|
|
756
734
|
export function printPackage(idl) {
|
|
757
|
-
if (!idl.
|
|
735
|
+
if (!idl.packageClause.length)
|
|
758
736
|
return [];
|
|
759
737
|
return [
|
|
760
|
-
`package ${idl.
|
|
738
|
+
`package ${idl.packageClause.join(".")};`
|
|
761
739
|
];
|
|
762
740
|
}
|
|
763
741
|
export function printImport(idl) {
|
|
@@ -856,6 +834,7 @@ export function printTypedef(idl) {
|
|
|
856
834
|
`typedef ${printType(idl.type)} ${idl.name};`
|
|
857
835
|
];
|
|
858
836
|
}
|
|
837
|
+
// TODO: use IndentedPrinter instead!
|
|
859
838
|
export function printIDL(idl, options) {
|
|
860
839
|
var _a;
|
|
861
840
|
if (idl.kind == IDLKind.Interface)
|
|
@@ -866,8 +845,6 @@ export function printIDL(idl, options) {
|
|
|
866
845
|
return printTypedef(idl);
|
|
867
846
|
if (idl.kind == IDLKind.Callback)
|
|
868
847
|
return printCallback(idl);
|
|
869
|
-
if (idl.kind == IDLKind.Package)
|
|
870
|
-
return printPackage(idl);
|
|
871
848
|
if (idl.kind == IDLKind.Import)
|
|
872
849
|
return printImport(idl);
|
|
873
850
|
if (idl.kind == IDLKind.Namespace)
|
|
@@ -883,23 +860,27 @@ export function printIDL(idl, options) {
|
|
|
883
860
|
throw new Error(`unexpected kind: ${idl.kind}`);
|
|
884
861
|
}
|
|
885
862
|
}
|
|
886
|
-
export function toIDLString(
|
|
863
|
+
export function toIDLString(file, options) {
|
|
887
864
|
let indent = 0;
|
|
888
|
-
const
|
|
865
|
+
const generated = printPackage(file);
|
|
866
|
+
return generated.concat(file.entries
|
|
889
867
|
.map(it => printIDL(it, options))
|
|
890
868
|
.flat()
|
|
891
869
|
.filter(isDefined)
|
|
892
870
|
.filter(it => it.length > 0)
|
|
893
871
|
.map(it => {
|
|
894
|
-
if (it === printedIndentInc)
|
|
872
|
+
if (it === printedIndentInc) {
|
|
895
873
|
++indent;
|
|
896
|
-
|
|
874
|
+
return undefined;
|
|
875
|
+
}
|
|
876
|
+
else if (it === printedIndentDec) {
|
|
897
877
|
--indent;
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
898
880
|
else
|
|
899
881
|
return indentedBy(it, indent);
|
|
900
882
|
})
|
|
901
|
-
.join("\n");
|
|
902
|
-
return generatedIdl;
|
|
883
|
+
.filter(isDefined)).join("\n");
|
|
903
884
|
}
|
|
904
885
|
// throws validation error
|
|
905
886
|
export function verifyIDLString(source) {
|
package/build/lib/src/index.d.ts
CHANGED
|
@@ -45,5 +45,5 @@ export * from "./peer-generation/ReferenceResolver";
|
|
|
45
45
|
export * from "./peer-generation/idl/common";
|
|
46
46
|
export { fromIDL } from "./from-idl/common";
|
|
47
47
|
export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
|
|
48
|
-
export {
|
|
48
|
+
export { toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
|
|
49
49
|
//# sourceMappingURL=index.d.ts.map
|
package/build/lib/src/index.js
CHANGED
|
@@ -59,5 +59,5 @@ export * from "./peer-generation/ReferenceResolver";
|
|
|
59
59
|
export * from "./peer-generation/idl/common";
|
|
60
60
|
export { fromIDL } from "./from-idl/common";
|
|
61
61
|
export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
|
|
62
|
-
export {
|
|
62
|
+
export { toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
|
|
63
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -31,7 +31,6 @@ export type QueryType<T> = LibraryQuery<IDLLibrary, T> | LensBuilder<T>;
|
|
|
31
31
|
export declare function query<T>(lib: IDLLibrary, input: QueryType<T>): T;
|
|
32
32
|
interface EntitiesParams {
|
|
33
33
|
expandNamespaces?: boolean;
|
|
34
|
-
slipPackage?: boolean;
|
|
35
34
|
}
|
|
36
35
|
export declare const lib: {
|
|
37
36
|
createLibrary: typeof createLibrary;
|
|
@@ -40,7 +39,7 @@ export declare const lib: {
|
|
|
40
39
|
query: typeof query;
|
|
41
40
|
select: {
|
|
42
41
|
files(): LibraryReducer<readonly idl.IDLFile[]>;
|
|
43
|
-
nodes(params
|
|
42
|
+
nodes(params?: EntitiesParams): LibraryQuery<readonly idl.IDLFile[], idl.IDLNode[]>;
|
|
44
43
|
entries(): LibraryQuery<idl.IDLNode[], idl.IDLEntry[]>;
|
|
45
44
|
interfaces(): LibraryQuery<idl.IDLNode[], idl.IDLInterface[]>;
|
|
46
45
|
hasExt<T extends idl.IDLNode>(attr: idl.IDLExtendedAttributes): LibraryQuery<T[], T[]>;
|
package/build/lib/src/library.js
CHANGED
|
@@ -139,12 +139,9 @@ const select = {
|
|
|
139
139
|
nodes(params) {
|
|
140
140
|
const key = 'entities' + serializeParam(params);
|
|
141
141
|
function go(node) {
|
|
142
|
-
if (idl.isNamespace(node) && params.expandNamespaces) {
|
|
142
|
+
if (idl.isNamespace(node) && (params === null || params === void 0 ? void 0 : params.expandNamespaces)) {
|
|
143
143
|
return node.members.flatMap(go);
|
|
144
144
|
}
|
|
145
|
-
if (idl.isPackage(node) && params.slipPackage) {
|
|
146
|
-
return [];
|
|
147
|
-
}
|
|
148
145
|
return [node];
|
|
149
146
|
}
|
|
150
147
|
return req(key, xs => {
|
|
@@ -52,9 +52,11 @@ export declare class MaterializedClass implements PeerClassBase {
|
|
|
52
52
|
getComponentName(): string;
|
|
53
53
|
getImplementationName(): string;
|
|
54
54
|
generatedName(isCallSignature: boolean): string;
|
|
55
|
+
private _isGlobal;
|
|
56
|
+
setGlobalScope(): void;
|
|
55
57
|
isGlobalScope(): boolean;
|
|
56
58
|
}
|
|
57
|
-
export declare function createDestroyPeerMethod(clazz: MaterializedClass): MaterializedMethod;
|
|
59
|
+
export declare function createDestroyPeerMethod(clazz: MaterializedClass): MaterializedMethod | undefined;
|
|
58
60
|
export declare function getInternalClassName(name: string): string;
|
|
59
61
|
export declare function getInternalClassQualifiedName(target: idl.IDLEntry): string;
|
|
60
62
|
export declare function getMaterializedFileName(name: string): string;
|
|
@@ -111,6 +111,7 @@ export class MaterializedClass {
|
|
|
111
111
|
this.methods = methods;
|
|
112
112
|
this.needBeGenerated = needBeGenerated;
|
|
113
113
|
this.taggedMethods = taggedMethods;
|
|
114
|
+
this._isGlobal = false;
|
|
114
115
|
PeerMethod.markAndGroupOverloads(methods);
|
|
115
116
|
}
|
|
116
117
|
getComponentName() {
|
|
@@ -122,11 +123,17 @@ export class MaterializedClass {
|
|
|
122
123
|
generatedName(isCallSignature) {
|
|
123
124
|
return this.className;
|
|
124
125
|
}
|
|
126
|
+
setGlobalScope() {
|
|
127
|
+
this._isGlobal = true;
|
|
128
|
+
}
|
|
125
129
|
isGlobalScope() {
|
|
126
|
-
return
|
|
130
|
+
return this._isGlobal;
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
export function createDestroyPeerMethod(clazz) {
|
|
134
|
+
if (clazz.isGlobalScope()) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
130
137
|
return new MaterializedMethod(clazz.className, clazz.getImplementationName(), [], idl.IDLVoidType, false, new Method('destroyPeer', new NamedMethodSignature(idl.IDLVoidType, [idl.createReferenceType(clazz.className)], ['peer'])));
|
|
131
138
|
}
|
|
132
139
|
export function getInternalClassName(name) {
|
|
@@ -7,7 +7,7 @@ export declare class PeerFile implements LibraryFileInterface {
|
|
|
7
7
|
readonly peers: Map<string, PeerClass>;
|
|
8
8
|
constructor(file: idl.IDLFile, isPredefined?: boolean);
|
|
9
9
|
packageName(): string;
|
|
10
|
-
|
|
10
|
+
packageClause(): string[];
|
|
11
11
|
get peersToGenerate(): PeerClass[];
|
|
12
12
|
get entries(): idl.IDLEntry[];
|
|
13
13
|
get originalFilename(): string;
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import * as idl from '../idl';
|
|
16
15
|
export class PeerFile {
|
|
17
16
|
constructor(file, isPredefined = false) {
|
|
18
17
|
this.file = file;
|
|
@@ -20,17 +19,10 @@ export class PeerFile {
|
|
|
20
19
|
this.peers = new Map();
|
|
21
20
|
}
|
|
22
21
|
packageName() {
|
|
23
|
-
|
|
24
|
-
if (packageTag === undefined) {
|
|
25
|
-
return "";
|
|
26
|
-
}
|
|
27
|
-
if (packageTag.name.startsWith('"') && packageTag.name.endsWith('"')) {
|
|
28
|
-
return packageTag.name.slice(1, packageTag.name.length - 1);
|
|
29
|
-
}
|
|
30
|
-
return packageTag.name;
|
|
22
|
+
return this.packageClause().join(".");
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
return this.
|
|
24
|
+
packageClause() {
|
|
25
|
+
return this.file.packageClause;
|
|
34
26
|
}
|
|
35
27
|
get peersToGenerate() {
|
|
36
28
|
const peers = Array.from(this.peers.values());
|
|
@@ -9,10 +9,14 @@ import { MaterializedClass } from './Materialized';
|
|
|
9
9
|
import { PeerFile } from './PeerFile';
|
|
10
10
|
import { LayoutManager, LayoutManagerStrategy } from './LayoutManager';
|
|
11
11
|
import { IDLLibrary } from '../library';
|
|
12
|
+
export interface GlobalScopeDeclarations {
|
|
13
|
+
methods: idl.IDLMethod[];
|
|
14
|
+
constants: idl.IDLConstant[];
|
|
15
|
+
}
|
|
12
16
|
export declare const lenses: {
|
|
13
17
|
globals: {
|
|
14
|
-
req: import("../library").LibraryReducer<
|
|
15
|
-
pipe<T>(r: import("../library").LibraryQuery<
|
|
18
|
+
req: import("../library").LibraryReducer<GlobalScopeDeclarations[]>;
|
|
19
|
+
pipe<T>(r: import("../library").LibraryQuery<GlobalScopeDeclarations[], T>): {
|
|
16
20
|
req: import("../library").LibraryReducer<T>;
|
|
17
21
|
pipe<T_1>(r: import("../library").LibraryQuery<T, T_1>): {
|
|
18
22
|
req: import("../library").LibraryReducer<T_1>;
|
|
@@ -5128,7 +5132,7 @@ export declare const lenses: {
|
|
|
5128
5132
|
};
|
|
5129
5133
|
query(): import("../library").LibraryReducer<T>;
|
|
5130
5134
|
};
|
|
5131
|
-
row<T_2047>(key: string, f: (x:
|
|
5135
|
+
row<T_2047>(key: string, f: (x: GlobalScopeDeclarations[]) => T_2047): {
|
|
5132
5136
|
req: import("../library").LibraryReducer<T_2047>;
|
|
5133
5137
|
pipe<T_2048>(r: import("../library").LibraryQuery<T_2047, T_2048>): {
|
|
5134
5138
|
req: import("../library").LibraryReducer<T_2048>;
|
|
@@ -10244,7 +10248,7 @@ export declare const lenses: {
|
|
|
10244
10248
|
};
|
|
10245
10249
|
query(): import("../library").LibraryReducer<T_2047>;
|
|
10246
10250
|
};
|
|
10247
|
-
query(): import("../library").LibraryReducer<
|
|
10251
|
+
query(): import("../library").LibraryReducer<GlobalScopeDeclarations[]>;
|
|
10248
10252
|
};
|
|
10249
10253
|
};
|
|
10250
10254
|
export declare class PeerLibrary implements LibraryInterface {
|
|
@@ -10252,10 +10256,11 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10252
10256
|
libraryPackages: string[] | undefined;
|
|
10253
10257
|
private _cachedIdlLibrary?;
|
|
10254
10258
|
asIDLLibrary(): IDLLibrary;
|
|
10255
|
-
get
|
|
10259
|
+
get globals(): GlobalScopeDeclarations[];
|
|
10256
10260
|
layout: LayoutManager;
|
|
10257
10261
|
private _syntheticFile;
|
|
10258
10262
|
initSyntheticEntries(file: idl.IDLFile): void;
|
|
10263
|
+
getSyntheticData(): idl.IDLInterface[];
|
|
10259
10264
|
readonly files: PeerFile[];
|
|
10260
10265
|
readonly builderClasses: Map<string, BuilderClass>;
|
|
10261
10266
|
get buildersToGenerate(): BuilderClass[];
|
|
@@ -30,9 +30,33 @@ import { lib, query } from '../library';
|
|
|
30
30
|
import { isMaterialized } from './isMaterialized';
|
|
31
31
|
export const lenses = {
|
|
32
32
|
globals: lib.lens(lib.select.files())
|
|
33
|
-
.pipe(lib.select.nodes(
|
|
34
|
-
.pipe(lib.
|
|
35
|
-
|
|
33
|
+
.pipe(lib.select.nodes())
|
|
34
|
+
.pipe(lib.req('globals', (nodes) => {
|
|
35
|
+
const result = [];
|
|
36
|
+
const queue = [nodes];
|
|
37
|
+
while (queue.length) {
|
|
38
|
+
const line = {
|
|
39
|
+
constants: [],
|
|
40
|
+
methods: []
|
|
41
|
+
};
|
|
42
|
+
const next = queue.pop();
|
|
43
|
+
next.forEach(node => {
|
|
44
|
+
if (idl.isNamespace(node)) {
|
|
45
|
+
queue.push(node.members);
|
|
46
|
+
}
|
|
47
|
+
if (idl.isConstant(node)) {
|
|
48
|
+
line.constants.push(node);
|
|
49
|
+
}
|
|
50
|
+
if (idl.isMethod(node)) {
|
|
51
|
+
line.methods.push(node);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (line.constants.length || line.methods.length) {
|
|
55
|
+
result.push(line);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}))
|
|
36
60
|
};
|
|
37
61
|
export class PeerLibrary {
|
|
38
62
|
asIDLLibrary() {
|
|
@@ -44,10 +68,13 @@ export class PeerLibrary {
|
|
|
44
68
|
};
|
|
45
69
|
return this._cachedIdlLibrary;
|
|
46
70
|
}
|
|
47
|
-
get
|
|
71
|
+
get globals() { return query(this.asIDLLibrary(), lenses.globals); }
|
|
48
72
|
initSyntheticEntries(file) {
|
|
49
73
|
this._syntheticFile = file;
|
|
50
74
|
}
|
|
75
|
+
getSyntheticData() {
|
|
76
|
+
return this._syntheticFile.entries.filter(it => idl.isInterface(it));
|
|
77
|
+
}
|
|
51
78
|
get buildersToGenerate() {
|
|
52
79
|
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
53
80
|
}
|
|
@@ -3,6 +3,7 @@ export declare class PrimitiveType {
|
|
|
3
3
|
protected isPointer: boolean;
|
|
4
4
|
constructor(name: string, isPointer?: boolean);
|
|
5
5
|
getText(): string;
|
|
6
|
+
getInterop(): string;
|
|
6
7
|
toString(): string;
|
|
7
8
|
}
|
|
8
9
|
export declare class PrimitiveTypeList {
|
|
@@ -11,6 +12,7 @@ export declare class PrimitiveTypeList {
|
|
|
11
12
|
static get ObjectTag(): string;
|
|
12
13
|
readonly Int32: PrimitiveType;
|
|
13
14
|
readonly Int64: PrimitiveType;
|
|
15
|
+
readonly Number: PrimitiveType;
|
|
14
16
|
readonly Boolean: PrimitiveType;
|
|
15
17
|
readonly Function: PrimitiveType;
|
|
16
18
|
readonly Undefined: PrimitiveType;
|
|
@@ -21,6 +21,9 @@ export class PrimitiveType {
|
|
|
21
21
|
getText() {
|
|
22
22
|
return generatorConfiguration().TypePrefix + this.name;
|
|
23
23
|
}
|
|
24
|
+
getInterop() {
|
|
25
|
+
return 'Interop' + this.name;
|
|
26
|
+
}
|
|
24
27
|
toString() {
|
|
25
28
|
return this.getText();
|
|
26
29
|
}
|
|
@@ -29,6 +32,7 @@ export class PrimitiveTypeList {
|
|
|
29
32
|
constructor() {
|
|
30
33
|
this.Int32 = new PrimitiveType(`Int32`);
|
|
31
34
|
this.Int64 = new PrimitiveType(`Int64`);
|
|
35
|
+
this.Number = new PrimitiveType(`Number`);
|
|
32
36
|
this.Boolean = new PrimitiveType(`Boolean`);
|
|
33
37
|
this.Function = new PrimitiveType(`Function`);
|
|
34
38
|
this.Undefined = new PrimitiveType(`Undefined`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as idl from '../idl';
|
|
2
2
|
import { ReferenceResolver } from './ReferenceResolver';
|
|
3
3
|
export declare function isMaterialized(declaration: idl.IDLInterface, resolver: ReferenceResolver): boolean;
|
|
4
|
+
export declare function isMaterializedType(type: idl.IDLType, resolver: ReferenceResolver): boolean;
|
|
4
5
|
//# sourceMappingURL=isMaterialized.d.ts.map
|
|
@@ -43,4 +43,12 @@ export function isMaterialized(declaration, resolver) {
|
|
|
43
43
|
}
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
|
+
export function isMaterializedType(type, resolver) {
|
|
47
|
+
if (!idl.isReferenceType(type))
|
|
48
|
+
return false;
|
|
49
|
+
const decl = resolver.resolveTypeReference(type);
|
|
50
|
+
if (!decl)
|
|
51
|
+
return false;
|
|
52
|
+
return (idl.isInterface(decl) && isMaterialized(decl, resolver));
|
|
53
|
+
}
|
|
46
54
|
//# sourceMappingURL=isMaterialized.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "build/lib/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"keywords": [],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@koalaui/interop": "1.5.
|
|
37
|
+
"@koalaui/interop": "1.5.6",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|