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
|
@@ -23,11 +23,13 @@ const Constant_1 = require("../base/Constant");
|
|
|
23
23
|
const Ref_1 = require("../base/Ref");
|
|
24
24
|
const DataflowSolver_1 = require("./DataflowSolver");
|
|
25
25
|
const Expr_1 = require("../base/Expr");
|
|
26
|
-
const
|
|
26
|
+
const Util_1 = require("./Util");
|
|
27
|
+
const Const_1 = require("../common/Const");
|
|
27
28
|
class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
28
29
|
constructor(stmt, method) {
|
|
29
30
|
super();
|
|
30
31
|
this.zeroValue = new Constant_1.Constant('undefined', Type_1.UndefinedType.getInstance());
|
|
32
|
+
this.outcomes = [];
|
|
31
33
|
this.entryPoint = stmt;
|
|
32
34
|
this.entryMethod = method;
|
|
33
35
|
this.scene = method.getDeclaringArkFile().getScene();
|
|
@@ -54,7 +56,7 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
54
56
|
return new class {
|
|
55
57
|
getDataFacts(dataFact) {
|
|
56
58
|
let ret = new Set();
|
|
57
|
-
if (checkerInstance.getEntryPoint()
|
|
59
|
+
if (checkerInstance.getEntryPoint() === srcStmt && checkerInstance.getZeroValue() === dataFact) {
|
|
58
60
|
let entryMethod = checkerInstance.getEntryMethod();
|
|
59
61
|
const parameters = [...entryMethod.getCfg().getBlocks()][0].getStmts().slice(0, entryMethod.getParameters().length);
|
|
60
62
|
for (let i = 0; i < parameters.length; i++) {
|
|
@@ -67,7 +69,7 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
67
69
|
const staticFields = entryMethod.getDeclaringArkClass().getStaticFields(checkerInstance.classMap);
|
|
68
70
|
for (const field of staticFields) {
|
|
69
71
|
const initializer = field.getInitializer();
|
|
70
|
-
if (initializer.length
|
|
72
|
+
if (initializer.length === 1 && initializer[0] instanceof Stmt_1.ArkAssignStmt && initializer[0].getRightOp() === undefined) {
|
|
71
73
|
ret.add(new Ref_1.ArkStaticFieldRef(field.getSignature()));
|
|
72
74
|
}
|
|
73
75
|
}
|
|
@@ -76,105 +78,128 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
76
78
|
}
|
|
77
79
|
return ret;
|
|
78
80
|
}
|
|
79
|
-
if (!(0, DataflowSolver_2.factEqual)(srcStmt.getDef(), dataFact)) {
|
|
80
|
-
if (!(dataFact instanceof Local_1.Local && dataFact.getName() == srcStmt.getDef().toString()))
|
|
81
|
-
ret.add(dataFact);
|
|
82
|
-
}
|
|
83
81
|
if (srcStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
84
|
-
|
|
85
|
-
let assigned = ass.getLeftOp();
|
|
86
|
-
let rightOp = ass.getRightOp();
|
|
87
|
-
if (checkerInstance.getZeroValue() == dataFact) {
|
|
88
|
-
if (checkerInstance.isUndefined(rightOp)) {
|
|
89
|
-
ret.add(assigned);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if ((0, DataflowSolver_2.factEqual)(rightOp, dataFact) || rightOp.getType() instanceof Type_1.UndefinedType) {
|
|
93
|
-
ret.add(assigned);
|
|
94
|
-
}
|
|
95
|
-
else if (rightOp instanceof Ref_1.ArkInstanceFieldRef) {
|
|
96
|
-
const base = rightOp.getBase();
|
|
97
|
-
if (base == dataFact || !base.getDeclaringStmt() && base.getName() == dataFact.toString()) {
|
|
98
|
-
console.log("undefined base");
|
|
99
|
-
console.log(srcStmt.toString());
|
|
100
|
-
console.log(srcStmt.getOriginPositionInfo().toString());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && rightOp == dataFact.getBase()) {
|
|
104
|
-
const field = new Ref_1.ArkInstanceFieldRef(srcStmt.getLeftOp(), dataFact.getFieldSignature());
|
|
105
|
-
ret.add(field);
|
|
106
|
-
}
|
|
82
|
+
checkerInstance.insideNormalFlowFunction(ret, srcStmt, dataFact);
|
|
107
83
|
}
|
|
108
84
|
return ret;
|
|
109
85
|
}
|
|
110
86
|
};
|
|
111
87
|
}
|
|
88
|
+
insideNormalFlowFunction(ret, srcStmt, dataFact) {
|
|
89
|
+
if (!this.factEqual(srcStmt.getDef(), dataFact)) {
|
|
90
|
+
if (!(dataFact instanceof Local_1.Local && dataFact.getName() === srcStmt.getDef().toString())) {
|
|
91
|
+
ret.add(dataFact);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
let ass = srcStmt;
|
|
95
|
+
let assigned = ass.getLeftOp();
|
|
96
|
+
let rightOp = ass.getRightOp();
|
|
97
|
+
if (this.getZeroValue() === dataFact) {
|
|
98
|
+
if (this.isUndefined(rightOp)) {
|
|
99
|
+
ret.add(assigned);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (this.factEqual(rightOp, dataFact) || rightOp.getType() instanceof Type_1.UndefinedType) {
|
|
103
|
+
ret.add(assigned);
|
|
104
|
+
}
|
|
105
|
+
else if (rightOp instanceof Ref_1.ArkInstanceFieldRef) {
|
|
106
|
+
const base = rightOp.getBase();
|
|
107
|
+
if (base === dataFact || !base.getDeclaringStmt() && base.getName() === dataFact.toString()) {
|
|
108
|
+
this.outcomes.push(new Outcome(rightOp, ass));
|
|
109
|
+
console.log('undefined base');
|
|
110
|
+
console.log(srcStmt.toString());
|
|
111
|
+
console.log(srcStmt.getOriginPositionInfo().toString());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && rightOp === dataFact.getBase()) {
|
|
115
|
+
const field = new Ref_1.ArkInstanceFieldRef(srcStmt.getLeftOp(), dataFact.getFieldSignature());
|
|
116
|
+
ret.add(field);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
112
119
|
getCallFlowFunction(srcStmt, method) {
|
|
113
120
|
let checkerInstance = this;
|
|
114
121
|
return new class {
|
|
115
122
|
getDataFacts(dataFact) {
|
|
116
123
|
const ret = new Set();
|
|
117
|
-
if (checkerInstance.getZeroValue()
|
|
118
|
-
|
|
119
|
-
// 加上调用函数能访问到的所有静态变量,如果不考虑多线程,加上所有变量,考虑则要统计之前已经处理过的变量并排除
|
|
120
|
-
for (const field of method.getDeclaringArkClass().getStaticFields(checkerInstance.classMap)) {
|
|
121
|
-
if (field.getInitializer() == undefined) {
|
|
122
|
-
ret.add(new Ref_1.ArkStaticFieldRef(field.getSignature()));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
for (const local of method.getDeclaringArkClass().getGlobalVariable(checkerInstance.globalVariableMap)) {
|
|
126
|
-
ret.add(local);
|
|
127
|
-
}
|
|
124
|
+
if (checkerInstance.getZeroValue() === dataFact) {
|
|
125
|
+
checkerInstance.insideCallFlowFunction(ret, method);
|
|
128
126
|
}
|
|
129
127
|
else {
|
|
130
128
|
const callExpr = srcStmt.getExprs()[0];
|
|
131
|
-
if (callExpr instanceof Expr_1.ArkInstanceInvokeExpr && dataFact instanceof Ref_1.ArkInstanceFieldRef && callExpr.getBase().getName()
|
|
129
|
+
if (callExpr instanceof Expr_1.ArkInstanceInvokeExpr && dataFact instanceof Ref_1.ArkInstanceFieldRef && callExpr.getBase().getName() === dataFact.getBase().getName()) {
|
|
132
130
|
// todo:base转this
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
const constructor = arkClass === null || arkClass === void 0 ? void 0 : arkClass.getMethodWithName("constructor");
|
|
136
|
-
const block = [...constructor.getCfg().getBlocks()][0];
|
|
137
|
-
for (const stmt of block.getStmts()) {
|
|
138
|
-
const def = stmt.getDef();
|
|
139
|
-
if (def && def instanceof Ref_1.ArkInstanceFieldRef && def.getBase().getName() == "this" && def.getFieldName() == dataFact.getFieldName()) {
|
|
140
|
-
ret.add(def);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
131
|
+
const thisRef = new Ref_1.ArkInstanceFieldRef(new Local_1.Local('this', new Type_1.ClassType(method.getDeclaringArkClass().getSignature())), dataFact.getFieldSignature());
|
|
132
|
+
ret.add(thisRef);
|
|
144
133
|
}
|
|
145
|
-
else if (callExpr instanceof Expr_1.ArkStaticInvokeExpr && dataFact instanceof Ref_1.ArkStaticFieldRef && callExpr.getMethodSignature().getDeclaringClassSignature()
|
|
134
|
+
else if (callExpr instanceof Expr_1.ArkStaticInvokeExpr && dataFact instanceof Ref_1.ArkStaticFieldRef && callExpr.getMethodSignature().getDeclaringClassSignature() === dataFact.getFieldSignature().getDeclaringSignature()) {
|
|
146
135
|
ret.add(dataFact);
|
|
147
136
|
}
|
|
148
137
|
}
|
|
149
|
-
|
|
150
|
-
const args = callStmt.getInvokeExpr().getArgs();
|
|
151
|
-
for (let i = 0; i < args.length; i++) {
|
|
152
|
-
if (args[i] == dataFact || checkerInstance.isUndefined(args[i]) && checkerInstance.getZeroValue() == dataFact) {
|
|
153
|
-
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
154
|
-
if (realParameter)
|
|
155
|
-
ret.add(realParameter);
|
|
156
|
-
}
|
|
157
|
-
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName() == args[i].toString()) {
|
|
158
|
-
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
159
|
-
if (realParameter) {
|
|
160
|
-
const retRef = new Ref_1.ArkInstanceFieldRef(realParameter, dataFact.getFieldSignature());
|
|
161
|
-
ret.add(retRef);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
138
|
+
checkerInstance.addParameters(srcStmt, dataFact, method, ret);
|
|
165
139
|
return ret;
|
|
166
140
|
}
|
|
167
141
|
};
|
|
168
142
|
}
|
|
143
|
+
insideCallFlowFunction(ret, method) {
|
|
144
|
+
ret.add(this.getZeroValue());
|
|
145
|
+
// 加上调用函数能访问到的所有静态变量,如果不考虑多线程,加上所有变量,考虑则要统计之前已经处理过的变量并排除
|
|
146
|
+
for (const field of method.getDeclaringArkClass().getStaticFields(this.classMap)) {
|
|
147
|
+
if (field.getInitializer() === undefined) {
|
|
148
|
+
ret.add(new Ref_1.ArkStaticFieldRef(field.getSignature()));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const local of method.getDeclaringArkClass().getGlobalVariable(this.globalVariableMap)) {
|
|
152
|
+
ret.add(local);
|
|
153
|
+
}
|
|
154
|
+
// 加上所有未定义初始值的属性
|
|
155
|
+
if (method.getName() === Const_1.INSTANCE_INIT_METHOD_NAME || method.getName() === Const_1.STATIC_INIT_METHOD_NAME) {
|
|
156
|
+
for (const field of method.getDeclaringArkClass().getFields()) {
|
|
157
|
+
this.addUndefinedField(field, method, ret);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
addUndefinedField(field, method, ret) {
|
|
162
|
+
let defined = false;
|
|
163
|
+
for (const stmt of method.getCfg().getStmts()) {
|
|
164
|
+
const def = stmt.getDef();
|
|
165
|
+
if (def instanceof Ref_1.ArkInstanceFieldRef && def.getFieldSignature() === field.getSignature()) {
|
|
166
|
+
defined = true;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!defined) {
|
|
171
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(new Local_1.Local('this', new Type_1.ClassType(method.getDeclaringArkClass().getSignature())), field.getSignature());
|
|
172
|
+
ret.add(fieldRef);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
addParameters(srcStmt, dataFact, method, ret) {
|
|
176
|
+
const callStmt = srcStmt;
|
|
177
|
+
const args = callStmt.getInvokeExpr().getArgs();
|
|
178
|
+
for (let i = 0; i < args.length; i++) {
|
|
179
|
+
if (args[i] === dataFact || this.isUndefined(args[i]) && this.getZeroValue() === dataFact) {
|
|
180
|
+
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
181
|
+
if (realParameter) {
|
|
182
|
+
ret.add(realParameter);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName() === args[i].toString()) {
|
|
186
|
+
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
187
|
+
if (realParameter) {
|
|
188
|
+
const retRef = new Ref_1.ArkInstanceFieldRef(realParameter, dataFact.getFieldSignature());
|
|
189
|
+
ret.add(retRef);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
169
194
|
getExitToReturnFlowFunction(srcStmt, tgtStmt, callStmt) {
|
|
170
195
|
let checkerInstance = this;
|
|
171
196
|
return new class {
|
|
172
197
|
getDataFacts(dataFact) {
|
|
173
198
|
let ret = new Set();
|
|
174
|
-
if (dataFact
|
|
199
|
+
if (dataFact === checkerInstance.getZeroValue()) {
|
|
175
200
|
ret.add(checkerInstance.getZeroValue());
|
|
176
201
|
}
|
|
177
|
-
if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName()
|
|
202
|
+
if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName() === "this") {
|
|
178
203
|
// todo:this转base。
|
|
179
204
|
const expr = callStmt.getExprs()[0];
|
|
180
205
|
if (expr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
@@ -189,13 +214,13 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
189
214
|
let ass = callStmt;
|
|
190
215
|
let leftOp = ass.getLeftOp();
|
|
191
216
|
let retVal = srcStmt.getOp();
|
|
192
|
-
if (dataFact
|
|
217
|
+
if (dataFact === checkerInstance.getZeroValue()) {
|
|
193
218
|
ret.add(checkerInstance.getZeroValue());
|
|
194
219
|
if (checkerInstance.isUndefined(retVal)) {
|
|
195
220
|
ret.add(leftOp);
|
|
196
221
|
}
|
|
197
222
|
}
|
|
198
|
-
else if (retVal
|
|
223
|
+
else if (retVal === dataFact) {
|
|
199
224
|
ret.add(leftOp);
|
|
200
225
|
}
|
|
201
226
|
}
|
|
@@ -208,11 +233,11 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
208
233
|
return new class {
|
|
209
234
|
getDataFacts(dataFact) {
|
|
210
235
|
const ret = new Set();
|
|
211
|
-
if (checkerInstance.getZeroValue()
|
|
236
|
+
if (checkerInstance.getZeroValue() === dataFact) {
|
|
212
237
|
ret.add(checkerInstance.getZeroValue());
|
|
213
238
|
}
|
|
214
239
|
const defValue = srcStmt.getDef();
|
|
215
|
-
if (!(defValue && defValue
|
|
240
|
+
if (!(defValue && defValue === dataFact)) {
|
|
216
241
|
ret.add(dataFact);
|
|
217
242
|
}
|
|
218
243
|
return ret;
|
|
@@ -225,6 +250,21 @@ class UndefinedVariableChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
225
250
|
getZeroValue() {
|
|
226
251
|
return this.zeroValue;
|
|
227
252
|
}
|
|
253
|
+
factEqual(d1, d2) {
|
|
254
|
+
if (d1 instanceof Constant_1.Constant && d2 instanceof Constant_1.Constant) {
|
|
255
|
+
return d1 === d2;
|
|
256
|
+
}
|
|
257
|
+
else if (d1 instanceof Local_1.Local && d2 instanceof Local_1.Local) {
|
|
258
|
+
return (0, Util_1.LocalEqual)(d1, d2);
|
|
259
|
+
}
|
|
260
|
+
else if (d1 instanceof Ref_1.AbstractRef && d2 instanceof Ref_1.AbstractRef) {
|
|
261
|
+
return (0, Util_1.RefEqual)(d1, d2);
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
getOutcomes() {
|
|
266
|
+
return this.outcomes;
|
|
267
|
+
}
|
|
228
268
|
}
|
|
229
269
|
exports.UndefinedVariableChecker = UndefinedVariableChecker;
|
|
230
270
|
class UndefinedVariableSolver extends DataflowSolver_1.DataflowSolver {
|
|
@@ -233,3 +273,9 @@ class UndefinedVariableSolver extends DataflowSolver_1.DataflowSolver {
|
|
|
233
273
|
}
|
|
234
274
|
}
|
|
235
275
|
exports.UndefinedVariableSolver = UndefinedVariableSolver;
|
|
276
|
+
class Outcome {
|
|
277
|
+
constructor(v, s) {
|
|
278
|
+
this.value = v;
|
|
279
|
+
this.stmt = s;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ArkInvokeStmt } from "../base/Stmt";
|
|
2
2
|
import { ArkMethod } from "../model/ArkMethod";
|
|
3
3
|
import { Scene } from "../../Scene";
|
|
4
|
+
import { Local } from "../base/Local";
|
|
5
|
+
import { AbstractRef } from "../base/Ref";
|
|
4
6
|
export declare const INTERNAL_PARAMETER_SOURCE: string[];
|
|
5
7
|
export declare const INTERNAL_SINK_METHOD: string[];
|
|
6
|
-
export declare function Json2ArkMethod(str: string, scene: Scene): ArkMethod | null;
|
|
8
|
+
export declare function Json2ArkMethod(sdkName: string, str: string, scene: Scene): ArkMethod | null;
|
|
7
9
|
export declare function getRecallMethodInParam(stmt: ArkInvokeStmt): ArkMethod | null;
|
|
10
|
+
export declare function LocalEqual(local1: Local, local2: Local): boolean;
|
|
11
|
+
export declare function RefEqual(ref1: AbstractRef, ref2: AbstractRef): boolean;
|
|
8
12
|
//# sourceMappingURL=Util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/Util.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/Util.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,WAAW,EAA0C,MAAM,aAAa,CAAC;AAGlF,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAE7C,CAAA;AAED,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAMxC,CAAA;AAID,wBAAgB,cAAc,CAAC,OAAO,EAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAoF1F;AAGD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAW5E;AAGD,wBAAgB,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAQhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAOtE"}
|
|
@@ -14,27 +14,31 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getRecallMethodInParam = exports.Json2ArkMethod = exports.INTERNAL_SINK_METHOD = exports.INTERNAL_PARAMETER_SOURCE = void 0;
|
|
17
|
+
exports.RefEqual = exports.LocalEqual = exports.getRecallMethodInParam = exports.Json2ArkMethod = exports.INTERNAL_SINK_METHOD = exports.INTERNAL_PARAMETER_SOURCE = void 0;
|
|
18
18
|
const Type_1 = require("../base/Type");
|
|
19
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
20
|
+
const Ref_1 = require("../base/Ref");
|
|
19
21
|
exports.INTERNAL_PARAMETER_SOURCE = [
|
|
20
22
|
'@ohos.app.ability.Want.d.ts: Want'
|
|
21
23
|
];
|
|
22
24
|
exports.INTERNAL_SINK_METHOD = [
|
|
23
|
-
'console
|
|
24
|
-
'console
|
|
25
|
-
'console
|
|
26
|
-
'console
|
|
27
|
-
'console
|
|
25
|
+
'console.<@%unk/%unk: .log()>',
|
|
26
|
+
'console.<@%unk/%unk: .error()>',
|
|
27
|
+
'console.<@%unk/%unk: .info()>',
|
|
28
|
+
'console.<@%unk/%unk: .warn()>',
|
|
29
|
+
'console.<@%unk/%unk: .assert()>'
|
|
28
30
|
];
|
|
29
31
|
const filenamePrefix = '@etsSdk/api/';
|
|
30
|
-
function Json2ArkMethod(str, scene) {
|
|
32
|
+
function Json2ArkMethod(sdkName, str, scene) {
|
|
31
33
|
const mes = str.split(': ');
|
|
32
34
|
const fileName = filenamePrefix + mes[0] + ': ';
|
|
33
35
|
const otherMes = mes.slice(1).join(': ').split('.');
|
|
34
36
|
if (otherMes.length < 3) {
|
|
35
37
|
return null;
|
|
36
38
|
}
|
|
37
|
-
const namespaceName = otherMes[0]
|
|
39
|
+
const namespaceName = otherMes[0];
|
|
40
|
+
const className = otherMes[1];
|
|
41
|
+
const methodName = otherMes[2].split('(')[0];
|
|
38
42
|
let paramNames = [];
|
|
39
43
|
if (otherMes[2]) {
|
|
40
44
|
if (!otherMes[2].match(/\((.*?)\)/)) {
|
|
@@ -42,19 +46,18 @@ function Json2ArkMethod(str, scene) {
|
|
|
42
46
|
}
|
|
43
47
|
paramNames = otherMes[2].match(/\((.*?)\)/)[1].split(',').map((item) => item.replace(/\s/g, '')).filter((item) => item !== '');
|
|
44
48
|
}
|
|
45
|
-
const file = scene.
|
|
49
|
+
const file = scene.getFile(new ArkSignature_1.FileSignature(sdkName, fileName));
|
|
46
50
|
if (!file) {
|
|
47
|
-
// console.log("no file: " + fileName);
|
|
48
51
|
return null;
|
|
49
52
|
}
|
|
50
53
|
let arkClass = null;
|
|
51
|
-
if (namespaceName
|
|
52
|
-
if (className
|
|
54
|
+
if (namespaceName === "_") {
|
|
55
|
+
if (className === '_') {
|
|
53
56
|
arkClass = file.getDefaultClass();
|
|
54
57
|
}
|
|
55
58
|
else {
|
|
56
59
|
for (const clas of file.getClasses()) {
|
|
57
|
-
if (clas.getName()
|
|
60
|
+
if (clas.getName() === className) {
|
|
58
61
|
arkClass = clas;
|
|
59
62
|
break;
|
|
60
63
|
}
|
|
@@ -64,18 +67,18 @@ function Json2ArkMethod(str, scene) {
|
|
|
64
67
|
else {
|
|
65
68
|
let arkNamespace = null;
|
|
66
69
|
for (const ns of file.getNamespaces()) {
|
|
67
|
-
if (ns.getName()
|
|
70
|
+
if (ns.getName() === namespaceName) {
|
|
68
71
|
arkNamespace = ns;
|
|
69
72
|
break;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
if (arkNamespace) {
|
|
73
|
-
if (className
|
|
76
|
+
if (className === '_') {
|
|
74
77
|
arkClass = arkNamespace.getDefaultClass();
|
|
75
78
|
}
|
|
76
79
|
else {
|
|
77
80
|
for (const clas of arkNamespace.getClasses()) {
|
|
78
|
-
if (clas.getName()
|
|
81
|
+
if (clas.getName() === className) {
|
|
79
82
|
arkClass = clas;
|
|
80
83
|
break;
|
|
81
84
|
}
|
|
@@ -83,27 +86,25 @@ function Json2ArkMethod(str, scene) {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
else {
|
|
86
|
-
// console.log("no namespace: " + namespaceName);
|
|
87
89
|
return null;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
if (!arkClass) {
|
|
91
|
-
// console.log("no class: " + className);
|
|
92
93
|
return null;
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
96
|
let arkMethod = null;
|
|
96
97
|
for (const method of arkClass.getMethods()) {
|
|
97
|
-
if (method.getName()
|
|
98
|
+
if (method.getName() === methodName) {
|
|
98
99
|
arkMethod = method;
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
if (arkMethod && arkMethod.getParameters().length
|
|
103
|
+
if (arkMethod && arkMethod.getParameters().length === paramNames.length) {
|
|
103
104
|
let paramEqual = true;
|
|
104
105
|
for (let i = 0; i < arkMethod.getParameters().length; i++) {
|
|
105
106
|
const param = arkMethod.getParameters()[i];
|
|
106
|
-
if (param.getName() + ':' + param.getType().toString()
|
|
107
|
+
if (param.getName() + ':' + param.getType().toString() !== paramNames[i]) {
|
|
107
108
|
paramEqual = false;
|
|
108
109
|
break;
|
|
109
110
|
}
|
|
@@ -113,7 +114,6 @@ function Json2ArkMethod(str, scene) {
|
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
else {
|
|
116
|
-
// console.log("no method: " + methodName);
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -135,3 +135,24 @@ function getRecallMethodInParam(stmt) {
|
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
137
|
exports.getRecallMethodInParam = getRecallMethodInParam;
|
|
138
|
+
function LocalEqual(local1, local2) {
|
|
139
|
+
var _a, _b, _c, _d;
|
|
140
|
+
if (local1.getName() === 'this' && local2.getName() === 'this') {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
const method1 = (_b = (_a = local1.getDeclaringStmt()) === null || _a === void 0 ? void 0 : _a.getCfg()) === null || _b === void 0 ? void 0 : _b.getDeclaringMethod();
|
|
144
|
+
const method2 = (_d = (_c = local2.getDeclaringStmt()) === null || _c === void 0 ? void 0 : _c.getCfg()) === null || _d === void 0 ? void 0 : _d.getDeclaringMethod();
|
|
145
|
+
const nameEqual = local1.getName() === local2.getName();
|
|
146
|
+
return method1 === method2 && nameEqual;
|
|
147
|
+
}
|
|
148
|
+
exports.LocalEqual = LocalEqual;
|
|
149
|
+
function RefEqual(ref1, ref2) {
|
|
150
|
+
if (ref1 instanceof Ref_1.ArkStaticFieldRef && ref2 instanceof Ref_1.ArkStaticFieldRef) {
|
|
151
|
+
return ref1.getFieldSignature().toString() === ref2.getFieldSignature().toString();
|
|
152
|
+
}
|
|
153
|
+
else if (ref1 instanceof Ref_1.ArkInstanceFieldRef && ref2 instanceof Ref_1.ArkInstanceFieldRef) {
|
|
154
|
+
return LocalEqual(ref1.getBase(), ref2.getBase()) && ref1.getFieldSignature().toString() === ref2.getFieldSignature().toString();
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
exports.RefEqual = RefEqual;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Stmt } from '../base/Stmt';
|
|
2
|
+
import { ArkError } from '../common/ArkError';
|
|
2
3
|
/**
|
|
3
4
|
* @category core/graph
|
|
5
|
+
* A `BasicBlock` is composed of:
|
|
6
|
+
* - ID: a **number** that uniquely identify the basic block, initialized as -1.
|
|
7
|
+
* - Statements: an **array** of statements in the basic block.
|
|
8
|
+
* - 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.
|
|
9
|
+
* - Successors: an **array** of basic blocks after the current basic block. More accurately, the current block can reach these basic blocks through edges.
|
|
4
10
|
*/
|
|
5
11
|
export declare class BasicBlock {
|
|
6
12
|
private id;
|
|
@@ -10,11 +16,75 @@ export declare class BasicBlock {
|
|
|
10
16
|
constructor();
|
|
11
17
|
getId(): number;
|
|
12
18
|
setId(id: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns an array of the statements in a basic block.
|
|
21
|
+
* @returns An array of statements in a basic block.
|
|
22
|
+
*/
|
|
13
23
|
getStmts(): Stmt[];
|
|
14
24
|
addStmt(stmt: Stmt): void;
|
|
25
|
+
/**
|
|
26
|
+
* Adds the given stmt at the beginning of the basic block.
|
|
27
|
+
* @param stmt
|
|
28
|
+
*/
|
|
29
|
+
addHead(stmt: Stmt | Stmt[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Adds the given stmt at the end of the basic block.
|
|
32
|
+
* @param stmt
|
|
33
|
+
*/
|
|
34
|
+
addTail(stmt: Stmt | Stmt[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Inserts toInsert in the basic block after point.
|
|
37
|
+
* @param toInsert
|
|
38
|
+
* @param point
|
|
39
|
+
* @returns The number of successfully inserted statements
|
|
40
|
+
*/
|
|
41
|
+
insertAfter(toInsert: Stmt | Stmt[], point: Stmt): number;
|
|
42
|
+
/**
|
|
43
|
+
* Inserts toInsert in the basic block befor point.
|
|
44
|
+
* @param toInsert
|
|
45
|
+
* @param point
|
|
46
|
+
* @returns The number of successfully inserted statements
|
|
47
|
+
*/
|
|
48
|
+
insertBefore(toInsert: Stmt | Stmt[], point: Stmt): number;
|
|
49
|
+
/**
|
|
50
|
+
* Removes the given stmt from this basic block.
|
|
51
|
+
* @param stmt
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
remove(stmt: Stmt): void;
|
|
55
|
+
/**
|
|
56
|
+
* Removes the first stmt from this basic block.
|
|
57
|
+
*/
|
|
58
|
+
removeHead(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Removes the last stmt from this basic block.
|
|
61
|
+
*/
|
|
62
|
+
removeTail(): void;
|
|
15
63
|
getHead(): Stmt | null;
|
|
16
64
|
getTail(): Stmt | null;
|
|
65
|
+
/**
|
|
66
|
+
* Returns successors of the current basic block, whose types are also basic blocks (i.e.{@link BasicBlock}).
|
|
67
|
+
* @returns Successors of the current basic block.
|
|
68
|
+
* @example
|
|
69
|
+
* 1. get block successors.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const body = arkMethod.getBody();
|
|
73
|
+
const blocks = [...body.getCfg().getBlocks()]
|
|
74
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
75
|
+
const block = blocks[i]
|
|
76
|
+
...
|
|
77
|
+
for (const next of block.getSuccessors()) {
|
|
78
|
+
...
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
*/
|
|
17
83
|
getSuccessors(): BasicBlock[];
|
|
84
|
+
/**
|
|
85
|
+
* Returns predecessors of the current basic block, whose types are also basic blocks.
|
|
86
|
+
* @returns An array of basic blocks.
|
|
87
|
+
*/
|
|
18
88
|
getPredecessors(): BasicBlock[];
|
|
19
89
|
addPredecessorBlock(block: BasicBlock): void;
|
|
20
90
|
setPredecessorBlock(idx: number, block: BasicBlock): boolean;
|
|
@@ -22,5 +92,7 @@ export declare class BasicBlock {
|
|
|
22
92
|
addStmtToFirst(stmt: Stmt): void;
|
|
23
93
|
addSuccessorBlock(block: BasicBlock): void;
|
|
24
94
|
toString(): string;
|
|
95
|
+
validate(): ArkError;
|
|
96
|
+
private insertPos;
|
|
25
97
|
}
|
|
26
98
|
//# sourceMappingURL=BasicBlock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicBlock.d.ts","sourceRoot":"","sources":["../../../src/core/graph/BasicBlock.ts"],"names":[],"mappings":"AAeA,OAAO,
|
|
1
|
+
{"version":3,"file":"BasicBlock.d.ts","sourceRoot":"","sources":["../../../src/core/graph/BasicBlock.ts"],"names":[],"mappings":"AAeA,OAAO,EAA8D,IAAI,EAAE,MAAM,cAAc,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAgB,MAAM,oBAAoB,CAAC;AAI5D;;;;;;;GAOG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,EAAE,CAAc;IACxB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,eAAe,CAAoB;;IAIpC,KAAK,IAAI,MAAM;IAIf,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI9B;;;OAGG;IACI,QAAQ,IAAI,IAAI,EAAE;IAIlB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIhC;;;OAGG;IACI,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAQzC;;;OAGG;IACI,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAQzC;;;;;OAKG;IACI,WAAW,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM;IAQhE;;;;;OAKG;IACI,YAAY,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM;IAQjE;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAQ/B;;OAEG;IACI,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACI,UAAU,IAAI,IAAI;IAIlB,OAAO,IAAI,IAAI,GAAG,IAAI;IAOtB,OAAO,IAAI,IAAI,GAAG,IAAI;IAQ7B;;;;;;;;;;;;;;;;;OAiBG;IACI,aAAa,IAAI,UAAU,EAAE;IAIpC;;;OAGG;IACI,eAAe,IAAI,UAAU,EAAE;IAI/B,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAI5C,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO;IAQ5D,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO;IAS1D,cAAc,CAAC,IAAI,EAAE,IAAI;IAKzB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAI1C,QAAQ,IAAI,MAAM;IAQlB,QAAQ,IAAI,QAAQ;IA4B3B,OAAO,CAAC,SAAS;CAQpB"}
|