arkanalyzer 1.0.20 → 1.0.21

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 (279) hide show
  1. package/lib/Config.d.ts +70 -70
  2. package/lib/Config.js +198 -198
  3. package/lib/Scene.d.ts +316 -316
  4. package/lib/Scene.js +1316 -1316
  5. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
  6. package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
  7. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
  8. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
  9. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
  10. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
  11. package/lib/callgraph/common/Statistics.d.ts +57 -57
  12. package/lib/callgraph/common/Statistics.js +228 -228
  13. package/lib/callgraph/model/CallGraph.d.ts +96 -96
  14. package/lib/callgraph/model/CallGraph.js +354 -354
  15. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
  16. package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
  17. package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
  18. package/lib/callgraph/pointerAnalysis/Context.js +155 -155
  19. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
  20. package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
  21. package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
  22. package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
  23. package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
  24. package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
  25. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
  26. package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
  27. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
  28. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
  29. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
  30. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
  31. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
  32. package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
  33. package/lib/core/base/Constant.d.ts +48 -48
  34. package/lib/core/base/Constant.js +103 -103
  35. package/lib/core/base/Decorator.d.ts +15 -15
  36. package/lib/core/base/Decorator.js +46 -46
  37. package/lib/core/base/DefUseChain.d.ts +8 -8
  38. package/lib/core/base/DefUseChain.js +25 -25
  39. package/lib/core/base/Expr.d.ts +340 -340
  40. package/lib/core/base/Expr.js +917 -917
  41. package/lib/core/base/Local.d.ts +104 -104
  42. package/lib/core/base/Local.js +176 -176
  43. package/lib/core/base/Position.d.ts +30 -30
  44. package/lib/core/base/Position.js +147 -147
  45. package/lib/core/base/Ref.d.ts +173 -173
  46. package/lib/core/base/Ref.js +374 -374
  47. package/lib/core/base/Stmt.d.ts +237 -237
  48. package/lib/core/base/Stmt.js +525 -525
  49. package/lib/core/base/Trap.d.ts +8 -8
  50. package/lib/core/base/Trap.js +30 -30
  51. package/lib/core/base/Type.d.ts +308 -308
  52. package/lib/core/base/Type.js +639 -639
  53. package/lib/core/base/TypeExpr.d.ts +71 -71
  54. package/lib/core/base/TypeExpr.js +155 -155
  55. package/lib/core/base/Value.d.ts +32 -32
  56. package/lib/core/base/Value.js +16 -16
  57. package/lib/core/common/ArkError.d.ts +14 -14
  58. package/lib/core/common/ArkError.js +28 -28
  59. package/lib/core/common/ArkIRTransformer.d.ts +67 -67
  60. package/lib/core/common/ArkIRTransformer.js +690 -690
  61. package/lib/core/common/ArkValueTransformer.d.ts +89 -89
  62. package/lib/core/common/ArkValueTransformer.js +1478 -1478
  63. package/lib/core/common/Builtin.d.ts +36 -36
  64. package/lib/core/common/Builtin.js +81 -81
  65. package/lib/core/common/Const.d.ts +21 -21
  66. package/lib/core/common/Const.js +43 -43
  67. package/lib/core/common/DummyMainCreater.d.ts +46 -46
  68. package/lib/core/common/DummyMainCreater.js +319 -319
  69. package/lib/core/common/EtsConst.d.ts +73 -73
  70. package/lib/core/common/EtsConst.js +1021 -1021
  71. package/lib/core/common/ExprUseReplacer.d.ts +21 -21
  72. package/lib/core/common/ExprUseReplacer.js +124 -124
  73. package/lib/core/common/IRInference.d.ts +36 -36
  74. package/lib/core/common/IRInference.d.ts.map +1 -1
  75. package/lib/core/common/IRInference.js +651 -648
  76. package/lib/core/common/IRUtils.d.ts +18 -18
  77. package/lib/core/common/IRUtils.js +141 -141
  78. package/lib/core/common/ModelUtils.d.ts +70 -70
  79. package/lib/core/common/ModelUtils.js +712 -712
  80. package/lib/core/common/RefUseReplacer.d.ts +13 -13
  81. package/lib/core/common/RefUseReplacer.js +52 -52
  82. package/lib/core/common/SdkUtils.d.ts +8 -8
  83. package/lib/core/common/SdkUtils.js +105 -105
  84. package/lib/core/common/StmtDefReplacer.d.ts +12 -12
  85. package/lib/core/common/StmtDefReplacer.js +41 -41
  86. package/lib/core/common/StmtUseReplacer.d.ts +16 -16
  87. package/lib/core/common/StmtUseReplacer.js +108 -108
  88. package/lib/core/common/TSConst.d.ts +18 -18
  89. package/lib/core/common/TSConst.js +36 -36
  90. package/lib/core/common/TypeInference.d.ts +102 -102
  91. package/lib/core/common/TypeInference.js +748 -748
  92. package/lib/core/common/ValueUtil.d.ts +12 -12
  93. package/lib/core/common/ValueUtil.js +54 -54
  94. package/lib/core/common/VisibleValue.d.ts +36 -36
  95. package/lib/core/common/VisibleValue.js +212 -212
  96. package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
  97. package/lib/core/dataflow/DataflowProblem.js +20 -20
  98. package/lib/core/dataflow/DataflowResult.d.ts +7 -7
  99. package/lib/core/dataflow/DataflowResult.js +26 -26
  100. package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
  101. package/lib/core/dataflow/DataflowSolver.js +307 -307
  102. package/lib/core/dataflow/Edge.d.ts +11 -11
  103. package/lib/core/dataflow/Edge.js +31 -31
  104. package/lib/core/dataflow/Fact.d.ts +6 -6
  105. package/lib/core/dataflow/Fact.js +24 -24
  106. package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
  107. package/lib/core/dataflow/GenericDataFlow.js +109 -109
  108. package/lib/core/dataflow/ReachingDef.d.ts +62 -62
  109. package/lib/core/dataflow/ReachingDef.js +168 -168
  110. package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
  111. package/lib/core/dataflow/UndefinedVariable.js +288 -288
  112. package/lib/core/dataflow/Util.d.ts +9 -9
  113. package/lib/core/dataflow/Util.js +64 -64
  114. package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
  115. package/lib/core/graph/BaseExplicitGraph.js +157 -157
  116. package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
  117. package/lib/core/graph/BaseImplicitGraph.js +78 -78
  118. package/lib/core/graph/BasicBlock.d.ts +104 -104
  119. package/lib/core/graph/BasicBlock.js +280 -280
  120. package/lib/core/graph/Cfg.d.ts +59 -59
  121. package/lib/core/graph/Cfg.js +282 -282
  122. package/lib/core/graph/DependsGraph.d.ts +35 -35
  123. package/lib/core/graph/DependsGraph.js +87 -87
  124. package/lib/core/graph/DominanceFinder.d.ts +15 -15
  125. package/lib/core/graph/DominanceFinder.js +121 -121
  126. package/lib/core/graph/DominanceTree.d.ts +12 -12
  127. package/lib/core/graph/DominanceTree.js +70 -70
  128. package/lib/core/graph/GraphTraits.d.ts +7 -7
  129. package/lib/core/graph/GraphTraits.js +16 -16
  130. package/lib/core/graph/Scc.d.ts +61 -61
  131. package/lib/core/graph/Scc.js +222 -222
  132. package/lib/core/graph/ViewTree.d.ts +114 -114
  133. package/lib/core/graph/ViewTree.js +16 -16
  134. package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
  135. package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
  136. package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
  137. package/lib/core/graph/builder/ConditionBuilder.js +252 -252
  138. package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
  139. package/lib/core/graph/builder/LoopBuilder.js +251 -251
  140. package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
  141. package/lib/core/graph/builder/SwitchBuilder.js +152 -152
  142. package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
  143. package/lib/core/graph/builder/TrapBuilder.js +272 -272
  144. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
  145. package/lib/core/graph/builder/ViewTreeBuilder.js +1055 -1055
  146. package/lib/core/model/ArkBaseModel.d.ts +59 -59
  147. package/lib/core/model/ArkBaseModel.js +274 -274
  148. package/lib/core/model/ArkBody.d.ts +24 -24
  149. package/lib/core/model/ArkBody.js +65 -65
  150. package/lib/core/model/ArkClass.d.ts +206 -206
  151. package/lib/core/model/ArkClass.js +439 -439
  152. package/lib/core/model/ArkExport.d.ts +72 -72
  153. package/lib/core/model/ArkExport.js +147 -147
  154. package/lib/core/model/ArkField.d.ts +62 -62
  155. package/lib/core/model/ArkField.js +113 -113
  156. package/lib/core/model/ArkFile.d.ts +131 -131
  157. package/lib/core/model/ArkFile.js +267 -267
  158. package/lib/core/model/ArkImport.d.ts +44 -44
  159. package/lib/core/model/ArkImport.js +108 -108
  160. package/lib/core/model/ArkMetadata.d.ts +31 -31
  161. package/lib/core/model/ArkMetadata.js +55 -55
  162. package/lib/core/model/ArkMethod.d.ts +261 -261
  163. package/lib/core/model/ArkMethod.js +592 -592
  164. package/lib/core/model/ArkNamespace.d.ts +66 -66
  165. package/lib/core/model/ArkNamespace.js +209 -209
  166. package/lib/core/model/ArkSignature.d.ts +162 -162
  167. package/lib/core/model/ArkSignature.js +379 -379
  168. package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
  169. package/lib/core/model/builder/ArkClassBuilder.js +454 -454
  170. package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
  171. package/lib/core/model/builder/ArkExportBuilder.js +210 -210
  172. package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
  173. package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
  174. package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
  175. package/lib/core/model/builder/ArkFileBuilder.js +165 -165
  176. package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
  177. package/lib/core/model/builder/ArkImportBuilder.js +128 -128
  178. package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
  179. package/lib/core/model/builder/ArkMethodBuilder.js +486 -486
  180. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
  181. package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
  182. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
  183. package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
  184. package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
  185. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
  186. package/lib/core/model/builder/BodyBuilder.js +542 -371
  187. package/lib/core/model/builder/builderUtils.d.ts +18 -18
  188. package/lib/core/model/builder/builderUtils.js +558 -558
  189. package/lib/index.d.ts +82 -80
  190. package/lib/index.d.ts.map +1 -1
  191. package/lib/index.js +201 -196
  192. package/lib/save/ArkStream.d.ts +23 -23
  193. package/lib/save/ArkStream.js +83 -83
  194. package/lib/save/DotPrinter.d.ts +43 -43
  195. package/lib/save/DotPrinter.js +170 -170
  196. package/lib/save/GraphPrinter.d.ts +16 -16
  197. package/lib/save/GraphPrinter.js +134 -134
  198. package/lib/save/JsonPrinter.d.ts +30 -30
  199. package/lib/save/JsonPrinter.js +580 -580
  200. package/lib/save/Printer.d.ts +12 -12
  201. package/lib/save/Printer.js +27 -27
  202. package/lib/save/PrinterBuilder.d.ts +53 -53
  203. package/lib/save/PrinterBuilder.js +145 -145
  204. package/lib/save/ViewTreePrinter.d.ts +14 -14
  205. package/lib/save/ViewTreePrinter.js +123 -123
  206. package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
  207. package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
  208. package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
  209. package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
  210. package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
  211. package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
  212. package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
  213. package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
  214. package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
  215. package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
  216. package/lib/save/base/BasePrinter.d.ts +23 -23
  217. package/lib/save/base/BasePrinter.js +70 -70
  218. package/lib/save/base/ExportPrinter.d.ts +8 -8
  219. package/lib/save/base/ExportPrinter.js +67 -67
  220. package/lib/save/base/ImportPrinter.d.ts +9 -9
  221. package/lib/save/base/ImportPrinter.js +92 -92
  222. package/lib/save/base/PrinterUtils.d.ts +24 -24
  223. package/lib/save/base/PrinterUtils.js +208 -208
  224. package/lib/save/serializeArkIR.d.ts +8 -8
  225. package/lib/save/serializeArkIR.js +294 -294
  226. package/lib/save/source/SourceBase.d.ts +22 -22
  227. package/lib/save/source/SourceBase.js +64 -64
  228. package/lib/save/source/SourceBody.d.ts +58 -58
  229. package/lib/save/source/SourceBody.js +296 -296
  230. package/lib/save/source/SourceClass.d.ts +25 -25
  231. package/lib/save/source/SourceClass.js +187 -187
  232. package/lib/save/source/SourceField.d.ts +13 -13
  233. package/lib/save/source/SourceField.js +73 -73
  234. package/lib/save/source/SourceFilePrinter.d.ts +12 -12
  235. package/lib/save/source/SourceFilePrinter.js +69 -69
  236. package/lib/save/source/SourceMethod.d.ts +22 -22
  237. package/lib/save/source/SourceMethod.d.ts.map +1 -1
  238. package/lib/save/source/SourceMethod.js +196 -193
  239. package/lib/save/source/SourceNamespace.d.ts +11 -11
  240. package/lib/save/source/SourceNamespace.js +83 -83
  241. package/lib/save/source/SourceStmt.d.ts +178 -178
  242. package/lib/save/source/SourceStmt.js +838 -838
  243. package/lib/save/source/SourceTransformer.d.ts +46 -46
  244. package/lib/save/source/SourceTransformer.js +446 -446
  245. package/lib/transformer/FunctionTransformer.d.ts +2 -2
  246. package/lib/transformer/FunctionTransformer.js +17 -17
  247. package/lib/transformer/SceneTransformer.d.ts +2 -2
  248. package/lib/transformer/SceneTransformer.js +17 -17
  249. package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
  250. package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
  251. package/lib/transformer/Transformer.d.ts +6 -6
  252. package/lib/transformer/Transformer.js +22 -22
  253. package/lib/utils/AstTreeUtils.d.ts +4 -4
  254. package/lib/utils/AstTreeUtils.js +26 -26
  255. package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
  256. package/lib/utils/CfgStructualAnalysis.js +1277 -1277
  257. package/lib/utils/FileUtils.d.ts +18 -18
  258. package/lib/utils/FileUtils.js +135 -135
  259. package/lib/utils/SparseBitVector.d.ts +100 -100
  260. package/lib/utils/SparseBitVector.js +445 -445
  261. package/lib/utils/callGraphUtils.d.ts +30 -30
  262. package/lib/utils/callGraphUtils.js +205 -205
  263. package/lib/utils/crypto_utils.d.ts +5 -5
  264. package/lib/utils/crypto_utils.js +57 -57
  265. package/lib/utils/entryMethodUtils.d.ts +13 -13
  266. package/lib/utils/entryMethodUtils.js +110 -110
  267. package/lib/utils/getAllFiles.d.ts +9 -9
  268. package/lib/utils/getAllFiles.js +90 -90
  269. package/lib/utils/json5parser.d.ts +6 -6
  270. package/lib/utils/json5parser.js +146 -146
  271. package/lib/utils/logger.d.ts +18 -18
  272. package/lib/utils/logger.d.ts.map +1 -1
  273. package/lib/utils/logger.js +97 -90
  274. package/lib/utils/pathTransfer.d.ts +1 -1
  275. package/lib/utils/pathTransfer.js +25 -25
  276. package/node_modules/json5/lib/cli.js +0 -0
  277. package/node_modules/ohos-typescript/bin/tsc +0 -0
  278. package/node_modules/ohos-typescript/bin/tsserver +0 -0
  279. package/package.json +3 -3
@@ -1,1055 +1,1055 @@
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
+ 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;