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
|
@@ -67,17 +67,18 @@ class SourceTransformer {
|
|
|
67
67
|
}
|
|
68
68
|
instanceInvokeExprToString(invokeExpr) {
|
|
69
69
|
let methodName = invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
70
|
-
if (methodName
|
|
70
|
+
if (methodName === Const_1.INSTANCE_INIT_METHOD_NAME) {
|
|
71
71
|
return '';
|
|
72
72
|
}
|
|
73
73
|
let args = [];
|
|
74
74
|
invokeExpr.getArgs().forEach((v) => {
|
|
75
75
|
args.push(this.valueToString(v));
|
|
76
76
|
});
|
|
77
|
+
let genericCode = this.genericTypesToString(invokeExpr.getRealGenericTypes());
|
|
77
78
|
if (SourceUtils_1.SourceUtils.isComponentAttributeInvoke(invokeExpr) && this.context.isInBuilderMethod()) {
|
|
78
|
-
return `.${methodName}(${args.join(', ')})`;
|
|
79
|
+
return `.${methodName}${genericCode}(${args.join(', ')})`;
|
|
79
80
|
}
|
|
80
|
-
return `${this.valueToString(invokeExpr.getBase())}.${methodName}(${args.join(', ')})`;
|
|
81
|
+
return `${this.valueToString(invokeExpr.getBase())}.${methodName}${genericCode}(${args.join(', ')})`;
|
|
81
82
|
}
|
|
82
83
|
staticInvokeExprToString(invokeExpr) {
|
|
83
84
|
let methodSignature = invokeExpr.getMethodSignature();
|
|
@@ -92,28 +93,29 @@ class SourceTransformer {
|
|
|
92
93
|
invokeExpr.getArgs().forEach((v) => {
|
|
93
94
|
args.push(this.valueToString(v));
|
|
94
95
|
});
|
|
96
|
+
let genericCode = this.genericTypesToString(invokeExpr.getRealGenericTypes());
|
|
95
97
|
if (this.context.isInBuilderMethod()) {
|
|
96
|
-
if (className
|
|
97
|
-
if (methodName
|
|
98
|
+
if (className === EtsConst_1.COMPONENT_CUSTOMVIEW) {
|
|
99
|
+
if (methodName === EtsConst_1.COMPONENT_CREATE_FUNCTION) {
|
|
98
100
|
// Anonymous @Builder method
|
|
99
101
|
if (args.length > 1) {
|
|
100
102
|
args[1] = args[1].substring('() => '.length);
|
|
101
103
|
}
|
|
102
104
|
return `${args.join(' ')}`;
|
|
103
105
|
}
|
|
104
|
-
if (methodName
|
|
106
|
+
if (methodName === EtsConst_1.COMPONENT_POP_FUNCTION) {
|
|
105
107
|
return '';
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
if (SourceUtils_1.SourceUtils.isComponentCreate(invokeExpr)) {
|
|
109
|
-
if (className
|
|
111
|
+
if (className === EtsConst_1.COMPONENT_IF) {
|
|
110
112
|
return `if (${args.join(', ')})`;
|
|
111
113
|
}
|
|
112
|
-
return `${className}(${args.join(', ')})`;
|
|
114
|
+
return `${className}${genericCode}(${args.join(', ')})`;
|
|
113
115
|
}
|
|
114
116
|
if (SourceUtils_1.SourceUtils.isComponentIfBranchInvoke(invokeExpr)) {
|
|
115
117
|
let arg0 = invokeExpr.getArg(0);
|
|
116
|
-
if (arg0.getValue()
|
|
118
|
+
if (arg0.getValue() === '0') {
|
|
117
119
|
return ``;
|
|
118
120
|
}
|
|
119
121
|
else {
|
|
@@ -125,9 +127,19 @@ class SourceTransformer {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
if (className && className.length > 0) {
|
|
128
|
-
return `${className}.${methodName}(${args.join(', ')})`;
|
|
130
|
+
return `${className}.${methodName}${genericCode}(${args.join(', ')})`;
|
|
129
131
|
}
|
|
130
|
-
return `${methodName}(${args.join(', ')})`;
|
|
132
|
+
return `${methodName}${genericCode}(${args.join(', ')})`;
|
|
133
|
+
}
|
|
134
|
+
genericTypesToString(types) {
|
|
135
|
+
if (!types) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
let code = this.typeArrayToString(types);
|
|
139
|
+
if (code.length > 0) {
|
|
140
|
+
return `<${code}>`;
|
|
141
|
+
}
|
|
142
|
+
return '';
|
|
131
143
|
}
|
|
132
144
|
typeArrayToString(types, split = ', ') {
|
|
133
145
|
let typesStr = [];
|
|
@@ -137,7 +149,7 @@ class SourceTransformer {
|
|
|
137
149
|
return typesStr.join(split);
|
|
138
150
|
}
|
|
139
151
|
static constToString(value) {
|
|
140
|
-
if (value.getType()
|
|
152
|
+
if (value.getType().toString() === 'string') {
|
|
141
153
|
return `'${SourceUtils_1.SourceUtils.escape(value.getValue())}'`;
|
|
142
154
|
}
|
|
143
155
|
else {
|
|
@@ -237,9 +249,9 @@ class SourceTransformer {
|
|
|
237
249
|
return this.anonymousClassToString(cls, this.context.getPrinter().getIndent());
|
|
238
250
|
}
|
|
239
251
|
}
|
|
240
|
-
if (operator
|
|
241
|
-
operator
|
|
242
|
-
operator
|
|
252
|
+
if (operator === Expr_1.NormalBinaryOperator.Division ||
|
|
253
|
+
operator === Expr_1.NormalBinaryOperator.Multiplication ||
|
|
254
|
+
operator === Expr_1.NormalBinaryOperator.Remainder) {
|
|
243
255
|
if (SourceUtils_1.SourceUtils.isTemp(value.getName())) {
|
|
244
256
|
let stmt = value.getDeclaringStmt();
|
|
245
257
|
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.ArkNormalBinopExpr) {
|
|
@@ -264,21 +276,13 @@ class SourceTransformer {
|
|
|
264
276
|
}
|
|
265
277
|
typeToString(type) {
|
|
266
278
|
if (type instanceof Type_1.LiteralType) {
|
|
267
|
-
|
|
268
|
-
if (typeof literalName === 'string' && literalName.endsWith('Keyword')) {
|
|
269
|
-
return literalName.substring(0, literalName.length - 'Keyword'.length).toLowerCase();
|
|
270
|
-
}
|
|
271
|
-
return `${literalName}`;
|
|
279
|
+
return this.literalType2string(type);
|
|
272
280
|
}
|
|
273
281
|
if (type instanceof Type_1.PrimitiveType) {
|
|
274
282
|
return type.getName();
|
|
275
283
|
}
|
|
276
284
|
if (type instanceof Type_1.UnionType) {
|
|
277
|
-
|
|
278
|
-
for (const member of type.getTypes()) {
|
|
279
|
-
typesStr.push(this.typeToString(member));
|
|
280
|
-
}
|
|
281
|
-
return typesStr.join(' | ');
|
|
285
|
+
return this.unionType2string(type);
|
|
282
286
|
}
|
|
283
287
|
if (type instanceof Type_1.UnknownType) {
|
|
284
288
|
return 'any';
|
|
@@ -287,29 +291,10 @@ class SourceTransformer {
|
|
|
287
291
|
return 'void';
|
|
288
292
|
}
|
|
289
293
|
if (type instanceof Type_1.ClassType) {
|
|
290
|
-
|
|
291
|
-
if (SourceUtils_1.SourceUtils.isDefaultClass(name)) {
|
|
292
|
-
return 'any';
|
|
293
|
-
}
|
|
294
|
-
if (SourceUtils_1.SourceUtils.isAnonymousClass(name)) {
|
|
295
|
-
let cls = this.context.getClass(type.getClassSignature());
|
|
296
|
-
if (cls && cls.getCategory() == ArkClass_1.ClassCategory.TYPE_LITERAL) {
|
|
297
|
-
return this.anonymousClassToString(cls, this.context.getPrinter().getIndent());
|
|
298
|
-
}
|
|
299
|
-
return 'Object';
|
|
300
|
-
}
|
|
301
|
-
return name;
|
|
294
|
+
return this.classType2string(type);
|
|
302
295
|
}
|
|
303
296
|
if (type instanceof Type_1.ArrayType) {
|
|
304
|
-
|
|
305
|
-
for (let i = 0; i < type.getDimension(); i++) {
|
|
306
|
-
dimensions.push('[]');
|
|
307
|
-
}
|
|
308
|
-
let baseType = type.getBaseType();
|
|
309
|
-
if (baseType instanceof Type_1.UnionType) {
|
|
310
|
-
return `(${this.typeToString(baseType)})${dimensions.join('')}`;
|
|
311
|
-
}
|
|
312
|
-
return `${this.typeToString(baseType)}${dimensions.join('')}`;
|
|
297
|
+
return this.arrayType2string(type);
|
|
313
298
|
}
|
|
314
299
|
if (type instanceof Type_1.FunctionType) {
|
|
315
300
|
let methodSignature = type.getMethodSignature();
|
|
@@ -319,11 +304,7 @@ class SourceTransformer {
|
|
|
319
304
|
}
|
|
320
305
|
}
|
|
321
306
|
if (type instanceof Type_1.UnclearReferenceType) {
|
|
322
|
-
|
|
323
|
-
if (genericTypes.length > 0) {
|
|
324
|
-
return `${type.getName()}<${genericTypes.join(', ')}>`;
|
|
325
|
-
}
|
|
326
|
-
return type.getName();
|
|
307
|
+
return this.unclearReferenceType2string(type);
|
|
327
308
|
}
|
|
328
309
|
if (type instanceof Type_1.GenericType) {
|
|
329
310
|
return type.getName();
|
|
@@ -334,5 +315,55 @@ class SourceTransformer {
|
|
|
334
315
|
logger.info(`valueToString ${type.constructor} not support.`);
|
|
335
316
|
return type.toString();
|
|
336
317
|
}
|
|
318
|
+
literalType2string(type) {
|
|
319
|
+
let literalName = type.getLiteralName();
|
|
320
|
+
if (typeof literalName === 'string' && literalName.endsWith('Keyword')) {
|
|
321
|
+
return literalName.substring(0, literalName.length - 'Keyword'.length).toLowerCase();
|
|
322
|
+
}
|
|
323
|
+
return `${literalName}`;
|
|
324
|
+
}
|
|
325
|
+
unionType2string(type) {
|
|
326
|
+
let typesStr = [];
|
|
327
|
+
for (const member of type.getTypes()) {
|
|
328
|
+
typesStr.push(this.typeToString(member));
|
|
329
|
+
}
|
|
330
|
+
return typesStr.join(' | ');
|
|
331
|
+
}
|
|
332
|
+
arrayType2string(type) {
|
|
333
|
+
const dimensions = [];
|
|
334
|
+
for (let i = 0; i < type.getDimension(); i++) {
|
|
335
|
+
dimensions.push('[]');
|
|
336
|
+
}
|
|
337
|
+
let baseType = type.getBaseType();
|
|
338
|
+
if (baseType instanceof Type_1.UnionType) {
|
|
339
|
+
return `(${this.typeToString(baseType)})${dimensions.join('')}`;
|
|
340
|
+
}
|
|
341
|
+
return `${this.typeToString(baseType)}${dimensions.join('')}`;
|
|
342
|
+
}
|
|
343
|
+
unclearReferenceType2string(type) {
|
|
344
|
+
let genericTypes = type.getGenericTypes();
|
|
345
|
+
if (genericTypes.length > 0) {
|
|
346
|
+
return `${type.getName()}<${genericTypes.join(', ')}>`;
|
|
347
|
+
}
|
|
348
|
+
return type.getName();
|
|
349
|
+
}
|
|
350
|
+
classType2string(type) {
|
|
351
|
+
let name = type.getClassSignature().getClassName();
|
|
352
|
+
if (SourceUtils_1.SourceUtils.isDefaultClass(name)) {
|
|
353
|
+
return 'any';
|
|
354
|
+
}
|
|
355
|
+
if (SourceUtils_1.SourceUtils.isAnonymousClass(name)) {
|
|
356
|
+
let cls = this.context.getClass(type.getClassSignature());
|
|
357
|
+
if (cls && cls.getCategory() === ArkClass_1.ClassCategory.TYPE_LITERAL) {
|
|
358
|
+
return this.anonymousClassToString(cls, this.context.getPrinter().getIndent());
|
|
359
|
+
}
|
|
360
|
+
return 'Object';
|
|
361
|
+
}
|
|
362
|
+
let genericTypes = type.getRealGenericTypes();
|
|
363
|
+
if (genericTypes && genericTypes.length > 0) {
|
|
364
|
+
return `${name}<${genericTypes.join(', ')}>`;
|
|
365
|
+
}
|
|
366
|
+
return name;
|
|
367
|
+
}
|
|
337
368
|
}
|
|
338
369
|
exports.SourceTransformer = SourceTransformer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SourceUtils.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceUtils.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,qBAAqB,EAErB,mBAAmB,EACnB,oBAAoB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAiB,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAS3D,OAAO,EAAE,QAAQ,EAAiB,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"SourceUtils.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceUtils.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,qBAAqB,EAErB,mBAAmB,EACnB,oBAAoB,EACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAiB,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAS3D,OAAO,EAAE,QAAQ,EAAiB,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAM7D,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,qBAAa,WAAW;IACpB,OAAc,uBAAuB,sBAQlC;WAEW,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIvC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIrC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIxC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI1C,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,EAAE,oBAAoB,GAAG,OAAO;WAqBvE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI7B,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM;WAOpC,cAAc,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO;WAcxD,iBAAiB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO;WAc3D,0BAA0B,CACpC,UAAU,EAAE,qBAAqB,EACjC,OAAO,GAAE,GAAG,CAAC,qBAAqB,CAAa,GAChD,OAAO;WA2BI,yBAAyB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO;WAUnE,uBAAuB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO;WAajE,4BAA4B,CACtC,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,YAAY,GAAG,SAAS,GACpC,MAAM;WAeK,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAevC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAY7C"}
|
|
@@ -50,6 +50,7 @@ const ArkClass_1 = require("../../core/model/ArkClass");
|
|
|
50
50
|
const logger_1 = __importStar(require("../../utils/logger"));
|
|
51
51
|
const Const_1 = require("../../core/common/Const");
|
|
52
52
|
const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
|
|
53
|
+
const Const_2 = require("../../core/common/Const");
|
|
53
54
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SourceUtils');
|
|
54
55
|
exports.CLASS_CATEGORY_COMPONENT = 100;
|
|
55
56
|
class SourceUtils {
|
|
@@ -57,13 +58,13 @@ class SourceUtils {
|
|
|
57
58
|
return name.startsWith(Const_1.ANONYMOUS_CLASS_PREFIX);
|
|
58
59
|
}
|
|
59
60
|
static isDefaultClass(name) {
|
|
60
|
-
return name
|
|
61
|
+
return name === Const_1.DEFAULT_ARK_CLASS_NAME;
|
|
61
62
|
}
|
|
62
63
|
static isAnonymousMethod(name) {
|
|
63
|
-
return name.startsWith(
|
|
64
|
+
return name.startsWith(Const_1.ANONYMOUS_METHOD_PREFIX);
|
|
64
65
|
}
|
|
65
66
|
static isConstructorMethod(name) {
|
|
66
|
-
return name
|
|
67
|
+
return name === 'constructor';
|
|
67
68
|
}
|
|
68
69
|
static isDeIncrementStmt(stmt, op) {
|
|
69
70
|
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
@@ -80,10 +81,10 @@ class SourceUtils {
|
|
|
80
81
|
if (!(op1 instanceof Local_1.Local) || !(op2 instanceof Constant_1.Constant)) {
|
|
81
82
|
return false;
|
|
82
83
|
}
|
|
83
|
-
return leftOp.getName()
|
|
84
|
+
return leftOp.getName() === op1.getName() && operator === op && op2.getValue() === '1';
|
|
84
85
|
}
|
|
85
86
|
static isTemp(name) {
|
|
86
|
-
return name.startsWith(
|
|
87
|
+
return name.startsWith(Const_2.TEMP_LOCAL_PREFIX);
|
|
87
88
|
}
|
|
88
89
|
static getOriginType(cls) {
|
|
89
90
|
if (cls.hasComponentDecorator()) {
|
|
@@ -94,7 +95,7 @@ class SourceUtils {
|
|
|
94
95
|
static isComponentPop(invokeExpr) {
|
|
95
96
|
let className = invokeExpr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
96
97
|
let methodName = invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
97
|
-
if (methodName
|
|
98
|
+
if (methodName === EtsConst_1.COMPONENT_POP_FUNCTION &&
|
|
98
99
|
((0, EtsConst_1.isEtsSystemComponent)(className) || EtsConst_1.SPECIAL_CONTAINER_COMPONENT.has(className))) {
|
|
99
100
|
return true;
|
|
100
101
|
}
|
|
@@ -103,7 +104,7 @@ class SourceUtils {
|
|
|
103
104
|
static isComponentCreate(invokeExpr) {
|
|
104
105
|
let className = invokeExpr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
105
106
|
let methodName = invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
106
|
-
if (methodName
|
|
107
|
+
if (methodName === EtsConst_1.COMPONENT_CREATE_FUNCTION &&
|
|
107
108
|
((0, EtsConst_1.isEtsSystemComponent)(className) || EtsConst_1.SPECIAL_CONTAINER_COMPONENT.has(className))) {
|
|
108
109
|
return true;
|
|
109
110
|
}
|
|
@@ -135,7 +136,7 @@ class SourceUtils {
|
|
|
135
136
|
static isComponentIfBranchInvoke(invokeExpr) {
|
|
136
137
|
let className = invokeExpr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
137
138
|
let methodName = invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
138
|
-
if (className
|
|
139
|
+
if (className === EtsConst_1.COMPONENT_IF && methodName === EtsConst_1.COMPONENT_BRANCH_FUNCTION) {
|
|
139
140
|
return true;
|
|
140
141
|
}
|
|
141
142
|
return false;
|
|
@@ -143,9 +144,9 @@ class SourceUtils {
|
|
|
143
144
|
static isComponentIfElseInvoke(invokeExpr) {
|
|
144
145
|
let className = invokeExpr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
145
146
|
let methodName = invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
146
|
-
if (className
|
|
147
|
+
if (className === EtsConst_1.COMPONENT_IF && methodName === EtsConst_1.COMPONENT_BRANCH_FUNCTION) {
|
|
147
148
|
let arg0 = invokeExpr.getArg(0);
|
|
148
|
-
if (arg0.getValue()
|
|
149
|
+
if (arg0.getValue() === '1') {
|
|
149
150
|
return true;
|
|
150
151
|
}
|
|
151
152
|
}
|
|
@@ -156,7 +157,7 @@ class SourceUtils {
|
|
|
156
157
|
let namespaceName = (_a = classSignature.getDeclaringNamespaceSignature()) === null || _a === void 0 ? void 0 : _a.getNamespaceName();
|
|
157
158
|
let className = classSignature.getClassName();
|
|
158
159
|
let code = [];
|
|
159
|
-
if (namespaceName && namespaceName.length > 0 && namespaceName
|
|
160
|
+
if (namespaceName && namespaceName.length > 0 && namespaceName !== (namespace === null || namespace === void 0 ? void 0 : namespace.getName())) {
|
|
160
161
|
code.push(namespaceName);
|
|
161
162
|
}
|
|
162
163
|
if (className && className.length > 0 && !SourceUtils.isDefaultClass(className)) {
|
|
@@ -59,7 +59,7 @@ class StaticSingleAssignmentFormer {
|
|
|
59
59
|
localToPhiBlock.set(local, new Set());
|
|
60
60
|
let phiBlocks = localToPhiBlock.get(local);
|
|
61
61
|
let blocks = Array.from(localToBlocks.get(local));
|
|
62
|
-
while (blocks.length
|
|
62
|
+
while (blocks.length !== 0) {
|
|
63
63
|
let block = blocks.splice(0, 1).at(0);
|
|
64
64
|
let dfs = dominanceFinder.getDominanceFrontiers(block);
|
|
65
65
|
for (const df of dfs) {
|
|
@@ -119,7 +119,7 @@ class StaticSingleAssignmentFormer {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
for (const phi of phis) {
|
|
122
|
-
cfg.insertBefore(block.getHead()
|
|
122
|
+
cfg.insertBefore(phi, block.getHead());
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -223,7 +223,7 @@ class StaticSingleAssignmentFormer {
|
|
|
223
223
|
let hashPos = local.getName().indexOf('#');
|
|
224
224
|
let oriName = local.getName().substring(0, hashPos);
|
|
225
225
|
for (const oriLocal of locals) {
|
|
226
|
-
if (oriLocal.getName()
|
|
226
|
+
if (oriLocal.getName() === oriName) {
|
|
227
227
|
return oriLocal;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CfgStructualAnalysis.d.ts","sourceRoot":"","sources":["../../src/utils/CfgStructualAnalysis.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,oBAAY,aAAa;IACrB,MAAM,IAAA;IACN,EAAE,IAAA;IACF,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,QAAQ,IAAA;IACR,EAAE,IAAA;IACF,QAAQ,IAAA;IACR,KAAK,IAAA;IACL,GAAG,IAAA;IACH,YAAY,IAAA;CACf;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;AAE7F,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,QAAQ,CAAwC;IACxD,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,YAAY,CAAmD;IACvE,OAAO,CAAC,OAAO,CAAmD;gBAEtD,GAAG,EAAE,GAAG;IAsBb,QAAQ,IAAI,YAAY;IAIxB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAM7C,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,OAAO,GAAE,GAAG,CAAC,YAAY,CAAa;IAUvG,OAAO,CAAC,kBAAkB;IA4B1B,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,qBAAqB;IAgC7B,OAAO,CAAC,iBAAiB;
|
|
1
|
+
{"version":3,"file":"CfgStructualAnalysis.d.ts","sourceRoot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