@idlizer/arktscgen 2.1.10-arktscgen-6 → 2.1.10-arktscgen-9

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.
Files changed (41) hide show
  1. package/build/libarkts-copy/generator/options.json5 +88 -97
  2. package/build/libarkts-copy/native/meson.build +60 -7
  3. package/build/libarkts-copy/native/mingw.cross +2 -5
  4. package/build/libarkts-copy/native/src/bridges.cpp +175 -0
  5. package/build/libarkts-copy/native/src/{common.cc → common.cpp} +176 -139
  6. package/build/libarkts-copy/native/src/common.h +22 -37
  7. package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +9 -3
  8. package/build/libarkts-copy/package.json +5 -9
  9. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +0 -56
  10. package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +8 -3
  11. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
  12. package/build/libarkts-copy/src/arkts-api/index.ts +0 -2
  13. package/build/libarkts-copy/src/arkts-api/node-utilities/OpaqueTypeNode.ts +1 -1
  14. package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
  15. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +25 -59
  16. package/build/libarkts-copy/src/arkts-api/peers/ExternalSource.ts +8 -13
  17. package/build/libarkts-copy/src/arkts-api/plugins.ts +5 -12
  18. package/build/libarkts-copy/src/arkts-api/static/global.ts +8 -4
  19. package/build/libarkts-copy/src/arkts-api/static/profiler.ts +4 -4
  20. package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +9 -12
  21. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +10 -34
  22. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +8 -5
  23. package/build/libarkts-copy/src/index.ts +0 -2
  24. package/build/libarkts-copy/src/plugin-utils.ts +60 -34
  25. package/build/libarkts-copy/src/reexport-for-generated.ts +3 -2
  26. package/build/libarkts-copy/tsconfig.json +0 -3
  27. package/lib/index.js +505 -216
  28. package/package.json +3 -4
  29. package/templates/Es2pandaNativeModule.ts +1 -0
  30. package/templates/{bridges.cc → bridges.cpp} +1 -1
  31. package/templates/peer.ts +1 -0
  32. package/build/libarkts-copy/native/src/bridges.cc +0 -443
  33. package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +0 -45
  34. package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +0 -1250
  35. package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +0 -125
  36. package/build/libarkts-copy/src/ts-api/index.ts +0 -27
  37. package/build/libarkts-copy/src/ts-api/static/enums.ts +0 -18
  38. package/build/libarkts-copy/src/ts-api/types.ts +0 -1075
  39. package/build/libarkts-copy/src/ts-api/utilities/private.ts +0 -292
  40. package/build/libarkts-copy/src/ts-api/utilities/public.ts +0 -55
  41. package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +0 -139
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
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
@@ -22,24 +22,26 @@
22
22
  #include <bitset>
23
23
 
24
24
  #include "interop-types.h"
25
+ #include "memoryTracker.h"
25
26
 
26
27
  using std::string, std::cout, std::endl, std::vector;
28
+ constexpr int AST_NODE_TYPE_LIMIT = 256;
27
29
 
28
30
  es2panda_Impl* es2pandaImplementation = nullptr;
29
31
  static thread_local StageArena currentArena;
30
32
 
31
- StageArena* StageArena::instance()
33
+ StageArena* StageArena::Instance()
32
34
  {
33
35
  return &currentArena;
34
36
  }
35
37
 
36
- void StageArena::add(void* pointer)
38
+ void StageArena::Add(void* pointer)
37
39
  {
38
40
  if (pointer)
39
41
  allocated.push_back(pointer);
40
42
  }
41
43
 
42
- void StageArena::cleanup()
44
+ void StageArena::Cleanup()
43
45
  {
44
46
  if (totalSize > 0 && false)
45
47
  printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize);
@@ -57,26 +59,26 @@ StageArena::StageArena()
57
59
 
58
60
  StageArena::~StageArena()
59
61
  {
60
- cleanup();
62
+ Cleanup();
61
63
  }
62
64
 
63
- char* StageArena::strdup(const char* string)
65
+ char* StageArena::Strdup(const char* string)
64
66
  {
65
- auto* arena = StageArena::instance();
67
+ auto* arena = StageArena::Instance();
66
68
  auto size = strlen(string) + 1;
67
- char* memory = (char*)arena->alloc(size);
69
+ char* memory = (char*)arena->Alloc(size);
68
70
  interop_memcpy(memory, size, string, size);
69
71
  return memory;
70
72
  }
71
73
 
72
- void* StageArena::alloc(size_t size)
74
+ void* StageArena::Alloc(size_t size)
73
75
  {
74
76
  void* result = malloc(size);
75
77
  if (!result) {
76
78
  INTEROP_FATAL("Cannot allocate memory");
77
79
  }
78
80
  totalSize += size;
79
- add(result);
81
+ Add(result);
80
82
  return result;
81
83
  }
82
84
 
@@ -178,7 +180,6 @@ void* TryLibrary(const char* name)
178
180
  return nullptr;
179
181
  }
180
182
 
181
- // TODO: @panda/sdk will be changed to match ohos-sdk
182
183
  void* FindLibrary()
183
184
  {
184
185
  void* res = nullptr;
@@ -227,7 +228,7 @@ const char** getStringArray(KStringArray& ptr)
227
228
 
228
229
  char* getStringCopy(KStringPtr& ptr)
229
230
  {
230
- return StageArena::strdup(ptr.c_str() ? ptr.c_str() : "");
231
+ return StageArena::Strdup(ptr.c_str() ? ptr.c_str() : "");
231
232
  }
232
233
 
233
234
  void impl_DestroyConfig(KNativePointer config)
@@ -236,41 +237,10 @@ void impl_DestroyConfig(KNativePointer config)
236
237
  // panda prints diagnostics here and do not clone our strings
237
238
  // so keep arena alive until this moment.
238
239
  GetImpl()->DestroyConfig(_config);
239
- StageArena::instance()->cleanup();
240
+ StageArena::Instance()->Cleanup();
240
241
  printf("[libarkts native] Arena cleaned up!\n");
241
242
  }
242
- KOALA_INTEROP_V1(DestroyConfig, KNativePointer);
243
-
244
- KNativePointer impl_UpdateCallExpression(KNativePointer contextPtr, KNativePointer nodePtr, KNativePointer calleePtr,
245
- KNativePointerArray argumentsPtr, KInt argumentsLen, KNativePointer typeParamsPtr, KBoolean optionalT,
246
- KBoolean trailingCommaT)
247
- {
248
- auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
249
- auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
250
- auto callee = reinterpret_cast<es2panda_AstNode*>(calleePtr);
251
- auto arguments = reinterpret_cast<es2panda_AstNode**>(argumentsPtr);
252
- auto typeParams = reinterpret_cast<es2panda_AstNode*>(typeParamsPtr);
253
- auto optional = static_cast<bool>(optionalT);
254
- auto trailingComma = static_cast<bool>(trailingCommaT);
255
-
256
- auto nn =
257
- GetImpl()->CreateCallExpression(context, callee, arguments, argumentsLen, typeParams, optional, trailingComma);
258
- GetImpl()->AstNodeSetOriginalNode(context, nn, node);
259
- return nn;
260
- }
261
- KOALA_INTEROP_8(UpdateCallExpression, KNativePointer, KNativePointer, KNativePointer, KNativePointer,
262
- KNativePointerArray, KInt, KNativePointer, KBoolean, KBoolean)
263
-
264
- KInt impl_IdentifierIdentifierFlags(KNativePointer contextPtr, KNativePointer nodePtr)
265
- {
266
- auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
267
- auto node = reinterpret_cast<es2panda_AstNode*>(nodePtr);
268
-
269
- return (GetImpl()->IdentifierIsOptionalConst(context, node) ? (1 << 0) : 0) |
270
- (GetImpl()->IdentifierIsReferenceConst(context, node) ? (1 << 1) : 0) |
271
- (GetImpl()->IdentifierIsTdzConst(context, node) ? (1 << 2) : 0);
272
- }
273
- KOALA_INTEROP_2(IdentifierIdentifierFlags, KInt, KNativePointer, KNativePointer)
243
+ KOALA_INTEROP_V1(DestroyConfig, KNativePointer)
274
244
 
275
245
  void impl_ClassDefinitionSetBody(
276
246
  KNativePointer context, KNativePointer receiver, KNativePointerArray body, KUInt bodyLength)
@@ -367,7 +337,7 @@ KNativePointer impl_AstNodeChildren(KNativePointer contextPtr, KNativePointer no
367
337
  cachedChildren.clear();
368
338
 
369
339
  GetImpl()->AstNodeIterateConst(context, node, visitChild);
370
- return StageArena::clone(cachedChildren);
340
+ return StageArena::Clone(cachedChildren);
371
341
  }
372
342
  KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer);
373
343
 
@@ -380,10 +350,29 @@ struct Pattern {
380
350
  std::regex regex;
381
351
 
382
352
  Pattern(const Pattern&) = delete;
353
+ Pattern& operator=(const Pattern&) = default;
354
+
355
+ Pattern(Pattern&& other) noexcept
356
+ : context(other.context),
357
+ key(std::move(other.key)),
358
+ value(std::move(other.value)),
359
+ impl(other.impl),
360
+ isWildcard(other.isWildcard),
361
+ regex(other.regex)
362
+ {
363
+ other.isWildcard = false;
364
+ }
383
365
 
384
- Pattern(Pattern&& other) noexcept :
385
- context(other.context), key(std::move(other.key)), value(std::move(other.value)), impl(other.impl), isWildcard(other.isWildcard), regex(other.regex) {
366
+ Pattern& operator=(Pattern&& other) noexcept
367
+ {
368
+ context = other.context;
369
+ key = std::move(other.key);
370
+ value = std::move(other.value);
371
+ impl = other.impl;
372
+ isWildcard = other.isWildcard;
373
+ regex = other.regex;
386
374
  other.isWildcard = false;
375
+ return *this;
387
376
  }
388
377
 
389
378
  Pattern(es2panda_Context* context, const std::string& part) : context(context), impl(GetImpl())
@@ -392,95 +381,104 @@ struct Pattern {
392
381
  std::getline(stream, key, '=');
393
382
  std::getline(stream, value, '=');
394
383
  isWildcard = value.find('*') != std::string::npos;
395
-
396
384
  if (isWildcard) {
397
385
  this->regex = std::regex(value);
398
386
  }
399
387
  }
400
-
388
+
401
389
  ~Pattern() = default;
402
390
 
403
391
  bool match(es2panda_AstNode* node) const
404
392
  {
405
393
  if (key == "type") {
406
- auto type = impl->AstNodeTypeConst(context, node);
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
- }
394
+ return matchByType(node, impl->AstNodeTypeConst(context, node));
421
395
  }
422
396
  if (key == "annotation") {
423
- std::size_t length = 0;
424
- Es2pandaAstNodeType type = impl->AstNodeTypeConst(context, node);
425
- es2panda_AstNode** result = nullptr;
426
- switch (type) {
427
- case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION: {
428
- result = impl->ScriptFunctionAnnotations(context, node, &length);
429
- break;
430
- }
431
- case Es2pandaAstNodeType::AST_NODE_TYPE_FUNCTION_DECLARATION: {
432
- result = impl->FunctionDeclarationAnnotations(context, node, &length);
433
- break;
434
- }
435
- case Es2pandaAstNodeType::AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION: {
436
- result = impl->ArrowFunctionExpressionAnnotations(context, node, &length);
437
- break;
438
- }
439
- case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_FUNCTION_TYPE: {
440
- result = impl->TypeNodeAnnotations(context, node, &length);
441
- break;
442
- }
443
- case Es2pandaAstNodeType::AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION: {
444
- result = impl->TSTypeAliasDeclarationAnnotations(context, node, &length);
445
- break;
446
- }
447
- case Es2pandaAstNodeType::AST_NODE_TYPE_VARIABLE_DECLARATION: {
448
- result = impl->VariableDeclarationAnnotations(context, node, &length);
449
- break;
450
- }
451
- case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_UNION_TYPE: {
452
- result = impl->TypeNodeAnnotations(context, node, &length);
453
- break;
454
- }
455
- case Es2pandaAstNodeType::AST_NODE_TYPE_CLASS_PROPERTY: {
456
- result = impl->ClassPropertyAnnotations(context, node, &length);
457
- break;
458
- }
459
- case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION: {
460
- result = impl->ETSParameterExpressionAnnotations(context, node, &length);
461
- break;
462
- }
463
- default:
464
- return false;
397
+ return matchByAnnotation(node, impl->AstNodeTypeConst(context, node));
398
+ }
399
+ return false;
400
+ }
401
+
402
+ bool matchByType(es2panda_AstNode* node, Es2pandaAstNodeType type) const
403
+ {
404
+ switch (type) {
405
+ case Es2pandaAstNodeType::AST_NODE_TYPE_METHOD_DEFINITION:
406
+ return value == "method";
407
+ case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION:
408
+ return value == "function";
409
+ case Es2pandaAstNodeType::AST_NODE_TYPE_STRUCT_DECLARATION:
410
+ return value == "struct";
411
+ case Es2pandaAstNodeType::AST_NODE_TYPE_CALL_EXPRESSION:
412
+ return value == "call";
413
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_IMPORT_DECLARATION:
414
+ return value == "import";
415
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ASSIGNMENT_EXPRESSION:
416
+ return value == "assignment";
417
+ default:
418
+ return false;
419
+ }
420
+ }
421
+
422
+ bool matchByAnnotation(es2panda_AstNode* node, Es2pandaAstNodeType type) const
423
+ {
424
+ std::size_t length = 0;
425
+ es2panda_AstNode** result = nullptr;
426
+ switch (type) {
427
+ case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION: {
428
+ result = impl->ScriptFunctionAnnotations(context, node, &length);
429
+ break;
430
+ }
431
+ case Es2pandaAstNodeType::AST_NODE_TYPE_FUNCTION_DECLARATION: {
432
+ result = impl->FunctionDeclarationAnnotations(context, node, &length);
433
+ break;
434
+ }
435
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION: {
436
+ result = impl->ArrowFunctionExpressionAnnotations(context, node, &length);
437
+ break;
438
+ }
439
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_FUNCTION_TYPE: {
440
+ result = impl->TypeNodeAnnotations(context, node, &length);
441
+ break;
442
+ }
443
+ case Es2pandaAstNodeType::AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION: {
444
+ result = impl->TSTypeAliasDeclarationAnnotations(context, node, &length);
445
+ break;
465
446
  }
466
- bool found = false;
467
- for (std::size_t i = 0; i < length && result; i++) {
468
- es2panda_AstNode* ident = impl->AnnotationUsageIrGetBaseNameConst(context, result[i]);
469
- const char* name = impl->IdentifierNameConst(context, ident);
470
- found |= matchWildcard(value, name);
447
+ case Es2pandaAstNodeType::AST_NODE_TYPE_VARIABLE_DECLARATION: {
448
+ result = impl->VariableDeclarationAnnotations(context, node, &length);
449
+ break;
471
450
  }
472
- return found;
451
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_UNION_TYPE: {
452
+ result = impl->TypeNodeAnnotations(context, node, &length);
453
+ break;
454
+ }
455
+ case Es2pandaAstNodeType::AST_NODE_TYPE_CLASS_PROPERTY: {
456
+ result = impl->ClassPropertyAnnotations(context, node, &length);
457
+ break;
458
+ }
459
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION: {
460
+ result = impl->ETSParameterExpressionAnnotations(context, node, &length);
461
+ break;
462
+ }
463
+ default:
464
+ return false;
473
465
  }
474
- return false;
466
+
467
+ bool found = false;
468
+ for (std::size_t i = 0; i < length && result; i++) {
469
+ es2panda_AstNode* ident = impl->AnnotationUsageIrGetBaseNameConst(context, result[i]);
470
+ found |= MatchWildcard(value, impl->IdentifierNameConst(context, ident));
471
+ }
472
+ return found;
475
473
  }
476
474
 
477
- bool matchWildcard(const std::string& pattern, const char* value) const
475
+ bool MatchWildcard(const std::string& pattern, const char* foundValue) const
478
476
  {
479
477
  if (!isWildcard) {
480
- return pattern == value;
478
+ return pattern == foundValue;
481
479
  }
482
480
 
483
- return std::regex_search(value, this->regex);
481
+ return std::regex_search(foundValue, this->regex);
484
482
  }
485
483
  };
486
484
 
@@ -507,11 +505,11 @@ struct Matcher {
507
505
  }
508
506
  };
509
507
 
510
- KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, const KStringPtr& filters, KBoolean deeperAfterMatch)
508
+ static KNativePointer DoFilterNodes(es2panda_Context* _context,
509
+ es2panda_AstNode* _node,
510
+ const char* _filters,
511
+ bool deeperAfterMatch)
511
512
  {
512
- auto _node = reinterpret_cast<es2panda_AstNode*>(node);
513
- auto _context = reinterpret_cast<es2panda_Context*>(context);
514
- const char* _filters = filters.c_str();
515
513
  std::vector<es2panda_AstNode*> result;
516
514
  es2panda_Impl* impl = GetImpl();
517
515
  Matcher matcher(_context, _filters);
@@ -526,18 +524,23 @@ KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, con
526
524
  }
527
525
  if (!isMatch || deeperAfterMatch) {
528
526
  impl->AstNodeIterateConst(_context, current, visitChild);
529
- // We want to retain match order, so add children in reverse order.
530
527
  for (auto it = cachedChildren.rbegin(); it != cachedChildren.rend(); ++it) {
531
528
  queue.push_back(*it);
532
529
  }
533
530
  cachedChildren.clear();
534
531
  }
535
532
  }
536
- return StageArena::cloneVector(result.data(), result.size());
533
+ return StageArena::CloneVector(result.data(), result.size());
537
534
  }
538
- KOALA_INTEROP_4(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr, KBoolean)
539
535
 
540
- constexpr int AST_NODE_TYPE_LIMIT = 256;
536
+ KNativePointer impl_FilterNodes(
537
+ KNativePointer context, KNativePointer node, const KStringPtr& filters, KBoolean deeperAfterMatch)
538
+ {
539
+ auto* _node = reinterpret_cast<es2panda_AstNode*>(node);
540
+ auto* _context = reinterpret_cast<es2panda_Context*>(context);
541
+ return DoFilterNodes(_context, _node, filters.c_str(), static_cast<bool>(deeperAfterMatch));
542
+ }
543
+ KOALA_INTEROP_4(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr, KBoolean)
541
544
 
542
545
  struct FilterArgs {
543
546
  es2panda_Impl *impl;
@@ -564,7 +567,7 @@ KNativePointer impl_FilterNodes2(KNativePointer context, KNativePointer node, KI
564
567
  std::vector<es2panda_AstNode *> result;
565
568
  FilterArgs args = { GetImpl(), _context, &typesMask, &result };
566
569
  GetImpl()->AstNodeForEach(_node, filterByType, &args);
567
- return StageArena::cloneVector(result.data(), result.size());
570
+ return StageArena::CloneVector(result.data(), result.size());
568
571
  }
569
572
  KOALA_INTEROP_3(FilterNodes2, KNativePointer, KNativePointer, KNativePointer, KInt)
570
573
 
@@ -579,7 +582,7 @@ KNativePointer impl_FilterNodes3(KNativePointer context, KNativePointer node, KI
579
582
  std::vector<es2panda_AstNode *> result;
580
583
  FilterArgs args = { GetImpl(), _context, &typesMask, &result };
581
584
  GetImpl()->AstNodeForEach(_node, filterByType, &args);
582
- return StageArena::cloneVector(result.data(), result.size());
585
+ return StageArena::CloneVector(result.data(), result.size());
583
586
  }
584
587
  KOALA_INTEROP_4(FilterNodes3, KNativePointer, KNativePointer, KNativePointer, KInt*, KInt)
585
588
 
@@ -590,18 +593,6 @@ KOALA_INTEROP_4(FilterNodes3, KNativePointer, KNativePointer, KNativePointer, KI
590
593
  // From koala-wrapper
591
594
  // Improve: check if some code should be generated
592
595
 
593
- void impl_MemInitialize()
594
- {
595
- GetImpl()->MemInitialize();
596
- }
597
- KOALA_INTEROP_V0(MemInitialize)
598
-
599
- void impl_MemFinalize()
600
- {
601
- GetImpl()->MemFinalize();
602
- }
603
- KOALA_INTEROP_V0(MemFinalize)
604
-
605
596
  static bool isUIHeaderFile(es2panda_Context* context, es2panda_Program* program)
606
597
  {
607
598
  auto result = GetImpl()->ProgramFileNameWithExtensionConst(context, program);
@@ -650,3 +641,49 @@ KNativePointer impl_AstNodeProgram(KNativePointer contextPtr, KNativePointer ins
650
641
  return impl_AstNodeProgram(_context, GetImpl()->AstNodeParent(_context, _receiver));
651
642
  }
652
643
  KOALA_INTEROP_2(AstNodeProgram, KNativePointer, KNativePointer, KNativePointer)
644
+
645
+ // This api could be generated (as combination of 2 briges) after namespace util is generated
646
+ KInt impl_GetCompilationMode(KNativePointer configPtr)
647
+ {
648
+ auto _config = reinterpret_cast<es2panda_Config*>(configPtr);
649
+ auto _options = const_cast<es2panda_Options*>(GetImpl()->ConfigGetOptions(_config));
650
+ return GetImpl()->OptionsUtilGetCompilationModeConst(nullptr, _options);
651
+ }
652
+ KOALA_INTEROP_1(GetCompilationMode, KInt, KNativePointer)
653
+
654
+ KNativePointer impl_CreateTypeNodeFromTsType(KNativePointer context, KNativePointer nodePtr)
655
+ {
656
+ const auto _context = reinterpret_cast<es2panda_Context*>(context);
657
+ const auto _nodePtr = reinterpret_cast<es2panda_AstNode*>(nodePtr);
658
+ auto _tsType = GetImpl()->TypedTsType(_context, _nodePtr);
659
+ if (_tsType == nullptr) {
660
+ _tsType = GetImpl()->ExpressionTsType(_context, _nodePtr);
661
+ }
662
+ if (_tsType == nullptr) {
663
+ return nullptr;
664
+ }
665
+ const auto _nodeTsType = reinterpret_cast<es2panda_Type*>(_tsType);
666
+ auto _typeAnnotation = GetImpl()->CreateOpaqueTypeNode(_context, _nodeTsType);
667
+ return _typeAnnotation;
668
+ }
669
+ KOALA_INTEROP_2(CreateTypeNodeFromTsType, KNativePointer, KNativePointer, KNativePointer)
670
+
671
+ MemoryTracker tracker;
672
+ void impl_MemoryTrackerReset(KNativePointer context)
673
+ {
674
+ tracker.Reset();
675
+ }
676
+ KOALA_INTEROP_V1(MemoryTrackerReset, KNativePointer);
677
+
678
+ void impl_MemoryTrackerGetDelta(KNativePointer context)
679
+ {
680
+ tracker.Report(tracker.GetDelta());
681
+ }
682
+ KOALA_INTEROP_V1(MemoryTrackerGetDelta, KNativePointer);
683
+
684
+ void impl_MemoryTrackerPrintCurrent(KNativePointer context)
685
+ {
686
+ tracker.Report(GetMemoryStats());
687
+ }
688
+ KOALA_INTEROP_V1(MemoryTrackerPrintCurrent, KNativePointer);
689
+
@@ -16,21 +16,6 @@
16
16
  #ifndef COMMON_H
17
17
  #define COMMON_H
18
18
 
19
- /*
20
- * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
21
- * Licensed under the Apache License, Version 2.0 (the "License");
22
- * you may not use this file except in compliance with the License.
23
- * You may obtain a copy of the License at
24
- *
25
- * http://www.apache.org/licenses/LICENSE-2.0
26
- *
27
- * Unless required by applicable law or agreed to in writing, software
28
- * distributed under the License is distributed on an "AS IS" BASIS,
29
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
- * See the License for the specific language governing permissions and
31
- * limitations under the License.
32
- */
33
-
34
19
  #include <iostream>
35
20
  #include <string>
36
21
  #include <vector>
@@ -82,52 +67,52 @@ class StageArena {
82
67
  public:
83
68
  StageArena();
84
69
  ~StageArena();
85
- static StageArena* instance();
70
+ static StageArena* Instance();
86
71
  template<typename T>
87
- static T* alloc()
72
+ static T* Alloc()
88
73
  {
89
- auto* arena = StageArena::instance();
90
- void* memory = arena->alloc(sizeof(T));
74
+ auto* arena = StageArena::Instance();
75
+ void* memory = arena->Alloc(sizeof(T));
91
76
  return new (memory) T();
92
77
  }
93
78
  template<class T, class T1>
94
- static T* alloc(T1 arg1)
79
+ static T* Alloc(T1 arg1)
95
80
  {
96
- auto* arena = StageArena::instance();
97
- void* memory = arena->alloc(sizeof(T));
81
+ auto* arena = StageArena::Instance();
82
+ void* memory = arena->Alloc(sizeof(T));
98
83
  return new (memory) T(std::forward(arg1));
99
84
  }
100
85
  template<class T, class T1, class T2>
101
- static T* alloc(T1 arg1, T2 arg2)
86
+ static T* Alloc(T1 arg1, T2 arg2)
102
87
  {
103
- auto* arena = StageArena::instance();
104
- void* memory = arena->alloc(sizeof(T));
88
+ auto* arena = StageArena::Instance();
89
+ void* memory = arena->Alloc(sizeof(T));
105
90
  return new (memory) T(arg1, arg2);
106
91
  }
107
92
  template<typename T>
108
- static T* allocArray(size_t count)
93
+ static T* AllocArray(size_t count)
109
94
  {
110
- auto* arena = StageArena::instance();
95
+ auto* arena = StageArena::Instance();
111
96
  // align?
112
- void* memory = arena->alloc(sizeof(T) * count);
97
+ void* memory = arena->Alloc(sizeof(T) * count);
113
98
  return new (memory) T();
114
99
  }
115
100
  template<class T>
116
- static T* clone(const T& arg)
101
+ static T* Clone(const T& arg)
117
102
  {
118
- auto* arena = StageArena::instance();
119
- void* memory = arena->alloc(sizeof(T));
103
+ auto* arena = StageArena::Instance();
104
+ void* memory = arena->Alloc(sizeof(T));
120
105
  return new (memory) T(arg);
121
106
  }
122
107
  template<class T>
123
- static std::vector<const void*>* cloneVector(const T* arg, size_t count)
108
+ static std::vector<const void*>* CloneVector(const T* arg, size_t count)
124
109
  {
125
- return alloc<std::vector<const void*>, const T*, const T*>(arg, arg + count);
110
+ return Alloc<std::vector<const void*>, const T*, const T*>(arg, arg + count);
126
111
  }
127
- void* alloc(size_t size);
128
- static char* strdup(const char* original);
129
- void add(void* pointer);
130
- void cleanup();
112
+ void* Alloc(size_t size);
113
+ static char* Strdup(const char* original);
114
+ void Add(void* pointer);
115
+ void Cleanup();
131
116
  };
132
117
 
133
118
  #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) return std::to_string(bytes / gb) + " GB";
167
- if (bytes > mb) return std::to_string(bytes / mb) + " MB";
168
- if (bytes > kb) return std::to_string(bytes / kb) + " KB";
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
 
@@ -4,9 +4,6 @@
4
4
  "main": "./lib/libarkts.js",
5
5
  "typesVersions": {
6
6
  "*": {
7
- "./compat/*": [
8
- "./lib/types/wrapper-compat/index.d.ts"
9
- ],
10
7
  "*": [
11
8
  "./lib/types/src/index.d.ts"
12
9
  ]
@@ -14,7 +11,6 @@
14
11
  },
15
12
  "exports": {
16
13
  ".": "./lib/libarkts.js",
17
- "./compat": "./lib/libarkts-compat.js",
18
14
  "./plugins/*": "./lib/plugins/*.js"
19
15
  },
20
16
  "files": [
@@ -24,7 +20,7 @@
24
20
  ],
25
21
  "config": {
26
22
  "panda_sdk_path": "../incremental/tools/panda/node_modules/@panda/sdk",
27
- "panda_sdk_version": "next"
23
+ "panda_sdk_version": "1.5.0-dev.53118"
28
24
  },
29
25
  "dependencies": {
30
26
  "@koalaui/compat": "1.7.10+devel",
@@ -42,7 +38,7 @@
42
38
  "tsconfig-paths": "^4.2.0",
43
39
  "rimraf": "^6.0.1",
44
40
  "@koalaui/fast-arktsc": "1.7.10+devel",
45
- "@idlizer/arktscgen": "2.1.10-arktscgen-5",
41
+ "@idlizer/arktscgen": "2.1.10-arktscgen-8",
46
42
  "mocha": "^9.2.2",
47
43
  "@koalaui/harness": "1.7.10+devel",
48
44
  "@koalaui/ets-tsc": "4.9.5-r6",
@@ -51,7 +47,7 @@
51
47
  "node-api-headers": "0.0.5"
52
48
  },
53
49
  "scripts": {
54
- "clean": "rimraf generated build native/build* ./.rollup.cache tsconfig.tsbuildinfo lib",
50
+ "clean": "rimraf generated build native/mingw_build native/build* ./.rollup.cache tsconfig.tsbuildinfo lib",
55
51
  "clean:plugins": "rimraf plugins/build",
56
52
  "compile:koala:interop": "npm run --prefix ../interop compile",
57
53
  "compile:meson": "cd native && meson setup build && meson compile -C build",
@@ -63,7 +59,7 @@
63
59
  "compile": "npm run regenerate && npm run compile:native && npm run compile:js",
64
60
  "compile:current": "npm run regenerate:current && npm run compile:native && npm run compile:js",
65
61
  "compile:release": "npm run regenerate && npm run crosscompile:native && npm run compile:js",
66
- "compile:js": "rm -rf lib/ && rollup -c rollup.lib.mjs && rollup -c rollup.es2panda.mjs",
62
+ "compile:js": "rm -rf lib/ && rollup -c rollup.libarkts.mjs && rollup -c rollup.es2panda.mjs",
67
63
  "compile:plugins": "rollup -c ./rollup.printer-plugin.mjs",
68
64
  "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
65
  "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",
@@ -78,7 +74,7 @@
78
74
  "compile:playground": "cd playground && meson setup build && meson compile -C build",
79
75
  "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
76
  "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",
77
+ "panda:sdk:install": "cd ../incremental/tools/panda && echo \"Installing panda sdk $npm_package_config_panda_sdk_version\" && PANDA_SDK_VERSION=${PANDA_SDK_VERSION:-$npm_package_config_panda_sdk_version} npm run panda:sdk:install",
82
78
  "panda:sdk:reinstall": "npm run panda:sdk:clean && npm run panda:sdk:install",
83
79
  "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",
84
80
  "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",