arkanalyzer 1.0.5

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 (322) hide show
  1. package/LICENSE +201 -0
  2. package/README.en.md +88 -0
  3. package/README.md +98 -0
  4. package/docs/HowToCreatePR.md +55 -0
  5. package/docs/HowToHandleIssues.md +155 -0
  6. package/docs/quickstart.pdf +0 -0
  7. package/lib/Config.d.ts +26 -0
  8. package/lib/Config.d.ts.map +1 -0
  9. package/lib/Config.js +128 -0
  10. package/lib/Scene.d.ts +125 -0
  11. package/lib/Scene.d.ts.map +1 -0
  12. package/lib/Scene.js +762 -0
  13. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -0
  14. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -0
  15. package/lib/callgraph/algorithm/AbstractAnalysis.js +137 -0
  16. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +11 -0
  17. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -0
  18. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +71 -0
  19. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +16 -0
  20. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -0
  21. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +147 -0
  22. package/lib/callgraph/common/Statistics.d.ts +58 -0
  23. package/lib/callgraph/common/Statistics.d.ts.map +1 -0
  24. package/lib/callgraph/common/Statistics.js +203 -0
  25. package/lib/callgraph/model/BaseGraph.d.ts +62 -0
  26. package/lib/callgraph/model/BaseGraph.d.ts.map +1 -0
  27. package/lib/callgraph/model/BaseGraph.js +158 -0
  28. package/lib/callgraph/model/CallGraph.d.ts +94 -0
  29. package/lib/callgraph/model/CallGraph.d.ts.map +1 -0
  30. package/lib/callgraph/model/CallGraph.js +339 -0
  31. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +16 -0
  32. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -0
  33. package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -0
  34. package/lib/callgraph/pointerAnalysis/Context.d.ts +38 -0
  35. package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -0
  36. package/lib/callgraph/pointerAnalysis/Context.js +156 -0
  37. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +23 -0
  38. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts.map +1 -0
  39. package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -0
  40. package/lib/callgraph/pointerAnalysis/Pag.d.ts +209 -0
  41. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -0
  42. package/lib/callgraph/pointerAnalysis/Pag.js +774 -0
  43. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +88 -0
  44. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -0
  45. package/lib/callgraph/pointerAnalysis/PagBuilder.js +821 -0
  46. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +64 -0
  47. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -0
  48. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +502 -0
  49. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +9 -0
  50. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts.map +1 -0
  51. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +57 -0
  52. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +58 -0
  53. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -0
  54. package/lib/callgraph/pointerAnalysis/PtsDS.js +234 -0
  55. package/lib/core/base/Constant.d.ts +17 -0
  56. package/lib/core/base/Constant.d.ts.map +1 -0
  57. package/lib/core/base/Constant.js +53 -0
  58. package/lib/core/base/Decorator.d.ts +15 -0
  59. package/lib/core/base/Decorator.d.ts.map +1 -0
  60. package/lib/core/base/Decorator.js +43 -0
  61. package/lib/core/base/DefUseChain.d.ts +9 -0
  62. package/lib/core/base/DefUseChain.d.ts.map +1 -0
  63. package/lib/core/base/DefUseChain.js +25 -0
  64. package/lib/core/base/Expr.d.ts +219 -0
  65. package/lib/core/base/Expr.d.ts.map +1 -0
  66. package/lib/core/base/Expr.js +896 -0
  67. package/lib/core/base/Local.d.ts +40 -0
  68. package/lib/core/base/Local.d.ts.map +1 -0
  69. package/lib/core/base/Local.js +101 -0
  70. package/lib/core/base/Position.d.ts +39 -0
  71. package/lib/core/base/Position.d.ts.map +1 -0
  72. package/lib/core/base/Position.js +86 -0
  73. package/lib/core/base/Ref.d.ts +75 -0
  74. package/lib/core/base/Ref.d.ts.map +1 -0
  75. package/lib/core/base/Ref.js +286 -0
  76. package/lib/core/base/Stmt.d.ts +109 -0
  77. package/lib/core/base/Stmt.d.ts.map +1 -0
  78. package/lib/core/base/Stmt.js +374 -0
  79. package/lib/core/base/Type.d.ts +220 -0
  80. package/lib/core/base/Type.d.ts.map +1 -0
  81. package/lib/core/base/Type.js +477 -0
  82. package/lib/core/base/Value.d.ts +11 -0
  83. package/lib/core/base/Value.d.ts.map +1 -0
  84. package/lib/core/base/Value.js +16 -0
  85. package/lib/core/common/ArkIRTransformer.d.ts +101 -0
  86. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -0
  87. package/lib/core/common/ArkIRTransformer.js +1674 -0
  88. package/lib/core/common/BodyBuilder.d.ts +10 -0
  89. package/lib/core/common/BodyBuilder.d.ts.map +1 -0
  90. package/lib/core/common/BodyBuilder.js +34 -0
  91. package/lib/core/common/Builtin.d.ts +35 -0
  92. package/lib/core/common/Builtin.d.ts.map +1 -0
  93. package/lib/core/common/Builtin.js +78 -0
  94. package/lib/core/common/CfgBuilder.d.ts +136 -0
  95. package/lib/core/common/CfgBuilder.d.ts.map +1 -0
  96. package/lib/core/common/CfgBuilder.js +1241 -0
  97. package/lib/core/common/Const.d.ts +15 -0
  98. package/lib/core/common/Const.d.ts.map +1 -0
  99. package/lib/core/common/Const.js +34 -0
  100. package/lib/core/common/DummyMainCreater.d.ts +48 -0
  101. package/lib/core/common/DummyMainCreater.d.ts.map +1 -0
  102. package/lib/core/common/DummyMainCreater.js +433 -0
  103. package/lib/core/common/EtsConst.d.ts +65 -0
  104. package/lib/core/common/EtsConst.d.ts.map +1 -0
  105. package/lib/core/common/EtsConst.js +918 -0
  106. package/lib/core/common/ExprUseReplacer.d.ts +18 -0
  107. package/lib/core/common/ExprUseReplacer.d.ts.map +1 -0
  108. package/lib/core/common/ExprUseReplacer.js +88 -0
  109. package/lib/core/common/IRUtils.d.ts +7 -0
  110. package/lib/core/common/IRUtils.d.ts.map +1 -0
  111. package/lib/core/common/IRUtils.js +39 -0
  112. package/lib/core/common/ModelUtils.d.ts +61 -0
  113. package/lib/core/common/ModelUtils.d.ts.map +1 -0
  114. package/lib/core/common/ModelUtils.js +628 -0
  115. package/lib/core/common/RefUseReplacer.d.ts +14 -0
  116. package/lib/core/common/RefUseReplacer.d.ts.map +1 -0
  117. package/lib/core/common/RefUseReplacer.js +50 -0
  118. package/lib/core/common/StmtUseReplacer.d.ts +16 -0
  119. package/lib/core/common/StmtUseReplacer.d.ts.map +1 -0
  120. package/lib/core/common/StmtUseReplacer.js +88 -0
  121. package/lib/core/common/TSConst.d.ts +11 -0
  122. package/lib/core/common/TSConst.d.ts.map +1 -0
  123. package/lib/core/common/TSConst.js +28 -0
  124. package/lib/core/common/TypeInference.d.ts +44 -0
  125. package/lib/core/common/TypeInference.d.ts.map +1 -0
  126. package/lib/core/common/TypeInference.js +519 -0
  127. package/lib/core/common/ValueUtil.d.ts +17 -0
  128. package/lib/core/common/ValueUtil.d.ts.map +1 -0
  129. package/lib/core/common/ValueUtil.js +71 -0
  130. package/lib/core/common/VisibleValue.d.ts +37 -0
  131. package/lib/core/common/VisibleValue.d.ts.map +1 -0
  132. package/lib/core/common/VisibleValue.js +212 -0
  133. package/lib/core/dataflow/DataflowProblem.d.ts +21 -0
  134. package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -0
  135. package/lib/core/dataflow/DataflowProblem.js +33 -0
  136. package/lib/core/dataflow/DataflowResult.d.ts +8 -0
  137. package/lib/core/dataflow/DataflowResult.d.ts.map +1 -0
  138. package/lib/core/dataflow/DataflowResult.js +26 -0
  139. package/lib/core/dataflow/DataflowSolver.d.ts +40 -0
  140. package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -0
  141. package/lib/core/dataflow/DataflowSolver.js +318 -0
  142. package/lib/core/dataflow/Edge.d.ts +16 -0
  143. package/lib/core/dataflow/Edge.d.ts.map +1 -0
  144. package/lib/core/dataflow/Edge.js +40 -0
  145. package/lib/core/dataflow/Fact.d.ts +7 -0
  146. package/lib/core/dataflow/Fact.d.ts.map +1 -0
  147. package/lib/core/dataflow/Fact.js +24 -0
  148. package/lib/core/dataflow/TiantAnalysis.d.ts +37 -0
  149. package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -0
  150. package/lib/core/dataflow/TiantAnalysis.js +326 -0
  151. package/lib/core/dataflow/UndefinedVariable.d.ts +32 -0
  152. package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -0
  153. package/lib/core/dataflow/UndefinedVariable.js +235 -0
  154. package/lib/core/dataflow/Util.d.ts +8 -0
  155. package/lib/core/dataflow/Util.d.ts.map +1 -0
  156. package/lib/core/dataflow/Util.js +137 -0
  157. package/lib/core/graph/BasicBlock.d.ts +26 -0
  158. package/lib/core/graph/BasicBlock.d.ts.map +1 -0
  159. package/lib/core/graph/BasicBlock.js +92 -0
  160. package/lib/core/graph/Cfg.d.ts +29 -0
  161. package/lib/core/graph/Cfg.d.ts.map +1 -0
  162. package/lib/core/graph/Cfg.js +154 -0
  163. package/lib/core/graph/DominanceFinder.d.ts +16 -0
  164. package/lib/core/graph/DominanceFinder.d.ts.map +1 -0
  165. package/lib/core/graph/DominanceFinder.js +121 -0
  166. package/lib/core/graph/DominanceTree.d.ts +13 -0
  167. package/lib/core/graph/DominanceTree.d.ts.map +1 -0
  168. package/lib/core/graph/DominanceTree.js +70 -0
  169. package/lib/core/graph/ViewTree.d.ts +115 -0
  170. package/lib/core/graph/ViewTree.d.ts.map +1 -0
  171. package/lib/core/graph/ViewTree.js +16 -0
  172. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +204 -0
  173. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -0
  174. package/lib/core/graph/builder/ViewTreeBuilder.js +1046 -0
  175. package/lib/core/model/ArkBody.d.ts +22 -0
  176. package/lib/core/model/ArkBody.d.ts.map +1 -0
  177. package/lib/core/model/ArkBody.js +63 -0
  178. package/lib/core/model/ArkClass.d.ts +110 -0
  179. package/lib/core/model/ArkClass.d.ts.map +1 -0
  180. package/lib/core/model/ArkClass.js +315 -0
  181. package/lib/core/model/ArkExport.d.ts +70 -0
  182. package/lib/core/model/ArkExport.d.ts.map +1 -0
  183. package/lib/core/model/ArkExport.js +143 -0
  184. package/lib/core/model/ArkField.d.ts +60 -0
  185. package/lib/core/model/ArkField.d.ts.map +1 -0
  186. package/lib/core/model/ArkField.js +157 -0
  187. package/lib/core/model/ArkFile.d.ts +62 -0
  188. package/lib/core/model/ArkFile.d.ts.map +1 -0
  189. package/lib/core/model/ArkFile.js +160 -0
  190. package/lib/core/model/ArkImport.d.ts +43 -0
  191. package/lib/core/model/ArkImport.d.ts.map +1 -0
  192. package/lib/core/model/ArkImport.js +109 -0
  193. package/lib/core/model/ArkMethod.d.ts +76 -0
  194. package/lib/core/model/ArkMethod.d.ts.map +1 -0
  195. package/lib/core/model/ArkMethod.js +235 -0
  196. package/lib/core/model/ArkNamespace.d.ts +65 -0
  197. package/lib/core/model/ArkNamespace.d.ts.map +1 -0
  198. package/lib/core/model/ArkNamespace.js +182 -0
  199. package/lib/core/model/ArkSignature.d.ts +98 -0
  200. package/lib/core/model/ArkSignature.d.ts.map +1 -0
  201. package/lib/core/model/ArkSignature.js +281 -0
  202. package/lib/core/model/builder/ArkClassBuilder.d.ts +13 -0
  203. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -0
  204. package/lib/core/model/builder/ArkClassBuilder.js +422 -0
  205. package/lib/core/model/builder/ArkExportBuilder.d.ts +25 -0
  206. package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -0
  207. package/lib/core/model/builder/ArkExportBuilder.js +207 -0
  208. package/lib/core/model/builder/ArkFieldBuilder.d.ts +9 -0
  209. package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -0
  210. package/lib/core/model/builder/ArkFieldBuilder.js +189 -0
  211. package/lib/core/model/builder/ArkFileBuilder.d.ts +10 -0
  212. package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -0
  213. package/lib/core/model/builder/ArkFileBuilder.js +164 -0
  214. package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -0
  215. package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -0
  216. package/lib/core/model/builder/ArkImportBuilder.js +125 -0
  217. package/lib/core/model/builder/ArkMethodBuilder.d.ts +60 -0
  218. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -0
  219. package/lib/core/model/builder/ArkMethodBuilder.js +419 -0
  220. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -0
  221. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -0
  222. package/lib/core/model/builder/ArkNamespaceBuilder.js +171 -0
  223. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
  224. package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -0
  225. package/lib/core/model/builder/ArkSignatureBuilder.js +40 -0
  226. package/lib/core/model/builder/builderUtils.d.ts +18 -0
  227. package/lib/core/model/builder/builderUtils.d.ts.map +1 -0
  228. package/lib/core/model/builder/builderUtils.js +449 -0
  229. package/lib/index.d.ts +77 -0
  230. package/lib/index.d.ts.map +1 -0
  231. package/lib/index.js +190 -0
  232. package/lib/save/ArkStream.d.ts +24 -0
  233. package/lib/save/ArkStream.d.ts.map +1 -0
  234. package/lib/save/ArkStream.js +83 -0
  235. package/lib/save/DotPrinter.d.ts +48 -0
  236. package/lib/save/DotPrinter.d.ts.map +1 -0
  237. package/lib/save/DotPrinter.js +229 -0
  238. package/lib/save/GraphPrinter.d.ts +17 -0
  239. package/lib/save/GraphPrinter.d.ts.map +1 -0
  240. package/lib/save/GraphPrinter.js +135 -0
  241. package/lib/save/JsonPrinter.d.ts +28 -0
  242. package/lib/save/JsonPrinter.d.ts.map +1 -0
  243. package/lib/save/JsonPrinter.js +511 -0
  244. package/lib/save/Printer.d.ts +17 -0
  245. package/lib/save/Printer.d.ts.map +1 -0
  246. package/lib/save/Printer.js +27 -0
  247. package/lib/save/PrinterBuilder.d.ts +38 -0
  248. package/lib/save/PrinterBuilder.d.ts.map +1 -0
  249. package/lib/save/PrinterBuilder.js +102 -0
  250. package/lib/save/serializeArkIR.d.ts +3 -0
  251. package/lib/save/serializeArkIR.d.ts.map +1 -0
  252. package/lib/save/serializeArkIR.js +166 -0
  253. package/lib/save/source/SourceBase.d.ts +32 -0
  254. package/lib/save/source/SourceBase.d.ts.map +1 -0
  255. package/lib/save/source/SourceBase.js +93 -0
  256. package/lib/save/source/SourceBody.d.ts +60 -0
  257. package/lib/save/source/SourceBody.d.ts.map +1 -0
  258. package/lib/save/source/SourceBody.js +292 -0
  259. package/lib/save/source/SourceClass.d.ts +27 -0
  260. package/lib/save/source/SourceClass.d.ts.map +1 -0
  261. package/lib/save/source/SourceClass.js +202 -0
  262. package/lib/save/source/SourceField.d.ts +15 -0
  263. package/lib/save/source/SourceField.d.ts.map +1 -0
  264. package/lib/save/source/SourceField.js +68 -0
  265. package/lib/save/source/SourceFilePrinter.d.ts +14 -0
  266. package/lib/save/source/SourceFilePrinter.d.ts.map +1 -0
  267. package/lib/save/source/SourceFilePrinter.js +73 -0
  268. package/lib/save/source/SourceMethod.d.ts +24 -0
  269. package/lib/save/source/SourceMethod.d.ts.map +1 -0
  270. package/lib/save/source/SourceMethod.js +170 -0
  271. package/lib/save/source/SourceModule.d.ts +18 -0
  272. package/lib/save/source/SourceModule.d.ts.map +1 -0
  273. package/lib/save/source/SourceModule.js +120 -0
  274. package/lib/save/source/SourceNamespace.d.ts +13 -0
  275. package/lib/save/source/SourceNamespace.d.ts.map +1 -0
  276. package/lib/save/source/SourceNamespace.js +80 -0
  277. package/lib/save/source/SourceStmt.d.ts +172 -0
  278. package/lib/save/source/SourceStmt.d.ts.map +1 -0
  279. package/lib/save/source/SourceStmt.js +757 -0
  280. package/lib/save/source/SourceTransformer.d.ts +37 -0
  281. package/lib/save/source/SourceTransformer.d.ts.map +1 -0
  282. package/lib/save/source/SourceTransformer.js +338 -0
  283. package/lib/save/source/SourceUtils.d.ts +25 -0
  284. package/lib/save/source/SourceUtils.d.ts.map +1 -0
  285. package/lib/save/source/SourceUtils.js +201 -0
  286. package/lib/transformer/FunctionTransformer.d.ts +3 -0
  287. package/lib/transformer/FunctionTransformer.d.ts.map +1 -0
  288. package/lib/transformer/FunctionTransformer.js +17 -0
  289. package/lib/transformer/SceneTransformer.d.ts +3 -0
  290. package/lib/transformer/SceneTransformer.d.ts.map +1 -0
  291. package/lib/transformer/SceneTransformer.js +17 -0
  292. package/lib/transformer/StaticSingleAssignmentFormer.d.ts +13 -0
  293. package/lib/transformer/StaticSingleAssignmentFormer.d.ts.map +1 -0
  294. package/lib/transformer/StaticSingleAssignmentFormer.js +259 -0
  295. package/lib/transformer/Transformer.d.ts +7 -0
  296. package/lib/transformer/Transformer.d.ts.map +1 -0
  297. package/lib/transformer/Transformer.js +22 -0
  298. package/lib/utils/CfgStructualAnalysis.d.ts +93 -0
  299. package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -0
  300. package/lib/utils/CfgStructualAnalysis.js +955 -0
  301. package/lib/utils/FileUtils.d.ts +18 -0
  302. package/lib/utils/FileUtils.d.ts.map +1 -0
  303. package/lib/utils/FileUtils.js +131 -0
  304. package/lib/utils/callGraphUtils.d.ts +31 -0
  305. package/lib/utils/callGraphUtils.d.ts.map +1 -0
  306. package/lib/utils/callGraphUtils.js +208 -0
  307. package/lib/utils/entryMethodUtils.d.ts +16 -0
  308. package/lib/utils/entryMethodUtils.d.ts.map +1 -0
  309. package/lib/utils/entryMethodUtils.js +139 -0
  310. package/lib/utils/getAllFiles.d.ts +10 -0
  311. package/lib/utils/getAllFiles.d.ts.map +1 -0
  312. package/lib/utils/getAllFiles.js +91 -0
  313. package/lib/utils/json5parser.d.ts +7 -0
  314. package/lib/utils/json5parser.d.ts.map +1 -0
  315. package/lib/utils/json5parser.js +146 -0
  316. package/lib/utils/logger.d.ts +19 -0
  317. package/lib/utils/logger.d.ts.map +1 -0
  318. package/lib/utils/logger.js +90 -0
  319. package/lib/utils/pathTransfer.d.ts +2 -0
  320. package/lib/utils/pathTransfer.d.ts.map +1 -0
  321. package/lib/utils/pathTransfer.js +25 -0
  322. package/package.json +29 -0
@@ -0,0 +1,896 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 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.ArkUnopExpr = exports.UnaryOperator = exports.ArkPhiExpr = exports.ArkCastExpr = exports.ArkInstanceOfExpr = exports.ArkTypeOfExpr = exports.ArkNormalBinopExpr = exports.ArkConditionExpr = exports.AbstractBinopExpr = exports.RelationalBinaryOperator = exports.NormalBinaryOperator = exports.ArkYieldExpr = exports.ArkAwaitExpr = exports.ArkDeleteExpr = exports.ArkNewArrayExpr = exports.ArkNewExpr = exports.ArkPtrInvokeExpr = exports.ArkStaticInvokeExpr = exports.ArkInstanceInvokeExpr = exports.AbstractInvokeExpr = exports.AbstractExpr = void 0;
41
+ const TypeInference_1 = require("../common/TypeInference");
42
+ const ArkClass_1 = require("../model/ArkClass");
43
+ const ArkSignature_1 = require("../model/ArkSignature");
44
+ const Local_1 = require("./Local");
45
+ const Type_1 = require("./Type");
46
+ const Ref_1 = require("./Ref");
47
+ const ModelUtils_1 = require("../common/ModelUtils");
48
+ const Stmt_1 = require("./Stmt");
49
+ const logger_1 = __importStar(require("../../utils/logger"));
50
+ const ValueUtil_1 = require("../common/ValueUtil");
51
+ const ArkMethod_1 = require("../model/ArkMethod");
52
+ const ArkImport_1 = require("../model/ArkImport");
53
+ const Constant_1 = require("./Constant");
54
+ const TSConst_1 = require("../common/TSConst");
55
+ const Builtin_1 = require("../common/Builtin");
56
+ const EtsConst_1 = require("../common/EtsConst");
57
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'Expr');
58
+ /**
59
+ * @category core/base/expr
60
+ */
61
+ class AbstractExpr {
62
+ inferType(arkClass) {
63
+ return this;
64
+ }
65
+ }
66
+ exports.AbstractExpr = AbstractExpr;
67
+ class AbstractInvokeExpr extends AbstractExpr {
68
+ constructor(methodSignature, args, realGenericTypes) {
69
+ super();
70
+ this.methodSignature = methodSignature;
71
+ this.args = args;
72
+ this.realGenericTypes = realGenericTypes;
73
+ }
74
+ getMethodSignature() {
75
+ return this.methodSignature;
76
+ }
77
+ setMethodSignature(newMethodSignature) {
78
+ this.methodSignature = newMethodSignature;
79
+ }
80
+ getArg(index) {
81
+ return this.args[index];
82
+ }
83
+ getArgs() {
84
+ return this.args;
85
+ }
86
+ setArgs(newArgs) {
87
+ this.args = newArgs;
88
+ }
89
+ getType() {
90
+ let type = this.methodSignature.getType();
91
+ if (!this.realGenericTypes) {
92
+ return type;
93
+ }
94
+ if (type instanceof Type_1.GenericType) {
95
+ const realType = this.realGenericTypes[type.getIndex()];
96
+ if (realType) {
97
+ type = realType;
98
+ }
99
+ }
100
+ else if (type instanceof Type_1.UnionType) {
101
+ const types = [];
102
+ type.getTypes().forEach(t => {
103
+ var _a;
104
+ let realType;
105
+ if (t instanceof Type_1.GenericType) {
106
+ realType = (_a = this.realGenericTypes) === null || _a === void 0 ? void 0 : _a[t.getIndex()];
107
+ }
108
+ types.push(realType !== null && realType !== void 0 ? realType : t);
109
+ });
110
+ type = new Type_1.UnionType(types, type.getCurrType());
111
+ }
112
+ return type;
113
+ }
114
+ getRealGenericTypes() {
115
+ return this.realGenericTypes;
116
+ }
117
+ getUses() {
118
+ let uses = [];
119
+ uses.push(...this.args);
120
+ for (const arg of this.args) {
121
+ uses.push(...arg.getUses());
122
+ }
123
+ return uses;
124
+ }
125
+ }
126
+ exports.AbstractInvokeExpr = AbstractInvokeExpr;
127
+ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
128
+ constructor(base, methodSignature, args, realGenericTypes) {
129
+ super(methodSignature, args, realGenericTypes);
130
+ this.base = base;
131
+ }
132
+ getBase() {
133
+ return this.base;
134
+ }
135
+ setBase(newBase) {
136
+ this.base = newBase;
137
+ }
138
+ getUses() {
139
+ let uses = [];
140
+ uses.push(this.base);
141
+ uses.push(...this.base.getUses());
142
+ uses.push(...this.getArgs());
143
+ for (const arg of this.getArgs()) {
144
+ uses.push(...arg.getUses());
145
+ }
146
+ return uses;
147
+ }
148
+ toString() {
149
+ let strs = [];
150
+ strs.push('instanceinvoke ');
151
+ strs.push(this.base.toString());
152
+ strs.push('.<');
153
+ strs.push(this.getMethodSignature().toString());
154
+ strs.push('>(');
155
+ if (this.getArgs().length > 0) {
156
+ for (const arg of this.getArgs()) {
157
+ strs.push(arg.toString());
158
+ strs.push(', ');
159
+ }
160
+ strs.pop();
161
+ }
162
+ strs.push(')');
163
+ return strs.join('');
164
+ }
165
+ inferType(arkClass) {
166
+ this.getArgs().forEach(arg => TypeInference_1.TypeInference.inferValueType(arg, arkClass));
167
+ let baseType = this.base.getType();
168
+ if (this.base instanceof Local_1.Local && baseType instanceof Type_1.UnknownType) {
169
+ baseType = TypeInference_1.TypeInference.inferBaseType(this.base.getName(), arkClass);
170
+ }
171
+ else if (baseType instanceof Type_1.UnclearReferenceType) {
172
+ baseType = TypeInference_1.TypeInference.inferUnclearReferenceType(baseType.getName(), arkClass);
173
+ }
174
+ const methodName = this.getMethodSignature().getMethodSubSignature().getMethodName();
175
+ if (!baseType) {
176
+ if (!this.tryInferFormGlobal(methodName, arkClass)) {
177
+ logger.warn('infer ArkInstanceInvokeExpr base type fail: ' + this.toString());
178
+ }
179
+ return this;
180
+ }
181
+ if (this.base instanceof Local_1.Local) {
182
+ this.base.setType(baseType);
183
+ }
184
+ const scene = arkClass.getDeclaringArkFile().getScene();
185
+ if ((methodName === 'forEach') && (baseType instanceof Type_1.ArrayType)) {
186
+ this.processForEach(baseType, scene);
187
+ }
188
+ TypeInference_1.TypeInference.inferRealGenericTypes(this.getRealGenericTypes(), arkClass);
189
+ let result;
190
+ if (baseType instanceof Type_1.AliasType) {
191
+ baseType = baseType.getOriginalType();
192
+ }
193
+ if (baseType instanceof Type_1.UnionType) {
194
+ for (const type of baseType.getTypes()) {
195
+ result = this.inferMethod(type, methodName, scene);
196
+ if (result) {
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ else {
202
+ result = this.inferMethod(baseType, methodName, scene);
203
+ }
204
+ if (!result && this.tryInferFormGlobal(methodName, arkClass)) {
205
+ result = this;
206
+ }
207
+ if (result) {
208
+ return result;
209
+ }
210
+ logger.warn('invoke ArkInstanceInvokeExpr MethodSignature type fail: ', this.toString());
211
+ return this;
212
+ }
213
+ processForEach(baseType, scene) {
214
+ const arg = this.getArg(0);
215
+ if (arg.getType() instanceof Type_1.FunctionType) {
216
+ const argMethodSignature = arg.getType().getMethodSignature();
217
+ const argMethod = scene.getMethod(argMethodSignature);
218
+ if (argMethod != null && argMethod.getBody()) {
219
+ const body = argMethod.getBody();
220
+ const firstStmt = body.getCfg().getStartingStmt();
221
+ if ((firstStmt instanceof Stmt_1.ArkAssignStmt) && (firstStmt.getRightOp() instanceof Ref_1.ArkParameterRef)) {
222
+ const parameterRef = firstStmt.getRightOp();
223
+ parameterRef.setType(baseType.getBaseType());
224
+ }
225
+ TypeInference_1.TypeInference.inferTypeInMethod(argMethod);
226
+ }
227
+ }
228
+ else {
229
+ logger.warn(`arg of forEach must be callable`);
230
+ }
231
+ }
232
+ tryInferFormGlobal(methodName, arkClass) {
233
+ if (arkClass.hasComponentDecorator() || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
234
+ const global = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(methodName);
235
+ if (global instanceof ArkMethod_1.ArkMethod) {
236
+ TypeInference_1.TypeInference.inferMethodReturnType(global);
237
+ this.setMethodSignature(global.getSignature());
238
+ return true;
239
+ }
240
+ }
241
+ return false;
242
+ }
243
+ inferMethod(baseType, methodName, scene) {
244
+ if (baseType instanceof Type_1.ClassType) {
245
+ const arkClass = scene.getClass(baseType.getClassSignature());
246
+ const method = arkClass ? ModelUtils_1.ModelUtils.findPropertyInClass(methodName, arkClass) : null;
247
+ if (method instanceof ArkMethod_1.ArkMethod) {
248
+ TypeInference_1.TypeInference.inferMethodReturnType(method);
249
+ this.setMethodSignature(method.getSignature());
250
+ if (method.isStatic()) {
251
+ return new ArkStaticInvokeExpr(method.getSignature(), this.getArgs(), this.getRealGenericTypes());
252
+ }
253
+ return this;
254
+ }
255
+ else if (methodName === TSConst_1.CONSTRUCTOR_NAME) { //sdk隐式构造
256
+ const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], new Type_1.ClassType(baseType.getClassSignature()));
257
+ const signature = new ArkSignature_1.MethodSignature(baseType.getClassSignature(), subSignature);
258
+ this.setMethodSignature(signature);
259
+ return this;
260
+ }
261
+ else if (methodName === Builtin_1.Builtin.ITERATOR_NEXT) { //sdk隐式构造
262
+ const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
263
+ if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
264
+ .getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
265
+ returnType.setRealGenericTypes(baseType.getRealGenericTypes());
266
+ return this;
267
+ }
268
+ }
269
+ }
270
+ else if (baseType instanceof Type_1.AnnotationNamespaceType) {
271
+ const namespace = scene.getNamespace(baseType.getNamespaceSignature());
272
+ if (namespace) {
273
+ const foundMethod = ModelUtils_1.ModelUtils.findPropertyInNamespace(methodName, namespace);
274
+ if (foundMethod instanceof ArkMethod_1.ArkMethod) {
275
+ TypeInference_1.TypeInference.inferMethodReturnType(foundMethod);
276
+ this.setMethodSignature(foundMethod.getSignature());
277
+ return new ArkStaticInvokeExpr(foundMethod.getSignature(), this.getArgs(), this.getRealGenericTypes());
278
+ }
279
+ }
280
+ }
281
+ else if (baseType instanceof Type_1.ArrayType && methodName === Builtin_1.Builtin.ITERATOR_FUNCTION) {
282
+ const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
283
+ if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
284
+ .getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
285
+ returnType.setRealGenericTypes([baseType.getBaseType()]);
286
+ return this;
287
+ }
288
+ }
289
+ return null;
290
+ }
291
+ }
292
+ exports.ArkInstanceInvokeExpr = ArkInstanceInvokeExpr;
293
+ class ArkStaticInvokeExpr extends AbstractInvokeExpr {
294
+ constructor(methodSignature, args, realGenericTypes) {
295
+ super(methodSignature, args, realGenericTypes);
296
+ }
297
+ toString() {
298
+ let strs = [];
299
+ strs.push('staticinvoke <');
300
+ strs.push(this.getMethodSignature().toString());
301
+ strs.push('>(');
302
+ if (this.getArgs().length > 0) {
303
+ for (const arg of this.getArgs()) {
304
+ strs.push(arg.toString());
305
+ strs.push(', ');
306
+ }
307
+ strs.pop();
308
+ }
309
+ strs.push(')');
310
+ return strs.join('');
311
+ }
312
+ inferType(arkClass) {
313
+ var _a, _b;
314
+ this.getArgs().forEach(arg => TypeInference_1.TypeInference.inferValueType(arg, arkClass));
315
+ const oldMethodSignature = this.getMethodSignature();
316
+ const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
317
+ const methodName = oldMethodSubSignature.getMethodName();
318
+ let method;
319
+ const arkExport = (_a = ModelUtils_1.ModelUtils.getStaticMethodWithName(methodName, arkClass)) !== null && _a !== void 0 ? _a : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(methodName, arkClass.getDeclaringArkFile());
320
+ if (arkExport instanceof ArkMethod_1.ArkMethod) {
321
+ method = arkExport;
322
+ }
323
+ else if (arkExport instanceof ArkClass_1.ArkClass) {
324
+ method = arkExport.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
325
+ }
326
+ if (!method) {
327
+ if (methodName === TSConst_1.IMPORT && this.getArgs()[0] instanceof Constant_1.Constant) {
328
+ const importInfo = new ArkImport_1.ImportInfo();
329
+ importInfo.setNameBeforeAs(TSConst_1.ALL);
330
+ importInfo.setImportClauseName(TSConst_1.ALL);
331
+ importInfo.setImportFrom(this.getArgs()[0].getValue());
332
+ importInfo.setDeclaringArkFile(arkClass.getDeclaringArkFile());
333
+ const type = TypeInference_1.TypeInference.parseArkExport2Type((_b = importInfo.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport());
334
+ if (type) {
335
+ const subSignature = new ArkSignature_1.MethodSubSignature(methodName, oldMethodSubSignature.getParameters(), type);
336
+ const signature = new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), subSignature);
337
+ this.setMethodSignature(signature);
338
+ }
339
+ return this;
340
+ }
341
+ if (arkClass.hasComponentDecorator() || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
342
+ let className;
343
+ if (EtsConst_1.COMPONENT_CREATE_FUNCTION === methodName || EtsConst_1.COMPONENT_POP_FUNCTION === methodName) {
344
+ className = this.getMethodSignature().getDeclaringClassSignature().getClassName();
345
+ }
346
+ const globalName = className !== null && className !== void 0 ? className : methodName;
347
+ const global = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(globalName);
348
+ if (global instanceof ArkMethod_1.ArkMethod) {
349
+ method = global;
350
+ }
351
+ else if (global instanceof ArkClass_1.ArkClass) {
352
+ const callable = ModelUtils_1.ModelUtils.findPropertyInClass(methodName, global);
353
+ if (callable instanceof ArkMethod_1.ArkMethod) {
354
+ method = callable;
355
+ }
356
+ else {
357
+ const signature = new ArkSignature_1.MethodSignature(global.getSignature(), oldMethodSubSignature);
358
+ this.setMethodSignature(signature);
359
+ }
360
+ }
361
+ }
362
+ }
363
+ if (method) {
364
+ this.setMethodSignature(method.getSignature());
365
+ TypeInference_1.TypeInference.inferMethodReturnType(method);
366
+ }
367
+ return this;
368
+ }
369
+ }
370
+ exports.ArkStaticInvokeExpr = ArkStaticInvokeExpr;
371
+ class ArkPtrInvokeExpr extends AbstractInvokeExpr {
372
+ constructor(methodSignature, ptr, args, realGenericTypes) {
373
+ super(methodSignature, args, realGenericTypes);
374
+ this.funPtrLocal = ptr;
375
+ }
376
+ setFunPtrLocal(ptr) {
377
+ this.funPtrLocal = ptr;
378
+ }
379
+ getFuncPtrLocal() {
380
+ return this.funPtrLocal;
381
+ }
382
+ toString() {
383
+ let strs = [];
384
+ strs.push('ptrinvoke <');
385
+ strs.push(this.getMethodSignature().toString());
386
+ strs.push('>(');
387
+ if (this.getArgs().length > 0) {
388
+ for (const arg of this.getArgs()) {
389
+ strs.push(arg.toString());
390
+ strs.push(', ');
391
+ }
392
+ strs.pop();
393
+ }
394
+ strs.push(')');
395
+ return strs.join('');
396
+ }
397
+ inferType(arkClass) {
398
+ // TODO: handle type inference
399
+ return this;
400
+ }
401
+ }
402
+ exports.ArkPtrInvokeExpr = ArkPtrInvokeExpr;
403
+ class ArkNewExpr extends AbstractExpr {
404
+ constructor(classType) {
405
+ super();
406
+ this.classType = classType;
407
+ }
408
+ getClassType() {
409
+ return this.classType;
410
+ }
411
+ getUses() {
412
+ return [];
413
+ }
414
+ getType() {
415
+ return this.classType;
416
+ }
417
+ toString() {
418
+ return 'new ' + this.classType;
419
+ }
420
+ inferType(arkClass) {
421
+ const className = this.classType.getClassSignature().getClassName();
422
+ const type = TypeInference_1.TypeInference.inferUnclearReferenceType(className, arkClass);
423
+ if (type && type instanceof Type_1.ClassType) {
424
+ let realGenericTypes = this.classType.getRealGenericTypes();
425
+ this.classType = realGenericTypes ? new Type_1.ClassType(type.getClassSignature(), realGenericTypes) : type;
426
+ }
427
+ return this;
428
+ }
429
+ }
430
+ exports.ArkNewExpr = ArkNewExpr;
431
+ class ArkNewArrayExpr extends AbstractExpr {
432
+ constructor(baseType, size, fromLiteral = false) {
433
+ super();
434
+ this.baseType = baseType;
435
+ this.size = size;
436
+ this.fromLiteral = fromLiteral;
437
+ }
438
+ getSize() {
439
+ return this.size;
440
+ }
441
+ setSize(newSize) {
442
+ this.size = newSize;
443
+ }
444
+ getType() {
445
+ return new Type_1.ArrayType(this.baseType, 1);
446
+ }
447
+ getBaseType() {
448
+ return this.baseType;
449
+ }
450
+ setBaseType(newType) {
451
+ this.baseType = newType;
452
+ }
453
+ isFromLiteral() {
454
+ return this.fromLiteral;
455
+ }
456
+ inferType(arkClass) {
457
+ const type = TypeInference_1.TypeInference.inferUnclearedType(this.baseType, arkClass);
458
+ if (type) {
459
+ this.baseType = type;
460
+ }
461
+ return this;
462
+ }
463
+ getUses() {
464
+ let uses = [this.size];
465
+ uses.push(...this.size.getUses());
466
+ return uses;
467
+ }
468
+ toString() {
469
+ return 'newarray (' + this.baseType + ')[' + this.size + ']';
470
+ }
471
+ }
472
+ exports.ArkNewArrayExpr = ArkNewArrayExpr;
473
+ class ArkDeleteExpr extends AbstractExpr {
474
+ constructor(field) {
475
+ super();
476
+ this.field = field;
477
+ }
478
+ getField() {
479
+ return this.field;
480
+ }
481
+ setField(newField) {
482
+ this.field = newField;
483
+ }
484
+ getType() {
485
+ return Type_1.BooleanType.getInstance();
486
+ }
487
+ getUses() {
488
+ const uses = [];
489
+ uses.push(this.field);
490
+ uses.push(...this.field.getUses());
491
+ return uses;
492
+ }
493
+ toString() {
494
+ return 'delete ' + this.field;
495
+ }
496
+ }
497
+ exports.ArkDeleteExpr = ArkDeleteExpr;
498
+ class ArkAwaitExpr extends AbstractExpr {
499
+ constructor(promise) {
500
+ super();
501
+ this.promise = promise;
502
+ }
503
+ getPromise() {
504
+ return this.promise;
505
+ }
506
+ setPromise(newPromise) {
507
+ this.promise = newPromise;
508
+ }
509
+ getType() {
510
+ return this.promise.getType();
511
+ }
512
+ inferType(arkClass) {
513
+ TypeInference_1.TypeInference.inferValueType(this.promise, arkClass);
514
+ return this;
515
+ }
516
+ getUses() {
517
+ const uses = [];
518
+ uses.push(this.promise);
519
+ uses.push(...this.promise.getUses());
520
+ return uses;
521
+ }
522
+ toString() {
523
+ const str = 'await ' + this.promise;
524
+ return str;
525
+ }
526
+ }
527
+ exports.ArkAwaitExpr = ArkAwaitExpr;
528
+ class ArkYieldExpr extends AbstractExpr {
529
+ constructor(yieldValue) {
530
+ super();
531
+ this.yieldValue = yieldValue;
532
+ }
533
+ getYieldValue() {
534
+ return this.yieldValue;
535
+ }
536
+ setYieldValue(newYieldValue) {
537
+ this.yieldValue = newYieldValue;
538
+ }
539
+ getType() {
540
+ return this.yieldValue.getType();
541
+ }
542
+ getUses() {
543
+ const uses = [];
544
+ uses.push(this.yieldValue);
545
+ uses.push(...this.yieldValue.getUses());
546
+ return uses;
547
+ }
548
+ toString() {
549
+ const str = 'yield ' + this.yieldValue;
550
+ return str;
551
+ }
552
+ }
553
+ exports.ArkYieldExpr = ArkYieldExpr;
554
+ var NormalBinaryOperator;
555
+ (function (NormalBinaryOperator) {
556
+ // TODO: unfold it
557
+ NormalBinaryOperator["NullishCoalescing"] = "??";
558
+ // arithmetic
559
+ NormalBinaryOperator["Exponentiation"] = "**";
560
+ NormalBinaryOperator["Division"] = "/";
561
+ NormalBinaryOperator["Addition"] = "+";
562
+ NormalBinaryOperator["Subtraction"] = "-";
563
+ NormalBinaryOperator["Multiplication"] = "*";
564
+ NormalBinaryOperator["Remainder"] = "%";
565
+ // shift
566
+ NormalBinaryOperator["LeftShift"] = "<<";
567
+ NormalBinaryOperator["RightShift"] = ">>";
568
+ NormalBinaryOperator["UnsignedRightShift"] = ">>>";
569
+ // Bitwise
570
+ NormalBinaryOperator["BitwiseAnd"] = "&";
571
+ NormalBinaryOperator["BitwiseOr"] = "|";
572
+ NormalBinaryOperator["BitwiseXor"] = "^";
573
+ // Logical
574
+ NormalBinaryOperator["LogicalAnd"] = "&&";
575
+ NormalBinaryOperator["LogicalOr"] = "||";
576
+ })(NormalBinaryOperator = exports.NormalBinaryOperator || (exports.NormalBinaryOperator = {}));
577
+ var RelationalBinaryOperator;
578
+ (function (RelationalBinaryOperator) {
579
+ RelationalBinaryOperator["LessThan"] = "<";
580
+ RelationalBinaryOperator["LessThanOrEqual"] = "<=";
581
+ RelationalBinaryOperator["GreaterThan"] = ">";
582
+ RelationalBinaryOperator["GreaterThanOrEqual"] = ">=";
583
+ RelationalBinaryOperator["Equality"] = "==";
584
+ RelationalBinaryOperator["InEquality"] = "!=";
585
+ RelationalBinaryOperator["StrictEquality"] = "===";
586
+ RelationalBinaryOperator["StrictInequality"] = "!==";
587
+ })(RelationalBinaryOperator = exports.RelationalBinaryOperator || (exports.RelationalBinaryOperator = {}));
588
+ // 二元运算表达式
589
+ class AbstractBinopExpr extends AbstractExpr {
590
+ constructor(op1, op2, operator) {
591
+ super();
592
+ this.op1 = op1;
593
+ this.op2 = op2;
594
+ this.operator = operator;
595
+ }
596
+ getOp1() {
597
+ return this.op1;
598
+ }
599
+ setOp1(newOp1) {
600
+ this.op1 = newOp1;
601
+ }
602
+ getOp2() {
603
+ return this.op2;
604
+ }
605
+ setOp2(newOp2) {
606
+ this.op2 = newOp2;
607
+ }
608
+ getOperator() {
609
+ return this.operator;
610
+ }
611
+ getType() {
612
+ if (!this.type) {
613
+ this.setType();
614
+ }
615
+ return this.type;
616
+ }
617
+ getUses() {
618
+ let uses = [];
619
+ uses.push(this.op1);
620
+ uses.push(...this.op1.getUses());
621
+ uses.push(this.op2);
622
+ uses.push(...this.op2.getUses());
623
+ return uses;
624
+ }
625
+ toString() {
626
+ return this.op1 + ' ' + this.operator + ' ' + this.op2;
627
+ }
628
+ inferOpType(op, arkClass) {
629
+ if (op instanceof AbstractExpr || op instanceof Ref_1.AbstractRef) {
630
+ TypeInference_1.TypeInference.inferValueType(op, arkClass);
631
+ }
632
+ }
633
+ setType() {
634
+ let op1Type = this.op1.getType();
635
+ let op2Type = this.op2.getType();
636
+ if (op1Type instanceof Type_1.UnionType) {
637
+ op1Type = op1Type.getCurrType();
638
+ }
639
+ if (op2Type instanceof Type_1.UnionType) {
640
+ op2Type = op2Type.getCurrType();
641
+ }
642
+ let type = Type_1.UnknownType.getInstance();
643
+ switch (this.operator) {
644
+ case '+':
645
+ if (op1Type === Type_1.StringType.getInstance() || op2Type === Type_1.StringType.getInstance()) {
646
+ type = Type_1.StringType.getInstance();
647
+ }
648
+ if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
649
+ type = Type_1.NumberType.getInstance();
650
+ }
651
+ break;
652
+ case '-':
653
+ case '*':
654
+ case '/':
655
+ case '%':
656
+ if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
657
+ type = Type_1.NumberType.getInstance();
658
+ }
659
+ break;
660
+ case '!=':
661
+ case '!==':
662
+ case '<':
663
+ case '>':
664
+ case '<=':
665
+ case '>=':
666
+ case '&&':
667
+ case '||':
668
+ case '==':
669
+ case '===':
670
+ type = Type_1.BooleanType.getInstance();
671
+ break;
672
+ case '&':
673
+ case '|':
674
+ case '^':
675
+ case '<<':
676
+ case '>>':
677
+ case '>>>':
678
+ if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
679
+ type = Type_1.NumberType.getInstance();
680
+ }
681
+ break;
682
+ case '??':
683
+ if (op1Type === Type_1.UnknownType.getInstance() || op1Type === Type_1.UndefinedType.getInstance()
684
+ || op1Type === Type_1.NullType.getInstance()) {
685
+ type = op2Type;
686
+ }
687
+ else {
688
+ type = op1Type;
689
+ }
690
+ break;
691
+ }
692
+ this.type = type;
693
+ }
694
+ inferType(arkClass) {
695
+ this.inferOpType(this.op1, arkClass);
696
+ this.inferOpType(this.op2, arkClass);
697
+ this.setType();
698
+ return this;
699
+ }
700
+ }
701
+ exports.AbstractBinopExpr = AbstractBinopExpr;
702
+ class ArkConditionExpr extends AbstractBinopExpr {
703
+ constructor(op1, op2, operator) {
704
+ super(op1, op2, operator);
705
+ }
706
+ inferType(arkClass) {
707
+ this.inferOpType(this.op1, arkClass);
708
+ const op1Type = this.op1.getType();
709
+ if (this.operator == RelationalBinaryOperator.InEquality && this.op2 == ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)) {
710
+ if (op1Type instanceof Type_1.StringType) {
711
+ this.op2 = ValueUtil_1.ValueUtil.createStringConst(ValueUtil_1.EMPTY_STRING);
712
+ }
713
+ else if (op1Type instanceof Type_1.BooleanType) {
714
+ this.op2 = ValueUtil_1.ValueUtil.getBooleanConstant(false);
715
+ }
716
+ else if (op1Type instanceof Type_1.ClassType) {
717
+ this.op2 = ValueUtil_1.ValueUtil.getUndefinedConst();
718
+ }
719
+ }
720
+ else {
721
+ this.inferOpType(this.getOp2(), arkClass);
722
+ }
723
+ this.type = Type_1.BooleanType.getInstance();
724
+ return this;
725
+ }
726
+ }
727
+ exports.ArkConditionExpr = ArkConditionExpr;
728
+ class ArkNormalBinopExpr extends AbstractBinopExpr {
729
+ constructor(op1, op2, operator) {
730
+ super(op1, op2, operator);
731
+ }
732
+ }
733
+ exports.ArkNormalBinopExpr = ArkNormalBinopExpr;
734
+ class ArkTypeOfExpr extends AbstractExpr {
735
+ constructor(op) {
736
+ super();
737
+ this.op = op;
738
+ }
739
+ getOp() {
740
+ return this.op;
741
+ }
742
+ setOp(newOp) {
743
+ this.op = newOp;
744
+ }
745
+ getUses() {
746
+ let uses = [];
747
+ uses.push(this.op);
748
+ uses.push(...this.op.getUses());
749
+ return uses;
750
+ }
751
+ getType() {
752
+ return Type_1.StringType.getInstance();
753
+ }
754
+ toString() {
755
+ return 'typeof ' + this.op;
756
+ }
757
+ }
758
+ exports.ArkTypeOfExpr = ArkTypeOfExpr;
759
+ class ArkInstanceOfExpr extends AbstractExpr {
760
+ constructor(op, checkType) {
761
+ super();
762
+ this.op = op;
763
+ this.checkType = checkType;
764
+ }
765
+ getOp() {
766
+ return this.op;
767
+ }
768
+ setOp(newOp) {
769
+ this.op = newOp;
770
+ }
771
+ getCheckType() {
772
+ return this.checkType;
773
+ }
774
+ getType() {
775
+ return Type_1.BooleanType.getInstance();
776
+ }
777
+ getUses() {
778
+ let uses = [];
779
+ uses.push(this.op);
780
+ uses.push(...this.op.getUses());
781
+ return uses;
782
+ }
783
+ toString() {
784
+ return this.op + ' instanceof ' + this.checkType;
785
+ }
786
+ }
787
+ exports.ArkInstanceOfExpr = ArkInstanceOfExpr;
788
+ // 类型转换
789
+ class ArkCastExpr extends AbstractExpr {
790
+ constructor(op, type) {
791
+ super();
792
+ this.op = op;
793
+ this.type = type;
794
+ }
795
+ getOp() {
796
+ return this.op;
797
+ }
798
+ setOp(newOp) {
799
+ this.op = newOp;
800
+ }
801
+ getUses() {
802
+ let uses = [];
803
+ uses.push(this.op);
804
+ uses.push(...this.op.getUses());
805
+ return uses;
806
+ }
807
+ getType() {
808
+ return this.type;
809
+ }
810
+ inferType(arkClass) {
811
+ var _a;
812
+ const type = (_a = TypeInference_1.TypeInference.inferUnclearedType(this.type, arkClass)) !== null && _a !== void 0 ? _a : this.op.getType();
813
+ if (!TypeInference_1.TypeInference.isUnclearType(type)) {
814
+ this.type = type;
815
+ }
816
+ return this;
817
+ }
818
+ toString() {
819
+ return '<' + this.type + '>' + this.op;
820
+ }
821
+ }
822
+ exports.ArkCastExpr = ArkCastExpr;
823
+ class ArkPhiExpr extends AbstractExpr {
824
+ constructor() {
825
+ super();
826
+ this.args = [];
827
+ this.argToBlock = new Map();
828
+ }
829
+ getUses() {
830
+ let uses = [];
831
+ uses.push(...this.args);
832
+ return uses;
833
+ }
834
+ getArgs() {
835
+ return this.args;
836
+ }
837
+ setArgs(args) {
838
+ this.args = args;
839
+ }
840
+ getArgToBlock() {
841
+ return this.argToBlock;
842
+ }
843
+ setArgToBlock(argToBlock) {
844
+ this.argToBlock = argToBlock;
845
+ }
846
+ getType() {
847
+ return this.args[0].getType();
848
+ }
849
+ toString() {
850
+ let strs = [];
851
+ strs.push('phi(');
852
+ if (this.args.length > 0) {
853
+ for (const arg of this.args) {
854
+ strs.push(arg.toString());
855
+ strs.push(', ');
856
+ }
857
+ strs.pop();
858
+ }
859
+ strs.push(')');
860
+ return strs.join('');
861
+ }
862
+ }
863
+ exports.ArkPhiExpr = ArkPhiExpr;
864
+ var UnaryOperator;
865
+ (function (UnaryOperator) {
866
+ UnaryOperator["Neg"] = "-";
867
+ UnaryOperator["BitwiseNot"] = "~";
868
+ UnaryOperator["LogicalNot"] = "!";
869
+ })(UnaryOperator = exports.UnaryOperator || (exports.UnaryOperator = {}));
870
+ // unary operation expression
871
+ class ArkUnopExpr extends AbstractExpr {
872
+ constructor(op, operator) {
873
+ super();
874
+ this.op = op;
875
+ this.operator = operator;
876
+ }
877
+ getUses() {
878
+ let uses = [];
879
+ uses.push(this.op);
880
+ uses.push(...this.op.getUses());
881
+ return uses;
882
+ }
883
+ getOp() {
884
+ return this.op;
885
+ }
886
+ getType() {
887
+ return this.op.getType();
888
+ }
889
+ getOperator() {
890
+ return this.operator;
891
+ }
892
+ toString() {
893
+ return this.operator + this.op;
894
+ }
895
+ }
896
+ exports.ArkUnopExpr = ArkUnopExpr;