@idlizer/core 2.0.26 → 2.0.27
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.d.ts +1 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +7 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +7 -3
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +45 -5
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +200 -9
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -35
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +24 -169
- package/build/lib/src/LanguageWriters/index.js +3 -3
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +4 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +11 -7
- package/build/lib/src/LibraryInterface.d.ts +1 -0
- package/build/lib/src/idl.d.ts +0 -1
- package/build/lib/src/idl.js +3 -19
- package/build/lib/src/index.d.ts +1 -0
- package/build/lib/src/index.js +1 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +0 -1
- package/build/lib/src/peer-generation/Materialized.js +3 -48
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +4 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +27 -9
- package/build/lib/src/peer-generation/PrimitiveType.d.ts +1 -0
- package/build/lib/src/peer-generation/PrimitiveType.js +1 -0
- package/build/lib/src/peer-generation/isMaterialized.d.ts +4 -0
- package/build/lib/src/peer-generation/isMaterialized.js +46 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +14 -3
- package/package.json +2 -2
|
@@ -236,7 +236,7 @@ export declare class TypeAliasConvertor extends ProxyConvertor {
|
|
|
236
236
|
export declare class CustomTypeConvertor extends BaseArgConvertor {
|
|
237
237
|
readonly customTypeName: string;
|
|
238
238
|
private readonly isGenericType;
|
|
239
|
-
constructor(param: string, customTypeName: string, isGenericType
|
|
239
|
+
constructor(param: string, customTypeName: string, isGenericType: boolean, tsType: string);
|
|
240
240
|
convertorArg(param: string, writer: LanguageWriter): string;
|
|
241
241
|
/** todo: check */
|
|
242
242
|
convertorSerialize(param: string, value: string, printer: LanguageWriter): void;
|
|
@@ -19,9 +19,9 @@ import { RuntimeType } from "./common";
|
|
|
19
19
|
import { generatorTypePrefix } from "../config";
|
|
20
20
|
import { hashCodeFromString, warn } from "../util";
|
|
21
21
|
import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
|
|
22
|
-
import {
|
|
22
|
+
import { CppNameConvertor } from "./convertors/CppConvertors";
|
|
23
23
|
import { createEmptyReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
24
|
-
import {
|
|
24
|
+
import { CppConvertor } from "./convertors/CppConvertors";
|
|
25
25
|
import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
|
|
26
26
|
export class BaseArgConvertor {
|
|
27
27
|
constructor(idlType, runtimeTypes, isScoped, useArray, param) {
|
|
@@ -221,7 +221,7 @@ export class NumericConvertor extends BaseArgConvertor {
|
|
|
221
221
|
constructor(param, type) {
|
|
222
222
|
// check numericPrimitiveTypes.include(type)
|
|
223
223
|
super(type, [RuntimeType.NUMBER], false, false, param);
|
|
224
|
-
this.interopNameConvertor = new
|
|
224
|
+
this.interopNameConvertor = new CppNameConvertor(createEmptyReferenceResolver());
|
|
225
225
|
}
|
|
226
226
|
convertorArg(param, writer) {
|
|
227
227
|
return param;
|
|
@@ -672,11 +672,11 @@ export class TypeAliasConvertor extends ProxyConvertor {
|
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
export class CustomTypeConvertor extends BaseArgConvertor {
|
|
675
|
-
constructor(param, customTypeName, isGenericType
|
|
675
|
+
constructor(param, customTypeName, isGenericType, tsType) {
|
|
676
676
|
super(idl.createReferenceType(tsType !== null && tsType !== void 0 ? tsType : "Object"), [RuntimeType.OBJECT], false, true, param);
|
|
677
677
|
this.customTypeName = customTypeName;
|
|
678
678
|
this.isGenericType = isGenericType;
|
|
679
|
-
warnCustomObject(`${tsType}`);
|
|
679
|
+
warnCustomObject(`${customTypeName}: ${tsType}`);
|
|
680
680
|
}
|
|
681
681
|
convertorArg(param, writer) {
|
|
682
682
|
throw new Error("Must never be used");
|
|
@@ -811,7 +811,7 @@ export class UnionConvertor extends BaseArgConvertor {
|
|
|
811
811
|
printer.popIndent();
|
|
812
812
|
printer.print(`}`);
|
|
813
813
|
});
|
|
814
|
-
this.unionChecker.reportConflicts((_a = this.library.getCurrentContext()) !== null && _a !== void 0 ? _a : "<unknown context>");
|
|
814
|
+
this.unionChecker.reportConflicts((_a = this.library.getCurrentContext()) !== null && _a !== void 0 ? _a : "<unknown context>", printer);
|
|
815
815
|
}
|
|
816
816
|
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
817
817
|
const statements = [];
|
|
@@ -1028,7 +1028,7 @@ export function generateCallbackKindValue(callback) {
|
|
|
1028
1028
|
return hashCodeFromString(name);
|
|
1029
1029
|
}
|
|
1030
1030
|
export function generateCallbackAPIArguments(library, callback) {
|
|
1031
|
-
const nameConvertor = new
|
|
1031
|
+
const nameConvertor = new CppConvertor(library);
|
|
1032
1032
|
const args = [`const ${PrimitiveTypesInstance.Int32.getText()} resourceId`];
|
|
1033
1033
|
args.push(...callback.parameters.map(it => {
|
|
1034
1034
|
const target = library.toDeclaration(it.type);
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from "../idl";
|
|
16
|
+
import { indentedBy } from "../util";
|
|
16
17
|
import * as fs from "fs";
|
|
17
18
|
import { RuntimeType } from "./common";
|
|
18
19
|
export class TernaryExpression {
|
|
@@ -31,6 +32,8 @@ export class NaryOpExpression {
|
|
|
31
32
|
this.args = args;
|
|
32
33
|
}
|
|
33
34
|
asString() {
|
|
35
|
+
if (this.args.length === 1)
|
|
36
|
+
return this.args[0].asString();
|
|
34
37
|
return `${this.args.map(arg => `(${arg.asString()})`).join(` ${this.op} `)}`;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -275,16 +278,17 @@ export class LambdaExpression {
|
|
|
275
278
|
this.body = body;
|
|
276
279
|
}
|
|
277
280
|
bodyAsString() {
|
|
281
|
+
var _a;
|
|
278
282
|
const writer = this.originalWriter.fork();
|
|
279
283
|
if (this.body) {
|
|
280
284
|
for (const stmt of this.body) {
|
|
281
285
|
stmt.write(writer);
|
|
282
286
|
}
|
|
283
287
|
}
|
|
284
|
-
return writer.getOutput()
|
|
288
|
+
return (this.body ? ((_a = this.body) === null || _a === void 0 ? void 0 : _a.length) > 1 ? '\n' : '' : '').concat(writer.getOutput()
|
|
285
289
|
.filter(line => line !== "")
|
|
286
|
-
.map(line => line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line}
|
|
287
|
-
.join("\n");
|
|
290
|
+
.map(line => indentedBy(line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line};`, 1))
|
|
291
|
+
.join("\n"));
|
|
288
292
|
}
|
|
289
293
|
}
|
|
290
294
|
////////////////////////////////////////////////////////////////
|
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import * as idl from '../../idl';
|
|
2
|
-
import { IdlNameConvertor } from "../nameConvertor";
|
|
3
|
-
import { InteropConvertor, InteropReturnTypeConvertor } from './InteropConvertors';
|
|
2
|
+
import { IdlNameConvertor, NodeConvertor, TypeConvertor } from "../nameConvertor";
|
|
4
3
|
import { InteropArgConvertor } from './InteropConvertors';
|
|
5
4
|
import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
|
|
6
|
-
export
|
|
5
|
+
export interface ConvertResult {
|
|
6
|
+
text: string;
|
|
7
|
+
noPrefix: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class GenericCppConvertor implements NodeConvertor<ConvertResult> {
|
|
10
|
+
protected resolver: ReferenceResolver;
|
|
11
|
+
constructor(resolver: ReferenceResolver);
|
|
12
|
+
private make;
|
|
13
|
+
convertNode(node: idl.IDLNode): ConvertResult;
|
|
14
|
+
convertNamespace(node: idl.IDLNamespace): ConvertResult;
|
|
15
|
+
convertInterface(node: idl.IDLInterface): ConvertResult;
|
|
16
|
+
convertEnum(node: idl.IDLEnum): ConvertResult;
|
|
17
|
+
convertTypedef(node: idl.IDLTypedef): ConvertResult;
|
|
18
|
+
convertCallback(node: idl.IDLCallback): ConvertResult;
|
|
19
|
+
convertMethod(node: idl.IDLMethod): ConvertResult;
|
|
20
|
+
convertConstant(node: idl.IDLConstant): ConvertResult;
|
|
21
|
+
convertOptional(type: idl.IDLOptionalType): ConvertResult;
|
|
22
|
+
convertUnion(type: idl.IDLUnionType): ConvertResult;
|
|
23
|
+
convertContainer(type: idl.IDLContainerType): ConvertResult;
|
|
24
|
+
convertImport(type: idl.IDLReferenceType, _: string): ConvertResult;
|
|
25
|
+
convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
|
|
26
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
|
|
27
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
|
|
28
|
+
private enumName;
|
|
29
|
+
private computeTargetTypeLiteralName;
|
|
30
|
+
}
|
|
31
|
+
export declare class CppConvertor extends GenericCppConvertor implements IdlNameConvertor {
|
|
7
32
|
private unwrap;
|
|
8
33
|
convert(node: idl.IDLNode): string;
|
|
9
34
|
}
|
|
35
|
+
export declare class CppNameConvertor implements IdlNameConvertor {
|
|
36
|
+
protected resolver: ReferenceResolver;
|
|
37
|
+
private readonly cppConvertor;
|
|
38
|
+
constructor(resolver: ReferenceResolver);
|
|
39
|
+
convert(node: idl.IDLNode): string;
|
|
40
|
+
}
|
|
10
41
|
export declare class CppInteropArgConvertor extends InteropArgConvertor {
|
|
11
42
|
static INSTANCE: CppInteropArgConvertor;
|
|
12
43
|
convertOptional(type: idl.IDLOptionalType): string;
|
|
13
44
|
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
14
45
|
}
|
|
15
|
-
export declare class CppReturnTypeConvertor
|
|
16
|
-
|
|
46
|
+
export declare class CppReturnTypeConvertor implements TypeConvertor<string> {
|
|
47
|
+
private resolver;
|
|
48
|
+
private convertor;
|
|
17
49
|
constructor(resolver: ReferenceResolver);
|
|
50
|
+
isVoid(returnType: idl.IDLType): boolean;
|
|
51
|
+
convert(type: idl.IDLType): string;
|
|
52
|
+
convertContainer(type: idl.IDLContainerType): string;
|
|
53
|
+
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
54
|
+
convertOptional(type: idl.IDLOptionalType): string;
|
|
55
|
+
convertPrimitiveType(type: idl.IDLPrimitiveType): string;
|
|
56
|
+
convertTypeParameter(type: idl.IDLTypeParameterType): string;
|
|
18
57
|
convertTypeReference(type: idl.IDLReferenceType): string;
|
|
58
|
+
convertUnion(type: idl.IDLUnionType): string;
|
|
19
59
|
}
|
|
20
60
|
//# sourceMappingURL=CppConvertors.d.ts.map
|
|
@@ -14,11 +14,159 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../../idl';
|
|
16
16
|
import { generatorConfiguration } from "../../config";
|
|
17
|
-
import {
|
|
17
|
+
import { convertNode, convertType } from "../nameConvertor";
|
|
18
18
|
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
19
|
import { InteropArgConvertor } from './InteropConvertors';
|
|
20
|
-
import {
|
|
21
|
-
|
|
20
|
+
import { maybeTransformManagedCallback } from '../ArgConvertors';
|
|
21
|
+
import { qualifiedName } from '../../peer-generation/idl/common';
|
|
22
|
+
import { capitalize } from '../../util';
|
|
23
|
+
import { isMaterialized } from '../../peer-generation/isMaterialized';
|
|
24
|
+
export class GenericCppConvertor {
|
|
25
|
+
constructor(resolver) {
|
|
26
|
+
this.resolver = resolver;
|
|
27
|
+
}
|
|
28
|
+
make(text, noPrefix = false) {
|
|
29
|
+
return { text, noPrefix };
|
|
30
|
+
}
|
|
31
|
+
convertNode(node) {
|
|
32
|
+
return convertNode(this, node);
|
|
33
|
+
}
|
|
34
|
+
convertNamespace(node) {
|
|
35
|
+
throw new Error("Internal error: namespaces are not allowed on the interop layer");
|
|
36
|
+
}
|
|
37
|
+
convertInterface(node) {
|
|
38
|
+
switch (node.subkind) {
|
|
39
|
+
case idl.IDLInterfaceSubkind.AnonymousInterface:
|
|
40
|
+
return node.name
|
|
41
|
+
? this.make(node.name)
|
|
42
|
+
: this.make(this.computeTargetTypeLiteralName(node), true);
|
|
43
|
+
case idl.IDLInterfaceSubkind.Interface:
|
|
44
|
+
case idl.IDLInterfaceSubkind.Class:
|
|
45
|
+
if (idl.hasExtAttribute(node, idl.IDLExtendedAttributes.Predefined)) {
|
|
46
|
+
return this.make(node.name, true);
|
|
47
|
+
}
|
|
48
|
+
return this.make(node.name);
|
|
49
|
+
case idl.IDLInterfaceSubkind.Tuple:
|
|
50
|
+
return node.name
|
|
51
|
+
? this.make(node.name)
|
|
52
|
+
: this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
convertEnum(node) {
|
|
56
|
+
return this.make(this.enumName(node));
|
|
57
|
+
}
|
|
58
|
+
convertTypedef(node) {
|
|
59
|
+
return this.make(node.name);
|
|
60
|
+
}
|
|
61
|
+
convertCallback(node) {
|
|
62
|
+
return this.make(generatorConfiguration().LibraryPrefix + node.name, true);
|
|
63
|
+
}
|
|
64
|
+
convertMethod(node) {
|
|
65
|
+
return this.make(node.name);
|
|
66
|
+
}
|
|
67
|
+
convertConstant(node) {
|
|
68
|
+
return this.make(node.name);
|
|
69
|
+
}
|
|
70
|
+
/////////////////////////////////////////////////////////////////////////////////////////
|
|
71
|
+
convertOptional(type) {
|
|
72
|
+
return this.convertNode(type.type);
|
|
73
|
+
}
|
|
74
|
+
convertUnion(type) {
|
|
75
|
+
return this.make(type.name, false);
|
|
76
|
+
}
|
|
77
|
+
convertContainer(type) {
|
|
78
|
+
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
79
|
+
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`);
|
|
80
|
+
}
|
|
81
|
+
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
82
|
+
if (type.elementType[0] === idl.IDLU8Type) {
|
|
83
|
+
return this.make(`uint8_t*`, true);
|
|
84
|
+
}
|
|
85
|
+
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
|
|
86
|
+
}
|
|
87
|
+
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
88
|
+
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
91
|
+
}
|
|
92
|
+
convertImport(type, _) {
|
|
93
|
+
return this.make(idl.IDLCustomObjectType.name);
|
|
94
|
+
}
|
|
95
|
+
convertTypeReference(type) {
|
|
96
|
+
var _a;
|
|
97
|
+
const refName = type.name;
|
|
98
|
+
switch (refName) {
|
|
99
|
+
case "object":
|
|
100
|
+
case "Object":
|
|
101
|
+
return this.make('CustomObject');
|
|
102
|
+
}
|
|
103
|
+
if (generatorConfiguration().param("parameterized").includes(refName)) {
|
|
104
|
+
return this.make('CustomObject');
|
|
105
|
+
}
|
|
106
|
+
let decl = this.resolver.toDeclaration(type);
|
|
107
|
+
if (idl.isCallback(decl)) {
|
|
108
|
+
decl = (_a = maybeTransformManagedCallback(decl)) !== null && _a !== void 0 ? _a : decl;
|
|
109
|
+
}
|
|
110
|
+
if (idl.isType(decl)) {
|
|
111
|
+
if (idl.isReferenceType(decl)) {
|
|
112
|
+
return this.make(`${capitalize(decl.name)}`);
|
|
113
|
+
}
|
|
114
|
+
return this.convertNode(decl);
|
|
115
|
+
}
|
|
116
|
+
let res = this.convertNode(decl);
|
|
117
|
+
if (type.name === "Optional")
|
|
118
|
+
res = this.make("Opt_" + res.text, true);
|
|
119
|
+
return res;
|
|
120
|
+
}
|
|
121
|
+
convertTypeParameter(type) {
|
|
122
|
+
return this.make('CustomObject');
|
|
123
|
+
}
|
|
124
|
+
convertPrimitiveType(type) {
|
|
125
|
+
switch (type) {
|
|
126
|
+
case idl.IDLVoidType: return this.make('void', true);
|
|
127
|
+
case idl.IDLI8Type: return this.make(`Int8`);
|
|
128
|
+
case idl.IDLU8Type: return this.make(`UInt8`);
|
|
129
|
+
case idl.IDLI16Type: return this.make(`Int16`);
|
|
130
|
+
case idl.IDLU16Type: return this.make(`UInt16`);
|
|
131
|
+
case idl.IDLI32Type: return this.make(`Int32`);
|
|
132
|
+
case idl.IDLU32Type: return this.make(`UInt32`);
|
|
133
|
+
case idl.IDLI64Type: return this.make(`Int64`);
|
|
134
|
+
case idl.IDLU64Type: return this.make(`UInt64`);
|
|
135
|
+
case idl.IDLF32Type: return this.make(`Float32`);
|
|
136
|
+
case idl.IDLF64Type: return this.make(`Float64`);
|
|
137
|
+
case idl.IDLNumberType: return this.make(`Number`);
|
|
138
|
+
case idl.IDLStringType: return this.make(`String`);
|
|
139
|
+
case idl.IDLBooleanType: return this.make(`Boolean`);
|
|
140
|
+
case idl.IDLBigintType: return this.make(`UInt64`); // TODO add arbitrary precision numeric type
|
|
141
|
+
case idl.IDLPointerType: return this.make('NativePointer');
|
|
142
|
+
case idl.IDLUnknownType:
|
|
143
|
+
case idl.IDLCustomObjectType:
|
|
144
|
+
case idl.IDLAnyType: return this.make(`CustomObject`);
|
|
145
|
+
case idl.IDLUndefinedType: return this.make(`Undefined`);
|
|
146
|
+
case idl.IDLLengthType: return this.make(`Length`);
|
|
147
|
+
case idl.IDLFunctionType: return this.make(`Function`);
|
|
148
|
+
case idl.IDLDate: return this.make(`Date`);
|
|
149
|
+
case idl.IDLBufferType: return this.make('Buffer');
|
|
150
|
+
case idl.IDLPointerType: return this.make('Pointer');
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
153
|
+
}
|
|
154
|
+
enumName(target) {
|
|
155
|
+
return qualifiedName(target, "_");
|
|
156
|
+
}
|
|
157
|
+
computeTargetTypeLiteralName(decl) {
|
|
158
|
+
const map = new Map();
|
|
159
|
+
for (const prop of decl.properties) {
|
|
160
|
+
const type = this.convertNode(prop.type);
|
|
161
|
+
const values = map.has(type.text) ? map.get(type.text) : [];
|
|
162
|
+
values.push(prop.name);
|
|
163
|
+
map.set(type.text, values);
|
|
164
|
+
}
|
|
165
|
+
const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
|
|
166
|
+
return `Literal_${names.join('_')}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export class CppConvertor extends GenericCppConvertor {
|
|
22
170
|
unwrap(type, result) {
|
|
23
171
|
const conf = generatorConfiguration();
|
|
24
172
|
if (idl.isType(type) && idl.isOptionalType(type)) {
|
|
@@ -37,6 +185,15 @@ export class CppInteropConvertor extends InteropConvertor {
|
|
|
37
185
|
return this.unwrap(node, this.convertNode(node));
|
|
38
186
|
}
|
|
39
187
|
}
|
|
188
|
+
export class CppNameConvertor {
|
|
189
|
+
constructor(resolver) {
|
|
190
|
+
this.resolver = resolver;
|
|
191
|
+
this.cppConvertor = new GenericCppConvertor(resolver);
|
|
192
|
+
}
|
|
193
|
+
convert(node) {
|
|
194
|
+
return this.cppConvertor.convertNode(node).text;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
40
197
|
export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
41
198
|
convertOptional(type) {
|
|
42
199
|
return PrimitiveTypesInstance.NativePointer.getText();
|
|
@@ -56,16 +213,50 @@ export class CppInteropArgConvertor extends InteropArgConvertor {
|
|
|
56
213
|
}
|
|
57
214
|
}
|
|
58
215
|
CppInteropArgConvertor.INSTANCE = new CppInteropArgConvertor();
|
|
59
|
-
export class CppReturnTypeConvertor
|
|
216
|
+
export class CppReturnTypeConvertor {
|
|
60
217
|
constructor(resolver) {
|
|
61
|
-
super();
|
|
62
218
|
this.resolver = resolver;
|
|
219
|
+
this.convertor = new CppConvertor(resolver);
|
|
220
|
+
}
|
|
221
|
+
isVoid(returnType) {
|
|
222
|
+
return this.convert(returnType) == 'void';
|
|
223
|
+
}
|
|
224
|
+
convert(type) {
|
|
225
|
+
return convertType(this, type);
|
|
226
|
+
}
|
|
227
|
+
convertContainer(type) {
|
|
228
|
+
// Promise return is done as CPS callback, thus return type is void.
|
|
229
|
+
if (idl.IDLContainerUtils.isPromise(type))
|
|
230
|
+
return 'void';
|
|
231
|
+
return this.convertor.convert(type);
|
|
232
|
+
}
|
|
233
|
+
convertImport(type, importClause) {
|
|
234
|
+
return this.convertor.convert(type);
|
|
235
|
+
}
|
|
236
|
+
convertOptional(type) {
|
|
237
|
+
return this.convertor.convert(type);
|
|
238
|
+
}
|
|
239
|
+
convertPrimitiveType(type) {
|
|
240
|
+
if (type == idl.IDLUndefinedType)
|
|
241
|
+
return 'void';
|
|
242
|
+
if (type == idl.IDLStringType)
|
|
243
|
+
return 'void';
|
|
244
|
+
if (type == idl.IDLNumberType)
|
|
245
|
+
return generatorConfiguration().param("TypePrefix") + 'Int32'; // :(
|
|
246
|
+
return this.convertor.convert(type);
|
|
247
|
+
}
|
|
248
|
+
convertTypeParameter(type) {
|
|
249
|
+
return this.convertor.convert(type);
|
|
63
250
|
}
|
|
64
251
|
convertTypeReference(type) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return generatorConfiguration().param("TypePrefix") +
|
|
68
|
-
|
|
252
|
+
const decl = this.resolver.resolveTypeReference(type);
|
|
253
|
+
if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
|
|
254
|
+
return generatorConfiguration().param("TypePrefix") + decl.name;
|
|
255
|
+
}
|
|
256
|
+
return this.convertor.convert(type);
|
|
257
|
+
}
|
|
258
|
+
convertUnion(type) {
|
|
259
|
+
return this.convertor.convert(type);
|
|
69
260
|
}
|
|
70
261
|
}
|
|
71
262
|
//# sourceMappingURL=CppConvertors.js.map
|
|
@@ -1,43 +1,12 @@
|
|
|
1
1
|
import * as idl from '../../idl';
|
|
2
2
|
import { PeerMethod } from '../../peer-generation/PeerMethod';
|
|
3
3
|
import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
|
|
4
|
-
import {
|
|
5
|
-
export interface ConvertResult {
|
|
6
|
-
text: string;
|
|
7
|
-
noPrefix: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare class InteropConvertor implements NodeConvertor<ConvertResult> {
|
|
10
|
-
protected resolver: ReferenceResolver;
|
|
11
|
-
constructor(resolver: ReferenceResolver);
|
|
12
|
-
private make;
|
|
13
|
-
convertNode(node: idl.IDLNode): ConvertResult;
|
|
14
|
-
convertNamespace(node: idl.IDLNamespace): ConvertResult;
|
|
15
|
-
convertInterface(node: idl.IDLInterface): ConvertResult;
|
|
16
|
-
convertEnum(node: idl.IDLEnum): ConvertResult;
|
|
17
|
-
convertTypedef(node: idl.IDLTypedef): ConvertResult;
|
|
18
|
-
convertCallback(node: idl.IDLCallback): ConvertResult;
|
|
19
|
-
convertMethod(node: idl.IDLMethod): ConvertResult;
|
|
20
|
-
convertConstant(node: idl.IDLConstant): ConvertResult;
|
|
21
|
-
convertOptional(type: idl.IDLOptionalType): ConvertResult;
|
|
22
|
-
convertUnion(type: idl.IDLUnionType): ConvertResult;
|
|
23
|
-
convertContainer(type: idl.IDLContainerType): ConvertResult;
|
|
24
|
-
convertImport(type: idl.IDLReferenceType, _: string): ConvertResult;
|
|
25
|
-
convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
|
|
26
|
-
convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
|
|
27
|
-
convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
|
|
28
|
-
private enumName;
|
|
29
|
-
private computeTargetTypeLiteralName;
|
|
30
|
-
}
|
|
31
|
-
export declare class InteropNameConvertor implements IdlNameConvertor {
|
|
32
|
-
protected resolver: ReferenceResolver;
|
|
33
|
-
private readonly interopConvertor;
|
|
34
|
-
constructor(resolver: ReferenceResolver);
|
|
35
|
-
convert(node: idl.IDLNode): string;
|
|
36
|
-
}
|
|
4
|
+
import { TypeConvertor } from '../nameConvertor';
|
|
37
5
|
export declare class InteropReturnTypeConvertor implements TypeConvertor<string> {
|
|
38
|
-
protected readonly resolver
|
|
39
|
-
constructor(resolver
|
|
6
|
+
protected readonly resolver: ReferenceResolver;
|
|
7
|
+
constructor(resolver: ReferenceResolver);
|
|
40
8
|
isVoid(method: PeerMethod): boolean;
|
|
9
|
+
isReturnInteropBuffer(type: idl.IDLType): boolean;
|
|
41
10
|
convert(type: idl.IDLType): string;
|
|
42
11
|
convertContainer(type: idl.IDLContainerType): string;
|
|
43
12
|
convertImport(type: idl.IDLReferenceType, importClause: string): string;
|
|
@@ -12,167 +12,11 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import { generatorConfiguration } from '../../config';
|
|
16
15
|
import * as idl from '../../idl';
|
|
17
|
-
import {
|
|
16
|
+
import { isMaterialized } from '../../peer-generation/isMaterialized';
|
|
18
17
|
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
import { convertNode, convertType } from '../nameConvertor';
|
|
22
|
-
export class InteropConvertor {
|
|
23
|
-
constructor(resolver) {
|
|
24
|
-
this.resolver = resolver;
|
|
25
|
-
}
|
|
26
|
-
make(text, noPrefix = false) {
|
|
27
|
-
return { text, noPrefix };
|
|
28
|
-
}
|
|
29
|
-
convertNode(node) {
|
|
30
|
-
return convertNode(this, node);
|
|
31
|
-
}
|
|
32
|
-
convertNamespace(node) {
|
|
33
|
-
throw new Error("Internal error: namespaces are not allowed on the interop layer");
|
|
34
|
-
}
|
|
35
|
-
convertInterface(node) {
|
|
36
|
-
switch (node.subkind) {
|
|
37
|
-
case idl.IDLInterfaceSubkind.AnonymousInterface:
|
|
38
|
-
return node.name
|
|
39
|
-
? this.make(node.name)
|
|
40
|
-
: this.make(this.computeTargetTypeLiteralName(node), true);
|
|
41
|
-
case idl.IDLInterfaceSubkind.Interface:
|
|
42
|
-
case idl.IDLInterfaceSubkind.Class:
|
|
43
|
-
if (idl.hasExtAttribute(node, idl.IDLExtendedAttributes.Predefined)) {
|
|
44
|
-
return this.make(node.name, true);
|
|
45
|
-
}
|
|
46
|
-
return this.make(node.name);
|
|
47
|
-
case idl.IDLInterfaceSubkind.Tuple:
|
|
48
|
-
return node.name
|
|
49
|
-
? this.make(node.name)
|
|
50
|
-
: this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
convertEnum(node) {
|
|
54
|
-
return this.make(this.enumName(node));
|
|
55
|
-
}
|
|
56
|
-
convertTypedef(node) {
|
|
57
|
-
return this.make(node.name);
|
|
58
|
-
}
|
|
59
|
-
convertCallback(node) {
|
|
60
|
-
return this.make(generatorConfiguration().LibraryPrefix + node.name, true);
|
|
61
|
-
}
|
|
62
|
-
convertMethod(node) {
|
|
63
|
-
return this.make(node.name);
|
|
64
|
-
}
|
|
65
|
-
convertConstant(node) {
|
|
66
|
-
return this.make(node.name);
|
|
67
|
-
}
|
|
68
|
-
/////////////////////////////////////////////////////////////////////////////////////////
|
|
69
|
-
convertOptional(type) {
|
|
70
|
-
return this.convertNode(type.type);
|
|
71
|
-
}
|
|
72
|
-
convertUnion(type) {
|
|
73
|
-
return this.make(type.name, false);
|
|
74
|
-
}
|
|
75
|
-
convertContainer(type) {
|
|
76
|
-
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
77
|
-
return this.make(`Promise_${this.convertNode(type.elementType[0]).text}`);
|
|
78
|
-
}
|
|
79
|
-
if (idl.IDLContainerUtils.isSequence(type)) {
|
|
80
|
-
if (type.elementType[0] === idl.IDLU8Type) {
|
|
81
|
-
return this.make(`uint8_t*`, true);
|
|
82
|
-
}
|
|
83
|
-
return this.make(`Array_${this.convertNode(type.elementType[0]).text}`, true);
|
|
84
|
-
}
|
|
85
|
-
if (idl.IDLContainerUtils.isRecord(type)) {
|
|
86
|
-
return this.make(`Map_${this.convertNode(type.elementType[0]).text}_${this.convertNode(type.elementType[1]).text}`, true);
|
|
87
|
-
}
|
|
88
|
-
throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
89
|
-
}
|
|
90
|
-
convertImport(type, _) {
|
|
91
|
-
return this.make(idl.IDLCustomObjectType.name);
|
|
92
|
-
}
|
|
93
|
-
convertTypeReference(type) {
|
|
94
|
-
var _a;
|
|
95
|
-
const refName = type.name;
|
|
96
|
-
switch (refName) {
|
|
97
|
-
case "object":
|
|
98
|
-
case "Object":
|
|
99
|
-
return this.make('CustomObject');
|
|
100
|
-
}
|
|
101
|
-
if (generatorConfiguration().param("parameterized").includes(refName)) {
|
|
102
|
-
return this.make('CustomObject');
|
|
103
|
-
}
|
|
104
|
-
let decl = this.resolver.toDeclaration(type);
|
|
105
|
-
if (idl.isCallback(decl)) {
|
|
106
|
-
decl = (_a = maybeTransformManagedCallback(decl)) !== null && _a !== void 0 ? _a : decl;
|
|
107
|
-
}
|
|
108
|
-
if (idl.isType(decl)) {
|
|
109
|
-
if (idl.isReferenceType(decl)) {
|
|
110
|
-
return this.make(`${capitalize(decl.name)}`);
|
|
111
|
-
}
|
|
112
|
-
return this.convertNode(decl);
|
|
113
|
-
}
|
|
114
|
-
let res = this.convertNode(decl);
|
|
115
|
-
if (type.name === "Optional")
|
|
116
|
-
res = this.make("Opt_" + res.text, true);
|
|
117
|
-
return res;
|
|
118
|
-
}
|
|
119
|
-
convertTypeParameter(type) {
|
|
120
|
-
return this.make('CustomObject');
|
|
121
|
-
}
|
|
122
|
-
convertPrimitiveType(type) {
|
|
123
|
-
switch (type) {
|
|
124
|
-
case idl.IDLVoidType: return this.make('void', true);
|
|
125
|
-
case idl.IDLI8Type: return this.make(`Int8`);
|
|
126
|
-
case idl.IDLU8Type: return this.make(`UInt8`);
|
|
127
|
-
case idl.IDLI16Type: return this.make(`Int16`);
|
|
128
|
-
case idl.IDLU16Type: return this.make(`UInt16`);
|
|
129
|
-
case idl.IDLI32Type: return this.make(`Int32`);
|
|
130
|
-
case idl.IDLU32Type: return this.make(`UInt32`);
|
|
131
|
-
case idl.IDLI64Type: return this.make(`Int64`);
|
|
132
|
-
case idl.IDLU64Type: return this.make(`UInt64`);
|
|
133
|
-
case idl.IDLF32Type: return this.make(`Float32`);
|
|
134
|
-
case idl.IDLF64Type: return this.make(`Float64`);
|
|
135
|
-
case idl.IDLNumberType: return this.make(`Number`);
|
|
136
|
-
case idl.IDLStringType: return this.make(`String`);
|
|
137
|
-
case idl.IDLBooleanType: return this.make(`Boolean`);
|
|
138
|
-
case idl.IDLBigintType: return this.make(`UInt64`); // TODO add arbitrary precision numeric type
|
|
139
|
-
case idl.IDLPointerType: return this.make('NativePointer');
|
|
140
|
-
case idl.IDLUnknownType:
|
|
141
|
-
case idl.IDLCustomObjectType:
|
|
142
|
-
case idl.IDLAnyType: return this.make(`CustomObject`);
|
|
143
|
-
case idl.IDLUndefinedType: return this.make(`Undefined`);
|
|
144
|
-
case idl.IDLLengthType: return this.make(`Length`);
|
|
145
|
-
case idl.IDLFunctionType: return this.make(`Function`);
|
|
146
|
-
case idl.IDLDate: return this.make(`Date`);
|
|
147
|
-
case idl.IDLBufferType: return this.make('Buffer');
|
|
148
|
-
case idl.IDLPointerType: return this.make('Pointer');
|
|
149
|
-
}
|
|
150
|
-
throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
151
|
-
}
|
|
152
|
-
enumName(target) {
|
|
153
|
-
return qualifiedName(target, "_");
|
|
154
|
-
}
|
|
155
|
-
computeTargetTypeLiteralName(decl) {
|
|
156
|
-
const map = new Map();
|
|
157
|
-
for (const prop of decl.properties) {
|
|
158
|
-
const type = this.convertNode(prop.type);
|
|
159
|
-
const values = map.has(type.text) ? map.get(type.text) : [];
|
|
160
|
-
values.push(prop.name);
|
|
161
|
-
map.set(type.text, values);
|
|
162
|
-
}
|
|
163
|
-
const names = Array.from(map.keys()).map(key => `${key}_${map.get(key).join('_')}`);
|
|
164
|
-
return `Literal_${names.join('_')}`;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
export class InteropNameConvertor {
|
|
168
|
-
constructor(resolver) {
|
|
169
|
-
this.resolver = resolver;
|
|
170
|
-
this.interopConvertor = new InteropConvertor(resolver);
|
|
171
|
-
}
|
|
172
|
-
convert(node) {
|
|
173
|
-
return this.interopConvertor.convertNode(node).text;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
18
|
+
import { convertType } from '../nameConvertor';
|
|
19
|
+
const KInteropReturnBuffer = 'KInteropReturnBuffer';
|
|
176
20
|
export class InteropReturnTypeConvertor {
|
|
177
21
|
constructor(resolver) {
|
|
178
22
|
this.resolver = resolver;
|
|
@@ -180,22 +24,24 @@ export class InteropReturnTypeConvertor {
|
|
|
180
24
|
isVoid(method) {
|
|
181
25
|
return this.convert(method.returnType) === idl.IDLVoidType.name;
|
|
182
26
|
}
|
|
27
|
+
isReturnInteropBuffer(type) {
|
|
28
|
+
return this.convert(type) === KInteropReturnBuffer;
|
|
29
|
+
}
|
|
183
30
|
convert(type) {
|
|
184
31
|
return convertType(this, type);
|
|
185
32
|
}
|
|
186
33
|
convertContainer(type) {
|
|
187
|
-
if (idl.IDLContainerUtils.
|
|
34
|
+
if (idl.IDLContainerUtils.isPromise(type)) {
|
|
188
35
|
// TODO return array by some way
|
|
189
36
|
return "void";
|
|
190
37
|
}
|
|
191
|
-
|
|
192
|
-
return PrimitiveTypesInstance.NativePointer.getText();
|
|
38
|
+
return KInteropReturnBuffer;
|
|
193
39
|
}
|
|
194
40
|
convertImport(type, importClause) {
|
|
195
41
|
throw new Error(`Cannot pass import type ${type.name} through interop`);
|
|
196
42
|
}
|
|
197
43
|
convertOptional(type) {
|
|
198
|
-
return
|
|
44
|
+
return 'KInteropReturnBuffer';
|
|
199
45
|
}
|
|
200
46
|
convertPrimitiveType(type) {
|
|
201
47
|
switch (type) {
|
|
@@ -215,10 +61,10 @@ export class InteropReturnTypeConvertor {
|
|
|
215
61
|
case idl.IDLBigintType: return PrimitiveTypesInstance.Int64.getText();
|
|
216
62
|
case idl.IDLAnyType:
|
|
217
63
|
case idl.IDLBufferType:
|
|
218
|
-
case idl.IDLStringType:
|
|
219
64
|
case idl.IDLThisType:
|
|
220
65
|
case idl.IDLUndefinedType:
|
|
221
66
|
case idl.IDLUnknownType:
|
|
67
|
+
case idl.IDLStringType:
|
|
222
68
|
case idl.IDLVoidType: return idl.IDLVoidType.name;
|
|
223
69
|
case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
|
|
224
70
|
}
|
|
@@ -230,14 +76,23 @@ export class InteropReturnTypeConvertor {
|
|
|
230
76
|
convertTypeReference(type) {
|
|
231
77
|
if (type.name.endsWith("Attribute"))
|
|
232
78
|
return idl.IDLVoidType.name;
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
return
|
|
79
|
+
const decl = this.resolver.resolveTypeReference(type);
|
|
80
|
+
if (decl) {
|
|
81
|
+
// Callbacks and array types return by value
|
|
82
|
+
if (idl.isCallback(this.resolver.toDeclaration(type))) {
|
|
83
|
+
return type.name;
|
|
84
|
+
}
|
|
85
|
+
if (idl.isInterface(decl)) {
|
|
86
|
+
if (isMaterialized(decl, this.resolver)) {
|
|
87
|
+
return PrimitiveTypesInstance.NativePointer.getText();
|
|
88
|
+
}
|
|
89
|
+
return KInteropReturnBuffer;
|
|
90
|
+
}
|
|
236
91
|
}
|
|
237
|
-
return
|
|
92
|
+
return KInteropReturnBuffer;
|
|
238
93
|
}
|
|
239
94
|
convertUnion(type) {
|
|
240
|
-
return
|
|
95
|
+
return KInteropReturnBuffer;
|
|
241
96
|
}
|
|
242
97
|
}
|
|
243
98
|
export class InteropArgConvertor {
|
|
@@ -3,7 +3,7 @@ import { Language } from "../Language";
|
|
|
3
3
|
import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
|
|
4
4
|
import { createEmptyReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
5
5
|
import { CJIDLTypeToForeignStringConvertor, CJInteropArgConvertor, CJTypeNameConvertor } from "./convertors/CJConvertors";
|
|
6
|
-
import { CppInteropArgConvertor,
|
|
6
|
+
import { CppInteropArgConvertor, CppConvertor } from "./convertors/CppConvertors";
|
|
7
7
|
import { ETSTypeNameConvertor } from "./convertors/ETSConvertors";
|
|
8
8
|
import { InteropArgConvertor } from "./convertors/InteropConvertors";
|
|
9
9
|
import { JavaInteropArgConvertor, JavaTypeNameConvertor } from "./convertors/JavaConvertors";
|
|
@@ -19,9 +19,9 @@ export function createLanguageWriter(language, resolver) {
|
|
|
19
19
|
const printer = new IndentedPrinter();
|
|
20
20
|
switch (language) {
|
|
21
21
|
case Language.TS: return new TSLanguageWriter(printer, resolver, new TSTypeNameConvertor(resolver));
|
|
22
|
-
case Language.ARKTS: return new ETSLanguageWriter(printer, resolver, new ETSTypeNameConvertor(resolver), new
|
|
22
|
+
case Language.ARKTS: return new ETSLanguageWriter(printer, resolver, new ETSTypeNameConvertor(resolver), new CppConvertor(resolver));
|
|
23
23
|
case Language.JAVA: return new JavaLanguageWriter(printer, resolver, new JavaTypeNameConvertor(resolver));
|
|
24
|
-
case Language.CPP: return new CppLanguageWriter(printer, resolver, new
|
|
24
|
+
case Language.CPP: return new CppLanguageWriter(printer, resolver, new CppConvertor(resolver), PrimitiveTypesInstance);
|
|
25
25
|
case Language.CJ: return new CJLanguageWriter(printer, resolver, new CJTypeNameConvertor(resolver), new CJIDLTypeToForeignStringConvertor(resolver));
|
|
26
26
|
default: throw new Error(`Language ${language.toString()} is not supported`);
|
|
27
27
|
}
|
|
@@ -29,7 +29,8 @@ export declare class CJMatchExpression implements LanguageExpression {
|
|
|
29
29
|
matchValue: LanguageExpression;
|
|
30
30
|
matchCases: LanguageExpression[];
|
|
31
31
|
caseBlocks: LanguageExpression[];
|
|
32
|
-
|
|
32
|
+
indentDepth?: number | undefined;
|
|
33
|
+
constructor(matchValue: LanguageExpression, matchCases: LanguageExpression[], caseBlocks: LanguageExpression[], indentDepth?: number | undefined);
|
|
33
34
|
asString(): string;
|
|
34
35
|
}
|
|
35
36
|
export declare class CJTernaryExpression implements LanguageExpression {
|
|
@@ -139,6 +140,8 @@ export declare class CJLanguageWriter extends LanguageWriter {
|
|
|
139
140
|
makeEquals(args: LanguageExpression[]): LanguageExpression;
|
|
140
141
|
runtimeType(param: ArgConvertor, valueType: string, value: string): void;
|
|
141
142
|
escapeKeyword(word: string): string;
|
|
143
|
+
pushNamespace(namespace: string, ident?: boolean): void;
|
|
144
|
+
popNamespace(ident?: boolean): void;
|
|
142
145
|
castToInt(value: string, bitness: 8 | 32): string;
|
|
143
146
|
castToBoolean(value: string): string;
|
|
144
147
|
makeLengthSerializer(serializer: string, value: string): LanguageStatement | undefined;
|
|
@@ -18,7 +18,7 @@ import { CJKeywords } from "../../languageSpecificKeywords";
|
|
|
18
18
|
import { RuntimeType } from "../common";
|
|
19
19
|
import { AssignStatement, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, MethodModifier, MethodSignature, ReturnStatement, StringExpression } from "../LanguageWriter";
|
|
20
20
|
import { Language } from "../../Language";
|
|
21
|
-
import { isDefined } from "../../util";
|
|
21
|
+
import { indentedBy, isDefined } from "../../util";
|
|
22
22
|
////////////////////////////////////////////////////////////////
|
|
23
23
|
// EXPRESSIONS //
|
|
24
24
|
////////////////////////////////////////////////////////////////
|
|
@@ -64,19 +64,21 @@ export class CJUnionCastExpression {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
export class CJMatchExpression {
|
|
67
|
-
constructor(matchValue, matchCases, caseBlocks) {
|
|
67
|
+
constructor(matchValue, matchCases, caseBlocks, indentDepth) {
|
|
68
68
|
this.matchValue = matchValue;
|
|
69
69
|
this.matchCases = matchCases;
|
|
70
70
|
this.caseBlocks = caseBlocks;
|
|
71
|
+
this.indentDepth = indentDepth;
|
|
71
72
|
}
|
|
72
73
|
asString() {
|
|
74
|
+
var _a, _b, _c;
|
|
73
75
|
let output = [];
|
|
74
76
|
output.push(`match (${this.matchValue.asString()}) {`);
|
|
75
77
|
for (let index in this.matchCases) {
|
|
76
|
-
output.push(`case ${this.matchCases[index].asString()} => ${this.caseBlocks[index].asString()}
|
|
78
|
+
output.push(indentedBy(`case ${this.matchCases[index].asString()} => ${this.caseBlocks[index].asString()}`, ((_a = this.indentDepth) !== null && _a !== void 0 ? _a : 0) + 1));
|
|
77
79
|
}
|
|
78
|
-
output.push(`case _ => throw Exception(\"Unmatched pattern ${this.matchValue.asString()}\")
|
|
79
|
-
output.push(`}
|
|
80
|
+
output.push(indentedBy(`case _ => throw Exception(\"Unmatched pattern ${this.matchValue.asString()}\")`, ((_b = this.indentDepth) !== null && _b !== void 0 ? _b : 1) + 1));
|
|
81
|
+
output.push(indentedBy(`}`, ((_c = this.indentDepth) !== null && _c !== void 0 ? _c : 1)));
|
|
80
82
|
return output.join('\n');
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -482,7 +484,7 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
482
484
|
return this.makeString("Option.None");
|
|
483
485
|
}
|
|
484
486
|
makeUnwrapOptional(expression) {
|
|
485
|
-
return new CJMatchExpression(expression, [this.makeString('Some(serializer)')], [this.makeString('serializer')]);
|
|
487
|
+
return new CJMatchExpression(expression, [this.makeString('Some(serializer)')], [this.makeString('serializer')], this.indentDepth());
|
|
486
488
|
}
|
|
487
489
|
makeValueFromOption(value, destinationConvertor) {
|
|
488
490
|
return this.makeString(`${value}`);
|
|
@@ -498,7 +500,7 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
498
500
|
return this.makeStatement(this.makeMethodCall(keyAccessor, "set", [this.makeString(key), this.makeString(value)]));
|
|
499
501
|
}
|
|
500
502
|
makeNull(value) {
|
|
501
|
-
return new StringExpression(`None
|
|
503
|
+
return new StringExpression(`Option.None`);
|
|
502
504
|
}
|
|
503
505
|
getTagType() {
|
|
504
506
|
return idl.createReferenceType("Tags");
|
|
@@ -545,6 +547,8 @@ export class CJLanguageWriter extends LanguageWriter {
|
|
|
545
547
|
escapeKeyword(word) {
|
|
546
548
|
return CJKeywords.has(word) ? word + "_" : word;
|
|
547
549
|
}
|
|
550
|
+
pushNamespace(namespace, ident = true) { }
|
|
551
|
+
popNamespace(ident = true) { }
|
|
548
552
|
castToInt(value, bitness) {
|
|
549
553
|
return `Int${bitness}(${value})`;
|
|
550
554
|
}
|
|
@@ -9,6 +9,7 @@ export interface LibraryFileInterface {
|
|
|
9
9
|
export interface LibraryInterface extends ReferenceResolver {
|
|
10
10
|
language: Language;
|
|
11
11
|
get files(): LibraryFileInterface[];
|
|
12
|
+
get libraryPackages(): string[] | undefined;
|
|
12
13
|
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
13
14
|
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
14
15
|
getInteropName(node: idl.IDLNode): string;
|
package/build/lib/src/idl.d.ts
CHANGED
package/build/lib/src/idl.js
CHANGED
|
@@ -98,7 +98,7 @@ export var IDLInterfaceSubkind;
|
|
|
98
98
|
IDLInterfaceSubkind[IDLInterfaceSubkind["Tuple"] = 3] = "Tuple";
|
|
99
99
|
})(IDLInterfaceSubkind || (IDLInterfaceSubkind = {}));
|
|
100
100
|
export function forEachChild(node, cbEnter, cbLeave) {
|
|
101
|
-
var _a, _b
|
|
101
|
+
var _a, _b;
|
|
102
102
|
cbEnter(node);
|
|
103
103
|
switch (node.kind) {
|
|
104
104
|
case IDLKind.Namespace:
|
|
@@ -111,7 +111,6 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
111
111
|
concrete.properties.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
112
112
|
concrete.methods.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
113
113
|
concrete.callables.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
114
|
-
(_a = concrete.scope) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
115
114
|
break;
|
|
116
115
|
}
|
|
117
116
|
case IDLKind.Method:
|
|
@@ -119,14 +118,14 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
119
118
|
case IDLKind.Callback:
|
|
120
119
|
case IDLKind.Constructor: {
|
|
121
120
|
let concrete = node;
|
|
122
|
-
(
|
|
121
|
+
(_a = concrete.parameters) === null || _a === void 0 ? void 0 : _a.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
123
122
|
if (concrete.returnType)
|
|
124
123
|
forEachChild(concrete.returnType, cbEnter, cbLeave);
|
|
125
124
|
break;
|
|
126
125
|
}
|
|
127
126
|
case IDLKind.UnionType: {
|
|
128
127
|
let concrete = node;
|
|
129
|
-
(
|
|
128
|
+
(_b = concrete.types) === null || _b === void 0 ? void 0 : _b.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
130
129
|
break;
|
|
131
130
|
}
|
|
132
131
|
case IDLKind.OptionalType: {
|
|
@@ -746,14 +745,6 @@ export function printScoped(idl) {
|
|
|
746
745
|
throw new Error(`Unexpected scoped: ${idl.kind} ${idl.name}`);
|
|
747
746
|
}
|
|
748
747
|
export function printInterface(idl) {
|
|
749
|
-
idl.methods
|
|
750
|
-
.map(it => {
|
|
751
|
-
let result = it.scope;
|
|
752
|
-
it.scope = undefined;
|
|
753
|
-
return result;
|
|
754
|
-
})
|
|
755
|
-
.filter(isDefined)
|
|
756
|
-
.forEach(scope => idl.scope ? idl.scope.push(...scope) : idl.scope = scope);
|
|
757
748
|
return [
|
|
758
749
|
...printExtendedAttributes(idl, 0),
|
|
759
750
|
`interface ${idl.name}${hasSuperType(idl) ? ": " + printType(idl.inheritance[0]) : ""} {`,
|
|
@@ -852,7 +843,6 @@ export function toIDLString(entries, options) {
|
|
|
852
843
|
let indent = 0;
|
|
853
844
|
const generatedIdl = entries
|
|
854
845
|
.map(it => printIDL(it, options))
|
|
855
|
-
.concat(printScopes(entries))
|
|
856
846
|
.flat()
|
|
857
847
|
.filter(isDefined)
|
|
858
848
|
.filter(it => it.length > 0)
|
|
@@ -872,12 +862,6 @@ export function verifyIDLString(source) {
|
|
|
872
862
|
webidl2.validate(webidl2.parse(source));
|
|
873
863
|
return true;
|
|
874
864
|
}
|
|
875
|
-
function printScopes(entries) {
|
|
876
|
-
return entries
|
|
877
|
-
.map((it) => it.scope)
|
|
878
|
-
.filter(isDefined)
|
|
879
|
-
.flatMap((it) => it.map(printScoped));
|
|
880
|
-
}
|
|
881
865
|
export function hasExtAttribute(node, attribute) {
|
|
882
866
|
var _a;
|
|
883
867
|
return ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find((it) => it.name == attribute)) != undefined;
|
package/build/lib/src/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export * from "./peer-generation/PeerClass";
|
|
|
37
37
|
export * from "./peer-generation/PeerMethod";
|
|
38
38
|
export * from "./peer-generation/BuilderClass";
|
|
39
39
|
export * from "./peer-generation/Materialized";
|
|
40
|
+
export * from "./peer-generation/isMaterialized";
|
|
40
41
|
export * from "./peer-generation/unions";
|
|
41
42
|
export * from "./LanguageWriters";
|
|
42
43
|
export * from "./peer-generation/ReferenceResolver";
|
package/build/lib/src/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export * from "./peer-generation/PeerClass";
|
|
|
51
51
|
export * from "./peer-generation/PeerMethod";
|
|
52
52
|
export * from "./peer-generation/BuilderClass";
|
|
53
53
|
export * from "./peer-generation/Materialized";
|
|
54
|
+
export * from "./peer-generation/isMaterialized";
|
|
54
55
|
export * from "./peer-generation/unions";
|
|
55
56
|
export * from "./LanguageWriters";
|
|
56
57
|
export * from "./peer-generation/ReferenceResolver";
|
|
@@ -4,7 +4,6 @@ import { Field, Method } from '../LanguageWriters/LanguageWriter';
|
|
|
4
4
|
import { PeerClassBase } from './PeerClass';
|
|
5
5
|
import { PeerMethod } from './PeerMethod';
|
|
6
6
|
import { ReferenceResolver } from './ReferenceResolver';
|
|
7
|
-
export declare function isMaterialized(declaration: idl.IDLInterface, resolver: ReferenceResolver): boolean;
|
|
8
7
|
export declare class MaterializedField {
|
|
9
8
|
field: Field;
|
|
10
9
|
argConvertor: ArgConvertor;
|
|
@@ -12,42 +12,11 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import { generatorConfiguration } from '../config';
|
|
16
15
|
import * as idl from '../idl';
|
|
17
|
-
import { CppReturnTypeConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
18
16
|
import { copyMethod, Method, MethodModifier, NamedMethodSignature } from '../LanguageWriters/LanguageWriter';
|
|
19
17
|
import { capitalize } from '../util';
|
|
20
|
-
import { isBuilderClass } from './BuilderClass';
|
|
21
18
|
import { qualifiedName } from './idl/common';
|
|
22
19
|
import { PeerMethod } from './PeerMethod';
|
|
23
|
-
export function isMaterialized(declaration, resolver) {
|
|
24
|
-
if (!idl.isInterfaceSubkind(declaration) && !idl.isClassSubkind(declaration))
|
|
25
|
-
return false;
|
|
26
|
-
if (idl.isHandwritten(declaration) || isBuilderClass(declaration))
|
|
27
|
-
return false;
|
|
28
|
-
for (const forceMaterialized of generatorConfiguration().param("forceMaterialized")) {
|
|
29
|
-
if (declaration.name == forceMaterialized)
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
for (const ignore of generatorConfiguration().param("ignoreMaterialized")) {
|
|
33
|
-
if (declaration.name.endsWith(ignore))
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
// A materialized class is a class or an interface with methods
|
|
37
|
-
// excluding components and related classes
|
|
38
|
-
if (declaration.methods.length > 0 || declaration.constructors.length > 0)
|
|
39
|
-
return true;
|
|
40
|
-
// Or a class or an interface derived from materialized class
|
|
41
|
-
if (idl.hasSuperType(declaration)) {
|
|
42
|
-
const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
|
|
43
|
-
if (!superType || !idl.isInterface(superType)) {
|
|
44
|
-
console.log(`Unable to resolve ${idl.getSuperType(declaration).name} type, consider ${declaration.name} to be not materialized`);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return isMaterialized(superType, resolver);
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
20
|
export class MaterializedField {
|
|
52
21
|
constructor(field, argConvertor, outArgConvertor, isNullableOriginalTypeField) {
|
|
53
22
|
this.field = field;
|
|
@@ -76,28 +45,14 @@ export class MaterializedMethod extends PeerMethod {
|
|
|
76
45
|
}
|
|
77
46
|
}
|
|
78
47
|
dummyReturnValue(resolver) {
|
|
79
|
-
var _a;
|
|
80
48
|
if (this.method.name === "ctor")
|
|
81
|
-
return `(${this.originalParentName}
|
|
49
|
+
return `(Ark_${this.originalParentName}) 100`;
|
|
82
50
|
if (this.method.name === "getFinalizer")
|
|
83
51
|
return `fnPtr<KNativePointer>(dummyClassFinalizer)`;
|
|
84
|
-
if ((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.STATIC)) {
|
|
85
|
-
if (this.method.signature.returnType === idl.IDLNumberType) {
|
|
86
|
-
return '100';
|
|
87
|
-
}
|
|
88
|
-
if (this.method.signature.returnType === idl.IDLBooleanType) {
|
|
89
|
-
return '0';
|
|
90
|
-
}
|
|
91
|
-
const convertor = new CppReturnTypeConvertor(resolver);
|
|
92
|
-
return `(${convertor.convert(this.returnType)}) 300`;
|
|
93
|
-
}
|
|
94
|
-
if (idl.isReferenceType(this.method.signature.returnType)) {
|
|
95
|
-
return "{}";
|
|
96
|
-
}
|
|
97
52
|
return undefined;
|
|
98
53
|
}
|
|
99
54
|
get receiverType() {
|
|
100
|
-
return
|
|
55
|
+
return `Ark_${this.originalParentName}`;
|
|
101
56
|
}
|
|
102
57
|
get apiCall() {
|
|
103
58
|
return "GetAccessors()";
|
|
@@ -110,7 +65,7 @@ export class MaterializedMethod extends PeerMethod {
|
|
|
110
65
|
return undefined;
|
|
111
66
|
return {
|
|
112
67
|
argName: 'peer',
|
|
113
|
-
argType:
|
|
68
|
+
argType: `Ark_${this.originalParentName}`
|
|
114
69
|
};
|
|
115
70
|
}
|
|
116
71
|
getImplementationName() {
|
|
@@ -10,6 +10,7 @@ import { PeerFile } from './PeerFile';
|
|
|
10
10
|
import { LayoutManager, LayoutManagerStrategy } from './LayoutManager';
|
|
11
11
|
export declare class PeerLibrary implements LibraryInterface {
|
|
12
12
|
language: Language;
|
|
13
|
+
libraryPackages: string[] | undefined;
|
|
13
14
|
layout: LayoutManager;
|
|
14
15
|
private _syntheticEntries;
|
|
15
16
|
/** @deprecated PeerLibrary should contain only SDK entries */
|
|
@@ -22,7 +23,7 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
22
23
|
get materializedToGenerate(): MaterializedClass[];
|
|
23
24
|
readonly predefinedDeclarations: idl.IDLInterface[];
|
|
24
25
|
readonly globalScopeInterfaces: idl.IDLInterface[];
|
|
25
|
-
constructor(language: Language);
|
|
26
|
+
constructor(language: Language, libraryPackages: string[] | undefined);
|
|
26
27
|
name: string;
|
|
27
28
|
readonly customComponentMethods: string[];
|
|
28
29
|
createLanguageWriter(language?: Language): LanguageWriter;
|
|
@@ -38,6 +39,8 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
38
39
|
findFileByOriginalFilename(filename: string): PeerFile | undefined;
|
|
39
40
|
mapType(type: idl.IDLType): string;
|
|
40
41
|
resolveTypeReference(type: idl.IDLReferenceType, pointOfView?: idl.IDLEntry, rootEntries?: idl.IDLEntry[]): idl.IDLEntry | undefined;
|
|
42
|
+
resolvePackageName(entry: idl.IDLEntry): string;
|
|
43
|
+
hasInLibrary(entry: idl.IDLEntry): boolean;
|
|
41
44
|
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
42
45
|
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
43
46
|
private customConvertor;
|
|
@@ -17,16 +17,16 @@ import * as idl from '../idl';
|
|
|
17
17
|
import { Language } from '../Language';
|
|
18
18
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
19
19
|
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
-
import {
|
|
20
|
+
import { CppNameConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
21
21
|
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
22
|
-
import {
|
|
22
|
+
import { CppConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
23
23
|
import { ETSTypeNameConvertor } from '../LanguageWriters/convertors/ETSConvertors';
|
|
24
24
|
import { JavaTypeNameConvertor } from '../LanguageWriters/convertors/JavaConvertors';
|
|
25
25
|
import { TSTypeNameConvertor } from '../LanguageWriters/convertors/TSConvertors';
|
|
26
26
|
import { isBuilderClass } from './BuilderClass';
|
|
27
27
|
import { generateSyntheticFunctionName, isImportAttr } from './idl/common';
|
|
28
|
-
import { isMaterialized } from './Materialized';
|
|
29
28
|
import { LayoutManager } from './LayoutManager';
|
|
29
|
+
import { isMaterialized } from './isMaterialized';
|
|
30
30
|
export class PeerLibrary {
|
|
31
31
|
/** @deprecated PeerLibrary should contain only SDK entries */
|
|
32
32
|
get syntheticEntries() {
|
|
@@ -41,8 +41,9 @@ export class PeerLibrary {
|
|
|
41
41
|
get materializedToGenerate() {
|
|
42
42
|
return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated);
|
|
43
43
|
}
|
|
44
|
-
constructor(language) {
|
|
44
|
+
constructor(language, libraryPackages) {
|
|
45
45
|
this.language = language;
|
|
46
|
+
this.libraryPackages = libraryPackages;
|
|
46
47
|
this.layout = LayoutManager.Empty();
|
|
47
48
|
this._syntheticEntries = [];
|
|
48
49
|
this.files = [];
|
|
@@ -53,7 +54,7 @@ export class PeerLibrary {
|
|
|
53
54
|
this.name = "";
|
|
54
55
|
this.customComponentMethods = [];
|
|
55
56
|
this.targetNameConvertorInstance = this.createTypeNameConvertor(this.language);
|
|
56
|
-
this.interopNameConvertorInstance = new
|
|
57
|
+
this.interopNameConvertorInstance = new CppNameConvertor(this);
|
|
57
58
|
}
|
|
58
59
|
createLanguageWriter(language) {
|
|
59
60
|
return createLanguageWriter(language !== null && language !== void 0 ? language : this.language, this);
|
|
@@ -64,7 +65,7 @@ export class PeerLibrary {
|
|
|
64
65
|
case Language.ARKTS: return new ETSTypeNameConvertor(this);
|
|
65
66
|
case Language.JAVA: return new JavaTypeNameConvertor(this);
|
|
66
67
|
case Language.CJ: return new CJTypeNameConvertor(this);
|
|
67
|
-
case Language.CPP: return new
|
|
68
|
+
case Language.CPP: return new CppConvertor(this);
|
|
68
69
|
}
|
|
69
70
|
throw new Error(`IdlNameConvertor for ${language} is not implemented`);
|
|
70
71
|
}
|
|
@@ -165,6 +166,23 @@ export class PeerLibrary {
|
|
|
165
166
|
} // end of block to remove
|
|
166
167
|
return undefined; // empty result
|
|
167
168
|
}
|
|
169
|
+
resolvePackageName(entry) {
|
|
170
|
+
var _a;
|
|
171
|
+
if (this._syntheticEntries.includes(entry))
|
|
172
|
+
return ((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) ? this.libraryPackages[0] : this.files[0].packageName();
|
|
173
|
+
while (entry.namespace) {
|
|
174
|
+
entry = entry.namespace;
|
|
175
|
+
}
|
|
176
|
+
for (const file of this.files) {
|
|
177
|
+
if (file.entries.includes(entry))
|
|
178
|
+
return file.packageName();
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`Package name for entry ${entry.name} was not found`);
|
|
181
|
+
}
|
|
182
|
+
hasInLibrary(entry) {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(this.resolvePackageName(entry)));
|
|
185
|
+
}
|
|
168
186
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
169
187
|
if (isOptionalParam) {
|
|
170
188
|
return new OptionConvertor(this, param, idl.maybeUnwrapOptionalType(type));
|
|
@@ -194,7 +212,7 @@ export class PeerLibrary {
|
|
|
194
212
|
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
195
213
|
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
196
214
|
case idl.IDLUnknownType:
|
|
197
|
-
case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any");
|
|
215
|
+
case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any", false, "Object");
|
|
198
216
|
default: throw new Error(`Unconverted primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
199
217
|
}
|
|
200
218
|
}
|
|
@@ -215,7 +233,7 @@ export class PeerLibrary {
|
|
|
215
233
|
}
|
|
216
234
|
if (idl.isTypeParameterType(type)) {
|
|
217
235
|
// TODO: unlikely correct.
|
|
218
|
-
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true);
|
|
236
|
+
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true, `<${type.name}>`);
|
|
219
237
|
}
|
|
220
238
|
throw new Error(`Cannot convert: ${type.kind}`);
|
|
221
239
|
}
|
|
@@ -267,7 +285,7 @@ export class PeerLibrary {
|
|
|
267
285
|
customConvertor(param, typeName, type) {
|
|
268
286
|
switch (typeName) {
|
|
269
287
|
case `Object`:
|
|
270
|
-
return new CustomTypeConvertor(param, "Object");
|
|
288
|
+
return new CustomTypeConvertor(param, "Object", false, "Object");
|
|
271
289
|
case `Date`:
|
|
272
290
|
return new DateConvertor(param);
|
|
273
291
|
case `Function`:
|
|
@@ -19,6 +19,7 @@ export declare class PrimitiveTypeList {
|
|
|
19
19
|
readonly Tag: PrimitiveType;
|
|
20
20
|
readonly Materialized: PrimitiveType;
|
|
21
21
|
readonly CustomObject: PrimitiveType;
|
|
22
|
+
readonly String: PrimitiveType;
|
|
22
23
|
}
|
|
23
24
|
export declare const PrimitiveTypesInstance: PrimitiveTypeList;
|
|
24
25
|
//# sourceMappingURL=PrimitiveType.d.ts.map
|
|
@@ -37,6 +37,7 @@ export class PrimitiveTypeList {
|
|
|
37
37
|
this.Tag = new PrimitiveType(`Tag`);
|
|
38
38
|
this.Materialized = new PrimitiveType(`Materialized`, true);
|
|
39
39
|
this.CustomObject = new PrimitiveType(`CustomObject`, true);
|
|
40
|
+
this.String = new PrimitiveType(`String`);
|
|
40
41
|
}
|
|
41
42
|
static get UndefinedTag() {
|
|
42
43
|
return "INTEROP_TAG_UNDEFINED";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { generatorConfiguration } from '../config';
|
|
16
|
+
import * as idl from '../idl';
|
|
17
|
+
import { isBuilderClass } from './BuilderClass';
|
|
18
|
+
export function isMaterialized(declaration, resolver) {
|
|
19
|
+
if (!idl.isInterfaceSubkind(declaration) && !idl.isClassSubkind(declaration))
|
|
20
|
+
return false;
|
|
21
|
+
if (idl.isHandwritten(declaration) || isBuilderClass(declaration))
|
|
22
|
+
return false;
|
|
23
|
+
for (const forceMaterialized of generatorConfiguration().param("forceMaterialized")) {
|
|
24
|
+
if (declaration.name == forceMaterialized)
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
for (const ignore of generatorConfiguration().param("ignoreMaterialized")) {
|
|
28
|
+
if (declaration.name.endsWith(ignore))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// A materialized class is a class or an interface with methods
|
|
32
|
+
// excluding components and related classes
|
|
33
|
+
if (declaration.methods.length > 0 || declaration.constructors.length > 0)
|
|
34
|
+
return true;
|
|
35
|
+
// Or a class or an interface derived from materialized class
|
|
36
|
+
if (idl.hasSuperType(declaration)) {
|
|
37
|
+
const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
|
|
38
|
+
if (!superType || !idl.isInterface(superType)) {
|
|
39
|
+
console.log(`Unable to resolve ${idl.getSuperType(declaration).name} type, consider ${declaration.name} to be not materialized`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return isMaterialized(superType, resolver);
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=isMaterialized.js.map
|
|
@@ -23,7 +23,7 @@ export declare class UnionRuntimeTypeChecker {
|
|
|
23
23
|
constructor(convertors: ArgConvertor[]);
|
|
24
24
|
private checkConflicts;
|
|
25
25
|
makeDiscriminator(value: string, convertorIndex: number, writer: LanguageWriter): LanguageExpression;
|
|
26
|
-
reportConflicts(context: string | undefined): void;
|
|
26
|
+
reportConflicts(context: string | undefined, writer: LanguageWriter): void;
|
|
27
27
|
}
|
|
28
28
|
export declare function flattenUnionType(library: LibraryInterface, type: IDLType): IDLType;
|
|
29
29
|
//# sourceMappingURL=unions.d.ts.map
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { convertType } from "../LanguageWriters";
|
|
16
16
|
import { IDLCustomObjectType, IDLUndefinedType, isType, isUnionType } from '../idl';
|
|
17
17
|
import { typeOrUnion } from "./idl/common";
|
|
18
|
+
import { CustomTypeConvertor } from "../LanguageWriters/ArgConvertors";
|
|
18
19
|
import { RuntimeType } from "../LanguageWriters/common";
|
|
19
20
|
export class UnionFlattener {
|
|
20
21
|
constructor(resolver) {
|
|
@@ -92,10 +93,20 @@ export class UnionRuntimeTypeChecker {
|
|
|
92
93
|
writer.makeUnionVariantCondition(convertor, value, `${value}_type`, RuntimeType[it], convertorIndex, runtimeTypeIndex)
|
|
93
94
|
])));
|
|
94
95
|
}
|
|
95
|
-
reportConflicts(context) {
|
|
96
|
+
reportConflicts(context, writer) {
|
|
96
97
|
if (this.discriminators.filter(([discriminator, _, __]) => discriminator === undefined).length > 1) {
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
let report = `Union discrimination code can not be generated for \`${context}\`.\n`;
|
|
99
|
+
report += `Possible reasons for that are too similar or unresolved types in union (see below).\n`;
|
|
100
|
+
report += ` # | type | duplicated properties | resolved | discriminator expression\n`;
|
|
101
|
+
const properties = Array.from(this.duplicateMembers).join(",").padEnd(30);
|
|
102
|
+
this.discriminators.forEach(([discr, conv, n]) => {
|
|
103
|
+
const num = n.toString().padEnd(3);
|
|
104
|
+
const typename = conv.targetType(writer).padEnd(30);
|
|
105
|
+
const resolved = (conv instanceof CustomTypeConvertor ? "no" : "yes").padEnd(9);
|
|
106
|
+
const discriminator = discr ? discr.asString() : "<undefined>";
|
|
107
|
+
report += ` ${num}| ${typename}| ${properties}| ${resolved}| ${discriminator}\n`;
|
|
108
|
+
});
|
|
109
|
+
throw new Error(report);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.27",
|
|
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.2",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|