@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
@@ -37,9 +37,6 @@ import { Es2pandaPluginDiagnosticType } from '../generated/Es2pandaEnums';
37
37
  export type KPtrArray = BigUint64Array;
38
38
 
39
39
  export class Es2pandaNativeModule {
40
- _AnnotationAllowedAnnotations(context: KPtr, node: KPtr, returnLen: KPtr): KPtr {
41
- throw new Error('Not implemented');
42
- }
43
40
  _AstNodeRebind(context: KPtr, node: KPtr): void {
44
41
  throw new Error('Not implemented');
45
42
  }
@@ -64,9 +61,6 @@ export class Es2pandaNativeModule {
64
61
  _HasGlobalStructInfo(context: KNativePointer, str: String): KBoolean {
65
62
  throw new Error('Not implemented');
66
63
  }
67
- _DestroyContext(context: KPtr): void {
68
- throw new Error('Not implemented');
69
- }
70
64
  _ProceedToState(context: KPtr, state: number): void {
71
65
  throw new Error('Not implemented');
72
66
  }
@@ -91,9 +85,6 @@ export class Es2pandaNativeModule {
91
85
  _VariableDeclaration(context: KPtr, variable: KPtr): KPtr {
92
86
  throw new Error('Not implemented');
93
87
  }
94
- _DeclNode(context: KPtr, decl: KPtr): KPtr {
95
- throw new Error('Not implemented');
96
- }
97
88
  _ProgramSourceFilePath(context: KNativePointer, instance: KNativePointer): KNativePointer {
98
89
  throw new Error('Not implemented');
99
90
  }
@@ -141,47 +132,6 @@ export class Es2pandaNativeModule {
141
132
  _OptionsArkTsConfig(context: KNativePointer, options: KNativePointer): KNativePointer {
142
133
  throw new Error('Not implemented');
143
134
  }
144
- _Checker_CreateOpaqueTypeNode(context: KNativePointer, type: KNativePointer): KNativePointer {
145
- throw new Error('Not implemented');
146
- }
147
- _Checker_ScriptFunctionSignature(context: KNativePointer, node: KNativePointer): KNativePointer {
148
- throw new Error('Not implemented');
149
- }
150
- _Checker_ScriptFunctionSetSignature(
151
- context: KNativePointer,
152
- node: KNativePointer,
153
- signature: KNativePointer
154
- ): void {
155
- throw new Error('Not implemented');
156
- }
157
- _Checker_SignatureReturnType(context: KNativePointer, signature: KNativePointer): KNativePointer {
158
- throw new Error('Not implemented');
159
- }
160
- _Checker_ScriptFunctionGetPreferredReturnType(context: KNativePointer, node: KNativePointer): KNativePointer {
161
- throw new Error('Not implemented');
162
- }
163
- _Checker_ScriptFunctionSetPreferredReturnType(
164
- context: KNativePointer,
165
- node: KNativePointer,
166
- type: KNativePointer
167
- ): void {
168
- throw new Error('Not implemented');
169
- }
170
- _Checker_ExpressionGetPreferredType(context: KNativePointer, node: KNativePointer): KNativePointer {
171
- throw new Error('Not implemented');
172
- }
173
- _Checker_ExpressionSetPreferredType(context: KNativePointer, node: KNativePointer, type: KNativePointer): void {
174
- throw new Error('Not implemented');
175
- }
176
- _Checker_TypeToString(context: KNativePointer, type: KNativePointer): KNativePointer {
177
- throw new Error('Not implemented');
178
- }
179
- _Checker_TypeClone(context: KNativePointer, type: KNativePointer): KNativePointer {
180
- throw new Error('Not implemented');
181
- }
182
- _Checker_TypeNodeGetType(context: KNativePointer, node: KNativePointer): KNativePointer {
183
- throw new Error('Not implemented');
184
- }
185
135
  _ScriptFunctionSetParams(
186
136
  context: KNativePointer,
187
137
  receiver: KNativePointer,
@@ -234,12 +184,6 @@ export class Es2pandaNativeModule {
234
184
  _SetUpSoPath(soPath: string): void {
235
185
  throw new Error('Not implemented');
236
186
  }
237
- _MemInitialize(): void {
238
- throw new Error('Not implemented');
239
- }
240
- _MemFinalize(): void {
241
- throw new Error('Not implemented');
242
- }
243
187
  _ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer): KBoolean {
244
188
  throw new Error('Not implemented');
245
189
  }
@@ -14,11 +14,10 @@
14
14
  */
15
15
 
16
16
  import { KNativePointer } from '@koalaui/interop';
17
- import { ETSModule, ImportDeclaration, isETSImportDeclaration, Program, Statement } from '../../generated';
17
+ import { ETSImportDeclaration, isETSImportDeclaration, Program, Statement } from '../../generated';
18
18
  import { passNode, passNodeArray, unpackNonNullableNode } from './utilities/private';
19
19
  import { global } from './static/global';
20
20
  import { Es2pandaImportFlags, Es2pandaImportKinds } from '../../generated/Es2pandaEnums';
21
- import { factory } from './factory/nodeFactory';
22
21
 
23
22
  export class ImportStorage {
24
23
  // Improve: migrate to wrappers instead of pointers
@@ -48,12 +47,18 @@ export class ImportStorage {
48
47
  const newStatements: Statement[] = [];
49
48
  for (const statement of statements) {
50
49
  if (isETSImportDeclaration(statement) && !this.imports.has(statement.peer)) {
50
+ // Weak workaround to avoid self-imports (see panda issue 31156)
51
+ if (this.program.moduleName == statement.source?.str || this.program.moduleName == `${statement.source?.str}.index`) {
52
+ continue
53
+ }
54
+
55
+ // On checked state imports from unparsed sources cannot be inserted
51
56
  if (!this.isParserState && !this.importSources.has(statement.source?.str)) {
52
57
  console.warn('Attempt to insert import from new source after parsed state:');
53
58
  console.warn(statement.dumpSrc());
54
59
  }
55
60
 
56
- const importDeclaration = unpackNonNullableNode<ImportDeclaration>(
61
+ const importDeclaration = unpackNonNullableNode<ETSImportDeclaration>(
57
62
  // Note: this call is important, we cannot just pass "statement" to "InsertETSImportDeclarationAndParse"
58
63
  global.es2panda._ETSParserBuildImportDeclaration(
59
64
  global.context,
@@ -30,6 +30,7 @@ import {
30
30
  TryStatement,
31
31
  TSTypeParameter,
32
32
  VariableDeclarator,
33
+ OverloadDeclaration,
33
34
  } from '../../../generated';
34
35
  import { factory as generatedFactory } from '../../../generated/factory';
35
36
  import {
@@ -59,6 +60,7 @@ import { createArrayExpression, updateArrayExpression } from '../node-utilities/
59
60
  import { updateBlockStatement } from '../node-utilities/BlockStatement';
60
61
  import { updateETSModule } from '../node-utilities/ETSModule';
61
62
  import { createOpaqueTypeNode } from '../node-utilities/OpaqueTypeNode';
63
+ import { createOverloadDeclaration } from '../node-utilities/OverloadDeclaration';
62
64
 
63
65
  export const factory = {
64
66
  ...generatedFactory,
@@ -141,4 +143,6 @@ export const factory = {
141
143
  updateClassStaticBlock: ClassStaticBlock.updateClassStaticBlock,
142
144
 
143
145
  createOpaqueTypeNode,
146
+
147
+ createOverloadDeclaration,
144
148
  };
@@ -29,11 +29,9 @@ export * from './ProgramProvider';
29
29
  export * from './peers/AstNode';
30
30
  export * from './peers/Config';
31
31
  export * from './peers/Context';
32
- export { GlobalContext } from './peers/Context';
33
32
  export * from './peers/ExternalSource';
34
33
  export * from './peers/Options';
35
34
  export * from './node-utilities/ArkTsConfig';
36
- export * from './node-utilities/Program';
37
35
  export * from './peers/ImportPathManager';
38
36
  export * from './static/globalUtils';
39
37
  export { global as arktsGlobal } from './static/global';
@@ -20,7 +20,7 @@ import { Es2pandaAstNodeType } from '../../../generated/Es2pandaEnums';
20
20
 
21
21
  export function createOpaqueTypeNode(typePointer: KNativePointer): OpaqueTypeNode {
22
22
  return new OpaqueTypeNode(
23
- global.es2panda._Checker_CreateOpaqueTypeNode(global.context, typePointer),
23
+ global.generatedEs2panda._CreateOpaqueTypeNode(global.context, typePointer),
24
24
  Es2pandaAstNodeType.AST_NODE_TYPE_OPAQUE_TYPE_NODE
25
25
  );
26
26
  }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import { Expression, OverloadDeclaration } from '../../../generated';
17
+ import { Es2pandaOverloadDeclFlags, Es2pandaModifierFlags } from '../../../generated/Es2pandaEnums';
18
+
19
+ export function createOverloadDeclaration(
20
+ key: Expression | undefined,
21
+ overloads: readonly Expression[],
22
+ flags: Es2pandaOverloadDeclFlags,
23
+ modifiers: Es2pandaModifierFlags,
24
+ ): OverloadDeclaration {
25
+ const res = OverloadDeclaration.createOverloadDeclaration(key, modifiers);
26
+ res.setOverloadedList(overloads)
27
+ res.addOverloadDeclFlag(flags)
28
+ return res
29
+ }
@@ -14,111 +14,77 @@
14
14
  */
15
15
 
16
16
  import { ArktsObject } from './ArktsObject';
17
- import { Program } from '../../../generated';
17
+ import { compiler, Program } from '../../../generated';
18
18
  import { global } from '../static/global';
19
- import { passString, passStringArray } from '../utilities/private';
20
19
  import { KNativePointer, nullptr, KBoolean } from '@koalaui/interop';
21
20
  import { Config } from './Config';
22
- import { filterSource, throwError } from '../../utils';
21
+ import { filterSource } from '../../utils';
23
22
  import { AstNode } from './AstNode';
24
23
 
24
+ // Perhaps, this file would become generated some time later
25
+ // Please, do not add hard logic here
26
+
25
27
  export class Context extends ArktsObject {
26
28
  constructor(peer: KNativePointer) {
27
29
  super(peer);
28
30
  }
29
31
 
30
32
  static createFromString(source: string): Context {
31
- if (!global.configIsInitialized()) {
32
- throw new Error(`Config not initialized`);
33
- }
34
- return new Context(
35
- global.generatedEs2panda._CreateContextFromString(global.config, passString(source), passString(global.filePath))
36
- );
33
+ return compiler.createContextFromString(global.configObj, source, global.filePath);
37
34
  }
38
35
 
39
- /** @deprecated Use {@link createCacheFromFile} instead */
40
36
  static createCacheContextFromFile(
41
37
  configPtr: KNativePointer,
42
38
  fileName: string,
43
39
  globalContextPtr: KNativePointer,
44
40
  isExternal: KBoolean
45
41
  ): Context {
46
- return new Context(
47
- global.generatedEs2panda._CreateCacheContextFromFile(configPtr, passString(fileName), globalContextPtr, isExternal)
48
- );
42
+ return compiler.createCacheContextFromFile(new Config(configPtr), fileName, new GlobalContext(globalContextPtr), isExternal);
49
43
  }
50
44
 
51
45
  static createFromFile(filePath: string): Context {
52
- return new Context(global.generatedEs2panda._CreateContextFromStringWithHistory(global.config, passString(filePath), passString(filePath)));
53
- return new Context(global.generatedEs2panda._CreateContextFromFile(global.config, passString(filePath)));
46
+ return compiler.createContextFromFile(global.configObj, filePath);
54
47
  }
55
48
 
56
- static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean) {
57
- return new Context(
58
- global.generatedEs2panda._CreateCacheContextFromFile(
59
- config.peer,
60
- passString(filePath),
61
- globalContext.peer,
62
- isExternal
63
- )
64
- );
49
+ static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean): Context {
50
+ return compiler.createCacheContextFromFile(config, filePath, globalContext, isExternal);
65
51
  }
66
52
 
67
53
  static createContextGenerateAbcForExternalSourceFiles(filenames: string[]): Context {
68
- if (!global.configIsInitialized()) {
69
- throwError(`Config not initialized`);
70
- }
71
- return new Context(
72
- global.generatedEs2panda._CreateContextGenerateAbcForExternalSourceFiles(
73
- global.config,
74
- filenames.length,
75
- passStringArray(filenames)
76
- )
77
- );
54
+ return compiler.createContextGenerateAbcForExternalSourceFiles(global.configObj, filenames);
78
55
  }
79
56
 
80
- destroy() {
81
- if (this.peer !== nullptr) {
82
- global.es2panda._DestroyContext(this.peer);
83
- this.peer = nullptr;
84
- }
57
+ static createFromStringWithHistory(source: string): Context {
58
+ return compiler.createContextFromStringWithHistory(global.configObj, source, global.filePath);
59
+ }
60
+
61
+ destroy(): void {
62
+ compiler.destroyContext();
85
63
  }
86
64
 
87
65
  /** @deprecated */
88
66
  static destroyAndRecreate(ast: AstNode): Context {
89
67
  console.log('[TS WRAPPER] DESTROY AND RECREATE');
90
68
  const source = filterSource(ast.dumpSrc());
91
- global.es2panda._DestroyContext(global.context);
92
- global.compilerContext = Context.createFromString(source) as any; // Improve: commonize Context
93
-
94
- return new Context(global.context);
69
+ compiler.destroyContext();
70
+ return global.compilerContext = Context.createFromString(source);
95
71
  }
96
72
 
97
73
  get program(): Program {
98
- return new Program(global.generatedEs2panda._ContextProgram(this.peer));
74
+ return compiler.contextProgram();
99
75
  }
100
76
  }
101
77
 
102
78
  export class GlobalContext extends ArktsObject {
103
- static create(config: Config, externalFileList: string[]): GlobalContext {
104
- return new GlobalContext(
105
- global.generatedEs2panda._CreateGlobalContext(
106
- config.peer,
107
- passStringArray(externalFileList),
108
- externalFileList.length,
109
- false
110
- )
111
- );
112
- }
113
-
114
79
  constructor(peer: KNativePointer) {
115
80
  super(peer);
116
81
  }
117
82
 
83
+ static create(config: Config, externalFileList: string[]): GlobalContext {
84
+ return compiler.createGlobalContext(config, externalFileList, false);
85
+ }
86
+
118
87
  destroy() {
119
- if (this.peer !== nullptr) {
120
- global.generatedEs2panda._DestroyGlobalContext(this.peer);
121
- this.peer = nullptr;
122
- }
88
+ compiler.destroyGlobalContext();
123
89
  }
124
90
  }
@@ -13,11 +13,13 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
- import { global } from '../static/global';
17
- import { acceptNativeObjectArrayResult, unpackString } from '../utilities/private';
18
- import { KNativePointer, nullptr } from '@koalaui/interop';
16
+ import { KNativePointer } from '@koalaui/interop';
19
17
  import { Program } from '../../../generated';
20
18
  import { ArktsObject } from './ArktsObject';
19
+ import { compiler } from '../../../generated';
20
+
21
+ // Perhaps, this file would become generated some time later
22
+ // Please, do not add hard logic here
21
23
 
22
24
  export class ExternalSource extends ArktsObject {
23
25
  constructor(peer: KNativePointer) {
@@ -25,17 +27,10 @@ export class ExternalSource extends ArktsObject {
25
27
  }
26
28
 
27
29
  getName(): string {
28
- return unpackString(global.es2panda._ExternalSourceName(this.peer));
29
- }
30
-
31
- get programs(): Program[] {
32
- return acceptNativeObjectArrayResult<Program>(
33
- global.es2panda._ExternalSourcePrograms(this.peer),
34
- (instance: KNativePointer) => new Program(instance)
35
- );
30
+ return compiler.externalSourceName(this);
36
31
  }
37
32
 
38
- static instantiate(peer: KNativePointer) {
39
- return new ExternalSource(peer);
33
+ get programs(): readonly Program[] {
34
+ return compiler.externalSourcePrograms(this);
40
35
  }
41
36
  }
@@ -18,7 +18,6 @@ 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';
22
21
  import { Context } from './peers/Context';
23
22
 
24
23
  export interface CompilationOptions {
@@ -61,6 +60,7 @@ export interface ProjectConfig {
61
60
  integratedHsp: boolean;
62
61
  frameworkMode?: string;
63
62
  isUi2abc?: boolean;
63
+ memoPluginOptions?: Object;
64
64
  }
65
65
 
66
66
  export interface PluginContextBase {
@@ -84,6 +84,8 @@ export interface PluginContext extends PluginContextBase {
84
84
  getCodingFilePath(): string | undefined
85
85
 
86
86
  isCoding(): boolean
87
+
88
+ getProjectConfig(): ProjectConfig | undefined
87
89
  }
88
90
 
89
91
 
@@ -221,10 +223,10 @@ export function defaultFilter(name: string): boolean {
221
223
  return true;
222
224
  }
223
225
 
224
- export function listPrograms(program: Program, filter: (name: string) => boolean = defaultFilter): Program[] {
226
+ export function listPrograms(program: Program, filter: (name: string) => boolean = defaultFilter): readonly Program[] {
225
227
  return [
226
228
  program,
227
- ...program.getExternalSources().flatMap((it: ExternalSource): Program[] => {
229
+ ...program.getExternalSources().flatMap((it: ExternalSource): readonly Program[] => {
228
230
  if (filter(it.getName())) {
229
231
  return it.programs;
230
232
  }
@@ -232,12 +234,3 @@ export function listPrograms(program: Program, filter: (name: string) => boolean
232
234
  }),
233
235
  ];
234
236
  }
235
-
236
- export interface PluginEntry {
237
- name?: string;
238
- parsed?: (hooks?: RunTransformerHooks) => void;
239
- checked?: (hooks?: RunTransformerHooks) => void;
240
- clean?: (hooks?: RunTransformerHooks) => void;
241
- }
242
-
243
- export type PluginInitializer = (parsedJson?: object, checkedJson?: object) => PluginEntry;
@@ -40,6 +40,7 @@ export class UpdateTracker {
40
40
  }
41
41
 
42
42
  export class global {
43
+ /** @deprecated */
43
44
  public static filePath: string = './plugins/input/main.ets';
44
45
 
45
46
  public static arktsconfig?: ArkTsConfig;
@@ -68,7 +69,6 @@ export class global {
68
69
 
69
70
  // Improve: rename to context when the pointer valued one is eliminated
70
71
  public static compilerContext: Context | undefined;
71
- public static isContextGenerateAbcForExternalSourceFiles: boolean = false;
72
72
 
73
73
  private static _es2panda: Es2pandaNativeModule | undefined = undefined;
74
74
  public static get es2panda(): Es2pandaNativeModule {
@@ -79,6 +79,13 @@ export class global {
79
79
  }
80
80
 
81
81
  private static _generatedEs2panda: GeneratedEs2pandaNativeModule | undefined = undefined;
82
+ /**
83
+ * @deprecated
84
+ *
85
+ * You should not generally use generatedEs2panda in handwritten code
86
+ * (only in exceptional cases).
87
+ * Please use generated wrapper for native call instead.
88
+ */
82
89
  public static get generatedEs2panda(): GeneratedEs2pandaNativeModule {
83
90
  if (this._generatedEs2panda === undefined) {
84
91
  this._generatedEs2panda = initGeneratedEs2panda();
@@ -94,9 +101,6 @@ export class global {
94
101
 
95
102
  public static profiler = new Profiler();
96
103
 
97
- // Check node type values during node creation
98
- public static validatePeerTypes = false;
99
-
100
104
  public static clearContext(): void {
101
105
  global.compilerContext = undefined;
102
106
  }
@@ -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) {
@@ -61,14 +61,14 @@ export function extension_MethodDefinitionOnUpdate(this: MethodDefinition, origi
61
61
 
62
62
  // Improve: generate checker related stuff
63
63
  export function extension_ScriptFunctionGetSignaturePointer(this: ScriptFunction): KNativePointer {
64
- return global.es2panda._Checker_ScriptFunctionSignature(global.context, this.peer);
64
+ return global.generatedEs2panda._ScriptFunctionSignature(global.context, this.peer);
65
65
  }
66
66
 
67
67
  export function extension_ScriptFunctionSetSignaturePointer(
68
68
  this: ScriptFunction,
69
69
  signaturePointer: KNativePointer
70
70
  ): void {
71
- global.es2panda._Checker_ScriptFunctionSetSignature(global.context, this.peer, signaturePointer);
71
+ global.generatedEs2panda._ScriptFunctionSetSignature(global.context, this.peer, signaturePointer);
72
72
  }
73
73
 
74
74
  // Improve: weird API
@@ -81,23 +81,23 @@ export function extension_ScriptFunctionGetParamsCasted(this: ScriptFunction): r
81
81
 
82
82
  // Improve: perhaps "preferredReturnType" stuff can be removed later if "signature" is always enough
83
83
  export function extension_ScriptFunctionGetPreferredReturnTypePointer(this: ScriptFunction): KNativePointer {
84
- return global.es2panda._Checker_ScriptFunctionGetPreferredReturnType(global.context, this.peer);
84
+ return global.generatedEs2panda._ScriptFunctionGetPreferredReturnType(global.context, this.peer);
85
85
  }
86
86
 
87
87
  export function extension_ScriptFunctionSetPreferredReturnTypePointer(
88
88
  this: ScriptFunction,
89
89
  typePointer: KNativePointer
90
90
  ): void {
91
- global.es2panda._Checker_ScriptFunctionSetPreferredReturnType(global.context, this.peer, typePointer);
91
+ global.generatedEs2panda._ScriptFunctionSetPreferredReturnType(global.context, this.peer, typePointer);
92
92
  }
93
93
 
94
94
  // Improve: generate checker related stuff
95
95
  export function extension_ExpressionGetPreferredTypePointer(this: Expression): KNativePointer {
96
- return global.es2panda._Checker_ExpressionGetPreferredType(global.context, this.peer);
96
+ return global.generatedEs2panda._ExpressionPreferredTypeConst(global.context, this.peer);
97
97
  }
98
98
 
99
99
  export function extension_ExpressionSetPreferredTypePointer(this: Expression, typePointer: KNativePointer): void {
100
- global.es2panda._Checker_ExpressionSetPreferredType(global.context, this.peer, typePointer);
100
+ global.generatedEs2panda._ExpressionSetPreferredType(global.context, this.peer, typePointer);
101
101
  }
102
102
 
103
103
  // Improve: weird API
@@ -108,12 +108,9 @@ export function extension_ProgramGetAstCasted(this: Program): ETSModule {
108
108
  );
109
109
  }
110
110
 
111
- // Improve: generate methods with string[] args or return type
112
- export function extension_ProgramGetExternalSources(this: Program): ExternalSource[] {
113
- return acceptNativeObjectArrayResult<ExternalSource>(
114
- global.es2panda._ProgramExternalSources(global.context, this.peer),
115
- ExternalSource.instantiate
116
- );
111
+ /** @deprecated Now generated */
112
+ export function extension_ProgramGetExternalSources(this: Program): readonly ExternalSource[] {
113
+ return this.externalSources;
117
114
  }
118
115
 
119
116
  // Improve: SourcePositionLine is global in idl
@@ -32,40 +32,6 @@ export const allFlags = Object.values(Es2pandaModifierFlags)
32
32
  .filter(isNumber)
33
33
  .reduce((prev, next) => prev | next, 0);
34
34
 
35
- export function assertValidPeer(peer: KPtr, expectedKind: Es2pandaAstNodeType): void {
36
- if (peer === nullptr) {
37
- throwError(`invalid peer`);
38
- }
39
-
40
- if (global.validatePeerTypes) {
41
- const peerType = global.generatedEs2panda._AstNodeTypeConst(global.context, peer);
42
- if (
43
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_STRUCT_DECLARATION &&
44
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION
45
- ) {
46
- // Improve: Struct is a child class of Class
47
- return;
48
- }
49
- if (
50
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_IMPORT_DECLARATION &&
51
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_IMPORT_DECLARATION
52
- ) {
53
- // Improve: ETSImportDeclaration is a child of a ImportDeclaration
54
- return;
55
- }
56
- if (
57
- peerType === Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE &&
58
- expectedKind === Es2pandaAstNodeType.AST_NODE_TYPE_BLOCK_STATEMENT
59
- ) {
60
- // Improve: ETSModule is a child of a BlockStatement
61
- return;
62
- }
63
- if (peerType !== expectedKind) {
64
- throwError(`expected: ${Es2pandaAstNodeType[expectedKind]}, got: ${Es2pandaAstNodeType[peerType]}`);
65
- }
66
- }
67
- }
68
-
69
35
  export function acceptNativeObjectArrayResult<T extends ArktsObject>(
70
36
  arrayObject: KNativePointer,
71
37
  factory: (instance: KNativePointer) => T
@@ -106,6 +72,16 @@ export function unpackNodeArray<T extends AstNode>(nodesPtr: KNativePointer, typ
106
72
  return new NativePtrDecoder().decode(nodesPtr).map((peer: KNativePointer) => unpackNonNullableNode(peer, typeHint));
107
73
  }
108
74
 
75
+ export function unpackNativeObjectArray<T extends ArktsObject>(
76
+ arrayObject: KNativePointer,
77
+ factory: (instance: KNativePointer) => T
78
+ ): T[] {
79
+ if (arrayObject == nullptr) {
80
+ return [];
81
+ }
82
+ return acceptNativeObjectArrayResult(arrayObject, factory);
83
+ }
84
+
109
85
  export function passNodeArray(nodes: readonly ArktsObject[] | undefined): BigUint64Array {
110
86
  return new BigUint64Array(nodes?.filter((it) => (!!it.peer))?.map((node) => BigInt(node.peer)) ?? []);
111
87
  }
@@ -70,6 +70,7 @@ import { Context } from '../peers/Context';
70
70
  import { NodeCache } from '../node-cache';
71
71
  import { factory } from '../factory/nodeFactory';
72
72
  import { traceGlobal } from '../../tracer';
73
+ import { compiler } from '../../../generated';
73
74
 
74
75
  /**
75
76
  * Improve: Replace or remove with better naming
@@ -292,7 +293,7 @@ export function getAnnotations(node: AstNode): readonly AnnotationUsage[] {
292
293
  if (!isFunctionDeclaration(node) && !isScriptFunction(node) && !isClassDefinition(node)) {
293
294
  throwError('for now annotations allowed only for: functionDeclaration, scriptFunction, classDefinition');
294
295
  }
295
- return unpackNodeArray(global.es2panda._AnnotationAllowedAnnotations(global.context, node.peer, nullptr));
296
+ return unpackNodeArray(global.generatedEs2panda._AnnotationAllowedAnnotations(global.context, node.peer));
296
297
  }
297
298
 
298
299
  export function getOriginalNode(node: AstNode): AstNode {
@@ -411,14 +412,14 @@ export function signatureReturnType(signature: KNativePointer): KNativePointer {
411
412
  if (!signature) {
412
413
  return nullptr;
413
414
  }
414
- return global.es2panda._Checker_SignatureReturnType(global.context, signature);
415
+ return global.generatedEs2panda._SignatureReturnType(global.context, signature);
415
416
  }
416
417
 
417
418
  export function convertCheckerTypeToTypeNode(typePeer: KNativePointer | undefined): TypeNode | undefined {
418
419
  if (!typePeer) {
419
420
  return undefined;
420
421
  }
421
- return factory.createOpaqueTypeNode(global.es2panda._Checker_TypeClone(global.context, typePeer));
422
+ return factory.createOpaqueTypeNode(global.generatedEs2panda._TypeClone(global.context, typePeer));
422
423
  }
423
424
 
424
425
  export function originalSourcePositionString(node: AstNode | undefined) {
@@ -521,10 +522,12 @@ export function filterNodesByTypes(node: AstNode, types: Es2pandaAstNodeType[]):
521
522
  return unpackNodeArray(global.es2panda._FilterNodes3(global.context, passNode(node), typesArray, types.length));
522
523
  }
523
524
 
525
+ // This functions are used as capitalized in build-system, unlike the others
526
+ // See https://gitcode.com/openharmony/arkcompiler_ets_frontend/issues/8196
524
527
  export function MemInitialize() {
525
- global.es2panda._MemInitialize()
528
+ compiler.memInitialize()
526
529
  }
527
530
 
528
531
  export function MemFinalize() {
529
- global.es2panda._MemFinalize()
532
+ compiler.memFinalize()
530
533
  }