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
package/lib/core/base/Expr.js
CHANGED
|
@@ -54,12 +54,14 @@ const Constant_1 = require("./Constant");
|
|
|
54
54
|
const TSConst_1 = require("../common/TSConst");
|
|
55
55
|
const Builtin_1 = require("../common/Builtin");
|
|
56
56
|
const EtsConst_1 = require("../common/EtsConst");
|
|
57
|
+
const Const_1 = require("../common/Const");
|
|
58
|
+
const ArkField_1 = require("../model/ArkField");
|
|
57
59
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'Expr');
|
|
58
60
|
/**
|
|
59
61
|
* @category core/base/expr
|
|
60
62
|
*/
|
|
61
63
|
class AbstractExpr {
|
|
62
|
-
inferType(
|
|
64
|
+
inferType(arkMethod) {
|
|
63
65
|
return this;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -71,28 +73,120 @@ class AbstractInvokeExpr extends AbstractExpr {
|
|
|
71
73
|
this.args = args;
|
|
72
74
|
this.realGenericTypes = realGenericTypes;
|
|
73
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Get method Signature. The method signature is consist of ClassSignature and MethodSubSignature.
|
|
78
|
+
* It is the unique flag of a method. It is usually used to compose a expression string in ArkIRTransformer.
|
|
79
|
+
* @returns The class method signature, such as ArkStaticInvokeExpr.
|
|
80
|
+
* @example
|
|
81
|
+
* 1. 3AC information composed of getMethodSignature ().
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
let strs: string[] = [];
|
|
85
|
+
strs.push('staticinvoke <');
|
|
86
|
+
strs.push(this.getMethodSignature().toString());
|
|
87
|
+
strs.push('>(');
|
|
88
|
+
```
|
|
89
|
+
*/
|
|
74
90
|
getMethodSignature() {
|
|
75
91
|
return this.methodSignature;
|
|
76
92
|
}
|
|
77
93
|
setMethodSignature(newMethodSignature) {
|
|
78
94
|
this.methodSignature = newMethodSignature;
|
|
79
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns an argument used in the expression according to its index.
|
|
98
|
+
* @param index - the index of the argument.
|
|
99
|
+
* @returns An argument used in the expression.
|
|
100
|
+
*/
|
|
80
101
|
getArg(index) {
|
|
81
102
|
return this.args[index];
|
|
82
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns an **array** of arguments used in the expression.
|
|
106
|
+
* @returns An **array** of arguments used in the expression.
|
|
107
|
+
* @example
|
|
108
|
+
* 1. get args number.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const argsNum = expr.getArgs().length;
|
|
112
|
+
if (argsNum < 5) {
|
|
113
|
+
... ...
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
2. iterate arg based on expression
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
for (const arg of this.getArgs()) {
|
|
121
|
+
strs.push(arg.toString());
|
|
122
|
+
strs.push(', ');
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
*/
|
|
83
126
|
getArgs() {
|
|
84
127
|
return this.args;
|
|
85
128
|
}
|
|
86
129
|
setArgs(newArgs) {
|
|
87
130
|
this.args = newArgs;
|
|
88
131
|
}
|
|
132
|
+
inferArgs(arkMethod) {
|
|
133
|
+
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
134
|
+
const parameters = this.methodSignature.getMethodSubSignature().getParameters();
|
|
135
|
+
let realTypes = [];
|
|
136
|
+
for (let index = 0; index < this.args.length; index++) {
|
|
137
|
+
const arg = this.args[index];
|
|
138
|
+
TypeInference_1.TypeInference.inferValueType(arg, arkMethod);
|
|
139
|
+
if (index >= parameters.length) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
const argType = arg.getType();
|
|
143
|
+
const paramType = parameters[index].getType();
|
|
144
|
+
if (paramType instanceof Type_1.UnionType) {
|
|
145
|
+
paramType.getTypes().forEach(t => this.inferArg(argType, t, scene));
|
|
146
|
+
}
|
|
147
|
+
else if (paramType instanceof Type_1.GenericType) {
|
|
148
|
+
realTypes.push(argType);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.inferArg(argType, paramType, scene);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (realTypes.length > 0) {
|
|
155
|
+
this.realGenericTypes = realTypes;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
inferArg(argType, paramType, scene) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
if (argType instanceof Type_1.FunctionType) {
|
|
161
|
+
let params;
|
|
162
|
+
let realTypes;
|
|
163
|
+
if (paramType instanceof Type_1.ClassType) {
|
|
164
|
+
params = (_b = (_a = scene.getClass(paramType.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethodWithName(Const_1.CALL_SIGNATURE_NAME)) === null || _b === void 0 ? void 0 : _b.getParameters();
|
|
165
|
+
realTypes = paramType.getRealGenericTypes();
|
|
166
|
+
}
|
|
167
|
+
else if (paramType instanceof Type_1.FunctionType) {
|
|
168
|
+
params = paramType.getMethodSignature().getMethodSubSignature().getParameters();
|
|
169
|
+
realTypes = this.realGenericTypes;
|
|
170
|
+
}
|
|
171
|
+
if (params) {
|
|
172
|
+
argType.getMethodSignature().getMethodSubSignature().getParameters().forEach((p, i) => {
|
|
173
|
+
var _a;
|
|
174
|
+
let type = (_a = params === null || params === void 0 ? void 0 : params[i]) === null || _a === void 0 ? void 0 : _a.getType();
|
|
175
|
+
if (type instanceof Type_1.GenericType && realTypes) {
|
|
176
|
+
type = realTypes === null || realTypes === void 0 ? void 0 : realTypes[type.getIndex()];
|
|
177
|
+
}
|
|
178
|
+
if (type) {
|
|
179
|
+
p.setType(type);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
89
185
|
getType() {
|
|
186
|
+
var _a;
|
|
90
187
|
let type = this.methodSignature.getType();
|
|
91
|
-
if (!this.realGenericTypes) {
|
|
92
|
-
return type;
|
|
93
|
-
}
|
|
94
188
|
if (type instanceof Type_1.GenericType) {
|
|
95
|
-
const realType = this.realGenericTypes[type.getIndex()];
|
|
189
|
+
const realType = (_a = this.realGenericTypes) === null || _a === void 0 ? void 0 : _a[type.getIndex()];
|
|
96
190
|
if (realType) {
|
|
97
191
|
type = realType;
|
|
98
192
|
}
|
|
@@ -114,6 +208,77 @@ class AbstractInvokeExpr extends AbstractExpr {
|
|
|
114
208
|
getRealGenericTypes() {
|
|
115
209
|
return this.realGenericTypes;
|
|
116
210
|
}
|
|
211
|
+
inferMethod(baseType, methodName, scene) {
|
|
212
|
+
if (baseType instanceof Type_1.ClassType) {
|
|
213
|
+
return this.processClassMethod(baseType, methodName, scene);
|
|
214
|
+
}
|
|
215
|
+
else if (baseType instanceof Type_1.AnnotationNamespaceType) {
|
|
216
|
+
const namespace = scene.getNamespace(baseType.getNamespaceSignature());
|
|
217
|
+
if (namespace) {
|
|
218
|
+
const foundMethod = ModelUtils_1.ModelUtils.findPropertyInNamespace(methodName, namespace);
|
|
219
|
+
if (foundMethod instanceof ArkMethod_1.ArkMethod) {
|
|
220
|
+
TypeInference_1.TypeInference.inferMethodReturnType(foundMethod);
|
|
221
|
+
let signature = foundMethod.matchMethodSignature(this.args);
|
|
222
|
+
this.setMethodSignature(signature);
|
|
223
|
+
return new ArkStaticInvokeExpr(signature, this.getArgs(), this.getRealGenericTypes());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (baseType instanceof Type_1.ArrayType && methodName === Builtin_1.Builtin.ITERATOR_FUNCTION) {
|
|
228
|
+
const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
229
|
+
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
|
|
230
|
+
.getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
231
|
+
returnType.setRealGenericTypes([baseType.getBaseType()]);
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
processClassMethod(baseType, methodName, scene) {
|
|
238
|
+
let arkClass = scene.getClass(baseType.getClassSignature());
|
|
239
|
+
if (!arkClass) {
|
|
240
|
+
const globalClass = scene.getSdkGlobal(baseType.getClassSignature().getClassName());
|
|
241
|
+
if (globalClass instanceof ArkClass_1.ArkClass) {
|
|
242
|
+
arkClass = globalClass;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const method = arkClass ? ModelUtils_1.ModelUtils.findPropertyInClass(methodName, arkClass) : null;
|
|
246
|
+
if (method instanceof ArkMethod_1.ArkMethod) {
|
|
247
|
+
TypeInference_1.TypeInference.inferMethodReturnType(method);
|
|
248
|
+
const methodSignature = method.matchMethodSignature(this.args);
|
|
249
|
+
this.setMethodSignature(methodSignature);
|
|
250
|
+
this.realGenericTypes = method.getDeclaringArkClass() === arkClass ? baseType.getRealGenericTypes() :
|
|
251
|
+
arkClass === null || arkClass === void 0 ? void 0 : arkClass.getRealTypes();
|
|
252
|
+
if (method.isStatic()) {
|
|
253
|
+
return new ArkStaticInvokeExpr(methodSignature, this.getArgs(), this.getRealGenericTypes());
|
|
254
|
+
}
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
else if (method instanceof ArkField_1.ArkField) {
|
|
258
|
+
const type = method.getType();
|
|
259
|
+
if (type instanceof Type_1.FunctionType ||
|
|
260
|
+
(type instanceof Type_1.ClassType && type.getClassSignature().getClassName() === EtsConst_1.CALL_BACK)) {
|
|
261
|
+
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], Type_1.VoidType);
|
|
262
|
+
this.setMethodSignature(new ArkSignature_1.MethodSignature(baseType.getClassSignature(), subSignature));
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else if (methodName === TSConst_1.CONSTRUCTOR_NAME) { //sdk隐式构造
|
|
267
|
+
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], new Type_1.ClassType(baseType.getClassSignature()));
|
|
268
|
+
const signature = new ArkSignature_1.MethodSignature(baseType.getClassSignature(), subSignature);
|
|
269
|
+
this.setMethodSignature(signature);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
else if (methodName === Builtin_1.Builtin.ITERATOR_NEXT) { //sdk隐式构造
|
|
273
|
+
const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
274
|
+
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
|
|
275
|
+
.getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
276
|
+
returnType.setRealGenericTypes(baseType.getRealGenericTypes());
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
117
282
|
getUses() {
|
|
118
283
|
let uses = [];
|
|
119
284
|
uses.push(...this.args);
|
|
@@ -129,12 +294,22 @@ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
|
129
294
|
super(methodSignature, args, realGenericTypes);
|
|
130
295
|
this.base = base;
|
|
131
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Returns the local of the instance of invoke expression.
|
|
299
|
+
* @returns The local of the invoke expression's instance..
|
|
300
|
+
*/
|
|
132
301
|
getBase() {
|
|
133
302
|
return this.base;
|
|
134
303
|
}
|
|
135
304
|
setBase(newBase) {
|
|
136
305
|
this.base = newBase;
|
|
137
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Returns an **array** of values used in this invoke expression,
|
|
309
|
+
* including all arguments and values each arguments used.
|
|
310
|
+
* For {@link ArkInstanceInvokeExpr}, the return also contains the caller base and uses of base.
|
|
311
|
+
* @returns An **array** of arguments used in the invoke expression.
|
|
312
|
+
*/
|
|
138
313
|
getUses() {
|
|
139
314
|
let uses = [];
|
|
140
315
|
uses.push(this.base);
|
|
@@ -162,8 +337,8 @@ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
|
162
337
|
strs.push(')');
|
|
163
338
|
return strs.join('');
|
|
164
339
|
}
|
|
165
|
-
inferType(
|
|
166
|
-
|
|
340
|
+
inferType(arkMethod) {
|
|
341
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
167
342
|
let baseType = this.base.getType();
|
|
168
343
|
if (this.base instanceof Local_1.Local && baseType instanceof Type_1.UnknownType) {
|
|
169
344
|
baseType = TypeInference_1.TypeInference.inferBaseType(this.base.getName(), arkClass);
|
|
@@ -173,7 +348,7 @@ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
|
173
348
|
}
|
|
174
349
|
const methodName = this.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
175
350
|
if (!baseType) {
|
|
176
|
-
if (!this.tryInferFormGlobal(methodName,
|
|
351
|
+
if (!this.tryInferFormGlobal(methodName, arkMethod)) {
|
|
177
352
|
logger.warn('infer ArkInstanceInvokeExpr base type fail: ' + this.toString());
|
|
178
353
|
}
|
|
179
354
|
return this;
|
|
@@ -201,10 +376,11 @@ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
|
201
376
|
else {
|
|
202
377
|
result = this.inferMethod(baseType, methodName, scene);
|
|
203
378
|
}
|
|
204
|
-
if (!result && this.tryInferFormGlobal(methodName,
|
|
379
|
+
if (!result && this.tryInferFormGlobal(methodName, arkMethod)) {
|
|
205
380
|
result = this;
|
|
206
381
|
}
|
|
207
382
|
if (result) {
|
|
383
|
+
this.inferArgs(arkMethod);
|
|
208
384
|
return result;
|
|
209
385
|
}
|
|
210
386
|
logger.warn('invoke ArkInstanceInvokeExpr MethodSignature type fail: ', this.toString());
|
|
@@ -229,65 +405,18 @@ class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
|
229
405
|
logger.warn(`arg of forEach must be callable`);
|
|
230
406
|
}
|
|
231
407
|
}
|
|
232
|
-
tryInferFormGlobal(methodName,
|
|
408
|
+
tryInferFormGlobal(methodName, arkMethod) {
|
|
409
|
+
let arkClass = arkMethod.getDeclaringArkClass();
|
|
233
410
|
if (arkClass.hasComponentDecorator() || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
|
|
234
411
|
const global = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(methodName);
|
|
235
412
|
if (global instanceof ArkMethod_1.ArkMethod) {
|
|
236
|
-
|
|
237
|
-
this.setMethodSignature(
|
|
413
|
+
const methodSignature = global.matchMethodSignature(this.getArgs());
|
|
414
|
+
this.setMethodSignature(methodSignature);
|
|
238
415
|
return true;
|
|
239
416
|
}
|
|
240
417
|
}
|
|
241
418
|
return false;
|
|
242
419
|
}
|
|
243
|
-
inferMethod(baseType, methodName, scene) {
|
|
244
|
-
if (baseType instanceof Type_1.ClassType) {
|
|
245
|
-
const arkClass = scene.getClass(baseType.getClassSignature());
|
|
246
|
-
const method = arkClass ? ModelUtils_1.ModelUtils.findPropertyInClass(methodName, arkClass) : null;
|
|
247
|
-
if (method instanceof ArkMethod_1.ArkMethod) {
|
|
248
|
-
TypeInference_1.TypeInference.inferMethodReturnType(method);
|
|
249
|
-
this.setMethodSignature(method.getSignature());
|
|
250
|
-
if (method.isStatic()) {
|
|
251
|
-
return new ArkStaticInvokeExpr(method.getSignature(), this.getArgs(), this.getRealGenericTypes());
|
|
252
|
-
}
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
else if (methodName === TSConst_1.CONSTRUCTOR_NAME) { //sdk隐式构造
|
|
256
|
-
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], new Type_1.ClassType(baseType.getClassSignature()));
|
|
257
|
-
const signature = new ArkSignature_1.MethodSignature(baseType.getClassSignature(), subSignature);
|
|
258
|
-
this.setMethodSignature(signature);
|
|
259
|
-
return this;
|
|
260
|
-
}
|
|
261
|
-
else if (methodName === Builtin_1.Builtin.ITERATOR_NEXT) { //sdk隐式构造
|
|
262
|
-
const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
263
|
-
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
|
|
264
|
-
.getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
265
|
-
returnType.setRealGenericTypes(baseType.getRealGenericTypes());
|
|
266
|
-
return this;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
else if (baseType instanceof Type_1.AnnotationNamespaceType) {
|
|
271
|
-
const namespace = scene.getNamespace(baseType.getNamespaceSignature());
|
|
272
|
-
if (namespace) {
|
|
273
|
-
const foundMethod = ModelUtils_1.ModelUtils.findPropertyInNamespace(methodName, namespace);
|
|
274
|
-
if (foundMethod instanceof ArkMethod_1.ArkMethod) {
|
|
275
|
-
TypeInference_1.TypeInference.inferMethodReturnType(foundMethod);
|
|
276
|
-
this.setMethodSignature(foundMethod.getSignature());
|
|
277
|
-
return new ArkStaticInvokeExpr(foundMethod.getSignature(), this.getArgs(), this.getRealGenericTypes());
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else if (baseType instanceof Type_1.ArrayType && methodName === Builtin_1.Builtin.ITERATOR_FUNCTION) {
|
|
282
|
-
const returnType = this.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
283
|
-
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
|
|
284
|
-
.getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
285
|
-
returnType.setRealGenericTypes([baseType.getBaseType()]);
|
|
286
|
-
return this;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
420
|
}
|
|
292
421
|
exports.ArkInstanceInvokeExpr = ArkInstanceInvokeExpr;
|
|
293
422
|
class ArkStaticInvokeExpr extends AbstractInvokeExpr {
|
|
@@ -309,63 +438,60 @@ class ArkStaticInvokeExpr extends AbstractInvokeExpr {
|
|
|
309
438
|
strs.push(')');
|
|
310
439
|
return strs.join('');
|
|
311
440
|
}
|
|
312
|
-
inferType(
|
|
441
|
+
inferType(arkMethod) {
|
|
313
442
|
var _a, _b;
|
|
314
|
-
|
|
443
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
315
444
|
const oldMethodSignature = this.getMethodSignature();
|
|
316
445
|
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
317
446
|
const methodName = oldMethodSubSignature.getMethodName();
|
|
447
|
+
if (methodName === TSConst_1.IMPORT && this.getArgs()[0] instanceof Constant_1.Constant) {
|
|
448
|
+
this.processDynamicImport(arkClass, methodName, oldMethodSignature);
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
const className = this.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
452
|
+
if (className && className !== Const_1.UNKNOWN_CLASS_NAME) {
|
|
453
|
+
const baseType = TypeInference_1.TypeInference.inferUnclearReferenceType(className, arkClass);
|
|
454
|
+
if (baseType) {
|
|
455
|
+
this.inferMethod(baseType, methodName, arkClass.getDeclaringArkFile().getScene());
|
|
456
|
+
this.inferArgs(arkMethod);
|
|
457
|
+
}
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
318
460
|
let method;
|
|
319
|
-
const arkExport = (_a = ModelUtils_1.ModelUtils.getStaticMethodWithName(methodName, arkClass)) !== null && _a !== void 0 ? _a : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(methodName, arkClass.getDeclaringArkFile());
|
|
461
|
+
const arkExport = (_b = (_a = ModelUtils_1.ModelUtils.getStaticMethodWithName(methodName, arkClass)) !== null && _a !== void 0 ? _a : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(methodName, arkClass.getDeclaringArkFile())) !== null && _b !== void 0 ? _b : arkClass.getDeclaringArkFile().getScene().getSdkGlobal(methodName);
|
|
320
462
|
if (arkExport instanceof ArkMethod_1.ArkMethod) {
|
|
321
463
|
method = arkExport;
|
|
322
464
|
}
|
|
323
465
|
else if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
324
466
|
method = arkExport.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
325
467
|
}
|
|
326
|
-
if (!method) {
|
|
327
|
-
if (methodName === TSConst_1.IMPORT && this.getArgs()[0] instanceof Constant_1.Constant) {
|
|
328
|
-
const importInfo = new ArkImport_1.ImportInfo();
|
|
329
|
-
importInfo.setNameBeforeAs(TSConst_1.ALL);
|
|
330
|
-
importInfo.setImportClauseName(TSConst_1.ALL);
|
|
331
|
-
importInfo.setImportFrom(this.getArgs()[0].getValue());
|
|
332
|
-
importInfo.setDeclaringArkFile(arkClass.getDeclaringArkFile());
|
|
333
|
-
const type = TypeInference_1.TypeInference.parseArkExport2Type((_b = importInfo.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport());
|
|
334
|
-
if (type) {
|
|
335
|
-
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, oldMethodSubSignature.getParameters(), type);
|
|
336
|
-
const signature = new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), subSignature);
|
|
337
|
-
this.setMethodSignature(signature);
|
|
338
|
-
}
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
if (arkClass.hasComponentDecorator() || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
|
|
342
|
-
let className;
|
|
343
|
-
if (EtsConst_1.COMPONENT_CREATE_FUNCTION === methodName || EtsConst_1.COMPONENT_POP_FUNCTION === methodName) {
|
|
344
|
-
className = this.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
345
|
-
}
|
|
346
|
-
const globalName = className !== null && className !== void 0 ? className : methodName;
|
|
347
|
-
const global = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(globalName);
|
|
348
|
-
if (global instanceof ArkMethod_1.ArkMethod) {
|
|
349
|
-
method = global;
|
|
350
|
-
}
|
|
351
|
-
else if (global instanceof ArkClass_1.ArkClass) {
|
|
352
|
-
const callable = ModelUtils_1.ModelUtils.findPropertyInClass(methodName, global);
|
|
353
|
-
if (callable instanceof ArkMethod_1.ArkMethod) {
|
|
354
|
-
method = callable;
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
const signature = new ArkSignature_1.MethodSignature(global.getSignature(), oldMethodSubSignature);
|
|
358
|
-
this.setMethodSignature(signature);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
468
|
if (method) {
|
|
364
|
-
this.setMethodSignature(method.getSignature());
|
|
365
469
|
TypeInference_1.TypeInference.inferMethodReturnType(method);
|
|
470
|
+
let signature = method.matchMethodSignature(this.getArgs());
|
|
471
|
+
if (method.isAnonymousMethod()) {
|
|
472
|
+
const subSignature = signature.getMethodSubSignature();
|
|
473
|
+
const newSubSignature = new ArkSignature_1.MethodSubSignature(methodName, subSignature.getParameters(), subSignature.getReturnType(), subSignature.isStatic());
|
|
474
|
+
signature = new ArkSignature_1.MethodSignature(signature.getDeclaringClassSignature(), newSubSignature);
|
|
475
|
+
}
|
|
476
|
+
this.setMethodSignature(signature);
|
|
477
|
+
this.inferArgs(arkMethod);
|
|
366
478
|
}
|
|
367
479
|
return this;
|
|
368
480
|
}
|
|
481
|
+
processDynamicImport(arkClass, methodName, oldMethodSignature) {
|
|
482
|
+
var _a;
|
|
483
|
+
const importInfo = new ArkImport_1.ImportInfo();
|
|
484
|
+
importInfo.setNameBeforeAs(TSConst_1.ALL);
|
|
485
|
+
importInfo.setImportClauseName(TSConst_1.ALL);
|
|
486
|
+
importInfo.setImportFrom(this.getArgs()[0].getValue());
|
|
487
|
+
importInfo.setDeclaringArkFile(arkClass.getDeclaringArkFile());
|
|
488
|
+
const type = TypeInference_1.TypeInference.parseArkExport2Type((_a = importInfo.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport());
|
|
489
|
+
if (type) {
|
|
490
|
+
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, oldMethodSignature.getMethodSubSignature().getParameters(), type);
|
|
491
|
+
const signature = new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), subSignature);
|
|
492
|
+
this.setMethodSignature(signature);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
369
495
|
}
|
|
370
496
|
exports.ArkStaticInvokeExpr = ArkStaticInvokeExpr;
|
|
371
497
|
class ArkPtrInvokeExpr extends AbstractInvokeExpr {
|
|
@@ -394,7 +520,7 @@ class ArkPtrInvokeExpr extends AbstractInvokeExpr {
|
|
|
394
520
|
strs.push(')');
|
|
395
521
|
return strs.join('');
|
|
396
522
|
}
|
|
397
|
-
inferType(
|
|
523
|
+
inferType(arkMethod) {
|
|
398
524
|
// TODO: handle type inference
|
|
399
525
|
return this;
|
|
400
526
|
}
|
|
@@ -417,12 +543,15 @@ class ArkNewExpr extends AbstractExpr {
|
|
|
417
543
|
toString() {
|
|
418
544
|
return 'new ' + this.classType;
|
|
419
545
|
}
|
|
420
|
-
inferType(
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
546
|
+
inferType(arkMethod) {
|
|
547
|
+
const classSignature = this.classType.getClassSignature();
|
|
548
|
+
if (classSignature.getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
549
|
+
const className = classSignature.getClassName();
|
|
550
|
+
const type = TypeInference_1.TypeInference.inferUnclearReferenceType(className, arkMethod.getDeclaringArkClass());
|
|
551
|
+
if (type && type instanceof Type_1.ClassType) {
|
|
552
|
+
let realGenericTypes = this.classType.getRealGenericTypes();
|
|
553
|
+
this.classType = realGenericTypes ? new Type_1.ClassType(type.getClassSignature(), realGenericTypes) : type;
|
|
554
|
+
}
|
|
426
555
|
}
|
|
427
556
|
return this;
|
|
428
557
|
}
|
|
@@ -453,8 +582,8 @@ class ArkNewArrayExpr extends AbstractExpr {
|
|
|
453
582
|
isFromLiteral() {
|
|
454
583
|
return this.fromLiteral;
|
|
455
584
|
}
|
|
456
|
-
inferType(
|
|
457
|
-
const type = TypeInference_1.TypeInference.inferUnclearedType(this.baseType,
|
|
585
|
+
inferType(arkMethod) {
|
|
586
|
+
const type = TypeInference_1.TypeInference.inferUnclearedType(this.baseType, arkMethod.getDeclaringArkClass());
|
|
458
587
|
if (type) {
|
|
459
588
|
this.baseType = type;
|
|
460
589
|
}
|
|
@@ -507,10 +636,18 @@ class ArkAwaitExpr extends AbstractExpr {
|
|
|
507
636
|
this.promise = newPromise;
|
|
508
637
|
}
|
|
509
638
|
getType() {
|
|
510
|
-
|
|
639
|
+
var _a, _b;
|
|
640
|
+
const type = this.promise.getType();
|
|
641
|
+
if (type instanceof Type_1.UnclearReferenceType) {
|
|
642
|
+
return type.getGenericTypes()[0];
|
|
643
|
+
}
|
|
644
|
+
else if (type instanceof Type_1.ClassType) {
|
|
645
|
+
return (_b = (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : type;
|
|
646
|
+
}
|
|
647
|
+
return type;
|
|
511
648
|
}
|
|
512
|
-
inferType(
|
|
513
|
-
TypeInference_1.TypeInference.inferValueType(this.promise,
|
|
649
|
+
inferType(arkMethod) {
|
|
650
|
+
TypeInference_1.TypeInference.inferValueType(this.promise, arkMethod);
|
|
514
651
|
return this;
|
|
515
652
|
}
|
|
516
653
|
getUses() {
|
|
@@ -573,7 +710,7 @@ var NormalBinaryOperator;
|
|
|
573
710
|
// Logical
|
|
574
711
|
NormalBinaryOperator["LogicalAnd"] = "&&";
|
|
575
712
|
NormalBinaryOperator["LogicalOr"] = "||";
|
|
576
|
-
})(NormalBinaryOperator
|
|
713
|
+
})(NormalBinaryOperator = exports.NormalBinaryOperator || (exports.NormalBinaryOperator = {}));
|
|
577
714
|
var RelationalBinaryOperator;
|
|
578
715
|
(function (RelationalBinaryOperator) {
|
|
579
716
|
RelationalBinaryOperator["LessThan"] = "<";
|
|
@@ -584,7 +721,7 @@ var RelationalBinaryOperator;
|
|
|
584
721
|
RelationalBinaryOperator["InEquality"] = "!=";
|
|
585
722
|
RelationalBinaryOperator["StrictEquality"] = "===";
|
|
586
723
|
RelationalBinaryOperator["StrictInequality"] = "!==";
|
|
587
|
-
})(RelationalBinaryOperator
|
|
724
|
+
})(RelationalBinaryOperator = exports.RelationalBinaryOperator || (exports.RelationalBinaryOperator = {}));
|
|
588
725
|
// 二元运算表达式
|
|
589
726
|
class AbstractBinopExpr extends AbstractExpr {
|
|
590
727
|
constructor(op1, op2, operator) {
|
|
@@ -593,18 +730,43 @@ class AbstractBinopExpr extends AbstractExpr {
|
|
|
593
730
|
this.op2 = op2;
|
|
594
731
|
this.operator = operator;
|
|
595
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Returns the first operand in the binary operation expression.
|
|
735
|
+
* For example, the first operand in `a + b;` is `a`.
|
|
736
|
+
* @returns The first operand in the binary operation expression.
|
|
737
|
+
*/
|
|
596
738
|
getOp1() {
|
|
597
739
|
return this.op1;
|
|
598
740
|
}
|
|
599
741
|
setOp1(newOp1) {
|
|
600
742
|
this.op1 = newOp1;
|
|
601
743
|
}
|
|
744
|
+
/**
|
|
745
|
+
* Returns the second operand in the binary operation expression.
|
|
746
|
+
* For example, the second operand in `a + b;` is `b`.
|
|
747
|
+
* @returns The second operand in the binary operation expression.
|
|
748
|
+
*/
|
|
602
749
|
getOp2() {
|
|
603
750
|
return this.op2;
|
|
604
751
|
}
|
|
605
752
|
setOp2(newOp2) {
|
|
606
753
|
this.op2 = newOp2;
|
|
607
754
|
}
|
|
755
|
+
/**
|
|
756
|
+
* Get the binary operator from the statement.
|
|
757
|
+
* The binary operator can be divided into two categories,
|
|
758
|
+
* one is the normal binary operator and the other is relational binary operator.
|
|
759
|
+
* @returns The binary operator from the statement.
|
|
760
|
+
* @example
|
|
761
|
+
```typescript
|
|
762
|
+
if (expr instanceof AbstractBinopExpr) {
|
|
763
|
+
let op1: Value = expr.getOp1();
|
|
764
|
+
let op2: Value = expr.getOp2();
|
|
765
|
+
let operator: string = expr.getOperator();
|
|
766
|
+
... ...
|
|
767
|
+
}
|
|
768
|
+
```
|
|
769
|
+
*/
|
|
608
770
|
getOperator() {
|
|
609
771
|
return this.operator;
|
|
610
772
|
}
|
|
@@ -625,9 +787,9 @@ class AbstractBinopExpr extends AbstractExpr {
|
|
|
625
787
|
toString() {
|
|
626
788
|
return this.op1 + ' ' + this.operator + ' ' + this.op2;
|
|
627
789
|
}
|
|
628
|
-
inferOpType(op,
|
|
790
|
+
inferOpType(op, arkMethod) {
|
|
629
791
|
if (op instanceof AbstractExpr || op instanceof Ref_1.AbstractRef) {
|
|
630
|
-
TypeInference_1.TypeInference.inferValueType(op,
|
|
792
|
+
TypeInference_1.TypeInference.inferValueType(op, arkMethod);
|
|
631
793
|
}
|
|
632
794
|
}
|
|
633
795
|
setType() {
|
|
@@ -688,12 +850,14 @@ class AbstractBinopExpr extends AbstractExpr {
|
|
|
688
850
|
type = op1Type;
|
|
689
851
|
}
|
|
690
852
|
break;
|
|
853
|
+
default:
|
|
854
|
+
;
|
|
691
855
|
}
|
|
692
856
|
this.type = type;
|
|
693
857
|
}
|
|
694
|
-
inferType(
|
|
695
|
-
this.inferOpType(this.op1,
|
|
696
|
-
this.inferOpType(this.op2,
|
|
858
|
+
inferType(arkMethod) {
|
|
859
|
+
this.inferOpType(this.op1, arkMethod);
|
|
860
|
+
this.inferOpType(this.op2, arkMethod);
|
|
697
861
|
this.setType();
|
|
698
862
|
return this;
|
|
699
863
|
}
|
|
@@ -703,10 +867,10 @@ class ArkConditionExpr extends AbstractBinopExpr {
|
|
|
703
867
|
constructor(op1, op2, operator) {
|
|
704
868
|
super(op1, op2, operator);
|
|
705
869
|
}
|
|
706
|
-
inferType(
|
|
707
|
-
this.inferOpType(this.op1,
|
|
870
|
+
inferType(arkMethod) {
|
|
871
|
+
this.inferOpType(this.op1, arkMethod);
|
|
708
872
|
const op1Type = this.op1.getType();
|
|
709
|
-
if (this.operator
|
|
873
|
+
if (this.operator === RelationalBinaryOperator.InEquality && this.op2 === ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)) {
|
|
710
874
|
if (op1Type instanceof Type_1.StringType) {
|
|
711
875
|
this.op2 = ValueUtil_1.ValueUtil.createStringConst(ValueUtil_1.EMPTY_STRING);
|
|
712
876
|
}
|
|
@@ -718,7 +882,7 @@ class ArkConditionExpr extends AbstractBinopExpr {
|
|
|
718
882
|
}
|
|
719
883
|
}
|
|
720
884
|
else {
|
|
721
|
-
this.inferOpType(this.getOp2(),
|
|
885
|
+
this.inferOpType(this.getOp2(), arkMethod);
|
|
722
886
|
}
|
|
723
887
|
this.type = Type_1.BooleanType.getInstance();
|
|
724
888
|
return this;
|
|
@@ -807,9 +971,9 @@ class ArkCastExpr extends AbstractExpr {
|
|
|
807
971
|
getType() {
|
|
808
972
|
return this.type;
|
|
809
973
|
}
|
|
810
|
-
inferType(
|
|
974
|
+
inferType(arkMethod) {
|
|
811
975
|
var _a;
|
|
812
|
-
const type = (_a = TypeInference_1.TypeInference.inferUnclearedType(this.type,
|
|
976
|
+
const type = (_a = TypeInference_1.TypeInference.inferUnclearedType(this.type, arkMethod.getDeclaringArkClass())) !== null && _a !== void 0 ? _a : this.op.getType();
|
|
813
977
|
if (!TypeInference_1.TypeInference.isUnclearType(type)) {
|
|
814
978
|
this.type = type;
|
|
815
979
|
}
|
|
@@ -866,7 +1030,7 @@ var UnaryOperator;
|
|
|
866
1030
|
UnaryOperator["Neg"] = "-";
|
|
867
1031
|
UnaryOperator["BitwiseNot"] = "~";
|
|
868
1032
|
UnaryOperator["LogicalNot"] = "!";
|
|
869
|
-
})(UnaryOperator
|
|
1033
|
+
})(UnaryOperator = exports.UnaryOperator || (exports.UnaryOperator = {}));
|
|
870
1034
|
// unary operation expression
|
|
871
1035
|
class ArkUnopExpr extends AbstractExpr {
|
|
872
1036
|
constructor(op, operator) {
|
|
@@ -886,6 +1050,10 @@ class ArkUnopExpr extends AbstractExpr {
|
|
|
886
1050
|
getType() {
|
|
887
1051
|
return this.op.getType();
|
|
888
1052
|
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Get the unary operator from the statement, such as `-`,`~`,`!`.
|
|
1055
|
+
* @returns the unary operator of a statement.
|
|
1056
|
+
*/
|
|
889
1057
|
getOperator() {
|
|
890
1058
|
return this.operator;
|
|
891
1059
|
}
|