@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.
Files changed (78) hide show
  1. package/build/lib/src/IndentedPrinter.d.ts +28 -0
  2. package/build/lib/src/IndentedPrinter.js +81 -0
  3. package/build/lib/src/Language.d.ts +15 -0
  4. package/build/lib/src/Language.js +42 -0
  5. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
  6. package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
  7. package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
  8. package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
  9. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
  10. package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
  11. package/build/lib/src/LanguageWriters/common.d.ts +17 -0
  12. package/build/lib/src/LanguageWriters/common.js +33 -0
  13. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
  14. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
  15. package/build/lib/src/LanguageWriters/index.d.ts +3 -0
  16. package/build/lib/src/LanguageWriters/index.js +3 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
  31. package/build/lib/src/LibraryInterface.d.ts +21 -0
  32. package/build/lib/src/LibraryInterface.js +2 -0
  33. package/build/lib/src/config.d.ts +8 -0
  34. package/build/lib/src/config.js +20 -0
  35. package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
  36. package/build/lib/src/from-idl/DtsPrinter.js +375 -0
  37. package/build/lib/src/from-idl/common.d.ts +5 -0
  38. package/build/lib/src/from-idl/common.js +83 -0
  39. package/build/lib/src/from-idl/deserialize.d.ts +9 -0
  40. package/build/lib/src/from-idl/deserialize.js +384 -0
  41. package/build/lib/src/from-idl/toString.d.ts +2 -0
  42. package/build/lib/src/from-idl/toString.js +18 -0
  43. package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
  44. package/build/lib/src/from-idl/webidl2-utils.js +84 -0
  45. package/build/lib/src/idl.d.ts +404 -0
  46. package/build/lib/src/idl.js +1015 -0
  47. package/build/lib/src/idlize.d.ts +4 -0
  48. package/build/lib/src/idlize.js +52 -0
  49. package/build/lib/src/index.d.ts +34 -0
  50. package/build/lib/src/index.js +48 -0
  51. package/build/lib/src/inheritance.d.ts +16 -0
  52. package/build/lib/src/inheritance.js +76 -0
  53. package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
  54. package/build/lib/src/languageSpecificKeywords.js +51 -0
  55. package/build/lib/src/library.d.ts +67 -0
  56. package/build/lib/src/library.js +190 -0
  57. package/build/lib/src/options.d.ts +11 -0
  58. package/build/lib/src/options.js +16 -0
  59. package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
  60. package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
  65. package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
  66. package/build/lib/src/peer-generation/idl/common.js +70 -0
  67. package/build/lib/src/peer-generation/unions.d.ts +29 -0
  68. package/build/lib/src/peer-generation/unions.js +111 -0
  69. package/build/lib/src/rand_utils.d.ts +6 -0
  70. package/build/lib/src/rand_utils.js +100 -0
  71. package/build/lib/src/util.d.ts +75 -0
  72. package/build/lib/src/util.js +622 -0
  73. package/package.json +49 -0
  74. package/webidl2.js/LICENSE +21 -0
  75. package/webidl2.js/README.md +827 -0
  76. package/webidl2.js/dist/package.json +3 -0
  77. package/webidl2.js/dist/webidl2.js +4547 -0
  78. package/webidl2.js/package.json +55 -0
@@ -0,0 +1,472 @@
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 { createReferenceType, forceAsNamedNode, IDLU32Type, IDLUint8ArrayType, IDLVoidType } from '../../idl';
16
+ import { Language } from '../../Language';
17
+ import { PrimitiveTypeList } from "../../peer-generation/PrimitiveType";
18
+ import { AssignStatement, BlockStatement, FieldModifier, PrintHint, MethodModifier, NamedMethodSignature, StringExpression } from "../LanguageWriter";
19
+ import { CDefinedExpression, CLikeExpressionStatement, CLikeLanguageWriter, CLikeLoopStatement, CLikeReturnStatement } from "./CLikeLanguageWriter";
20
+ import { RuntimeType } from "../common";
21
+ import { IndentedPrinter } from "../../IndentedPrinter";
22
+ import { throwException } from "../../util";
23
+ import { cppKeywords } from "../../languageSpecificKeywords";
24
+ ////////////////////////////////////////////////////////////////
25
+ // EXPRESSIONS //
26
+ ////////////////////////////////////////////////////////////////
27
+ export class CppCastExpression {
28
+ constructor(convertor, value, type, options) {
29
+ this.convertor = convertor;
30
+ this.value = value;
31
+ this.type = type;
32
+ this.options = options;
33
+ }
34
+ asString() {
35
+ var _a, _b, _c, _d;
36
+ if (forceAsNamedNode(this.type).name === "Tag") {
37
+ return `${this.value.asString()} == ${PrimitiveTypeList.UndefinedRuntime} ? ${PrimitiveTypeList.UndefinedTag} : ${PrimitiveTypeList.ObjectTag}`;
38
+ }
39
+ let resultName = '';
40
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.overrideTypeName) {
41
+ resultName = this.options.overrideTypeName;
42
+ }
43
+ else {
44
+ const pureName = this.mapTypeWithReceiver(this.type, (_b = this.options) === null || _b === void 0 ? void 0 : _b.receiver);
45
+ const qualifiedName = ((_c = this.options) === null || _c === void 0 ? void 0 : _c.toRef) ? `${pureName}&` : pureName;
46
+ resultName = qualifiedName;
47
+ }
48
+ return ((_d = this.options) === null || _d === void 0 ? void 0 : _d.unsafe)
49
+ ? `reinterpret_cast<${resultName}>(${this.value.asString()})`
50
+ : `static_cast<${resultName}>(${this.value.asString()})`;
51
+ }
52
+ mapTypeWithReceiver(type, receiver) {
53
+ // make deducing type from receiver
54
+ if (receiver !== undefined) {
55
+ return `std::decay<decltype(${receiver})>::type`;
56
+ }
57
+ return this.convertor.convert(type);
58
+ }
59
+ }
60
+ export class CppPointerPropertyAccessExpression {
61
+ constructor(expression, name) {
62
+ this.expression = expression;
63
+ this.name = name;
64
+ }
65
+ asString() {
66
+ return `${this.expression}->${this.name}`;
67
+ }
68
+ }
69
+ ////////////////////////////////////////////////////////////////
70
+ // STATEMENTS //
71
+ ////////////////////////////////////////////////////////////////
72
+ export class CppAssignStatement extends AssignStatement {
73
+ constructor(variableName, type, expression, isDeclared = true, isConst = true, options) {
74
+ super(variableName, type, expression, isDeclared, isConst, options);
75
+ this.variableName = variableName;
76
+ this.type = type;
77
+ this.expression = expression;
78
+ this.isDeclared = isDeclared;
79
+ this.isConst = isConst;
80
+ this.options = options;
81
+ }
82
+ write(writer) {
83
+ var _a, _b;
84
+ if (this.isDeclared) {
85
+ const typeName = this.type ? writer.stringifyTypeWithReceiver(this.type, (_a = this.options) === null || _a === void 0 ? void 0 : _a.receiver) : "auto";
86
+ const typeSpec = ((_b = this.options) === null || _b === void 0 ? void 0 : _b.assignRef) ? `${typeName}&` : typeName;
87
+ const initValue = this.expression ? this.expression.asString() : "{}";
88
+ const constSpec = this.isConst ? "const " : "";
89
+ writer.print(`${constSpec}${typeSpec} ${this.variableName} = ${initValue};`);
90
+ }
91
+ else {
92
+ writer.print(`${this.variableName} = ${this.expression.asString()};`);
93
+ }
94
+ }
95
+ }
96
+ class CppArrayResizeStatement {
97
+ constructor(array, length, deserializer) {
98
+ this.array = array;
99
+ this.length = length;
100
+ this.deserializer = deserializer;
101
+ }
102
+ write(writer) {
103
+ writer.print(`${this.deserializer}.resizeArray<std::decay<decltype(${this.array})>::type,
104
+ std::decay<decltype(*${this.array}.array)>::type>(&${this.array}, ${this.length});`);
105
+ }
106
+ }
107
+ class CppMapResizeStatement {
108
+ constructor(mapTypeName, keyType, valueType, map, size, deserializer) {
109
+ this.mapTypeName = mapTypeName;
110
+ this.keyType = keyType;
111
+ this.valueType = valueType;
112
+ this.map = map;
113
+ this.size = size;
114
+ this.deserializer = deserializer;
115
+ }
116
+ write(writer) {
117
+ writer.print(`${this.deserializer}.resizeMap<${this.mapTypeName}, ${writer.getNodeName(this.keyType)}, ${writer.getNodeName(this.valueType)}>(&${this.map}, ${this.size});`);
118
+ }
119
+ }
120
+ class CppMapForEachStatement {
121
+ constructor(map, key, value, op) {
122
+ this.map = map;
123
+ this.key = key;
124
+ this.value = value;
125
+ this.op = op;
126
+ }
127
+ write(writer) {
128
+ writer.print(`for (int32_t i = 0; i < ${this.map}.size; i++) {`);
129
+ writer.pushIndent();
130
+ writer.print(`auto ${this.key} = ${this.map}.keys[i];`);
131
+ writer.print(`auto ${this.value} = ${this.map}.values[i];`);
132
+ this.op();
133
+ writer.popIndent();
134
+ writer.print(`}`);
135
+ }
136
+ }
137
+ // todo:
138
+ class CppEnumEntityStatement {
139
+ constructor(_enum) {
140
+ this._enum = _enum;
141
+ }
142
+ write(writer) {
143
+ writer.print(`typedef enum ${this._enum.name} {`);
144
+ writer.pushIndent();
145
+ this._enum.elements.forEach((member, index) => { var _a; return writer.print(`${member.name} = ${(_a = member.initializer) !== null && _a !== void 0 ? _a : index},`); });
146
+ writer.popIndent();
147
+ writer.print(`} ${this._enum.name};`);
148
+ }
149
+ }
150
+ class CPPThrowErrorStatement {
151
+ constructor(message) {
152
+ this.message = message;
153
+ }
154
+ write(writer) {
155
+ writer.print(`throw "${this.message}";`);
156
+ }
157
+ }
158
+ ////////////////////////////////////////////////////////////////
159
+ // WRITER //
160
+ ////////////////////////////////////////////////////////////////
161
+ export class CppLanguageWriter extends CLikeLanguageWriter {
162
+ constructor(printer, resolver, typeConvertor, primitivesTypes) {
163
+ super(printer, resolver, Language.CPP);
164
+ this.primitivesTypes = primitivesTypes;
165
+ this.typeConvertor = typeConvertor;
166
+ }
167
+ getNodeName(type) {
168
+ return this.typeConvertor.convert(type);
169
+ }
170
+ fork(options) {
171
+ var _a;
172
+ return new CppLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
173
+ }
174
+ writeClass(name, op, superClass, interfaces) {
175
+ const superClasses = (superClass ? [superClass] : []).concat(interfaces !== null && interfaces !== void 0 ? interfaces : []);
176
+ const extendsClause = superClasses.length > 0 ? ` : ${superClasses.map(c => `public ${c}`).join(", ")}` : '';
177
+ this.printer.print(`class ${name}${extendsClause} {`);
178
+ this.pushIndent();
179
+ op(this);
180
+ this.popIndent();
181
+ this.printer.print(`};`);
182
+ }
183
+ writeInterface(name, op, superInterfaces) {
184
+ throw new Error("Method not implemented.");
185
+ }
186
+ writeMethodCall(receiver, method, params, nullable = false) {
187
+ if (nullable) {
188
+ this.printer.print(`if (${receiver}) ${receiver}.${method}(${params.join(", ")});`);
189
+ }
190
+ else {
191
+ super.writeMethodCall(receiver, method, params, nullable);
192
+ }
193
+ }
194
+ writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
195
+ let filter = function (modifier_name) {
196
+ return modifier_name !== FieldModifier.STATIC;
197
+ };
198
+ let prefix = this.makeFieldModifiersList(modifiers, filter);
199
+ this.printer.print(`${prefix}:`);
200
+ this.printer.pushIndent();
201
+ this.printer.print(`${forceAsNamedNode(type).name} ${name};`);
202
+ this.printer.popIndent();
203
+ }
204
+ writeConstructorImplementation(className, signature, op, superCall, modifiers) {
205
+ const superInvocation = superCall
206
+ ? ` : ${superCall.name}(${superCall.signature.args.map((_, i) => superCall === null || superCall === void 0 ? void 0 : superCall.signature.argName(i)).join(", ")})`
207
+ : "";
208
+ const argList = signature.args.map((it, index) => {
209
+ var _a;
210
+ const maybeDefault = ((_a = signature.defaults) === null || _a === void 0 ? void 0 : _a[index]) ? ` = ${signature.defaults[index]}` : "";
211
+ return `${this.stringifyMethodArgType(it, signature.argHint(index))} ${signature.argName(index)}${maybeDefault}`;
212
+ }).join(", ");
213
+ this.print("public:");
214
+ this.print(`${className}(${argList})${superInvocation} {`);
215
+ this.pushIndent();
216
+ op(this);
217
+ this.popIndent();
218
+ this.print(`}`);
219
+ }
220
+ writeProperty(propName, propType, mutable = true) {
221
+ throw new Error("writeProperty for c++ is not implemented yet.");
222
+ }
223
+ /**
224
+ * Writes multiline comments decorated with stars
225
+ */
226
+ writeMultilineCommentBlock(lines) {
227
+ this.print('/*');
228
+ lines.split("\n").forEach(it => this.print(' * ' + it));
229
+ this.print(' */');
230
+ }
231
+ /**
232
+ * Writes `#include "path"`
233
+ * @param path File path to be included
234
+ */
235
+ writeInclude(path) {
236
+ this.print(`#include "${path}"`);
237
+ }
238
+ /**
239
+ * Writes `#include <path>`
240
+ * @param path File path to be included
241
+ */
242
+ writeGlobalInclude(path) {
243
+ this.print(`#include <${path}>`);
244
+ }
245
+ makeRef(type, options) {
246
+ return createReferenceType(`${this.stringifyTypeWithReceiver(type, options === null || options === void 0 ? void 0 : options.receiver)}&`, undefined, type);
247
+ }
248
+ makeThis() {
249
+ return new StringExpression("*this");
250
+ }
251
+ makeNull() {
252
+ return new StringExpression("nullptr");
253
+ }
254
+ makeValueFromOption(value) {
255
+ return this.makeString(`${value}.value`);
256
+ }
257
+ makeThrowError(message) {
258
+ return new CPPThrowErrorStatement(message);
259
+ }
260
+ makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
261
+ return new CppAssignStatement(variableName, type, expr, isDeclared, isConst, options);
262
+ }
263
+ makeLambda(signature, body) {
264
+ throw new Error(`TBD`);
265
+ }
266
+ makeReturn(expr) {
267
+ return new CLikeReturnStatement(expr);
268
+ }
269
+ makeCheckOptional(optional, doStatement) {
270
+ throw new Error(`TBD`);
271
+ }
272
+ makeStatement(expr) {
273
+ return new CLikeExpressionStatement(expr);
274
+ }
275
+ makeArrayAccess(value, indexVar) {
276
+ return this.makeString(`${value}.array[${indexVar}]`);
277
+ }
278
+ makeTupleAccess(value, index) {
279
+ return this.makeString(`${value}.value${index}`);
280
+ }
281
+ makeUnionSelector(value, valueType) {
282
+ return this.makeAssign(valueType, undefined, this.makeString(`${value}.selector`), false);
283
+ }
284
+ makeUnionVariantCondition(_convertor, _valueName, valueType, type, convertorIndex) {
285
+ return this.makeString(`${valueType} == ${convertorIndex}`);
286
+ }
287
+ makeUnionVariantCast(value, type, convertor, index) {
288
+ return this.makeString(`${value}.value${index}`);
289
+ }
290
+ makeLoop(counter, limit, statement) {
291
+ return new CLikeLoopStatement(counter, limit, statement);
292
+ }
293
+ makeMapForEach(map, key, value, op) {
294
+ return new CppMapForEachStatement(map, key, value, op);
295
+ }
296
+ makeArrayInit(type) {
297
+ return this.makeString(`{}`);
298
+ }
299
+ makeClassInit(type, paramenters) {
300
+ return this.makeString(`${this.getNodeName(type)}(${paramenters.map(it => it.asString()).join(", ")})`);
301
+ }
302
+ makeMapInit(type) {
303
+ return this.makeString(`{}`);
304
+ }
305
+ makeArrayResize(array, arrayType, length, deserializer) {
306
+ return new CppArrayResizeStatement(array, length, deserializer);
307
+ }
308
+ makeMapResize(mapTypeName, keyType, valueType, map, size, deserializer) {
309
+ return new CppMapResizeStatement(mapTypeName, keyType, valueType, map, size, deserializer);
310
+ }
311
+ makeCast(expr, type, options) {
312
+ return new CppCastExpression(this.typeConvertor, expr, type, options);
313
+ }
314
+ makePointerPropertyAccessExpression(expression, name) {
315
+ return new CppPointerPropertyAccessExpression(expression, name);
316
+ }
317
+ writePrintLog(message) {
318
+ this.print(`printf("${message}\n")`);
319
+ }
320
+ makeDefinedCheck(value) {
321
+ return new CDefinedExpression(value);
322
+ }
323
+ makeSetUnionSelector(value, index) {
324
+ return this.makeAssign(`${value}.selector`, undefined, this.makeString(index), false);
325
+ }
326
+ makeSetOptionTag(value, tag) {
327
+ return this.makeAssign(`${value}.tag`, undefined, tag, false);
328
+ }
329
+ getObjectAccessor(convertor, value, args) {
330
+ return value;
331
+ }
332
+ makeUndefined() {
333
+ return this.makeString(`${this.primitivesTypes.Undefined.getText()}()`);
334
+ }
335
+ makeVoid() {
336
+ return this.makeString(`${this.primitivesTypes.Void.getText()}()`);
337
+ }
338
+ makeRuntimeType(rt) {
339
+ return this.makeString(`INTEROP_RUNTIME_${RuntimeType[rt]}`);
340
+ }
341
+ makeMapInsert(keyAccessor, key, valueAccessor, value) {
342
+ // TODO: maybe use std::move?
343
+ return new BlockStatement([
344
+ this.makeAssign(keyAccessor, undefined, this.makeString(key), false),
345
+ this.makeAssign(valueAccessor, undefined, this.makeString(value), false)
346
+ ], false);
347
+ }
348
+ getTagType() {
349
+ return createReferenceType('Tag');
350
+ }
351
+ getRuntimeType() {
352
+ return createReferenceType(`RuntimeType`);
353
+ }
354
+ makeTupleAssign(receiver, tupleFields) {
355
+ const statements = tupleFields.map((field, index) => {
356
+ //TODO: maybe use std::move?
357
+ return this.makeAssign(`${receiver}.value${index}`, undefined, this.makeString(field), false);
358
+ });
359
+ return new BlockStatement(statements, false);
360
+ }
361
+ get supportedModifiers() {
362
+ return [MethodModifier.INLINE, MethodModifier.STATIC];
363
+ }
364
+ get supportedFieldModifiers() {
365
+ return [];
366
+ }
367
+ enumFromOrdinal(value, type) {
368
+ return this.makeString(`static_cast<${this.typeConvertor.convert(type)}>(` + value.asString() + `)`);
369
+ }
370
+ ordinalFromEnum(value, _) {
371
+ return value;
372
+ }
373
+ makeUnsafeCast(convertor, param) {
374
+ return param;
375
+ }
376
+ makeUnsafeCast_(value, type, typeOptions) {
377
+ let typeName = this.getNodeName(type);
378
+ switch (typeOptions) {
379
+ case PrintHint.AsPointer:
380
+ typeName = `${typeName}*`;
381
+ break;
382
+ case PrintHint.AsConstPointer:
383
+ typeName = `const ${typeName}*`;
384
+ break;
385
+ case PrintHint.AsConstReference:
386
+ typeName = `const ${typeName}&`;
387
+ break;
388
+ default:
389
+ break;
390
+ }
391
+ return `(${typeName}) (${value.asString()})`;
392
+ }
393
+ makeEnumCast(value, _unsafe, convertor) {
394
+ if (convertor !== undefined) {
395
+ return `static_cast<${this.typeConvertor.convert(convertor.nativeType())}>(${value})`;
396
+ }
397
+ throwException("Need pass EnumConvertor");
398
+ }
399
+ escapeKeyword(name) {
400
+ return cppKeywords.has(name) ? name + "_" : name;
401
+ }
402
+ makeEnumEntity(enumEntity, isExport) {
403
+ return new CppEnumEntityStatement(enumEntity);
404
+ }
405
+ decayTypeName(typeName) {
406
+ if (typeName.endsWith('*') || typeName.endsWith('&')) {
407
+ typeName = typeName.substring(0, typeName.length - 1);
408
+ }
409
+ if (typeName.startsWith('const ')) {
410
+ typeName = typeName.substring(6);
411
+ }
412
+ return typeName;
413
+ }
414
+ stringifyMethodReturnType(type, hint) {
415
+ const name = this.getNodeName(type);
416
+ let postfix = '';
417
+ if (hint === PrintHint.AsPointer || hint === PrintHint.AsConstPointer) {
418
+ postfix = '*';
419
+ }
420
+ let constModifier = '';
421
+ if (hint === PrintHint.AsConstPointer) {
422
+ constModifier = 'const ';
423
+ }
424
+ return `${constModifier}${name}${postfix}`;
425
+ }
426
+ stringifyMethodArgType(type, hint) {
427
+ // we should decide pass by value or by reference here
428
+ const name = this.getNodeName(type);
429
+ let constModifier = '';
430
+ let postfix = '';
431
+ switch (hint) {
432
+ case undefined:
433
+ case PrintHint.AsValue:
434
+ break;
435
+ case PrintHint.AsPointer:
436
+ postfix = '*';
437
+ break;
438
+ case PrintHint.AsConstPointer:
439
+ constModifier = 'const ';
440
+ postfix = '*';
441
+ break;
442
+ case PrintHint.AsConstReference:
443
+ constModifier = 'const ';
444
+ postfix = '&';
445
+ break;
446
+ default:
447
+ throw new Error(`Unknown hint ${hint}`);
448
+ }
449
+ return `${constModifier}${name}${postfix}`;
450
+ }
451
+ stringifyTypeWithReceiver(type, receiver) {
452
+ // make deducing type from receiver
453
+ if (receiver !== undefined) {
454
+ return `std::decay<decltype(${receiver})>::type`;
455
+ }
456
+ return this.getNodeName(type);
457
+ }
458
+ makeSerializerConstructorSignature() {
459
+ return new NamedMethodSignature(IDLVoidType, [
460
+ IDLUint8ArrayType,
461
+ IDLU32Type,
462
+ createReferenceType("CallbackResourceHolder" /* ast */)
463
+ ], ["data", "dataLength", "resourceHolder"], [undefined, `0`, `nullptr`], [undefined, undefined, undefined, PrintHint.AsPointer]);
464
+ }
465
+ makeLengthSerializer(serializer, value) {
466
+ return undefined;
467
+ }
468
+ makeLengthDeserializer(deserializer) {
469
+ return undefined;
470
+ }
471
+ }
472
+ //# sourceMappingURL=CppLanguageWriter.js.map
@@ -0,0 +1,72 @@
1
+ import { IndentedPrinter } from "../../IndentedPrinter";
2
+ import { LambdaExpression, LanguageExpression, LanguageStatement, LanguageWriter, MakeCastOptions, MethodModifier, MethodSignature, ObjectArgs } from "../LanguageWriter";
3
+ import { TSLanguageWriter } from "./TsLanguageWriter";
4
+ import { IDLEnum, IDLType } from '../../idl';
5
+ import { ArgConvertor } from "../ArgConvertors";
6
+ import * as idl from '../../idl';
7
+ import { IdlNameConvertor } from "../nameConvertor";
8
+ import { ReferenceResolver } from "../../peer-generation/ReferenceResolver";
9
+ export declare class EtsAssignStatement implements LanguageStatement {
10
+ variableName: string;
11
+ type: IDLType | undefined;
12
+ expression: LanguageExpression;
13
+ isDeclared: boolean;
14
+ protected isConst: boolean;
15
+ constructor(variableName: string, type: IDLType | undefined, expression: LanguageExpression, isDeclared?: boolean, isConst?: boolean);
16
+ write(writer: LanguageWriter): void;
17
+ }
18
+ export declare class ArkTSEnumEntityStatement implements LanguageStatement {
19
+ private readonly enumEntity;
20
+ private readonly isExport;
21
+ constructor(enumEntity: IDLEnum, isExport: boolean);
22
+ write(writer: LanguageWriter): void;
23
+ }
24
+ export declare class ETSLambdaExpression extends LambdaExpression {
25
+ private convertor;
26
+ constructor(writer: LanguageWriter, convertor: IdlNameConvertor, signature: MethodSignature, resolver: ReferenceResolver, body?: LanguageStatement[]);
27
+ protected get statementHasSemicolon(): boolean;
28
+ asString(): string;
29
+ }
30
+ export declare function generateTypeCheckerName(typeName: string): string;
31
+ export declare function makeArrayTypeCheckCall(valueAccessor: string, typeName: string, writer: LanguageWriter): LanguageExpression;
32
+ export declare class ETSLanguageWriter extends TSLanguageWriter {
33
+ private arrayConvertor;
34
+ constructor(printer: IndentedPrinter, resolver: ReferenceResolver, typeConvertor: IdlNameConvertor, arrayConvertor: IdlNameConvertor);
35
+ fork(options?: {
36
+ resolver?: ReferenceResolver;
37
+ }): LanguageWriter;
38
+ writeNativeMethodDeclaration(name: string, signature: MethodSignature): void;
39
+ makeAssign(variableName: string, type: IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean): LanguageStatement;
40
+ makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
41
+ makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
42
+ makeMapSize(map: string): LanguageExpression;
43
+ get supportedModifiers(): MethodModifier[];
44
+ makeUnsafeCast(convertor: ArgConvertor, param: string): string;
45
+ runtimeType(param: ArgConvertor, valueType: string, value: string): void;
46
+ makeUnionVariantCast(value: string, type: string, convertor: ArgConvertor, index?: number): LanguageExpression;
47
+ enumFromOrdinal(value: LanguageExpression, enumEntry: idl.IDLType): LanguageExpression;
48
+ ordinalFromEnum(value: LanguageExpression, _: idl.IDLType): LanguageExpression;
49
+ makeDiscriminatorFromFields(convertor: {
50
+ targetType: (writer: LanguageWriter) => string;
51
+ }, value: string, accessors: string[], duplicates: Set<string>): LanguageExpression;
52
+ makeValueFromOption(value: string, destinationConvertor: ArgConvertor): LanguageExpression;
53
+ makeCallIsResource(value: string): LanguageExpression;
54
+ makeEnumEntity(enumEntity: IDLEnum, isExport: boolean): LanguageStatement;
55
+ getObjectAccessor(convertor: ArgConvertor, value: string, args?: ObjectArgs): string;
56
+ writeMethodCall(receiver: string, method: string, params: string[], nullable?: boolean): void;
57
+ writeProperty(propName: string, propType: IDLType): void;
58
+ makeEnumCast(value: string, _unsafe: boolean, convertor: ArgConvertor | undefined): string;
59
+ makeUnionVariantCondition(convertor: ArgConvertor, valueName: string, valueType: string, type: string, convertorIndex: number, runtimeTypeIndex: number): LanguageExpression;
60
+ makeCastCustomObject(customName: string, isGenericType: boolean): LanguageExpression;
61
+ makeHasOwnProperty(value: string, valueTypeName: string, property: string, propertyTypeName: string): LanguageExpression;
62
+ makeEquals(args: LanguageExpression[]): LanguageExpression;
63
+ makeDiscriminatorConvertor(convertor: ArgConvertor, value: string, index: number): LanguageExpression;
64
+ castToInt(value: string, bitness: 8 | 32): string;
65
+ castToBoolean(value: string): string;
66
+ instanceOf(convertor: ArgConvertor, value: string, duplicateMembers?: Set<string>): LanguageExpression;
67
+ typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
68
+ makeTypeCast(value: LanguageExpression, type: idl.IDLType, options?: MakeCastOptions): LanguageExpression;
69
+ makeCast(value: LanguageExpression, type: idl.IDLType, options?: MakeCastOptions): LanguageExpression;
70
+ }
71
+ export declare function makeEnumTypeCheckerCall(valueAccessor: string, enumName: string, writer: LanguageWriter): LanguageExpression;
72
+ //# sourceMappingURL=ETSLanguageWriter.d.ts.map