arkanalyzer 1.0.20 → 1.0.21
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/lib/Config.d.ts +70 -70
- package/lib/Config.js +198 -198
- package/lib/Scene.d.ts +316 -316
- package/lib/Scene.js +1316 -1316
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
- package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
- package/lib/callgraph/common/Statistics.d.ts +57 -57
- package/lib/callgraph/common/Statistics.js +228 -228
- package/lib/callgraph/model/CallGraph.d.ts +96 -96
- package/lib/callgraph/model/CallGraph.js +354 -354
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
- package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
- package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
- package/lib/callgraph/pointerAnalysis/Context.js +155 -155
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
- package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
- package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
- package/lib/core/base/Constant.d.ts +48 -48
- package/lib/core/base/Constant.js +103 -103
- package/lib/core/base/Decorator.d.ts +15 -15
- package/lib/core/base/Decorator.js +46 -46
- package/lib/core/base/DefUseChain.d.ts +8 -8
- package/lib/core/base/DefUseChain.js +25 -25
- package/lib/core/base/Expr.d.ts +340 -340
- package/lib/core/base/Expr.js +917 -917
- package/lib/core/base/Local.d.ts +104 -104
- package/lib/core/base/Local.js +176 -176
- package/lib/core/base/Position.d.ts +30 -30
- package/lib/core/base/Position.js +147 -147
- package/lib/core/base/Ref.d.ts +173 -173
- package/lib/core/base/Ref.js +374 -374
- package/lib/core/base/Stmt.d.ts +237 -237
- package/lib/core/base/Stmt.js +525 -525
- package/lib/core/base/Trap.d.ts +8 -8
- package/lib/core/base/Trap.js +30 -30
- package/lib/core/base/Type.d.ts +308 -308
- package/lib/core/base/Type.js +639 -639
- package/lib/core/base/TypeExpr.d.ts +71 -71
- package/lib/core/base/TypeExpr.js +155 -155
- package/lib/core/base/Value.d.ts +32 -32
- package/lib/core/base/Value.js +16 -16
- package/lib/core/common/ArkError.d.ts +14 -14
- package/lib/core/common/ArkError.js +28 -28
- package/lib/core/common/ArkIRTransformer.d.ts +67 -67
- package/lib/core/common/ArkIRTransformer.js +690 -690
- package/lib/core/common/ArkValueTransformer.d.ts +89 -89
- package/lib/core/common/ArkValueTransformer.js +1478 -1478
- package/lib/core/common/Builtin.d.ts +36 -36
- package/lib/core/common/Builtin.js +81 -81
- package/lib/core/common/Const.d.ts +21 -21
- package/lib/core/common/Const.js +43 -43
- package/lib/core/common/DummyMainCreater.d.ts +46 -46
- package/lib/core/common/DummyMainCreater.js +319 -319
- package/lib/core/common/EtsConst.d.ts +73 -73
- package/lib/core/common/EtsConst.js +1021 -1021
- package/lib/core/common/ExprUseReplacer.d.ts +21 -21
- package/lib/core/common/ExprUseReplacer.js +124 -124
- package/lib/core/common/IRInference.d.ts +36 -36
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +651 -648
- package/lib/core/common/IRUtils.d.ts +18 -18
- package/lib/core/common/IRUtils.js +141 -141
- package/lib/core/common/ModelUtils.d.ts +70 -70
- package/lib/core/common/ModelUtils.js +712 -712
- package/lib/core/common/RefUseReplacer.d.ts +13 -13
- package/lib/core/common/RefUseReplacer.js +52 -52
- package/lib/core/common/SdkUtils.d.ts +8 -8
- package/lib/core/common/SdkUtils.js +105 -105
- package/lib/core/common/StmtDefReplacer.d.ts +12 -12
- package/lib/core/common/StmtDefReplacer.js +41 -41
- package/lib/core/common/StmtUseReplacer.d.ts +16 -16
- package/lib/core/common/StmtUseReplacer.js +108 -108
- package/lib/core/common/TSConst.d.ts +18 -18
- package/lib/core/common/TSConst.js +36 -36
- package/lib/core/common/TypeInference.d.ts +102 -102
- package/lib/core/common/TypeInference.js +748 -748
- package/lib/core/common/ValueUtil.d.ts +12 -12
- package/lib/core/common/ValueUtil.js +54 -54
- package/lib/core/common/VisibleValue.d.ts +36 -36
- package/lib/core/common/VisibleValue.js +212 -212
- package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
- package/lib/core/dataflow/DataflowProblem.js +20 -20
- package/lib/core/dataflow/DataflowResult.d.ts +7 -7
- package/lib/core/dataflow/DataflowResult.js +26 -26
- package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
- package/lib/core/dataflow/DataflowSolver.js +307 -307
- package/lib/core/dataflow/Edge.d.ts +11 -11
- package/lib/core/dataflow/Edge.js +31 -31
- package/lib/core/dataflow/Fact.d.ts +6 -6
- package/lib/core/dataflow/Fact.js +24 -24
- package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
- package/lib/core/dataflow/GenericDataFlow.js +109 -109
- package/lib/core/dataflow/ReachingDef.d.ts +62 -62
- package/lib/core/dataflow/ReachingDef.js +168 -168
- package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
- package/lib/core/dataflow/UndefinedVariable.js +288 -288
- package/lib/core/dataflow/Util.d.ts +9 -9
- package/lib/core/dataflow/Util.js +64 -64
- package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
- package/lib/core/graph/BaseExplicitGraph.js +157 -157
- package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
- package/lib/core/graph/BaseImplicitGraph.js +78 -78
- package/lib/core/graph/BasicBlock.d.ts +104 -104
- package/lib/core/graph/BasicBlock.js +280 -280
- package/lib/core/graph/Cfg.d.ts +59 -59
- package/lib/core/graph/Cfg.js +282 -282
- package/lib/core/graph/DependsGraph.d.ts +35 -35
- package/lib/core/graph/DependsGraph.js +87 -87
- package/lib/core/graph/DominanceFinder.d.ts +15 -15
- package/lib/core/graph/DominanceFinder.js +121 -121
- package/lib/core/graph/DominanceTree.d.ts +12 -12
- package/lib/core/graph/DominanceTree.js +70 -70
- package/lib/core/graph/GraphTraits.d.ts +7 -7
- package/lib/core/graph/GraphTraits.js +16 -16
- package/lib/core/graph/Scc.d.ts +61 -61
- package/lib/core/graph/Scc.js +222 -222
- package/lib/core/graph/ViewTree.d.ts +114 -114
- package/lib/core/graph/ViewTree.js +16 -16
- package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
- package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
- package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
- package/lib/core/graph/builder/ConditionBuilder.js +252 -252
- package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
- package/lib/core/graph/builder/LoopBuilder.js +251 -251
- package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
- package/lib/core/graph/builder/SwitchBuilder.js +152 -152
- package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
- package/lib/core/graph/builder/TrapBuilder.js +272 -272
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
- package/lib/core/graph/builder/ViewTreeBuilder.js +1055 -1055
- package/lib/core/model/ArkBaseModel.d.ts +59 -59
- package/lib/core/model/ArkBaseModel.js +274 -274
- package/lib/core/model/ArkBody.d.ts +24 -24
- package/lib/core/model/ArkBody.js +65 -65
- package/lib/core/model/ArkClass.d.ts +206 -206
- package/lib/core/model/ArkClass.js +439 -439
- package/lib/core/model/ArkExport.d.ts +72 -72
- package/lib/core/model/ArkExport.js +147 -147
- package/lib/core/model/ArkField.d.ts +62 -62
- package/lib/core/model/ArkField.js +113 -113
- package/lib/core/model/ArkFile.d.ts +131 -131
- package/lib/core/model/ArkFile.js +267 -267
- package/lib/core/model/ArkImport.d.ts +44 -44
- package/lib/core/model/ArkImport.js +108 -108
- package/lib/core/model/ArkMetadata.d.ts +31 -31
- package/lib/core/model/ArkMetadata.js +55 -55
- package/lib/core/model/ArkMethod.d.ts +261 -261
- package/lib/core/model/ArkMethod.js +592 -592
- package/lib/core/model/ArkNamespace.d.ts +66 -66
- package/lib/core/model/ArkNamespace.js +209 -209
- package/lib/core/model/ArkSignature.d.ts +162 -162
- package/lib/core/model/ArkSignature.js +379 -379
- package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
- package/lib/core/model/builder/ArkClassBuilder.js +454 -454
- package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
- package/lib/core/model/builder/ArkExportBuilder.js +210 -210
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
- package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
- package/lib/core/model/builder/ArkFileBuilder.js +165 -165
- package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
- package/lib/core/model/builder/ArkImportBuilder.js +128 -128
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
- package/lib/core/model/builder/ArkMethodBuilder.js +486 -486
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
- package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
- package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +542 -371
- package/lib/core/model/builder/builderUtils.d.ts +18 -18
- package/lib/core/model/builder/builderUtils.js +558 -558
- package/lib/index.d.ts +82 -80
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +201 -196
- package/lib/save/ArkStream.d.ts +23 -23
- package/lib/save/ArkStream.js +83 -83
- package/lib/save/DotPrinter.d.ts +43 -43
- package/lib/save/DotPrinter.js +170 -170
- package/lib/save/GraphPrinter.d.ts +16 -16
- package/lib/save/GraphPrinter.js +134 -134
- package/lib/save/JsonPrinter.d.ts +30 -30
- package/lib/save/JsonPrinter.js +580 -580
- package/lib/save/Printer.d.ts +12 -12
- package/lib/save/Printer.js +27 -27
- package/lib/save/PrinterBuilder.d.ts +53 -53
- package/lib/save/PrinterBuilder.js +145 -145
- package/lib/save/ViewTreePrinter.d.ts +14 -14
- package/lib/save/ViewTreePrinter.js +123 -123
- package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
- package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
- package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
- package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
- package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
- package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
- package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
- package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
- package/lib/save/base/BasePrinter.d.ts +23 -23
- package/lib/save/base/BasePrinter.js +70 -70
- package/lib/save/base/ExportPrinter.d.ts +8 -8
- package/lib/save/base/ExportPrinter.js +67 -67
- package/lib/save/base/ImportPrinter.d.ts +9 -9
- package/lib/save/base/ImportPrinter.js +92 -92
- package/lib/save/base/PrinterUtils.d.ts +24 -24
- package/lib/save/base/PrinterUtils.js +208 -208
- package/lib/save/serializeArkIR.d.ts +8 -8
- package/lib/save/serializeArkIR.js +294 -294
- package/lib/save/source/SourceBase.d.ts +22 -22
- package/lib/save/source/SourceBase.js +64 -64
- package/lib/save/source/SourceBody.d.ts +58 -58
- package/lib/save/source/SourceBody.js +296 -296
- package/lib/save/source/SourceClass.d.ts +25 -25
- package/lib/save/source/SourceClass.js +187 -187
- package/lib/save/source/SourceField.d.ts +13 -13
- package/lib/save/source/SourceField.js +73 -73
- package/lib/save/source/SourceFilePrinter.d.ts +12 -12
- package/lib/save/source/SourceFilePrinter.js +69 -69
- package/lib/save/source/SourceMethod.d.ts +22 -22
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +196 -193
- package/lib/save/source/SourceNamespace.d.ts +11 -11
- package/lib/save/source/SourceNamespace.js +83 -83
- package/lib/save/source/SourceStmt.d.ts +178 -178
- package/lib/save/source/SourceStmt.js +838 -838
- package/lib/save/source/SourceTransformer.d.ts +46 -46
- package/lib/save/source/SourceTransformer.js +446 -446
- package/lib/transformer/FunctionTransformer.d.ts +2 -2
- package/lib/transformer/FunctionTransformer.js +17 -17
- package/lib/transformer/SceneTransformer.d.ts +2 -2
- package/lib/transformer/SceneTransformer.js +17 -17
- package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
- package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
- package/lib/transformer/Transformer.d.ts +6 -6
- package/lib/transformer/Transformer.js +22 -22
- package/lib/utils/AstTreeUtils.d.ts +4 -4
- package/lib/utils/AstTreeUtils.js +26 -26
- package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
- package/lib/utils/CfgStructualAnalysis.js +1277 -1277
- package/lib/utils/FileUtils.d.ts +18 -18
- package/lib/utils/FileUtils.js +135 -135
- package/lib/utils/SparseBitVector.d.ts +100 -100
- package/lib/utils/SparseBitVector.js +445 -445
- package/lib/utils/callGraphUtils.d.ts +30 -30
- package/lib/utils/callGraphUtils.js +205 -205
- package/lib/utils/crypto_utils.d.ts +5 -5
- package/lib/utils/crypto_utils.js +57 -57
- package/lib/utils/entryMethodUtils.d.ts +13 -13
- package/lib/utils/entryMethodUtils.js +110 -110
- package/lib/utils/getAllFiles.d.ts +9 -9
- package/lib/utils/getAllFiles.js +90 -90
- package/lib/utils/json5parser.d.ts +6 -6
- package/lib/utils/json5parser.js +146 -146
- package/lib/utils/logger.d.ts +18 -18
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +97 -90
- package/lib/utils/pathTransfer.d.ts +1 -1
- package/lib/utils/pathTransfer.js +25 -25
- package/node_modules/json5/lib/cli.js +0 -0
- package/node_modules/ohos-typescript/bin/tsc +0 -0
- package/node_modules/ohos-typescript/bin/tsserver +0 -0
- package/package.json +3 -3
package/lib/core/base/Expr.js
CHANGED
|
@@ -1,917 +1,917 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AliasTypeExpr = exports.ArkUnopExpr = exports.UnaryOperator = exports.ArkPhiExpr = exports.ArkCastExpr = exports.ArkInstanceOfExpr = exports.ArkTypeOfExpr = exports.ArkNormalBinopExpr = exports.ArkConditionExpr = exports.AbstractBinopExpr = exports.RelationalBinaryOperator = exports.NormalBinaryOperator = exports.ArkYieldExpr = exports.ArkAwaitExpr = exports.ArkDeleteExpr = exports.ArkNewArrayExpr = exports.ArkNewExpr = exports.ArkPtrInvokeExpr = exports.ArkStaticInvokeExpr = exports.ArkInstanceInvokeExpr = exports.AbstractInvokeExpr = exports.AbstractExpr = void 0;
|
|
18
|
-
const TypeInference_1 = require("../common/TypeInference");
|
|
19
|
-
const Local_1 = require("./Local");
|
|
20
|
-
const Type_1 = require("./Type");
|
|
21
|
-
const Ref_1 = require("./Ref");
|
|
22
|
-
const ValueUtil_1 = require("../common/ValueUtil");
|
|
23
|
-
const ArkMethod_1 = require("../model/ArkMethod");
|
|
24
|
-
const Const_1 = require("../common/Const");
|
|
25
|
-
const IRInference_1 = require("../common/IRInference");
|
|
26
|
-
const ArkImport_1 = require("../model/ArkImport");
|
|
27
|
-
const ArkClass_1 = require("../model/ArkClass");
|
|
28
|
-
const ArkField_1 = require("../model/ArkField");
|
|
29
|
-
/**
|
|
30
|
-
* @category core/base/expr
|
|
31
|
-
*/
|
|
32
|
-
class AbstractExpr {
|
|
33
|
-
inferType(arkMethod) {
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.AbstractExpr = AbstractExpr;
|
|
38
|
-
class AbstractInvokeExpr extends AbstractExpr {
|
|
39
|
-
constructor(methodSignature, args, realGenericTypes) {
|
|
40
|
-
super();
|
|
41
|
-
this.methodSignature = methodSignature;
|
|
42
|
-
this.args = args;
|
|
43
|
-
this.realGenericTypes = realGenericTypes;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get method Signature. The method signature is consist of ClassSignature and MethodSubSignature.
|
|
47
|
-
* It is the unique flag of a method. It is usually used to compose a expression string in ArkIRTransformer.
|
|
48
|
-
* @returns The class method signature, such as ArkStaticInvokeExpr.
|
|
49
|
-
* @example
|
|
50
|
-
* 1. 3AC information composed of getMethodSignature ().
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
let strs: string[] = [];
|
|
54
|
-
strs.push('staticinvoke <');
|
|
55
|
-
strs.push(this.getMethodSignature().toString());
|
|
56
|
-
strs.push('>(');
|
|
57
|
-
```
|
|
58
|
-
*/
|
|
59
|
-
getMethodSignature() {
|
|
60
|
-
return this.methodSignature;
|
|
61
|
-
}
|
|
62
|
-
setMethodSignature(newMethodSignature) {
|
|
63
|
-
this.methodSignature = newMethodSignature;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Returns an argument used in the expression according to its index.
|
|
67
|
-
* @param index - the index of the argument.
|
|
68
|
-
* @returns An argument used in the expression.
|
|
69
|
-
*/
|
|
70
|
-
getArg(index) {
|
|
71
|
-
return this.args[index];
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Returns an **array** of arguments used in the expression.
|
|
75
|
-
* @returns An **array** of arguments used in the expression.
|
|
76
|
-
* @example
|
|
77
|
-
* 1. get args number.
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
const argsNum = expr.getArgs().length;
|
|
81
|
-
if (argsNum < 5) {
|
|
82
|
-
... ...
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
2. iterate arg based on expression
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
for (const arg of this.getArgs()) {
|
|
90
|
-
strs.push(arg.toString());
|
|
91
|
-
strs.push(', ');
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
*/
|
|
95
|
-
getArgs() {
|
|
96
|
-
return this.args;
|
|
97
|
-
}
|
|
98
|
-
setArgs(newArgs) {
|
|
99
|
-
this.args = newArgs;
|
|
100
|
-
}
|
|
101
|
-
getType() {
|
|
102
|
-
const type = this.methodSignature.getType();
|
|
103
|
-
if (this.realGenericTypes) {
|
|
104
|
-
return TypeInference_1.TypeInference.replaceTypeWithReal(type, this.realGenericTypes);
|
|
105
|
-
}
|
|
106
|
-
return type;
|
|
107
|
-
}
|
|
108
|
-
getRealGenericTypes() {
|
|
109
|
-
return this.realGenericTypes;
|
|
110
|
-
}
|
|
111
|
-
setRealGenericTypes(realTypes) {
|
|
112
|
-
if (realTypes) {
|
|
113
|
-
this.realGenericTypes = realTypes;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
getUses() {
|
|
117
|
-
let uses = [];
|
|
118
|
-
uses.push(...this.args);
|
|
119
|
-
for (const arg of this.args) {
|
|
120
|
-
uses.push(...arg.getUses());
|
|
121
|
-
}
|
|
122
|
-
return uses;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.AbstractInvokeExpr = AbstractInvokeExpr;
|
|
126
|
-
class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
127
|
-
constructor(base, methodSignature, args, realGenericTypes) {
|
|
128
|
-
super(methodSignature, args, realGenericTypes);
|
|
129
|
-
this.base = base;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Returns the local of the instance of invoke expression.
|
|
133
|
-
* @returns The local of the invoke expression's instance..
|
|
134
|
-
*/
|
|
135
|
-
getBase() {
|
|
136
|
-
return this.base;
|
|
137
|
-
}
|
|
138
|
-
setBase(newBase) {
|
|
139
|
-
this.base = newBase;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Returns an **array** of values used in this invoke expression,
|
|
143
|
-
* including all arguments and values each arguments used.
|
|
144
|
-
* For {@link ArkInstanceInvokeExpr}, the return also contains the caller base and uses of base.
|
|
145
|
-
* @returns An **array** of arguments used in the invoke expression.
|
|
146
|
-
*/
|
|
147
|
-
getUses() {
|
|
148
|
-
let uses = [];
|
|
149
|
-
uses.push(this.base);
|
|
150
|
-
uses.push(...this.base.getUses());
|
|
151
|
-
uses.push(...this.getArgs());
|
|
152
|
-
for (const arg of this.getArgs()) {
|
|
153
|
-
uses.push(...arg.getUses());
|
|
154
|
-
}
|
|
155
|
-
return uses;
|
|
156
|
-
}
|
|
157
|
-
toString() {
|
|
158
|
-
let strs = [];
|
|
159
|
-
strs.push('instanceinvoke ');
|
|
160
|
-
strs.push(this.base.toString());
|
|
161
|
-
strs.push('.<');
|
|
162
|
-
strs.push(this.getMethodSignature().toString());
|
|
163
|
-
strs.push('>(');
|
|
164
|
-
if (this.getArgs().length > 0) {
|
|
165
|
-
for (const arg of this.getArgs()) {
|
|
166
|
-
strs.push(arg.toString());
|
|
167
|
-
strs.push(', ');
|
|
168
|
-
}
|
|
169
|
-
strs.pop();
|
|
170
|
-
}
|
|
171
|
-
strs.push(')');
|
|
172
|
-
return strs.join('');
|
|
173
|
-
}
|
|
174
|
-
inferType(arkMethod) {
|
|
175
|
-
return IRInference_1.IRInference.inferInstanceInvokeExpr(this, arkMethod);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.ArkInstanceInvokeExpr = ArkInstanceInvokeExpr;
|
|
179
|
-
class ArkStaticInvokeExpr extends AbstractInvokeExpr {
|
|
180
|
-
constructor(methodSignature, args, realGenericTypes) {
|
|
181
|
-
super(methodSignature, args, realGenericTypes);
|
|
182
|
-
}
|
|
183
|
-
toString() {
|
|
184
|
-
let strs = [];
|
|
185
|
-
strs.push('staticinvoke <');
|
|
186
|
-
strs.push(this.getMethodSignature().toString());
|
|
187
|
-
strs.push('>(');
|
|
188
|
-
if (this.getArgs().length > 0) {
|
|
189
|
-
for (const arg of this.getArgs()) {
|
|
190
|
-
strs.push(arg.toString());
|
|
191
|
-
strs.push(', ');
|
|
192
|
-
}
|
|
193
|
-
strs.pop();
|
|
194
|
-
}
|
|
195
|
-
strs.push(')');
|
|
196
|
-
return strs.join('');
|
|
197
|
-
}
|
|
198
|
-
inferType(arkMethod) {
|
|
199
|
-
return IRInference_1.IRInference.inferStaticInvokeExpr(this, arkMethod);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.ArkStaticInvokeExpr = ArkStaticInvokeExpr;
|
|
203
|
-
class ArkPtrInvokeExpr extends AbstractInvokeExpr {
|
|
204
|
-
constructor(methodSignature, ptr, args, realGenericTypes) {
|
|
205
|
-
super(methodSignature, args, realGenericTypes);
|
|
206
|
-
this.funPtrLocal = ptr;
|
|
207
|
-
}
|
|
208
|
-
setFunPtrLocal(ptr) {
|
|
209
|
-
this.funPtrLocal = ptr;
|
|
210
|
-
}
|
|
211
|
-
getFuncPtrLocal() {
|
|
212
|
-
return this.funPtrLocal;
|
|
213
|
-
}
|
|
214
|
-
toString() {
|
|
215
|
-
let strs = [];
|
|
216
|
-
strs.push('ptrinvoke <');
|
|
217
|
-
strs.push(this.getMethodSignature().toString());
|
|
218
|
-
strs.push('>(');
|
|
219
|
-
if (this.getArgs().length > 0) {
|
|
220
|
-
for (const arg of this.getArgs()) {
|
|
221
|
-
strs.push(arg.toString());
|
|
222
|
-
strs.push(', ');
|
|
223
|
-
}
|
|
224
|
-
strs.pop();
|
|
225
|
-
}
|
|
226
|
-
strs.push(')');
|
|
227
|
-
return strs.join('');
|
|
228
|
-
}
|
|
229
|
-
inferType(arkMethod) {
|
|
230
|
-
// TODO: handle type inference
|
|
231
|
-
return this;
|
|
232
|
-
}
|
|
233
|
-
getUses() {
|
|
234
|
-
let uses = [];
|
|
235
|
-
uses.push(this.getFuncPtrLocal());
|
|
236
|
-
uses.push(...this.getArgs());
|
|
237
|
-
for (const arg of this.getArgs()) {
|
|
238
|
-
uses.push(...arg.getUses());
|
|
239
|
-
}
|
|
240
|
-
return uses;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.ArkPtrInvokeExpr = ArkPtrInvokeExpr;
|
|
244
|
-
class ArkNewExpr extends AbstractExpr {
|
|
245
|
-
constructor(classType) {
|
|
246
|
-
super();
|
|
247
|
-
this.classType = classType;
|
|
248
|
-
}
|
|
249
|
-
getClassType() {
|
|
250
|
-
return this.classType;
|
|
251
|
-
}
|
|
252
|
-
getUses() {
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
getType() {
|
|
256
|
-
return this.classType;
|
|
257
|
-
}
|
|
258
|
-
toString() {
|
|
259
|
-
return 'new ' + this.classType;
|
|
260
|
-
}
|
|
261
|
-
inferType(arkMethod) {
|
|
262
|
-
const classSignature = this.classType.getClassSignature();
|
|
263
|
-
if (classSignature.getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
264
|
-
const className = classSignature.getClassName();
|
|
265
|
-
let type = TypeInference_1.TypeInference.inferUnclearRefName(className, arkMethod.getDeclaringArkClass());
|
|
266
|
-
if (type && type instanceof Type_1.ClassType) {
|
|
267
|
-
let realGenericTypes = this.classType.getRealGenericTypes();
|
|
268
|
-
this.classType = realGenericTypes ? new Type_1.ClassType(type.getClassSignature(), realGenericTypes) : type;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
exports.ArkNewExpr = ArkNewExpr;
|
|
275
|
-
class ArkNewArrayExpr extends AbstractExpr {
|
|
276
|
-
constructor(baseType, size, fromLiteral = false) {
|
|
277
|
-
super();
|
|
278
|
-
this.baseType = baseType;
|
|
279
|
-
this.size = size;
|
|
280
|
-
this.fromLiteral = fromLiteral;
|
|
281
|
-
}
|
|
282
|
-
getSize() {
|
|
283
|
-
return this.size;
|
|
284
|
-
}
|
|
285
|
-
setSize(newSize) {
|
|
286
|
-
this.size = newSize;
|
|
287
|
-
}
|
|
288
|
-
getType() {
|
|
289
|
-
return new Type_1.ArrayType(this.baseType, 1);
|
|
290
|
-
}
|
|
291
|
-
getBaseType() {
|
|
292
|
-
return this.baseType;
|
|
293
|
-
}
|
|
294
|
-
setBaseType(newType) {
|
|
295
|
-
this.baseType = newType;
|
|
296
|
-
}
|
|
297
|
-
isFromLiteral() {
|
|
298
|
-
return this.fromLiteral;
|
|
299
|
-
}
|
|
300
|
-
inferType(arkMethod) {
|
|
301
|
-
const type = TypeInference_1.TypeInference.inferUnclearedType(this.baseType, arkMethod.getDeclaringArkClass());
|
|
302
|
-
if (type) {
|
|
303
|
-
this.baseType = type;
|
|
304
|
-
}
|
|
305
|
-
return this;
|
|
306
|
-
}
|
|
307
|
-
getUses() {
|
|
308
|
-
let uses = [this.size];
|
|
309
|
-
uses.push(...this.size.getUses());
|
|
310
|
-
return uses;
|
|
311
|
-
}
|
|
312
|
-
toString() {
|
|
313
|
-
return 'newarray (' + this.baseType + ')[' + this.size + ']';
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
exports.ArkNewArrayExpr = ArkNewArrayExpr;
|
|
317
|
-
class ArkDeleteExpr extends AbstractExpr {
|
|
318
|
-
constructor(field) {
|
|
319
|
-
super();
|
|
320
|
-
this.field = field;
|
|
321
|
-
}
|
|
322
|
-
getField() {
|
|
323
|
-
return this.field;
|
|
324
|
-
}
|
|
325
|
-
setField(newField) {
|
|
326
|
-
this.field = newField;
|
|
327
|
-
}
|
|
328
|
-
getType() {
|
|
329
|
-
return Type_1.BooleanType.getInstance();
|
|
330
|
-
}
|
|
331
|
-
getUses() {
|
|
332
|
-
const uses = [];
|
|
333
|
-
uses.push(this.field);
|
|
334
|
-
uses.push(...this.field.getUses());
|
|
335
|
-
return uses;
|
|
336
|
-
}
|
|
337
|
-
toString() {
|
|
338
|
-
return 'delete ' + this.field;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.ArkDeleteExpr = ArkDeleteExpr;
|
|
342
|
-
class ArkAwaitExpr extends AbstractExpr {
|
|
343
|
-
constructor(promise) {
|
|
344
|
-
super();
|
|
345
|
-
this.promise = promise;
|
|
346
|
-
}
|
|
347
|
-
getPromise() {
|
|
348
|
-
return this.promise;
|
|
349
|
-
}
|
|
350
|
-
setPromise(newPromise) {
|
|
351
|
-
this.promise = newPromise;
|
|
352
|
-
}
|
|
353
|
-
getType() {
|
|
354
|
-
var _a, _b;
|
|
355
|
-
const type = this.promise.getType();
|
|
356
|
-
if (type instanceof Type_1.UnclearReferenceType) {
|
|
357
|
-
return type.getGenericTypes()[0];
|
|
358
|
-
}
|
|
359
|
-
else if (type instanceof Type_1.ClassType) {
|
|
360
|
-
return (_b = (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : type;
|
|
361
|
-
}
|
|
362
|
-
return type;
|
|
363
|
-
}
|
|
364
|
-
inferType(arkMethod) {
|
|
365
|
-
TypeInference_1.TypeInference.inferValueType(this.promise, arkMethod);
|
|
366
|
-
return this;
|
|
367
|
-
}
|
|
368
|
-
getUses() {
|
|
369
|
-
const uses = [];
|
|
370
|
-
uses.push(this.promise);
|
|
371
|
-
uses.push(...this.promise.getUses());
|
|
372
|
-
return uses;
|
|
373
|
-
}
|
|
374
|
-
toString() {
|
|
375
|
-
const str = 'await ' + this.promise;
|
|
376
|
-
return str;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
exports.ArkAwaitExpr = ArkAwaitExpr;
|
|
380
|
-
class ArkYieldExpr extends AbstractExpr {
|
|
381
|
-
constructor(yieldValue) {
|
|
382
|
-
super();
|
|
383
|
-
this.yieldValue = yieldValue;
|
|
384
|
-
}
|
|
385
|
-
getYieldValue() {
|
|
386
|
-
return this.yieldValue;
|
|
387
|
-
}
|
|
388
|
-
setYieldValue(newYieldValue) {
|
|
389
|
-
this.yieldValue = newYieldValue;
|
|
390
|
-
}
|
|
391
|
-
getType() {
|
|
392
|
-
return this.yieldValue.getType();
|
|
393
|
-
}
|
|
394
|
-
getUses() {
|
|
395
|
-
const uses = [];
|
|
396
|
-
uses.push(this.yieldValue);
|
|
397
|
-
uses.push(...this.yieldValue.getUses());
|
|
398
|
-
return uses;
|
|
399
|
-
}
|
|
400
|
-
toString() {
|
|
401
|
-
const str = 'yield ' + this.yieldValue;
|
|
402
|
-
return str;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
exports.ArkYieldExpr = ArkYieldExpr;
|
|
406
|
-
var NormalBinaryOperator;
|
|
407
|
-
(function (NormalBinaryOperator) {
|
|
408
|
-
// TODO: unfold it
|
|
409
|
-
NormalBinaryOperator["NullishCoalescing"] = "??";
|
|
410
|
-
// arithmetic
|
|
411
|
-
NormalBinaryOperator["Exponentiation"] = "**";
|
|
412
|
-
NormalBinaryOperator["Division"] = "/";
|
|
413
|
-
NormalBinaryOperator["Addition"] = "+";
|
|
414
|
-
NormalBinaryOperator["Subtraction"] = "-";
|
|
415
|
-
NormalBinaryOperator["Multiplication"] = "*";
|
|
416
|
-
NormalBinaryOperator["Remainder"] = "%";
|
|
417
|
-
// shift
|
|
418
|
-
NormalBinaryOperator["LeftShift"] = "<<";
|
|
419
|
-
NormalBinaryOperator["RightShift"] = ">>";
|
|
420
|
-
NormalBinaryOperator["UnsignedRightShift"] = ">>>";
|
|
421
|
-
// Bitwise
|
|
422
|
-
NormalBinaryOperator["BitwiseAnd"] = "&";
|
|
423
|
-
NormalBinaryOperator["BitwiseOr"] = "|";
|
|
424
|
-
NormalBinaryOperator["BitwiseXor"] = "^";
|
|
425
|
-
// Logical
|
|
426
|
-
NormalBinaryOperator["LogicalAnd"] = "&&";
|
|
427
|
-
NormalBinaryOperator["LogicalOr"] = "||";
|
|
428
|
-
})(NormalBinaryOperator = exports.NormalBinaryOperator || (exports.NormalBinaryOperator = {}));
|
|
429
|
-
var RelationalBinaryOperator;
|
|
430
|
-
(function (RelationalBinaryOperator) {
|
|
431
|
-
RelationalBinaryOperator["LessThan"] = "<";
|
|
432
|
-
RelationalBinaryOperator["LessThanOrEqual"] = "<=";
|
|
433
|
-
RelationalBinaryOperator["GreaterThan"] = ">";
|
|
434
|
-
RelationalBinaryOperator["GreaterThanOrEqual"] = ">=";
|
|
435
|
-
RelationalBinaryOperator["Equality"] = "==";
|
|
436
|
-
RelationalBinaryOperator["InEquality"] = "!=";
|
|
437
|
-
RelationalBinaryOperator["StrictEquality"] = "===";
|
|
438
|
-
RelationalBinaryOperator["StrictInequality"] = "!==";
|
|
439
|
-
RelationalBinaryOperator["isPropertyOf"] = "in";
|
|
440
|
-
})(RelationalBinaryOperator = exports.RelationalBinaryOperator || (exports.RelationalBinaryOperator = {}));
|
|
441
|
-
// 二元运算表达式
|
|
442
|
-
class AbstractBinopExpr extends AbstractExpr {
|
|
443
|
-
constructor(op1, op2, operator) {
|
|
444
|
-
super();
|
|
445
|
-
this.op1 = op1;
|
|
446
|
-
this.op2 = op2;
|
|
447
|
-
this.operator = operator;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Returns the first operand in the binary operation expression.
|
|
451
|
-
* For example, the first operand in `a + b;` is `a`.
|
|
452
|
-
* @returns The first operand in the binary operation expression.
|
|
453
|
-
*/
|
|
454
|
-
getOp1() {
|
|
455
|
-
return this.op1;
|
|
456
|
-
}
|
|
457
|
-
setOp1(newOp1) {
|
|
458
|
-
this.op1 = newOp1;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Returns the second operand in the binary operation expression.
|
|
462
|
-
* For example, the second operand in `a + b;` is `b`.
|
|
463
|
-
* @returns The second operand in the binary operation expression.
|
|
464
|
-
*/
|
|
465
|
-
getOp2() {
|
|
466
|
-
return this.op2;
|
|
467
|
-
}
|
|
468
|
-
setOp2(newOp2) {
|
|
469
|
-
this.op2 = newOp2;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Get the binary operator from the statement.
|
|
473
|
-
* The binary operator can be divided into two categories,
|
|
474
|
-
* one is the normal binary operator and the other is relational binary operator.
|
|
475
|
-
* @returns The binary operator from the statement.
|
|
476
|
-
* @example
|
|
477
|
-
```typescript
|
|
478
|
-
if (expr instanceof AbstractBinopExpr) {
|
|
479
|
-
let op1: Value = expr.getOp1();
|
|
480
|
-
let op2: Value = expr.getOp2();
|
|
481
|
-
let operator: string = expr.getOperator();
|
|
482
|
-
... ...
|
|
483
|
-
}
|
|
484
|
-
```
|
|
485
|
-
*/
|
|
486
|
-
getOperator() {
|
|
487
|
-
return this.operator;
|
|
488
|
-
}
|
|
489
|
-
getType() {
|
|
490
|
-
if (!this.type) {
|
|
491
|
-
this.setType();
|
|
492
|
-
}
|
|
493
|
-
return this.type;
|
|
494
|
-
}
|
|
495
|
-
getUses() {
|
|
496
|
-
let uses = [];
|
|
497
|
-
uses.push(this.op1);
|
|
498
|
-
uses.push(...this.op1.getUses());
|
|
499
|
-
uses.push(this.op2);
|
|
500
|
-
uses.push(...this.op2.getUses());
|
|
501
|
-
return uses;
|
|
502
|
-
}
|
|
503
|
-
toString() {
|
|
504
|
-
return this.op1 + ' ' + this.operator + ' ' + this.op2;
|
|
505
|
-
}
|
|
506
|
-
inferOpType(op, arkMethod) {
|
|
507
|
-
if (op instanceof AbstractExpr || op instanceof Ref_1.AbstractRef) {
|
|
508
|
-
TypeInference_1.TypeInference.inferValueType(op, arkMethod);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
setType() {
|
|
512
|
-
let op1Type = this.op1.getType();
|
|
513
|
-
let op2Type = this.op2.getType();
|
|
514
|
-
if (op1Type instanceof Type_1.UnionType) {
|
|
515
|
-
op1Type = op1Type.getCurrType();
|
|
516
|
-
}
|
|
517
|
-
if (op2Type instanceof Type_1.UnionType) {
|
|
518
|
-
op2Type = op2Type.getCurrType();
|
|
519
|
-
}
|
|
520
|
-
let type = Type_1.UnknownType.getInstance();
|
|
521
|
-
switch (this.operator) {
|
|
522
|
-
case '+':
|
|
523
|
-
if (op1Type === Type_1.StringType.getInstance() || op2Type === Type_1.StringType.getInstance()) {
|
|
524
|
-
type = Type_1.StringType.getInstance();
|
|
525
|
-
}
|
|
526
|
-
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
527
|
-
type = Type_1.NumberType.getInstance();
|
|
528
|
-
}
|
|
529
|
-
break;
|
|
530
|
-
case '-':
|
|
531
|
-
case '*':
|
|
532
|
-
case '/':
|
|
533
|
-
case '%':
|
|
534
|
-
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
535
|
-
type = Type_1.NumberType.getInstance();
|
|
536
|
-
}
|
|
537
|
-
break;
|
|
538
|
-
case '!=':
|
|
539
|
-
case '!==':
|
|
540
|
-
case '<':
|
|
541
|
-
case '>':
|
|
542
|
-
case '<=':
|
|
543
|
-
case '>=':
|
|
544
|
-
case '&&':
|
|
545
|
-
case '||':
|
|
546
|
-
case '==':
|
|
547
|
-
case '===':
|
|
548
|
-
case 'in':
|
|
549
|
-
type = Type_1.BooleanType.getInstance();
|
|
550
|
-
break;
|
|
551
|
-
case '&':
|
|
552
|
-
case '|':
|
|
553
|
-
case '^':
|
|
554
|
-
case '<<':
|
|
555
|
-
case '>>':
|
|
556
|
-
case '>>>':
|
|
557
|
-
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
558
|
-
type = Type_1.NumberType.getInstance();
|
|
559
|
-
}
|
|
560
|
-
break;
|
|
561
|
-
case '??':
|
|
562
|
-
if (op1Type === Type_1.UnknownType.getInstance() || op1Type === Type_1.UndefinedType.getInstance()
|
|
563
|
-
|| op1Type === Type_1.NullType.getInstance()) {
|
|
564
|
-
type = op2Type;
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
type = op1Type;
|
|
568
|
-
}
|
|
569
|
-
break;
|
|
570
|
-
default:
|
|
571
|
-
;
|
|
572
|
-
}
|
|
573
|
-
this.type = type;
|
|
574
|
-
}
|
|
575
|
-
inferType(arkMethod) {
|
|
576
|
-
this.inferOpType(this.op1, arkMethod);
|
|
577
|
-
this.inferOpType(this.op2, arkMethod);
|
|
578
|
-
this.setType();
|
|
579
|
-
return this;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
exports.AbstractBinopExpr = AbstractBinopExpr;
|
|
583
|
-
class ArkConditionExpr extends AbstractBinopExpr {
|
|
584
|
-
constructor(op1, op2, operator) {
|
|
585
|
-
super(op1, op2, operator);
|
|
586
|
-
}
|
|
587
|
-
inferType(arkMethod) {
|
|
588
|
-
this.inferOpType(this.op1, arkMethod);
|
|
589
|
-
const op1Type = this.op1.getType();
|
|
590
|
-
if (this.operator === RelationalBinaryOperator.InEquality && this.op2 === ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)) {
|
|
591
|
-
if (op1Type instanceof Type_1.StringType) {
|
|
592
|
-
this.op2 = ValueUtil_1.ValueUtil.createStringConst(ValueUtil_1.EMPTY_STRING);
|
|
593
|
-
}
|
|
594
|
-
else if (op1Type instanceof Type_1.BooleanType) {
|
|
595
|
-
this.op2 = ValueUtil_1.ValueUtil.getBooleanConstant(false);
|
|
596
|
-
}
|
|
597
|
-
else if (op1Type instanceof Type_1.ClassType) {
|
|
598
|
-
this.op2 = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
this.inferOpType(this.getOp2(), arkMethod);
|
|
603
|
-
}
|
|
604
|
-
this.type = Type_1.BooleanType.getInstance();
|
|
605
|
-
return this;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
exports.ArkConditionExpr = ArkConditionExpr;
|
|
609
|
-
class ArkNormalBinopExpr extends AbstractBinopExpr {
|
|
610
|
-
constructor(op1, op2, operator) {
|
|
611
|
-
super(op1, op2, operator);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
exports.ArkNormalBinopExpr = ArkNormalBinopExpr;
|
|
615
|
-
class ArkTypeOfExpr extends AbstractExpr {
|
|
616
|
-
constructor(op) {
|
|
617
|
-
super();
|
|
618
|
-
this.op = op;
|
|
619
|
-
}
|
|
620
|
-
getOp() {
|
|
621
|
-
return this.op;
|
|
622
|
-
}
|
|
623
|
-
setOp(newOp) {
|
|
624
|
-
this.op = newOp;
|
|
625
|
-
}
|
|
626
|
-
getUses() {
|
|
627
|
-
let uses = [];
|
|
628
|
-
uses.push(this.op);
|
|
629
|
-
uses.push(...this.op.getUses());
|
|
630
|
-
return uses;
|
|
631
|
-
}
|
|
632
|
-
getType() {
|
|
633
|
-
return this.op.getType();
|
|
634
|
-
}
|
|
635
|
-
toString() {
|
|
636
|
-
return 'typeof ' + this.op;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
exports.ArkTypeOfExpr = ArkTypeOfExpr;
|
|
640
|
-
class ArkInstanceOfExpr extends AbstractExpr {
|
|
641
|
-
constructor(op, checkType) {
|
|
642
|
-
super();
|
|
643
|
-
this.op = op;
|
|
644
|
-
this.checkType = checkType;
|
|
645
|
-
}
|
|
646
|
-
getOp() {
|
|
647
|
-
return this.op;
|
|
648
|
-
}
|
|
649
|
-
setOp(newOp) {
|
|
650
|
-
this.op = newOp;
|
|
651
|
-
}
|
|
652
|
-
getCheckType() {
|
|
653
|
-
return this.checkType;
|
|
654
|
-
}
|
|
655
|
-
getType() {
|
|
656
|
-
return Type_1.BooleanType.getInstance();
|
|
657
|
-
}
|
|
658
|
-
getUses() {
|
|
659
|
-
let uses = [];
|
|
660
|
-
uses.push(this.op);
|
|
661
|
-
uses.push(...this.op.getUses());
|
|
662
|
-
return uses;
|
|
663
|
-
}
|
|
664
|
-
toString() {
|
|
665
|
-
return this.op + ' instanceof ' + this.checkType;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
exports.ArkInstanceOfExpr = ArkInstanceOfExpr;
|
|
669
|
-
// 类型转换
|
|
670
|
-
class ArkCastExpr extends AbstractExpr {
|
|
671
|
-
constructor(op, type) {
|
|
672
|
-
super();
|
|
673
|
-
this.op = op;
|
|
674
|
-
this.type = type;
|
|
675
|
-
}
|
|
676
|
-
getOp() {
|
|
677
|
-
return this.op;
|
|
678
|
-
}
|
|
679
|
-
setOp(newOp) {
|
|
680
|
-
this.op = newOp;
|
|
681
|
-
}
|
|
682
|
-
getUses() {
|
|
683
|
-
let uses = [];
|
|
684
|
-
uses.push(this.op);
|
|
685
|
-
uses.push(...this.op.getUses());
|
|
686
|
-
return uses;
|
|
687
|
-
}
|
|
688
|
-
getType() {
|
|
689
|
-
return this.type;
|
|
690
|
-
}
|
|
691
|
-
inferType(arkMethod) {
|
|
692
|
-
var _a;
|
|
693
|
-
const type = (_a = TypeInference_1.TypeInference.inferUnclearedType(this.type, arkMethod.getDeclaringArkClass())) !== null && _a !== void 0 ? _a : this.op.getType();
|
|
694
|
-
if (!TypeInference_1.TypeInference.isUnclearType(type)) {
|
|
695
|
-
this.type = type;
|
|
696
|
-
IRInference_1.IRInference.inferRightWithSdkType(type, this.op.getType(), arkMethod.getDeclaringArkClass());
|
|
697
|
-
}
|
|
698
|
-
return this;
|
|
699
|
-
}
|
|
700
|
-
toString() {
|
|
701
|
-
return '<' + this.type + '>' + this.op;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
exports.ArkCastExpr = ArkCastExpr;
|
|
705
|
-
class ArkPhiExpr extends AbstractExpr {
|
|
706
|
-
constructor() {
|
|
707
|
-
super();
|
|
708
|
-
this.args = [];
|
|
709
|
-
this.argToBlock = new Map();
|
|
710
|
-
}
|
|
711
|
-
getUses() {
|
|
712
|
-
let uses = [];
|
|
713
|
-
uses.push(...this.args);
|
|
714
|
-
return uses;
|
|
715
|
-
}
|
|
716
|
-
getArgs() {
|
|
717
|
-
return this.args;
|
|
718
|
-
}
|
|
719
|
-
setArgs(args) {
|
|
720
|
-
this.args = args;
|
|
721
|
-
}
|
|
722
|
-
getArgToBlock() {
|
|
723
|
-
return this.argToBlock;
|
|
724
|
-
}
|
|
725
|
-
setArgToBlock(argToBlock) {
|
|
726
|
-
this.argToBlock = argToBlock;
|
|
727
|
-
}
|
|
728
|
-
getType() {
|
|
729
|
-
return this.args[0].getType();
|
|
730
|
-
}
|
|
731
|
-
toString() {
|
|
732
|
-
let strs = [];
|
|
733
|
-
strs.push('phi(');
|
|
734
|
-
if (this.args.length > 0) {
|
|
735
|
-
for (const arg of this.args) {
|
|
736
|
-
strs.push(arg.toString());
|
|
737
|
-
strs.push(', ');
|
|
738
|
-
}
|
|
739
|
-
strs.pop();
|
|
740
|
-
}
|
|
741
|
-
strs.push(')');
|
|
742
|
-
return strs.join('');
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
exports.ArkPhiExpr = ArkPhiExpr;
|
|
746
|
-
var UnaryOperator;
|
|
747
|
-
(function (UnaryOperator) {
|
|
748
|
-
UnaryOperator["Neg"] = "-";
|
|
749
|
-
UnaryOperator["BitwiseNot"] = "~";
|
|
750
|
-
UnaryOperator["LogicalNot"] = "!";
|
|
751
|
-
})(UnaryOperator = exports.UnaryOperator || (exports.UnaryOperator = {}));
|
|
752
|
-
// unary operation expression
|
|
753
|
-
class ArkUnopExpr extends AbstractExpr {
|
|
754
|
-
constructor(op, operator) {
|
|
755
|
-
super();
|
|
756
|
-
this.op = op;
|
|
757
|
-
this.operator = operator;
|
|
758
|
-
}
|
|
759
|
-
getUses() {
|
|
760
|
-
let uses = [];
|
|
761
|
-
uses.push(this.op);
|
|
762
|
-
uses.push(...this.op.getUses());
|
|
763
|
-
return uses;
|
|
764
|
-
}
|
|
765
|
-
getOp() {
|
|
766
|
-
return this.op;
|
|
767
|
-
}
|
|
768
|
-
setOp(newOp) {
|
|
769
|
-
this.op = newOp;
|
|
770
|
-
}
|
|
771
|
-
getType() {
|
|
772
|
-
return this.op.getType();
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* Get the unary operator from the statement, such as `-`,`~`,`!`.
|
|
776
|
-
* @returns the unary operator of a statement.
|
|
777
|
-
*/
|
|
778
|
-
getOperator() {
|
|
779
|
-
return this.operator;
|
|
780
|
-
}
|
|
781
|
-
toString() {
|
|
782
|
-
return this.operator + this.op;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
exports.ArkUnopExpr = ArkUnopExpr;
|
|
786
|
-
/**
|
|
787
|
-
* Expression of the right hand of the type alias definition statement.
|
|
788
|
-
* @category core/base/expr
|
|
789
|
-
* @extends AbstractExpr
|
|
790
|
-
* @example
|
|
791
|
-
```typescript
|
|
792
|
-
let a: number = 123;
|
|
793
|
-
type ABC = typeof a;
|
|
794
|
-
```
|
|
795
|
-
* The AliasTypeExpr of the previous statement is with local 'a' as the 'originalObject' and 'transferWithTypeOf' is true.
|
|
796
|
-
*
|
|
797
|
-
* The Following case: import type with no clause name is not supported now,
|
|
798
|
-
* whose 'originalObject' is {@link ImportInfo} with 'null' 'lazyExportInfo'.
|
|
799
|
-
```typescript
|
|
800
|
-
let a = typeof import('./abc');
|
|
801
|
-
```
|
|
802
|
-
*/
|
|
803
|
-
class AliasTypeExpr extends AbstractExpr {
|
|
804
|
-
constructor(originalObject, transferWithTypeOf) {
|
|
805
|
-
super();
|
|
806
|
-
this.transferWithTypeOf = false;
|
|
807
|
-
this.originalObject = originalObject;
|
|
808
|
-
if (transferWithTypeOf !== undefined) {
|
|
809
|
-
this.transferWithTypeOf = transferWithTypeOf;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
getOriginalObject() {
|
|
813
|
-
return this.originalObject;
|
|
814
|
-
}
|
|
815
|
-
setOriginalObject(object) {
|
|
816
|
-
this.originalObject = object;
|
|
817
|
-
}
|
|
818
|
-
getTransferWithTypeOf() {
|
|
819
|
-
return this.transferWithTypeOf;
|
|
820
|
-
}
|
|
821
|
-
setRealGenericTypes(realGenericTypes) {
|
|
822
|
-
this.realGenericTypes = realGenericTypes;
|
|
823
|
-
}
|
|
824
|
-
getRealGenericTypes() {
|
|
825
|
-
return this.realGenericTypes;
|
|
826
|
-
}
|
|
827
|
-
getType() {
|
|
828
|
-
function getTypeOfImportInfo(importInfo) {
|
|
829
|
-
var _a, _b;
|
|
830
|
-
const arkExport = (_a = importInfo.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport();
|
|
831
|
-
if (arkExport) {
|
|
832
|
-
return (_b = TypeInference_1.TypeInference.parseArkExport2Type(arkExport)) !== null && _b !== void 0 ? _b : Type_1.UnknownType.getInstance();
|
|
833
|
-
}
|
|
834
|
-
return Type_1.UnknownType.getInstance();
|
|
835
|
-
}
|
|
836
|
-
const operator = this.getOriginalObject();
|
|
837
|
-
if (!this.getTransferWithTypeOf()) {
|
|
838
|
-
if (operator instanceof Type_1.Type) {
|
|
839
|
-
return TypeInference_1.TypeInference.replaceTypeWithReal(operator, this.getRealGenericTypes());
|
|
840
|
-
}
|
|
841
|
-
if (operator instanceof ArkImport_1.ImportInfo) {
|
|
842
|
-
return getTypeOfImportInfo(operator);
|
|
843
|
-
}
|
|
844
|
-
if (operator instanceof ArkClass_1.ArkClass) {
|
|
845
|
-
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.ClassType(operator.getSignature(), operator.getGenericsTypes()), this.getRealGenericTypes());
|
|
846
|
-
}
|
|
847
|
-
return Type_1.UnknownType.getInstance();
|
|
848
|
-
}
|
|
849
|
-
if (operator instanceof ArkImport_1.ImportInfo) {
|
|
850
|
-
return getTypeOfImportInfo(operator);
|
|
851
|
-
}
|
|
852
|
-
if (operator instanceof Local_1.Local || operator instanceof ArkField_1.ArkField) {
|
|
853
|
-
return operator.getType();
|
|
854
|
-
}
|
|
855
|
-
if (operator instanceof ArkClass_1.ArkClass) {
|
|
856
|
-
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.ClassType(operator.getSignature(), operator.getGenericsTypes()), this.getRealGenericTypes());
|
|
857
|
-
}
|
|
858
|
-
if (operator instanceof ArkMethod_1.ArkMethod) {
|
|
859
|
-
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.FunctionType(operator.getSignature(), operator.getGenericTypes()), this.getRealGenericTypes());
|
|
860
|
-
}
|
|
861
|
-
return Type_1.UnknownType.getInstance();
|
|
862
|
-
}
|
|
863
|
-
inferType(arkMethod) {
|
|
864
|
-
return IRInference_1.IRInference.inferAliasTypeExpr(this, arkMethod);
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* Returns all used values which mainly used for def-use chain analysis.
|
|
868
|
-
* @returns Always returns empty array because her is the alias type definition which has no relationship with value flow.
|
|
869
|
-
*/
|
|
870
|
-
getUses() {
|
|
871
|
-
return [];
|
|
872
|
-
}
|
|
873
|
-
toString() {
|
|
874
|
-
let typeOf = '';
|
|
875
|
-
if (this.getTransferWithTypeOf()) {
|
|
876
|
-
typeOf = 'typeof ';
|
|
877
|
-
}
|
|
878
|
-
const typeObject = this.getOriginalObject();
|
|
879
|
-
if (typeObject instanceof Type_1.AliasType && this.getRealGenericTypes()) {
|
|
880
|
-
return `${typeOf}${typeObject.getSignature().toString()}<${this.getRealGenericTypes().join(',')}>`;
|
|
881
|
-
}
|
|
882
|
-
if (typeObject instanceof Type_1.Type) {
|
|
883
|
-
return `${typeOf}${typeObject.getTypeString()}`;
|
|
884
|
-
}
|
|
885
|
-
if (typeObject instanceof ArkImport_1.ImportInfo) {
|
|
886
|
-
let res = `${typeOf}import('${typeObject.getFrom()}')`;
|
|
887
|
-
if (typeObject.getImportClauseName() !== '') {
|
|
888
|
-
res = `${res}.${typeObject.getImportClauseName()}`;
|
|
889
|
-
}
|
|
890
|
-
return res;
|
|
891
|
-
}
|
|
892
|
-
if (typeObject instanceof Local_1.Local) {
|
|
893
|
-
return `${typeOf}${typeObject.toString()}`;
|
|
894
|
-
}
|
|
895
|
-
if (typeObject instanceof ArkClass_1.ArkClass || typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
896
|
-
let res = `${typeOf}${typeObject.getSignature().toString()}`;
|
|
897
|
-
if (this.getRealGenericTypes() && typeObject instanceof ArkClass_1.ArkClass) {
|
|
898
|
-
res += `<${this.getRealGenericTypes().join(',')}>`;
|
|
899
|
-
}
|
|
900
|
-
else if (this.getRealGenericTypes() && typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
901
|
-
const genericTypes = this.getRealGenericTypes().join(',');
|
|
902
|
-
res = res.replace('(', `<${genericTypes}>(`).replace(/\([^)]*\)/g, `(${genericTypes})`);
|
|
903
|
-
}
|
|
904
|
-
return res;
|
|
905
|
-
}
|
|
906
|
-
return `${typeOf}${typeObject.getName()}`;
|
|
907
|
-
}
|
|
908
|
-
static isAliasTypeOriginalModel(object) {
|
|
909
|
-
return object instanceof Type_1.Type ||
|
|
910
|
-
object instanceof ArkImport_1.ImportInfo ||
|
|
911
|
-
object instanceof Local_1.Local ||
|
|
912
|
-
object instanceof ArkClass_1.ArkClass ||
|
|
913
|
-
object instanceof ArkMethod_1.ArkMethod ||
|
|
914
|
-
object instanceof ArkField_1.ArkField;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
exports.AliasTypeExpr = AliasTypeExpr;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AliasTypeExpr = exports.ArkUnopExpr = exports.UnaryOperator = exports.ArkPhiExpr = exports.ArkCastExpr = exports.ArkInstanceOfExpr = exports.ArkTypeOfExpr = exports.ArkNormalBinopExpr = exports.ArkConditionExpr = exports.AbstractBinopExpr = exports.RelationalBinaryOperator = exports.NormalBinaryOperator = exports.ArkYieldExpr = exports.ArkAwaitExpr = exports.ArkDeleteExpr = exports.ArkNewArrayExpr = exports.ArkNewExpr = exports.ArkPtrInvokeExpr = exports.ArkStaticInvokeExpr = exports.ArkInstanceInvokeExpr = exports.AbstractInvokeExpr = exports.AbstractExpr = void 0;
|
|
18
|
+
const TypeInference_1 = require("../common/TypeInference");
|
|
19
|
+
const Local_1 = require("./Local");
|
|
20
|
+
const Type_1 = require("./Type");
|
|
21
|
+
const Ref_1 = require("./Ref");
|
|
22
|
+
const ValueUtil_1 = require("../common/ValueUtil");
|
|
23
|
+
const ArkMethod_1 = require("../model/ArkMethod");
|
|
24
|
+
const Const_1 = require("../common/Const");
|
|
25
|
+
const IRInference_1 = require("../common/IRInference");
|
|
26
|
+
const ArkImport_1 = require("../model/ArkImport");
|
|
27
|
+
const ArkClass_1 = require("../model/ArkClass");
|
|
28
|
+
const ArkField_1 = require("../model/ArkField");
|
|
29
|
+
/**
|
|
30
|
+
* @category core/base/expr
|
|
31
|
+
*/
|
|
32
|
+
class AbstractExpr {
|
|
33
|
+
inferType(arkMethod) {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.AbstractExpr = AbstractExpr;
|
|
38
|
+
class AbstractInvokeExpr extends AbstractExpr {
|
|
39
|
+
constructor(methodSignature, args, realGenericTypes) {
|
|
40
|
+
super();
|
|
41
|
+
this.methodSignature = methodSignature;
|
|
42
|
+
this.args = args;
|
|
43
|
+
this.realGenericTypes = realGenericTypes;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get method Signature. The method signature is consist of ClassSignature and MethodSubSignature.
|
|
47
|
+
* It is the unique flag of a method. It is usually used to compose a expression string in ArkIRTransformer.
|
|
48
|
+
* @returns The class method signature, such as ArkStaticInvokeExpr.
|
|
49
|
+
* @example
|
|
50
|
+
* 1. 3AC information composed of getMethodSignature ().
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
let strs: string[] = [];
|
|
54
|
+
strs.push('staticinvoke <');
|
|
55
|
+
strs.push(this.getMethodSignature().toString());
|
|
56
|
+
strs.push('>(');
|
|
57
|
+
```
|
|
58
|
+
*/
|
|
59
|
+
getMethodSignature() {
|
|
60
|
+
return this.methodSignature;
|
|
61
|
+
}
|
|
62
|
+
setMethodSignature(newMethodSignature) {
|
|
63
|
+
this.methodSignature = newMethodSignature;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns an argument used in the expression according to its index.
|
|
67
|
+
* @param index - the index of the argument.
|
|
68
|
+
* @returns An argument used in the expression.
|
|
69
|
+
*/
|
|
70
|
+
getArg(index) {
|
|
71
|
+
return this.args[index];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns an **array** of arguments used in the expression.
|
|
75
|
+
* @returns An **array** of arguments used in the expression.
|
|
76
|
+
* @example
|
|
77
|
+
* 1. get args number.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const argsNum = expr.getArgs().length;
|
|
81
|
+
if (argsNum < 5) {
|
|
82
|
+
... ...
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. iterate arg based on expression
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
for (const arg of this.getArgs()) {
|
|
90
|
+
strs.push(arg.toString());
|
|
91
|
+
strs.push(', ');
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
*/
|
|
95
|
+
getArgs() {
|
|
96
|
+
return this.args;
|
|
97
|
+
}
|
|
98
|
+
setArgs(newArgs) {
|
|
99
|
+
this.args = newArgs;
|
|
100
|
+
}
|
|
101
|
+
getType() {
|
|
102
|
+
const type = this.methodSignature.getType();
|
|
103
|
+
if (this.realGenericTypes) {
|
|
104
|
+
return TypeInference_1.TypeInference.replaceTypeWithReal(type, this.realGenericTypes);
|
|
105
|
+
}
|
|
106
|
+
return type;
|
|
107
|
+
}
|
|
108
|
+
getRealGenericTypes() {
|
|
109
|
+
return this.realGenericTypes;
|
|
110
|
+
}
|
|
111
|
+
setRealGenericTypes(realTypes) {
|
|
112
|
+
if (realTypes) {
|
|
113
|
+
this.realGenericTypes = realTypes;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getUses() {
|
|
117
|
+
let uses = [];
|
|
118
|
+
uses.push(...this.args);
|
|
119
|
+
for (const arg of this.args) {
|
|
120
|
+
uses.push(...arg.getUses());
|
|
121
|
+
}
|
|
122
|
+
return uses;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.AbstractInvokeExpr = AbstractInvokeExpr;
|
|
126
|
+
class ArkInstanceInvokeExpr extends AbstractInvokeExpr {
|
|
127
|
+
constructor(base, methodSignature, args, realGenericTypes) {
|
|
128
|
+
super(methodSignature, args, realGenericTypes);
|
|
129
|
+
this.base = base;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the local of the instance of invoke expression.
|
|
133
|
+
* @returns The local of the invoke expression's instance..
|
|
134
|
+
*/
|
|
135
|
+
getBase() {
|
|
136
|
+
return this.base;
|
|
137
|
+
}
|
|
138
|
+
setBase(newBase) {
|
|
139
|
+
this.base = newBase;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns an **array** of values used in this invoke expression,
|
|
143
|
+
* including all arguments and values each arguments used.
|
|
144
|
+
* For {@link ArkInstanceInvokeExpr}, the return also contains the caller base and uses of base.
|
|
145
|
+
* @returns An **array** of arguments used in the invoke expression.
|
|
146
|
+
*/
|
|
147
|
+
getUses() {
|
|
148
|
+
let uses = [];
|
|
149
|
+
uses.push(this.base);
|
|
150
|
+
uses.push(...this.base.getUses());
|
|
151
|
+
uses.push(...this.getArgs());
|
|
152
|
+
for (const arg of this.getArgs()) {
|
|
153
|
+
uses.push(...arg.getUses());
|
|
154
|
+
}
|
|
155
|
+
return uses;
|
|
156
|
+
}
|
|
157
|
+
toString() {
|
|
158
|
+
let strs = [];
|
|
159
|
+
strs.push('instanceinvoke ');
|
|
160
|
+
strs.push(this.base.toString());
|
|
161
|
+
strs.push('.<');
|
|
162
|
+
strs.push(this.getMethodSignature().toString());
|
|
163
|
+
strs.push('>(');
|
|
164
|
+
if (this.getArgs().length > 0) {
|
|
165
|
+
for (const arg of this.getArgs()) {
|
|
166
|
+
strs.push(arg.toString());
|
|
167
|
+
strs.push(', ');
|
|
168
|
+
}
|
|
169
|
+
strs.pop();
|
|
170
|
+
}
|
|
171
|
+
strs.push(')');
|
|
172
|
+
return strs.join('');
|
|
173
|
+
}
|
|
174
|
+
inferType(arkMethod) {
|
|
175
|
+
return IRInference_1.IRInference.inferInstanceInvokeExpr(this, arkMethod);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.ArkInstanceInvokeExpr = ArkInstanceInvokeExpr;
|
|
179
|
+
class ArkStaticInvokeExpr extends AbstractInvokeExpr {
|
|
180
|
+
constructor(methodSignature, args, realGenericTypes) {
|
|
181
|
+
super(methodSignature, args, realGenericTypes);
|
|
182
|
+
}
|
|
183
|
+
toString() {
|
|
184
|
+
let strs = [];
|
|
185
|
+
strs.push('staticinvoke <');
|
|
186
|
+
strs.push(this.getMethodSignature().toString());
|
|
187
|
+
strs.push('>(');
|
|
188
|
+
if (this.getArgs().length > 0) {
|
|
189
|
+
for (const arg of this.getArgs()) {
|
|
190
|
+
strs.push(arg.toString());
|
|
191
|
+
strs.push(', ');
|
|
192
|
+
}
|
|
193
|
+
strs.pop();
|
|
194
|
+
}
|
|
195
|
+
strs.push(')');
|
|
196
|
+
return strs.join('');
|
|
197
|
+
}
|
|
198
|
+
inferType(arkMethod) {
|
|
199
|
+
return IRInference_1.IRInference.inferStaticInvokeExpr(this, arkMethod);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.ArkStaticInvokeExpr = ArkStaticInvokeExpr;
|
|
203
|
+
class ArkPtrInvokeExpr extends AbstractInvokeExpr {
|
|
204
|
+
constructor(methodSignature, ptr, args, realGenericTypes) {
|
|
205
|
+
super(methodSignature, args, realGenericTypes);
|
|
206
|
+
this.funPtrLocal = ptr;
|
|
207
|
+
}
|
|
208
|
+
setFunPtrLocal(ptr) {
|
|
209
|
+
this.funPtrLocal = ptr;
|
|
210
|
+
}
|
|
211
|
+
getFuncPtrLocal() {
|
|
212
|
+
return this.funPtrLocal;
|
|
213
|
+
}
|
|
214
|
+
toString() {
|
|
215
|
+
let strs = [];
|
|
216
|
+
strs.push('ptrinvoke <');
|
|
217
|
+
strs.push(this.getMethodSignature().toString());
|
|
218
|
+
strs.push('>(');
|
|
219
|
+
if (this.getArgs().length > 0) {
|
|
220
|
+
for (const arg of this.getArgs()) {
|
|
221
|
+
strs.push(arg.toString());
|
|
222
|
+
strs.push(', ');
|
|
223
|
+
}
|
|
224
|
+
strs.pop();
|
|
225
|
+
}
|
|
226
|
+
strs.push(')');
|
|
227
|
+
return strs.join('');
|
|
228
|
+
}
|
|
229
|
+
inferType(arkMethod) {
|
|
230
|
+
// TODO: handle type inference
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
getUses() {
|
|
234
|
+
let uses = [];
|
|
235
|
+
uses.push(this.getFuncPtrLocal());
|
|
236
|
+
uses.push(...this.getArgs());
|
|
237
|
+
for (const arg of this.getArgs()) {
|
|
238
|
+
uses.push(...arg.getUses());
|
|
239
|
+
}
|
|
240
|
+
return uses;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.ArkPtrInvokeExpr = ArkPtrInvokeExpr;
|
|
244
|
+
class ArkNewExpr extends AbstractExpr {
|
|
245
|
+
constructor(classType) {
|
|
246
|
+
super();
|
|
247
|
+
this.classType = classType;
|
|
248
|
+
}
|
|
249
|
+
getClassType() {
|
|
250
|
+
return this.classType;
|
|
251
|
+
}
|
|
252
|
+
getUses() {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
getType() {
|
|
256
|
+
return this.classType;
|
|
257
|
+
}
|
|
258
|
+
toString() {
|
|
259
|
+
return 'new ' + this.classType;
|
|
260
|
+
}
|
|
261
|
+
inferType(arkMethod) {
|
|
262
|
+
const classSignature = this.classType.getClassSignature();
|
|
263
|
+
if (classSignature.getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
264
|
+
const className = classSignature.getClassName();
|
|
265
|
+
let type = TypeInference_1.TypeInference.inferUnclearRefName(className, arkMethod.getDeclaringArkClass());
|
|
266
|
+
if (type && type instanceof Type_1.ClassType) {
|
|
267
|
+
let realGenericTypes = this.classType.getRealGenericTypes();
|
|
268
|
+
this.classType = realGenericTypes ? new Type_1.ClassType(type.getClassSignature(), realGenericTypes) : type;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
exports.ArkNewExpr = ArkNewExpr;
|
|
275
|
+
class ArkNewArrayExpr extends AbstractExpr {
|
|
276
|
+
constructor(baseType, size, fromLiteral = false) {
|
|
277
|
+
super();
|
|
278
|
+
this.baseType = baseType;
|
|
279
|
+
this.size = size;
|
|
280
|
+
this.fromLiteral = fromLiteral;
|
|
281
|
+
}
|
|
282
|
+
getSize() {
|
|
283
|
+
return this.size;
|
|
284
|
+
}
|
|
285
|
+
setSize(newSize) {
|
|
286
|
+
this.size = newSize;
|
|
287
|
+
}
|
|
288
|
+
getType() {
|
|
289
|
+
return new Type_1.ArrayType(this.baseType, 1);
|
|
290
|
+
}
|
|
291
|
+
getBaseType() {
|
|
292
|
+
return this.baseType;
|
|
293
|
+
}
|
|
294
|
+
setBaseType(newType) {
|
|
295
|
+
this.baseType = newType;
|
|
296
|
+
}
|
|
297
|
+
isFromLiteral() {
|
|
298
|
+
return this.fromLiteral;
|
|
299
|
+
}
|
|
300
|
+
inferType(arkMethod) {
|
|
301
|
+
const type = TypeInference_1.TypeInference.inferUnclearedType(this.baseType, arkMethod.getDeclaringArkClass());
|
|
302
|
+
if (type) {
|
|
303
|
+
this.baseType = type;
|
|
304
|
+
}
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
getUses() {
|
|
308
|
+
let uses = [this.size];
|
|
309
|
+
uses.push(...this.size.getUses());
|
|
310
|
+
return uses;
|
|
311
|
+
}
|
|
312
|
+
toString() {
|
|
313
|
+
return 'newarray (' + this.baseType + ')[' + this.size + ']';
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
exports.ArkNewArrayExpr = ArkNewArrayExpr;
|
|
317
|
+
class ArkDeleteExpr extends AbstractExpr {
|
|
318
|
+
constructor(field) {
|
|
319
|
+
super();
|
|
320
|
+
this.field = field;
|
|
321
|
+
}
|
|
322
|
+
getField() {
|
|
323
|
+
return this.field;
|
|
324
|
+
}
|
|
325
|
+
setField(newField) {
|
|
326
|
+
this.field = newField;
|
|
327
|
+
}
|
|
328
|
+
getType() {
|
|
329
|
+
return Type_1.BooleanType.getInstance();
|
|
330
|
+
}
|
|
331
|
+
getUses() {
|
|
332
|
+
const uses = [];
|
|
333
|
+
uses.push(this.field);
|
|
334
|
+
uses.push(...this.field.getUses());
|
|
335
|
+
return uses;
|
|
336
|
+
}
|
|
337
|
+
toString() {
|
|
338
|
+
return 'delete ' + this.field;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
exports.ArkDeleteExpr = ArkDeleteExpr;
|
|
342
|
+
class ArkAwaitExpr extends AbstractExpr {
|
|
343
|
+
constructor(promise) {
|
|
344
|
+
super();
|
|
345
|
+
this.promise = promise;
|
|
346
|
+
}
|
|
347
|
+
getPromise() {
|
|
348
|
+
return this.promise;
|
|
349
|
+
}
|
|
350
|
+
setPromise(newPromise) {
|
|
351
|
+
this.promise = newPromise;
|
|
352
|
+
}
|
|
353
|
+
getType() {
|
|
354
|
+
var _a, _b;
|
|
355
|
+
const type = this.promise.getType();
|
|
356
|
+
if (type instanceof Type_1.UnclearReferenceType) {
|
|
357
|
+
return type.getGenericTypes()[0];
|
|
358
|
+
}
|
|
359
|
+
else if (type instanceof Type_1.ClassType) {
|
|
360
|
+
return (_b = (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : type;
|
|
361
|
+
}
|
|
362
|
+
return type;
|
|
363
|
+
}
|
|
364
|
+
inferType(arkMethod) {
|
|
365
|
+
TypeInference_1.TypeInference.inferValueType(this.promise, arkMethod);
|
|
366
|
+
return this;
|
|
367
|
+
}
|
|
368
|
+
getUses() {
|
|
369
|
+
const uses = [];
|
|
370
|
+
uses.push(this.promise);
|
|
371
|
+
uses.push(...this.promise.getUses());
|
|
372
|
+
return uses;
|
|
373
|
+
}
|
|
374
|
+
toString() {
|
|
375
|
+
const str = 'await ' + this.promise;
|
|
376
|
+
return str;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
exports.ArkAwaitExpr = ArkAwaitExpr;
|
|
380
|
+
class ArkYieldExpr extends AbstractExpr {
|
|
381
|
+
constructor(yieldValue) {
|
|
382
|
+
super();
|
|
383
|
+
this.yieldValue = yieldValue;
|
|
384
|
+
}
|
|
385
|
+
getYieldValue() {
|
|
386
|
+
return this.yieldValue;
|
|
387
|
+
}
|
|
388
|
+
setYieldValue(newYieldValue) {
|
|
389
|
+
this.yieldValue = newYieldValue;
|
|
390
|
+
}
|
|
391
|
+
getType() {
|
|
392
|
+
return this.yieldValue.getType();
|
|
393
|
+
}
|
|
394
|
+
getUses() {
|
|
395
|
+
const uses = [];
|
|
396
|
+
uses.push(this.yieldValue);
|
|
397
|
+
uses.push(...this.yieldValue.getUses());
|
|
398
|
+
return uses;
|
|
399
|
+
}
|
|
400
|
+
toString() {
|
|
401
|
+
const str = 'yield ' + this.yieldValue;
|
|
402
|
+
return str;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.ArkYieldExpr = ArkYieldExpr;
|
|
406
|
+
var NormalBinaryOperator;
|
|
407
|
+
(function (NormalBinaryOperator) {
|
|
408
|
+
// TODO: unfold it
|
|
409
|
+
NormalBinaryOperator["NullishCoalescing"] = "??";
|
|
410
|
+
// arithmetic
|
|
411
|
+
NormalBinaryOperator["Exponentiation"] = "**";
|
|
412
|
+
NormalBinaryOperator["Division"] = "/";
|
|
413
|
+
NormalBinaryOperator["Addition"] = "+";
|
|
414
|
+
NormalBinaryOperator["Subtraction"] = "-";
|
|
415
|
+
NormalBinaryOperator["Multiplication"] = "*";
|
|
416
|
+
NormalBinaryOperator["Remainder"] = "%";
|
|
417
|
+
// shift
|
|
418
|
+
NormalBinaryOperator["LeftShift"] = "<<";
|
|
419
|
+
NormalBinaryOperator["RightShift"] = ">>";
|
|
420
|
+
NormalBinaryOperator["UnsignedRightShift"] = ">>>";
|
|
421
|
+
// Bitwise
|
|
422
|
+
NormalBinaryOperator["BitwiseAnd"] = "&";
|
|
423
|
+
NormalBinaryOperator["BitwiseOr"] = "|";
|
|
424
|
+
NormalBinaryOperator["BitwiseXor"] = "^";
|
|
425
|
+
// Logical
|
|
426
|
+
NormalBinaryOperator["LogicalAnd"] = "&&";
|
|
427
|
+
NormalBinaryOperator["LogicalOr"] = "||";
|
|
428
|
+
})(NormalBinaryOperator = exports.NormalBinaryOperator || (exports.NormalBinaryOperator = {}));
|
|
429
|
+
var RelationalBinaryOperator;
|
|
430
|
+
(function (RelationalBinaryOperator) {
|
|
431
|
+
RelationalBinaryOperator["LessThan"] = "<";
|
|
432
|
+
RelationalBinaryOperator["LessThanOrEqual"] = "<=";
|
|
433
|
+
RelationalBinaryOperator["GreaterThan"] = ">";
|
|
434
|
+
RelationalBinaryOperator["GreaterThanOrEqual"] = ">=";
|
|
435
|
+
RelationalBinaryOperator["Equality"] = "==";
|
|
436
|
+
RelationalBinaryOperator["InEquality"] = "!=";
|
|
437
|
+
RelationalBinaryOperator["StrictEquality"] = "===";
|
|
438
|
+
RelationalBinaryOperator["StrictInequality"] = "!==";
|
|
439
|
+
RelationalBinaryOperator["isPropertyOf"] = "in";
|
|
440
|
+
})(RelationalBinaryOperator = exports.RelationalBinaryOperator || (exports.RelationalBinaryOperator = {}));
|
|
441
|
+
// 二元运算表达式
|
|
442
|
+
class AbstractBinopExpr extends AbstractExpr {
|
|
443
|
+
constructor(op1, op2, operator) {
|
|
444
|
+
super();
|
|
445
|
+
this.op1 = op1;
|
|
446
|
+
this.op2 = op2;
|
|
447
|
+
this.operator = operator;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Returns the first operand in the binary operation expression.
|
|
451
|
+
* For example, the first operand in `a + b;` is `a`.
|
|
452
|
+
* @returns The first operand in the binary operation expression.
|
|
453
|
+
*/
|
|
454
|
+
getOp1() {
|
|
455
|
+
return this.op1;
|
|
456
|
+
}
|
|
457
|
+
setOp1(newOp1) {
|
|
458
|
+
this.op1 = newOp1;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Returns the second operand in the binary operation expression.
|
|
462
|
+
* For example, the second operand in `a + b;` is `b`.
|
|
463
|
+
* @returns The second operand in the binary operation expression.
|
|
464
|
+
*/
|
|
465
|
+
getOp2() {
|
|
466
|
+
return this.op2;
|
|
467
|
+
}
|
|
468
|
+
setOp2(newOp2) {
|
|
469
|
+
this.op2 = newOp2;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Get the binary operator from the statement.
|
|
473
|
+
* The binary operator can be divided into two categories,
|
|
474
|
+
* one is the normal binary operator and the other is relational binary operator.
|
|
475
|
+
* @returns The binary operator from the statement.
|
|
476
|
+
* @example
|
|
477
|
+
```typescript
|
|
478
|
+
if (expr instanceof AbstractBinopExpr) {
|
|
479
|
+
let op1: Value = expr.getOp1();
|
|
480
|
+
let op2: Value = expr.getOp2();
|
|
481
|
+
let operator: string = expr.getOperator();
|
|
482
|
+
... ...
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
*/
|
|
486
|
+
getOperator() {
|
|
487
|
+
return this.operator;
|
|
488
|
+
}
|
|
489
|
+
getType() {
|
|
490
|
+
if (!this.type) {
|
|
491
|
+
this.setType();
|
|
492
|
+
}
|
|
493
|
+
return this.type;
|
|
494
|
+
}
|
|
495
|
+
getUses() {
|
|
496
|
+
let uses = [];
|
|
497
|
+
uses.push(this.op1);
|
|
498
|
+
uses.push(...this.op1.getUses());
|
|
499
|
+
uses.push(this.op2);
|
|
500
|
+
uses.push(...this.op2.getUses());
|
|
501
|
+
return uses;
|
|
502
|
+
}
|
|
503
|
+
toString() {
|
|
504
|
+
return this.op1 + ' ' + this.operator + ' ' + this.op2;
|
|
505
|
+
}
|
|
506
|
+
inferOpType(op, arkMethod) {
|
|
507
|
+
if (op instanceof AbstractExpr || op instanceof Ref_1.AbstractRef) {
|
|
508
|
+
TypeInference_1.TypeInference.inferValueType(op, arkMethod);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
setType() {
|
|
512
|
+
let op1Type = this.op1.getType();
|
|
513
|
+
let op2Type = this.op2.getType();
|
|
514
|
+
if (op1Type instanceof Type_1.UnionType) {
|
|
515
|
+
op1Type = op1Type.getCurrType();
|
|
516
|
+
}
|
|
517
|
+
if (op2Type instanceof Type_1.UnionType) {
|
|
518
|
+
op2Type = op2Type.getCurrType();
|
|
519
|
+
}
|
|
520
|
+
let type = Type_1.UnknownType.getInstance();
|
|
521
|
+
switch (this.operator) {
|
|
522
|
+
case '+':
|
|
523
|
+
if (op1Type === Type_1.StringType.getInstance() || op2Type === Type_1.StringType.getInstance()) {
|
|
524
|
+
type = Type_1.StringType.getInstance();
|
|
525
|
+
}
|
|
526
|
+
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
527
|
+
type = Type_1.NumberType.getInstance();
|
|
528
|
+
}
|
|
529
|
+
break;
|
|
530
|
+
case '-':
|
|
531
|
+
case '*':
|
|
532
|
+
case '/':
|
|
533
|
+
case '%':
|
|
534
|
+
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
535
|
+
type = Type_1.NumberType.getInstance();
|
|
536
|
+
}
|
|
537
|
+
break;
|
|
538
|
+
case '!=':
|
|
539
|
+
case '!==':
|
|
540
|
+
case '<':
|
|
541
|
+
case '>':
|
|
542
|
+
case '<=':
|
|
543
|
+
case '>=':
|
|
544
|
+
case '&&':
|
|
545
|
+
case '||':
|
|
546
|
+
case '==':
|
|
547
|
+
case '===':
|
|
548
|
+
case 'in':
|
|
549
|
+
type = Type_1.BooleanType.getInstance();
|
|
550
|
+
break;
|
|
551
|
+
case '&':
|
|
552
|
+
case '|':
|
|
553
|
+
case '^':
|
|
554
|
+
case '<<':
|
|
555
|
+
case '>>':
|
|
556
|
+
case '>>>':
|
|
557
|
+
if (op1Type === Type_1.NumberType.getInstance() && op2Type === Type_1.NumberType.getInstance()) {
|
|
558
|
+
type = Type_1.NumberType.getInstance();
|
|
559
|
+
}
|
|
560
|
+
break;
|
|
561
|
+
case '??':
|
|
562
|
+
if (op1Type === Type_1.UnknownType.getInstance() || op1Type === Type_1.UndefinedType.getInstance()
|
|
563
|
+
|| op1Type === Type_1.NullType.getInstance()) {
|
|
564
|
+
type = op2Type;
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
type = op1Type;
|
|
568
|
+
}
|
|
569
|
+
break;
|
|
570
|
+
default:
|
|
571
|
+
;
|
|
572
|
+
}
|
|
573
|
+
this.type = type;
|
|
574
|
+
}
|
|
575
|
+
inferType(arkMethod) {
|
|
576
|
+
this.inferOpType(this.op1, arkMethod);
|
|
577
|
+
this.inferOpType(this.op2, arkMethod);
|
|
578
|
+
this.setType();
|
|
579
|
+
return this;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
exports.AbstractBinopExpr = AbstractBinopExpr;
|
|
583
|
+
class ArkConditionExpr extends AbstractBinopExpr {
|
|
584
|
+
constructor(op1, op2, operator) {
|
|
585
|
+
super(op1, op2, operator);
|
|
586
|
+
}
|
|
587
|
+
inferType(arkMethod) {
|
|
588
|
+
this.inferOpType(this.op1, arkMethod);
|
|
589
|
+
const op1Type = this.op1.getType();
|
|
590
|
+
if (this.operator === RelationalBinaryOperator.InEquality && this.op2 === ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)) {
|
|
591
|
+
if (op1Type instanceof Type_1.StringType) {
|
|
592
|
+
this.op2 = ValueUtil_1.ValueUtil.createStringConst(ValueUtil_1.EMPTY_STRING);
|
|
593
|
+
}
|
|
594
|
+
else if (op1Type instanceof Type_1.BooleanType) {
|
|
595
|
+
this.op2 = ValueUtil_1.ValueUtil.getBooleanConstant(false);
|
|
596
|
+
}
|
|
597
|
+
else if (op1Type instanceof Type_1.ClassType) {
|
|
598
|
+
this.op2 = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
this.inferOpType(this.getOp2(), arkMethod);
|
|
603
|
+
}
|
|
604
|
+
this.type = Type_1.BooleanType.getInstance();
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
exports.ArkConditionExpr = ArkConditionExpr;
|
|
609
|
+
class ArkNormalBinopExpr extends AbstractBinopExpr {
|
|
610
|
+
constructor(op1, op2, operator) {
|
|
611
|
+
super(op1, op2, operator);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
exports.ArkNormalBinopExpr = ArkNormalBinopExpr;
|
|
615
|
+
class ArkTypeOfExpr extends AbstractExpr {
|
|
616
|
+
constructor(op) {
|
|
617
|
+
super();
|
|
618
|
+
this.op = op;
|
|
619
|
+
}
|
|
620
|
+
getOp() {
|
|
621
|
+
return this.op;
|
|
622
|
+
}
|
|
623
|
+
setOp(newOp) {
|
|
624
|
+
this.op = newOp;
|
|
625
|
+
}
|
|
626
|
+
getUses() {
|
|
627
|
+
let uses = [];
|
|
628
|
+
uses.push(this.op);
|
|
629
|
+
uses.push(...this.op.getUses());
|
|
630
|
+
return uses;
|
|
631
|
+
}
|
|
632
|
+
getType() {
|
|
633
|
+
return this.op.getType();
|
|
634
|
+
}
|
|
635
|
+
toString() {
|
|
636
|
+
return 'typeof ' + this.op;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
exports.ArkTypeOfExpr = ArkTypeOfExpr;
|
|
640
|
+
class ArkInstanceOfExpr extends AbstractExpr {
|
|
641
|
+
constructor(op, checkType) {
|
|
642
|
+
super();
|
|
643
|
+
this.op = op;
|
|
644
|
+
this.checkType = checkType;
|
|
645
|
+
}
|
|
646
|
+
getOp() {
|
|
647
|
+
return this.op;
|
|
648
|
+
}
|
|
649
|
+
setOp(newOp) {
|
|
650
|
+
this.op = newOp;
|
|
651
|
+
}
|
|
652
|
+
getCheckType() {
|
|
653
|
+
return this.checkType;
|
|
654
|
+
}
|
|
655
|
+
getType() {
|
|
656
|
+
return Type_1.BooleanType.getInstance();
|
|
657
|
+
}
|
|
658
|
+
getUses() {
|
|
659
|
+
let uses = [];
|
|
660
|
+
uses.push(this.op);
|
|
661
|
+
uses.push(...this.op.getUses());
|
|
662
|
+
return uses;
|
|
663
|
+
}
|
|
664
|
+
toString() {
|
|
665
|
+
return this.op + ' instanceof ' + this.checkType;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
exports.ArkInstanceOfExpr = ArkInstanceOfExpr;
|
|
669
|
+
// 类型转换
|
|
670
|
+
class ArkCastExpr extends AbstractExpr {
|
|
671
|
+
constructor(op, type) {
|
|
672
|
+
super();
|
|
673
|
+
this.op = op;
|
|
674
|
+
this.type = type;
|
|
675
|
+
}
|
|
676
|
+
getOp() {
|
|
677
|
+
return this.op;
|
|
678
|
+
}
|
|
679
|
+
setOp(newOp) {
|
|
680
|
+
this.op = newOp;
|
|
681
|
+
}
|
|
682
|
+
getUses() {
|
|
683
|
+
let uses = [];
|
|
684
|
+
uses.push(this.op);
|
|
685
|
+
uses.push(...this.op.getUses());
|
|
686
|
+
return uses;
|
|
687
|
+
}
|
|
688
|
+
getType() {
|
|
689
|
+
return this.type;
|
|
690
|
+
}
|
|
691
|
+
inferType(arkMethod) {
|
|
692
|
+
var _a;
|
|
693
|
+
const type = (_a = TypeInference_1.TypeInference.inferUnclearedType(this.type, arkMethod.getDeclaringArkClass())) !== null && _a !== void 0 ? _a : this.op.getType();
|
|
694
|
+
if (!TypeInference_1.TypeInference.isUnclearType(type)) {
|
|
695
|
+
this.type = type;
|
|
696
|
+
IRInference_1.IRInference.inferRightWithSdkType(type, this.op.getType(), arkMethod.getDeclaringArkClass());
|
|
697
|
+
}
|
|
698
|
+
return this;
|
|
699
|
+
}
|
|
700
|
+
toString() {
|
|
701
|
+
return '<' + this.type + '>' + this.op;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
exports.ArkCastExpr = ArkCastExpr;
|
|
705
|
+
class ArkPhiExpr extends AbstractExpr {
|
|
706
|
+
constructor() {
|
|
707
|
+
super();
|
|
708
|
+
this.args = [];
|
|
709
|
+
this.argToBlock = new Map();
|
|
710
|
+
}
|
|
711
|
+
getUses() {
|
|
712
|
+
let uses = [];
|
|
713
|
+
uses.push(...this.args);
|
|
714
|
+
return uses;
|
|
715
|
+
}
|
|
716
|
+
getArgs() {
|
|
717
|
+
return this.args;
|
|
718
|
+
}
|
|
719
|
+
setArgs(args) {
|
|
720
|
+
this.args = args;
|
|
721
|
+
}
|
|
722
|
+
getArgToBlock() {
|
|
723
|
+
return this.argToBlock;
|
|
724
|
+
}
|
|
725
|
+
setArgToBlock(argToBlock) {
|
|
726
|
+
this.argToBlock = argToBlock;
|
|
727
|
+
}
|
|
728
|
+
getType() {
|
|
729
|
+
return this.args[0].getType();
|
|
730
|
+
}
|
|
731
|
+
toString() {
|
|
732
|
+
let strs = [];
|
|
733
|
+
strs.push('phi(');
|
|
734
|
+
if (this.args.length > 0) {
|
|
735
|
+
for (const arg of this.args) {
|
|
736
|
+
strs.push(arg.toString());
|
|
737
|
+
strs.push(', ');
|
|
738
|
+
}
|
|
739
|
+
strs.pop();
|
|
740
|
+
}
|
|
741
|
+
strs.push(')');
|
|
742
|
+
return strs.join('');
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
exports.ArkPhiExpr = ArkPhiExpr;
|
|
746
|
+
var UnaryOperator;
|
|
747
|
+
(function (UnaryOperator) {
|
|
748
|
+
UnaryOperator["Neg"] = "-";
|
|
749
|
+
UnaryOperator["BitwiseNot"] = "~";
|
|
750
|
+
UnaryOperator["LogicalNot"] = "!";
|
|
751
|
+
})(UnaryOperator = exports.UnaryOperator || (exports.UnaryOperator = {}));
|
|
752
|
+
// unary operation expression
|
|
753
|
+
class ArkUnopExpr extends AbstractExpr {
|
|
754
|
+
constructor(op, operator) {
|
|
755
|
+
super();
|
|
756
|
+
this.op = op;
|
|
757
|
+
this.operator = operator;
|
|
758
|
+
}
|
|
759
|
+
getUses() {
|
|
760
|
+
let uses = [];
|
|
761
|
+
uses.push(this.op);
|
|
762
|
+
uses.push(...this.op.getUses());
|
|
763
|
+
return uses;
|
|
764
|
+
}
|
|
765
|
+
getOp() {
|
|
766
|
+
return this.op;
|
|
767
|
+
}
|
|
768
|
+
setOp(newOp) {
|
|
769
|
+
this.op = newOp;
|
|
770
|
+
}
|
|
771
|
+
getType() {
|
|
772
|
+
return this.op.getType();
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Get the unary operator from the statement, such as `-`,`~`,`!`.
|
|
776
|
+
* @returns the unary operator of a statement.
|
|
777
|
+
*/
|
|
778
|
+
getOperator() {
|
|
779
|
+
return this.operator;
|
|
780
|
+
}
|
|
781
|
+
toString() {
|
|
782
|
+
return this.operator + this.op;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
exports.ArkUnopExpr = ArkUnopExpr;
|
|
786
|
+
/**
|
|
787
|
+
* Expression of the right hand of the type alias definition statement.
|
|
788
|
+
* @category core/base/expr
|
|
789
|
+
* @extends AbstractExpr
|
|
790
|
+
* @example
|
|
791
|
+
```typescript
|
|
792
|
+
let a: number = 123;
|
|
793
|
+
type ABC = typeof a;
|
|
794
|
+
```
|
|
795
|
+
* The AliasTypeExpr of the previous statement is with local 'a' as the 'originalObject' and 'transferWithTypeOf' is true.
|
|
796
|
+
*
|
|
797
|
+
* The Following case: import type with no clause name is not supported now,
|
|
798
|
+
* whose 'originalObject' is {@link ImportInfo} with 'null' 'lazyExportInfo'.
|
|
799
|
+
```typescript
|
|
800
|
+
let a = typeof import('./abc');
|
|
801
|
+
```
|
|
802
|
+
*/
|
|
803
|
+
class AliasTypeExpr extends AbstractExpr {
|
|
804
|
+
constructor(originalObject, transferWithTypeOf) {
|
|
805
|
+
super();
|
|
806
|
+
this.transferWithTypeOf = false;
|
|
807
|
+
this.originalObject = originalObject;
|
|
808
|
+
if (transferWithTypeOf !== undefined) {
|
|
809
|
+
this.transferWithTypeOf = transferWithTypeOf;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
getOriginalObject() {
|
|
813
|
+
return this.originalObject;
|
|
814
|
+
}
|
|
815
|
+
setOriginalObject(object) {
|
|
816
|
+
this.originalObject = object;
|
|
817
|
+
}
|
|
818
|
+
getTransferWithTypeOf() {
|
|
819
|
+
return this.transferWithTypeOf;
|
|
820
|
+
}
|
|
821
|
+
setRealGenericTypes(realGenericTypes) {
|
|
822
|
+
this.realGenericTypes = realGenericTypes;
|
|
823
|
+
}
|
|
824
|
+
getRealGenericTypes() {
|
|
825
|
+
return this.realGenericTypes;
|
|
826
|
+
}
|
|
827
|
+
getType() {
|
|
828
|
+
function getTypeOfImportInfo(importInfo) {
|
|
829
|
+
var _a, _b;
|
|
830
|
+
const arkExport = (_a = importInfo.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport();
|
|
831
|
+
if (arkExport) {
|
|
832
|
+
return (_b = TypeInference_1.TypeInference.parseArkExport2Type(arkExport)) !== null && _b !== void 0 ? _b : Type_1.UnknownType.getInstance();
|
|
833
|
+
}
|
|
834
|
+
return Type_1.UnknownType.getInstance();
|
|
835
|
+
}
|
|
836
|
+
const operator = this.getOriginalObject();
|
|
837
|
+
if (!this.getTransferWithTypeOf()) {
|
|
838
|
+
if (operator instanceof Type_1.Type) {
|
|
839
|
+
return TypeInference_1.TypeInference.replaceTypeWithReal(operator, this.getRealGenericTypes());
|
|
840
|
+
}
|
|
841
|
+
if (operator instanceof ArkImport_1.ImportInfo) {
|
|
842
|
+
return getTypeOfImportInfo(operator);
|
|
843
|
+
}
|
|
844
|
+
if (operator instanceof ArkClass_1.ArkClass) {
|
|
845
|
+
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.ClassType(operator.getSignature(), operator.getGenericsTypes()), this.getRealGenericTypes());
|
|
846
|
+
}
|
|
847
|
+
return Type_1.UnknownType.getInstance();
|
|
848
|
+
}
|
|
849
|
+
if (operator instanceof ArkImport_1.ImportInfo) {
|
|
850
|
+
return getTypeOfImportInfo(operator);
|
|
851
|
+
}
|
|
852
|
+
if (operator instanceof Local_1.Local || operator instanceof ArkField_1.ArkField) {
|
|
853
|
+
return operator.getType();
|
|
854
|
+
}
|
|
855
|
+
if (operator instanceof ArkClass_1.ArkClass) {
|
|
856
|
+
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.ClassType(operator.getSignature(), operator.getGenericsTypes()), this.getRealGenericTypes());
|
|
857
|
+
}
|
|
858
|
+
if (operator instanceof ArkMethod_1.ArkMethod) {
|
|
859
|
+
return TypeInference_1.TypeInference.replaceTypeWithReal(new Type_1.FunctionType(operator.getSignature(), operator.getGenericTypes()), this.getRealGenericTypes());
|
|
860
|
+
}
|
|
861
|
+
return Type_1.UnknownType.getInstance();
|
|
862
|
+
}
|
|
863
|
+
inferType(arkMethod) {
|
|
864
|
+
return IRInference_1.IRInference.inferAliasTypeExpr(this, arkMethod);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Returns all used values which mainly used for def-use chain analysis.
|
|
868
|
+
* @returns Always returns empty array because her is the alias type definition which has no relationship with value flow.
|
|
869
|
+
*/
|
|
870
|
+
getUses() {
|
|
871
|
+
return [];
|
|
872
|
+
}
|
|
873
|
+
toString() {
|
|
874
|
+
let typeOf = '';
|
|
875
|
+
if (this.getTransferWithTypeOf()) {
|
|
876
|
+
typeOf = 'typeof ';
|
|
877
|
+
}
|
|
878
|
+
const typeObject = this.getOriginalObject();
|
|
879
|
+
if (typeObject instanceof Type_1.AliasType && this.getRealGenericTypes()) {
|
|
880
|
+
return `${typeOf}${typeObject.getSignature().toString()}<${this.getRealGenericTypes().join(',')}>`;
|
|
881
|
+
}
|
|
882
|
+
if (typeObject instanceof Type_1.Type) {
|
|
883
|
+
return `${typeOf}${typeObject.getTypeString()}`;
|
|
884
|
+
}
|
|
885
|
+
if (typeObject instanceof ArkImport_1.ImportInfo) {
|
|
886
|
+
let res = `${typeOf}import('${typeObject.getFrom()}')`;
|
|
887
|
+
if (typeObject.getImportClauseName() !== '') {
|
|
888
|
+
res = `${res}.${typeObject.getImportClauseName()}`;
|
|
889
|
+
}
|
|
890
|
+
return res;
|
|
891
|
+
}
|
|
892
|
+
if (typeObject instanceof Local_1.Local) {
|
|
893
|
+
return `${typeOf}${typeObject.toString()}`;
|
|
894
|
+
}
|
|
895
|
+
if (typeObject instanceof ArkClass_1.ArkClass || typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
896
|
+
let res = `${typeOf}${typeObject.getSignature().toString()}`;
|
|
897
|
+
if (this.getRealGenericTypes() && typeObject instanceof ArkClass_1.ArkClass) {
|
|
898
|
+
res += `<${this.getRealGenericTypes().join(',')}>`;
|
|
899
|
+
}
|
|
900
|
+
else if (this.getRealGenericTypes() && typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
901
|
+
const genericTypes = this.getRealGenericTypes().join(',');
|
|
902
|
+
res = res.replace('(', `<${genericTypes}>(`).replace(/\([^)]*\)/g, `(${genericTypes})`);
|
|
903
|
+
}
|
|
904
|
+
return res;
|
|
905
|
+
}
|
|
906
|
+
return `${typeOf}${typeObject.getName()}`;
|
|
907
|
+
}
|
|
908
|
+
static isAliasTypeOriginalModel(object) {
|
|
909
|
+
return object instanceof Type_1.Type ||
|
|
910
|
+
object instanceof ArkImport_1.ImportInfo ||
|
|
911
|
+
object instanceof Local_1.Local ||
|
|
912
|
+
object instanceof ArkClass_1.ArkClass ||
|
|
913
|
+
object instanceof ArkMethod_1.ArkMethod ||
|
|
914
|
+
object instanceof ArkField_1.ArkField;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
exports.AliasTypeExpr = AliasTypeExpr;
|