arkanalyzer 1.0.6 → 1.0.8

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 (224) hide show
  1. package/config/arkanalyzer.json +8 -0
  2. package/docs/IR2ts-stmt.md +81 -0
  3. package/docs/IR2ts.md +82 -0
  4. package/lib/Config.d.ts +29 -1
  5. package/lib/Config.d.ts.map +1 -1
  6. package/lib/Config.js +44 -11
  7. package/lib/Scene.d.ts +152 -9
  8. package/lib/Scene.d.ts.map +1 -1
  9. package/lib/Scene.js +233 -66
  10. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +2 -1
  11. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
  12. package/lib/callgraph/algorithm/AbstractAnalysis.js +14 -7
  13. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -1
  14. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +2 -4
  15. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
  16. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
  17. package/lib/callgraph/common/Statistics.js +1 -1
  18. package/lib/callgraph/model/BaseGraph.js +2 -2
  19. package/lib/callgraph/model/CallGraph.d.ts +3 -2
  20. package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
  21. package/lib/callgraph/model/CallGraph.js +23 -14
  22. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +2 -2
  23. package/lib/callgraph/model/builder/CallGraphBuilder.js +3 -3
  24. package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -1
  25. package/lib/callgraph/pointerAnalysis/Context.js +0 -1
  26. package/lib/callgraph/pointerAnalysis/Pag.d.ts +36 -9
  27. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
  28. package/lib/callgraph/pointerAnalysis/Pag.js +130 -37
  29. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +34 -5
  30. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
  31. package/lib/callgraph/pointerAnalysis/PagBuilder.js +479 -126
  32. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +6 -0
  33. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
  34. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +107 -45
  35. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -1
  36. package/lib/callgraph/pointerAnalysis/PtsDS.js +0 -2
  37. package/lib/core/base/Constant.d.ts +37 -5
  38. package/lib/core/base/Constant.d.ts.map +1 -1
  39. package/lib/core/base/Constant.js +58 -8
  40. package/lib/core/base/Expr.d.ts +98 -13
  41. package/lib/core/base/Expr.d.ts.map +1 -1
  42. package/lib/core/base/Expr.js +295 -127
  43. package/lib/core/base/Local.d.ts +70 -5
  44. package/lib/core/base/Local.d.ts.map +1 -1
  45. package/lib/core/base/Local.js +77 -4
  46. package/lib/core/base/Ref.d.ts +79 -5
  47. package/lib/core/base/Ref.d.ts.map +1 -1
  48. package/lib/core/base/Ref.js +143 -38
  49. package/lib/core/base/Stmt.d.ts +126 -12
  50. package/lib/core/base/Stmt.d.ts.map +1 -1
  51. package/lib/core/base/Stmt.js +135 -28
  52. package/lib/core/base/Type.d.ts +11 -2
  53. package/lib/core/base/Type.d.ts.map +1 -1
  54. package/lib/core/base/Type.js +47 -42
  55. package/lib/core/base/Value.d.ts +24 -2
  56. package/lib/core/base/Value.d.ts.map +1 -1
  57. package/lib/core/common/ArkError.d.ts +15 -0
  58. package/lib/core/common/ArkError.d.ts.map +1 -0
  59. package/lib/core/common/ArkError.js +28 -0
  60. package/lib/core/common/ArkIRTransformer.d.ts +12 -5
  61. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  62. package/lib/core/common/ArkIRTransformer.js +90 -45
  63. package/lib/core/common/BodyBuilder.d.ts +2 -0
  64. package/lib/core/common/BodyBuilder.d.ts.map +1 -1
  65. package/lib/core/common/BodyBuilder.js +5 -2
  66. package/lib/core/common/Builtin.js +1 -1
  67. package/lib/core/common/CfgBuilder.d.ts +12 -7
  68. package/lib/core/common/CfgBuilder.d.ts.map +1 -1
  69. package/lib/core/common/CfgBuilder.js +336 -140
  70. package/lib/core/common/Const.d.ts +15 -10
  71. package/lib/core/common/Const.d.ts.map +1 -1
  72. package/lib/core/common/Const.js +18 -11
  73. package/lib/core/common/DummyMainCreater.d.ts +5 -4
  74. package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
  75. package/lib/core/common/DummyMainCreater.js +43 -28
  76. package/lib/core/common/EtsConst.d.ts +1 -0
  77. package/lib/core/common/EtsConst.d.ts.map +1 -1
  78. package/lib/core/common/EtsConst.js +2 -1
  79. package/lib/core/common/ExprUseReplacer.js +8 -8
  80. package/lib/core/common/IRUtils.d.ts +7 -0
  81. package/lib/core/common/IRUtils.d.ts.map +1 -1
  82. package/lib/core/common/IRUtils.js +34 -2
  83. package/lib/core/common/ModelUtils.d.ts +1 -0
  84. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  85. package/lib/core/common/ModelUtils.js +39 -36
  86. package/lib/core/common/RefUseReplacer.js +3 -3
  87. package/lib/core/common/StmtUseReplacer.js +4 -4
  88. package/lib/core/common/TSConst.d.ts +10 -3
  89. package/lib/core/common/TSConst.d.ts.map +1 -1
  90. package/lib/core/common/TSConst.js +11 -4
  91. package/lib/core/common/TypeInference.d.ts +8 -2
  92. package/lib/core/common/TypeInference.d.ts.map +1 -1
  93. package/lib/core/common/TypeInference.js +222 -90
  94. package/lib/core/common/ValueUtil.d.ts +0 -4
  95. package/lib/core/common/ValueUtil.d.ts.map +1 -1
  96. package/lib/core/common/ValueUtil.js +10 -27
  97. package/lib/core/common/VisibleValue.js +1 -1
  98. package/lib/core/dataflow/DataflowProblem.d.ts +1 -0
  99. package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -1
  100. package/lib/core/dataflow/DataflowProblem.js +4 -4
  101. package/lib/core/dataflow/DataflowSolver.d.ts +20 -16
  102. package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
  103. package/lib/core/dataflow/DataflowSolver.js +67 -78
  104. package/lib/core/dataflow/TiantAnalysis.d.ts +1 -0
  105. package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -1
  106. package/lib/core/dataflow/TiantAnalysis.js +42 -28
  107. package/lib/core/dataflow/UndefinedVariable.d.ts +15 -1
  108. package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -1
  109. package/lib/core/dataflow/UndefinedVariable.js +122 -76
  110. package/lib/core/dataflow/Util.d.ts +5 -1
  111. package/lib/core/dataflow/Util.d.ts.map +1 -1
  112. package/lib/core/dataflow/Util.js +43 -22
  113. package/lib/core/graph/BasicBlock.d.ts +72 -0
  114. package/lib/core/graph/BasicBlock.d.ts.map +1 -1
  115. package/lib/core/graph/BasicBlock.js +165 -3
  116. package/lib/core/graph/Cfg.d.ts +30 -1
  117. package/lib/core/graph/Cfg.d.ts.map +1 -1
  118. package/lib/core/graph/Cfg.js +131 -11
  119. package/lib/core/graph/DominanceFinder.js +7 -7
  120. package/lib/core/graph/DominanceTree.js +4 -4
  121. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
  122. package/lib/core/graph/builder/ViewTreeBuilder.js +6 -5
  123. package/lib/core/model/ArkBaseModel.d.ts +59 -0
  124. package/lib/core/model/ArkBaseModel.d.ts.map +1 -0
  125. package/lib/core/model/ArkBaseModel.js +271 -0
  126. package/lib/core/model/ArkBody.d.ts +3 -9
  127. package/lib/core/model/ArkBody.d.ts.map +1 -1
  128. package/lib/core/model/ArkBody.js +3 -14
  129. package/lib/core/model/ArkClass.d.ts +107 -13
  130. package/lib/core/model/ArkClass.d.ts.map +1 -1
  131. package/lib/core/model/ArkClass.js +152 -54
  132. package/lib/core/model/ArkExport.d.ts +8 -7
  133. package/lib/core/model/ArkExport.d.ts.map +1 -1
  134. package/lib/core/model/ArkExport.js +16 -18
  135. package/lib/core/model/ArkField.d.ts +16 -13
  136. package/lib/core/model/ArkField.d.ts.map +1 -1
  137. package/lib/core/model/ArkField.js +18 -62
  138. package/lib/core/model/ArkFile.d.ts +42 -0
  139. package/lib/core/model/ArkFile.d.ts.map +1 -1
  140. package/lib/core/model/ArkFile.js +58 -0
  141. package/lib/core/model/ArkImport.d.ts +9 -7
  142. package/lib/core/model/ArkImport.d.ts.map +1 -1
  143. package/lib/core/model/ArkImport.js +11 -12
  144. package/lib/core/model/ArkMetadata.d.ts +20 -0
  145. package/lib/core/model/ArkMetadata.d.ts.map +1 -0
  146. package/lib/core/model/ArkMetadata.js +44 -0
  147. package/lib/core/model/ArkMethod.d.ts +195 -17
  148. package/lib/core/model/ArkMethod.d.ts.map +1 -1
  149. package/lib/core/model/ArkMethod.js +363 -46
  150. package/lib/core/model/ArkNamespace.d.ts +6 -8
  151. package/lib/core/model/ArkNamespace.d.ts.map +1 -1
  152. package/lib/core/model/ArkNamespace.js +16 -20
  153. package/lib/core/model/ArkSignature.d.ts +41 -0
  154. package/lib/core/model/ArkSignature.d.ts.map +1 -1
  155. package/lib/core/model/ArkSignature.js +76 -19
  156. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  157. package/lib/core/model/builder/ArkClassBuilder.js +60 -49
  158. package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
  159. package/lib/core/model/builder/ArkExportBuilder.js +12 -6
  160. package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
  161. package/lib/core/model/builder/ArkFieldBuilder.js +13 -9
  162. package/lib/core/model/builder/ArkFileBuilder.js +1 -3
  163. package/lib/core/model/builder/ArkImportBuilder.d.ts +2 -1
  164. package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -1
  165. package/lib/core/model/builder/ArkImportBuilder.js +16 -13
  166. package/lib/core/model/builder/ArkMethodBuilder.d.ts +3 -1
  167. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  168. package/lib/core/model/builder/ArkMethodBuilder.js +105 -45
  169. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  170. package/lib/core/model/builder/ArkNamespaceBuilder.js +4 -5
  171. package/lib/core/model/builder/builderUtils.d.ts +2 -1
  172. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  173. package/lib/core/model/builder/builderUtils.js +63 -43
  174. package/lib/index.d.ts +2 -1
  175. package/lib/index.d.ts.map +1 -1
  176. package/lib/index.js +4 -3
  177. package/lib/save/ArkStream.js +1 -1
  178. package/lib/save/DotPrinter.d.ts.map +1 -1
  179. package/lib/save/DotPrinter.js +1 -15
  180. package/lib/save/GraphPrinter.d.ts.map +1 -1
  181. package/lib/save/GraphPrinter.js +4 -2
  182. package/lib/save/JsonPrinter.js +5 -5
  183. package/lib/save/ViewTreePrinter.d.ts +16 -0
  184. package/lib/save/ViewTreePrinter.d.ts.map +1 -0
  185. package/lib/save/ViewTreePrinter.js +130 -0
  186. package/lib/save/source/SourceBase.d.ts +2 -2
  187. package/lib/save/source/SourceBase.d.ts.map +1 -1
  188. package/lib/save/source/SourceBase.js +6 -13
  189. package/lib/save/source/SourceBody.d.ts.map +1 -1
  190. package/lib/save/source/SourceBody.js +27 -14
  191. package/lib/save/source/SourceClass.d.ts.map +1 -1
  192. package/lib/save/source/SourceClass.js +12 -8
  193. package/lib/save/source/SourceField.d.ts.map +1 -1
  194. package/lib/save/source/SourceField.js +6 -2
  195. package/lib/save/source/SourceMethod.d.ts.map +1 -1
  196. package/lib/save/source/SourceMethod.js +10 -3
  197. package/lib/save/source/SourceModule.d.ts.map +1 -1
  198. package/lib/save/source/SourceModule.js +16 -10
  199. package/lib/save/source/SourceNamespace.d.ts.map +1 -1
  200. package/lib/save/source/SourceNamespace.js +4 -0
  201. package/lib/save/source/SourceStmt.d.ts +1 -1
  202. package/lib/save/source/SourceStmt.d.ts.map +1 -1
  203. package/lib/save/source/SourceStmt.js +37 -25
  204. package/lib/save/source/SourceTransformer.d.ts +6 -0
  205. package/lib/save/source/SourceTransformer.d.ts.map +1 -1
  206. package/lib/save/source/SourceTransformer.js +82 -51
  207. package/lib/save/source/SourceUtils.d.ts.map +1 -1
  208. package/lib/save/source/SourceUtils.js +12 -11
  209. package/lib/transformer/StaticSingleAssignmentFormer.js +3 -3
  210. package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
  211. package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
  212. package/lib/utils/CfgStructualAnalysis.js +103 -72
  213. package/lib/utils/callGraphUtils.d.ts.map +1 -1
  214. package/lib/utils/callGraphUtils.js +7 -10
  215. package/lib/utils/crypto_utils.d.ts +6 -0
  216. package/lib/utils/crypto_utils.d.ts.map +1 -0
  217. package/lib/utils/crypto_utils.js +57 -0
  218. package/lib/utils/entryMethodUtils.d.ts.map +1 -1
  219. package/lib/utils/entryMethodUtils.js +27 -26
  220. package/lib/utils/getAllFiles.d.ts +1 -1
  221. package/lib/utils/getAllFiles.d.ts.map +1 -1
  222. package/lib/utils/getAllFiles.js +4 -5
  223. package/lib/utils/logger.js +2 -2
  224. package/package.json +3 -2
package/lib/Scene.js CHANGED
@@ -77,7 +77,6 @@ class Scene {
77
77
  this.realProjectDir = '';
78
78
  this.moduleScenesMap = new Map();
79
79
  this.modulePath2NameMap = new Map();
80
- this.globalImportInfos = [];
81
80
  this.moduleSdkMap = new Map();
82
81
  this.projectSdkMap = new Map();
83
82
  // values that are visible in curr scope
@@ -95,16 +94,58 @@ class Scene {
95
94
  this.ohPkgContent = {};
96
95
  this.buildStage = SceneBuildStage.BUILD_INIT;
97
96
  }
97
+ getOptions() {
98
+ return this.options;
99
+ }
100
+ clear() {
101
+ this.projectFiles = [];
102
+ this.moduleScenesMap.clear();
103
+ this.modulePath2NameMap.clear();
104
+ this.moduleSdkMap.clear();
105
+ this.projectSdkMap.clear();
106
+ this.filesMap.clear();
107
+ this.namespacesMap.clear();
108
+ this.classesMap.clear();
109
+ this.methodsMap.clear();
110
+ this.sdkArkFilesMap.clear();
111
+ this.sdkGlobalMap.clear();
112
+ this.ohPkgContentMap.clear();
113
+ this.ohPkgContent = {};
114
+ }
98
115
  getStage() {
99
116
  return this.buildStage;
100
117
  }
118
+ /**
119
+ * Build scene object according to the {@link SceneConfig}. This API implements 3 functions.
120
+ * First is to build scene object from {@link SceneConfig}, second is to generate {@link ArkFile}s,
121
+ * and the last is to collect project import infomation.
122
+ * @param sceneConfig - a sceneConfig object, which is usally defined by user or Json file.
123
+ * @example
124
+ * 1. Build Scene object from scene config
125
+
126
+ ```typescript
127
+ // build config
128
+ const projectDir = ... ...;
129
+ const sceneConfig = new SceneConfig();
130
+ sceneConfig.buildFromProjectDir(projectDir);
131
+
132
+ // build scene
133
+ const scene = new Scene();
134
+ scene.buildSceneFromProjectDir(sceneConfig);
135
+ ```
136
+ */
101
137
  buildSceneFromProjectDir(sceneConfig) {
102
138
  this.buildBasicInfo(sceneConfig);
103
139
  this.genArkFiles();
104
- this.collectProjectImportInfos();
105
140
  }
141
+ /**
142
+ * Set the basic information of the scene using a config,
143
+ * such as the project's name, real path and files.
144
+ * @param sceneConfig - the config used to set the basic information of scene.
145
+ */
106
146
  buildBasicInfo(sceneConfig) {
107
147
  var _a;
148
+ this.options = sceneConfig.getOptions();
108
149
  this.projectName = sceneConfig.getTargetProjectName();
109
150
  this.realProjectDir = fs_1.default.realpathSync(sceneConfig.getTargetProjectDirectory());
110
151
  this.projectFiles = sceneConfig.getProjectFiles();
@@ -154,6 +195,9 @@ class Scene {
154
195
  }
155
196
  }
156
197
  });
198
+ this.sdkArkFilesMap.forEach(file => {
199
+ this.inferFile(file);
200
+ });
157
201
  }
158
202
  addDefaultConstructors() {
159
203
  for (const file of this.getFiles()) {
@@ -187,23 +231,28 @@ class Scene {
187
231
  let arkFile = new ArkFile_1.ArkFile();
188
232
  arkFile.setScene(this);
189
233
  (0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.realProjectDir, arkFile, this.projectName);
190
- this.filesMap.set(arkFile.getFileSignature().toString(), arkFile);
234
+ this.filesMap.set(arkFile.getFileSignature().toMapKey(), arkFile);
191
235
  });
192
236
  this.buildAllMethodBody();
193
237
  this.addDefaultConstructors();
194
238
  }
195
239
  buildSdk(sdkName, sdkPath) {
196
- const allFiles = (0, getAllFiles_1.getAllFiles)(sdkPath, ['.ets', '.ts']);
240
+ const allFiles = (0, getAllFiles_1.getAllFiles)(sdkPath, ['.ets', '.ts'], this.options.ignoreFileNames);
197
241
  allFiles.forEach((file) => {
198
242
  logger.info('=== parse sdk file:', file);
199
243
  let arkFile = new ArkFile_1.ArkFile();
200
244
  arkFile.setScene(this);
201
245
  (0, ArkFileBuilder_1.buildArkFileFromFile)(file, path_1.default.normalize(sdkPath), arkFile, sdkName);
202
246
  ModelUtils_1.ModelUtils.getAllClassesInFile(arkFile).forEach(cls => { var _a; return (_a = cls.getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.buildBody(); });
203
- const fileSig = arkFile.getFileSignature().toString();
247
+ const fileSig = arkFile.getFileSignature().toMapKey();
204
248
  this.sdkArkFilesMap.set(fileSig, arkFile);
249
+ ModelUtils_1.ModelUtils.buildGlobalMap(arkFile, this.sdkGlobalMap);
205
250
  });
206
251
  }
252
+ /**
253
+ * Build the scene for harmony project. It resolves the file path of the project first, and then fetches dependencies from this file.
254
+ * Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally, it build bodies of all methods, generate extended classes, and add DefaultConstructors.
255
+ */
207
256
  buildScene4HarmonyProject() {
208
257
  this.modulePath2NameMap.forEach((value, key) => {
209
258
  const moduleOhPkgFilePath = path_1.default.resolve(key, './oh-package.json5');
@@ -213,8 +262,8 @@ class Scene {
213
262
  }
214
263
  });
215
264
  this.modulePath2NameMap.forEach((value, key) => {
216
- let moduleScene = new ModuleScene();
217
- moduleScene.ModuleScenBuilder(value, key, this);
265
+ let moduleScene = new ModuleScene(this);
266
+ moduleScene.ModuleSceneBuilder(value, key);
218
267
  this.moduleScenesMap.set(value, moduleScene);
219
268
  });
220
269
  this.buildAllMethodBody();
@@ -258,14 +307,27 @@ class Scene {
258
307
  });
259
308
  }
260
309
  }
261
- let moduleScene = new ModuleScene();
262
- moduleScene.ModuleScenBuilder(moduleName, modulePath, this);
310
+ let moduleScene = new ModuleScene(this);
311
+ moduleScene.ModuleSceneBuilder(moduleName, modulePath);
263
312
  this.moduleScenesMap.set(moduleName, moduleScene);
264
313
  this.buildAllMethodBody();
265
314
  }
315
+ /**
316
+ * Get the absolute path of current project.
317
+ * @returns The real project's directiory.
318
+ * @example
319
+ * 1. get real project directory, such as:
320
+ ```typescript
321
+ let projectDir = projectScene.getRealProjectDir();
322
+ ```
323
+ */
266
324
  getRealProjectDir() {
267
325
  return this.realProjectDir;
268
326
  }
327
+ /**
328
+ * Returns the **string** name of the project.
329
+ * @returns The name of the project.
330
+ */
269
331
  getProjectName() {
270
332
  return this.projectName;
271
333
  }
@@ -275,19 +337,71 @@ class Scene {
275
337
  getSdkGlobal(globalName) {
276
338
  return this.sdkGlobalMap.get(globalName) || null;
277
339
  }
340
+ /**
341
+ * Returns the file based on its signature.
342
+ * If no file can be found according to the input signature, **null** will be returned.
343
+ * A typical {@link ArkFile} contains: file's name (i.e., its relative path), project's name,
344
+ * project's dir, file's signature etc.
345
+ * @param fileSignature - the signature of file.
346
+ * @returns a file defined by ArkAnalyzer. **null** will be returned if no file could be found.
347
+ * @example
348
+ * 1. get ArkFile based on file signature.
349
+
350
+ ```typescript
351
+ if (...) {
352
+ const fromSignature = new FileSignature();
353
+ fromSignature.setProjectName(im.getDeclaringArkFile().getProjectName());
354
+ fromSignature.setFileName(fileName);
355
+ return scene.getFile(fromSignature);
356
+ }
357
+ ```
358
+ */
278
359
  getFile(fileSignature) {
279
360
  if (this.projectName === fileSignature.getProjectName()) {
280
- return this.filesMap.get(fileSignature.toString()) || null;
361
+ return this.filesMap.get(fileSignature.toMapKey()) || null;
281
362
  }
282
363
  else {
283
- return this.sdkArkFilesMap.get(fileSignature.toString()) || null;
364
+ return this.sdkArkFilesMap.get(fileSignature.toMapKey()) || null;
284
365
  }
285
366
  }
367
+ setFile(file) {
368
+ this.filesMap.set(file.getFileSignature().toMapKey(), file);
369
+ }
370
+ hasSdkFile(fileSignature) {
371
+ return this.sdkArkFilesMap.has(fileSignature.toMapKey());
372
+ }
373
+ /**
374
+ * Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different class. We need to generate {@link ArkFile} objects from these ets/ts files.
375
+ * @returns The array of {@link ArkFile} from `scene.filesMap.values()`.
376
+ * @example
377
+ * 1. In inferSimpleTypes() to check arkClass and arkMethod.
378
+ * ```typescript
379
+ * public inferSimpleTypes() {
380
+ * for (let arkFile of this.getFiles()) {
381
+ * for (let arkClass of arkFile.getClasses()) {
382
+ * for (let arkMethod of arkClass.getMethods()) {
383
+ * // ... ...;
384
+ * }
385
+ * }
386
+ * }
387
+ * }
388
+ * ```
389
+ * 2. To iterate each method
390
+ * ```typescript
391
+ * for (const file of this.getFiles()) {
392
+ * for (const cls of file.getClasses()) {
393
+ * for (const method of cls.getMethods()) {
394
+ * // ... ...
395
+ * }
396
+ * }
397
+ * }
398
+ *```
399
+ */
286
400
  getFiles() {
287
401
  return Array.from(this.filesMap.values());
288
402
  }
289
- getSdkArkFilesMap() {
290
- return this.sdkArkFilesMap;
403
+ getSdkArkFiles() {
404
+ return Array.from(this.sdkArkFilesMap.values());
291
405
  }
292
406
  getModuleSdkMap() {
293
407
  return this.moduleSdkMap;
@@ -295,23 +409,25 @@ class Scene {
295
409
  getProjectSdkMap() {
296
410
  return this.projectSdkMap;
297
411
  }
298
- getFilesMap() {
299
- return this.filesMap;
300
- }
301
412
  getNamespace(namespaceSignature) {
413
+ var _a;
302
414
  if (this.projectName === namespaceSignature.getDeclaringFileSignature().getProjectName()) {
303
- return this.getNamespacesMap().get(namespaceSignature.toString()) || null;
415
+ return this.getNamespacesMap().get(namespaceSignature.toMapKey()) || null;
304
416
  }
305
417
  else {
306
- const arkFile = this.sdkArkFilesMap.get(namespaceSignature.getDeclaringFileSignature().toString());
418
+ const arkFile = this.getFile(namespaceSignature.getDeclaringFileSignature());
419
+ const parentNs = namespaceSignature.getDeclaringNamespaceSignature();
420
+ if (parentNs) {
421
+ return ((_a = arkFile === null || arkFile === void 0 ? void 0 : arkFile.getNamespace(parentNs)) === null || _a === void 0 ? void 0 : _a.getNamespace(namespaceSignature)) || null;
422
+ }
307
423
  return (arkFile === null || arkFile === void 0 ? void 0 : arkFile.getNamespace(namespaceSignature)) || null;
308
424
  }
309
425
  }
310
426
  getNamespacesMap() {
311
- if (this.namespacesMap.size == 0) {
427
+ if (this.namespacesMap.size === 0) {
312
428
  for (const file of this.getFiles()) {
313
429
  ModelUtils_1.ModelUtils.getAllNamespacesInFile(file).forEach((namespace) => {
314
- this.namespacesMap.set(namespace.getNamespaceSignature().toString(), namespace);
430
+ this.namespacesMap.set(namespace.getNamespaceSignature().toMapKey(), namespace);
315
431
  });
316
432
  }
317
433
  }
@@ -320,13 +436,18 @@ class Scene {
320
436
  getNamespaces() {
321
437
  return Array.from(this.getNamespacesMap().values());
322
438
  }
439
+ /**
440
+ * Returns the class according to the input class signature.
441
+ * @param classSignature - signature of the class to be obtained.
442
+ * @returns A class.
443
+ */
323
444
  getClass(classSignature, refresh) {
324
445
  var _a;
325
446
  if (this.projectName === classSignature.getDeclaringFileSignature().getProjectName()) {
326
- return this.getClassesMap(refresh).get(classSignature.toString()) || null;
447
+ return this.getClassesMap(refresh).get(classSignature.toMapKey()) || null;
327
448
  }
328
449
  else {
329
- const arkFile = this.sdkArkFilesMap.get(classSignature.getDeclaringFileSignature().toString());
450
+ const arkFile = this.getFile(classSignature.getDeclaringFileSignature());
330
451
  const namespaceSignature = classSignature.getDeclaringNamespaceSignature();
331
452
  if (namespaceSignature) {
332
453
  return ((_a = arkFile === null || arkFile === void 0 ? void 0 : arkFile.getNamespace(namespaceSignature)) === null || _a === void 0 ? void 0 : _a.getClass(classSignature)) || null;
@@ -339,12 +460,12 @@ class Scene {
339
460
  this.classesMap.clear();
340
461
  for (const file of this.getFiles()) {
341
462
  for (const cls of file.getClasses()) {
342
- this.classesMap.set(cls.getSignature().toString(), cls);
463
+ this.classesMap.set(cls.getSignature().toMapKey(), cls);
343
464
  }
344
465
  }
345
466
  for (const namespace of this.getNamespacesMap().values()) {
346
467
  for (const cls of namespace.getClasses()) {
347
- this.classesMap.set(cls.getSignature().toString(), cls);
468
+ this.classesMap.set(cls.getSignature().toMapKey(), cls);
348
469
  }
349
470
  }
350
471
  }
@@ -356,7 +477,7 @@ class Scene {
356
477
  getMethod(methodSignature, refresh) {
357
478
  var _a;
358
479
  if (this.projectName === methodSignature.getDeclaringClassSignature().getDeclaringFileSignature().getProjectName()) {
359
- return this.getMethodsMap(refresh).get(methodSignature.toString()) || null;
480
+ return this.getMethodsMap(refresh).get(methodSignature.toMapKey()) || null;
360
481
  }
361
482
  else {
362
483
  return ((_a = this.getClass(methodSignature.getDeclaringClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethod(methodSignature)) || null;
@@ -367,17 +488,54 @@ class Scene {
367
488
  this.methodsMap.clear();
368
489
  for (const cls of this.getClassesMap().values()) {
369
490
  for (const method of cls.getMethods(true)) {
370
- this.methodsMap.set(method.getSignature().toString(), method);
491
+ this.methodsMap.set(method.getSignature().toMapKey(), method);
371
492
  }
372
493
  }
373
494
  }
374
495
  return this.methodsMap;
375
496
  }
497
+ /**
498
+ * Returns the method associated with the method signature.
499
+ * If no method is associated with this signature, **null** will be returned.
500
+ * An {@link ArkMethod} includes:
501
+ * - Name: the **string** name of method.
502
+ * - Code: the **string** code of the method.
503
+ * - Line: a **number** indicating the line location, initialized as -1.
504
+ * - Column: a **number** indicating the column location, initialized as -1.
505
+ * - Parameters & Types of parameters: the parameters of method and their types.
506
+ * - View tree: the view tree of the method.
507
+ * - ...
508
+ *
509
+ * @param methodSignature - the signature of method.
510
+ * @returns The method associated with the method signature.
511
+ * @example
512
+ * 1. get method from getMethod.
513
+
514
+ ```typescript
515
+ const methodSignatures = this.CHA.resolveCall(xxx, yyy);
516
+ for (const methodSignature of methodSignatures) {
517
+ const method = this.scene.getMethod(methodSignature);
518
+ ... ...
519
+ }
520
+ ```
521
+ */
376
522
  getMethods(refresh) {
377
523
  return Array.from(this.getMethodsMap(refresh).values());
378
524
  }
379
525
  addToMethodsMap(method) {
380
- this.methodsMap.set(method.getSignature().toString(), method);
526
+ this.methodsMap.set(method.getSignature().toMapKey(), method);
527
+ }
528
+ removeMethod(method) {
529
+ return this.methodsMap.delete(method.getSignature().toMapKey());
530
+ }
531
+ removeClass(arkClass) {
532
+ return this.classesMap.delete(arkClass.getSignature().toMapKey());
533
+ }
534
+ removeNamespace(namespace) {
535
+ return this.namespacesMap.delete(namespace.getSignature().toMapKey());
536
+ }
537
+ removeFile(file) {
538
+ return this.filesMap.delete(file.getFileSignature().toMapKey());
381
539
  }
382
540
  hasMainMethod() {
383
541
  return false;
@@ -412,28 +570,46 @@ class Scene {
412
570
  return callGraph;
413
571
  }
414
572
  /**
415
- * inference type for each non-default method
416
- * because default and generated method was finished
573
+ * Infer type for each non-default method. It infers the type of each field/local/reference.
574
+ * For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s = 'hello';`, the type of local `s` is `StringType`. The detailed types are defined in the Type.ts file.
575
+ * @example
576
+ * 1. Infer the type of each class field and method field.
577
+
578
+ ```typescript
579
+ const scene = new Scene();
580
+ scene.buildSceneFromProjectDir(sceneConfig);
581
+ scene.inferTypes();
582
+ ```
417
583
  */
418
584
  inferTypes() {
419
- this.sdkArkFilesMap.forEach(file => {
420
- ModelUtils_1.ModelUtils.buildGlobalMap(file, this.sdkGlobalMap);
421
- });
422
- this.filesMap.forEach(file => {
423
- ModelUtils_1.ModelUtils.getAllClassesInFile(file).forEach(arkClass => {
424
- TypeInference_1.TypeInference.inferGenericType(arkClass.getGenericsTypes(), arkClass);
425
- arkClass.getFields().forEach(arkField => TypeInference_1.TypeInference.inferTypeInArkField(arkField));
426
- const defaultArkMethod = arkClass.getDefaultArkMethod();
427
- if (defaultArkMethod) {
428
- TypeInference_1.TypeInference.inferTypeInMethod(defaultArkMethod);
429
- }
430
- arkClass.getMethods().forEach(arkMethod => TypeInference_1.TypeInference.inferTypeInMethod(arkMethod));
431
- });
432
- });
585
+ this.filesMap.forEach(file => this.inferFile(file));
586
+ this.getClasses(true);
433
587
  this.getMethodsMap(true);
434
588
  }
589
+ inferFile(file) {
590
+ ModelUtils_1.ModelUtils.getAllClassesInFile(file).forEach(arkClass => {
591
+ TypeInference_1.TypeInference.inferGenericType(arkClass.getGenericsTypes(), arkClass);
592
+ const defaultArkMethod = arkClass.getDefaultArkMethod();
593
+ if (defaultArkMethod) {
594
+ TypeInference_1.TypeInference.inferTypeInMethod(defaultArkMethod);
595
+ }
596
+ arkClass.getFields().forEach(arkField => TypeInference_1.TypeInference.inferTypeInArkField(arkField));
597
+ arkClass.getMethods().forEach(arkMethod => TypeInference_1.TypeInference.inferTypeInMethod(arkMethod));
598
+ });
599
+ }
435
600
  /**
601
+ * Iterate all assignment statements in methods,
602
+ * and set the type of left operand based on the type of right operand
603
+ * if the left operand is a local variable as well as an unknown.
436
604
  * @Deprecated
605
+ * @example
606
+ * 1. Infer simple type when scene building.
607
+
608
+ ```typescript
609
+ let scene = new Scene();
610
+ scene.buildSceneFromProjectDir(config);
611
+ scene.inferSimpleTypes();
612
+ ```
437
613
  */
438
614
  inferSimpleTypes() {
439
615
  for (let arkFile of this.getFiles()) {
@@ -444,13 +620,6 @@ class Scene {
444
620
  }
445
621
  }
446
622
  }
447
- collectProjectImportInfos() {
448
- this.getFiles().forEach((arkFile) => {
449
- arkFile.getImportInfos().forEach((importInfo) => {
450
- this.globalImportInfos.push(importInfo);
451
- });
452
- });
453
- }
454
623
  getClassMap() {
455
624
  var _a, _b, _c, _d;
456
625
  const classMap = new Map();
@@ -475,7 +644,7 @@ class Scene {
475
644
  nsClass.push(arkClass);
476
645
  }
477
646
  classMap.set(ns.getNamespaceSignature(), nsClass);
478
- if (ns.getNamespaces().length == 0) {
647
+ if (ns.getNamespaces().length === 0) {
479
648
  finalNamespaces.push(ns);
480
649
  }
481
650
  else {
@@ -533,7 +702,7 @@ class Scene {
533
702
  try {
534
703
  // 遗留问题:只统计了项目文件的namespace,没统计sdk文件内部的引入
535
704
  const importNameSpaceClasses = classMap.get(importNameSpace.getNamespaceSignature());
536
- importClasses.push(...importNameSpaceClasses.filter(c => !importClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
705
+ importClasses.push(...importNameSpaceClasses.filter(c => !importClasses.includes(c) && c.getName() !== Const_1.DEFAULT_ARK_CLASS_NAME));
537
706
  }
538
707
  catch (_e) {
539
708
  }
@@ -545,14 +714,14 @@ class Scene {
545
714
  const namespaceStack = [...file.getNamespaces()];
546
715
  for (const ns of namespaceStack) {
547
716
  const nsClasses = classMap.get(ns.getNamespaceSignature());
548
- nsClasses.push(...fileClasses.filter(c => !nsClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
717
+ nsClasses.push(...fileClasses.filter(c => !nsClasses.includes(c) && c.getName() !== Const_1.DEFAULT_ARK_CLASS_NAME));
549
718
  }
550
719
  while (namespaceStack.length > 0) {
551
720
  const ns = namespaceStack.shift();
552
721
  const nsClasses = classMap.get(ns.getNamespaceSignature());
553
722
  for (const nsns of ns.getNamespaces()) {
554
723
  const nsnsClasses = classMap.get(nsns.getNamespaceSignature());
555
- nsnsClasses.push(...nsClasses.filter(c => !nsnsClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
724
+ nsnsClasses.push(...nsClasses.filter(c => !nsnsClasses.includes(c) && c.getName() !== Const_1.DEFAULT_ARK_CLASS_NAME));
556
725
  namespaceStack.push(nsns);
557
726
  }
558
727
  }
@@ -568,7 +737,7 @@ class Scene {
568
737
  const finalNamespaces = [];
569
738
  const globalLocals = [];
570
739
  (_b = (_a = file.getDefaultClass()) === null || _a === void 0 ? void 0 : _a.getDefaultArkMethod().getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().forEach(local => {
571
- if (local.getDeclaringStmt() && local.getName() != 'this' && local.getName()[0] != '$') {
740
+ if (local.getDeclaringStmt() && local.getName() !== 'this' && local.getName()[0] !== '$') {
572
741
  globalLocals.push(local);
573
742
  }
574
743
  });
@@ -582,12 +751,12 @@ class Scene {
582
751
  const ns = namespaceStack.shift();
583
752
  const nsGlobalLocals = [];
584
753
  (_c = ns.getDefaultClass().getDefaultArkMethod().getBody()) === null || _c === void 0 ? void 0 : _c.getLocals().forEach(local => {
585
- if (local.getDeclaringStmt() && local.getName() != 'this' && local.getName()[0] != '$') {
754
+ if (local.getDeclaringStmt() && local.getName() !== 'this' && local.getName()[0] !== '$') {
586
755
  nsGlobalLocals.push(local);
587
756
  }
588
757
  });
589
758
  globalVariableMap.set(ns.getNamespaceSignature(), nsGlobalLocals);
590
- if (ns.getNamespaces().length == 0) {
759
+ if (ns.getNamespaces().length === 0) {
591
760
  finalNamespaces.push(ns);
592
761
  }
593
762
  else {
@@ -644,7 +813,7 @@ class Scene {
644
813
  try {
645
814
  // 遗留问题:只统计了项目文件,没统计sdk文件内部的引入
646
815
  const importNameSpaceClasses = globalVariableMap.get(importNameSpace.getNamespaceSignature());
647
- importLocals.push(...importNameSpaceClasses.filter(c => !importLocals.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
816
+ importLocals.push(...importNameSpaceClasses.filter(c => !importLocals.includes(c) && c.getName() !== Const_1.DEFAULT_ARK_CLASS_NAME));
648
817
  }
649
818
  catch (_h) {
650
819
  }
@@ -683,7 +852,7 @@ class Scene {
683
852
  getStaticInitMethods() {
684
853
  const staticInitMethods = [];
685
854
  for (const method of Array.from(this.getMethodsMap(true).values())) {
686
- if (method.getName() == Const_1.STATIC_INIT_METHOD_NAME) {
855
+ if (method.getName() === Const_1.STATIC_INIT_METHOD_NAME) {
687
856
  staticInitMethods.push(method);
688
857
  }
689
858
  }
@@ -701,17 +870,16 @@ class Scene {
701
870
  }
702
871
  exports.Scene = Scene;
703
872
  class ModuleScene {
704
- constructor() {
705
- this.projectScene = new Scene();
873
+ constructor(projectScene) {
706
874
  this.moduleName = '';
707
875
  this.modulePath = '';
708
876
  this.moduleOhPkgFilePath = '';
709
877
  this.ohPkgContent = {};
878
+ this.projectScene = projectScene;
710
879
  }
711
- ModuleScenBuilder(moduleName, modulePath, projectScene, recursively = false) {
880
+ ModuleSceneBuilder(moduleName, modulePath, recursively = false) {
712
881
  this.moduleName = moduleName;
713
882
  this.modulePath = modulePath;
714
- this.projectScene = projectScene;
715
883
  this.getModuleOhPkgFilePath();
716
884
  if (this.moduleOhPkgFilePath) {
717
885
  this.ohPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(this.moduleOhPkgFilePath);
@@ -747,14 +915,13 @@ class ModuleScene {
747
915
  return this.ohPkgContent;
748
916
  }
749
917
  genArkFiles() {
750
- (0, getAllFiles_1.getAllFiles)(this.modulePath, ['.ets', '.ts']).forEach((file) => {
918
+ (0, getAllFiles_1.getAllFiles)(this.modulePath, ['.ets', '.ts'], this.projectScene.getOptions().ignoreFileNames).forEach((file) => {
751
919
  logger.info('=== parse file:', file);
752
920
  let arkFile = new ArkFile_1.ArkFile();
753
921
  arkFile.setScene(this.projectScene);
754
922
  arkFile.setModuleScene(this);
755
923
  (0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.projectScene.getRealProjectDir(), arkFile, this.projectScene.getProjectName());
756
- const fileSig = arkFile.getFileSignature().toString();
757
- this.projectScene.getFilesMap().set(fileSig, arkFile);
924
+ this.projectScene.setFile(arkFile);
758
925
  });
759
926
  }
760
927
  }
@@ -20,9 +20,10 @@ export declare abstract class AbstractAnalysis {
20
20
  protected abstract preProcessMethod(funcID: FuncID): CallSite[];
21
21
  resolveInvokeExpr(invokeExpr: AbstractInvokeExpr): ArkMethod | undefined;
22
22
  getClassHierarchy(arkClass: ArkClass): ArkClass[];
23
- start(displayGeneratedMethod: Boolean): void;
23
+ start(displayGeneratedMethod: boolean): void;
24
24
  protected init(): void;
25
25
  protected processMethod(methodID: FuncID): CallSite[];
26
26
  protected getParamAnonymousMethod(invokeExpr: AbstractInvokeExpr): MethodSignature[];
27
+ protected addCallGraphEdge(caller: FuncID, callee: ArkMethod | null, cs: CallSite, displayGeneratedMethod: boolean): void;
27
28
  }
28
29
  //# sourceMappingURL=AbstractAnalysis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/AbstractAnalysis.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,8BAAsB,gBAAgB;IAClC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,EAAE,EAAG,SAAS,CAAC;IACzB,SAAS,CAAC,SAAS,EAAG,gBAAgB,CAAC;IACvC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAM;IAClC,SAAS,CAAC,eAAe,EAAG,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE5B,CAAC,EAAE,KAAK;IAIb,QAAQ,IAAI,KAAK;IAIjB,YAAY,IAAI,SAAS;IAIhC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IAClF,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAExD,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,SAAS,GAAG,SAAS;IAOxE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,EAAE;IAiBjD,KAAK,CAAC,sBAAsB,EAAE,OAAO,GAAG,IAAI;IAiCnD,SAAS,CAAC,IAAI,IAAI,IAAI;IAOtB,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;IAsBrD,SAAS,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,GAAG,eAAe,EAAE;CAYvF"}
1
+ {"version":3,"file":"AbstractAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/AbstractAnalysis.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,8BAAsB,gBAAgB;IAClC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,EAAE,EAAG,SAAS,CAAC;IACzB,SAAS,CAAC,SAAS,EAAG,gBAAgB,CAAC;IACvC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAM;IAClC,SAAS,CAAC,eAAe,EAAG,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE5B,CAAC,EAAE,KAAK;IAIb,QAAQ,IAAI,KAAK;IAIjB,YAAY,IAAI,SAAS;IAIhC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IAClF,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAExD,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,SAAS,GAAG,SAAS;IAOxE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,EAAE;IAgBjD,KAAK,CAAC,sBAAsB,EAAE,OAAO,GAAG,IAAI;IA8BnD,SAAS,CAAC,IAAI,IAAI,IAAI;IAOtB,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;IAsBrD,SAAS,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,GAAG,eAAe,EAAE;IAapF,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,sBAAsB,EAAE,OAAO,GAAG,IAAI;CAU5H"}
@@ -62,7 +62,6 @@ class AbstractAnalysis {
62
62
  // TODO: remove abstract class
63
63
  let classWorkList = [arkClass];
64
64
  // TODO: check class with no super Class
65
- // let classHierarchy: ArkClass[] = [arkClass.getSuperClass()]
66
65
  let classHierarchy = [];
67
66
  while (classWorkList.length > 0) {
68
67
  // TODO: no dumplicated check, TS doesn't allow multi extend
@@ -74,10 +73,10 @@ class AbstractAnalysis {
74
73
  }
75
74
  start(displayGeneratedMethod) {
76
75
  this.init();
77
- while (this.workList.length != 0) {
76
+ while (this.workList.length !== 0) {
78
77
  const method = this.workList.shift();
79
78
  const cgNode = this.cg.getNode(method);
80
- if (this.processedMethod.has(method) || cgNode.getIsSdkMethod()) {
79
+ if (this.processedMethod.has(method) || cgNode.isSdkMethod()) {
81
80
  continue;
82
81
  }
83
82
  // pre process for RTA only
@@ -87,10 +86,7 @@ class AbstractAnalysis {
87
86
  this.processMethod(method).forEach((cs) => {
88
87
  var _a;
89
88
  let me = this.cg.getArkMethodByFuncID(cs.calleeFuncID);
90
- // check if need to display generated method
91
- if (displayGeneratedMethod || (me === null || me === void 0 ? void 0 : me.isGenerated())) {
92
- this.cg.addDynamicCallEdge(method, cs.calleeFuncID, cs.callStmt);
93
- }
89
+ this.addCallGraphEdge(method, me, cs, displayGeneratedMethod);
94
90
  if (!this.processedMethod.has(cs.calleeFuncID)) {
95
91
  this.workList.push(cs.calleeFuncID);
96
92
  logger.info(`New workList item ${cs.calleeFuncID}: ${(_a = this.cg.getArkMethodByFuncID(cs.calleeFuncID)) === null || _a === void 0 ? void 0 : _a.getSignature().toString()}`);
@@ -133,5 +129,16 @@ class AbstractAnalysis {
133
129
  });
134
130
  return paramMethod;
135
131
  }
132
+ addCallGraphEdge(caller, callee, cs, displayGeneratedMethod) {
133
+ // check if need to display generated method
134
+ if (!callee) {
135
+ logger.error(`FuncID has no method ${cs.calleeFuncID}`);
136
+ }
137
+ else {
138
+ if (displayGeneratedMethod || !(callee === null || callee === void 0 ? void 0 : callee.isGenerated())) {
139
+ this.cg.addDynamicCallEdge(caller, cs.calleeFuncID, cs.callStmt);
140
+ }
141
+ }
142
+ }
136
143
  }
137
144
  exports.AbstractAnalysis = AbstractAnalysis;
@@ -1 +1 @@
1
- {"version":3,"file":"ClassHierarchyAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/ClassHierarchyAnalysis.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,qBAAa,sBAAuB,SAAQ,gBAAgB;gBAE5C,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS;IAKhC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IAyDtE,SAAS,CAAC,gBAAgB,IAAI,QAAQ,EAAE;CAI3C"}
1
+ {"version":3,"file":"ClassHierarchyAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/ClassHierarchyAnalysis.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,qBAAa,sBAAuB,SAAQ,gBAAgB;gBAE5C,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS;IAKhC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IAwDtE,SAAS,CAAC,gBAAgB,IAAI,QAAQ,EAAE;CAI3C"}
@@ -18,7 +18,6 @@ exports.ClassHierarchyAnalysis = void 0;
18
18
  const Expr_1 = require("../../core/base/Expr");
19
19
  const CallGraph_1 = require("../model/CallGraph");
20
20
  const AbstractAnalysis_1 = require("./AbstractAnalysis");
21
- const TSConst_1 = require("../../core/common/TSConst");
22
21
  class ClassHierarchyAnalysis extends AbstractAnalysis_1.AbstractAnalysis {
23
22
  constructor(scene, cg) {
24
23
  super(scene);
@@ -40,14 +39,13 @@ class ClassHierarchyAnalysis extends AbstractAnalysis_1.AbstractAnalysis {
40
39
  }
41
40
  if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr) {
42
41
  // get specific method
43
- // resolveResult.push(calleeMethod.getSignature())
44
42
  resolveResult.push(new CallGraph_1.CallSite(invokeStmt, undefined, this.cg.getCallGraphNodeByMethod(calleeMethod.getSignature()).getID(), callerMethod));
45
43
  }
46
44
  else {
47
45
  let declareClass = calleeMethod.getDeclaringArkClass();
48
46
  // TODO: super class method should be placed at the end
49
47
  this.getClassHierarchy(declareClass).forEach((arkClass) => {
50
- if (arkClass.getModifiers().has(TSConst_1.ABSTRACT_KEYWORD)) {
48
+ if (arkClass.isAbstract()) {
51
49
  return;
52
50
  }
53
51
  let possibleCalleeMethod = arkClass.getMethodWithName(calleeMethod.getName());
@@ -56,7 +54,7 @@ class ClassHierarchyAnalysis extends AbstractAnalysis_1.AbstractAnalysis {
56
54
  // remove the generated method in extended classes
57
55
  return;
58
56
  }
59
- if (possibleCalleeMethod && !possibleCalleeMethod.getModifiers().has(TSConst_1.ABSTRACT_KEYWORD)) {
57
+ if (possibleCalleeMethod && !possibleCalleeMethod.isAbstract()) {
60
58
  resolveResult.push(new CallGraph_1.CallSite(invokeStmt, undefined, this.cg.getCallGraphNodeByMethod(possibleCalleeMethod.getSignature()).getID(), callerMethod));
61
59
  }
62
60
  });
@@ -1 +1 @@
1
- {"version":3,"file":"RapidTypeAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/RapidTypeAnalysis.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAOtD,qBAAa,iBAAkB,SAAQ,gBAAgB;IAEnD,OAAO,CAAC,gBAAgB,CAAkC;IAE1D,OAAO,CAAC,YAAY,CAA2F;gBAEnG,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS;IAKhC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IA4DtE,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAqBtD,OAAO,CAAC,+BAA+B;IA4BhC,eAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI;CAKxG"}
1
+ {"version":3,"file":"RapidTypeAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/algorithm/RapidTypeAnalysis.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,qBAAa,iBAAkB,SAAQ,gBAAgB;IAEnD,OAAO,CAAC,gBAAgB,CAAkC;IAE1D,OAAO,CAAC,YAAY,CAA2F;gBAEnG,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS;IAKhC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IA4DtE,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAqBtD,OAAO,CAAC,+BAA+B;IA4BhC,eAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI;CAKxG"}