@idlizer/core 2.1.10-arktscgen-4 → 2.1.10-arktscgen-6

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 (122) hide show
  1. package/build/lib/src/Language.d.ts +0 -1
  2. package/build/lib/src/Language.js +1 -3
  3. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -7
  4. package/build/lib/src/LanguageWriters/ArgConvertors.js +95 -103
  5. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +13 -7
  6. package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -2
  7. package/build/lib/src/LanguageWriters/common.d.ts +1 -0
  8. package/build/lib/src/LanguageWriters/common.js +2 -1
  9. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +0 -1
  10. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -3
  11. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +14 -8
  12. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +88 -36
  13. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
  14. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
  15. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
  16. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +9 -5
  17. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -4
  18. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +98 -44
  19. package/build/lib/src/LanguageWriters/index.d.ts +5 -4
  20. package/build/lib/src/LanguageWriters/index.js +8 -15
  21. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
  22. package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
  23. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
  24. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +13 -1
  25. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -0
  26. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +8 -2
  27. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -10
  28. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +52 -92
  29. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +8 -0
  30. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +75 -27
  31. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +5 -0
  32. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +58 -18
  33. package/build/lib/src/LibraryInterface.d.ts +0 -1
  34. package/build/lib/src/config.d.ts +2 -1461
  35. package/build/lib/src/config.js +16 -32
  36. package/build/lib/src/configMerge.d.ts +3 -0
  37. package/build/lib/src/configMerge.js +63 -0
  38. package/build/lib/src/diagnostictypes.d.ts +1 -5
  39. package/build/lib/src/diagnostictypes.js +1 -27
  40. package/build/lib/src/from-idl/DtsPrinter.js +13 -6
  41. package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
  42. package/build/lib/src/from-idl/IDLLinter.js +30 -32
  43. package/build/lib/src/from-idl/deserialize.d.ts +3 -4
  44. package/build/lib/src/from-idl/deserialize.js +30 -642
  45. package/build/lib/src/from-idl/parser.d.ts +20 -2
  46. package/build/lib/src/from-idl/parser.js +97 -29
  47. package/build/lib/src/idl/builders.d.ts +43 -0
  48. package/build/lib/src/idl/builders.js +135 -0
  49. package/build/lib/src/idl/discriminators.d.ts +53 -0
  50. package/build/lib/src/idl/discriminators.js +232 -0
  51. package/build/lib/src/idl/dump.d.ts +48 -0
  52. package/build/lib/src/idl/dump.js +327 -0
  53. package/build/lib/src/idl/index.d.ts +9 -0
  54. package/build/lib/src/idl/index.js +23 -0
  55. package/build/lib/src/idl/keywords.d.ts +2 -0
  56. package/build/lib/src/{options.js → idl/keywords.js} +7 -3
  57. package/build/lib/src/idl/node.d.ts +233 -0
  58. package/build/lib/src/idl/node.js +103 -0
  59. package/build/lib/src/idl/stdlib.d.ts +34 -0
  60. package/build/lib/src/idl/stdlib.js +54 -0
  61. package/build/lib/src/idl/utils.d.ts +44 -0
  62. package/build/lib/src/idl/utils.js +215 -0
  63. package/build/lib/src/idl/visitors.d.ts +15 -0
  64. package/build/lib/src/idl/visitors.js +593 -0
  65. package/build/lib/src/index.d.ts +5 -6
  66. package/build/lib/src/index.js +6 -7
  67. package/build/lib/src/inheritance.d.ts +0 -2
  68. package/build/lib/src/inheritance.js +0 -17
  69. package/build/lib/src/inputPaths.d.ts +11 -0
  70. package/build/lib/src/inputPaths.js +81 -0
  71. package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
  72. package/build/lib/src/languageSpecificKeywords.js +0 -5
  73. package/build/lib/src/peer-generation/ConflictingDeclarations.d.ts +6 -0
  74. package/build/lib/src/peer-generation/ConflictingDeclarations.js +43 -0
  75. package/build/lib/src/peer-generation/LayoutManager.d.ts +3 -1
  76. package/build/lib/src/peer-generation/LayoutManager.js +15 -0
  77. package/build/lib/src/peer-generation/Materialized.d.ts +8 -0
  78. package/build/lib/src/peer-generation/Materialized.js +26 -1
  79. package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -18
  80. package/build/lib/src/peer-generation/PeerLibrary.js +63 -227
  81. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
  82. package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
  83. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +6 -0
  84. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +15 -3
  85. package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
  86. package/build/lib/src/peer-generation/idl/common.js +7 -7
  87. package/build/lib/src/peer-generation/isMaterialized.js +2 -3
  88. package/build/lib/src/peer-generation/modules.js +2 -0
  89. package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
  90. package/build/lib/src/peer-generation/toDeclaration.js +53 -0
  91. package/build/lib/src/peer-generation/unions.d.ts +1 -1
  92. package/build/lib/src/peer-generation/unions.js +15 -7
  93. package/build/lib/src/resolveNamedNode.d.ts +1 -0
  94. package/build/lib/src/resolveNamedNode.js +7 -0
  95. package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
  96. package/build/lib/src/transformers/FqnTransformer.js +20 -12
  97. package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
  98. package/build/lib/src/transformers/GenericTransformer.js +252 -158
  99. package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
  100. package/build/lib/src/transformers/IdlTransformer.js +7 -0
  101. package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
  102. package/build/lib/src/transformers/NullTransformer.js +27 -21
  103. package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
  104. package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
  105. package/build/lib/src/util.d.ts +9 -39
  106. package/build/lib/src/util.js +65 -369
  107. package/package.json +44 -49
  108. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
  109. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
  110. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -83
  111. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -295
  112. package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
  113. package/build/lib/src/from-idl/webidl2-utils.js +0 -87
  114. package/build/lib/src/idl.d.ts +0 -439
  115. package/build/lib/src/idl.js +0 -1367
  116. package/build/lib/src/idlize.d.ts +0 -25
  117. package/build/lib/src/idlize.js +0 -198
  118. package/build/lib/src/options.d.ts +0 -13
  119. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
  120. package/build/lib/src/peer-generation/BuilderClass.js +0 -68
  121. package/webidl2.js/dist/webidl2.js +0 -4622
  122. package/webidl2.js/package.json +0 -55
@@ -1,37 +0,0 @@
1
- import * as idl from '../../idl';
2
- import { ReferenceResolver } from '../../peer-generation/ReferenceResolver';
3
- import { IdlNameConvertor, NodeConvertor } from '../nameConvertor';
4
- import { InteropArgConvertor } from './InteropConvertors';
5
- export declare class JavaTypeNameConvertor implements NodeConvertor<string>, IdlNameConvertor {
6
- private resolver;
7
- constructor(resolver: ReferenceResolver);
8
- protected solidConvertor: import("../../util").Lazy<JavaIdlNodeToSolidStringConvertor>;
9
- convert(node: idl.IDLNode): string;
10
- convertNamespace(node: idl.IDLNamespace): string;
11
- convertInterface(node: idl.IDLInterface): string;
12
- convertEnum(node: idl.IDLEnum): string;
13
- convertTypedef(node: idl.IDLTypedef): string;
14
- convertOptional(type: idl.IDLOptionalType): string;
15
- convertUnion(type: idl.IDLUnionType): string;
16
- convertContainer(type: idl.IDLContainerType): string;
17
- convertCallback(type: idl.IDLCallback): string;
18
- convertMethod(type: idl.IDLMethod): string;
19
- convertConstant(type: idl.IDLConstant): string;
20
- convertImport(type: idl.IDLImport): string;
21
- convertTypeReferenceAsImport(type: idl.IDLReferenceType, importClause: string): string;
22
- convertTypeReference(type: idl.IDLReferenceType): string;
23
- convertTypeParameter(type: idl.IDLTypeParameterType): string;
24
- convertPrimitiveType(type: idl.IDLPrimitiveType): string;
25
- private readonly javaPrimitiveToReferenceTypeMap;
26
- protected maybeConvertPrimitiveType(javaType: string): string;
27
- private mapTypeName;
28
- }
29
- declare class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
30
- protected solidConvertor: import("../../util").Lazy<this>;
31
- convertContainer(type: idl.IDLContainerType): string;
32
- }
33
- export declare class JavaInteropArgConvertor extends InteropArgConvertor {
34
- convertPrimitiveType(type: idl.IDLPrimitiveType): string;
35
- }
36
- export {};
37
- //# sourceMappingURL=JavaConvertors.d.ts.map
@@ -1,210 +0,0 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
- import * as idl from '../../idl';
16
- import { lazy } from '../../util';
17
- import { convertNode, convertType } from '../nameConvertor';
18
- import { InteropArgConvertor } from './InteropConvertors';
19
- function convertJavaOptional(type) {
20
- switch (type) {
21
- case 'boolean': return 'Opt_Boolean';
22
- case 'double': return 'Opt_Number';
23
- }
24
- return type;
25
- }
26
- export class JavaTypeNameConvertor {
27
- constructor(resolver) {
28
- this.resolver = resolver;
29
- this.solidConvertor = lazy(() => new JavaIdlNodeToSolidStringConvertor(this.resolver));
30
- this.javaPrimitiveToReferenceTypeMap = new Map([
31
- ['byte', 'Byte'],
32
- ['short', 'Short'],
33
- ['int', 'Integer'],
34
- ['float', 'Float'],
35
- ['double', 'Double'],
36
- ['boolean', 'Boolean'],
37
- ['char', 'Character'],
38
- ]);
39
- }
40
- convert(node) {
41
- const typeString = convertNode(this, node);
42
- return this.mapTypeName(typeString);
43
- }
44
- convertNamespace(node) {
45
- throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
46
- }
47
- convertInterface(node) {
48
- if (node.subkind === idl.IDLInterfaceSubkind.Tuple) {
49
- const javaTypeAliases = node.properties.map(it => convertType(this, idl.maybeOptional(it.type, it.isOptional)));
50
- return `Tuple_${javaTypeAliases.join('_')}`;
51
- }
52
- return node.name;
53
- }
54
- convertEnum(node) {
55
- return node.name;
56
- }
57
- convertTypedef(node) {
58
- return node.name;
59
- }
60
- convertOptional(type) {
61
- return convertJavaOptional(this.convert(type.type));
62
- }
63
- convertUnion(type) {
64
- const aliases = type.types.map(it => convertType(this.solidConvertor.value, it));
65
- return `Union_${aliases.join('_')}`;
66
- }
67
- convertContainer(type) {
68
- if (idl.IDLContainerUtils.isSequence(type)) {
69
- const javaType = convertType(this, type.elementType[0]);
70
- return `${javaType}[]`;
71
- }
72
- if (idl.IDLContainerUtils.isRecord(type)) {
73
- const javaTypes = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
74
- return `Map<${javaTypes[0]}, ${javaTypes[1]}>`;
75
- }
76
- throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
77
- }
78
- convertCallback(type) {
79
- return `Callback`;
80
- }
81
- convertMethod(type) {
82
- throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
83
- }
84
- convertConstant(type) {
85
- throw new Error('Method not implemented.'); // TODO: namespace-related-to-rework
86
- }
87
- convertImport(type) {
88
- console.warn("Imports are not implemented yet");
89
- return type.name;
90
- }
91
- convertTypeReferenceAsImport(type, importClause) {
92
- return type.name;
93
- }
94
- convertTypeReference(type) {
95
- const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
96
- if (importAttr) {
97
- return this.convertTypeReferenceAsImport(type, importAttr);
98
- }
99
- const decl = this.resolver.resolveTypeReference(type);
100
- if (decl) {
101
- const declName = this.convert(decl);
102
- return declName;
103
- }
104
- if (type.name === `Optional`) {
105
- return convertJavaOptional(idl.printType(type.typeArguments[0]));
106
- }
107
- return type.name;
108
- }
109
- convertTypeParameter(type) {
110
- // TODO
111
- return type.name;
112
- }
113
- convertPrimitiveType(type) {
114
- switch (type) {
115
- case idl.IDLStringType: return 'String';
116
- case idl.IDLNumberType: return 'double';
117
- case idl.IDLBooleanType: return 'boolean';
118
- case idl.IDLUndefinedType: return 'Ark_Undefined';
119
- case idl.IDLI8Type: return 'byte';
120
- case idl.IDLU8Type: return 'byte';
121
- case idl.IDLI16Type: return 'short';
122
- case idl.IDLU16Type: return 'short';
123
- case idl.IDLI32Type: return 'int';
124
- case idl.IDLU32Type: return 'int';
125
- case idl.IDLI64Type: return 'long';
126
- case idl.IDLU64Type: return 'long';
127
- case idl.IDLF32Type: return 'float';
128
- case idl.IDLF64Type: return 'double';
129
- case idl.IDLPointerType: return 'long';
130
- case idl.IDLVoidType: return 'void';
131
- case idl.IDLDate: return 'Date';
132
- case idl.IDLBufferType: return 'byte[]';
133
- case idl.IDLInteropReturnBufferType: return 'byte[]';
134
- case idl.IDLSerializerBuffer: return 'long';
135
- case idl.IDLAnyType: return 'Ark_Object';
136
- case idl.IDLUnknownType: return 'Ark_Object';
137
- }
138
- throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
139
- }
140
- maybeConvertPrimitiveType(javaType) {
141
- if (this.javaPrimitiveToReferenceTypeMap.has(javaType)) {
142
- return this.javaPrimitiveToReferenceTypeMap.get(javaType);
143
- }
144
- return javaType;
145
- }
146
- mapTypeName(name) {
147
- switch (name) {
148
- case 'KPointer': return 'long';
149
- case 'KBoolean': return 'boolean';
150
- case 'KUInt': return 'int';
151
- case 'int32':
152
- case 'KInt': return 'int';
153
- case 'int64':
154
- case 'KLong': return 'long';
155
- case 'float32':
156
- case 'KFloat': return 'float';
157
- case 'float64':
158
- case 'KDouble': return 'double';
159
- case 'KUint8ArrayPtr': return 'byte[]';
160
- case 'KInt32ArrayPtr': return 'int[]';
161
- case 'KFloat32ArrayPtr': return 'float[]';
162
- // case 'ArrayBuffer': return 'byte[]'
163
- case 'KStringPtr': return 'String';
164
- case 'string': return 'String';
165
- }
166
- return name.split(".").at(-1);
167
- }
168
- }
169
- class JavaIdlNodeToSolidStringConvertor extends JavaTypeNameConvertor {
170
- constructor() {
171
- super(...arguments);
172
- this.solidConvertor = lazy(() => this);
173
- }
174
- convertContainer(type) {
175
- if (idl.IDLContainerUtils.isSequence(type)) {
176
- const javaTypeSolid = convertType(this, type.elementType[0]);
177
- return `Array_${javaTypeSolid}`;
178
- }
179
- if (idl.IDLContainerUtils.isRecord(type)) {
180
- const javaTypeSolids = type.elementType.slice(0, 2).map(it => convertType(this, it)).map(this.maybeConvertPrimitiveType, this);
181
- return `Map_${javaTypeSolids[0]}_${javaTypeSolids[1]}`;
182
- }
183
- throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
184
- }
185
- }
186
- export class JavaInteropArgConvertor extends InteropArgConvertor {
187
- convertPrimitiveType(type) {
188
- switch (type) {
189
- case idl.IDLNumberType: return "double";
190
- case idl.IDLBooleanType: return "boolean";
191
- case idl.IDLI64Type: return "long";
192
- case idl.IDLU64Type: return "long";
193
- case idl.IDLI32Type: return "int";
194
- case idl.IDLU32Type: return "int";
195
- case idl.IDLF32Type: return "float";
196
- case idl.IDLF64Type: return "double";
197
- case idl.IDLBigintType: return "long";
198
- case idl.IDLSerializerBuffer: return "long";
199
- case idl.IDLFunctionType: return "int";
200
- case idl.IDLStringType: return "String";
201
- case idl.IDLBufferType: return "byte[]";
202
- case idl.IDLDate: return "long";
203
- case idl.IDLVoidType: return "void";
204
- case idl.IDLUndefinedType: return "long";
205
- case idl.IDLPointerType: return "long"; // return PrimitiveTypesInstance.NativePointer.getText()
206
- }
207
- return super.convertPrimitiveType(type);
208
- }
209
- }
210
- //# sourceMappingURL=JavaConvertors.js.map
@@ -1,83 +0,0 @@
1
- import { IndentedPrinter } from "../../IndentedPrinter";
2
- import { AssignStatement, DelegationCall, FieldModifier, LanguageExpression, LanguageStatement, LanguageWriter, MakeCastOptions, Method, MethodModifier, MethodSignature, ObjectArgs } from "../LanguageWriter";
3
- import { CLikeLanguageWriter } from "./CLikeLanguageWriter";
4
- import * as idl from '../../idl';
5
- import { ArgConvertor, BaseArgConvertor } from "../ArgConvertors";
6
- import { IdlNameConvertor } from "../nameConvertor";
7
- import { RuntimeType } from "../common";
8
- import { ReferenceResolver } from "../../peer-generation/ReferenceResolver";
9
- export declare class JavaCastExpression implements LanguageExpression {
10
- value: LanguageExpression;
11
- type: string;
12
- private unsafe;
13
- constructor(value: LanguageExpression, type: string, unsafe?: boolean);
14
- asString(): string;
15
- }
16
- export declare class JavaAssignStatement extends AssignStatement {
17
- variableName: string;
18
- type: idl.IDLType | undefined;
19
- expression: LanguageExpression;
20
- isDeclared: boolean;
21
- protected isConst: boolean;
22
- constructor(variableName: string, type: idl.IDLType | undefined, expression: LanguageExpression, isDeclared?: boolean, isConst?: boolean);
23
- write(writer: LanguageWriter): void;
24
- }
25
- export declare class JavaLanguageWriter extends CLikeLanguageWriter {
26
- protected typeConvertor: IdlNameConvertor;
27
- constructor(printer: IndentedPrinter, resolver: ReferenceResolver, typeConvertor: IdlNameConvertor);
28
- getNodeName(type: idl.IDLNode): string;
29
- fork(options?: {
30
- resolver?: ReferenceResolver;
31
- }): LanguageWriter;
32
- writeClass(name: string, op: (writer: this) => void, superClass?: string, interfaces?: string[], generics?: string[], isDeclared?: boolean, isExport?: boolean): void;
33
- writeInterface(name: string, op: (writer: this) => void, superInterfaces?: string[], generics?: string[]): void;
34
- writeMethodCall(receiver: string, method: string, params: string[], nullable?: boolean): void;
35
- writeFieldDeclaration(name: string, type: idl.IDLType, modifiers: FieldModifier[] | undefined, optional: boolean, initExpr?: LanguageExpression): void;
36
- writeNativeMethodDeclaration(method: Method): void;
37
- writeConstructorImplementation(className: string, signature: MethodSignature, op: (writer: this) => void, delegationCall?: DelegationCall, modifiers?: MethodModifier[]): void;
38
- writeProperty(propName: string, propType: idl.IDLType, modifiers: FieldModifier[], getter?: {
39
- method: Method;
40
- op: () => void;
41
- }, setter?: {
42
- method: Method;
43
- op: () => void;
44
- }, initExpr?: LanguageExpression): void;
45
- writeTypeDeclaration(decl: idl.IDLTypedef): void;
46
- writeConstant(constName: string, constType: idl.IDLType, constVal?: string): void;
47
- makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean): LanguageStatement;
48
- makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
49
- makeReturn(expr: LanguageExpression): LanguageStatement;
50
- makeDefinedCheck(value: string): LanguageExpression;
51
- makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
52
- makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
53
- makeMapSize(map: string): LanguageExpression;
54
- makeCast(value: LanguageExpression, node: idl.IDLNode, options?: MakeCastOptions): LanguageExpression;
55
- makeStatement(expr: LanguageExpression): LanguageStatement;
56
- makeUnionSelector(value: string, valueType: string): LanguageStatement;
57
- makeUnionVariantCondition(_convertor: ArgConvertor, _valueName: string, valueType: string, _type: string, convertorIndex: number): LanguageExpression;
58
- makeUnionVariantCast(value: string, type: string, convertor: ArgConvertor, index: number): LanguageExpression;
59
- makeUnionTypeDefaultInitializer(): LanguageExpression;
60
- writePrintLog(message: string): void;
61
- mapIDLContainerType(type: idl.IDLContainerType): string;
62
- applyToObject(p: BaseArgConvertor, param: string, value: string, args?: ObjectArgs): LanguageStatement;
63
- getObjectAccessor(convertor: ArgConvertor, value: string, args?: ObjectArgs): string;
64
- makeUndefined(): LanguageExpression;
65
- makeRuntimeType(rt: RuntimeType): LanguageExpression;
66
- protected makeRuntimeTypeGetterCall(value: string): LanguageExpression;
67
- makeMapInsert(keyAccessor: string, key: string, valueAccessor: string, value: string): LanguageStatement;
68
- getTagType(): idl.IDLType;
69
- getRuntimeType(): idl.IDLType;
70
- makeTupleAssign(receiver: string, tupleFields: string[]): LanguageStatement;
71
- get supportedModifiers(): MethodModifier[];
72
- get supportedFieldModifiers(): FieldModifier[];
73
- makeArrayInit(type: idl.IDLContainerType, size?: number): LanguageExpression;
74
- makeClassInit(type: idl.IDLType, paramenters: LanguageExpression[]): LanguageExpression;
75
- makeMapInit(type: idl.IDLType): LanguageExpression;
76
- makeTupleAccess(value: string, index: number): LanguageExpression;
77
- enumFromI32(value: LanguageExpression, enumEntry: idl.IDLEnum): LanguageExpression;
78
- makeValueFromOption(value: string): LanguageExpression;
79
- runtimeType(param: ArgConvertor, valueType: string, value: string): void;
80
- i32FromEnum(value: LanguageExpression, enumEntry: idl.IDLEnum): LanguageExpression;
81
- castToBoolean(value: string): string;
82
- }
83
- //# sourceMappingURL=JavaLanguageWriter.d.ts.map
@@ -1,295 +0,0 @@
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 { Language } from '../../Language';
16
- import { IndentedPrinter } from "../../IndentedPrinter";
17
- import { AssignStatement, BlockStatement, FieldModifier, LambdaExpression, Method, MethodModifier, MethodSignature, NamedMethodSignature, } from "../LanguageWriter";
18
- import { CLikeExpressionStatement, CLikeLanguageWriter, CLikeLoopStatement, CLikeReturnStatement } from "./CLikeLanguageWriter";
19
- import * as idl from '../../idl';
20
- import { RuntimeType } from "../common";
21
- ////////////////////////////////////////////////////////////////
22
- // EXPRESSIONS //
23
- ////////////////////////////////////////////////////////////////
24
- class JavaLambdaExpression extends LambdaExpression {
25
- constructor(writer, signature, resolver, body) {
26
- super(writer, signature, resolver, body);
27
- }
28
- get statementHasSemicolon() {
29
- return true;
30
- }
31
- asString() {
32
- const params = this.signature.args.map((it, i) => `${idl.forceAsNamedNode(it).name} ${this.signature.argName(i)}`);
33
- return `(${params.join(", ")}) ->${this.bodyAsString(true)}`;
34
- }
35
- }
36
- export class JavaCastExpression {
37
- constructor(value, type, unsafe = false) {
38
- this.value = value;
39
- this.type = type;
40
- this.unsafe = unsafe;
41
- }
42
- asString() {
43
- return `(${this.type})(${this.value.asString()})`;
44
- }
45
- }
46
- ////////////////////////////////////////////////////////////////
47
- // STATEMENTS //
48
- ////////////////////////////////////////////////////////////////
49
- export class JavaAssignStatement extends AssignStatement {
50
- constructor(variableName, type, expression, isDeclared = true, isConst = true) {
51
- super(variableName, type, expression, isDeclared, isConst);
52
- this.variableName = variableName;
53
- this.type = type;
54
- this.expression = expression;
55
- this.isDeclared = isDeclared;
56
- this.isConst = isConst;
57
- }
58
- write(writer) {
59
- if (this.isDeclared) {
60
- const typeSpec = this.type ? writer.getNodeName(this.type) : "var";
61
- writer.print(`${typeSpec} ${this.variableName} = ${this.expression.asString()};`);
62
- }
63
- else {
64
- writer.print(`${this.variableName} = ${this.expression.asString()};`);
65
- }
66
- }
67
- }
68
- class JavaMapForEachStatement {
69
- constructor(map, key, value, body) {
70
- this.map = map;
71
- this.key = key;
72
- this.value = value;
73
- this.body = body;
74
- }
75
- write(writer) {
76
- const entryVar = `${this.map}Entry`;
77
- writer.print(`for (var ${entryVar}: ${this.map}.entrySet()) {`);
78
- writer.pushIndent();
79
- writer.print(`var ${this.key} = ${entryVar}.getKey();`);
80
- writer.print(`var ${this.value} = ${entryVar}.getValue();`);
81
- writer.writeStatement(new BlockStatement(this.body, false));
82
- writer.popIndent();
83
- writer.print(`}`);
84
- }
85
- }
86
- ////////////////////////////////////////////////////////////////
87
- // WRITER //
88
- ////////////////////////////////////////////////////////////////
89
- export class JavaLanguageWriter extends CLikeLanguageWriter {
90
- constructor(printer, resolver, typeConvertor) {
91
- super(printer, resolver, Language.JAVA);
92
- this.typeConvertor = typeConvertor;
93
- }
94
- getNodeName(type) {
95
- // another stub. Bad one.
96
- // I hope that I will rewrite LWs soon
97
- if (idl.isType(type) && idl.isReferenceType(type)) {
98
- if (type.name.startsWith('%TEXT%:')) {
99
- return type.name.substring(7);
100
- }
101
- }
102
- return this.typeConvertor.convert(type);
103
- }
104
- fork(options) {
105
- var _a;
106
- return new JavaLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor);
107
- }
108
- writeClass(name, op, superClass, interfaces, generics, isDeclared, isExport = true) {
109
- let genericsClause = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(', ')}> ` : ``;
110
- let extendsClause = superClass ? ` extends ${superClass}` : '';
111
- let implementsClause = interfaces ? ` implements ${interfaces.join(",")}` : '';
112
- this.printer.print(`${isExport ? 'public ' : ''}class ${name}${genericsClause}${extendsClause}${implementsClause} {`); // TODO check for multiple classes in file
113
- this.pushIndent();
114
- op(this);
115
- this.popIndent();
116
- this.printer.print(`}`);
117
- }
118
- writeInterface(name, op, superInterfaces, generics) {
119
- let extendsClause = superInterfaces ? ` extends ${superInterfaces.join(",")}` : '';
120
- this.printer.print(`interface ${name}${extendsClause} {`);
121
- this.pushIndent();
122
- op(this);
123
- this.popIndent();
124
- this.printer.print(`}`);
125
- }
126
- writeMethodCall(receiver, method, params, nullable = false) {
127
- if (nullable) {
128
- this.printer.print(`if (${receiver} != null) ${receiver}.${method}(${params.join(", ")});`);
129
- }
130
- else {
131
- super.writeMethodCall(receiver, method, params, nullable);
132
- }
133
- }
134
- writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
135
- let prefix = this.makeFieldModifiersList(modifiers);
136
- this.printer.print(`${prefix} ${(this.getNodeName(type))} ${name}${initExpr ? ` = ${initExpr.asString()}` : ""};`);
137
- }
138
- writeNativeMethodDeclaration(method) {
139
- this.writeMethodDeclaration(method.name, method.signature, [MethodModifier.STATIC, MethodModifier.NATIVE]);
140
- }
141
- writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
142
- this.printer.print(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') : ''} ${className}(${signature.args.map((it, index) => `${this.getNodeName(it)} ${signature.argName(index)}`).join(", ")}) {`);
143
- this.pushIndent();
144
- if (delegationCall) {
145
- this.print(`super(${delegationCall.delegationArgs.map(it => it.asString()).join(", ")});`);
146
- }
147
- op(this);
148
- this.popIndent();
149
- this.printer.print(`}`);
150
- }
151
- writeProperty(propName, propType, modifiers, getter, setter, initExpr) {
152
- let isStatic = modifiers.includes(FieldModifier.STATIC);
153
- let isMutable = !modifiers.includes(FieldModifier.READONLY);
154
- let containerName = propName.concat("_container");
155
- if (getter) {
156
- if (!getter.op) {
157
- this.print(`private var ${this.getNodeName(propType)} ${containerName};`);
158
- }
159
- this.writeGetterImplementation(new Method(propName, new MethodSignature(propType, []), isStatic ? [MethodModifier.STATIC, MethodModifier.PUBLIC] : [MethodModifier.PUBLIC]), getter ? getter.op :
160
- (writer) => {
161
- writer.print(`return ${containerName}`);
162
- });
163
- if (isMutable) {
164
- const setSignature = new NamedMethodSignature(idl.IDLVoidType, [propType], [propName]);
165
- this.writeSetterImplementation(new Method(propName, setSignature, isStatic ? [MethodModifier.STATIC, MethodModifier.PUBLIC] : [MethodModifier.PUBLIC]), setter ? setter.op :
166
- (writer) => {
167
- writer.print(`${containerName} = ${propName};`);
168
- });
169
- }
170
- }
171
- else {
172
- // TBD: use initExpr
173
- this.writeMethodDeclaration(propName, new MethodSignature(propType, []));
174
- }
175
- }
176
- writeTypeDeclaration(decl) {
177
- throw new Error(`Type declarations do not exist in Java, use something else`);
178
- }
179
- writeConstant(constName, constType, constVal) {
180
- throw new Error("writeConstant for Java is not implemented yet.");
181
- }
182
- makeAssign(variableName, type, expr, isDeclared = true, isConst = true) {
183
- return new JavaAssignStatement(variableName, type, expr, isDeclared, isConst);
184
- }
185
- makeLambda(signature, body) {
186
- return new JavaLambdaExpression(this, signature, this.resolver, body);
187
- }
188
- makeReturn(expr) {
189
- return new CLikeReturnStatement(expr);
190
- }
191
- makeDefinedCheck(value) {
192
- return this.makeString(`${value} != null`);
193
- }
194
- makeLoop(counter, limit, statement) {
195
- return new CLikeLoopStatement(counter, limit, statement);
196
- }
197
- makeMapForEach(map, key, value, body) {
198
- return new JavaMapForEachStatement(map, key, value, body);
199
- }
200
- makeMapSize(map) {
201
- return this.makeString(`${map}.size()`);
202
- }
203
- makeCast(value, node, options) {
204
- var _a;
205
- return new JavaCastExpression(value, this.getNodeName(node), (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
206
- }
207
- makeStatement(expr) {
208
- return new CLikeExpressionStatement(expr);
209
- }
210
- makeUnionSelector(value, valueType) {
211
- return this.makeAssign(valueType, undefined, this.makeMethodCall(value, "getSelector", []), false);
212
- }
213
- makeUnionVariantCondition(_convertor, _valueName, valueType, _type, convertorIndex) {
214
- return this.makeString(`${valueType} == ${convertorIndex}`);
215
- }
216
- makeUnionVariantCast(value, type, convertor, index) {
217
- return this.makeMethodCall(value, `getValue${index}`, []);
218
- }
219
- makeUnionTypeDefaultInitializer() {
220
- return this.makeString("-1");
221
- }
222
- writePrintLog(message) {
223
- this.print(`System.out.println("${message}")`);
224
- }
225
- mapIDLContainerType(type) {
226
- switch (type.containerKind) {
227
- case "sequence": return `${this.getNodeName(type.elementType[0])}[]`;
228
- }
229
- throw new Error(`Unmapped container type ${idl.DebugUtils.debugPrintType(type)}`);
230
- }
231
- applyToObject(p, param, value, args) {
232
- throw new Error("Method not implemented.");
233
- }
234
- getObjectAccessor(convertor, value, args) {
235
- return value;
236
- }
237
- makeUndefined() {
238
- return this.makeString("null");
239
- }
240
- makeRuntimeType(rt) {
241
- return this.makeString(`RuntimeType.${RuntimeType[rt]}`);
242
- }
243
- makeRuntimeTypeGetterCall(value) {
244
- return this.makeMethodCall("Ark_Object", "getRuntimeType", [this.makeString(value)]);
245
- }
246
- makeMapInsert(keyAccessor, key, valueAccessor, value) {
247
- throw new Error("Method not implemented.");
248
- }
249
- getTagType() {
250
- throw new Error("Method not implemented.");
251
- }
252
- getRuntimeType() {
253
- throw new Error("Method not implemented.");
254
- }
255
- makeTupleAssign(receiver, tupleFields) {
256
- throw new Error("Method not implemented.");
257
- }
258
- get supportedModifiers() {
259
- return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.STATIC, MethodModifier.NATIVE];
260
- }
261
- get supportedFieldModifiers() {
262
- return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.STATIC, FieldModifier.FINAL];
263
- }
264
- makeArrayInit(type, size) {
265
- return this.makeString(`new ${this.getNodeName(type.elementType[0])}[${size !== null && size !== void 0 ? size : 0}]`);
266
- }
267
- makeClassInit(type, paramenters) {
268
- throw new Error("Method not implemented.");
269
- }
270
- makeMapInit(type) {
271
- throw new Error("Method not implemented.");
272
- }
273
- makeTupleAccess(value, index) {
274
- return this.makeString(`${value}.value${index}`);
275
- }
276
- enumFromI32(value, enumEntry) {
277
- const enumName = idl.forceAsNamedNode(enumEntry).name;
278
- const ordinal = value.asString();
279
- return this.makeString(`${enumName}.values()[${ordinal}]`);
280
- }
281
- makeValueFromOption(value) {
282
- return this.makeString(`${value}`);
283
- }
284
- runtimeType(param, valueType, value) {
285
- this.writeStatement(this.makeAssign(valueType, undefined, this.makeRuntimeTypeGetterCall(value), false));
286
- }
287
- i32FromEnum(value, enumEntry) {
288
- const i32Value = idl.isStringEnum(enumEntry)
289
- ? `${value.asString()}.ordinal`
290
- : `${value.asString()}.value`;
291
- return this.makeString(i32Value);
292
- }
293
- castToBoolean(value) { return value; }
294
- }
295
- //# sourceMappingURL=JavaLanguageWriter.js.map
@@ -1,21 +0,0 @@
1
- import * as webidl2 from "webidl2";
2
- export declare function isEnum(node: webidl2.IDLRootType): node is webidl2.EnumType;
3
- export declare function isInterface(node: webidl2.IDLRootType): node is webidl2.InterfaceType;
4
- export declare function isImport(node: webidl2.IDLRootType): node is webidl2.ImportType;
5
- export declare function isPackage(node: webidl2.IDLRootType): node is webidl2.PackageType;
6
- export declare function isClass(node: webidl2.IDLRootType): node is webidl2.InterfaceType;
7
- export declare function isCallback(node: webidl2.IDLRootType): node is webidl2.CallbackType;
8
- export declare function isTypedef(node: webidl2.IDLRootType): node is webidl2.TypedefType;
9
- export declare function isDictionary(node: webidl2.IDLRootType): node is webidl2.DictionaryType;
10
- export declare function isAttribute(node: webidl2.IDLInterfaceMemberType | webidl2.IDLNamespaceMemberType): node is webidl2.AttributeMemberType;
11
- export declare function isOperation(node: webidl2.IDLInterfaceMemberType | webidl2.IDLNamespaceMemberType): node is webidl2.OperationMemberType;
12
- export declare function isConstructor(node: webidl2.IDLInterfaceMemberType): node is webidl2.ConstructorMemberType;
13
- export declare function isUnionTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnionTypeDescription;
14
- export declare function isSingleTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SingleTypeDescription;
15
- export declare function isSequenceTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SequenceTypeDescription;
16
- export declare function isPromiseTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.PromiseTypeDescription;
17
- export declare function isRecordTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.RecordTypeDescription;
18
- export declare function isConstant(node: webidl2.IDLRootType): node is webidl2.ConstantMemberType;
19
- export declare function isUnspecifiedGenericTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnspecifiedGenericTypeDescription;
20
- export declare function isOptional(node: webidl2.AttributeMemberType | webidl2.OperationMemberType): boolean;
21
- //# sourceMappingURL=webidl2-utils.d.ts.map