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
|
@@ -61,27 +61,28 @@ class TypeInference {
|
|
|
61
61
|
const arkClass = arkField.getDeclaringArkClass();
|
|
62
62
|
const stmts = arkField.getInitializer();
|
|
63
63
|
let rightType;
|
|
64
|
-
let fieldRef
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
}
|
|
71
|
-
const lastStmt = stmts[stmts.length - 1];
|
|
72
|
-
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
73
|
-
rightType = lastStmt.getRightOp().getType();
|
|
74
|
-
if (lastStmt.getLeftOp() instanceof Ref_1.AbstractFieldRef) {
|
|
75
|
-
fieldRef = lastStmt.getLeftOp();
|
|
76
|
-
}
|
|
64
|
+
let fieldRef;
|
|
65
|
+
const method = arkClass.getMethodWithName(Const_1.INSTANCE_INIT_METHOD_NAME);
|
|
66
|
+
for (const stmt of stmts) {
|
|
67
|
+
if (method) {
|
|
68
|
+
this.resolveExprsInStmt(stmt, method);
|
|
69
|
+
this.resolveFieldRefsInStmt(stmt, method);
|
|
77
70
|
}
|
|
71
|
+
this.resolveArkAssignStmt(stmt, arkClass);
|
|
78
72
|
}
|
|
79
73
|
const beforeType = arkField.getType();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fieldType = new Type_1.ClassType(arkClass.getSignature());
|
|
74
|
+
if (!this.isUnclearType(beforeType)) {
|
|
75
|
+
return;
|
|
83
76
|
}
|
|
84
|
-
|
|
77
|
+
const lastStmt = stmts[stmts.length - 1];
|
|
78
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
79
|
+
rightType = lastStmt.getRightOp().getType();
|
|
80
|
+
if (lastStmt.getLeftOp() instanceof Ref_1.AbstractFieldRef) {
|
|
81
|
+
fieldRef = lastStmt.getLeftOp();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let fieldType;
|
|
85
|
+
if (beforeType) {
|
|
85
86
|
fieldType = this.inferUnclearedType(beforeType, arkClass, rightType);
|
|
86
87
|
}
|
|
87
88
|
if (fieldType) {
|
|
@@ -96,7 +97,7 @@ class TypeInference {
|
|
|
96
97
|
static inferUnclearedType(leftOpType, declaringArkClass, rightType) {
|
|
97
98
|
let type;
|
|
98
99
|
if (leftOpType instanceof Type_1.UnclearReferenceType) {
|
|
99
|
-
type = this.
|
|
100
|
+
type = this.inferUnclearRefType(leftOpType, declaringArkClass);
|
|
100
101
|
}
|
|
101
102
|
else if (leftOpType instanceof Type_1.ClassType
|
|
102
103
|
&& leftOpType.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
@@ -116,10 +117,10 @@ class TypeInference {
|
|
|
116
117
|
else {
|
|
117
118
|
newType = optionType;
|
|
118
119
|
}
|
|
119
|
-
if (newType
|
|
120
|
+
if (newType) {
|
|
120
121
|
types[i] = newType;
|
|
121
122
|
}
|
|
122
|
-
if (rightType && newType && newType === rightType) {
|
|
123
|
+
if (rightType && newType && newType.constructor === rightType.constructor) {
|
|
123
124
|
leftOpType.setCurrType(rightType);
|
|
124
125
|
type = leftOpType;
|
|
125
126
|
}
|
|
@@ -145,24 +146,42 @@ class TypeInference {
|
|
|
145
146
|
return type;
|
|
146
147
|
}
|
|
147
148
|
static inferTypeInMethod(arkMethod) {
|
|
148
|
-
var _a;
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
151
|
+
this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
|
|
152
|
+
const signatures = [];
|
|
153
|
+
(_a = arkMethod.getDeclareSignatures()) === null || _a === void 0 ? void 0 : _a.forEach(m => signatures.push(m));
|
|
154
|
+
const impl = arkMethod.getImplementationSignature();
|
|
155
|
+
if (impl) {
|
|
156
|
+
signatures.push(impl);
|
|
157
|
+
}
|
|
158
|
+
signatures.forEach(s => {
|
|
159
|
+
s.getMethodSubSignature().getParameters().forEach(p => {
|
|
160
|
+
const type = TypeInference.inferUnclearedType(p.getType(), arkClass);
|
|
161
|
+
if (type) {
|
|
162
|
+
p.setType(type);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const type = TypeInference.inferUnclearedType(s.getMethodSubSignature().getReturnType(), arkClass);
|
|
166
|
+
if (type) {
|
|
167
|
+
s.getMethodSubSignature().setReturnType(type);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
149
170
|
const body = arkMethod.getBody();
|
|
150
171
|
if (!body) {
|
|
151
172
|
logger.warn('empty body');
|
|
152
173
|
return;
|
|
153
174
|
}
|
|
154
|
-
|
|
155
|
-
(_a = body.getAliasTypeMap()) === null || _a === void 0 ? void 0 : _a.forEach((value) => this.inferUnclearedType(value[0], arkClass));
|
|
175
|
+
(_b = body.getAliasTypeMap()) === null || _b === void 0 ? void 0 : _b.forEach((value) => this.inferUnclearedType(value[0], arkClass));
|
|
156
176
|
this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
|
|
157
177
|
const cfg = body.getCfg();
|
|
158
178
|
for (const block of cfg.getBlocks()) {
|
|
159
179
|
for (const stmt of block.getStmts()) {
|
|
160
|
-
this.resolveExprsInStmt(stmt,
|
|
161
|
-
this.resolveFieldRefsInStmt(stmt,
|
|
180
|
+
this.resolveExprsInStmt(stmt, arkMethod);
|
|
181
|
+
this.resolveFieldRefsInStmt(stmt, arkMethod);
|
|
162
182
|
this.resolveArkAssignStmt(stmt, arkClass);
|
|
163
183
|
}
|
|
164
184
|
}
|
|
165
|
-
this.inferMethodReturnType(arkMethod);
|
|
166
185
|
}
|
|
167
186
|
/**
|
|
168
187
|
* @Deprecated
|
|
@@ -185,10 +204,10 @@ class TypeInference {
|
|
|
185
204
|
* infer type for Exprs in stmt which invoke method.
|
|
186
205
|
* such as ArkInstanceInvokeExpr ArkStaticInvokeExpr ArkNewExpr
|
|
187
206
|
*/
|
|
188
|
-
static resolveExprsInStmt(stmt,
|
|
207
|
+
static resolveExprsInStmt(stmt, arkMethod) {
|
|
189
208
|
const exprs = stmt.getExprs();
|
|
190
209
|
for (const expr of exprs) {
|
|
191
|
-
const newExpr = expr.inferType(
|
|
210
|
+
const newExpr = expr.inferType(arkMethod);
|
|
192
211
|
if (stmt.containsInvokeExpr() && expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
193
212
|
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
194
213
|
stmt.setRightOp(newExpr);
|
|
@@ -202,57 +221,50 @@ class TypeInference {
|
|
|
202
221
|
/**
|
|
203
222
|
* infer type for fieldRefs in stmt.
|
|
204
223
|
*/
|
|
205
|
-
static resolveFieldRefsInStmt(stmt,
|
|
206
|
-
var _a;
|
|
224
|
+
static resolveFieldRefsInStmt(stmt, arkMethod) {
|
|
207
225
|
for (const use of stmt.getUses()) {
|
|
208
226
|
if (use instanceof Ref_1.AbstractRef) {
|
|
209
|
-
|
|
210
|
-
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
211
|
-
if (stmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
212
|
-
stmt.setRightOp(fieldRef);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
stmt.replaceUse(use, fieldRef);
|
|
216
|
-
stmt.setRightOp(stmt.getRightOp());
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
220
|
-
const index = fieldRef.getIndex();
|
|
221
|
-
if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
|
|
222
|
-
const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(index.getValue());
|
|
223
|
-
if (local) {
|
|
224
|
-
fieldRef.setIndex(local);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
stmt.replaceUse(use, fieldRef);
|
|
228
|
-
stmt.setRightOp(stmt.getRightOp());
|
|
229
|
-
}
|
|
227
|
+
this.processRef(use, stmt, arkMethod);
|
|
230
228
|
}
|
|
231
229
|
}
|
|
232
230
|
const stmtDef = stmt.getDef();
|
|
233
231
|
if (stmtDef && stmtDef instanceof Ref_1.AbstractRef) {
|
|
234
|
-
const fieldRef = stmtDef.inferType(
|
|
232
|
+
const fieldRef = stmtDef.inferType(arkMethod);
|
|
235
233
|
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
236
234
|
stmt.setLeftOp(fieldRef);
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
|
-
static
|
|
238
|
+
static processRef(use, stmt, arkMethod) {
|
|
241
239
|
var _a;
|
|
240
|
+
const fieldRef = use.inferType(arkMethod);
|
|
241
|
+
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
242
|
+
if (stmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
243
|
+
stmt.setRightOp(fieldRef);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
stmt.replaceUse(use, fieldRef);
|
|
247
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
251
|
+
const index = fieldRef.getIndex();
|
|
252
|
+
if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
|
|
253
|
+
const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(index.getValue());
|
|
254
|
+
if (local) {
|
|
255
|
+
fieldRef.setIndex(local);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
stmt.replaceUse(use, fieldRef);
|
|
259
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
static parseArkExport2Type(arkExport) {
|
|
242
263
|
if (!arkExport) {
|
|
243
264
|
return null;
|
|
244
265
|
}
|
|
245
266
|
if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
246
|
-
return new Type_1.ClassType(arkExport.getSignature(),
|
|
247
|
-
let defaultType = x.getDefaultType();
|
|
248
|
-
if (defaultType instanceof Type_1.UnclearReferenceType) {
|
|
249
|
-
const newType = TypeInference.inferUnclearReferenceType(defaultType.getName(), arkExport);
|
|
250
|
-
if (newType) {
|
|
251
|
-
defaultType = newType;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return defaultType !== null && defaultType !== void 0 ? defaultType : Type_1.UndefinedType.getInstance();
|
|
255
|
-
}));
|
|
267
|
+
return new Type_1.ClassType(arkExport.getSignature(), arkExport.getGenericsTypes());
|
|
256
268
|
}
|
|
257
269
|
else if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
|
|
258
270
|
let namespaceType = new Type_1.AnnotationNamespaceType(arkExport.getName());
|
|
@@ -298,28 +310,44 @@ class TypeInference {
|
|
|
298
310
|
}
|
|
299
311
|
}
|
|
300
312
|
const leftOp = stmt.getLeftOp();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
else if (this.isUnclearType(leftOpType) && !this.isUnclearType(stmt.getRightOp().getType())) {
|
|
311
|
-
leftOp.setType(stmt.getRightOp().getType());
|
|
313
|
+
let type = leftOp.getType();
|
|
314
|
+
if (this.isUnclearType(type)) {
|
|
315
|
+
type = this.inferUnclearedType(type, arkClass, rightOp.getType());
|
|
316
|
+
}
|
|
317
|
+
if (type instanceof Type_1.UnionType &&
|
|
318
|
+
!this.isUnclearType(rightOp.getType()) && !(leftOp instanceof Ref_1.ArkArrayRef)) {
|
|
319
|
+
const cur = type.getTypes().find(t => rightOp.getType().constructor === t.constructor);
|
|
320
|
+
if (cur) {
|
|
321
|
+
type.setCurrType(cur);
|
|
312
322
|
}
|
|
313
323
|
}
|
|
324
|
+
if (this.isUnclearType(type) && !this.isUnclearType(rightOp.getType())) {
|
|
325
|
+
type = rightOp.getType();
|
|
326
|
+
}
|
|
327
|
+
if (type && leftOp instanceof Local_1.Local) {
|
|
328
|
+
leftOp.setType(type);
|
|
329
|
+
}
|
|
330
|
+
else if (type && leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
331
|
+
leftOp.getFieldSignature().setType(type);
|
|
332
|
+
}
|
|
314
333
|
}
|
|
315
334
|
static isUnclearType(type) {
|
|
316
335
|
if (!type || type instanceof Type_1.UnknownType || type instanceof Type_1.UnclearReferenceType) {
|
|
317
336
|
return true;
|
|
318
337
|
}
|
|
319
338
|
else if (type instanceof Type_1.ClassType
|
|
320
|
-
&& type.getClassSignature().getDeclaringFileSignature().getFileName() ===
|
|
339
|
+
&& type.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
321
340
|
return true;
|
|
322
341
|
}
|
|
342
|
+
else if (type instanceof Type_1.UnionType) {
|
|
343
|
+
return !!type.getTypes().find(t => t instanceof Type_1.UnclearReferenceType);
|
|
344
|
+
}
|
|
345
|
+
else if (type instanceof Type_1.ArrayType) {
|
|
346
|
+
return (type.getBaseType() instanceof Type_1.UnclearReferenceType);
|
|
347
|
+
}
|
|
348
|
+
else if (type instanceof Type_1.AliasType) {
|
|
349
|
+
return (type.getOriginalType() instanceof Type_1.UnclearReferenceType);
|
|
350
|
+
}
|
|
323
351
|
return false;
|
|
324
352
|
}
|
|
325
353
|
static inferSimpleTypeInStmt(stmt) {
|
|
@@ -353,40 +381,58 @@ class TypeInference {
|
|
|
353
381
|
return Type_1.VoidType.getInstance();
|
|
354
382
|
case 'never':
|
|
355
383
|
return Type_1.NeverType.getInstance();
|
|
356
|
-
case 'RegularExpression':
|
|
384
|
+
case 'RegularExpression': {
|
|
357
385
|
const classSignature = Builtin_1.Builtin.REGEXP_CLASS_SIGNATURE;
|
|
358
386
|
return new Type_1.ClassType(classSignature);
|
|
387
|
+
}
|
|
359
388
|
default:
|
|
360
389
|
return new Type_1.UnclearReferenceType(typeStr);
|
|
361
390
|
}
|
|
362
391
|
}
|
|
363
|
-
static inferValueType(value,
|
|
392
|
+
static inferValueType(value, arkMethod) {
|
|
364
393
|
if (value instanceof Ref_1.ArkInstanceFieldRef || value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
365
|
-
this.inferValueType(value.getBase(),
|
|
394
|
+
this.inferValueType(value.getBase(), arkMethod);
|
|
366
395
|
}
|
|
367
396
|
if (value instanceof Ref_1.AbstractRef || value instanceof Expr_1.AbstractExpr || value instanceof Local_1.Local) {
|
|
368
|
-
value.inferType(
|
|
397
|
+
value.inferType(arkMethod);
|
|
369
398
|
}
|
|
370
399
|
return value.getType();
|
|
371
400
|
}
|
|
372
401
|
static inferMethodReturnType(method) {
|
|
373
|
-
const oldMethodSignature = method.getSignature();
|
|
374
|
-
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
375
402
|
if (method.getName() === TSConst_1.CONSTRUCTOR_NAME) {
|
|
403
|
+
const oldMethodSignature = method.getSignature();
|
|
404
|
+
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
376
405
|
const newReturnType = new Type_1.ClassType(method.getDeclaringArkClass().getSignature());
|
|
377
406
|
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldMethodSubSignature.getMethodName(), oldMethodSubSignature.getParameters(), newReturnType, oldMethodSubSignature.isStatic());
|
|
378
|
-
method.
|
|
407
|
+
method.setImplementationSignature(new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), newMethodSubSignature));
|
|
379
408
|
return;
|
|
380
409
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
410
|
+
let implSignature = method.getImplementationSignature();
|
|
411
|
+
if (implSignature !== null) {
|
|
412
|
+
const newSignature = this.inferSignatureReturnType(implSignature, method.getDeclaringArkClass());
|
|
413
|
+
if (newSignature !== null) {
|
|
414
|
+
method.setImplementationSignature(newSignature);
|
|
415
|
+
}
|
|
385
416
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
417
|
+
let declareSignatures = method.getDeclareSignatures();
|
|
418
|
+
declareSignatures === null || declareSignatures === void 0 ? void 0 : declareSignatures.forEach((signature, index) => {
|
|
419
|
+
const newSignature = this.inferSignatureReturnType(signature, method.getDeclaringArkClass());
|
|
420
|
+
if (newSignature !== null) {
|
|
421
|
+
method.setDeclareSignatureWithIndex(newSignature, index);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
static inferSignatureReturnType(oldSignature, declaringClass) {
|
|
426
|
+
const currReturnType = oldSignature.getType();
|
|
427
|
+
if (currReturnType instanceof Type_1.UnclearReferenceType) {
|
|
428
|
+
const newReturnType = this.inferUnclearReferenceType(currReturnType.getName(), declaringClass);
|
|
429
|
+
if (newReturnType !== null) {
|
|
430
|
+
const oldSubSignature = oldSignature.getMethodSubSignature();
|
|
431
|
+
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldSubSignature.getMethodName(), oldSubSignature.getParameters(), newReturnType, oldSubSignature.isStatic());
|
|
432
|
+
return new ArkSignature_1.MethodSignature(oldSignature.getDeclaringClassSignature(), newMethodSubSignature);
|
|
433
|
+
}
|
|
389
434
|
}
|
|
435
|
+
return null;
|
|
390
436
|
}
|
|
391
437
|
static inferGenericType(types, arkClass) {
|
|
392
438
|
types === null || types === void 0 ? void 0 : types.forEach(type => {
|
|
@@ -406,6 +452,27 @@ class TypeInference {
|
|
|
406
452
|
}
|
|
407
453
|
});
|
|
408
454
|
}
|
|
455
|
+
static inferUnclearRefType(urType, arkClass) {
|
|
456
|
+
var _a;
|
|
457
|
+
const realTypes = urType.getGenericTypes();
|
|
458
|
+
this.inferRealGenericTypes(realTypes, arkClass);
|
|
459
|
+
if (urType.getName() === Builtin_1.Builtin.ARRAY) {
|
|
460
|
+
return new Type_1.ArrayType((_a = realTypes[0]) !== null && _a !== void 0 ? _a : Type_1.AnyType, 1);
|
|
461
|
+
}
|
|
462
|
+
const type = this.inferUnclearReferenceType(urType.getName(), arkClass);
|
|
463
|
+
if (realTypes.length === 0) {
|
|
464
|
+
return type;
|
|
465
|
+
}
|
|
466
|
+
if (type instanceof Type_1.ClassType) {
|
|
467
|
+
return new Type_1.ClassType(type.getClassSignature(), realTypes);
|
|
468
|
+
}
|
|
469
|
+
else if (type instanceof Type_1.FunctionType) {
|
|
470
|
+
return new Type_1.FunctionType(type.getMethodSignature(), realTypes);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
return new Type_1.UnclearReferenceType(urType.getName(), realTypes);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
409
476
|
static inferUnclearReferenceType(refName, arkClass) {
|
|
410
477
|
var _a;
|
|
411
478
|
if (!refName) {
|
|
@@ -416,7 +483,7 @@ class TypeInference {
|
|
|
416
483
|
let type = null;
|
|
417
484
|
for (let i = 0; i < singleNames.length; i++) {
|
|
418
485
|
let genericName = ValueUtil_1.EMPTY_STRING;
|
|
419
|
-
const name = singleNames[i].replace(/<(\w+)>/,
|
|
486
|
+
const name = singleNames[i].replace(/<(\w+)>/, (match, group1) => {
|
|
420
487
|
genericName = group1;
|
|
421
488
|
return ValueUtil_1.EMPTY_STRING;
|
|
422
489
|
});
|
|
@@ -464,6 +531,10 @@ class TypeInference {
|
|
|
464
531
|
}
|
|
465
532
|
return propertyAndType;
|
|
466
533
|
}
|
|
534
|
+
if (arkClass.isAnonymousClass()) {
|
|
535
|
+
const fieldType = this.inferUnclearReferenceType(fieldName, arkClass);
|
|
536
|
+
return fieldType ? [null, fieldType] : null;
|
|
537
|
+
}
|
|
467
538
|
const property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arkClass);
|
|
468
539
|
let propertyType = null;
|
|
469
540
|
if (property instanceof ArkField_1.ArkField) {
|
|
@@ -520,5 +591,66 @@ class TypeInference {
|
|
|
520
591
|
}
|
|
521
592
|
}
|
|
522
593
|
}
|
|
594
|
+
static inferAnonymousClass(anon, declaredSignature, set = new Set()) {
|
|
595
|
+
var _a;
|
|
596
|
+
if (!anon) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const key = anon.getSignature().toString();
|
|
600
|
+
if (set.has(key)) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
set.add(key);
|
|
605
|
+
}
|
|
606
|
+
const scene = anon.getDeclaringArkFile().getScene();
|
|
607
|
+
const declaredClass = scene.getClass(declaredSignature);
|
|
608
|
+
if (!declaredClass) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
for (const anonField of anon.getFields()) {
|
|
612
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInClass(anon.getName(), declaredClass);
|
|
613
|
+
if (property instanceof ArkField_1.ArkField) {
|
|
614
|
+
TypeInference.assignAnonField(property, anonField, scene, set);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
for (const anonMethod of anon.getMethods()) {
|
|
618
|
+
const methodSignature = (_a = declaredClass.getMethodWithName(anonMethod.getName())) === null || _a === void 0 ? void 0 : _a.matchMethodSignature(anonMethod.getSubSignature().getParameterTypes());
|
|
619
|
+
if (methodSignature) {
|
|
620
|
+
anonMethod.setImplementationSignature(methodSignature);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
static assignAnonField(property, anonField, scene, set) {
|
|
625
|
+
function deepInfer(anonType, declaredSignature) {
|
|
626
|
+
if (anonType instanceof Type_1.ClassType && anonType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)) {
|
|
627
|
+
TypeInference.inferAnonymousClass(scene.getClass(anonType.getClassSignature()), declaredSignature, set);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const type = property.getSignature().getType();
|
|
631
|
+
const lastStmt = anonField.getInitializer().at(-1);
|
|
632
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
633
|
+
const rightType = lastStmt.getRightOp().getType();
|
|
634
|
+
if (type instanceof Type_1.ClassType) {
|
|
635
|
+
deepInfer(rightType, type.getClassSignature());
|
|
636
|
+
}
|
|
637
|
+
else if (type instanceof Type_1.ArrayType && type.getBaseType() instanceof Type_1.ClassType &&
|
|
638
|
+
rightType instanceof Type_1.ArrayType) {
|
|
639
|
+
const baseType = rightType.getBaseType();
|
|
640
|
+
const classSignature = type.getBaseType().getClassSignature();
|
|
641
|
+
if (baseType instanceof Type_1.UnionType) {
|
|
642
|
+
baseType.getTypes().forEach(t => deepInfer(t, classSignature));
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
deepInfer(rightType, classSignature);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const leftOp = lastStmt.getLeftOp();
|
|
649
|
+
if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
650
|
+
leftOp.setFieldSignature(property.getSignature());
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
anonField.setSignature(property.getSignature());
|
|
654
|
+
}
|
|
523
655
|
}
|
|
524
656
|
exports.TypeInference = TypeInference;
|
|
@@ -2,10 +2,6 @@ import { Constant } from '../base/Constant';
|
|
|
2
2
|
export declare const EMPTY_STRING = "";
|
|
3
3
|
export declare class ValueUtil {
|
|
4
4
|
private static readonly NumberConstantCache;
|
|
5
|
-
private static readonly UndefinedConstant;
|
|
6
|
-
private static readonly NullConstant;
|
|
7
|
-
private static readonly TrueConstant;
|
|
8
|
-
private static readonly FalseConstant;
|
|
9
5
|
private static readonly EMPTY_STRING_CONSTANT;
|
|
10
6
|
static getOrCreateNumberConst(n: number): Constant;
|
|
11
7
|
static createStringConst(str: string): Constant;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueUtil.d.ts","sourceRoot":"","sources":["../../../src/core/common/ValueUtil.ts"],"names":[],"mappings":"AAeA,OAAO,
|
|
1
|
+
{"version":3,"file":"ValueUtil.d.ts","sourceRoot":"","sources":["../../../src/core/common/ValueUtil.ts"],"names":[],"mappings":"AAeA,OAAO,EAEH,QAAQ,EAKX,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAoC;IAC/E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAoC;WAEnE,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;WAS3C,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAOxC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAQlC,iBAAiB,IAAI,QAAQ;WAI7B,eAAe,IAAI,QAAQ;WAI3B,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;CAG7D"}
|
|
@@ -16,56 +16,39 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ValueUtil = exports.EMPTY_STRING = void 0;
|
|
18
18
|
const Constant_1 = require("../base/Constant");
|
|
19
|
-
const Type_1 = require("../base/Type");
|
|
20
19
|
exports.EMPTY_STRING = '';
|
|
21
20
|
class ValueUtil {
|
|
22
21
|
static getOrCreateNumberConst(n) {
|
|
23
22
|
let constant = this.NumberConstantCache.get(n);
|
|
24
|
-
if (constant
|
|
25
|
-
constant = new Constant_1.
|
|
23
|
+
if (constant === undefined) {
|
|
24
|
+
constant = new Constant_1.NumberConstant(n);
|
|
26
25
|
this.NumberConstantCache.set(n, constant);
|
|
27
26
|
}
|
|
28
27
|
return constant;
|
|
29
28
|
}
|
|
30
29
|
static createStringConst(str) {
|
|
31
|
-
if (str
|
|
30
|
+
if (str === exports.EMPTY_STRING) {
|
|
32
31
|
return this.EMPTY_STRING_CONSTANT;
|
|
33
32
|
}
|
|
34
|
-
return new Constant_1.
|
|
33
|
+
return new Constant_1.StringConstant(str);
|
|
35
34
|
}
|
|
36
35
|
static createConst(str) {
|
|
37
36
|
const n = Number(str);
|
|
38
37
|
if (!isNaN(n)) {
|
|
39
38
|
return this.getOrCreateNumberConst(n);
|
|
40
39
|
}
|
|
41
|
-
return new Constant_1.
|
|
40
|
+
return new Constant_1.StringConstant(str);
|
|
42
41
|
}
|
|
43
42
|
static getUndefinedConst() {
|
|
44
|
-
return
|
|
43
|
+
return Constant_1.UndefinedConstant.getInstance();
|
|
45
44
|
}
|
|
46
45
|
static getNullConstant() {
|
|
47
|
-
return
|
|
46
|
+
return Constant_1.NullConstant.getInstance();
|
|
48
47
|
}
|
|
49
48
|
static getBooleanConstant(value) {
|
|
50
|
-
return
|
|
49
|
+
return Constant_1.BooleanConstant.getInstance(value);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
exports.ValueUtil = ValueUtil;
|
|
54
|
-
ValueUtil.NumberConstantCache = new Map(
|
|
55
|
-
|
|
56
|
-
[1, new Constant_1.Constant('1', Type_1.NumberType.getInstance())],
|
|
57
|
-
[2, new Constant_1.Constant('2', Type_1.NumberType.getInstance())],
|
|
58
|
-
[3, new Constant_1.Constant('3', Type_1.NumberType.getInstance())],
|
|
59
|
-
[4, new Constant_1.Constant('4', Type_1.NumberType.getInstance())],
|
|
60
|
-
[5, new Constant_1.Constant('5', Type_1.NumberType.getInstance())],
|
|
61
|
-
[6, new Constant_1.Constant('6', Type_1.NumberType.getInstance())],
|
|
62
|
-
[7, new Constant_1.Constant('7', Type_1.NumberType.getInstance())],
|
|
63
|
-
[8, new Constant_1.Constant('8', Type_1.NumberType.getInstance())],
|
|
64
|
-
[9, new Constant_1.Constant('9', Type_1.NumberType.getInstance())],
|
|
65
|
-
[10, new Constant_1.Constant('10', Type_1.NumberType.getInstance())],
|
|
66
|
-
]);
|
|
67
|
-
ValueUtil.UndefinedConstant = new Constant_1.Constant('undefined', Type_1.UndefinedType.getInstance());
|
|
68
|
-
ValueUtil.NullConstant = new Constant_1.Constant('null', Type_1.NullType.getInstance());
|
|
69
|
-
ValueUtil.TrueConstant = new Constant_1.Constant('true', Type_1.BooleanType.getInstance());
|
|
70
|
-
ValueUtil.FalseConstant = new Constant_1.Constant('false', Type_1.BooleanType.getInstance());
|
|
71
|
-
ValueUtil.EMPTY_STRING_CONSTANT = new Constant_1.Constant(exports.EMPTY_STRING, Type_1.StringType.getInstance());
|
|
53
|
+
ValueUtil.NumberConstantCache = new Map();
|
|
54
|
+
ValueUtil.EMPTY_STRING_CONSTANT = new Constant_1.StringConstant(exports.EMPTY_STRING);
|
|
@@ -176,7 +176,7 @@ class VisibleValue {
|
|
|
176
176
|
const fields = cls.getFields();
|
|
177
177
|
const classSignature = cls.getSignature();
|
|
178
178
|
for (const field of fields) {
|
|
179
|
-
if (field.
|
|
179
|
+
if (field.isStatic()) {
|
|
180
180
|
const staticFieldRef = new Ref_1.ArkStaticFieldRef(field.getSignature());
|
|
181
181
|
values.push(staticFieldRef);
|
|
182
182
|
}
|
|
@@ -14,6 +14,7 @@ export declare abstract class DataflowProblem<D> {
|
|
|
14
14
|
abstract createZeroValue(): D;
|
|
15
15
|
abstract getEntryPoint(): Stmt;
|
|
16
16
|
abstract getEntryMethod(): ArkMethod;
|
|
17
|
+
abstract factEqual(d1: D, d2: D): boolean;
|
|
17
18
|
}
|
|
18
19
|
export interface FlowFunction<D> {
|
|
19
20
|
getDataFacts(d: D): Set<D>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataflowProblem.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/DataflowProblem.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,8BAAsB,eAAe,CAAC,CAAC;IAG5B,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;IAchD;;;;OAIG;IAWH,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAE5E,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,SAAS,GAAI,YAAY,CAAC,CAAC,CAAC;IAE9E,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAEjG,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAElF,QAAQ,CAAC,eAAe,IAAK,CAAC;IAE9B,QAAQ,CAAC,aAAa,IAAK,IAAI;IAE/B,QAAQ,CAAC,cAAc,IAAK,SAAS;
|
|
1
|
+
{"version":3,"file":"DataflowProblem.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/DataflowProblem.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,8BAAsB,eAAe,CAAC,CAAC;IAG5B,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;IAchD;;;;OAIG;IAWH,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAE5E,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,SAAS,GAAI,YAAY,CAAC,CAAC,CAAC;IAE9E,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAEjG,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAElF,QAAQ,CAAC,eAAe,IAAK,CAAC;IAE9B,QAAQ,CAAC,aAAa,IAAK,IAAI;IAE/B,QAAQ,CAAC,cAAc,IAAK,SAAS;IAErC,QAAQ,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO;CAC5C;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,YAAY,CAAC,CAAC,EAAC,CAAC,GAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CAC9B"}
|
|
@@ -19,14 +19,14 @@ const Edge_1 = require("./Edge");
|
|
|
19
19
|
class DataflowProblem {
|
|
20
20
|
transferEdge(srcStmt, tgtStmt) {
|
|
21
21
|
let edgeKind = Edge_1.Edge.getKind(srcStmt, tgtStmt);
|
|
22
|
-
if (0
|
|
22
|
+
if (0 === edgeKind) {
|
|
23
23
|
//normal
|
|
24
24
|
}
|
|
25
|
-
else if (1
|
|
25
|
+
else if (1 === edgeKind) { //Call-Edge
|
|
26
26
|
}
|
|
27
|
-
else if (2
|
|
27
|
+
else if (2 === edgeKind) { //Return-Edge
|
|
28
28
|
}
|
|
29
|
-
else if (3
|
|
29
|
+
else if (3 === edgeKind) { //Call-To-Return-Edge
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -2,27 +2,30 @@ import { Scene } from '../../Scene';
|
|
|
2
2
|
import { ArkInvokeStmt, Stmt } from '../base/Stmt';
|
|
3
3
|
import { ArkMethod } from '../model/ArkMethod';
|
|
4
4
|
import { DataflowProblem } from './DataflowProblem';
|
|
5
|
-
import { PathEdge } from './Edge';
|
|
5
|
+
import { PathEdge, PathEdgePoint } from './Edge';
|
|
6
|
+
import { BasicBlock } from '../graph/BasicBlock';
|
|
7
|
+
import { ClassHierarchyAnalysis } from '../../callgraph/algorithm/ClassHierarchyAnalysis';
|
|
8
|
+
type CallToReturnCacheEdge<D> = PathEdge<D>;
|
|
6
9
|
export declare abstract class DataflowSolver<D> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
protected problem: DataflowProblem<D>;
|
|
11
|
+
protected workList: Array<PathEdge<D>>;
|
|
12
|
+
protected pathEdgeSet: Set<PathEdge<D>>;
|
|
13
|
+
protected zeroFact: D;
|
|
14
|
+
protected inComing: Map<PathEdgePoint<D>, Set<PathEdgePoint<D>>>;
|
|
15
|
+
protected endSummary: Map<PathEdgePoint<D>, Set<PathEdgePoint<D>>>;
|
|
16
|
+
protected summaryEdge: Set<CallToReturnCacheEdge<D>>;
|
|
17
|
+
protected scene: Scene;
|
|
18
|
+
protected CHA: ClassHierarchyAnalysis;
|
|
19
|
+
protected stmtNexts: Map<Stmt, Set<Stmt>>;
|
|
20
|
+
protected laterEdges: Set<PathEdge<D>>;
|
|
18
21
|
constructor(problem: DataflowProblem<D>, scene: Scene);
|
|
19
22
|
solve(): void;
|
|
20
23
|
protected computeResult(stmt: Stmt, d: D): boolean;
|
|
21
24
|
protected getChildren(stmt: Stmt): Stmt[];
|
|
22
25
|
protected init(): void;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
protected buildStmtMapInClass(): void;
|
|
27
|
+
protected buildStmtMapInBlock(block: BasicBlock): void;
|
|
28
|
+
protected setCfg4AllStmt(): void;
|
|
26
29
|
protected getAllCalleeMethods(callNode: ArkInvokeStmt): Set<ArkMethod>;
|
|
27
30
|
protected getReturnSiteOfCall(call: Stmt): Stmt;
|
|
28
31
|
protected getStartOfCallerMethod(call: Stmt): Stmt;
|
|
@@ -31,10 +34,11 @@ export declare abstract class DataflowSolver<D> {
|
|
|
31
34
|
protected processExitNode(edge: PathEdge<D>): void;
|
|
32
35
|
protected processNormalNode(edge: PathEdge<D>): void;
|
|
33
36
|
protected processCallNode(edge: PathEdge<D>): void;
|
|
37
|
+
protected callNodeFactPropagate(edge: PathEdge<D>, firstStmt: Stmt, fact: D, returnSite: Stmt): void;
|
|
34
38
|
protected doSolve(): void;
|
|
35
39
|
protected isCallStatement(stmt: Stmt): boolean;
|
|
36
40
|
protected isExitStatement(stmt: Stmt): boolean;
|
|
37
41
|
getPathEdgeSet(): Set<PathEdge<D>>;
|
|
38
42
|
}
|
|
39
|
-
export
|
|
43
|
+
export {};
|
|
40
44
|
//# sourceMappingURL=DataflowSolver.d.ts.map
|