arkanalyzer 1.0.6 → 1.0.8
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.
- package/config/arkanalyzer.json +8 -0
- package/docs/IR2ts-stmt.md +81 -0
- package/docs/IR2ts.md +82 -0
- package/lib/Config.d.ts +29 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +44 -11
- package/lib/Scene.d.ts +152 -9
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +233 -66
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +2 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.js +14 -7
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +2 -4
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
- package/lib/callgraph/common/Statistics.js +1 -1
- package/lib/callgraph/model/BaseGraph.js +2 -2
- package/lib/callgraph/model/CallGraph.d.ts +3 -2
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
- package/lib/callgraph/model/CallGraph.js +23 -14
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +2 -2
- package/lib/callgraph/model/builder/CallGraphBuilder.js +3 -3
- package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Context.js +0 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +36 -9
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +130 -37
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +34 -5
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +479 -126
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +6 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +107 -45
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PtsDS.js +0 -2
- package/lib/core/base/Constant.d.ts +37 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +58 -8
- package/lib/core/base/Expr.d.ts +98 -13
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +295 -127
- package/lib/core/base/Local.d.ts +70 -5
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +77 -4
- package/lib/core/base/Ref.d.ts +79 -5
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +143 -38
- package/lib/core/base/Stmt.d.ts +126 -12
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -28
- package/lib/core/base/Type.d.ts +11 -2
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +47 -42
- package/lib/core/base/Value.d.ts +24 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/common/ArkError.d.ts +15 -0
- package/lib/core/common/ArkError.d.ts.map +1 -0
- package/lib/core/common/ArkError.js +28 -0
- package/lib/core/common/ArkIRTransformer.d.ts +12 -5
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +90 -45
- package/lib/core/common/BodyBuilder.d.ts +2 -0
- package/lib/core/common/BodyBuilder.d.ts.map +1 -1
- package/lib/core/common/BodyBuilder.js +5 -2
- package/lib/core/common/Builtin.js +1 -1
- package/lib/core/common/CfgBuilder.d.ts +12 -7
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +336 -140
- package/lib/core/common/Const.d.ts +15 -10
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +18 -11
- package/lib/core/common/DummyMainCreater.d.ts +5 -4
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +43 -28
- package/lib/core/common/EtsConst.d.ts +1 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -1
- package/lib/core/common/EtsConst.js +2 -1
- package/lib/core/common/ExprUseReplacer.js +8 -8
- package/lib/core/common/IRUtils.d.ts +7 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +34 -2
- package/lib/core/common/ModelUtils.d.ts +1 -0
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +39 -36
- package/lib/core/common/RefUseReplacer.js +3 -3
- package/lib/core/common/StmtUseReplacer.js +4 -4
- package/lib/core/common/TSConst.d.ts +10 -3
- package/lib/core/common/TSConst.d.ts.map +1 -1
- package/lib/core/common/TSConst.js +11 -4
- package/lib/core/common/TypeInference.d.ts +8 -2
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +222 -90
- package/lib/core/common/ValueUtil.d.ts +0 -4
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +10 -27
- package/lib/core/common/VisibleValue.js +1 -1
- package/lib/core/dataflow/DataflowProblem.d.ts +1 -0
- package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowProblem.js +4 -4
- package/lib/core/dataflow/DataflowSolver.d.ts +20 -16
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowSolver.js +67 -78
- package/lib/core/dataflow/TiantAnalysis.d.ts +1 -0
- package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -1
- package/lib/core/dataflow/TiantAnalysis.js +42 -28
- package/lib/core/dataflow/UndefinedVariable.d.ts +15 -1
- package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -1
- package/lib/core/dataflow/UndefinedVariable.js +122 -76
- package/lib/core/dataflow/Util.d.ts +5 -1
- package/lib/core/dataflow/Util.d.ts.map +1 -1
- package/lib/core/dataflow/Util.js +43 -22
- package/lib/core/graph/BasicBlock.d.ts +72 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +165 -3
- package/lib/core/graph/Cfg.d.ts +30 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +131 -11
- package/lib/core/graph/DominanceFinder.js +7 -7
- package/lib/core/graph/DominanceTree.js +4 -4
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -5
- package/lib/core/model/ArkBaseModel.d.ts +59 -0
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -0
- package/lib/core/model/ArkBaseModel.js +271 -0
- package/lib/core/model/ArkBody.d.ts +3 -9
- package/lib/core/model/ArkBody.d.ts.map +1 -1
- package/lib/core/model/ArkBody.js +3 -14
- package/lib/core/model/ArkClass.d.ts +107 -13
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +152 -54
- package/lib/core/model/ArkExport.d.ts +8 -7
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +16 -18
- package/lib/core/model/ArkField.d.ts +16 -13
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +18 -62
- package/lib/core/model/ArkFile.d.ts +42 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +58 -0
- package/lib/core/model/ArkImport.d.ts +9 -7
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +11 -12
- package/lib/core/model/ArkMetadata.d.ts +20 -0
- package/lib/core/model/ArkMetadata.d.ts.map +1 -0
- package/lib/core/model/ArkMetadata.js +44 -0
- package/lib/core/model/ArkMethod.d.ts +195 -17
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +363 -46
- package/lib/core/model/ArkNamespace.d.ts +6 -8
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +16 -20
- package/lib/core/model/ArkSignature.d.ts +41 -0
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +76 -19
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +60 -49
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +12 -6
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +13 -9
- package/lib/core/model/builder/ArkFileBuilder.js +1 -3
- package/lib/core/model/builder/ArkImportBuilder.d.ts +2 -1
- package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkImportBuilder.js +16 -13
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +3 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +105 -45
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +4 -5
- package/lib/core/model/builder/builderUtils.d.ts +2 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +63 -43
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/save/ArkStream.js +1 -1
- package/lib/save/DotPrinter.d.ts.map +1 -1
- package/lib/save/DotPrinter.js +1 -15
- package/lib/save/GraphPrinter.d.ts.map +1 -1
- package/lib/save/GraphPrinter.js +4 -2
- package/lib/save/JsonPrinter.js +5 -5
- package/lib/save/ViewTreePrinter.d.ts +16 -0
- package/lib/save/ViewTreePrinter.d.ts.map +1 -0
- package/lib/save/ViewTreePrinter.js +130 -0
- package/lib/save/source/SourceBase.d.ts +2 -2
- package/lib/save/source/SourceBase.d.ts.map +1 -1
- package/lib/save/source/SourceBase.js +6 -13
- package/lib/save/source/SourceBody.d.ts.map +1 -1
- package/lib/save/source/SourceBody.js +27 -14
- package/lib/save/source/SourceClass.d.ts.map +1 -1
- package/lib/save/source/SourceClass.js +12 -8
- package/lib/save/source/SourceField.d.ts.map +1 -1
- package/lib/save/source/SourceField.js +6 -2
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +10 -3
- package/lib/save/source/SourceModule.d.ts.map +1 -1
- package/lib/save/source/SourceModule.js +16 -10
- package/lib/save/source/SourceNamespace.d.ts.map +1 -1
- package/lib/save/source/SourceNamespace.js +4 -0
- package/lib/save/source/SourceStmt.d.ts +1 -1
- package/lib/save/source/SourceStmt.d.ts.map +1 -1
- package/lib/save/source/SourceStmt.js +37 -25
- package/lib/save/source/SourceTransformer.d.ts +6 -0
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +82 -51
- package/lib/save/source/SourceUtils.d.ts.map +1 -1
- package/lib/save/source/SourceUtils.js +12 -11
- package/lib/transformer/StaticSingleAssignmentFormer.js +3 -3
- package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
- package/lib/utils/CfgStructualAnalysis.js +103 -72
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -10
- package/lib/utils/crypto_utils.d.ts +6 -0
- package/lib/utils/crypto_utils.d.ts.map +1 -0
- package/lib/utils/crypto_utils.js +57 -0
- package/lib/utils/entryMethodUtils.d.ts.map +1 -1
- package/lib/utils/entryMethodUtils.js +27 -26
- package/lib/utils/getAllFiles.d.ts +1 -1
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +4 -5
- package/lib/utils/logger.js +2 -2
- package/package.json +3 -2
|
@@ -13,10 +13,42 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
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
|
+
};
|
|
16
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
40
|
exports.BasicBlock = void 0;
|
|
41
|
+
const Stmt_1 = require("../base/Stmt");
|
|
42
|
+
const ArkError_1 = require("../common/ArkError");
|
|
43
|
+
const logger_1 = __importStar(require("../../utils/logger"));
|
|
44
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'BasicBlock');
|
|
18
45
|
/**
|
|
19
46
|
* @category core/graph
|
|
47
|
+
* A `BasicBlock` is composed of:
|
|
48
|
+
* - ID: a **number** that uniquely identify the basic block, initialized as -1.
|
|
49
|
+
* - Statements: an **array** of statements in the basic block.
|
|
50
|
+
* - Predecessors: an **array** of basic blocks in front of the current basic block. More accurately, these basic blocks can reach the current block through edges.
|
|
51
|
+
* - Successors: an **array** of basic blocks after the current basic block. More accurately, the current block can reach these basic blocks through edges.
|
|
20
52
|
*/
|
|
21
53
|
class BasicBlock {
|
|
22
54
|
constructor() {
|
|
@@ -31,28 +63,128 @@ class BasicBlock {
|
|
|
31
63
|
setId(id) {
|
|
32
64
|
this.id = id;
|
|
33
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns an array of the statements in a basic block.
|
|
68
|
+
* @returns An array of statements in a basic block.
|
|
69
|
+
*/
|
|
34
70
|
getStmts() {
|
|
35
71
|
return this.stmts;
|
|
36
72
|
}
|
|
37
73
|
addStmt(stmt) {
|
|
38
74
|
this.stmts.push(stmt);
|
|
39
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Adds the given stmt at the beginning of the basic block.
|
|
78
|
+
* @param stmt
|
|
79
|
+
*/
|
|
80
|
+
addHead(stmt) {
|
|
81
|
+
if (stmt instanceof Stmt_1.Stmt) {
|
|
82
|
+
this.stmts.unshift(stmt);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.stmts.unshift(...stmt);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Adds the given stmt at the end of the basic block.
|
|
90
|
+
* @param stmt
|
|
91
|
+
*/
|
|
92
|
+
addTail(stmt) {
|
|
93
|
+
if (stmt instanceof Stmt_1.Stmt) {
|
|
94
|
+
this.stmts.push(stmt);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.stmts.push(...stmt);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Inserts toInsert in the basic block after point.
|
|
102
|
+
* @param toInsert
|
|
103
|
+
* @param point
|
|
104
|
+
* @returns The number of successfully inserted statements
|
|
105
|
+
*/
|
|
106
|
+
insertAfter(toInsert, point) {
|
|
107
|
+
let index = this.stmts.indexOf(point);
|
|
108
|
+
if (index < 0) {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
return this.insertPos(index + 1, toInsert);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Inserts toInsert in the basic block befor point.
|
|
115
|
+
* @param toInsert
|
|
116
|
+
* @param point
|
|
117
|
+
* @returns The number of successfully inserted statements
|
|
118
|
+
*/
|
|
119
|
+
insertBefore(toInsert, point) {
|
|
120
|
+
let index = this.stmts.indexOf(point);
|
|
121
|
+
if (index < 0) {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
return this.insertPos(index, toInsert);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Removes the given stmt from this basic block.
|
|
128
|
+
* @param stmt
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
remove(stmt) {
|
|
132
|
+
let index = this.stmts.indexOf(stmt);
|
|
133
|
+
if (index < 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.stmts.splice(index, 1);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Removes the first stmt from this basic block.
|
|
140
|
+
*/
|
|
141
|
+
removeHead() {
|
|
142
|
+
this.stmts.splice(0, 1);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes the last stmt from this basic block.
|
|
146
|
+
*/
|
|
147
|
+
removeTail() {
|
|
148
|
+
this.stmts.splice(this.stmts.length - 1, 1);
|
|
149
|
+
}
|
|
40
150
|
getHead() {
|
|
41
|
-
if (this.stmts.length
|
|
151
|
+
if (this.stmts.length === 0) {
|
|
42
152
|
return null;
|
|
43
153
|
}
|
|
44
154
|
return this.stmts[0];
|
|
45
155
|
}
|
|
46
156
|
getTail() {
|
|
47
157
|
let size = this.stmts.length;
|
|
48
|
-
if (size
|
|
158
|
+
if (size === 0) {
|
|
49
159
|
return null;
|
|
50
160
|
}
|
|
51
161
|
return this.stmts[size - 1];
|
|
52
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns successors of the current basic block, whose types are also basic blocks (i.e.{@link BasicBlock}).
|
|
165
|
+
* @returns Successors of the current basic block.
|
|
166
|
+
* @example
|
|
167
|
+
* 1. get block successors.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const body = arkMethod.getBody();
|
|
171
|
+
const blocks = [...body.getCfg().getBlocks()]
|
|
172
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
173
|
+
const block = blocks[i]
|
|
174
|
+
...
|
|
175
|
+
for (const next of block.getSuccessors()) {
|
|
176
|
+
...
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
*/
|
|
53
181
|
getSuccessors() {
|
|
54
182
|
return this.successorBlocks;
|
|
55
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Returns predecessors of the current basic block, whose types are also basic blocks.
|
|
186
|
+
* @returns An array of basic blocks.
|
|
187
|
+
*/
|
|
56
188
|
getPredecessors() {
|
|
57
189
|
return this.predecessorBlocks;
|
|
58
190
|
}
|
|
@@ -75,7 +207,7 @@ class BasicBlock {
|
|
|
75
207
|
}
|
|
76
208
|
// Temp just for SSA
|
|
77
209
|
addStmtToFirst(stmt) {
|
|
78
|
-
this.
|
|
210
|
+
this.addHead(stmt);
|
|
79
211
|
}
|
|
80
212
|
// Temp just for SSA
|
|
81
213
|
addSuccessorBlock(block) {
|
|
@@ -88,5 +220,35 @@ class BasicBlock {
|
|
|
88
220
|
}
|
|
89
221
|
return strs.join('');
|
|
90
222
|
}
|
|
223
|
+
validate() {
|
|
224
|
+
let branchStmts = [];
|
|
225
|
+
for (const stmt of this.stmts) {
|
|
226
|
+
if (stmt instanceof Stmt_1.ArkIfStmt ||
|
|
227
|
+
stmt instanceof Stmt_1.ArkReturnStmt ||
|
|
228
|
+
stmt instanceof Stmt_1.ArkReturnVoidStmt ||
|
|
229
|
+
stmt instanceof Stmt_1.ArkSwitchStmt) {
|
|
230
|
+
branchStmts.push(stmt);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (branchStmts.length > 1) {
|
|
234
|
+
let errMsg = `More than one branch or return stmts in the block: ${branchStmts.map((value) => value.toString()).join('\n')}`;
|
|
235
|
+
logger.error(errMsg);
|
|
236
|
+
return { errCode: ArkError_1.ArkErrorCode.BB_MORE_THAN_ONE_BRANCH_RET_STMT, errMsg: errMsg };
|
|
237
|
+
}
|
|
238
|
+
if (branchStmts.length === 1 && branchStmts[0] !== this.stmts[this.stmts.length - 1]) {
|
|
239
|
+
let errMsg = `${branchStmts[0].toString()} not at the end of block.`;
|
|
240
|
+
logger.error(errMsg);
|
|
241
|
+
return { errCode: ArkError_1.ArkErrorCode.BB_BRANCH_RET_STMT_NOT_AT_END, errMsg: errMsg };
|
|
242
|
+
}
|
|
243
|
+
return { errCode: ArkError_1.ArkErrorCode.OK };
|
|
244
|
+
}
|
|
245
|
+
insertPos(index, toInsert) {
|
|
246
|
+
if (toInsert instanceof Stmt_1.Stmt) {
|
|
247
|
+
this.stmts.splice(index, 0, toInsert);
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
this.stmts.splice(index, 0, ...toInsert);
|
|
251
|
+
return toInsert.length;
|
|
252
|
+
}
|
|
91
253
|
}
|
|
92
254
|
exports.BasicBlock = BasicBlock;
|
package/lib/core/graph/Cfg.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DefUseChain } from '../base/DefUseChain';
|
|
2
2
|
import { Stmt } from '../base/Stmt';
|
|
3
|
+
import { ArkError } from '../common/ArkError';
|
|
3
4
|
import { ArkMethod } from '../model/ArkMethod';
|
|
4
5
|
import { BasicBlock } from './BasicBlock';
|
|
5
6
|
/**
|
|
@@ -13,7 +14,32 @@ export declare class Cfg {
|
|
|
13
14
|
private declaringMethod;
|
|
14
15
|
constructor();
|
|
15
16
|
getStmts(): Stmt[];
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Inserts toInsert in the basic block in CFG after point.
|
|
19
|
+
* @param toInsert
|
|
20
|
+
* @param point
|
|
21
|
+
* @returns The number of successfully inserted statements
|
|
22
|
+
*/
|
|
23
|
+
insertAfter(toInsert: Stmt | Stmt[], point: Stmt): number;
|
|
24
|
+
/**
|
|
25
|
+
* Inserts toInsert in the basic block in CFG befor point.
|
|
26
|
+
* @param toInsert
|
|
27
|
+
* @param point
|
|
28
|
+
* @returns The number of successfully inserted statements
|
|
29
|
+
*/
|
|
30
|
+
insertBefore(toInsert: Stmt | Stmt[], point: Stmt): number;
|
|
31
|
+
/**
|
|
32
|
+
* Removes the given stmt from the basic block in CFG.
|
|
33
|
+
* @param stmt
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
remove(stmt: Stmt): void;
|
|
37
|
+
/**
|
|
38
|
+
* Update stmtToBlock Map
|
|
39
|
+
* @param block
|
|
40
|
+
* @param changed
|
|
41
|
+
*/
|
|
42
|
+
updateStmt2BlockMap(block: BasicBlock, changed?: Stmt | Stmt[]): void;
|
|
17
43
|
addBlock(block: BasicBlock): void;
|
|
18
44
|
getBlocks(): Set<BasicBlock>;
|
|
19
45
|
getStartingBlock(): BasicBlock | undefined;
|
|
@@ -25,5 +51,8 @@ export declare class Cfg {
|
|
|
25
51
|
toString(): string;
|
|
26
52
|
buildDefUseStmt(): void;
|
|
27
53
|
buildDefUseChain(): void;
|
|
54
|
+
getUnreachableBlocks(): Set<BasicBlock>;
|
|
55
|
+
validate(): ArkError;
|
|
56
|
+
private dfsPostOrder;
|
|
28
57
|
}
|
|
29
58
|
//# sourceMappingURL=Cfg.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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IAAI,IAAI;IAIvB,eAAe,CAAC,eAAe,EAAE,IAAI,GAAG,IAAI;IAI5C,kBAAkB,IAAI,SAAS;IAI/B,kBAAkB,CAAC,MAAM,EAAE,SAAS;IAIpC,eAAe,IAAI,WAAW,EAAE;IAKhC,QAAQ,IAAI,MAAM;IAIlB,eAAe;IAiBf,gBAAgB;IA0DhB,oBAAoB,IAAI,GAAG,CAAC,UAAU,CAAC;IAevC,QAAQ,IAAI,QAAQ;IAoB3B,OAAO,CAAC,YAAY;CAevB"}
|
package/lib/core/graph/Cfg.js
CHANGED
|
@@ -13,13 +13,38 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
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
|
+
};
|
|
16
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
40
|
exports.Cfg = void 0;
|
|
18
41
|
const DefUseChain_1 = require("../base/DefUseChain");
|
|
19
42
|
const Local_1 = require("../base/Local");
|
|
20
43
|
const Stmt_1 = require("../base/Stmt");
|
|
44
|
+
const ArkError_1 = require("../common/ArkError");
|
|
21
45
|
const ArkMethod_1 = require("../model/ArkMethod");
|
|
22
|
-
const
|
|
46
|
+
const logger_1 = __importStar(require("../../utils/logger"));
|
|
47
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'BasicBlock');
|
|
23
48
|
/**
|
|
24
49
|
* @category core/graph
|
|
25
50
|
*/
|
|
@@ -27,7 +52,6 @@ class Cfg {
|
|
|
27
52
|
constructor() {
|
|
28
53
|
this.blocks = new Set();
|
|
29
54
|
this.stmtToBlock = new Map();
|
|
30
|
-
this.startingStmt = new Stmt_1.OriginalStmt('', Position_1.LineColPosition.DEFAULT);
|
|
31
55
|
this.defUseChains = [];
|
|
32
56
|
this.declaringMethod = new ArkMethod_1.ArkMethod();
|
|
33
57
|
}
|
|
@@ -38,12 +62,66 @@ class Cfg {
|
|
|
38
62
|
}
|
|
39
63
|
return stmts;
|
|
40
64
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Inserts toInsert in the basic block in CFG after point.
|
|
67
|
+
* @param toInsert
|
|
68
|
+
* @param point
|
|
69
|
+
* @returns The number of successfully inserted statements
|
|
70
|
+
*/
|
|
71
|
+
insertAfter(toInsert, point) {
|
|
72
|
+
const block = this.stmtToBlock.get(point);
|
|
73
|
+
if (!block) {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
this.updateStmt2BlockMap(block, toInsert);
|
|
77
|
+
return block.insertAfter(toInsert, point);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Inserts toInsert in the basic block in CFG befor point.
|
|
81
|
+
* @param toInsert
|
|
82
|
+
* @param point
|
|
83
|
+
* @returns The number of successfully inserted statements
|
|
84
|
+
*/
|
|
85
|
+
insertBefore(toInsert, point) {
|
|
86
|
+
const block = this.stmtToBlock.get(point);
|
|
87
|
+
if (!block) {
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
this.updateStmt2BlockMap(block, toInsert);
|
|
91
|
+
return block.insertBefore(toInsert, point);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes the given stmt from the basic block in CFG.
|
|
95
|
+
* @param stmt
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
remove(stmt) {
|
|
99
|
+
const block = this.stmtToBlock.get(stmt);
|
|
100
|
+
if (!block) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.stmtToBlock.delete(stmt);
|
|
104
|
+
block.remove(stmt);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Update stmtToBlock Map
|
|
108
|
+
* @param block
|
|
109
|
+
* @param changed
|
|
110
|
+
*/
|
|
111
|
+
updateStmt2BlockMap(block, changed) {
|
|
112
|
+
if (!changed) {
|
|
113
|
+
for (const stmt of block.getStmts()) {
|
|
114
|
+
this.stmtToBlock.set(stmt, block);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (changed instanceof Stmt_1.Stmt) {
|
|
118
|
+
this.stmtToBlock.set(changed, block);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
for (const insert of changed) {
|
|
122
|
+
this.stmtToBlock.set(insert, block);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
47
125
|
}
|
|
48
126
|
// TODO: 添加block之间的边
|
|
49
127
|
addBlock(block) {
|
|
@@ -104,13 +182,13 @@ class Cfg {
|
|
|
104
182
|
// 判断本block之前有无对应def
|
|
105
183
|
for (let i = stmtIndex - 1; i >= 0; i--) {
|
|
106
184
|
const beforeStmt = block.getStmts()[i];
|
|
107
|
-
if (beforeStmt.getDef() && ((_a = beforeStmt.getDef()) === null || _a === void 0 ? void 0 : _a.toString())
|
|
185
|
+
if (beforeStmt.getDef() && ((_a = beforeStmt.getDef()) === null || _a === void 0 ? void 0 : _a.toString()) === name) {
|
|
108
186
|
defStmts.push(beforeStmt);
|
|
109
187
|
break;
|
|
110
188
|
}
|
|
111
189
|
}
|
|
112
190
|
// 本block有对应def直接结束,否则找所有的前序block
|
|
113
|
-
if (defStmts.length
|
|
191
|
+
if (defStmts.length !== 0) {
|
|
114
192
|
this.defUseChains.push(new DefUseChain_1.DefUseChain(value, defStmts[0], stmt));
|
|
115
193
|
}
|
|
116
194
|
else {
|
|
@@ -128,7 +206,7 @@ class Cfg {
|
|
|
128
206
|
let predecessorHasDef = false;
|
|
129
207
|
for (let i = predecessorStmts.length - 1; i >= 0; i--) {
|
|
130
208
|
const beforeStmt = predecessorStmts[i];
|
|
131
|
-
if (beforeStmt.getDef() && ((_b = beforeStmt.getDef()) === null || _b === void 0 ? void 0 : _b.toString())
|
|
209
|
+
if (beforeStmt.getDef() && ((_b = beforeStmt.getDef()) === null || _b === void 0 ? void 0 : _b.toString()) === name) {
|
|
132
210
|
defStmts.push(beforeStmt);
|
|
133
211
|
predecessorHasDef = true;
|
|
134
212
|
break;
|
|
@@ -150,5 +228,47 @@ class Cfg {
|
|
|
150
228
|
}
|
|
151
229
|
}
|
|
152
230
|
}
|
|
231
|
+
getUnreachableBlocks() {
|
|
232
|
+
let unreachable = new Set();
|
|
233
|
+
let startBB = this.getStartingBlock();
|
|
234
|
+
if (!startBB) {
|
|
235
|
+
return unreachable;
|
|
236
|
+
}
|
|
237
|
+
let postOrder = this.dfsPostOrder(startBB);
|
|
238
|
+
for (const bb of this.blocks) {
|
|
239
|
+
if (!postOrder.has(bb)) {
|
|
240
|
+
unreachable.add(bb);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return unreachable;
|
|
244
|
+
}
|
|
245
|
+
validate() {
|
|
246
|
+
let startBB = this.getStartingBlock();
|
|
247
|
+
if (!startBB) {
|
|
248
|
+
let errMsg = `Not found starting block}`;
|
|
249
|
+
logger.error(errMsg);
|
|
250
|
+
return { errCode: ArkError_1.ArkErrorCode.CFG_NOT_FOUND_START_BLOCK, errMsg: errMsg };
|
|
251
|
+
}
|
|
252
|
+
let unreachable = this.getUnreachableBlocks();
|
|
253
|
+
if (unreachable.size !== 0) {
|
|
254
|
+
let errMsg = `Unreachable blocks: ${Array.from(unreachable)
|
|
255
|
+
.map((value) => value.toString())
|
|
256
|
+
.join('\n')}`;
|
|
257
|
+
logger.error(errMsg);
|
|
258
|
+
return { errCode: ArkError_1.ArkErrorCode.CFG_HAS_UNREACHABLE_BLOCK, errMsg: errMsg };
|
|
259
|
+
}
|
|
260
|
+
return { errCode: ArkError_1.ArkErrorCode.OK };
|
|
261
|
+
}
|
|
262
|
+
dfsPostOrder(node, visitor = new Set(), postOrder = new Set()) {
|
|
263
|
+
visitor.add(node);
|
|
264
|
+
for (const succ of node.getSuccessors()) {
|
|
265
|
+
if (visitor.has(succ)) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
this.dfsPostOrder(succ, visitor, postOrder);
|
|
269
|
+
}
|
|
270
|
+
postOrder.add(node);
|
|
271
|
+
return postOrder;
|
|
272
|
+
}
|
|
153
273
|
}
|
|
154
274
|
exports.Cfg = Cfg;
|
|
@@ -37,20 +37,20 @@ class DominanceFinder {
|
|
|
37
37
|
while (isChanged) {
|
|
38
38
|
isChanged = false;
|
|
39
39
|
for (const block of this.blocks) {
|
|
40
|
-
if (block
|
|
40
|
+
if (block === startingBlock) {
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
let blockIdx = this.blockToIdx.get(block);
|
|
44
44
|
let preds = Array.from(block.getPredecessors());
|
|
45
45
|
let newIdom = this.getFirstDefinedBlockPredIdx(preds);
|
|
46
|
-
if (preds.length > 0 && newIdom
|
|
46
|
+
if (preds.length > 0 && newIdom !== -1) {
|
|
47
47
|
for (const pred of preds) {
|
|
48
48
|
let predIdx = this.blockToIdx.get(pred);
|
|
49
|
-
if (this.idoms[predIdx]
|
|
49
|
+
if (this.idoms[predIdx] !== -1) {
|
|
50
50
|
newIdom = this.intersect(newIdom, predIdx);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
if (this.idoms[blockIdx]
|
|
53
|
+
if (this.idoms[blockIdx] !== newIdom) {
|
|
54
54
|
this.idoms[blockIdx] = newIdom;
|
|
55
55
|
isChanged = true;
|
|
56
56
|
}
|
|
@@ -68,7 +68,7 @@ class DominanceFinder {
|
|
|
68
68
|
let blockIdx = this.blockToIdx.get(block);
|
|
69
69
|
for (const pred of preds) {
|
|
70
70
|
let predIdx = this.blockToIdx.get(pred);
|
|
71
|
-
while (predIdx
|
|
71
|
+
while (predIdx !== this.idoms[blockIdx]) {
|
|
72
72
|
this.domFrontiers[predIdx].push(blockIdx);
|
|
73
73
|
predIdx = this.idoms[predIdx];
|
|
74
74
|
}
|
|
@@ -100,14 +100,14 @@ class DominanceFinder {
|
|
|
100
100
|
getFirstDefinedBlockPredIdx(preds) {
|
|
101
101
|
for (const block of preds) {
|
|
102
102
|
let idx = this.blockToIdx.get(block);
|
|
103
|
-
if (this.idoms[idx]
|
|
103
|
+
if (this.idoms[idx] !== -1) {
|
|
104
104
|
return idx;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
return -1;
|
|
108
108
|
}
|
|
109
109
|
intersect(a, b) {
|
|
110
|
-
while (a
|
|
110
|
+
while (a !== b) {
|
|
111
111
|
if (a > b) {
|
|
112
112
|
a = this.idoms[a];
|
|
113
113
|
}
|
|
@@ -29,11 +29,11 @@ class DominanceTree {
|
|
|
29
29
|
this.children = new Array(treeSize);
|
|
30
30
|
this.parents = new Array(treeSize);
|
|
31
31
|
for (let i = 0; i < treeSize; i++) {
|
|
32
|
-
this.children[i] =
|
|
32
|
+
this.children[i] = [];
|
|
33
33
|
this.parents[i] = -1;
|
|
34
34
|
}
|
|
35
35
|
for (let i = 0; i < treeSize; i++) {
|
|
36
|
-
if (idoms[i]
|
|
36
|
+
if (idoms[i] !== i) {
|
|
37
37
|
this.parents[i] = idoms[i];
|
|
38
38
|
this.children[idoms[i]].push(i);
|
|
39
39
|
}
|
|
@@ -43,11 +43,11 @@ class DominanceTree {
|
|
|
43
43
|
let dfsBlocks = new Array();
|
|
44
44
|
let queue = new Array();
|
|
45
45
|
queue.push(this.getRoot());
|
|
46
|
-
while (queue.length
|
|
46
|
+
while (queue.length !== 0) {
|
|
47
47
|
let curr = queue.splice(0, 1)[0];
|
|
48
48
|
dfsBlocks.push(curr);
|
|
49
49
|
let childList = this.getChildren(curr);
|
|
50
|
-
if (childList.length
|
|
50
|
+
if (childList.length !== 0) {
|
|
51
51
|
for (let i = childList.length - 1; i >= 0; i--) {
|
|
52
52
|
queue.splice(0, 0, childList[i]);
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewTreeBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/graph/builder/ViewTreeBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAUjD,OAAO,EAAE,mBAAmB,EAAc,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAgC,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAA2B,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAiBhE,OAAO,EAAE,QAAQ,EAAiB,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3E,OAAO,EAAE,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;IACH,OAAO,CAAC,cAAc;IA0BtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAiC9B,OAAO,CAAC,qBAAqB;IAmB7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,6BAA6B;IA4BrC,OAAO,CAAC,sBAAsB;IA4D9B,OAAO,CAAC,2BAA2B;IAmDnC,OAAO,CAAC,uBAAuB;IA0B/B,OAAO,CAAC,qBAAqB;IAsB7B,OAAO,CAAC,oBAAoB;IAiB5B,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,wBAAwB,CAU7B;IAEH,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,qBAAqB;IAkC7B;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAgD/B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,oBAAoB;CAmB/B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAEzD"}
|
|
@@ -49,6 +49,7 @@ const EtsConst_1 = require("../../common/EtsConst");
|
|
|
49
49
|
const ArkClass_1 = require("../../model/ArkClass");
|
|
50
50
|
const logger_1 = __importStar(require("../../../utils/logger"));
|
|
51
51
|
const ModelUtils_1 = require("../../common/ModelUtils");
|
|
52
|
+
const Const_1 = require("../../common/Const");
|
|
52
53
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ViewTreeBuilder');
|
|
53
54
|
const COMPONENT_CREATE_FUNCTIONS = new Set([EtsConst_1.COMPONENT_CREATE_FUNCTION, EtsConst_1.COMPONENT_BRANCH_FUNCTION]);
|
|
54
55
|
function backtraceLocalInitValue(value) {
|
|
@@ -58,7 +59,7 @@ function backtraceLocalInitValue(value) {
|
|
|
58
59
|
if (rightOp instanceof Local_1.Local) {
|
|
59
60
|
return backtraceLocalInitValue(rightOp);
|
|
60
61
|
}
|
|
61
|
-
else if (rightOp instanceof Ref_1.ArkInstanceFieldRef && rightOp.getBase().getName().startsWith(
|
|
62
|
+
else if (rightOp instanceof Ref_1.ArkInstanceFieldRef && rightOp.getBase().getName().startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
62
63
|
return backtraceLocalInitValue(rightOp.getBase());
|
|
63
64
|
}
|
|
64
65
|
return rightOp;
|
|
@@ -423,7 +424,7 @@ class TreeNodeStack {
|
|
|
423
424
|
return;
|
|
424
425
|
}
|
|
425
426
|
let node = this.stack[this.stack.length - 1];
|
|
426
|
-
if (name
|
|
427
|
+
if (name !== node.name && !this.isContainer(node.name)) {
|
|
427
428
|
this.stack.pop();
|
|
428
429
|
}
|
|
429
430
|
}
|
|
@@ -432,7 +433,7 @@ class TreeNodeStack {
|
|
|
432
433
|
*/
|
|
433
434
|
popComponentExpect(name) {
|
|
434
435
|
for (let i = this.stack.length - 1; i >= 0; i--) {
|
|
435
|
-
if (this.stack[i].name
|
|
436
|
+
if (this.stack[i].name !== name) {
|
|
436
437
|
this.stack.pop();
|
|
437
438
|
}
|
|
438
439
|
else {
|
|
@@ -822,7 +823,7 @@ class ViewTreeImpl extends TreeNodeStack {
|
|
|
822
823
|
if (builder) {
|
|
823
824
|
let method = this.findMethod(builder.getType().getMethodSignature());
|
|
824
825
|
if (!(method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
|
|
825
|
-
method === null || method === void 0 ? void 0 : method.
|
|
826
|
+
method === null || method === void 0 ? void 0 : method.addDecorator(new Decorator_1.Decorator(EtsConst_1.BUILDER_DECORATOR));
|
|
826
827
|
}
|
|
827
828
|
if (!(method === null || method === void 0 ? void 0 : method.hasViewTree())) {
|
|
828
829
|
method === null || method === void 0 ? void 0 : method.setViewTree(new ViewTreeImpl(method));
|
|
@@ -970,7 +971,7 @@ class ViewTreeImpl extends TreeNodeStack {
|
|
|
970
971
|
return component;
|
|
971
972
|
}
|
|
972
973
|
let name = expr.getBase().getName();
|
|
973
|
-
if (name.startsWith(
|
|
974
|
+
if (name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
974
975
|
let initValue = backtraceLocalInitValue(expr.getBase());
|
|
975
976
|
if (initValue instanceof Ref_1.ArkThisRef) {
|
|
976
977
|
name = 'this';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ts from 'ohos-typescript';
|
|
2
|
+
import { Decorator } from '../base/Decorator';
|
|
3
|
+
import { ArkError } from '../common/ArkError';
|
|
4
|
+
import { ArkMetadata, ArkMetadataKind, ArkMetadataType } from './ArkMetadata';
|
|
5
|
+
export declare enum ModifierType {
|
|
6
|
+
PRIVATE = 1,
|
|
7
|
+
PROTECTED = 2,
|
|
8
|
+
PUBLIC = 4,
|
|
9
|
+
EXPORT = 8,
|
|
10
|
+
STATIC = 16,
|
|
11
|
+
ABSTRACT = 32,
|
|
12
|
+
ASYNC = 64,
|
|
13
|
+
CONST = 128,
|
|
14
|
+
ACCESSOR = 256,
|
|
15
|
+
DEFAULT = 512,
|
|
16
|
+
IN = 1024,
|
|
17
|
+
READONLY = 2048,
|
|
18
|
+
OUT = 4096,
|
|
19
|
+
OVERRIDE = 8192,
|
|
20
|
+
DECLARE = 16384
|
|
21
|
+
}
|
|
22
|
+
export declare const MODIFIER_TYPE_MASK = 65535;
|
|
23
|
+
export declare function modifierKind2Enum(kind: ts.SyntaxKind): ModifierType;
|
|
24
|
+
export declare function modifiers2stringArray(modifiers: number): string[];
|
|
25
|
+
export declare abstract class ArkBaseModel {
|
|
26
|
+
protected modifiers?: number;
|
|
27
|
+
protected decorators?: Set<Decorator>;
|
|
28
|
+
protected metadata?: ArkMetadata;
|
|
29
|
+
getMetadata(kind: ArkMetadataKind): ArkMetadataType | undefined;
|
|
30
|
+
setMetadata(kind: ArkMetadataKind, value: ArkMetadataType): void;
|
|
31
|
+
getModifiers(): number;
|
|
32
|
+
setModifiers(modifiers: number): void;
|
|
33
|
+
addModifier(modifier: ModifierType | number): void;
|
|
34
|
+
removeModifier(modifier: ModifierType): void;
|
|
35
|
+
isStatic(): boolean;
|
|
36
|
+
isProtected(): boolean;
|
|
37
|
+
isPrivate(): boolean;
|
|
38
|
+
isPublic(): boolean;
|
|
39
|
+
isReadonly(): boolean;
|
|
40
|
+
isAbstract(): boolean;
|
|
41
|
+
isExport(): boolean;
|
|
42
|
+
/** @deprecated Use {@link isExport} instead. */
|
|
43
|
+
isExported(): boolean;
|
|
44
|
+
isDeclare(): boolean;
|
|
45
|
+
containsModifier(modifierType: ModifierType): boolean;
|
|
46
|
+
getDecorators(): Decorator[];
|
|
47
|
+
setDecorators(decorators: Set<Decorator>): void;
|
|
48
|
+
addDecorator(decorator: Decorator): void;
|
|
49
|
+
removeDecorator(kind: string): void;
|
|
50
|
+
hasBuilderDecorator(): boolean;
|
|
51
|
+
getStateDecorators(): Decorator[];
|
|
52
|
+
hasBuilderParamDecorator(): boolean;
|
|
53
|
+
hasEntryDecorator(): boolean;
|
|
54
|
+
hasComponentDecorator(): boolean;
|
|
55
|
+
hasDecorator(kind: string | Set<string>): boolean;
|
|
56
|
+
protected validateFields(fields: string[]): ArkError;
|
|
57
|
+
abstract validate(): ArkError;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=ArkBaseModel.d.ts.map
|