arkanalyzer 1.0.87 → 1.0.88

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 (91) hide show
  1. package/lib/Config.d.ts +4 -1
  2. package/lib/Config.d.ts.map +1 -1
  3. package/lib/Config.js +17 -2
  4. package/lib/Scene.d.ts.map +1 -1
  5. package/lib/Scene.js +7 -8
  6. package/lib/cli/commands/cg.d.ts +27 -6
  7. package/lib/cli/commands/cg.d.ts.map +1 -1
  8. package/lib/cli/commands/cg.js +9 -6
  9. package/lib/core/base/Expr.js +3 -3
  10. package/lib/core/base/Position.d.ts +1 -1
  11. package/lib/core/base/Position.d.ts.map +1 -1
  12. package/lib/core/base/Position.js +2 -2
  13. package/lib/core/common/Const.d.ts +1 -0
  14. package/lib/core/common/Const.d.ts.map +1 -1
  15. package/lib/core/common/Const.js +2 -1
  16. package/lib/core/common/IRInference.d.ts.map +1 -1
  17. package/lib/core/common/IRInference.js +1 -1
  18. package/lib/core/common/IRUtils.d.ts.map +1 -1
  19. package/lib/core/common/IRUtils.js +3 -33
  20. package/lib/core/model/ArkClass.d.ts +3 -0
  21. package/lib/core/model/ArkClass.d.ts.map +1 -1
  22. package/lib/core/model/ArkClass.js +13 -2
  23. package/lib/core/model/ArkMetadata.d.ts +32 -1
  24. package/lib/core/model/ArkMetadata.d.ts.map +1 -1
  25. package/lib/core/model/ArkMetadata.js +28 -2
  26. package/lib/core/model/builder/ArkMetadataBuilder.d.ts +21 -0
  27. package/lib/core/model/builder/ArkMetadataBuilder.d.ts.map +1 -0
  28. package/lib/core/model/builder/ArkMetadataBuilder.js +160 -0
  29. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  30. package/lib/core/model/builder/ArkMethodBuilder.js +32 -24
  31. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.d.ts +8 -0
  32. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.d.ts.map +1 -0
  33. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiApi.js +90 -0
  34. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.d.ts +8 -0
  35. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.d.ts.map +1 -0
  36. package/lib/frontend/cppFrontend/ast/astJsonNapi/napiRunner.js +183 -0
  37. package/lib/frontend/cppFrontend/ast/astParser.d.ts +25 -0
  38. package/lib/frontend/cppFrontend/ast/astParser.d.ts.map +1 -0
  39. package/lib/frontend/cppFrontend/ast/astParser.js +280 -0
  40. package/lib/frontend/cppFrontend/ast/astUtils.d.ts +12 -45
  41. package/lib/frontend/cppFrontend/ast/astUtils.d.ts.map +1 -1
  42. package/lib/frontend/cppFrontend/ast/astUtils.js +62 -374
  43. package/lib/frontend/cppFrontend/ast/const.d.ts +0 -13
  44. package/lib/frontend/cppFrontend/ast/const.d.ts.map +1 -1
  45. package/lib/frontend/cppFrontend/ast/const.js +1 -77
  46. package/lib/frontend/cppFrontend/ast/index.d.ts +5 -0
  47. package/lib/frontend/cppFrontend/ast/index.d.ts.map +1 -0
  48. package/lib/frontend/cppFrontend/ast/index.js +31 -0
  49. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts +1 -1
  50. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
  51. package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +55 -55
  52. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
  53. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
  54. package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +151 -151
  55. package/lib/frontend/cppFrontend/common/IRInference.js +2 -2
  56. package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -1
  57. package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
  58. package/lib/frontend/cppFrontend/common/IRUtils.js +2 -2
  59. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts +1 -1
  60. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
  61. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +74 -74
  62. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts +1 -1
  63. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
  64. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +3 -3
  65. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts +1 -1
  66. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
  67. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +1 -1
  68. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
  69. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +16 -17
  70. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts +1 -1
  71. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts.map +1 -1
  72. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts +1 -1
  73. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  74. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +2 -2
  75. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +1 -1
  76. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  77. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +2 -2
  78. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -1
  79. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
  80. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts +1 -1
  81. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
  82. package/lib/frontend/cppFrontend/model/builder/builderUtils.js +3 -3
  83. package/lib/index.d.ts +2 -2
  84. package/lib/index.d.ts.map +1 -1
  85. package/lib/index.js +7 -6
  86. package/lib/save/source/SourceStmt.d.ts.map +1 -1
  87. package/lib/save/source/SourceStmt.js +3 -1
  88. package/lib/utils/FileUtils.d.ts +1 -0
  89. package/lib/utils/FileUtils.d.ts.map +1 -1
  90. package/lib/utils/FileUtils.js +11 -3
  91. package/package.json +5 -2
@@ -36,422 +36,110 @@ var __importStar = (this && this.__importStar) || function (mod) {
36
36
  __setModuleDefault(result, mod);
37
37
  return result;
38
38
  };
39
- var __rest = (this && this.__rest) || function (s, e) {
40
- var t = {};
41
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
42
- t[p] = s[p];
43
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
44
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
46
- t[p[i]] = s[p[i]];
47
- }
48
- return t;
49
- };
50
39
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.findCompileCommands = exports.AstUtils = void 0;
52
- const child_process_1 = require("child_process");
40
+ exports.findCompileCommands = exports.extractAllCppModifiers = exports.ClangPath = exports.isAstJsonDumperAvailable = exports.getAstJsonDumperNodePath = exports.findProjectRoot = void 0;
53
41
  const fs = __importStar(require("fs"));
54
42
  const path = __importStar(require("path"));
55
- const os = __importStar(require("os"));
56
- const logger_1 = __importStar(require("../../../utils/logger"));
57
- const const_1 = require("./const");
58
- const ArkCxxAstNode_1 = require("./ArkCxxAstNode");
59
- const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'astUtils');
60
- // Module level cache: Sub project root directory (including. cxx directory) ->compile_commands.json absolute path
43
+ // Module level cache: Sub project root directory (including .cxx directory) -> compile_commands.json absolute path
61
44
  const ccJsonCache = new Map();
62
- class AstUtils {
63
- static deleteFileSync(filePath) {
64
- try {
65
- fs.unlinkSync(filePath);
66
- }
67
- catch (_a) {
68
- logger.warn('delete file failed:', filePath);
69
- }
70
- }
71
- static parse(sourceFile, ccJsonPath, includeDirs, llvmPath, cppAstPath) {
72
- var _a;
73
- logger.info(`[Debug] Parsing File: ${sourceFile}`);
74
- if (!fs.existsSync(sourceFile)) {
75
- logger.warn('parse file is not exists');
76
- return this.createEmptyNode();
77
- }
78
- const clangPath = this.getPlatformClang().toString();
79
- logger.info(`[Debug] Clang Path: ${clangPath}`);
80
- // 1. Prepare the path and directory
81
- const rawAstPath = this.getAstOutputPath(sourceFile, cppAstPath);
82
- const astPath = path.resolve(rawAstPath);
83
- this.ensureOutputDir(path.dirname(astPath));
84
- const workingDir = this.getWorkingDir(ccJsonPath);
85
- // 2. Prepare the Include path (automatically inject source code root directory)
86
- const finalIncludeDirs = includeDirs ? [...includeDirs] : [];
87
- const projectRoot = this.resolveProjectRoot(sourceFile);
88
- if (projectRoot && !finalIncludeDirs.includes(projectRoot)) {
89
- finalIncludeDirs.push(projectRoot);
90
- }
91
- // 3. Build parameters and environment
92
- let parseArguments = [sourceFile, '-o', astPath];
93
- parseArguments = [...parseArguments, ...constructParseArguments(sourceFile, ccJsonPath, finalIncludeDirs)];
94
- const sep = path.delimiter;
95
- const existingPath = (_a = process.env.PATH) !== null && _a !== void 0 ? _a : '';
96
- const shouldAppend = llvmPath && !existingPath.split(sep).includes(llvmPath);
97
- const envVars = shouldAppend ? Object.assign(Object.assign({}, process.env), { PATH: existingPath + sep + llvmPath }) : undefined;
98
- // 4. Execute Clang
99
- const status = this.runClang(clangPath, parseArguments, envVars, workingDir);
100
- // 5. Processing result
101
- return this.processAstFile(astPath, sourceFile, status);
102
- }
103
- /**
104
- * Auxiliary method: Try to find and return the root directory of src/main/cpp
105
- */
106
- static resolveProjectRoot(sourceFile) {
107
- try {
108
- let currentDir = path.dirname(sourceFile);
109
- for (let i = 0; i < 10; i++) {
110
- if (path.dirname(currentDir) === currentDir) {
111
- break;
112
- }
113
- if (path.basename(currentDir) === 'cpp' && path.basename(path.dirname(currentDir)) === 'main') {
114
- const absRoot = path.resolve(currentDir);
115
- logger.info(`[Debug] Found Source Root: ${absRoot}`);
116
- return absRoot;
117
- }
118
- currentDir = path.dirname(currentDir);
119
- }
120
- }
121
- catch (e) {
122
- logger.error('[Debug] Error finding source root:', e);
123
- }
124
- return null;
125
- }
126
- /**
127
- * Auxiliary method: Determine Work Catalog (CWD)
128
- */
129
- static getWorkingDir(ccJsonPath) {
130
- let workingDir = process.cwd();
131
- if (ccJsonPath && fs.existsSync(ccJsonPath)) {
132
- const stats = fs.statSync(ccJsonPath);
133
- if (stats.isFile()) {
134
- workingDir = path.dirname(ccJsonPath);
135
- }
136
- else {
137
- workingDir = ccJsonPath;
138
- }
139
- }
140
- return workingDir;
141
- }
142
- /**
143
- * Auxiliary method: Execute Clang process and print debugging logs
144
- */
145
- static runClang(clangPath, args, env, cwd) {
146
- var _a;
147
- const fullCmd = `"${clangPath}" ${args.map(a => a.includes(' ') ? `"${a}"` : a).join(' ')}`;
148
- logger.info('================================================================');
149
- logger.info(`[Debug] CWD: ${cwd}`);
150
- logger.info(`[Debug] CMD: ${fullCmd}`);
151
- logger.info('================================================================');
152
- const result = (0, child_process_1.spawnSync)(clangPath, args, {
153
- stdio: ['inherit', 'pipe'],
154
- encoding: 'utf-8',
155
- env: env,
156
- cwd: cwd
157
- });
158
- if (result.status !== 0) {
159
- logger.error(`[Debug] Clang exited with code ${result.status}`);
160
- logger.error(`[Debug] Stderr: ${result.stderr}`);
161
- return (_a = result.status) !== null && _a !== void 0 ? _a : -1;
162
- }
163
- else {
164
- logger.info('[Debug] Clang finished successfully.');
165
- return 0;
166
- }
167
- }
168
- /**
169
- * Auxiliary method: Read and parse the generated AST JSON file
170
- */
171
- static processAstFile(astPath, sourceFile, status) {
172
- try {
173
- if (!fs.existsSync(astPath)) {
174
- logger.error(`[Debug] AST file missing at: ${astPath}`);
175
- return this.createEmptyNode();
176
- }
177
- const content = fs.readFileSync(astPath, 'utf-8');
178
- if (!content || content.trim() === '') {
179
- return this.createEmptyNode();
180
- }
181
- let tu = JSON.parse(content);
182
- tu = this.filter(sourceFile, tu);
183
- return tu;
184
- }
185
- catch (e) {
186
- logger.error('Failed to parse AST json:', e);
187
- return this.createEmptyNode();
188
- }
189
- finally {
190
- // [Debug] If you need to debug file generation, you can comment out the following line
191
- this.deleteFileSync(astPath);
192
- }
193
- }
194
- static createEmptyNode() {
195
- return { kind: '', name: '', code: '', type: { qualType: '' }, inner: [] };
196
- }
197
- static updateInner(sourceFile, entry, newInner) {
198
- // isImplicit=true indicates that the node must exist under the rules of the C/C++ language but is not explicitly
199
- // written in the source code, so it needs to be filtered out.
200
- if (entry.isImplicit) {
201
- return;
202
- }
203
- let loc = entry.loc;
204
- if (!loc) {
205
- logger.warn('Node skipped due to missing "locFile", kind of node: ', entry.kind);
206
- return;
207
- }
208
- newInner.push(entry);
209
- }
210
- static filter(sourceFile, translationUnit) {
211
- let newInner = [];
212
- for (const entry of translationUnit.inner) {
213
- this.updateInner(sourceFile, entry, newInner);
214
- }
215
- translationUnit.inner = newInner;
216
- translationUnit.fileName = sourceFile;
217
- translationUnit.projectName = path.dirname(sourceFile);
218
- this.fullInfo(translationUnit);
219
- return translationUnit;
220
- }
221
- static filterChildren(cursor) {
222
- let filteredChildren = [];
223
- if (!cursor.inner) {
224
- return filteredChildren;
225
- }
226
- filteredChildren = cursor.inner.filter((item) => !item.isImplicit);
227
- return filteredChildren;
228
- }
229
- // Factory: generates a getParent implementation with overload signatures for a given cursor
230
- static makeGetParent(cursor) {
231
- function getParent(isNeedInner) {
232
- if (isNeedInner) {
233
- // Return the "full parent node": shallow copy, keeping the inner property
234
- // Note: This will also copy getParent itself (usually not an issue)
235
- return Object.assign({}, cursor);
236
- }
237
- // Return the "lightweight snapshot": shallow copy without inner, keeping other fields
238
- const { inner } = cursor, rest = __rest(cursor, ["inner"]);
239
- return rest; // Inferred as CxxAstNodeLite
240
- }
241
- return getParent;
242
- }
243
- static fullInfo(cursor) {
244
- if (!cursor.inner) {
245
- cursor.inner = [];
246
- }
247
- cursor.inner = this.filterChildren(cursor);
248
- if (cursor.name === undefined) {
249
- cursor.name = '';
250
- }
251
- // handle modifiers of lambda function
252
- if (cursor.kind === 'LambdaExpr') {
253
- this.processAccess(cursor);
254
- }
255
- // The default access property of class is 'private',The default access property of struct is 'public'
256
- if (cursor.kind === ArkCxxAstNode_1.astKind.CXXRecordDecl && cursor.tagUsed === 'class') {
257
- this.currentAccess = 'private';
258
- }
259
- else if (cursor.kind === ArkCxxAstNode_1.astKind.CXXRecordDecl && cursor.tagUsed === 'struct') {
260
- this.currentAccess = 'public';
261
- }
262
- else {
263
- this.currentAccess = '';
264
- }
265
- for (const currentCursor of cursor.inner) {
266
- // Overloaded implementation without any usage of 'any' or type assertions
267
- Object.assign(currentCursor, { getParent: this.makeGetParent(cursor) });
268
- if (cursor.kind === ArkCxxAstNode_1.astKind.CXXRecordDecl || cursor.kind === ArkCxxAstNode_1.astKind.CXXMethodDecl || cursor.kind === ArkCxxAstNode_1.astKind.FunctionDecl) {
269
- this.processAccess(currentCursor);
270
- }
271
- this.fullInfo(currentCursor);
272
- }
273
- }
274
- static extractAllCppModifiers(code) {
275
- if (!code) {
276
- return [];
277
- }
278
- const cppModifiers = [
279
- 'static',
280
- 'public',
281
- 'private',
282
- 'protected',
283
- 'const',
284
- 'virtual',
285
- 'inline',
286
- 'mutable',
287
- 'explicit',
288
- 'friend',
289
- 'constexpr',
290
- 'volatile'
291
- ];
292
- // Construct the regular expression; \b ensures whole-word matching
293
- const pattern = new RegExp(`\\b(${cppModifiers.join('|')})\\b`, 'g');
294
- const matches = code.match(pattern);
295
- return matches ? matches : [];
296
- }
297
- // Members in the syntax tree do not have control attributes, please process them here
298
- static processAccess(cursor) {
299
- var _a, _b;
300
- cursor.modifiers = [];
301
- // C++access control is a partition declaration that updates current information when encountering an access control symbol
302
- if (cursor.kind === 'AccessSpecDecl') {
303
- this.currentAccess = (_b = (_a = cursor.access) !== null && _a !== void 0 ? _a : this.extractAllCppModifiers(cursor.code)[0]) !== null && _b !== void 0 ? _b : '';
304
- }
305
- else {
306
- const extractedCode = this.getCodeForExtractModifiers(cursor);
307
- let codeModifier = this.extractAllCppModifiers(extractedCode);
308
- if (this.currentAccess !== '') {
309
- cursor.modifiers.push(this.currentAccess);
310
- }
311
- if (codeModifier !== null) {
312
- cursor.modifiers.push(...codeModifier);
313
- }
314
- }
315
- }
316
- static getCodeForExtractModifiers(cursor) {
317
- let extractedCode = cursor.code;
318
- if (!['CXXConstructorDecl', 'CXXDestructorDecl', 'CXXMethodDecl', 'FriendDecl', 'FunctionDecl', 'FunctionTemplateDecl'].includes(cursor.kind)) {
319
- return extractedCode;
320
- }
321
- const bodyNode = cursor.inner.filter(inn => inn.kind === 'CompoundStmt');
322
- const bodyCode = bodyNode.length === 0 ? '' : bodyNode[0].code;
323
- return this.stripFucntionParams(extractedCode.replace(bodyCode, ''));
324
- }
325
- static stripFucntionParams(code) {
326
- let depth = 0;
327
- let start = -1;
328
- let end = -1;
329
- for (let i = 0; i < code.length; i++) {
330
- const ch = code[i];
331
- if (ch === '(') {
332
- if (depth === 0) {
333
- start = i;
334
- }
335
- depth++;
336
- }
337
- else if (ch === ')') {
338
- depth--;
339
- if (depth === 0) {
340
- end = i;
341
- break;
342
- }
343
- }
344
- }
345
- if (start === -1 || end === -1) {
346
- return code;
347
- }
348
- return code.slice(0, start).trimEnd() + ' ' + code.slice(end + 1).trimStart();
349
- }
350
- static getAstOutputPath(sourceFile, cppAstPath) {
351
- const fileName = `${path.parse(path.basename(sourceFile)).name}_AST.json`;
352
- if (cppAstPath !== '') {
353
- return path.join(cppAstPath, fileName);
354
- }
355
- return path.join(const_1.ClangPath.protectRoot, 'src', 'frontend', 'cppFrontend', 'ast', 'out', fileName);
356
- }
357
- static ensureOutputDir(dir) {
358
- if (!fs.existsSync(dir)) {
359
- fs.mkdirSync(dir, { recursive: true });
45
+ function findProjectRoot(startDir = __dirname) {
46
+ let dir = path.resolve(startDir);
47
+ while (true) {
48
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
49
+ return dir;
360
50
  }
361
- }
362
- static getPlatformClang() {
363
- let platform = os.platform();
364
- switch (platform) {
365
- case 'win32':
366
- return const_1.ClangPath.WindowsPath;
367
- case 'linux':
368
- case 'darwin':
369
- return const_1.ClangPath.LinuxPath;
370
- default:
371
- return const_1.ClangPath.Unknown;
51
+ const parentDir = path.dirname(dir);
52
+ if (parentDir === dir) {
53
+ return dir;
372
54
  }
55
+ dir = parentDir;
373
56
  }
374
57
  }
375
- exports.AstUtils = AstUtils;
376
- AstUtils.currentAccess = '';
377
- function constructParseArguments(srcFilePath, ccJsonPath, includeDirs) {
378
- const args = [];
379
- if (ccJsonPath) {
380
- args.push('-p', ccJsonPath);
381
- }
382
- if (includeDirs && includeDirs.length > 0) {
383
- includeDirs.forEach(dir => {
384
- args.push('--extra-arg-before=-I' + `${dir}`);
385
- });
58
+ exports.findProjectRoot = findProjectRoot;
59
+ /**
60
+ * Resolved path to the astJsonDumper N-API addon ({@code astJsonDumper.node} under dumper/ or lib/ast/).
61
+ */
62
+ function getAstJsonDumperNodePath() {
63
+ const projectRoot = findProjectRoot(__dirname);
64
+ let nodeAddonPath = path.join(projectRoot, 'src', 'frontend', 'cppFrontend', 'ast', 'dumper', 'astJsonDumper.node');
65
+ if (!fs.existsSync(nodeAddonPath)) {
66
+ nodeAddonPath = path.join(projectRoot, 'lib', 'ast', 'astJsonDumper.node');
386
67
  }
387
- return args;
68
+ return nodeAddonPath;
388
69
  }
70
+ exports.getAstJsonDumperNodePath = getAstJsonDumperNodePath;
71
+ /** True when {@link getAstJsonDumperNodePath} exists on disk. */
72
+ function isAstJsonDumperAvailable() {
73
+ return fs.existsSync(getAstJsonDumperNodePath());
74
+ }
75
+ exports.isAstJsonDumperAvailable = isAstJsonDumperAvailable;
76
+ /** Project-root anchor for C++ AST output paths (legacy name: historically held Clang binary paths). */
77
+ class ClangPath {
78
+ }
79
+ exports.ClangPath = ClangPath;
80
+ ClangPath.protectRoot = findProjectRoot(__dirname);
81
+ function extractAllCppModifiers(code) {
82
+ if (!code) {
83
+ return [];
84
+ }
85
+ const cppModifiers = [
86
+ 'static',
87
+ 'public',
88
+ 'private',
89
+ 'protected',
90
+ 'const',
91
+ 'virtual',
92
+ 'inline',
93
+ 'mutable',
94
+ 'explicit',
95
+ 'friend',
96
+ 'constexpr',
97
+ 'volatile'
98
+ ];
99
+ const pattern = new RegExp(`\\b(${cppModifiers.join('|')})\\b`, 'g');
100
+ const matches = code.match(pattern);
101
+ return matches ? matches : [];
102
+ }
103
+ exports.extractAllCppModifiers = extractAllCppModifiers;
389
104
  /**
390
105
  * Find the absolute path of compile_commands.json starting from a file path.
391
- * Strict logic: Only traverses upward (ancestors) to find a ".cxx" directory.
392
- * Does NOT search sibling/uncle directories.
393
- * Caches the result based on the project root (the directory containing .cxx).
394
- * CxxTodo :Further confirmation can be made on whether there is a summary of the entire project's ccjson,
395
- * which only needs to be provided once in the scene build,(the directory containing ./.idea/.deveco/cxx/.cache)
396
- * * @param filePath Absolute path of the input file
397
- * @returns Absolute path of compile_commands.json if found, otherwise empty string
106
+ * Strict logic: only traverses upward (ancestors) to find a ".cxx" directory.
398
107
  */
399
108
  function findCompileCommands(filePath) {
400
- // 1. [Cache hit check]
401
- // Traverse the cache and check if the current file is located in a known sub project directory
402
- // Logic: If the filePath starts with projectRoot, it means it belongs to this sub project
403
109
  for (const [projectRoot, jsonPath] of ccJsonCache) {
404
- // Add path.sep to ensure directory level matching (prevent/app matching/apple)
405
110
  if (filePath === projectRoot || filePath.startsWith(projectRoot + path.sep)) {
406
111
  return jsonPath;
407
112
  }
408
113
  }
409
114
  let currentDir = path.dirname(filePath);
410
- // 2. [Upstream search logic]
411
115
  while (true) {
412
- // Core logic: Only check the. cxx directory under the current directory
413
- // Will not check other sibling directories under the current directory, achieving the requirement of 'not querying uncle directories'
414
116
  const cxxDir = path.join(currentDir, '.cxx');
415
117
  if (fs.existsSync(cxxDir) && fs.statSync(cxxDir).isDirectory()) {
416
- // Found. cxx, indicating that the current dir is the root directory of a sub project
417
- // Recursive search for JSON files within. cxx (this is necessary as JSON is often hidden deep within. cxx)
418
118
  const result = searchCompileCommandsInDir(cxxDir);
419
119
  if (result) {
420
- // [Establish cache]
421
- // Key: CurrentDir (the root directory of the sub project, which is the parent directory of. cxx)
422
- // Value: result (full path of json file)
423
120
  ccJsonCache.set(currentDir, result);
424
121
  return result;
425
122
  }
426
- else {
427
- // If there is a. cxx directory but json cannot be found, it usually means that it has not been compiled or the build structure is abnormal.
428
- // At this point, the upward search should be stopped to prevent incorrect matching to higher-level parent projects (if nested),
429
- // Alternatively, according to your needs, you can choose to continue searching upwards.
430
- // The default strategy here is to identify. cxx as the project boundary.
431
- return '';
432
- }
123
+ return '';
433
124
  }
434
125
  const parent = path.dirname(currentDir);
435
126
  if (parent === currentDir) {
436
- break; // Arriving at the system root directory, stop
127
+ break;
437
128
  }
438
- currentDir = parent; // Continue moving up one layer
129
+ currentDir = parent;
439
130
  }
440
131
  return '';
441
132
  }
442
133
  exports.findCompileCommands = findCompileCommands;
443
134
  /**
444
- * Recursively search for compile_commands.json inside a directory
445
- * This is only used INSIDE the .cxx directory.
446
- * @param dir Directory path to start searching
447
- * @returns Absolute path of compile_commands.json if found, otherwise empty string
135
+ * Recursively search for compile_commands.json inside .cxx directory.
448
136
  */
449
137
  function searchCompileCommandsInDir(dir) {
450
138
  let entries;
451
139
  try {
452
140
  entries = fs.readdirSync(dir, { withFileTypes: true });
453
141
  }
454
- catch (e) {
142
+ catch (_a) {
455
143
  return '';
456
144
  }
457
145
  for (const entry of entries) {
@@ -459,7 +147,7 @@ function searchCompileCommandsInDir(dir) {
459
147
  if (entry.isFile() && entry.name === 'compile_commands.json') {
460
148
  return dir;
461
149
  }
462
- else if (entry.isDirectory()) {
150
+ if (entry.isDirectory()) {
463
151
  const result = searchCompileCommandsInDir(fullPath);
464
152
  if (result) {
465
153
  return result;
@@ -14,17 +14,4 @@ export declare function getCxxHeaderFileExtensionSet(): ReadonlySet<string>;
14
14
  export declare function getCxxImplementationFileExtensions(): readonly string[];
15
15
  /** Returns a read-only set for fast C/C++ implementation-file checks. */
16
16
  export declare function getCxxImplementationFileExtensionSet(): ReadonlySet<string>;
17
- export declare function findProjectRoot(startDIr?: string): string;
18
- /**
19
- * Resolved path to the astJsonDumper executable for the current OS (Windows: .exe under dumper/ or lib/ast/).
20
- */
21
- export declare function getAstJsonDumperPath(): string;
22
- /** True when the astJsonDumper binary exists at {@link getAstJsonDumperPath}. */
23
- export declare function isAstJsonDumperAvailable(): boolean;
24
- export declare class ClangPath {
25
- static WindowsPath: string;
26
- static LinuxPath: string;
27
- static Unknown: string;
28
- static protectRoot: string;
29
- }
30
17
  //# sourceMappingURL=const.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/frontend/cppFrontend/ast/const.ts"],"names":[],"mappings":"AAgCA;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,SAAS,MAAM,EAAE,CAE9D;AAED,6EAA6E;AAC7E,wBAAgB,4BAA4B,IAAI,WAAW,CAAC,MAAM,CAAC,CAElE;AAED,sEAAsE;AACtE,wBAAgB,4BAA4B,IAAI,WAAW,CAAC,MAAM,CAAC,CAElE;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,SAAS,MAAM,EAAE,CAEtE;AAED,yEAAyE;AACzE,wBAAgB,oCAAoC,IAAI,WAAW,CAAC,MAAM,CAAC,CAE1E;AAED,wBAAgB,eAAe,CAAC,QAAQ,GAAE,MAAkB,GAAG,MAAM,CAYpE;AAuBD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,iFAAiF;AACjF,wBAAgB,wBAAwB,IAAI,OAAO,CAElD;AAED,qBAAa,SAAS;IAClB,MAAM,CAAC,WAAW,SAAmB;IACrC,MAAM,CAAC,SAAS,SAAwB;IACxC,MAAM,CAAC,OAAO,SAAM;IACpB,MAAM,CAAC,WAAW,SAAe;CACpC"}
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/frontend/cppFrontend/ast/const.ts"],"names":[],"mappings":"AA4BA;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,SAAS,MAAM,EAAE,CAE9D;AAED,6EAA6E;AAC7E,wBAAgB,4BAA4B,IAAI,WAAW,CAAC,MAAM,CAAC,CAElE;AAED,sEAAsE;AACtE,wBAAgB,4BAA4B,IAAI,WAAW,CAAC,MAAM,CAAC,CAElE;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,SAAS,MAAM,EAAE,CAEtE;AAED,yEAAyE;AACzE,wBAAgB,oCAAoC,IAAI,WAAW,CAAC,MAAM,CAAC,CAE1E"}
@@ -13,34 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
16
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.ClangPath = exports.isAstJsonDumperAvailable = exports.getAstJsonDumperPath = exports.findProjectRoot = exports.getCxxImplementationFileExtensionSet = exports.getCxxImplementationFileExtensions = exports.getCxxHeaderFileExtensionSet = exports.getCxxSourceFileExtensionSet = exports.getCxxSourceFileExtensions = void 0;
41
- const fs = __importStar(require("fs"));
42
- const os = __importStar(require("os"));
43
- const path = __importStar(require("path"));
17
+ exports.getCxxImplementationFileExtensionSet = exports.getCxxImplementationFileExtensions = exports.getCxxHeaderFileExtensionSet = exports.getCxxSourceFileExtensionSet = exports.getCxxSourceFileExtensions = void 0;
44
18
  /** C/C++ implementation file extensions (translation units). */
45
19
  const CXX_IMPLEMENTATION_EXTENSIONS = ['.c', '.cc', '.cpp', '.cxx'];
46
20
  /** C/C++ header extensions. */
@@ -82,53 +56,3 @@ function getCxxImplementationFileExtensionSet() {
82
56
  return CXX_IMPLEMENTATION_EXTENSION_SET;
83
57
  }
84
58
  exports.getCxxImplementationFileExtensionSet = getCxxImplementationFileExtensionSet;
85
- function findProjectRoot(startDIr = __dirname) {
86
- let dir = path.resolve(startDIr);
87
- while (true) {
88
- if (fs.existsSync(path.join(dir, 'package.json'))) {
89
- return dir;
90
- }
91
- const parentDIr = path.dirname(dir);
92
- if (parentDIr === dir) {
93
- return dir;
94
- }
95
- dir = parentDIr;
96
- }
97
- }
98
- exports.findProjectRoot = findProjectRoot;
99
- const projectRoot = findProjectRoot(__dirname);
100
- function getPrintAstExePath() {
101
- let printAstExePath = path.join(projectRoot, 'src', 'frontend', 'cppFrontend', 'ast', 'dumper', 'astJsonDumper.exe');
102
- if (!fs.existsSync(printAstExePath)) {
103
- printAstExePath = path.join(projectRoot, 'lib', 'ast', 'astJsonDumper.exe');
104
- }
105
- return printAstExePath;
106
- }
107
- function getPrintAstExePathLinux() {
108
- let printAstExePath = path.join(projectRoot, 'src', 'frontend', 'cppFrontend', 'ast', 'dumper', 'astJsonDumper');
109
- if (!fs.existsSync(printAstExePath)) {
110
- printAstExePath = path.join(projectRoot, 'lib', 'ast', 'astJsonDumper');
111
- }
112
- return printAstExePath;
113
- }
114
- const printAstExePath = getPrintAstExePath();
115
- const printAstExePathLinux = getPrintAstExePathLinux();
116
- /**
117
- * Resolved path to the astJsonDumper executable for the current OS (Windows: .exe under dumper/ or lib/ast/).
118
- */
119
- function getAstJsonDumperPath() {
120
- return os.platform() === 'win32' ? getPrintAstExePath() : getPrintAstExePathLinux();
121
- }
122
- exports.getAstJsonDumperPath = getAstJsonDumperPath;
123
- /** True when the astJsonDumper binary exists at {@link getAstJsonDumperPath}. */
124
- function isAstJsonDumperAvailable() {
125
- return fs.existsSync(getAstJsonDumperPath());
126
- }
127
- exports.isAstJsonDumperAvailable = isAstJsonDumperAvailable;
128
- class ClangPath {
129
- }
130
- exports.ClangPath = ClangPath;
131
- ClangPath.WindowsPath = printAstExePath;
132
- ClangPath.LinuxPath = printAstExePathLinux;
133
- ClangPath.Unknown = '';
134
- ClangPath.protectRoot = projectRoot;
@@ -0,0 +1,5 @@
1
+ export { getCxxImplementationFileExtensionSet, getCxxImplementationFileExtensions, getCxxHeaderFileExtensionSet, getCxxSourceFileExtensionSet, getCxxSourceFileExtensions, } from './const';
2
+ export { astKind, CxxAstNode, CxxIncludeInfo, CxxTranslationUnit, defaultArg, getNodeStartLineAndCol, } from './ArkCxxAstNode';
3
+ export { findCompileCommands, isAstJsonDumperAvailable } from './astUtils';
4
+ export { AstParser } from './astParser';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/frontend/cppFrontend/ast/index.ts"],"names":[],"mappings":"AAeA,OAAO,EACH,oCAAoC,EACpC,kCAAkC,EAClC,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,GAC7B,MAAM,SAAS,CAAC;AAEjB,OAAO,EACH,OAAO,EACP,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,sBAAsB,GACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AstParser = exports.isAstJsonDumperAvailable = exports.findCompileCommands = exports.getNodeStartLineAndCol = exports.astKind = exports.getCxxSourceFileExtensions = exports.getCxxSourceFileExtensionSet = exports.getCxxHeaderFileExtensionSet = exports.getCxxImplementationFileExtensions = exports.getCxxImplementationFileExtensionSet = void 0;
18
+ var const_1 = require("./const");
19
+ Object.defineProperty(exports, "getCxxImplementationFileExtensionSet", { enumerable: true, get: function () { return const_1.getCxxImplementationFileExtensionSet; } });
20
+ Object.defineProperty(exports, "getCxxImplementationFileExtensions", { enumerable: true, get: function () { return const_1.getCxxImplementationFileExtensions; } });
21
+ Object.defineProperty(exports, "getCxxHeaderFileExtensionSet", { enumerable: true, get: function () { return const_1.getCxxHeaderFileExtensionSet; } });
22
+ Object.defineProperty(exports, "getCxxSourceFileExtensionSet", { enumerable: true, get: function () { return const_1.getCxxSourceFileExtensionSet; } });
23
+ Object.defineProperty(exports, "getCxxSourceFileExtensions", { enumerable: true, get: function () { return const_1.getCxxSourceFileExtensions; } });
24
+ var ArkCxxAstNode_1 = require("./ArkCxxAstNode");
25
+ Object.defineProperty(exports, "astKind", { enumerable: true, get: function () { return ArkCxxAstNode_1.astKind; } });
26
+ Object.defineProperty(exports, "getNodeStartLineAndCol", { enumerable: true, get: function () { return ArkCxxAstNode_1.getNodeStartLineAndCol; } });
27
+ var astUtils_1 = require("./astUtils");
28
+ Object.defineProperty(exports, "findCompileCommands", { enumerable: true, get: function () { return astUtils_1.findCompileCommands; } });
29
+ Object.defineProperty(exports, "isAstJsonDumperAvailable", { enumerable: true, get: function () { return astUtils_1.isAstJsonDumperAvailable; } });
30
+ var astParser_1 = require("./astParser");
31
+ Object.defineProperty(exports, "AstParser", { enumerable: true, get: function () { return astParser_1.AstParser; } });
@@ -7,7 +7,7 @@ import { AliasType } from '../../../core/base/Type';
7
7
  import { ArkMethod } from '../../../core/model/ArkMethod';
8
8
  import { FullPosition } from '../../../core/base/Position';
9
9
  import { ArkIRTransformer } from '../../../core/common/ArkIRTransformer';
10
- import { CxxAstNode, CxxTranslationUnit } from '../ast/ArkCxxAstNode';
10
+ import { CxxAstNode, CxxTranslationUnit } from '../ast';
11
11
  export type ValueAndStmts = {
12
12
  value: Value;
13
13
  valueOriginalPositions: FullPosition[];