arkanalyzer 1.0.40 → 1.0.42

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 (115) hide show
  1. package/config/arkanalyzer.json +1 -2
  2. package/lib/Scene.d.ts.map +1 -1
  3. package/lib/Scene.js +9 -2
  4. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -1
  5. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +3 -4
  6. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
  7. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +7 -8
  8. package/lib/callgraph/model/CallGraph.d.ts +5 -5
  9. package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
  10. package/lib/callgraph/model/CallGraph.js +18 -21
  11. package/lib/callgraph/model/CallSite.d.ts +16 -6
  12. package/lib/callgraph/model/CallSite.d.ts.map +1 -1
  13. package/lib/callgraph/model/CallSite.js +48 -8
  14. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +0 -1
  15. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -1
  16. package/lib/callgraph/model/builder/CallGraphBuilder.js +0 -8
  17. package/lib/callgraph/pointerAnalysis/Pag.d.ts +3 -6
  18. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
  19. package/lib/callgraph/pointerAnalysis/Pag.js +6 -29
  20. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +6 -15
  21. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
  22. package/lib/callgraph/pointerAnalysis/PagBuilder.js +63 -81
  23. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +2 -1
  24. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
  25. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +12 -8
  26. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +9 -3
  27. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts.map +1 -1
  28. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +12 -5
  29. package/lib/callgraph/pointerAnalysis/context/Context.d.ts +69 -0
  30. package/lib/callgraph/pointerAnalysis/context/Context.d.ts.map +1 -0
  31. package/lib/callgraph/pointerAnalysis/context/Context.js +202 -0
  32. package/lib/callgraph/pointerAnalysis/context/ContextItem.d.ts +40 -0
  33. package/lib/callgraph/pointerAnalysis/context/ContextItem.d.ts.map +1 -0
  34. package/lib/callgraph/pointerAnalysis/context/ContextItem.js +99 -0
  35. package/lib/callgraph/pointerAnalysis/context/ContextSelector.d.ts +46 -0
  36. package/lib/callgraph/pointerAnalysis/context/ContextSelector.d.ts.map +1 -0
  37. package/lib/callgraph/pointerAnalysis/context/ContextSelector.js +138 -0
  38. package/lib/core/base/Expr.d.ts +1 -0
  39. package/lib/core/base/Expr.d.ts.map +1 -1
  40. package/lib/core/base/Expr.js +9 -0
  41. package/lib/core/common/ArkIRTransformer.d.ts +1 -0
  42. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  43. package/lib/core/common/ArkIRTransformer.js +58 -2
  44. package/lib/core/common/ArkValueTransformer.d.ts +1 -1
  45. package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
  46. package/lib/core/common/IRInference.d.ts +1 -1
  47. package/lib/core/common/IRInference.d.ts.map +1 -1
  48. package/lib/core/common/IRInference.js +7 -3
  49. package/lib/core/common/ModelUtils.js +1 -1
  50. package/lib/core/common/SdkUtils.d.ts +2 -1
  51. package/lib/core/common/SdkUtils.d.ts.map +1 -1
  52. package/lib/core/common/SdkUtils.js +33 -23
  53. package/lib/core/common/TypeInference.d.ts.map +1 -1
  54. package/lib/core/common/TypeInference.js +5 -3
  55. package/lib/core/dataflow/DataflowSolver.js +3 -3
  56. package/lib/core/dataflow/UndefinedVariable.js +2 -2
  57. package/lib/core/graph/BaseExplicitGraph.d.ts +1 -0
  58. package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
  59. package/lib/core/graph/BaseExplicitGraph.js +3 -0
  60. package/lib/core/graph/BasicBlock.d.ts.map +1 -1
  61. package/lib/core/graph/BasicBlock.js +9 -4
  62. package/lib/core/graph/Cfg.d.ts.map +1 -1
  63. package/lib/core/graph/Cfg.js +4 -1
  64. package/lib/core/graph/builder/CfgBuilder.d.ts +2 -1
  65. package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
  66. package/lib/core/graph/builder/CfgBuilder.js +54 -10
  67. package/lib/core/graph/builder/ConditionBuilder.d.ts +2 -1
  68. package/lib/core/graph/builder/ConditionBuilder.d.ts.map +1 -1
  69. package/lib/core/graph/builder/ConditionBuilder.js +7 -3
  70. package/lib/core/graph/builder/TrapBuilder.d.ts +19 -1
  71. package/lib/core/graph/builder/TrapBuilder.d.ts.map +1 -1
  72. package/lib/core/graph/builder/TrapBuilder.js +195 -68
  73. package/lib/core/model/ArkMethod.d.ts.map +1 -1
  74. package/lib/core/model/ArkMethod.js +3 -4
  75. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  76. package/lib/core/model/builder/ArkClassBuilder.js +42 -21
  77. package/lib/core/model/builder/ArkImportBuilder.js +28 -25
  78. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  79. package/lib/core/model/builder/ArkMethodBuilder.js +1 -2
  80. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  81. package/lib/core/model/builder/builderUtils.js +2 -1
  82. package/lib/index.d.ts +0 -1
  83. package/lib/index.d.ts.map +1 -1
  84. package/lib/index.js +2 -4
  85. package/lib/pass/Context.d.ts +47 -0
  86. package/lib/pass/Context.d.ts.map +1 -0
  87. package/lib/pass/Context.js +72 -0
  88. package/lib/pass/Dispatcher.d.ts +102 -0
  89. package/lib/pass/Dispatcher.d.ts.map +1 -0
  90. package/lib/pass/Dispatcher.js +202 -0
  91. package/lib/pass/Pass.d.ts +83 -0
  92. package/lib/pass/Pass.d.ts.map +1 -0
  93. package/lib/pass/Pass.js +95 -0
  94. package/lib/pass/ScenePassMgr.d.ts +73 -0
  95. package/lib/pass/ScenePassMgr.d.ts.map +1 -0
  96. package/lib/pass/ScenePassMgr.js +156 -0
  97. package/lib/pass/SceneValidator.d.ts +215 -0
  98. package/lib/pass/SceneValidator.d.ts.map +1 -0
  99. package/lib/pass/SceneValidator.js +339 -0
  100. package/lib/save/JsonPrinter.d.ts.map +1 -1
  101. package/lib/save/JsonPrinter.js +26 -102
  102. package/lib/save/arkir/ArkIRMethodPrinter.d.ts.map +1 -1
  103. package/lib/save/arkir/ArkIRMethodPrinter.js +13 -5
  104. package/lib/save/source/SourceStmt.d.ts +1 -0
  105. package/lib/save/source/SourceStmt.d.ts.map +1 -1
  106. package/lib/save/source/SourceStmt.js +13 -8
  107. package/lib/utils/FileUtils.d.ts.map +1 -1
  108. package/lib/utils/FileUtils.js +13 -6
  109. package/lib/utils/ValueAsserts.d.ts +9 -0
  110. package/lib/utils/ValueAsserts.d.ts.map +1 -0
  111. package/lib/utils/ValueAsserts.js +89 -0
  112. package/package.json +2 -2
  113. package/lib/callgraph/pointerAnalysis/Context.d.ts +0 -38
  114. package/lib/callgraph/pointerAnalysis/Context.d.ts.map +0 -1
  115. package/lib/callgraph/pointerAnalysis/Context.js +0 -154
@@ -0,0 +1,202 @@
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.Dispatcher = exports.Dispatch = void 0;
41
+ const Stmt_1 = require("../core/base/Stmt");
42
+ const Expr_1 = require("../core/base/Expr");
43
+ const Constant_1 = require("../core/base/Constant");
44
+ const logger_1 = __importStar(require("../utils/logger"));
45
+ const Local_1 = require("../core/base/Local");
46
+ const Ref_1 = require("../core/base/Ref");
47
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'Inst');
48
+ /**
49
+ * Represents all statement types used within the system.
50
+ */
51
+ const STMTS = [
52
+ Stmt_1.ArkAssignStmt,
53
+ Stmt_1.ArkInvokeStmt,
54
+ Stmt_1.ArkIfStmt,
55
+ Stmt_1.ArkReturnStmt,
56
+ Stmt_1.ArkReturnVoidStmt,
57
+ Stmt_1.ArkThrowStmt,
58
+ Stmt_1.ArkAliasTypeDefineStmt,
59
+ Stmt_1.Stmt,
60
+ ];
61
+ /**
62
+ * Represents all values types used within the system.
63
+ */
64
+ const VALUES = [
65
+ // expr
66
+ Expr_1.AliasTypeExpr,
67
+ Expr_1.ArkUnopExpr,
68
+ Expr_1.ArkPhiExpr,
69
+ Expr_1.ArkCastExpr,
70
+ Expr_1.ArkInstanceOfExpr,
71
+ Expr_1.ArkTypeOfExpr,
72
+ Expr_1.ArkNormalBinopExpr,
73
+ Expr_1.ArkConditionExpr,
74
+ Expr_1.AbstractBinopExpr,
75
+ Expr_1.ArkYieldExpr,
76
+ Expr_1.ArkAwaitExpr,
77
+ Expr_1.ArkDeleteExpr,
78
+ Expr_1.ArkNewArrayExpr,
79
+ Expr_1.ArkNewExpr,
80
+ Expr_1.ArkPtrInvokeExpr,
81
+ Expr_1.ArkStaticInvokeExpr,
82
+ Expr_1.ArkInstanceInvokeExpr,
83
+ Expr_1.AbstractInvokeExpr,
84
+ Expr_1.AbstractExpr,
85
+ // ref
86
+ Ref_1.ClosureFieldRef,
87
+ Ref_1.GlobalRef,
88
+ Ref_1.ArkCaughtExceptionRef,
89
+ Ref_1.ArkThisRef,
90
+ Ref_1.ArkParameterRef,
91
+ Ref_1.ArkStaticFieldRef,
92
+ Ref_1.ArkInstanceFieldRef,
93
+ Ref_1.AbstractFieldRef,
94
+ Ref_1.AbstractRef,
95
+ // constant
96
+ Constant_1.UndefinedConstant,
97
+ Constant_1.NullConstant,
98
+ Constant_1.StringConstant,
99
+ Constant_1.BigIntConstant,
100
+ Constant_1.NumberConstant,
101
+ Constant_1.BooleanConstant,
102
+ Constant_1.Constant,
103
+ // local
104
+ Local_1.Local,
105
+ ];
106
+ /**
107
+ * the dispatch table, it can be cached
108
+ */
109
+ class Dispatch {
110
+ constructor(stmts = [], values = []) {
111
+ this.name = 'dispatch';
112
+ this.stmts = [];
113
+ this.smap = new Map();
114
+ this.values = [];
115
+ this.vmap = new Map();
116
+ this.stmts = stmts.map(v => v[0]);
117
+ const smap = new Map();
118
+ for (const [k, v] of stmts) {
119
+ if (Array.isArray(v)) {
120
+ smap.set(k, v);
121
+ }
122
+ else {
123
+ smap.set(k, [v]);
124
+ }
125
+ }
126
+ // replace it, in case of modified
127
+ this.smap = smap;
128
+ this.values = values.map(v => v[0]);
129
+ const vmap = new Map();
130
+ for (const [k, v] of values) {
131
+ if (Array.isArray(v)) {
132
+ vmap.set(k, v);
133
+ }
134
+ else {
135
+ vmap.set(k, [v]);
136
+ }
137
+ }
138
+ // replace it, in case of modified
139
+ this.vmap = vmap;
140
+ }
141
+ }
142
+ exports.Dispatch = Dispatch;
143
+ /**
144
+ * the ArkIR dispatcher, to dispatch stmts and values actions
145
+ */
146
+ class Dispatcher {
147
+ constructor(ctx, dispatch = new Dispatch()) {
148
+ // action when match stmts
149
+ this.fallAction = 1 /* FallAction.Break */;
150
+ // value cache to prevent cycle dependencies
151
+ this.cache = new Set();
152
+ this.ctx = ctx;
153
+ this.dispatch = dispatch;
154
+ }
155
+ dispatchStmt(mtd, stmt) {
156
+ var _a;
157
+ logger.debug(`dispatch stmt ${stmt}`);
158
+ const tys = this.dispatch.stmts;
159
+ for (let ty of tys) {
160
+ if (stmt instanceof ty) {
161
+ let pass = (_a = this.dispatch.smap.get(ty)) !== null && _a !== void 0 ? _a : [];
162
+ for (const p of pass) {
163
+ p(stmt, this.ctx, mtd);
164
+ }
165
+ if (this.fallAction === 1 /* FallAction.Break */) {
166
+ break;
167
+ }
168
+ }
169
+ }
170
+ for (let use of stmt.getUses()) {
171
+ this.dispatchValue(mtd, use);
172
+ }
173
+ }
174
+ dispatchValue(mtd, value) {
175
+ var _a;
176
+ logger.debug(`dispatch value ${value}`);
177
+ // skip uses if there is no value pass
178
+ if (this.dispatch.values.length === 0) {
179
+ return;
180
+ }
181
+ if (this.cache.has(value)) {
182
+ return;
183
+ }
184
+ this.cache.add(value);
185
+ const tys = this.dispatch.values;
186
+ for (let ty of tys) {
187
+ if (value instanceof ty) {
188
+ let pass = (_a = this.dispatch.vmap.get(ty)) !== null && _a !== void 0 ? _a : [];
189
+ for (const p of pass) {
190
+ p(value, this.ctx, mtd);
191
+ }
192
+ if (this.fallAction === 1 /* FallAction.Break */) {
193
+ break;
194
+ }
195
+ }
196
+ }
197
+ for (let use of value.getUses()) {
198
+ this.dispatchValue(mtd, use);
199
+ }
200
+ }
201
+ }
202
+ exports.Dispatcher = Dispatcher;
@@ -0,0 +1,83 @@
1
+ import { ArkMethod } from '../core/model/ArkMethod';
2
+ import { Context, CtxArg } from './Context';
3
+ import { SceneCtx } from './ScenePassMgr';
4
+ import { ArkFile } from '../core/model/ArkFile';
5
+ import { ArkClass } from '../core/model/ArkClass';
6
+ /**
7
+ fallthrough actions
8
+ Continue: will run next pass
9
+ Break: will break the pass list
10
+ */
11
+ export declare const enum FallAction {
12
+ Continue = 0,
13
+ Break = 1
14
+ }
15
+ /**
16
+ * Represents an abstract file responsible for handling file-related operations.
17
+ * The ClassPass class is designed to define a contract for executing specific logic
18
+ * when processing a given class within a particular context. Implementations of this
19
+ * class are expected to provide concrete behavior for the `run` method.
20
+ *
21
+ * @param cls:ArkFile - The class to be executed
22
+ * @param ctx:FileCtx - The context used in executed
23
+ * @returns The result of the method execution, which can be of FallAction or void.
24
+ */
25
+ export declare abstract class FilePass {
26
+ abstract run(file: ArkFile, ctx: FileCtx): FallAction | void;
27
+ }
28
+ /**
29
+ * Represents a specialized context class that extends the base Context class with specific types.
30
+ * Provides functionality to access the root context within a hierarchical structure.
31
+ * The FileCtx is bound to a SceneCtx and CtxArg, defining its operational scope.
32
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
33
+ */
34
+ export declare class FileCtx extends Context<SceneCtx, CtxArg> {
35
+ root(): SceneCtx;
36
+ }
37
+ /**
38
+ * Represents an abstract class responsible for handling class-related operations.
39
+ * The ClassPass class is designed to define a contract for executing specific logic
40
+ * when processing a given class within a particular context. Implementations of this
41
+ * class are expected to provide concrete behavior for the `run` method.
42
+ *
43
+ * @param cls:ArkClass - The class to be executed
44
+ * @param ctx:ClassCtx - The context used in executed
45
+ * @returns The result of the method execution, which can be of FallAction or void.
46
+ */
47
+ export declare abstract class ClassPass {
48
+ abstract run(cls: ArkClass, ctx: ClassCtx): FallAction | void;
49
+ }
50
+ /**
51
+ * Represents a specialized context class that extends the base Context class with specific types.
52
+ * Provides functionality to access the root context within a hierarchical structure.
53
+ * The ClassCtx is bound to a FileCtx and CtxArg, defining its operational scope.
54
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
55
+ */
56
+ export declare class ClassCtx extends Context<FileCtx, CtxArg> {
57
+ root(): SceneCtx;
58
+ }
59
+ /**
60
+ * Represents an abstract class for executing a method within a specific context.
61
+ * The MethodPass class is designed to be extended by concrete implementations
62
+ * that define how a given method should be processed or executed.
63
+ *
64
+ * The `run` method must be implemented by subclasses to provide the logic
65
+ * for handling the execution of the provided method using the given context.
66
+ *
67
+ * @param method: ArkMethod - The method to be executed
68
+ * @param ctx: MethodCtx - The context used in executed
69
+ * @returns The result of the method execution, which can be of FallAction or void.
70
+ */
71
+ export declare abstract class MethodPass {
72
+ abstract run(method: ArkMethod, ctx: MethodCtx): FallAction | void;
73
+ }
74
+ /**
75
+ * Represents a specialized context class that extends the base Context class with specific types.
76
+ * Provides functionality to access the root context within a hierarchical structure.
77
+ * The MethodCtx is bound to a ClassCtx and CtxArg, defining its operational scope.
78
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
79
+ */
80
+ export declare class MethodCtx extends Context<ClassCtx, CtxArg> {
81
+ root(): SceneCtx;
82
+ }
83
+ //# sourceMappingURL=Pass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pass.d.ts","sourceRoot":"","sources":["../../src/pass/Pass.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD;;;;EAIE;AACF,0BAAkB,UAAU;IACxB,QAAQ,IAAA;IACR,KAAK,IAAA;CACR;AAED;;;;;;;;;GASG;AACH,8BAAsB,QAAQ;IAC1B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI;CAC/D;AAED;;;;;GAKG;AACH,qBAAa,OAAQ,SAAQ,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC;IAClD,IAAI,IAAI,QAAQ;CAGnB;AAGD;;;;;;;;;GASG;AACH,8BAAsB,SAAS;IAC3B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,GAAG,UAAU,GAAG,IAAI;CAChE;AAGD;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC;IAClD,IAAI,IAAI,QAAQ;CAGnB;AAED;;;;;;;;;;;GAWG;AACH,8BAAsB,UAAU;IAC5B,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,UAAU,GAAG,IAAI;CACrE;AAED;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC;IACpD,IAAI,IAAI,QAAQ;CAGnB"}
@@ -0,0 +1,95 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.MethodCtx = exports.MethodPass = exports.ClassCtx = exports.ClassPass = exports.FileCtx = exports.FilePass = void 0;
18
+ const Context_1 = require("./Context");
19
+ /**
20
+ * Represents an abstract file responsible for handling file-related operations.
21
+ * The ClassPass class is designed to define a contract for executing specific logic
22
+ * when processing a given class within a particular context. Implementations of this
23
+ * class are expected to provide concrete behavior for the `run` method.
24
+ *
25
+ * @param cls:ArkFile - The class to be executed
26
+ * @param ctx:FileCtx - The context used in executed
27
+ * @returns The result of the method execution, which can be of FallAction or void.
28
+ */
29
+ class FilePass {
30
+ }
31
+ exports.FilePass = FilePass;
32
+ /**
33
+ * Represents a specialized context class that extends the base Context class with specific types.
34
+ * Provides functionality to access the root context within a hierarchical structure.
35
+ * The FileCtx is bound to a SceneCtx and CtxArg, defining its operational scope.
36
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
37
+ */
38
+ class FileCtx extends Context_1.Context {
39
+ root() {
40
+ return this.upper.root();
41
+ }
42
+ }
43
+ exports.FileCtx = FileCtx;
44
+ /**
45
+ * Represents an abstract class responsible for handling class-related operations.
46
+ * The ClassPass class is designed to define a contract for executing specific logic
47
+ * when processing a given class within a particular context. Implementations of this
48
+ * class are expected to provide concrete behavior for the `run` method.
49
+ *
50
+ * @param cls:ArkClass - The class to be executed
51
+ * @param ctx:ClassCtx - The context used in executed
52
+ * @returns The result of the method execution, which can be of FallAction or void.
53
+ */
54
+ class ClassPass {
55
+ }
56
+ exports.ClassPass = ClassPass;
57
+ /**
58
+ * Represents a specialized context class that extends the base Context class with specific types.
59
+ * Provides functionality to access the root context within a hierarchical structure.
60
+ * The ClassCtx is bound to a FileCtx and CtxArg, defining its operational scope.
61
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
62
+ */
63
+ class ClassCtx extends Context_1.Context {
64
+ root() {
65
+ return this.upper.root();
66
+ }
67
+ }
68
+ exports.ClassCtx = ClassCtx;
69
+ /**
70
+ * Represents an abstract class for executing a method within a specific context.
71
+ * The MethodPass class is designed to be extended by concrete implementations
72
+ * that define how a given method should be processed or executed.
73
+ *
74
+ * The `run` method must be implemented by subclasses to provide the logic
75
+ * for handling the execution of the provided method using the given context.
76
+ *
77
+ * @param method: ArkMethod - The method to be executed
78
+ * @param ctx: MethodCtx - The context used in executed
79
+ * @returns The result of the method execution, which can be of FallAction or void.
80
+ */
81
+ class MethodPass {
82
+ }
83
+ exports.MethodPass = MethodPass;
84
+ /**
85
+ * Represents a specialized context class that extends the base Context class with specific types.
86
+ * Provides functionality to access the root context within a hierarchical structure.
87
+ * The MethodCtx is bound to a ClassCtx and CtxArg, defining its operational scope.
88
+ * The root method retrieves the top-level SceneCtx by traversing the context hierarchy.
89
+ */
90
+ class MethodCtx extends Context_1.Context {
91
+ root() {
92
+ return this.upper.root();
93
+ }
94
+ }
95
+ exports.MethodCtx = MethodCtx;
@@ -0,0 +1,73 @@
1
+ import { Scene } from '../Scene';
2
+ import { AnyKey, Context, CtxArg, UpperRoot } from './Context';
3
+ import { Dispatcher } from './Dispatcher';
4
+ import { ClassPass, FilePass, MethodPass } from './Pass';
5
+ import { ArkFile } from '../core/model/ArkFile';
6
+ import { ArkClass } from '../core/model/ArkClass';
7
+ import { ArkMethod } from '../core/model/ArkMethod';
8
+ /**
9
+ * Represents a specialized context class that extends the base Context class with specific types.
10
+ * Provides functionality to access the root context within a hierarchical structure.
11
+ * The SceneCtx is bound to a UpperRoot and CtxArg, defining its operational scope.
12
+ * The root method retrieves the top-level SceneCtx itself.
13
+ */
14
+ export declare class SceneCtx extends Context<UpperRoot, CtxArg> {
15
+ constructor();
16
+ root(): SceneCtx;
17
+ }
18
+ /**
19
+ * Represents the properties required for configuring various passes in a system.
20
+ * The PassProps interface is designed to hold arrays of different types of passes,
21
+ * specifically file-level, class-level, and method-level passes. Each pass type
22
+ * is identified by a unique key and associated with specific configurations or rules.
23
+ * These passes are used to define how certain operations or validations should be
24
+ * applied at different levels of granularity within the system.
25
+ */
26
+ export interface PassProps {
27
+ file: AnyKey<FilePass>[];
28
+ klass: AnyKey<ClassPass>[];
29
+ method: AnyKey<MethodPass>[];
30
+ }
31
+ /**
32
+ * Represents the properties for a selector configuration.
33
+ * Provides options to define callback functions for selecting files, classes, and methods.
34
+ * The file property allows specifying a function to select files from a given scene.
35
+ * The klass property allows specifying a function to select classes from a given file.
36
+ * The method property allows specifying a function to select methods from a given class.
37
+ */
38
+ export interface SelectorProps {
39
+ file?: (s: Scene) => ArkFile[];
40
+ klass?: (s: ArkFile) => ArkClass[];
41
+ method?: (s: ArkClass) => ArkMethod[];
42
+ }
43
+ /**
44
+ * Represents the properties for configuring a scene pass manager.
45
+ *
46
+ * The SceneProps interface allows defining optional configurations for a scene,
47
+ * including rendering passes, selector properties, and a dispatcher implementation.
48
+ *
49
+ * The passes property defines the configuration for rendering stages or phases within the scene.
50
+ *
51
+ * The selectors property provides options for selecting elements or components within the scene.
52
+ *
53
+ * The dispatcher property specifies the dispatcher class responsible for handling events or actions
54
+ * within the scene, defaulting to the base Dispatcher type if not provided.
55
+ */
56
+ export interface SceneProps {
57
+ passes?: PassProps;
58
+ selectors?: SelectorProps;
59
+ dispatcher?: typeof Dispatcher;
60
+ }
61
+ export declare class ScenePassMgr {
62
+ private passes;
63
+ private selectors?;
64
+ private dispatcher?;
65
+ private sctx;
66
+ constructor(props: SceneProps);
67
+ sceneContext(): SceneCtx;
68
+ run(scene: Scene): void;
69
+ private iterFile;
70
+ private iterClass;
71
+ private iterMethod;
72
+ }
73
+ //# sourceMappingURL=ScenePassMgr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScenePassMgr.d.ts","sourceRoot":"","sources":["../../src/pass/ScenePassMgr.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAY,SAAS,EAAuB,QAAQ,EAAa,UAAU,EAAE,MAAM,QAAQ,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;;IAKpD,IAAI,IAAI,QAAQ;CAGnB;AAGD;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IAEtB,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAEzB,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;IAE3B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAA;CAC/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAE1B,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,OAAO,EAAE,CAAC;IAE/B,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,QAAQ,EAAE,CAAC;IAEnC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,SAAS,EAAE,CAAA;CACxC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACvB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,UAAU,CAAC;CAClC;AAED,qBAAa,YAAY;IACrB,OAAO,CAAC,MAAM,CAIZ;IACF,OAAO,CAAC,SAAS,CAAC,CAA4B;IAC9C,OAAO,CAAC,UAAU,CAAC,CAAiC;IACpD,OAAO,CAAC,IAAI,CAA4B;gBAE5B,KAAK,EAAE,UAAU;IAY7B,YAAY,IAAI,QAAQ;IAIxB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAavB,OAAO,CAAC,QAAQ;IAmBhB,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,UAAU;CAgBrB"}
@@ -0,0 +1,156 @@
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.ScenePassMgr = exports.SceneCtx = void 0;
41
+ const Context_1 = require("./Context");
42
+ const logger_1 = __importStar(require("../utils/logger"));
43
+ const Dispatcher_1 = require("./Dispatcher");
44
+ const Pass_1 = require("./Pass");
45
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SceneMgr');
46
+ /**
47
+ * Represents a specialized context class that extends the base Context class with specific types.
48
+ * Provides functionality to access the root context within a hierarchical structure.
49
+ * The SceneCtx is bound to a UpperRoot and CtxArg, defining its operational scope.
50
+ * The root method retrieves the top-level SceneCtx itself.
51
+ */
52
+ class SceneCtx extends Context_1.Context {
53
+ constructor() {
54
+ super(Context_1.UpperRoot.getInstance());
55
+ }
56
+ root() {
57
+ return this;
58
+ }
59
+ }
60
+ exports.SceneCtx = SceneCtx;
61
+ class ScenePassMgr {
62
+ constructor(props) {
63
+ this.passes = {
64
+ file: [],
65
+ klass: [],
66
+ method: [],
67
+ };
68
+ this.selectors = undefined;
69
+ this.dispatcher = Dispatcher_1.Dispatcher;
70
+ this.sctx = new SceneCtx();
71
+ if (props.passes) {
72
+ this.passes = props.passes;
73
+ }
74
+ if (props.selectors) {
75
+ this.selectors = props.selectors;
76
+ }
77
+ if (props.dispatcher) {
78
+ this.dispatcher = props.dispatcher;
79
+ }
80
+ }
81
+ sceneContext() {
82
+ return this.sctx;
83
+ }
84
+ run(scene) {
85
+ var _a;
86
+ logger.info('run scene');
87
+ let files;
88
+ if ((_a = this.selectors) === null || _a === void 0 ? void 0 : _a.file) {
89
+ files = this.selectors.file(scene);
90
+ }
91
+ else {
92
+ files = scene.getFiles();
93
+ }
94
+ for (let file of files) {
95
+ this.iterFile(file);
96
+ }
97
+ }
98
+ iterFile(file) {
99
+ var _a;
100
+ let fctx = new Pass_1.FileCtx(this.sctx);
101
+ for (let P of this.passes.file) {
102
+ let p = new P();
103
+ if (p.run(file, fctx) === 1 /* FallAction.Break */) {
104
+ break;
105
+ }
106
+ }
107
+ let classes;
108
+ if ((_a = this.selectors) === null || _a === void 0 ? void 0 : _a.klass) {
109
+ classes = this.selectors.klass(file);
110
+ }
111
+ else {
112
+ classes = file.getClasses();
113
+ }
114
+ for (let cls of classes) {
115
+ this.iterClass(cls, fctx);
116
+ }
117
+ }
118
+ iterClass(cls, fctx) {
119
+ var _a;
120
+ let cctx = new Pass_1.ClassCtx(fctx);
121
+ for (let P of this.passes.klass) {
122
+ let p = new P();
123
+ if (p.run(cls, cctx) === 1 /* FallAction.Break */) {
124
+ break;
125
+ }
126
+ }
127
+ let methods;
128
+ if ((_a = this.selectors) === null || _a === void 0 ? void 0 : _a.method) {
129
+ methods = this.selectors.method(cls);
130
+ }
131
+ else {
132
+ methods = cls.getMethods();
133
+ }
134
+ for (let mtd of methods) {
135
+ this.iterMethod(mtd, cctx);
136
+ }
137
+ }
138
+ iterMethod(mtd, cctx) {
139
+ var _a;
140
+ let mctx = new Pass_1.MethodCtx(cctx);
141
+ for (let P of this.passes.method) {
142
+ let p = new P();
143
+ if (p.run(mtd, mctx) === 1 /* FallAction.Break */) {
144
+ break;
145
+ }
146
+ }
147
+ if (this.dispatcher) {
148
+ let stmts = ((_a = mtd.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts()) || [];
149
+ let dispatcher = new this.dispatcher(mctx);
150
+ for (let s of stmts) {
151
+ dispatcher.dispatchStmt(mtd, s);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ exports.ScenePassMgr = ScenePassMgr;