@idlizer/arktscgen 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libarkts-copy/native/meson.build +13 -0
- package/build/libarkts-copy/native/meson_options.txt +13 -0
- package/build/libarkts-copy/native/src/bridges.cc +8 -8
- package/build/libarkts-copy/native/src/common.cc +56 -8
- package/build/libarkts-copy/native/src/common.h +48 -0
- package/build/libarkts-copy/native/src/generated/bridges.cc +138 -138
- package/build/libarkts-copy/package.json +67 -61
- package/build/libarkts-copy/src/InteropNativeModule.ts +3 -1
- package/build/libarkts-copy/src/arkts-api/CheckedBackFilter.ts +53 -0
- package/build/libarkts-copy/src/arkts-api/SetBaseOverloads.ts +51 -0
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/index.ts +3 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassProperty.ts +26 -3
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSImportDeclaration.ts +9 -3
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +29 -9
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +10 -2
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +3 -3
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +1 -2
- package/build/libarkts-copy/src/arkts-api/peers/Program.ts +4 -2
- package/build/libarkts-copy/src/arkts-api/plugins.ts +48 -0
- package/build/libarkts-copy/src/arkts-api/static/global.ts +3 -2
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +15 -0
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +5 -3
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +15 -9
- package/build/libarkts-copy/src/arkts-api/visitor.ts +152 -3
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +3 -3
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +3 -3
- package/build/libarkts-copy/src/index.ts +18 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +15 -0
- package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +15 -0
- package/build/libarkts-copy/src/ts-api/types.ts +15 -0
- package/build/libarkts-copy/src/utils.ts +9 -15
- package/build/libarkts-copy/tsconfig.json +2 -1
- package/lib/index.js +1374 -118
- package/package.json +2 -2
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
1
14
|
project(
|
|
2
15
|
'es2panda_interop',
|
|
3
16
|
'cpp',
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
1
14
|
option(
|
|
2
15
|
'node_modules_dir',
|
|
3
16
|
type : 'string',
|
|
@@ -39,7 +39,7 @@ KNativePointer impl_AnnotationAllowedAnnotations(KNativePointer contextPtr, KNat
|
|
|
39
39
|
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
40
40
|
std::size_t params_len = 0;
|
|
41
41
|
auto annotations = GetImpl()->AnnotationAllowedAnnotations(context, node, ¶ms_len);
|
|
42
|
-
return
|
|
42
|
+
return StageArena::cloneVector(annotations, params_len);
|
|
43
43
|
}
|
|
44
44
|
KOALA_INTEROP_3(AnnotationAllowedAnnotations, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
|
|
45
45
|
|
|
@@ -49,7 +49,7 @@ KNativePointer impl_AnnotationAllowedAnnotationsConst(KNativePointer contextPtr,
|
|
|
49
49
|
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
50
50
|
std::size_t params_len = 0;
|
|
51
51
|
auto annotations = GetImpl()->AnnotationAllowedAnnotationsConst(context, node, ¶ms_len);
|
|
52
|
-
return
|
|
52
|
+
return StageArena::cloneVector(annotations, params_len);
|
|
53
53
|
}
|
|
54
54
|
KOALA_INTEROP_3(AnnotationAllowedAnnotationsConst, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
|
|
55
55
|
|
|
@@ -151,7 +151,7 @@ KOALA_INTEROP_1(ContextProgram, KNativePointer, KNativePointer)
|
|
|
151
151
|
|
|
152
152
|
KNativePointer impl_ProgramAst(KNativePointer contextPtr, KNativePointer programPtr)
|
|
153
153
|
{
|
|
154
|
-
auto context = reinterpret_cast<es2panda_Context*>(
|
|
154
|
+
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
155
155
|
auto program = reinterpret_cast<es2panda_Program*>(programPtr);
|
|
156
156
|
return GetImpl()->ProgramAst(context, program);
|
|
157
157
|
}
|
|
@@ -190,7 +190,7 @@ KNativePointer impl_ContextErrorMessage(KNativePointer contextPtr)
|
|
|
190
190
|
{
|
|
191
191
|
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
192
192
|
|
|
193
|
-
return
|
|
193
|
+
return StageArena::strdup(GetImpl()->ContextErrorMessage(context));
|
|
194
194
|
}
|
|
195
195
|
KOALA_INTEROP_1(ContextErrorMessage, KNativePointer, KNativePointer)
|
|
196
196
|
|
|
@@ -228,15 +228,15 @@ static KNativePointer impl_ProgramExternalSources(KNativePointer contextPtr, KNa
|
|
|
228
228
|
auto&& instance = reinterpret_cast<es2panda_Program *>(instancePtr);
|
|
229
229
|
std::size_t source_len = 0;
|
|
230
230
|
auto external_sources = GetImpl()->ProgramExternalSources(context, instance, &source_len);
|
|
231
|
-
return
|
|
231
|
+
return StageArena::cloneVector(external_sources, source_len);
|
|
232
232
|
}
|
|
233
233
|
KOALA_INTEROP_2(ProgramExternalSources, KNativePointer, KNativePointer, KNativePointer);
|
|
234
234
|
|
|
235
235
|
static KNativePointer impl_ExternalSourceName(KNativePointer instance)
|
|
236
236
|
{
|
|
237
237
|
auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource *>(instance);
|
|
238
|
-
auto&&
|
|
239
|
-
return
|
|
238
|
+
auto&& result = GetImpl()->ExternalSourceName(_instance_);
|
|
239
|
+
return StageArena::strdup(result);
|
|
240
240
|
}
|
|
241
241
|
KOALA_INTEROP_1(ExternalSourceName, KNativePointer, KNativePointer);
|
|
242
242
|
|
|
@@ -245,7 +245,7 @@ static KNativePointer impl_ExternalSourcePrograms(KNativePointer instance)
|
|
|
245
245
|
auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource *>(instance);
|
|
246
246
|
std::size_t program_len = 0;
|
|
247
247
|
auto programs = GetImpl()->ExternalSourcePrograms(_instance_, &program_len);
|
|
248
|
-
return
|
|
248
|
+
return StageArena::cloneVector(programs, program_len);
|
|
249
249
|
}
|
|
250
250
|
KOALA_INTEROP_1(ExternalSourcePrograms, KNativePointer, KNativePointer);
|
|
251
251
|
|
|
@@ -14,11 +14,56 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
#include <common.h>
|
|
17
|
+
#include <utility>
|
|
17
18
|
|
|
18
19
|
using std::string, std::cout, std::endl, std::vector;
|
|
19
20
|
|
|
20
21
|
static es2panda_Impl *impl = nullptr;
|
|
21
22
|
|
|
23
|
+
static thread_local StageArena currentArena;
|
|
24
|
+
|
|
25
|
+
StageArena* StageArena::instance() {
|
|
26
|
+
return ¤tArena;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void StageArena::add(void* pointer) {
|
|
30
|
+
if (pointer)
|
|
31
|
+
allocated.push_back(pointer);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void StageArena::cleanup() {
|
|
35
|
+
if (totalSize > 0 && false)
|
|
36
|
+
printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize);
|
|
37
|
+
for (auto it : allocated) {
|
|
38
|
+
free(it);
|
|
39
|
+
}
|
|
40
|
+
totalSize = 0;
|
|
41
|
+
allocated.clear();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
StageArena::StageArena() {
|
|
45
|
+
totalSize = 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
StageArena::~StageArena() {
|
|
49
|
+
cleanup();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
char* StageArena::strdup(const char* string) {
|
|
53
|
+
auto* arena = StageArena::instance();
|
|
54
|
+
auto size = strlen(string) + 1;
|
|
55
|
+
char* memory = (char*)arena->alloc(size);
|
|
56
|
+
memcpy(memory, string, size);
|
|
57
|
+
return memory;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void* StageArena::alloc(size_t size) {
|
|
61
|
+
void* result = malloc(size);
|
|
62
|
+
totalSize += size;
|
|
63
|
+
add(result);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
22
67
|
#ifdef KOALA_WINDOWS
|
|
23
68
|
#include <windows.h>
|
|
24
69
|
#define PLUGIN_DIR "windows_host_tools"
|
|
@@ -58,11 +103,13 @@ es2panda_Impl *GetImpl() {
|
|
|
58
103
|
}
|
|
59
104
|
auto library = FindLibrary();
|
|
60
105
|
if (!library) {
|
|
61
|
-
|
|
106
|
+
printf("No library (es2panda_lib.cc)"); // TODO: dont use throw for ohos build
|
|
107
|
+
abort();
|
|
62
108
|
}
|
|
63
109
|
auto symbol = findSymbol(library, "es2panda_GetImpl");
|
|
64
110
|
if (!symbol) {
|
|
65
|
-
|
|
111
|
+
printf("no entry point");
|
|
112
|
+
abort();
|
|
66
113
|
}
|
|
67
114
|
impl = reinterpret_cast<es2panda_Impl *(*)(int)>(symbol)(ES2PANDA_LIB_VERSION);
|
|
68
115
|
return impl;
|
|
@@ -78,7 +125,7 @@ string getString(KStringPtr ptr) {
|
|
|
78
125
|
}
|
|
79
126
|
|
|
80
127
|
char* getStringCopy(KStringPtr& ptr) {
|
|
81
|
-
return strdup(ptr.c_str());
|
|
128
|
+
return StageArena::strdup(ptr.c_str() ? ptr.c_str() : "");
|
|
82
129
|
}
|
|
83
130
|
|
|
84
131
|
inline KUInt unpackUInt(const KByte* bytes) {
|
|
@@ -91,7 +138,7 @@ inline KUInt unpackUInt(const KByte* bytes) {
|
|
|
91
138
|
const KUInt BYTE_2_SHIFT = 16;
|
|
92
139
|
const KUInt BYTE_3_SHIFT = 24;
|
|
93
140
|
return (
|
|
94
|
-
bytes[BYTE_0]
|
|
141
|
+
bytes[BYTE_0]
|
|
95
142
|
| (bytes[BYTE_1] << BYTE_1_SHIFT)
|
|
96
143
|
| (bytes[BYTE_2] << BYTE_2_SHIFT)
|
|
97
144
|
| (bytes[BYTE_3] << BYTE_3_SHIFT)
|
|
@@ -101,13 +148,13 @@ inline KUInt unpackUInt(const KByte* bytes) {
|
|
|
101
148
|
KNativePointer impl_CreateConfig(KInt argc, KStringArray argvPtr) {
|
|
102
149
|
const std::size_t headerLen = 4;
|
|
103
150
|
|
|
104
|
-
const char** argv =
|
|
151
|
+
const char** argv = StageArena::allocArray<const char*>(argc);
|
|
105
152
|
std::size_t position = headerLen;
|
|
106
153
|
std::size_t strLen;
|
|
107
154
|
for (std::size_t i = 0; i < static_cast<std::size_t>(argc); ++i) {
|
|
108
155
|
strLen = unpackUInt(argvPtr + position);
|
|
109
156
|
position += headerLen;
|
|
110
|
-
argv[i] = strdup(std::string(reinterpret_cast<const char*>(argvPtr + position), strLen).c_str());
|
|
157
|
+
argv[i] = StageArena::strdup(std::string(reinterpret_cast<const char*>(argvPtr + position), strLen).c_str());
|
|
111
158
|
position += strLen;
|
|
112
159
|
}
|
|
113
160
|
return GetImpl()->CreateConfig(argc, argv);
|
|
@@ -124,6 +171,7 @@ KOALA_INTEROP_1(DestroyConfig, KNativePointer, KNativePointer)
|
|
|
124
171
|
KNativePointer impl_DestroyContext(KNativePointer contextPtr) {
|
|
125
172
|
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
126
173
|
GetImpl()->DestroyContext(context);
|
|
174
|
+
StageArena::instance()->cleanup();
|
|
127
175
|
return nullptr;
|
|
128
176
|
}
|
|
129
177
|
KOALA_INTEROP_1(DestroyContext, KNativePointer, KNativePointer)
|
|
@@ -148,7 +196,7 @@ KNativePointer impl_UpdateCallExpression(
|
|
|
148
196
|
|
|
149
197
|
auto nn = GetImpl()->CreateCallExpression(
|
|
150
198
|
context, callee, arguments, argumentsLen, typeParams, optional, trailingComma
|
|
151
|
-
);
|
|
199
|
+
);
|
|
152
200
|
GetImpl()->AstNodeSetOriginalNode(context, nn, node);
|
|
153
201
|
return nn;
|
|
154
202
|
}
|
|
@@ -222,7 +270,7 @@ KNativePointer impl_AstNodeChildren(
|
|
|
222
270
|
cachedChildren.clear();
|
|
223
271
|
|
|
224
272
|
GetImpl()->AstNodeIterateConst(context, node, visitChild);
|
|
225
|
-
return
|
|
273
|
+
return StageArena::clone(cachedChildren);
|
|
226
274
|
}
|
|
227
275
|
KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer)
|
|
228
276
|
|
|
@@ -36,4 +36,52 @@ inline KUInt unpackUInt(const KByte* bytes);
|
|
|
36
36
|
|
|
37
37
|
es2panda_ContextState intToState(KInt state);
|
|
38
38
|
|
|
39
|
+
class StageArena {
|
|
40
|
+
std::vector<void*> allocated;
|
|
41
|
+
size_t totalSize;
|
|
42
|
+
public:
|
|
43
|
+
StageArena();
|
|
44
|
+
~StageArena();
|
|
45
|
+
static StageArena* instance();
|
|
46
|
+
template <typename T>
|
|
47
|
+
static T* alloc() {
|
|
48
|
+
auto* arena = StageArena::instance();
|
|
49
|
+
void* memory = arena->alloc(sizeof(T));
|
|
50
|
+
return new (memory) T();
|
|
51
|
+
}
|
|
52
|
+
template <class T, class T1>
|
|
53
|
+
static T* alloc(T1 arg1) {
|
|
54
|
+
auto* arena = StageArena::instance();
|
|
55
|
+
void* memory = arena->alloc(sizeof(T));
|
|
56
|
+
return new (memory) T(std::forward(arg1));
|
|
57
|
+
}
|
|
58
|
+
template <class T, class T1, class T2>
|
|
59
|
+
static T* alloc(T1 arg1, T2 arg2) {
|
|
60
|
+
auto* arena = StageArena::instance();
|
|
61
|
+
void* memory = arena->alloc(sizeof(T));
|
|
62
|
+
return new (memory) T(arg1, arg2);
|
|
63
|
+
}
|
|
64
|
+
template <typename T>
|
|
65
|
+
static T* allocArray(size_t count) {
|
|
66
|
+
auto* arena = StageArena::instance();
|
|
67
|
+
// align?
|
|
68
|
+
void* memory = arena->alloc(sizeof(T) * count);
|
|
69
|
+
return new (memory) T();
|
|
70
|
+
}
|
|
71
|
+
template <class T>
|
|
72
|
+
static T* clone(const T& arg) {
|
|
73
|
+
auto* arena = StageArena::instance();
|
|
74
|
+
void* memory = arena->alloc(sizeof(T));
|
|
75
|
+
return new (memory) T(arg);
|
|
76
|
+
}
|
|
77
|
+
template <class T>
|
|
78
|
+
static std::vector<const void*>* cloneVector(const T* arg, size_t count) {
|
|
79
|
+
return alloc<std::vector<const void*>, const T*, const T*>(arg, arg + count);
|
|
80
|
+
}
|
|
81
|
+
void* alloc(size_t size);
|
|
82
|
+
static char* strdup(const char* original);
|
|
83
|
+
void add(void* pointer);
|
|
84
|
+
void cleanup();
|
|
85
|
+
};
|
|
86
|
+
|
|
39
87
|
#endif // COMMON_H
|