@idlizer/core 2.1.10-arktscgen-7 → 2.1.10-arktscgen-9

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.
@@ -17,14 +17,15 @@ import { Language } from "../Language";
17
17
  import { BlockStatement, PrintHint, StringExpression, NamedMethodSignature, ProxyStatement, ExpressionStatement } from "./LanguageWriter";
18
18
  import { RuntimeType } from "./common";
19
19
  import { generatorConfiguration, generatorTypePrefix } from "../config";
20
- import { capitalize, getExtractor, getTransformer, hashCodeFromString, throwException, warn } from "../util";
20
+ import { capitalize, getExtractor, entryToFunctionName as entryToFunctionName, getTransformer, hashCodeFromString, throwException, warn } from "../util";
21
21
  import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
22
22
  import { CppConvertor, CppNameConvertor } from "./convertors/CppConvertors";
23
23
  import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
24
24
  import { LayoutNodeRole } from "../peer-generation/LayoutManager";
25
25
  import { isInExternalModule } from "../peer-generation/modules";
26
+ import { maybeRestoreGenerics } from "../transformers/GenericTransformer";
26
27
  export function getSerializerName(_library, _language, declaration) {
27
- return `${idl.getQualifiedName(declaration, "package.namespace.name").split('.').map(capitalize).join('')}SerializerImpl`;
28
+ return entryToFunctionName(_language, declaration, "", "SerializerImpl");
28
29
  }
29
30
  export class BaseArgConvertor {
30
31
  constructor(idlType, runtimeTypes, isScoped, useArray, param) {
@@ -900,8 +901,9 @@ export class UnionConvertor extends BaseArgConvertor {
900
901
  statements.push(printer.makeAssign(varName, undefined, printer.makeUnionVariantCast(convertor.getObjectAccessor(printer.language, value), printer.getNodeName(convertor.idlType), convertor, index), true));
901
902
  statements.push(convertor.convertorSerialize(param, varName, printer));
902
903
  }
904
+ const genericDiscriminator = withGenericDiscriminator(this.library, this.memberConvertors, value, discriminator, type, printer);
903
905
  const stmt = new BlockStatement(statements, false);
904
- return { expr: discriminator, stmt };
906
+ return { expr: genericDiscriminator, stmt };
905
907
  }
906
908
  makeArrayBranch(param, value, printer, arrayConvertorItems) {
907
909
  if (arrayConvertorItems.length == 0)
@@ -1349,4 +1351,25 @@ export function createOutArgConvertor(library, type, otherParams) {
1349
1351
  }
1350
1352
  return undefined;
1351
1353
  }
1354
+ function withGenericDiscriminator(library, convertors, value, discriminator, type, writer) {
1355
+ if (writer.language == Language.CPP)
1356
+ return discriminator;
1357
+ if (!idl.isReferenceType(type))
1358
+ return discriminator;
1359
+ const mayBeGeneric = maybeRestoreGenerics(type, writer.resolver);
1360
+ if (mayBeGeneric == undefined)
1361
+ return discriminator;
1362
+ const count = convertors
1363
+ .map(it => it.idlType)
1364
+ .filter(it => idl.isReferenceType(it))
1365
+ .map(it => idl.isReferenceType(it) ? maybeRestoreGenerics(it, writer.resolver) : undefined)
1366
+ .filter(it => it && idl.isReferenceType(it) && it.name == mayBeGeneric.name)
1367
+ .length;
1368
+ if (count < 2)
1369
+ return discriminator;
1370
+ writer.addFeature("typechecks", library.layout.handwrittenPackage());
1371
+ const decl = writer.resolver.resolveTypeReference(type);
1372
+ const checkGenericFunc = entryToFunctionName(writer.language, decl, "isGeneric_", "");
1373
+ return writer.makeAnd(discriminator, writer.makeFunctionCall(`typechecks.${checkGenericFunc}`, [writer.makeString(value)]));
1374
+ }
1352
1375
  //# sourceMappingURL=ArgConvertors.js.map
@@ -168,7 +168,8 @@ export declare enum MethodModifier {
168
168
  THROWS = 8,
169
169
  FREE = 9,
170
170
  FORCE_CONTEXT = 10,
171
- OVERRIDE = 11
171
+ OVERRIDE = 11,
172
+ OPEN = 12
172
173
  }
173
174
  export declare enum ClassModifier {
174
175
  PUBLIC = 0,
@@ -326,7 +327,8 @@ export declare abstract class LanguageWriter {
326
327
  writeStatements(...statements: LanguageStatement[]): void;
327
328
  writeExpressionStatement(smth: LanguageExpression): void;
328
329
  writeExpressionStatements(...statements: LanguageExpression[]): void;
329
- writeStaticBlock(op: (writer: this) => void): void;
330
+ writePrefixedBlock(prefix: string, op: (writer: this) => void): void;
331
+ writeStaticInitBlock(op: (writer: this) => void): void;
330
332
  makeRef(type: idl.IDLType, _options?: MakeRefOptions): idl.IDLType;
331
333
  makeThis(): LanguageExpression;
332
334
  makeNull(type?: idl.IDLOptionalType): LanguageExpression;
@@ -387,12 +389,14 @@ export declare abstract class LanguageWriter {
387
389
  makeHasOwnProperty(value: string, property: string, propertyTypeName?: string): LanguageExpression;
388
390
  discriminate(value: string, index: number, type: idl.IDLType, runtimeTypes: RuntimeType[]): string;
389
391
  makeNot(expr: LanguageExpression): LanguageExpression;
392
+ makeAnd(...args: LanguageExpression[]): LanguageExpression;
393
+ makeOr(...args: LanguageExpression[]): LanguageExpression;
390
394
  makeSerializedBufferGetter(serializer: string): LanguageExpression;
391
395
  makeEquals(args: LanguageExpression[]): LanguageExpression;
392
396
  castToInt(value: string, bitness: 8 | 32): string;
393
397
  castToBoolean(value: string): string;
394
398
  makeCallIsObject(value: string): LanguageExpression;
395
- makeStaticBlock(op: (writer: LanguageWriter) => void): void;
399
+ writeStaticEntitiesBlock(op: (writer: LanguageWriter) => void): void;
396
400
  instanceOf(value: string, type: idl.IDLType): LanguageExpression;
397
401
  typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
398
402
  /**
@@ -337,6 +337,7 @@ export var MethodModifier;
337
337
  MethodModifier[MethodModifier["FREE"] = 9] = "FREE";
338
338
  MethodModifier[MethodModifier["FORCE_CONTEXT"] = 10] = "FORCE_CONTEXT";
339
339
  MethodModifier[MethodModifier["OVERRIDE"] = 11] = "OVERRIDE";
340
+ MethodModifier[MethodModifier["OPEN"] = 12] = "OPEN";
340
341
  })(MethodModifier || (MethodModifier = {}));
341
342
  export var ClassModifier;
342
343
  (function (ClassModifier) {
@@ -496,13 +497,16 @@ export class LanguageWriter {
496
497
  writeExpressionStatements(...statements) {
497
498
  statements.forEach(it => this.writeExpressionStatement(it));
498
499
  }
499
- writeStaticBlock(op) {
500
- this.print("static {");
500
+ writePrefixedBlock(prefix, op) {
501
+ this.print(`${prefix} {`);
501
502
  this.pushIndent();
502
503
  op(this);
503
504
  this.popIndent();
504
505
  this.print("}");
505
506
  }
507
+ writeStaticInitBlock(op) {
508
+ this.writePrefixedBlock("static", op);
509
+ }
506
510
  makeRef(type, _options) {
507
511
  return type;
508
512
  }
@@ -683,6 +687,12 @@ export class LanguageWriter {
683
687
  makeNot(expr) {
684
688
  return this.makeString(`!(${expr.asString()})`);
685
689
  }
690
+ makeAnd(...args) {
691
+ return this.makeNaryOp("&&", args);
692
+ }
693
+ makeOr(...args) {
694
+ return this.makeNaryOp("||", args);
695
+ }
686
696
  makeSerializedBufferGetter(serializer) {
687
697
  return this.makeMethodCall(serializer, `asBuffer`, []);
688
698
  }
@@ -694,7 +704,7 @@ export class LanguageWriter {
694
704
  makeCallIsObject(value) {
695
705
  return this.makeString(`typeof ${value} === "object"`);
696
706
  }
697
- makeStaticBlock(op) {
707
+ writeStaticEntitiesBlock(op) {
698
708
  op(this);
699
709
  }
700
710
  instanceOf(value, type) {
@@ -229,7 +229,7 @@ export class ETSLanguageWriter extends TSLanguageWriter {
229
229
  // The explicit cast forces ui2abc to call valueOf on an int, which fails the compilation
230
230
  // TODO Fix this cast
231
231
  if (bitness === 8)
232
- return `(${value}).toChar()`;
232
+ return `(${value}).toByte()`;
233
233
  return `(${value}).toInt()`; // FIXME: is there int8 in ARKTS?
234
234
  }
235
235
  castToBoolean(value) { return `${value} ? true : false`; }
@@ -148,7 +148,7 @@ export declare class KotlinLanguageWriter extends LanguageWriter {
148
148
  makeCallIsObject(value: string): LanguageExpression;
149
149
  makeNewObject(objectName: string, params?: LanguageExpression[]): LanguageExpression;
150
150
  escapeKeyword(keyword: string): string;
151
- makeStaticBlock(op: (writer: LanguageWriter) => void): void;
151
+ writeStaticEntitiesBlock(op: (writer: LanguageWriter) => void): void;
152
152
  pushNamespace(namespace: string, options: NamespaceOptions): void;
153
153
  popNamespace(options: {
154
154
  ident: boolean;
@@ -85,7 +85,7 @@ export class KotlinEnumWithGetter {
85
85
  let mangledName = removePoints(idl.getQualifiedName(this.enumEntity, 'namespace.name'));
86
86
  writer.writeClass(mangledName, () => {
87
87
  const enumType = idl.createReferenceType(this.enumEntity);
88
- writer.makeStaticBlock(() => {
88
+ writer.writeStaticEntitiesBlock(() => {
89
89
  members.forEach(it => {
90
90
  writer.writeFieldDeclaration(it.name, enumType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.FINAL], false, writer.makeString(`${mangledName}(${it.stringId ? `\"${it.stringId}\"` : it.numberId})`));
91
91
  });
@@ -236,11 +236,11 @@ export class KotlinLanguageWriter extends LanguageWriter {
236
236
  maybeSemicolon() { return ""; }
237
237
  writeClass(name, op, superClass, interfaces, generics, isDeclared, isAbstract) {
238
238
  let extendsClause = superClass ? `${superClass}` : undefined;
239
- let implementsClause = interfaces ? `${interfaces.join(' , ')}` : undefined;
239
+ let implementsClause = interfaces ? `${interfaces.join(', ')}` : undefined;
240
240
  let inheritancePart = [extendsClause, implementsClause]
241
241
  .filter(isDefined)
242
- .join(' , ');
243
- inheritancePart = inheritancePart.length != 0 ? ' : '.concat(inheritancePart) : '';
242
+ .join(', ');
243
+ inheritancePart = inheritancePart.length != 0 ? ': '.concat(inheritancePart) : '';
244
244
  this.printer.print(`public open class ${name}${inheritancePart} {`);
245
245
  this.pushIndent();
246
246
  op(this);
@@ -590,7 +590,7 @@ export class KotlinLanguageWriter extends LanguageWriter {
590
590
  throw new Error("Not implemented");
591
591
  }
592
592
  get supportedModifiers() {
593
- return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.OVERRIDE];
593
+ return [MethodModifier.PUBLIC, MethodModifier.PROTECTED, MethodModifier.PRIVATE, MethodModifier.OVERRIDE, MethodModifier.OPEN];
594
594
  }
595
595
  get supportedFieldModifiers() {
596
596
  return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY, FieldModifier.OVERRIDE];
@@ -619,12 +619,8 @@ export class KotlinLanguageWriter extends LanguageWriter {
619
619
  escapeKeyword(keyword) {
620
620
  return keyword;
621
621
  }
622
- makeStaticBlock(op) {
623
- this.printer.print('companion object {');
624
- this.printer.pushIndent();
625
- op(this);
626
- this.popIndent();
627
- this.printer.print('}');
622
+ writeStaticEntitiesBlock(op) {
623
+ this.writePrefixedBlock("companion object", op);
628
624
  }
629
625
  pushNamespace(namespace, options) { }
630
626
  popNamespace(options) { }
@@ -31,7 +31,7 @@ interface Token {
31
31
  value: string;
32
32
  location: Location;
33
33
  }
34
- type ModifierToken = "static" | "readonly" | "async";
34
+ type ModifierToken = "static" | "readonly" | "async" | "optional";
35
35
  type ModifiersContainer = {
36
36
  [Key in ModifierToken]?: Token;
37
37
  };
@@ -69,7 +69,7 @@ const unsupportedDeclarations = new Set(["deleter", "getter", "includes", "inher
69
69
  const interfaceContent = new Set([idl.IDLKind.Constructor, idl.IDLKind.Const, idl.IDLKind.Property, idl.IDLKind.Method, idl.IDLKind.Callable]);
70
70
  const globalContent = new Set([idl.IDLKind.Namespace, idl.IDLKind.Interface, idl.IDLKind.Enum, idl.IDLKind.Method, idl.IDLKind.Typedef, idl.IDLKind.Callback, idl.IDLKind.Import, idl.IDLKind.Version, idl.IDLKind.Const]);
71
71
  const havingBlocks = new Set([idl.IDLKind.Namespace, idl.IDLKind.Interface, idl.IDLKind.Enum]);
72
- const modifierTokens = new Set(["static", "readonly", "async"]);
72
+ const modifierTokens = new Set(["static", "readonly", "async", "optional"]);
73
73
  // Uncomment in case of parser debugging
74
74
  function trac(s) {
75
75
  // console.log(s)
@@ -402,7 +402,7 @@ export class Parser {
402
402
  }
403
403
  switch (this.curValue) {
404
404
  case "attribute":
405
- this.assertPossibleModifiers("static", "readonly");
405
+ this.assertPossibleModifiers("static", "readonly", "optional");
406
406
  return this.parseAttribute();
407
407
  case "callback":
408
408
  return this.parseCallback();
@@ -737,7 +737,7 @@ export class Parser {
737
737
  const ext = this.consumeCurrentExtended();
738
738
  const isReadonly = !!this.currentModifiers.readonly;
739
739
  const isStatic = !!this.currentModifiers.static;
740
- const isOptional = extractOptional(ext);
740
+ let isOptional = !!this.currentModifiers.optional || extractOptional(ext);
741
741
  this.skip("attribute");
742
742
  const type = this.parseType();
743
743
  const name = this.parseSingleIdentifier();
@@ -128,8 +128,9 @@ export class IDLWriter {
128
128
  printProperty(idl) {
129
129
  const staticMod = idl.isStatic ? "static " : "";
130
130
  const readonlyMod = idl.isReadonly ? "readonly " : "";
131
+ const optional = idl.isOptional ? "optional " : "";
131
132
  return this.printExtendedAttributes(idl)
132
- .print(`${staticMod}${readonlyMod}attribute ${nameWithType(idl)};`);
133
+ .print(`${staticMod}${readonlyMod}${optional}attribute ${nameWithType(idl)};`);
133
134
  }
134
135
  printExtendedAttributes(idl) {
135
136
  var _a;
@@ -10255,6 +10255,7 @@ export declare class PeerLibrary implements LibraryInterface {
10255
10255
  language: Language;
10256
10256
  interopNativeModule: NativeModuleType;
10257
10257
  readonly useMemoM3: boolean;
10258
+ readonly useComponentNamedOverloads: boolean;
10258
10259
  private _cachedIdlLibrary?;
10259
10260
  asIDLLibrary(): IDLLibrary;
10260
10261
  get globals(): GlobalScopeDeclarations[];
@@ -10266,7 +10267,7 @@ export declare class PeerLibrary implements LibraryInterface {
10266
10267
  private resolver;
10267
10268
  readonly materializedClasses: Map<string, MaterializedClass>;
10268
10269
  get orderedMaterialized(): MaterializedClass[];
10269
- constructor(language: Language, interopNativeModule: NativeModuleType, useMemoM3?: boolean);
10270
+ constructor(language: Language, interopNativeModule: NativeModuleType, useMemoM3?: boolean, useComponentNamedOverloads?: boolean);
10270
10271
  name: string;
10271
10272
  readonly customComponentMethods: string[];
10272
10273
  createLanguageWriter(language?: Language): LanguageWriter;
@@ -91,10 +91,11 @@ export class PeerLibrary {
91
91
  return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated)
92
92
  .sort((a, b) => accessorName(a.decl).localeCompare(accessorName(b.decl)));
93
93
  }
94
- constructor(language, interopNativeModule, useMemoM3 = false) {
94
+ constructor(language, interopNativeModule, useMemoM3 = false, useComponentNamedOverloads = true) {
95
95
  this.language = language;
96
96
  this.interopNativeModule = interopNativeModule;
97
97
  this.useMemoM3 = useMemoM3;
98
+ this.useComponentNamedOverloads = useComponentNamedOverloads;
98
99
  this.layout = LayoutManager.Empty();
99
100
  this._files = [];
100
101
  this.auxFiles = [];
@@ -10,14 +10,24 @@ class FqnTransformer extends IdlTransformer {
10
10
  this.resolver = resolver;
11
11
  }
12
12
  visit(node) {
13
- var _a;
13
+ var _a, _b;
14
+ const defaultGenericReferenceAttribute = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(a => a.name === idl.IDLExtendedAttributes.TypeParametersDefaults);
15
+ if (defaultGenericReferenceAttribute && defaultGenericReferenceAttribute.typesValue) {
16
+ const fqVisited = defaultGenericReferenceAttribute.typesValue.map(type => {
17
+ const tmpType = idl.clone(type);
18
+ tmpType.parent = node;
19
+ return this.visit(tmpType);
20
+ });
21
+ defaultGenericReferenceAttribute.typesValue = fqVisited;
22
+ return this.visitEachChild(node);
23
+ }
14
24
  if (idl.isReferenceType(node)) {
15
25
  const resolved = this.resolver.resolveTypeReference(node);
16
26
  if (resolved === undefined) {
17
27
  this.resolver.resolveTypeReference(node);
18
28
  throw new Error("Can not expand FQN for " + idl.DebugUtils.debugPrintType(node));
19
29
  }
20
- return idl.createReferenceType(idl.getFQName(resolved), (_a = node.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => this.visit(it)), idl.cloneNodeInitializer(node));
30
+ return idl.createReferenceType(idl.getFQName(resolved), (_b = node.typeArguments) === null || _b === void 0 ? void 0 : _b.map(it => this.visit(it)), idl.cloneNodeInitializer(node));
21
31
  }
22
32
  return this.visitEachChild(node);
23
33
  }
@@ -139,7 +139,7 @@ class GenericsTransformer extends IdlTransformer {
139
139
  throw new Error(`Unsupported generics target ${resolved.kind}`);
140
140
  }
141
141
  const inplacedRef = idl.createReferenceType(idl.deriveQualifiedNameFrom(monomorphisedEntryName(resolved, ref.typeArguments, this.options), resolved), undefined, idl.cloneNodeInitializer(ref));
142
- if (!this.resolver.resolveTypeReference(inplacedRef)) {
142
+ if (!this.resolver.resolveTypeReference(inplacedRef, { unresolvedOk: true })) {
143
143
  const monomorphizedEntry = this.visit(this.monomorphizeEntry(resolved, ref.typeArguments));
144
144
  this.producer({ anchor: idl.getFQName(resolved), produced: monomorphizedEntry });
145
145
  }
@@ -26,6 +26,7 @@ export declare function renameDtsToInterfaces(fileName: string, language: Langua
26
26
  export declare function renameClassToBuilderClass(className: string, language: Language, withFileExtension?: boolean): string;
27
27
  export declare function renameClassToMaterialized(className: string, language: Language, withFileExtension?: boolean): string;
28
28
  export declare function throwException(message: string): never;
29
+ export declare function entryToFunctionName(_language: Language, declaration: idl.IDLEntry, prefix: string, postfix: string): string;
29
30
  /**
30
31
  * Add a prefix to an enum value which camel case name coincidence
31
32
  * with the the same upper case name for an another enum value
@@ -194,6 +194,9 @@ export function renameClassToMaterialized(className, language, withFileExtension
194
194
  export function throwException(message) {
195
195
  throw new Error(message);
196
196
  }
197
+ export function entryToFunctionName(_language, declaration, prefix, postfix) {
198
+ return `${prefix}${idl.getQualifiedName(declaration, "package.namespace.name").split('.').map(capitalize).join('')}${postfix}`;
199
+ }
197
200
  /**
198
201
  * Add a prefix to an enum value which camel case name coincidence
199
202
  * with the the same upper case name for an another enum value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.1.10-arktscgen-7",
3
+ "version": "2.1.10-arktscgen-9",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {
@@ -36,7 +36,7 @@
36
36
  "mocha": "^9.2.2",
37
37
  "ts-node": "^10.9.2",
38
38
  "typescript": "4.9.5",
39
- "@types/node": "^18.0.0",
39
+ "@types/node": "^18.19.127",
40
40
  "rimraf": "^6.0.1"
41
41
  },
42
42
  "scripts": {