@idlizer/core 2.0.43 → 2.1.0

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.
@@ -1,9 +1,10 @@
1
1
  import * as idl from "../idl";
2
2
  import { Language } from "../Language";
3
- import { LanguageExpression, LanguageStatement, LanguageWriter, ExpressionAssigner } from "./LanguageWriter";
3
+ import { ExpressionAssigner, LanguageExpression, LanguageStatement, LanguageWriter, Method } from "./LanguageWriter";
4
4
  import { RuntimeType } from "./common";
5
5
  import { LibraryInterface } from "../LibraryInterface";
6
6
  import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
7
+ import { PeerLibrary } from "../peer-generation/PeerLibrary";
7
8
  export interface ArgConvertor {
8
9
  param: string;
9
10
  idlType: idl.IDLType;
@@ -22,6 +23,8 @@ export interface ArgConvertor {
22
23
  getMembers(): string[];
23
24
  getObjectAccessor(languge: Language, value: string, args?: Record<string, string>, writer?: LanguageWriter): string;
24
25
  }
26
+ export declare function isVMContextMethod(method: Method): boolean;
27
+ export declare function isDirectMethod(method: Method, library: PeerLibrary): boolean;
25
28
  export declare abstract class BaseArgConvertor implements ArgConvertor {
26
29
  idlType: idl.IDLType;
27
30
  runtimeTypes: RuntimeType[];
@@ -14,15 +14,65 @@
14
14
  */
15
15
  import * as idl from "../idl";
16
16
  import { Language } from "../Language";
17
- import { PrintHint, BlockStatement, StringExpression } from "./LanguageWriter";
17
+ import { BlockStatement, PrintHint, StringExpression, MethodModifier } from "./LanguageWriter";
18
18
  import { RuntimeType } from "./common";
19
19
  import { generatorTypePrefix } from "../config";
20
20
  import { hashCodeFromString, warn } from "../util";
21
21
  import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
22
- import { CppNameConvertor } from "./convertors/CppConvertors";
22
+ import { CppConvertor, CppNameConvertor } from "./convertors/CppConvertors";
23
23
  import { createEmptyReferenceResolver } from "../peer-generation/ReferenceResolver";
24
- import { CppConvertor } from "./convertors/CppConvertors";
25
24
  import { PrimitiveTypesInstance } from "../peer-generation/PrimitiveType";
25
+ import { qualifiedName } from "../peer-generation/idl/common";
26
+ function isDirectConvertedType(originalType, library) {
27
+ if (originalType == undefined)
28
+ return true; // TODO: is it correct?
29
+ if (originalType == idl.IDLInteropReturnBufferType)
30
+ return false;
31
+ if (originalType == idl.IDLThisType)
32
+ return true;
33
+ let convertor = library.typeConvertor("x", originalType, false);
34
+ // Resolve aliases.
35
+ while (convertor instanceof TypeAliasConvertor) {
36
+ convertor = convertor.convertor;
37
+ }
38
+ // Temporary!
39
+ if (convertor instanceof ArrayConvertor ||
40
+ convertor instanceof MapConvertor ||
41
+ convertor instanceof CustomTypeConvertor ||
42
+ convertor instanceof CallbackConvertor ||
43
+ convertor instanceof AggregateConvertor ||
44
+ convertor instanceof UnionConvertor) {
45
+ // try { console.log(`convertor is ${convertor.constructor.name} for ${JSON.stringify(originalType)}`) } catch (e) {}
46
+ return false;
47
+ }
48
+ let type = convertor.interopType();
49
+ // TODO: make 'number' be direct!
50
+ let result = type == idl.IDLI8Type || type == idl.IDLU8Type
51
+ || type == idl.IDLI16Type || type == idl.IDLU16Type
52
+ || type == idl.IDLI32Type || type == idl.IDLU32Type
53
+ || type == idl.IDLF32Type
54
+ || type == idl.IDLI64Type || type == idl.IDLU64Type
55
+ || type == idl.IDLPointerType
56
+ || type == idl.IDLBooleanType
57
+ || type == idl.IDLVoidType
58
+ || type == idl.IDLUndefinedType;
59
+ // try { if (!result) console.log(`type ${JSON.stringify(type)} is not direct`) } catch (e) {}
60
+ return result;
61
+ }
62
+ export function isVMContextMethod(method) {
63
+ var _a, _b;
64
+ return !!idl.asPromise(method.signature.returnType) ||
65
+ !!((_a = method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.THROWS)) ||
66
+ !!((_b = method.modifiers) === null || _b === void 0 ? void 0 : _b.includes(MethodModifier.FORCE_CONTEXT));
67
+ }
68
+ export function isDirectMethod(method, library) {
69
+ if (isVMContextMethod(method))
70
+ return false;
71
+ let result = isDirectConvertedType(method.signature.returnType, library) &&
72
+ method.signature.args.every((arg) => isDirectConvertedType(arg, library));
73
+ //if (!result) console.log(`method ${method.name} is not direct`)
74
+ return result;
75
+ }
26
76
  export class BaseArgConvertor {
27
77
  constructor(idlType, runtimeTypes, isScoped, useArray, param) {
28
78
  this.idlType = idlType;
@@ -158,14 +208,10 @@ export class EnumConvertor extends BaseArgConvertor {
158
208
  this.enumEntry = enumEntry;
159
209
  }
160
210
  convertorArg(param, writer) {
161
- return writer.makeEnumCast(writer.escapeKeyword(param), false, this);
211
+ return writer.makeEnumCast(this.enumEntry, writer.escapeKeyword(param));
162
212
  }
163
213
  convertorSerialize(param, value, writer) {
164
- value =
165
- idl.isStringEnum(this.enumEntry)
166
- ? writer.ordinalFromEnum(writer.makeString(value), idl.createReferenceType(this.enumEntry)).asString()
167
- : writer.makeEnumCast(value, false, this);
168
- writer.writeMethodCall(`${param}Serializer`, "writeInt32", [value]);
214
+ writer.writeMethodCall(`${param}Serializer`, "writeInt32", [writer.makeEnumCast(this.enumEntry, value)]);
169
215
  }
170
216
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
171
217
  const readExpr = writer.makeMethodCall(`${deserializerName}`, "readInt32", []);
@@ -456,7 +502,9 @@ export class InterfaceConvertor extends BaseArgConvertor {
456
502
  return this.idlType;
457
503
  }
458
504
  interopType() {
459
- throw new Error("Must never be used");
505
+ // Actually shouldn't be used!
506
+ // throw new Error("Must never be used")
507
+ return idl.IDLObjectType;
460
508
  }
461
509
  isPointerType() {
462
510
  return true;
@@ -889,7 +937,7 @@ export class MaterializedClassConvertor extends BaseArgConvertor {
889
937
  convertorArg(param, writer) {
890
938
  switch (writer.language) {
891
939
  case Language.CPP:
892
- return `static_cast<${generatorTypePrefix()}${this.declaration.name}>(${param})`;
940
+ return `static_cast<${generatorTypePrefix()}${qualifiedName(this.declaration, "_")}>(${param})`;
893
941
  case Language.JAVA:
894
942
  case Language.CJ:
895
943
  return `MaterializedBase.toPeerPtr(${param})`;
@@ -898,12 +946,12 @@ export class MaterializedClassConvertor extends BaseArgConvertor {
898
946
  }
899
947
  }
900
948
  convertorSerialize(param, value, printer) {
901
- printer.writeStatement(printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, `write${this.declaration.name}`, [
949
+ printer.writeStatement(printer.makeStatement(printer.makeMethodCall(`${param}Serializer`, `write${qualifiedName(this.declaration, "_")}`, [
902
950
  printer.makeString(value)
903
951
  ])));
904
952
  }
905
953
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
906
- const readStatement = writer.makeCast(writer.makeMethodCall(`${deserializerName}`, `read${this.declaration.name}`, []), idl.createReferenceType(this.declaration));
954
+ const readStatement = writer.makeCast(writer.makeMethodCall(`${deserializerName}`, `read${qualifiedName(this.declaration, "_")}`, []), idl.createReferenceType(this.declaration));
907
955
  return assigneer(readStatement);
908
956
  }
909
957
  nativeType() {
@@ -154,7 +154,8 @@ export declare enum MethodModifier {
154
154
  GETTER = 6,
155
155
  SETTER = 7,
156
156
  THROWS = 8,
157
- FREE = 9
157
+ FREE = 9,
158
+ FORCE_CONTEXT = 10
158
159
  }
159
160
  export declare enum ClassModifier {
160
161
  PUBLIC = 0,
@@ -172,6 +173,7 @@ export declare class Method {
172
173
  signature: MethodSignature;
173
174
  modifiers: MethodModifier[] | undefined;
174
175
  generics?: string[] | undefined;
176
+ private static knownReferenceTypes;
175
177
  constructor(name: string, signature: MethodSignature, modifiers?: MethodModifier[] | undefined, generics?: string[] | undefined);
176
178
  }
177
179
  export declare class PrintHint {
@@ -263,7 +265,7 @@ export declare abstract class LanguageWriter {
263
265
  abstract get supportedFieldModifiers(): FieldModifier[];
264
266
  abstract enumFromOrdinal(value: LanguageExpression, enumEntry: idl.IDLType): LanguageExpression;
265
267
  abstract ordinalFromEnum(value: LanguageExpression, enumReference: idl.IDLType): LanguageExpression;
266
- abstract makeEnumCast(enumName: string, unsafe: boolean, convertor: ArgConvertor | undefined): string;
268
+ abstract makeEnumCast(enumEntry: idl.IDLEnum, enumName: string): string;
267
269
  abstract getNodeName(type: idl.IDLNode): string;
268
270
  abstract fork(options?: {
269
271
  resolver?: ReferenceResolver;
@@ -315,7 +317,6 @@ export declare abstract class LanguageWriter {
315
317
  makeString(value: string): LanguageExpression;
316
318
  makeNaryOp(op: string, args: LanguageExpression[]): LanguageExpression;
317
319
  makeStatement(expr: LanguageExpression): LanguageStatement;
318
- tryWriteQuick(method: Method): void;
319
320
  writeNativeMethodDeclaration(method: Method): void;
320
321
  writeUnsafeNativeMethodDeclaration(name: string, signature: MethodSignature): void;
321
322
  pushIndent(): void;
@@ -331,7 +332,7 @@ export declare abstract class LanguageWriter {
331
332
  /**
332
333
  * TODO: replace me with {@link makeUnsafeCast_}
333
334
  */
334
- makeUnsafeCast(convertor: ArgConvertor, param: string): string;
335
+ makeUnsafeCast(param: string): string;
335
336
  makeUnsafeCast_(value: LanguageExpression, type: idl.IDLType, typeOptions?: PrintHint): string;
336
337
  runtimeType(param: ArgConvertor, valueType: string, value: string): void;
337
338
  makeDiscriminatorFromFields(convertor: {
@@ -317,6 +317,7 @@ export var MethodModifier;
317
317
  MethodModifier[MethodModifier["SETTER"] = 7] = "SETTER";
318
318
  MethodModifier[MethodModifier["THROWS"] = 8] = "THROWS";
319
319
  MethodModifier[MethodModifier["FREE"] = 9] = "FREE";
320
+ MethodModifier[MethodModifier["FORCE_CONTEXT"] = 10] = "FORCE_CONTEXT";
320
321
  })(MethodModifier || (MethodModifier = {}));
321
322
  export var ClassModifier;
322
323
  (function (ClassModifier) {
@@ -339,6 +340,10 @@ export class Method {
339
340
  this.generics = generics;
340
341
  }
341
342
  }
343
+ // Mostly for synthetic methods.
344
+ Method.knownReferenceTypes = [
345
+ 'KInt', 'KPointer', 'undefined' /* This one looks like a bug */
346
+ ];
342
347
  export class PrintHint {
343
348
  constructor(hint) {
344
349
  this.hint = hint;
@@ -565,9 +570,7 @@ export class LanguageWriter {
565
570
  makeStatement(expr) {
566
571
  return new ExpressionStatement(expr);
567
572
  }
568
- tryWriteQuick(method) { }
569
573
  writeNativeMethodDeclaration(method) {
570
- this.tryWriteQuick(method);
571
574
  this.writeMethodDeclaration(method.name, method.signature);
572
575
  }
573
576
  writeUnsafeNativeMethodDeclaration(name, signature) {
@@ -609,7 +612,7 @@ export class LanguageWriter {
609
612
  /**
610
613
  * TODO: replace me with {@link makeUnsafeCast_}
611
614
  */
612
- makeUnsafeCast(convertor, param) {
615
+ makeUnsafeCast(param) {
613
616
  return `unsafeCast<int32>(${param})`;
614
617
  }
615
618
  makeUnsafeCast_(value, type, typeOptions) {
@@ -25,7 +25,7 @@ export declare class GenericCppConvertor implements NodeConvertor<ConvertResult>
25
25
  convertTypeReference(type: idl.IDLReferenceType): ConvertResult;
26
26
  convertTypeParameter(type: idl.IDLTypeParameterType): ConvertResult;
27
27
  convertPrimitiveType(type: idl.IDLPrimitiveType): ConvertResult;
28
- private enumName;
28
+ private qualifiedName;
29
29
  private computeTargetTypeLiteralName;
30
30
  }
31
31
  export declare class CppConvertor extends GenericCppConvertor implements IdlNameConvertor {
@@ -39,34 +39,34 @@ export class GenericCppConvertor {
39
39
  switch (node.subkind) {
40
40
  case idl.IDLInterfaceSubkind.AnonymousInterface:
41
41
  return node.name
42
- ? this.make(node.name)
42
+ ? this.make(this.qualifiedName(node))
43
43
  : this.make(this.computeTargetTypeLiteralName(node), true);
44
44
  case idl.IDLInterfaceSubkind.Interface:
45
45
  case idl.IDLInterfaceSubkind.Class:
46
46
  if (isInIdlizeInternal(node)) {
47
- return this.make(node.name, true);
47
+ return this.make(this.qualifiedName(node), true);
48
48
  }
49
- return this.make(node.name);
49
+ return this.make(this.qualifiedName(node));
50
50
  case idl.IDLInterfaceSubkind.Tuple:
51
51
  return node.name
52
- ? this.make(node.name)
52
+ ? this.make(this.qualifiedName(node))
53
53
  : this.make(`Tuple_${node.properties.map(it => this.convertNode(idl.maybeOptional(it.type, it.isOptional)).text).join("_")}`, true);
54
54
  }
55
55
  }
56
56
  convertEnum(node) {
57
- return this.make(this.enumName(node));
57
+ return this.make(this.qualifiedName(node));
58
58
  }
59
59
  convertTypedef(node) {
60
- return this.make(node.name);
60
+ return this.make(this.qualifiedName(node));
61
61
  }
62
62
  convertCallback(node) {
63
- return this.make(generatorConfiguration().LibraryPrefix + node.name, true);
63
+ return this.make(generatorConfiguration().LibraryPrefix + this.qualifiedName(node), true);
64
64
  }
65
65
  convertMethod(node) {
66
66
  return this.make(node.name);
67
67
  }
68
68
  convertConstant(node) {
69
- return this.make(node.name);
69
+ return this.make(this.qualifiedName(node));
70
70
  }
71
71
  /////////////////////////////////////////////////////////////////////////////////////////
72
72
  convertOptional(type) {
@@ -152,7 +152,7 @@ export class GenericCppConvertor {
152
152
  }
153
153
  throw new Error(`Unmapped primitive type ${idl.DebugUtils.debugPrintType(type)}`);
154
154
  }
155
- enumName(target) {
155
+ qualifiedName(target) {
156
156
  return qualifiedName(target, "_");
157
157
  }
158
158
  computeTargetTypeLiteralName(decl) {
@@ -262,7 +262,7 @@ export class CppReturnTypeConvertor {
262
262
  convertTypeReference(type) {
263
263
  const decl = this.resolver.resolveTypeReference(type);
264
264
  if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
265
- return generatorTypePrefix() + decl.name;
265
+ return generatorTypePrefix() + qualifiedName(decl, "_");
266
266
  }
267
267
  return this.convertor.convert(type);
268
268
  }
@@ -97,7 +97,7 @@ export declare class CJLanguageWriter extends LanguageWriter {
97
97
  private writeDeclaration;
98
98
  writeNativeFunctionCall(printer: LanguageWriter, name: string, signature: MethodSignature): void;
99
99
  writeNativeMethodDeclaration(method: Method): void;
100
- makeEnumCast(enumName: string, _unsafe: boolean, _convertor: ArgConvertor | undefined): string;
100
+ makeEnumCast(_enumEntry: idl.IDLEnum, enumName: string): string;
101
101
  makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean): LanguageStatement;
102
102
  makeClassInit(type: idl.IDLType, parameters: LanguageExpression[]): LanguageExpression;
103
103
  makeArrayInit(type: idl.IDLContainerType, size?: number): LanguageExpression;
@@ -410,7 +410,7 @@ export class CJLanguageWriter extends LanguageWriter {
410
410
  name = name.startsWith('_') ? name.slice(1) : name;
411
411
  this.print(`func ${name}(${signture}): ${this.typeForeignConvertor.convert(method.signature.returnType)}`);
412
412
  }
413
- makeEnumCast(enumName, _unsafe, _convertor) {
413
+ makeEnumCast(_enumEntry, enumName) {
414
414
  return `${enumName}.value`;
415
415
  }
416
416
  makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
@@ -7,6 +7,7 @@ import { IdlNameConvertor } from "../nameConvertor";
7
7
  import { RuntimeType } from "../common";
8
8
  import { IndentedPrinter } from "../../IndentedPrinter";
9
9
  import { ReferenceResolver } from "../../peer-generation/ReferenceResolver";
10
+ import * as idl from "../../idl";
10
11
  export declare class CppCastExpression implements LanguageExpression {
11
12
  convertor: IdlNameConvertor;
12
13
  value: LanguageExpression;
@@ -102,9 +103,9 @@ export declare class CppLanguageWriter extends CLikeLanguageWriter {
102
103
  get supportedFieldModifiers(): FieldModifier[];
103
104
  enumFromOrdinal(value: LanguageExpression, type: IDLType): LanguageExpression;
104
105
  ordinalFromEnum(value: LanguageExpression, _: IDLType): LanguageExpression;
105
- makeUnsafeCast(convertor: ArgConvertor, param: string): string;
106
+ makeUnsafeCast(param: string): string;
106
107
  makeUnsafeCast_(value: LanguageExpression, type: IDLType, typeOptions?: PrintHint): string;
107
- makeEnumCast(value: string, _unsafe: boolean, convertor: ArgConvertor | undefined): string;
108
+ makeEnumCast(enumEntry: idl.IDLEnum, value: string): string;
108
109
  escapeKeyword(name: string): string;
109
110
  makeEnumEntity(enumEntity: IDLEnum, isExport: boolean): LanguageStatement;
110
111
  private decayTypeName;
@@ -19,8 +19,8 @@ import { AssignStatement, BlockStatement, FieldModifier, PrintHint, MethodModifi
19
19
  import { CDefinedExpression, CLikeExpressionStatement, CLikeLanguageWriter, CLikeLoopStatement, CLikeReturnStatement } from "./CLikeLanguageWriter";
20
20
  import { RuntimeType } from "../common";
21
21
  import { IndentedPrinter } from "../../IndentedPrinter";
22
- import { throwException } from "../../util";
23
22
  import { cppKeywords } from "../../languageSpecificKeywords";
23
+ import * as idl from "../../idl";
24
24
  ////////////////////////////////////////////////////////////////
25
25
  // EXPRESSIONS //
26
26
  ////////////////////////////////////////////////////////////////
@@ -376,7 +376,7 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
376
376
  ordinalFromEnum(value, _) {
377
377
  return value;
378
378
  }
379
- makeUnsafeCast(convertor, param) {
379
+ makeUnsafeCast(param) {
380
380
  return param;
381
381
  }
382
382
  makeUnsafeCast_(value, type, typeOptions) {
@@ -396,11 +396,8 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
396
396
  }
397
397
  return `(${typeName}) (${value.asString()})`;
398
398
  }
399
- makeEnumCast(value, _unsafe, convertor) {
400
- if (convertor !== undefined) {
401
- return `static_cast<${this.typeConvertor.convert(convertor.nativeType())}>(${value})`;
402
- }
403
- throwException("Need pass EnumConvertor");
399
+ makeEnumCast(enumEntry, value) {
400
+ return `static_cast<${this.typeConvertor.convert(idl.createReferenceType(enumEntry))}>(${value})`;
404
401
  }
405
402
  escapeKeyword(name) {
406
403
  return cppKeywords.has(name) ? name + "_" : name;
@@ -42,7 +42,6 @@ export declare class ETSLanguageWriter extends TSLanguageWriter {
42
42
  makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
43
43
  makeMapSize(map: string): LanguageExpression;
44
44
  get supportedModifiers(): MethodModifier[];
45
- makeUnsafeCast(convertor: ArgConvertor, param: string): string;
46
45
  runtimeType(param: ArgConvertor, valueType: string, value: string): void;
47
46
  makeUnionVariantCast(value: string, type: string, convertor: ArgConvertor, index?: number): LanguageExpression;
48
47
  enumFromOrdinal(value: LanguageExpression, enumEntry: idl.IDLType): LanguageExpression;
@@ -55,12 +54,9 @@ export declare class ETSLanguageWriter extends TSLanguageWriter {
55
54
  makeEnumEntity(enumEntity: IDLEnum, isExport: boolean): LanguageStatement;
56
55
  getObjectAccessor(convertor: ArgConvertor, value: string, args?: ObjectArgs): string;
57
56
  writeMethodCall(receiver: string, method: string, params: string[], nullable?: boolean): void;
58
- isDirectType(type: IDLType): boolean;
59
57
  isQuickType(type: IDLType): boolean;
60
- tryWriteQuick(method: Method): void;
61
58
  writeNativeMethodDeclaration(method: Method): void;
62
59
  writeProperty(propName: string, propType: IDLType): void;
63
- makeEnumCast(value: string, _unsafe: boolean, convertor: ArgConvertor | undefined): string;
64
60
  makeUnionVariantCondition(convertor: ArgConvertor, valueName: string, valueType: string, type: string, convertorIndex: number, runtimeTypeIndex: number): LanguageExpression;
65
61
  makeCastCustomObject(customName: string, isGenericType: boolean): LanguageExpression;
66
62
  makeHasOwnProperty(value: string, valueTypeName: string, property: string, propertyTypeName: string): LanguageExpression;
@@ -15,14 +15,13 @@
15
15
  import { IndentedPrinter } from "../../IndentedPrinter";
16
16
  import { LambdaExpression, MethodModifier } from "../LanguageWriter";
17
17
  import { TSCastExpression, TSLanguageWriter } from "./TsLanguageWriter";
18
- import { getExtAttribute, IDLI32Type, IDLThisType } from '../../idl';
18
+ import { getExtAttribute, IDLThisType } from '../../idl';
19
19
  import { AggregateConvertor, ArrayConvertor, CustomTypeConvertor, InterfaceConvertor, MaterializedClassConvertor, OptionConvertor, UnionConvertor, BufferConvertor } from "../ArgConvertors";
20
20
  import * as idl from '../../idl';
21
21
  import { convertDeclaration } from "../nameConvertor";
22
22
  import { createDeclarationNameConvertor } from "../../peer-generation/idl/IdlNameConvertor";
23
23
  import { Language } from "../../Language";
24
24
  import { RuntimeType } from "../common";
25
- import { throwException } from "../../util";
26
25
  ////////////////////////////////////////////////////////////////
27
26
  // STATEMENTS //
28
27
  ////////////////////////////////////////////////////////////////
@@ -177,13 +176,6 @@ export class ETSLanguageWriter extends TSLanguageWriter {
177
176
  get supportedModifiers() {
178
177
  return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.NATIVE, MethodModifier.STATIC];
179
178
  }
180
- makeUnsafeCast(convertor, param) {
181
- if (idl.isEnum(convertor.idlType) && !param.endsWith(".value")) {
182
- const isStringEnum = idl.isStringEnum(convertor.idlType);
183
- return `(${param} as ${this.typeConvertor.convert(convertor.idlType)}).${isStringEnum ? 'ordinal' : 'value'}`;
184
- }
185
- return super.makeUnsafeCast(convertor, param);
186
- }
187
179
  runtimeType(param, valueType, value) {
188
180
  super.runtimeType(param, valueType, value);
189
181
  }
@@ -226,48 +218,18 @@ export class ETSLanguageWriter extends TSLanguageWriter {
226
218
  // ArkTS does not support - 'this.?'
227
219
  super.writeMethodCall(receiver, method, params, nullable && receiver !== "this");
228
220
  }
229
- isDirectType(type) {
230
- let converted = this.getNodeName(type);
231
- return type == idl.IDLI32Type || type == idl.IDLPointerType || type == idl.IDLBooleanType
232
- || type == idl.IDLVoidType || converted == "KPointer" || converted == "KInt";
233
- }
234
221
  isQuickType(type) {
235
222
  return idl.asPromise(type) == undefined;
236
223
  }
237
- tryWriteQuick(method) {
238
- var _a;
239
- if ((_a = method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.THROWS))
240
- return;
241
- if (false && this.isDirectType(method.signature.returnType) && method.signature.args.every((type) => this.isDirectType(type))) {
242
- this.print('@ani.unsafe.Direct');
243
- return;
244
- }
245
- if (this.isQuickType(method.signature.returnType)) {
246
- this.print('@ani.unsafe.Quick');
247
- return;
248
- }
249
- }
250
224
  writeNativeMethodDeclaration(method) {
251
225
  if (method.signature.returnType === IDLThisType) {
252
226
  throw new Error('static method can not return this!');
253
227
  }
254
- this.tryWriteQuick(method);
255
228
  this.writeMethodDeclaration(method.name, method.signature, [MethodModifier.STATIC, MethodModifier.NATIVE]);
256
229
  }
257
230
  writeProperty(propName, propType) {
258
231
  throw new Error("writeProperty for ArkTS is not implemented yet.");
259
232
  }
260
- makeEnumCast(value, _unsafe, convertor) {
261
- if (convertor === undefined) {
262
- throwException(`The makeEnumCast function required EnumConvertor`);
263
- }
264
- const decl = this.resolver.toDeclaration(convertor.nativeType());
265
- if (!idl.isEnum(decl)) {
266
- throwException(`Declaration type must be Enum`);
267
- }
268
- // ((value as Axis) as int) - in case when Axis was casted to Object in Map<Axis, Smth>
269
- return this.makeCast(this.makeCast(this.makeString(value), convertor.idlType), IDLI32Type).asString();
270
- }
271
233
  makeUnionVariantCondition(convertor, valueName, valueType, type, convertorIndex, runtimeTypeIndex) {
272
234
  if (idl.isEnum(this.resolver.toDeclaration(convertor.nativeType()))) {
273
235
  return this.instanceOf(convertor, valueName);
@@ -78,7 +78,7 @@ export declare class JavaLanguageWriter extends CLikeLanguageWriter {
78
78
  ordinalFromEnum(value: LanguageExpression, _: idl.IDLType): LanguageExpression;
79
79
  makeValueFromOption(value: string): LanguageExpression;
80
80
  runtimeType(param: ArgConvertor, valueType: string, value: string): void;
81
- makeEnumCast(enumName: string, _unsafe: boolean, _convertor: ArgConvertor | undefined): string;
81
+ makeEnumCast(_enumEntry: idl.IDLEnum, enumName: string): string;
82
82
  castToBoolean(value: string): string;
83
83
  makeLengthSerializer(serializer: string, value: string): LanguageStatement | undefined;
84
84
  }
@@ -267,7 +267,7 @@ export class JavaLanguageWriter extends CLikeLanguageWriter {
267
267
  runtimeType(param, valueType, value) {
268
268
  this.writeStatement(this.makeAssign(valueType, undefined, this.makeRuntimeTypeGetterCall(value), false));
269
269
  }
270
- makeEnumCast(enumName, _unsafe, _convertor) {
270
+ makeEnumCast(_enumEntry, enumName) {
271
271
  return `${enumName}.value`;
272
272
  }
273
273
  castToBoolean(value) { return value; }
@@ -85,7 +85,7 @@ export declare class TSLanguageWriter extends LanguageWriter {
85
85
  get supportedFieldModifiers(): FieldModifier[];
86
86
  enumFromOrdinal(value: LanguageExpression, enumEntry: idl.IDLType): LanguageExpression;
87
87
  ordinalFromEnum(value: LanguageExpression, enumEntry: idl.IDLType): LanguageExpression;
88
- makeEnumCast(enumName: string, unsafe: boolean, convertor: ArgConvertor): string;
88
+ makeEnumCast(enumEntry: idl.IDLEnum, param: string): string;
89
89
  castToBoolean(value: string): string;
90
90
  makeCallIsObject(value: string): LanguageExpression;
91
91
  escapeKeyword(keyword: string): string;
@@ -13,13 +13,13 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import * as idl from '../../idl';
16
+ import { isOptionalType } from '../../idl';
16
17
  import { Language } from '../../Language';
17
18
  import { IndentedPrinter } from "../../IndentedPrinter";
18
19
  import { AssignStatement, BlockStatement, CheckOptionalStatement, ExpressionStatement, FieldModifier, IfStatement, LambdaExpression, LanguageWriter, Method, MethodModifier, NamedMethodSignature, NaryOpExpression, ReturnStatement, StringExpression } from "../LanguageWriter";
19
20
  import { RuntimeType } from "../common";
20
21
  import { rightmostIndexOf, throwException } from "../../util";
21
22
  import { TSKeywords } from '../../languageSpecificKeywords';
22
- import { isOptionalType } from "../../idl";
23
23
  ////////////////////////////////////////////////////////////////
24
24
  // EXPRESSIONS //
25
25
  ////////////////////////////////////////////////////////////////
@@ -388,11 +388,12 @@ export class TSLanguageWriter extends LanguageWriter {
388
388
  }
389
389
  return value;
390
390
  }
391
- makeEnumCast(enumName, unsafe, convertor) {
392
- if (unsafe) {
393
- return this.makeUnsafeCast(convertor, enumName);
394
- }
395
- return enumName;
391
+ makeEnumCast(enumEntry, param) {
392
+ // Take the ordinal value if Enum is a string, and valueOf when it is an integer
393
+ // Enum.valueOf() - compatible with ArkTS/TS
394
+ return idl.isStringEnum(enumEntry)
395
+ ? this.ordinalFromEnum(this.makeString(param), idl.createReferenceType(enumEntry)).asString()
396
+ : `${param}.valueOf()`;
396
397
  }
397
398
  castToBoolean(value) { return `+${value}`; }
398
399
  makeCallIsObject(value) {
@@ -13,6 +13,7 @@ export declare const CoreConfigurationSchema: {
13
13
  readonly builderClasses: string[];
14
14
  readonly forceMaterialized: string[];
15
15
  readonly forceCallback: string[];
16
+ readonly forceContext: string[];
16
17
  }>;
17
18
  success(): boolean;
18
19
  unwrap(): {
@@ -26,6 +27,7 @@ export declare const CoreConfigurationSchema: {
26
27
  readonly builderClasses: string[];
27
28
  readonly forceMaterialized: string[];
28
29
  readonly forceCallback: string[];
30
+ readonly forceContext: string[];
29
31
  };
30
32
  error(): string;
31
33
  get(): import("./configDescriber").ValidationResult<{
@@ -39,6 +41,7 @@ export declare const CoreConfigurationSchema: {
39
41
  readonly builderClasses: string[];
40
42
  readonly forceMaterialized: string[];
41
43
  readonly forceCallback: string[];
44
+ readonly forceContext: string[];
42
45
  }>;
43
46
  or<U>(x: U): {
44
47
  box: import("./configDescriber").ValidationResult<{
@@ -52,6 +55,7 @@ export declare const CoreConfigurationSchema: {
52
55
  readonly builderClasses: string[];
53
56
  readonly forceMaterialized: string[];
54
57
  readonly forceCallback: string[];
58
+ readonly forceContext: string[];
55
59
  } | U>;
56
60
  success(): boolean;
57
61
  unwrap(): {
@@ -65,6 +69,7 @@ export declare const CoreConfigurationSchema: {
65
69
  readonly builderClasses: string[];
66
70
  readonly forceMaterialized: string[];
67
71
  readonly forceCallback: string[];
72
+ readonly forceContext: string[];
68
73
  } | U;
69
74
  error(): string;
70
75
  get(): import("./configDescriber").ValidationResult<{
@@ -78,6 +83,7 @@ export declare const CoreConfigurationSchema: {
78
83
  readonly builderClasses: string[];
79
84
  readonly forceMaterialized: string[];
80
85
  readonly forceCallback: string[];
86
+ readonly forceContext: string[];
81
87
  } | U>;
82
88
  or<U_1>(x: U_1): {
83
89
  box: import("./configDescriber").ValidationResult<{
@@ -91,6 +97,7 @@ export declare const CoreConfigurationSchema: {
91
97
  readonly builderClasses: string[];
92
98
  readonly forceMaterialized: string[];
93
99
  readonly forceCallback: string[];
100
+ readonly forceContext: string[];
94
101
  } | U | U_1>;
95
102
  success(): boolean;
96
103
  unwrap(): {
@@ -104,6 +111,7 @@ export declare const CoreConfigurationSchema: {
104
111
  readonly builderClasses: string[];
105
112
  readonly forceMaterialized: string[];
106
113
  readonly forceCallback: string[];
114
+ readonly forceContext: string[];
107
115
  } | U | U_1;
108
116
  error(): string;
109
117
  get(): import("./configDescriber").ValidationResult<{
@@ -117,6 +125,7 @@ export declare const CoreConfigurationSchema: {
117
125
  readonly builderClasses: string[];
118
126
  readonly forceMaterialized: string[];
119
127
  readonly forceCallback: string[];
128
+ readonly forceContext: string[];
120
129
  } | U | U_1>;
121
130
  or<U_2>(x: U_2): {
122
131
  box: import("./configDescriber").ValidationResult<{
@@ -130,6 +139,7 @@ export declare const CoreConfigurationSchema: {
130
139
  readonly builderClasses: string[];
131
140
  readonly forceMaterialized: string[];
132
141
  readonly forceCallback: string[];
142
+ readonly forceContext: string[];
133
143
  } | U | U_1 | U_2>;
134
144
  success(): boolean;
135
145
  unwrap(): {
@@ -143,6 +153,7 @@ export declare const CoreConfigurationSchema: {
143
153
  readonly builderClasses: string[];
144
154
  readonly forceMaterialized: string[];
145
155
  readonly forceCallback: string[];
156
+ readonly forceContext: string[];
146
157
  } | U | U_1 | U_2;
147
158
  error(): string;
148
159
  get(): import("./configDescriber").ValidationResult<{
@@ -156,6 +167,7 @@ export declare const CoreConfigurationSchema: {
156
167
  readonly builderClasses: string[];
157
168
  readonly forceMaterialized: string[];
158
169
  readonly forceCallback: string[];
170
+ readonly forceContext: string[];
159
171
  } | U | U_1 | U_2>;
160
172
  or<U_3>(x: U_3): {
161
173
  box: import("./configDescriber").ValidationResult<{
@@ -169,6 +181,7 @@ export declare const CoreConfigurationSchema: {
169
181
  readonly builderClasses: string[];
170
182
  readonly forceMaterialized: string[];
171
183
  readonly forceCallback: string[];
184
+ readonly forceContext: string[];
172
185
  } | U | U_1 | U_2 | U_3>;
173
186
  success(): boolean;
174
187
  unwrap(): {
@@ -182,6 +195,7 @@ export declare const CoreConfigurationSchema: {
182
195
  readonly builderClasses: string[];
183
196
  readonly forceMaterialized: string[];
184
197
  readonly forceCallback: string[];
198
+ readonly forceContext: string[];
185
199
  } | U | U_1 | U_2 | U_3;
186
200
  error(): string;
187
201
  get(): import("./configDescriber").ValidationResult<{
@@ -195,6 +209,7 @@ export declare const CoreConfigurationSchema: {
195
209
  readonly builderClasses: string[];
196
210
  readonly forceMaterialized: string[];
197
211
  readonly forceCallback: string[];
212
+ readonly forceContext: string[];
198
213
  } | U | U_1 | U_2 | U_3>;
199
214
  or<U_4>(x: U_4): {
200
215
  box: import("./configDescriber").ValidationResult<{
@@ -208,6 +223,7 @@ export declare const CoreConfigurationSchema: {
208
223
  readonly builderClasses: string[];
209
224
  readonly forceMaterialized: string[];
210
225
  readonly forceCallback: string[];
226
+ readonly forceContext: string[];
211
227
  } | U | U_1 | U_2 | U_3 | U_4>;
212
228
  success(): boolean;
213
229
  unwrap(): {
@@ -221,6 +237,7 @@ export declare const CoreConfigurationSchema: {
221
237
  readonly builderClasses: string[];
222
238
  readonly forceMaterialized: string[];
223
239
  readonly forceCallback: string[];
240
+ readonly forceContext: string[];
224
241
  } | U | U_1 | U_2 | U_3 | U_4;
225
242
  error(): string;
226
243
  get(): import("./configDescriber").ValidationResult<{
@@ -234,6 +251,7 @@ export declare const CoreConfigurationSchema: {
234
251
  readonly builderClasses: string[];
235
252
  readonly forceMaterialized: string[];
236
253
  readonly forceCallback: string[];
254
+ readonly forceContext: string[];
237
255
  } | U | U_1 | U_2 | U_3 | U_4>;
238
256
  or<U_5>(x: U_5): {
239
257
  box: import("./configDescriber").ValidationResult<{
@@ -247,6 +265,7 @@ export declare const CoreConfigurationSchema: {
247
265
  readonly builderClasses: string[];
248
266
  readonly forceMaterialized: string[];
249
267
  readonly forceCallback: string[];
268
+ readonly forceContext: string[];
250
269
  } | U | U_1 | U_2 | U_3 | U_4 | U_5>;
251
270
  success(): boolean;
252
271
  unwrap(): {
@@ -260,6 +279,7 @@ export declare const CoreConfigurationSchema: {
260
279
  readonly builderClasses: string[];
261
280
  readonly forceMaterialized: string[];
262
281
  readonly forceCallback: string[];
282
+ readonly forceContext: string[];
263
283
  } | U | U_1 | U_2 | U_3 | U_4 | U_5;
264
284
  error(): string;
265
285
  get(): import("./configDescriber").ValidationResult<{
@@ -273,6 +293,7 @@ export declare const CoreConfigurationSchema: {
273
293
  readonly builderClasses: string[];
274
294
  readonly forceMaterialized: string[];
275
295
  readonly forceCallback: string[];
296
+ readonly forceContext: string[];
276
297
  } | U | U_1 | U_2 | U_3 | U_4 | U_5>;
277
298
  or<U_6>(x: U_6): {
278
299
  box: import("./configDescriber").ValidationResult<{
@@ -286,6 +307,7 @@ export declare const CoreConfigurationSchema: {
286
307
  readonly builderClasses: string[];
287
308
  readonly forceMaterialized: string[];
288
309
  readonly forceCallback: string[];
310
+ readonly forceContext: string[];
289
311
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6>;
290
312
  success(): boolean;
291
313
  unwrap(): {
@@ -299,6 +321,7 @@ export declare const CoreConfigurationSchema: {
299
321
  readonly builderClasses: string[];
300
322
  readonly forceMaterialized: string[];
301
323
  readonly forceCallback: string[];
324
+ readonly forceContext: string[];
302
325
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6;
303
326
  error(): string;
304
327
  get(): import("./configDescriber").ValidationResult<{
@@ -312,6 +335,7 @@ export declare const CoreConfigurationSchema: {
312
335
  readonly builderClasses: string[];
313
336
  readonly forceMaterialized: string[];
314
337
  readonly forceCallback: string[];
338
+ readonly forceContext: string[];
315
339
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6>;
316
340
  or<U_7>(x: U_7): {
317
341
  box: import("./configDescriber").ValidationResult<{
@@ -325,6 +349,7 @@ export declare const CoreConfigurationSchema: {
325
349
  readonly builderClasses: string[];
326
350
  readonly forceMaterialized: string[];
327
351
  readonly forceCallback: string[];
352
+ readonly forceContext: string[];
328
353
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7>;
329
354
  success(): boolean;
330
355
  unwrap(): {
@@ -338,6 +363,7 @@ export declare const CoreConfigurationSchema: {
338
363
  readonly builderClasses: string[];
339
364
  readonly forceMaterialized: string[];
340
365
  readonly forceCallback: string[];
366
+ readonly forceContext: string[];
341
367
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7;
342
368
  error(): string;
343
369
  get(): import("./configDescriber").ValidationResult<{
@@ -351,6 +377,7 @@ export declare const CoreConfigurationSchema: {
351
377
  readonly builderClasses: string[];
352
378
  readonly forceMaterialized: string[];
353
379
  readonly forceCallback: string[];
380
+ readonly forceContext: string[];
354
381
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7>;
355
382
  or<U_8>(x: U_8): {
356
383
  box: import("./configDescriber").ValidationResult<{
@@ -364,6 +391,7 @@ export declare const CoreConfigurationSchema: {
364
391
  readonly builderClasses: string[];
365
392
  readonly forceMaterialized: string[];
366
393
  readonly forceCallback: string[];
394
+ readonly forceContext: string[];
367
395
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8>;
368
396
  success(): boolean;
369
397
  unwrap(): {
@@ -377,6 +405,7 @@ export declare const CoreConfigurationSchema: {
377
405
  readonly builderClasses: string[];
378
406
  readonly forceMaterialized: string[];
379
407
  readonly forceCallback: string[];
408
+ readonly forceContext: string[];
380
409
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8;
381
410
  error(): string;
382
411
  get(): import("./configDescriber").ValidationResult<{
@@ -390,6 +419,7 @@ export declare const CoreConfigurationSchema: {
390
419
  readonly builderClasses: string[];
391
420
  readonly forceMaterialized: string[];
392
421
  readonly forceCallback: string[];
422
+ readonly forceContext: string[];
393
423
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8>;
394
424
  or<U_9>(x: U_9): {
395
425
  box: import("./configDescriber").ValidationResult<{
@@ -403,6 +433,7 @@ export declare const CoreConfigurationSchema: {
403
433
  readonly builderClasses: string[];
404
434
  readonly forceMaterialized: string[];
405
435
  readonly forceCallback: string[];
436
+ readonly forceContext: string[];
406
437
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9>;
407
438
  success(): boolean;
408
439
  unwrap(): {
@@ -416,6 +447,7 @@ export declare const CoreConfigurationSchema: {
416
447
  readonly builderClasses: string[];
417
448
  readonly forceMaterialized: string[];
418
449
  readonly forceCallback: string[];
450
+ readonly forceContext: string[];
419
451
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9;
420
452
  error(): string;
421
453
  get(): import("./configDescriber").ValidationResult<{
@@ -429,6 +461,7 @@ export declare const CoreConfigurationSchema: {
429
461
  readonly builderClasses: string[];
430
462
  readonly forceMaterialized: string[];
431
463
  readonly forceCallback: string[];
464
+ readonly forceContext: string[];
432
465
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9>;
433
466
  or<U_10>(x: U_10): any;
434
467
  };
@@ -456,6 +489,7 @@ export declare const CoreConfigurationSchema: {
456
489
  readonly builderClasses: string[];
457
490
  readonly forceMaterialized: string[];
458
491
  readonly forceCallback: string[];
492
+ readonly forceContext: string[];
459
493
  }>;
460
494
  success(): boolean;
461
495
  unwrap(): {
@@ -469,6 +503,7 @@ export declare const CoreConfigurationSchema: {
469
503
  readonly builderClasses: string[];
470
504
  readonly forceMaterialized: string[];
471
505
  readonly forceCallback: string[];
506
+ readonly forceContext: string[];
472
507
  };
473
508
  error(): string;
474
509
  get(): import("./configDescriber").ValidationResult<{
@@ -482,6 +517,7 @@ export declare const CoreConfigurationSchema: {
482
517
  readonly builderClasses: string[];
483
518
  readonly forceMaterialized: string[];
484
519
  readonly forceCallback: string[];
520
+ readonly forceContext: string[];
485
521
  }>;
486
522
  or<U>(x: U): {
487
523
  box: import("./configDescriber").ValidationResult<{
@@ -495,6 +531,7 @@ export declare const CoreConfigurationSchema: {
495
531
  readonly builderClasses: string[];
496
532
  readonly forceMaterialized: string[];
497
533
  readonly forceCallback: string[];
534
+ readonly forceContext: string[];
498
535
  } | U>;
499
536
  success(): boolean;
500
537
  unwrap(): {
@@ -508,6 +545,7 @@ export declare const CoreConfigurationSchema: {
508
545
  readonly builderClasses: string[];
509
546
  readonly forceMaterialized: string[];
510
547
  readonly forceCallback: string[];
548
+ readonly forceContext: string[];
511
549
  } | U;
512
550
  error(): string;
513
551
  get(): import("./configDescriber").ValidationResult<{
@@ -521,6 +559,7 @@ export declare const CoreConfigurationSchema: {
521
559
  readonly builderClasses: string[];
522
560
  readonly forceMaterialized: string[];
523
561
  readonly forceCallback: string[];
562
+ readonly forceContext: string[];
524
563
  } | U>;
525
564
  or<U_1>(x: U_1): {
526
565
  box: import("./configDescriber").ValidationResult<{
@@ -534,6 +573,7 @@ export declare const CoreConfigurationSchema: {
534
573
  readonly builderClasses: string[];
535
574
  readonly forceMaterialized: string[];
536
575
  readonly forceCallback: string[];
576
+ readonly forceContext: string[];
537
577
  } | U | U_1>;
538
578
  success(): boolean;
539
579
  unwrap(): {
@@ -547,6 +587,7 @@ export declare const CoreConfigurationSchema: {
547
587
  readonly builderClasses: string[];
548
588
  readonly forceMaterialized: string[];
549
589
  readonly forceCallback: string[];
590
+ readonly forceContext: string[];
550
591
  } | U | U_1;
551
592
  error(): string;
552
593
  get(): import("./configDescriber").ValidationResult<{
@@ -560,6 +601,7 @@ export declare const CoreConfigurationSchema: {
560
601
  readonly builderClasses: string[];
561
602
  readonly forceMaterialized: string[];
562
603
  readonly forceCallback: string[];
604
+ readonly forceContext: string[];
563
605
  } | U | U_1>;
564
606
  or<U_2>(x: U_2): {
565
607
  box: import("./configDescriber").ValidationResult<{
@@ -573,6 +615,7 @@ export declare const CoreConfigurationSchema: {
573
615
  readonly builderClasses: string[];
574
616
  readonly forceMaterialized: string[];
575
617
  readonly forceCallback: string[];
618
+ readonly forceContext: string[];
576
619
  } | U | U_1 | U_2>;
577
620
  success(): boolean;
578
621
  unwrap(): {
@@ -586,6 +629,7 @@ export declare const CoreConfigurationSchema: {
586
629
  readonly builderClasses: string[];
587
630
  readonly forceMaterialized: string[];
588
631
  readonly forceCallback: string[];
632
+ readonly forceContext: string[];
589
633
  } | U | U_1 | U_2;
590
634
  error(): string;
591
635
  get(): import("./configDescriber").ValidationResult<{
@@ -599,6 +643,7 @@ export declare const CoreConfigurationSchema: {
599
643
  readonly builderClasses: string[];
600
644
  readonly forceMaterialized: string[];
601
645
  readonly forceCallback: string[];
646
+ readonly forceContext: string[];
602
647
  } | U | U_1 | U_2>;
603
648
  or<U_3>(x: U_3): {
604
649
  box: import("./configDescriber").ValidationResult<{
@@ -612,6 +657,7 @@ export declare const CoreConfigurationSchema: {
612
657
  readonly builderClasses: string[];
613
658
  readonly forceMaterialized: string[];
614
659
  readonly forceCallback: string[];
660
+ readonly forceContext: string[];
615
661
  } | U | U_1 | U_2 | U_3>;
616
662
  success(): boolean;
617
663
  unwrap(): {
@@ -625,6 +671,7 @@ export declare const CoreConfigurationSchema: {
625
671
  readonly builderClasses: string[];
626
672
  readonly forceMaterialized: string[];
627
673
  readonly forceCallback: string[];
674
+ readonly forceContext: string[];
628
675
  } | U | U_1 | U_2 | U_3;
629
676
  error(): string;
630
677
  get(): import("./configDescriber").ValidationResult<{
@@ -638,6 +685,7 @@ export declare const CoreConfigurationSchema: {
638
685
  readonly builderClasses: string[];
639
686
  readonly forceMaterialized: string[];
640
687
  readonly forceCallback: string[];
688
+ readonly forceContext: string[];
641
689
  } | U | U_1 | U_2 | U_3>;
642
690
  or<U_4>(x: U_4): {
643
691
  box: import("./configDescriber").ValidationResult<{
@@ -651,6 +699,7 @@ export declare const CoreConfigurationSchema: {
651
699
  readonly builderClasses: string[];
652
700
  readonly forceMaterialized: string[];
653
701
  readonly forceCallback: string[];
702
+ readonly forceContext: string[];
654
703
  } | U | U_1 | U_2 | U_3 | U_4>;
655
704
  success(): boolean;
656
705
  unwrap(): {
@@ -664,6 +713,7 @@ export declare const CoreConfigurationSchema: {
664
713
  readonly builderClasses: string[];
665
714
  readonly forceMaterialized: string[];
666
715
  readonly forceCallback: string[];
716
+ readonly forceContext: string[];
667
717
  } | U | U_1 | U_2 | U_3 | U_4;
668
718
  error(): string;
669
719
  get(): import("./configDescriber").ValidationResult<{
@@ -677,6 +727,7 @@ export declare const CoreConfigurationSchema: {
677
727
  readonly builderClasses: string[];
678
728
  readonly forceMaterialized: string[];
679
729
  readonly forceCallback: string[];
730
+ readonly forceContext: string[];
680
731
  } | U | U_1 | U_2 | U_3 | U_4>;
681
732
  or<U_5>(x: U_5): {
682
733
  box: import("./configDescriber").ValidationResult<{
@@ -690,6 +741,7 @@ export declare const CoreConfigurationSchema: {
690
741
  readonly builderClasses: string[];
691
742
  readonly forceMaterialized: string[];
692
743
  readonly forceCallback: string[];
744
+ readonly forceContext: string[];
693
745
  } | U | U_1 | U_2 | U_3 | U_4 | U_5>;
694
746
  success(): boolean;
695
747
  unwrap(): {
@@ -703,6 +755,7 @@ export declare const CoreConfigurationSchema: {
703
755
  readonly builderClasses: string[];
704
756
  readonly forceMaterialized: string[];
705
757
  readonly forceCallback: string[];
758
+ readonly forceContext: string[];
706
759
  } | U | U_1 | U_2 | U_3 | U_4 | U_5;
707
760
  error(): string;
708
761
  get(): import("./configDescriber").ValidationResult<{
@@ -716,6 +769,7 @@ export declare const CoreConfigurationSchema: {
716
769
  readonly builderClasses: string[];
717
770
  readonly forceMaterialized: string[];
718
771
  readonly forceCallback: string[];
772
+ readonly forceContext: string[];
719
773
  } | U | U_1 | U_2 | U_3 | U_4 | U_5>;
720
774
  or<U_6>(x: U_6): {
721
775
  box: import("./configDescriber").ValidationResult<{
@@ -729,6 +783,7 @@ export declare const CoreConfigurationSchema: {
729
783
  readonly builderClasses: string[];
730
784
  readonly forceMaterialized: string[];
731
785
  readonly forceCallback: string[];
786
+ readonly forceContext: string[];
732
787
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6>;
733
788
  success(): boolean;
734
789
  unwrap(): {
@@ -742,6 +797,7 @@ export declare const CoreConfigurationSchema: {
742
797
  readonly builderClasses: string[];
743
798
  readonly forceMaterialized: string[];
744
799
  readonly forceCallback: string[];
800
+ readonly forceContext: string[];
745
801
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6;
746
802
  error(): string;
747
803
  get(): import("./configDescriber").ValidationResult<{
@@ -755,6 +811,7 @@ export declare const CoreConfigurationSchema: {
755
811
  readonly builderClasses: string[];
756
812
  readonly forceMaterialized: string[];
757
813
  readonly forceCallback: string[];
814
+ readonly forceContext: string[];
758
815
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6>;
759
816
  or<U_7>(x: U_7): {
760
817
  box: import("./configDescriber").ValidationResult<{
@@ -768,6 +825,7 @@ export declare const CoreConfigurationSchema: {
768
825
  readonly builderClasses: string[];
769
826
  readonly forceMaterialized: string[];
770
827
  readonly forceCallback: string[];
828
+ readonly forceContext: string[];
771
829
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7>;
772
830
  success(): boolean;
773
831
  unwrap(): {
@@ -781,6 +839,7 @@ export declare const CoreConfigurationSchema: {
781
839
  readonly builderClasses: string[];
782
840
  readonly forceMaterialized: string[];
783
841
  readonly forceCallback: string[];
842
+ readonly forceContext: string[];
784
843
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7;
785
844
  error(): string;
786
845
  get(): import("./configDescriber").ValidationResult<{
@@ -794,6 +853,7 @@ export declare const CoreConfigurationSchema: {
794
853
  readonly builderClasses: string[];
795
854
  readonly forceMaterialized: string[];
796
855
  readonly forceCallback: string[];
856
+ readonly forceContext: string[];
797
857
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7>;
798
858
  or<U_8>(x: U_8): {
799
859
  box: import("./configDescriber").ValidationResult<{
@@ -807,6 +867,7 @@ export declare const CoreConfigurationSchema: {
807
867
  readonly builderClasses: string[];
808
868
  readonly forceMaterialized: string[];
809
869
  readonly forceCallback: string[];
870
+ readonly forceContext: string[];
810
871
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8>;
811
872
  success(): boolean;
812
873
  unwrap(): {
@@ -820,6 +881,7 @@ export declare const CoreConfigurationSchema: {
820
881
  readonly builderClasses: string[];
821
882
  readonly forceMaterialized: string[];
822
883
  readonly forceCallback: string[];
884
+ readonly forceContext: string[];
823
885
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8;
824
886
  error(): string;
825
887
  get(): import("./configDescriber").ValidationResult<{
@@ -833,6 +895,7 @@ export declare const CoreConfigurationSchema: {
833
895
  readonly builderClasses: string[];
834
896
  readonly forceMaterialized: string[];
835
897
  readonly forceCallback: string[];
898
+ readonly forceContext: string[];
836
899
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8>;
837
900
  or<U_9>(x: U_9): {
838
901
  box: import("./configDescriber").ValidationResult<{
@@ -846,6 +909,7 @@ export declare const CoreConfigurationSchema: {
846
909
  readonly builderClasses: string[];
847
910
  readonly forceMaterialized: string[];
848
911
  readonly forceCallback: string[];
912
+ readonly forceContext: string[];
849
913
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9>;
850
914
  success(): boolean;
851
915
  unwrap(): {
@@ -859,6 +923,7 @@ export declare const CoreConfigurationSchema: {
859
923
  readonly builderClasses: string[];
860
924
  readonly forceMaterialized: string[];
861
925
  readonly forceCallback: string[];
926
+ readonly forceContext: string[];
862
927
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9;
863
928
  error(): string;
864
929
  get(): import("./configDescriber").ValidationResult<{
@@ -872,6 +937,7 @@ export declare const CoreConfigurationSchema: {
872
937
  readonly builderClasses: string[];
873
938
  readonly forceMaterialized: string[];
874
939
  readonly forceCallback: string[];
940
+ readonly forceContext: string[];
875
941
  } | U | U_1 | U_2 | U_3 | U_4 | U_5 | U_6 | U_7 | U_8 | U_9>;
876
942
  or<U_10>(x: U_10): any;
877
943
  };
@@ -27,6 +27,7 @@ export const CoreConfigurationSchema = D.object({
27
27
  builderClasses: T.stringArray(),
28
28
  forceMaterialized: T.stringArray(),
29
29
  forceCallback: T.stringArray(),
30
+ forceContext: T.stringArray(),
30
31
  });
31
32
  export const defaultCoreConfiguration = {
32
33
  TypePrefix: "",
@@ -39,6 +40,7 @@ export const defaultCoreConfiguration = {
39
40
  builderClasses: [],
40
41
  forceMaterialized: [],
41
42
  forceCallback: [],
43
+ forceContext: [],
42
44
  };
43
45
  let currentConfig = defaultCoreConfiguration;
44
46
  export function setDefaultConfiguration(config) {
@@ -152,6 +152,8 @@ export class PeerLibrary {
152
152
  return entry;
153
153
  const qualifiedName = type.name.split(".");
154
154
  let pointOfViewNamespace = idl.fetchNamespaceFrom(type.parent);
155
+ // TODO: Choose what to do if `rootEntries.some(it => idl.isNamespace(it))`
156
+ // One of possible options - `rootEntries = rootEntries.flatMap(it => idl.isNamespace(it) ? it.members : it)` - cause error
155
157
  rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
156
158
  if (1 === qualifiedName.length) {
157
159
  const predefined = rootEntries.filter(it => isInIdlizeInternal(it));
@@ -248,6 +250,17 @@ export class PeerLibrary {
248
250
  if (idl.isReferenceType(type)) {
249
251
  if (isImportAttr(type))
250
252
  return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
253
+ // TODO: special cases for interop types.
254
+ switch (type.name) {
255
+ case 'KBoolean': return new BooleanConvertor(param);
256
+ case 'KInt': return new NumericConvertor(param, idl.IDLI32Type);
257
+ case 'KFloat': return new NumericConvertor(param, idl.IDLF32Type);
258
+ case 'KLong': return new NumericConvertor(param, idl.IDLI64Type);
259
+ case 'KDouble': return new NumericConvertor(param, idl.IDLF64Type);
260
+ case 'KStringPtr': return new StringConvertor(param);
261
+ case 'number': return new NumberConvertor(param);
262
+ case 'KPointer': return new PointerConvertor(param);
263
+ }
251
264
  const decl = this.resolveTypeReference(type);
252
265
  return this.declarationConvertor(param, type, decl);
253
266
  }
@@ -1,19 +1,6 @@
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
1
  import { generatorTypePrefix } from "../config";
16
2
  import { asPromise } from "../idl";
3
+ import { isVMContextMethod } from "../LanguageWriters/ArgConvertors";
17
4
  import { mangleMethodName, MethodModifier } from "../LanguageWriters/LanguageWriter";
18
5
  import { capitalize, isDefined } from "../util";
19
6
  import { PrimitiveTypesInstance } from "./PrimitiveType";
@@ -71,7 +58,6 @@ export class PeerMethod {
71
58
  return !((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.STATIC));
72
59
  }
73
60
  generateAPIParameters(converter) {
74
- var _a;
75
61
  const args = this.argAndOutConvertors.map(it => {
76
62
  let isPointer = it.isPointerType();
77
63
  return `${isPointer ? "const " : ""}${converter.convert(it.nativeType())}${isPointer ? "*" : ""} ${it.param}`;
@@ -81,7 +67,7 @@ export class PeerMethod {
81
67
  args.unshift(`${receiver.argType} ${receiver.argName}`);
82
68
  if (!!asPromise(this.method.signature.returnType))
83
69
  args.unshift(`${generatorTypePrefix()}AsyncWorkerPtr asyncWorker`);
84
- if (!!asPromise(this.method.signature.returnType) || ((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.THROWS)))
70
+ if (isVMContextMethod(this.method))
85
71
  args.unshift(`${generatorTypePrefix()}VMContext vmContext`);
86
72
  return args;
87
73
  }
@@ -47,7 +47,22 @@ export function isMaterialized(declaration, resolver) {
47
47
  return false;
48
48
  }
49
49
  export function isStaticMaterialized(declaration, resolver) {
50
- return isMaterialized(declaration, resolver) && (declaration.methods.length > 0 && declaration.methods.every(it => it.isStatic)) && !declaration.properties.length && !declaration.constructors.length;
50
+ if (isMaterialized(declaration, resolver)) {
51
+ if (declaration.properties.length || declaration.constructors.length)
52
+ return false;
53
+ if (!declaration.methods.every(it => it.isStatic))
54
+ return false;
55
+ if (idl.hasSuperType(declaration)) {
56
+ const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
57
+ if (!superType || !idl.isInterface(superType)) {
58
+ console.log(`Unable to resolve ${idl.getSuperType(declaration).name} type, consider ${declaration.name} to be not materialized`);
59
+ return false;
60
+ }
61
+ return isStaticMaterialized(superType, resolver);
62
+ }
63
+ return true;
64
+ }
65
+ return false;
51
66
  }
52
67
  export function isMaterializedType(type, resolver) {
53
68
  if (!idl.isReferenceType(type))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.0.43",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "keywords": [],
36
36
  "dependencies": {
37
- "@koalaui/interop": "1.5.8",
37
+ "@koalaui/interop": "1.5.9",
38
38
  "typescript": "4.9.5",
39
39
  "@types/node": "^18.0.0"
40
40
  },