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

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 (39) hide show
  1. package/build/libarkts-copy/generator/options.json5 +24 -47
  2. package/build/libarkts-copy/native/meson.build +25 -9
  3. package/build/libarkts-copy/native/meson_options.txt +9 -3
  4. package/build/libarkts-copy/native/mingw.cross +2 -0
  5. package/build/libarkts-copy/native/src/bridges.cc +20 -81
  6. package/build/libarkts-copy/native/src/common.cc +127 -49
  7. package/build/libarkts-copy/native/src/memoryTracker.cc +42 -35
  8. package/build/libarkts-copy/package.json +12 -10
  9. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +10 -63
  10. package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +9 -3
  11. package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +2 -4
  12. package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +14 -5
  13. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +19 -1
  14. package/build/libarkts-copy/src/arkts-api/index.ts +0 -1
  15. package/build/libarkts-copy/src/arkts-api/node-cache.ts +12 -3
  16. package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
  17. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +4 -4
  18. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +0 -16
  19. package/build/libarkts-copy/src/arkts-api/peers/Config.ts +1 -1
  20. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +10 -9
  21. package/build/libarkts-copy/src/arkts-api/plugins.ts +110 -5
  22. package/build/libarkts-copy/src/arkts-api/static/global.ts +1 -1
  23. package/build/libarkts-copy/src/arkts-api/static/profiler.ts +1 -1
  24. package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +2 -1
  25. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +4 -9
  26. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -9
  27. package/build/libarkts-copy/src/arkts-api/visitor.ts +4 -25
  28. package/build/libarkts-copy/src/checkSdk.ts +1 -1
  29. package/build/libarkts-copy/src/index.ts +1 -1
  30. package/build/libarkts-copy/src/memo-node-cache.ts +143 -0
  31. package/build/libarkts-copy/src/plugin-utils.ts +19 -12
  32. package/build/libarkts-copy/src/reexport-for-generated.ts +2 -0
  33. package/build/libarkts-copy/src/tracer.ts +2 -2
  34. package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +2 -2
  35. package/build/libarkts-copy/src/ts-api/utilities/private.ts +2 -2
  36. package/build/libarkts-copy/src/utils.ts +10 -14
  37. package/lib/index.js +5316 -10427
  38. package/package.json +9 -7
  39. package/build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts +0 -23
@@ -22,31 +22,14 @@
22
22
  "ETSUndefinedType",
23
23
  ],
24
24
  "ignore": {
25
- "full": [
25
+ "peers": [
26
26
  "es2panda_Config",
27
+ "es2panda_Context",
28
+ "es2panda_GlobalContext",
29
+ ],
30
+ "full": [
27
31
  "es2panda_ExternalSource",
28
32
  "es2panda_OverloadInfo",
29
- "es2panda_GlobalContext",
30
-
31
- // Duplicates of types in ir namespace
32
- // They will be removed in the fututre.
33
- 'es2panda_Signature',
34
- 'es2panda_CheckerContext',
35
- 'es2panda_Type',
36
- 'es2panda_TypeRelation',
37
- 'es2panda_GlobalTypesHolder',
38
- 'es2panda_Variable',
39
- 'es2panda_Scope',
40
- 'es2panda_Path',
41
- 'es2panda_ResolveResult',
42
- 'es2panda_RecordTable',
43
- 'es2panda_BoundContext',
44
- 'es2panda_ImportPathManager',
45
- 'es2panda_Options',
46
- 'es2panda_AstNode',
47
- 'es2panda_Program',
48
- 'es2panda_ArkTsConfig',
49
- 'es2panda_FunctionSignature',
50
33
 
51
34
  'NodeTransformer',
52
35
  'NodeTraverser',
@@ -87,25 +70,22 @@
87
70
  interface: "es2panda_Impl",
88
71
  methods: [
89
72
  "LogSyntaxError", "LogWarning", "LogTypeError", // wrong idl
90
- "DestroyContext", // cleanup arena (Improve: move this cleanup to another method)
73
+ "DestroyConfig", // cleanup arena
91
74
 
92
75
  // Handwritten bridges
93
- "AstNodeRebind",
94
- "ConfigGetOptions",
95
- "CreateCacheContextFromFile",
96
- "CreateContextFromFile",
97
- "CreateContextFromString",
98
- "CreateContextGenerateAbcForExternalSourceFiles",
99
- "CreateDiagnosticInfo",
76
+ "ConfigGetOptions", // handwritten class
77
+ "ExternalSourceName", // handwritten class and used in panda API
78
+ "SourcePositionCol", // not in idl
79
+ "ExternalSourcePrograms", // Wrong args
80
+ "LogDiagnostic", // not in idl
100
81
  "CreateDiagnosticKind",
101
- "CreateGlobalContext",
102
- "CreateSuggestionInfo",
103
- "DestroyGlobalContext",
104
- "SourcePositionCol",
105
- "ExternalSourceName",
106
- "ExternalSourcePrograms",
107
- "GenerateTsDeclarationsFromContext",
108
- "LogDiagnostic",
82
+ "GetSemanticErrors",
83
+ "GetSyntaxErrors",
84
+ "GetPluginErrors",
85
+ "GetWarnings",
86
+ "NumberLiteralStrConst",
87
+ "MemInitialize",
88
+ "MemFinalize",
109
89
  ],
110
90
  },
111
91
  {
@@ -235,18 +215,15 @@
235
215
  "Parse",
236
216
  ]
237
217
  },
218
+ {
219
+ interface: "ClassDefinition",
220
+ methods: [
221
+ "SetBody", // handwritten
222
+ ]
223
+ },
238
224
  ]
239
225
  },
240
226
  nonNullable: [
241
- {
242
- name: "ScriptFunction",
243
- methods: [
244
- {
245
- name: "SetIdent",
246
- types: ["id"]
247
- }
248
- ]
249
- },
250
227
  {
251
228
  name: "ArrowFunctionExpression",
252
229
  methods: [
@@ -27,10 +27,10 @@ sources = [
27
27
  './src/memoryTracker.cc',
28
28
  './src/bridges.cc',
29
29
  '../generated/native/bridges.cc',
30
- get_option('interop_src_dir') / 'common-interop.cc',
31
- get_option('interop_src_dir') / 'callback-resource.cc',
32
- get_option('interop_src_dir') / 'interop-logging.cc',
33
- get_option('interop_src_dir') / 'napi' / 'convertors-napi.cc',
30
+ get_option('interop_src_dir') / 'common-interop.cpp',
31
+ get_option('interop_src_dir') / 'callback-resource.cpp',
32
+ get_option('interop_src_dir') / 'interop-logging.cpp',
33
+ get_option('interop_src_dir') / 'napi' / 'convertors-napi.cpp',
34
34
  ]
35
35
 
36
36
  cflags = [
@@ -44,7 +44,7 @@ if (host_machine.system() == 'windows')
44
44
  cflags += ['-DKOALA_WINDOWS']
45
45
  # apply node.exe symbol loading hook
46
46
  sources += [
47
- get_option('interop_src_dir') / 'napi/win-dynamic-node.cc'
47
+ get_option('interop_src_dir') / 'napi/win-dynamic-node.cpp'
48
48
  ]
49
49
  else
50
50
  cflags += ['-DKOALA_LINUX']
@@ -76,6 +76,22 @@ suffix_cross = '_' + os + '_arm64'
76
76
  endif
77
77
  endif
78
78
 
79
+ fs = import('fs')
80
+ if fs.is_dir(get_option('node_modules_dir_1') + '/node-api-headers')
81
+ node_api_headers_dir = get_option('node_modules_dir_1')
82
+ elif fs.is_dir(get_option('node_modules_dir_2') + '/node-api-headers')
83
+ node_api_headers_dir = get_option('node_modules_dir_2')
84
+ else
85
+ error('node-api-headers not found')
86
+ endif
87
+ if fs.is_dir(get_option('node_modules_dir_1') + '/node-addon-api')
88
+ node_addon_api_dir = get_option('node_modules_dir_1')
89
+ elif fs.is_dir(get_option('node_modules_dir_2') + '/node-addon-api')
90
+ node_addon_api_dir = get_option('node_modules_dir_2')
91
+ else
92
+ error('node-addon-api not found')
93
+ endif
94
+
79
95
  shared_library(
80
96
  get_option('lib_name') + suffix_host,
81
97
  sources,
@@ -92,8 +108,8 @@ shared_library(
92
108
  get_option('interop_src_dir'),
93
109
  get_option('interop_src_dir') / 'types',
94
110
  get_option('interop_src_dir') / 'napi',
95
- get_option('node_modules_dir') / 'node-api-headers/include',
96
- get_option('node_modules_dir') / 'node-addon-api',
111
+ node_api_headers_dir / 'node-api-headers/include',
112
+ node_addon_api_dir / 'node-addon-api',
97
113
  ],
98
114
  cpp_args: cflags + cflags_host,
99
115
  link_args: [cflags_host],
@@ -118,8 +134,8 @@ if is_cross
118
134
  get_option('interop_src_dir'),
119
135
  get_option('interop_src_dir') / 'types',
120
136
  get_option('interop_src_dir') / 'napi',
121
- get_option('node_modules_dir') / 'node-api-headers/include',
122
- get_option('node_modules_dir') / 'node-addon-api',
137
+ node_api_headers_dir / 'node-api-headers/include',
138
+ node_addon_api_dir / 'node-addon-api',
123
139
  ],
124
140
  cpp_args: cflags + cflags_cross,
125
141
  link_args: [cflags_cross],
@@ -12,7 +12,13 @@
12
12
  # limitations under the License.
13
13
 
14
14
  option(
15
- 'node_modules_dir',
15
+ 'node_modules_dir_1',
16
+ type : 'string',
17
+ value : '../node_modules/',
18
+ description : 'path to node_modules'
19
+ )
20
+ option(
21
+ 'node_modules_dir_2',
16
22
  type : 'string',
17
23
  value : '../../node_modules/',
18
24
  description : 'path to node_modules'
@@ -20,13 +26,13 @@ option(
20
26
  option(
21
27
  'interop_src_dir',
22
28
  type : 'string',
23
- value : '../../../interop/src/cpp/',
29
+ value : '../../interop/src/cpp/',
24
30
  description : 'path to koala interop cpp files'
25
31
  )
26
32
  option(
27
33
  'panda_sdk_dir',
28
34
  type : 'string',
29
- value : '../../../incremental/tools/panda/node_modules/@panda/sdk/',
35
+ value : '../../incremental/tools/panda/node_modules/@panda/sdk/',
30
36
  description : 'path to panda sdk'
31
37
  )
32
38
  option(
@@ -25,3 +25,5 @@ cpu_family = 'x86_64'
25
25
  cpu = 'x86_64'
26
26
  endian = 'little'
27
27
 
28
+ [properties]
29
+ cpp_link_args = ['-lpsapi']
@@ -18,6 +18,7 @@
18
18
  #include <string>
19
19
 
20
20
  #include "common.h"
21
+ #include "memoryTracker.h"
21
22
 
22
23
  /** XXX: If you add or remove methods that exist in C API,
23
24
  * please change generator/options.json5 accordingly.
@@ -91,20 +92,6 @@ KNativePointer impl_ETSParserCreateExpression(KNativePointer contextPtr, KString
91
92
  }
92
93
  KOALA_INTEROP_3(ETSParserCreateExpression, KNativePointer, KNativePointer, KStringPtr, KInt)
93
94
 
94
- KNativePointer impl_CreateContextFromString(KNativePointer configPtr, KStringPtr& sourcePtr, KStringPtr& filenamePtr)
95
- {
96
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
97
- return GetImpl()->CreateContextFromString(config, sourcePtr.data(), filenamePtr.data());
98
- }
99
- KOALA_INTEROP_3(CreateContextFromString, KNativePointer, KNativePointer, KStringPtr, KStringPtr)
100
-
101
- KNativePointer impl_CreateContextFromFile(KNativePointer configPtr, KStringPtr& filenamePtr)
102
- {
103
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
104
- return GetImpl()->CreateContextFromFile(config, getStringCopy(filenamePtr));
105
- }
106
- KOALA_INTEROP_2(CreateContextFromFile, KNativePointer, KNativePointer, KStringPtr)
107
-
108
95
  KNativePointer impl_SignatureFunction(KNativePointer context, KNativePointer classInstance)
109
96
  {
110
97
  const auto _context = reinterpret_cast<es2panda_Context*>(context);
@@ -210,30 +197,6 @@ KNativePointer impl_OptionsArkTsConfig(KNativePointer context, KNativePointer op
210
197
  }
211
198
  KOALA_INTEROP_2(OptionsArkTsConfig, KNativePointer, KNativePointer, KNativePointer)
212
199
 
213
- KNativePointer impl_CreateCacheContextFromFile(
214
- KNativePointer configPtr, KStringPtr& source_file_namePtr, KNativePointer globalContextPtr, KBoolean isExternal)
215
- {
216
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
217
- auto globalContext = reinterpret_cast<es2panda_GlobalContext*>(globalContextPtr);
218
- return GetImpl()->CreateCacheContextFromFile(config, getStringCopy(source_file_namePtr), globalContext, isExternal);
219
- }
220
- KOALA_INTEROP_4(CreateCacheContextFromFile, KNativePointer, KNativePointer, KStringPtr, KNativePointer, KBoolean)
221
-
222
- KNativePointer impl_CreateGlobalContext(
223
- KNativePointer configPtr, KStringArray& externalFileListPtr, KUInt fileNum, KBoolean LspUsage)
224
- {
225
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
226
- return GetImpl()->CreateGlobalContext(config, getStringArray(externalFileListPtr), fileNum, LspUsage);
227
- }
228
- KOALA_INTEROP_4(CreateGlobalContext, KNativePointer, KNativePointer, KStringArray, KUInt, KBoolean)
229
-
230
- void impl_DestroyGlobalContext(KNativePointer globalContextPtr)
231
- {
232
- auto globalContext = reinterpret_cast<es2panda_GlobalContext*>(globalContextPtr);
233
- GetImpl()->DestroyGlobalContext(globalContext);
234
- }
235
- KOALA_INTEROP_V1(DestroyGlobalContext, KNativePointer)
236
-
237
200
  // All these "Checker_" bridges are related to checker namespace in es2panda, so work with them carefully
238
201
  // Checker.Type does reset on recheck, so modifying them makes no sence
239
202
  // It seems that compiler does not provide API to convert Checker.Type to ir.Type
@@ -415,31 +378,6 @@ KNativePointer impl_CreateDiagnosticKind(KNativePointer context, KStringPtr& mes
415
378
  }
416
379
  KOALA_INTEROP_3(CreateDiagnosticKind, KNativePointer, KNativePointer, KStringPtr, KInt)
417
380
 
418
- KNativePointer impl_CreateDiagnosticInfo(
419
- KNativePointer context, KNativePointer kind, KStringArray& argsPtr, KInt argc, KNativePointer pos)
420
- {
421
- const auto _context = reinterpret_cast<es2panda_Context*>(context);
422
- const auto _kind = reinterpret_cast<es2panda_DiagnosticKind*>(kind);
423
- const auto _pos = reinterpret_cast<es2panda_SourcePosition*>(pos);
424
- return GetImpl()->CreateDiagnosticInfo(_context, _kind, getStringArray(argsPtr), argc, _pos);
425
- }
426
- KOALA_INTEROP_5(
427
- CreateDiagnosticInfo, KNativePointer, KNativePointer, KNativePointer, KStringArray, KInt, KNativePointer)
428
-
429
- KNativePointer impl_CreateSuggestionInfo(KNativePointer context, KNativePointer kind, KStringArray& argsPtr, KInt argc,
430
- KStringPtr& substitutionCode, KStringPtr& title, KNativePointer range)
431
- {
432
- const auto _context = reinterpret_cast<es2panda_Context*>(context);
433
- const auto _kind = reinterpret_cast<es2panda_DiagnosticKind*>(kind);
434
- const auto _title = getStringCopy(title);
435
- const auto _range = reinterpret_cast<es2panda_SourceRange*>(range);
436
- const auto _substitutionCode = getStringCopy(substitutionCode);
437
- return GetImpl()->CreateSuggestionInfo(
438
- _context, _kind, getStringArray(argsPtr), argc, _substitutionCode, _title, _range);
439
- }
440
- KOALA_INTEROP_7(CreateSuggestionInfo, KNativePointer, KNativePointer, KNativePointer, KStringArray, KInt, KStringPtr,
441
- KStringPtr, KNativePointer)
442
-
443
381
  void impl_LogDiagnostic(
444
382
  KNativePointer context, KNativePointer kind, KStringArray& argvPtr, KInt argc, KNativePointer pos)
445
383
  {
@@ -460,24 +398,6 @@ KNativePointer impl_AnnotationUsageIrPropertiesPtrConst(KNativePointer context,
460
398
  }
461
399
  KOALA_INTEROP_2(AnnotationUsageIrPropertiesPtrConst, KNativePointer, KNativePointer, KNativePointer);
462
400
 
463
- KInt impl_GenerateTsDeclarationsFromContext(KNativePointer contextPtr, KStringPtr& outputDeclEts, KStringPtr& outputEts,
464
- KBoolean exportAll, KBoolean isolated, KStringPtr& recordFile, KBoolean genAnnotations)
465
- {
466
- auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
467
- return GetImpl()->GenerateTsDeclarationsFromContext(
468
- context, outputDeclEts.data(), outputEts.data(), exportAll, isolated, recordFile.data(), genAnnotations);
469
- }
470
- KOALA_INTEROP_7(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean,
471
- KStringPtr, KBoolean)
472
-
473
- KNativePointer impl_CreateContextGenerateAbcForExternalSourceFiles(
474
- KNativePointer configPtr, KInt fileNamesCount, KStringArray& fileNames)
475
- {
476
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
477
- return GetImpl()->CreateContextGenerateAbcForExternalSourceFiles(config, fileNamesCount, getStringArray(fileNames));
478
- }
479
- KOALA_INTEROP_3(CreateContextGenerateAbcForExternalSourceFiles, KNativePointer, KNativePointer, KInt, KStringArray)
480
-
481
401
  KInt impl_GetCompilationMode(KNativePointer configPtr)
482
402
  {
483
403
  auto _config = reinterpret_cast<es2panda_Config*>(configPtr);
@@ -502,3 +422,22 @@ KNativePointer impl_CreateTypeNodeFromTsType(KNativePointer context, KNativePoin
502
422
  return _typeAnnotation;
503
423
  }
504
424
  KOALA_INTEROP_2(CreateTypeNodeFromTsType, KNativePointer, KNativePointer, KNativePointer)
425
+
426
+ MemoryTracker tracker;
427
+ void impl_MemoryTrackerReset(KNativePointer context)
428
+ {
429
+ tracker.Reset();
430
+ }
431
+ KOALA_INTEROP_V1(MemoryTrackerReset, KNativePointer);
432
+
433
+ void impl_MemoryTrackerGetDelta(KNativePointer context)
434
+ {
435
+ tracker.Report(tracker.GetDelta());
436
+ }
437
+ KOALA_INTEROP_V1(MemoryTrackerGetDelta, KNativePointer);
438
+
439
+ void impl_MemoryTrackerPrintCurrent(KNativePointer context)
440
+ {
441
+ tracker.Report(GetMemoryStats());
442
+ }
443
+ KOALA_INTEROP_V1(MemoryTrackerPrintCurrent, KNativePointer);
@@ -15,10 +15,11 @@
15
15
 
16
16
  #include <common.h>
17
17
  #include <iterator>
18
- #include <regex.h>
18
+ #include <regex>
19
19
  #include <sstream>
20
20
  #include <utility>
21
21
  #include <vector>
22
+ #include <bitset>
22
23
 
23
24
  #include "interop-types.h"
24
25
 
@@ -136,14 +137,14 @@ void impl_SetUpSoPath(KStringPtr& soPath)
136
137
  }
137
138
  KOALA_INTEROP_V1(SetUpSoPath, KStringPtr);
138
139
 
139
- void* TryLibrary(const char* name)
140
+ void* TryLibrary(const char* name)
140
141
  {
141
142
  void* res = nullptr;
142
143
  std::vector<std::string> pathArray;
143
144
 
144
145
  // find by SetUpSoPath
145
146
  if (!ES2PANDA_LIB_PATH.empty()) {
146
- pathArray = {ES2PANDA_LIB_PATH, LIB_DIR, name};
147
+ pathArray = { ES2PANDA_LIB_PATH, LIB_DIR, name };
147
148
  res = loadLibrary(joinPath(pathArray));
148
149
  if (res) {
149
150
  return res;
@@ -153,7 +154,7 @@ void* TryLibrary(const char* name)
153
154
  // find by set PANDA_SDK_PATH
154
155
  char* envValue = getenv("PANDA_SDK_PATH");
155
156
  if (envValue) {
156
- pathArray = {envValue, PLUGIN_DIR, LIB_DIR, name};
157
+ pathArray = { envValue, PLUGIN_DIR, LIB_DIR, name };
157
158
  res = loadLibrary(joinPath(pathArray));
158
159
  if (res) {
159
160
  return res;
@@ -161,14 +162,14 @@ void* TryLibrary(const char* name)
161
162
  }
162
163
 
163
164
  // find by set LD_LIBRARY_PATH
164
- pathArray = {name};
165
+ pathArray = { name };
165
166
  res = loadLibrary(joinPath(pathArray));
166
167
  if (res) {
167
168
  return res;
168
169
  }
169
170
 
170
171
  // find by DEFAULT_SDK_PATH
171
- pathArray = {DEFAULT_SDK_PATH, PLUGIN_DIR, LIB_DIR, name};
172
+ pathArray = { DEFAULT_SDK_PATH, PLUGIN_DIR, LIB_DIR, name };
172
173
  res = loadLibrary(joinPath(pathArray));
173
174
  if (res) {
174
175
  return res;
@@ -178,8 +179,9 @@ void* TryLibrary(const char* name)
178
179
  }
179
180
 
180
181
  // TODO: @panda/sdk will be changed to match ohos-sdk
181
- void* FindLibrary() {
182
- void *res = nullptr;
182
+ void* FindLibrary()
183
+ {
184
+ void* res = nullptr;
183
185
 
184
186
  res = TryLibrary(LIB_ES2PANDA_PUBLIC);
185
187
  if (res) {
@@ -228,27 +230,16 @@ char* getStringCopy(KStringPtr& ptr)
228
230
  return StageArena::strdup(ptr.c_str() ? ptr.c_str() : "");
229
231
  }
230
232
 
231
- KNativePointer impl_CreateConfig(KInt argc, KStringArray& argvPtr)
232
- {
233
- return GetImpl()->CreateConfig(argc, getStringArray(argvPtr));
234
- }
235
- KOALA_INTEROP_2(CreateConfig, KNativePointer, KInt, KStringArray)
236
-
237
- KNativePointer impl_DestroyConfig(KNativePointer configPtr)
238
- {
239
- auto config = reinterpret_cast<es2panda_Config*>(configPtr);
240
- GetImpl()->DestroyConfig(config);
241
- return nullptr;
242
- }
243
- KOALA_INTEROP_1(DestroyConfig, KNativePointer, KNativePointer)
244
-
245
- void impl_DestroyContext(KNativePointer contextPtr)
233
+ void impl_DestroyConfig(KNativePointer config)
246
234
  {
247
- auto context = reinterpret_cast<es2panda_Context*>(contextPtr);
248
- GetImpl()->DestroyContext(context);
235
+ const auto _config = reinterpret_cast<es2panda_Config*>(config);
236
+ // panda prints diagnostics here and do not clone our strings
237
+ // so keep arena alive until this moment.
238
+ GetImpl()->DestroyConfig(_config);
249
239
  StageArena::instance()->cleanup();
240
+ printf("[libarkts native] Arena cleaned up!\n");
250
241
  }
251
- KOALA_INTEROP_V1(DestroyContext, KNativePointer)
242
+ KOALA_INTEROP_V1(DestroyConfig, KNativePointer);
252
243
 
253
244
  KNativePointer impl_UpdateCallExpression(KNativePointer contextPtr, KNativePointer nodePtr, KNativePointer calleePtr,
254
245
  KNativePointerArray argumentsPtr, KInt argumentsLen, KNativePointer typeParamsPtr, KBoolean optionalT,
@@ -385,24 +376,45 @@ struct Pattern {
385
376
  std::string key;
386
377
  std::string value;
387
378
  es2panda_Impl* impl;
379
+ bool isWildcard = false;
380
+ std::regex regex;
381
+
382
+ Pattern(const Pattern&) = delete;
383
+
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) {
386
+ other.isWildcard = false;
387
+ }
388
388
 
389
389
  Pattern(es2panda_Context* context, const std::string& part) : context(context), impl(GetImpl())
390
390
  {
391
391
  std::istringstream stream(part);
392
392
  std::getline(stream, key, '=');
393
393
  std::getline(stream, value, '=');
394
+ isWildcard = value.find('*') != std::string::npos;
395
+
396
+ if (isWildcard) {
397
+ this->regex = std::regex(value);
398
+ }
394
399
  }
395
- bool match(es2panda_AstNode* node)
400
+
401
+ ~Pattern() = default;
402
+
403
+ bool match(es2panda_AstNode* node) const
396
404
  {
397
405
  if (key == "type") {
398
406
  auto type = impl->AstNodeTypeConst(context, node);
399
407
  switch (type) {
400
408
  case Es2pandaAstNodeType::AST_NODE_TYPE_METHOD_DEFINITION:
401
- case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION:
402
-
403
409
  return value == "method";
410
+ case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION:
411
+ return value == "function";
404
412
  case Es2pandaAstNodeType::AST_NODE_TYPE_STRUCT_DECLARATION:
405
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";
406
418
  default:
407
419
  return false;
408
420
  }
@@ -412,22 +424,42 @@ struct Pattern {
412
424
  Es2pandaAstNodeType type = impl->AstNodeTypeConst(context, node);
413
425
  es2panda_AstNode** result = nullptr;
414
426
  switch (type) {
415
- case Es2pandaAstNodeType::AST_NODE_TYPE_METHOD_DEFINITION: {
416
- auto function = impl->MethodDefinitionFunction(context, node);
417
- result = impl->FunctionDeclarationAnnotations(context, function, &length);
427
+ case Es2pandaAstNodeType::AST_NODE_TYPE_SCRIPT_FUNCTION: {
428
+ result = impl->ScriptFunctionAnnotations(context, node, &length);
418
429
  break;
419
430
  }
420
- case Es2pandaAstNodeType::AST_NODE_TYPE_FUNCTION_DECLARATION:
431
+ case Es2pandaAstNodeType::AST_NODE_TYPE_FUNCTION_DECLARATION: {
421
432
  result = impl->FunctionDeclarationAnnotations(context, node, &length);
422
433
  break;
423
- case AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION: {
424
- auto function = impl->ArrowFunctionExpressionFunction(context, node);
425
- result = impl->FunctionDeclarationAnnotations(context, function, &length);
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);
426
445
  break;
427
446
  }
428
- case Es2pandaAstNodeType::AST_NODE_TYPE_CLASS_PROPERTY:
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: {
429
456
  result = impl->ClassPropertyAnnotations(context, node, &length);
430
457
  break;
458
+ }
459
+ case Es2pandaAstNodeType::AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION: {
460
+ result = impl->ETSParameterExpressionAnnotations(context, node, &length);
461
+ break;
462
+ }
431
463
  default:
432
464
  return false;
433
465
  }
@@ -442,15 +474,13 @@ struct Pattern {
442
474
  return false;
443
475
  }
444
476
 
445
- bool matchWildcard(const std::string& pattern, const char* value)
477
+ bool matchWildcard(const std::string& pattern, const char* value) const
446
478
  {
447
- if (pattern.find('*') == std::string::npos) {
479
+ if (!isWildcard) {
448
480
  return pattern == value;
449
481
  }
450
- regex_t regex;
451
- regmatch_t match[1];
452
- regcomp(&regex, pattern.c_str(), REG_NEWLINE);
453
- return regexec(&regex, value, 1, match, 0) != REG_NOMATCH;
482
+
483
+ return std::regex_search(value, this->regex);
454
484
  }
455
485
  };
456
486
 
@@ -464,20 +494,20 @@ struct Matcher {
464
494
  std::istringstream stream(query);
465
495
  std::string item;
466
496
  while (std::getline(stream, item, ';')) {
467
- patterns.emplace_back(Pattern(context, item));
497
+ patterns.emplace_back(std::forward<Pattern>(Pattern(context, item)));
468
498
  }
469
499
  }
470
500
  bool match(es2panda_AstNode* node)
471
501
  {
472
502
  bool result = true;
473
- for (auto pattern : patterns) {
503
+ for (const auto& pattern : patterns) {
474
504
  result &= pattern.match(node);
475
505
  }
476
506
  return result;
477
507
  }
478
508
  };
479
509
 
480
- KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, const KStringPtr& filters)
510
+ KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, const KStringPtr& filters, KBoolean deeperAfterMatch)
481
511
  {
482
512
  auto _node = reinterpret_cast<es2panda_AstNode*>(node);
483
513
  auto _context = reinterpret_cast<es2panda_Context*>(context);
@@ -490,9 +520,11 @@ KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, con
490
520
  while (queue.size() > 0) {
491
521
  auto* current = queue.back();
492
522
  queue.pop_back();
493
- if (matcher.match(current)) {
523
+ bool isMatch = matcher.match(current);
524
+ if (isMatch) {
494
525
  result.push_back(current);
495
- } else {
526
+ }
527
+ if (!isMatch || deeperAfterMatch) {
496
528
  impl->AstNodeIterateConst(_context, current, visitChild);
497
529
  // We want to retain match order, so add children in reverse order.
498
530
  for (auto it = cachedChildren.rbegin(); it != cachedChildren.rend(); ++it) {
@@ -503,7 +535,53 @@ KNativePointer impl_FilterNodes(KNativePointer context, KNativePointer node, con
503
535
  }
504
536
  return StageArena::cloneVector(result.data(), result.size());
505
537
  }
506
- KOALA_INTEROP_3(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr)
538
+ KOALA_INTEROP_4(FilterNodes, KNativePointer, KNativePointer, KNativePointer, KStringPtr, KBoolean)
539
+
540
+ constexpr int AST_NODE_TYPE_LIMIT = 256;
541
+
542
+ struct FilterArgs {
543
+ es2panda_Impl *impl;
544
+ es2panda_Context *context;
545
+ std::bitset<AST_NODE_TYPE_LIMIT> *typesMask;
546
+ std::vector<es2panda_AstNode *> *result;
547
+ };
548
+
549
+ void filterByType(es2panda_AstNode *node, void *argsPointer)
550
+ {
551
+ FilterArgs *args = reinterpret_cast<FilterArgs *>(argsPointer);
552
+ auto type = args->impl->AstNodeTypeConst(args->context, node);
553
+ if ((*args->typesMask)[type]) {
554
+ args->result->push_back(node);
555
+ }
556
+ }
557
+
558
+ KNativePointer impl_FilterNodes2(KNativePointer context, KNativePointer node, KInt type)
559
+ {
560
+ auto _node = reinterpret_cast<es2panda_AstNode*>(node);
561
+ auto _context = reinterpret_cast<es2panda_Context*>(context);
562
+ std::bitset<AST_NODE_TYPE_LIMIT> typesMask;
563
+ typesMask.set(type);
564
+ std::vector<es2panda_AstNode *> result;
565
+ FilterArgs args = { GetImpl(), _context, &typesMask, &result };
566
+ GetImpl()->AstNodeForEach(_node, filterByType, &args);
567
+ return StageArena::cloneVector(result.data(), result.size());
568
+ }
569
+ KOALA_INTEROP_3(FilterNodes2, KNativePointer, KNativePointer, KNativePointer, KInt)
570
+
571
+ KNativePointer impl_FilterNodes3(KNativePointer context, KNativePointer node, KInt* types, KInt typesSize)
572
+ {
573
+ auto _node = reinterpret_cast<es2panda_AstNode*>(node);
574
+ auto _context = reinterpret_cast<es2panda_Context*>(context);
575
+ std::bitset<AST_NODE_TYPE_LIMIT> typesMask;
576
+ for (int i = 0; i < typesSize; i++) {
577
+ typesMask.set(types[i]);
578
+ }
579
+ std::vector<es2panda_AstNode *> result;
580
+ FilterArgs args = { GetImpl(), _context, &typesMask, &result };
581
+ GetImpl()->AstNodeForEach(_node, filterByType, &args);
582
+ return StageArena::cloneVector(result.data(), result.size());
583
+ }
584
+ KOALA_INTEROP_4(FilterNodes3, KNativePointer, KNativePointer, KNativePointer, KInt*, KInt)
507
585
 
508
586
  /*
509
587
  -----------------------------------------------------------------------------------------------------------------------------