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,757 @@
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.stmt2SourceStmt = exports.SourceNewArrayExpr = exports.SourceTypeAliasStmt = exports.SourceThrowStmt = exports.SourceCommonStmt = exports.SourceCompoundEndStmt = exports.SourceCaseStmt = exports.SourceSwitchStmt = exports.SourceReturnVoidStmt = exports.SourceReturnStmt = exports.SourceBreakStmt = exports.SourceContinueStmt = exports.SourceElseStmt = exports.SourceDoWhileStmt = exports.SourceDoStmt = exports.SourceForStmt = exports.SourceWhileStmt = exports.SourceIfStmt = exports.SourceInvokeStmt = exports.SourceAssignStmt = exports.SourceStmt = void 0;
41
+ const Constant_1 = require("../../core/base/Constant");
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 logger_1 = __importStar(require("../../utils/logger"));
48
+ const SourceBody_1 = require("./SourceBody");
49
+ const SourceTransformer_1 = require("./SourceTransformer");
50
+ const SourceUtils_1 = require("./SourceUtils");
51
+ const ValueUtil_1 = require("../../core/common/ValueUtil");
52
+ const ArkClass_1 = require("../../core/model/ArkClass");
53
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SourceStmt');
54
+ const IGNOR_TYPES = new Set(['any', 'Map', 'Set']);
55
+ class SourceStmt {
56
+ constructor(context, original) {
57
+ this.text = '';
58
+ this.original = original;
59
+ this.context = context;
60
+ this.line = original.getOriginPositionInfo().getLineNo();
61
+ this.transformer = new SourceTransformer_1.SourceTransformer(context);
62
+ }
63
+ getLine() {
64
+ return this.line;
65
+ }
66
+ setLine(line) {
67
+ this.line = line;
68
+ }
69
+ dump() {
70
+ this.beforeDump();
71
+ let code = this.dumpTs();
72
+ this.afterDump();
73
+ return code;
74
+ }
75
+ beforeDump() { }
76
+ afterDump() { }
77
+ dumpTs() {
78
+ if (this.text.length > 0) {
79
+ return `${this.printer.getIndent()}${this.text}\n`;
80
+ }
81
+ return ``;
82
+ }
83
+ get printer() {
84
+ return this.context.getPrinter();
85
+ }
86
+ toString() {
87
+ return this.text;
88
+ }
89
+ setText(text) {
90
+ this.text = text;
91
+ }
92
+ getIntent() {
93
+ return this.context.getPrinter().getIndent();
94
+ }
95
+ isLocalTempValue(value) {
96
+ if (!(value instanceof Local_1.Local)) {
97
+ return false;
98
+ }
99
+ return SourceUtils_1.SourceUtils.isTemp(value.getName());
100
+ }
101
+ }
102
+ exports.SourceStmt = SourceStmt;
103
+ var AssignStmtDumpType;
104
+ (function (AssignStmtDumpType) {
105
+ AssignStmtDumpType[AssignStmtDumpType["NORMAL"] = 0] = "NORMAL";
106
+ AssignStmtDumpType[AssignStmtDumpType["TEMP_REPLACE"] = 1] = "TEMP_REPLACE";
107
+ AssignStmtDumpType[AssignStmtDumpType["COMPONENT_CREATE"] = 2] = "COMPONENT_CREATE";
108
+ })(AssignStmtDumpType || (AssignStmtDumpType = {}));
109
+ class SourceAssignStmt extends SourceStmt {
110
+ constructor(context, original) {
111
+ super(context, original);
112
+ this.leftOp = ValueUtil_1.ValueUtil.getUndefinedConst();
113
+ this.rightOp = ValueUtil_1.ValueUtil.getUndefinedConst();
114
+ this.leftCode = '';
115
+ this.rightCode = '';
116
+ this.leftTypeCode = '';
117
+ }
118
+ transfer2ts() {
119
+ this.leftOp = this.original.getLeftOp();
120
+ this.rightOp = this.original.getRightOp();
121
+ if ((this.leftOp instanceof Local_1.Local && this.leftOp.getName() == 'this') ||
122
+ (this.rightOp instanceof Constant_1.Constant && this.rightOp.getValue() == 'undefined') ||
123
+ this.rightOp instanceof Ref_1.ArkParameterRef) {
124
+ this.setText('');
125
+ this.dumpType = AssignStmtDumpType.NORMAL;
126
+ return;
127
+ }
128
+ this.leftCode = this.transformer.valueToString(this.leftOp);
129
+ if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewExpr) {
130
+ this.transferRightNewExpr();
131
+ }
132
+ else if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewArrayExpr) {
133
+ this.transferRightNewArrayExpr();
134
+ }
135
+ else if (this.rightOp instanceof Expr_1.ArkStaticInvokeExpr && SourceUtils_1.SourceUtils.isComponentCreate(this.rightOp)) {
136
+ this.transferRightComponentCreate();
137
+ }
138
+ else if (this.rightOp instanceof Expr_1.ArkInstanceInvokeExpr &&
139
+ SourceUtils_1.SourceUtils.isComponentAttributeInvoke(this.rightOp)) {
140
+ this.transferRightComponentAttribute();
141
+ }
142
+ else {
143
+ this.rightCode = this.transformer.valueToString(this.rightOp);
144
+ }
145
+ if (this.isLocalTempValue(this.leftOp)) {
146
+ this.context.setTempCode(this.leftOp.getName(), this.rightCode);
147
+ }
148
+ if ((this.leftOp instanceof Ref_1.ArkInstanceFieldRef && this.leftOp.getBase().getName() == 'this') ||
149
+ this.leftOp instanceof Ref_1.ArkStaticFieldRef) {
150
+ this.context.setTempCode(this.leftOp.getFieldName(), this.rightCode);
151
+ }
152
+ if (this.dumpType == undefined) {
153
+ this.setText(`${this.leftCode} = ${this.rightCode}`);
154
+ this.dumpType = AssignStmtDumpType.TEMP_REPLACE;
155
+ }
156
+ let leftOpType = this.leftOp.getType();
157
+ if (leftOpType instanceof Type_1.ClassType) {
158
+ let name = leftOpType.getClassSignature().getClassName();
159
+ if (SourceUtils_1.SourceUtils.isAnonymousClass(name)) {
160
+ this.leftTypeCode = 'any';
161
+ }
162
+ else {
163
+ this.leftTypeCode = name;
164
+ }
165
+ }
166
+ else {
167
+ this.leftTypeCode = this.transformer.typeToString(leftOpType);
168
+ }
169
+ if (IGNOR_TYPES.has(this.leftTypeCode)) {
170
+ this.leftTypeCode = '';
171
+ }
172
+ }
173
+ beforeDump() {
174
+ if (this.dumpType != AssignStmtDumpType.TEMP_REPLACE) {
175
+ return;
176
+ }
177
+ if (this.context.hasTempVisit(this.leftCode)) {
178
+ this.setText('');
179
+ }
180
+ else if (SourceUtils_1.SourceUtils.isTemp(this.leftCode)) {
181
+ this.setText(`${this.rightCode};`);
182
+ }
183
+ else {
184
+ if (this.leftOp instanceof Local_1.Local &&
185
+ this.context.getLocals().has(this.leftOp.getName()) &&
186
+ !this.isLocalTempValue(this.leftOp)) {
187
+ if (this.context.isLocalDefined(this.leftOp)) {
188
+ this.setText(`${this.leftCode} = ${this.rightCode};`);
189
+ }
190
+ else {
191
+ let flag = this.leftOp.getConstFlag() ? 'const' : 'let';
192
+ if (this.context.getArkFile().getExportInfoBy(this.leftCode) && this.context.isInDefaultMethod()) {
193
+ this.setText(`export ${flag} ${this.leftCode} = ${this.rightCode};`);
194
+ }
195
+ else {
196
+ if (this.leftTypeCode.length > 0) {
197
+ this.setText(`${flag} ${this.leftCode}: ${this.leftTypeCode} = ${this.rightCode};`);
198
+ }
199
+ else {
200
+ this.setText(`${flag} ${this.leftCode} = ${this.rightCode};`);
201
+ }
202
+ }
203
+ this.context.defineLocal(this.leftOp);
204
+ }
205
+ }
206
+ else {
207
+ this.setText(`${this.leftCode} = ${this.rightCode};`);
208
+ }
209
+ }
210
+ }
211
+ afterDump() {
212
+ if (this.dumpType == AssignStmtDumpType.COMPONENT_CREATE) {
213
+ this.printer.incIndent();
214
+ }
215
+ }
216
+ getClassOriginType(type) {
217
+ if (!(type instanceof Type_1.ClassType)) {
218
+ return undefined;
219
+ }
220
+ let signature = type.getClassSignature();
221
+ let cls = this.context.getClass(signature);
222
+ if (!cls) {
223
+ return undefined;
224
+ }
225
+ return SourceUtils_1.SourceUtils.getOriginType(cls);
226
+ }
227
+ /**
228
+ * temp1 = new Person
229
+ * temp1.constructor(10)
230
+ */
231
+ transferRightNewExpr() {
232
+ let originType = this.getClassOriginType(this.rightOp.getType());
233
+ if (this.context.getStmtReader().hasNext()) {
234
+ let stmt = this.context.getStmtReader().next();
235
+ let rollback = true;
236
+ if (stmt instanceof Stmt_1.ArkInvokeStmt && stmt.getInvokeExpr()) {
237
+ let instanceInvokeExpr = stmt.getInvokeExpr();
238
+ if ('constructor' == instanceInvokeExpr.getMethodSignature().getMethodSubSignature().getMethodName() &&
239
+ instanceInvokeExpr.getBase().getName() == this.leftOp.getName()) {
240
+ let args = [];
241
+ instanceInvokeExpr.getArgs().forEach((v) => {
242
+ args.push(this.transformer.valueToString(v));
243
+ });
244
+ if (originType == SourceUtils_1.CLASS_CATEGORY_COMPONENT) {
245
+ this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
246
+ }
247
+ else if (originType == ArkClass_1.ClassCategory.TYPE_LITERAL || originType == ArkClass_1.ClassCategory.OBJECT) {
248
+ this.rightCode = `${this.transformer.literalObjectToString(this.rightOp.getType())}`;
249
+ }
250
+ else {
251
+ this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
252
+ }
253
+ return;
254
+ }
255
+ }
256
+ if (rollback) {
257
+ this.context.getStmtReader().rollback();
258
+ }
259
+ }
260
+ if (originType == SourceUtils_1.CLASS_CATEGORY_COMPONENT) {
261
+ this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}()`;
262
+ }
263
+ else if (originType == ArkClass_1.ClassCategory.TYPE_LITERAL || originType == ArkClass_1.ClassCategory.OBJECT) {
264
+ this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}`;
265
+ }
266
+ else {
267
+ this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}()`;
268
+ }
269
+ }
270
+ /**
271
+ * $temp0 = newarray[4]
272
+ * $temp0[0] = 1
273
+ * $temp0[1] = 2
274
+ * $temp0[2] = 3
275
+ */
276
+ transferRightNewArrayExpr() {
277
+ let arrayExpr = new SourceNewArrayExpr(this.rightOp);
278
+ let localName = this.leftOp.getName();
279
+ while (this.context.getStmtReader().hasNext()) {
280
+ let stmt = this.context.getStmtReader().next();
281
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
282
+ let left = stmt.getLeftOp();
283
+ if (left instanceof Ref_1.ArkArrayRef && left.getBase().getName() == localName) {
284
+ arrayExpr.addInitValue(this.transformer.valueToString(stmt.getRightOp()));
285
+ }
286
+ else {
287
+ this.context.getStmtReader().rollback();
288
+ break;
289
+ }
290
+ }
291
+ else {
292
+ this.context.getStmtReader().rollback();
293
+ break;
294
+ }
295
+ }
296
+ this.rightCode = arrayExpr.toString();
297
+ }
298
+ transferRightComponentCreate() {
299
+ this.rightCode = this.transformer.valueToString(this.rightOp);
300
+ if (this.context.getStmtReader().hasNext()) {
301
+ let stmt = this.context.getStmtReader().next();
302
+ if (stmt instanceof Stmt_1.ArkInvokeStmt) {
303
+ let expr = stmt.getInvokeExpr();
304
+ if (expr instanceof Expr_1.ArkStaticInvokeExpr && SourceUtils_1.SourceUtils.isComponentPop(expr)) {
305
+ this.setText(`${this.rightCode}`);
306
+ this.dumpType = AssignStmtDumpType.NORMAL;
307
+ return;
308
+ }
309
+ }
310
+ this.context.getStmtReader().rollback();
311
+ }
312
+ this.setText(`${this.rightCode} {`);
313
+ this.dumpType = AssignStmtDumpType.COMPONENT_CREATE;
314
+ }
315
+ transferRightComponentAttribute() {
316
+ this.rightCode = this.transformer.valueToString(this.rightOp);
317
+ this.setText(`${this.rightCode}`);
318
+ this.dumpType = AssignStmtDumpType.NORMAL;
319
+ }
320
+ }
321
+ exports.SourceAssignStmt = SourceAssignStmt;
322
+ class SourceInvokeStmt extends SourceStmt {
323
+ constructor(context, original) {
324
+ super(context, original);
325
+ }
326
+ transfer2ts() {
327
+ let invokeExpr = this.original.getInvokeExpr();
328
+ let code = '';
329
+ let isAttr = false;
330
+ if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr) {
331
+ if (SourceUtils_1.SourceUtils.isComponentPop(invokeExpr)) {
332
+ code = '}';
333
+ isAttr = true;
334
+ }
335
+ else {
336
+ code = this.transformer.staticInvokeExprToString(invokeExpr);
337
+ isAttr = SourceUtils_1.SourceUtils.isComponentIfElseInvoke(invokeExpr);
338
+ }
339
+ }
340
+ else if (invokeExpr instanceof Expr_1.ArkInstanceInvokeExpr) {
341
+ code = this.transformer.instanceInvokeExprToString(invokeExpr);
342
+ isAttr = SourceUtils_1.SourceUtils.isComponentAttributeInvoke(invokeExpr);
343
+ }
344
+ if (code.length > 0 && !isAttr) {
345
+ this.setText(`${code};`);
346
+ }
347
+ else {
348
+ this.setText(`${code}`);
349
+ }
350
+ }
351
+ beforeDump() {
352
+ let invokeExpr = this.original.getInvokeExpr();
353
+ if ((invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && SourceUtils_1.SourceUtils.isComponentPop(invokeExpr)) ||
354
+ (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && SourceUtils_1.SourceUtils.isComponentIfElseInvoke(invokeExpr))) {
355
+ this.printer.decIndent();
356
+ return;
357
+ }
358
+ }
359
+ afterDump() {
360
+ let invokeExpr = this.original.getInvokeExpr();
361
+ if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && SourceUtils_1.SourceUtils.isComponentIfElseInvoke(invokeExpr)) {
362
+ this.printer.incIndent();
363
+ return;
364
+ }
365
+ }
366
+ }
367
+ exports.SourceInvokeStmt = SourceInvokeStmt;
368
+ class SourceIfStmt extends SourceStmt {
369
+ constructor(context, original) {
370
+ super(context, original);
371
+ }
372
+ transfer2ts() {
373
+ let code;
374
+ let expr = this.original.getConditionExprExpr();
375
+ code = `if (${this.transformer.valueToString(expr.getOp1())}`;
376
+ code += ` ${expr.getOperator()} `;
377
+ code += `${this.transformer.valueToString(expr.getOp2())}) {`;
378
+ this.setText(code);
379
+ }
380
+ afterDump() {
381
+ this.printer.incIndent();
382
+ }
383
+ }
384
+ exports.SourceIfStmt = SourceIfStmt;
385
+ class SourceWhileStmt extends SourceStmt {
386
+ constructor(context, original, block) {
387
+ super(context, original);
388
+ this.block = block;
389
+ }
390
+ afterDump() {
391
+ this.printer.incIndent();
392
+ }
393
+ /**
394
+ * $temp2 = $temp1.next()
395
+ * $temp3 = $temp2.done()
396
+ * if $temp3 == true
397
+ * $temp4 = $temp2.value
398
+ * $temp5 = <> cast
399
+ * @returns
400
+ */
401
+ forOf2ts() {
402
+ let expr = this.original.getConditionExprExpr();
403
+ let temp3 = expr.getOp1();
404
+ let op2 = expr.getOp2();
405
+ let firstStmt = this.context.getStmtReader().first();
406
+ if (!(firstStmt instanceof Stmt_1.ArkAssignStmt)) {
407
+ return false;
408
+ }
409
+ if (!(this.isLocalTempValue(temp3) && op2 instanceof Constant_1.Constant && op2.getValue() == 'true')) {
410
+ return false;
411
+ }
412
+ let stmt = temp3.getDeclaringStmt();
413
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
414
+ return false;
415
+ }
416
+ let done = stmt.getRightOp();
417
+ if (!(done instanceof Ref_1.ArkInstanceFieldRef)) {
418
+ return false;
419
+ }
420
+ if (done.getFieldSignature().toString() != '@ES2015/BuiltinClass: IteratorResult.done') {
421
+ return false;
422
+ }
423
+ let temp2 = done.getBase();
424
+ if (!(temp2 instanceof Local_1.Local)) {
425
+ return false;
426
+ }
427
+ stmt = temp2.getDeclaringStmt();
428
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
429
+ return false;
430
+ }
431
+ let next = stmt.getRightOp();
432
+ if (!(next instanceof Expr_1.ArkInstanceInvokeExpr)) {
433
+ return false;
434
+ }
435
+ if (next.getMethodSignature().getMethodSubSignature().getMethodName() != 'next') {
436
+ return false;
437
+ }
438
+ let temp1 = next.getBase();
439
+ if (!(temp1 instanceof Local_1.Local)) {
440
+ return false;
441
+ }
442
+ stmt = temp1.getDeclaringStmt();
443
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
444
+ return false;
445
+ }
446
+ let iterator = stmt.getRightOp();
447
+ if (!(iterator instanceof Expr_1.ArkInstanceInvokeExpr)) {
448
+ return false;
449
+ }
450
+ if (iterator.getMethodSignature().getMethodSubSignature().getMethodName() != 'iterator') {
451
+ return false;
452
+ }
453
+ let successors = this.block.getSuccessors();
454
+ if (successors.length != 2) {
455
+ return false;
456
+ }
457
+ let stmts = successors[0].getStmts();
458
+ if (stmts.length < 2) {
459
+ return false;
460
+ }
461
+ stmt = stmts[1];
462
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
463
+ return false;
464
+ }
465
+ this.context.setSkipStmt(stmts[0]);
466
+ this.context.setSkipStmt(stmts[1]);
467
+ while (this.context.getStmtReader().hasNext()) {
468
+ this.context.getStmtReader().next();
469
+ }
470
+ let v = stmt.getLeftOp();
471
+ let valueName = v.getName();
472
+ if (!this.isLocalTempValue(v)) {
473
+ this.setText(`for (let ${valueName} of ${this.transformer.valueToString(iterator.getBase())}) {`);
474
+ this.context.setTempVisit(temp1.getName());
475
+ this.context.setTempVisit(temp3.getName());
476
+ return true;
477
+ }
478
+ // iterate map 'for (let [key, value] of map)'
479
+ let stmtReader = new SourceBody_1.StmtReader(stmts);
480
+ stmtReader.next();
481
+ stmtReader.next();
482
+ let arrayValueNames = [];
483
+ while (stmtReader.hasNext()) {
484
+ stmt = stmtReader.next();
485
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
486
+ break;
487
+ }
488
+ let ref = stmt.getRightOp();
489
+ if (!(ref instanceof Ref_1.ArkArrayRef)) {
490
+ break;
491
+ }
492
+ if (ref.getBase().getName() != valueName) {
493
+ break;
494
+ }
495
+ let name = stmt.getLeftOp().getName();
496
+ arrayValueNames.push(name);
497
+ this.context.setTempVisit(name);
498
+ }
499
+ this.setText(`for (let [${arrayValueNames.join(', ')}] of ${this.transformer.valueToString(iterator.getBase())}) {`);
500
+ this.context.setTempVisit(temp3.getName());
501
+ return true;
502
+ }
503
+ transfer2ts() {
504
+ if (this.forOf2ts()) {
505
+ return;
506
+ }
507
+ let code;
508
+ let expr = this.original.getConditionExprExpr();
509
+ code = `while (${this.valueToString(expr.getOp1())}`;
510
+ code += ` ${expr.getOperator().trim()} `;
511
+ code += `${this.valueToString(expr.getOp2())}) {`;
512
+ this.setText(code);
513
+ }
514
+ valueToString(value) {
515
+ if (!(value instanceof Local_1.Local)) {
516
+ return this.transformer.valueToString(value);
517
+ }
518
+ for (const stmt of this.block.getStmts()) {
519
+ if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
520
+ continue;
521
+ }
522
+ if (SourceUtils_1.SourceUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Addition) &&
523
+ stmt.getLeftOp().getName() == value.getName()) {
524
+ this.context.setSkipStmt(stmt);
525
+ return `${value.getName()}++`;
526
+ }
527
+ if (SourceUtils_1.SourceUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Subtraction) &&
528
+ stmt.getLeftOp().getName() == value.getName()) {
529
+ this.context.setSkipStmt(stmt);
530
+ return `${value.getName()}--`;
531
+ }
532
+ }
533
+ return this.transformer.valueToString(value);
534
+ }
535
+ }
536
+ exports.SourceWhileStmt = SourceWhileStmt;
537
+ class SourceForStmt extends SourceWhileStmt {
538
+ constructor(context, original, block, incBlock) {
539
+ super(context, original, block);
540
+ this.incBlock = incBlock;
541
+ }
542
+ transfer2ts() {
543
+ let code;
544
+ let expr = this.original.getConditionExprExpr();
545
+ code = `for (; ${this.transformer.valueToString(expr.getOp1())}`;
546
+ code += ` ${expr.getOperator().trim()} `;
547
+ code += `${this.transformer.valueToString(expr.getOp2())}; `;
548
+ let stmtReader = new SourceBody_1.StmtReader(this.incBlock.getStmts());
549
+ while (stmtReader.hasNext()) {
550
+ let sourceStmt = stmt2SourceStmt(this.context, stmtReader.next());
551
+ sourceStmt.transfer2ts();
552
+ code += sourceStmt.toString();
553
+ if (stmtReader.hasNext()) {
554
+ code += ', ';
555
+ }
556
+ }
557
+ code += `) {`;
558
+ this.setText(code);
559
+ }
560
+ }
561
+ exports.SourceForStmt = SourceForStmt;
562
+ class SourceDoStmt extends SourceStmt {
563
+ constructor(context, stmt) {
564
+ super(context, stmt);
565
+ }
566
+ transfer2ts() {
567
+ this.setText('do {');
568
+ }
569
+ afterDump() {
570
+ this.printer.incIndent();
571
+ }
572
+ }
573
+ exports.SourceDoStmt = SourceDoStmt;
574
+ class SourceDoWhileStmt extends SourceWhileStmt {
575
+ constructor(context, stmt, block) {
576
+ super(context, stmt, block);
577
+ }
578
+ transfer2ts() {
579
+ let code;
580
+ let expr = this.original.getConditionExprExpr();
581
+ code = `} while (${this.valueToString(expr.getOp1())}`;
582
+ code += ` ${expr.getOperator().trim()} `;
583
+ code += `${this.valueToString(expr.getOp2())})`;
584
+ this.setText(code);
585
+ }
586
+ beforeDump() {
587
+ this.printer.decIndent();
588
+ }
589
+ afterDump() { }
590
+ }
591
+ exports.SourceDoWhileStmt = SourceDoWhileStmt;
592
+ class SourceElseStmt extends SourceStmt {
593
+ constructor(context, original) {
594
+ super(context, original);
595
+ }
596
+ transfer2ts() {
597
+ this.setText('} else {');
598
+ }
599
+ beforeDump() {
600
+ this.printer.decIndent();
601
+ }
602
+ afterDump() {
603
+ this.printer.incIndent();
604
+ }
605
+ }
606
+ exports.SourceElseStmt = SourceElseStmt;
607
+ class SourceContinueStmt extends SourceStmt {
608
+ constructor(context, original) {
609
+ super(context, original);
610
+ }
611
+ // trans 2 break or continue
612
+ transfer2ts() {
613
+ this.setText('continue;');
614
+ }
615
+ }
616
+ exports.SourceContinueStmt = SourceContinueStmt;
617
+ class SourceBreakStmt extends SourceStmt {
618
+ constructor(context, original) {
619
+ super(context, original);
620
+ }
621
+ // trans 2 break or continue
622
+ transfer2ts() {
623
+ this.setText('break;');
624
+ }
625
+ }
626
+ exports.SourceBreakStmt = SourceBreakStmt;
627
+ class SourceReturnStmt extends SourceStmt {
628
+ constructor(context, original) {
629
+ super(context, original);
630
+ }
631
+ transfer2ts() {
632
+ this.setText(`return ${this.transformer.valueToString(this.original.getOp())};`);
633
+ }
634
+ }
635
+ exports.SourceReturnStmt = SourceReturnStmt;
636
+ class SourceReturnVoidStmt extends SourceStmt {
637
+ constructor(context, original) {
638
+ super(context, original);
639
+ }
640
+ transfer2ts() {
641
+ if (this.original.getOriginPositionInfo().getLineNo() <= 0) {
642
+ this.setText('');
643
+ }
644
+ else {
645
+ this.setText('return;');
646
+ }
647
+ }
648
+ }
649
+ exports.SourceReturnVoidStmt = SourceReturnVoidStmt;
650
+ class SourceSwitchStmt extends SourceStmt {
651
+ constructor(context, original) {
652
+ super(context, original);
653
+ }
654
+ transfer2ts() {
655
+ this.setText(`switch (${this.transformer.valueToString(this.original.getKey())}) {`);
656
+ }
657
+ afterDump() {
658
+ this.printer.incIndent();
659
+ }
660
+ }
661
+ exports.SourceSwitchStmt = SourceSwitchStmt;
662
+ class SourceCaseStmt extends SourceStmt {
663
+ constructor(context, original, index) {
664
+ super(context, original);
665
+ this.caseIndex = index;
666
+ }
667
+ isDefault() {
668
+ let cases = this.original.getCases();
669
+ return this.caseIndex >= cases.length;
670
+ }
671
+ transfer2ts() {
672
+ let cases = this.original.getCases();
673
+ if (this.caseIndex < cases.length) {
674
+ let value = this.original.getCases()[this.caseIndex];
675
+ this.setText(`case ${this.transformer.valueToString(value)}:`);
676
+ }
677
+ else {
678
+ this.setText('default: ');
679
+ }
680
+ }
681
+ afterDump() {
682
+ this.printer.incIndent();
683
+ }
684
+ }
685
+ exports.SourceCaseStmt = SourceCaseStmt;
686
+ class SourceCompoundEndStmt extends SourceStmt {
687
+ constructor(context, stmt, text) {
688
+ super(context, stmt);
689
+ this.setText(text);
690
+ }
691
+ transfer2ts() { }
692
+ beforeDump() {
693
+ this.printer.decIndent();
694
+ }
695
+ }
696
+ exports.SourceCompoundEndStmt = SourceCompoundEndStmt;
697
+ class SourceCommonStmt extends SourceStmt {
698
+ constructor(context, stmt) {
699
+ super(context, stmt);
700
+ }
701
+ transfer2ts() {
702
+ this.setText(this.original.toString());
703
+ }
704
+ }
705
+ exports.SourceCommonStmt = SourceCommonStmt;
706
+ class SourceThrowStmt extends SourceStmt {
707
+ constructor(context, original) {
708
+ super(context, original);
709
+ }
710
+ transfer2ts() {
711
+ this.setText(`throw ${this.transformer.valueToString(this.original.getOp())};`);
712
+ }
713
+ }
714
+ exports.SourceThrowStmt = SourceThrowStmt;
715
+ class SourceTypeAliasStmt extends SourceStmt {
716
+ constructor(context, original, aliasType) {
717
+ super(context, original);
718
+ this.aliasType = aliasType;
719
+ }
720
+ transfer2ts() {
721
+ this.setText(`type ${this.aliasType.getName()} = ${this.transformer.typeToString(this.aliasType.getOriginalType())};`);
722
+ }
723
+ }
724
+ exports.SourceTypeAliasStmt = SourceTypeAliasStmt;
725
+ class SourceNewArrayExpr {
726
+ constructor(expr) {
727
+ this.expr = expr;
728
+ this.values = [];
729
+ }
730
+ addInitValue(value) {
731
+ this.values.push(value);
732
+ }
733
+ toString() {
734
+ return `[${this.values.join(', ')}]`;
735
+ }
736
+ }
737
+ exports.SourceNewArrayExpr = SourceNewArrayExpr;
738
+ function stmt2SourceStmt(context, stmt) {
739
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
740
+ return new SourceAssignStmt(context, stmt);
741
+ }
742
+ if (stmt instanceof Stmt_1.ArkInvokeStmt) {
743
+ return new SourceInvokeStmt(context, stmt);
744
+ }
745
+ if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
746
+ return new SourceReturnVoidStmt(context, stmt);
747
+ }
748
+ if (stmt instanceof Stmt_1.ArkReturnStmt) {
749
+ return new SourceReturnStmt(context, stmt);
750
+ }
751
+ if (stmt instanceof Stmt_1.ArkThrowStmt) {
752
+ return new SourceThrowStmt(context, stmt);
753
+ }
754
+ logger.info(`stmt2SourceStmt ${stmt.constructor} not support.`);
755
+ return new SourceCommonStmt(context, stmt);
756
+ }
757
+ exports.stmt2SourceStmt = stmt2SourceStmt;