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,135 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.GraphPrinter = void 0;
18
+ const Printer_1 = require("./Printer");
19
+ function escapeStr(input) {
20
+ let str = input;
21
+ for (let i = 0; i < str.length; ++i) {
22
+ switch (str[i]) {
23
+ case '\n':
24
+ str = str.substring(0, i) + '\\n' + str.substring(i + 1);
25
+ ++i;
26
+ break;
27
+ case '\t':
28
+ str = str.substring(0, i) + ' ' + str.substring(i + 1);
29
+ ++i;
30
+ break;
31
+ case '\\':
32
+ if (i + 1 < str.length) {
33
+ switch (str[i + 1]) {
34
+ case 'l':
35
+ continue; // don't disturb \l
36
+ case '|':
37
+ case '{':
38
+ case '}':
39
+ str = str.substring(0, i) + str.substring(i + 1);
40
+ continue;
41
+ default:
42
+ break;
43
+ }
44
+ }
45
+ str = str.substring(0, i) + '\\\\' + str.substring(i + 1);
46
+ ++i;
47
+ break;
48
+ case '{':
49
+ case '}':
50
+ case '<':
51
+ case '>':
52
+ case '|':
53
+ case '"':
54
+ str = str.substring(0, i) + '\\' + str[i] + str.substring(i + 1);
55
+ ++i;
56
+ break;
57
+ }
58
+ }
59
+ return str;
60
+ }
61
+ class GraphPrinter extends Printer_1.Printer {
62
+ constructor(g, t) {
63
+ super();
64
+ this.startID = undefined;
65
+ this.graph = g;
66
+ if (t) {
67
+ this.title = t;
68
+ }
69
+ }
70
+ setStartID(n) {
71
+ this.startID = n;
72
+ }
73
+ dump() {
74
+ this.printer.clear();
75
+ this.writeGraph();
76
+ return this.printer.toString();
77
+ }
78
+ dumpOriginal() {
79
+ return "";
80
+ }
81
+ writeGraph() {
82
+ this.writeHeader();
83
+ this.writeNodes();
84
+ this.writeFooter();
85
+ }
86
+ writeNodes() {
87
+ var _a;
88
+ let itor = this.graph.nodesItor();
89
+ if (this.startID) {
90
+ // from start id
91
+ let nodes = new Set();
92
+ let startNode = this.graph.getNode(this.startID);
93
+ let worklist = [startNode];
94
+ while (worklist.length > 0) {
95
+ let n = worklist.shift();
96
+ if (nodes.has(n)) {
97
+ continue;
98
+ }
99
+ nodes.add(n);
100
+ (_a = n.getOutgoingEdges()) === null || _a === void 0 ? void 0 : _a.forEach(e => worklist.push(e.getDstNode()));
101
+ }
102
+ itor = nodes.values();
103
+ }
104
+ for (let node of itor) {
105
+ let nodeAttr = node.getDotAttr();
106
+ if (nodeAttr == '') {
107
+ continue;
108
+ }
109
+ let nodeLabel = escapeStr(node.getDotLabel());
110
+ this.printer.writeLine(`\tNode${node.getID()} [shape=recode,${nodeAttr},label="${nodeLabel}"];`);
111
+ for (let edge of node.getOutgoingEdges()) {
112
+ this.writeEdge(edge);
113
+ }
114
+ }
115
+ }
116
+ writeEdge(edge) {
117
+ let edgeAttr = edge.getDotAttr();
118
+ if (edgeAttr == '') {
119
+ return;
120
+ }
121
+ this.printer.writeLine(`\tNode${edge.getSrcID()} -> Node${edge.getDstID()}[${edgeAttr}]`);
122
+ }
123
+ writeHeader() {
124
+ const GraphName = this.graph.getGraphName();
125
+ let graphNameStr = `digraph "${escapeStr(this.title || GraphName || 'unnamed')}" {\n`;
126
+ this.printer.writeLine(graphNameStr);
127
+ let labelStr = `\tlabel="${escapeStr(this.title || GraphName)}";\n`;
128
+ this.printer.writeLine(labelStr);
129
+ // TODO: need graph attr?
130
+ }
131
+ writeFooter() {
132
+ this.printer.writeLine("}\n");
133
+ }
134
+ }
135
+ exports.GraphPrinter = GraphPrinter;
@@ -0,0 +1,28 @@
1
+ import { Printer } from './Printer';
2
+ import { ArkFile } from '../core/model/ArkFile';
3
+ export declare class JsonPrinter extends Printer {
4
+ private arkFile;
5
+ constructor(arkFile: ArkFile);
6
+ dump(): string;
7
+ dumpOriginal(): string;
8
+ private serializeArkFile;
9
+ private serializeNamespace;
10
+ private serializeClass;
11
+ private serializeField;
12
+ private serializeMethod;
13
+ private serializeMethodBody;
14
+ private serializeMethodParameter;
15
+ private serializeImportInfo;
16
+ private serializeExportInfo;
17
+ private serializeLineColPosition;
18
+ private serializeType;
19
+ private serializeClassSignature;
20
+ private serializeFieldSignature;
21
+ private serializeMethodSignature;
22
+ private serializeCfg;
23
+ private serializeBasicBlock;
24
+ private serializeLocal;
25
+ private serializeValue;
26
+ private serializeStmt;
27
+ }
28
+ //# sourceMappingURL=JsonPrinter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonPrinter.d.ts","sourceRoot":"","sources":["../../src/save/JsonPrinter.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAgEhD,qBAAa,WAAY,SAAQ,OAAO;IACxB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAI7B,IAAI,IAAI,MAAM;IAKd,YAAY,IAAI,MAAM;IAI7B,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,wBAAwB;IAOhC,OAAO,CAAC,aAAa;IAyFrB,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAmJtB,OAAO,CAAC,aAAa;CA4CxB"}
@@ -0,0 +1,511 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.JsonPrinter = void 0;
18
+ const Printer_1 = require("./Printer");
19
+ const Type_1 = require("../core/base/Type");
20
+ const Stmt_1 = require("../core/base/Stmt");
21
+ const Expr_1 = require("../core/base/Expr");
22
+ const Constant_1 = require("../core/base/Constant");
23
+ const Ref_1 = require("../core/base/Ref");
24
+ const Local_1 = require("../core/base/Local");
25
+ class JsonPrinter extends Printer_1.Printer {
26
+ constructor(arkFile) {
27
+ super();
28
+ this.arkFile = arkFile;
29
+ }
30
+ dump() {
31
+ const jsonObject = this.serializeArkFile(this.arkFile);
32
+ return JSON.stringify(jsonObject, null, 2);
33
+ }
34
+ dumpOriginal() {
35
+ return "";
36
+ }
37
+ serializeArkFile(arkFile) {
38
+ return {
39
+ name: arkFile.getName(),
40
+ namespaces: arkFile
41
+ .getNamespaces()
42
+ .map((ns) => this.serializeNamespace(ns)),
43
+ classes: arkFile
44
+ .getClasses()
45
+ .map((cls) => this.serializeClass(cls)),
46
+ importInfos: arkFile
47
+ .getImportInfos()
48
+ .map((info) => this.serializeImportInfo(info)),
49
+ exportInfos: arkFile
50
+ .getExportInfos().map((info) => this.serializeExportInfo(info)),
51
+ };
52
+ }
53
+ serializeNamespace(ns) {
54
+ return {
55
+ name: ns.getName(),
56
+ namespaces: ns.getNamespaces().map((ns) => this.serializeNamespace(ns)),
57
+ classes: ns.getClasses().map((cls) => this.serializeClass(cls)),
58
+ };
59
+ }
60
+ serializeClass(cls) {
61
+ var _a;
62
+ return {
63
+ signature: this.serializeClassSignature(cls.getSignature()),
64
+ modifiers: Array.from(cls.getModifiers()),
65
+ typeParameters: (_a = cls.getGenericsTypes()) === null || _a === void 0 ? void 0 : _a.map((type) => this.serializeType(type)),
66
+ superClassName: cls.getSuperClassName(),
67
+ implementedInterfaceNames: cls.getImplementedInterfaceNames(),
68
+ fields: cls.getFields().map((field) => this.serializeField(field)),
69
+ methods: cls.getMethods(true).map((method) => this.serializeMethod(method)),
70
+ };
71
+ }
72
+ serializeField(field) {
73
+ return {
74
+ signature: this.serializeFieldSignature(field.getSignature()),
75
+ modifiers: Array.from(field.getModifiers()),
76
+ questionToken: field.getQuestionToken(),
77
+ exclamationToken: field.getExclamationToken(),
78
+ };
79
+ }
80
+ serializeMethod(method) {
81
+ var _a;
82
+ return {
83
+ signature: this.serializeMethodSignature(method.getSignature()),
84
+ modifiers: Array.from(method.getModifiers()),
85
+ typeParameters: ((_a = method.getGenericTypes()) === null || _a === void 0 ? void 0 : _a.map(type => this.serializeType(type))) || [],
86
+ body: this.serializeMethodBody(method.getBody()),
87
+ };
88
+ }
89
+ serializeMethodBody(body) {
90
+ if (body === undefined) {
91
+ return null;
92
+ }
93
+ return {
94
+ locals: Array.from(body.getLocals().values()).map(local => this.serializeLocal(local)),
95
+ cfg: this.serializeCfg(body.getCfg()),
96
+ };
97
+ }
98
+ serializeMethodParameter(parameter) {
99
+ return {
100
+ name: parameter.getName(),
101
+ type: this.serializeType(parameter.getType()),
102
+ isOptional: parameter.isOptional(),
103
+ };
104
+ }
105
+ serializeImportInfo(importInfo) {
106
+ return {
107
+ importClauseName: importInfo.getImportClauseName(),
108
+ importType: importInfo.getImportType(),
109
+ importFrom: importInfo.getFrom(),
110
+ nameBeforeAs: importInfo.getNameBeforeAs(),
111
+ modifiers: Array.from(importInfo.getModifiers()),
112
+ originTsPosition: this.serializeLineColPosition(importInfo.getOriginTsPosition()),
113
+ };
114
+ }
115
+ serializeExportInfo(exportInfo) {
116
+ return {
117
+ exportClauseName: exportInfo.getExportClauseName(),
118
+ exportClauseType: exportInfo.getExportClauseType(),
119
+ exportFrom: exportInfo.getFrom(),
120
+ nameBeforeAs: exportInfo.getNameBeforeAs(),
121
+ isDefault: exportInfo.isDefault(),
122
+ modifiers: Array.from(exportInfo.getModifiers()),
123
+ originTsPosition: this.serializeLineColPosition(exportInfo.getOriginTsPosition()),
124
+ };
125
+ }
126
+ serializeLineColPosition(position) {
127
+ return {
128
+ line: position.getLineNo(),
129
+ col: position.getColNo(),
130
+ };
131
+ }
132
+ serializeType(type) {
133
+ if (type === undefined) {
134
+ return {
135
+ "_": "UnknownType"
136
+ };
137
+ }
138
+ if (type instanceof Type_1.AnyType) {
139
+ return {
140
+ "_": "AnyType"
141
+ };
142
+ }
143
+ else if (type instanceof Type_1.UnknownType) {
144
+ return {
145
+ "_": "UnknownType"
146
+ };
147
+ }
148
+ else if (type instanceof Type_1.VoidType) {
149
+ return {
150
+ "_": "VoidType"
151
+ };
152
+ }
153
+ else if (type instanceof Type_1.NeverType) {
154
+ return {
155
+ "_": "NeverType"
156
+ };
157
+ }
158
+ else if (type instanceof Type_1.UnionType) {
159
+ return {
160
+ "_": "UnionType",
161
+ "types": type.getTypes().map(t => this.serializeType(t)),
162
+ };
163
+ }
164
+ else if (type instanceof Type_1.TupleType) {
165
+ return {
166
+ "_": "TupleType",
167
+ "types": type.getTypes().map(t => this.serializeType(t)),
168
+ };
169
+ }
170
+ else if (type instanceof Type_1.BooleanType) {
171
+ return {
172
+ "_": "BooleanType"
173
+ };
174
+ }
175
+ else if (type instanceof Type_1.NumberType) {
176
+ return {
177
+ "_": "NumberType"
178
+ };
179
+ }
180
+ else if (type instanceof Type_1.StringType) {
181
+ return {
182
+ "_": "StringType"
183
+ };
184
+ }
185
+ else if (type instanceof Type_1.NullType) {
186
+ return {
187
+ "_": "NullType"
188
+ };
189
+ }
190
+ else if (type instanceof Type_1.UndefinedType) {
191
+ return {
192
+ "_": "UndefinedType"
193
+ };
194
+ }
195
+ else if (type instanceof Type_1.LiteralType) {
196
+ return {
197
+ "_": "LiteralType",
198
+ "literal": type.getLiteralName(),
199
+ };
200
+ }
201
+ else if (type instanceof Type_1.PrimitiveType) {
202
+ throw new Error("Unhandled PrimitiveType: " + type.toString());
203
+ }
204
+ else if (type instanceof Type_1.ClassType) {
205
+ return {
206
+ "_": "ClassType",
207
+ "signature": this.serializeClassSignature(type.getClassSignature()),
208
+ };
209
+ }
210
+ else if (type instanceof Type_1.FunctionType) {
211
+ return {
212
+ "_": "FunctionType",
213
+ "signature": this.serializeMethodSignature(type.getMethodSignature()),
214
+ };
215
+ }
216
+ else if (type instanceof Type_1.ArrayType) {
217
+ return {
218
+ "_": "ArrayType",
219
+ "elementType": this.serializeType(type.getBaseType()),
220
+ "dimensions": type.getDimension(),
221
+ };
222
+ }
223
+ else if (type instanceof Type_1.UnclearReferenceType) {
224
+ return {
225
+ "_": "UnclearReferenceType",
226
+ "name": type.getName(),
227
+ };
228
+ }
229
+ else {
230
+ return {
231
+ "_": "UNKNOWN_TYPE",
232
+ "type": type.toString(),
233
+ };
234
+ }
235
+ }
236
+ serializeClassSignature(clazz) {
237
+ return {
238
+ name: clazz.getClassName(),
239
+ };
240
+ }
241
+ serializeFieldSignature(field) {
242
+ return {
243
+ // TODO: handle NOT class signature
244
+ enclosingClass: this.serializeClassSignature(field.getDeclaringSignature()),
245
+ name: field.getFieldName(),
246
+ type: this.serializeType(field.getType()),
247
+ };
248
+ }
249
+ serializeMethodSignature(method) {
250
+ return {
251
+ enclosingClass: this.serializeClassSignature(method.getDeclaringClassSignature()),
252
+ name: method.getMethodSubSignature().getMethodName(),
253
+ parameters: method
254
+ .getMethodSubSignature()
255
+ .getParameters()
256
+ .map(param => this.serializeMethodParameter(param)),
257
+ returnType: this.serializeType(method.getType()),
258
+ };
259
+ }
260
+ serializeCfg(cfg) {
261
+ // Traverse CFG basic blocks and fill their `id` fields in topological order:
262
+ const visited = new Set();
263
+ const stack = [];
264
+ const startingBlock = cfg.getStartingBlock();
265
+ if (startingBlock) {
266
+ stack.push(startingBlock);
267
+ }
268
+ let id = 0;
269
+ while (stack.length > 0) {
270
+ const block = stack.pop();
271
+ if (visited.has(block)) {
272
+ continue;
273
+ }
274
+ visited.add(block);
275
+ block.setId(id++);
276
+ stack.push(...block.getSuccessors());
277
+ }
278
+ return {
279
+ blocks: Array.from(visited).map(block => this.serializeBasicBlock(block)),
280
+ };
281
+ }
282
+ serializeBasicBlock(block) {
283
+ const successors = block.getSuccessors().map(successor => successor.getId());
284
+ successors.sort((a, b) => a - b);
285
+ return {
286
+ id: block.getId(),
287
+ successors,
288
+ stmts: block.getStmts().map(stmt => this.serializeStmt(stmt)),
289
+ };
290
+ }
291
+ serializeLocal(local) {
292
+ return {
293
+ name: local.getName(),
294
+ type: this.serializeType(local.getType()),
295
+ };
296
+ }
297
+ serializeValue(value) {
298
+ if (value == null) {
299
+ return null;
300
+ }
301
+ if (value === undefined) {
302
+ throw new Error("Value is undefined");
303
+ }
304
+ if (value instanceof Local_1.Local) {
305
+ return Object.assign({ _: 'Local' }, this.serializeLocal(value));
306
+ }
307
+ else if (value instanceof Constant_1.Constant) {
308
+ return {
309
+ _: 'Constant',
310
+ value: value.getValue(),
311
+ type: this.serializeType(value.getType()),
312
+ };
313
+ }
314
+ else if (value instanceof Expr_1.ArkNewExpr) {
315
+ return {
316
+ _: 'NewExpr',
317
+ classType: this.serializeType(value.getClassType()),
318
+ };
319
+ }
320
+ else if (value instanceof Expr_1.ArkNewArrayExpr) {
321
+ return {
322
+ _: 'NewArrayExpr',
323
+ elementType: this.serializeType(value.getBaseType()),
324
+ size: this.serializeValue(value.getSize()),
325
+ };
326
+ }
327
+ else if (value instanceof Expr_1.ArkDeleteExpr) {
328
+ return {
329
+ _: 'DeleteExpr',
330
+ arg: this.serializeValue(value.getField()),
331
+ };
332
+ }
333
+ else if (value instanceof Expr_1.ArkAwaitExpr) {
334
+ return {
335
+ _: "AwaitExpr",
336
+ arg: this.serializeValue(value.getPromise()),
337
+ };
338
+ }
339
+ else if (value instanceof Expr_1.ArkYieldExpr) {
340
+ return {
341
+ _: "YieldExpr",
342
+ arg: this.serializeValue(value.getYieldValue()),
343
+ };
344
+ }
345
+ else if (value instanceof Expr_1.ArkTypeOfExpr) {
346
+ return {
347
+ _: 'TypeOfExpr',
348
+ arg: this.serializeValue(value.getOp()),
349
+ };
350
+ }
351
+ else if (value instanceof Expr_1.ArkInstanceOfExpr) {
352
+ return {
353
+ _: 'InstanceOfExpr',
354
+ arg: this.serializeValue(value.getOp()),
355
+ checkType: this.serializeType(value.getCheckType()),
356
+ };
357
+ }
358
+ else if (value instanceof Expr_1.ArkCastExpr) {
359
+ return {
360
+ _: 'CastExpr',
361
+ arg: this.serializeValue(value.getOp()),
362
+ type: this.serializeType(value.getType()),
363
+ };
364
+ }
365
+ else if (value instanceof Expr_1.ArkPhiExpr) {
366
+ const args = value.getArgs();
367
+ const argToBlock = value.getArgToBlock();
368
+ return {
369
+ _: 'PhiExpr',
370
+ args: args.map(arg => this.serializeValue(arg)),
371
+ blocks: args.map(arg => argToBlock.get(arg).getId()),
372
+ type: this.serializeType(value.getType()),
373
+ };
374
+ }
375
+ else if (value instanceof Expr_1.ArkConditionExpr) {
376
+ return {
377
+ _: 'ConditionExpr',
378
+ op: value.getOperator(),
379
+ left: this.serializeValue(value.getOp1()),
380
+ right: this.serializeValue(value.getOp2()),
381
+ type: this.serializeType(value.getType()),
382
+ };
383
+ }
384
+ else if (value instanceof Expr_1.AbstractBinopExpr) {
385
+ return {
386
+ _: 'BinopExpr',
387
+ op: value.getOperator(),
388
+ left: this.serializeValue(value.getOp1()),
389
+ right: this.serializeValue(value.getOp2()),
390
+ };
391
+ }
392
+ else if (value instanceof Expr_1.ArkUnopExpr) {
393
+ return {
394
+ _: 'UnopExpr',
395
+ op: value.getOperator(),
396
+ arg: this.serializeValue(value.getOp()),
397
+ };
398
+ }
399
+ else if (value instanceof Expr_1.ArkInstanceInvokeExpr) {
400
+ return {
401
+ _: 'InstanceCallExpr',
402
+ instance: this.serializeValue(value.getBase()),
403
+ method: this.serializeMethodSignature(value.getMethodSignature()),
404
+ args: value.getArgs().map(arg => this.serializeValue(arg)),
405
+ };
406
+ }
407
+ else if (value instanceof Expr_1.ArkStaticInvokeExpr) {
408
+ return {
409
+ _: 'StaticCallExpr',
410
+ method: this.serializeMethodSignature(value.getMethodSignature()),
411
+ args: value.getArgs().map(arg => this.serializeValue(arg)),
412
+ };
413
+ }
414
+ else if (value instanceof Ref_1.ArkThisRef) {
415
+ return {
416
+ _: 'ThisRef',
417
+ type: this.serializeType(value.getType()),
418
+ };
419
+ }
420
+ else if (value instanceof Ref_1.ArkParameterRef) {
421
+ return {
422
+ _: 'ParameterRef',
423
+ index: value.getIndex(),
424
+ type: this.serializeType(value.getType()),
425
+ };
426
+ }
427
+ else if (value instanceof Ref_1.ArkArrayRef) {
428
+ return {
429
+ _: 'ArrayRef',
430
+ array: this.serializeValue(value.getBase()),
431
+ index: this.serializeValue(value.getIndex()),
432
+ type: this.serializeType(value.getType()),
433
+ };
434
+ }
435
+ else if (value instanceof Ref_1.ArkInstanceFieldRef) {
436
+ return {
437
+ _: 'InstanceFieldRef',
438
+ instance: this.serializeValue(value.getBase()),
439
+ field: this.serializeFieldSignature(value.getFieldSignature()),
440
+ };
441
+ }
442
+ else if (value instanceof Ref_1.ArkStaticFieldRef) {
443
+ return {
444
+ _: 'StaticFieldRef',
445
+ field: this.serializeFieldSignature(value.getFieldSignature()),
446
+ };
447
+ }
448
+ else {
449
+ return {
450
+ _: 'UNKNOWN_VALUE',
451
+ // TODO: add simple 'value' field here to be able to see the "unknown" value
452
+ // currently not possible due to circular structure
453
+ // which cannot be serialized via `JSON.stringify`
454
+ // value,
455
+ value: value.toString(),
456
+ };
457
+ }
458
+ }
459
+ serializeStmt(stmt) {
460
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
461
+ return {
462
+ _: 'AssignStmt',
463
+ left: this.serializeValue(stmt.getLeftOp()),
464
+ right: this.serializeValue(stmt.getRightOp()),
465
+ };
466
+ }
467
+ else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
468
+ return {
469
+ _: 'CallStmt',
470
+ expr: this.serializeValue(stmt.getInvokeExpr()),
471
+ };
472
+ }
473
+ else if (stmt instanceof Stmt_1.ArkIfStmt) {
474
+ return {
475
+ _: 'IfStmt',
476
+ condition: this.serializeValue(stmt.getConditionExprExpr()),
477
+ };
478
+ }
479
+ else if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
480
+ return {
481
+ _: 'ReturnVoidStmt',
482
+ };
483
+ }
484
+ else if (stmt instanceof Stmt_1.ArkReturnStmt) {
485
+ return {
486
+ _: 'ReturnStmt',
487
+ arg: this.serializeValue(stmt.getOp())
488
+ };
489
+ }
490
+ else if (stmt instanceof Stmt_1.ArkThrowStmt) {
491
+ return {
492
+ _: 'ThrowStmt',
493
+ arg: this.serializeValue(stmt.getOp()),
494
+ };
495
+ }
496
+ else if (stmt instanceof Stmt_1.ArkSwitchStmt) {
497
+ return {
498
+ _: 'SwitchStmt',
499
+ arg: this.serializeValue(stmt.getKey()),
500
+ cases: stmt.getCases().map((caseValue) => this.serializeValue(caseValue)),
501
+ };
502
+ }
503
+ else {
504
+ return {
505
+ _: 'UNKNOWN_STMT',
506
+ stmt: stmt.toString(),
507
+ };
508
+ }
509
+ }
510
+ }
511
+ exports.JsonPrinter = JsonPrinter;
@@ -0,0 +1,17 @@
1
+ import { ArkCodeBuffer } from './ArkStream';
2
+ /**
3
+ * @category save
4
+ */
5
+ export declare abstract class Printer {
6
+ protected printer: ArkCodeBuffer;
7
+ constructor(indent?: string);
8
+ /**
9
+ * ArkIR dump
10
+ */
11
+ abstract dump(): string;
12
+ /**
13
+ * Original dump
14
+ */
15
+ abstract dumpOriginal(): string;
16
+ }
17
+ //# sourceMappingURL=Printer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Printer.d.ts","sourceRoot":"","sources":["../../src/save/Printer.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;GAEG;AACH,8BAAsB,OAAO;IACzB,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC;gBAEd,MAAM,GAAE,MAAW;IAItC;;OAEG;aACa,IAAI,IAAI,MAAM;IAE9B;;OAEG;aACa,YAAY,IAAI,MAAM;CACzC"}