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,292 @@
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.StmtReader = exports.SourceBody = void 0;
41
+ const Local_1 = require("../../core/base/Local");
42
+ const Stmt_1 = require("../../core/base/Stmt");
43
+ const logger_1 = __importStar(require("../../utils/logger"));
44
+ const ArkStream_1 = require("../ArkStream");
45
+ const SourceStmt_1 = require("./SourceStmt");
46
+ const CfgStructualAnalysis_1 = require("../../utils/CfgStructualAnalysis");
47
+ const ModelUtils_1 = require("../../core/common/ModelUtils");
48
+ const SourceUtils_1 = require("./SourceUtils");
49
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SourceBody');
50
+ class SourceBody {
51
+ constructor(indent, method, inBuilder) {
52
+ this.stmts = [];
53
+ this.printer = new ArkStream_1.ArkCodeBuffer(indent);
54
+ this.method = method;
55
+ this.arkBody = method.getBody();
56
+ this.cfgUtils = new CfgStructualAnalysis_1.AbstractFlowGraph(method.getCfg());
57
+ this.tempCodeMap = new Map();
58
+ this.tempVisitor = new Set();
59
+ this.definedLocals = new Set();
60
+ this.inBuilder = inBuilder;
61
+ this.skipStmts = new Set();
62
+ this.stmtReader = new StmtReader([]);
63
+ this.lastStmt = this.arkBody.getCfg().getStartingStmt();
64
+ this.buildSourceStmt();
65
+ }
66
+ setSkipStmt(stmt) {
67
+ this.skipStmts.add(stmt);
68
+ }
69
+ isInBuilderMethod() {
70
+ return this.inBuilder;
71
+ }
72
+ isInDefaultMethod() {
73
+ return this.method.isDefaultArkMethod();
74
+ }
75
+ getArkFile() {
76
+ return this.method.getDeclaringArkFile();
77
+ }
78
+ getDeclaringArkNamespace() {
79
+ return this.method.getDeclaringArkClass().getDeclaringArkNamespace();
80
+ }
81
+ getMethod(signature) {
82
+ let method = this.method.getDeclaringArkFile().getScene().getMethod(signature);
83
+ if (method) {
84
+ return method;
85
+ }
86
+ return this.method.getDeclaringArkClass().getMethodWithName(signature.getMethodSubSignature().getMethodName());
87
+ }
88
+ getClass(signature) {
89
+ return ModelUtils_1.ModelUtils.getClass(this.method, signature);
90
+ }
91
+ getLocals() {
92
+ return this.arkBody.getLocals();
93
+ }
94
+ defineLocal(local) {
95
+ this.definedLocals.add(local);
96
+ }
97
+ isLocalDefined(local) {
98
+ return this.definedLocals.has(local);
99
+ }
100
+ getStmtReader() {
101
+ return this.stmtReader;
102
+ }
103
+ setTempCode(temp, code) {
104
+ this.tempCodeMap.set(temp, code);
105
+ }
106
+ transTemp2Code(temp) {
107
+ if (this.tempCodeMap.has(temp.getName()) && SourceUtils_1.SourceUtils.isTemp(temp.getName())) {
108
+ this.tempVisitor.add(temp.getName());
109
+ return this.tempCodeMap.get(temp.getName());
110
+ }
111
+ return temp.getName();
112
+ }
113
+ getTempCodeMap() {
114
+ return this.tempCodeMap;
115
+ }
116
+ hasTempVisit(temp) {
117
+ return this.tempVisitor.has(temp);
118
+ }
119
+ setTempVisit(temp) {
120
+ this.tempVisitor.add(temp);
121
+ }
122
+ getPrinter() {
123
+ return this.printer;
124
+ }
125
+ dump() {
126
+ this.printStmts();
127
+ return this.printer.toString();
128
+ }
129
+ buildSourceStmt() {
130
+ this.cfgUtils.preOrder(this.cfgUtils.getEntry(), (block, type) => {
131
+ this.buildBasicBlock(block, type);
132
+ });
133
+ this.buildTypeAliasStmt();
134
+ }
135
+ buildTypeAliasStmt() {
136
+ for (const [_, [aliasType, declaration]] of this.arkBody.getAliasTypeMap()) {
137
+ let stmt = new Stmt_1.OriginalStmt('', declaration.getPosition());
138
+ this.pushStmt(new SourceStmt_1.SourceTypeAliasStmt(this, stmt, aliasType));
139
+ }
140
+ }
141
+ buildBasicBlock(block, type) {
142
+ if (type == CfgStructualAnalysis_1.CodeBlockType.BREAK) {
143
+ this.pushStmt(new SourceStmt_1.SourceBreakStmt(this, this.lastStmt));
144
+ return;
145
+ }
146
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.CONTINUE) {
147
+ this.pushStmt(new SourceStmt_1.SourceContinueStmt(this, this.lastStmt));
148
+ }
149
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.COMPOUND_END) {
150
+ this.pushStmt(new SourceStmt_1.SourceCompoundEndStmt(this, this.lastStmt, '}'));
151
+ }
152
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.ELSE) {
153
+ this.pushStmt(new SourceStmt_1.SourceElseStmt(this, this.lastStmt));
154
+ }
155
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.DO) {
156
+ this.pushStmt(new SourceStmt_1.SourceDoStmt(this, this.lastStmt));
157
+ }
158
+ if (!block) {
159
+ return;
160
+ }
161
+ let originalStmts = this.sortStmt(block.getStmts());
162
+ this.stmtReader = new StmtReader(originalStmts);
163
+ while (this.stmtReader.hasNext()) {
164
+ let stmt = this.stmtReader.next();
165
+ if (this.skipStmts.has(stmt)) {
166
+ continue;
167
+ }
168
+ if (stmt instanceof Stmt_1.ArkIfStmt) {
169
+ if (type == CfgStructualAnalysis_1.CodeBlockType.IF) {
170
+ this.pushStmt(new SourceStmt_1.SourceIfStmt(this, stmt));
171
+ }
172
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.WHILE) {
173
+ this.pushStmt(new SourceStmt_1.SourceWhileStmt(this, stmt, block));
174
+ }
175
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.FOR) {
176
+ let inc = this.cfgUtils.getForIncBlock(block);
177
+ this.pushStmt(new SourceStmt_1.SourceForStmt(this, stmt, block, inc));
178
+ }
179
+ else if (type == CfgStructualAnalysis_1.CodeBlockType.DO_WHILE) {
180
+ this.pushStmt(new SourceStmt_1.SourceDoWhileStmt(this, stmt, block));
181
+ }
182
+ }
183
+ else {
184
+ this.pushStmt((0, SourceStmt_1.stmt2SourceStmt)(this, stmt));
185
+ }
186
+ this.lastStmt = stmt;
187
+ }
188
+ }
189
+ printStmts() {
190
+ for (let stmt of this.stmts) {
191
+ if (this.skipStmts.has(stmt.original)) {
192
+ continue;
193
+ }
194
+ this.printer.write(stmt.dump());
195
+ }
196
+ }
197
+ getStmts() {
198
+ return this.stmts.filter((value) => {
199
+ if (!this.skipStmts.has(value.original)) {
200
+ return value;
201
+ }
202
+ });
203
+ }
204
+ pushStmt(stmt) {
205
+ let lastLine = this.getLastLine();
206
+ if (stmt.getLine() < lastLine) {
207
+ stmt.setLine(lastLine + 0.1);
208
+ }
209
+ stmt.transfer2ts();
210
+ this.stmts.push(stmt);
211
+ }
212
+ getLastLine() {
213
+ if (this.stmts.length > 0) {
214
+ return this.stmts[this.stmts.length - 1].getLine();
215
+ }
216
+ return 0;
217
+ }
218
+ /*
219
+ * temp9 = new <>.<>(); temp10 = new Array<number>(3);
220
+ * temp10 = new Array<number>(3); temp10[0] = 'Cat';
221
+ * temp10[0] = 'Cat'; ==> temp10[1] = 'Dog';
222
+ * temp10[1] = 'Dog'; temp10[2] = 'Hamster';
223
+ * temp10[2] = 'Hamster'; temp9 = new <>.<>();
224
+ * temp9.constructor(temp10); temp9.constructor(temp10);
225
+ */
226
+ sortStmt(stmts) {
227
+ for (let i = stmts.length - 1; i > 0; i--) {
228
+ if (stmts[i] instanceof Stmt_1.ArkInvokeStmt && stmts[i].getInvokeExpr()) {
229
+ let instanceInvokeExpr = stmts[i].getInvokeExpr();
230
+ if ('constructor' == instanceInvokeExpr.getMethodSignature().getMethodSubSignature().getMethodName()) {
231
+ let localName = instanceInvokeExpr.getBase().getName();
232
+ let newExprIdx = findNewExpr(i, localName);
233
+ if (newExprIdx >= 0 && newExprIdx < i - 1) {
234
+ moveStmt(i, newExprIdx);
235
+ }
236
+ }
237
+ }
238
+ }
239
+ return stmts;
240
+ function findNewExpr(constructorIdx, name) {
241
+ for (let j = constructorIdx - 1; j >= 0; j--) {
242
+ if (!(stmts[j] instanceof Stmt_1.ArkAssignStmt)) {
243
+ continue;
244
+ }
245
+ if (stmts[j].getLeftOp() instanceof Local_1.Local) {
246
+ if (stmts[j].getLeftOp().getName() == name) {
247
+ return j;
248
+ }
249
+ }
250
+ }
251
+ return -1;
252
+ }
253
+ function moveStmt(constructorIdx, newExprIdx) {
254
+ let back = stmts[newExprIdx];
255
+ for (let i = newExprIdx; i < constructorIdx - 1; i++) {
256
+ stmts[i] = stmts[i + 1];
257
+ }
258
+ stmts[constructorIdx - 1] = back;
259
+ }
260
+ }
261
+ }
262
+ exports.SourceBody = SourceBody;
263
+ class StmtReader {
264
+ constructor(stmts) {
265
+ this.stmts = [];
266
+ this.stmts = stmts;
267
+ this.pos = 0;
268
+ }
269
+ first() {
270
+ return this.stmts[0];
271
+ }
272
+ hasNext() {
273
+ return this.pos < this.stmts.length;
274
+ }
275
+ next() {
276
+ if (!this.hasNext()) {
277
+ logger.error('SourceBody: StmtReader->next No more stmt.');
278
+ throw new Error('No more stmt.');
279
+ }
280
+ let stmt = this.stmts[this.pos];
281
+ this.pos++;
282
+ return stmt;
283
+ }
284
+ rollback() {
285
+ if (this.pos == 0) {
286
+ logger.error('SourceBody: StmtReader->rollback No more stmt to rollback.');
287
+ throw new Error('No more stmt to rollback.');
288
+ }
289
+ this.pos--;
290
+ }
291
+ }
292
+ exports.StmtReader = StmtReader;
@@ -0,0 +1,27 @@
1
+ import { ArkClass } from '../../core/model/ArkClass';
2
+ import { Dump, SourceBase } from './SourceBase';
3
+ import { ArkNamespace } from '../../core/model/ArkNamespace';
4
+ /**
5
+ * @category save
6
+ */
7
+ export declare class SourceClass extends SourceBase {
8
+ protected cls: ArkClass;
9
+ private transformer;
10
+ constructor(cls: ArkClass, indent?: string);
11
+ getDeclaringArkNamespace(): ArkNamespace | undefined;
12
+ getLine(): number;
13
+ dump(): string;
14
+ dumpOriginal(): string;
15
+ private dumpObject;
16
+ private dumpTypeLiteral;
17
+ protected printMethods(): Dump[];
18
+ private printFields;
19
+ private parseFieldInitMethod;
20
+ }
21
+ export declare class SourceDefaultClass extends SourceClass {
22
+ constructor(cls: ArkClass, indent?: string);
23
+ getLine(): number;
24
+ dump(): string;
25
+ dumpOriginal(): string;
26
+ }
27
+ //# sourceMappingURL=SourceClass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceClass.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceClass.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAiB,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAOhD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACvC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC;IACxB,OAAO,CAAC,WAAW,CAAoB;gBAEpB,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAE,MAAW;IAM9C,wBAAwB,IAAI,YAAY,GAAG,SAAS;IAIpD,OAAO,IAAI,MAAM;IAIjB,IAAI,IAAI,MAAM;IAoDd,YAAY,IAAI,MAAM;IAI7B,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,eAAe;IAmBvB,SAAS,CAAC,YAAY,IAAI,IAAI,EAAE;IAgBhC,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,oBAAoB;CAU/B;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBAC5B,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAE,MAAW;IAI9C,OAAO,IAAI,MAAM;IAIjB,IAAI,IAAI,MAAM;IAKd,YAAY,IAAI,MAAM;CAmBhC"}
@@ -0,0 +1,202 @@
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.SourceDefaultClass = exports.SourceClass = void 0;
18
+ const ArkClass_1 = require("../../core/model/ArkClass");
19
+ const SourceBase_1 = require("./SourceBase");
20
+ const SourceBody_1 = require("./SourceBody");
21
+ const SourceField_1 = require("./SourceField");
22
+ const SourceMethod_1 = require("./SourceMethod");
23
+ const SourceTransformer_1 = require("./SourceTransformer");
24
+ const SourceUtils_1 = require("./SourceUtils");
25
+ const Const_1 = require("../../core/common/Const");
26
+ const ArkField_1 = require("../../core/model/ArkField");
27
+ /**
28
+ * @category save
29
+ */
30
+ class SourceClass extends SourceBase_1.SourceBase {
31
+ constructor(cls, indent = '') {
32
+ super(cls.getDeclaringArkFile(), indent);
33
+ this.cls = cls;
34
+ this.transformer = new SourceTransformer_1.SourceTransformer(this);
35
+ }
36
+ getDeclaringArkNamespace() {
37
+ return this.cls.getDeclaringArkNamespace();
38
+ }
39
+ getLine() {
40
+ return this.cls.getLine();
41
+ }
42
+ dump() {
43
+ this.printer.clear();
44
+ if (this.cls.getCategory() == ArkClass_1.ClassCategory.OBJECT) {
45
+ return this.dumpObject();
46
+ }
47
+ if (this.cls.getCategory() == ArkClass_1.ClassCategory.TYPE_LITERAL) {
48
+ return this.dumpTypeLiteral();
49
+ }
50
+ this.printDecorator(this.cls.getModifiers());
51
+ // print export class name<> + extends c0 implements x1, x2 {
52
+ this.printer
53
+ .writeIndent()
54
+ .writeSpace(this.modifiersToString(this.cls.getModifiers()))
55
+ .write(`${SourceUtils_1.SourceUtils.classOriginTypeToString.get(this.cls.getCategory())} `);
56
+ if (!SourceUtils_1.SourceUtils.isAnonymousClass(this.cls.getName())) {
57
+ this.printer.write(this.cls.getName());
58
+ }
59
+ const genericsTypes = this.cls.getGenericsTypes();
60
+ if (genericsTypes) {
61
+ this.printer.write(`<${this.transformer.typeArrayToString(genericsTypes)}>`);
62
+ }
63
+ if (this.cls.getSuperClassName() && !this.cls.hasComponentDecorator()) {
64
+ this.printer.write(` extends ${this.cls.getSuperClassName()}`);
65
+ }
66
+ if (this.cls.getImplementedInterfaceNames().length > 0) {
67
+ this.printer.write(` implements ${this.cls.getImplementedInterfaceNames().join(', ')}`);
68
+ }
69
+ this.printer.writeLine(' {');
70
+ this.printer.incIndent();
71
+ let items = [];
72
+ items.push(...this.printFields());
73
+ items.push(...this.printMethods());
74
+ items.sort((a, b) => a.getLine() - b.getLine());
75
+ items.forEach((v) => {
76
+ this.printer.write(v.dump());
77
+ });
78
+ this.printer.decIndent();
79
+ this.printer.writeIndent().write('}');
80
+ if (!SourceUtils_1.SourceUtils.isAnonymousClass(this.cls.getName())) {
81
+ this.printer.writeLine('');
82
+ }
83
+ return this.printer.toString();
84
+ }
85
+ dumpOriginal() {
86
+ return this.cls.getCode() + '\n';
87
+ }
88
+ dumpObject() {
89
+ this.printer.write('{');
90
+ this.cls.getFields().forEach((field, index, array) => {
91
+ let name = SourceUtils_1.SourceUtils.escape(field.getName());
92
+ if (SourceUtils_1.SourceUtils.isIdentifierText(field.getName())) {
93
+ this.printer.write(name);
94
+ }
95
+ else {
96
+ this.printer.write(`'${name}'`);
97
+ }
98
+ let instanceInitializer = this.parseFieldInitMethod(Const_1.INSTANCE_INIT_METHOD_NAME);
99
+ if (instanceInitializer.has(field.getName())) {
100
+ this.printer.write(`: ${instanceInitializer.get(field.getName())}`);
101
+ }
102
+ if (index != array.length - 1) {
103
+ this.printer.write(`, `);
104
+ }
105
+ });
106
+ this.printer.write('}');
107
+ return this.printer.toString();
108
+ }
109
+ dumpTypeLiteral() {
110
+ this.printer.write('{');
111
+ this.cls.getFields().forEach((field, index, array) => {
112
+ let name = SourceUtils_1.SourceUtils.escape(field.getName());
113
+ if (SourceUtils_1.SourceUtils.isIdentifierText(field.getName())) {
114
+ this.printer.write(`${name}: ${this.transformer.typeToString(field.getType())}`);
115
+ }
116
+ else {
117
+ this.printer.write(`'${name}': ${this.transformer.typeToString(field.getType())}`);
118
+ }
119
+ if (index != array.length - 1) {
120
+ this.printer.write(`, `);
121
+ }
122
+ });
123
+ this.printer.write('}');
124
+ return this.printer.toString();
125
+ }
126
+ printMethods() {
127
+ let items = [];
128
+ for (let method of this.cls.getMethods()) {
129
+ if (method.isGenerated() || (SourceUtils_1.SourceUtils.isConstructorMethod(method.getName()) && this.cls.hasViewTree())) {
130
+ continue;
131
+ }
132
+ if (method.isDefaultArkMethod()) {
133
+ items.push(...new SourceMethod_1.SourceMethod(method, this.printer.getIndent()).dumpDefaultMethod());
134
+ }
135
+ else if (!SourceUtils_1.SourceUtils.isAnonymousMethod(method.getName())) {
136
+ items.push(new SourceMethod_1.SourceMethod(method, this.printer.getIndent()));
137
+ }
138
+ }
139
+ return items;
140
+ }
141
+ printFields() {
142
+ let instanceInitializer = this.parseFieldInitMethod(Const_1.INSTANCE_INIT_METHOD_NAME);
143
+ let staticInitializer = this.parseFieldInitMethod(Const_1.STATIC_INIT_METHOD_NAME);
144
+ let items = [];
145
+ for (let field of this.cls.getFields()) {
146
+ if (field.getCategory() == ArkField_1.FieldCategory.GET_ACCESSOR) {
147
+ continue;
148
+ }
149
+ if (field.getModifiers().has('StaticKeyword')) {
150
+ items.push(new SourceField_1.SourceField(field, this.printer.getIndent(), staticInitializer));
151
+ }
152
+ else {
153
+ items.push(new SourceField_1.SourceField(field, this.printer.getIndent(), instanceInitializer));
154
+ }
155
+ }
156
+ return items;
157
+ }
158
+ parseFieldInitMethod(name) {
159
+ let method = this.cls.getMethodWithName(name);
160
+ if (!method || (method === null || method === void 0 ? void 0 : method.getBody()) == undefined) {
161
+ return new Map();
162
+ }
163
+ let srcBody = new SourceBody_1.SourceBody(this.printer.getIndent(), method, false);
164
+ srcBody.dump();
165
+ return srcBody.getTempCodeMap();
166
+ }
167
+ }
168
+ exports.SourceClass = SourceClass;
169
+ class SourceDefaultClass extends SourceClass {
170
+ constructor(cls, indent = '') {
171
+ super(cls, indent);
172
+ }
173
+ getLine() {
174
+ return this.cls.getLine();
175
+ }
176
+ dump() {
177
+ this.printMethods();
178
+ return this.printer.toString();
179
+ }
180
+ dumpOriginal() {
181
+ var _a;
182
+ for (let method of this.cls.getMethods()) {
183
+ if (method.isDefaultArkMethod()) {
184
+ const stmts = (_a = method.getOriginalCfg()) === null || _a === void 0 ? void 0 : _a.getStmts();
185
+ if (!stmts) {
186
+ continue;
187
+ }
188
+ for (let stmt of stmts) {
189
+ let code = stmt.toString();
190
+ if (!code.startsWith('import') && code !== 'return;') {
191
+ this.printer.writeLine(code);
192
+ }
193
+ }
194
+ }
195
+ else {
196
+ this.printer.writeLine(method.getCode());
197
+ }
198
+ }
199
+ return this.printer.toString();
200
+ }
201
+ }
202
+ exports.SourceDefaultClass = SourceDefaultClass;
@@ -0,0 +1,15 @@
1
+ import { ArkField } from '../../core/model/ArkField';
2
+ import { SourceBase } from './SourceBase';
3
+ /**
4
+ * @category save
5
+ */
6
+ export declare class SourceField extends SourceBase {
7
+ private field;
8
+ private transformer;
9
+ private initializer;
10
+ constructor(field: ArkField, indent: string | undefined, initializer: Map<string, string>);
11
+ getLine(): number;
12
+ dump(): string;
13
+ dumpOriginal(): string;
14
+ }
15
+ //# sourceMappingURL=SourceField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceField.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceField.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAiB,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACvC,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,WAAW,CAAsB;gBAEtB,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAa,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAOlF,OAAO,IAAI,MAAM;IAGjB,IAAI,IAAI,MAAM;IAiCd,YAAY,IAAI,MAAM;CAGhC"}
@@ -0,0 +1,68 @@
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.SourceField = void 0;
18
+ const ArkField_1 = require("../../core/model/ArkField");
19
+ const SourceBase_1 = require("./SourceBase");
20
+ const SourceTransformer_1 = require("./SourceTransformer");
21
+ const Type_1 = require("../../core/base/Type");
22
+ /**
23
+ * @category save
24
+ */
25
+ class SourceField extends SourceBase_1.SourceBase {
26
+ constructor(field, indent = '', initializer) {
27
+ super(field.getDeclaringArkClass().getDeclaringArkFile(), indent);
28
+ this.field = field;
29
+ this.transformer = new SourceTransformer_1.SourceTransformer(this);
30
+ this.initializer = initializer;
31
+ }
32
+ getLine() {
33
+ return this.field.getOriginPosition().getLineNo();
34
+ }
35
+ dump() {
36
+ this.printer.clear();
37
+ this.printDecorator(this.field.getModifiers());
38
+ this.printer.writeIndent();
39
+ if (this.field.getCategory() !== ArkField_1.FieldCategory.ENUM_MEMBER) {
40
+ this.printer.writeSpace(this.modifiersToString(this.field.getModifiers()));
41
+ }
42
+ this.printer.write(this.field.getName());
43
+ if (this.field.getQuestionToken()) {
44
+ this.printer.write('?');
45
+ }
46
+ if (this.field.getExclamationToken()) {
47
+ this.printer.write('!');
48
+ }
49
+ // property.getInitializer() PropertyAccessExpression ArrowFunction ClassExpression FirstLiteralToken StringLiteral
50
+ if (!(this.field.getType() instanceof Type_1.UnknownType) && this.field.getCategory() !== ArkField_1.FieldCategory.ENUM_MEMBER) {
51
+ this.printer.write(`: ${this.transformer.typeToString(this.field.getType())}`);
52
+ }
53
+ if (this.initializer.has(this.field.getName())) {
54
+ this.printer.write(` = ${this.initializer.get(this.field.getName())}`);
55
+ }
56
+ if (this.field.getCategory() == ArkField_1.FieldCategory.ENUM_MEMBER) {
57
+ this.printer.writeLine(',');
58
+ }
59
+ else {
60
+ this.printer.writeLine(';');
61
+ }
62
+ return this.printer.toString();
63
+ }
64
+ dumpOriginal() {
65
+ return this.field.getCode() + '\n';
66
+ }
67
+ }
68
+ exports.SourceField = SourceField;
@@ -0,0 +1,14 @@
1
+ import { ArkFile } from '../../core/model/ArkFile';
2
+ import { Printer } from '../Printer';
3
+ import { Dump } from './SourceBase';
4
+ /**
5
+ * @category save
6
+ */
7
+ export declare class SourceFilePrinter extends Printer {
8
+ arkFile: ArkFile;
9
+ items: Dump[];
10
+ constructor(arkFile: ArkFile);
11
+ dump(): string;
12
+ dumpOriginal(): string;
13
+ }
14
+ //# sourceMappingURL=SourceFilePrinter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceFilePrinter.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceFilePrinter.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAOpC;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,OAAO;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,IAAI,EAAE,CAAM;gBAEP,OAAO,EAAE,OAAO;IAKrB,IAAI,IAAI,MAAM;IA4Cd,YAAY,IAAI,MAAM;CAGhC"}