@idlizer/arktscgen 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/libarkts-copy/generator/options.json5 +24 -47
- package/build/libarkts-copy/native/meson.build +29 -13
- package/build/libarkts-copy/native/meson_options.txt +9 -3
- package/build/libarkts-copy/native/mingw.cross +2 -0
- package/build/libarkts-copy/native/src/{bridges.cc → bridges.cpp} +31 -92
- package/build/libarkts-copy/native/src/{common.cc → common.cpp} +240 -107
- package/build/libarkts-copy/native/src/common.h +22 -22
- package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +45 -32
- package/build/libarkts-copy/package.json +13 -11
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +10 -63
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +9 -3
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +10 -7
- package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +14 -5
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +19 -1
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
- package/build/libarkts-copy/src/arkts-api/index.ts +0 -2
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +12 -3
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +0 -16
- package/build/libarkts-copy/src/arkts-api/peers/Config.ts +1 -1
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +9 -9
- package/build/libarkts-copy/src/arkts-api/plugins.ts +113 -15
- package/build/libarkts-copy/src/arkts-api/static/global.ts +1 -4
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +5 -5
- package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +11 -43
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -9
- package/build/libarkts-copy/src/arkts-api/visitor.ts +4 -25
- package/build/libarkts-copy/src/checkSdk.ts +1 -1
- package/build/libarkts-copy/src/index.ts +1 -2
- package/build/libarkts-copy/src/memo-node-cache.ts +143 -0
- package/build/libarkts-copy/src/plugin-utils.ts +72 -40
- package/build/libarkts-copy/src/reexport-for-generated.ts +3 -1
- package/build/libarkts-copy/src/tracer.ts +2 -2
- package/build/libarkts-copy/src/utils.ts +10 -14
- package/build/libarkts-copy/tsconfig.json +0 -3
- package/lib/index.js +5517 -10446
- package/package.json +9 -7
- package/templates/{bridges.cc → bridges.cpp} +1 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +0 -45
- package/build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts +0 -23
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +0 -1250
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +0 -125
- package/build/libarkts-copy/src/ts-api/index.ts +0 -27
- package/build/libarkts-copy/src/ts-api/static/enums.ts +0 -18
- package/build/libarkts-copy/src/ts-api/types.ts +0 -1075
- package/build/libarkts-copy/src/ts-api/utilities/private.ts +0 -292
- package/build/libarkts-copy/src/ts-api/utilities/public.ts +0 -55
- package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +0 -139
|
@@ -18,29 +18,29 @@
|
|
|
18
18
|
#include <cstdint>
|
|
19
19
|
#include <fstream>
|
|
20
20
|
#include <iostream>
|
|
21
|
-
#include <regex>
|
|
22
21
|
#include <sstream>
|
|
23
22
|
#include <system_error>
|
|
24
23
|
#include <vector>
|
|
24
|
+
#include <regex>
|
|
25
25
|
|
|
26
26
|
#ifdef _WIN32
|
|
27
|
-
#include <
|
|
28
|
-
#include <
|
|
27
|
+
#include <windows.h>
|
|
28
|
+
#include <psapi.h>
|
|
29
29
|
#elif defined(__APPLE__)
|
|
30
|
-
#include <mach/mach.h>
|
|
31
|
-
#include <sys/resource.h>
|
|
30
|
+
#include <mach/mach.h>
|
|
31
|
+
#include <sys/resource.h>
|
|
32
32
|
#elif defined(__linux__)
|
|
33
|
-
#include <sys/resource.h>
|
|
34
|
-
#include <unistd.h>
|
|
33
|
+
#include <sys/resource.h>
|
|
34
|
+
#include <unistd.h>
|
|
35
35
|
#endif
|
|
36
36
|
|
|
37
37
|
constexpr const char* UNIT_K = "kB";
|
|
38
38
|
constexpr size_t BYTES_PER_KB = 1024;
|
|
39
39
|
constexpr const char* MEMORY_STATUS_FILE = "/proc/self/status";
|
|
40
|
-
const std::regex VM_RSS_REGEX(
|
|
41
|
-
|
|
42
|
-
const std::regex VM_SIZE_REGEX(
|
|
43
|
-
|
|
40
|
+
const std::regex VM_RSS_REGEX(R"#(VmRSS:\s*(\d+)\s*([kKmMgG]?B))#",
|
|
41
|
+
std::regex_constants::ECMAScript | std::regex_constants::icase);
|
|
42
|
+
const std::regex VM_SIZE_REGEX(R"#(VmSize:\s*(\d+)\s*([kKmMgG]?B))#",
|
|
43
|
+
std::regex_constants::ECMAScript | std::regex_constants::icase);
|
|
44
44
|
|
|
45
45
|
constexpr int MATCH_GROUP_VALUE = 1;
|
|
46
46
|
constexpr int MATCH_GROUP_UNIT = 2;
|
|
@@ -49,9 +49,10 @@ constexpr int MATCH_GROUP_SIZE = 3;
|
|
|
49
49
|
#if defined(_WIN32)
|
|
50
50
|
MemoryStats GetMemoryStats()
|
|
51
51
|
{
|
|
52
|
-
MemoryStats stats = {
|
|
52
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
53
53
|
PROCESS_MEMORY_COUNTERS_EX pmc;
|
|
54
|
-
if (GetProcessMemoryInfo(GetCurrentProcess(),
|
|
54
|
+
if (GetProcessMemoryInfo(GetCurrentProcess(),
|
|
55
|
+
reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), sizeof(pmc))) {
|
|
55
56
|
stats.currentRss = pmc.WorkingSetSize;
|
|
56
57
|
stats.peakRss = pmc.PeakWorkingSetSize;
|
|
57
58
|
stats.currentVss = pmc.PrivateUsage; // 私有内存使用量
|
|
@@ -65,18 +66,19 @@ MemoryStats GetMemoryStats()
|
|
|
65
66
|
#elif defined(__APPLE__)
|
|
66
67
|
MemoryStats GetMemoryStats()
|
|
67
68
|
{
|
|
68
|
-
MemoryStats stats = {
|
|
69
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
69
70
|
struct rusage ru;
|
|
70
71
|
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
|
71
|
-
stats.currentRss = 0;
|
|
72
|
+
stats.currentRss = 0; // macOS需要专用API获取当前内存
|
|
72
73
|
stats.peakRss = ru.ru_maxrss; // macOS返回字节
|
|
73
74
|
stats.pageFaultsMinor = ru.ru_minflt;
|
|
74
75
|
stats.pageFaultsMajor = ru.ru_majflt;
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
// 获取当前内存使用 (macOS专用API)
|
|
77
78
|
task_basic_info info;
|
|
78
79
|
mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
|
|
79
|
-
if (task_info(mach_task_self(), TASK_BASIC_INFO_64,
|
|
80
|
+
if (task_info(mach_task_self(), TASK_BASIC_INFO_64,
|
|
81
|
+
(task_info_t)&info, &count) == KERN_SUCCESS) {
|
|
80
82
|
stats.currentRss = info.resident_size; // 物理内存使用量
|
|
81
83
|
stats.currentVss = info.virtual_size; // 虚拟内存总量
|
|
82
84
|
}
|
|
@@ -87,7 +89,7 @@ MemoryStats GetMemoryStats()
|
|
|
87
89
|
#elif defined(__linux__)
|
|
88
90
|
MemoryStats GetMemoryStats()
|
|
89
91
|
{
|
|
90
|
-
MemoryStats stats = {
|
|
92
|
+
MemoryStats stats = {0, 0, 0, 0, 0};
|
|
91
93
|
struct rusage ru;
|
|
92
94
|
if (getrusage(RUSAGE_SELF, &ru) == 0) {
|
|
93
95
|
stats.peakRss = static_cast<size_t>(ru.ru_maxrss) * BYTES_PER_KB; // KB -> 字节
|
|
@@ -127,9 +129,13 @@ void MemoryTracker::Reset()
|
|
|
127
129
|
MemoryStats MemoryTracker::GetDelta()
|
|
128
130
|
{
|
|
129
131
|
MemoryStats current = GetMemoryStats();
|
|
130
|
-
MemoryStats delta = {
|
|
131
|
-
current.
|
|
132
|
-
current.
|
|
132
|
+
MemoryStats delta = {
|
|
133
|
+
current.currentRss - baseline.currentRss,
|
|
134
|
+
current.peakRss - baseline.peakRss,
|
|
135
|
+
current.currentVss - baseline.currentVss,
|
|
136
|
+
current.pageFaultsMinor - baseline.pageFaultsMinor,
|
|
137
|
+
current.pageFaultsMajor - baseline.pageFaultsMajor
|
|
138
|
+
};
|
|
133
139
|
return delta;
|
|
134
140
|
}
|
|
135
141
|
|
|
@@ -141,9 +147,13 @@ MemoryStats MemoryTracker::MeasureMemory(Func&& func)
|
|
|
141
147
|
func();
|
|
142
148
|
auto postStats = GetMemoryStats();
|
|
143
149
|
|
|
144
|
-
return {
|
|
145
|
-
postStats.
|
|
146
|
-
postStats.
|
|
150
|
+
return {
|
|
151
|
+
postStats.currentRss - preStats.currentRss,
|
|
152
|
+
postStats.peakRss - preStats.peakRss,
|
|
153
|
+
postStats.currentVss - preStats.currentVss,
|
|
154
|
+
postStats.pageFaultsMinor - preStats.pageFaultsMinor,
|
|
155
|
+
postStats.pageFaultsMajor - preStats.pageFaultsMajor
|
|
156
|
+
};
|
|
147
157
|
}
|
|
148
158
|
|
|
149
159
|
void MemoryTracker::Report(MemoryStats stats)
|
|
@@ -153,19 +163,22 @@ void MemoryTracker::Report(MemoryStats stats)
|
|
|
153
163
|
const double mb = kb * BYTES_PER_KB;
|
|
154
164
|
const double gb = mb * BYTES_PER_KB;
|
|
155
165
|
|
|
156
|
-
if (bytes > gb)
|
|
166
|
+
if (bytes > gb) {
|
|
157
167
|
return std::to_string(bytes / gb) + " GB";
|
|
158
|
-
|
|
168
|
+
}
|
|
169
|
+
if (bytes > mb) {
|
|
159
170
|
return std::to_string(bytes / mb) + " MB";
|
|
160
|
-
|
|
171
|
+
}
|
|
172
|
+
if (bytes > kb) {
|
|
161
173
|
return std::to_string(bytes / kb) + " KB";
|
|
174
|
+
}
|
|
162
175
|
return std::to_string(bytes) + " B";
|
|
163
176
|
};
|
|
164
177
|
|
|
165
|
-
std::cout << "Current RSS: " << formatBytes(stats.currentRss) << "\n";
|
|
166
|
-
std::cout << "Peak RSS : " << formatBytes(stats.peakRss) << "\n";
|
|
167
|
-
std::cout << "VSS : " << formatBytes(stats.currentVss) << "\n";
|
|
168
|
-
std::cout << "FaultsMinor: " << stats.pageFaultsMinor << "\n";
|
|
169
|
-
std::cout << "FaultsMajor: " << stats.pageFaultsMajor << "\n";
|
|
178
|
+
std::cout << "Current RSS: " << formatBytes(stats.currentRss) << "\n" << std::endl;
|
|
179
|
+
std::cout << "Peak RSS : " << formatBytes(stats.peakRss) << "\n" << std::endl;
|
|
180
|
+
std::cout << "VSS : " << formatBytes(stats.currentVss) << "\n" << std::endl;
|
|
181
|
+
std::cout << "FaultsMinor: " << stats.pageFaultsMinor << "\n" << std::endl;
|
|
182
|
+
std::cout << "FaultsMajor: " << stats.pageFaultsMajor << "\n" << std::endl;
|
|
170
183
|
return;
|
|
171
184
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaui/libarkts",
|
|
3
3
|
"version": "1.7.10+devel",
|
|
4
|
-
"
|
|
4
|
+
"main": "./lib/libarkts.js",
|
|
5
5
|
"typesVersions": {
|
|
6
6
|
"*": {
|
|
7
7
|
"./compat/*": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./plugins/build/src/**/*"
|
|
24
24
|
],
|
|
25
25
|
"config": {
|
|
26
|
-
"panda_sdk_path": "
|
|
26
|
+
"panda_sdk_path": "../incremental/tools/panda/node_modules/@panda/sdk",
|
|
27
27
|
"panda_sdk_version": "next"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
@@ -33,14 +33,16 @@
|
|
|
33
33
|
"commander": "10.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"tslib": "^2.3.1",
|
|
36
37
|
"rollup": "^4.13.0",
|
|
37
38
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
38
39
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
39
40
|
"@rollup/plugin-terser": "^0.4.4",
|
|
40
41
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"tsconfig-paths": "^4.2.0",
|
|
41
43
|
"rimraf": "^6.0.1",
|
|
42
44
|
"@koalaui/fast-arktsc": "1.7.10+devel",
|
|
43
|
-
"@idlizer/arktscgen": "2.1.10-arktscgen-
|
|
45
|
+
"@idlizer/arktscgen": "2.1.10-arktscgen-6",
|
|
44
46
|
"mocha": "^9.2.2",
|
|
45
47
|
"@koalaui/harness": "1.7.10+devel",
|
|
46
48
|
"@koalaui/ets-tsc": "4.9.5-r6",
|
|
@@ -51,7 +53,7 @@
|
|
|
51
53
|
"scripts": {
|
|
52
54
|
"clean": "rimraf generated build native/build* ./.rollup.cache tsconfig.tsbuildinfo lib",
|
|
53
55
|
"clean:plugins": "rimraf plugins/build",
|
|
54
|
-
"compile:koala:interop": "npm run --prefix
|
|
56
|
+
"compile:koala:interop": "npm run --prefix ../interop compile",
|
|
55
57
|
"compile:meson": "cd native && meson setup build && meson compile -C build",
|
|
56
58
|
"compile:meson:mingw": "cd native && meson setup --cross-file ./mingw.cross mingw_build && meson compile -C mingw_build",
|
|
57
59
|
"crosscompile:meson": "cd native && CXX=clang++ meson setup -D cross_compile=true build && CXX=clang++ meson compile -C build",
|
|
@@ -61,10 +63,10 @@
|
|
|
61
63
|
"compile": "npm run regenerate && npm run compile:native && npm run compile:js",
|
|
62
64
|
"compile:current": "npm run regenerate:current && npm run compile:native && npm run compile:js",
|
|
63
65
|
"compile:release": "npm run regenerate && npm run crosscompile:native && npm run compile:js",
|
|
64
|
-
"compile:js": "rm -rf lib/ && rollup -c rollup.
|
|
66
|
+
"compile:js": "rm -rf lib/ && rollup -c rollup.libarkts.mjs && rollup -c rollup.es2panda.mjs",
|
|
65
67
|
"compile:plugins": "rollup -c ./rollup.printer-plugin.mjs",
|
|
66
|
-
"direct": "fast-arktsc --config arktsconfig.json --compiler
|
|
67
|
-
"simultaneous": "mkdir -p build/abc && bash
|
|
68
|
+
"direct": "fast-arktsc --config arktsconfig.json --compiler ../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc && ninja -f build/abc/build.ninja",
|
|
69
|
+
"simultaneous": "mkdir -p build/abc && bash ../incremental/tools/panda/arkts/ui2abc --simultaneous --arktsconfig arktsconfig.json --output ./build/abc/main.abc:./build/abc/library.abc plugins/input/main.ets:plugins/input/library.ets",
|
|
68
70
|
"run": "npm run compile && npm run compile:plugins && npm run simultaneous",
|
|
69
71
|
"run:current": "npm run compile:current && npm run compile:plugins && npm run simultaneous",
|
|
70
72
|
"run:memo": "npm run compile && npm run compile:plugins && npm run compile --prefix ../memo-plugin-ng && npm run memo",
|
|
@@ -74,11 +76,11 @@
|
|
|
74
76
|
"test": "npm run compile:native && npm run test:light",
|
|
75
77
|
"test:golden": "npm run compile:native && TEST_GOLDEN=1 npm run test:light",
|
|
76
78
|
"compile:playground": "cd playground && meson setup build && meson compile -C build",
|
|
77
|
-
"run:playground": "npm run compile:playground && mkdir -p build && ./playground/build/playground _ --extension ets --stdlib
|
|
78
|
-
"panda:sdk:clean": "cd
|
|
79
|
-
"panda:sdk:install": "cd
|
|
79
|
+
"run:playground": "npm run compile:playground && mkdir -p build && ./playground/build/playground _ --extension ets --stdlib ../incremental/tools/panda/node_modules/@panda/sdk/ets/stdlib --output build/playground.abc ./playground/src/main.ets",
|
|
80
|
+
"panda:sdk:clean": "cd ../incremental/tools/panda && rimraf node_modules",
|
|
81
|
+
"panda:sdk:install": "cd ../incremental/tools/panda && echo \"Installing panda sdk $npm_package_config_panda_sdk_version\" && PANDA_SDK_VERSION=$npm_package_config_panda_sdk_version npm run panda:sdk:install",
|
|
80
82
|
"panda:sdk:reinstall": "npm run panda:sdk:clean && npm run panda:sdk:install",
|
|
81
|
-
"regenerate:current": "rimraf -rf ./generated && npm run compile -C
|
|
83
|
+
"regenerate:current": "rimraf -rf ./generated && npm run compile -C ../../arktscgen && node ../../arktscgen --panda-sdk-path $npm_package_config_panda_sdk_path --output-dir ../ --options-file ./generator/options.json5 --no-initialize --debug",
|
|
82
84
|
"regenerate": "rimraf -rf ./generated && arktscgen --panda-sdk-path ${PANDA_SDK_PATH:=$npm_package_config_panda_sdk_path} --output-dir ../ --options-file ./generator/options.json5 --no-initialize",
|
|
83
85
|
"reinstall:regenerate": "npm run panda:sdk:reinstall && npm run regenerate && git diff --shortstat",
|
|
84
86
|
"format:src:ts": "npx prettier --config .prettierrc --write \"./src/**/*.ts\"",
|
|
@@ -58,37 +58,12 @@ export class Es2pandaNativeModule {
|
|
|
58
58
|
_DestroyConfig(peer: KNativePointer): void {
|
|
59
59
|
throw new Error('Not implemented');
|
|
60
60
|
}
|
|
61
|
-
_CreateContextFromString(config: KPtr, source: String, filename: String): KPtr {
|
|
62
|
-
throw new Error('Not implemented');
|
|
63
|
-
}
|
|
64
|
-
_CreateContextFromFile(config: KPtr, filename: String): KPtr {
|
|
65
|
-
throw new Error('Not implemented');
|
|
66
|
-
}
|
|
67
|
-
_CreateCacheContextFromFile(
|
|
68
|
-
config: KNativePointer,
|
|
69
|
-
sourceFileName: String,
|
|
70
|
-
globalContext: KNativePointer,
|
|
71
|
-
isExternal: KBoolean
|
|
72
|
-
): KNativePointer {
|
|
73
|
-
throw new Error('Not implemented');
|
|
74
|
-
}
|
|
75
61
|
_InsertGlobalStructInfo(context: KNativePointer, str: String): void {
|
|
76
62
|
throw new Error('Not implemented');
|
|
77
63
|
}
|
|
78
64
|
_HasGlobalStructInfo(context: KNativePointer, str: String): KBoolean {
|
|
79
65
|
throw new Error('Not implemented');
|
|
80
66
|
}
|
|
81
|
-
_CreateGlobalContext(
|
|
82
|
-
config: KNativePointer,
|
|
83
|
-
externalFileList: KStringArrayPtr,
|
|
84
|
-
fileNum: KUInt,
|
|
85
|
-
lspUsage: KBoolean
|
|
86
|
-
): KNativePointer {
|
|
87
|
-
throw new Error('Not implemented');
|
|
88
|
-
}
|
|
89
|
-
_DestroyGlobalContext(context: KNativePointer): void {
|
|
90
|
-
throw new Error('Not implemented');
|
|
91
|
-
}
|
|
92
67
|
_DestroyContext(context: KPtr): void {
|
|
93
68
|
throw new Error('Not implemented');
|
|
94
69
|
}
|
|
@@ -157,10 +132,10 @@ export class Es2pandaNativeModule {
|
|
|
157
132
|
_ETSParserGetImportPathManager(context: KNativePointer): KPtr {
|
|
158
133
|
throw new Error('Not implemented');
|
|
159
134
|
}
|
|
160
|
-
|
|
135
|
+
_ConfigGetOptions(config: KNativePointer): KNativePointer {
|
|
161
136
|
throw new Error('Not implemented');
|
|
162
137
|
}
|
|
163
|
-
|
|
138
|
+
_SourcePositionCol(context: KNativePointer, instance: KNativePointer): KUInt {
|
|
164
139
|
throw new Error('Not implemented');
|
|
165
140
|
}
|
|
166
141
|
_OptionsArkTsConfig(context: KNativePointer, options: KNativePointer): KNativePointer {
|
|
@@ -223,7 +198,13 @@ export class Es2pandaNativeModule {
|
|
|
223
198
|
): void {
|
|
224
199
|
throw new Error('Not implemented');
|
|
225
200
|
}
|
|
226
|
-
_FilterNodes(context: KNativePointer, root: KNativePointer, filters: KStringPtr): KNativePointer {
|
|
201
|
+
_FilterNodes(context: KNativePointer, root: KNativePointer, filters: KStringPtr, deeperAfterMatch: KBoolean): KNativePointer {
|
|
202
|
+
throw new Error('Not implemented');
|
|
203
|
+
}
|
|
204
|
+
_FilterNodes2(context: KNativePointer, root: KNativePointer, type: KInt): KNativePointer {
|
|
205
|
+
throw new Error('Not implemented');
|
|
206
|
+
}
|
|
207
|
+
_FilterNodes3(context: KNativePointer, root: KNativePointer, types: Int32Array, typesSize: KInt): KNativePointer {
|
|
227
208
|
throw new Error('Not implemented');
|
|
228
209
|
}
|
|
229
210
|
|
|
@@ -241,26 +222,6 @@ export class Es2pandaNativeModule {
|
|
|
241
222
|
): KNativePointer {
|
|
242
223
|
throw new Error('Not implemented');
|
|
243
224
|
}
|
|
244
|
-
_CreateDiagnosticInfo(
|
|
245
|
-
context: KNativePointer,
|
|
246
|
-
kind: KNativePointer,
|
|
247
|
-
args: string[],
|
|
248
|
-
argc: number,
|
|
249
|
-
pos: KNativePointer
|
|
250
|
-
): KNativePointer {
|
|
251
|
-
throw new Error('Not implemented');
|
|
252
|
-
}
|
|
253
|
-
_CreateSuggestionInfo(
|
|
254
|
-
context: KNativePointer,
|
|
255
|
-
kind: KNativePointer,
|
|
256
|
-
args: string[],
|
|
257
|
-
argc: number,
|
|
258
|
-
substitutionCode: string,
|
|
259
|
-
title: string,
|
|
260
|
-
range: KNativePointer
|
|
261
|
-
): KNativePointer {
|
|
262
|
-
throw new Error('Not implemented');
|
|
263
|
-
}
|
|
264
225
|
_LogDiagnostic(
|
|
265
226
|
context: KNativePointer,
|
|
266
227
|
kind: KNativePointer,
|
|
@@ -279,26 +240,12 @@ export class Es2pandaNativeModule {
|
|
|
279
240
|
_MemFinalize(): void {
|
|
280
241
|
throw new Error('Not implemented');
|
|
281
242
|
}
|
|
282
|
-
_ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer):
|
|
283
|
-
throw new Error('Not implemented');
|
|
284
|
-
}
|
|
285
|
-
_GenerateTsDeclarationsFromContext(
|
|
286
|
-
config: KPtr,
|
|
287
|
-
outputDeclEts: String,
|
|
288
|
-
outputEts: String,
|
|
289
|
-
exportAll: KBoolean,
|
|
290
|
-
isolated: KBoolean,
|
|
291
|
-
recordFile: String,
|
|
292
|
-
genAnnotations: KBoolean
|
|
293
|
-
): KPtr {
|
|
243
|
+
_ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer): KBoolean {
|
|
294
244
|
throw new Error('Not implemented');
|
|
295
245
|
}
|
|
296
246
|
_AstNodeProgram(context: KNativePointer, instance: KNativePointer): KNativePointer {
|
|
297
247
|
throw new Error('Not implemented');
|
|
298
248
|
}
|
|
299
|
-
_CreateContextGenerateAbcForExternalSourceFiles(config: KPtr, fileCount: KInt, filenames: string[]): KPtr {
|
|
300
|
-
throw new Error('Not implemented');
|
|
301
|
-
}
|
|
302
249
|
|
|
303
250
|
_GetCompilationMode(config: KNativePointer): KInt {
|
|
304
251
|
throw new Error('Not implemented');
|
|
@@ -37,13 +37,19 @@ export abstract class AbstractVisitor {
|
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
process(node: AstNode, options?:
|
|
40
|
+
process(node: AstNode, options?: any): AstNode {
|
|
41
41
|
return this.visitor(node, options);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
init(): void {}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
reset(): void {
|
|
47
|
+
this.indentation = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
abstract visitor(node: AstNode, options?: any): AstNode;
|
|
51
|
+
|
|
52
|
+
visitEachChild(node: AstNode, options?: any): AstNode {
|
|
47
53
|
return this.withIndentation((): AstNode => visitEachChild(node, (it): AstNode => this.visitor(it, options)));
|
|
48
54
|
}
|
|
49
55
|
}
|
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { KNativePointer } from '@koalaui/interop';
|
|
17
|
-
import {
|
|
17
|
+
import { ETSImportDeclaration, isETSImportDeclaration, Program, Statement } from '../../generated';
|
|
18
18
|
import { passNode, passNodeArray, unpackNonNullableNode } from './utilities/private';
|
|
19
19
|
import { global } from './static/global';
|
|
20
20
|
import { Es2pandaImportFlags, Es2pandaImportKinds } from '../../generated/Es2pandaEnums';
|
|
21
|
-
import { factory } from './factory/nodeFactory';
|
|
22
21
|
|
|
23
22
|
export class ImportStorage {
|
|
24
23
|
// Improve: migrate to wrappers instead of pointers
|
|
@@ -48,12 +47,18 @@ export class ImportStorage {
|
|
|
48
47
|
const newStatements: Statement[] = [];
|
|
49
48
|
for (const statement of statements) {
|
|
50
49
|
if (isETSImportDeclaration(statement) && !this.imports.has(statement.peer)) {
|
|
50
|
+
// Weak workaround to avoid self-imports (see panda issue 31156)
|
|
51
|
+
if (this.program.moduleName == statement.source?.str || this.program.moduleName == `${statement.source?.str}.index`) {
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// On checked state imports from unparsed sources cannot be inserted
|
|
51
56
|
if (!this.isParserState && !this.importSources.has(statement.source?.str)) {
|
|
52
57
|
console.warn('Attempt to insert import from new source after parsed state:');
|
|
53
58
|
console.warn(statement.dumpSrc());
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
const importDeclaration = unpackNonNullableNode<
|
|
61
|
+
const importDeclaration = unpackNonNullableNode<ETSImportDeclaration>(
|
|
57
62
|
// Note: this call is important, we cannot just pass "statement" to "InsertETSImportDeclarationAndParse"
|
|
58
63
|
global.es2panda._ETSParserBuildImportDeclaration(
|
|
59
64
|
global.context,
|
|
@@ -77,9 +82,7 @@ export class ImportStorage {
|
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
// Drop import statements generated by compiler in the beginning of the ETSModule
|
|
80
|
-
const module = this.program.
|
|
81
|
-
|
|
82
|
-
factory.updateETSModule(module, newStatements, module.ident, module.getNamespaceFlag(), module.program)
|
|
83
|
-
);
|
|
85
|
+
const module = this.program.getAstCasted()
|
|
86
|
+
module.setStatements(newStatements)
|
|
84
87
|
}
|
|
85
88
|
}
|
|
@@ -18,16 +18,24 @@ import { defaultFilter, listPrograms } from './plugins';
|
|
|
18
18
|
import { Program } from '../../generated';
|
|
19
19
|
|
|
20
20
|
export class ProgramProvider {
|
|
21
|
-
|
|
21
|
+
static programListCache: Map<string, Program[]> = new Map();
|
|
22
|
+
programListFromCache?: Program[];
|
|
22
23
|
seenPrograms: Set<KNativePointer> = new Set<KNativePointer>();
|
|
23
24
|
queue: Program[] = [];
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
|
-
private mainProgram: Program,
|
|
27
|
-
private readonly
|
|
27
|
+
private readonly mainProgram: Program,
|
|
28
|
+
private readonly stableDeps: boolean = false,
|
|
29
|
+
private readonly filter: (name: string) => boolean = defaultFilter,
|
|
28
30
|
) {
|
|
29
31
|
this.seenPrograms.add(mainProgram.peer);
|
|
30
|
-
|
|
32
|
+
if (!stableDeps || !ProgramProvider.programListCache.has(mainProgram.absoluteName)) {
|
|
33
|
+
this.programListFromCache = [mainProgram]
|
|
34
|
+
ProgramProvider.programListCache.set(mainProgram.absoluteName, this.programListFromCache)
|
|
35
|
+
} else {
|
|
36
|
+
this.programListFromCache = ProgramProvider.programListCache.get(mainProgram.absoluteName)
|
|
37
|
+
}
|
|
38
|
+
this.queue = [...this.programListFromCache!]
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
updateQueue(): void {
|
|
@@ -35,13 +43,14 @@ export class ProgramProvider {
|
|
|
35
43
|
for (const program of listed) {
|
|
36
44
|
if (!this.seenPrograms.has(program.peer)) {
|
|
37
45
|
this.seenPrograms.add(program.peer);
|
|
46
|
+
this.programListFromCache?.push(program)
|
|
38
47
|
this.queue.push(program);
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
next(): Program | undefined {
|
|
44
|
-
if (this.queue.length === 0) {
|
|
53
|
+
if (this.queue.length === 0 && (!this.stableDeps || this.programListFromCache?.length == 1)) {
|
|
45
54
|
this.updateQueue();
|
|
46
55
|
if (this.queue.length === 0) {
|
|
47
56
|
// console.log("PROGRAMS:", this.seenPrograms.size)
|
|
@@ -22,12 +22,30 @@ import { NodeCache } from './node-cache';
|
|
|
22
22
|
|
|
23
23
|
export const nodeByType = new Map<Es2pandaAstNodeType, (peer: KNativePointer) => AstNode>([]);
|
|
24
24
|
|
|
25
|
+
// TODO: These node types are "specially mapped" in the compiler, they don't have C++ classes
|
|
26
|
+
// See AST_NODE_REINTERPRET_MAPPING in the compiler source
|
|
27
|
+
// Do we need managed wrappers for them? Need to investigate.
|
|
28
|
+
export function nodeTypeFilter(type: Es2pandaAstNodeType): Es2pandaAstNodeType {
|
|
29
|
+
switch (type) {
|
|
30
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_REST_ELEMENT:
|
|
31
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_SPREAD_ELEMENT
|
|
32
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_PATTERN:
|
|
33
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION
|
|
34
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_ASSIGNMENT_PATTERN:
|
|
35
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_ASSIGNMENT_EXPRESSION
|
|
36
|
+
case Es2pandaAstNodeType.AST_NODE_TYPE_ARRAY_PATTERN:
|
|
37
|
+
return Es2pandaAstNodeType.AST_NODE_TYPE_ARRAY_EXPRESSION
|
|
38
|
+
}
|
|
39
|
+
return type
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
export function nodeFrom<T extends AstNode>(peer: KNativePointer, typeHint?: Es2pandaAstNodeType): T {
|
|
26
43
|
const fromCache = NodeCache.get<T>(peer);
|
|
27
44
|
if (fromCache) {
|
|
28
45
|
return fromCache;
|
|
29
46
|
}
|
|
30
|
-
|
|
47
|
+
|
|
48
|
+
const type = nodeTypeFilter(typeHint ?? global.generatedEs2panda._AstNodeTypeConst(global.context, peer))
|
|
31
49
|
const create = nodeByType.get(type) ?? throwError(`unknown node type: ${type}`);
|
|
32
50
|
return create(peer) as T;
|
|
33
51
|
}
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
TryStatement,
|
|
31
31
|
TSTypeParameter,
|
|
32
32
|
VariableDeclarator,
|
|
33
|
+
OverloadDeclaration,
|
|
33
34
|
} from '../../../generated';
|
|
34
35
|
import { factory as generatedFactory } from '../../../generated/factory';
|
|
35
36
|
import {
|
|
@@ -59,6 +60,7 @@ import { createArrayExpression, updateArrayExpression } from '../node-utilities/
|
|
|
59
60
|
import { updateBlockStatement } from '../node-utilities/BlockStatement';
|
|
60
61
|
import { updateETSModule } from '../node-utilities/ETSModule';
|
|
61
62
|
import { createOpaqueTypeNode } from '../node-utilities/OpaqueTypeNode';
|
|
63
|
+
import { createOverloadDeclaration } from '../node-utilities/OverloadDeclaration';
|
|
62
64
|
|
|
63
65
|
export const factory = {
|
|
64
66
|
...generatedFactory,
|
|
@@ -141,4 +143,6 @@ export const factory = {
|
|
|
141
143
|
updateClassStaticBlock: ClassStaticBlock.updateClassStaticBlock,
|
|
142
144
|
|
|
143
145
|
createOpaqueTypeNode,
|
|
146
|
+
|
|
147
|
+
createOverloadDeclaration,
|
|
144
148
|
};
|
|
@@ -32,9 +32,7 @@ export * from './peers/Context';
|
|
|
32
32
|
export { GlobalContext } from './peers/Context';
|
|
33
33
|
export * from './peers/ExternalSource';
|
|
34
34
|
export * from './peers/Options';
|
|
35
|
-
export * from './peers/DiagnosticKind';
|
|
36
35
|
export * from './node-utilities/ArkTsConfig';
|
|
37
|
-
export * from './node-utilities/Program';
|
|
38
36
|
export * from './peers/ImportPathManager';
|
|
39
37
|
export * from './static/globalUtils';
|
|
40
38
|
export { global as arktsGlobal } from './static/global';
|
|
@@ -16,12 +16,17 @@
|
|
|
16
16
|
import { KNativePointer } from '@koalaui/interop';
|
|
17
17
|
import { AstNode } from './peers/AstNode';
|
|
18
18
|
|
|
19
|
+
const useCache = false;
|
|
20
|
+
|
|
19
21
|
export class NodeCache {
|
|
20
22
|
private static cache = new Map<KNativePointer, AstNode>();
|
|
21
23
|
|
|
22
24
|
static cached<T extends AstNode>(pointer: KNativePointer, factory: (pointer: KNativePointer) => AstNode): T {
|
|
25
|
+
if (!useCache) {
|
|
26
|
+
return factory(pointer) as T;
|
|
27
|
+
}
|
|
23
28
|
const cached = NodeCache.cache.get(pointer);
|
|
24
|
-
if (cached
|
|
29
|
+
if (!!cached) {
|
|
25
30
|
return cached as T;
|
|
26
31
|
}
|
|
27
32
|
const node = factory(pointer);
|
|
@@ -34,10 +39,14 @@ export class NodeCache {
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
public static addToCache(pointer: KNativePointer, node: AstNode): void {
|
|
37
|
-
|
|
42
|
+
if (useCache) {
|
|
43
|
+
NodeCache.cache.set(pointer, node);
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
public static clear(): void {
|
|
41
|
-
|
|
48
|
+
if (useCache) {
|
|
49
|
+
NodeCache.cache.clear();
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
}
|
|
@@ -41,7 +41,7 @@ export function updateObjectExpression(
|
|
|
41
41
|
): ObjectExpression {
|
|
42
42
|
if (
|
|
43
43
|
isSameNativeObject(properties, original.properties) &&
|
|
44
|
-
preferredReturnType
|
|
44
|
+
preferredReturnType === original.getPreferredTypePointer()
|
|
45
45
|
) {
|
|
46
46
|
return original;
|
|
47
47
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
|
|
16
|
+
import { Expression, OverloadDeclaration } from '../../../generated';
|
|
17
|
+
import { Es2pandaOverloadDeclFlags, Es2pandaModifierFlags } from '../../../generated/Es2pandaEnums';
|
|
18
|
+
|
|
19
|
+
export function createOverloadDeclaration(
|
|
20
|
+
key: Expression | undefined,
|
|
21
|
+
overloads: readonly Expression[],
|
|
22
|
+
flags: Es2pandaOverloadDeclFlags,
|
|
23
|
+
modifiers: Es2pandaModifierFlags,
|
|
24
|
+
): OverloadDeclaration {
|
|
25
|
+
const res = OverloadDeclaration.createOverloadDeclaration(key, modifiers);
|
|
26
|
+
res.setOverloadedList(overloads)
|
|
27
|
+
res.addOverloadDeclFlag(flags)
|
|
28
|
+
return res
|
|
29
|
+
}
|
|
@@ -83,8 +83,8 @@ export function updateScriptFunction(
|
|
|
83
83
|
isSameNativeObject(dataflags, original.modifierFlags) &&
|
|
84
84
|
isSameNativeObject(ident, original.id) &&
|
|
85
85
|
isSameNativeObject(annotations, original.annotations) &&
|
|
86
|
-
signaturePointer
|
|
87
|
-
preferredReturnTypePointer
|
|
86
|
+
signaturePointer === original.getSignaturePointer() &&
|
|
87
|
+
preferredReturnTypePointer === original.getPreferredReturnTypePointer()
|
|
88
88
|
) {
|
|
89
89
|
return original;
|
|
90
90
|
}
|
|
@@ -121,7 +121,6 @@ export function inplaceUpdateScriptFunction(
|
|
|
121
121
|
preferredReturnTypePointer?: KNativePointer
|
|
122
122
|
) {
|
|
123
123
|
if (
|
|
124
|
-
!isSameNativeObject(typeParams, original.typeParams) ||
|
|
125
124
|
!isSameNativeObject(hasReceiver, original.hasReceiver) ||
|
|
126
125
|
!isSameNativeObject(datafuncFlags, original.flags)
|
|
127
126
|
) {
|
|
@@ -145,9 +144,10 @@ export function inplaceUpdateScriptFunction(
|
|
|
145
144
|
}
|
|
146
145
|
original.setBody(databody);
|
|
147
146
|
original.setParams(params);
|
|
147
|
+
original.setTypeParams(typeParams);
|
|
148
148
|
original.setReturnTypeAnnotation(returnTypeAnnotation);
|
|
149
149
|
original.modifierFlags = dataflags;
|
|
150
|
-
|
|
150
|
+
original.setIdent(ident);
|
|
151
151
|
if (annotations) original.setAnnotations(annotations);
|
|
152
152
|
if (signaturePointer) original.setSignaturePointer(signaturePointer);
|
|
153
153
|
if (preferredReturnTypePointer) original.setPreferredReturnTypePointer(preferredReturnTypePointer);
|