@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-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/Language.js +1 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +16 -6
- package/build/lib/src/LanguageWriters/ArgConvertors.js +80 -92
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +8 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +35 -22
- package/build/lib/src/LanguageWriters/common.d.ts +1 -0
- package/build/lib/src/LanguageWriters/common.js +2 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +7 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +53 -15
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +26 -14
- package/build/lib/src/LanguageWriters/index.d.ts +4 -3
- package/build/lib/src/LanguageWriters/index.js +9 -11
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -22
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +34 -113
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -9
- package/build/lib/src/config.d.ts +2 -1461
- package/build/lib/src/config.js +16 -32
- package/build/lib/src/configMerge.d.ts +3 -0
- package/build/lib/src/configMerge.js +63 -0
- package/build/lib/src/diagnostictypes.d.ts +1 -5
- package/build/lib/src/diagnostictypes.js +1 -27
- package/build/lib/src/from-idl/DtsPrinter.js +12 -5
- package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
- package/build/lib/src/from-idl/IDLLinter.js +30 -32
- package/build/lib/src/from-idl/deserialize.d.ts +3 -4
- package/build/lib/src/from-idl/deserialize.js +29 -641
- package/build/lib/src/from-idl/parser.d.ts +20 -2
- package/build/lib/src/from-idl/parser.js +97 -29
- package/build/lib/src/idl/builders.d.ts +43 -0
- package/build/lib/src/idl/builders.js +135 -0
- package/build/lib/src/idl/discriminators.d.ts +53 -0
- package/build/lib/src/idl/discriminators.js +232 -0
- package/build/lib/src/idl/dump.d.ts +48 -0
- package/build/lib/src/idl/dump.js +327 -0
- package/build/lib/src/idl/index.d.ts +9 -0
- package/build/lib/src/idl/index.js +23 -0
- package/build/lib/src/idl/keywords.d.ts +2 -0
- package/build/lib/src/{options.js → idl/keywords.js} +7 -3
- package/build/lib/src/idl/node.d.ts +233 -0
- package/build/lib/src/idl/node.js +103 -0
- package/build/lib/src/idl/stdlib.d.ts +34 -0
- package/build/lib/src/idl/stdlib.js +54 -0
- package/build/lib/src/idl/utils.d.ts +44 -0
- package/build/lib/src/idl/utils.js +215 -0
- package/build/lib/src/idl/visitors.d.ts +15 -0
- package/build/lib/src/idl/visitors.js +593 -0
- package/build/lib/src/index.d.ts +4 -2
- package/build/lib/src/index.js +5 -3
- package/build/lib/src/inputPaths.d.ts +11 -0
- package/build/lib/src/inputPaths.js +81 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
- package/build/lib/src/languageSpecificKeywords.js +0 -5
- package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +8 -2
- package/build/lib/src/peer-generation/Materialized.js +24 -12
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -15
- package/build/lib/src/peer-generation/PeerLibrary.js +35 -215
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
- package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
- package/build/lib/src/peer-generation/idl/common.js +7 -7
- package/build/lib/src/peer-generation/isMaterialized.js +2 -3
- package/build/lib/src/peer-generation/modules.js +2 -0
- package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
- package/build/lib/src/peer-generation/toDeclaration.js +53 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +15 -7
- package/build/lib/src/resolveNamedNode.d.ts +1 -0
- package/build/lib/src/resolveNamedNode.js +7 -0
- package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
- package/build/lib/src/transformers/FqnTransformer.js +20 -12
- package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
- package/build/lib/src/transformers/GenericTransformer.js +252 -158
- package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
- package/build/lib/src/transformers/IdlTransformer.js +7 -0
- package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
- package/build/lib/src/transformers/NullTransformer.js +27 -21
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
- package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
- package/build/lib/src/util.d.ts +5 -0
- package/build/lib/src/util.js +25 -0
- package/package.json +6 -7
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -85
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -306
- package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
- package/build/lib/src/from-idl/webidl2-utils.js +0 -87
- package/build/lib/src/idl.d.ts +0 -444
- package/build/lib/src/idl.js +0 -1385
- package/build/lib/src/idlize.d.ts +0 -25
- package/build/lib/src/idlize.js +0 -198
- package/build/lib/src/options.d.ts +0 -13
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
- package/build/lib/src/peer-generation/BuilderClass.js +0 -68
- package/webidl2.js/dist/webidl2.js +0 -4622
- package/webidl2.js/package.json +0 -55
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type InputPaths = {
|
|
2
|
+
baseDirs: string[];
|
|
3
|
+
inputDirs: string[];
|
|
4
|
+
auxInputDirs: string[];
|
|
5
|
+
inputFiles: string[];
|
|
6
|
+
auxInputFiles: string[];
|
|
7
|
+
libraryPackages: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare function formatInputPaths(options: any): InputPaths;
|
|
10
|
+
export declare function validatePaths(paths: string[], type: 'file' | 'dir'): void;
|
|
11
|
+
//# sourceMappingURL=inputPaths.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
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 * as fs from "fs";
|
|
16
|
+
import * as path from "path";
|
|
17
|
+
function processInputOption(option) {
|
|
18
|
+
if (typeof option === 'undefined') {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
else if (typeof option === 'string') {
|
|
22
|
+
return option.split(',')
|
|
23
|
+
.map(item => item.trim())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return option.flatMap(processInputOption);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// iterate through files in the same order even if input order changes
|
|
31
|
+
function sortFiles(files) {
|
|
32
|
+
return files.sort((a, b) => path.basename(a).localeCompare(path.basename(b)));
|
|
33
|
+
}
|
|
34
|
+
export function formatInputPaths(options) {
|
|
35
|
+
if (options.inputFiles) {
|
|
36
|
+
options.inputFiles = processInputOption(options.inputFiles);
|
|
37
|
+
}
|
|
38
|
+
if (options.auxInputFiles) {
|
|
39
|
+
options.auxInputFiles = processInputOption(options.auxInputFiles);
|
|
40
|
+
}
|
|
41
|
+
if (options.inputDir) {
|
|
42
|
+
options.inputDir = processInputOption(options.inputDir);
|
|
43
|
+
}
|
|
44
|
+
if (options.auxInputDir) {
|
|
45
|
+
options.auxInputDir = processInputOption(options.auxInputDir);
|
|
46
|
+
}
|
|
47
|
+
if (options.libraryPackages) {
|
|
48
|
+
options.libraryPackages = processInputOption(options.libraryPackages);
|
|
49
|
+
}
|
|
50
|
+
const inputDirs = options.inputDir || [];
|
|
51
|
+
const auxInputDirs = options.auxInputDir || [];
|
|
52
|
+
const inputFiles = options.inputFiles || [];
|
|
53
|
+
const auxInputFiles = options.auxInputFiles || [];
|
|
54
|
+
const libraryPackages = options.libraryPackages || [];
|
|
55
|
+
let baseDirs = options.baseDir ? processInputOption(options.baseDir) : inputDirs;
|
|
56
|
+
if (!baseDirs.length && inputFiles.length) {
|
|
57
|
+
baseDirs = [...(new Set(options.inputFiles.map((it) => path.dirname(it))).values())];
|
|
58
|
+
}
|
|
59
|
+
if (!baseDirs.length)
|
|
60
|
+
throw new Error("Check your --base-dir parameter, value is missing");
|
|
61
|
+
return {
|
|
62
|
+
baseDirs,
|
|
63
|
+
inputDirs,
|
|
64
|
+
auxInputDirs,
|
|
65
|
+
inputFiles: sortFiles(inputFiles),
|
|
66
|
+
auxInputFiles: sortFiles(auxInputFiles),
|
|
67
|
+
libraryPackages
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function validatePaths(paths, type) {
|
|
71
|
+
paths.forEach(pathItem => {
|
|
72
|
+
if (!fs.existsSync(pathItem)) {
|
|
73
|
+
console.error(`Input ${type} does not exist: ${pathItem}`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(`Input ${type} exists: ${pathItem}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=inputPaths.js.map
|
|
@@ -40,11 +40,6 @@ export const CJKeywords = new Set([
|
|
|
40
40
|
'open', 'operator', 'foreign', 'inout',
|
|
41
41
|
'prop', 'mut', 'unsafe', 'get', 'set', 'type'
|
|
42
42
|
]);
|
|
43
|
-
export const IDLKeywords = new Set([
|
|
44
|
-
"attribute", "callback", "object", "toString",
|
|
45
|
-
'sequence', 'record', 'or', 'Int8Array',
|
|
46
|
-
'interface', 'number', 'undefined'
|
|
47
|
-
]);
|
|
48
43
|
export const TSKeywords = new Set([
|
|
49
44
|
"namespace"
|
|
50
45
|
]);
|
|
@@ -6,7 +6,7 @@ export declare enum LayoutNodeRole {
|
|
|
6
6
|
COMPONENT = 3,
|
|
7
7
|
SERIALIZER = 4
|
|
8
8
|
}
|
|
9
|
-
export type LayoutTargetDescriptionHint = 'component.implementation' | 'component.interface' | 'component.function' | 'component.modifier';
|
|
9
|
+
export type LayoutTargetDescriptionHint = 'component.implementation' | 'component.interface' | 'component.function' | 'component.modifier' | 'component.handwritten';
|
|
10
10
|
export interface LayoutTargetDescription {
|
|
11
11
|
node: IDLEntry;
|
|
12
12
|
role: LayoutNodeRole;
|
|
@@ -11,8 +11,14 @@ export declare class MaterializedField {
|
|
|
11
11
|
isNullableOriginalTypeField?: boolean | undefined;
|
|
12
12
|
extraMethodName: string | undefined;
|
|
13
13
|
constructor(field: Field, argConvertor: ArgConvertor, outArgConvertor?: ArgConvertor | undefined, isNullableOriginalTypeField?: boolean | undefined, extraMethodName?: string | undefined);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
get state(): {
|
|
15
|
+
isAccessor: true;
|
|
16
|
+
hasGetter: boolean;
|
|
17
|
+
hasSetter: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
isAccessor: false;
|
|
20
|
+
isReadonly: boolean;
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
23
|
export declare class MaterializedMethod extends PeerMethod {
|
|
18
24
|
decl: idl.IDLConstructor | idl.IDLMethod | undefined;
|
|
@@ -24,19 +24,31 @@ export class MaterializedField {
|
|
|
24
24
|
this.outArgConvertor = outArgConvertor;
|
|
25
25
|
this.isNullableOriginalTypeField = isNullableOriginalTypeField;
|
|
26
26
|
this.extraMethodName = extraMethodName;
|
|
27
|
+
const isReadonly = field.modifiers.includes(FieldModifier.READONLY);
|
|
28
|
+
const isGetter = field.modifiers.includes(FieldModifier.GET);
|
|
29
|
+
const isSetter = field.modifiers.includes(FieldModifier.SET);
|
|
30
|
+
if (isReadonly && (isGetter || isSetter))
|
|
31
|
+
throw new Error(`Unsupported modifiers combination: field can be either readonly or getter/setter or mutable for field ${field.name}`);
|
|
32
|
+
if (isSetter && !isGetter)
|
|
33
|
+
throw new Error(`Unsupported modifiers combination: if setter is defined getter must be defined too for field ${field.name}`);
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
get state() {
|
|
36
|
+
const hasGetter = this.field.modifiers.includes(FieldModifier.GET);
|
|
37
|
+
const hasSetter = this.field.modifiers.includes(FieldModifier.SET);
|
|
38
|
+
if (hasGetter || hasSetter) {
|
|
39
|
+
return {
|
|
40
|
+
isAccessor: true,
|
|
41
|
+
hasGetter,
|
|
42
|
+
hasSetter
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const isReadonly = this.field.modifiers.includes(FieldModifier.READONLY);
|
|
47
|
+
return {
|
|
48
|
+
isAccessor: false,
|
|
49
|
+
isReadonly
|
|
50
|
+
};
|
|
51
|
+
}
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
export class MaterializedMethod extends PeerMethod {
|
|
@@ -4,11 +4,11 @@ import { LanguageWriter } from '../LanguageWriters/LanguageWriter';
|
|
|
4
4
|
import { IdlNameConvertor } from '../LanguageWriters';
|
|
5
5
|
import { ArgConvertor } from "../LanguageWriters/ArgConvertors";
|
|
6
6
|
import { LibraryInterface } from '../LibraryInterface';
|
|
7
|
-
import { BuilderClass } from './BuilderClass';
|
|
8
7
|
import { MaterializedClass } from './Materialized';
|
|
9
8
|
import { LayoutManager, LayoutManagerStrategy } from './LayoutManager';
|
|
10
9
|
import { IDLLibrary } from '../library';
|
|
11
10
|
import { NativeModuleType } from '../LanguageWriters/common';
|
|
11
|
+
import { ReferenceResolver } from './ReferenceResolver';
|
|
12
12
|
export interface GlobalScopeDeclarations {
|
|
13
13
|
methods: idl.IDLMethod[];
|
|
14
14
|
constants: idl.IDLConstant[];
|
|
@@ -10259,13 +10259,11 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10259
10259
|
asIDLLibrary(): IDLLibrary;
|
|
10260
10260
|
get globals(): GlobalScopeDeclarations[];
|
|
10261
10261
|
layout: LayoutManager;
|
|
10262
|
-
private
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
readonly files: idl.IDLFile[];
|
|
10262
|
+
private _files;
|
|
10263
|
+
get files(): idl.IDLFile[];
|
|
10264
|
+
set files(value: idl.IDLFile[]);
|
|
10266
10265
|
readonly auxFiles: idl.IDLFile[];
|
|
10267
|
-
|
|
10268
|
-
get buildersToGenerate(): BuilderClass[];
|
|
10266
|
+
private resolver;
|
|
10269
10267
|
readonly materializedClasses: Map<string, MaterializedClass>;
|
|
10270
10268
|
get orderedMaterialized(): MaterializedClass[];
|
|
10271
10269
|
constructor(language: Language, interopNativeModule: NativeModuleType, useMemoM3?: boolean);
|
|
@@ -10281,14 +10279,10 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10281
10279
|
setCurrentContext(context: string | undefined): void;
|
|
10282
10280
|
findFileByOriginalFilename(filename: string): idl.IDLFile | undefined;
|
|
10283
10281
|
mapType(type: idl.IDLType): string;
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
private _useFallback;
|
|
10289
|
-
disableFallback(): void;
|
|
10290
|
-
resolveNamedNode(target: string[], pov?: idl.IDLNode | undefined): idl.IDLEntry | undefined;
|
|
10291
|
-
resolveImport(target: idl.IDLImport): idl.IDLEntry | undefined;
|
|
10282
|
+
resolveTypeReference(type: idl.IDLReferenceType, options?: {
|
|
10283
|
+
terminalImports?: boolean;
|
|
10284
|
+
unresolvedOk?: boolean;
|
|
10285
|
+
}): idl.IDLEntry | undefined;
|
|
10292
10286
|
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
10293
10287
|
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
10294
10288
|
private customConvertor;
|
|
@@ -10302,4 +10296,5 @@ export declare const ArkFunction: idl.IDLPrimitiveType;
|
|
|
10302
10296
|
export declare const ArkDate: idl.IDLPrimitiveType;
|
|
10303
10297
|
export declare const ArkCustomObject: idl.IDLPrimitiveType;
|
|
10304
10298
|
export declare function cleanPrefix(name: string, prefix: string): string;
|
|
10299
|
+
export declare function forceTypedefAsResource(resolver: ReferenceResolver, type: idl.IDLType, decl: idl.IDLTypedef): boolean;
|
|
10305
10300
|
//# sourceMappingURL=PeerLibrary.d.ts.map
|
|
@@ -14,24 +14,24 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { warn } from 'console';
|
|
16
16
|
import * as idl from '../idl';
|
|
17
|
-
import { resolveNamedNode } from '../resolveNamedNode';
|
|
18
17
|
import { Language } from '../Language';
|
|
19
18
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
20
|
-
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor,
|
|
19
|
+
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, TransformOnSerializeConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
+
import { StructureNameConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
21
21
|
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
22
22
|
import { CppConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
23
23
|
import { ETSTypeNameConvertor } from '../LanguageWriters/convertors/ETSConvertors';
|
|
24
24
|
import { TSTypeNameConvertor } from '../LanguageWriters/convertors/TSConvertors';
|
|
25
|
-
import { isBuilderClass } from './BuilderClass';
|
|
26
25
|
import { generateSyntheticFunctionName, isImportAttr } from './idl/common';
|
|
27
26
|
import { LayoutManager } from './LayoutManager';
|
|
28
27
|
import { lib, query } from '../library';
|
|
29
28
|
import { isMaterialized } from './isMaterialized';
|
|
30
|
-
import { isInIdlizeInternal } from '../idl';
|
|
31
29
|
import { isInCurrentModule } from './modules';
|
|
32
30
|
import { generatorConfiguration } from '../config';
|
|
33
31
|
import { KotlinTypeNameConvertor } from '../LanguageWriters/convertors/KotlinConvertors';
|
|
34
32
|
import { toIdlType } from '../from-idl/deserialize';
|
|
33
|
+
import { createCachedReferenceResolver } from './ReferenceResolver';
|
|
34
|
+
import { toDeclaration } from './toDeclaration';
|
|
35
35
|
export const lenses = {
|
|
36
36
|
globals: lib.lens(lib.select.files())
|
|
37
37
|
.pipe(lib.select.nodes())
|
|
@@ -77,14 +77,12 @@ export class PeerLibrary {
|
|
|
77
77
|
get globals() {
|
|
78
78
|
return query(this.asIDLLibrary(), lenses.globals);
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
this.
|
|
80
|
+
get files() {
|
|
81
|
+
return this._files;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
get buildersToGenerate() {
|
|
87
|
-
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
83
|
+
set files(value) {
|
|
84
|
+
this._files = value;
|
|
85
|
+
this.resolver = createCachedReferenceResolver(value);
|
|
88
86
|
}
|
|
89
87
|
get orderedMaterialized() {
|
|
90
88
|
function accessorName(decl) {
|
|
@@ -98,14 +96,12 @@ export class PeerLibrary {
|
|
|
98
96
|
this.interopNativeModule = interopNativeModule;
|
|
99
97
|
this.useMemoM3 = useMemoM3;
|
|
100
98
|
this.layout = LayoutManager.Empty();
|
|
101
|
-
this.
|
|
102
|
-
this.files = [];
|
|
99
|
+
this._files = [];
|
|
103
100
|
this.auxFiles = [];
|
|
104
|
-
this.
|
|
101
|
+
this.resolver = createCachedReferenceResolver([]);
|
|
105
102
|
this.materializedClasses = new Map();
|
|
106
103
|
this.name = "";
|
|
107
104
|
this.customComponentMethods = [];
|
|
108
|
-
this._useFallback = true;
|
|
109
105
|
}
|
|
110
106
|
createLanguageWriter(language) {
|
|
111
107
|
return createLanguageWriter(language !== null && language !== void 0 ? language : this.language, this);
|
|
@@ -140,8 +136,11 @@ export class PeerLibrary {
|
|
|
140
136
|
}
|
|
141
137
|
createContinuationCallbackReference(continuationType) {
|
|
142
138
|
const continuationParameters = this.createContinuationParameters(continuationType);
|
|
143
|
-
const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType);
|
|
144
|
-
|
|
139
|
+
const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType, { nameConvertor: new StructureNameConvertor(this) });
|
|
140
|
+
const primaryReference = idl.createReferenceType(`synthetic.${syntheticName}`);
|
|
141
|
+
if (this.resolveTypeReference(primaryReference, { unresolvedOk: true }))
|
|
142
|
+
return primaryReference;
|
|
143
|
+
return idl.createReferenceType(`synthetic.synthetic_${syntheticName}`);
|
|
145
144
|
}
|
|
146
145
|
getCurrentContext() {
|
|
147
146
|
return this.context;
|
|
@@ -155,124 +154,8 @@ export class PeerLibrary {
|
|
|
155
154
|
mapType(type) {
|
|
156
155
|
return this.createTypeNameConvertor(this.language).convert(type);
|
|
157
156
|
}
|
|
158
|
-
|
|
159
|
-
this.
|
|
160
|
-
}
|
|
161
|
-
resolveTypeReference(type, singleStep) {
|
|
162
|
-
var _a, _b;
|
|
163
|
-
const key = type.parent ? type : type.name; // does entry have resolve context or just FQN
|
|
164
|
-
let result = ((_a = this.referenceCache) === null || _a === void 0 ? void 0 : _a.has(key))
|
|
165
|
-
? this.referenceCache.get(key)
|
|
166
|
-
: this.resolveTypeReferenceUncached(type, singleStep);
|
|
167
|
-
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(key, result);
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
|
-
resolveTypeReferenceUncached(type, singleStep) {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
if ((_a = this.referenceCache) === null || _a === void 0 ? void 0 : _a.has(type))
|
|
173
|
-
return this.referenceCache.get(type);
|
|
174
|
-
let result = this.resolveNamedNode(type.name.split("."), type.parent);
|
|
175
|
-
if (!singleStep) {
|
|
176
|
-
const seen = new Set;
|
|
177
|
-
while (result) {
|
|
178
|
-
let nextResult = undefined;
|
|
179
|
-
if (idl.isImport(result))
|
|
180
|
-
nextResult = this.resolveImport(result);
|
|
181
|
-
else if (idl.isReferenceType(result))
|
|
182
|
-
nextResult = this.resolveNamedNode(result.name.split("."));
|
|
183
|
-
else if (idl.isTypedef(result) && idl.isReferenceType(result.type))
|
|
184
|
-
nextResult = this.resolveNamedNode(result.type.name.split("."));
|
|
185
|
-
if (!nextResult)
|
|
186
|
-
break;
|
|
187
|
-
if (seen.has(nextResult)) {
|
|
188
|
-
console.warn(`Cyclic referenceType: ${type.name}, seen: [${[...seen.values()].map(idl.getFQName).join(", ")}]`);
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
seen.add(nextResult);
|
|
192
|
-
result = nextResult;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (result && (idl.isImport(result) || idl.isNamespace(result)))
|
|
196
|
-
result = undefined;
|
|
197
|
-
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
disableFallback() {
|
|
201
|
-
this._useFallback = false;
|
|
202
|
-
}
|
|
203
|
-
resolveNamedNode(target, pov = undefined) {
|
|
204
|
-
const qualifiedName = target.join(".");
|
|
205
|
-
const entry = this._syntheticFile.entries.find(it => it.name === qualifiedName);
|
|
206
|
-
if (entry)
|
|
207
|
-
return entry;
|
|
208
|
-
if (1 === target.length) {
|
|
209
|
-
const predefined = this.files.flatMap(it => it.entries).filter(isInIdlizeInternal);
|
|
210
|
-
const found = predefined.find(it => it.name === target.at(-1));
|
|
211
|
-
if (found)
|
|
212
|
-
return found;
|
|
213
|
-
}
|
|
214
|
-
const corpus = this.files.concat(this.auxFiles);
|
|
215
|
-
let result = resolveNamedNode(target, pov, corpus);
|
|
216
|
-
if (result && idl.isEntry(result))
|
|
217
|
-
return result;
|
|
218
|
-
if (1 == target.length) {
|
|
219
|
-
const stdScopes = generatorConfiguration().globalPackages.map(it => it.split('.'));
|
|
220
|
-
for (const stdScope of stdScopes) {
|
|
221
|
-
result = resolveNamedNode([...stdScope, ...target], undefined, corpus);
|
|
222
|
-
if (result && idl.isEntry(result))
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
// TODO: remove the next block after namespaces out of quarantine
|
|
227
|
-
if (this._useFallback) {
|
|
228
|
-
const povAsReadableString = pov
|
|
229
|
-
? `'${idl.getFQName(pov)}'`
|
|
230
|
-
: "[root]";
|
|
231
|
-
// retry from root
|
|
232
|
-
pov = undefined;
|
|
233
|
-
const resolveds = [];
|
|
234
|
-
for (let file of this.files) {
|
|
235
|
-
result = resolveNamedNode([...file.packageClause, ...target], pov, corpus);
|
|
236
|
-
if (result && idl.isEntry(result)) {
|
|
237
|
-
// too much spam
|
|
238
|
-
// console.warn(`WARNING: Type reference '${qualifiedName}' is not resolved from ${povAsReadableString} but resolved from some package '${file.packageClause().join(".")}'`)
|
|
239
|
-
resolveds.push(result);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
// and from each namespace
|
|
243
|
-
const traverseNamespaces = (entry) => {
|
|
244
|
-
if (entry && idl.isNamespace(entry) && entry.members.length) {
|
|
245
|
-
const resolved = resolveNamedNode([...idl.getNamespacesPathFor(entry).map(it => it.name), ...target], pov, corpus);
|
|
246
|
-
if (resolved) {
|
|
247
|
-
console.warn(`WARNING: Name '${qualifiedName}' is not resolved from ${povAsReadableString} but resolved from some namespace: '${idl.getNamespacesPathFor(resolved).map(obj => obj.name).join(".")}'`);
|
|
248
|
-
resolveds.push(resolved);
|
|
249
|
-
}
|
|
250
|
-
entry.members.forEach(traverseNamespaces);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
this.files.forEach(file => file.entries.forEach(traverseNamespaces));
|
|
254
|
-
for (const resolved of resolveds)
|
|
255
|
-
if (idl.isEntry(resolved))
|
|
256
|
-
return resolved;
|
|
257
|
-
} // end of block to remove
|
|
258
|
-
return undefined;
|
|
259
|
-
}
|
|
260
|
-
resolveImport(target) {
|
|
261
|
-
let result = this.resolveNamedNode(target.clause);
|
|
262
|
-
if (result) {
|
|
263
|
-
if (idl.isReferenceType(result))
|
|
264
|
-
return this.resolveTypeReference(result);
|
|
265
|
-
if (idl.isImport(result)) {
|
|
266
|
-
if (result == target) {
|
|
267
|
-
console.log("Self-targeted Import?");
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
return this.resolveImport(result);
|
|
271
|
-
}
|
|
272
|
-
if (idl.isEntry(result))
|
|
273
|
-
return result;
|
|
274
|
-
}
|
|
275
|
-
return undefined;
|
|
157
|
+
resolveTypeReference(type, options) {
|
|
158
|
+
return this.resolver.resolveTypeReference(type, options);
|
|
276
159
|
}
|
|
277
160
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
278
161
|
if (isOptionalParam) {
|
|
@@ -362,17 +245,11 @@ export class PeerLibrary {
|
|
|
362
245
|
return new ImportTypeConvertor(param, this.createTypeNameConvertor(this.language).convert(type));
|
|
363
246
|
}
|
|
364
247
|
if (idl.isImport(declaration)) {
|
|
365
|
-
|
|
366
|
-
if (target && idl.isEntry(target))
|
|
367
|
-
return this.declarationConvertor(param, type, target);
|
|
368
|
-
else {
|
|
369
|
-
warn(`Unable to resolve Import ${declaration.clause.join(".")} as ${declaration.name}`);
|
|
370
|
-
return new CustomTypeConvertor(param, declaration.name, false, declaration.name);
|
|
371
|
-
}
|
|
248
|
+
throw new Error(`Unexpected declaration ${declaration.kind}`);
|
|
372
249
|
}
|
|
373
250
|
if (idl.hasExtAttribute(declaration, idl.IDLExtendedAttributes.TransformOnSerialize)) {
|
|
374
|
-
const
|
|
375
|
-
return new TransformOnSerializeConvertor(param, this, declaration,
|
|
251
|
+
const targetType = toIdlType("", idl.getExtAttribute(declaration, idl.IDLExtendedAttributes.TransformOnSerialize));
|
|
252
|
+
return new TransformOnSerializeConvertor(param, this, declaration, targetType);
|
|
376
253
|
}
|
|
377
254
|
if (idl.isEnum(declaration)) {
|
|
378
255
|
return new EnumConvertor(param, declaration);
|
|
@@ -384,17 +261,17 @@ export class PeerLibrary {
|
|
|
384
261
|
return new CallbackConvertor(this, param, declaration, this.interopNativeModule);
|
|
385
262
|
}
|
|
386
263
|
if (idl.isTypedef(declaration)) {
|
|
387
|
-
if (forceTypedefAsResource(type, declaration))
|
|
264
|
+
if (forceTypedefAsResource(this, type, declaration))
|
|
388
265
|
return new ObjectConvertor(param, type);
|
|
389
266
|
return new TypeAliasConvertor(this, param, declaration);
|
|
390
267
|
}
|
|
391
268
|
if (idl.isInterface(declaration)) {
|
|
269
|
+
if (generatorConfiguration().forceResource.includes(declaration.name)) {
|
|
270
|
+
return new ObjectConvertor(param, type);
|
|
271
|
+
}
|
|
392
272
|
if (isMaterialized(declaration, this)) {
|
|
393
273
|
return new MaterializedClassConvertor(this, param, declaration);
|
|
394
274
|
}
|
|
395
|
-
if (isBuilderClass(declaration)) {
|
|
396
|
-
return new ClassConvertor(this, declarationName, param, declaration);
|
|
397
|
-
}
|
|
398
275
|
switch (declaration.subkind) {
|
|
399
276
|
case idl.IDLInterfaceSubkind.Interface:
|
|
400
277
|
case idl.IDLInterfaceSubkind.Class:
|
|
@@ -424,51 +301,7 @@ export class PeerLibrary {
|
|
|
424
301
|
return undefined;
|
|
425
302
|
}
|
|
426
303
|
toDeclaration(type) {
|
|
427
|
-
|
|
428
|
-
case idl.IDLAnyType: return ArkCustomObject;
|
|
429
|
-
case idl.IDLVoidType: return idl.IDLVoidType;
|
|
430
|
-
case idl.IDLUndefinedType: return idl.IDLUndefinedType;
|
|
431
|
-
case idl.IDLUnknownType: return ArkCustomObject;
|
|
432
|
-
// case idl.IDLObjectType: return ArkCustomObject
|
|
433
|
-
}
|
|
434
|
-
const typeName = idl.isNamedNode(type) ? type.name : undefined;
|
|
435
|
-
switch (typeName) {
|
|
436
|
-
case "object":
|
|
437
|
-
case "Object": return idl.IDLObjectType;
|
|
438
|
-
}
|
|
439
|
-
if (idl.isReferenceType(type)) {
|
|
440
|
-
// TODO: remove all this!
|
|
441
|
-
if (type.name === 'Date') {
|
|
442
|
-
return ArkDate;
|
|
443
|
-
}
|
|
444
|
-
if (type.name === 'AnimationRange') {
|
|
445
|
-
return ArkCustomObject;
|
|
446
|
-
}
|
|
447
|
-
if (type.name === 'Function') {
|
|
448
|
-
return ArkFunction;
|
|
449
|
-
}
|
|
450
|
-
if (type.name === 'Optional') {
|
|
451
|
-
return this.toDeclaration(type.typeArguments[0]);
|
|
452
|
-
}
|
|
453
|
-
const decl = this.resolveTypeReference(type);
|
|
454
|
-
if (!decl) {
|
|
455
|
-
warn(`undeclared type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
456
|
-
}
|
|
457
|
-
if (decl && idl.isTypedef(decl) && forceTypedefAsResource(type, decl)) {
|
|
458
|
-
return idl.IDLObjectType;
|
|
459
|
-
}
|
|
460
|
-
if (decl && idl.hasExtAttribute(decl, idl.IDLExtendedAttributes.TransformOnSerialize)) {
|
|
461
|
-
const type = toIdlType("", idl.getExtAttribute(decl, idl.IDLExtendedAttributes.TransformOnSerialize));
|
|
462
|
-
return this.toDeclaration(type);
|
|
463
|
-
}
|
|
464
|
-
return !decl ? ArkCustomObject // assume some builtin type
|
|
465
|
-
: idl.isTypedef(decl) ? this.toDeclaration(decl.type)
|
|
466
|
-
: decl;
|
|
467
|
-
}
|
|
468
|
-
if (isImportAttr(type)) {
|
|
469
|
-
return ArkCustomObject;
|
|
470
|
-
}
|
|
471
|
-
return type;
|
|
304
|
+
return toDeclaration(type, this);
|
|
472
305
|
}
|
|
473
306
|
setFileLayout(strategy) {
|
|
474
307
|
this.layout = new LayoutManager(strategy);
|
|
@@ -488,34 +321,21 @@ export const ArkCustomObject = idl.IDLCustomObjectType;
|
|
|
488
321
|
export function cleanPrefix(name, prefix) {
|
|
489
322
|
return name.replace(prefix, "");
|
|
490
323
|
}
|
|
491
|
-
function forceTypedefAsResource(type, decl) {
|
|
324
|
+
export function forceTypedefAsResource(resolver, type, decl) {
|
|
492
325
|
if (generatorConfiguration().forceResource.includes(idl.getFQName(decl)))
|
|
493
326
|
return true;
|
|
494
|
-
if (isCyclicTypeDef(decl)) {
|
|
327
|
+
if (isCyclicTypeDef(resolver, decl)) {
|
|
495
328
|
warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
|
|
496
329
|
return true;
|
|
497
330
|
}
|
|
498
331
|
return false;
|
|
499
332
|
}
|
|
500
|
-
function isCyclicTypeDef(decl) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
return true;
|
|
508
|
-
if (idl.isUnionType(type) && checkCyclicTypes(fqn, type.types))
|
|
509
|
-
return true;
|
|
510
|
-
if (idl.isContainerType(type) && checkCyclicTypes(fqn, type.elementType))
|
|
511
|
-
return true;
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
514
|
-
function checkCyclicTypes(fqn, types) {
|
|
515
|
-
for (const t of types) {
|
|
516
|
-
if (checkCyclicType(fqn, t))
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
return false;
|
|
333
|
+
function isCyclicTypeDef(resolver, decl) {
|
|
334
|
+
let foundCycle = false;
|
|
335
|
+
idl.forEachChild(decl, (node) => {
|
|
336
|
+
if (idl.isReferenceType(node) && resolver.resolveTypeReference(node) === decl)
|
|
337
|
+
foundCycle = true;
|
|
338
|
+
});
|
|
339
|
+
return foundCycle;
|
|
520
340
|
}
|
|
521
341
|
//# sourceMappingURL=PeerLibrary.js.map
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import * as idl from '../idl';
|
|
2
2
|
export interface ReferenceResolver {
|
|
3
|
-
resolveTypeReference(type: idl.IDLReferenceType,
|
|
3
|
+
resolveTypeReference(type: idl.IDLReferenceType, options?: {
|
|
4
|
+
terminalImports?: boolean;
|
|
5
|
+
unresolvedOk?: boolean;
|
|
6
|
+
}): idl.IDLEntry | undefined;
|
|
4
7
|
toDeclaration(type: idl.IDLNode): idl.IDLNode;
|
|
5
8
|
}
|
|
6
9
|
export declare function createEmptyReferenceResolver(): ReferenceResolver;
|
|
7
10
|
/** Please do not store any global instances */
|
|
8
11
|
export declare function createAlternativeReferenceResolver(mainResolver: ReferenceResolver, alternatives: Map<string, idl.IDLEntry>): ReferenceResolver;
|
|
12
|
+
export declare function createAlgotithmicReferenceResolver(files: idl.IDLFile[], useFallback?: boolean): ReferenceResolver;
|
|
13
|
+
export declare function createCachedReferenceResolver(files: idl.IDLFile[]): ReferenceResolver;
|
|
9
14
|
//# sourceMappingURL=ReferenceResolver.d.ts.map
|