@idlizer/core 2.0.17 → 2.0.19
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/convertors/CJConvertors.d.ts +30 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +154 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +13 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +118 -0
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +32 -0
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +175 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +27 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +173 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LibraryInterface.d.ts +2 -0
- package/build/lib/src/config.js +14 -0
- package/build/lib/src/configMerge.d.ts +2 -0
- package/build/lib/src/configMerge.js +42 -0
- package/build/lib/src/from-idl/common.d.ts +1 -1
- package/build/lib/src/from-idl/common.js +20 -11
- package/build/lib/src/idl.d.ts +6 -3
- package/build/lib/src/idl.js +14 -10
- package/build/lib/src/idlize.d.ts +1 -1
- package/build/lib/src/idlize.js +57 -13
- package/build/lib/src/index.d.ts +7 -0
- package/build/lib/src/index.js +7 -0
- package/build/lib/src/options.d.ts +1 -0
- package/build/lib/src/peer-generation/LanguageWriters/index.d.ts +2 -0
- package/build/lib/src/peer-generation/LanguageWriters/index.js +2 -0
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.d.ts +25 -0
- package/build/lib/src/peer-generation/LanguageWriters/nameConvertor.js +55 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +15 -0
- package/build/lib/src/peer-generation/LayoutManager.js +32 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +2 -0
- package/build/lib/src/peer-generation/Materialized.js +28 -0
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +53 -0
- package/build/lib/src/peer-generation/PeerLibrary.js +340 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +3 -0
- package/package.json +2 -2
- package/webidl2.js/LICENSE +0 -21
- package/webidl2.js/README.md +0 -827
- package/webidl2.js/dist/package.json +0 -3
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
export function convertType(convertor, type) {
|
|
17
|
+
if (idl.isOptionalType(type))
|
|
18
|
+
return convertor.convertOptional(type);
|
|
19
|
+
if (idl.isUnionType(type))
|
|
20
|
+
return convertor.convertUnion(type);
|
|
21
|
+
if (idl.isContainerType(type))
|
|
22
|
+
return convertor.convertContainer(type);
|
|
23
|
+
if (idl.isReferenceType(type)) {
|
|
24
|
+
const importAttr = idl.getExtAttribute(type, idl.IDLExtendedAttributes.Import);
|
|
25
|
+
return importAttr
|
|
26
|
+
? convertor.convertImport(type, importAttr)
|
|
27
|
+
: convertor.convertTypeReference(type);
|
|
28
|
+
}
|
|
29
|
+
if (idl.isTypeParameterType(type))
|
|
30
|
+
return convertor.convertTypeParameter(type);
|
|
31
|
+
if (idl.isPrimitiveType(type))
|
|
32
|
+
return convertor.convertPrimitiveType(type);
|
|
33
|
+
throw new Error(`Unknown type ${idl.IDLKind[type.kind]}`);
|
|
34
|
+
}
|
|
35
|
+
export function convertDeclaration(convertor, decl) {
|
|
36
|
+
if (idl.isInterface(decl))
|
|
37
|
+
return convertor.convertInterface(decl);
|
|
38
|
+
if (idl.isEnum(decl))
|
|
39
|
+
return convertor.convertEnum(decl);
|
|
40
|
+
if (idl.isEnumMember(decl))
|
|
41
|
+
return convertor.convertEnum(decl.parent);
|
|
42
|
+
if (idl.isTypedef(decl))
|
|
43
|
+
return convertor.convertTypedef(decl);
|
|
44
|
+
if (idl.isCallback(decl))
|
|
45
|
+
return convertor.convertCallback(decl);
|
|
46
|
+
throw new Error(`Unknown declaration type ${decl.kind ? idl.IDLKind[decl.kind] : "(undefined kind)"}`);
|
|
47
|
+
}
|
|
48
|
+
export function convertNode(convertor, node) {
|
|
49
|
+
if (idl.isEntry(node))
|
|
50
|
+
return convertDeclaration(convertor, node);
|
|
51
|
+
if (idl.isType(node))
|
|
52
|
+
return convertType(convertor, node);
|
|
53
|
+
throw new Error(`Unknown node type ${idl.IDLKind[node.kind]}`);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=nameConvertor.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IDLNode } from "../idl";
|
|
2
|
+
export declare enum LayoutNodeRole {
|
|
3
|
+
PEER = 0,
|
|
4
|
+
INTERFACE = 1
|
|
5
|
+
}
|
|
6
|
+
export interface LayoutManagerStrategy {
|
|
7
|
+
resolve(node: IDLNode, role: LayoutNodeRole): string;
|
|
8
|
+
}
|
|
9
|
+
export declare class LayoutManager {
|
|
10
|
+
private strategy;
|
|
11
|
+
constructor(strategy: LayoutManagerStrategy);
|
|
12
|
+
resolve(node: IDLNode, role: LayoutNodeRole): string;
|
|
13
|
+
static Empty(): LayoutManager;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=LayoutManager.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
export var LayoutNodeRole;
|
|
16
|
+
(function (LayoutNodeRole) {
|
|
17
|
+
LayoutNodeRole[LayoutNodeRole["PEER"] = 0] = "PEER";
|
|
18
|
+
LayoutNodeRole[LayoutNodeRole["INTERFACE"] = 1] = "INTERFACE";
|
|
19
|
+
})(LayoutNodeRole || (LayoutNodeRole = {}));
|
|
20
|
+
export class LayoutManager {
|
|
21
|
+
constructor(strategy) {
|
|
22
|
+
this.strategy = strategy;
|
|
23
|
+
}
|
|
24
|
+
resolve(node, role) {
|
|
25
|
+
return this.strategy.resolve(node, role);
|
|
26
|
+
}
|
|
27
|
+
////////////////////////////////////////////////////////////////////
|
|
28
|
+
static Empty() {
|
|
29
|
+
return new LayoutManager({ resolve: () => '' });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=LayoutManager.js.map
|
|
@@ -3,6 +3,8 @@ import { ArgConvertor } from '../LanguageWriters/ArgConvertors';
|
|
|
3
3
|
import { Field, Method } from '../LanguageWriters/LanguageWriter';
|
|
4
4
|
import { PeerClassBase } from './PeerClass';
|
|
5
5
|
import { PeerMethod } from './PeerMethod';
|
|
6
|
+
import { ReferenceResolver } from './ReferenceResolver';
|
|
7
|
+
export declare function isMaterialized(declaration: idl.IDLInterface, resolver: ReferenceResolver): boolean;
|
|
6
8
|
export declare class MaterializedField {
|
|
7
9
|
field: Field;
|
|
8
10
|
argConvertor: ArgConvertor;
|
|
@@ -12,11 +12,39 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
+
import { generatorConfiguration } from '../config';
|
|
15
16
|
import * as idl from '../idl';
|
|
16
17
|
import { copyMethod, Method, MethodModifier, NamedMethodSignature } from '../LanguageWriters/LanguageWriter';
|
|
17
18
|
import { capitalize } from '../util';
|
|
19
|
+
import { isBuilderClass } from './BuilderClass';
|
|
18
20
|
import { qualifiedName } from './idl/common';
|
|
19
21
|
import { PeerMethod } from './PeerMethod';
|
|
22
|
+
export function isMaterialized(declaration, resolver) {
|
|
23
|
+
if (idl.isHandwritten(declaration) ||
|
|
24
|
+
isBuilderClass(declaration) ||
|
|
25
|
+
declaration.subkind === idl.IDLInterfaceSubkind.AnonymousInterface ||
|
|
26
|
+
declaration.subkind === idl.IDLInterfaceSubkind.Tuple) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
for (const ignore of generatorConfiguration().paramArray("ignoreMaterialized")) {
|
|
30
|
+
if (declaration.name.endsWith(ignore))
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// A materialized class is a class or an interface with methods
|
|
34
|
+
// excluding components and related classes
|
|
35
|
+
if (declaration.methods.length > 0)
|
|
36
|
+
return true;
|
|
37
|
+
// Or a class or an interface derived from materialized class
|
|
38
|
+
if (idl.hasSuperType(declaration)) {
|
|
39
|
+
const superType = resolver.resolveTypeReference(idl.getSuperType(declaration));
|
|
40
|
+
if (!superType || !idl.isInterface(superType)) {
|
|
41
|
+
console.log(`Unable to resolve ${idl.getSuperType(declaration).name} type, consider ${declaration.name} to be not materialized`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return isMaterialized(superType, resolver);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
20
48
|
export class MaterializedField {
|
|
21
49
|
constructor(field, argConvertor, outArgConvertor, isNullableOriginalTypeField) {
|
|
22
50
|
this.field = field;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as idl from '../idl';
|
|
2
|
+
import { Language } from '../Language';
|
|
3
|
+
import { IdlNameConvertor } from '../LanguageWriters';
|
|
4
|
+
import { ArgConvertor } from "../LanguageWriters/ArgConvertors";
|
|
5
|
+
import { LibraryInterface } from '../LibraryInterface';
|
|
6
|
+
import { BuilderClass } from './BuilderClass';
|
|
7
|
+
import { MaterializedClass } from './Materialized';
|
|
8
|
+
import { PeerFile } from './PeerFile';
|
|
9
|
+
import { LayoutManager, LayoutManagerStrategy } from './LayoutManager';
|
|
10
|
+
export declare class PeerLibrary implements LibraryInterface {
|
|
11
|
+
language: Language;
|
|
12
|
+
layout: LayoutManager;
|
|
13
|
+
private _syntheticEntries;
|
|
14
|
+
/** @deprecated PeerLibrary should contain only SDK entries */
|
|
15
|
+
get syntheticEntries(): idl.IDLEntry[];
|
|
16
|
+
initSyntheticEntries(entries: idl.IDLEntry[]): void;
|
|
17
|
+
readonly files: PeerFile[];
|
|
18
|
+
readonly builderClasses: Map<string, BuilderClass>;
|
|
19
|
+
get buildersToGenerate(): BuilderClass[];
|
|
20
|
+
readonly materializedClasses: Map<string, MaterializedClass>;
|
|
21
|
+
get materializedToGenerate(): MaterializedClass[];
|
|
22
|
+
readonly predefinedDeclarations: idl.IDLInterface[];
|
|
23
|
+
readonly globalScopeInterfaces: idl.IDLInterface[];
|
|
24
|
+
constructor(language: Language);
|
|
25
|
+
name: string;
|
|
26
|
+
readonly customComponentMethods: string[];
|
|
27
|
+
createTypeNameConvertor(language: Language): IdlNameConvertor;
|
|
28
|
+
protected readonly targetNameConvertorInstance: IdlNameConvertor;
|
|
29
|
+
private readonly interopNameConvertorInstance;
|
|
30
|
+
get libraryPrefix(): string;
|
|
31
|
+
createContinuationParameters(continuationType: idl.IDLType): idl.IDLParameter[];
|
|
32
|
+
createContinuationCallbackReference(continuationType: idl.IDLType): idl.IDLReferenceType;
|
|
33
|
+
private context;
|
|
34
|
+
getCurrentContext(): string | undefined;
|
|
35
|
+
setCurrentContext(context: string | undefined): void;
|
|
36
|
+
findFileByOriginalFilename(filename: string): PeerFile | undefined;
|
|
37
|
+
mapType(type: idl.IDLType): string;
|
|
38
|
+
resolveTypeReference(type: idl.IDLReferenceType, pointOfView?: idl.IDLEntry, rootEntries?: idl.IDLEntry[]): idl.IDLEntry | undefined;
|
|
39
|
+
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
40
|
+
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
41
|
+
private customConvertor;
|
|
42
|
+
getInteropName(node: idl.IDLNode): string;
|
|
43
|
+
toDeclaration(type: idl.IDLType | idl.IDLTypedef | idl.IDLCallback | idl.IDLEnum | idl.IDLInterface): idl.IDLEntry | idl.IDLType;
|
|
44
|
+
setFileLayout(strategy: LayoutManagerStrategy): void;
|
|
45
|
+
}
|
|
46
|
+
export declare const ArkInt32: idl.IDLPrimitiveType;
|
|
47
|
+
export declare const ArkInt64: idl.IDLPrimitiveType;
|
|
48
|
+
export declare const ArkFunction: idl.IDLPrimitiveType;
|
|
49
|
+
export declare const ArkLength: idl.IDLPrimitiveType;
|
|
50
|
+
export declare const ArkDate: idl.IDLPrimitiveType;
|
|
51
|
+
export declare const ArkCustomObject: idl.IDLPrimitiveType;
|
|
52
|
+
export declare function cleanPrefix(name: string, prefix: string): string;
|
|
53
|
+
//# sourceMappingURL=PeerLibrary.d.ts.map
|
|
@@ -0,0 +1,340 @@
|
|
|
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 { warn } from 'console';
|
|
16
|
+
import * as idl from '../idl';
|
|
17
|
+
import { Language } from '../Language';
|
|
18
|
+
import { InteropNameConvertor } from '../LanguageWriters';
|
|
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, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
+
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
21
|
+
import { CppInteropConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
22
|
+
import { ETSTypeNameConvertor } from '../LanguageWriters/convertors/ETSConvertors';
|
|
23
|
+
import { JavaTypeNameConvertor } from '../LanguageWriters/convertors/JavaConvertors';
|
|
24
|
+
import { TSTypeNameConvertor } from '../LanguageWriters/convertors/TSConvertors';
|
|
25
|
+
import { generateSyntheticFunctionName, isImportAttr } from './idl/common';
|
|
26
|
+
import { isMaterialized } from './Materialized';
|
|
27
|
+
import { LayoutManager } from './LayoutManager';
|
|
28
|
+
export class PeerLibrary {
|
|
29
|
+
/** @deprecated PeerLibrary should contain only SDK entries */
|
|
30
|
+
get syntheticEntries() {
|
|
31
|
+
return this._syntheticEntries;
|
|
32
|
+
}
|
|
33
|
+
initSyntheticEntries(entries) {
|
|
34
|
+
this._syntheticEntries = entries;
|
|
35
|
+
}
|
|
36
|
+
get buildersToGenerate() {
|
|
37
|
+
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
38
|
+
}
|
|
39
|
+
get materializedToGenerate() {
|
|
40
|
+
return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated);
|
|
41
|
+
}
|
|
42
|
+
constructor(language) {
|
|
43
|
+
this.language = language;
|
|
44
|
+
this.layout = LayoutManager.Empty();
|
|
45
|
+
this._syntheticEntries = [];
|
|
46
|
+
this.files = [];
|
|
47
|
+
this.builderClasses = new Map();
|
|
48
|
+
this.materializedClasses = new Map();
|
|
49
|
+
this.predefinedDeclarations = [];
|
|
50
|
+
this.globalScopeInterfaces = [];
|
|
51
|
+
this.name = "";
|
|
52
|
+
this.customComponentMethods = [];
|
|
53
|
+
this.targetNameConvertorInstance = this.createTypeNameConvertor(this.language);
|
|
54
|
+
this.interopNameConvertorInstance = new InteropNameConvertor(this);
|
|
55
|
+
}
|
|
56
|
+
createTypeNameConvertor(language) {
|
|
57
|
+
switch (language) {
|
|
58
|
+
case Language.TS: return new TSTypeNameConvertor(this);
|
|
59
|
+
case Language.ARKTS: return new ETSTypeNameConvertor(this);
|
|
60
|
+
case Language.JAVA: return new JavaTypeNameConvertor(this);
|
|
61
|
+
case Language.CJ: return new CJTypeNameConvertor(this);
|
|
62
|
+
case Language.CPP: return new CppInteropConvertor(this);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`IdlNameConvertor for ${language} is not implemented`);
|
|
65
|
+
}
|
|
66
|
+
get libraryPrefix() {
|
|
67
|
+
return this.name ? this.name + "_" : "";
|
|
68
|
+
}
|
|
69
|
+
createContinuationParameters(continuationType) {
|
|
70
|
+
const continuationParameters = [];
|
|
71
|
+
if (idl.isContainerType(continuationType) && idl.IDLContainerUtils.isPromise(continuationType)) {
|
|
72
|
+
const errorType = idl.createOptionalType(idl.createContainerType("sequence", [idl.IDLStringType]));
|
|
73
|
+
continuationParameters.push(idl.createParameter("error", errorType, true));
|
|
74
|
+
const promise = continuationType;
|
|
75
|
+
if (!idl.isVoidType(promise.elementType[0])) {
|
|
76
|
+
const valueType = idl.createOptionalType(promise.elementType[0]);
|
|
77
|
+
continuationParameters.unshift(idl.createParameter("value", valueType, true));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (!idl.isVoidType(continuationType))
|
|
81
|
+
continuationParameters.push(idl.createParameter('value', continuationType));
|
|
82
|
+
return continuationParameters;
|
|
83
|
+
}
|
|
84
|
+
createContinuationCallbackReference(continuationType) {
|
|
85
|
+
const continuationParameters = this.createContinuationParameters(continuationType);
|
|
86
|
+
const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType);
|
|
87
|
+
return idl.createReferenceType(syntheticName, undefined, continuationType);
|
|
88
|
+
}
|
|
89
|
+
getCurrentContext() {
|
|
90
|
+
return this.context;
|
|
91
|
+
}
|
|
92
|
+
setCurrentContext(context) {
|
|
93
|
+
this.context = context;
|
|
94
|
+
}
|
|
95
|
+
findFileByOriginalFilename(filename) {
|
|
96
|
+
return this.files.find(it => it.originalFilename === filename);
|
|
97
|
+
}
|
|
98
|
+
mapType(type) {
|
|
99
|
+
return this.targetNameConvertorInstance.convert(type);
|
|
100
|
+
}
|
|
101
|
+
resolveTypeReference(type, pointOfView, rootEntries) {
|
|
102
|
+
const entry = this.syntheticEntries.find(it => it.name === type.name);
|
|
103
|
+
if (entry)
|
|
104
|
+
return entry;
|
|
105
|
+
const qualifiedName = type.name.split(".");
|
|
106
|
+
pointOfView !== null && pointOfView !== void 0 ? pointOfView : (pointOfView = type.namespace);
|
|
107
|
+
let pointOfViewNamespace = !pointOfView || idl.isNamespace(pointOfView)
|
|
108
|
+
? pointOfView
|
|
109
|
+
: pointOfView.namespace;
|
|
110
|
+
rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
|
|
111
|
+
if (1 === qualifiedName.length) {
|
|
112
|
+
const predefined = rootEntries.filter(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Predefined));
|
|
113
|
+
predefined.push(...this.predefinedDeclarations);
|
|
114
|
+
const found = predefined.find(it => it.name === qualifiedName[0]);
|
|
115
|
+
if (found)
|
|
116
|
+
return found;
|
|
117
|
+
}
|
|
118
|
+
let doWork = true;
|
|
119
|
+
while (doWork) {
|
|
120
|
+
doWork = !!pointOfViewNamespace;
|
|
121
|
+
let entries = pointOfViewNamespace
|
|
122
|
+
? [...pointOfViewNamespace.members]
|
|
123
|
+
: [...rootEntries];
|
|
124
|
+
for (let qualifiedNamePart = 0; qualifiedNamePart < qualifiedName.length; ++qualifiedNamePart) {
|
|
125
|
+
const candidates = entries.filter(it => it.name === qualifiedName[qualifiedNamePart]);
|
|
126
|
+
if (!candidates.length)
|
|
127
|
+
break;
|
|
128
|
+
if (qualifiedNamePart === qualifiedName.length - 1) {
|
|
129
|
+
return candidates.length == 1
|
|
130
|
+
? candidates[0]
|
|
131
|
+
: candidates.find(it => !idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Import)); // probably the wrong logic here
|
|
132
|
+
}
|
|
133
|
+
entries = [];
|
|
134
|
+
for (const candidate of candidates) {
|
|
135
|
+
if (idl.isNamespace(candidate))
|
|
136
|
+
entries.push(...candidate.members);
|
|
137
|
+
else if (idl.isEnum(candidate))
|
|
138
|
+
entries.push(...candidate.elements);
|
|
139
|
+
else if (idl.isInterface(candidate))
|
|
140
|
+
entries.push(...candidate.constants, ...candidate.properties, ...candidate.methods);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
pointOfViewNamespace = pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.namespace;
|
|
144
|
+
}
|
|
145
|
+
// TODO: remove the next block after namespaces out of quarantine
|
|
146
|
+
if (!pointOfView) {
|
|
147
|
+
const resolveds = [];
|
|
148
|
+
const traverseNamespaces = (entry) => {
|
|
149
|
+
if (entry && idl.isNamespace(entry) && entry.members.length) {
|
|
150
|
+
//console.log(`Try alien namespace '${idl.getNamespacesPathFor(entry.members[0]).map(obj => obj.name).join(".")}' to resolve name '${type.name}'`)
|
|
151
|
+
const resolved = this.resolveTypeReference(type, entry, rootEntries);
|
|
152
|
+
if (resolved)
|
|
153
|
+
resolveds.push(resolved);
|
|
154
|
+
entry.members.forEach(traverseNamespaces);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
this.files.forEach(file => file.entries.forEach(traverseNamespaces));
|
|
158
|
+
if (resolveds.length)
|
|
159
|
+
console.log(`WARNING: Type reference '${type.name}' is not resolved without own namespace/pointOfView but resolved within some other namespace: '${idl.getNamespacesPathFor(resolveds[0]).map(obj => obj.name).join(".")}'`);
|
|
160
|
+
} // end of block to remove
|
|
161
|
+
return undefined; // empty result
|
|
162
|
+
}
|
|
163
|
+
typeConvertor(param, type, isOptionalParam = false) {
|
|
164
|
+
if (isOptionalParam) {
|
|
165
|
+
return new OptionConvertor(this, param, idl.maybeUnwrapOptionalType(type));
|
|
166
|
+
}
|
|
167
|
+
if (idl.isOptionalType(type)) {
|
|
168
|
+
return new OptionConvertor(this, param, type.type);
|
|
169
|
+
}
|
|
170
|
+
if (idl.isPrimitiveType(type)) {
|
|
171
|
+
switch (type) {
|
|
172
|
+
case idl.IDLI8Type: return new NumericConvertor(param, type);
|
|
173
|
+
case idl.IDLU8Type: return new NumericConvertor(param, type);
|
|
174
|
+
case idl.IDLI16Type: return new NumericConvertor(param, type);
|
|
175
|
+
case idl.IDLU16Type: return new NumericConvertor(param, type);
|
|
176
|
+
case idl.IDLI32Type: return new NumericConvertor(param, type);
|
|
177
|
+
case idl.IDLU32Type: return new NumericConvertor(param, type);
|
|
178
|
+
case idl.IDLI64Type: return new NumericConvertor(param, type);
|
|
179
|
+
case idl.IDLU64Type: return new NumericConvertor(param, type);
|
|
180
|
+
case idl.IDLF16Type: return new NumericConvertor(param, type);
|
|
181
|
+
case idl.IDLF32Type: return new NumericConvertor(param, type);
|
|
182
|
+
case idl.IDLF64Type: return new NumericConvertor(param, type);
|
|
183
|
+
case idl.IDLPointerType: return new PointerConvertor(param);
|
|
184
|
+
case idl.IDLBufferType: return new BufferConvertor(param);
|
|
185
|
+
case idl.IDLBooleanType: return new BooleanConvertor(param);
|
|
186
|
+
case idl.IDLStringType: return new StringConvertor(param);
|
|
187
|
+
case idl.IDLNumberType: return new NumberConvertor(param);
|
|
188
|
+
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
189
|
+
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
190
|
+
case idl.IDLUnknownType:
|
|
191
|
+
case idl.IDLAnyType: return new CustomTypeConvertor(param, "Any");
|
|
192
|
+
default: throw new Error(`Unconverted primitive ${idl.DebugUtils.debugPrintType(type)}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (idl.isReferenceType(type)) {
|
|
196
|
+
if (isImportAttr(type))
|
|
197
|
+
return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
|
|
198
|
+
const decl = this.resolveTypeReference(type);
|
|
199
|
+
return this.declarationConvertor(param, type, decl);
|
|
200
|
+
}
|
|
201
|
+
if (idl.isUnionType(type)) {
|
|
202
|
+
return new UnionConvertor(this, param, type);
|
|
203
|
+
}
|
|
204
|
+
if (idl.isContainerType(type)) {
|
|
205
|
+
if (idl.IDLContainerUtils.isSequence(type))
|
|
206
|
+
return new ArrayConvertor(this, param, type, type.elementType[0]);
|
|
207
|
+
if (idl.IDLContainerUtils.isRecord(type))
|
|
208
|
+
return new MapConvertor(this, param, type, type.elementType[0], type.elementType[1]);
|
|
209
|
+
}
|
|
210
|
+
if (idl.isTypeParameterType(type)) {
|
|
211
|
+
// TODO: unlikely correct.
|
|
212
|
+
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), true);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`Cannot convert: ${type.kind}`);
|
|
215
|
+
}
|
|
216
|
+
declarationConvertor(param, type, declaration) {
|
|
217
|
+
let customConv = this.customConvertor(param, type.name, type);
|
|
218
|
+
if (customConv)
|
|
219
|
+
return customConv;
|
|
220
|
+
if (!declaration)
|
|
221
|
+
return new CustomTypeConvertor(param, this.targetNameConvertorInstance.convert(type), false, this.targetNameConvertorInstance.convert(type)); // assume some predefined type
|
|
222
|
+
const declarationName = declaration.name;
|
|
223
|
+
if (isImportAttr(declaration)) {
|
|
224
|
+
return new ImportTypeConvertor(param, this.targetNameConvertorInstance.convert(type));
|
|
225
|
+
}
|
|
226
|
+
if (idl.isEnum(declaration)) {
|
|
227
|
+
return new EnumConvertor(param, declaration);
|
|
228
|
+
}
|
|
229
|
+
if (idl.isEnumMember(declaration)) {
|
|
230
|
+
return new EnumConvertor(param, declaration.parent);
|
|
231
|
+
}
|
|
232
|
+
if (idl.isCallback(declaration)) {
|
|
233
|
+
return new CallbackConvertor(this, param, declaration);
|
|
234
|
+
}
|
|
235
|
+
if (idl.isTypedef(declaration)) {
|
|
236
|
+
if (isCyclicTypeDef(declaration)) {
|
|
237
|
+
warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
|
|
238
|
+
return new CustomTypeConvertor(param, declaration.name, false, declaration.name);
|
|
239
|
+
}
|
|
240
|
+
return new TypeAliasConvertor(this, param, declaration);
|
|
241
|
+
}
|
|
242
|
+
if (idl.isInterface(declaration)) {
|
|
243
|
+
if (isMaterialized(declaration, this)) {
|
|
244
|
+
return new MaterializedClassConvertor(param, declaration);
|
|
245
|
+
}
|
|
246
|
+
switch (declaration.subkind) {
|
|
247
|
+
case idl.IDLInterfaceSubkind.Interface:
|
|
248
|
+
return new InterfaceConvertor(this, declarationName, param, declaration);
|
|
249
|
+
case idl.IDLInterfaceSubkind.Class:
|
|
250
|
+
return new ClassConvertor(this, declarationName, param, declaration);
|
|
251
|
+
case idl.IDLInterfaceSubkind.AnonymousInterface:
|
|
252
|
+
return new AggregateConvertor(this, param, type, declaration);
|
|
253
|
+
case idl.IDLInterfaceSubkind.Tuple:
|
|
254
|
+
return new TupleConvertor(this, param, type, declaration);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
throw new Error(`Unknown decl ${declarationName} of kind ${declaration.kind}`);
|
|
258
|
+
}
|
|
259
|
+
customConvertor(param, typeName, type) {
|
|
260
|
+
switch (typeName) {
|
|
261
|
+
case `Object`:
|
|
262
|
+
return new CustomTypeConvertor(param, "Object");
|
|
263
|
+
case `Date`:
|
|
264
|
+
return new DateConvertor(param);
|
|
265
|
+
case `Function`:
|
|
266
|
+
return new FunctionConvertor(this, param, type);
|
|
267
|
+
case `Record`:
|
|
268
|
+
return new CustomTypeConvertor(param, "Record", false, "Record<string, string>");
|
|
269
|
+
case `Optional`:
|
|
270
|
+
return new OptionConvertor(this, param, type.typeArguments[0]);
|
|
271
|
+
}
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
getInteropName(node) {
|
|
275
|
+
return this.interopNameConvertorInstance.convert(node);
|
|
276
|
+
}
|
|
277
|
+
toDeclaration(type) {
|
|
278
|
+
switch (type) {
|
|
279
|
+
case idl.IDLAnyType: return ArkCustomObject;
|
|
280
|
+
case idl.IDLVoidType: return idl.IDLVoidType;
|
|
281
|
+
case idl.IDLUndefinedType: return idl.IDLUndefinedType;
|
|
282
|
+
case idl.IDLUnknownType: return ArkCustomObject;
|
|
283
|
+
case idl.IDLObjectType: return ArkCustomObject;
|
|
284
|
+
}
|
|
285
|
+
const typeName = idl.isNamedNode(type) ? type.name : undefined;
|
|
286
|
+
switch (typeName) {
|
|
287
|
+
case "object":
|
|
288
|
+
case "Object": return ArkCustomObject;
|
|
289
|
+
}
|
|
290
|
+
if (isImportAttr(type)) {
|
|
291
|
+
return ArkCustomObject;
|
|
292
|
+
}
|
|
293
|
+
if (idl.isReferenceType(type)) {
|
|
294
|
+
// TODO: remove all this!
|
|
295
|
+
if (type.name === 'Dimension' || type.name === 'Length') {
|
|
296
|
+
return ArkLength;
|
|
297
|
+
}
|
|
298
|
+
if (type.name === 'Date') {
|
|
299
|
+
return ArkDate;
|
|
300
|
+
}
|
|
301
|
+
if (type.name === 'AnimationRange' || type.name === 'ContentModifier') {
|
|
302
|
+
return ArkCustomObject;
|
|
303
|
+
}
|
|
304
|
+
if (type.name === 'Function') {
|
|
305
|
+
return ArkFunction;
|
|
306
|
+
}
|
|
307
|
+
if (type.name === 'Optional') {
|
|
308
|
+
return this.toDeclaration(type.typeArguments[0]);
|
|
309
|
+
}
|
|
310
|
+
const decl = this.resolveTypeReference(type);
|
|
311
|
+
if (!decl) {
|
|
312
|
+
warn(`undeclared type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
313
|
+
}
|
|
314
|
+
if (decl && idl.isTypedef(decl) && isCyclicTypeDef(decl)) {
|
|
315
|
+
warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
|
|
316
|
+
return ArkCustomObject;
|
|
317
|
+
}
|
|
318
|
+
return !decl ? ArkCustomObject // assume some builtin type
|
|
319
|
+
: idl.isTypedef(decl) ? this.toDeclaration(decl.type)
|
|
320
|
+
: decl;
|
|
321
|
+
}
|
|
322
|
+
return type;
|
|
323
|
+
}
|
|
324
|
+
setFileLayout(strategy) {
|
|
325
|
+
this.layout = new LayoutManager(strategy);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
export const ArkInt32 = idl.IDLI32Type;
|
|
329
|
+
export const ArkInt64 = idl.IDLI64Type;
|
|
330
|
+
export const ArkFunction = idl.IDLFunctionType;
|
|
331
|
+
export const ArkLength = idl.IDLLengthType;
|
|
332
|
+
export const ArkDate = idl.IDLDate;
|
|
333
|
+
export const ArkCustomObject = idl.IDLCustomObjectType;
|
|
334
|
+
export function cleanPrefix(name, prefix) {
|
|
335
|
+
return name.replace(prefix, "");
|
|
336
|
+
}
|
|
337
|
+
function isCyclicTypeDef(decl) {
|
|
338
|
+
return idl.isReferenceType(decl.type) && idl.isNamedNode(decl.type) && decl.type.name == decl.name;
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=PeerLibrary.js.map
|
|
@@ -16,6 +16,7 @@ export declare class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
|
16
16
|
static readonly I: TSFeatureNameConvertor;
|
|
17
17
|
}
|
|
18
18
|
export declare class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
19
|
+
convertInterface(decl: idl.IDLInterface): string;
|
|
19
20
|
convertEnum(decl: idl.IDLEnum): string;
|
|
20
21
|
static readonly I: ETSDeclarationNameConvertor;
|
|
21
22
|
}
|
|
@@ -46,6 +46,9 @@ export class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
|
46
46
|
}
|
|
47
47
|
TSFeatureNameConvertor.I = new TSFeatureNameConvertor();
|
|
48
48
|
export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
49
|
+
convertInterface(decl) {
|
|
50
|
+
return idl.getFQName(decl);
|
|
51
|
+
}
|
|
49
52
|
convertEnum(decl) {
|
|
50
53
|
const namespace = idl.getNamespacesPathFor(decl).map(it => it.name).join('_');
|
|
51
54
|
return `${namespace ? `${namespace}_` : ``}${decl.name}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.19",
|
|
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": "
|
|
37
|
+
"@koalaui/interop": "1.4.6",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|
package/webidl2.js/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014 Robin Berjon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|