arkanalyzer 1.0.87 → 1.0.89

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 (143) hide show
  1. package/config/arkanalyzer.json +11 -0
  2. package/lib/Config.d.ts +27 -2
  3. package/lib/Config.d.ts.map +1 -1
  4. package/lib/Config.js +65 -2
  5. package/lib/Scene.d.ts +5 -2
  6. package/lib/Scene.d.ts.map +1 -1
  7. package/lib/Scene.js +34 -67
  8. package/lib/callgraph/pointerAnalysis/context/Context.d.ts.map +1 -1
  9. package/lib/callgraph/pointerAnalysis/context/Context.js +10 -12
  10. package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +1 -1
  11. package/lib/cli/commands/cg.d.ts +27 -6
  12. package/lib/cli/commands/cg.d.ts.map +1 -1
  13. package/lib/cli/commands/cg.js +9 -6
  14. package/lib/core/base/Expr.js +3 -3
  15. package/lib/core/base/Position.d.ts +1 -1
  16. package/lib/core/base/Position.d.ts.map +1 -1
  17. package/lib/core/base/Position.js +2 -2
  18. package/lib/core/base/Type.d.ts.map +1 -1
  19. package/lib/core/base/Type.js +1 -2
  20. package/lib/core/common/Const.d.ts +1 -0
  21. package/lib/core/common/Const.d.ts.map +1 -1
  22. package/lib/core/common/Const.js +2 -1
  23. package/lib/core/common/IRInference.d.ts.map +1 -1
  24. package/lib/core/common/IRInference.js +1 -1
  25. package/lib/core/common/IRUtils.d.ts.map +1 -1
  26. package/lib/core/common/IRUtils.js +3 -33
  27. package/lib/core/common/ModelUtils.d.ts +6 -0
  28. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  29. package/lib/core/common/ModelUtils.js +30 -0
  30. package/lib/core/common/SdkUtils.js +1 -1
  31. package/lib/core/common/TypeInference.d.ts +13 -0
  32. package/lib/core/common/TypeInference.d.ts.map +1 -1
  33. package/lib/core/common/TypeInference.js +44 -0
  34. package/lib/core/common/ValueUtil.d.ts +1 -1
  35. package/lib/core/common/ValueUtil.d.ts.map +1 -1
  36. package/lib/core/common/ValueUtil.js +28 -12
  37. package/lib/core/graph/Cfg.d.ts.map +1 -1
  38. package/lib/core/graph/Cfg.js +0 -2
  39. package/lib/core/graph/DominanceFinder.d.ts +3 -0
  40. package/lib/core/graph/DominanceFinder.d.ts.map +1 -1
  41. package/lib/core/graph/DominanceFinder.js +42 -36
  42. package/lib/core/graph/DominanceTree.d.ts.map +1 -1
  43. package/lib/core/graph/DominanceTree.js +0 -4
  44. package/lib/core/inference/ValueInference.d.ts.map +1 -1
  45. package/lib/core/inference/ValueInference.js +3 -2
  46. package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
  47. package/lib/core/inference/abc/AbcInference.js +2 -1
  48. package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
  49. package/lib/core/inference/arkts/ArkTsInference.js +3 -2
  50. package/lib/core/model/ArkClass.d.ts +3 -0
  51. package/lib/core/model/ArkClass.d.ts.map +1 -1
  52. package/lib/core/model/ArkClass.js +32 -6
  53. package/lib/core/model/ArkFile.d.ts.map +1 -1
  54. package/lib/core/model/ArkFile.js +0 -1
  55. package/lib/core/model/ArkMetadata.d.ts +32 -1
  56. package/lib/core/model/ArkMetadata.d.ts.map +1 -1
  57. package/lib/core/model/ArkMetadata.js +28 -3
  58. package/lib/core/model/builder/ArkMetadataBuilder.d.ts +21 -0
  59. package/lib/core/model/builder/ArkMetadataBuilder.d.ts.map +1 -0
  60. package/lib/core/model/builder/ArkMetadataBuilder.js +160 -0
  61. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  62. package/lib/core/model/builder/ArkMethodBuilder.js +32 -26
  63. package/lib/frontend/FrontendBuilder.d.ts +26 -0
  64. package/lib/frontend/FrontendBuilder.d.ts.map +1 -0
  65. package/lib/frontend/FrontendBuilder.js +108 -0
  66. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +16 -0
  67. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -0
  68. package/lib/frontend/arktsFrontend/ArktsFrontend.js +52 -0
  69. package/lib/frontend/cppFrontend/CppFrontend.d.ts +13 -0
  70. package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -0
  71. package/lib/frontend/cppFrontend/CppFrontend.js +85 -0
  72. package/lib/frontend/cppFrontend/ast/index.d.ts +5 -0
  73. package/lib/frontend/cppFrontend/ast/index.d.ts.map +1 -0
  74. package/lib/frontend/cppFrontend/ast/index.js +31 -0
  75. package/lib/frontend/cppFrontend/ast/ts/ArkCxxAstNode.d.ts.map +1 -0
  76. package/lib/frontend/cppFrontend/ast/ts/astParser.d.ts +25 -0
  77. package/lib/frontend/cppFrontend/ast/ts/astParser.d.ts.map +1 -0
  78. package/lib/frontend/cppFrontend/ast/ts/astParser.js +280 -0
  79. package/lib/frontend/cppFrontend/ast/ts/astUtils.d.ts +18 -0
  80. package/lib/frontend/cppFrontend/ast/ts/astUtils.d.ts.map +1 -0
  81. package/lib/frontend/cppFrontend/ast/ts/astUtils.js +158 -0
  82. package/lib/frontend/cppFrontend/ast/{const.d.ts → ts/const.d.ts} +0 -13
  83. package/lib/frontend/cppFrontend/ast/ts/const.d.ts.map +1 -0
  84. package/lib/frontend/cppFrontend/ast/ts/const.js +58 -0
  85. package/lib/frontend/cppFrontend/ast/ts/napi/napiApi.d.ts +8 -0
  86. package/lib/frontend/cppFrontend/ast/ts/napi/napiApi.d.ts.map +1 -0
  87. package/lib/frontend/cppFrontend/ast/ts/napi/napiApi.js +90 -0
  88. package/lib/frontend/cppFrontend/ast/ts/napi/napiRunner.d.ts +8 -0
  89. package/lib/frontend/cppFrontend/ast/ts/napi/napiRunner.d.ts.map +1 -0
  90. package/lib/frontend/cppFrontend/ast/ts/napi/napiRunner.js +180 -0
  91. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts +1 -1
  92. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
  93. package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +55 -55
  94. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
  95. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
  96. package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +151 -151
  97. package/lib/frontend/cppFrontend/common/IRInference.js +2 -2
  98. package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -1
  99. package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
  100. package/lib/frontend/cppFrontend/common/IRUtils.js +2 -2
  101. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts +1 -1
  102. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
  103. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +74 -74
  104. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts +1 -1
  105. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
  106. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +3 -3
  107. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts +1 -1
  108. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
  109. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +1 -1
  110. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
  111. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +16 -17
  112. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts +1 -1
  113. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts.map +1 -1
  114. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts +1 -1
  115. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  116. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +2 -2
  117. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +1 -1
  118. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  119. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +2 -2
  120. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -1
  121. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
  122. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts +1 -1
  123. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
  124. package/lib/frontend/cppFrontend/model/builder/builderUtils.js +3 -3
  125. package/lib/index.d.ts +5 -2
  126. package/lib/index.d.ts.map +1 -1
  127. package/lib/index.js +14 -6
  128. package/lib/pass/Dispatcher.d.ts.map +1 -1
  129. package/lib/pass/Dispatcher.js +0 -4
  130. package/lib/save/source/SourceStmt.d.ts.map +1 -1
  131. package/lib/save/source/SourceStmt.js +3 -1
  132. package/lib/utils/FileUtils.d.ts +1 -0
  133. package/lib/utils/FileUtils.d.ts.map +1 -1
  134. package/lib/utils/FileUtils.js +11 -3
  135. package/package.json +9 -4
  136. package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.d.ts.map +0 -1
  137. package/lib/frontend/cppFrontend/ast/astUtils.d.ts +0 -51
  138. package/lib/frontend/cppFrontend/ast/astUtils.d.ts.map +0 -1
  139. package/lib/frontend/cppFrontend/ast/astUtils.js +0 -470
  140. package/lib/frontend/cppFrontend/ast/const.d.ts.map +0 -1
  141. package/lib/frontend/cppFrontend/ast/const.js +0 -134
  142. /package/lib/frontend/cppFrontend/ast/{ArkCxxAstNode.d.ts → ts/ArkCxxAstNode.d.ts} +0 -0
  143. /package/lib/frontend/cppFrontend/ast/{ArkCxxAstNode.js → ts/ArkCxxAstNode.js} +0 -0
@@ -1,470 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2025 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
- 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
- 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
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.findCompileCommands = exports.AstUtils = void 0;
52
- const child_process_1 = require("child_process");
53
- const fs = __importStar(require("fs"));
54
- 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
61
- 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 });
360
- }
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;
372
- }
373
- }
374
- }
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
- });
386
- }
387
- return args;
388
- }
389
- /**
390
- * 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
398
- */
399
- 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
- for (const [projectRoot, jsonPath] of ccJsonCache) {
404
- // Add path.sep to ensure directory level matching (prevent/app matching/apple)
405
- if (filePath === projectRoot || filePath.startsWith(projectRoot + path.sep)) {
406
- return jsonPath;
407
- }
408
- }
409
- let currentDir = path.dirname(filePath);
410
- // 2. [Upstream search logic]
411
- 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
- const cxxDir = path.join(currentDir, '.cxx');
415
- 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
- const result = searchCompileCommandsInDir(cxxDir);
419
- 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
- ccJsonCache.set(currentDir, result);
424
- return result;
425
- }
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
- }
433
- }
434
- const parent = path.dirname(currentDir);
435
- if (parent === currentDir) {
436
- break; // Arriving at the system root directory, stop
437
- }
438
- currentDir = parent; // Continue moving up one layer
439
- }
440
- return '';
441
- }
442
- exports.findCompileCommands = findCompileCommands;
443
- /**
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
448
- */
449
- function searchCompileCommandsInDir(dir) {
450
- let entries;
451
- try {
452
- entries = fs.readdirSync(dir, { withFileTypes: true });
453
- }
454
- catch (e) {
455
- return '';
456
- }
457
- for (const entry of entries) {
458
- const fullPath = path.join(dir, entry.name);
459
- if (entry.isFile() && entry.name === 'compile_commands.json') {
460
- return dir;
461
- }
462
- else if (entry.isDirectory()) {
463
- const result = searchCompileCommandsInDir(fullPath);
464
- if (result) {
465
- return result;
466
- }
467
- }
468
- }
469
- return '';
470
- }
@@ -1 +0,0 @@
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,134 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2025 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
- 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
- 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"));
44
- /** C/C++ implementation file extensions (translation units). */
45
- const CXX_IMPLEMENTATION_EXTENSIONS = ['.c', '.cc', '.cpp', '.cxx'];
46
- /** C/C++ header extensions. */
47
- const CXX_HEADER_EXTENSIONS = ['.h', '.hh', '.hpp'];
48
- const CXX_IMPLEMENTATION_EXTENSION_SET = new Set(CXX_IMPLEMENTATION_EXTENSIONS);
49
- const CXX_HEADER_EXTENSION_SET = new Set(CXX_HEADER_EXTENSIONS);
50
- const CXX_SOURCE_EXTENSION_SET = new Set([
51
- ...CXX_IMPLEMENTATION_EXTENSIONS,
52
- ...CXX_HEADER_EXTENSIONS,
53
- ]);
54
- /**
55
- * Returns extensions for C/C++ implementation and header files used across the C++ frontend
56
- * (scanning, SceneConfig defaults, language detection).
57
- */
58
- function getCxxSourceFileExtensions() {
59
- return [...CXX_IMPLEMENTATION_EXTENSIONS, ...CXX_HEADER_EXTENSIONS];
60
- }
61
- exports.getCxxSourceFileExtensions = getCxxSourceFileExtensions;
62
- /** Returns a read-only set for fast C/C++ source/header extension checks. */
63
- function getCxxSourceFileExtensionSet() {
64
- return CXX_SOURCE_EXTENSION_SET;
65
- }
66
- exports.getCxxSourceFileExtensionSet = getCxxSourceFileExtensionSet;
67
- /** Returns a read-only set for fast C/C++ header extension checks. */
68
- function getCxxHeaderFileExtensionSet() {
69
- return CXX_HEADER_EXTENSION_SET;
70
- }
71
- exports.getCxxHeaderFileExtensionSet = getCxxHeaderFileExtensionSet;
72
- /**
73
- * Returns extensions for C/C++ translation units only (no headers), e.g. for IR passes that
74
- * walk implementation files.
75
- */
76
- function getCxxImplementationFileExtensions() {
77
- return [...CXX_IMPLEMENTATION_EXTENSIONS];
78
- }
79
- exports.getCxxImplementationFileExtensions = getCxxImplementationFileExtensions;
80
- /** Returns a read-only set for fast C/C++ implementation-file checks. */
81
- function getCxxImplementationFileExtensionSet() {
82
- return CXX_IMPLEMENTATION_EXTENSION_SET;
83
- }
84
- 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;