@idlizer/arktscgen 2.1.10-arktscgen-6 → 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/native/meson.build +4 -4
- package/build/libarkts-copy/native/src/{bridges.cc → bridges.cpp} +11 -11
- package/build/libarkts-copy/native/src/{common.cc → common.cpp} +163 -108
- package/build/libarkts-copy/native/src/common.h +22 -22
- package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +9 -3
- package/build/libarkts-copy/package.json +2 -2
- package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +8 -3
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
- package/build/libarkts-copy/src/arkts-api/index.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
- package/build/libarkts-copy/src/arkts-api/peers/Context.ts +0 -1
- package/build/libarkts-copy/src/arkts-api/plugins.ts +3 -10
- package/build/libarkts-copy/src/arkts-api/static/global.ts +0 -3
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +7 -34
- package/build/libarkts-copy/src/index.ts +0 -1
- package/build/libarkts-copy/src/plugin-utils.ts +58 -33
- package/build/libarkts-copy/src/reexport-for-generated.ts +1 -1
- package/build/libarkts-copy/tsconfig.json +0 -3
- package/lib/index.js +218 -36
- package/package.json +2 -2
- 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/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
|
@@ -23,10 +23,10 @@ project(
|
|
|
23
23
|
is_cross = get_option('cross_compile')
|
|
24
24
|
|
|
25
25
|
sources = [
|
|
26
|
-
'./src/common.
|
|
27
|
-
'./src/memoryTracker.
|
|
28
|
-
'./src/bridges.
|
|
29
|
-
'../generated/native/bridges.
|
|
26
|
+
'./src/common.cpp',
|
|
27
|
+
'./src/memoryTracker.cpp',
|
|
28
|
+
'./src/bridges.cpp',
|
|
29
|
+
'../generated/native/bridges.cpp',
|
|
30
30
|
get_option('interop_src_dir') / 'common-interop.cpp',
|
|
31
31
|
get_option('interop_src_dir') / 'callback-resource.cpp',
|
|
32
32
|
get_option('interop_src_dir') / 'interop-logging.cpp',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
3
3
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
* you may not use this file except in compliance with the License.
|
|
5
5
|
* You may obtain a copy of the License at
|
|
@@ -40,7 +40,7 @@ KNativePointer impl_AnnotationAllowedAnnotations(
|
|
|
40
40
|
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
41
41
|
std::size_t params_len = 0;
|
|
42
42
|
auto annotations = GetImpl()->AnnotationAllowedAnnotations(context, node, ¶ms_len);
|
|
43
|
-
return StageArena::
|
|
43
|
+
return StageArena::CloneVector(annotations, params_len);
|
|
44
44
|
}
|
|
45
45
|
KOALA_INTEROP_3(AnnotationAllowedAnnotations, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
|
|
46
46
|
|
|
@@ -51,7 +51,7 @@ KNativePointer impl_AnnotationAllowedAnnotationsConst(
|
|
|
51
51
|
auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
|
|
52
52
|
std::size_t params_len = 0;
|
|
53
53
|
auto annotations = GetImpl()->AnnotationAllowedAnnotationsConst(context, node, ¶ms_len);
|
|
54
|
-
return StageArena::
|
|
54
|
+
return StageArena::CloneVector(annotations, params_len);
|
|
55
55
|
}
|
|
56
56
|
KOALA_INTEROP_3(AnnotationAllowedAnnotationsConst, KNativePointer, KNativePointer, KNativePointer, KNativePointer)
|
|
57
57
|
|
|
@@ -107,7 +107,7 @@ static KNativePointer impl_ProgramExternalSources(KNativePointer contextPtr, KNa
|
|
|
107
107
|
auto&& instance = reinterpret_cast<es2panda_Program*>(instancePtr);
|
|
108
108
|
std::size_t source_len = 0;
|
|
109
109
|
auto external_sources = GetImpl()->ProgramExternalSources(context, instance, &source_len);
|
|
110
|
-
return StageArena::
|
|
110
|
+
return StageArena::CloneVector(external_sources, source_len);
|
|
111
111
|
}
|
|
112
112
|
KOALA_INTEROP_2(ProgramExternalSources, KNativePointer, KNativePointer, KNativePointer);
|
|
113
113
|
|
|
@@ -126,7 +126,7 @@ static KNativePointer impl_ProgramSourceFilePath(KNativePointer contextPtr, KNat
|
|
|
126
126
|
auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
|
|
127
127
|
auto&& instance = reinterpret_cast<es2panda_Program*>(instancePtr);
|
|
128
128
|
auto&& result = GetImpl()->ProgramSourceFilePathConst(context, instance);
|
|
129
|
-
return StageArena::
|
|
129
|
+
return StageArena::Strdup(result);
|
|
130
130
|
}
|
|
131
131
|
KOALA_INTEROP_2(ProgramSourceFilePath, KNativePointer, KNativePointer, KNativePointer);
|
|
132
132
|
|
|
@@ -134,7 +134,7 @@ static KNativePointer impl_ExternalSourceName(KNativePointer instance)
|
|
|
134
134
|
{
|
|
135
135
|
auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource*>(instance);
|
|
136
136
|
auto&& result = GetImpl()->ExternalSourceName(_instance_);
|
|
137
|
-
return StageArena::
|
|
137
|
+
return StageArena::Strdup(result);
|
|
138
138
|
}
|
|
139
139
|
KOALA_INTEROP_1(ExternalSourceName, KNativePointer, KNativePointer);
|
|
140
140
|
|
|
@@ -143,7 +143,7 @@ static KNativePointer impl_ExternalSourcePrograms(KNativePointer instance)
|
|
|
143
143
|
auto&& _instance_ = reinterpret_cast<es2panda_ExternalSource*>(instance);
|
|
144
144
|
std::size_t program_len = 0;
|
|
145
145
|
auto programs = GetImpl()->ExternalSourcePrograms(_instance_, &program_len);
|
|
146
|
-
return StageArena::
|
|
146
|
+
return StageArena::CloneVector(programs, program_len);
|
|
147
147
|
}
|
|
148
148
|
KOALA_INTEROP_1(ExternalSourcePrograms, KNativePointer, KNativePointer);
|
|
149
149
|
|
|
@@ -275,7 +275,7 @@ KNativePointer impl_Checker_TypeToString(KNativePointer context, KNativePointer
|
|
|
275
275
|
auto _context = reinterpret_cast<es2panda_Context*>(context);
|
|
276
276
|
auto _type = reinterpret_cast<es2panda_Type*>(type);
|
|
277
277
|
auto result = GetImpl()->TypeToStringConst(_context, _type);
|
|
278
|
-
return StageArena::
|
|
278
|
+
return StageArena::Strdup(result);
|
|
279
279
|
}
|
|
280
280
|
KOALA_INTEROP_2(Checker_TypeToString, KNativePointer, KNativePointer, KNativePointer)
|
|
281
281
|
|
|
@@ -347,7 +347,7 @@ KNativePointer impl_TSInterfaceBodyBodyPtr(KNativePointer context, KNativePointe
|
|
|
347
347
|
const auto _receiver = reinterpret_cast<es2panda_AstNode*>(receiver);
|
|
348
348
|
std::size_t length;
|
|
349
349
|
auto result = GetImpl()->TSInterfaceBodyBodyPtr(_context, _receiver, &length);
|
|
350
|
-
return StageArena::
|
|
350
|
+
return StageArena::CloneVector(result, length);
|
|
351
351
|
}
|
|
352
352
|
KOALA_INTEROP_2(TSInterfaceBodyBodyPtr, KNativePointer, KNativePointer, KNativePointer);
|
|
353
353
|
|
|
@@ -357,7 +357,7 @@ KNativePointer impl_AnnotationDeclarationPropertiesPtrConst(KNativePointer conte
|
|
|
357
357
|
const auto _receiver = reinterpret_cast<es2panda_AstNode*>(receiver);
|
|
358
358
|
std::size_t length;
|
|
359
359
|
auto result = GetImpl()->AnnotationDeclarationPropertiesPtrConst(_context, _receiver, &length);
|
|
360
|
-
return StageArena::
|
|
360
|
+
return StageArena::CloneVector(result, length);
|
|
361
361
|
}
|
|
362
362
|
KOALA_INTEROP_2(AnnotationDeclarationPropertiesPtrConst, KNativePointer, KNativePointer, KNativePointer);
|
|
363
363
|
|
|
@@ -394,7 +394,7 @@ KNativePointer impl_AnnotationUsageIrPropertiesPtrConst(KNativePointer context,
|
|
|
394
394
|
const auto _receiver = reinterpret_cast<es2panda_AstNode*>(receiver);
|
|
395
395
|
std::size_t length;
|
|
396
396
|
auto result = GetImpl()->AnnotationUsageIrPropertiesPtrConst(_context, _receiver, &length);
|
|
397
|
-
return StageArena::
|
|
397
|
+
return StageArena::CloneVector(result, length);
|
|
398
398
|
}
|
|
399
399
|
KOALA_INTEROP_2(AnnotationUsageIrPropertiesPtrConst, KNativePointer, KNativePointer, KNativePointer);
|
|
400
400
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
3
3
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
* you may not use this file except in compliance with the License.
|
|
5
5
|
* You may obtain a copy of the License at
|
|
@@ -24,22 +24,23 @@
|
|
|
24
24
|
#include "interop-types.h"
|
|
25
25
|
|
|
26
26
|
using std::string, std::cout, std::endl, std::vector;
|
|
27
|
+
constexpr int AST_NODE_TYPE_LIMIT = 256;
|
|
27
28
|
|
|
28
29
|
es2panda_Impl* es2pandaImplementation = nullptr;
|
|
29
30
|
static thread_local StageArena currentArena;
|
|
30
31
|
|
|
31
|
-
StageArena* StageArena::
|
|
32
|
+
StageArena* StageArena::Instance()
|
|
32
33
|
{
|
|
33
34
|
return ¤tArena;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
void StageArena::
|
|
37
|
+
void StageArena::Add(void* pointer)
|
|
37
38
|
{
|
|
38
39
|
if (pointer)
|
|
39
40
|
allocated.push_back(pointer);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
void StageArena::
|
|
43
|
+
void StageArena::Cleanup()
|
|
43
44
|
{
|
|
44
45
|
if (totalSize > 0 && false)
|
|
45
46
|
printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize);
|
|
@@ -57,26 +58,26 @@ StageArena::StageArena()
|
|
|
57
58
|
|
|
58
59
|
StageArena::~StageArena()
|
|
59
60
|
{
|
|
60
|
-
|
|
61
|
+
Cleanup();
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
char* StageArena::
|
|
64
|
+
char* StageArena::Strdup(const char* string)
|
|
64
65
|
{
|
|
65
|
-
auto* arena = StageArena::
|
|
66
|
+
auto* arena = StageArena::Instance();
|
|
66
67
|
auto size = strlen(string) + 1;
|
|
67
|
-
char* memory = (char*)arena->
|
|
68
|
+
char* memory = (char*)arena->Alloc(size);
|
|
68
69
|
interop_memcpy(memory, size, string, size);
|
|
69
70
|
return memory;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
void* StageArena::
|
|
73
|
+
void* StageArena::Alloc(size_t size)
|
|
73
74
|
{
|
|
74
75
|
void* result = malloc(size);
|
|
75
76
|
if (!result) {
|
|
76
77
|
INTEROP_FATAL("Cannot allocate memory");
|
|
77
78
|
}
|
|
78
79
|
totalSize += size;
|
|
79
|
-
|
|
80
|
+
Add(result);
|
|
80
81
|
return result;
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -178,7 +179,6 @@ void* TryLibrary(const char* name)
|
|
|
178
179
|
return nullptr;
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
// TODO: @panda/sdk will be changed to match ohos-sdk
|
|
182
182
|
void* FindLibrary()
|
|
183
183
|
{
|
|
184
184
|
void* res = nullptr;
|
|
@@ -227,7 +227,7 @@ const char** getStringArray(KStringArray& ptr)
|
|
|
227
227
|
|
|
228
228
|
char* getStringCopy(KStringPtr& ptr)
|
|
229
229
|
{
|
|
230
|
-
return StageArena::
|
|
230
|
+
return StageArena::Strdup(ptr.c_str() ? ptr.c_str() : "");
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
void impl_DestroyConfig(KNativePointer config)
|
|
@@ -236,27 +236,51 @@ void impl_DestroyConfig(KNativePointer config)
|
|
|
236
236
|
// panda prints diagnostics here and do not clone our strings
|
|
237
237
|
// so keep arena alive until this moment.
|
|
238
238
|
GetImpl()->DestroyConfig(_config);
|
|
239
|
-
StageArena::
|
|
239
|
+
StageArena::Instance()->Cleanup();
|
|
240
240
|
printf("[libarkts native] Arena cleaned up!\n");
|
|
241
241
|
}
|
|
242
|
-
KOALA_INTEROP_V1(DestroyConfig, KNativePointer)
|
|
242
|
+
KOALA_INTEROP_V1(DestroyConfig, KNativePointer)
|
|
243
|
+
|
|
244
|
+
// ─── Helpers to lower function size/complexity ────────────────────────────────
|
|
245
|
+
namespace {
|
|
246
|
+
template <class T, class U>
|
|
247
|
+
inline T As(U v) { return reinterpret_cast<T>(v); }
|
|
248
|
+
|
|
249
|
+
struct CallExprArgs {
|
|
250
|
+
es2panda_Context* context;
|
|
251
|
+
es2panda_AstNode* node;
|
|
252
|
+
es2panda_AstNode* callee;
|
|
253
|
+
es2panda_AstNode** arguments;
|
|
254
|
+
KInt argumentsLen;
|
|
255
|
+
es2panda_AstNode* typeParams;
|
|
256
|
+
bool optional;
|
|
257
|
+
bool trailingComma;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
inline KNativePointer DoUpdateCallExpression(const CallExprArgs& a)
|
|
261
|
+
{
|
|
262
|
+
auto nn = GetImpl()->CreateCallExpression(
|
|
263
|
+
a.context, a.callee, a.arguments, a.argumentsLen, a.typeParams, a.optional, a.trailingComma);
|
|
264
|
+
GetImpl()->AstNodeSetOriginalNode(a.context, nn, a.node);
|
|
265
|
+
return nn;
|
|
266
|
+
}
|
|
267
|
+
} // namespace
|
|
243
268
|
|
|
244
269
|
KNativePointer impl_UpdateCallExpression(KNativePointer contextPtr, KNativePointer nodePtr, KNativePointer calleePtr,
|
|
245
270
|
KNativePointerArray argumentsPtr, KInt argumentsLen, KNativePointer typeParamsPtr, KBoolean optionalT,
|
|
246
271
|
KBoolean trailingCommaT)
|
|
247
272
|
{
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return nn;
|
|
273
|
+
const CallExprArgs a{
|
|
274
|
+
As<es2panda_Context*>(contextPtr),
|
|
275
|
+
As<es2panda_AstNode*>(nodePtr),
|
|
276
|
+
As<es2panda_AstNode*>(calleePtr),
|
|
277
|
+
As<es2panda_AstNode**>(argumentsPtr),
|
|
278
|
+
argumentsLen,
|
|
279
|
+
As<es2panda_AstNode*>(typeParamsPtr),
|
|
280
|
+
static_cast<bool>(optionalT),
|
|
281
|
+
static_cast<bool>(trailingCommaT),
|
|
282
|
+
};
|
|
283
|
+
return DoUpdateCallExpression(a);
|
|
260
284
|
}
|
|
261
285
|
KOALA_INTEROP_8(UpdateCallExpression, KNativePointer, KNativePointer, KNativePointer, KNativePointer,
|
|
262
286
|
KNativePointerArray, KInt, KNativePointer, KBoolean, KBoolean)
|
|
@@ -367,7 +391,7 @@ KNativePointer impl_AstNodeChildren(KNativePointer contextPtr, KNativePointer no
|
|
|
367
391
|
cachedChildren.clear();
|
|
368
392
|
|
|
369
393
|
GetImpl()->AstNodeIterateConst(context, node, visitChild);
|
|
370
|
-
return StageArena::
|
|
394
|
+
return StageArena::Clone(cachedChildren);
|
|
371
395
|
}
|
|
372
396
|
KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer);
|
|
373
397
|
|
|
@@ -380,10 +404,29 @@ struct Pattern {
|
|
|
380
404
|
std::regex regex;
|
|
381
405
|
|
|
382
406
|
Pattern(const Pattern&) = delete;
|
|
407
|
+
Pattern& operator=(const Pattern&) = default;
|
|
408
|
+
|
|
409
|
+
Pattern(Pattern&& other) noexcept
|
|
410
|
+
: context(other.context),
|
|
411
|
+
key(std::move(other.key)),
|
|
412
|
+
value(std::move(other.value)),
|
|
413
|
+
impl(other.impl),
|
|
414
|
+
isWildcard(other.isWildcard),
|
|
415
|
+
regex(other.regex)
|
|
416
|
+
{
|
|
417
|
+
other.isWildcard = false;
|
|
418
|
+
}
|
|
383
419
|
|
|
384
|
-
Pattern(Pattern&& other) noexcept
|
|
385
|
-
|
|
420
|
+
Pattern& operator=(Pattern&& other) noexcept
|
|
421
|
+
{
|
|
422
|
+
context = other.context;
|
|
423
|
+
key = std::move(other.key);
|
|
424
|
+
value = std::move(other.value);
|
|
425
|
+
impl = other.impl;
|
|
426
|
+
isWildcard = other.isWildcard;
|
|
427
|
+
regex = other.regex;
|
|
386
428
|
other.isWildcard = false;
|
|
429
|
+
return *this;
|
|
387
430
|
}
|
|
388
431
|
|
|
389
432
|
Pattern(es2panda_Context* context, const std::string& part) : context(context), impl(GetImpl())
|
|
@@ -392,95 +435,102 @@ struct Pattern {
|
|
|
392
435
|
std::getline(stream, key, '=');
|
|
393
436
|
std::getline(stream, value, '=');
|
|
394
437
|
isWildcard = value.find('*') != std::string::npos;
|
|
395
|
-
|
|
396
438
|
if (isWildcard) {
|
|
397
439
|
this->regex = std::regex(value);
|
|
398
440
|
}
|
|
399
441
|
}
|
|
400
|
-
|
|
442
|
+
|
|
401
443
|
~Pattern() = default;
|
|
402
444
|
|
|
403
445
|
bool match(es2panda_AstNode* node) const
|
|
404
446
|
{
|
|
405
447
|
if (key == "type") {
|
|
406
|
-
|
|
407
|
-
switch (type) {
|
|
408
|
-
case Es2pandaAstNodeType::AST_NODE_TYPE_METHOD_DEFINITION:
|
|
409
|
-
return value == "method";
|
|
410
|
-
case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION:
|
|
411
|
-
return value == "function";
|
|
412
|
-
case Es2pandaAstNodeType::AST_NODE_TYPE_STRUCT_DECLARATION:
|
|
413
|
-
return value == "struct";
|
|
414
|
-
case Es2pandaAstNodeType::AST_NODE_TYPE_CALL_EXPRESSION:
|
|
415
|
-
return value == "call";
|
|
416
|
-
case Es2pandaAstNodeType::AST_NODE_TYPE_ASSIGNMENT_EXPRESSION:
|
|
417
|
-
return value == "assignment";
|
|
418
|
-
default:
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
448
|
+
return matchByType(node, impl->AstNodeTypeConst(context, node));
|
|
421
449
|
}
|
|
422
450
|
if (key == "annotation") {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
451
|
+
return matchByAnnotation(node, impl->AstNodeTypeConst(context, node));
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
bool matchByType(es2panda_AstNode* node, Es2pandaAstNodeType type) const
|
|
457
|
+
{
|
|
458
|
+
switch (type) {
|
|
459
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_METHOD_DEFINITION:
|
|
460
|
+
return value == "method";
|
|
461
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION:
|
|
462
|
+
return value == "function";
|
|
463
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_STRUCT_DECLARATION:
|
|
464
|
+
return value == "struct";
|
|
465
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_CALL_EXPRESSION:
|
|
466
|
+
return value == "call";
|
|
467
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_ASSIGNMENT_EXPRESSION:
|
|
468
|
+
return value == "assignment";
|
|
469
|
+
default:
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
bool matchByAnnotation(es2panda_AstNode* node, Es2pandaAstNodeType type) const
|
|
475
|
+
{
|
|
476
|
+
std::size_t length = 0;
|
|
477
|
+
es2panda_AstNode** result = nullptr;
|
|
478
|
+
switch (type) {
|
|
479
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION: {
|
|
480
|
+
result = impl->ScriptFunctionAnnotations(context, node, &length);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_FUNCTION_DECLARATION: {
|
|
484
|
+
result = impl->FunctionDeclarationAnnotations(context, node, &length);
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION: {
|
|
488
|
+
result = impl->ArrowFunctionExpressionAnnotations(context, node, &length);
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_FUNCTION_TYPE: {
|
|
492
|
+
result = impl->TypeNodeAnnotations(context, node, &length);
|
|
493
|
+
break;
|
|
465
494
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const char* name = impl->IdentifierNameConst(context, ident);
|
|
470
|
-
found |= matchWildcard(value, name);
|
|
495
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION: {
|
|
496
|
+
result = impl->TSTypeAliasDeclarationAnnotations(context, node, &length);
|
|
497
|
+
break;
|
|
471
498
|
}
|
|
472
|
-
|
|
499
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_VARIABLE_DECLARATION: {
|
|
500
|
+
result = impl->VariableDeclarationAnnotations(context, node, &length);
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_UNION_TYPE: {
|
|
504
|
+
result = impl->TypeNodeAnnotations(context, node, &length);
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_CLASS_PROPERTY: {
|
|
508
|
+
result = impl->ClassPropertyAnnotations(context, node, &length);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION: {
|
|
512
|
+
result = impl->ETSParameterExpressionAnnotations(context, node, &length);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
default:
|
|
516
|
+
return false;
|
|
473
517
|
}
|
|
474
|
-
|
|
518
|
+
|
|
519
|
+
bool found = false;
|
|
520
|
+
for (std::size_t i = 0; i < length && result; i++) {
|
|
521
|
+
es2panda_AstNode* ident = impl->AnnotationUsageIrGetBaseNameConst(context, result[i]);
|
|
522
|
+
found |= MatchWildcard(value, impl->IdentifierNameConst(context, ident));
|
|
523
|
+
}
|
|
524
|
+
return found;
|
|
475
525
|
}
|
|
476
526
|
|
|
477
|
-
bool
|
|
527
|
+
bool MatchWildcard(const std::string& pattern, const char* foundValue) const
|
|
478
528
|
{
|
|
479
529
|
if (!isWildcard) {
|
|
480
|
-
return pattern ==
|
|
530
|
+
return pattern == foundValue;
|
|
481
531
|
}
|
|
482
532
|
|
|
483
|
-
return std::regex_search(
|
|
533
|
+
return std::regex_search(foundValue, this->regex);
|
|
484
534
|
}
|
|
485
535
|
};
|
|
486
536
|
|
|
@@ -507,11 +557,11 @@ struct Matcher {
|
|
|
507
557
|
}
|
|
508
558
|
};
|
|
509
559
|
|
|
510
|
-
KNativePointer
|
|
560
|
+
static KNativePointer DoFilterNodes(es2panda_Context* _context,
|
|
561
|
+
es2panda_AstNode* _node,
|
|
562
|
+
const char* _filters,
|
|
563
|
+
bool deeperAfterMatch)
|
|
511
564
|
{
|
|
512
|
-
auto _node = reinterpret_cast<es2panda_AstNode*>(node);
|
|
513
|
-
auto _context = reinterpret_cast<es2panda_Context*>(context);
|
|
514
|
-
const char* _filters = filters.c_str();
|
|
515
565
|
std::vector<es2panda_AstNode*> result;
|
|
516
566
|
es2panda_Impl* impl = GetImpl();
|
|
517
567
|
Matcher matcher(_context, _filters);
|
|
@@ -526,18 +576,23 @@ KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, con
|
|
|
526
576
|
}
|
|
527
577
|
if (!isMatch || deeperAfterMatch) {
|
|
528
578
|
impl->AstNodeIterateConst(_context, current, visitChild);
|
|
529
|
-
// We want to retain match order, so add children in reverse order.
|
|
530
579
|
for (auto it = cachedChildren.rbegin(); it != cachedChildren.rend(); ++it) {
|
|
531
580
|
queue.push_back(*it);
|
|
532
581
|
}
|
|
533
582
|
cachedChildren.clear();
|
|
534
583
|
}
|
|
535
584
|
}
|
|
536
|
-
return StageArena::
|
|
585
|
+
return StageArena::CloneVector(result.data(), result.size());
|
|
537
586
|
}
|
|
538
|
-
KOALA_INTEROP_4(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr, KBoolean)
|
|
539
587
|
|
|
540
|
-
|
|
588
|
+
KNativePointer impl_FilterNodes(
|
|
589
|
+
KNativePointer context, KNativePointer node, const KStringPtr& filters, KBoolean deeperAfterMatch)
|
|
590
|
+
{
|
|
591
|
+
auto* _node = reinterpret_cast<es2panda_AstNode*>(node);
|
|
592
|
+
auto* _context = reinterpret_cast<es2panda_Context*>(context);
|
|
593
|
+
return DoFilterNodes(_context, _node, filters.c_str(), static_cast<bool>(deeperAfterMatch));
|
|
594
|
+
}
|
|
595
|
+
KOALA_INTEROP_4(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr, KBoolean)
|
|
541
596
|
|
|
542
597
|
struct FilterArgs {
|
|
543
598
|
es2panda_Impl *impl;
|
|
@@ -564,7 +619,7 @@ KNativePointer impl_FilterNodes2(KNativePointer context, KNativePointer node, KI
|
|
|
564
619
|
std::vector<es2panda_AstNode *> result;
|
|
565
620
|
FilterArgs args = { GetImpl(), _context, &typesMask, &result };
|
|
566
621
|
GetImpl()->AstNodeForEach(_node, filterByType, &args);
|
|
567
|
-
return StageArena::
|
|
622
|
+
return StageArena::CloneVector(result.data(), result.size());
|
|
568
623
|
}
|
|
569
624
|
KOALA_INTEROP_3(FilterNodes2, KNativePointer, KNativePointer, KNativePointer, KInt)
|
|
570
625
|
|
|
@@ -579,7 +634,7 @@ KNativePointer impl_FilterNodes3(KNativePointer context, KNativePointer node, KI
|
|
|
579
634
|
std::vector<es2panda_AstNode *> result;
|
|
580
635
|
FilterArgs args = { GetImpl(), _context, &typesMask, &result };
|
|
581
636
|
GetImpl()->AstNodeForEach(_node, filterByType, &args);
|
|
582
|
-
return StageArena::
|
|
637
|
+
return StageArena::CloneVector(result.data(), result.size());
|
|
583
638
|
}
|
|
584
639
|
KOALA_INTEROP_4(FilterNodes3, KNativePointer, KNativePointer, KNativePointer, KInt*, KInt)
|
|
585
640
|
|
|
@@ -82,52 +82,52 @@ class StageArena {
|
|
|
82
82
|
public:
|
|
83
83
|
StageArena();
|
|
84
84
|
~StageArena();
|
|
85
|
-
static StageArena*
|
|
85
|
+
static StageArena* Instance();
|
|
86
86
|
template<typename T>
|
|
87
|
-
static T*
|
|
87
|
+
static T* Alloc()
|
|
88
88
|
{
|
|
89
|
-
auto* arena = StageArena::
|
|
90
|
-
void* memory = arena->
|
|
89
|
+
auto* arena = StageArena::Instance();
|
|
90
|
+
void* memory = arena->Alloc(sizeof(T));
|
|
91
91
|
return new (memory) T();
|
|
92
92
|
}
|
|
93
93
|
template<class T, class T1>
|
|
94
|
-
static T*
|
|
94
|
+
static T* Alloc(T1 arg1)
|
|
95
95
|
{
|
|
96
|
-
auto* arena = StageArena::
|
|
97
|
-
void* memory = arena->
|
|
96
|
+
auto* arena = StageArena::Instance();
|
|
97
|
+
void* memory = arena->Alloc(sizeof(T));
|
|
98
98
|
return new (memory) T(std::forward(arg1));
|
|
99
99
|
}
|
|
100
100
|
template<class T, class T1, class T2>
|
|
101
|
-
static T*
|
|
101
|
+
static T* Alloc(T1 arg1, T2 arg2)
|
|
102
102
|
{
|
|
103
|
-
auto* arena = StageArena::
|
|
104
|
-
void* memory = arena->
|
|
103
|
+
auto* arena = StageArena::Instance();
|
|
104
|
+
void* memory = arena->Alloc(sizeof(T));
|
|
105
105
|
return new (memory) T(arg1, arg2);
|
|
106
106
|
}
|
|
107
107
|
template<typename T>
|
|
108
|
-
static T*
|
|
108
|
+
static T* AllocArray(size_t count)
|
|
109
109
|
{
|
|
110
|
-
auto* arena = StageArena::
|
|
110
|
+
auto* arena = StageArena::Instance();
|
|
111
111
|
// align?
|
|
112
|
-
void* memory = arena->
|
|
112
|
+
void* memory = arena->Alloc(sizeof(T) * count);
|
|
113
113
|
return new (memory) T();
|
|
114
114
|
}
|
|
115
115
|
template<class T>
|
|
116
|
-
static T*
|
|
116
|
+
static T* Clone(const T& arg)
|
|
117
117
|
{
|
|
118
|
-
auto* arena = StageArena::
|
|
119
|
-
void* memory = arena->
|
|
118
|
+
auto* arena = StageArena::Instance();
|
|
119
|
+
void* memory = arena->Alloc(sizeof(T));
|
|
120
120
|
return new (memory) T(arg);
|
|
121
121
|
}
|
|
122
122
|
template<class T>
|
|
123
|
-
static std::vector<const void*>*
|
|
123
|
+
static std::vector<const void*>* CloneVector(const T* arg, size_t count)
|
|
124
124
|
{
|
|
125
|
-
return
|
|
125
|
+
return Alloc<std::vector<const void*>, const T*, const T*>(arg, arg + count);
|
|
126
126
|
}
|
|
127
|
-
void*
|
|
128
|
-
static char*
|
|
129
|
-
void
|
|
130
|
-
void
|
|
127
|
+
void* Alloc(size_t size);
|
|
128
|
+
static char* Strdup(const char* original);
|
|
129
|
+
void Add(void* pointer);
|
|
130
|
+
void Cleanup();
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
#endif // COMMON_H
|
|
@@ -163,9 +163,15 @@ void MemoryTracker::Report(MemoryStats stats)
|
|
|
163
163
|
const double mb = kb * BYTES_PER_KB;
|
|
164
164
|
const double gb = mb * BYTES_PER_KB;
|
|
165
165
|
|
|
166
|
-
if (bytes > gb)
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
if (bytes > gb) {
|
|
167
|
+
return std::to_string(bytes / gb) + " GB";
|
|
168
|
+
}
|
|
169
|
+
if (bytes > mb) {
|
|
170
|
+
return std::to_string(bytes / mb) + " MB";
|
|
171
|
+
}
|
|
172
|
+
if (bytes > kb) {
|
|
173
|
+
return std::to_string(bytes / kb) + " KB";
|
|
174
|
+
}
|
|
169
175
|
return std::to_string(bytes) + " B";
|
|
170
176
|
};
|
|
171
177
|
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"tsconfig-paths": "^4.2.0",
|
|
43
43
|
"rimraf": "^6.0.1",
|
|
44
44
|
"@koalaui/fast-arktsc": "1.7.10+devel",
|
|
45
|
-
"@idlizer/arktscgen": "2.1.10-arktscgen-
|
|
45
|
+
"@idlizer/arktscgen": "2.1.10-arktscgen-6",
|
|
46
46
|
"mocha": "^9.2.2",
|
|
47
47
|
"@koalaui/harness": "1.7.10+devel",
|
|
48
48
|
"@koalaui/ets-tsc": "4.9.5-r6",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"compile": "npm run regenerate && npm run compile:native && npm run compile:js",
|
|
64
64
|
"compile:current": "npm run regenerate:current && npm run compile:native && npm run compile:js",
|
|
65
65
|
"compile:release": "npm run regenerate && npm run crosscompile:native && npm run compile:js",
|
|
66
|
-
"compile:js": "rm -rf lib/ && rollup -c rollup.
|
|
66
|
+
"compile:js": "rm -rf lib/ && rollup -c rollup.libarkts.mjs && rollup -c rollup.es2panda.mjs",
|
|
67
67
|
"compile:plugins": "rollup -c ./rollup.printer-plugin.mjs",
|
|
68
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
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",
|