@idlizer/core 2.0.26 → 2.0.28
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 +1 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +7 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +4 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -5
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +45 -5
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +200 -9
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -35
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +24 -169
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +2 -0
- package/build/lib/src/LanguageWriters/index.js +3 -3
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +4 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +13 -9
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +7 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +2 -2
- package/build/lib/src/LibraryInterface.d.ts +1 -0
- package/build/lib/src/config.d.ts +13 -16
- package/build/lib/src/config.js +13 -17
- package/build/lib/src/idl.d.ts +1 -1
- package/build/lib/src/idl.js +4 -19
- package/build/lib/src/index.d.ts +2 -0
- package/build/lib/src/index.js +2 -0
- package/build/lib/src/inheritance.js +2 -2
- package/build/lib/src/languageSpecificKeywords.js +1 -1
- package/build/lib/src/library.d.ts +5 -4
- package/build/lib/src/library.js +3 -0
- package/build/lib/src/peer-generation/BuilderClass.js +1 -1
- package/build/lib/src/peer-generation/LayoutManager.d.ts +2 -1
- package/build/lib/src/peer-generation/LayoutManager.js +1 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +0 -1
- package/build/lib/src/peer-generation/Materialized.js +3 -48
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -0
- package/build/lib/src/peer-generation/PeerFile.js +4 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10246 -2
- package/build/lib/src/peer-generation/PeerLibrary.js +48 -10
- package/build/lib/src/peer-generation/PrimitiveType.d.ts +1 -0
- package/build/lib/src/peer-generation/PrimitiveType.js +1 -0
- package/build/lib/src/peer-generation/isMaterialized.d.ts +4 -0
- package/build/lib/src/peer-generation/isMaterialized.js +46 -0
- package/build/lib/src/peer-generation/isStructureType.d.ts +4 -0
- package/build/lib/src/peer-generation/isStructureType.js +25 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +14 -3
- package/package.json +2 -2
|
@@ -17,17 +17,38 @@ import * as idl from '../idl';
|
|
|
17
17
|
import { Language } from '../Language';
|
|
18
18
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
19
19
|
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, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
-
import {
|
|
20
|
+
import { CppNameConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
21
21
|
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
22
|
-
import {
|
|
22
|
+
import { CppConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
23
23
|
import { ETSTypeNameConvertor } from '../LanguageWriters/convertors/ETSConvertors';
|
|
24
24
|
import { JavaTypeNameConvertor } from '../LanguageWriters/convertors/JavaConvertors';
|
|
25
25
|
import { TSTypeNameConvertor } from '../LanguageWriters/convertors/TSConvertors';
|
|
26
26
|
import { isBuilderClass } from './BuilderClass';
|
|
27
27
|
import { generateSyntheticFunctionName, isImportAttr } from './idl/common';
|
|
28
|
-
import { isMaterialized } from './Materialized';
|
|
29
28
|
import { LayoutManager } from './LayoutManager';
|
|
29
|
+
import { lib, query } from '../library';
|
|
30
|
+
import { isMaterialized } from './isMaterialized';
|
|
31
|
+
export const lenses = {
|
|
32
|
+
globals: lib.lens(lib.select.files())
|
|
33
|
+
.pipe(lib.select.nodes({ expandNamespaces: true }))
|
|
34
|
+
.pipe(lib.select.interfaces())
|
|
35
|
+
.pipe(lib.select.hasExt(idl.IDLExtendedAttributes.GlobalScope))
|
|
36
|
+
};
|
|
30
37
|
export class PeerLibrary {
|
|
38
|
+
asIDLLibrary() {
|
|
39
|
+
if (this._cachedIdlLibrary) {
|
|
40
|
+
return this._cachedIdlLibrary;
|
|
41
|
+
}
|
|
42
|
+
this._cachedIdlLibrary = {
|
|
43
|
+
files: this.files.map(file => ({
|
|
44
|
+
fileName: file.originalFilename,
|
|
45
|
+
entities: file.entries,
|
|
46
|
+
package: file.package()
|
|
47
|
+
}))
|
|
48
|
+
};
|
|
49
|
+
return this._cachedIdlLibrary;
|
|
50
|
+
}
|
|
51
|
+
get globalScopeInterfaces() { return query(this.asIDLLibrary(), lenses.globals); }
|
|
31
52
|
/** @deprecated PeerLibrary should contain only SDK entries */
|
|
32
53
|
get syntheticEntries() {
|
|
33
54
|
return this._syntheticEntries;
|
|
@@ -41,19 +62,19 @@ export class PeerLibrary {
|
|
|
41
62
|
get materializedToGenerate() {
|
|
42
63
|
return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated);
|
|
43
64
|
}
|
|
44
|
-
constructor(language) {
|
|
65
|
+
constructor(language, libraryPackages) {
|
|
45
66
|
this.language = language;
|
|
67
|
+
this.libraryPackages = libraryPackages;
|
|
46
68
|
this.layout = LayoutManager.Empty();
|
|
47
69
|
this._syntheticEntries = [];
|
|
48
70
|
this.files = [];
|
|
49
71
|
this.builderClasses = new Map();
|
|
50
72
|
this.materializedClasses = new Map();
|
|
51
73
|
this.predefinedDeclarations = [];
|
|
52
|
-
this.globalScopeInterfaces = [];
|
|
53
74
|
this.name = "";
|
|
54
75
|
this.customComponentMethods = [];
|
|
55
76
|
this.targetNameConvertorInstance = this.createTypeNameConvertor(this.language);
|
|
56
|
-
this.interopNameConvertorInstance = new
|
|
77
|
+
this.interopNameConvertorInstance = new CppNameConvertor(this);
|
|
57
78
|
}
|
|
58
79
|
createLanguageWriter(language) {
|
|
59
80
|
return createLanguageWriter(language !== null && language !== void 0 ? language : this.language, this);
|
|
@@ -64,7 +85,7 @@ export class PeerLibrary {
|
|
|
64
85
|
case Language.ARKTS: return new ETSTypeNameConvertor(this);
|
|
65
86
|
case Language.JAVA: return new JavaTypeNameConvertor(this);
|
|
66
87
|
case Language.CJ: return new CJTypeNameConvertor(this);
|
|
67
|
-
case Language.CPP: return new
|
|
88
|
+
case Language.CPP: return new CppConvertor(this);
|
|
68
89
|
}
|
|
69
90
|
throw new Error(`IdlNameConvertor for ${language} is not implemented`);
|
|
70
91
|
}
|
|
@@ -165,6 +186,23 @@ export class PeerLibrary {
|
|
|
165
186
|
} // end of block to remove
|
|
166
187
|
return undefined; // empty result
|
|
167
188
|
}
|
|
189
|
+
resolvePackageName(entry) {
|
|
190
|
+
var _a;
|
|
191
|
+
if (this._syntheticEntries.includes(entry))
|
|
192
|
+
return ((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) ? this.libraryPackages[0] : this.files[0].packageName();
|
|
193
|
+
while (entry.namespace) {
|
|
194
|
+
entry = entry.namespace;
|
|
195
|
+
}
|
|
196
|
+
for (const file of this.files) {
|
|
197
|
+
if (file.entries.includes(entry))
|
|
198
|
+
return file.packageName();
|
|
199
|
+
}
|
|
200
|
+
throw new Error(`Package name for entry ${entry.name} was not found`);
|
|
201
|
+
}
|
|
202
|
+
hasInLibrary(entry) {
|
|
203
|
+
var _a, _b;
|
|
204
|
+
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(this.resolvePackageName(entry)));
|
|
205
|
+
}
|
|
168
206
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
169
207
|
if (isOptionalParam) {
|
|
170
208
|
return new OptionConvertor(this, param, idl.maybeUnwrapOptionalType(type));
|
|
@@ -194,7 +232,7 @@ export class PeerLibrary {
|
|
|
194
232
|
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
195
233
|
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
196
234
|
case idl.IDLUnknownType:
|
|
197
|
-
case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any");
|
|
235
|
+
case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any", false, "Object");
|
|
198
236
|
default: throw new Error(`Unconverted primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
199
237
|
}
|
|
200
238
|
}
|
|
@@ -215,7 +253,7 @@ export class PeerLibrary {
|
|
|
215
253
|
}
|
|
216
254
|
if (idl.isTypeParameterType(type)) {
|
|
217
255
|
// TODO: unlikely correct.
|
|
218
|
-
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true);
|
|
256
|
+
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true, `<${type.name}>`);
|
|
219
257
|
}
|
|
220
258
|
throw new Error(`Cannot convert: ${type.kind}`);
|
|
221
259
|
}
|
|
@@ -267,7 +305,7 @@ export class PeerLibrary {
|
|
|
267
305
|
customConvertor(param, typeName, type) {
|
|
268
306
|
switch (typeName) {
|
|
269
307
|
case `Object`:
|
|
270
|
-
return new CustomTypeConvertor(param, "Object");
|
|
308
|
+
return new CustomTypeConvertor(param, "Object", false, "Object");
|
|
271
309
|
case `Date`:
|
|
272
310
|
return new DateConvertor(param);
|
|
273
311
|
case `Function`:
|
|
@@ -19,6 +19,7 @@ export declare class PrimitiveTypeList {
|
|
|
19
19
|
readonly Tag: PrimitiveType;
|
|
20
20
|
readonly Materialized: PrimitiveType;
|
|
21
21
|
readonly CustomObject: PrimitiveType;
|
|
22
|
+
readonly String: PrimitiveType;
|
|
22
23
|
}
|
|
23
24
|
export declare const PrimitiveTypesInstance: PrimitiveTypeList;
|
|
24
25
|
//# sourceMappingURL=PrimitiveType.d.ts.map
|
|
@@ -37,6 +37,7 @@ export class PrimitiveTypeList {
|
|
|
37
37
|
this.Tag = new PrimitiveType(`Tag`);
|
|
38
38
|
this.Materialized = new PrimitiveType(`Materialized`, true);
|
|
39
39
|
this.CustomObject = new PrimitiveType(`CustomObject`, true);
|
|
40
|
+
this.String = new PrimitiveType(`String`);
|
|
40
41
|
}
|
|
41
42
|
static get UndefinedTag() {
|
|
42
43
|
return "INTEROP_TAG_UNDEFINED";
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { generatorConfiguration } from '../config';
|
|
16
|
+
import * as idl from '../idl';
|
|
17
|
+
import { isBuilderClass } from './BuilderClass';
|
|
18
|
+
export function isMaterialized(declaration, resolver) {
|
|
19
|
+
if (!idl.isInterfaceSubkind(declaration) && !idl.isClassSubkind(declaration))
|
|
20
|
+
return false;
|
|
21
|
+
if (idl.isHandwritten(declaration) || isBuilderClass(declaration))
|
|
22
|
+
return false;
|
|
23
|
+
for (const forceMaterialized of generatorConfiguration().forceMaterialized) {
|
|
24
|
+
if (declaration.name == forceMaterialized)
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
for (const ignore of generatorConfiguration().ignoreMaterialized) {
|
|
28
|
+
if (declaration.name.endsWith(ignore))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// A materialized class is a class or an interface with methods
|
|
32
|
+
// excluding components and related classes
|
|
33
|
+
if (declaration.methods.length > 0 || declaration.constructors.length > 0)
|
|
34
|
+
return true;
|
|
35
|
+
// Or a class or an interface derived from materialized class
|
|
36
|
+
if (idl.hasSuperType(declaration)) {
|
|
37
|
+
const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
|
|
38
|
+
if (!superType || !idl.isInterface(superType)) {
|
|
39
|
+
console.log(`Unable to resolve ${idl.getSuperType(declaration).name} type, consider ${declaration.name} to be not materialized`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return isMaterialized(superType, resolver);
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=isMaterialized.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 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 { isReferenceType, isInterface } from "../idl";
|
|
16
|
+
import { isMaterialized } from "./isMaterialized";
|
|
17
|
+
export function isStructureType(type, library) {
|
|
18
|
+
if (!isReferenceType(type))
|
|
19
|
+
return false;
|
|
20
|
+
const resolved = library.resolveTypeReference(type);
|
|
21
|
+
if (!resolved || !isInterface(resolved))
|
|
22
|
+
return false;
|
|
23
|
+
return !isMaterialized(resolved, library);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=isStructureType.js.map
|
|
@@ -23,7 +23,7 @@ export declare class UnionRuntimeTypeChecker {
|
|
|
23
23
|
constructor(convertors: ArgConvertor[]);
|
|
24
24
|
private checkConflicts;
|
|
25
25
|
makeDiscriminator(value: string, convertorIndex: number, writer: LanguageWriter): LanguageExpression;
|
|
26
|
-
reportConflicts(context: string | undefined): void;
|
|
26
|
+
reportConflicts(context: string | undefined, writer: LanguageWriter): void;
|
|
27
27
|
}
|
|
28
28
|
export declare function flattenUnionType(library: LibraryInterface, type: IDLType): IDLType;
|
|
29
29
|
//# sourceMappingURL=unions.d.ts.map
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { convertType } from "../LanguageWriters";
|
|
16
16
|
import { IDLCustomObjectType, IDLUndefinedType, isType, isUnionType } from '../idl';
|
|
17
17
|
import { typeOrUnion } from "./idl/common";
|
|
18
|
+
import { CustomTypeConvertor } from "../LanguageWriters/ArgConvertors";
|
|
18
19
|
import { RuntimeType } from "../LanguageWriters/common";
|
|
19
20
|
export class UnionFlattener {
|
|
20
21
|
constructor(resolver) {
|
|
@@ -92,10 +93,20 @@ export class UnionRuntimeTypeChecker {
|
|
|
92
93
|
writer.makeUnionVariantCondition(convertor, value, `${value}_type`, RuntimeType[it], convertorIndex, runtimeTypeIndex)
|
|
93
94
|
])));
|
|
94
95
|
}
|
|
95
|
-
reportConflicts(context) {
|
|
96
|
+
reportConflicts(context, writer) {
|
|
96
97
|
if (this.discriminators.filter(([discriminator, _, __]) => discriminator === undefined).length > 1) {
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
let report = `Union discrimination code can not be generated for \`${context}\`.\n`;
|
|
99
|
+
report += `Possible reasons for that are too similar or unresolved types in union (see below).\n`;
|
|
100
|
+
report += ` # | type | duplicated properties | resolved | discriminator expression\n`;
|
|
101
|
+
const properties = Array.from(this.duplicateMembers).join(",").padEnd(30);
|
|
102
|
+
this.discriminators.forEach(([discr, conv, n]) => {
|
|
103
|
+
const num = n.toString().padEnd(3);
|
|
104
|
+
const typename = conv.targetType(writer).padEnd(30);
|
|
105
|
+
const resolved = (conv instanceof CustomTypeConvertor ? "no" : "yes").padEnd(9);
|
|
106
|
+
const discriminator = discr ? discr.asString() : "<undefined>";
|
|
107
|
+
report += ` ${num}| ${typename}| ${properties}| ${resolved}| ${discriminator}\n`;
|
|
108
|
+
});
|
|
109
|
+
throw new Error(report);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.28",
|
|
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.
|
|
37
|
+
"@koalaui/interop": "1.5.3",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|