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/Local.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Stmt } from './Stmt';
|
|
2
2
|
import { Type } from './Type';
|
|
3
3
|
import { Value } from './Value';
|
|
4
|
-
import { ArkClass } from '../model/ArkClass';
|
|
5
4
|
import { ArkExport, ExportType } from '../model/ArkExport';
|
|
6
|
-
import { Decorator } from './Decorator';
|
|
7
5
|
import { LocalSignature } from '../model/ArkSignature';
|
|
6
|
+
import { ModifierType } from '../model/ArkBaseModel';
|
|
7
|
+
import { ArkMethod } from '../model/ArkMethod';
|
|
8
8
|
/**
|
|
9
9
|
* @category core/base
|
|
10
10
|
*/
|
|
@@ -15,23 +15,88 @@ export declare class Local implements Value, ArkExport {
|
|
|
15
15
|
private declaringStmt;
|
|
16
16
|
private usedStmts;
|
|
17
17
|
private signature?;
|
|
18
|
-
private constFlag
|
|
18
|
+
private constFlag?;
|
|
19
19
|
constructor(name: string, type?: Type);
|
|
20
|
-
inferType(
|
|
20
|
+
inferType(arkMethod: ArkMethod): Local;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the name of local value.
|
|
23
|
+
* @returns The name of local value.
|
|
24
|
+
* @example
|
|
25
|
+
* 1. get the name of local value.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
arkClass.getDefaultArkMethod()?.getBody().getLocals().forEach(local => {
|
|
29
|
+
const arkField = new ArkField();
|
|
30
|
+
arkField.setFieldType(ArkField.DEFAULT_ARK_Field);
|
|
31
|
+
arkField.setDeclaringClass(defaultClass);
|
|
32
|
+
arkField.setType(local.getType());
|
|
33
|
+
arkField.setName(local.getName());
|
|
34
|
+
arkField.genSignature();
|
|
35
|
+
defaultClass.addField(arkField);
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
*/
|
|
21
39
|
getName(): string;
|
|
22
40
|
setName(name: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the type of this local.
|
|
43
|
+
* @returns The type of this local.
|
|
44
|
+
*/
|
|
23
45
|
getType(): Type;
|
|
24
46
|
setType(newType: Type): void;
|
|
25
47
|
getOriginalValue(): Value | null;
|
|
26
48
|
setOriginalValue(originalValue: Value): void;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the declaring statement, which may also be a **null**.
|
|
51
|
+
* For example, if the code snippet in a function is `let dd = cc + 5;` where `cc` is a **number**
|
|
52
|
+
* and `dd` is not defined before, then the declaring statemet of local `dd`:
|
|
53
|
+
* - its **string** text is "dd = cc + 5".
|
|
54
|
+
* - the **strings** of right operand and left operand are "cc + 5" and "dd", respectively.
|
|
55
|
+
* - three values are used in this statement: `cc + 5` (i.e., a normal binary operation expression), `cc` (a local), and `5` (a constant), respectively.
|
|
56
|
+
* @returns The declaring statement (maybe a **null**) of the local.
|
|
57
|
+
* @example
|
|
58
|
+
* 1. get the statement that defines the local for the first time.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
let stmt = local.getDeclaringStmt();
|
|
62
|
+
if (stmt !== null) {
|
|
63
|
+
...
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
*/
|
|
27
67
|
getDeclaringStmt(): Stmt | null;
|
|
28
68
|
setDeclaringStmt(declaringStmt: Stmt): void;
|
|
69
|
+
/**
|
|
70
|
+
* Returns an **array** of values which are contained in this local.
|
|
71
|
+
* @returns An **array** of values used by this local.
|
|
72
|
+
*/
|
|
29
73
|
getUses(): Value[];
|
|
30
74
|
addUsedStmt(usedStmt: Stmt): void;
|
|
75
|
+
/**
|
|
76
|
+
* Returns an array of statements used by the local, i.e., the statements in which the local participate.
|
|
77
|
+
* For example, if the code snippet is `let dd = cc + 5;` where `cc` is a local and `cc` only appears once,
|
|
78
|
+
* then the length of **array** returned is 1 and `Stmts[0]` will be same as the example described
|
|
79
|
+
* in the `Local.getDeclaringStmt()`.
|
|
80
|
+
* @returns An array of statements used by the local.
|
|
81
|
+
*/
|
|
31
82
|
getUsedStmts(): Stmt[];
|
|
83
|
+
/**
|
|
84
|
+
* Get a string of local name in Local
|
|
85
|
+
* @returns The string of local name.
|
|
86
|
+
* @example
|
|
87
|
+
* 1. get a name string.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
for (const value of stmt.getUses()) {
|
|
91
|
+
const name = value.toString();
|
|
92
|
+
...
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
*/
|
|
32
96
|
toString(): string;
|
|
33
97
|
getExportType(): ExportType;
|
|
34
|
-
getModifiers():
|
|
98
|
+
getModifiers(): number;
|
|
99
|
+
containsModifier(modifierType: ModifierType): boolean;
|
|
35
100
|
getSignature(): LocalSignature;
|
|
36
101
|
setSignature(signature: LocalSignature): void;
|
|
37
102
|
getConstFlag(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Local.d.ts","sourceRoot":"","sources":["../../../src/core/base/Local.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAe,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Local.d.ts","sourceRoot":"","sources":["../../../src/core/base/Local.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAe,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAkB,cAAc,EAAmB,MAAM,uBAAuB,CAAC;AAGxF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,o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
|
package/lib/core/base/Local.js
CHANGED
|
@@ -21,33 +21,55 @@ const ArkExport_1 = require("../model/ArkExport");
|
|
|
21
21
|
const ArkSignature_1 = require("../model/ArkSignature");
|
|
22
22
|
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
23
23
|
const Const_1 = require("../common/Const");
|
|
24
|
+
const ArkBaseModel_1 = require("../model/ArkBaseModel");
|
|
24
25
|
/**
|
|
25
26
|
* @category core/base
|
|
26
27
|
*/
|
|
27
28
|
class Local {
|
|
28
29
|
constructor(name, type = Type_1.UnknownType.getInstance()) {
|
|
29
|
-
this.constFlag = false;
|
|
30
30
|
this.name = name;
|
|
31
31
|
this.type = type;
|
|
32
32
|
this.originalValue = null;
|
|
33
33
|
this.declaringStmt = null;
|
|
34
34
|
this.usedStmts = [];
|
|
35
35
|
}
|
|
36
|
-
inferType(
|
|
36
|
+
inferType(arkMethod) {
|
|
37
37
|
if (TypeInference_1.TypeInference.isUnclearType(this.type)) {
|
|
38
|
-
const type = TypeInference_1.TypeInference.inferUnclearReferenceType(this.name,
|
|
38
|
+
const type = TypeInference_1.TypeInference.inferUnclearReferenceType(this.name, arkMethod.getDeclaringArkClass());
|
|
39
39
|
if (type) {
|
|
40
40
|
this.type = type;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the name of local value.
|
|
47
|
+
* @returns The name of local value.
|
|
48
|
+
* @example
|
|
49
|
+
* 1. get the name of local value.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
arkClass.getDefaultArkMethod()?.getBody().getLocals().forEach(local => {
|
|
53
|
+
const arkField = new ArkField();
|
|
54
|
+
arkField.setFieldType(ArkField.DEFAULT_ARK_Field);
|
|
55
|
+
arkField.setDeclaringClass(defaultClass);
|
|
56
|
+
arkField.setType(local.getType());
|
|
57
|
+
arkField.setName(local.getName());
|
|
58
|
+
arkField.genSignature();
|
|
59
|
+
defaultClass.addField(arkField);
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
*/
|
|
45
63
|
getName() {
|
|
46
64
|
return this.name;
|
|
47
65
|
}
|
|
48
66
|
setName(name) {
|
|
49
67
|
this.name = name;
|
|
50
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the type of this local.
|
|
71
|
+
* @returns The type of this local.
|
|
72
|
+
*/
|
|
51
73
|
getType() {
|
|
52
74
|
return this.type;
|
|
53
75
|
}
|
|
@@ -60,21 +82,63 @@ class Local {
|
|
|
60
82
|
setOriginalValue(originalValue) {
|
|
61
83
|
this.originalValue = originalValue;
|
|
62
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the declaring statement, which may also be a **null**.
|
|
87
|
+
* For example, if the code snippet in a function is `let dd = cc + 5;` where `cc` is a **number**
|
|
88
|
+
* and `dd` is not defined before, then the declaring statemet of local `dd`:
|
|
89
|
+
* - its **string** text is "dd = cc + 5".
|
|
90
|
+
* - the **strings** of right operand and left operand are "cc + 5" and "dd", respectively.
|
|
91
|
+
* - three values are used in this statement: `cc + 5` (i.e., a normal binary operation expression), `cc` (a local), and `5` (a constant), respectively.
|
|
92
|
+
* @returns The declaring statement (maybe a **null**) of the local.
|
|
93
|
+
* @example
|
|
94
|
+
* 1. get the statement that defines the local for the first time.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
let stmt = local.getDeclaringStmt();
|
|
98
|
+
if (stmt !== null) {
|
|
99
|
+
...
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
*/
|
|
63
103
|
getDeclaringStmt() {
|
|
64
104
|
return this.declaringStmt;
|
|
65
105
|
}
|
|
66
106
|
setDeclaringStmt(declaringStmt) {
|
|
67
107
|
this.declaringStmt = declaringStmt;
|
|
68
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns an **array** of values which are contained in this local.
|
|
111
|
+
* @returns An **array** of values used by this local.
|
|
112
|
+
*/
|
|
69
113
|
getUses() {
|
|
70
114
|
return [];
|
|
71
115
|
}
|
|
72
116
|
addUsedStmt(usedStmt) {
|
|
73
117
|
this.usedStmts.push(usedStmt);
|
|
74
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns an array of statements used by the local, i.e., the statements in which the local participate.
|
|
121
|
+
* For example, if the code snippet is `let dd = cc + 5;` where `cc` is a local and `cc` only appears once,
|
|
122
|
+
* then the length of **array** returned is 1 and `Stmts[0]` will be same as the example described
|
|
123
|
+
* in the `Local.getDeclaringStmt()`.
|
|
124
|
+
* @returns An array of statements used by the local.
|
|
125
|
+
*/
|
|
75
126
|
getUsedStmts() {
|
|
76
127
|
return this.usedStmts;
|
|
77
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a string of local name in Local
|
|
131
|
+
* @returns The string of local name.
|
|
132
|
+
* @example
|
|
133
|
+
* 1. get a name string.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
for (const value of stmt.getUses()) {
|
|
137
|
+
const name = value.toString();
|
|
138
|
+
...
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
*/
|
|
78
142
|
toString() {
|
|
79
143
|
return this.getName();
|
|
80
144
|
}
|
|
@@ -82,7 +146,13 @@ class Local {
|
|
|
82
146
|
return ArkExport_1.ExportType.LOCAL;
|
|
83
147
|
}
|
|
84
148
|
getModifiers() {
|
|
85
|
-
return
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
containsModifier(modifierType) {
|
|
152
|
+
if (modifierType === ArkBaseModel_1.ModifierType.CONST) {
|
|
153
|
+
return this.getConstFlag();
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
86
156
|
}
|
|
87
157
|
getSignature() {
|
|
88
158
|
var _a;
|
|
@@ -92,6 +162,9 @@ class Local {
|
|
|
92
162
|
this.signature = signature;
|
|
93
163
|
}
|
|
94
164
|
getConstFlag() {
|
|
165
|
+
if (!this.constFlag) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
95
168
|
return this.constFlag;
|
|
96
169
|
}
|
|
97
170
|
setConstFlag(newConstFlag) {
|
package/lib/core/base/Ref.d.ts
CHANGED
|
@@ -2,21 +2,52 @@ import { FieldSignature } from '../model/ArkSignature';
|
|
|
2
2
|
import { Local } from './Local';
|
|
3
3
|
import { ClassType, Type } from './Type';
|
|
4
4
|
import { Value } from './Value';
|
|
5
|
-
import {
|
|
5
|
+
import { ArkMethod } from '../model/ArkMethod';
|
|
6
6
|
/**
|
|
7
7
|
* @category core/base/ref
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class AbstractRef implements Value {
|
|
10
10
|
abstract getUses(): Value[];
|
|
11
11
|
abstract getType(): Type;
|
|
12
|
-
inferType(
|
|
12
|
+
inferType(arkMethod: ArkMethod): AbstractRef;
|
|
13
13
|
}
|
|
14
14
|
export declare class ArkArrayRef extends AbstractRef {
|
|
15
15
|
private base;
|
|
16
16
|
private index;
|
|
17
17
|
constructor(base: Local, index: Value);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the base of this array reference. Array reference refers to access to array elements.
|
|
20
|
+
* Array references usually consist of an local variable and an index.
|
|
21
|
+
* For example, `a[i]` is a typical array reference, where `a` is the base (i.e., local variable)
|
|
22
|
+
* pointing to the actual memory location where the array is stored
|
|
23
|
+
* and `i` is the index indicating access to the `i-th` element from array `a`.
|
|
24
|
+
* @returns the base of this array reference.
|
|
25
|
+
* @example
|
|
26
|
+
* 1. Get the base and the specific elements.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// Create an array
|
|
30
|
+
let myArray: number[] = [10, 20, 30, 40];
|
|
31
|
+
// Create an ArrayRef object representing a reference to myArray[2]
|
|
32
|
+
let arrayRef = new ArkArrayRef(myArray, 2);
|
|
33
|
+
// Use the getBase() method to get the base of the array
|
|
34
|
+
let baseArray = arrayRef.getBase();
|
|
35
|
+
|
|
36
|
+
console.log("Base array:", baseArray); // Output: Base array: [10, 20, 30, 40]
|
|
37
|
+
|
|
38
|
+
// Use baseArray and obeject index of ArrayRef to access to specific array elements
|
|
39
|
+
let element = baseArray[arrayRef.index];
|
|
40
|
+
console.log("Element at index", arrayRef.index, ":", element); // Output: Element at index 2 : 30
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
18
43
|
getBase(): Local;
|
|
19
44
|
setBase(newBase: Local): void;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the index of this array reference.
|
|
47
|
+
* In TypeScript, an array reference means that the variable stores
|
|
48
|
+
* the memory address of the array rather than the actual data of the array.
|
|
49
|
+
* @returns The index of this array reference.
|
|
50
|
+
*/
|
|
20
51
|
getIndex(): Value;
|
|
21
52
|
setIndex(newIndex: Value): void;
|
|
22
53
|
getType(): Type;
|
|
@@ -26,7 +57,29 @@ export declare class ArkArrayRef extends AbstractRef {
|
|
|
26
57
|
export declare abstract class AbstractFieldRef extends AbstractRef {
|
|
27
58
|
private fieldSignature;
|
|
28
59
|
constructor(fieldSignature: FieldSignature);
|
|
60
|
+
/**
|
|
61
|
+
* Returns the the field name as a **string**.
|
|
62
|
+
* @returns The the field name.
|
|
63
|
+
*/
|
|
29
64
|
getFieldName(): string;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a field signature, which consists of a class signature,
|
|
67
|
+
* a **string** field name, and a **boolean** label indicating whether it is static or not.
|
|
68
|
+
* @returns The field signature.
|
|
69
|
+
* @example
|
|
70
|
+
* 1. Compare two Fields
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const fieldSignature = new FieldSignature();
|
|
74
|
+
fieldSignature.setFieldName(...);
|
|
75
|
+
const fieldRef = new ArkInstanceFieldRef(baseValue as Local, fieldSignature);
|
|
76
|
+
...
|
|
77
|
+
if (fieldRef.getFieldSignature().getFieldName() ===
|
|
78
|
+
targetField.getFieldSignature().getFieldName()) {
|
|
79
|
+
...
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
*/
|
|
30
83
|
getFieldSignature(): FieldSignature;
|
|
31
84
|
setFieldSignature(newFieldSignature: FieldSignature): void;
|
|
32
85
|
getType(): Type;
|
|
@@ -34,11 +87,32 @@ export declare abstract class AbstractFieldRef extends AbstractRef {
|
|
|
34
87
|
export declare class ArkInstanceFieldRef extends AbstractFieldRef {
|
|
35
88
|
private base;
|
|
36
89
|
constructor(base: Local, fieldSignature: FieldSignature);
|
|
90
|
+
/**
|
|
91
|
+
* Returns the local of field, showing which object this field belongs to.
|
|
92
|
+
* A {@link Local} consists of :
|
|
93
|
+
* - Name: the **string** name of local value, e.g., "$temp0".
|
|
94
|
+
* - Type: the type of value.
|
|
95
|
+
* @returns The object that the field belongs to.
|
|
96
|
+
* @example
|
|
97
|
+
* 1. Get a base.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
if (expr instanceof ArkInstanceFieldRef) {
|
|
101
|
+
...
|
|
102
|
+
let base = expr.getBase();
|
|
103
|
+
if (base.getName() == 'this') {
|
|
104
|
+
...
|
|
105
|
+
}
|
|
106
|
+
...
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
*/
|
|
37
110
|
getBase(): Local;
|
|
38
111
|
setBase(newBase: Local): void;
|
|
39
112
|
getUses(): Value[];
|
|
40
113
|
toString(): string;
|
|
41
|
-
|
|
114
|
+
private getBaseType;
|
|
115
|
+
inferType(arkMethod: ArkMethod): AbstractRef;
|
|
42
116
|
private getNewFieldSignature;
|
|
43
117
|
}
|
|
44
118
|
export declare class ArkStaticFieldRef extends AbstractFieldRef {
|
|
@@ -53,14 +127,14 @@ export declare class ArkParameterRef extends AbstractRef {
|
|
|
53
127
|
getIndex(): number;
|
|
54
128
|
getType(): Type;
|
|
55
129
|
setType(newType: Type): void;
|
|
56
|
-
inferType(
|
|
130
|
+
inferType(arkMethod: ArkMethod): AbstractRef;
|
|
57
131
|
getUses(): Value[];
|
|
58
132
|
toString(): string;
|
|
59
133
|
}
|
|
60
134
|
export declare class ArkThisRef extends AbstractRef {
|
|
61
135
|
private type;
|
|
62
136
|
constructor(type: ClassType);
|
|
63
|
-
inferType(
|
|
137
|
+
inferType(arkMethod: ArkMethod): AbstractRef;
|
|
64
138
|
getType(): ClassType;
|
|
65
139
|
getUses(): Value[];
|
|
66
140
|
toString(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/core/base/Ref.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAiB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,
|
|
1
|
+
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/core/base/Ref.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAiB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAIH,SAAS,EAET,IAAI,EAKP,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM/C;;GAEG;AACH,8BAAsB,WAAY,YAAW,KAAK;IAC9C,QAAQ,CAAC,OAAO,IAAI,KAAK,EAAE;IAE3B,QAAQ,CAAC,OAAO,IAAI,IAAI;IAEjB,SAAS,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW;CAGtD;AAED,qBAAa,WAAY,SAAQ,WAAW;IACxC,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,KAAK,CAAQ;gBAET,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAMrC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACI,OAAO,IAAI,KAAK;IAIhB,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI;IAIpC;;;;;OAKG;IACI,QAAQ,IAAI,KAAK;IAIjB,QAAQ,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI;IAI/B,OAAO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