@idlizer/core 2.0.15
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.d.ts +28 -0
- package/build/lib/src/IndentedPrinter.js +81 -0
- package/build/lib/src/Language.d.ts +15 -0
- package/build/lib/src/Language.js +42 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
- package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
- package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
- package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
- package/build/lib/src/LanguageWriters/common.d.ts +17 -0
- package/build/lib/src/LanguageWriters/common.js +33 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
- package/build/lib/src/LanguageWriters/index.d.ts +3 -0
- package/build/lib/src/LanguageWriters/index.js +3 -0
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
- package/build/lib/src/LibraryInterface.d.ts +21 -0
- package/build/lib/src/LibraryInterface.js +2 -0
- package/build/lib/src/config.d.ts +8 -0
- package/build/lib/src/config.js +20 -0
- package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
- package/build/lib/src/from-idl/DtsPrinter.js +375 -0
- package/build/lib/src/from-idl/common.d.ts +5 -0
- package/build/lib/src/from-idl/common.js +83 -0
- package/build/lib/src/from-idl/deserialize.d.ts +9 -0
- package/build/lib/src/from-idl/deserialize.js +384 -0
- package/build/lib/src/from-idl/toString.d.ts +2 -0
- package/build/lib/src/from-idl/toString.js +18 -0
- package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
- package/build/lib/src/from-idl/webidl2-utils.js +84 -0
- package/build/lib/src/idl.d.ts +404 -0
- package/build/lib/src/idl.js +1015 -0
- package/build/lib/src/idlize.d.ts +4 -0
- package/build/lib/src/idlize.js +52 -0
- package/build/lib/src/index.d.ts +34 -0
- package/build/lib/src/index.js +48 -0
- package/build/lib/src/inheritance.d.ts +16 -0
- package/build/lib/src/inheritance.js +76 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
- package/build/lib/src/languageSpecificKeywords.js +51 -0
- package/build/lib/src/library.d.ts +67 -0
- package/build/lib/src/library.js +190 -0
- package/build/lib/src/options.d.ts +11 -0
- package/build/lib/src/options.js +16 -0
- package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
- package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
- package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
- package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
- package/build/lib/src/peer-generation/idl/common.js +70 -0
- package/build/lib/src/peer-generation/unions.d.ts +29 -0
- package/build/lib/src/peer-generation/unions.js +111 -0
- package/build/lib/src/rand_utils.d.ts +6 -0
- package/build/lib/src/rand_utils.js +100 -0
- package/build/lib/src/util.d.ts +75 -0
- package/build/lib/src/util.js +622 -0
- package/package.json +49 -0
- package/webidl2.js/LICENSE +21 -0
- package/webidl2.js/README.md +827 -0
- package/webidl2.js/dist/package.json +3 -0
- package/webidl2.js/dist/webidl2.js +4547 -0
- package/webidl2.js/package.json +55 -0
|
@@ -0,0 +1,578 @@
|
|
|
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 { IndentedPrinter } from "../../IndentedPrinter";
|
|
17
|
+
import { CJKeywords } from "../../languageSpecificKeywords";
|
|
18
|
+
import { RuntimeType } from "../common";
|
|
19
|
+
import { AssignStatement, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, MethodModifier, MethodSignature, ReturnStatement, StringExpression } from "../LanguageWriter";
|
|
20
|
+
import { Language } from "../../Language";
|
|
21
|
+
import { isDefined } from "../../util";
|
|
22
|
+
////////////////////////////////////////////////////////////////
|
|
23
|
+
// EXPRESSIONS //
|
|
24
|
+
////////////////////////////////////////////////////////////////
|
|
25
|
+
class CJLambdaExpression extends LambdaExpression {
|
|
26
|
+
constructor(writer, signature, resolver, body) {
|
|
27
|
+
super(writer, signature, resolver, body);
|
|
28
|
+
this.writer = writer;
|
|
29
|
+
}
|
|
30
|
+
get statementHasSemicolon() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
asString() {
|
|
34
|
+
const params = this.signature.args.map((it, i) => `${this.signature.argName(i)}: ${this.writer.getNodeName(it)}`);
|
|
35
|
+
return `{${params.join(", ")} => ${this.bodyAsString()} }`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class CJCheckDefinedExpression {
|
|
39
|
+
constructor(value) {
|
|
40
|
+
this.value = value;
|
|
41
|
+
}
|
|
42
|
+
asString() {
|
|
43
|
+
return `${this.value}.isSome()`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class CJCastExpression {
|
|
47
|
+
constructor(value, type, unsafe = false) {
|
|
48
|
+
this.value = value;
|
|
49
|
+
this.type = type;
|
|
50
|
+
this.unsafe = unsafe;
|
|
51
|
+
}
|
|
52
|
+
asString() {
|
|
53
|
+
return `match (${this.value.asString()} as ${this.type}) { case Some(x) => x; case None => throw Exception("Cast is not succeeded")}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class CJUnionCastExpression {
|
|
57
|
+
constructor(value, type, unsafe = false) {
|
|
58
|
+
this.value = value;
|
|
59
|
+
this.type = type;
|
|
60
|
+
this.unsafe = unsafe;
|
|
61
|
+
}
|
|
62
|
+
asString() {
|
|
63
|
+
return `${this.type}(${this.value.asString})`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class CJMatchExpression {
|
|
67
|
+
constructor(matchValue, matchCases, caseBlocks) {
|
|
68
|
+
this.matchValue = matchValue;
|
|
69
|
+
this.matchCases = matchCases;
|
|
70
|
+
this.caseBlocks = caseBlocks;
|
|
71
|
+
}
|
|
72
|
+
asString() {
|
|
73
|
+
let output = [];
|
|
74
|
+
output.push(`match (${this.matchValue.asString()}) {`);
|
|
75
|
+
for (let index in this.matchCases) {
|
|
76
|
+
output.push(`case ${this.matchCases[index].asString()} => ${this.caseBlocks[index].asString()} `);
|
|
77
|
+
}
|
|
78
|
+
output.push(`case _ => throw Exception(\"Unmatched pattern ${this.matchValue.asString()}\")`);
|
|
79
|
+
output.push(`}`);
|
|
80
|
+
return output.join('\n');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export class CJTernaryExpression {
|
|
84
|
+
constructor(condition, trueExpression, falseExpression) {
|
|
85
|
+
this.condition = condition;
|
|
86
|
+
this.trueExpression = trueExpression;
|
|
87
|
+
this.falseExpression = falseExpression;
|
|
88
|
+
}
|
|
89
|
+
asString() {
|
|
90
|
+
return `if (${this.condition.asString()}) { ${this.trueExpression.asString()} } else { ${this.falseExpression.asString()} }`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export class CJNewObjectExpression {
|
|
94
|
+
constructor(objectName, params) {
|
|
95
|
+
this.objectName = objectName;
|
|
96
|
+
this.params = params;
|
|
97
|
+
}
|
|
98
|
+
asString() {
|
|
99
|
+
return `${this.objectName}(${this.params.map(it => it.asString()).join(", ")})`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
////////////////////////////////////////////////////////////////
|
|
103
|
+
// STATEMENTS //
|
|
104
|
+
////////////////////////////////////////////////////////////////
|
|
105
|
+
export class CJAssignStatement extends AssignStatement {
|
|
106
|
+
constructor(variableName, type, expression, isDeclared = true, isConst = true) {
|
|
107
|
+
super(variableName, type, expression, isDeclared, isConst);
|
|
108
|
+
this.variableName = variableName;
|
|
109
|
+
this.type = type;
|
|
110
|
+
this.expression = expression;
|
|
111
|
+
this.isDeclared = isDeclared;
|
|
112
|
+
this.isConst = isConst;
|
|
113
|
+
}
|
|
114
|
+
write(writer) {
|
|
115
|
+
var _a;
|
|
116
|
+
if (this.isDeclared) {
|
|
117
|
+
const typeSpec = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.overrideTypeName)
|
|
118
|
+
? `: ${this.options.overrideTypeName}`
|
|
119
|
+
: this.type ? `: ${writer.getNodeName(this.type)}` : "";
|
|
120
|
+
const constSpec = this.isConst ? "let" : "var";
|
|
121
|
+
const initValue = this.expression ? `= ${this.expression.asString()}` : "";
|
|
122
|
+
writer.print(`${constSpec} ${this.variableName}${typeSpec} ${initValue}`);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
writer.print(`${this.variableName} = ${this.expression.asString()}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class CJLoopStatement {
|
|
130
|
+
constructor(counter, limit, statement) {
|
|
131
|
+
this.counter = counter;
|
|
132
|
+
this.limit = limit;
|
|
133
|
+
this.statement = statement;
|
|
134
|
+
}
|
|
135
|
+
write(writer) {
|
|
136
|
+
writer.print(`for (${this.counter} in 0..${this.limit}) {`);
|
|
137
|
+
if (this.statement) {
|
|
138
|
+
writer.pushIndent();
|
|
139
|
+
this.statement.write(writer);
|
|
140
|
+
writer.popIndent();
|
|
141
|
+
writer.print("}");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
class CJMapForEachStatement {
|
|
146
|
+
constructor(map, key, value, op) {
|
|
147
|
+
this.map = map;
|
|
148
|
+
this.key = key;
|
|
149
|
+
this.value = value;
|
|
150
|
+
this.op = op;
|
|
151
|
+
}
|
|
152
|
+
write(writer) {
|
|
153
|
+
writer.print(`for ((key, value) in ${this.map}) {`);
|
|
154
|
+
writer.pushIndent();
|
|
155
|
+
this.op();
|
|
156
|
+
writer.popIndent();
|
|
157
|
+
writer.print(`}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class CJEnumWithGetter {
|
|
161
|
+
constructor(enumEntity, isExport) {
|
|
162
|
+
this.enumEntity = enumEntity;
|
|
163
|
+
this.isExport = isExport;
|
|
164
|
+
}
|
|
165
|
+
write(writer) {
|
|
166
|
+
const initializers = this.enumEntity.elements.map(it => {
|
|
167
|
+
return { name: it.name, id: it.initializer };
|
|
168
|
+
});
|
|
169
|
+
const isStringEnum = initializers.every(it => typeof it.id == 'string');
|
|
170
|
+
let memberValue = 0;
|
|
171
|
+
const members = [];
|
|
172
|
+
for (const initializer of initializers) {
|
|
173
|
+
if (typeof initializer.id == 'string') {
|
|
174
|
+
members.push({ name: initializer.name, stringId: initializer.id, numberId: memberValue });
|
|
175
|
+
}
|
|
176
|
+
else if (typeof initializer.id == 'number') {
|
|
177
|
+
memberValue = initializer.id;
|
|
178
|
+
members.push({ name: initializer.name, stringId: undefined, numberId: memberValue });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
members.push({ name: initializer.name, stringId: undefined, numberId: memberValue });
|
|
182
|
+
}
|
|
183
|
+
memberValue += 1;
|
|
184
|
+
}
|
|
185
|
+
let enumName = this.enumEntity.name;
|
|
186
|
+
writer.writeClass(enumName, () => {
|
|
187
|
+
const enumType = idl.createReferenceType(enumName, undefined, this.enumEntity);
|
|
188
|
+
members.forEach(it => {
|
|
189
|
+
writer.writeFieldDeclaration(it.name, enumType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.FINAL], false, writer.makeString(`${enumName}(${it.numberId})`));
|
|
190
|
+
});
|
|
191
|
+
const value = 'value';
|
|
192
|
+
const intType = idl.IDLI32Type;
|
|
193
|
+
writer.writeFieldDeclaration(value, intType, [FieldModifier.PUBLIC, FieldModifier.FINAL], false);
|
|
194
|
+
const signature = new MethodSignature(idl.IDLVoidType, [intType]);
|
|
195
|
+
writer.writeConstructorImplementation(enumName, signature, () => {
|
|
196
|
+
writer.writeStatement(writer.makeAssign(value, undefined, writer.makeString(signature.argName(0)), false));
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export class CJEnumEntityStatement {
|
|
202
|
+
constructor(enumEntity, isExport) {
|
|
203
|
+
this.enumEntity = enumEntity;
|
|
204
|
+
this.isExport = isExport;
|
|
205
|
+
}
|
|
206
|
+
write(writer) {
|
|
207
|
+
writer.print(this.enumEntity.comment);
|
|
208
|
+
writer.print(`${this.isExport ? "public " : ""}enum ${this.enumEntity.name} {`);
|
|
209
|
+
writer.pushIndent();
|
|
210
|
+
this.enumEntity.elements.forEach((member, index) => {
|
|
211
|
+
writer.print(member.comment);
|
|
212
|
+
const varticalBar = index < this.enumEntity.elements.length - 1 ? '|' : '';
|
|
213
|
+
const initValue = member.initializer ? ` = ${member.initializer}` : ``;
|
|
214
|
+
writer.print(`${member.name}${initValue}${varticalBar}`);
|
|
215
|
+
});
|
|
216
|
+
writer.popIndent();
|
|
217
|
+
writer.print(`}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
class CJThrowErrorStatement {
|
|
221
|
+
constructor(message) {
|
|
222
|
+
this.message = message;
|
|
223
|
+
}
|
|
224
|
+
write(writer) {
|
|
225
|
+
writer.print(`throw Exception("${this.message}")`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
class CJCheckOptionalStatement {
|
|
229
|
+
constructor(undefinedValue, optionalExpression, doStatement) {
|
|
230
|
+
this.undefinedValue = undefinedValue;
|
|
231
|
+
this.optionalExpression = optionalExpression;
|
|
232
|
+
this.doStatement = doStatement;
|
|
233
|
+
}
|
|
234
|
+
write(writer) {
|
|
235
|
+
writer.print(`if (let Some(${this.optionalExpression.asString()}) <- ${this.optionalExpression.asString()}) {`);
|
|
236
|
+
writer.pushIndent();
|
|
237
|
+
this.doStatement.write(writer);
|
|
238
|
+
writer.popIndent();
|
|
239
|
+
writer.print('}');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
class CJArrayResizeStatement {
|
|
243
|
+
constructor(array, arrayType, length, deserializer) {
|
|
244
|
+
this.array = array;
|
|
245
|
+
this.arrayType = arrayType;
|
|
246
|
+
this.length = length;
|
|
247
|
+
this.deserializer = deserializer;
|
|
248
|
+
}
|
|
249
|
+
write(writer) {
|
|
250
|
+
writer.print(`${this.array} = ${this.arrayType}(Int64(${this.length}))`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
////////////////////////////////////////////////////////////////
|
|
254
|
+
// WRITER //
|
|
255
|
+
////////////////////////////////////////////////////////////////
|
|
256
|
+
export class CJLanguageWriter extends LanguageWriter {
|
|
257
|
+
constructor(printer, resolver, typeConvertor, typeForeignConvertor, language = Language.CJ) {
|
|
258
|
+
super(printer, resolver, language);
|
|
259
|
+
this.typeConvertor = typeConvertor;
|
|
260
|
+
this.typeForeignConvertor = typeForeignConvertor;
|
|
261
|
+
}
|
|
262
|
+
fork(options) {
|
|
263
|
+
var _a;
|
|
264
|
+
return new CJLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.typeForeignConvertor);
|
|
265
|
+
}
|
|
266
|
+
getNodeName(type) {
|
|
267
|
+
return this.typeConvertor.convert(type);
|
|
268
|
+
}
|
|
269
|
+
writeClass(name, op, superClass, interfaces, generics) {
|
|
270
|
+
let extendsClause = superClass ? `${superClass}` : undefined;
|
|
271
|
+
let implementsClause = interfaces ? `${interfaces.join(' & ')}` : undefined;
|
|
272
|
+
let inheritancePart = [extendsClause, implementsClause]
|
|
273
|
+
.filter(isDefined)
|
|
274
|
+
.join(' & ');
|
|
275
|
+
inheritancePart = inheritancePart.length != 0 ? ' <: '.concat(inheritancePart) : '';
|
|
276
|
+
this.printer.print(`public open class ${name}${inheritancePart} {`);
|
|
277
|
+
this.pushIndent();
|
|
278
|
+
op(this);
|
|
279
|
+
this.popIndent();
|
|
280
|
+
this.printer.print(`}`);
|
|
281
|
+
}
|
|
282
|
+
writeEnum(name, members, op) {
|
|
283
|
+
this.printer.print(`public enum ${name}{`);
|
|
284
|
+
this.pushIndent();
|
|
285
|
+
for (const member of members) {
|
|
286
|
+
this.print('|'.concat(member.name));
|
|
287
|
+
}
|
|
288
|
+
op(this);
|
|
289
|
+
this.popIndent();
|
|
290
|
+
this.printer.print(`}`);
|
|
291
|
+
}
|
|
292
|
+
writeInterface(name, op, superInterfaces) {
|
|
293
|
+
let extendsClause = superInterfaces ? ` <: ${superInterfaces.join(" & ")}` : '';
|
|
294
|
+
this.printer.print(`public interface ${name}${extendsClause} {`);
|
|
295
|
+
this.pushIndent();
|
|
296
|
+
op(this);
|
|
297
|
+
this.popIndent();
|
|
298
|
+
this.printer.print(`}`);
|
|
299
|
+
}
|
|
300
|
+
writeFunctionDeclaration(name, signature) {
|
|
301
|
+
this.printer.print(this.generateFunctionDeclaration(name, signature));
|
|
302
|
+
}
|
|
303
|
+
writeFunctionImplementation(name, signature, op) {
|
|
304
|
+
this.printer.print(`${this.generateFunctionDeclaration(name, signature)} {`);
|
|
305
|
+
this.printer.pushIndent();
|
|
306
|
+
op(this);
|
|
307
|
+
this.printer.popIndent();
|
|
308
|
+
this.printer.print('}');
|
|
309
|
+
}
|
|
310
|
+
generateFunctionDeclaration(name, signature) {
|
|
311
|
+
const args = signature.args.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}`);
|
|
312
|
+
return `public func ${name}(${args.join(", ")})`;
|
|
313
|
+
}
|
|
314
|
+
writeMethodCall(receiver, method, params, nullable = false) {
|
|
315
|
+
params = params.map(argName => this.escapeKeyword(argName));
|
|
316
|
+
if (nullable) {
|
|
317
|
+
if (receiver == 'this') {
|
|
318
|
+
this.printer.print('let thisObj = this');
|
|
319
|
+
super.writeMethodCall('thisObj', method, params, false);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.printer.print(`if (let Some(${receiver}) <- ${receiver}) { ${receiver}.${method}(${params.join(", ")}) }`);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
super.writeMethodCall(receiver, method, params, nullable);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
|
|
329
|
+
const init = initExpr != undefined ? ` = ${initExpr.asString()}` : ``;
|
|
330
|
+
name = this.escapeKeyword(name);
|
|
331
|
+
let prefix = this.makeFieldModifiersList(modifiers);
|
|
332
|
+
this.printer.print(`${prefix ? prefix.concat(" ") : ""}var ${name}: ${this.getNodeName(type)}${init}`);
|
|
333
|
+
}
|
|
334
|
+
writeMethodDeclaration(name, signature, modifiers) {
|
|
335
|
+
this.writeDeclaration(name, signature, modifiers);
|
|
336
|
+
}
|
|
337
|
+
writeConstructorImplementation(className, signature, op, superCall, modifiers) {
|
|
338
|
+
this.printer.print(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') + ' ' : ''}${className}(${signature.args.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}`).join(", ")}) {`);
|
|
339
|
+
this.pushIndent();
|
|
340
|
+
if (superCall) {
|
|
341
|
+
this.print(`super(${superCall.signature.args.map((_, i) => superCall === null || superCall === void 0 ? void 0 : superCall.signature.argName(i)).join(", ")})`);
|
|
342
|
+
}
|
|
343
|
+
op(this);
|
|
344
|
+
this.popIndent();
|
|
345
|
+
this.printer.print(`}`);
|
|
346
|
+
}
|
|
347
|
+
writeProperty(propName, propType, mutable, getterLambda, setterLambda) {
|
|
348
|
+
let shortName = propName.concat("_container");
|
|
349
|
+
if (!getterLambda) {
|
|
350
|
+
this.print(`private var ${shortName}: ${this.getNodeName(propType)}`);
|
|
351
|
+
}
|
|
352
|
+
this.print(`${mutable ? "mut " : ""}prop ${propName}: ${this.getNodeName(propType)} {`);
|
|
353
|
+
this.pushIndent();
|
|
354
|
+
this.print(`get() {`);
|
|
355
|
+
this.pushIndent();
|
|
356
|
+
if (getterLambda) {
|
|
357
|
+
getterLambda(this);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.print(`return ${shortName}`);
|
|
361
|
+
}
|
|
362
|
+
this.popIndent();
|
|
363
|
+
this.print(`}`);
|
|
364
|
+
if (mutable) {
|
|
365
|
+
this.print(`set(x) { ${shortName} = x }`);
|
|
366
|
+
this.pushIndent();
|
|
367
|
+
if (setterLambda)
|
|
368
|
+
setterLambda(this);
|
|
369
|
+
this.popIndent();
|
|
370
|
+
}
|
|
371
|
+
this.popIndent();
|
|
372
|
+
this.print(`}`);
|
|
373
|
+
}
|
|
374
|
+
writeMethodImplementation(method, op) {
|
|
375
|
+
this.writeDeclaration(method.name, method.signature, method.modifiers, " {");
|
|
376
|
+
this.pushIndent();
|
|
377
|
+
op(this);
|
|
378
|
+
this.popIndent();
|
|
379
|
+
this.printer.print(`}`);
|
|
380
|
+
}
|
|
381
|
+
writeCJForeign(op) {
|
|
382
|
+
this.print(`foreign {`);
|
|
383
|
+
this.pushIndent();
|
|
384
|
+
op(this);
|
|
385
|
+
this.popIndent();
|
|
386
|
+
this.print('}');
|
|
387
|
+
}
|
|
388
|
+
writeDeclaration(name, signature, modifiers, postfix) {
|
|
389
|
+
let prefix = modifiers === null || modifiers === void 0 ? void 0 : modifiers.filter(it => this.supportedModifiers.includes(it)).map(it => this.mapMethodModifier(it)).join(" ");
|
|
390
|
+
prefix = prefix ? prefix + " " : "";
|
|
391
|
+
this.print(`${prefix}func ${name}(${signature.args.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}`).join(", ")}): ${this.getNodeName(signature.returnType)}${postfix !== null && postfix !== void 0 ? postfix : ""}`);
|
|
392
|
+
}
|
|
393
|
+
writeNativeFunctionCall(printer, name, signature) {
|
|
394
|
+
printer.print(`return unsafe { ${name}(${signature.args.map((it, index) => `${signature.argName(index)}`).join(", ")}) }`);
|
|
395
|
+
}
|
|
396
|
+
writeNativeMethodDeclaration(name, signature) {
|
|
397
|
+
let signture = `${signature.args.map((it, index) => `${this.escapeKeyword(signature.argName(index))}: ${this.typeForeignConvertor.convert(it)}`).join(", ")}`;
|
|
398
|
+
this.print(`func ${name}(${signture}): ${this.typeForeignConvertor.convert(signature.returnType)}`);
|
|
399
|
+
}
|
|
400
|
+
makeEnumCast(enumName, _unsafe, _convertor) {
|
|
401
|
+
return `${enumName}.value`;
|
|
402
|
+
}
|
|
403
|
+
makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
|
|
404
|
+
return new CJAssignStatement(variableName, type, expr, isDeclared, isConst);
|
|
405
|
+
}
|
|
406
|
+
makeClassInit(type, parameters) {
|
|
407
|
+
throw new Error(`makeClassInit`);
|
|
408
|
+
}
|
|
409
|
+
makeArrayInit(type, size) {
|
|
410
|
+
return this.makeString(`ArrayList<${this.getNodeName(type.elementType[0])}>(${size !== null && size !== void 0 ? size : ''})`);
|
|
411
|
+
}
|
|
412
|
+
makeMapInit(type) {
|
|
413
|
+
throw new Error(`TBD`);
|
|
414
|
+
}
|
|
415
|
+
makeArrayLength(array, length) {
|
|
416
|
+
return this.makeString(`${array}.size`);
|
|
417
|
+
}
|
|
418
|
+
makeArrayResize(array, arrayType, length, deserializer) {
|
|
419
|
+
return new CJArrayResizeStatement(array, arrayType, length, deserializer);
|
|
420
|
+
}
|
|
421
|
+
makeArrayAccess(value, indexVar) {
|
|
422
|
+
return this.makeString(`${value}[Int64(${indexVar})]`);
|
|
423
|
+
}
|
|
424
|
+
makeRuntimeTypeCondition(typeVarName, equals, type, varName) {
|
|
425
|
+
if (varName) {
|
|
426
|
+
varName = this.escapeKeyword(varName);
|
|
427
|
+
return this.makeString(`let Some(${varName}) <- ${varName}`);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
const op = equals ? "==" : "!=";
|
|
431
|
+
return this.makeNaryOp(op, [this.makeRuntimeType(type), this.makeString(`Int32(${typeVarName})`)]);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
makeLambda(signature, body) {
|
|
435
|
+
return new CJLambdaExpression(this, signature, this.resolver, body);
|
|
436
|
+
}
|
|
437
|
+
makeThrowError(message) {
|
|
438
|
+
return new CJThrowErrorStatement(message);
|
|
439
|
+
}
|
|
440
|
+
makeTernary(condition, trueExpression, falseExpression) {
|
|
441
|
+
return new CJTernaryExpression(condition, trueExpression, falseExpression);
|
|
442
|
+
}
|
|
443
|
+
makeReturn(expr) {
|
|
444
|
+
return new ReturnStatement(expr);
|
|
445
|
+
}
|
|
446
|
+
makeCheckOptional(optional, doStatement) {
|
|
447
|
+
return new CJCheckOptionalStatement("undefined", optional, doStatement);
|
|
448
|
+
}
|
|
449
|
+
makeStatement(expr) {
|
|
450
|
+
return new ExpressionStatement(expr);
|
|
451
|
+
}
|
|
452
|
+
makeLoop(counter, limit, statement) {
|
|
453
|
+
return new CJLoopStatement(counter, limit, statement);
|
|
454
|
+
}
|
|
455
|
+
makeMapForEach(map, key, value, op) {
|
|
456
|
+
return new CJMapForEachStatement(map, key, value, op);
|
|
457
|
+
}
|
|
458
|
+
makeDefinedCheck(value) {
|
|
459
|
+
return new CJCheckDefinedExpression(value);
|
|
460
|
+
}
|
|
461
|
+
makeNewObject(objectName, params = []) {
|
|
462
|
+
return new CJNewObjectExpression(objectName, params);
|
|
463
|
+
}
|
|
464
|
+
writePrintLog(message) {
|
|
465
|
+
this.print(`println("${message}")`);
|
|
466
|
+
}
|
|
467
|
+
makeCast(value, type, options) {
|
|
468
|
+
var _a;
|
|
469
|
+
return new CJCastExpression(value, this.getNodeName(type), (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
|
|
470
|
+
}
|
|
471
|
+
typeInstanceOf(type, value, members) {
|
|
472
|
+
if (idl.isInterface(type)) {
|
|
473
|
+
return this.makeString(`${value} is ${this.getNodeName(type)}`);
|
|
474
|
+
}
|
|
475
|
+
throw new Error(`typeInstanceOf fails: not class or interface: ${this.getNodeName(type)}`);
|
|
476
|
+
}
|
|
477
|
+
getObjectAccessor(convertor, value, args) {
|
|
478
|
+
return `${value}`;
|
|
479
|
+
}
|
|
480
|
+
makeUndefined() {
|
|
481
|
+
return this.makeString("Option.None");
|
|
482
|
+
}
|
|
483
|
+
makeUnwrapOptional(expression) {
|
|
484
|
+
return new CJMatchExpression(expression, [this.makeString('Some(serializer)')], [this.makeString('serializer')]);
|
|
485
|
+
}
|
|
486
|
+
makeValueFromOption(value, destinationConvertor) {
|
|
487
|
+
return this.makeString(`${value}`);
|
|
488
|
+
}
|
|
489
|
+
makeRuntimeType(rt) {
|
|
490
|
+
return this.makeString(`RuntimeType.${RuntimeType[rt]}.ordinal`);
|
|
491
|
+
}
|
|
492
|
+
makeRuntimeTypeGetterCall(value) {
|
|
493
|
+
let methodCall = this.makeMethodCall("Ark_Object", "getRuntimeType", [this.makeString(value)]);
|
|
494
|
+
return this.makeString(methodCall.asString() + '.ordinal');
|
|
495
|
+
}
|
|
496
|
+
makeMapInsert(keyAccessor, key, valueAccessor, value) {
|
|
497
|
+
return this.makeStatement(this.makeMethodCall(keyAccessor, "set", [this.makeString(key), this.makeString(value)]));
|
|
498
|
+
}
|
|
499
|
+
makeNull(value) {
|
|
500
|
+
return new StringExpression(`None<${value}>`);
|
|
501
|
+
}
|
|
502
|
+
getTagType() {
|
|
503
|
+
return idl.createReferenceType("Tags");
|
|
504
|
+
}
|
|
505
|
+
getRuntimeType() {
|
|
506
|
+
return idl.IDLNumberType;
|
|
507
|
+
}
|
|
508
|
+
makeTupleAssign(receiver, fields) {
|
|
509
|
+
return this.makeAssign(receiver, undefined, this.makeString(`[${fields.map(it => `${it}!`).join(",")}]`), false);
|
|
510
|
+
}
|
|
511
|
+
get supportedModifiers() {
|
|
512
|
+
return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.STATIC];
|
|
513
|
+
}
|
|
514
|
+
get supportedFieldModifiers() {
|
|
515
|
+
return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY, FieldModifier.STATIC];
|
|
516
|
+
}
|
|
517
|
+
makeUnionSelector(value, valueType) {
|
|
518
|
+
return this.makeAssign(valueType, undefined, this.makeMethodCall(value, "getSelector", []), false);
|
|
519
|
+
}
|
|
520
|
+
makeUnionVariantCondition(_convertor, _valueName, valueType, type, convertorIndex) {
|
|
521
|
+
return this.makeString(`${valueType} == ${convertorIndex}`);
|
|
522
|
+
}
|
|
523
|
+
makeUnionVariantCast(value, type, convertor, index) {
|
|
524
|
+
return this.makeMethodCall(value, `getValue${index}`, []);
|
|
525
|
+
}
|
|
526
|
+
makeTupleAccess(value, index) {
|
|
527
|
+
return this.makeString(`${value}.value${index}`);
|
|
528
|
+
}
|
|
529
|
+
enumFromOrdinal(value, enumEntry) {
|
|
530
|
+
return this.makeString(`${this.getNodeName(enumEntry)}(${value.asString()})`);
|
|
531
|
+
}
|
|
532
|
+
ordinalFromEnum(value, _) {
|
|
533
|
+
return this.makeString(`Int32(${value.asString()}.value)`);
|
|
534
|
+
}
|
|
535
|
+
makeEnumEntity(enumEntity, isExport) {
|
|
536
|
+
return new CJEnumWithGetter(enumEntity, isExport);
|
|
537
|
+
}
|
|
538
|
+
makeEquals(args) {
|
|
539
|
+
return this.makeString(`refEq(${args.map(arg => `${arg.asString()}`).join(`, `)})`);
|
|
540
|
+
}
|
|
541
|
+
runtimeType(param, valueType, value) {
|
|
542
|
+
this.writeStatement(this.makeAssign(valueType, undefined, this.makeRuntimeTypeGetterCall(value), false));
|
|
543
|
+
}
|
|
544
|
+
escapeKeyword(word) {
|
|
545
|
+
return CJKeywords.has(word) ? word + "_" : word;
|
|
546
|
+
}
|
|
547
|
+
castToInt(value, bitness) {
|
|
548
|
+
return `Int${bitness}(${value})`;
|
|
549
|
+
}
|
|
550
|
+
castToBoolean(value) {
|
|
551
|
+
return `if (${value}) { Int32(1) } else { Int32(0) }`;
|
|
552
|
+
}
|
|
553
|
+
makeLengthSerializer(serializer, value) {
|
|
554
|
+
return this.makeBlock([
|
|
555
|
+
this.makeStatement(this.makeMethodCall(serializer, "writeInt8", [this.makeRuntimeType(RuntimeType.STRING)])),
|
|
556
|
+
this.makeStatement(this.makeMethodCall(serializer, "writeString", [this.makeString(`${value}.getValue1()`)]))
|
|
557
|
+
], false);
|
|
558
|
+
}
|
|
559
|
+
makeLengthDeserializer(deserializer) {
|
|
560
|
+
const valueType = "valueType";
|
|
561
|
+
return this.makeBlock([
|
|
562
|
+
this.makeAssign(valueType, undefined, this.makeMethodCall(deserializer, "readInt8", []), true),
|
|
563
|
+
this.makeMultiBranchCondition([{
|
|
564
|
+
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.NUMBER, ''),
|
|
565
|
+
stmt: this.makeReturn(this.makeString(`Ark_Length(${deserializer}.readFloat32())`))
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.STRING, ''),
|
|
569
|
+
stmt: this.makeReturn(this.makeString(`Ark_Length(${deserializer}.readString())`))
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
expr: this.makeRuntimeTypeCondition(valueType, true, RuntimeType.OBJECT, ''),
|
|
573
|
+
stmt: this.makeReturn(this.makeString(`Ark_Length(Resource(${deserializer}.readString(), "", 0.0, Option.None, Option.None))`))
|
|
574
|
+
}], this.makeReturn(this.makeUndefined())),
|
|
575
|
+
], false);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
//# sourceMappingURL=CJLanguageWriter.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Language } from "../../Language";
|
|
2
|
+
import { IndentedPrinter } from "../../IndentedPrinter";
|
|
3
|
+
import * as idl from "../../idl";
|
|
4
|
+
import { ExpressionStatement, LanguageExpression, LanguageStatement, LanguageWriter, Method, PrintHint, MethodModifier, MethodSignature, ReturnStatement } from "../LanguageWriter";
|
|
5
|
+
import { ReferenceResolver } from "../../peer-generation/ReferenceResolver";
|
|
6
|
+
export declare class CLikeReturnStatement extends ReturnStatement {
|
|
7
|
+
expression: LanguageExpression;
|
|
8
|
+
constructor(expression: LanguageExpression);
|
|
9
|
+
write(writer: LanguageWriter): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class CDefinedExpression implements LanguageExpression {
|
|
12
|
+
private value;
|
|
13
|
+
constructor(value: string);
|
|
14
|
+
asString(): string;
|
|
15
|
+
}
|
|
16
|
+
export declare class CLikeLoopStatement implements LanguageStatement {
|
|
17
|
+
private counter;
|
|
18
|
+
private limit;
|
|
19
|
+
private statement;
|
|
20
|
+
constructor(counter: string, limit: string, statement: LanguageStatement | undefined);
|
|
21
|
+
write(writer: LanguageWriter): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class CLikeExpressionStatement extends ExpressionStatement {
|
|
24
|
+
expression: LanguageExpression;
|
|
25
|
+
constructor(expression: LanguageExpression);
|
|
26
|
+
write(writer: LanguageWriter): void;
|
|
27
|
+
}
|
|
28
|
+
export declare abstract class CLikeLanguageWriter extends LanguageWriter {
|
|
29
|
+
protected constructor(printer: IndentedPrinter, resolver: ReferenceResolver, language: Language);
|
|
30
|
+
writeFunctionDeclaration(name: string, signature: MethodSignature): void;
|
|
31
|
+
writeFunctionImplementation(name: string, signature: MethodSignature, op: (writer: this) => void): void;
|
|
32
|
+
makeThrowError(message: string): LanguageStatement;
|
|
33
|
+
makeEquals(args: LanguageExpression[]): LanguageExpression;
|
|
34
|
+
writeMethodCall(receiver: string, method: string, params: string[], nullable?: boolean): void;
|
|
35
|
+
writeMethodDeclaration(name: string, signature: MethodSignature, modifiers?: MethodModifier[]): void;
|
|
36
|
+
writeEnum(name: string, members: {
|
|
37
|
+
name: string;
|
|
38
|
+
stringId: string | undefined;
|
|
39
|
+
numberId: number;
|
|
40
|
+
}[], op: (writer: LanguageWriter) => void): void;
|
|
41
|
+
writeMethodImplementation(method: Method, op: (writer: this) => void): void;
|
|
42
|
+
private writeDeclaration;
|
|
43
|
+
protected stringifyMethodReturnType(type: idl.IDLType, _?: PrintHint): string;
|
|
44
|
+
protected stringifyMethodArgType(type: idl.IDLType, _?: PrintHint): string;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=CLikeLanguageWriter.d.ts.map
|