arkanalyzer 1.0.20 → 1.0.22

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 (292) hide show
  1. package/config/arkanalyzer.json +14 -13
  2. package/lib/Config.d.ts +70 -70
  3. package/lib/Config.js +198 -198
  4. package/lib/Scene.d.ts +316 -316
  5. package/lib/Scene.js +1316 -1316
  6. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
  7. package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
  8. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
  9. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
  10. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
  11. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
  12. package/lib/callgraph/common/Statistics.d.ts +57 -57
  13. package/lib/callgraph/common/Statistics.js +228 -228
  14. package/lib/callgraph/model/CallGraph.d.ts +96 -96
  15. package/lib/callgraph/model/CallGraph.js +354 -354
  16. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
  17. package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
  18. package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
  19. package/lib/callgraph/pointerAnalysis/Context.js +155 -155
  20. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
  21. package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
  22. package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
  23. package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
  24. package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
  25. package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
  26. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
  27. package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
  28. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
  29. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
  30. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
  31. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
  32. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
  33. package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
  34. package/lib/core/base/Constant.d.ts +48 -48
  35. package/lib/core/base/Constant.js +103 -103
  36. package/lib/core/base/Decorator.d.ts +15 -15
  37. package/lib/core/base/Decorator.js +46 -46
  38. package/lib/core/base/DefUseChain.d.ts +8 -8
  39. package/lib/core/base/DefUseChain.js +25 -25
  40. package/lib/core/base/Expr.d.ts +340 -340
  41. package/lib/core/base/Expr.js +917 -917
  42. package/lib/core/base/Local.d.ts +104 -104
  43. package/lib/core/base/Local.js +176 -176
  44. package/lib/core/base/Position.d.ts +30 -30
  45. package/lib/core/base/Position.js +147 -147
  46. package/lib/core/base/Ref.d.ts +173 -173
  47. package/lib/core/base/Ref.d.ts.map +1 -1
  48. package/lib/core/base/Ref.js +373 -374
  49. package/lib/core/base/Stmt.d.ts +237 -237
  50. package/lib/core/base/Stmt.js +525 -525
  51. package/lib/core/base/Trap.d.ts +8 -8
  52. package/lib/core/base/Trap.js +30 -30
  53. package/lib/core/base/Type.d.ts +308 -308
  54. package/lib/core/base/Type.js +639 -639
  55. package/lib/core/base/TypeExpr.d.ts +71 -71
  56. package/lib/core/base/TypeExpr.js +155 -155
  57. package/lib/core/base/Value.d.ts +32 -32
  58. package/lib/core/base/Value.js +16 -16
  59. package/lib/core/common/ArkError.d.ts +14 -14
  60. package/lib/core/common/ArkError.js +28 -28
  61. package/lib/core/common/ArkIRTransformer.d.ts +68 -67
  62. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  63. package/lib/core/common/ArkIRTransformer.js +705 -690
  64. package/lib/core/common/ArkValueTransformer.d.ts +89 -89
  65. package/lib/core/common/ArkValueTransformer.js +1478 -1478
  66. package/lib/core/common/Builtin.d.ts +36 -36
  67. package/lib/core/common/Builtin.js +81 -81
  68. package/lib/core/common/Const.d.ts +21 -21
  69. package/lib/core/common/Const.js +43 -43
  70. package/lib/core/common/DummyMainCreater.d.ts +46 -46
  71. package/lib/core/common/DummyMainCreater.js +319 -319
  72. package/lib/core/common/EtsConst.d.ts +73 -73
  73. package/lib/core/common/EtsConst.js +1021 -1021
  74. package/lib/core/common/ExprUseReplacer.d.ts +21 -21
  75. package/lib/core/common/ExprUseReplacer.js +124 -124
  76. package/lib/core/common/IRInference.d.ts +45 -36
  77. package/lib/core/common/IRInference.d.ts.map +1 -1
  78. package/lib/core/common/IRInference.js +731 -648
  79. package/lib/core/common/IRUtils.d.ts +18 -18
  80. package/lib/core/common/IRUtils.js +141 -141
  81. package/lib/core/common/ModelUtils.d.ts +70 -70
  82. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  83. package/lib/core/common/ModelUtils.js +723 -712
  84. package/lib/core/common/RefUseReplacer.d.ts +13 -13
  85. package/lib/core/common/RefUseReplacer.js +52 -52
  86. package/lib/core/common/SdkUtils.d.ts +11 -8
  87. package/lib/core/common/SdkUtils.d.ts.map +1 -1
  88. package/lib/core/common/SdkUtils.js +127 -105
  89. package/lib/core/common/StmtDefReplacer.d.ts +12 -12
  90. package/lib/core/common/StmtDefReplacer.js +41 -41
  91. package/lib/core/common/StmtUseReplacer.d.ts +16 -16
  92. package/lib/core/common/StmtUseReplacer.js +108 -108
  93. package/lib/core/common/TSConst.d.ts +20 -18
  94. package/lib/core/common/TSConst.d.ts.map +1 -1
  95. package/lib/core/common/TSConst.js +38 -36
  96. package/lib/core/common/TypeInference.d.ts +105 -102
  97. package/lib/core/common/TypeInference.d.ts.map +1 -1
  98. package/lib/core/common/TypeInference.js +806 -748
  99. package/lib/core/common/ValueUtil.d.ts +12 -12
  100. package/lib/core/common/ValueUtil.js +54 -54
  101. package/lib/core/common/VisibleValue.d.ts +36 -36
  102. package/lib/core/common/VisibleValue.js +212 -212
  103. package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
  104. package/lib/core/dataflow/DataflowProblem.js +20 -20
  105. package/lib/core/dataflow/DataflowResult.d.ts +7 -7
  106. package/lib/core/dataflow/DataflowResult.js +26 -26
  107. package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
  108. package/lib/core/dataflow/DataflowSolver.js +307 -307
  109. package/lib/core/dataflow/Edge.d.ts +11 -11
  110. package/lib/core/dataflow/Edge.js +31 -31
  111. package/lib/core/dataflow/Fact.d.ts +6 -6
  112. package/lib/core/dataflow/Fact.js +24 -24
  113. package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
  114. package/lib/core/dataflow/GenericDataFlow.js +109 -109
  115. package/lib/core/dataflow/ReachingDef.d.ts +62 -62
  116. package/lib/core/dataflow/ReachingDef.js +168 -168
  117. package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
  118. package/lib/core/dataflow/UndefinedVariable.js +288 -288
  119. package/lib/core/dataflow/Util.d.ts +9 -9
  120. package/lib/core/dataflow/Util.js +64 -64
  121. package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
  122. package/lib/core/graph/BaseExplicitGraph.js +157 -157
  123. package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
  124. package/lib/core/graph/BaseImplicitGraph.js +78 -78
  125. package/lib/core/graph/BasicBlock.d.ts +104 -104
  126. package/lib/core/graph/BasicBlock.js +280 -280
  127. package/lib/core/graph/Cfg.d.ts +59 -59
  128. package/lib/core/graph/Cfg.js +282 -282
  129. package/lib/core/graph/DependsGraph.d.ts +35 -35
  130. package/lib/core/graph/DependsGraph.js +87 -87
  131. package/lib/core/graph/DominanceFinder.d.ts +15 -15
  132. package/lib/core/graph/DominanceFinder.js +121 -121
  133. package/lib/core/graph/DominanceTree.d.ts +12 -12
  134. package/lib/core/graph/DominanceTree.js +70 -70
  135. package/lib/core/graph/GraphTraits.d.ts +7 -7
  136. package/lib/core/graph/GraphTraits.js +16 -16
  137. package/lib/core/graph/Scc.d.ts +61 -61
  138. package/lib/core/graph/Scc.js +222 -222
  139. package/lib/core/graph/ViewTree.d.ts +114 -114
  140. package/lib/core/graph/ViewTree.js +16 -16
  141. package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
  142. package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
  143. package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
  144. package/lib/core/graph/builder/ConditionBuilder.js +252 -252
  145. package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
  146. package/lib/core/graph/builder/LoopBuilder.js +251 -251
  147. package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
  148. package/lib/core/graph/builder/SwitchBuilder.js +152 -152
  149. package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
  150. package/lib/core/graph/builder/TrapBuilder.js +272 -272
  151. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
  152. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
  153. package/lib/core/graph/builder/ViewTreeBuilder.js +1058 -1055
  154. package/lib/core/model/ArkBaseModel.d.ts +59 -59
  155. package/lib/core/model/ArkBaseModel.js +274 -274
  156. package/lib/core/model/ArkBody.d.ts +24 -24
  157. package/lib/core/model/ArkBody.js +65 -65
  158. package/lib/core/model/ArkClass.d.ts +206 -206
  159. package/lib/core/model/ArkClass.d.ts.map +1 -1
  160. package/lib/core/model/ArkClass.js +442 -439
  161. package/lib/core/model/ArkExport.d.ts +72 -72
  162. package/lib/core/model/ArkExport.js +147 -147
  163. package/lib/core/model/ArkField.d.ts +62 -62
  164. package/lib/core/model/ArkField.js +113 -113
  165. package/lib/core/model/ArkFile.d.ts +131 -131
  166. package/lib/core/model/ArkFile.js +267 -267
  167. package/lib/core/model/ArkImport.d.ts +44 -44
  168. package/lib/core/model/ArkImport.js +108 -108
  169. package/lib/core/model/ArkMetadata.d.ts +31 -31
  170. package/lib/core/model/ArkMetadata.js +55 -55
  171. package/lib/core/model/ArkMethod.d.ts +261 -261
  172. package/lib/core/model/ArkMethod.js +592 -592
  173. package/lib/core/model/ArkNamespace.d.ts +66 -66
  174. package/lib/core/model/ArkNamespace.js +209 -209
  175. package/lib/core/model/ArkSignature.d.ts +167 -162
  176. package/lib/core/model/ArkSignature.d.ts.map +1 -1
  177. package/lib/core/model/ArkSignature.js +393 -379
  178. package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
  179. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  180. package/lib/core/model/builder/ArkClassBuilder.js +423 -454
  181. package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
  182. package/lib/core/model/builder/ArkExportBuilder.js +210 -210
  183. package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
  184. package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
  185. package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
  186. package/lib/core/model/builder/ArkFileBuilder.js +165 -165
  187. package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
  188. package/lib/core/model/builder/ArkImportBuilder.js +128 -128
  189. package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
  190. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  191. package/lib/core/model/builder/ArkMethodBuilder.js +487 -486
  192. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
  193. package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
  194. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
  195. package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
  196. package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
  197. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
  198. package/lib/core/model/builder/BodyBuilder.js +542 -371
  199. package/lib/core/model/builder/builderUtils.d.ts +18 -18
  200. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  201. package/lib/core/model/builder/builderUtils.js +571 -558
  202. package/lib/index.d.ts +82 -80
  203. package/lib/index.d.ts.map +1 -1
  204. package/lib/index.js +201 -196
  205. package/lib/save/ArkStream.d.ts +23 -23
  206. package/lib/save/ArkStream.js +83 -83
  207. package/lib/save/DotPrinter.d.ts +43 -43
  208. package/lib/save/DotPrinter.js +170 -170
  209. package/lib/save/GraphPrinter.d.ts +16 -16
  210. package/lib/save/GraphPrinter.js +134 -134
  211. package/lib/save/JsonPrinter.d.ts +30 -30
  212. package/lib/save/JsonPrinter.js +580 -580
  213. package/lib/save/Printer.d.ts +12 -12
  214. package/lib/save/Printer.js +27 -27
  215. package/lib/save/PrinterBuilder.d.ts +53 -53
  216. package/lib/save/PrinterBuilder.js +145 -145
  217. package/lib/save/ViewTreePrinter.d.ts +14 -14
  218. package/lib/save/ViewTreePrinter.js +123 -123
  219. package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
  220. package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
  221. package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
  222. package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
  223. package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
  224. package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
  225. package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
  226. package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
  227. package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
  228. package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
  229. package/lib/save/base/BasePrinter.d.ts +23 -23
  230. package/lib/save/base/BasePrinter.js +70 -70
  231. package/lib/save/base/ExportPrinter.d.ts +8 -8
  232. package/lib/save/base/ExportPrinter.js +67 -67
  233. package/lib/save/base/ImportPrinter.d.ts +9 -9
  234. package/lib/save/base/ImportPrinter.js +92 -92
  235. package/lib/save/base/PrinterUtils.d.ts +24 -24
  236. package/lib/save/base/PrinterUtils.js +208 -208
  237. package/lib/save/serializeArkIR.d.ts +8 -8
  238. package/lib/save/serializeArkIR.js +294 -294
  239. package/lib/save/source/SourceBase.d.ts +22 -22
  240. package/lib/save/source/SourceBase.js +64 -64
  241. package/lib/save/source/SourceBody.d.ts +58 -58
  242. package/lib/save/source/SourceBody.js +296 -296
  243. package/lib/save/source/SourceClass.d.ts +25 -25
  244. package/lib/save/source/SourceClass.js +187 -187
  245. package/lib/save/source/SourceField.d.ts +13 -13
  246. package/lib/save/source/SourceField.js +73 -73
  247. package/lib/save/source/SourceFilePrinter.d.ts +12 -12
  248. package/lib/save/source/SourceFilePrinter.js +69 -69
  249. package/lib/save/source/SourceMethod.d.ts +22 -22
  250. package/lib/save/source/SourceMethod.d.ts.map +1 -1
  251. package/lib/save/source/SourceMethod.js +196 -193
  252. package/lib/save/source/SourceNamespace.d.ts +11 -11
  253. package/lib/save/source/SourceNamespace.js +83 -83
  254. package/lib/save/source/SourceStmt.d.ts +178 -178
  255. package/lib/save/source/SourceStmt.js +838 -838
  256. package/lib/save/source/SourceTransformer.d.ts +46 -46
  257. package/lib/save/source/SourceTransformer.js +446 -446
  258. package/lib/transformer/FunctionTransformer.d.ts +2 -2
  259. package/lib/transformer/FunctionTransformer.js +17 -17
  260. package/lib/transformer/SceneTransformer.d.ts +2 -2
  261. package/lib/transformer/SceneTransformer.js +17 -17
  262. package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
  263. package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
  264. package/lib/transformer/Transformer.d.ts +6 -6
  265. package/lib/transformer/Transformer.js +22 -22
  266. package/lib/utils/AstTreeUtils.d.ts +4 -4
  267. package/lib/utils/AstTreeUtils.js +26 -26
  268. package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
  269. package/lib/utils/CfgStructualAnalysis.js +1277 -1277
  270. package/lib/utils/FileUtils.d.ts +18 -18
  271. package/lib/utils/FileUtils.js +135 -135
  272. package/lib/utils/SparseBitVector.d.ts +100 -100
  273. package/lib/utils/SparseBitVector.js +445 -445
  274. package/lib/utils/callGraphUtils.d.ts +30 -30
  275. package/lib/utils/callGraphUtils.js +205 -205
  276. package/lib/utils/crypto_utils.d.ts +5 -5
  277. package/lib/utils/crypto_utils.js +57 -57
  278. package/lib/utils/entryMethodUtils.d.ts +13 -13
  279. package/lib/utils/entryMethodUtils.js +110 -110
  280. package/lib/utils/getAllFiles.d.ts +9 -9
  281. package/lib/utils/getAllFiles.js +90 -90
  282. package/lib/utils/json5parser.d.ts +6 -6
  283. package/lib/utils/json5parser.js +146 -146
  284. package/lib/utils/logger.d.ts +18 -18
  285. package/lib/utils/logger.d.ts.map +1 -1
  286. package/lib/utils/logger.js +97 -90
  287. package/lib/utils/pathTransfer.d.ts +1 -1
  288. package/lib/utils/pathTransfer.js +25 -25
  289. package/node_modules/json5/lib/cli.js +0 -0
  290. package/node_modules/ohos-typescript/bin/tsc +0 -0
  291. package/node_modules/ohos-typescript/bin/tsserver +0 -0
  292. package/package.json +3 -3
@@ -1,1055 +1,1058 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.buildViewTree = exports.ViewTreeImpl = void 0;
41
- const Constant_1 = require("../../base/Constant");
42
- const Decorator_1 = require("../../base/Decorator");
43
- const Expr_1 = require("../../base/Expr");
44
- const Local_1 = require("../../base/Local");
45
- const Ref_1 = require("../../base/Ref");
46
- const Stmt_1 = require("../../base/Stmt");
47
- const Type_1 = require("../../base/Type");
48
- const EtsConst_1 = require("../../common/EtsConst");
49
- const ArkClass_1 = require("../../model/ArkClass");
50
- const logger_1 = __importStar(require("../../../utils/logger"));
51
- const ModelUtils_1 = require("../../common/ModelUtils");
52
- const Const_1 = require("../../common/Const");
53
- const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ViewTreeBuilder');
54
- const COMPONENT_CREATE_FUNCTIONS = new Set([EtsConst_1.COMPONENT_CREATE_FUNCTION, EtsConst_1.COMPONENT_BRANCH_FUNCTION]);
55
- function backtraceLocalInitValue(value) {
56
- let stmt = value.getDeclaringStmt();
57
- if (stmt instanceof Stmt_1.ArkAssignStmt) {
58
- let rightOp = stmt.getRightOp();
59
- if (rightOp instanceof Local_1.Local) {
60
- return backtraceLocalInitValue(rightOp);
61
- }
62
- else if (rightOp instanceof Ref_1.ArkInstanceFieldRef && rightOp.getBase().getName().startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
63
- return backtraceLocalInitValue(rightOp.getBase());
64
- }
65
- return rightOp;
66
- }
67
- return value;
68
- }
69
- function parseObjectLiteral(objectLiteralCls, scene) {
70
- let map = new Map();
71
- if ((objectLiteralCls === null || objectLiteralCls === void 0 ? void 0 : objectLiteralCls.getCategory()) !== ArkClass_1.ClassCategory.OBJECT) {
72
- return map;
73
- }
74
- objectLiteralCls === null || objectLiteralCls === void 0 ? void 0 : objectLiteralCls.getFields().forEach((field) => {
75
- let stmts = field.getInitializer();
76
- if (stmts.length === 0) {
77
- return;
78
- }
79
- let assignStmt = stmts[stmts.length - 1];
80
- if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
81
- return;
82
- }
83
- let value = assignStmt.getRightOp();
84
- if (value instanceof Local_1.Local) {
85
- value = backtraceLocalInitValue(value);
86
- }
87
- map.set(field, value);
88
- if (value instanceof Expr_1.ArkNewExpr) {
89
- let subCls = ModelUtils_1.ModelUtils.getArkClassInBuild(scene, value.getClassType());
90
- let childMap = parseObjectLiteral(subCls, scene);
91
- if (childMap) {
92
- map.set(field, childMap);
93
- }
94
- }
95
- });
96
- return map;
97
- }
98
- class StateValuesUtils {
99
- constructor(declaringArkClass) {
100
- this.declaringArkClass = declaringArkClass;
101
- }
102
- static getInstance(declaringArkClass) {
103
- return new StateValuesUtils(declaringArkClass);
104
- }
105
- parseStmtUsesStateValues(stmt, uses = new Set(), wholeMethod = false, visitor = new Set()) {
106
- if (visitor.has(stmt)) {
107
- return uses;
108
- }
109
- visitor.add(stmt);
110
- let values = stmt.getUses();
111
- if (stmt instanceof Stmt_1.ArkAssignStmt) {
112
- values.push(stmt.getLeftOp());
113
- }
114
- for (const v of values) {
115
- this.parseValueUsesStateValues(v, uses, wholeMethod, visitor);
116
- }
117
- return uses;
118
- }
119
- objectLiteralMapUsedStateValues(uses, map) {
120
- for (const [_, value] of map) {
121
- if (value instanceof Ref_1.ArkInstanceFieldRef) {
122
- let srcField = this.declaringArkClass.getFieldWithName(value.getFieldName());
123
- let decorators = srcField === null || srcField === void 0 ? void 0 : srcField.getStateDecorators();
124
- if (srcField && decorators && decorators.length > 0) {
125
- uses.add(srcField);
126
- }
127
- }
128
- else if (value instanceof Map) {
129
- this.objectLiteralMapUsedStateValues(uses, value);
130
- }
131
- else if (value instanceof Expr_1.ArkNormalBinopExpr || value instanceof Expr_1.ArkConditionExpr) {
132
- this.parseValueUsesStateValues(value.getOp1(), uses);
133
- this.parseValueUsesStateValues(value.getOp2(), uses);
134
- }
135
- }
136
- }
137
- parseObjectUsedStateValues(type, uses = new Set()) {
138
- if (!(type instanceof Type_1.ClassType)) {
139
- return uses;
140
- }
141
- let cls = ModelUtils_1.ModelUtils.getArkClassInBuild(this.declaringArkClass.getDeclaringArkFile().getScene(), type);
142
- let map = parseObjectLiteral(cls, this.declaringArkClass.getDeclaringArkFile().getScene());
143
- this.objectLiteralMapUsedStateValues(uses, map);
144
- return uses;
145
- }
146
- parseMethodUsesStateValues(methodSignature, uses, visitor = new Set()) {
147
- var _a;
148
- if (visitor.has(methodSignature)) {
149
- return;
150
- }
151
- visitor.add(methodSignature);
152
- let method = this.declaringArkClass.getDeclaringArkFile().getScene().getMethod(methodSignature);
153
- if (!method) {
154
- return;
155
- }
156
- let stmts = (_a = method.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts();
157
- if (!stmts) {
158
- return;
159
- }
160
- for (const stmt of stmts) {
161
- this.parseStmtUsesStateValues(stmt, uses, true, visitor);
162
- }
163
- }
164
- parseValueUsesStateValues(v, uses = new Set(), wholeMethod = false, visitor = new Set()) {
165
- if (v instanceof Ref_1.ArkInstanceFieldRef) {
166
- let field = this.declaringArkClass.getField(v.getFieldSignature());
167
- let decorators = field === null || field === void 0 ? void 0 : field.getStateDecorators();
168
- if (field && decorators && decorators.length > 0) {
169
- uses.add(field);
170
- }
171
- }
172
- else if (v instanceof Expr_1.ArkInstanceInvokeExpr) {
173
- this.parseMethodUsesStateValues(v.getMethodSignature(), uses, visitor);
174
- }
175
- else if (v instanceof Local_1.Local) {
176
- if (v.getName() === 'this') {
177
- return uses;
178
- }
179
- let type = v.getType();
180
- if (type instanceof Type_1.FunctionType) {
181
- this.parseMethodUsesStateValues(type.getMethodSignature(), uses, visitor);
182
- return uses;
183
- }
184
- this.parseObjectUsedStateValues(type, uses);
185
- let declaringStmt = v.getDeclaringStmt();
186
- if (!wholeMethod && declaringStmt) {
187
- this.parseStmtUsesStateValues(declaringStmt, uses, wholeMethod, visitor);
188
- }
189
- }
190
- return uses;
191
- }
192
- }
193
- var ViewTreeNodeType;
194
- (function (ViewTreeNodeType) {
195
- ViewTreeNodeType[ViewTreeNodeType["SystemComponent"] = 0] = "SystemComponent";
196
- ViewTreeNodeType[ViewTreeNodeType["CustomComponent"] = 1] = "CustomComponent";
197
- ViewTreeNodeType[ViewTreeNodeType["Builder"] = 2] = "Builder";
198
- ViewTreeNodeType[ViewTreeNodeType["BuilderParam"] = 3] = "BuilderParam";
199
- })(ViewTreeNodeType || (ViewTreeNodeType = {}));
200
- class ViewTreeNodeImpl {
201
- constructor(name) {
202
- this.name = name;
203
- this.attributes = new Map();
204
- this.stmts = this.attributes;
205
- this.stateValues = new Set();
206
- this.parent = null;
207
- this.children = [];
208
- this.type = ViewTreeNodeType.SystemComponent;
209
- }
210
- /**
211
- * Whether the node type is Builder.
212
- * @returns true: node is Builder, false others.
213
- */
214
- isBuilder() {
215
- return this.type === ViewTreeNodeType.Builder;
216
- }
217
- /**
218
- * @internal
219
- */
220
- isBuilderParam() {
221
- return this.type === ViewTreeNodeType.BuilderParam;
222
- }
223
- /**
224
- * Whether the node type is custom component.
225
- * @returns true: node is custom component, false others.
226
- */
227
- isCustomComponent() {
228
- return this.type === ViewTreeNodeType.CustomComponent;
229
- }
230
- /**
231
- * walk node and node's children
232
- * @param selector Node selector function, return true skipping the follow-up nodes.
233
- * @returns
234
- * - true: There are nodes that meet the selector.
235
- * - false: does not exist.
236
- */
237
- walk(selector, visitor = new Set()) {
238
- if (visitor.has(this)) {
239
- return false;
240
- }
241
- let ret = selector(this);
242
- visitor.add(this);
243
- for (const child of this.children) {
244
- ret = ret || child.walk(selector, visitor);
245
- if (ret) {
246
- break;
247
- }
248
- }
249
- return ret;
250
- }
251
- static createCustomComponent() {
252
- let instance = new ViewTreeNodeImpl(EtsConst_1.COMPONENT_CUSTOMVIEW);
253
- instance.type = ViewTreeNodeType.CustomComponent;
254
- return instance;
255
- }
256
- static createBuilderNode() {
257
- let instance = new ViewTreeNodeImpl(EtsConst_1.BUILDER_DECORATOR);
258
- instance.type = ViewTreeNodeType.Builder;
259
- return instance;
260
- }
261
- static createBuilderParamNode() {
262
- let instance = new ViewTreeNodeImpl(EtsConst_1.BUILDER_PARAM_DECORATOR);
263
- instance.type = ViewTreeNodeType.BuilderParam;
264
- return instance;
265
- }
266
- changeBuilderParam2BuilderNode(builder) {
267
- var _a;
268
- this.name = EtsConst_1.BUILDER_DECORATOR;
269
- this.type = ViewTreeNodeType.Builder;
270
- this.signature = builder.getSignature();
271
- this.classSignature = this.signature;
272
- const root = (_a = builder.getViewTree()) === null || _a === void 0 ? void 0 : _a.getRoot();
273
- if (root) {
274
- for (let child of root.children) {
275
- this.children.push(child);
276
- }
277
- }
278
- else {
279
- logger.error(`ViewTree->changeBuilderParam2BuilderNode ${builder.getSignature().toString()} @Builder viewtree fail.`);
280
- }
281
- }
282
- hasBuilderParam() {
283
- return this.walk((item) => {
284
- return item.isBuilderParam();
285
- });
286
- }
287
- clone(parent, map = new Map()) {
288
- let newNode = new ViewTreeNodeImpl(this.name);
289
- newNode.attributes = this.attributes;
290
- newNode.stmts = newNode.attributes;
291
- newNode.stateValues = this.stateValues;
292
- newNode.parent = parent;
293
- newNode.type = this.type;
294
- newNode.signature = this.signature;
295
- newNode.classSignature = newNode.signature;
296
- newNode.builderParam = this.builderParam;
297
- newNode.builder = this.builder;
298
- map.set(this, newNode);
299
- for (const child of this.children) {
300
- if (map.has(child)) {
301
- newNode.children.push(map.get(child));
302
- }
303
- else {
304
- newNode.children.push(child.clone(newNode, map));
305
- }
306
- }
307
- return newNode;
308
- }
309
- addStmt(tree, stmt) {
310
- this.parseAttributes(stmt);
311
- if (this.name !== EtsConst_1.COMPONENT_FOR_EACH && this.name !== EtsConst_1.COMPONENT_LAZY_FOR_EACH) {
312
- this.parseStateValues(tree, stmt);
313
- }
314
- }
315
- parseAttributes(stmt) {
316
- let expr;
317
- if (stmt instanceof Stmt_1.ArkAssignStmt) {
318
- let op = stmt.getRightOp();
319
- if (op instanceof Expr_1.ArkInstanceInvokeExpr) {
320
- expr = op;
321
- }
322
- else if (op instanceof Expr_1.ArkStaticInvokeExpr) {
323
- expr = op;
324
- }
325
- }
326
- else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
327
- let invoke = stmt.getInvokeExpr();
328
- if (invoke instanceof Expr_1.ArkInstanceInvokeExpr) {
329
- expr = invoke;
330
- }
331
- else if (invoke instanceof Expr_1.ArkStaticInvokeExpr) {
332
- expr = invoke;
333
- }
334
- }
335
- if (expr) {
336
- let key = expr.getMethodSignature().getMethodSubSignature().getMethodName();
337
- let relationValues = [];
338
- for (const arg of expr.getArgs()) {
339
- if (arg instanceof Local_1.Local) {
340
- this.getBindValues(arg, relationValues);
341
- }
342
- else if (arg instanceof Constant_1.Constant) {
343
- relationValues.push(arg);
344
- }
345
- }
346
- this.attributes.set(key, [stmt, relationValues]);
347
- }
348
- }
349
- getBindValues(local, relationValues, visitor = new Set()) {
350
- if (visitor.has(local)) {
351
- return;
352
- }
353
- visitor.add(local);
354
- const stmt = local.getDeclaringStmt();
355
- if (!stmt) {
356
- let type = local.getType();
357
- if (type instanceof Type_1.FunctionType) {
358
- relationValues.push(type.getMethodSignature());
359
- }
360
- return;
361
- }
362
- for (const v of stmt.getUses()) {
363
- if (v instanceof Constant_1.Constant) {
364
- relationValues.push(v);
365
- }
366
- else if (v instanceof Ref_1.ArkInstanceFieldRef) {
367
- relationValues.push(v);
368
- }
369
- else if (v instanceof Local_1.Local) {
370
- this.getBindValues(v, relationValues, visitor);
371
- }
372
- }
373
- }
374
- parseStateValues(tree, stmt) {
375
- let stateValues = StateValuesUtils.getInstance(tree.getDeclaringArkClass()).parseStmtUsesStateValues(stmt);
376
- stateValues.forEach((field) => {
377
- this.stateValues.add(field);
378
- tree.addStateValue(field, this);
379
- }, this);
380
- }
381
- }
382
- class TreeNodeStack {
383
- constructor() {
384
- this.root = null;
385
- this.stack = [];
386
- }
387
- /**
388
- * @internal
389
- */
390
- push(node) {
391
- let parent = this.getParent();
392
- node.parent = parent;
393
- this.stack.push(node);
394
- if (parent === null || parent === undefined) {
395
- this.root = node;
396
- }
397
- else {
398
- parent.children.push(node);
399
- }
400
- }
401
- /**
402
- * @internal
403
- */
404
- pop() {
405
- this.stack.pop();
406
- }
407
- /**
408
- * @internal
409
- */
410
- top() {
411
- return this.isEmpty() ? null : this.stack[this.stack.length - 1];
412
- }
413
- /**
414
- * @internal
415
- */
416
- isEmpty() {
417
- return this.stack.length === 0;
418
- }
419
- /**
420
- * @internal
421
- */
422
- popAutomicComponent(name) {
423
- if (this.isEmpty()) {
424
- return;
425
- }
426
- let node = this.stack[this.stack.length - 1];
427
- if (name !== node.name && !this.isContainer(node.name)) {
428
- this.stack.pop();
429
- }
430
- }
431
- /**
432
- * @internal
433
- */
434
- popComponentExpect(name) {
435
- for (let i = this.stack.length - 1; i >= 0; i--) {
436
- if (this.stack[i].name !== name) {
437
- this.stack.pop();
438
- }
439
- else {
440
- break;
441
- }
442
- }
443
- return this;
444
- }
445
- getParent() {
446
- if (this.stack.length === 0) {
447
- return null;
448
- }
449
- let node = this.stack[this.stack.length - 1];
450
- if (!this.isContainer(node.name)) {
451
- this.stack.pop();
452
- }
453
- return this.stack[this.stack.length - 1];
454
- }
455
- isContainer(name) {
456
- return (0, EtsConst_1.isEtsContainerComponent)(name) || EtsConst_1.SPECIAL_CONTAINER_COMPONENT.has(name) || name === EtsConst_1.BUILDER_DECORATOR;
457
- }
458
- }
459
- class ViewTreeImpl extends TreeNodeStack {
460
- /**
461
- * @internal
462
- */
463
- constructor(render) {
464
- super();
465
- this.COMPONENT_CREATE_PARSERS = new Map([
466
- ['ForEach.create', this.forEachCreationParser.bind(this)],
467
- ['LazyForEach.create', this.forEachCreationParser.bind(this)],
468
- ['Repeat.create', this.repeatCreationParser.bind(this)],
469
- ['View.create', this.viewComponentCreationParser.bind(this)],
470
- ['If.branch', this.ifBranchCreationParser.bind(this)],
471
- ['WaterFlow.create', this.waterFlowCreationParser.bind(this)],
472
- ]);
473
- this.render = render;
474
- this.stateValues = new Map();
475
- this.fieldTypes = new Map();
476
- this.buildViewStatus = false;
477
- }
478
- /**
479
- * ViewTree root node.
480
- * @returns root node
481
- */
482
- getRoot() {
483
- this.buildViewTree();
484
- return this.root;
485
- }
486
- /**
487
- * Map of the component controlled by the state variable
488
- * @returns
489
- */
490
- getStateValues() {
491
- this.buildViewTree();
492
- return this.stateValues;
493
- }
494
- /**
495
- * @deprecated Use {@link getStateValues} instead.
496
- */
497
- isClassField(name) {
498
- return this.fieldTypes.has(name);
499
- }
500
- /**
501
- * @deprecated Use {@link getStateValues} instead.
502
- */
503
- getClassFieldType(name) {
504
- return this.fieldTypes.get(name);
505
- }
506
- /**
507
- * @internal
508
- */
509
- buildViewTree() {
510
- if (!this.render || this.isInitialized()) {
511
- return;
512
- }
513
- this.buildViewStatus = true;
514
- this.loadClasssFieldTypes();
515
- if (this.render.hasBuilderDecorator()) {
516
- let node = ViewTreeNodeImpl.createBuilderNode();
517
- node.signature = this.render.getSignature();
518
- node.classSignature = node.signature;
519
- this.push(node);
520
- }
521
- if (this.render.getCfg()) {
522
- this.buildViewTreeFromCfg(this.render.getCfg());
523
- }
524
- }
525
- /**
526
- * @internal
527
- */
528
- isInitialized() {
529
- return this.root != null || this.buildViewStatus;
530
- }
531
- /**
532
- * @internal
533
- */
534
- addStateValue(field, node) {
535
- if (!this.stateValues.has(field)) {
536
- this.stateValues.set(field, new Set());
537
- }
538
- let sets = this.stateValues.get(field);
539
- sets === null || sets === void 0 ? void 0 : sets.add(node);
540
- }
541
- /**
542
- * @internal
543
- */
544
- isCreateFunc(name) {
545
- return COMPONENT_CREATE_FUNCTIONS.has(name);
546
- }
547
- loadClasssFieldTypes() {
548
- for (const field of this.render.getDeclaringArkClass().getFields()) {
549
- let decorators = field.getStateDecorators();
550
- if (decorators.length > 0) {
551
- if (decorators.length === 1) {
552
- this.fieldTypes.set(field.getName(), decorators[0]);
553
- }
554
- else {
555
- this.fieldTypes.set(field.getName(), decorators[0]);
556
- }
557
- }
558
- else {
559
- this.fieldTypes.set(field.getName(), field.getSignature().getType());
560
- }
561
- }
562
- }
563
- /**
564
- * @internal
565
- */
566
- getDeclaringArkClass() {
567
- return this.render.getDeclaringArkClass();
568
- }
569
- /**
570
- * @internal
571
- */
572
- findMethod(methodSignature) {
573
- let method = this.render.getDeclaringArkFile().getScene().getMethod(methodSignature);
574
- if (method) {
575
- return method;
576
- }
577
- // class
578
- method = this.getDeclaringArkClass().getMethod(methodSignature);
579
- if (method) {
580
- return method;
581
- }
582
- return this.findMethodWithName(methodSignature.getMethodSubSignature().getMethodName());
583
- }
584
- /**
585
- * @internal
586
- */
587
- findMethodWithName(name) {
588
- var _a;
589
- let method = this.getDeclaringArkClass().getMethodWithName(name);
590
- if (method) {
591
- return method;
592
- }
593
- // namespace
594
- (_a = this.getDeclaringArkClass()
595
- .getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getAllMethodsUnderThisNamespace().forEach((value) => {
596
- if (value.getName() === name) {
597
- method = value;
598
- }
599
- });
600
- if (method) {
601
- return method;
602
- }
603
- this.getDeclaringArkClass()
604
- .getDeclaringArkFile()
605
- .getAllNamespacesUnderThisFile()
606
- .forEach((namespace) => {
607
- namespace.getAllMethodsUnderThisNamespace().forEach((value) => {
608
- if (value.getName() === name) {
609
- method = value;
610
- }
611
- });
612
- });
613
- return method;
614
- }
615
- /**
616
- * @internal
617
- */
618
- findClass(classSignature) {
619
- return ModelUtils_1.ModelUtils.getClass(this.render, classSignature);
620
- }
621
- findBuilderMethod(value) {
622
- let method;
623
- if (value instanceof Ref_1.ArkInstanceFieldRef) {
624
- method = this.findMethodWithName(value.getFieldName());
625
- }
626
- else if (value instanceof Expr_1.ArkStaticInvokeExpr) {
627
- method = this.findMethod(value.getMethodSignature());
628
- }
629
- else if (value instanceof Local_1.Local && value.getType() instanceof Type_1.FunctionType) {
630
- method = this.findMethod(value.getType().getMethodSignature());
631
- }
632
- else if (value instanceof Local_1.Local) {
633
- method = this.findMethodWithName(value.getName());
634
- }
635
- if (method && !method.hasBuilderDecorator()) {
636
- method = this.findMethodInvokeBuilderMethod(method);
637
- }
638
- return method;
639
- }
640
- /**
641
- * @internal
642
- */
643
- addBuilderNode(method) {
644
- let builderViewTree = method.getViewTree();
645
- if (!builderViewTree || !builderViewTree.getRoot()) {
646
- logger.error(`ViewTree->addBuilderNode ${method.getSignature().toString()} build viewtree fail.`);
647
- // add empty node
648
- let node = ViewTreeNodeImpl.createBuilderNode();
649
- node.signature = method.getSignature();
650
- node.classSignature = node.signature;
651
- this.push(node);
652
- this.pop();
653
- return node;
654
- }
655
- let root = builderViewTree.getRoot();
656
- this.push(root);
657
- if (method.getDeclaringArkClass() === this.render.getDeclaringArkClass()) {
658
- for (const [field, nodes] of builderViewTree.getStateValues()) {
659
- for (const node of nodes) {
660
- this.addStateValue(field, node);
661
- }
662
- }
663
- }
664
- this.pop();
665
- return root;
666
- }
667
- /**
668
- * @internal
669
- */
670
- addCustomComponentNode(cls, arg, builder) {
671
- let node = ViewTreeNodeImpl.createCustomComponent();
672
- node.signature = cls.getSignature();
673
- node.classSignature = node.signature;
674
- node.stateValuesTransfer = this.parseObjectLiteralExpr(cls, arg, builder);
675
- if (arg instanceof Local_1.Local && arg.getType()) {
676
- let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseObjectUsedStateValues(arg.getType());
677
- stateValues.forEach((field) => {
678
- node.stateValues.add(field);
679
- this.addStateValue(field, node);
680
- });
681
- }
682
- this.push(node);
683
- let componentViewTree = cls.getViewTree();
684
- if (!componentViewTree || !componentViewTree.getRoot()) {
685
- logger.error(`ViewTree->addCustomComponentNode ${cls.getSignature().toString()} build viewtree fail.`);
686
- return node;
687
- }
688
- let root = componentViewTree.getRoot();
689
- if (root.hasBuilderParam()) {
690
- root = this.cloneBuilderParamNode(node, root);
691
- }
692
- node.children.push(root);
693
- return node;
694
- }
695
- cloneBuilderParamNode(node, root) {
696
- root = root.clone(node);
697
- if (node.stateValuesTransfer) {
698
- root.walk((item) => {
699
- var _a;
700
- let child = item;
701
- if (!child.isBuilderParam() || !child.builderParam) {
702
- return false;
703
- }
704
- let method = (_a = node.stateValuesTransfer) === null || _a === void 0 ? void 0 : _a.get(child.builderParam);
705
- if (method) {
706
- child.changeBuilderParam2BuilderNode(method);
707
- }
708
- return false;
709
- });
710
- }
711
- return root;
712
- }
713
- /**
714
- * @internal
715
- */
716
- addBuilderParamNode(field) {
717
- let node = ViewTreeNodeImpl.createBuilderParamNode();
718
- node.builderParam = field;
719
- this.push(node);
720
- this.pop();
721
- return node;
722
- }
723
- /**
724
- * @internal
725
- */
726
- addSystemComponentNode(name) {
727
- let node = new ViewTreeNodeImpl(name);
728
- this.push(node);
729
- return node;
730
- }
731
- findMethodInvokeBuilderMethod(method) {
732
- var _a;
733
- let stmts = (_a = method.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts();
734
- if (!stmts) {
735
- return;
736
- }
737
- for (const stmt of stmts) {
738
- let expr;
739
- if (stmt instanceof Stmt_1.ArkInvokeStmt) {
740
- expr = stmt.getInvokeExpr();
741
- }
742
- else if (stmt instanceof Stmt_1.ArkAssignStmt) {
743
- let rightOp = stmt.getRightOp();
744
- if (rightOp instanceof Expr_1.ArkInstanceInvokeExpr || rightOp instanceof Expr_1.ArkStaticInvokeExpr) {
745
- expr = rightOp;
746
- }
747
- }
748
- if (expr === undefined) {
749
- continue;
750
- }
751
- let method = this.findMethod(expr.getMethodSignature());
752
- if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
753
- return method;
754
- }
755
- }
756
- }
757
- parseObjectLiteralExpr(cls, object, builder) {
758
- let transferMap = new Map();
759
- if (object instanceof Local_1.Local && object.getType() instanceof Type_1.ClassType) {
760
- let anonymousSig = object.getType().getClassSignature();
761
- let anonymous = this.findClass(anonymousSig);
762
- anonymous === null || anonymous === void 0 ? void 0 : anonymous.getFields().forEach((field) => {
763
- let dstField = cls.getFieldWithName(field.getName());
764
- if ((dstField === null || dstField === void 0 ? void 0 : dstField.getStateDecorators().length) === 0 && !(dstField === null || dstField === void 0 ? void 0 : dstField.hasBuilderParamDecorator())) {
765
- return;
766
- }
767
- let stmts = field.getInitializer();
768
- if (stmts.length === 0) {
769
- return;
770
- }
771
- let assignStmt = stmts[stmts.length - 1];
772
- if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
773
- return;
774
- }
775
- let value = assignStmt.getRightOp();
776
- if (value instanceof Local_1.Local) {
777
- value = backtraceLocalInitValue(value);
778
- }
779
- if (dstField === null || dstField === void 0 ? void 0 : dstField.hasBuilderParamDecorator()) {
780
- let method = this.findBuilderMethod(value);
781
- if (method) {
782
- transferMap.set(dstField, method);
783
- }
784
- }
785
- else {
786
- let srcField;
787
- if (value instanceof Ref_1.ArkInstanceFieldRef) {
788
- srcField = this.getDeclaringArkClass().getFieldWithName(value.getFieldName());
789
- }
790
- if (srcField && dstField) {
791
- transferMap.set(dstField, srcField);
792
- }
793
- }
794
- });
795
- }
796
- // If the builder exists, there will be a unique BuilderParam
797
- if (builder) {
798
- cls.getFields().forEach((value) => {
799
- if (value.hasBuilderParamDecorator()) {
800
- transferMap.set(value, builder);
801
- }
802
- });
803
- }
804
- if (transferMap.size === 0) {
805
- return;
806
- }
807
- return transferMap;
808
- }
809
- viewComponentCreationParser(name, stmt, expr) {
810
- let temp = expr.getArg(0);
811
- let arg;
812
- temp.getUsedStmts().forEach((value) => {
813
- if (value instanceof Stmt_1.ArkInvokeStmt) {
814
- let invokerExpr = value.getInvokeExpr();
815
- let methodName = invokerExpr.getMethodSignature().getMethodSubSignature().getMethodName();
816
- if (methodName === 'constructor') {
817
- arg = invokerExpr.getArg(0);
818
- }
819
- }
820
- });
821
- let builderMethod;
822
- let builder = expr.getArg(1);
823
- if (builder) {
824
- let method = this.findMethod(builder.getType().getMethodSignature());
825
- if (!(method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
826
- method === null || method === void 0 ? void 0 : method.addDecorator(new Decorator_1.Decorator(EtsConst_1.BUILDER_DECORATOR));
827
- }
828
- if (!(method === null || method === void 0 ? void 0 : method.hasViewTree())) {
829
- method === null || method === void 0 ? void 0 : method.setViewTree(new ViewTreeImpl(method));
830
- }
831
- if (method) {
832
- builderMethod = method;
833
- }
834
- }
835
- let initValue = backtraceLocalInitValue(temp);
836
- if (!(initValue instanceof Expr_1.ArkNewExpr)) {
837
- return undefined;
838
- }
839
- let clsSignature = initValue.getType().getClassSignature();
840
- if (clsSignature) {
841
- let cls = this.findClass(clsSignature);
842
- if (cls && cls.hasComponentDecorator()) {
843
- return this.addCustomComponentNode(cls, arg, builderMethod);
844
- }
845
- else {
846
- logger.error(`ViewTree->viewComponentCreationParser not found class ${clsSignature.toString()}. ${stmt.toString()}`);
847
- }
848
- }
849
- return undefined;
850
- }
851
- waterFlowCreationParser(name, stmt, expr) {
852
- let node = this.addSystemComponentNode(name);
853
- let object = expr.getArg(0);
854
- if (object instanceof Local_1.Local && object.getType() instanceof Type_1.ClassType) {
855
- let anonymousSig = object.getType().getClassSignature();
856
- let anonymous = this.findClass(anonymousSig);
857
- let footer = anonymous === null || anonymous === void 0 ? void 0 : anonymous.getFieldWithName('footer');
858
- if (!footer) {
859
- return node;
860
- }
861
- let stmts = footer.getInitializer();
862
- let assignStmt = stmts[stmts.length - 1];
863
- if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
864
- return node;
865
- }
866
- let value = assignStmt.getRightOp();
867
- let method = this.findBuilderMethod(value);
868
- if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
869
- return this.addBuilderNode(method);
870
- }
871
- }
872
- return node;
873
- }
874
- forEachCreationParser(name, stmt, expr) {
875
- let node = this.addSystemComponentNode(name);
876
- let values = expr.getArg(0);
877
- let declaringStmt = values === null || values === void 0 ? void 0 : values.getDeclaringStmt();
878
- if (declaringStmt) {
879
- let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseStmtUsesStateValues(declaringStmt);
880
- stateValues.forEach((field) => {
881
- node.stateValues.add(field);
882
- this.addStateValue(field, node);
883
- });
884
- }
885
- let type = expr.getArg(1).getType();
886
- let method = this.findMethod(type.getMethodSignature());
887
- if (method && method.getCfg()) {
888
- this.buildViewTreeFromCfg(method.getCfg());
889
- }
890
- return node;
891
- }
892
- repeatCreationParser(name, stmt, expr) {
893
- let node = this.addSystemComponentNode(name);
894
- let arg = expr.getArg(0);
895
- let declaringStmt = arg === null || arg === void 0 ? void 0 : arg.getDeclaringStmt();
896
- if (declaringStmt) {
897
- let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseStmtUsesStateValues(declaringStmt);
898
- stateValues.forEach((field) => {
899
- node.stateValues.add(field);
900
- this.addStateValue(field, node);
901
- });
902
- }
903
- return node;
904
- }
905
- ifBranchCreationParser(name, stmt, expr) {
906
- this.popComponentExpect(EtsConst_1.COMPONENT_IF);
907
- return this.addSystemComponentNode(EtsConst_1.COMPONENT_IF_BRANCH);
908
- }
909
- componentCreateParse(componentName, methodName, stmt, expr) {
910
- let parserFn = this.COMPONENT_CREATE_PARSERS.get(`${componentName}.${methodName}`);
911
- if (parserFn) {
912
- let node = parserFn(componentName, stmt, expr);
913
- node === null || node === void 0 ? void 0 : node.addStmt(this, stmt);
914
- return node;
915
- }
916
- this.popAutomicComponent(componentName);
917
- let node = this.addSystemComponentNode(componentName);
918
- node.addStmt(this, stmt);
919
- return node;
920
- }
921
- parseStaticInvokeExpr(local2Node, stmt, expr) {
922
- let methodSignature = expr.getMethodSignature();
923
- let method = this.findMethod(methodSignature);
924
- if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
925
- let node = this.addBuilderNode(method);
926
- node.parseStateValues(this, stmt);
927
- return node;
928
- }
929
- let name = methodSignature.getDeclaringClassSignature().getClassName();
930
- let methodName = methodSignature.getMethodSubSignature().getMethodName();
931
- if (this.isCreateFunc(methodName)) {
932
- return this.componentCreateParse(name, methodName, stmt, expr);
933
- }
934
- let currentNode = this.top();
935
- if (name === (currentNode === null || currentNode === void 0 ? void 0 : currentNode.name)) {
936
- currentNode.addStmt(this, stmt);
937
- if (methodName === EtsConst_1.COMPONENT_POP_FUNCTION) {
938
- this.pop();
939
- }
940
- return currentNode;
941
- }
942
- else if (name === EtsConst_1.COMPONENT_IF && methodName === EtsConst_1.COMPONENT_POP_FUNCTION) {
943
- this.popComponentExpect(EtsConst_1.COMPONENT_IF);
944
- this.pop();
945
- }
946
- return undefined;
947
- }
948
- /**
949
- * $temp4.margin({ top: 20 });
950
- * @param viewTree
951
- * @param local2Node
952
- * @param expr
953
- */
954
- parseInstanceInvokeExpr(local2Node, stmt, expr) {
955
- let temp = expr.getBase();
956
- if (local2Node.has(temp)) {
957
- let component = local2Node.get(temp);
958
- if ((component === null || component === void 0 ? void 0 : component.name) === EtsConst_1.COMPONENT_REPEAT &&
959
- expr.getMethodSignature().getMethodSubSignature().getMethodName() === 'each') {
960
- let arg = expr.getArg(0);
961
- let type = arg.getType();
962
- if (type instanceof Type_1.FunctionType) {
963
- let method = this.findMethod(type.getMethodSignature());
964
- this.buildViewTreeFromCfg(method === null || method === void 0 ? void 0 : method.getCfg());
965
- }
966
- this.pop();
967
- }
968
- else {
969
- component === null || component === void 0 ? void 0 : component.addStmt(this, stmt);
970
- }
971
- return component;
972
- }
973
- let name = expr.getBase().getName();
974
- if (name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
975
- let initValue = backtraceLocalInitValue(expr.getBase());
976
- if (initValue instanceof Ref_1.ArkThisRef) {
977
- name = 'this';
978
- }
979
- }
980
- let methodName = expr.getMethodSignature().getMethodSubSignature().getMethodName();
981
- let field = this.getDeclaringArkClass().getFieldWithName(methodName);
982
- if (name === 'this' && (field === null || field === void 0 ? void 0 : field.hasBuilderParamDecorator())) {
983
- return this.addBuilderParamNode(field);
984
- }
985
- let method = this.findMethod(expr.getMethodSignature());
986
- if (name === 'this' && (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
987
- return this.addBuilderNode(method);
988
- }
989
- return undefined;
990
- }
991
- /**
992
- * $temp3 = View.create($temp2);
993
- * $temp4 = View.pop();
994
- * $temp4.margin({ top: 20 });
995
- *
996
- * $temp2 = List.create();
997
- * $temp5 = $temp2.width('100%');
998
- * $temp6 = $temp5.height('100%');
999
- * $temp6.backgroundColor('#FFDCDCDC');
1000
- * @param viewTree
1001
- * @param local2Node
1002
- * @param stmt
1003
- * @returns
1004
- */
1005
- parseAssignStmt(local2Node, stmt) {
1006
- let left = stmt.getLeftOp();
1007
- let right = stmt.getRightOp();
1008
- if (!(left instanceof Local_1.Local)) {
1009
- return;
1010
- }
1011
- let component;
1012
- if (right instanceof Expr_1.ArkStaticInvokeExpr) {
1013
- component = this.parseStaticInvokeExpr(local2Node, stmt, right);
1014
- }
1015
- else if (right instanceof Expr_1.ArkInstanceInvokeExpr) {
1016
- component = this.parseInstanceInvokeExpr(local2Node, stmt, right);
1017
- }
1018
- if (component) {
1019
- local2Node.set(left, component);
1020
- }
1021
- }
1022
- parseInvokeStmt(local2Node, stmt) {
1023
- let expr = stmt.getInvokeExpr();
1024
- if (expr instanceof Expr_1.ArkStaticInvokeExpr) {
1025
- this.parseStaticInvokeExpr(local2Node, stmt, expr);
1026
- }
1027
- else if (expr instanceof Expr_1.ArkInstanceInvokeExpr) {
1028
- this.parseInstanceInvokeExpr(local2Node, stmt, expr);
1029
- }
1030
- }
1031
- buildViewTreeFromCfg(cfg, local2Node = new Map()) {
1032
- if (!cfg) {
1033
- return;
1034
- }
1035
- let blocks = cfg.getBlocks();
1036
- for (const block of blocks) {
1037
- for (const stmt of block.getStmts()) {
1038
- if (!(stmt instanceof Stmt_1.ArkInvokeStmt || stmt instanceof Stmt_1.ArkAssignStmt)) {
1039
- continue;
1040
- }
1041
- if (stmt instanceof Stmt_1.ArkAssignStmt) {
1042
- this.parseAssignStmt(local2Node, stmt);
1043
- }
1044
- else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
1045
- this.parseInvokeStmt(local2Node, stmt);
1046
- }
1047
- }
1048
- }
1049
- }
1050
- }
1051
- exports.ViewTreeImpl = ViewTreeImpl;
1052
- function buildViewTree(render) {
1053
- return new ViewTreeImpl(render);
1054
- }
1055
- exports.buildViewTree = buildViewTree;
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ var desc = Object.getOwnPropertyDescriptor(m, k);
19
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
+ }
22
+ Object.defineProperty(o, k2, desc);
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
31
+ });
32
+ var __importStar = (this && this.__importStar) || function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.buildViewTree = exports.ViewTreeImpl = void 0;
41
+ const Constant_1 = require("../../base/Constant");
42
+ const Decorator_1 = require("../../base/Decorator");
43
+ const Expr_1 = require("../../base/Expr");
44
+ const Local_1 = require("../../base/Local");
45
+ const Ref_1 = require("../../base/Ref");
46
+ const Stmt_1 = require("../../base/Stmt");
47
+ const Type_1 = require("../../base/Type");
48
+ const EtsConst_1 = require("../../common/EtsConst");
49
+ const ArkClass_1 = require("../../model/ArkClass");
50
+ const logger_1 = __importStar(require("../../../utils/logger"));
51
+ const ModelUtils_1 = require("../../common/ModelUtils");
52
+ const Const_1 = require("../../common/Const");
53
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ViewTreeBuilder');
54
+ const COMPONENT_CREATE_FUNCTIONS = new Set([EtsConst_1.COMPONENT_CREATE_FUNCTION, EtsConst_1.COMPONENT_BRANCH_FUNCTION]);
55
+ function backtraceLocalInitValue(value) {
56
+ let stmt = value.getDeclaringStmt();
57
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
58
+ let rightOp = stmt.getRightOp();
59
+ if (rightOp instanceof Local_1.Local) {
60
+ return backtraceLocalInitValue(rightOp);
61
+ }
62
+ else if (rightOp instanceof Ref_1.ArkInstanceFieldRef && rightOp.getBase().getName().startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
63
+ return backtraceLocalInitValue(rightOp.getBase());
64
+ }
65
+ else if (rightOp instanceof Ref_1.ArkArrayRef) {
66
+ return backtraceLocalInitValue(rightOp.getBase());
67
+ }
68
+ return rightOp;
69
+ }
70
+ return value;
71
+ }
72
+ function parseObjectLiteral(objectLiteralCls, scene) {
73
+ let map = new Map();
74
+ if ((objectLiteralCls === null || objectLiteralCls === void 0 ? void 0 : objectLiteralCls.getCategory()) !== ArkClass_1.ClassCategory.OBJECT) {
75
+ return map;
76
+ }
77
+ objectLiteralCls === null || objectLiteralCls === void 0 ? void 0 : objectLiteralCls.getFields().forEach((field) => {
78
+ let stmts = field.getInitializer();
79
+ if (stmts.length === 0) {
80
+ return;
81
+ }
82
+ let assignStmt = stmts[stmts.length - 1];
83
+ if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
84
+ return;
85
+ }
86
+ let value = assignStmt.getRightOp();
87
+ if (value instanceof Local_1.Local) {
88
+ value = backtraceLocalInitValue(value);
89
+ }
90
+ map.set(field, value);
91
+ if (value instanceof Expr_1.ArkNewExpr) {
92
+ let subCls = ModelUtils_1.ModelUtils.getArkClassInBuild(scene, value.getClassType());
93
+ let childMap = parseObjectLiteral(subCls, scene);
94
+ if (childMap) {
95
+ map.set(field, childMap);
96
+ }
97
+ }
98
+ });
99
+ return map;
100
+ }
101
+ class StateValuesUtils {
102
+ constructor(declaringArkClass) {
103
+ this.declaringArkClass = declaringArkClass;
104
+ }
105
+ static getInstance(declaringArkClass) {
106
+ return new StateValuesUtils(declaringArkClass);
107
+ }
108
+ parseStmtUsesStateValues(stmt, uses = new Set(), wholeMethod = false, visitor = new Set()) {
109
+ if (visitor.has(stmt)) {
110
+ return uses;
111
+ }
112
+ visitor.add(stmt);
113
+ let values = stmt.getUses();
114
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
115
+ values.push(stmt.getLeftOp());
116
+ }
117
+ for (const v of values) {
118
+ this.parseValueUsesStateValues(v, uses, wholeMethod, visitor);
119
+ }
120
+ return uses;
121
+ }
122
+ objectLiteralMapUsedStateValues(uses, map) {
123
+ for (const [_, value] of map) {
124
+ if (value instanceof Ref_1.ArkInstanceFieldRef) {
125
+ let srcField = this.declaringArkClass.getFieldWithName(value.getFieldName());
126
+ let decorators = srcField === null || srcField === void 0 ? void 0 : srcField.getStateDecorators();
127
+ if (srcField && decorators && decorators.length > 0) {
128
+ uses.add(srcField);
129
+ }
130
+ }
131
+ else if (value instanceof Map) {
132
+ this.objectLiteralMapUsedStateValues(uses, value);
133
+ }
134
+ else if (value instanceof Expr_1.ArkNormalBinopExpr || value instanceof Expr_1.ArkConditionExpr) {
135
+ this.parseValueUsesStateValues(value.getOp1(), uses);
136
+ this.parseValueUsesStateValues(value.getOp2(), uses);
137
+ }
138
+ }
139
+ }
140
+ parseObjectUsedStateValues(type, uses = new Set()) {
141
+ if (!(type instanceof Type_1.ClassType)) {
142
+ return uses;
143
+ }
144
+ let cls = ModelUtils_1.ModelUtils.getArkClassInBuild(this.declaringArkClass.getDeclaringArkFile().getScene(), type);
145
+ let map = parseObjectLiteral(cls, this.declaringArkClass.getDeclaringArkFile().getScene());
146
+ this.objectLiteralMapUsedStateValues(uses, map);
147
+ return uses;
148
+ }
149
+ parseMethodUsesStateValues(methodSignature, uses, visitor = new Set()) {
150
+ var _a;
151
+ if (visitor.has(methodSignature)) {
152
+ return;
153
+ }
154
+ visitor.add(methodSignature);
155
+ let method = this.declaringArkClass.getDeclaringArkFile().getScene().getMethod(methodSignature);
156
+ if (!method) {
157
+ return;
158
+ }
159
+ let stmts = (_a = method.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts();
160
+ if (!stmts) {
161
+ return;
162
+ }
163
+ for (const stmt of stmts) {
164
+ this.parseStmtUsesStateValues(stmt, uses, true, visitor);
165
+ }
166
+ }
167
+ parseValueUsesStateValues(v, uses = new Set(), wholeMethod = false, visitor = new Set()) {
168
+ if (v instanceof Ref_1.ArkInstanceFieldRef) {
169
+ let field = this.declaringArkClass.getField(v.getFieldSignature());
170
+ let decorators = field === null || field === void 0 ? void 0 : field.getStateDecorators();
171
+ if (field && decorators && decorators.length > 0) {
172
+ uses.add(field);
173
+ }
174
+ }
175
+ else if (v instanceof Expr_1.ArkInstanceInvokeExpr) {
176
+ this.parseMethodUsesStateValues(v.getMethodSignature(), uses, visitor);
177
+ }
178
+ else if (v instanceof Local_1.Local) {
179
+ if (v.getName() === 'this') {
180
+ return uses;
181
+ }
182
+ let type = v.getType();
183
+ if (type instanceof Type_1.FunctionType) {
184
+ this.parseMethodUsesStateValues(type.getMethodSignature(), uses, visitor);
185
+ return uses;
186
+ }
187
+ this.parseObjectUsedStateValues(type, uses);
188
+ let declaringStmt = v.getDeclaringStmt();
189
+ if (!wholeMethod && declaringStmt) {
190
+ this.parseStmtUsesStateValues(declaringStmt, uses, wholeMethod, visitor);
191
+ }
192
+ }
193
+ return uses;
194
+ }
195
+ }
196
+ var ViewTreeNodeType;
197
+ (function (ViewTreeNodeType) {
198
+ ViewTreeNodeType[ViewTreeNodeType["SystemComponent"] = 0] = "SystemComponent";
199
+ ViewTreeNodeType[ViewTreeNodeType["CustomComponent"] = 1] = "CustomComponent";
200
+ ViewTreeNodeType[ViewTreeNodeType["Builder"] = 2] = "Builder";
201
+ ViewTreeNodeType[ViewTreeNodeType["BuilderParam"] = 3] = "BuilderParam";
202
+ })(ViewTreeNodeType || (ViewTreeNodeType = {}));
203
+ class ViewTreeNodeImpl {
204
+ constructor(name) {
205
+ this.name = name;
206
+ this.attributes = new Map();
207
+ this.stmts = this.attributes;
208
+ this.stateValues = new Set();
209
+ this.parent = null;
210
+ this.children = [];
211
+ this.type = ViewTreeNodeType.SystemComponent;
212
+ }
213
+ /**
214
+ * Whether the node type is Builder.
215
+ * @returns true: node is Builder, false others.
216
+ */
217
+ isBuilder() {
218
+ return this.type === ViewTreeNodeType.Builder;
219
+ }
220
+ /**
221
+ * @internal
222
+ */
223
+ isBuilderParam() {
224
+ return this.type === ViewTreeNodeType.BuilderParam;
225
+ }
226
+ /**
227
+ * Whether the node type is custom component.
228
+ * @returns true: node is custom component, false others.
229
+ */
230
+ isCustomComponent() {
231
+ return this.type === ViewTreeNodeType.CustomComponent;
232
+ }
233
+ /**
234
+ * walk node and node's children
235
+ * @param selector Node selector function, return true skipping the follow-up nodes.
236
+ * @returns
237
+ * - true: There are nodes that meet the selector.
238
+ * - false: does not exist.
239
+ */
240
+ walk(selector, visitor = new Set()) {
241
+ if (visitor.has(this)) {
242
+ return false;
243
+ }
244
+ let ret = selector(this);
245
+ visitor.add(this);
246
+ for (const child of this.children) {
247
+ ret = ret || child.walk(selector, visitor);
248
+ if (ret) {
249
+ break;
250
+ }
251
+ }
252
+ return ret;
253
+ }
254
+ static createCustomComponent() {
255
+ let instance = new ViewTreeNodeImpl(EtsConst_1.COMPONENT_CUSTOMVIEW);
256
+ instance.type = ViewTreeNodeType.CustomComponent;
257
+ return instance;
258
+ }
259
+ static createBuilderNode() {
260
+ let instance = new ViewTreeNodeImpl(EtsConst_1.BUILDER_DECORATOR);
261
+ instance.type = ViewTreeNodeType.Builder;
262
+ return instance;
263
+ }
264
+ static createBuilderParamNode() {
265
+ let instance = new ViewTreeNodeImpl(EtsConst_1.BUILDER_PARAM_DECORATOR);
266
+ instance.type = ViewTreeNodeType.BuilderParam;
267
+ return instance;
268
+ }
269
+ changeBuilderParam2BuilderNode(builder) {
270
+ var _a;
271
+ this.name = EtsConst_1.BUILDER_DECORATOR;
272
+ this.type = ViewTreeNodeType.Builder;
273
+ this.signature = builder.getSignature();
274
+ this.classSignature = this.signature;
275
+ const root = (_a = builder.getViewTree()) === null || _a === void 0 ? void 0 : _a.getRoot();
276
+ if (root) {
277
+ for (let child of root.children) {
278
+ this.children.push(child);
279
+ }
280
+ }
281
+ else {
282
+ logger.error(`ViewTree->changeBuilderParam2BuilderNode ${builder.getSignature().toString()} @Builder viewtree fail.`);
283
+ }
284
+ }
285
+ hasBuilderParam() {
286
+ return this.walk((item) => {
287
+ return item.isBuilderParam();
288
+ });
289
+ }
290
+ clone(parent, map = new Map()) {
291
+ let newNode = new ViewTreeNodeImpl(this.name);
292
+ newNode.attributes = this.attributes;
293
+ newNode.stmts = newNode.attributes;
294
+ newNode.stateValues = this.stateValues;
295
+ newNode.parent = parent;
296
+ newNode.type = this.type;
297
+ newNode.signature = this.signature;
298
+ newNode.classSignature = newNode.signature;
299
+ newNode.builderParam = this.builderParam;
300
+ newNode.builder = this.builder;
301
+ map.set(this, newNode);
302
+ for (const child of this.children) {
303
+ if (map.has(child)) {
304
+ newNode.children.push(map.get(child));
305
+ }
306
+ else {
307
+ newNode.children.push(child.clone(newNode, map));
308
+ }
309
+ }
310
+ return newNode;
311
+ }
312
+ addStmt(tree, stmt) {
313
+ this.parseAttributes(stmt);
314
+ if (this.name !== EtsConst_1.COMPONENT_FOR_EACH && this.name !== EtsConst_1.COMPONENT_LAZY_FOR_EACH) {
315
+ this.parseStateValues(tree, stmt);
316
+ }
317
+ }
318
+ parseAttributes(stmt) {
319
+ let expr;
320
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
321
+ let op = stmt.getRightOp();
322
+ if (op instanceof Expr_1.ArkInstanceInvokeExpr) {
323
+ expr = op;
324
+ }
325
+ else if (op instanceof Expr_1.ArkStaticInvokeExpr) {
326
+ expr = op;
327
+ }
328
+ }
329
+ else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
330
+ let invoke = stmt.getInvokeExpr();
331
+ if (invoke instanceof Expr_1.ArkInstanceInvokeExpr) {
332
+ expr = invoke;
333
+ }
334
+ else if (invoke instanceof Expr_1.ArkStaticInvokeExpr) {
335
+ expr = invoke;
336
+ }
337
+ }
338
+ if (expr) {
339
+ let key = expr.getMethodSignature().getMethodSubSignature().getMethodName();
340
+ let relationValues = [];
341
+ for (const arg of expr.getArgs()) {
342
+ if (arg instanceof Local_1.Local) {
343
+ this.getBindValues(arg, relationValues);
344
+ }
345
+ else if (arg instanceof Constant_1.Constant) {
346
+ relationValues.push(arg);
347
+ }
348
+ }
349
+ this.attributes.set(key, [stmt, relationValues]);
350
+ }
351
+ }
352
+ getBindValues(local, relationValues, visitor = new Set()) {
353
+ if (visitor.has(local)) {
354
+ return;
355
+ }
356
+ visitor.add(local);
357
+ const stmt = local.getDeclaringStmt();
358
+ if (!stmt) {
359
+ let type = local.getType();
360
+ if (type instanceof Type_1.FunctionType) {
361
+ relationValues.push(type.getMethodSignature());
362
+ }
363
+ return;
364
+ }
365
+ for (const v of stmt.getUses()) {
366
+ if (v instanceof Constant_1.Constant) {
367
+ relationValues.push(v);
368
+ }
369
+ else if (v instanceof Ref_1.ArkInstanceFieldRef) {
370
+ relationValues.push(v);
371
+ }
372
+ else if (v instanceof Local_1.Local) {
373
+ this.getBindValues(v, relationValues, visitor);
374
+ }
375
+ }
376
+ }
377
+ parseStateValues(tree, stmt) {
378
+ let stateValues = StateValuesUtils.getInstance(tree.getDeclaringArkClass()).parseStmtUsesStateValues(stmt);
379
+ stateValues.forEach((field) => {
380
+ this.stateValues.add(field);
381
+ tree.addStateValue(field, this);
382
+ }, this);
383
+ }
384
+ }
385
+ class TreeNodeStack {
386
+ constructor() {
387
+ this.root = null;
388
+ this.stack = [];
389
+ }
390
+ /**
391
+ * @internal
392
+ */
393
+ push(node) {
394
+ let parent = this.getParent();
395
+ node.parent = parent;
396
+ this.stack.push(node);
397
+ if (parent === null || parent === undefined) {
398
+ this.root = node;
399
+ }
400
+ else {
401
+ parent.children.push(node);
402
+ }
403
+ }
404
+ /**
405
+ * @internal
406
+ */
407
+ pop() {
408
+ this.stack.pop();
409
+ }
410
+ /**
411
+ * @internal
412
+ */
413
+ top() {
414
+ return this.isEmpty() ? null : this.stack[this.stack.length - 1];
415
+ }
416
+ /**
417
+ * @internal
418
+ */
419
+ isEmpty() {
420
+ return this.stack.length === 0;
421
+ }
422
+ /**
423
+ * @internal
424
+ */
425
+ popAutomicComponent(name) {
426
+ if (this.isEmpty()) {
427
+ return;
428
+ }
429
+ let node = this.stack[this.stack.length - 1];
430
+ if (name !== node.name && !this.isContainer(node.name)) {
431
+ this.stack.pop();
432
+ }
433
+ }
434
+ /**
435
+ * @internal
436
+ */
437
+ popComponentExpect(name) {
438
+ for (let i = this.stack.length - 1; i >= 0; i--) {
439
+ if (this.stack[i].name !== name) {
440
+ this.stack.pop();
441
+ }
442
+ else {
443
+ break;
444
+ }
445
+ }
446
+ return this;
447
+ }
448
+ getParent() {
449
+ if (this.stack.length === 0) {
450
+ return null;
451
+ }
452
+ let node = this.stack[this.stack.length - 1];
453
+ if (!this.isContainer(node.name)) {
454
+ this.stack.pop();
455
+ }
456
+ return this.stack[this.stack.length - 1];
457
+ }
458
+ isContainer(name) {
459
+ return (0, EtsConst_1.isEtsContainerComponent)(name) || EtsConst_1.SPECIAL_CONTAINER_COMPONENT.has(name) || name === EtsConst_1.BUILDER_DECORATOR;
460
+ }
461
+ }
462
+ class ViewTreeImpl extends TreeNodeStack {
463
+ /**
464
+ * @internal
465
+ */
466
+ constructor(render) {
467
+ super();
468
+ this.COMPONENT_CREATE_PARSERS = new Map([
469
+ ['ForEach.create', this.forEachCreationParser.bind(this)],
470
+ ['LazyForEach.create', this.forEachCreationParser.bind(this)],
471
+ ['Repeat.create', this.repeatCreationParser.bind(this)],
472
+ ['View.create', this.viewComponentCreationParser.bind(this)],
473
+ ['If.branch', this.ifBranchCreationParser.bind(this)],
474
+ ['WaterFlow.create', this.waterFlowCreationParser.bind(this)],
475
+ ]);
476
+ this.render = render;
477
+ this.stateValues = new Map();
478
+ this.fieldTypes = new Map();
479
+ this.buildViewStatus = false;
480
+ }
481
+ /**
482
+ * ViewTree root node.
483
+ * @returns root node
484
+ */
485
+ getRoot() {
486
+ this.buildViewTree();
487
+ return this.root;
488
+ }
489
+ /**
490
+ * Map of the component controlled by the state variable
491
+ * @returns
492
+ */
493
+ getStateValues() {
494
+ this.buildViewTree();
495
+ return this.stateValues;
496
+ }
497
+ /**
498
+ * @deprecated Use {@link getStateValues} instead.
499
+ */
500
+ isClassField(name) {
501
+ return this.fieldTypes.has(name);
502
+ }
503
+ /**
504
+ * @deprecated Use {@link getStateValues} instead.
505
+ */
506
+ getClassFieldType(name) {
507
+ return this.fieldTypes.get(name);
508
+ }
509
+ /**
510
+ * @internal
511
+ */
512
+ buildViewTree() {
513
+ if (!this.render || this.isInitialized()) {
514
+ return;
515
+ }
516
+ this.buildViewStatus = true;
517
+ this.loadClasssFieldTypes();
518
+ if (this.render.hasBuilderDecorator()) {
519
+ let node = ViewTreeNodeImpl.createBuilderNode();
520
+ node.signature = this.render.getSignature();
521
+ node.classSignature = node.signature;
522
+ this.push(node);
523
+ }
524
+ if (this.render.getCfg()) {
525
+ this.buildViewTreeFromCfg(this.render.getCfg());
526
+ }
527
+ }
528
+ /**
529
+ * @internal
530
+ */
531
+ isInitialized() {
532
+ return this.root != null || this.buildViewStatus;
533
+ }
534
+ /**
535
+ * @internal
536
+ */
537
+ addStateValue(field, node) {
538
+ if (!this.stateValues.has(field)) {
539
+ this.stateValues.set(field, new Set());
540
+ }
541
+ let sets = this.stateValues.get(field);
542
+ sets === null || sets === void 0 ? void 0 : sets.add(node);
543
+ }
544
+ /**
545
+ * @internal
546
+ */
547
+ isCreateFunc(name) {
548
+ return COMPONENT_CREATE_FUNCTIONS.has(name);
549
+ }
550
+ loadClasssFieldTypes() {
551
+ for (const field of this.render.getDeclaringArkClass().getFields()) {
552
+ let decorators = field.getStateDecorators();
553
+ if (decorators.length > 0) {
554
+ if (decorators.length === 1) {
555
+ this.fieldTypes.set(field.getName(), decorators[0]);
556
+ }
557
+ else {
558
+ this.fieldTypes.set(field.getName(), decorators[0]);
559
+ }
560
+ }
561
+ else {
562
+ this.fieldTypes.set(field.getName(), field.getSignature().getType());
563
+ }
564
+ }
565
+ }
566
+ /**
567
+ * @internal
568
+ */
569
+ getDeclaringArkClass() {
570
+ return this.render.getDeclaringArkClass();
571
+ }
572
+ /**
573
+ * @internal
574
+ */
575
+ findMethod(methodSignature) {
576
+ let method = this.render.getDeclaringArkFile().getScene().getMethod(methodSignature);
577
+ if (method) {
578
+ return method;
579
+ }
580
+ // class
581
+ method = this.getDeclaringArkClass().getMethod(methodSignature);
582
+ if (method) {
583
+ return method;
584
+ }
585
+ return this.findMethodWithName(methodSignature.getMethodSubSignature().getMethodName());
586
+ }
587
+ /**
588
+ * @internal
589
+ */
590
+ findMethodWithName(name) {
591
+ var _a;
592
+ let method = this.getDeclaringArkClass().getMethodWithName(name);
593
+ if (method) {
594
+ return method;
595
+ }
596
+ // namespace
597
+ (_a = this.getDeclaringArkClass()
598
+ .getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getAllMethodsUnderThisNamespace().forEach((value) => {
599
+ if (value.getName() === name) {
600
+ method = value;
601
+ }
602
+ });
603
+ if (method) {
604
+ return method;
605
+ }
606
+ this.getDeclaringArkClass()
607
+ .getDeclaringArkFile()
608
+ .getAllNamespacesUnderThisFile()
609
+ .forEach((namespace) => {
610
+ namespace.getAllMethodsUnderThisNamespace().forEach((value) => {
611
+ if (value.getName() === name) {
612
+ method = value;
613
+ }
614
+ });
615
+ });
616
+ return method;
617
+ }
618
+ /**
619
+ * @internal
620
+ */
621
+ findClass(classSignature) {
622
+ return ModelUtils_1.ModelUtils.getClass(this.render, classSignature);
623
+ }
624
+ findBuilderMethod(value) {
625
+ let method;
626
+ if (value instanceof Ref_1.ArkInstanceFieldRef) {
627
+ method = this.findMethodWithName(value.getFieldName());
628
+ }
629
+ else if (value instanceof Expr_1.ArkStaticInvokeExpr) {
630
+ method = this.findMethod(value.getMethodSignature());
631
+ }
632
+ else if (value instanceof Local_1.Local && value.getType() instanceof Type_1.FunctionType) {
633
+ method = this.findMethod(value.getType().getMethodSignature());
634
+ }
635
+ else if (value instanceof Local_1.Local) {
636
+ method = this.findMethodWithName(value.getName());
637
+ }
638
+ if (method && !method.hasBuilderDecorator()) {
639
+ method = this.findMethodInvokeBuilderMethod(method);
640
+ }
641
+ return method;
642
+ }
643
+ /**
644
+ * @internal
645
+ */
646
+ addBuilderNode(method) {
647
+ let builderViewTree = method.getViewTree();
648
+ if (!builderViewTree || !builderViewTree.getRoot()) {
649
+ logger.error(`ViewTree->addBuilderNode ${method.getSignature().toString()} build viewtree fail.`);
650
+ // add empty node
651
+ let node = ViewTreeNodeImpl.createBuilderNode();
652
+ node.signature = method.getSignature();
653
+ node.classSignature = node.signature;
654
+ this.push(node);
655
+ this.pop();
656
+ return node;
657
+ }
658
+ let root = builderViewTree.getRoot();
659
+ this.push(root);
660
+ if (method.getDeclaringArkClass() === this.render.getDeclaringArkClass()) {
661
+ for (const [field, nodes] of builderViewTree.getStateValues()) {
662
+ for (const node of nodes) {
663
+ this.addStateValue(field, node);
664
+ }
665
+ }
666
+ }
667
+ this.pop();
668
+ return root;
669
+ }
670
+ /**
671
+ * @internal
672
+ */
673
+ addCustomComponentNode(cls, arg, builder) {
674
+ let node = ViewTreeNodeImpl.createCustomComponent();
675
+ node.signature = cls.getSignature();
676
+ node.classSignature = node.signature;
677
+ node.stateValuesTransfer = this.parseObjectLiteralExpr(cls, arg, builder);
678
+ if (arg instanceof Local_1.Local && arg.getType()) {
679
+ let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseObjectUsedStateValues(arg.getType());
680
+ stateValues.forEach((field) => {
681
+ node.stateValues.add(field);
682
+ this.addStateValue(field, node);
683
+ });
684
+ }
685
+ this.push(node);
686
+ let componentViewTree = cls.getViewTree();
687
+ if (!componentViewTree || !componentViewTree.getRoot()) {
688
+ logger.error(`ViewTree->addCustomComponentNode ${cls.getSignature().toString()} build viewtree fail.`);
689
+ return node;
690
+ }
691
+ let root = componentViewTree.getRoot();
692
+ if (root.hasBuilderParam()) {
693
+ root = this.cloneBuilderParamNode(node, root);
694
+ }
695
+ node.children.push(root);
696
+ return node;
697
+ }
698
+ cloneBuilderParamNode(node, root) {
699
+ root = root.clone(node);
700
+ if (node.stateValuesTransfer) {
701
+ root.walk((item) => {
702
+ var _a;
703
+ let child = item;
704
+ if (!child.isBuilderParam() || !child.builderParam) {
705
+ return false;
706
+ }
707
+ let method = (_a = node.stateValuesTransfer) === null || _a === void 0 ? void 0 : _a.get(child.builderParam);
708
+ if (method) {
709
+ child.changeBuilderParam2BuilderNode(method);
710
+ }
711
+ return false;
712
+ });
713
+ }
714
+ return root;
715
+ }
716
+ /**
717
+ * @internal
718
+ */
719
+ addBuilderParamNode(field) {
720
+ let node = ViewTreeNodeImpl.createBuilderParamNode();
721
+ node.builderParam = field;
722
+ this.push(node);
723
+ this.pop();
724
+ return node;
725
+ }
726
+ /**
727
+ * @internal
728
+ */
729
+ addSystemComponentNode(name) {
730
+ let node = new ViewTreeNodeImpl(name);
731
+ this.push(node);
732
+ return node;
733
+ }
734
+ findMethodInvokeBuilderMethod(method) {
735
+ var _a;
736
+ let stmts = (_a = method.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts();
737
+ if (!stmts) {
738
+ return;
739
+ }
740
+ for (const stmt of stmts) {
741
+ let expr;
742
+ if (stmt instanceof Stmt_1.ArkInvokeStmt) {
743
+ expr = stmt.getInvokeExpr();
744
+ }
745
+ else if (stmt instanceof Stmt_1.ArkAssignStmt) {
746
+ let rightOp = stmt.getRightOp();
747
+ if (rightOp instanceof Expr_1.ArkInstanceInvokeExpr || rightOp instanceof Expr_1.ArkStaticInvokeExpr) {
748
+ expr = rightOp;
749
+ }
750
+ }
751
+ if (expr === undefined) {
752
+ continue;
753
+ }
754
+ let method = this.findMethod(expr.getMethodSignature());
755
+ if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
756
+ return method;
757
+ }
758
+ }
759
+ }
760
+ parseObjectLiteralExpr(cls, object, builder) {
761
+ let transferMap = new Map();
762
+ if (object instanceof Local_1.Local && object.getType() instanceof Type_1.ClassType) {
763
+ let anonymousSig = object.getType().getClassSignature();
764
+ let anonymous = this.findClass(anonymousSig);
765
+ anonymous === null || anonymous === void 0 ? void 0 : anonymous.getFields().forEach((field) => {
766
+ let dstField = cls.getFieldWithName(field.getName());
767
+ if ((dstField === null || dstField === void 0 ? void 0 : dstField.getStateDecorators().length) === 0 && !(dstField === null || dstField === void 0 ? void 0 : dstField.hasBuilderParamDecorator())) {
768
+ return;
769
+ }
770
+ let stmts = field.getInitializer();
771
+ if (stmts.length === 0) {
772
+ return;
773
+ }
774
+ let assignStmt = stmts[stmts.length - 1];
775
+ if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
776
+ return;
777
+ }
778
+ let value = assignStmt.getRightOp();
779
+ if (value instanceof Local_1.Local) {
780
+ value = backtraceLocalInitValue(value);
781
+ }
782
+ if (dstField === null || dstField === void 0 ? void 0 : dstField.hasBuilderParamDecorator()) {
783
+ let method = this.findBuilderMethod(value);
784
+ if (method) {
785
+ transferMap.set(dstField, method);
786
+ }
787
+ }
788
+ else {
789
+ let srcField;
790
+ if (value instanceof Ref_1.ArkInstanceFieldRef) {
791
+ srcField = this.getDeclaringArkClass().getFieldWithName(value.getFieldName());
792
+ }
793
+ if (srcField && dstField) {
794
+ transferMap.set(dstField, srcField);
795
+ }
796
+ }
797
+ });
798
+ }
799
+ // If the builder exists, there will be a unique BuilderParam
800
+ if (builder) {
801
+ cls.getFields().forEach((value) => {
802
+ if (value.hasBuilderParamDecorator()) {
803
+ transferMap.set(value, builder);
804
+ }
805
+ });
806
+ }
807
+ if (transferMap.size === 0) {
808
+ return;
809
+ }
810
+ return transferMap;
811
+ }
812
+ viewComponentCreationParser(name, stmt, expr) {
813
+ let temp = expr.getArg(0);
814
+ let arg;
815
+ temp.getUsedStmts().forEach((value) => {
816
+ if (value instanceof Stmt_1.ArkInvokeStmt) {
817
+ let invokerExpr = value.getInvokeExpr();
818
+ let methodName = invokerExpr.getMethodSignature().getMethodSubSignature().getMethodName();
819
+ if (methodName === 'constructor') {
820
+ arg = invokerExpr.getArg(0);
821
+ }
822
+ }
823
+ });
824
+ let builderMethod;
825
+ let builder = expr.getArg(1);
826
+ if (builder) {
827
+ let method = this.findMethod(builder.getType().getMethodSignature());
828
+ if (!(method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
829
+ method === null || method === void 0 ? void 0 : method.addDecorator(new Decorator_1.Decorator(EtsConst_1.BUILDER_DECORATOR));
830
+ }
831
+ if (!(method === null || method === void 0 ? void 0 : method.hasViewTree())) {
832
+ method === null || method === void 0 ? void 0 : method.setViewTree(new ViewTreeImpl(method));
833
+ }
834
+ if (method) {
835
+ builderMethod = method;
836
+ }
837
+ }
838
+ let initValue = backtraceLocalInitValue(temp);
839
+ if (!(initValue instanceof Expr_1.ArkNewExpr)) {
840
+ return undefined;
841
+ }
842
+ let clsSignature = initValue.getType().getClassSignature();
843
+ if (clsSignature) {
844
+ let cls = this.findClass(clsSignature);
845
+ if (cls && cls.hasComponentDecorator()) {
846
+ return this.addCustomComponentNode(cls, arg, builderMethod);
847
+ }
848
+ else {
849
+ logger.error(`ViewTree->viewComponentCreationParser not found class ${clsSignature.toString()}. ${stmt.toString()}`);
850
+ }
851
+ }
852
+ return undefined;
853
+ }
854
+ waterFlowCreationParser(name, stmt, expr) {
855
+ let node = this.addSystemComponentNode(name);
856
+ let object = expr.getArg(0);
857
+ if (object instanceof Local_1.Local && object.getType() instanceof Type_1.ClassType) {
858
+ let anonymousSig = object.getType().getClassSignature();
859
+ let anonymous = this.findClass(anonymousSig);
860
+ let footer = anonymous === null || anonymous === void 0 ? void 0 : anonymous.getFieldWithName('footer');
861
+ if (!footer) {
862
+ return node;
863
+ }
864
+ let stmts = footer.getInitializer();
865
+ let assignStmt = stmts[stmts.length - 1];
866
+ if (!(assignStmt instanceof Stmt_1.ArkAssignStmt)) {
867
+ return node;
868
+ }
869
+ let value = assignStmt.getRightOp();
870
+ let method = this.findBuilderMethod(value);
871
+ if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
872
+ return this.addBuilderNode(method);
873
+ }
874
+ }
875
+ return node;
876
+ }
877
+ forEachCreationParser(name, stmt, expr) {
878
+ let node = this.addSystemComponentNode(name);
879
+ let values = expr.getArg(0);
880
+ let declaringStmt = values === null || values === void 0 ? void 0 : values.getDeclaringStmt();
881
+ if (declaringStmt) {
882
+ let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseStmtUsesStateValues(declaringStmt);
883
+ stateValues.forEach((field) => {
884
+ node.stateValues.add(field);
885
+ this.addStateValue(field, node);
886
+ });
887
+ }
888
+ let type = expr.getArg(1).getType();
889
+ let method = this.findMethod(type.getMethodSignature());
890
+ if (method && method.getCfg()) {
891
+ this.buildViewTreeFromCfg(method.getCfg());
892
+ }
893
+ return node;
894
+ }
895
+ repeatCreationParser(name, stmt, expr) {
896
+ let node = this.addSystemComponentNode(name);
897
+ let arg = expr.getArg(0);
898
+ let declaringStmt = arg === null || arg === void 0 ? void 0 : arg.getDeclaringStmt();
899
+ if (declaringStmt) {
900
+ let stateValues = StateValuesUtils.getInstance(this.getDeclaringArkClass()).parseStmtUsesStateValues(declaringStmt);
901
+ stateValues.forEach((field) => {
902
+ node.stateValues.add(field);
903
+ this.addStateValue(field, node);
904
+ });
905
+ }
906
+ return node;
907
+ }
908
+ ifBranchCreationParser(name, stmt, expr) {
909
+ this.popComponentExpect(EtsConst_1.COMPONENT_IF);
910
+ return this.addSystemComponentNode(EtsConst_1.COMPONENT_IF_BRANCH);
911
+ }
912
+ componentCreateParse(componentName, methodName, stmt, expr) {
913
+ let parserFn = this.COMPONENT_CREATE_PARSERS.get(`${componentName}.${methodName}`);
914
+ if (parserFn) {
915
+ let node = parserFn(componentName, stmt, expr);
916
+ node === null || node === void 0 ? void 0 : node.addStmt(this, stmt);
917
+ return node;
918
+ }
919
+ this.popAutomicComponent(componentName);
920
+ let node = this.addSystemComponentNode(componentName);
921
+ node.addStmt(this, stmt);
922
+ return node;
923
+ }
924
+ parseStaticInvokeExpr(local2Node, stmt, expr) {
925
+ let methodSignature = expr.getMethodSignature();
926
+ let method = this.findMethod(methodSignature);
927
+ if (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator()) {
928
+ let node = this.addBuilderNode(method);
929
+ node.parseStateValues(this, stmt);
930
+ return node;
931
+ }
932
+ let name = methodSignature.getDeclaringClassSignature().getClassName();
933
+ let methodName = methodSignature.getMethodSubSignature().getMethodName();
934
+ if (this.isCreateFunc(methodName)) {
935
+ return this.componentCreateParse(name, methodName, stmt, expr);
936
+ }
937
+ let currentNode = this.top();
938
+ if (name === (currentNode === null || currentNode === void 0 ? void 0 : currentNode.name)) {
939
+ currentNode.addStmt(this, stmt);
940
+ if (methodName === EtsConst_1.COMPONENT_POP_FUNCTION) {
941
+ this.pop();
942
+ }
943
+ return currentNode;
944
+ }
945
+ else if (name === EtsConst_1.COMPONENT_IF && methodName === EtsConst_1.COMPONENT_POP_FUNCTION) {
946
+ this.popComponentExpect(EtsConst_1.COMPONENT_IF);
947
+ this.pop();
948
+ }
949
+ return undefined;
950
+ }
951
+ /**
952
+ * $temp4.margin({ top: 20 });
953
+ * @param viewTree
954
+ * @param local2Node
955
+ * @param expr
956
+ */
957
+ parseInstanceInvokeExpr(local2Node, stmt, expr) {
958
+ let temp = expr.getBase();
959
+ if (local2Node.has(temp)) {
960
+ let component = local2Node.get(temp);
961
+ if ((component === null || component === void 0 ? void 0 : component.name) === EtsConst_1.COMPONENT_REPEAT &&
962
+ expr.getMethodSignature().getMethodSubSignature().getMethodName() === 'each') {
963
+ let arg = expr.getArg(0);
964
+ let type = arg.getType();
965
+ if (type instanceof Type_1.FunctionType) {
966
+ let method = this.findMethod(type.getMethodSignature());
967
+ this.buildViewTreeFromCfg(method === null || method === void 0 ? void 0 : method.getCfg());
968
+ }
969
+ this.pop();
970
+ }
971
+ else {
972
+ component === null || component === void 0 ? void 0 : component.addStmt(this, stmt);
973
+ }
974
+ return component;
975
+ }
976
+ let name = expr.getBase().getName();
977
+ if (name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
978
+ let initValue = backtraceLocalInitValue(expr.getBase());
979
+ if (initValue instanceof Ref_1.ArkThisRef) {
980
+ name = 'this';
981
+ }
982
+ }
983
+ let methodName = expr.getMethodSignature().getMethodSubSignature().getMethodName();
984
+ let field = this.getDeclaringArkClass().getFieldWithName(methodName);
985
+ if (name === 'this' && (field === null || field === void 0 ? void 0 : field.hasBuilderParamDecorator())) {
986
+ return this.addBuilderParamNode(field);
987
+ }
988
+ let method = this.findMethod(expr.getMethodSignature());
989
+ if (name === 'this' && (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
990
+ return this.addBuilderNode(method);
991
+ }
992
+ return undefined;
993
+ }
994
+ /**
995
+ * $temp3 = View.create($temp2);
996
+ * $temp4 = View.pop();
997
+ * $temp4.margin({ top: 20 });
998
+ *
999
+ * $temp2 = List.create();
1000
+ * $temp5 = $temp2.width('100%');
1001
+ * $temp6 = $temp5.height('100%');
1002
+ * $temp6.backgroundColor('#FFDCDCDC');
1003
+ * @param viewTree
1004
+ * @param local2Node
1005
+ * @param stmt
1006
+ * @returns
1007
+ */
1008
+ parseAssignStmt(local2Node, stmt) {
1009
+ let left = stmt.getLeftOp();
1010
+ let right = stmt.getRightOp();
1011
+ if (!(left instanceof Local_1.Local)) {
1012
+ return;
1013
+ }
1014
+ let component;
1015
+ if (right instanceof Expr_1.ArkStaticInvokeExpr) {
1016
+ component = this.parseStaticInvokeExpr(local2Node, stmt, right);
1017
+ }
1018
+ else if (right instanceof Expr_1.ArkInstanceInvokeExpr) {
1019
+ component = this.parseInstanceInvokeExpr(local2Node, stmt, right);
1020
+ }
1021
+ if (component) {
1022
+ local2Node.set(left, component);
1023
+ }
1024
+ }
1025
+ parseInvokeStmt(local2Node, stmt) {
1026
+ let expr = stmt.getInvokeExpr();
1027
+ if (expr instanceof Expr_1.ArkStaticInvokeExpr) {
1028
+ this.parseStaticInvokeExpr(local2Node, stmt, expr);
1029
+ }
1030
+ else if (expr instanceof Expr_1.ArkInstanceInvokeExpr) {
1031
+ this.parseInstanceInvokeExpr(local2Node, stmt, expr);
1032
+ }
1033
+ }
1034
+ buildViewTreeFromCfg(cfg, local2Node = new Map()) {
1035
+ if (!cfg) {
1036
+ return;
1037
+ }
1038
+ let blocks = cfg.getBlocks();
1039
+ for (const block of blocks) {
1040
+ for (const stmt of block.getStmts()) {
1041
+ if (!(stmt instanceof Stmt_1.ArkInvokeStmt || stmt instanceof Stmt_1.ArkAssignStmt)) {
1042
+ continue;
1043
+ }
1044
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
1045
+ this.parseAssignStmt(local2Node, stmt);
1046
+ }
1047
+ else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
1048
+ this.parseInvokeStmt(local2Node, stmt);
1049
+ }
1050
+ }
1051
+ }
1052
+ }
1053
+ }
1054
+ exports.ViewTreeImpl = ViewTreeImpl;
1055
+ function buildViewTree(render) {
1056
+ return new ViewTreeImpl(render);
1057
+ }
1058
+ exports.buildViewTree = buildViewTree;