@idlizer/core 2.1.5 → 2.1.9-arktscgen-4
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/IndentedPrinter.js +2 -0
- package/build/lib/src/Language.d.ts +1 -0
- package/build/lib/src/Language.js +3 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -4
- package/build/lib/src/LanguageWriters/ArgConvertors.js +162 -26
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +38 -8
- package/build/lib/src/LanguageWriters/LanguageWriter.js +46 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +37 -14
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.d.ts +24 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.js +69 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +25 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +128 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
- package/build/lib/src/LanguageWriters/index.js +4 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +12 -7
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +43 -27
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +11 -2
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +43 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +5 -2
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +45 -11
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -2
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -3
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +149 -0
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +495 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +8 -5
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -13
- package/build/lib/src/LibraryInterface.d.ts +2 -0
- package/build/lib/src/config.d.ts +673 -44
- package/build/lib/src/config.js +20 -0
- package/build/lib/src/configDescriber.d.ts +2 -2
- package/build/lib/src/configDescriber.js +3 -3
- package/build/lib/src/from-idl/DtsPrinter.js +12 -8
- package/build/lib/src/from-idl/IDLLinter.d.ts +0 -1
- package/build/lib/src/from-idl/IDLLinter.js +1 -7
- package/build/lib/src/from-idl/deserialize.d.ts +7 -1
- package/build/lib/src/from-idl/deserialize.js +72 -40
- package/build/lib/src/idl.d.ts +8 -15
- package/build/lib/src/idl.js +69 -72
- package/build/lib/src/idlize.js +2 -0
- package/build/lib/src/index.d.ts +2 -0
- package/build/lib/src/index.js +2 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +4 -1
- package/build/lib/src/peer-generation/LayoutManager.js +5 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +7 -3
- package/build/lib/src/peer-generation/Materialized.js +18 -4
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +5 -2
- package/build/lib/src/peer-generation/PeerLibrary.js +30 -10
- package/build/lib/src/peer-generation/PeerMethod.d.ts +1 -1
- package/build/lib/src/peer-generation/getSuperType.d.ts +5 -0
- package/build/lib/src/peer-generation/getSuperType.js +55 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +4 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +7 -0
- package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/common.js +9 -3
- package/build/lib/src/peer-generation/isExternalType.d.ts +4 -0
- package/build/lib/src/peer-generation/isExternalType.js +15 -0
- package/build/lib/src/peer-generation/isMaterialized.js +18 -6
- package/build/lib/src/peer-generation/unions.js +1 -1
- package/build/lib/src/util.d.ts +4 -1
- package/build/lib/src/util.js +25 -10
- package/build/lib/src/visitor.d.ts +2 -0
- package/build/lib/src/visitor.js +108 -1
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +62 -16
- package/webidl2.js/LICENSE +0 -21
- package/webidl2.js/README.md +0 -827
- package/webidl2.js/dist/package.json +0 -3
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import * as idl from '../../idl';
|
|
16
|
+
import { Language } from '../../Language';
|
|
17
|
+
import { IndentedPrinter } from "../../IndentedPrinter";
|
|
18
|
+
import { AssignStatement, DelegationType, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, Method, MethodModifier, MethodSignature } from "../LanguageWriter";
|
|
19
|
+
import { RuntimeType } from "../common";
|
|
20
|
+
import { isDefined } from "../../util";
|
|
21
|
+
import { TSReturnStatement } from './TsLanguageWriter';
|
|
22
|
+
import { removePoints } from '../convertors/CJConvertors';
|
|
23
|
+
export class KotlinEnumEntityStatement {
|
|
24
|
+
constructor(enumEntity, options) {
|
|
25
|
+
this.enumEntity = enumEntity;
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
write(writer) {
|
|
29
|
+
let mangledName = removePoints(idl.getQualifiedName(this.enumEntity, 'namespace.name'));
|
|
30
|
+
writer.print(`${this.options.isExport ? "public " : ""}enum class ${mangledName}(val value: Int) {`);
|
|
31
|
+
writer.pushIndent();
|
|
32
|
+
this.enumEntity.elements.forEach((member, index) => {
|
|
33
|
+
const initValue = member.initializer != undefined
|
|
34
|
+
? `(${this.maybeQuoted(member.initializer)})` : ``;
|
|
35
|
+
writer.print(`${member.name}${initValue},`);
|
|
36
|
+
let originalName = idl.getExtAttribute(member, idl.IDLExtendedAttributes.OriginalEnumMemberName);
|
|
37
|
+
if (originalName) {
|
|
38
|
+
const initValue = `(${member.name}.value)`;
|
|
39
|
+
writer.print(`${originalName}${initValue},`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
writer.popIndent();
|
|
43
|
+
writer.print(`}`);
|
|
44
|
+
}
|
|
45
|
+
maybeQuoted(value) {
|
|
46
|
+
if (typeof value == "string")
|
|
47
|
+
return `"${value}"`;
|
|
48
|
+
else
|
|
49
|
+
return `${value}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class KotlinEnumWithGetter {
|
|
53
|
+
constructor(enumEntity, isExport) {
|
|
54
|
+
this.enumEntity = enumEntity;
|
|
55
|
+
this.isExport = isExport;
|
|
56
|
+
}
|
|
57
|
+
write(writer) {
|
|
58
|
+
const initializers = this.enumEntity.elements.map(it => {
|
|
59
|
+
return { name: it.name, id: it.initializer };
|
|
60
|
+
});
|
|
61
|
+
const isStringEnum = initializers.every(it => typeof it.id == 'string');
|
|
62
|
+
let memberValue = 0;
|
|
63
|
+
const members = [];
|
|
64
|
+
for (const initializer of initializers) {
|
|
65
|
+
if (typeof initializer.id == 'string') {
|
|
66
|
+
members.push({ name: initializer.name, stringId: initializer.id, numberId: memberValue });
|
|
67
|
+
}
|
|
68
|
+
else if (typeof initializer.id == 'number') {
|
|
69
|
+
memberValue = initializer.id;
|
|
70
|
+
members.push({ name: initializer.name, stringId: undefined, numberId: memberValue });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
members.push({ name: initializer.name, stringId: undefined, numberId: memberValue });
|
|
74
|
+
}
|
|
75
|
+
memberValue += 1;
|
|
76
|
+
}
|
|
77
|
+
let mangledName = removePoints(idl.getQualifiedName(this.enumEntity, 'namespace.name'));
|
|
78
|
+
writer.writeClass(mangledName, () => {
|
|
79
|
+
const enumType = idl.createReferenceType(this.enumEntity);
|
|
80
|
+
writer.makeStaticBlock(() => {
|
|
81
|
+
members.forEach(it => {
|
|
82
|
+
writer.writeFieldDeclaration(it.name, idl.IDLAnyType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.FINAL], false, writer.makeString(`${mangledName}(${it.stringId ? `\"${it.stringId}\"` : it.numberId})`));
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
const value = 'value';
|
|
86
|
+
writer.writeFieldDeclaration(value, idl.IDLI32Type, [FieldModifier.PUBLIC], true, writer.makeNull());
|
|
87
|
+
const signature = new MethodSignature(idl.IDLVoidType, [idl.IDLI32Type]);
|
|
88
|
+
writer.writeConstructorImplementation('constructor', signature, () => {
|
|
89
|
+
writer.writeStatement(writer.makeAssign(`this.${value}`, undefined, writer.makeString(signature.argName(0)), false));
|
|
90
|
+
});
|
|
91
|
+
if (isStringEnum) {
|
|
92
|
+
const stringValue = 'stringValue';
|
|
93
|
+
writer.writeFieldDeclaration(stringValue, idl.IDLStringType, [FieldModifier.PUBLIC], true, writer.makeNull());
|
|
94
|
+
const signature = new MethodSignature(idl.IDLVoidType, [idl.IDLStringType]);
|
|
95
|
+
writer.writeConstructorImplementation('constructor', signature, () => {
|
|
96
|
+
writer.writeStatement(writer.makeAssign(`this.${stringValue}`, undefined, writer.makeString(signature.argName(0)), false));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class KotlinMapForEachStatement {
|
|
103
|
+
constructor(map, key, value, op) {
|
|
104
|
+
this.map = map;
|
|
105
|
+
this.key = key;
|
|
106
|
+
this.value = value;
|
|
107
|
+
this.op = op;
|
|
108
|
+
}
|
|
109
|
+
write(writer) {
|
|
110
|
+
writer.print(`for ((${this.key}, ${this.value}) in ${this.map}) {`);
|
|
111
|
+
writer.pushIndent();
|
|
112
|
+
this.op();
|
|
113
|
+
writer.popIndent();
|
|
114
|
+
writer.print(`}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export class KotlinThrowErrorStatement {
|
|
118
|
+
constructor(message) {
|
|
119
|
+
this.message = message;
|
|
120
|
+
}
|
|
121
|
+
write(writer) {
|
|
122
|
+
writer.print(`throw Error("${this.message}")`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export class KotlinLoopStatement {
|
|
126
|
+
constructor(counter, limit, statement) {
|
|
127
|
+
this.counter = counter;
|
|
128
|
+
this.limit = limit;
|
|
129
|
+
this.statement = statement;
|
|
130
|
+
}
|
|
131
|
+
write(writer) {
|
|
132
|
+
writer.print(`for (${this.counter} in 0..${this.limit}) {`);
|
|
133
|
+
if (this.statement) {
|
|
134
|
+
writer.pushIndent();
|
|
135
|
+
this.statement.write(writer);
|
|
136
|
+
writer.popIndent();
|
|
137
|
+
writer.print("}");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export class KotlinAssignStatement extends AssignStatement {
|
|
142
|
+
constructor(variableName, type, expression, isDeclared = true, isConst = true) {
|
|
143
|
+
super(variableName, type, expression, isDeclared, isConst);
|
|
144
|
+
this.variableName = variableName;
|
|
145
|
+
this.type = type;
|
|
146
|
+
this.expression = expression;
|
|
147
|
+
this.isDeclared = isDeclared;
|
|
148
|
+
this.isConst = isConst;
|
|
149
|
+
}
|
|
150
|
+
write(writer) {
|
|
151
|
+
var _a;
|
|
152
|
+
if (this.isDeclared) {
|
|
153
|
+
const typeSpec = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.overrideTypeName)
|
|
154
|
+
? `: ${this.options.overrideTypeName}`
|
|
155
|
+
: this.type ? `: ${writer.getNodeName(this.type)}` : "";
|
|
156
|
+
const constSpec = this.isConst ? "val" : "var";
|
|
157
|
+
const initValue = this.expression ? `= ${this.expression.asString()}` : "";
|
|
158
|
+
writer.print(`${constSpec} ${this.variableName}${typeSpec} ${initValue}`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
writer.print(`${this.variableName} = ${this.expression.asString()}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export class KotlinNewObjectExpression {
|
|
166
|
+
constructor(objectName, params) {
|
|
167
|
+
this.objectName = objectName;
|
|
168
|
+
this.params = params;
|
|
169
|
+
}
|
|
170
|
+
asString() {
|
|
171
|
+
return `${this.objectName}(${this.params.map(it => it.asString()).join(", ")})`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export class KotlinCheckDefinedExpression {
|
|
175
|
+
constructor(value) {
|
|
176
|
+
this.value = value;
|
|
177
|
+
}
|
|
178
|
+
asString() {
|
|
179
|
+
return `${this.value} != null`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
class KotlinUnwrapOptionalExpression {
|
|
183
|
+
constructor(value) {
|
|
184
|
+
this.value = value;
|
|
185
|
+
}
|
|
186
|
+
asString() {
|
|
187
|
+
return `requireNotNull(${this.value.asString()})`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
class KotlinLambdaExpression extends LambdaExpression {
|
|
191
|
+
constructor(writer, signature, resolver, body) {
|
|
192
|
+
super(writer, signature, resolver, body);
|
|
193
|
+
this.writer = writer;
|
|
194
|
+
}
|
|
195
|
+
get statementHasSemicolon() {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
asString() {
|
|
199
|
+
const params = this.signature.args.map((it, i) => `${this.writer.escapeKeyword(this.signature.argName(i))}: ${this.writer.getNodeName(it)}`);
|
|
200
|
+
return `{${params.join(", ")} -> ${this.bodyAsString()} }`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export class KotlinLanguageWriter extends LanguageWriter {
|
|
204
|
+
constructor(printer, resolver, typeConvertor, language = Language.KOTLIN) {
|
|
205
|
+
super(printer, resolver, language);
|
|
206
|
+
this.typeConvertor = typeConvertor;
|
|
207
|
+
}
|
|
208
|
+
fork(options) {
|
|
209
|
+
var _a;
|
|
210
|
+
return new KotlinLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
|
|
211
|
+
}
|
|
212
|
+
getNodeName(type) {
|
|
213
|
+
return this.typeConvertor.convert(type);
|
|
214
|
+
}
|
|
215
|
+
writeClass(name, op, superClass, interfaces, generics, isDeclared, isAbstract) {
|
|
216
|
+
let extendsClause = superClass ? `${superClass}` : undefined;
|
|
217
|
+
let implementsClause = interfaces ? `${interfaces.join(' , ')}` : undefined;
|
|
218
|
+
let inheritancePart = [extendsClause, implementsClause]
|
|
219
|
+
.filter(isDefined)
|
|
220
|
+
.join(' , ');
|
|
221
|
+
inheritancePart = inheritancePart.length != 0 ? ' : '.concat(inheritancePart) : '';
|
|
222
|
+
this.printer.print(`public open class ${name}${inheritancePart} {`);
|
|
223
|
+
this.pushIndent();
|
|
224
|
+
op(this);
|
|
225
|
+
this.popIndent();
|
|
226
|
+
this.printer.print(`}`);
|
|
227
|
+
}
|
|
228
|
+
writeInterface(name, op, superInterfaces, generics, isDeclared) {
|
|
229
|
+
this.printer.print(`public interface ${name} {`);
|
|
230
|
+
this.pushIndent();
|
|
231
|
+
op(this);
|
|
232
|
+
this.popIndent();
|
|
233
|
+
this.printer.print(`}`);
|
|
234
|
+
}
|
|
235
|
+
writeFunctionDeclaration(name, signature, generics) {
|
|
236
|
+
this.printer.print(this.generateFunctionDeclaration(name, signature));
|
|
237
|
+
}
|
|
238
|
+
writeFunctionImplementation(name, signature, op, generics) {
|
|
239
|
+
this.printer.print(`${this.generateFunctionDeclaration(name, signature)} {`);
|
|
240
|
+
this.printer.pushIndent();
|
|
241
|
+
op(this);
|
|
242
|
+
this.printer.popIndent();
|
|
243
|
+
this.printer.print('}');
|
|
244
|
+
}
|
|
245
|
+
generateFunctionDeclaration(name, signature) {
|
|
246
|
+
const args = signature.args.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}`);
|
|
247
|
+
return `public fun ${name}(${args.join(", ")}): ${this.getNodeName(signature.returnType)}`;
|
|
248
|
+
}
|
|
249
|
+
writeEnum(name, members, options) {
|
|
250
|
+
throw new Error("Try to avoid writeEnum");
|
|
251
|
+
}
|
|
252
|
+
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
253
|
+
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
254
|
+
.filter(it => modifiers.includes(it))
|
|
255
|
+
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
256
|
+
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER)) {
|
|
257
|
+
prefix = `${prefix} get`;
|
|
258
|
+
}
|
|
259
|
+
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) {
|
|
260
|
+
prefix = `${prefix} set`;
|
|
261
|
+
needReturn = false;
|
|
262
|
+
}
|
|
263
|
+
prefix = prefix ? prefix.trim() + " " : "";
|
|
264
|
+
const typeParams = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(", ")}>` : "";
|
|
265
|
+
const normalizedArgs = signature.args.map((it, i) => idl.isOptionalType(it) && signature.isArgOptional(i) ? idl.maybeUnwrapOptionalType(it) : it);
|
|
266
|
+
this.printer.print(`${prefix}fun ${name}${typeParams}(${normalizedArgs.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}${signature.isArgOptional(index) ? "?" : ``}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""}${needBracket ? " {" : ""}`);
|
|
267
|
+
}
|
|
268
|
+
writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
|
|
269
|
+
const init = initExpr != undefined ? ` = ${initExpr.asString()}` : ``;
|
|
270
|
+
let prefix = this.makeFieldModifiersList(modifiers === null || modifiers === void 0 ? void 0 : modifiers.filter(m => m != FieldModifier.READONLY && m != FieldModifier.STATIC));
|
|
271
|
+
this.printer.print(`${prefix ? prefix.concat(" ") : ""}${(modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(FieldModifier.READONLY)) ? 'val' : 'var'} ${name}: ${this.getNodeName(idl.maybeOptional(type, optional))}${init}`);
|
|
272
|
+
}
|
|
273
|
+
writeNativeMethodDeclaration(method) {
|
|
274
|
+
let name = method.name;
|
|
275
|
+
let signature = method.signature;
|
|
276
|
+
this.writeMethodImplementation(new Method(name, signature, [MethodModifier.STATIC]), writer => { });
|
|
277
|
+
}
|
|
278
|
+
writeMethodDeclaration(name, signature, modifiers) {
|
|
279
|
+
this.writeDeclaration(name, signature, true, false, modifiers);
|
|
280
|
+
}
|
|
281
|
+
writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
|
|
282
|
+
const delegationType = ((delegationCall === null || delegationCall === void 0 ? void 0 : delegationCall.delegationType) == DelegationType.THIS) ? "this" : "super";
|
|
283
|
+
const superInvocation = delegationCall
|
|
284
|
+
? ` : ${delegationType}(${delegationCall.delegationArgs.map(it => it.asString()).join(", ")})`
|
|
285
|
+
: "";
|
|
286
|
+
const argList = signature.args.map((it, index) => {
|
|
287
|
+
var _a;
|
|
288
|
+
const maybeDefault = ((_a = signature.defaults) === null || _a === void 0 ? void 0 : _a[index]) ? ` = ${signature.defaults[index]}` : "";
|
|
289
|
+
return `${signature.argName(index)}: ${this.getNodeName(it)}${maybeDefault}`;
|
|
290
|
+
}).join(", ");
|
|
291
|
+
this.print(`constructor(${argList})${superInvocation} {`);
|
|
292
|
+
this.pushIndent();
|
|
293
|
+
op(this);
|
|
294
|
+
this.popIndent();
|
|
295
|
+
this.printer.print(`}`);
|
|
296
|
+
}
|
|
297
|
+
writeMethodImplementation(method, op) {
|
|
298
|
+
this.writeDeclaration(method.name, method.signature, true, true, method.modifiers, method.generics);
|
|
299
|
+
this.pushIndent();
|
|
300
|
+
op(this);
|
|
301
|
+
this.popIndent();
|
|
302
|
+
this.printer.print(`}`);
|
|
303
|
+
}
|
|
304
|
+
writeProperty(propName, propType, modifiers, getter, setter) {
|
|
305
|
+
let containerName = propName.concat("_container");
|
|
306
|
+
let truePropName = this.escapeKeyword(propName);
|
|
307
|
+
if (getter) {
|
|
308
|
+
if (!getter.op) {
|
|
309
|
+
this.print(`private var ${containerName}: ${this.getNodeName(propType)}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
let isStatic = modifiers.includes(FieldModifier.STATIC);
|
|
313
|
+
let isMutable = !modifiers.includes(FieldModifier.READONLY);
|
|
314
|
+
this.print(`public ${isMutable ? "var " : "val "}${truePropName}: ${this.getNodeName(propType)}`);
|
|
315
|
+
if (getter) {
|
|
316
|
+
this.pushIndent();
|
|
317
|
+
this.writeGetterImplementation(getter.method, getter.op);
|
|
318
|
+
if (isMutable) {
|
|
319
|
+
if (setter) {
|
|
320
|
+
this.writeSetterImplementation(setter.method, setter ? setter.op : (writer) => { this.print(`${containerName} = ${truePropName}`); });
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
this.print(`set(${truePropName}) {`);
|
|
324
|
+
this.pushIndent();
|
|
325
|
+
this.print(`${containerName} = ${truePropName}`);
|
|
326
|
+
this.popIndent();
|
|
327
|
+
this.print(`}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
this.popIndent();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
writeGetterImplementation(method, op) {
|
|
334
|
+
this.print(`get() {`);
|
|
335
|
+
this.pushIndent();
|
|
336
|
+
op ? op(this) : this.print(`return ${method.signature.argsNames.map(arg => `${arg}_container`).join(', ')}`);
|
|
337
|
+
this.popIndent();
|
|
338
|
+
this.print('}');
|
|
339
|
+
}
|
|
340
|
+
writeSetterImplementation(method, op) {
|
|
341
|
+
this.print(`set(${method.signature.argsNames.map(arg => this.escapeKeyword(arg)).join(', ')}) {`);
|
|
342
|
+
this.pushIndent();
|
|
343
|
+
op(this);
|
|
344
|
+
this.popIndent();
|
|
345
|
+
this.print('}');
|
|
346
|
+
}
|
|
347
|
+
writeTypeDeclaration(decl) {
|
|
348
|
+
throw new Error("Not implemented");
|
|
349
|
+
}
|
|
350
|
+
writeConstant(constName, constType, constVal) {
|
|
351
|
+
throw new Error("Not implemented");
|
|
352
|
+
}
|
|
353
|
+
makeNull() {
|
|
354
|
+
return this.makeString('null');
|
|
355
|
+
}
|
|
356
|
+
makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
|
|
357
|
+
return new KotlinAssignStatement(variableName, type, expr, isDeclared, isConst);
|
|
358
|
+
}
|
|
359
|
+
makeLambda(signature, body) {
|
|
360
|
+
return new KotlinLambdaExpression(this, signature, this.resolver, body);
|
|
361
|
+
}
|
|
362
|
+
makeThrowError(message) {
|
|
363
|
+
return new KotlinThrowErrorStatement(message);
|
|
364
|
+
}
|
|
365
|
+
makeReturn(expr) {
|
|
366
|
+
return new TSReturnStatement(expr);
|
|
367
|
+
}
|
|
368
|
+
makeCheckOptional(optional, doStatement) {
|
|
369
|
+
throw new Error("Not implemented");
|
|
370
|
+
}
|
|
371
|
+
makeStatement(expr) {
|
|
372
|
+
return new ExpressionStatement(expr);
|
|
373
|
+
}
|
|
374
|
+
makeLoop(counter, limit, statement) {
|
|
375
|
+
return new KotlinLoopStatement(counter, limit, statement);
|
|
376
|
+
}
|
|
377
|
+
makeMapForEach(map, key, value, op) {
|
|
378
|
+
return new KotlinMapForEachStatement(map, key, value, op);
|
|
379
|
+
}
|
|
380
|
+
writePrintLog(message) {
|
|
381
|
+
throw new Error("Not implemented");
|
|
382
|
+
}
|
|
383
|
+
makeCast(value, node, options) {
|
|
384
|
+
return this.makeString(`${value.asString()} as ${this.getNodeName(node)}`);
|
|
385
|
+
}
|
|
386
|
+
typeInstanceOf(type, value, members) {
|
|
387
|
+
throw new Error("Not implemented");
|
|
388
|
+
}
|
|
389
|
+
getObjectAccessor(convertor, value, args) {
|
|
390
|
+
throw new Error("Not implemented");
|
|
391
|
+
}
|
|
392
|
+
makeUndefined() {
|
|
393
|
+
return this.makeNull();
|
|
394
|
+
}
|
|
395
|
+
makeRuntimeType(rt) {
|
|
396
|
+
return this.makeString(`RuntimeType.${RuntimeType[rt]}.value`);
|
|
397
|
+
}
|
|
398
|
+
makeTupleAlloc(option) {
|
|
399
|
+
throw new Error("Not implemented");
|
|
400
|
+
}
|
|
401
|
+
makeArrayInit(type, size) {
|
|
402
|
+
return this.makeString(`Array<${this.getNodeName(type.elementType[0])}>(${size !== null && size !== void 0 ? size : ''})`);
|
|
403
|
+
}
|
|
404
|
+
makeArrayLength(array, length) {
|
|
405
|
+
return this.makeString(`${array}.size`);
|
|
406
|
+
}
|
|
407
|
+
makeClassInit(type, paramenters) {
|
|
408
|
+
throw new Error("Not implemented");
|
|
409
|
+
}
|
|
410
|
+
makeMapInit(type) {
|
|
411
|
+
return this.makeString(`${this.getNodeName(type)}()`);
|
|
412
|
+
}
|
|
413
|
+
makeMapInsert(keyAccessor, key, valueAccessor, value) {
|
|
414
|
+
return this.makeStatement(this.makeMethodCall(keyAccessor, "set", [this.makeString(key), this.makeString(value)]));
|
|
415
|
+
}
|
|
416
|
+
makeUnwrapOptional(expression) {
|
|
417
|
+
return new KotlinUnwrapOptionalExpression(expression);
|
|
418
|
+
}
|
|
419
|
+
makeDefinedCheck(value) {
|
|
420
|
+
return new KotlinCheckDefinedExpression(value);
|
|
421
|
+
}
|
|
422
|
+
makeUnionSelector(value, valueType) {
|
|
423
|
+
return this.makeAssign(valueType, undefined, this.makeMethodCall(value, "getSelector", []), false);
|
|
424
|
+
}
|
|
425
|
+
makeUnionVariantCast(value, type, convertor, index) {
|
|
426
|
+
return this.makeMethodCall(value, `getValue${index}`, []);
|
|
427
|
+
}
|
|
428
|
+
makeValueFromOption(value, destinationConvertor) {
|
|
429
|
+
return this.makeString(`${value}!!`);
|
|
430
|
+
}
|
|
431
|
+
makeUnionVariantCondition(_convertor, _valueName, valueType, type, _convertorIndex, _runtimeTypeIndex) {
|
|
432
|
+
return this.makeString(`RuntimeType.${type.toUpperCase()}.value == ${valueType}`);
|
|
433
|
+
}
|
|
434
|
+
makeRuntimeTypeCondition(typeVarName, equals, type, varName) {
|
|
435
|
+
if (varName) {
|
|
436
|
+
return this.makeDefinedCheck(varName);
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
const op = equals ? "==" : "!=";
|
|
440
|
+
return this.makeNaryOp(op, [this.makeRuntimeType(type), this.makeString(`${typeVarName}.toInt()`)]);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
getTagType() {
|
|
444
|
+
return idl.createReferenceType("Tag");
|
|
445
|
+
}
|
|
446
|
+
getRuntimeType() {
|
|
447
|
+
return idl.IDLNumberType;
|
|
448
|
+
}
|
|
449
|
+
makeTupleAssign(receiver, fields) {
|
|
450
|
+
throw new Error("Not implemented");
|
|
451
|
+
}
|
|
452
|
+
get supportedModifiers() {
|
|
453
|
+
return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.OVERRIDE];
|
|
454
|
+
}
|
|
455
|
+
get supportedFieldModifiers() {
|
|
456
|
+
return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY];
|
|
457
|
+
}
|
|
458
|
+
enumFromI32(value, enumEntry) {
|
|
459
|
+
return this.makeString(`${this.getNodeName(enumEntry)}(${value.asString()})`);
|
|
460
|
+
}
|
|
461
|
+
i32FromEnum(value, enumEntry) {
|
|
462
|
+
return this.makeString(`${value.asString()}.value`);
|
|
463
|
+
}
|
|
464
|
+
makeEnumEntity(enumEntity, options) {
|
|
465
|
+
return new KotlinEnumWithGetter(enumEntity, options.isExport);
|
|
466
|
+
}
|
|
467
|
+
castToBoolean(value) {
|
|
468
|
+
return `if (${value}) { 1 } else { 0 }`;
|
|
469
|
+
}
|
|
470
|
+
castToInt(value, bitness) {
|
|
471
|
+
return `${this.escapeKeyword(value)}.${bitness == 8 ? 'toByte()' : 'toInt()'}`;
|
|
472
|
+
}
|
|
473
|
+
makeCallIsObject(value) {
|
|
474
|
+
throw new Error("Not implemented");
|
|
475
|
+
}
|
|
476
|
+
makeNewObject(objectName, params = []) {
|
|
477
|
+
return new KotlinNewObjectExpression(objectName, params);
|
|
478
|
+
}
|
|
479
|
+
escapeKeyword(keyword) {
|
|
480
|
+
return keyword;
|
|
481
|
+
}
|
|
482
|
+
makeDiscriminatorConvertor(convertor, value, index) {
|
|
483
|
+
throw new Error("Not implemented");
|
|
484
|
+
}
|
|
485
|
+
makeStaticBlock(op) {
|
|
486
|
+
this.printer.print('companion object {');
|
|
487
|
+
this.printer.pushIndent();
|
|
488
|
+
op(this);
|
|
489
|
+
this.popIndent();
|
|
490
|
+
this.printer.print('}');
|
|
491
|
+
}
|
|
492
|
+
pushNamespace(namespace, options) { }
|
|
493
|
+
popNamespace(options) { }
|
|
494
|
+
}
|
|
495
|
+
//# sourceMappingURL=KotlinLanguageWriter.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as idl from '../../idl';
|
|
2
2
|
import { Language } from '../../Language';
|
|
3
3
|
import { IndentedPrinter } from "../../IndentedPrinter";
|
|
4
|
-
import { FieldModifier, LambdaExpression, LanguageExpression, LanguageStatement, LanguageWriter, MakeAssignOptions, MakeCastOptions, Method, MethodModifier, MethodSignature, NamedMethodSignature, ObjectArgs, ReturnStatement } from "../LanguageWriter";
|
|
4
|
+
import { DelegationCall, FieldModifier, LambdaExpression, LanguageExpression, LanguageStatement, LanguageWriter, MakeAssignOptions, MakeCastOptions, Method, MethodModifier, MethodSignature, NamedMethodSignature, ObjectArgs, ReturnStatement } from "../LanguageWriter";
|
|
5
5
|
import { ArgConvertor } from "../ArgConvertors";
|
|
6
6
|
import { IdlNameConvertor } from "../nameConvertor";
|
|
7
7
|
import { RuntimeType } from "../common";
|
|
@@ -32,15 +32,18 @@ export declare class TSLanguageWriter extends LanguageWriter {
|
|
|
32
32
|
protected typeConvertor: IdlNameConvertor;
|
|
33
33
|
constructor(printer: IndentedPrinter, resolver: ReferenceResolver, typeConvertor: IdlNameConvertor, language?: Language);
|
|
34
34
|
maybeSemicolon(): string;
|
|
35
|
-
pushNamespace(namespace: string,
|
|
35
|
+
pushNamespace(namespace: string, options: {
|
|
36
|
+
ident: boolean;
|
|
37
|
+
isDeclared?: boolean;
|
|
38
|
+
}): void;
|
|
36
39
|
fork(options?: {
|
|
37
40
|
resolver?: ReferenceResolver;
|
|
38
41
|
}): LanguageWriter;
|
|
39
42
|
getNodeName(type: idl.IDLNode): string;
|
|
40
43
|
writeClass(name: string, op: (writer: this) => void, superClass?: string, interfaces?: string[], generics?: string[], isDeclared?: boolean, isAbstract?: boolean): void;
|
|
41
44
|
writeInterface(name: string, op: (writer: this) => void, superInterfaces?: string[], generics?: string[], isDeclared?: boolean): void;
|
|
42
|
-
writeFunctionDeclaration(name: string, signature: MethodSignature): void;
|
|
43
|
-
writeFunctionImplementation(name: string, signature: MethodSignature, op: (writer: this) => void): void;
|
|
45
|
+
writeFunctionDeclaration(name: string, signature: MethodSignature, generics?: string[]): void;
|
|
46
|
+
writeFunctionImplementation(name: string, signature: MethodSignature, op: (writer: this) => void, generics?: string[]): void;
|
|
44
47
|
private generateFunctionDeclaration;
|
|
45
48
|
writeEnum(name: string, members: {
|
|
46
49
|
name: string;
|
|
@@ -54,7 +57,7 @@ export declare class TSLanguageWriter extends LanguageWriter {
|
|
|
54
57
|
writeFieldDeclaration(name: string, type: idl.IDLType, modifiers: FieldModifier[] | undefined, optional: boolean, initExpr?: LanguageExpression): void;
|
|
55
58
|
writeNativeMethodDeclaration(method: Method): void;
|
|
56
59
|
writeMethodDeclaration(name: string, signature: MethodSignature, modifiers?: MethodModifier[]): void;
|
|
57
|
-
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void,
|
|
60
|
+
writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, delegationCall?: DelegationCall, modifiers?: MethodModifier[]): void;
|
|
58
61
|
writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
59
62
|
writeProperty(propName: string, propType: idl.IDLType, modifiers: FieldModifier[], getter?: {
|
|
60
63
|
method: Method;
|
|
@@ -16,7 +16,7 @@ import * as idl from '../../idl';
|
|
|
16
16
|
import { isOptionalType } from '../../idl';
|
|
17
17
|
import { Language } from '../../Language';
|
|
18
18
|
import { IndentedPrinter } from "../../IndentedPrinter";
|
|
19
|
-
import { AssignStatement, BlockStatement, CheckOptionalStatement, ExpressionStatement, FieldModifier, IfStatement, LambdaExpression, LanguageWriter, Method, MethodModifier, MethodSignature, NamedMethodSignature, NaryOpExpression, ReturnStatement, StringExpression } from "../LanguageWriter";
|
|
19
|
+
import { AssignStatement, BlockStatement, CheckOptionalStatement, DelegationType, ExpressionStatement, FieldModifier, IfStatement, LambdaExpression, LanguageWriter, Method, MethodModifier, MethodSignature, NamedMethodSignature, NaryOpExpression, ReturnStatement, StringExpression } from "../LanguageWriter";
|
|
20
20
|
import { RuntimeType } from "../common";
|
|
21
21
|
import { rightmostIndexOf, throwException } from "../../util";
|
|
22
22
|
import { TSKeywords } from '../../languageSpecificKeywords';
|
|
@@ -124,10 +124,11 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
124
124
|
this.typeConvertor = typeConvertor;
|
|
125
125
|
}
|
|
126
126
|
maybeSemicolon() { return ""; }
|
|
127
|
-
pushNamespace(namespace,
|
|
127
|
+
pushNamespace(namespace, options) {
|
|
128
128
|
this.namespaceStack.push(namespace);
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
const declaredPrefix = options.isDeclared ? "declare " : "";
|
|
130
|
+
this.print(`export ${declaredPrefix}namespace ${namespace} {`);
|
|
131
|
+
if (options.ident)
|
|
131
132
|
this.pushIndent();
|
|
132
133
|
}
|
|
133
134
|
fork(options) {
|
|
@@ -165,24 +166,25 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
165
166
|
this.popIndent();
|
|
166
167
|
this.printer.print(`}`);
|
|
167
168
|
}
|
|
168
|
-
writeFunctionDeclaration(name, signature) {
|
|
169
|
-
this.printer.print(this.generateFunctionDeclaration(name, signature));
|
|
169
|
+
writeFunctionDeclaration(name, signature, generics) {
|
|
170
|
+
this.printer.print(this.generateFunctionDeclaration(name, signature, generics));
|
|
170
171
|
}
|
|
171
|
-
writeFunctionImplementation(name, signature, op) {
|
|
172
|
-
this.printer.print(`${this.generateFunctionDeclaration(name, signature)} {`);
|
|
172
|
+
writeFunctionImplementation(name, signature, op, generics) {
|
|
173
|
+
this.printer.print(`${this.generateFunctionDeclaration(name, signature, generics)} {`);
|
|
173
174
|
this.printer.pushIndent();
|
|
174
175
|
op(this);
|
|
175
176
|
this.printer.popIndent();
|
|
176
177
|
this.printer.print('}');
|
|
177
178
|
}
|
|
178
|
-
generateFunctionDeclaration(name, signature) {
|
|
179
|
+
generateFunctionDeclaration(name, signature, generics) {
|
|
179
180
|
const rightmostRegularParameterIndex = rightmostIndexOf(signature.args, it => !isOptionalType(it));
|
|
180
181
|
const args = signature.args.map((it, index) => {
|
|
181
182
|
const optionalToken = idl.isOptionalType(it) && index > rightmostRegularParameterIndex ? '?' : '';
|
|
182
183
|
return `${signature.argName(index)}${optionalToken}: ${this.getNodeName(it)}`;
|
|
183
184
|
});
|
|
184
185
|
const returnType = this.getNodeName(signature.returnType);
|
|
185
|
-
|
|
186
|
+
const typeParams = generics && generics.length ? '<' + (generics === null || generics === void 0 ? void 0 : generics.join(', ')) + '>' : '';
|
|
187
|
+
return `export function ${name}${typeParams}(${args.join(", ")}): ${returnType}`;
|
|
186
188
|
}
|
|
187
189
|
writeEnum(name, members, options) {
|
|
188
190
|
this.printer.print(`${options.isExport ? "export " : ""}${options.isDeclare ? "declare " : ""}enum ${name} {`);
|
|
@@ -222,11 +224,13 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
222
224
|
writeMethodDeclaration(name, signature, modifiers) {
|
|
223
225
|
this.writeDeclaration(name, signature, true, false, modifiers);
|
|
224
226
|
}
|
|
225
|
-
writeConstructorImplementation(className, signature, op,
|
|
227
|
+
writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
|
|
228
|
+
var _a;
|
|
226
229
|
this.writeDeclaration(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') + ' ' : ''}constructor`, signature, false, true);
|
|
227
230
|
this.pushIndent();
|
|
228
|
-
if (
|
|
229
|
-
|
|
231
|
+
if (delegationCall) {
|
|
232
|
+
const delegationType = ((delegationCall === null || delegationCall === void 0 ? void 0 : delegationCall.delegationType) == DelegationType.THIS) ? "this" : "super";
|
|
233
|
+
this.print(`${delegationType}(${(_a = delegationCall.delegationArgs) === null || _a === void 0 ? void 0 : _a.map(it => it.asString()).join(", ")})`);
|
|
230
234
|
}
|
|
231
235
|
op(this);
|
|
232
236
|
this.popIndent();
|
|
@@ -2,6 +2,7 @@ import * as idl from "./idl";
|
|
|
2
2
|
import { Language } from "./Language";
|
|
3
3
|
import { IdlNameConvertor } from "./LanguageWriters";
|
|
4
4
|
import { ArgConvertor } from "./LanguageWriters/ArgConvertors";
|
|
5
|
+
import { LayoutManager } from "./peer-generation/LayoutManager";
|
|
5
6
|
import { ReferenceResolver } from "./peer-generation/ReferenceResolver";
|
|
6
7
|
export interface LibraryInterface extends ReferenceResolver {
|
|
7
8
|
language: Language;
|
|
@@ -12,6 +13,7 @@ export interface LibraryInterface extends ReferenceResolver {
|
|
|
12
13
|
createTypeNameConvertor(language: Language): IdlNameConvertor;
|
|
13
14
|
createContinuationCallbackReference(continuationType: idl.IDLType): idl.IDLReferenceType;
|
|
14
15
|
getCurrentContext(): string | undefined;
|
|
16
|
+
layout: LayoutManager;
|
|
15
17
|
/**
|
|
16
18
|
* todo: is it really needed?
|
|
17
19
|
*/
|