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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/libarkts-copy/generator/options.json5 +24 -47
  2. package/build/libarkts-copy/native/meson.build +29 -13
  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 → bridges.cpp} +31 -92
  6. package/build/libarkts-copy/native/src/{common.cc → common.cpp} +240 -107
  7. package/build/libarkts-copy/native/src/common.h +22 -22
  8. package/build/libarkts-copy/native/src/{memoryTracker.cc → memoryTracker.cpp} +45 -32
  9. package/build/libarkts-copy/package.json +13 -11
  10. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +10 -63
  11. package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +9 -3
  12. package/build/libarkts-copy/src/arkts-api/ImportStorage.ts +10 -7
  13. package/build/libarkts-copy/src/arkts-api/ProgramProvider.ts +14 -5
  14. package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +19 -1
  15. package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +4 -0
  16. package/build/libarkts-copy/src/arkts-api/index.ts +0 -2
  17. package/build/libarkts-copy/src/arkts-api/node-cache.ts +12 -3
  18. package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +1 -1
  19. package/build/libarkts-copy/src/arkts-api/node-utilities/OverloadDeclaration.ts +29 -0
  20. package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +4 -4
  21. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +0 -16
  22. package/build/libarkts-copy/src/arkts-api/peers/Config.ts +1 -1
  23. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +9 -9
  24. package/build/libarkts-copy/src/arkts-api/plugins.ts +113 -15
  25. package/build/libarkts-copy/src/arkts-api/static/global.ts +1 -4
  26. package/build/libarkts-copy/src/arkts-api/static/profiler.ts +5 -5
  27. package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +2 -1
  28. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +11 -43
  29. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +41 -9
  30. package/build/libarkts-copy/src/arkts-api/visitor.ts +4 -25
  31. package/build/libarkts-copy/src/checkSdk.ts +1 -1
  32. package/build/libarkts-copy/src/index.ts +1 -2
  33. package/build/libarkts-copy/src/memo-node-cache.ts +143 -0
  34. package/build/libarkts-copy/src/plugin-utils.ts +72 -40
  35. package/build/libarkts-copy/src/reexport-for-generated.ts +3 -1
  36. package/build/libarkts-copy/src/tracer.ts +2 -2
  37. package/build/libarkts-copy/src/utils.ts +10 -14
  38. package/build/libarkts-copy/tsconfig.json +0 -3
  39. package/lib/index.js +5517 -10446
  40. package/package.json +9 -7
  41. package/templates/{bridges.cc → bridges.cpp} +1 -1
  42. package/build/libarkts-copy/src/arkts-api/node-utilities/Program.ts +0 -45
  43. package/build/libarkts-copy/src/arkts-api/peers/DiagnosticKind.ts +0 -23
  44. package/build/libarkts-copy/src/ts-api/factory/nodeFactory.ts +0 -1250
  45. package/build/libarkts-copy/src/ts-api/factory/nodeTests.ts +0 -125
  46. package/build/libarkts-copy/src/ts-api/index.ts +0 -27
  47. package/build/libarkts-copy/src/ts-api/static/enums.ts +0 -18
  48. package/build/libarkts-copy/src/ts-api/types.ts +0 -1075
  49. package/build/libarkts-copy/src/ts-api/utilities/private.ts +0 -292
  50. package/build/libarkts-copy/src/ts-api/utilities/public.ts +0 -55
  51. package/build/libarkts-copy/src/ts-api/visitor/visitor.ts +0 -139
@@ -97,22 +97,6 @@ export abstract class AstNode extends ArktsObject {
97
97
  return unpackString(global.es2panda._AstNodeDumpModifiers(global.context, this.peer));
98
98
  }
99
99
 
100
- // public clone(): this {
101
- // return unpackNonNullableNode(global.generatedEs2panda._AstNodeClone(global.context, this.peer, this.parent.peer));
102
- // }
103
-
104
- // public get parent(): AstNode {
105
- // const parent = global.generatedEs2panda._AstNodeParent(global.context, this.peer)
106
- // if (parent === nullptr) {
107
- // throwError(`no parent`)
108
- // }
109
- // return unpackNonNullableNode(parent)
110
- // }
111
-
112
- // public set parent(node: AstNode) {
113
- // global.generatedEs2panda._AstNodeSetParent(global.context, this.peer, node.peer)
114
- // }
115
-
116
100
  public clone(): this {
117
101
  const clonedNode = unpackNonNullableNode(
118
102
  global.generatedEs2panda._AstNodeClone(global.context, this.peer, this.parent?.peer ?? nullptr)
@@ -44,7 +44,7 @@ export class Config extends ArktsObject {
44
44
  }
45
45
 
46
46
  destroy() {
47
- if (this.peer != nullptr) {
47
+ if (this.peer !== nullptr) {
48
48
  global.es2panda._DestroyConfig(this.peer);
49
49
  this.peer = nullptr;
50
50
  }
@@ -32,7 +32,7 @@ export class Context extends ArktsObject {
32
32
  throw new Error(`Config not initialized`);
33
33
  }
34
34
  return new Context(
35
- global.es2panda._CreateContextFromString(global.config, passString(source), passString(global.filePath))
35
+ global.generatedEs2panda._CreateContextFromString(global.config, passString(source), passString(global.filePath))
36
36
  );
37
37
  }
38
38
 
@@ -44,17 +44,17 @@ export class Context extends ArktsObject {
44
44
  isExternal: KBoolean
45
45
  ): Context {
46
46
  return new Context(
47
- global.es2panda._CreateCacheContextFromFile(configPtr, passString(fileName), globalContextPtr, isExternal)
47
+ global.generatedEs2panda._CreateCacheContextFromFile(configPtr, passString(fileName), globalContextPtr, isExternal)
48
48
  );
49
49
  }
50
50
 
51
51
  static createFromFile(filePath: string): Context {
52
- return new Context(global.es2panda._CreateContextFromFile(global.config, passString(filePath)));
52
+ return new Context(global.generatedEs2panda._CreateContextFromFile(global.config, passString(filePath)));
53
53
  }
54
54
 
55
55
  static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean) {
56
56
  return new Context(
57
- global.es2panda._CreateCacheContextFromFile(
57
+ global.generatedEs2panda._CreateCacheContextFromFile(
58
58
  config.peer,
59
59
  passString(filePath),
60
60
  globalContext.peer,
@@ -68,7 +68,7 @@ export class Context extends ArktsObject {
68
68
  throwError(`Config not initialized`);
69
69
  }
70
70
  return new Context(
71
- global.es2panda._CreateContextGenerateAbcForExternalSourceFiles(
71
+ global.generatedEs2panda._CreateContextGenerateAbcForExternalSourceFiles(
72
72
  global.config,
73
73
  filenames.length,
74
74
  passStringArray(filenames)
@@ -77,7 +77,7 @@ export class Context extends ArktsObject {
77
77
  }
78
78
 
79
79
  destroy() {
80
- if (this.peer != nullptr) {
80
+ if (this.peer !== nullptr) {
81
81
  global.es2panda._DestroyContext(this.peer);
82
82
  this.peer = nullptr;
83
83
  }
@@ -101,7 +101,7 @@ export class Context extends ArktsObject {
101
101
  export class GlobalContext extends ArktsObject {
102
102
  static create(config: Config, externalFileList: string[]): GlobalContext {
103
103
  return new GlobalContext(
104
- global.es2panda._CreateGlobalContext(
104
+ global.generatedEs2panda._CreateGlobalContext(
105
105
  config.peer,
106
106
  passStringArray(externalFileList),
107
107
  externalFileList.length,
@@ -115,8 +115,8 @@ export class GlobalContext extends ArktsObject {
115
115
  }
116
116
 
117
117
  destroy() {
118
- if (this.peer != nullptr) {
119
- global.es2panda._DestroyGlobalContext(this.peer);
118
+ if (this.peer !== nullptr) {
119
+ global.generatedEs2panda._DestroyGlobalContext(this.peer);
120
120
  this.peer = nullptr;
121
121
  }
122
122
  }
@@ -18,7 +18,7 @@ import { ETSModule, Program } from '../../generated';
18
18
  import { ExternalSource } from './peers/ExternalSource';
19
19
  import { KNativePointer, nullptr } from '@koalaui/interop';
20
20
  import { global } from './static/global';
21
- import { RunTransformerHooks } from '../plugin-utils';
21
+ import { Context } from './peers/Context';
22
22
 
23
23
  export interface CompilationOptions {
24
24
  readonly isProgramForCodegeneration: boolean;
@@ -60,18 +60,37 @@ export interface ProjectConfig {
60
60
  integratedHsp: boolean;
61
61
  frameworkMode?: string;
62
62
  isUi2abc?: boolean;
63
+ memoPluginOptions?: Object;
63
64
  }
64
65
 
65
- export interface PluginContext {
66
+ export interface PluginContextBase {
66
67
  setParameter<V>(name: string, value: V): void;
67
68
  parameter<V>(name: string): V | undefined;
68
69
  }
69
70
 
70
- export class PluginContextImpl implements PluginContext {
71
- map = new Map<string, object | undefined>();
71
+ export interface PluginContext extends PluginContextBase {
72
+ /**
73
+ * @deprecated
74
+ */
75
+ setArkTSProgram(program: Program): void
76
+
77
+ /**
78
+ * @deprecated
79
+ */
80
+ getArkTSProgram(): Program | undefined
81
+
82
+ setCodingFilePath(codingFilePath: string): void
72
83
 
73
- private ast: ETSModule | undefined = undefined;
74
- private projectConfig: ProjectConfig | undefined = undefined;
84
+ getCodingFilePath(): string | undefined
85
+
86
+ isCoding(): boolean
87
+
88
+ getProjectConfig(): ProjectConfig | undefined
89
+ }
90
+
91
+
92
+ export class PluginContextBaseImpl implements PluginContextBase {
93
+ map = new Map<string, object | undefined>();
75
94
 
76
95
  parameter<V>(name: string): V | undefined {
77
96
  return this.map.get(name) as V | undefined;
@@ -79,9 +98,38 @@ export class PluginContextImpl implements PluginContext {
79
98
  setParameter<V>(name: string, value: V): void {
80
99
  this.map.set(name, value as object);
81
100
  }
101
+ }
102
+
103
+ // Temporary hack to use plugin context's parameters when compiling with driver
104
+ export function extendPluginContext(context: PluginContextImpl) {
105
+ if (typeof context.setParameter == "function") {
106
+ return
107
+ }
108
+ const pluginContextBaseImpl = new PluginContextBaseImpl()
109
+ context.map = pluginContextBaseImpl.map
110
+ context.setParameter = pluginContextBaseImpl.setParameter
111
+ context.parameter = pluginContextBaseImpl.parameter
112
+ }
113
+
114
+ export class PluginContextImpl extends PluginContextBaseImpl implements PluginContext {
115
+ private ast: ETSModule | undefined;
116
+ private projectConfig: ProjectConfig | undefined;
117
+
118
+ private program: Program | undefined;
119
+ private codingFilePath: string | undefined;
120
+
121
+ setContextPtr(ptr: KNativePointer): void {
122
+ if (!global.compilerContext) {
123
+ global.compilerContext = new Context(ptr);
124
+ } else {
125
+ global.compilerContext.peer = ptr;
126
+ }
127
+ }
128
+
82
129
  getContextPtr(): KNativePointer {
83
130
  return global.compilerContext?.peer ?? nullptr;
84
131
  }
132
+
85
133
  public setProjectConfig(projectConfig: ProjectConfig): void {
86
134
  this.projectConfig = projectConfig;
87
135
  }
@@ -102,14 +150,73 @@ export class PluginContextImpl implements PluginContext {
102
150
  public getArkTSAst(): ETSModule | undefined {
103
151
  return this.ast;
104
152
  }
153
+
154
+ /**
155
+ * @deprecated
156
+ */
157
+ public setArkTSProgram(program: Program): void {
158
+ this.program = program;
159
+ }
160
+
161
+ /**ProjectConfig
162
+ * @deprecated
163
+ */
164
+ public getArkTSProgram(): Program | undefined {
165
+ return this.program;
166
+ }
167
+
168
+ public setCodingFilePath(codingFilePath: string): void {
169
+ this.codingFilePath = codingFilePath;
170
+ }
171
+
172
+ public getCodingFilePath(): string | undefined {
173
+ return this.codingFilePath;
174
+ }
175
+
176
+ public isCoding(): boolean {
177
+ return this.codingFilePath !== undefined;
178
+ }
105
179
  }
106
180
 
181
+ export type PluginHandlerFunction = () => void;
182
+
183
+ export type PluginHandlerObject = {
184
+ order: 'pre' | 'post' | undefined;
185
+ handler: PluginHandlerFunction;
186
+ };
187
+
188
+ export type PluginHandler = PluginHandlerFunction | PluginHandlerObject;
189
+
107
190
  export type ProgramTransformer = (
108
191
  program: Program,
109
192
  compilationOptions: CompilationOptions,
110
193
  context: PluginContext
111
194
  ) => void;
112
195
 
196
+ export interface Plugins {
197
+ name: string;
198
+ afterNew?: PluginHandler;
199
+ parsed?: PluginHandler;
200
+ scopeInited?: PluginHandler;
201
+ checked?: PluginHandler;
202
+ lowered?: PluginHandler;
203
+ asmGenerated?: PluginHandler;
204
+ binGenerated?: PluginHandler;
205
+ clean?: PluginHandler;
206
+ }
207
+
208
+ export type PluginState = keyof Omit<Plugins, 'name'>;
209
+
210
+ export type PluginExecutor = {
211
+ name: string;
212
+ handler: PluginHandlerFunction;
213
+ };
214
+
215
+ export interface BuildConfig {
216
+ compileFiles: string[];
217
+ }
218
+
219
+
113
220
  export function defaultFilter(name: string): boolean {
114
221
  if (name.startsWith('std.')) return false;
115
222
  if (name.startsWith('escompat')) return false;
@@ -127,12 +234,3 @@ export function listPrograms(program: Program, filter: (name: string) => boolean
127
234
  }),
128
235
  ];
129
236
  }
130
-
131
- export interface PluginEntry {
132
- name?: string;
133
- parsed?: (hooks?: RunTransformerHooks) => void;
134
- checked?: (hooks?: RunTransformerHooks) => void;
135
- clean?: (hooks?: RunTransformerHooks) => void;
136
- }
137
-
138
- export type PluginInitializer = (parsedJson?: object, checkedJson?: object) => PluginEntry;
@@ -54,7 +54,7 @@ export class global {
54
54
  return global._config ?? throwError('Global.config not initialized');
55
55
  }
56
56
  public static configIsInitialized(): boolean {
57
- return global._config !== undefined && global._config !== nullptr;
57
+ return !!global._config && global._config !== nullptr;
58
58
  }
59
59
  public static resetConfig(): void {
60
60
  global._config = undefined;
@@ -94,9 +94,6 @@ export class global {
94
94
 
95
95
  public static profiler = new Profiler();
96
96
 
97
- // Check node type values during node creation
98
- public static validatePeerTypes = false;
99
-
100
97
  public static clearContext(): void {
101
98
  global.compilerContext = undefined;
102
99
  }
@@ -80,7 +80,7 @@ export class Profiler implements PerformanceData {
80
80
  return this.pluginsByName[pluginName];
81
81
  }
82
82
 
83
- disableReport = false;
83
+ disableReport = true;
84
84
 
85
85
  nodeCreated() {
86
86
  this.createdNodes++;
@@ -101,16 +101,16 @@ export class Profiler implements PerformanceData {
101
101
  this.transformDepStartTime = Date.now();
102
102
  }
103
103
 
104
- transformEnded(state: Es2pandaContextState, pluginName: string): void {
104
+ transformEnded(): void {
105
105
  const transformEndTime = Date.now();
106
106
  const consumedTime = transformEndTime - this.transformStartTime;
107
- this.getPluginData(pluginName, state).transformTime += consumedTime;
107
+ this.getPluginData(this.curPlugin, this.curContextState).transformTime += consumedTime;
108
108
  }
109
109
 
110
- transformDepEnded(state: Es2pandaContextState, pluginName: string): void {
110
+ transformDepEnded(): void {
111
111
  const transformEndTime = Date.now();
112
112
  const consumedTime = transformEndTime - this.transformDepStartTime;
113
- this.getPluginData(pluginName, state).transformTimeDeps += consumedTime;
113
+ this.getPluginData(this.curPlugin, this.curContextState).transformTimeDeps += consumedTime;
114
114
  }
115
115
 
116
116
  proceededToState(consumedTime: number) {
@@ -13,6 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
+ const { performance } = require('perf_hooks');
16
17
  import * as process from 'process';
17
18
  import { global as localGlobal } from '../static/global';
18
19
 
@@ -286,7 +287,7 @@ export class Performance {
286
287
  '[PERFORMANCE]',
287
288
  `External | ${context.startMemory.external.toFixed(2)} | ${(endMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`
288
289
  );
289
- if (endMemory.arrayBuffers !== undefined) {
290
+ if (!!endMemory.arrayBuffers) {
290
291
  console.log(
291
292
  `Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${((endMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`
292
293
  );
@@ -17,7 +17,6 @@ import { global } from '../static/global';
17
17
  import { isNumber, throwError } from '../../utils';
18
18
  import { KInt, KNativePointer as KPtr, KNativePointer, nullptr, withString, withStringArray } from '@koalaui/interop';
19
19
  import { NativePtrDecoder } from './nativePtrDecoder';
20
- //import { OptimizedNativePtrDecoder as NativePtrDecoder } from "./nativePtrDecoder"
21
20
  import {
22
21
  Es2pandaAstNodeType,
23
22
  Es2pandaModifierFlags,
@@ -33,51 +32,13 @@ export const allFlags = Object.values(Es2pandaModifierFlags)
33
32
  .filter(isNumber)
34
33
  .reduce((prev, next) => prev | next, 0);
35
34
 
36
- export function assertValidPeer(peer: KPtr, expectedKind: Es2pandaAstNodeType): void {
37
- if (peer === nullptr) {
38
- throwError(`invalid peer`);
39
- }
40
-
41
- if (global.validatePeerTypes) {
42
- const peerType = global.generatedEs2panda._AstNodeTypeConst(global.context, peer);
43
- if (
44
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_STRUCT_DECLARATION &&
45
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION
46
- ) {
47
- // Improve: Struct is a child class of Class
48
- return;
49
- }
50
- if (
51
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_IMPORT_DECLARATION &&
52
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_IMPORT_DECLARATION
53
- ) {
54
- // Improve: ETSImportDeclaration is a child of a ImportDeclaration
55
- return;
56
- }
57
- if (
58
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE &&
59
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_BLOCK_STATEMENT
60
- ) {
61
- // Improve: ETSModule is a child of a BlockStatement
62
- return;
63
- }
64
- if (peerType !== expectedKind) {
65
- throwError(`expected: ${Es2pandaAstNodeType[expectedKind]}, got: ${Es2pandaAstNodeType[peerType]}`);
66
- }
67
- }
68
- }
69
-
70
35
  export function acceptNativeObjectArrayResult<T extends ArktsObject>(
71
36
  arrayObject: KNativePointer,
72
37
  factory: (instance: KNativePointer) => T
73
38
  ): T[] {
74
- // For OptimizedNativePtrDecoder
75
- //const decoded = new NativePtrDecoder().decode(arrayObject)
76
- //return decoded.reduce((prev, curr) => {
77
- // prev.push(factory(curr))
78
- // return prev
79
- //}, [] as T[])
80
- return new NativePtrDecoder().decode(arrayObject).map(factory);
39
+ // OptimizedNativePtrDecoder:return decoded.reduce((prev, curr)=>{prev.push(factory(curr));return prev},[] as T[])
40
+ const decoded = new NativePtrDecoder().decode(arrayObject)
41
+ return decoded.map(factory);
81
42
  }
82
43
 
83
44
  export function unpackNonNullableNode<T extends AstNode>(peer: KNativePointer, typeHint?: Es2pandaAstNodeType): T {
@@ -111,8 +72,15 @@ export function unpackNodeArray<T extends AstNode>(nodesPtr: KNativePointer, typ
111
72
  return new NativePtrDecoder().decode(nodesPtr).map((peer: KNativePointer) => unpackNonNullableNode(peer, typeHint));
112
73
  }
113
74
 
75
+ export function unpackNativeObjectArray<T extends ArktsObject>(
76
+ arrayObject: KNativePointer,
77
+ factory: (instance: KNativePointer) => T
78
+ ): T[] {
79
+ return acceptNativeObjectArrayResult(arrayObject, factory);
80
+ }
81
+
114
82
  export function passNodeArray(nodes: readonly ArktsObject[] | undefined): BigUint64Array {
115
- return new BigUint64Array(nodes?.filter((it) => it.peer != undefined)?.map((node) => BigInt(node.peer)) ?? []);
83
+ return new BigUint64Array(nodes?.filter((it) => (!!it.peer))?.map((node) => BigInt(node.peer)) ?? []);
116
84
  }
117
85
 
118
86
  export function unpackString(peer: KNativePointer): string {
@@ -63,13 +63,13 @@ import {
63
63
  MemberExpression,
64
64
  isMethodDefinition,
65
65
  TypeNode,
66
+ DiagnosticKind
66
67
  } from '../../../generated';
67
68
  import { Config } from '../peers/Config';
68
69
  import { Context } from '../peers/Context';
69
70
  import { NodeCache } from '../node-cache';
70
71
  import { factory } from '../factory/nodeFactory';
71
72
  import { traceGlobal } from '../../tracer';
72
- import { DiagnosticKind } from '../peers/DiagnosticKind';
73
73
 
74
74
  /**
75
75
  * Improve: Replace or remove with better naming
@@ -78,11 +78,11 @@ import { DiagnosticKind } from '../peers/DiagnosticKind';
78
78
  */
79
79
  export function createETSModuleFromContext(): ETSModule {
80
80
  let program = global.generatedEs2panda._ContextProgram(global.context);
81
- if (program == nullptr) {
81
+ if (program === nullptr || program === null) {
82
82
  throw new Error(`Program is null for context ${global.context.toString(16)}`);
83
83
  }
84
84
  const ast = global.generatedEs2panda._ProgramAst(global.context, program);
85
- if (ast == nullptr) {
85
+ if (ast === nullptr || ast === null) {
86
86
  throw new Error(`AST is null for program ${program.toString(16)}`);
87
87
  }
88
88
  return new ETSModule(ast, Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE);
@@ -122,10 +122,19 @@ export function checkErrors() {
122
122
  traceGlobal(() => `Terminated due to compilation errors occured`);
123
123
  console.log(unpackString(global.generatedEs2panda._GetAllErrorMessages(global.context)));
124
124
  // global.es2panda._DestroyConfig(global.config)
125
- process.exit(1);
125
+ throw new Error(`Compilation error`)
126
126
  }
127
127
  }
128
128
 
129
+ function format(value: number): string {
130
+ return `${(value / 1024 / 1024 / 1024).toFixed(4)} GB`
131
+ }
132
+
133
+ // Improve: move to profiler
134
+ function dumpMemoryProfilerInfo(str: string) {
135
+ console.log(str, format(process.memoryUsage().rss));
136
+ }
137
+
129
138
  export function proceedToState(state: Es2pandaContextState): void {
130
139
  if (state <= global.es2panda._ContextState(global.context)) {
131
140
  return;
@@ -137,6 +146,9 @@ export function proceedToState(state: Es2pandaContextState): void {
137
146
  traceGlobal(() => `Proceeding to state ${Es2pandaContextState[state]}: done`);
138
147
  const after = Date.now();
139
148
  global.profiler.proceededToState(after - before);
149
+ if (state == Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) {
150
+ dumpMemoryProfilerInfo("Memory usage (rss) after proceed to bin:")
151
+ }
140
152
  checkErrors();
141
153
  }
142
154
 
@@ -372,7 +384,7 @@ export function generateTsDeclarationsFromContext(
372
384
  recordFile: string,
373
385
  genAnnotations: boolean
374
386
  ): KInt {
375
- return global.es2panda._GenerateTsDeclarationsFromContext(
387
+ return global.generatedEs2panda._GenerateTsDeclarationsFromContext(
376
388
  global.context,
377
389
  passString(outputDeclEts),
378
390
  passString(outputEts),
@@ -451,7 +463,7 @@ export function createDiagnosticInfo(
451
463
  ...args: string[]
452
464
  ): DiagnosticInfo {
453
465
  return new DiagnosticInfo(
454
- global.es2panda._CreateDiagnosticInfo(
466
+ global.generatedEs2panda._CreateDiagnosticInfo(
455
467
  global.context,
456
468
  kind.peer,
457
469
  passStringArray(args),
@@ -469,7 +481,7 @@ export function createSuggestionInfo(
469
481
  ...args: string[]
470
482
  ): SuggestionInfo {
471
483
  return new SuggestionInfo(
472
- global.es2panda._CreateSuggestionInfo(
484
+ global.generatedEs2panda._CreateSuggestionInfo(
473
485
  global.context,
474
486
  kind.peer,
475
487
  passStringArray(args),
@@ -493,6 +505,26 @@ export function logDiagnosticWithSuggestion(diagnosticInfo: DiagnosticInfo, sugg
493
505
  global.generatedEs2panda._LogDiagnosticWithSuggestion(global.context, diagnosticInfo.peer, suggestionInfo.peer);
494
506
  }
495
507
 
496
- export function filterNodes(node: AstNode, filter: string): AstNode[] {
497
- return unpackNodeArray(global.es2panda._FilterNodes(global.context, passNode(node), filter));
508
+ export function filterNodes(node: AstNode, filter: string, deeperAfterMatch: boolean): AstNode[] {
509
+ return unpackNodeArray(global.es2panda._FilterNodes(global.context, passNode(node), filter, deeperAfterMatch));
510
+ }
511
+
512
+ export function filterNodesByType<T extends AstNode = AstNode>(node: AstNode, type: Es2pandaAstNodeType): T[] {
513
+ return unpackNodeArray(global.es2panda._FilterNodes2(global.context, passNode(node), type), type);
514
+ }
515
+
516
+ export function filterNodesByTypes(node: AstNode, types: Es2pandaAstNodeType[]): AstNode[] {
517
+ const typesArray = new Int32Array(types.length)
518
+ for (let i = 0; i < types.length; i++) {
519
+ typesArray[i] = types[i]
520
+ }
521
+ return unpackNodeArray(global.es2panda._FilterNodes3(global.context, passNode(node), typesArray, types.length));
522
+ }
523
+
524
+ export function MemInitialize() {
525
+ global.es2panda._MemInitialize()
526
+ }
527
+
528
+ export function MemFinalize() {
529
+ global.es2panda._MemFinalize()
498
530
  }
@@ -258,34 +258,17 @@ function visitETSTypeReferencePart(node: ETSTypeReferencePart, visitor: Visitor)
258
258
  function visitScriptFunction(node: ScriptFunction, visitor: Visitor): ScriptFunction {
259
259
  global.updateTracker.push();
260
260
  const newBody = nodeVisitor(node.body, visitor);
261
- const oldTypeParams = node.typeParams;
262
- const newTypeParams = nodeVisitor(oldTypeParams, visitor);
261
+ const newTypeParams = nodeVisitor(node.typeParams, visitor);
263
262
  const newParams: readonly Expression[] = nodesVisitor(node.params, visitor);
264
263
  const newReturnTypeAnnotation = nodeVisitor(node.returnTypeAnnotation, visitor);
265
264
  const newId = nodeVisitor(node.id, visitor);
266
265
  const newAnnotations: readonly AnnotationUsage[] = nodesVisitor(node.annotations, visitor);
267
266
  if (global.updateTracker.check()) {
268
- if (!isSameNativeObject(newTypeParams, oldTypeParams)) {
269
- const result = factory.createScriptFunction(
270
- newBody,
271
- newTypeParams,
272
- newParams,
273
- newReturnTypeAnnotation,
274
- node.hasReceiver,
275
- node.flags,
276
- node.modifierFlags,
277
- newId,
278
- newAnnotations,
279
- node.getSignaturePointer(),
280
- node.getPreferredReturnTypePointer()
281
- );
282
- result.onUpdate(node);
283
- return result;
284
- }
285
267
  node.setBody(newBody);
286
268
  node.setParams(newParams);
269
+ node.setTypeParams(newTypeParams);
287
270
  node.setReturnTypeAnnotation(newReturnTypeAnnotation);
288
- if (newId) node.setIdent(newId);
271
+ node.setIdent(newId);
289
272
  node.setAnnotations(newAnnotations);
290
273
  }
291
274
  return node;
@@ -314,7 +297,6 @@ function visitMethodDefinition(node: MethodDefinition, visitor: Visitor): Method
314
297
  node.setOverloads(newOverloads);
315
298
  newOverloads.forEach((it): void => {
316
299
  it.setBaseOverloadMethod(node);
317
- it.parent = node;
318
300
  });
319
301
  }
320
302
  return node;
@@ -538,7 +520,6 @@ function visitIfStatement(node: IfStatement, visitor: Visitor): IfStatement {
538
520
  return result;
539
521
  }
540
522
  node.setTest(newTest);
541
- if (newTest) newTest.parent = node;
542
523
  node.setAlternate(newAlternate);
543
524
  }
544
525
  return node;
@@ -828,7 +809,6 @@ function visitETSNewClassInstanceExpression(
828
809
  return result;
829
810
  }
830
811
  node.setArguments(newArguments);
831
- newArguments.forEach((it) => (it.parent = node));
832
812
  }
833
813
  return node;
834
814
  }
@@ -865,7 +845,7 @@ function visitForUpdateStatement(node: ForUpdateStatement, visitor: Visitor): Fo
865
845
  global.updateTracker.push();
866
846
  const newInit = nodeVisitor(node.init, visitor);
867
847
  const newTest = nodeVisitor(node.test, visitor);
868
- const newUpdate = nodeVisitor(node.update, visitor);
848
+ const newUpdate = nodeVisitor(node.updateExpression, visitor);
869
849
  const newBody = nodeVisitor(node.body, visitor);
870
850
  if (global.updateTracker.check()) {
871
851
  const result = factory.createForUpdateStatement(newInit, newTest, newUpdate, newBody);
@@ -922,7 +902,6 @@ function visitTSNonNullExpression(node: TSNonNullExpression, visitor: Visitor):
922
902
  const newExpr = nodeVisitor(node.expr, visitor);
923
903
  if (global.updateTracker.check()) {
924
904
  node.setExpr(newExpr);
925
- if (newExpr) newExpr.parent = node;
926
905
  }
927
906
  return node;
928
907
  }
@@ -31,7 +31,7 @@ export function checkSDK() {
31
31
  if (!version) reportErrorAndExit(`version is unknown`);
32
32
  const packageJsonOur = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')).toString());
33
33
  const expectedVersion = packageJsonOur.config.panda_sdk_version;
34
- if (expectedVersion && expectedVersion != 'next' && version != expectedVersion)
34
+ if (expectedVersion && expectedVersion !== 'next' && version !== expectedVersion)
35
35
  console.log(`WARNING: Panda SDK version "${version}" doesn't match expected "${expectedVersion}"`);
36
36
  else console.log(`Using Panda ${version}`);
37
37
  }
@@ -28,7 +28,6 @@ export * from './arkts-api/AbstractVisitor';
28
28
  export * from './arkts-api/plugins';
29
29
  export * from './arkts-api/ImportStorage';
30
30
  export * from './arkts-api/ProgramProvider';
31
- export * from './arkts-api/node-utilities/Program';
32
31
  export * from './arkts-api/node-utilities/ArkTsConfig';
33
32
 
34
33
  export * from './arkts-api/peers/AstNode';
@@ -38,10 +37,10 @@ export { GlobalContext } from './arkts-api/peers/Context';
38
37
  export * from './arkts-api/peers/ExternalSource';
39
38
  export * from './arkts-api/peers/ImportPathManager';
40
39
  export * from './arkts-api/peers/Options';
41
- export * from './arkts-api/peers/DiagnosticKind';
42
40
  export { global as arktsGlobal } from './arkts-api/static/global';
43
41
  export * from './arkts-api/static/globalUtils';
44
42
  export * as arkts from './arkts-api';
45
43
 
46
44
  export * from './plugin-utils';
47
45
  export * from './tracer';
46
+ export * from './memo-node-cache';