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/Stmt.js
CHANGED
|
@@ -14,22 +14,30 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ArkThrowStmt = exports.ArkSwitchStmt = exports.ArkReturnVoidStmt = exports.ArkReturnStmt = exports.ArkIfStmt = exports.ArkInvokeStmt = exports.ArkAssignStmt = exports.
|
|
17
|
+
exports.ArkThrowStmt = exports.ArkSwitchStmt = exports.ArkReturnVoidStmt = exports.ArkReturnStmt = exports.ArkIfStmt = exports.ArkInvokeStmt = exports.ArkAssignStmt = exports.Stmt = void 0;
|
|
18
18
|
const StmtUseReplacer_1 = require("../common/StmtUseReplacer");
|
|
19
19
|
const Expr_1 = require("./Expr");
|
|
20
20
|
const Ref_1 = require("./Ref");
|
|
21
21
|
const Position_1 = require("./Position");
|
|
22
|
+
const ArkMetadata_1 = require("../model/ArkMetadata");
|
|
22
23
|
/**
|
|
23
24
|
* @category core/base/stmt
|
|
24
25
|
*/
|
|
25
26
|
class Stmt {
|
|
26
27
|
constructor() {
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
this.originalPosition = Position_1.LineColPosition.DEFAULT;
|
|
29
|
+
}
|
|
30
|
+
getMetadata(kind) {
|
|
31
|
+
var _a;
|
|
32
|
+
return (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.getMetadata(kind);
|
|
33
|
+
}
|
|
34
|
+
setMetadata(kind, value) {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!this.metadata) {
|
|
37
|
+
this.metadata = new ArkMetadata_1.ArkMetadata();
|
|
38
|
+
}
|
|
39
|
+
return (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.setMetadata(kind, value);
|
|
31
40
|
}
|
|
32
|
-
// def and uses one by one
|
|
33
41
|
/** Return a list of values which are uesd in this statement */
|
|
34
42
|
getUses() {
|
|
35
43
|
return [];
|
|
@@ -38,7 +46,23 @@ class Stmt {
|
|
|
38
46
|
let stmtUseReplacer = new StmtUseReplacer_1.StmtUseReplacer(oldUse, newUse);
|
|
39
47
|
stmtUseReplacer.caseStmt(this);
|
|
40
48
|
}
|
|
41
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Return the definition which is uesd in this statement. Generally, the definition is the left value of `=` in 3AC.
|
|
51
|
+
* For example, the definition in 3AC of `value = parameter0: @project-1/sample-1.ets: AnonymousClass-0` is `value`,
|
|
52
|
+
* and the definition in `$temp0 = staticinvoke <@_ProjectName/_FileName: xxx.create()>()` is `\$temp0`.
|
|
53
|
+
* @returns The definition in 3AC (may be a **null**).
|
|
54
|
+
* @example
|
|
55
|
+
* 1. get the def in stmt.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
for (const block of this.blocks) {
|
|
59
|
+
for (const stmt of block.getStmts()) {
|
|
60
|
+
const defValue = stmt.getDef();
|
|
61
|
+
...
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
*/
|
|
42
66
|
getDef() {
|
|
43
67
|
return null;
|
|
44
68
|
}
|
|
@@ -51,6 +75,27 @@ class Stmt {
|
|
|
51
75
|
defAndUses.push(...this.getUses());
|
|
52
76
|
return defAndUses;
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the CFG (i.e., control flow graph) of an {@link ArkBody} in which the statement is.
|
|
80
|
+
* A CFG contains a set of basic blocks and statements corresponding to each basic block.
|
|
81
|
+
* Note that, "source code" and "three-address" are two types of {@link Stmt} in ArkAnalyzer.
|
|
82
|
+
* Source code {@link Stmt} represents the statement of ets/ts source code, while three-address code {@link Stmt} represents the statement after it has been converted into three-address code.
|
|
83
|
+
* Since the source code {@link Stmt} does not save its CFG reference, it returns **null**,
|
|
84
|
+
* while the `getCfg()` of the third address code {@link Stmt} will return its CFG reference.
|
|
85
|
+
* @returns The CFG (i.e., control flow graph) of an {@link ArkBody} in which the statement is.
|
|
86
|
+
* @example
|
|
87
|
+
* 1. get the ArkFile based on stmt.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const arkFile = stmt.getCfg()?.getDeclaringMethod().getDeclaringArkFile();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
2. get the ArkMethod based on stmt.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
let sourceMethod: ArkMethod = stmt.getCfg()?.getDeclaringMethod();
|
|
97
|
+
```
|
|
98
|
+
*/
|
|
54
99
|
getCfg() {
|
|
55
100
|
return this.cfg;
|
|
56
101
|
}
|
|
@@ -76,6 +121,17 @@ class Stmt {
|
|
|
76
121
|
}
|
|
77
122
|
return false;
|
|
78
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the method's invocation expression (including method signature and its arguments)
|
|
126
|
+
* in the current statement. An **undefined** will be returned if there is no method used in this statement.
|
|
127
|
+
* @returns the method's invocation expression from the statement. An **undefined** will be returned if there is no method can be found in this statement.
|
|
128
|
+
* @example
|
|
129
|
+
* 1. get invoke expr based on stmt.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
let invoke = stmt.getInvokeExpr();
|
|
133
|
+
```
|
|
134
|
+
*/
|
|
79
135
|
getInvokeExpr() {
|
|
80
136
|
for (const use of this.getUses()) {
|
|
81
137
|
if (use instanceof Expr_1.AbstractInvokeExpr) {
|
|
@@ -84,6 +140,18 @@ class Stmt {
|
|
|
84
140
|
}
|
|
85
141
|
return undefined;
|
|
86
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns an array of expressions in the statement.
|
|
145
|
+
* @returns An array of expressions in the statement.
|
|
146
|
+
* @example
|
|
147
|
+
* 1. Traverse expression of statement.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
for (const expr of stmt.getExprs()) {
|
|
151
|
+
...
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
*/
|
|
87
155
|
getExprs() {
|
|
88
156
|
let exprs = [];
|
|
89
157
|
for (const use of this.getUses()) {
|
|
@@ -137,23 +205,40 @@ class Stmt {
|
|
|
137
205
|
}
|
|
138
206
|
return undefined;
|
|
139
207
|
}
|
|
140
|
-
|
|
141
|
-
this.
|
|
208
|
+
setOriginPositionInfo(originPositionInfo) {
|
|
209
|
+
this.originalPosition = originPositionInfo;
|
|
142
210
|
}
|
|
143
|
-
|
|
144
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Returns the original position of the statement.
|
|
213
|
+
* The position consists of two parts: line number and column number.
|
|
214
|
+
* In the source file, the former (i.e., line number) indicates which line the statement is in,
|
|
215
|
+
* and the latter (i.e., column number) indicates the position of the statement in the line.
|
|
216
|
+
* The position is described as `LineColPosition(lineNo,colNum)` in ArkAnalyzer,
|
|
217
|
+
* and its default value is LineColPosition(-1,-1).
|
|
218
|
+
* @returns The original location of the statement.
|
|
219
|
+
* @example
|
|
220
|
+
* 1. Get the stmt position info to make some condition judgements.
|
|
221
|
+
```typescript
|
|
222
|
+
for (const stmt of stmts) {
|
|
223
|
+
if (stmt.getOriginPositionInfo().getLineNo() === -1) {
|
|
224
|
+
stmt.setOriginPositionInfo(originalStmt.getOriginPositionInfo());
|
|
225
|
+
this.stmtToOriginalStmt.set(stmt, originalStmt);
|
|
226
|
+
}
|
|
145
227
|
}
|
|
228
|
+
```
|
|
229
|
+
*/
|
|
146
230
|
getOriginPositionInfo() {
|
|
147
|
-
|
|
148
|
-
const originPositionInfo = (_e = (_d = (_c = (_b = (_a = this.cfg) === null || _a === void 0 ? void 0 : _a.getDeclaringMethod()) === null || _b === void 0 ? void 0 : _b.getBody()) === null || _c === void 0 ? void 0 : _c.getStmtToOriginalStmt()) === null || _d === void 0 ? void 0 : _d.get(this)) === null || _e === void 0 ? void 0 : _e.position;
|
|
149
|
-
if (!originPositionInfo) {
|
|
150
|
-
return Position_1.LineColPosition.DEFAULT;
|
|
151
|
-
}
|
|
152
|
-
return originPositionInfo;
|
|
231
|
+
return this.originalPosition;
|
|
153
232
|
}
|
|
154
233
|
setText(text) {
|
|
155
234
|
this.text = text;
|
|
156
235
|
}
|
|
236
|
+
setOriginalText(originalText) {
|
|
237
|
+
this.originalText = originalText;
|
|
238
|
+
}
|
|
239
|
+
getOriginalText() {
|
|
240
|
+
return this.originalText;
|
|
241
|
+
}
|
|
157
242
|
setOperandOriginalPositions(operandOriginalPositions) {
|
|
158
243
|
this.operandOriginalPositions = operandOriginalPositions;
|
|
159
244
|
}
|
|
@@ -180,29 +265,35 @@ class Stmt {
|
|
|
180
265
|
;
|
|
181
266
|
}
|
|
182
267
|
exports.Stmt = Stmt;
|
|
183
|
-
class OriginalStmt extends Stmt {
|
|
184
|
-
constructor(text, position) {
|
|
185
|
-
super();
|
|
186
|
-
this.text = text;
|
|
187
|
-
this.position = position;
|
|
188
|
-
}
|
|
189
|
-
toString() {
|
|
190
|
-
return this.text;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
exports.OriginalStmt = OriginalStmt;
|
|
194
268
|
class ArkAssignStmt extends Stmt {
|
|
195
269
|
constructor(leftOp, rightOp) {
|
|
196
270
|
super();
|
|
197
271
|
this.leftOp = leftOp;
|
|
198
272
|
this.rightOp = rightOp;
|
|
199
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Returns the left operand of the assigning statement.
|
|
276
|
+
* @returns The left operand of the assigning statement.
|
|
277
|
+
* @example
|
|
278
|
+
* 1. If the statement is `a=b;`, the right operand is `a`; if the statement is `dd = cc + 5;`, the right operand is `cc`.
|
|
279
|
+
*/
|
|
200
280
|
getLeftOp() {
|
|
201
281
|
return this.leftOp;
|
|
202
282
|
}
|
|
203
283
|
setLeftOp(newLeftOp) {
|
|
204
284
|
this.leftOp = newLeftOp;
|
|
205
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Returns the right operand of the assigning statement.
|
|
288
|
+
* @returns The right operand of the assigning statement.
|
|
289
|
+
* @example
|
|
290
|
+
* 1. If the statement is `a=b;`, the right operand is `b`; if the statement is `dd = cc + 5;`, the right operand is `cc + 5`.
|
|
291
|
+
* 2. Get the rightOp from stmt.
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
const rightOp = stmt.getRightOp();
|
|
295
|
+
```
|
|
296
|
+
*/
|
|
206
297
|
getRightOp() {
|
|
207
298
|
return this.rightOp;
|
|
208
299
|
}
|
|
@@ -253,6 +344,18 @@ class ArkIfStmt extends Stmt {
|
|
|
253
344
|
super();
|
|
254
345
|
this.conditionExpr = conditionExpr;
|
|
255
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* The condition expression consisit of two values as operands and one binary operator as operator.
|
|
349
|
+
* The operator can indicate the relation between the two values, e.g., `<`, `<=`,`>`, `>=`, `==`, `!=`, `===`, `!==`.
|
|
350
|
+
* @returns a condition expression.
|
|
351
|
+
* @example
|
|
352
|
+
* 1. When a statement is `if (a > b)`, the operands are `a` and `b`, the operator is `<`. Therefore, the condition expression is `a > b`.
|
|
353
|
+
* 2. get a conditon expr from a condition statement.
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
let expr = (this.original as ArkIfStmt).getConditionExprExpr();
|
|
357
|
+
```
|
|
358
|
+
*/
|
|
256
359
|
getConditionExprExpr() {
|
|
257
360
|
return this.conditionExpr;
|
|
258
361
|
}
|
|
@@ -319,6 +422,10 @@ class ArkSwitchStmt extends Stmt {
|
|
|
319
422
|
this.key = key;
|
|
320
423
|
this.cases = cases;
|
|
321
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Returns the key in a switch statement.
|
|
427
|
+
* @returns The key in a switch statement.
|
|
428
|
+
*/
|
|
322
429
|
getKey() {
|
|
323
430
|
return this.key;
|
|
324
431
|
}
|
package/lib/core/base/Type.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClassSignature, LocalSignature, MethodSignature, NamespaceSignature } from '../model/ArkSignature';
|
|
2
2
|
import { ArkExport, ExportType } from '../model/ArkExport';
|
|
3
|
-
import { Decorator } from './Decorator';
|
|
4
3
|
import { LineColPosition } from './Position';
|
|
4
|
+
import { ModifierType } from '../model/ArkBaseModel';
|
|
5
5
|
/**
|
|
6
6
|
* @category core/base/type
|
|
7
7
|
*/
|
|
@@ -154,6 +154,10 @@ export declare class ArrayType extends Type {
|
|
|
154
154
|
private baseType;
|
|
155
155
|
private dimension;
|
|
156
156
|
constructor(baseType: Type, dimension: number);
|
|
157
|
+
/**
|
|
158
|
+
* Returns the base type of this array, such as `Any`, `Unknown`, `TypeParameter`, etc.
|
|
159
|
+
* @returns The base type of array.
|
|
160
|
+
*/
|
|
157
161
|
getBaseType(): Type;
|
|
158
162
|
setBaseType(newType: Type): void;
|
|
159
163
|
getDimension(): number;
|
|
@@ -169,13 +173,18 @@ export declare class AliasType extends Type implements ArkExport {
|
|
|
169
173
|
private originalType;
|
|
170
174
|
private name;
|
|
171
175
|
private signature;
|
|
176
|
+
protected modifiers?: number;
|
|
172
177
|
constructor(name: string, originalType: Type, signature: LocalSignature);
|
|
173
178
|
getName(): string;
|
|
174
179
|
setOriginalType(type: Type): void;
|
|
175
180
|
getOriginalType(): Type;
|
|
176
181
|
toString(): string;
|
|
177
182
|
getExportType(): ExportType;
|
|
178
|
-
getModifiers():
|
|
183
|
+
getModifiers(): number;
|
|
184
|
+
containsModifier(modifierType: ModifierType): boolean;
|
|
185
|
+
setModifiers(modifiers: number): void;
|
|
186
|
+
addModifier(modifier: ModifierType | number): void;
|
|
187
|
+
removeModifier(modifier: ModifierType): void;
|
|
179
188
|
getSignature(): LocalSignature;
|
|
180
189
|
}
|
|
181
190
|
export declare class GenericType extends Type {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../src/core/base/Type.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,kBAA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IAAI,IAAI,GAAG,SAAS;IAIjC,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI/B,QAAQ,CAAC,KAAK,EAAE,MAAM;IAItB,QAAQ,IAAI,MAAM;IAIlB,QAAQ,IAAI,MAAM;CAU5B;AAED,qBAAa,oBAAoB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe;IAKlD,aAAa,IAAI,MAAM;IAIvB,WAAW,IAAI,eAAe;CAGxC;AAED,8BAAsB,cAAe,SAAQ,IAAI;IAC7C,OAAO,CAAC,UAAU,CAAS;IAE3B,SAAS,aAAa,UAAU,EAAE,MAAM;IAKjC,aAAa,IAAI,MAAM;IAIvB,QAAQ;CAGlB;AAED,qBAAa,uBAAwB,SAAQ,cAAc;IACvD,OAAO,CAAC,kBAAkB,CAAkD;WAE9D,WAAW,CAAC,SAAS,EAAE,kBAAkB,GAAG,uBAAuB;IAM1E,qBAAqB,IAAI,kBAAkB;IAI3C,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;gBAIrD,UAAU,EAAE,MAAM;IAIvB,aAAa,IAAI,MAAM;CAGjC;AAED,qBAAa,uBAAwB,SAAQ,cAAc;gBAC3C,UAAU,EAAE,MAAM;CAGjC"}
|
package/lib/core/base/Type.js
CHANGED
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.AnnotationTypeQueryType = exports.AnnotationNamespaceType = exports.AnnotationType = exports.AliasTypeDeclaration = exports.GenericType = exports.AliasType = exports.TupleType = exports.ArrayType = exports.ClassType = exports.FunctionType = exports.NeverType = exports.VoidType = exports.UnionType = exports.LiteralType = exports.UndefinedType = exports.NullType = exports.StringType = exports.NumberType = exports.BooleanType = exports.PrimitiveType = exports.UnclearReferenceType = exports.UnknownType = exports.AnyType = exports.Type = void 0;
|
|
18
18
|
const ArkSignature_1 = require("../model/ArkSignature");
|
|
19
19
|
const ArkExport_1 = require("../model/ArkExport");
|
|
20
|
+
const ArkBaseModel_1 = require("../model/ArkBaseModel");
|
|
21
|
+
const TSConst_1 = require("../common/TSConst");
|
|
20
22
|
/**
|
|
21
23
|
* @category core/base/type
|
|
22
24
|
*/
|
|
@@ -35,7 +37,7 @@ class AnyType extends Type {
|
|
|
35
37
|
super();
|
|
36
38
|
}
|
|
37
39
|
toString() {
|
|
38
|
-
return
|
|
40
|
+
return TSConst_1.ANY_KEYWORD;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
exports.AnyType = AnyType;
|
|
@@ -52,37 +54,11 @@ class UnknownType extends Type {
|
|
|
52
54
|
super();
|
|
53
55
|
}
|
|
54
56
|
toString() {
|
|
55
|
-
return
|
|
57
|
+
return TSConst_1.UNKNOWN_KEYWORD;
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
exports.UnknownType = UnknownType;
|
|
59
61
|
UnknownType.INSTANCE = new UnknownType();
|
|
60
|
-
// /**
|
|
61
|
-
// * typeParameter type
|
|
62
|
-
// * @category core/base/type
|
|
63
|
-
// */
|
|
64
|
-
// export class TypeParameterType extends Type {
|
|
65
|
-
// private name: string;
|
|
66
|
-
// private type: Type;
|
|
67
|
-
//
|
|
68
|
-
// constructor(name: string, type: Type = UnknownType.getInstance()) {
|
|
69
|
-
// super();
|
|
70
|
-
// this.name = name;
|
|
71
|
-
// this.type = type;
|
|
72
|
-
// }
|
|
73
|
-
//
|
|
74
|
-
// public getName() {
|
|
75
|
-
// return this.name;
|
|
76
|
-
// }
|
|
77
|
-
//
|
|
78
|
-
// public getType() {
|
|
79
|
-
// return this.type;
|
|
80
|
-
// }
|
|
81
|
-
//
|
|
82
|
-
// public toString() {
|
|
83
|
-
// return this.name;
|
|
84
|
-
// }
|
|
85
|
-
// }
|
|
86
62
|
/**
|
|
87
63
|
* unclear type
|
|
88
64
|
* @category core/base/type
|
|
@@ -127,7 +103,7 @@ class PrimitiveType extends Type {
|
|
|
127
103
|
exports.PrimitiveType = PrimitiveType;
|
|
128
104
|
class BooleanType extends PrimitiveType {
|
|
129
105
|
constructor() {
|
|
130
|
-
super(
|
|
106
|
+
super(TSConst_1.BOOLEAN_KEYWORD);
|
|
131
107
|
}
|
|
132
108
|
static getInstance() {
|
|
133
109
|
return this.INSTANCE;
|
|
@@ -137,7 +113,7 @@ exports.BooleanType = BooleanType;
|
|
|
137
113
|
BooleanType.INSTANCE = new BooleanType();
|
|
138
114
|
class NumberType extends PrimitiveType {
|
|
139
115
|
constructor() {
|
|
140
|
-
super(
|
|
116
|
+
super(TSConst_1.NUMBER_KEYWORD);
|
|
141
117
|
}
|
|
142
118
|
static getInstance() {
|
|
143
119
|
return this.INSTANCE;
|
|
@@ -147,7 +123,7 @@ exports.NumberType = NumberType;
|
|
|
147
123
|
NumberType.INSTANCE = new NumberType();
|
|
148
124
|
class StringType extends PrimitiveType {
|
|
149
125
|
constructor() {
|
|
150
|
-
super(
|
|
126
|
+
super(TSConst_1.STRING_KEYWORD);
|
|
151
127
|
}
|
|
152
128
|
static getInstance() {
|
|
153
129
|
return this.INSTANCE;
|
|
@@ -164,7 +140,7 @@ class NullType extends PrimitiveType {
|
|
|
164
140
|
return this.INSTANCE;
|
|
165
141
|
}
|
|
166
142
|
constructor() {
|
|
167
|
-
super(
|
|
143
|
+
super(TSConst_1.NULL_KEYWORD);
|
|
168
144
|
}
|
|
169
145
|
}
|
|
170
146
|
exports.NullType = NullType;
|
|
@@ -178,7 +154,7 @@ class UndefinedType extends PrimitiveType {
|
|
|
178
154
|
return this.INSTANCE;
|
|
179
155
|
}
|
|
180
156
|
constructor() {
|
|
181
|
-
super(
|
|
157
|
+
super(TSConst_1.UNDEFINED_KEYWORD);
|
|
182
158
|
}
|
|
183
159
|
}
|
|
184
160
|
exports.UndefinedType = UndefinedType;
|
|
@@ -222,11 +198,7 @@ class UnionType extends Type {
|
|
|
222
198
|
this.currType = newType;
|
|
223
199
|
}
|
|
224
200
|
toString() {
|
|
225
|
-
|
|
226
|
-
if (!(this.currType instanceof UnknownType) && this.currType != this) {
|
|
227
|
-
typeStr += '-' + this.currType;
|
|
228
|
-
}
|
|
229
|
-
return typeStr;
|
|
201
|
+
return this.types.join('|');
|
|
230
202
|
}
|
|
231
203
|
}
|
|
232
204
|
exports.UnionType = UnionType;
|
|
@@ -242,7 +214,7 @@ class VoidType extends Type {
|
|
|
242
214
|
super();
|
|
243
215
|
}
|
|
244
216
|
toString() {
|
|
245
|
-
return
|
|
217
|
+
return TSConst_1.VOID_KEYWORD;
|
|
246
218
|
}
|
|
247
219
|
}
|
|
248
220
|
exports.VoidType = VoidType;
|
|
@@ -255,7 +227,7 @@ class NeverType extends Type {
|
|
|
255
227
|
super();
|
|
256
228
|
}
|
|
257
229
|
toString() {
|
|
258
|
-
return
|
|
230
|
+
return TSConst_1.NEVER_KEYWORD;
|
|
259
231
|
}
|
|
260
232
|
}
|
|
261
233
|
exports.NeverType = NeverType;
|
|
@@ -304,7 +276,13 @@ class ClassType extends Type {
|
|
|
304
276
|
this.realGenericTypes = types;
|
|
305
277
|
}
|
|
306
278
|
toString() {
|
|
307
|
-
|
|
279
|
+
var _a;
|
|
280
|
+
let temp = this.classSignature.toString();
|
|
281
|
+
let generic = (_a = this.realGenericTypes) === null || _a === void 0 ? void 0 : _a.join(',');
|
|
282
|
+
if (generic) {
|
|
283
|
+
temp += `<${generic}>`;
|
|
284
|
+
}
|
|
285
|
+
return temp;
|
|
308
286
|
}
|
|
309
287
|
}
|
|
310
288
|
exports.ClassType = ClassType;
|
|
@@ -314,6 +292,10 @@ class ArrayType extends Type {
|
|
|
314
292
|
this.baseType = baseType;
|
|
315
293
|
this.dimension = dimension;
|
|
316
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns the base type of this array, such as `Any`, `Unknown`, `TypeParameter`, etc.
|
|
297
|
+
* @returns The base type of array.
|
|
298
|
+
*/
|
|
317
299
|
getBaseType() {
|
|
318
300
|
return this.baseType;
|
|
319
301
|
}
|
|
@@ -374,7 +356,30 @@ class AliasType extends Type {
|
|
|
374
356
|
return ArkExport_1.ExportType.TYPE;
|
|
375
357
|
}
|
|
376
358
|
getModifiers() {
|
|
377
|
-
|
|
359
|
+
if (!this.modifiers) {
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
362
|
+
return this.modifiers;
|
|
363
|
+
}
|
|
364
|
+
containsModifier(modifierType) {
|
|
365
|
+
if (!this.modifiers) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return (this.modifiers & modifierType) === modifierType;
|
|
369
|
+
}
|
|
370
|
+
setModifiers(modifiers) {
|
|
371
|
+
if (modifiers !== 0) {
|
|
372
|
+
this.modifiers = modifiers;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
addModifier(modifier) {
|
|
376
|
+
this.modifiers = this.getModifiers() | modifier;
|
|
377
|
+
}
|
|
378
|
+
removeModifier(modifier) {
|
|
379
|
+
if (!this.modifiers) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.modifiers &= ArkBaseModel_1.MODIFIER_TYPE_MASK ^ modifier;
|
|
378
383
|
}
|
|
379
384
|
getSignature() {
|
|
380
385
|
return this.signature;
|
package/lib/core/base/Value.d.ts
CHANGED
|
@@ -3,9 +3,31 @@ import { Type } from './Type';
|
|
|
3
3
|
* @category core/base
|
|
4
4
|
*/
|
|
5
5
|
export interface Value {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Return a list of values which are contained in this {@link Value}.
|
|
8
|
+
* Value is a core interface in ArkAnalyzer, which may represent any value or expression.
|
|
9
|
+
* @returns An **array** of values used by this value.
|
|
10
|
+
*/
|
|
7
11
|
getUses(): Value[];
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Return the type of this value. The interface is encapsulated in {@link Value}.
|
|
14
|
+
* The `Type` is defined in type.ts, such as **Any**, **Unknown**, **TypeParameter**,
|
|
15
|
+
* **UnclearReference**, **Primitive**, **Number**, **String**, etc.
|
|
16
|
+
* @returns The type of this value.
|
|
17
|
+
* @example
|
|
18
|
+
* 1. In the declaration statement, determine the left-value type and right-value type.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
let leftValue:Value;
|
|
22
|
+
let rightValue:Value;
|
|
23
|
+
...
|
|
24
|
+
if (leftValue.getType() instanceof UnknownType &&
|
|
25
|
+
!(rightValue.getType() instanceof UnknownType) &&
|
|
26
|
+
!(rightValue.getType() instanceof UndefinedType)) {
|
|
27
|
+
...
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
*/
|
|
9
31
|
getType(): Type;
|
|
10
32
|
}
|
|
11
33
|
//# sourceMappingURL=Value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Value.d.ts","sourceRoot":"","sources":["../../../src/core/base/Value.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,KAAK;IAClB
|
|
1
|
+
{"version":3,"file":"Value.d.ts","sourceRoot":"","sources":["../../../src/core/base/Value.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,KAAK;IAClB;;;;MAIE;IACF,OAAO,IAAI,KAAK,EAAE,CAAC;IAEnB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,IAAG,IAAI,CAAC;CAClB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum ArkErrorCode {
|
|
2
|
+
OK = 0,
|
|
3
|
+
CLASS_INSTANCE_FIELD_UNDEFINDED = -1,
|
|
4
|
+
BB_MORE_THAN_ONE_BRANCH_RET_STMT = -2,
|
|
5
|
+
BB_BRANCH_RET_STMT_NOT_AT_END = -3,
|
|
6
|
+
CFG_NOT_FOUND_START_BLOCK = -4,
|
|
7
|
+
CFG_HAS_UNREACHABLE_BLOCK = -5,
|
|
8
|
+
METHOD_SIGNATURE_UNDEFINED = -6,
|
|
9
|
+
METHOD_SIGNATURE_LINE_UNMATCHED = -7
|
|
10
|
+
}
|
|
11
|
+
export interface ArkError {
|
|
12
|
+
errCode: ArkErrorCode;
|
|
13
|
+
errMsg?: string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ArkError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArkError.d.ts","sourceRoot":"","sources":["../../../src/core/common/ArkError.ts"],"names":[],"mappings":"AAeA,oBAAY,YAAY;IACpB,EAAE,IAAI;IACN,+BAA+B,KAAK;IACpC,gCAAgC,KAAK;IACrC,6BAA6B,KAAK;IAClC,yBAAyB,KAAK;IAC9B,yBAAyB,KAAK;IAC9B,0BAA0B,KAAK;IAC/B,+BAA+B,KAAK;CACvC;AAED,MAAM,WAAW,QAAQ;IACrB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.ArkErrorCode = void 0;
|
|
18
|
+
var ArkErrorCode;
|
|
19
|
+
(function (ArkErrorCode) {
|
|
20
|
+
ArkErrorCode[ArkErrorCode["OK"] = 0] = "OK";
|
|
21
|
+
ArkErrorCode[ArkErrorCode["CLASS_INSTANCE_FIELD_UNDEFINDED"] = -1] = "CLASS_INSTANCE_FIELD_UNDEFINDED";
|
|
22
|
+
ArkErrorCode[ArkErrorCode["BB_MORE_THAN_ONE_BRANCH_RET_STMT"] = -2] = "BB_MORE_THAN_ONE_BRANCH_RET_STMT";
|
|
23
|
+
ArkErrorCode[ArkErrorCode["BB_BRANCH_RET_STMT_NOT_AT_END"] = -3] = "BB_BRANCH_RET_STMT_NOT_AT_END";
|
|
24
|
+
ArkErrorCode[ArkErrorCode["CFG_NOT_FOUND_START_BLOCK"] = -4] = "CFG_NOT_FOUND_START_BLOCK";
|
|
25
|
+
ArkErrorCode[ArkErrorCode["CFG_HAS_UNREACHABLE_BLOCK"] = -5] = "CFG_HAS_UNREACHABLE_BLOCK";
|
|
26
|
+
ArkErrorCode[ArkErrorCode["METHOD_SIGNATURE_UNDEFINED"] = -6] = "METHOD_SIGNATURE_UNDEFINED";
|
|
27
|
+
ArkErrorCode[ArkErrorCode["METHOD_SIGNATURE_LINE_UNMATCHED"] = -7] = "METHOD_SIGNATURE_LINE_UNMATCHED";
|
|
28
|
+
})(ArkErrorCode = exports.ArkErrorCode || (exports.ArkErrorCode = {}));
|
|
@@ -6,30 +6,37 @@ import { Stmt } from '../base/Stmt';
|
|
|
6
6
|
import { AliasType, AliasTypeDeclaration } from '../base/Type';
|
|
7
7
|
import { ArkMethod } from '../model/ArkMethod';
|
|
8
8
|
import { FullPosition } from '../base/Position';
|
|
9
|
-
export declare const DUMMY_INITIALIZER_STMT = "dummyInitializerStmt";
|
|
10
9
|
type ValueAndStmts = {
|
|
11
10
|
value: Value;
|
|
12
11
|
valueOriginalPositions: FullPosition[];
|
|
13
12
|
stmts: Stmt[];
|
|
14
13
|
};
|
|
14
|
+
export declare class DummyStmt extends Stmt {
|
|
15
|
+
constructor(text: string);
|
|
16
|
+
toString(): string;
|
|
17
|
+
}
|
|
15
18
|
export declare class ArkIRTransformer {
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
static readonly DUMMY_LOOP_INITIALIZER_STMT = "LoopInitializer";
|
|
20
|
+
static readonly DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT = "ConditionalOperatorIfTrue";
|
|
21
|
+
static readonly DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT = "ConditionalOperatorIfFalse";
|
|
22
|
+
static readonly DUMMY_CONDITIONAL_OPERATOR_END_STMT = "ConditionalOperatorEnd";
|
|
23
|
+
private conditionalOperatorNo;
|
|
24
|
+
private tempLocalNo;
|
|
18
25
|
private locals;
|
|
19
26
|
private sourceFile;
|
|
20
27
|
private declaringMethod;
|
|
21
28
|
private thisLocal;
|
|
22
29
|
private inBuilderMethod;
|
|
23
|
-
private stmtToOriginalStmt;
|
|
24
30
|
private aliasTypeMap;
|
|
31
|
+
private stmtsHaveOriginalText;
|
|
25
32
|
private builderMethodContextFlag;
|
|
26
33
|
constructor(sourceFile: ts.SourceFile, declaringMethod: ArkMethod);
|
|
27
34
|
getLocals(): Set<Local>;
|
|
28
35
|
getThisLocal(): Local;
|
|
29
|
-
getStmtToOriginalStmt(): Map<Stmt, Stmt>;
|
|
30
36
|
getAliasTypeMap(): Map<string, [AliasType, AliasTypeDeclaration]>;
|
|
31
37
|
prebuildStmts(): Stmt[];
|
|
32
38
|
tsNodeToStmts(node: ts.Node): Stmt[];
|
|
39
|
+
private functionDeclarationToStmts;
|
|
33
40
|
private returnStatementToStmts;
|
|
34
41
|
private blockToStmts;
|
|
35
42
|
private expressionStatementToStmts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkIRTransformer.d.ts","sourceRoot":"","sources":["../../../src/core/common/ArkIRTransformer.ts"],"names":[],"mappings":"AAeA,OAAO,EAkBH,cAAc,EAGd,aAAa,EAChB,M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