@idlizer/core 2.1.2 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +3 -4
- package/build/lib/src/LanguageWriters/ArgConvertors.js +43 -32
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +35 -17
- package/build/lib/src/LanguageWriters/LanguageWriter.js +30 -56
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +3 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +32 -11
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +5 -2
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +71 -62
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +9 -19
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -3
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +8 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +87 -33
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
- package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +19 -11
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +34 -47
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +9 -9
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +15 -24
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +17 -8
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +48 -23
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +4 -6
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +15 -14
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +13 -8
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -52
- package/build/lib/src/LibraryInterface.d.ts +1 -4
- package/build/lib/src/config.d.ts +813 -110
- package/build/lib/src/config.js +25 -3
- package/build/lib/src/configDescriber.d.ts +31 -4
- package/build/lib/src/configDescriber.js +101 -3
- package/build/lib/src/from-idl/DtsPrinter.js +31 -18
- package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
- package/build/lib/src/from-idl/IDLLinter.js +211 -25
- package/build/lib/src/from-idl/common.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +10 -1
- package/build/lib/src/from-idl/deserialize.js +486 -352
- package/build/lib/src/idl.d.ts +29 -19
- package/build/lib/src/idl.js +404 -119
- package/build/lib/src/idlize.d.ts +2 -1
- package/build/lib/src/idlize.js +82 -26
- package/build/lib/src/index.d.ts +4 -3
- package/build/lib/src/index.js +3 -2
- package/build/lib/src/options.d.ts +1 -1
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
- package/build/lib/src/peer-generation/BuilderClass.js +0 -8
- package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
- package/build/lib/src/peer-generation/LayoutManager.js +3 -2
- package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.js +3 -3
- package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
- package/build/lib/src/peer-generation/PeerClass.js +0 -1
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
- package/build/lib/src/peer-generation/PeerFile.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -7
- package/build/lib/src/peer-generation/PeerLibrary.js +131 -67
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
- package/build/lib/src/peer-generation/idl/common.d.ts +3 -1
- package/build/lib/src/peer-generation/idl/common.js +21 -4
- package/build/lib/src/peer-generation/isMaterialized.js +28 -7
- package/build/lib/src/peer-generation/unions.d.ts +3 -2
- package/build/lib/src/peer-generation/unions.js +7 -3
- package/build/lib/src/resolveNamedNode.d.ts +3 -0
- package/build/lib/src/resolveNamedNode.js +105 -0
- package/build/lib/src/util.d.ts +8 -1
- package/build/lib/src/util.js +41 -3
- package/build/lib/src/visitor.d.ts +2 -1
- package/build/lib/src/visitor.js +109 -7
- package/package.json +2 -2
- package/webidl2.js/LICENSE +21 -0
- package/webidl2.js/README.md +827 -0
- package/webidl2.js/dist/package.json +3 -0
- package/webidl2.js/dist/webidl2.js +93 -19
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { warn } from 'console';
|
|
16
16
|
import * as idl from '../idl';
|
|
17
|
+
import { resolveNamedNode } from '../resolveNamedNode';
|
|
17
18
|
import { Language } from '../Language';
|
|
18
19
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
19
20
|
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
@@ -30,6 +31,7 @@ import { lib, query } from '../library';
|
|
|
30
31
|
import { isMaterialized } from './isMaterialized';
|
|
31
32
|
import { isInIdlizeInternal } from '../idlize';
|
|
32
33
|
import { isInCurrentModule } from './modules';
|
|
34
|
+
import { generatorConfiguration } from '../config';
|
|
33
35
|
export const lenses = {
|
|
34
36
|
globals: lib.lens(lib.select.files())
|
|
35
37
|
.pipe(lib.select.nodes())
|
|
@@ -68,7 +70,7 @@ export class PeerLibrary {
|
|
|
68
70
|
return this._cachedIdlLibrary;
|
|
69
71
|
}
|
|
70
72
|
this._cachedIdlLibrary = {
|
|
71
|
-
files: this.files.map(file => file
|
|
73
|
+
files: this.files.map(file => file)
|
|
72
74
|
};
|
|
73
75
|
return this._cachedIdlLibrary;
|
|
74
76
|
}
|
|
@@ -87,17 +89,20 @@ export class PeerLibrary {
|
|
|
87
89
|
get materializedToGenerate() {
|
|
88
90
|
return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated);
|
|
89
91
|
}
|
|
90
|
-
constructor(language) {
|
|
92
|
+
constructor(language, useMemoM3 = false) {
|
|
91
93
|
this.language = language;
|
|
94
|
+
this.useMemoM3 = useMemoM3;
|
|
92
95
|
this.layout = LayoutManager.Empty();
|
|
93
96
|
this._syntheticFile = idl.createFile([]);
|
|
94
97
|
this.files = [];
|
|
98
|
+
this.auxFiles = [];
|
|
95
99
|
this.builderClasses = new Map();
|
|
96
100
|
this.materializedClasses = new Map();
|
|
97
101
|
this.name = "";
|
|
98
102
|
this.customComponentMethods = [];
|
|
99
103
|
this.targetNameConvertorInstance = this.createTypeNameConvertor(this.language);
|
|
100
104
|
this.interopNameConvertorInstance = new CppNameConvertor(this);
|
|
105
|
+
this._useFallback = true;
|
|
101
106
|
}
|
|
102
107
|
createLanguageWriter(language) {
|
|
103
108
|
return createLanguageWriter(language !== null && language !== void 0 ? language : this.language, this);
|
|
@@ -142,76 +147,120 @@ export class PeerLibrary {
|
|
|
142
147
|
this.context = context;
|
|
143
148
|
}
|
|
144
149
|
findFileByOriginalFilename(filename) {
|
|
145
|
-
return this.files.find(it => it.
|
|
150
|
+
return this.files.find(it => it.fileName === filename);
|
|
146
151
|
}
|
|
147
152
|
mapType(type) {
|
|
148
153
|
return this.targetNameConvertorInstance.convert(type);
|
|
149
154
|
}
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
enableCache() {
|
|
156
|
+
this.referenceCache = new Map();
|
|
152
157
|
}
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
resolveTypeReference(type, singleStep) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
if ((_a = this.referenceCache) === null || _a === void 0 ? void 0 : _a.has(type))
|
|
161
|
+
return this.referenceCache.get(type);
|
|
162
|
+
let result = this.resolveNamedNode(type.name.split("."), type.parent);
|
|
163
|
+
if (!singleStep) {
|
|
164
|
+
const seen = new Set;
|
|
165
|
+
while (result) {
|
|
166
|
+
let nextResult = undefined;
|
|
167
|
+
if (idl.isImport(result))
|
|
168
|
+
nextResult = this.resolveImport(result);
|
|
169
|
+
else if (idl.isReferenceType(result))
|
|
170
|
+
nextResult = this.resolveNamedNode(result.name.split("."));
|
|
171
|
+
else if (idl.isTypedef(result) && idl.isReferenceType(result.type))
|
|
172
|
+
nextResult = this.resolveNamedNode(result.type.name.split("."));
|
|
173
|
+
if (!nextResult)
|
|
174
|
+
break;
|
|
175
|
+
if (seen.has(nextResult)) {
|
|
176
|
+
console.warn(`Cyclic referenceType: ${type.name}, seen: [${[...seen.values()].map(idl.getFQName).join(", ")}]`);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
seen.add(nextResult);
|
|
180
|
+
result = nextResult;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (result && (idl.isImport(result) || idl.isNamespace(result)))
|
|
184
|
+
result = undefined;
|
|
185
|
+
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
disableFallback() {
|
|
189
|
+
this._useFallback = false;
|
|
190
|
+
}
|
|
191
|
+
resolveNamedNode(target, pov = undefined) {
|
|
192
|
+
const qualifiedName = target.join(".");
|
|
193
|
+
const entry = this._syntheticFile.entries.find(it => it.name === qualifiedName);
|
|
155
194
|
if (entry)
|
|
156
195
|
return entry;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// One of possible options - `rootEntries = rootEntries.flatMap(it => idl.isNamespace(it) ? it.members : it)` - cause error
|
|
161
|
-
rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
|
|
162
|
-
if (1 === qualifiedName.length) {
|
|
163
|
-
const predefined = rootEntries.filter(it => isInIdlizeInternal(it));
|
|
164
|
-
const found = predefined.find(it => it.name === qualifiedName[0]);
|
|
196
|
+
if (1 === target.length) {
|
|
197
|
+
const predefined = this.files.flatMap(it => it.entries).filter(isInIdlizeInternal);
|
|
198
|
+
const found = predefined.find(it => it.name === target.at(-1));
|
|
165
199
|
if (found)
|
|
166
200
|
return found;
|
|
167
201
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
for (
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
if (qualifiedNamePart === qualifiedName.length - 1) {
|
|
179
|
-
const target = candidates.length == 1
|
|
180
|
-
? candidates[0]
|
|
181
|
-
: candidates.find(it => !idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Import)); // probably the wrong logic here
|
|
182
|
-
if (target && idl.isImport(target)) // Temporary disable Import declarations
|
|
183
|
-
return undefined;
|
|
184
|
-
return target;
|
|
185
|
-
}
|
|
186
|
-
entries = [];
|
|
187
|
-
for (const candidate of candidates) {
|
|
188
|
-
if (idl.isNamespace(candidate))
|
|
189
|
-
entries.push(...candidate.members);
|
|
190
|
-
else if (idl.isEnum(candidate))
|
|
191
|
-
entries.push(...candidate.elements);
|
|
192
|
-
else if (idl.isInterface(candidate))
|
|
193
|
-
entries.push(...candidate.constants, ...candidate.properties, ...candidate.methods);
|
|
194
|
-
}
|
|
202
|
+
const corpus = this.files.concat(this.auxFiles);
|
|
203
|
+
let result = resolveNamedNode(target, pov, corpus);
|
|
204
|
+
if (result && idl.isEntry(result))
|
|
205
|
+
return result;
|
|
206
|
+
if (1 == target.length) {
|
|
207
|
+
const stdScopes = generatorConfiguration().globalPackages.map(it => it.split('.'));
|
|
208
|
+
for (const stdScope of stdScopes) {
|
|
209
|
+
result = resolveNamedNode([...stdScope, ...target], undefined, corpus);
|
|
210
|
+
if (result && idl.isEntry(result))
|
|
211
|
+
return result;
|
|
195
212
|
}
|
|
196
|
-
pointOfViewNamespace = idl.fetchNamespaceFrom(pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.parent);
|
|
197
213
|
}
|
|
198
214
|
// TODO: remove the next block after namespaces out of quarantine
|
|
199
|
-
if (
|
|
215
|
+
if (this._useFallback) {
|
|
216
|
+
const povAsReadableString = pov
|
|
217
|
+
? `'${idl.getFQName(pov)}'`
|
|
218
|
+
: "[root]";
|
|
219
|
+
// retry from root
|
|
220
|
+
pov = undefined;
|
|
200
221
|
const resolveds = [];
|
|
222
|
+
for (let file of this.files) {
|
|
223
|
+
result = resolveNamedNode([...file.packageClause, ...target], pov, corpus);
|
|
224
|
+
if (result && idl.isEntry(result)) {
|
|
225
|
+
// too much spam
|
|
226
|
+
// console.warn(`WARNING: Type reference '${qualifiedName}' is not resolved from ${povAsReadableString} but resolved from some package '${file.packageClause().join(".")}'`)
|
|
227
|
+
resolveds.push(result);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// and from each namespace
|
|
201
231
|
const traverseNamespaces = (entry) => {
|
|
202
232
|
if (entry && idl.isNamespace(entry) && entry.members.length) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
233
|
+
const resolved = resolveNamedNode([...idl.getNamespacesPathFor(entry).map(it => it.name), ...target], pov, corpus);
|
|
234
|
+
if (resolved) {
|
|
235
|
+
console.warn(`WARNING: Name '${qualifiedName}' is not resolved from ${povAsReadableString} but resolved from some namespace: '${idl.getNamespacesPathFor(resolved).map(obj => obj.name).join(".")}'`);
|
|
206
236
|
resolveds.push(resolved);
|
|
237
|
+
}
|
|
207
238
|
entry.members.forEach(traverseNamespaces);
|
|
208
239
|
}
|
|
209
240
|
};
|
|
210
241
|
this.files.forEach(file => file.entries.forEach(traverseNamespaces));
|
|
211
|
-
|
|
212
|
-
|
|
242
|
+
for (const resolved of resolveds)
|
|
243
|
+
if (idl.isEntry(resolved))
|
|
244
|
+
return resolved;
|
|
213
245
|
} // end of block to remove
|
|
214
|
-
return undefined;
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
resolveImport(target) {
|
|
249
|
+
let result = this.resolveNamedNode(target.clause);
|
|
250
|
+
if (result) {
|
|
251
|
+
if (idl.isReferenceType(result))
|
|
252
|
+
return this.resolveTypeReference(result);
|
|
253
|
+
if (idl.isImport(result)) {
|
|
254
|
+
if (result == target) {
|
|
255
|
+
console.log("Self-targeted Import?");
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return this.resolveImport(result);
|
|
259
|
+
}
|
|
260
|
+
if (idl.isEntry(result))
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
215
264
|
}
|
|
216
265
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
217
266
|
if (isOptionalParam) {
|
|
@@ -243,16 +292,17 @@ export class PeerLibrary {
|
|
|
243
292
|
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
244
293
|
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
245
294
|
case idl.IDLUnknownType:
|
|
246
|
-
case idl.
|
|
295
|
+
case idl.IDLObjectType:
|
|
296
|
+
case idl.IDLAnyType: return new ObjectConvertor(param, idl.IDLAnyType);
|
|
247
297
|
case idl.IDLDate: return new DateConvertor(param);
|
|
298
|
+
case idl.IDLFunctionType: return new FunctionConvertor(this, param);
|
|
248
299
|
default: throw new Error(`Unconverted primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
249
300
|
}
|
|
250
301
|
}
|
|
251
302
|
if (idl.isReferenceType(type)) {
|
|
252
|
-
if (isImportAttr(type))
|
|
253
|
-
return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
|
|
254
303
|
// TODO: special cases for interop types.
|
|
255
|
-
|
|
304
|
+
// TODO: this types are not references! NativeModulePrinter must be fixed
|
|
305
|
+
switch (type.name.replaceAll('%TEXT%:', '')) { // this is really bad stub, to fix legacy references
|
|
256
306
|
case 'KBoolean': return new BooleanConvertor(param);
|
|
257
307
|
case 'KInt': return new NumericConvertor(param, idl.IDLI32Type);
|
|
258
308
|
case 'KFloat': return new NumericConvertor(param, idl.IDLF32Type);
|
|
@@ -262,7 +312,12 @@ export class PeerLibrary {
|
|
|
262
312
|
case 'number': return new NumberConvertor(param);
|
|
263
313
|
case 'KPointer': return new PointerConvertor(param);
|
|
264
314
|
}
|
|
315
|
+
if (generatorConfiguration().forceResource.includes(type.name)) {
|
|
316
|
+
return new ObjectConvertor(param, type);
|
|
317
|
+
}
|
|
265
318
|
const decl = this.resolveTypeReference(type);
|
|
319
|
+
if (decl && isImportAttr(decl) || !decl && isImportAttr(type))
|
|
320
|
+
return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
|
|
266
321
|
return this.declarationConvertor(param, type, decl);
|
|
267
322
|
}
|
|
268
323
|
if (idl.isUnionType(type)) {
|
|
@@ -281,15 +336,28 @@ export class PeerLibrary {
|
|
|
281
336
|
throw new Error(`Cannot convert: ${type.kind}`);
|
|
282
337
|
}
|
|
283
338
|
declarationConvertor(param, type, declaration) {
|
|
339
|
+
if (generatorConfiguration().forceResource.includes(type.name)) {
|
|
340
|
+
return new ObjectConvertor(param, type);
|
|
341
|
+
}
|
|
284
342
|
let customConv = this.customConvertor(param, type.name, type);
|
|
285
343
|
if (customConv)
|
|
286
344
|
return customConv;
|
|
287
|
-
if (!declaration)
|
|
345
|
+
if (!declaration) {
|
|
288
346
|
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), false, this.targetNameConvertorInstance.convert(type)); // assume some predefined type
|
|
347
|
+
}
|
|
289
348
|
const declarationName = declaration.name;
|
|
290
349
|
if (isImportAttr(declaration)) {
|
|
291
350
|
return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
|
|
292
351
|
}
|
|
352
|
+
if (idl.isImport(declaration)) {
|
|
353
|
+
const target = this.resolveImport(declaration);
|
|
354
|
+
if (target && idl.isEntry(target))
|
|
355
|
+
return this.declarationConvertor(param, type, target);
|
|
356
|
+
else {
|
|
357
|
+
warn(`Unable to resolve Import ${declaration.clause.join(".")} as ${declaration.name}`);
|
|
358
|
+
return new CustomTypeConvertor(param, declaration.name, false, declaration.name);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
293
361
|
if (idl.isEnum(declaration)) {
|
|
294
362
|
return new EnumConvertor(param, declaration);
|
|
295
363
|
}
|
|
@@ -328,11 +396,11 @@ export class PeerLibrary {
|
|
|
328
396
|
customConvertor(param, typeName, type) {
|
|
329
397
|
switch (typeName) {
|
|
330
398
|
case `Object`:
|
|
331
|
-
return new
|
|
399
|
+
return new ObjectConvertor(param, idl.IDLObjectType);
|
|
332
400
|
case `Date`:
|
|
333
401
|
return new DateConvertor(param);
|
|
334
402
|
case `Function`:
|
|
335
|
-
return new FunctionConvertor(this, param
|
|
403
|
+
return new FunctionConvertor(this, param);
|
|
336
404
|
case `Record`:
|
|
337
405
|
return new CustomTypeConvertor(param, "Record", false, "Record<string, string>");
|
|
338
406
|
case `Optional`:
|
|
@@ -349,25 +417,19 @@ export class PeerLibrary {
|
|
|
349
417
|
case idl.IDLVoidType: return idl.IDLVoidType;
|
|
350
418
|
case idl.IDLUndefinedType: return idl.IDLUndefinedType;
|
|
351
419
|
case idl.IDLUnknownType: return ArkCustomObject;
|
|
352
|
-
case idl.IDLObjectType: return ArkCustomObject
|
|
420
|
+
// case idl.IDLObjectType: return ArkCustomObject
|
|
353
421
|
}
|
|
354
422
|
const typeName = idl.isNamedNode(type) ? type.name : undefined;
|
|
355
423
|
switch (typeName) {
|
|
356
424
|
case "object":
|
|
357
|
-
case "Object": return
|
|
358
|
-
}
|
|
359
|
-
if (isImportAttr(type)) {
|
|
360
|
-
return ArkCustomObject;
|
|
425
|
+
case "Object": return idl.IDLObjectType;
|
|
361
426
|
}
|
|
362
427
|
if (idl.isReferenceType(type)) {
|
|
363
428
|
// TODO: remove all this!
|
|
364
|
-
if (type.name === 'Dimension' || type.name === 'Length') {
|
|
365
|
-
return ArkLength;
|
|
366
|
-
}
|
|
367
429
|
if (type.name === 'Date') {
|
|
368
430
|
return ArkDate;
|
|
369
431
|
}
|
|
370
|
-
if (type.name === 'AnimationRange'
|
|
432
|
+
if (type.name === 'AnimationRange') {
|
|
371
433
|
return ArkCustomObject;
|
|
372
434
|
}
|
|
373
435
|
if (type.name === 'Function') {
|
|
@@ -388,6 +450,9 @@ export class PeerLibrary {
|
|
|
388
450
|
: idl.isTypedef(decl) ? this.toDeclaration(decl.type)
|
|
389
451
|
: decl;
|
|
390
452
|
}
|
|
453
|
+
if (isImportAttr(type)) {
|
|
454
|
+
return ArkCustomObject;
|
|
455
|
+
}
|
|
391
456
|
return type;
|
|
392
457
|
}
|
|
393
458
|
setFileLayout(strategy) {
|
|
@@ -397,7 +462,6 @@ export class PeerLibrary {
|
|
|
397
462
|
export const ArkInt32 = idl.IDLI32Type;
|
|
398
463
|
export const ArkInt64 = idl.IDLI64Type;
|
|
399
464
|
export const ArkFunction = idl.IDLFunctionType;
|
|
400
|
-
export const ArkLength = idl.IDLLengthType;
|
|
401
465
|
export const ArkDate = idl.IDLDate;
|
|
402
466
|
export const ArkCustomObject = idl.IDLCustomObjectType;
|
|
403
467
|
export function cleanPrefix(name, prefix) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as idl from '../idl';
|
|
2
2
|
export interface ReferenceResolver {
|
|
3
|
-
resolveTypeReference(type: idl.IDLReferenceType,
|
|
3
|
+
resolveTypeReference(type: idl.IDLReferenceType, terminalImports?: boolean): idl.IDLEntry | undefined;
|
|
4
4
|
toDeclaration(type: idl.IDLNode): idl.IDLNode;
|
|
5
5
|
}
|
|
6
6
|
export declare function createEmptyReferenceResolver(): ReferenceResolver;
|
|
@@ -25,9 +25,9 @@ export function createEmptyReferenceResolver() {
|
|
|
25
25
|
/** Please do not store any global instances */
|
|
26
26
|
export function createAlternativeReferenceResolver(mainResolver, alternatives) {
|
|
27
27
|
return {
|
|
28
|
-
resolveTypeReference(type,
|
|
28
|
+
resolveTypeReference(type, terminalImports) {
|
|
29
29
|
var _a;
|
|
30
|
-
return (_a = mainResolver.resolveTypeReference(type,
|
|
30
|
+
return (_a = mainResolver.resolveTypeReference(type, terminalImports)) !== null && _a !== void 0 ? _a : alternatives.get(type.name);
|
|
31
31
|
},
|
|
32
32
|
toDeclaration(type) {
|
|
33
33
|
return mainResolver.toDeclaration(type);
|
|
@@ -2,6 +2,7 @@ import * as idl from "../../idl";
|
|
|
2
2
|
import { DeclarationConvertor } from "../../LanguageWriters/nameConvertor";
|
|
3
3
|
import { Language } from "../../Language";
|
|
4
4
|
export declare class DeclarationNameConvertor implements DeclarationConvertor<string> {
|
|
5
|
+
convertImport(decl: idl.IDLImport): string;
|
|
5
6
|
convertInterface(decl: idl.IDLInterface): string;
|
|
6
7
|
convertEnum(decl: idl.IDLEnum): string;
|
|
7
8
|
convertTypedef(decl: idl.IDLTypedef): string;
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
import * as idl from "../../idl";
|
|
16
16
|
import { Language } from "../../Language";
|
|
17
17
|
export class DeclarationNameConvertor {
|
|
18
|
+
convertImport(decl) {
|
|
19
|
+
console.warn("Imports are not implemented yet");
|
|
20
|
+
return decl.name;
|
|
21
|
+
}
|
|
18
22
|
convertInterface(decl) {
|
|
19
23
|
return decl.name;
|
|
20
24
|
}
|
|
@@ -50,10 +54,10 @@ export class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
|
50
54
|
TSFeatureNameConvertor.I = new TSFeatureNameConvertor();
|
|
51
55
|
export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
52
56
|
convertInterface(decl) {
|
|
53
|
-
return idl.
|
|
57
|
+
return idl.getQualifiedName(decl, "namespace.name");
|
|
54
58
|
}
|
|
55
59
|
convertEnum(decl) {
|
|
56
|
-
return idl.
|
|
60
|
+
return idl.getQualifiedName(decl, "namespace.name");
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
ETSDeclarationNameConvertor.I = new ETSDeclarationNameConvertor();
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as idl from "../../idl";
|
|
2
2
|
import { Language } from "../../Language";
|
|
3
3
|
export declare function generateSyntheticIdlNodeName(type: idl.IDLType): string;
|
|
4
|
-
export declare function qualifiedName(decl: idl.IDLNode, languageOrDelimiter: Language | string): string;
|
|
4
|
+
export declare function qualifiedName(decl: idl.IDLNode, languageOrDelimiter: Language | string, pattern: idl.QNPattern): string;
|
|
5
5
|
export declare function collapseTypes(types: idl.IDLType[], name?: string): idl.IDLType;
|
|
6
6
|
export declare function generifiedTypeName(refType: idl.IDLReferenceType | undefined, refName?: string): string | undefined;
|
|
7
|
+
export declare function sanitizeGenerics(genericDeclarationString: string): string;
|
|
7
8
|
export declare function generateSyntheticUnionName(types: idl.IDLType[]): string;
|
|
9
|
+
export declare function generateSyntheticFunctionParameterName(parameter: idl.IDLParameter): string;
|
|
8
10
|
export declare function generateSyntheticFunctionName(parameters: idl.IDLParameter[], returnType: idl.IDLType, isAsync?: boolean): string;
|
|
9
11
|
export declare function isImportAttr(decl: idl.IDLNode): boolean;
|
|
10
12
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -28,12 +28,12 @@ export function generateSyntheticIdlNodeName(type) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (idl.isNamedNode(type))
|
|
31
|
-
return type.name;
|
|
31
|
+
return type.name.split('.').map(capitalize).join('_');
|
|
32
32
|
if (idl.isOptionalType(type))
|
|
33
33
|
return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
|
|
34
34
|
throw `Can not compute type name of ${idl.IDLKind[type.kind]}`;
|
|
35
35
|
}
|
|
36
|
-
export function qualifiedName(decl, languageOrDelimiter) {
|
|
36
|
+
export function qualifiedName(decl, languageOrDelimiter, pattern) {
|
|
37
37
|
if (!idl.isNamedNode(decl))
|
|
38
38
|
throw new Error("internal error, name required for no-named node");
|
|
39
39
|
const delimiter = typeof languageOrDelimiter === "string"
|
|
@@ -41,7 +41,7 @@ export function qualifiedName(decl, languageOrDelimiter) {
|
|
|
41
41
|
: (languageOrDelimiter === Language.CPP ? '_' : '.');
|
|
42
42
|
if (!idl.isEntry(decl))
|
|
43
43
|
throw new Error(`Expected to have an IDLEntry, got ${idl.IDLKind[decl.kind]}`);
|
|
44
|
-
return idl.
|
|
44
|
+
return idl.getQualifiedName(decl, pattern).split(".").join(delimiter);
|
|
45
45
|
}
|
|
46
46
|
export function collapseTypes(types, name) {
|
|
47
47
|
const seenNames = new Set();
|
|
@@ -61,12 +61,29 @@ export function generifiedTypeName(refType, refName) {
|
|
|
61
61
|
const typeArgs = (_a = refType.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it)).join(",");
|
|
62
62
|
return `${refName ? refName : refType.name}${typeArgs ? `<${typeArgs}>` : ``}`;
|
|
63
63
|
}
|
|
64
|
+
export function sanitizeGenerics(genericDeclarationString) {
|
|
65
|
+
const eqIdx = genericDeclarationString.indexOf('=');
|
|
66
|
+
if (eqIdx !== -1) {
|
|
67
|
+
genericDeclarationString = genericDeclarationString.substring(0, eqIdx);
|
|
68
|
+
}
|
|
69
|
+
const extendsIdx = genericDeclarationString.indexOf('extends');
|
|
70
|
+
if (extendsIdx !== -1) {
|
|
71
|
+
genericDeclarationString = genericDeclarationString.substring(0, extendsIdx);
|
|
72
|
+
}
|
|
73
|
+
return genericDeclarationString.trim();
|
|
74
|
+
}
|
|
64
75
|
export function generateSyntheticUnionName(types) {
|
|
65
76
|
return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_").replaceAll(".", "_")}`;
|
|
66
77
|
}
|
|
78
|
+
export function generateSyntheticFunctionParameterName(parameter) {
|
|
79
|
+
if (parameter.isOptional) {
|
|
80
|
+
return generateSyntheticIdlNodeName(idl.createOptionalType(parameter.type));
|
|
81
|
+
}
|
|
82
|
+
return generateSyntheticIdlNodeName(parameter.type);
|
|
83
|
+
}
|
|
67
84
|
export function generateSyntheticFunctionName(parameters, returnType, isAsync = false) {
|
|
68
85
|
let prefix = isAsync ? "AsyncCallback" : "Callback";
|
|
69
|
-
const names = parameters.map(
|
|
86
|
+
const names = parameters.map(generateSyntheticFunctionParameterName).concat(generateSyntheticIdlNodeName(returnType));
|
|
70
87
|
return `${prefix}_${names.join("_").replaceAll(".", "_")}`;
|
|
71
88
|
}
|
|
72
89
|
export function isImportAttr(decl) {
|
|
@@ -16,20 +16,31 @@ import { generatorConfiguration } from '../config';
|
|
|
16
16
|
import * as idl from '../idl';
|
|
17
17
|
import { isBuilderClass } from './BuilderClass';
|
|
18
18
|
export function isMaterialized(declaration, resolver) {
|
|
19
|
+
var _a;
|
|
19
20
|
if (!idl.isInterfaceSubkind(declaration) && !idl.isClassSubkind(declaration))
|
|
20
21
|
return false;
|
|
21
22
|
if (idl.isHandwritten(declaration) || isBuilderClass(declaration))
|
|
22
23
|
return false;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (generatorConfiguration().forceResource.includes(declaration.name)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (generatorConfiguration().forceMaterialized.includes(declaration.name)) {
|
|
28
|
+
return true;
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
// TODO: rework this
|
|
31
|
+
if (["BaseSpan"].includes(declaration.name)) {
|
|
28
32
|
return false;
|
|
29
33
|
}
|
|
30
|
-
for (const ignore of
|
|
31
|
-
if (declaration.name.endsWith(ignore))
|
|
34
|
+
for (const ignore of ["Attribute", "Method", "Interface"]) {
|
|
35
|
+
if (declaration.name.endsWith(ignore)) {
|
|
32
36
|
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (((_a = generatorConfiguration().forceCallback.get(declaration.name)) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (generatorConfiguration().ignoreMaterialized.includes(declaration.name)) {
|
|
43
|
+
return false;
|
|
33
44
|
}
|
|
34
45
|
// A materialized class is a class or an interface with methods
|
|
35
46
|
// excluding components and related classes
|
|
@@ -46,11 +57,21 @@ export function isMaterialized(declaration, resolver) {
|
|
|
46
57
|
}
|
|
47
58
|
return false;
|
|
48
59
|
}
|
|
60
|
+
function isSelfReturnMethod(method, entry, resolver) {
|
|
61
|
+
if (!idl.isReferenceType(method.returnType)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const found = resolver.resolveTypeReference(method.returnType);
|
|
65
|
+
if (!found) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return idl.getFQName(found) === idl.getFQName(entry);
|
|
69
|
+
}
|
|
49
70
|
export function isStaticMaterialized(declaration, resolver) {
|
|
50
71
|
if (isMaterialized(declaration, resolver)) {
|
|
51
72
|
if (declaration.properties.length || declaration.constructors.length)
|
|
52
73
|
return false;
|
|
53
|
-
if (!declaration.methods.every(it => it.isStatic))
|
|
74
|
+
if (!declaration.methods.every(it => it.isStatic && !isSelfReturnMethod(it, declaration, resolver)))
|
|
54
75
|
return false;
|
|
55
76
|
if (idl.hasSuperType(declaration)) {
|
|
56
77
|
const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypeConvertor } from "../LanguageWriters";
|
|
2
|
-
import { IDLContainerType, IDLOptionalType, IDLPrimitiveType, IDLReferenceType, IDLType, IDLTypeParameterType, IDLUnionType } from '../idl';
|
|
2
|
+
import { IDLImport, IDLContainerType, IDLOptionalType, IDLPrimitiveType, IDLReferenceType, IDLType, IDLTypeParameterType, IDLUnionType } from '../idl';
|
|
3
3
|
import { LanguageExpression, LanguageWriter } from "../LanguageWriters/LanguageWriter";
|
|
4
4
|
import { ArgConvertor } from "../LanguageWriters/ArgConvertors";
|
|
5
5
|
import { LibraryInterface } from "../LibraryInterface";
|
|
@@ -7,11 +7,12 @@ import { ReferenceResolver } from "./ReferenceResolver";
|
|
|
7
7
|
export declare class UnionFlattener implements TypeConvertor<IDLType[]> {
|
|
8
8
|
private resolver;
|
|
9
9
|
constructor(resolver: ReferenceResolver);
|
|
10
|
+
convertImport(type: IDLImport): IDLType[];
|
|
10
11
|
convertUnion(type: IDLUnionType): IDLType[];
|
|
11
12
|
convertTypeReference(type: IDLReferenceType): IDLType[];
|
|
12
13
|
convertOptional(type: IDLOptionalType): IDLType[];
|
|
13
14
|
convertContainer(type: IDLContainerType): IDLType[];
|
|
14
|
-
|
|
15
|
+
convertTypeReferenceAsImport(type: IDLReferenceType, importClause: string): IDLType[];
|
|
15
16
|
convertPrimitiveType(type: IDLPrimitiveType): IDLType[];
|
|
16
17
|
convertTypeParameter(type: IDLTypeParameterType): IDLType[];
|
|
17
18
|
}
|
|
@@ -21,6 +21,10 @@ export class UnionFlattener {
|
|
|
21
21
|
constructor(resolver) {
|
|
22
22
|
this.resolver = resolver;
|
|
23
23
|
}
|
|
24
|
+
convertImport(type) {
|
|
25
|
+
console.warn("Imports are not implemented yet");
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
24
28
|
convertUnion(type) {
|
|
25
29
|
return type.types.flatMap(it => convertType(this, it));
|
|
26
30
|
}
|
|
@@ -34,7 +38,7 @@ export class UnionFlattener {
|
|
|
34
38
|
convertContainer(type) {
|
|
35
39
|
return [type];
|
|
36
40
|
}
|
|
37
|
-
|
|
41
|
+
convertTypeReferenceAsImport(type, importClause) {
|
|
38
42
|
return [type];
|
|
39
43
|
}
|
|
40
44
|
convertPrimitiveType(type) {
|
|
@@ -106,13 +110,13 @@ export class UnionRuntimeTypeChecker {
|
|
|
106
110
|
const discriminator = discr ? discr.asString() : "<undefined>";
|
|
107
111
|
report += ` ${num}| ${typename}| ${properties}| ${resolved}| ${discriminator}\n`;
|
|
108
112
|
});
|
|
109
|
-
throw new Error(report)
|
|
113
|
+
// throw new Error(report)
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
export function flattenUnionType(library, type) {
|
|
114
|
-
const unionFlattener = new UnionFlattener(library);
|
|
115
118
|
if (isUnionType(type)) {
|
|
119
|
+
const unionFlattener = new UnionFlattener(library);
|
|
116
120
|
const allTypes = type.types.flatMap(it => convertType(unionFlattener, it));
|
|
117
121
|
const uniqueTypes = new Set(allTypes);
|
|
118
122
|
return uniqueTypes.size === allTypes.length ? type : collapseTypes(Array.from(uniqueTypes));
|