arkanalyzer 1.0.86 → 1.0.87

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 (400) hide show
  1. package/README.en.md +69 -65
  2. package/README.md +56 -70
  3. package/config/arkanalyzer.json +7 -2
  4. package/docs/cppFrontend/ArkAnalyzer-cpp_usage_guide.md +245 -0
  5. package/docs/cppFrontend/cpp_frontend_build_guide.md +126 -0
  6. package/docs/cppFrontend/cpp_frontend_user_guide.md +175 -0
  7. package/docs/cppFrontend/img.png +0 -0
  8. package/docs/cppFrontend/img_1.png +0 -0
  9. package/docs/cppFrontend/img_10.png +0 -0
  10. package/docs/cppFrontend/img_11.png +0 -0
  11. package/docs/cppFrontend/img_12.png +0 -0
  12. package/docs/cppFrontend/img_13.png +0 -0
  13. package/docs/cppFrontend/img_14.png +0 -0
  14. package/docs/cppFrontend/img_15.png +0 -0
  15. package/docs/cppFrontend/img_16.png +0 -0
  16. package/docs/cppFrontend/img_17.png +0 -0
  17. package/docs/cppFrontend/img_18.png +0 -0
  18. package/docs/cppFrontend/img_19.png +0 -0
  19. package/docs/cppFrontend/img_2.png +0 -0
  20. package/docs/cppFrontend/img_20.png +0 -0
  21. package/docs/cppFrontend/img_21.png +0 -0
  22. package/docs/cppFrontend/img_22.png +0 -0
  23. package/docs/cppFrontend/img_23.png +0 -0
  24. package/docs/cppFrontend/img_3.png +0 -0
  25. package/docs/cppFrontend/img_4.png +0 -0
  26. package/docs/cppFrontend/img_5.png +0 -0
  27. package/docs/cppFrontend/img_6.png +0 -0
  28. package/docs/cppFrontend/img_7.png +0 -0
  29. package/docs/cppFrontend/img_8.png +0 -0
  30. package/docs/cppFrontend/img_9.png +0 -0
  31. package/docs/sig_programanalysis.en.md +66 -0
  32. package/docs/sig_programanalysis.md +73 -0
  33. package/lib/Config.d.ts +32 -1
  34. package/lib/Config.d.ts.map +1 -1
  35. package/lib/Config.js +76 -2
  36. package/lib/Scene.d.ts +25 -2
  37. package/lib/Scene.d.ts.map +1 -1
  38. package/lib/Scene.js +148 -40
  39. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +4 -3
  40. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
  41. package/lib/callgraph/algorithm/AbstractAnalysis.js +17 -17
  42. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +6 -1
  43. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
  44. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +117 -14
  45. package/lib/callgraph/common/Statistics.d.ts +4 -2
  46. package/lib/callgraph/common/Statistics.d.ts.map +1 -1
  47. package/lib/callgraph/common/Statistics.js +14 -2
  48. package/lib/callgraph/model/CallGraph.d.ts +12 -8
  49. package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
  50. package/lib/callgraph/model/CallGraph.js +53 -29
  51. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +1 -0
  52. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -1
  53. package/lib/callgraph/model/builder/CallGraphBuilder.js +5 -1
  54. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
  55. package/lib/callgraph/pointerAnalysis/Pag.js +3 -0
  56. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +4 -2
  57. package/lib/cli/cli.d.ts +3 -0
  58. package/lib/cli/cli.d.ts.map +1 -0
  59. package/lib/cli/cli.js +82 -0
  60. package/lib/cli/commands/cg.d.ts +32 -0
  61. package/lib/cli/commands/cg.d.ts.map +1 -0
  62. package/lib/cli/commands/cg.js +401 -0
  63. package/lib/cli/commands/index.d.ts +6 -0
  64. package/lib/cli/commands/index.d.ts.map +1 -0
  65. package/lib/cli/commands/index.js +64 -0
  66. package/lib/cli/commands/ir.d.ts +26 -0
  67. package/lib/cli/commands/ir.d.ts.map +1 -0
  68. package/lib/cli/commands/ir.js +94 -0
  69. package/lib/core/base/Constant.d.ts +1 -1
  70. package/lib/core/base/Constant.d.ts.map +1 -1
  71. package/lib/core/base/Constant.js +1 -1
  72. package/lib/core/base/Expr.d.ts +29 -5
  73. package/lib/core/base/Expr.d.ts.map +1 -1
  74. package/lib/core/base/Expr.js +144 -22
  75. package/lib/core/base/Position.d.ts +14 -0
  76. package/lib/core/base/Position.d.ts.map +1 -1
  77. package/lib/core/base/Position.js +27 -0
  78. package/lib/core/base/Ref.d.ts +1 -0
  79. package/lib/core/base/Ref.d.ts.map +1 -1
  80. package/lib/core/base/Ref.js +4 -1
  81. package/lib/core/base/Type.d.ts +64 -24
  82. package/lib/core/base/Type.d.ts.map +1 -1
  83. package/lib/core/base/Type.js +144 -49
  84. package/lib/core/common/ArkError.d.ts +26 -2
  85. package/lib/core/common/ArkError.d.ts.map +1 -1
  86. package/lib/core/common/ArkError.js +56 -2
  87. package/lib/core/common/ArkIRTransformer.d.ts +11 -10
  88. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  89. package/lib/core/common/ArkIRTransformer.js +1 -1
  90. package/lib/core/common/ArkValueTransformer.d.ts +14 -12
  91. package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
  92. package/lib/core/common/ArkValueTransformer.js +1 -5
  93. package/lib/core/common/Const.d.ts +3 -0
  94. package/lib/core/common/Const.d.ts.map +1 -1
  95. package/lib/core/common/Const.js +4 -1
  96. package/lib/core/common/DummyMainCreater.d.ts +23 -13
  97. package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
  98. package/lib/core/common/DummyMainCreater.js +66 -43
  99. package/lib/core/common/EtsConst.d.ts +11 -0
  100. package/lib/core/common/EtsConst.d.ts.map +1 -1
  101. package/lib/core/common/EtsConst.js +12 -1
  102. package/lib/core/common/IRInference.d.ts.map +1 -1
  103. package/lib/core/common/IRInference.js +5 -1
  104. package/lib/core/common/ModelUtils.d.ts +4 -7
  105. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  106. package/lib/core/common/ModelUtils.js +77 -110
  107. package/lib/core/common/SdkUtils.d.ts +1 -1
  108. package/lib/core/common/SdkUtils.d.ts.map +1 -1
  109. package/lib/core/common/SdkUtils.js +14 -5
  110. package/lib/core/common/TypeInference.d.ts.map +1 -1
  111. package/lib/core/common/TypeInference.js +9 -3
  112. package/lib/core/graph/BaseExplicitGraph.d.ts +4 -4
  113. package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
  114. package/lib/core/graph/BaseExplicitGraph.js +15 -8
  115. package/lib/core/graph/BasicBlock.d.ts.map +1 -1
  116. package/lib/core/graph/Scc.d.ts.map +1 -1
  117. package/lib/core/graph/Scc.js +7 -2
  118. package/lib/core/graph/builder/CfgBuilder.d.ts +10 -7
  119. package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
  120. package/lib/core/graph/builder/CfgBuilder.js +12 -5
  121. package/lib/core/inference/Inference.d.ts.map +1 -1
  122. package/lib/core/inference/Inference.js +7 -0
  123. package/lib/core/inference/ModelInference.d.ts +1 -1
  124. package/lib/core/inference/ModelInference.d.ts.map +1 -1
  125. package/lib/core/inference/ValueInference.d.ts +3 -2
  126. package/lib/core/inference/ValueInference.d.ts.map +1 -1
  127. package/lib/core/inference/ValueInference.js +64 -12
  128. package/lib/core/inference/abc/AbcInference.d.ts +28 -2
  129. package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
  130. package/lib/core/inference/abc/AbcInference.js +105 -4
  131. package/lib/core/model/ArkBaseModel.d.ts +14 -1
  132. package/lib/core/model/ArkBaseModel.d.ts.map +1 -1
  133. package/lib/core/model/ArkBaseModel.js +61 -2
  134. package/lib/core/model/ArkBody.d.ts.map +1 -1
  135. package/lib/core/model/ArkBody.js +1 -3
  136. package/lib/core/model/ArkClass.d.ts +22 -2
  137. package/lib/core/model/ArkClass.d.ts.map +1 -1
  138. package/lib/core/model/ArkClass.js +59 -28
  139. package/lib/core/model/ArkField.d.ts.map +1 -1
  140. package/lib/core/model/ArkField.js +3 -1
  141. package/lib/core/model/ArkFile.d.ts +4 -1
  142. package/lib/core/model/ArkFile.d.ts.map +1 -1
  143. package/lib/core/model/ArkFile.js +44 -3
  144. package/lib/core/model/ArkImport.d.ts.map +1 -1
  145. package/lib/core/model/ArkImport.js +9 -1
  146. package/lib/core/model/ArkMethod.d.ts +5 -0
  147. package/lib/core/model/ArkMethod.d.ts.map +1 -1
  148. package/lib/core/model/ArkMethod.js +33 -1
  149. package/lib/core/model/ArkNamespace.d.ts +2 -0
  150. package/lib/core/model/ArkNamespace.d.ts.map +1 -1
  151. package/lib/core/model/ArkNamespace.js +11 -0
  152. package/lib/core/model/ArkSignature.d.ts +3 -3
  153. package/lib/core/model/ArkSignature.d.ts.map +1 -1
  154. package/lib/core/model/ArkSignature.js +14 -9
  155. package/lib/core/model/builder/ArkClassBuilder.d.ts +2 -0
  156. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  157. package/lib/core/model/builder/ArkClassBuilder.js +3 -3
  158. package/lib/core/model/builder/ArkMethodBuilder.d.ts +4 -1
  159. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  160. package/lib/core/model/builder/ArkMethodBuilder.js +19 -6
  161. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +1 -0
  162. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  163. package/lib/core/model/builder/ArkNamespaceBuilder.js +2 -1
  164. package/lib/core/model/builder/BodyBuilder.d.ts +4 -0
  165. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
  166. package/lib/core/model/builder/builderUtils.d.ts +1 -0
  167. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  168. package/lib/core/model/builder/builderUtils.js +7 -3
  169. package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.d.ts +296 -0
  170. package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.d.ts.map +1 -0
  171. package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.js +145 -0
  172. package/lib/frontend/cppFrontend/ast/astUtils.d.ts +51 -0
  173. package/lib/frontend/cppFrontend/ast/astUtils.d.ts.map +1 -0
  174. package/lib/frontend/cppFrontend/ast/astUtils.js +470 -0
  175. package/lib/frontend/cppFrontend/ast/const.d.ts +30 -0
  176. package/lib/frontend/cppFrontend/ast/const.d.ts.map +1 -0
  177. package/lib/frontend/cppFrontend/ast/const.js +134 -0
  178. package/lib/frontend/cppFrontend/base/Constant.d.ts +9 -0
  179. package/lib/frontend/cppFrontend/base/Constant.d.ts.map +1 -0
  180. package/lib/frontend/cppFrontend/base/Constant.js +33 -0
  181. package/lib/frontend/cppFrontend/base/Expr.d.ts +174 -0
  182. package/lib/frontend/cppFrontend/base/Expr.d.ts.map +1 -0
  183. package/lib/frontend/cppFrontend/base/Expr.js +530 -0
  184. package/lib/frontend/cppFrontend/base/Ref.d.ts +25 -0
  185. package/lib/frontend/cppFrontend/base/Ref.d.ts.map +1 -0
  186. package/lib/frontend/cppFrontend/base/Ref.js +53 -0
  187. package/lib/frontend/cppFrontend/base/Trap.d.ts +8 -0
  188. package/lib/frontend/cppFrontend/base/Trap.d.ts.map +1 -0
  189. package/lib/frontend/cppFrontend/base/Trap.js +28 -0
  190. package/lib/frontend/cppFrontend/base/Type.d.ts +264 -0
  191. package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -0
  192. package/lib/frontend/cppFrontend/base/Type.js +600 -0
  193. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts +109 -0
  194. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -0
  195. package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +925 -0
  196. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +477 -0
  197. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -0
  198. package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +2746 -0
  199. package/lib/frontend/cppFrontend/common/Builtin.d.ts +57 -0
  200. package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -0
  201. package/lib/frontend/cppFrontend/common/Builtin.js +106 -0
  202. package/lib/frontend/cppFrontend/common/IRInference.d.ts +94 -0
  203. package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -0
  204. package/lib/frontend/cppFrontend/common/IRInference.js +1087 -0
  205. package/lib/frontend/cppFrontend/common/IRUtils.d.ts +23 -0
  206. package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -0
  207. package/lib/frontend/cppFrontend/common/IRUtils.js +168 -0
  208. package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +44 -0
  209. package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -0
  210. package/lib/frontend/cppFrontend/common/ModelUtils.js +567 -0
  211. package/lib/frontend/cppFrontend/common/TypeInference.d.ts +278 -0
  212. package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -0
  213. package/lib/frontend/cppFrontend/common/TypeInference.js +1354 -0
  214. package/lib/frontend/cppFrontend/common/ValueUtil.d.ts +16 -0
  215. package/lib/frontend/cppFrontend/common/ValueUtil.d.ts.map +1 -0
  216. package/lib/frontend/cppFrontend/common/ValueUtil.js +61 -0
  217. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts +182 -0
  218. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -0
  219. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +1435 -0
  220. package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.d.ts +21 -0
  221. package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.d.ts.map +1 -0
  222. package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.js +303 -0
  223. package/lib/frontend/cppFrontend/graph/builder/IfBuilder.d.ts +15 -0
  224. package/lib/frontend/cppFrontend/graph/builder/IfBuilder.d.ts.map +1 -0
  225. package/lib/frontend/cppFrontend/graph/builder/IfBuilder.js +161 -0
  226. package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.d.ts +21 -0
  227. package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.d.ts.map +1 -0
  228. package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.js +261 -0
  229. package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.d.ts +12 -0
  230. package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.d.ts.map +1 -0
  231. package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.js +155 -0
  232. package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.d.ts +29 -0
  233. package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.d.ts.map +1 -0
  234. package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.js +302 -0
  235. package/lib/frontend/cppFrontend/inference/CxxInference.d.ts +10 -0
  236. package/lib/frontend/cppFrontend/inference/CxxInference.d.ts.map +1 -0
  237. package/lib/frontend/cppFrontend/inference/CxxInference.js +41 -0
  238. package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +28 -0
  239. package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -0
  240. package/lib/frontend/cppFrontend/inference/CxxModelInference.js +98 -0
  241. package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts +20 -0
  242. package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -0
  243. package/lib/frontend/cppFrontend/inference/CxxValueInference.js +128 -0
  244. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts +11 -0
  245. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -0
  246. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +413 -0
  247. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts +5 -0
  248. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -0
  249. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +61 -0
  250. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +17 -0
  251. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -0
  252. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +285 -0
  253. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts +6 -0
  254. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts.map +1 -0
  255. package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.js +57 -0
  256. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts +14 -0
  257. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -0
  258. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +422 -0
  259. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +8 -0
  260. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -0
  261. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +194 -0
  262. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +59 -0
  263. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -0
  264. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +605 -0
  265. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts +46 -0
  266. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -0
  267. package/lib/frontend/cppFrontend/model/builder/builderUtils.js +499 -0
  268. package/lib/frontend/cppFrontend/utils/cmakeUtils.d.ts +44 -0
  269. package/lib/frontend/cppFrontend/utils/cmakeUtils.d.ts.map +1 -0
  270. package/lib/frontend/cppFrontend/utils/cmakeUtils.js +240 -0
  271. package/lib/index.d.ts +1 -0
  272. package/lib/index.d.ts.map +1 -1
  273. package/lib/index.js +7 -1
  274. package/lib/node_modules/ohos-typescript/.ohos-typescript-version +1 -0
  275. package/{node_modules → lib/node_modules}/ohos-typescript/package.json +2 -1
  276. package/lib/save/CGJsonPrinter.d.ts +8 -0
  277. package/lib/save/CGJsonPrinter.d.ts.map +1 -0
  278. package/lib/save/CGJsonPrinter.js +41 -0
  279. package/lib/save/GraphPrinter.js +2 -2
  280. package/lib/save/json/JsonDto.d.ts +86 -2
  281. package/lib/save/json/JsonDto.d.ts.map +1 -1
  282. package/lib/save/json/JsonSerialization.d.ts +1 -1
  283. package/lib/save/json/JsonSerialization.d.ts.map +1 -1
  284. package/lib/save/json/JsonSerialization.js +235 -145
  285. package/lib/save/source/SourceTransformer.d.ts.map +1 -1
  286. package/lib/save/source/SourceTransformer.js +0 -3
  287. package/lib/utils/CxxSceneUtils.d.ts +11 -0
  288. package/lib/utils/CxxSceneUtils.d.ts.map +1 -0
  289. package/lib/utils/CxxSceneUtils.js +178 -0
  290. package/lib/utils/FileUtils.d.ts +7 -8
  291. package/lib/utils/FileUtils.d.ts.map +1 -1
  292. package/lib/utils/FileUtils.js +27 -45
  293. package/lib/utils/LRUCacheDecorator.d.ts +20 -0
  294. package/lib/utils/LRUCacheDecorator.d.ts.map +1 -0
  295. package/lib/utils/LRUCacheDecorator.js +89 -0
  296. package/lib/utils/ModuleUtils.d.ts +39 -0
  297. package/lib/utils/ModuleUtils.d.ts.map +1 -0
  298. package/lib/utils/ModuleUtils.js +261 -0
  299. package/package.json +10 -7
  300. /package/{node_modules → lib/node_modules}/ohos-typescript/LICENSE +0 -0
  301. /package/{node_modules → lib/node_modules}/ohos-typescript/README.OpenSource +0 -0
  302. /package/{node_modules → lib/node_modules}/ohos-typescript/README.md +0 -0
  303. /package/{node_modules → lib/node_modules}/ohos-typescript/SECURITY.md +0 -0
  304. /package/{node_modules → lib/node_modules}/ohos-typescript/ThirdPartyNoticeText.txt +0 -0
  305. /package/{node_modules → lib/node_modules}/ohos-typescript/bin/tsc +0 -0
  306. /package/{node_modules → lib/node_modules}/ohos-typescript/bin/tsserver +0 -0
  307. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/README.md +0 -0
  308. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/cancellationToken.js +0 -0
  309. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/cs/diagnosticMessages.generated.json +0 -0
  310. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/de/diagnosticMessages.generated.json +0 -0
  311. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/es/diagnosticMessages.generated.json +0 -0
  312. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/fr/diagnosticMessages.generated.json +0 -0
  313. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/it/diagnosticMessages.generated.json +0 -0
  314. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ja/diagnosticMessages.generated.json +0 -0
  315. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ko/diagnosticMessages.generated.json +0 -0
  316. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.d.ts +0 -0
  317. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.dom.d.ts +0 -0
  318. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.dom.iterable.d.ts +0 -0
  319. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.collection.d.ts +0 -0
  320. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.core.d.ts +0 -0
  321. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.d.ts +0 -0
  322. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.generator.d.ts +0 -0
  323. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.iterable.d.ts +0 -0
  324. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.promise.d.ts +0 -0
  325. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.proxy.d.ts +0 -0
  326. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.reflect.d.ts +0 -0
  327. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.symbol.d.ts +0 -0
  328. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -0
  329. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.array.include.d.ts +0 -0
  330. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.d.ts +0 -0
  331. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.full.d.ts +0 -0
  332. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.d.ts +0 -0
  333. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.full.d.ts +0 -0
  334. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.intl.d.ts +0 -0
  335. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.object.d.ts +0 -0
  336. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.sharedmemory.d.ts +0 -0
  337. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.string.d.ts +0 -0
  338. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.typedarrays.d.ts +0 -0
  339. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -0
  340. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.asynciterable.d.ts +0 -0
  341. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.d.ts +0 -0
  342. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.full.d.ts +0 -0
  343. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.intl.d.ts +0 -0
  344. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.promise.d.ts +0 -0
  345. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.regexp.d.ts +0 -0
  346. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.array.d.ts +0 -0
  347. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.d.ts +0 -0
  348. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.full.d.ts +0 -0
  349. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.intl.d.ts +0 -0
  350. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.object.d.ts +0 -0
  351. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.string.d.ts +0 -0
  352. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.symbol.d.ts +0 -0
  353. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.bigint.d.ts +0 -0
  354. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.d.ts +0 -0
  355. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.date.d.ts +0 -0
  356. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.full.d.ts +0 -0
  357. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.intl.d.ts +0 -0
  358. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.number.d.ts +0 -0
  359. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.promise.d.ts +0 -0
  360. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.sharedmemory.d.ts +0 -0
  361. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.string.d.ts +0 -0
  362. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -0
  363. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.d.ts +0 -0
  364. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.full.d.ts +0 -0
  365. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.intl.d.ts +0 -0
  366. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.promise.d.ts +0 -0
  367. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.string.d.ts +0 -0
  368. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.weakref.d.ts +0 -0
  369. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.array.d.ts +0 -0
  370. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.d.ts +0 -0
  371. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.error.d.ts +0 -0
  372. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.full.d.ts +0 -0
  373. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.intl.d.ts +0 -0
  374. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.object.d.ts +0 -0
  375. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.sharedmemory.d.ts +0 -0
  376. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.string.d.ts +0 -0
  377. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es5.d.ts +0 -0
  378. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es6.d.ts +0 -0
  379. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.d.ts +0 -0
  380. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.full.d.ts +0 -0
  381. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.intl.d.ts +0 -0
  382. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.scripthost.d.ts +0 -0
  383. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.d.ts +0 -0
  384. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.importscripts.d.ts +0 -0
  385. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.iterable.d.ts +0 -0
  386. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/pl/diagnosticMessages.generated.json +0 -0
  387. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/pt-br/diagnosticMessages.generated.json +0 -0
  388. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ru/diagnosticMessages.generated.json +0 -0
  389. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tr/diagnosticMessages.generated.json +0 -0
  390. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsc.js +0 -0
  391. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserver.js +0 -0
  392. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserverlibrary.d.ts +0 -0
  393. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserverlibrary.js +0 -0
  394. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typesMap.json +0 -0
  395. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typescript.d.ts +0 -0
  396. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typescript.js +0 -0
  397. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typingsInstaller.js +0 -0
  398. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/watchGuard.js +0 -0
  399. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -0
  400. /package/{node_modules → lib/node_modules}/ohos-typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -0
@@ -0,0 +1,1354 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024-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.TypeInference = void 0;
41
+ const logger_1 = __importStar(require("../../../utils/logger"));
42
+ const Expr_1 = require("../../../core/base/Expr");
43
+ const Local_1 = require("../../../core/base/Local");
44
+ const Ref_1 = require("../../../core/base/Ref");
45
+ const Stmt_1 = require("../../../core/base/Stmt");
46
+ const Type_1 = require("../../../core/base/Type");
47
+ const Type_2 = require("../base/Type");
48
+ const ArkMethod_1 = require("../../../core/model/ArkMethod");
49
+ const ArkClass_1 = require("../../../core/model/ArkClass");
50
+ const ArkField_1 = require("../../../core/model/ArkField");
51
+ const Constant_1 = require("../../../core/base/Constant");
52
+ const ArkNamespace_1 = require("../../../core/model/ArkNamespace");
53
+ const TSConst_1 = require("../../../core/common/TSConst");
54
+ const ModelUtils_1 = require("../../../core/common/ModelUtils");
55
+ const Builtin_1 = require("../../../core/common/Builtin");
56
+ const ArkSignature_1 = require("../../../core/model/ArkSignature");
57
+ const Const_1 = require("../../../core/common/Const");
58
+ const ValueUtil_1 = require("../../../core/common/ValueUtil");
59
+ const ArkImport_1 = require("../../../core/model/ArkImport");
60
+ const IRInference_1 = require("./IRInference");
61
+ const TypeExpr_1 = require("../../../core/base/TypeExpr");
62
+ const SdkUtils_1 = require("../../../core/common/SdkUtils");
63
+ const ArkBaseModel_1 = require("../../../core/model/ArkBaseModel");
64
+ const Builtin_2 = require("./Builtin");
65
+ const ModelUtils_2 = require("./ModelUtils");
66
+ const ArkFile_1 = require("../../../core/model/ArkFile");
67
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'TypeInference');
68
+ const unknownFileName = [Const_1.UNKNOWN_FILE_NAME, Builtin_1.Builtin.DUMMY_FILE_NAME];
69
+ class TypeInference {
70
+ static inferTypeInArkField(arkField) {
71
+ var _a, _b;
72
+ const arkClass = arkField.getDeclaringArkClass();
73
+ const stmts = arkField.getInitializer();
74
+ const method = (_b = (_a = arkClass.getMethodWithName(Const_1.INSTANCE_INIT_METHOD_NAME)) !== null && _a !== void 0 ? _a : arkClass.getMethodWithName(Const_1.STATIC_INIT_METHOD_NAME)) !== null && _b !== void 0 ? _b : arkClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
75
+ for (const stmt of stmts) {
76
+ if (method) {
77
+ this.resolveStmt(stmt, method);
78
+ }
79
+ }
80
+ const beforeType = arkField.getType();
81
+ if (!this.isUnclearType(beforeType)) {
82
+ return;
83
+ }
84
+ let rightType;
85
+ let fieldRef;
86
+ const lastStmt = stmts[stmts.length - 1];
87
+ if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
88
+ rightType = lastStmt.getRightOp().getType();
89
+ if (lastStmt.getLeftOp() instanceof Ref_1.ArkInstanceFieldRef) {
90
+ fieldRef = lastStmt.getLeftOp();
91
+ }
92
+ }
93
+ let fieldType;
94
+ if (beforeType) {
95
+ fieldType = this.inferUnclearedType(beforeType, arkClass);
96
+ }
97
+ if (fieldType) {
98
+ arkField.getSignature().setType(fieldType);
99
+ fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.setFieldSignature(arkField.getSignature());
100
+ }
101
+ else if (rightType && this.isUnclearType(beforeType) && !this.isUnclearType(rightType)) {
102
+ arkField.getSignature().setType(rightType);
103
+ fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.setFieldSignature(arkField.getSignature());
104
+ }
105
+ }
106
+ /**
107
+ * Infer type for a given unclear type.
108
+ * It returns an array with 2 items, original object and original type.
109
+ * The original object is null if there is no object, or it failed to find the object.
110
+ * The original type is null if failed to infer the type.
111
+ * @param leftOpType
112
+ * @param declaringArkClass
113
+ * @param visited
114
+ * @returns
115
+ */
116
+ static inferUnclearedType(leftOpType, declaringArkClass, visited = new Set()) {
117
+ let typeWithoutPtrOrRef = leftOpType;
118
+ if (typeWithoutPtrOrRef instanceof Type_2.PointerType || typeWithoutPtrOrRef instanceof Type_2.ReferenceType) {
119
+ typeWithoutPtrOrRef = typeWithoutPtrOrRef.getBaseType();
120
+ }
121
+ if (visited.has(typeWithoutPtrOrRef)) {
122
+ return typeWithoutPtrOrRef;
123
+ }
124
+ else {
125
+ visited.add(typeWithoutPtrOrRef);
126
+ }
127
+ let type;
128
+ if (typeWithoutPtrOrRef instanceof Type_1.ClassType &&
129
+ unknownFileName.includes(typeWithoutPtrOrRef.getClassSignature().getDeclaringFileSignature().getFileName())) {
130
+ const realTypes = typeWithoutPtrOrRef.getRealGenericTypes();
131
+ this.inferRealGenericTypes(realTypes, declaringArkClass);
132
+ let newType = this.inferUnclearRefName(typeWithoutPtrOrRef.getClassSignature().getClassName(), declaringArkClass);
133
+ type = newType ? this.replaceTypeWithReal(newType, realTypes) : null;
134
+ }
135
+ else if (typeWithoutPtrOrRef instanceof TypeExpr_1.TypeQueryExpr) {
136
+ this.inferRealGenericTypes(typeWithoutPtrOrRef.getGenerateTypes(), declaringArkClass);
137
+ type = typeWithoutPtrOrRef;
138
+ }
139
+ else if (typeWithoutPtrOrRef instanceof Type_1.TupleType) {
140
+ this.inferRealGenericTypes(typeWithoutPtrOrRef.getTypes(), declaringArkClass);
141
+ type = typeWithoutPtrOrRef;
142
+ }
143
+ else if (typeWithoutPtrOrRef instanceof Type_1.GenericType) {
144
+ this.inferGenericType([typeWithoutPtrOrRef], declaringArkClass);
145
+ type = typeWithoutPtrOrRef;
146
+ }
147
+ else if (typeWithoutPtrOrRef instanceof Type_1.AnnotationNamespaceType) {
148
+ type = this.inferBaseType(typeWithoutPtrOrRef.getOriginType(), declaringArkClass);
149
+ }
150
+ else if (typeWithoutPtrOrRef instanceof Type_1.UnclearReferenceType) {
151
+ type = this.inferUnclearRefType(typeWithoutPtrOrRef, declaringArkClass);
152
+ }
153
+ if (type) {
154
+ if (leftOpType instanceof Type_2.PointerType || leftOpType instanceof Type_2.ReferenceType) {
155
+ leftOpType.setBaseType(type);
156
+ return leftOpType;
157
+ }
158
+ return type;
159
+ }
160
+ type = this.inferUnclearComplexType(typeWithoutPtrOrRef, declaringArkClass, visited);
161
+ if (type) {
162
+ if (leftOpType instanceof Type_2.PointerType || leftOpType instanceof Type_2.ReferenceType) {
163
+ leftOpType.setBaseType(type);
164
+ return leftOpType;
165
+ }
166
+ }
167
+ return type;
168
+ }
169
+ static inferUnclearComplexType(leftOpType, declaringArkClass, visited) {
170
+ var _a;
171
+ let type;
172
+ if (leftOpType instanceof Type_1.ArrayType) {
173
+ let baseType = this.inferUnclearedType(leftOpType.getBaseType(), declaringArkClass, visited);
174
+ if (baseType) {
175
+ leftOpType.setBaseType(baseType);
176
+ type = leftOpType;
177
+ }
178
+ }
179
+ else if (leftOpType instanceof Type_1.AliasType) {
180
+ const defArkClass = (_a = declaringArkClass.getDeclaringArkFile().getScene().getMethod(leftOpType.getSignature().getDeclaringMethodSignature())) === null || _a === void 0 ? void 0 : _a.getDeclaringArkClass();
181
+ let baseType = this.inferUnclearedType(leftOpType.getOriginalType(), defArkClass !== null && defArkClass !== void 0 ? defArkClass : declaringArkClass, visited);
182
+ if (baseType) {
183
+ leftOpType.setOriginalType(baseType);
184
+ type = leftOpType;
185
+ }
186
+ }
187
+ return type;
188
+ }
189
+ /**
190
+ * Type information in inference method
191
+ * @param arkMethod Ark method object for type inference
192
+ */
193
+ static inferTypeInMethod(arkMethod) {
194
+ var _a, _b;
195
+ const arkClass = arkMethod.getDeclaringArkClass();
196
+ this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
197
+ const signatures = [];
198
+ (_a = arkMethod.getDeclareSignatures()) === null || _a === void 0 ? void 0 : _a.forEach(m => signatures.push(m));
199
+ const impl = arkMethod.getImplementationSignature();
200
+ if (impl) {
201
+ signatures.push(impl);
202
+ }
203
+ signatures.forEach(s => {
204
+ s.getMethodSubSignature()
205
+ .getParameters()
206
+ .forEach(p => {
207
+ this.inferParameterType(p, arkMethod);
208
+ });
209
+ });
210
+ const body = arkMethod.getBody();
211
+ if (!body) {
212
+ signatures.forEach(s => this.inferSignatureReturnType(s, arkMethod));
213
+ return;
214
+ }
215
+ (_b = body.getUsedGlobals()) === null || _b === void 0 ? void 0 : _b.forEach((value, key) => {
216
+ if (value instanceof Ref_1.GlobalRef && !value.getRef()) {
217
+ const arkExport = ModelUtils_1.ModelUtils.findGlobalRef(key, arkMethod);
218
+ if (arkExport instanceof Local_1.Local) {
219
+ arkExport.getUsedStmts().push(...value.getUsedStmts());
220
+ value.setRef(arkExport);
221
+ }
222
+ }
223
+ });
224
+ const cfg = body.getCfg();
225
+ for (const block of cfg.getBlocks()) {
226
+ for (const stmt of block.getStmts()) {
227
+ this.resolveStmt(stmt, arkMethod);
228
+ }
229
+ }
230
+ signatures.forEach(s => this.inferSignatureReturnType(s, arkMethod));
231
+ }
232
+ /**
233
+ * Parse statement and process various references and expressions within it
234
+ * @param stmt Statement object to be parsed
235
+ * @param arkMethod Current Ark method context
236
+ */
237
+ static resolveStmt(stmt, arkMethod) {
238
+ try {
239
+ this.resolveTypeExprsInStmt(stmt, arkMethod);
240
+ this.resolveExprsInStmt(stmt, arkMethod);
241
+ this.resolveFieldRefsInStmt(stmt, arkMethod);
242
+ this.resolveArkAssignStmt(stmt, arkMethod);
243
+ this.resolveArkReturnStmt(stmt, arkMethod);
244
+ }
245
+ catch (e) {
246
+ logger.warn('stmt is not correct: ' + stmt.toString());
247
+ }
248
+ }
249
+ /**
250
+ * @Deprecated
251
+ * @param arkMethod
252
+ */
253
+ static inferSimpleTypeInMethod(arkMethod) {
254
+ const body = arkMethod.getBody();
255
+ if (!body) {
256
+ logger.warn('empty body');
257
+ return;
258
+ }
259
+ const cfg = body.getCfg();
260
+ for (const block of cfg.getBlocks()) {
261
+ for (const stmt of block.getStmts()) {
262
+ TypeInference.inferSimpleTypeInStmt(stmt);
263
+ }
264
+ }
265
+ }
266
+ /**
267
+ * infer type for Exprs in stmt which invoke method.
268
+ * such as ArkInstanceInvokeExpr ArkStaticInvokeExpr ArkNewExpr
269
+ */
270
+ static resolveExprsInStmt(stmt, arkMethod) {
271
+ var _a;
272
+ for (const expr of stmt.getExprs()) {
273
+ const newExpr = expr.inferType(arkMethod);
274
+ if ((stmt.containsInvokeExpr() &&
275
+ ((expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) || newExpr instanceof Expr_1.ArkPtrInvokeExpr)) ||
276
+ (newExpr instanceof Expr_1.ArkInstanceInvokeExpr && Builtin_2.BuiltinCxx.isBuiltinClass(newExpr.getMethodSignature().getDeclaringClassSignature()))) {
277
+ stmt.replaceUse(expr, newExpr);
278
+ }
279
+ // After infer the invoke method, it should replace the super.foo() to this.foo() while the foo is with super class as declaring class.
280
+ if (newExpr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr.getBase().getName() === TSConst_1.SUPER_NAME) {
281
+ const thisLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(TSConst_1.THIS_NAME);
282
+ if (thisLocal) {
283
+ newExpr.setBase(thisLocal);
284
+ thisLocal.addUsedStmt(stmt);
285
+ }
286
+ }
287
+ }
288
+ if (stmt instanceof Stmt_1.ArkAliasTypeDefineStmt && this.isUnclearType(stmt.getAliasType().getOriginalType())) {
289
+ stmt.getAliasType().setOriginalType(stmt.getAliasTypeExpr().getType());
290
+ }
291
+ // 处理ts2cxxFuncMap
292
+ if (stmt instanceof Stmt_1.ArkInvokeStmt) {
293
+ const invokeExpr = stmt.getInvokeExpr();
294
+ if (!(invokeExpr instanceof Expr_1.ArkInstanceInvokeExpr)) {
295
+ return;
296
+ }
297
+ const instInvokeExpr = invokeExpr;
298
+ const invokeBaseType = instInvokeExpr.getBase().getType();
299
+ if (invokeBaseType instanceof Type_1.ClassType && invokeBaseType.getClassSignature().getClassName() === 'napi_property_descriptor') {
300
+ (0, ModelUtils_2.setTs2CxxFuncMapOfClass)(instInvokeExpr.getArgs(), false, stmt.getCfg().getDeclaringMethod());
301
+ }
302
+ }
303
+ }
304
+ /**
305
+ * infer value type for TypeExprs in stmt which specify the type such as TypeQueryExpr
306
+ */
307
+ static resolveTypeExprsInStmt(stmt, arkMethod) {
308
+ for (let typeExpr of stmt.getTypeExprs()) {
309
+ typeExpr.inferType(arkMethod);
310
+ }
311
+ }
312
+ /**
313
+ * infer type for fieldRefs in stmt.
314
+ */
315
+ static resolveFieldRefsInStmt(stmt, arkMethod) {
316
+ for (const use of stmt.getUses()) {
317
+ if (use instanceof Ref_1.AbstractRef) {
318
+ this.processRef(use, stmt, arkMethod);
319
+ }
320
+ }
321
+ const stmtDef = stmt.getDef();
322
+ if (stmtDef && stmtDef instanceof Ref_1.AbstractRef) {
323
+ if (arkMethod.getName() === Const_1.INSTANCE_INIT_METHOD_NAME &&
324
+ stmtDef instanceof Ref_1.ArkInstanceFieldRef &&
325
+ stmtDef.getBase().getName() === TSConst_1.THIS_NAME &&
326
+ arkMethod.getDeclaringArkClass().isAnonymousClass() &&
327
+ stmtDef.getFieldName().indexOf('.') === -1) {
328
+ return;
329
+ }
330
+ this.processRef(stmtDef, stmt, arkMethod, false);
331
+ }
332
+ }
333
+ /**
334
+ *Process field references, perform corresponding conversion processing according to the reference type and statement type,
335
+ * process static field references, process instance field references and field references as array references,
336
+ * and try to replace them with local variables when the index is a string constant
337
+ *@param use - abstract reference object, which may be a static field reference or an instance field reference
338
+ *@param stmt - statement object, used to replace references
339
+ *@param arkMethod - Ark method object, used to obtain method body information
340
+ *@param replaceUse - is new fieldRef replace use
341
+ */
342
+ static processRef(use, stmt, arkMethod, replaceUse = true) {
343
+ const fieldRef = use.inferType(arkMethod);
344
+ if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
345
+ if (replaceUse) {
346
+ stmt.replaceUse(use, fieldRef);
347
+ }
348
+ else {
349
+ stmt.replaceDef(use, fieldRef);
350
+ }
351
+ }
352
+ else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
353
+ const index = fieldRef.getIndex();
354
+ if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
355
+ const local = this.getLocalFromMethodBody(index.getValue(), arkMethod);
356
+ if (local) {
357
+ fieldRef.setIndex(local);
358
+ }
359
+ }
360
+ if (replaceUse) {
361
+ stmt.replaceUse(use, fieldRef);
362
+ }
363
+ else {
364
+ stmt.replaceDef(use, fieldRef);
365
+ }
366
+ }
367
+ }
368
+ static getLocalFromMethodBody(name, arkMethod) {
369
+ var _a, _b, _c;
370
+ const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
371
+ if (local) {
372
+ return local;
373
+ }
374
+ const globalRef = (_c = (_b = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _b === void 0 ? void 0 : _b.getUsedGlobals()) === null || _c === void 0 ? void 0 : _c.get(name);
375
+ if (globalRef === undefined || !(globalRef instanceof Ref_1.GlobalRef)) {
376
+ return null;
377
+ }
378
+ const ref = globalRef.getRef();
379
+ if (ref !== null && ref instanceof Local_1.Local) {
380
+ return ref;
381
+ }
382
+ return null;
383
+ }
384
+ /**
385
+ * Parse ArkExport object into corresponding Type
386
+ * @param arkExport - The ArkExport object to parse, may be undefined or null
387
+ * @returns The parsed Type object, or null if it cannot be parsed
388
+ */
389
+ static parseArkExport2Type(arkExport) {
390
+ if (!arkExport) {
391
+ return null;
392
+ }
393
+ if (arkExport instanceof ArkClass_1.ArkClass) {
394
+ return new Type_1.ClassType(arkExport.getSignature(), arkExport.getGenericsTypes());
395
+ }
396
+ else if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
397
+ return Type_1.AnnotationNamespaceType.getInstance(arkExport.getSignature());
398
+ }
399
+ else if (arkExport instanceof ArkMethod_1.ArkMethod) {
400
+ return new Type_1.FunctionType(arkExport.getSignature());
401
+ }
402
+ else if (arkExport instanceof Local_1.Local) {
403
+ if (arkExport.getType() instanceof Type_1.UnknownType || arkExport.getType() instanceof Type_1.UnclearReferenceType) {
404
+ return null;
405
+ }
406
+ return arkExport.getType();
407
+ }
408
+ else if (arkExport instanceof Type_1.AliasType) {
409
+ return arkExport;
410
+ }
411
+ else {
412
+ return null;
413
+ }
414
+ }
415
+ /**
416
+ * infer and pass type for ArkAssignStmt right and left
417
+ * @param stmt
418
+ * @param arkMethod
419
+ */
420
+ static resolveArkAssignStmt(stmt, arkMethod) {
421
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
422
+ return;
423
+ }
424
+ const arkClass = arkMethod.getDeclaringArkClass();
425
+ const rightOp = stmt.getRightOp();
426
+ // infer not only UnknowType but also other unclear types
427
+ if (rightOp instanceof Local_1.Local && this.isUnclearType(rightOp.getType())) {
428
+ IRInference_1.IRInference.inferLocal(rightOp, arkMethod);
429
+ }
430
+ let rightType = rightOp.getType();
431
+ let baseType;
432
+ if (rightType instanceof Type_2.PointerType || rightType instanceof Type_2.ReferenceType) {
433
+ baseType = rightType.getBaseType();
434
+ if (this.isUnclearType(baseType)) {
435
+ baseType = this.inferUnclearedType(baseType, arkClass);
436
+ if (baseType) {
437
+ rightType.setBaseType(baseType);
438
+ }
439
+ }
440
+ }
441
+ if (this.isUnclearType(rightType)) {
442
+ rightType = this.inferUnclearedType(rightType, arkClass);
443
+ if (rightType) {
444
+ this.setValueType(rightOp, rightType);
445
+ }
446
+ }
447
+ TypeInference.resolveLeftOp(stmt, arkClass, rightType, arkMethod);
448
+ }
449
+ /**
450
+ * Resolve type inference and setting for the left operand of an assignment statement
451
+ *
452
+ * @param stmt Assignment statement node
453
+ * @param arkClass The current Ark class
454
+ * @param rightType Type of the right-hand expression in the assignment
455
+ * @param arkMethod The current Ark method
456
+ */
457
+ static resolveLeftOp(stmt, arkClass, rightType, arkMethod) {
458
+ var _a;
459
+ let leftType = this.inferLeftOpType(stmt, arkClass, rightType, arkMethod);
460
+ const leftOp = stmt.getLeftOp();
461
+ if (leftType && !this.isUnclearType(leftType)) {
462
+ this.setValueType(leftOp, leftType);
463
+ if (leftOp instanceof Local_1.Local && ((_a = stmt.getOriginalText()) === null || _a === void 0 ? void 0 : _a.startsWith(leftOp.getName()))) {
464
+ let localDef = ModelUtils_1.ModelUtils.findDeclaredLocal(leftOp, arkMethod);
465
+ if (localDef && this.isUnclearType(localDef.getType())) {
466
+ localDef.setType(leftType);
467
+ }
468
+ }
469
+ if (rightType) {
470
+ IRInference_1.IRInference.inferRightWithSdkType(leftType, rightType, arkClass);
471
+ }
472
+ if (leftOp instanceof Ref_1.AbstractFieldRef) {
473
+ const declaringSignature = leftOp.getFieldSignature().getDeclaringSignature();
474
+ if (declaringSignature instanceof ArkSignature_1.NamespaceSignature && declaringSignature.getNamespaceName() === TSConst_1.GLOBAL_THIS_NAME) {
475
+ SdkUtils_1.SdkUtils.computeGlobalThis(leftOp, arkMethod);
476
+ }
477
+ }
478
+ }
479
+ }
480
+ /**
481
+ * Infer the type of the left operand in an assignment statement
482
+ *
483
+ * @param arkClass Current class object
484
+ * @param rightType The type on the right side of the assignment statement
485
+ * @param leftOp The operand on the left side of the assignment
486
+ * @param arkMethod Current method object
487
+ * @param stmt Assignment statement object
488
+ * @returns The inferred left type, or null/undefined if it cannot be inferred
489
+ */
490
+ static inferLeftOpType(stmt, arkClass, rightType, arkMethod) {
491
+ const leftOp = stmt.getLeftOp();
492
+ let leftType = leftOp.getType();
493
+ let baseType = leftType;
494
+ // If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
495
+ if (leftType instanceof Type_2.PointerType || leftType instanceof Type_2.ReferenceType) {
496
+ baseType = leftType.getBaseType();
497
+ }
498
+ if (this.isUnclearType(baseType)) {
499
+ const newLeftType = this.inferUnclearedType(baseType, arkClass);
500
+ if (!newLeftType && !this.isUnclearType(rightType)) {
501
+ leftType = rightType;
502
+ }
503
+ else if (newLeftType) {
504
+ if (leftType instanceof Type_2.PointerType || leftType instanceof Type_2.ReferenceType) {
505
+ leftType.setBaseType(newLeftType);
506
+ }
507
+ else {
508
+ leftType = newLeftType;
509
+ }
510
+ }
511
+ }
512
+ else if (leftOp instanceof Local_1.Local && leftOp.getName() === TSConst_1.THIS_NAME) {
513
+ const thisLocal = IRInference_1.IRInference.inferThisLocal(arkMethod);
514
+ if (thisLocal) {
515
+ stmt.setLeftOp(thisLocal);
516
+ }
517
+ else {
518
+ leftType = rightType;
519
+ }
520
+ }
521
+ else if (baseType instanceof Type_1.FunctionType && !this.isUnclearType(rightType) &&
522
+ baseType.getMethodSignature().getMethodSubSignature().getMethodName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX)) {
523
+ leftType = rightType;
524
+ }
525
+ return leftType || null;
526
+ }
527
+ /**
528
+ * Set the type of value
529
+ *
530
+ * @param value The value object whose type needs to be set
531
+ * @param type The type to be set
532
+ */
533
+ static setValueType(value, type) {
534
+ if (value instanceof Local_1.Local || value instanceof Ref_1.ArkParameterRef) {
535
+ value.setType(type);
536
+ }
537
+ else if (value instanceof Ref_1.AbstractFieldRef) {
538
+ value.getFieldSignature().setType(type);
539
+ }
540
+ else if (value instanceof Expr_1.ArkNewExpr && type instanceof Type_1.AliasType && type.getOriginalType() instanceof Type_1.ClassType) {
541
+ value.getClassType().setClassSignature(type.getOriginalType().getClassSignature());
542
+ }
543
+ }
544
+ /**
545
+ * Determine if the given type is an unclear type
546
+ * @param type The type to check, which can be null or undefined
547
+ * @returns true if the type is unclear, otherwise false
548
+ */
549
+ static isUnclearType(type) {
550
+ var _a;
551
+ // TODO: For UnionType, IntersectionType and TupleType, it should recurse check every item of them.
552
+ if (!type ||
553
+ type instanceof Type_1.UnknownType ||
554
+ type instanceof Type_1.UnclearReferenceType ||
555
+ type instanceof Type_1.NullType ||
556
+ type instanceof Type_1.UndefinedType ||
557
+ type instanceof Type_1.GenericType) {
558
+ return true;
559
+ }
560
+ else if (type instanceof Type_1.ClassType &&
561
+ (type.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME ||
562
+ (type.getClassSignature().getClassName() === TSConst_1.PROMISE && !type.getRealGenericTypes()) ||
563
+ (type.getClassSignature().getDeclaringFileSignature().getFileName() === Builtin_1.Builtin.DUMMY_FILE_NAME &&
564
+ ((_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => t instanceof Type_1.GenericType))))) {
565
+ return true;
566
+ }
567
+ else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
568
+ return !!type.getTypes().find(t => this.checkType(t, e => e instanceof Type_1.UnclearReferenceType || e instanceof Type_1.GenericType));
569
+ }
570
+ else if (type instanceof Type_1.ArrayType) {
571
+ const baseType = type.getBaseType();
572
+ return this.checkType(baseType, t => t instanceof Type_1.UnclearReferenceType || baseType instanceof Type_1.GenericType);
573
+ }
574
+ else if (type instanceof Type_1.AliasType) {
575
+ return this.isUnclearType(type.getOriginalType());
576
+ }
577
+ else if (type instanceof TypeExpr_1.KeyofTypeExpr) {
578
+ return this.isUnclearType(type.getOpType());
579
+ }
580
+ else if (type instanceof TypeExpr_1.TypeQueryExpr) {
581
+ return this.isUnclearType(type.getType());
582
+ }
583
+ return false;
584
+ }
585
+ /**
586
+ * This is the temporal function to check Type recursively and can be removed after typeInfer supports multiple candidate types.
587
+ * @param type The type to check
588
+ * @param check Condition checking function that takes a type parameter and returns a boolean
589
+ * @param visited Set of visited types to prevent infinite recursion from circular references, defaults to empty set
590
+ * @returns true if the type meets the condition, otherwise false
591
+ */
592
+ static checkType(type, check, visited = new Set()) {
593
+ var _a;
594
+ if (visited.has(type)) {
595
+ return false;
596
+ }
597
+ else {
598
+ visited.add(type);
599
+ }
600
+ if (check(type)) {
601
+ return true;
602
+ }
603
+ else if (type instanceof Type_1.ClassType) {
604
+ return !!((_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => this.checkType(t, check, visited)));
605
+ }
606
+ else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
607
+ return !!type.getTypes().find(t => this.checkType(t, check, visited));
608
+ }
609
+ else if (type instanceof Type_1.ArrayType) {
610
+ return this.checkType(type.getBaseType(), check, visited);
611
+ }
612
+ else if (type instanceof Type_1.AliasType) {
613
+ return this.checkType(type.getOriginalType(), check, visited);
614
+ }
615
+ else if (type instanceof TypeExpr_1.KeyofTypeExpr) {
616
+ return this.checkType(type.getOpType(), check, visited);
617
+ }
618
+ else if (type instanceof TypeExpr_1.TypeQueryExpr) {
619
+ return this.checkType(type.getType(), check, visited);
620
+ }
621
+ return false;
622
+ }
623
+ /**
624
+ * Infer simple types in a statement
625
+ * @param stmt The statement to perform type inference on
626
+ */
627
+ static inferSimpleTypeInStmt(stmt) {
628
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
629
+ const leftOp = stmt.getLeftOp();
630
+ if (leftOp instanceof Local_1.Local) {
631
+ const leftOpType = leftOp.getType();
632
+ if (leftOpType instanceof Type_1.UnknownType) {
633
+ const rightOp = stmt.getRightOp();
634
+ leftOp.setType(rightOp.getType());
635
+ }
636
+ }
637
+ }
638
+ }
639
+ /**
640
+ * Build corresponding Type object based on TypeScript type string
641
+ * Deal only with simple situations
642
+ * @param tsTypeStr TypeScript type string used to identify basic types
643
+ * @param cxxTypeStr Optional C++ type string used for detailed type information of number and string types
644
+ * @returns Returns the Type instance corresponding to the input string
645
+ */
646
+ static buildTypeFromStr(tsTypeStr, cxxTypeStr) {
647
+ switch (tsTypeStr) {
648
+ case 'boolean':
649
+ return Type_1.BooleanType.getInstance();
650
+ case 'number':
651
+ return this.buildTypeFromCxxNumberStr(cxxTypeStr);
652
+ case 'string':
653
+ return this.buildTypeFromCxxStringStr(cxxTypeStr);
654
+ case 'undefined':
655
+ return Type_1.UndefinedType.getInstance();
656
+ case 'null':
657
+ return Type_1.NullType.getInstance();
658
+ case 'any':
659
+ return Type_1.AnyType.getInstance();
660
+ case 'void':
661
+ return Type_1.VoidType.getInstance();
662
+ case 'never':
663
+ return Type_1.NeverType.getInstance();
664
+ case 'RegularExpression': {
665
+ const classSignature = Builtin_1.Builtin.REGEXP_CLASS_SIGNATURE;
666
+ return new Type_1.ClassType(classSignature);
667
+ }
668
+ case 'type_info':
669
+ return new Type_2.TypeInfo('type_info', new Type_1.UnclearReferenceType(tsTypeStr));
670
+ case 'auto':
671
+ return Type_2.AutoType.getInstance();
672
+ default:
673
+ return new Type_1.UnclearReferenceType(tsTypeStr);
674
+ }
675
+ }
676
+ static buildTypeFromCxxNumberStr(cxxTypeStr) {
677
+ if (!cxxTypeStr) {
678
+ return Type_1.NumberType.getInstance();
679
+ }
680
+ cxxTypeStr = cxxTypeStr.replace(Builtin_2.BuiltinCxx.CXXSTDREF, '');
681
+ switch (cxxTypeStr) {
682
+ case 'short':
683
+ return Type_2.CxxShortType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.SIXTEEN_BITS, Type_2.CxxStdTypeName.SHORT);
684
+ case 'unsigned short':
685
+ return Type_2.CxxShortType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.SIXTEEN_BITS, Type_2.CxxStdTypeName.UNSIGNED_SHORT);
686
+ case 'int':
687
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.INT);
688
+ case 'unsigned int':
689
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.UNSIGNED_INT);
690
+ case 'int8_t':
691
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.INT8_T);
692
+ case 'uint8_t':
693
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.UINT8_T);
694
+ case 'int16_t':
695
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.SIXTEEN_BITS, Type_2.CxxStdTypeName.INT16_T);
696
+ case 'uint16_t':
697
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.SIXTEEN_BITS, Type_2.CxxStdTypeName.UINT16_T);
698
+ case 'int32_t':
699
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.INT32_T);
700
+ case 'uint32_t':
701
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.UINT32_T);
702
+ case 'int64_t':
703
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.SIXTY_FOUR_BITS, Type_2.CxxStdTypeName.INT64_T);
704
+ case 'uint64_t':
705
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.SIXTY_FOUR_BITS, Type_2.CxxStdTypeName.UINT64_T);
706
+ case 'intptr_t':
707
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.UNKNOWN, Type_2.CxxStdTypeName.INTPTR_T);
708
+ case 'uintptr_t':
709
+ return Type_2.CxxIntType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.UNKNOWN, Type_2.CxxStdTypeName.UINTPTR_T);
710
+ case 'size_t':
711
+ return Type_2.CxxSizeTType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.UNKNOWN, Type_2.CxxStdTypeName.SIZE_T);
712
+ case 'long':
713
+ return Type_2.CxxLongType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.LONG);
714
+ case 'unsigned long':
715
+ return Type_2.CxxLongType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.UNSIGNED_LONG);
716
+ case 'long long':
717
+ return Type_2.CxxLongLongType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.SIXTY_FOUR_BITS, Type_2.CxxStdTypeName.LONG_LONG);
718
+ case 'unsigned long long':
719
+ return Type_2.CxxLongLongType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.SIXTY_FOUR_BITS, Type_2.CxxStdTypeName.UNSIGNED_LONG_LONG);
720
+ case 'float':
721
+ return Type_2.CxxFloatType.getInstance();
722
+ case 'double':
723
+ return Type_2.CxxDoubleType.getInstance();
724
+ case 'long double':
725
+ return Type_2.CxxLongDoubleType.getInstance();
726
+ default:
727
+ return new Type_1.UnclearReferenceType(cxxTypeStr);
728
+ }
729
+ }
730
+ static buildTypeFromCxxStringStr(cxxTypeStr) {
731
+ if (!cxxTypeStr) {
732
+ return Type_1.StringType.getInstance();
733
+ }
734
+ switch (cxxTypeStr) {
735
+ case 'string':
736
+ case 'std::string':
737
+ case 'std::basic_string<char>':
738
+ return Type_1.StringType.getInstance();
739
+ case 'char':
740
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNKNOWN, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.CHAR);
741
+ case 'signed char':
742
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.SIGNED, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.SIGNED_CHAR);
743
+ case 'unsigned char':
744
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.UNSIGNED_CHAR);
745
+ case 'unsignedchar':
746
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.UNSIGNED_CHAR);
747
+ case 'char16_t':
748
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.SIXTEEN_BITS, Type_2.CxxStdTypeName.CHAR16_T);
749
+ case 'char32_t':
750
+ return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNSIGNED, Type_2.CxxTypeBitWidth.THIRTY_TWO_BITS, Type_2.CxxStdTypeName.CHAR32_T);
751
+ case 'wchar_t':
752
+ return Type_2.CxxWcharType.getInstance(Type_2.CxxTypeSigned.UNKNOWN, Type_2.CxxTypeBitWidth.UNKNOWN, Type_2.CxxStdTypeName.WCHAR_T);
753
+ default:
754
+ return new Type_1.UnclearReferenceType(cxxTypeStr);
755
+ }
756
+ }
757
+ /**
758
+ * Infer the type of value
759
+ * @param value The value whose type needs to be inferred
760
+ * @param arkMethod The current method context
761
+ * @returns The inferred type, or null if it cannot be inferred
762
+ */
763
+ static inferValueType(value, arkMethod) {
764
+ if (value instanceof Ref_1.ArkInstanceFieldRef || value instanceof Expr_1.ArkInstanceInvokeExpr) {
765
+ this.inferValueType(value.getBase(), arkMethod);
766
+ }
767
+ if (value instanceof Ref_1.AbstractRef || value instanceof Expr_1.AbstractExpr || value instanceof Local_1.Local) {
768
+ value.inferType(arkMethod);
769
+ // If the type of value is functionType and the current file is a CXX file,
770
+ // it should be represented as a CXX function pointer type ==> PointerType(FunctionType, 1).
771
+ const valueType = value.getType();
772
+ if (arkMethod.getLanguage() === ArkFile_1.Language.CXX && valueType instanceof Type_1.FunctionType) {
773
+ if (value instanceof Ref_1.ArkParameterRef || value instanceof Local_1.Local) {
774
+ value.setType(new Type_2.PointerType(valueType, 1));
775
+ }
776
+ }
777
+ }
778
+ return value.getType();
779
+ }
780
+ /**
781
+ * Infer the type of method parameters and update the parameter's type information.
782
+ *
783
+ * @param param - The parameter object whose type needs to be inferred
784
+ * @param arkMethod - The method object that the parameter belongs to
785
+ */
786
+ static inferParameterType(param, arkMethod) {
787
+ let pType = param.getType();
788
+ const arkClass = arkMethod.getDeclaringArkClass();
789
+ let type;
790
+ if (pType instanceof TypeExpr_1.AbstractTypeExpr) {
791
+ pType.inferType(arkMethod);
792
+ }
793
+ else if (param.getName() === 'value' && arkClass.hasComponentDecorator() && arkMethod.getName() === TSConst_1.CONSTRUCTOR_NAME) {
794
+ type = this.parseArkExport2Type(arkClass);
795
+ }
796
+ else {
797
+ type = TypeInference.inferUnclearedType(pType, arkClass);
798
+ }
799
+ if (type) {
800
+ param.setType(type);
801
+ }
802
+ }
803
+ /**
804
+ * Infer the return type of method signature and update the return type information in the signature.
805
+ *
806
+ * @param oldSignature - The method signature object whose return type needs to be inferred
807
+ * @param arkMethod - The method object that corresponds to the signature
808
+ */
809
+ static inferSignatureReturnType(oldSignature, arkMethod) {
810
+ if (oldSignature.getMethodSubSignature().getMethodName() === TSConst_1.CONSTRUCTOR_NAME) {
811
+ const newReturnType = new Type_1.ClassType(oldSignature.getDeclaringClassSignature());
812
+ oldSignature.getMethodSubSignature().setReturnType(newReturnType);
813
+ return;
814
+ }
815
+ const currReturnType = oldSignature.getType();
816
+ let retTypeWithoutPtrOrRef = currReturnType;
817
+ // If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
818
+ if (retTypeWithoutPtrOrRef instanceof Type_2.PointerType || retTypeWithoutPtrOrRef instanceof Type_2.ReferenceType) {
819
+ retTypeWithoutPtrOrRef = retTypeWithoutPtrOrRef.getBaseType();
820
+ }
821
+ if (!this.isUnclearType(retTypeWithoutPtrOrRef)) {
822
+ return;
823
+ }
824
+ if (currReturnType instanceof TypeExpr_1.AbstractTypeExpr) {
825
+ currReturnType.inferType(arkMethod);
826
+ return;
827
+ }
828
+ if (currReturnType instanceof Type_1.ArrayType && currReturnType.getBaseType() instanceof TypeExpr_1.AbstractTypeExpr) {
829
+ currReturnType.getBaseType().inferType(arkMethod);
830
+ return;
831
+ }
832
+ let newReturnType = this.inferUnclearedType(retTypeWithoutPtrOrRef, arkMethod.getDeclaringArkClass());
833
+ if (newReturnType && (currReturnType instanceof Type_2.PointerType || currReturnType instanceof Type_2.ReferenceType)) {
834
+ currReturnType.setBaseType(newReturnType);
835
+ newReturnType = currReturnType;
836
+ }
837
+ if (newReturnType) {
838
+ oldSignature.getMethodSubSignature().setReturnType(newReturnType);
839
+ }
840
+ else if (arkMethod.getBody()) {
841
+ const returnType = TypeInference.inferReturnType(arkMethod);
842
+ if (returnType) {
843
+ oldSignature.getMethodSubSignature().setReturnType(returnType);
844
+ }
845
+ }
846
+ }
847
+ /**
848
+ * Infer the return type of method and update the return type information in the method.
849
+ *
850
+ * @param arkMethod - The method object whose return type needs to be inferred
851
+ */
852
+ static inferReturnType(arkMethod) {
853
+ const typeMap = new Map();
854
+ for (let returnValue of arkMethod.getReturnValues()) {
855
+ const type = returnValue.getType();
856
+ if (type instanceof Type_1.UnionType) {
857
+ type.flatType()
858
+ .filter(t => !TypeInference.isUnclearType(t))
859
+ .forEach(t => typeMap.set(t.toString(), t));
860
+ }
861
+ else if (type instanceof Type_2.PointerType || type instanceof Type_2.ReferenceType) {
862
+ if (!TypeInference.isUnclearType(type.getBaseType())) {
863
+ typeMap.set(type.toString(), type);
864
+ }
865
+ }
866
+ else if (!TypeInference.isUnclearType(type)) {
867
+ typeMap.set(type.toString(), type);
868
+ }
869
+ }
870
+ if (typeMap.size > 0) {
871
+ const types = Array.from(typeMap.values());
872
+ let returnType = types.length === 1 ? types[0] : new Type_1.UnionType(types);
873
+ if (arkMethod.containsModifier(ArkBaseModel_1.ModifierType.ASYNC)) {
874
+ const promise = arkMethod.getDeclaringArkFile().getScene().getSdkGlobal(TSConst_1.PROMISE);
875
+ if (promise instanceof ArkClass_1.ArkClass) {
876
+ returnType = new Type_1.ClassType(promise.getSignature(), [returnType]);
877
+ }
878
+ }
879
+ return returnType;
880
+ }
881
+ return null;
882
+ }
883
+ /**
884
+ * Infer the type of generic type and update the generic type information.
885
+ *
886
+ * @param types - The generic type array that needs to be inferred
887
+ * @param arkClass - The class object that the generic type belongs to
888
+ */
889
+ static inferGenericType(types, arkClass) {
890
+ types === null || types === void 0 ? void 0 : types.forEach(type => {
891
+ const defaultType = type.getDefaultType();
892
+ if (defaultType && this.isUnclearType(defaultType)) {
893
+ const newDefaultType = TypeInference.inferUnclearedType(defaultType, arkClass);
894
+ if (newDefaultType) {
895
+ type.setDefaultType(this.replaceTypeWithReal(newDefaultType));
896
+ }
897
+ }
898
+ const constraint = type.getConstraint();
899
+ if (constraint && this.isUnclearType(constraint)) {
900
+ const newConstraint = TypeInference.inferUnclearedType(constraint, arkClass);
901
+ if (newConstraint) {
902
+ type.setConstraint(this.replaceTypeWithReal(newConstraint));
903
+ }
904
+ }
905
+ });
906
+ }
907
+ /**
908
+ * Infer type for a given {@link UnclearReferenceType} type.
909
+ * It returns original type.
910
+ * The original type is null if it failed to infer the type.
911
+ * @param urType
912
+ * @param arkClass
913
+ * @returns
914
+ */
915
+ static inferUnclearRefType(urType, arkClass) {
916
+ var _a;
917
+ const realTypes = urType.getGenericTypes();
918
+ this.inferRealGenericTypes(realTypes, arkClass);
919
+ if (urType.getName() === Builtin_1.Builtin.ARRAY) {
920
+ return new Type_1.ArrayType((_a = realTypes[0]) !== null && _a !== void 0 ? _a : Type_1.AnyType.getInstance(), 1);
921
+ }
922
+ const type = this.inferUnclearRefName(urType.getName(), arkClass);
923
+ return type ? this.replaceTypeWithReal(type, realTypes) : null;
924
+ }
925
+ /**
926
+ * Find out the original object and type for a given unclear reference type name.
927
+ * It returns original type.
928
+ * The original type is null if it failed to infer the type.
929
+ * @param refName
930
+ * @param arkClass
931
+ * @returns
932
+ */
933
+ static inferUnclearRefName(refName, arkClass) {
934
+ var _a;
935
+ if (!refName) {
936
+ return null;
937
+ }
938
+ //split and iterate to infer each type
939
+ const singleNames = refName.split(/\.|::|->/);
940
+ let type = null;
941
+ for (let i = 0; i < singleNames.length; i++) {
942
+ let genericName = ValueUtil_1.EMPTY_STRING;
943
+ const name = singleNames[i].replace(/<(\w+)>/, (match, group1) => {
944
+ genericName = group1;
945
+ return ValueUtil_1.EMPTY_STRING;
946
+ });
947
+ if (i === 0) {
948
+ type = singleNames.length > 1 ? this.inferBaseType(name, arkClass) : this.inferTypeByName(name, arkClass);
949
+ }
950
+ else if (type) {
951
+ type = (_a = this.inferFieldType(type, name, arkClass)) === null || _a === void 0 ? void 0 : _a[1];
952
+ }
953
+ if (!type) {
954
+ return null;
955
+ }
956
+ if (genericName) {
957
+ const realTypes = genericName.split(',').map(generic => {
958
+ const realType = this.inferUnclearRefName(generic, arkClass);
959
+ return realType !== null && realType !== void 0 ? realType : new Type_1.UnclearReferenceType(generic);
960
+ });
961
+ if (type instanceof Type_1.ClassType) {
962
+ type = new Type_1.ClassType(type.getClassSignature(), realTypes);
963
+ }
964
+ else if (type instanceof Type_1.FunctionType) {
965
+ type = new Type_1.FunctionType(type.getMethodSignature(), realTypes);
966
+ }
967
+ }
968
+ }
969
+ return type;
970
+ }
971
+ /**
972
+ *Inferred field type
973
+ *@ param baseType Base Type
974
+ *@ param fieldName
975
+ *@ param declareClass Declare the class
976
+ *@ returns a tuple of attributes and types. If the inference fails, null is returned
977
+ */
978
+ static inferFieldType(baseType, fieldName, declareClass) {
979
+ var _a;
980
+ if (baseType instanceof Type_1.AliasType) {
981
+ baseType = baseType.getOriginalType();
982
+ }
983
+ else if (baseType instanceof Type_1.UnionType && baseType.getCurrType()) {
984
+ baseType = baseType.getCurrType();
985
+ }
986
+ let propertyAndType = null;
987
+ let typeWithoutPtrOrRef = baseType;
988
+ // If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
989
+ if (baseType instanceof Type_2.PointerType || baseType instanceof Type_2.ReferenceType) {
990
+ typeWithoutPtrOrRef = baseType.getBaseType();
991
+ }
992
+ if (typeWithoutPtrOrRef instanceof Type_1.ClassType) {
993
+ if (fieldName === Builtin_1.Builtin.ITERATOR_RESULT_VALUE &&
994
+ typeWithoutPtrOrRef.getClassSignature().getDeclaringFileSignature().getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
995
+ const types = typeWithoutPtrOrRef.getRealGenericTypes();
996
+ if (types && types.length > 0) {
997
+ return [null, types[0]];
998
+ }
999
+ return null;
1000
+ }
1001
+ propertyAndType =
1002
+ (_a = this.inferClassFieldType(declareClass, typeWithoutPtrOrRef, fieldName)) !== null && _a !== void 0 ? _a : this.inferNestedClassType(declareClass, typeWithoutPtrOrRef, fieldName);
1003
+ }
1004
+ else if (typeWithoutPtrOrRef instanceof Type_1.ArrayType) {
1005
+ propertyAndType = this.inferArrayFieldType(declareClass, fieldName);
1006
+ }
1007
+ else if (typeWithoutPtrOrRef instanceof Type_1.AnnotationNamespaceType) {
1008
+ const namespace = declareClass.getDeclaringArkFile().getScene().getNamespace(typeWithoutPtrOrRef.getNamespaceSignature());
1009
+ if (namespace) {
1010
+ const property = ModelUtils_2.CxxModelUtils.findPropertyInNamespace(fieldName, namespace);
1011
+ const propertyType = this.parseArkExport2Type(property);
1012
+ if (propertyType) {
1013
+ propertyAndType = [property, propertyType];
1014
+ }
1015
+ }
1016
+ }
1017
+ else {
1018
+ logger.warn('infer unclear reference type fail: ' + fieldName);
1019
+ }
1020
+ return propertyAndType;
1021
+ }
1022
+ /**
1023
+ *Infer type information of class fields
1024
+ *@ param declareClass Declare the class object
1025
+ *@ param baseType Basic class type
1026
+ *@ param fieldName
1027
+ *@ returns a tuple containing property and type information. If it cannot be inferred, it returns null
1028
+ */
1029
+ static inferClassFieldType(declareClass, baseType, fieldName) {
1030
+ const arkClass = declareClass.getDeclaringArkFile().getScene().getClass(baseType.getClassSignature());
1031
+ if (!arkClass) {
1032
+ return null;
1033
+ }
1034
+ const property = ModelUtils_2.CxxModelUtils.findPropertyInClass(fieldName, arkClass);
1035
+ let propertyType = null;
1036
+ if (property instanceof ArkField_1.ArkField) {
1037
+ if (arkClass.getCategory() === ArkClass_1.ClassCategory.ENUM) {
1038
+ propertyType = this.getEnumValueType(property);
1039
+ }
1040
+ else {
1041
+ propertyType = this.replaceTypeWithReal(property.getType(), baseType.getRealGenericTypes());
1042
+ }
1043
+ }
1044
+ else if (property) {
1045
+ propertyType = this.parseArkExport2Type(property);
1046
+ }
1047
+ if (propertyType) {
1048
+ return [property, propertyType];
1049
+ }
1050
+ else if (arkClass.isAnonymousClass()) {
1051
+ const fieldType = this.inferUnclearRefName(fieldName, arkClass);
1052
+ return fieldType ? [null, fieldType] : null;
1053
+ }
1054
+ return null;
1055
+ }
1056
+ static getEnumValueType(property) {
1057
+ if (property.getCategory() !== ArkField_1.FieldCategory.ENUM_MEMBER) {
1058
+ return null;
1059
+ }
1060
+ const type = property.getType();
1061
+ if (type instanceof Type_1.EnumValueType) {
1062
+ return type;
1063
+ }
1064
+ const initStmts = property.getInitializer();
1065
+ const lastStmt = initStmts[initStmts.length - 1];
1066
+ let constant;
1067
+ if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
1068
+ const rightOp = lastStmt.getRightOp();
1069
+ constant = rightOp instanceof Constant_1.Constant ? rightOp : new Constant_1.Constant('unknown', rightOp.getType());
1070
+ }
1071
+ const enumValueType = new Type_1.EnumValueType(property.getSignature(), constant);
1072
+ property.getSignature().setType(enumValueType);
1073
+ return enumValueType;
1074
+ }
1075
+ static inferArrayFieldType(declareClass, fieldName) {
1076
+ const arrayClass = declareClass.getDeclaringArkFile().getScene().getSdkGlobal(Builtin_1.Builtin.ARRAY);
1077
+ if (arrayClass instanceof ArkClass_1.ArkClass) {
1078
+ const property = ModelUtils_2.CxxModelUtils.findPropertyInClass(fieldName, arrayClass);
1079
+ if (property instanceof ArkField_1.ArkField) {
1080
+ return [property, property.getType()];
1081
+ }
1082
+ return null;
1083
+ }
1084
+ return null;
1085
+ }
1086
+ /**
1087
+ *Infer Base Type
1088
+ *@ param baseName
1089
+ *@ param arkClass Ark class object
1090
+ *@ returns the inferred type. If it cannot be inferred, it returns null
1091
+ */
1092
+ static inferBaseType(baseName, arkClass) {
1093
+ var _a, _b;
1094
+ if (TSConst_1.SUPER_NAME === baseName) {
1095
+ return this.parseArkExport2Type(arkClass.getSuperClass());
1096
+ }
1097
+ else if (TSConst_1.DEFAULT === baseName) {
1098
+ return this.parseArkExport2Type((_a = arkClass.getDeclaringArkFile().getExportInfoBy(TSConst_1.DEFAULT)) === null || _a === void 0 ? void 0 : _a.getArkExport());
1099
+ }
1100
+ let arkExport = (_b = ModelUtils_2.CxxModelUtils.findSymbolInFileWithName(baseName, arkClass)) !== null && _b !== void 0 ? _b : ModelUtils_2.CxxModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile(), arkClass);
1101
+ if (!arkExport && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
1102
+ arkExport = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(baseName);
1103
+ }
1104
+ return this.parseArkExport2Type(arkExport);
1105
+ }
1106
+ /**
1107
+ *Infer type information based on type name
1108
+ *@ param typeName - the type name to infer
1109
+ *@ param arkClass - the current Ark class object
1110
+ *@ returns The type object inferred. If it cannot be inferred, null is returned
1111
+ */
1112
+ static inferTypeByName(typeName, arkClass) {
1113
+ var _a, _b;
1114
+ //look up from declared file, if not found then from imports
1115
+ const declaredArkFile = arkClass.getDeclaringArkFile();
1116
+ let arkExport = (_a = ModelUtils_2.CxxModelUtils.findSymbolInFileWithName(typeName, arkClass, true)) !== null && _a !== void 0 ? _a : ModelUtils_2.CxxModelUtils.getArkExportInImportInfoWithName(typeName, declaredArkFile, arkClass);
1117
+ //if not found or local in built-in then look up global in sdks
1118
+ if ((!arkExport || (arkExport instanceof Local_1.Local && declaredArkFile.getProjectName() === SdkUtils_1.SdkUtils.BUILT_IN_NAME)) &&
1119
+ !declaredArkFile.getImportInfoBy(typeName)) {
1120
+ const globalVal = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(typeName);
1121
+ if (globalVal) {
1122
+ arkExport = globalVal;
1123
+ }
1124
+ }
1125
+ const type = this.parseArkExport2Type(arkExport);
1126
+ if (type instanceof Type_1.ClassType || type instanceof Type_1.AliasType) {
1127
+ return type;
1128
+ }
1129
+ return ((_b = arkClass.getGenericsTypes()) === null || _b === void 0 ? void 0 : _b.find(g => g.getName() === typeName)) || null;
1130
+ }
1131
+ /**
1132
+ * Infer real generic types
1133
+ *
1134
+ * This function iterates through the passed type array, infers unclear types,
1135
+ * and replaces the unclear types in the original array with the inferred concrete types.
1136
+ *
1137
+ * @param realTypes - Type array that may contain unclear types, returns directly if undefined
1138
+ * @param arkClass - ArkClass object used for type inference
1139
+ */
1140
+ static inferRealGenericTypes(realTypes, arkClass) {
1141
+ if (!realTypes) {
1142
+ return;
1143
+ }
1144
+ for (let i = 0; i < realTypes.length; i++) {
1145
+ const mayType = realTypes[i];
1146
+ if (this.isUnclearType(mayType)) {
1147
+ const newType = this.inferUnclearedType(mayType, arkClass);
1148
+ if (newType) {
1149
+ realTypes[i] = newType;
1150
+ }
1151
+ }
1152
+ }
1153
+ }
1154
+ /**
1155
+ *Infer type information of dynamic import
1156
+ *@ param from - import source path
1157
+ *@ param arkClass - Ark class information
1158
+ *@ returns The type information obtained by parsing. If it cannot be parsed, null is returned
1159
+ */
1160
+ static inferDynamicImportType(from, arkClass) {
1161
+ var _a;
1162
+ const importInfo = new ArkImport_1.ImportInfo();
1163
+ importInfo.setNameBeforeAs(TSConst_1.ALL);
1164
+ importInfo.setImportClauseName(TSConst_1.ALL);
1165
+ importInfo.setImportFrom(from);
1166
+ importInfo.setDeclaringArkFile(arkClass.getDeclaringArkFile());
1167
+ return TypeInference.parseArkExport2Type((_a = importInfo.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport());
1168
+ }
1169
+ /**
1170
+ *Replace generic parameters in type with actual types
1171
+ *@ param type - the original type to be replaced
1172
+ *@ param realTypes - array of actual types, used to replace generic parameters
1173
+ *@ param visited - the accessed type collection, used to prevent circular references
1174
+ *@ returns The actual type after replacement
1175
+ */
1176
+ static replaceTypeWithReal(type, realTypes, visited = new Set()) {
1177
+ var _a, _b;
1178
+ if (visited.has(type)) {
1179
+ return type;
1180
+ }
1181
+ else {
1182
+ visited.add(type);
1183
+ }
1184
+ if (type instanceof Type_1.GenericType) {
1185
+ const realType = (_b = (_a = realTypes === null || realTypes === void 0 ? void 0 : realTypes[type.getIndex()]) !== null && _a !== void 0 ? _a : type.getDefaultType()) !== null && _b !== void 0 ? _b : type.getConstraint();
1186
+ return realType !== null && realType !== void 0 ? realType : type;
1187
+ }
1188
+ else if (type instanceof Type_1.AnyType) {
1189
+ const realType = realTypes === null || realTypes === void 0 ? void 0 : realTypes[0];
1190
+ return realType !== null && realType !== void 0 ? realType : type;
1191
+ }
1192
+ return this.replaceRecursiveType(type, visited, realTypes);
1193
+ }
1194
+ /**
1195
+ * Recursively replace generic parameters in types with actual types.
1196
+ *
1197
+ * @param type The original type to process
1198
+ * @param visited Set of visited types to prevent infinite recursion
1199
+ * @param realTypes List of actual types used to replace generic parameters
1200
+ * @returns The replaced type
1201
+ */
1202
+ static replaceRecursiveType(type, visited, realTypes) {
1203
+ var _a, _b, _c, _d, _e, _f;
1204
+ if (type instanceof Type_1.ClassType) {
1205
+ const replacedTypes = (_b = (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.map(g => this.replaceTypeWithReal(g, realTypes, visited))) !== null && _b !== void 0 ? _b : realTypes;
1206
+ return replacedTypes && replacedTypes.length > 0 ? new Type_1.ClassType(type.getClassSignature(), replacedTypes) : type;
1207
+ }
1208
+ else if (type instanceof Type_1.FunctionType) {
1209
+ const replacedTypes = (_d = (_c = type.getRealGenericTypes()) === null || _c === void 0 ? void 0 : _c.map(g => this.replaceTypeWithReal(g, realTypes, visited))) !== null && _d !== void 0 ? _d : realTypes;
1210
+ return replacedTypes && replacedTypes.length > 0 ? new Type_1.FunctionType(type.getMethodSignature(), replacedTypes) : type;
1211
+ }
1212
+ else if (type instanceof Type_1.AliasType && realTypes) {
1213
+ const newObjectType = this.replaceTypeWithReal(type.getOriginalType(), realTypes, visited);
1214
+ const replacedTypes = (_f = (_e = type.getRealGenericTypes()) === null || _e === void 0 ? void 0 : _e.map(g => this.replaceTypeWithReal(g, realTypes, visited))) !== null && _f !== void 0 ? _f : realTypes;
1215
+ if (replacedTypes.length > 0) {
1216
+ const newAliasType = new Type_1.AliasType(type.getName(), newObjectType, type.getSignature(), type.getGenericTypes());
1217
+ newAliasType.setRealGenericTypes(replacedTypes);
1218
+ return newAliasType;
1219
+ }
1220
+ }
1221
+ else if (type instanceof Type_1.UnionType && realTypes) {
1222
+ const types = [];
1223
+ type.flatType().forEach(t => types.push(this.replaceTypeWithReal(t, realTypes, visited)));
1224
+ return new Type_1.UnionType(types, this.replaceTypeWithReal(type.getCurrType(), realTypes, visited));
1225
+ }
1226
+ else if (type instanceof Type_1.IntersectionType && realTypes) {
1227
+ const types = [];
1228
+ type.getTypes().forEach(t => types.push(this.replaceTypeWithReal(t, realTypes, visited)));
1229
+ return new Type_1.IntersectionType(types);
1230
+ }
1231
+ else if (type instanceof Type_1.ArrayType && realTypes) {
1232
+ const replacedBaseType = this.replaceTypeWithReal(type.getBaseType(), realTypes, visited);
1233
+ return new Type_1.ArrayType(replacedBaseType, type.getDimension());
1234
+ }
1235
+ else if (type instanceof Type_1.TupleType && realTypes) {
1236
+ let replacedTypes = [];
1237
+ type.getTypes().forEach(t => replacedTypes.push(this.replaceTypeWithReal(t, realTypes, visited)));
1238
+ return new Type_1.TupleType(replacedTypes);
1239
+ }
1240
+ return type;
1241
+ }
1242
+ /**
1243
+ * Replace alias types with their original types
1244
+ *
1245
+ * This function recursively resolves alias types by following the chain of type aliases
1246
+ * until it reaches the original underlying type. If the input type is an alias type,
1247
+ * it will trace through to the non-alias type.
1248
+ *
1249
+ * @param type - The type to be replaced, which may be an alias type
1250
+ * @returns Returns the resolved original type; if the input is not an alias type, it returns the original type directly
1251
+ */
1252
+ static replaceAliasType(type) {
1253
+ let aliasType = type;
1254
+ while (aliasType instanceof Type_1.AliasType) {
1255
+ aliasType = aliasType.getOriginalType();
1256
+ }
1257
+ return aliasType;
1258
+ }
1259
+ /**
1260
+ * Infer function type for generic type inference
1261
+ * @param argType Function argument type
1262
+ * @param paramSubSignature Parameter sub-signature
1263
+ * @param realTypes Array of real types
1264
+ */
1265
+ static inferFunctionType(argType, paramSubSignature, realTypes) {
1266
+ const returnType = argType.getMethodSignature().getMethodSubSignature().getReturnType();
1267
+ const declareType = paramSubSignature === null || paramSubSignature === void 0 ? void 0 : paramSubSignature.getReturnType();
1268
+ if (declareType instanceof Type_1.GenericType &&
1269
+ realTypes &&
1270
+ !realTypes[declareType.getIndex()] &&
1271
+ !this.isUnclearType(returnType) &&
1272
+ !(returnType instanceof Type_1.VoidType)) {
1273
+ realTypes[declareType.getIndex()] = returnType;
1274
+ }
1275
+ const params = paramSubSignature === null || paramSubSignature === void 0 ? void 0 : paramSubSignature.getParameters();
1276
+ if (!params) {
1277
+ return;
1278
+ }
1279
+ argType
1280
+ .getMethodSignature()
1281
+ .getMethodSubSignature()
1282
+ .getParameters()
1283
+ .filter(p => !p.getName().startsWith(Const_1.LEXICAL_ENV_NAME_PREFIX))
1284
+ .forEach((p, i) => {
1285
+ var _a;
1286
+ if (this.isUnclearType(p.getType())) {
1287
+ let type = (_a = params === null || params === void 0 ? void 0 : params[i]) === null || _a === void 0 ? void 0 : _a.getType();
1288
+ if (type instanceof Type_1.GenericType && realTypes) {
1289
+ type = realTypes === null || realTypes === void 0 ? void 0 : realTypes[type.getIndex()];
1290
+ }
1291
+ if (type) {
1292
+ p.setType(type);
1293
+ }
1294
+ }
1295
+ });
1296
+ }
1297
+ /**
1298
+ * Resolve Ark return statement, perform type inference processing
1299
+ * @param stmt The statement object that needs to be parsed
1300
+ * @param arkMethod The current Ark method
1301
+ */
1302
+ static resolveArkReturnStmt(stmt, arkMethod) {
1303
+ var _a;
1304
+ if (!(stmt instanceof Stmt_1.ArkReturnStmt)) {
1305
+ return;
1306
+ }
1307
+ this.inferValueType(stmt.getOp(), arkMethod);
1308
+ let returnType = arkMethod.getSignature().getType();
1309
+ if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getClassName() === TSConst_1.PROMISE) {
1310
+ returnType = (_a = returnType.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a[0];
1311
+ }
1312
+ if (returnType) {
1313
+ IRInference_1.IRInference.inferRightWithSdkType(returnType, stmt.getOp().getType(), arkMethod.getDeclaringArkClass());
1314
+ }
1315
+ }
1316
+ static inferMethodFromImportNamespace(baseType, expr, arkMethod, methodName) {
1317
+ var _a, _b;
1318
+ if (!(baseType instanceof Type_1.AnnotationNamespaceType)) {
1319
+ return null;
1320
+ }
1321
+ const im = arkMethod.getDeclaringArkFile().getImportInfoBy(baseType.getNamespaceSignature().getNamespaceName());
1322
+ if (!im || !(((_a = im.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport()) instanceof ArkNamespace_1.ArkNamespace)) {
1323
+ return null;
1324
+ }
1325
+ const matchedNamespace = (_b = im.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport();
1326
+ const foundMethod = ModelUtils_2.CxxModelUtils.findPropertyInNamespace(methodName, matchedNamespace);
1327
+ if (foundMethod instanceof ArkMethod_1.ArkMethod) {
1328
+ let signature = foundMethod.matchMethodSignature(expr.getArgs());
1329
+ TypeInference.inferSignatureReturnType(signature, foundMethod);
1330
+ expr.setMethodSignature(signature);
1331
+ return expr instanceof Expr_1.ArkInstanceInvokeExpr ? new Expr_1.ArkStaticInvokeExpr(signature, expr.getArgs(), expr.getRealGenericTypes()) : expr;
1332
+ }
1333
+ return null;
1334
+ }
1335
+ static inferNestedClassType(declareClass, baseType, fieldName) {
1336
+ var _a;
1337
+ const arkClass = declareClass.getDeclaringArkFile().getScene().getClass(baseType.getClassSignature());
1338
+ if (!arkClass) {
1339
+ return null;
1340
+ }
1341
+ const declScope = (_a = arkClass.getDeclaringArkNamespace()) !== null && _a !== void 0 ? _a : arkClass.getDeclaringArkFile();
1342
+ const nestedClassName = fieldName + Const_1.NAME_DELIMITER + baseType.getClassSignature().getClassName();
1343
+ const nestedClass = declScope.getClassWithName(nestedClassName);
1344
+ if (!nestedClass) {
1345
+ return null;
1346
+ }
1347
+ const type = this.parseArkExport2Type(nestedClass);
1348
+ if (type) {
1349
+ return [nestedClass, type];
1350
+ }
1351
+ return null;
1352
+ }
1353
+ }
1354
+ exports.TypeInference = TypeInference;