arkanalyzer 1.0.19 → 1.0.20
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/Scene.d.ts +11 -5
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +74 -29
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +3 -1
- package/lib/core/common/DummyMainCreater.d.ts +4 -0
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +63 -44
- package/lib/core/dataflow/GenericDataFlow.d.ts +143 -0
- package/lib/core/dataflow/GenericDataFlow.d.ts.map +1 -0
- package/lib/core/dataflow/GenericDataFlow.js +109 -0
- package/lib/core/dataflow/ReachingDef.d.ts +63 -0
- package/lib/core/dataflow/ReachingDef.d.ts.map +1 -0
- package/lib/core/dataflow/ReachingDef.js +168 -0
- package/lib/core/graph/BaseExplicitGraph.d.ts +3 -8
- package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
- package/lib/core/graph/BaseImplicitGraph.d.ts +78 -0
- package/lib/core/graph/BaseImplicitGraph.d.ts.map +1 -0
- package/lib/core/graph/BaseImplicitGraph.js +78 -0
- package/lib/core/graph/GraphTraits.d.ts +8 -0
- package/lib/core/graph/GraphTraits.d.ts.map +1 -0
- package/lib/core/graph/GraphTraits.js +16 -0
- package/lib/core/graph/Scc.d.ts +3 -2
- package/lib/core/graph/Scc.d.ts.map +1 -1
- package/lib/core/graph/Scc.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/save/GraphPrinter.d.ts +4 -3
- package/lib/save/GraphPrinter.d.ts.map +1 -1
- package/lib/utils/SparseBitVector.d.ts +1 -1
- package/lib/utils/SparseBitVector.d.ts.map +1 -1
- package/lib/utils/SparseBitVector.js +11 -10
- package/package.json +2 -1
package/lib/Scene.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare class Scene {
|
|
|
46
46
|
private buildStage;
|
|
47
47
|
private options;
|
|
48
48
|
private indexPathArray;
|
|
49
|
+
private unhandledFilePaths;
|
|
50
|
+
private unhandledSdkFilePaths;
|
|
49
51
|
constructor();
|
|
50
52
|
getOptions(): SceneOptions;
|
|
51
53
|
getOverRides(): Map<string, string>;
|
|
@@ -105,8 +107,9 @@ export declare class Scene {
|
|
|
105
107
|
private addFileNode2DependencyGrap;
|
|
106
108
|
private buildSdk;
|
|
107
109
|
/**
|
|
108
|
-
* Build the scene for harmony project. It resolves the file path of the project first, and then fetches
|
|
109
|
-
* Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally,
|
|
110
|
+
* Build the scene for harmony project. It resolves the file path of the project first, and then fetches
|
|
111
|
+
* dependencies from this file. Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally,
|
|
112
|
+
* it build bodies of all methods, generate extended classes, and add DefaultConstructors.
|
|
110
113
|
*/
|
|
111
114
|
buildScene4HarmonyProject(): void;
|
|
112
115
|
private buildOhPkgContentMap;
|
|
@@ -149,10 +152,13 @@ export declare class Scene {
|
|
|
149
152
|
```
|
|
150
153
|
*/
|
|
151
154
|
getFile(fileSignature: FileSignature): ArkFile | null;
|
|
155
|
+
getUnhandledFilePaths(): string[];
|
|
156
|
+
getUnhandledSdkFilePaths(): string[];
|
|
152
157
|
setFile(file: ArkFile): void;
|
|
153
158
|
hasSdkFile(fileSignature: FileSignature): boolean;
|
|
154
159
|
/**
|
|
155
|
-
* Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different
|
|
160
|
+
* Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different
|
|
161
|
+
* class. We need to generate {@link ArkFile} objects from these ets/ts files.
|
|
156
162
|
* @returns The array of {@link ArkFile} from `scene.filesMap.values()`.
|
|
157
163
|
* @example
|
|
158
164
|
* 1. In inferSimpleTypes() to check arkClass and arkMethod.
|
|
@@ -242,10 +248,10 @@ export declare class Scene {
|
|
|
242
248
|
makeCallGraphRTA(entryPoints: MethodSignature[]): CallGraph;
|
|
243
249
|
/**
|
|
244
250
|
* Infer type for each non-default method. It infers the type of each field/local/reference.
|
|
245
|
-
* For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s =
|
|
251
|
+
* For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s =
|
|
252
|
+
* 'hello';`, the type of local `s` is `StringType`. The detailed types are defined in the Type.ts file.
|
|
246
253
|
* @example
|
|
247
254
|
* 1. Infer the type of each class field and method field.
|
|
248
|
-
|
|
249
255
|
```typescript
|
|
250
256
|
const scene = new Scene();
|
|
251
257
|
scene.buildSceneFromProjectDir(sceneConfig);
|
package/lib/Scene.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scene.d.ts","sourceRoot":"","sources":["../src/Scene.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,EAAY,MAAM,UAAU,CAAC;AAGpE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/G,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK1C,OAAO,EAAE,SAAS,EAA0B,MAAM,wBAAwB,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAUxD,aAAK,eAAe;IAChB,UAAU,IAAA;IACV,UAAU,IAAA;IACV,WAAW,IAAA;IACX,eAAe,IAAA;I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,EAAE,MAAM,EAAE,EAAE,WAAW,GAAE,OAAe,GAAG,IAAI;IAczH,2BAA2B,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAUhF;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAO9B;;;OAGG;IACI,aAAa,IAAI,MAAM;IAIvB,aAAa,IAAI,MAAM;IAIvB,gBAAgB;IAIhB,eAAe;;;IAIf,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIzC,OAAO,CAAC,WAAW;CAiBtB"}
|
package/lib/Scene.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -105,6 +105,8 @@ class Scene {
|
|
|
105
105
|
this.overRideDependencyMap = new Map();
|
|
106
106
|
this.buildStage = SceneBuildStage.BUILD_INIT;
|
|
107
107
|
this.indexPathArray = ['Index.ets', 'Index.ts', 'Index.d.ets', 'Index.d.ts', 'index.ets', 'index.ts', 'index.d.ets', 'index.d.ts'];
|
|
108
|
+
this.unhandledFilePaths = [];
|
|
109
|
+
this.unhandledSdkFilePaths = [];
|
|
108
110
|
}
|
|
109
111
|
getOptions() {
|
|
110
112
|
return this.options;
|
|
@@ -307,10 +309,17 @@ class Scene {
|
|
|
307
309
|
genArkFiles() {
|
|
308
310
|
this.projectFiles.forEach((file) => {
|
|
309
311
|
logger.info('=== parse file:', file);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
try {
|
|
313
|
+
const arkFile = new ArkFile_1.ArkFile();
|
|
314
|
+
arkFile.setScene(this);
|
|
315
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.realProjectDir, arkFile, this.projectName);
|
|
316
|
+
this.filesMap.set(arkFile.getFileSignature().toMapKey(), arkFile);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
logger.error('Error parsing file:', file, error);
|
|
320
|
+
this.unhandledFilePaths.push(file);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
314
323
|
});
|
|
315
324
|
this.buildAllMethodBody();
|
|
316
325
|
this.addDefaultConstructors();
|
|
@@ -327,8 +336,11 @@ class Scene {
|
|
|
327
336
|
return;
|
|
328
337
|
}
|
|
329
338
|
const fileSignature = new ArkSignature_1.FileSignature(this.getProjectName(), path_1.default.relative(this.getRealProjectDir(), projectFile));
|
|
330
|
-
if (
|
|
331
|
-
|
|
339
|
+
if (this.filesMap.has(fileSignature.toMapKey()) || this.isRepeatBuildFile(projectFile)) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const arkFile = new ArkFile_1.ArkFile();
|
|
332
344
|
arkFile.setScene(this);
|
|
333
345
|
(0, ArkFileBuilder_1.buildArkFileFromFile)(projectFile, this.getRealProjectDir(), arkFile, this.getProjectName());
|
|
334
346
|
for (const [modulePath, moduleName] of this.modulePath2NameMap) {
|
|
@@ -339,11 +351,16 @@ class Scene {
|
|
|
339
351
|
}
|
|
340
352
|
this.filesMap.set(arkFile.getFileSignature().toMapKey(), arkFile);
|
|
341
353
|
const importInfos = arkFile.getImportInfos();
|
|
342
|
-
|
|
354
|
+
const repeatFroms = [];
|
|
343
355
|
this.findDependencyFiles(importInfos, arkFile, repeatFroms);
|
|
344
356
|
const exportInfos = arkFile.getExportInfos();
|
|
345
357
|
this.findDependencyFiles(exportInfos, arkFile, repeatFroms);
|
|
346
358
|
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
logger.error('Error parsing file:', projectFile, error);
|
|
361
|
+
this.unhandledFilePaths.push(projectFile);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
347
364
|
}
|
|
348
365
|
isRepeatBuildFile(projectFile) {
|
|
349
366
|
for (const [key, file] of this.filesMap) {
|
|
@@ -521,22 +538,30 @@ class Scene {
|
|
|
521
538
|
const allFiles = (0, getAllFiles_1.getAllFiles)(sdkPath, this.options.supportFileExts, this.options.ignoreFileNames);
|
|
522
539
|
allFiles.forEach((file) => {
|
|
523
540
|
logger.info('=== parse sdk file:', file);
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
541
|
+
try {
|
|
542
|
+
const arkFile = new ArkFile_1.ArkFile();
|
|
543
|
+
arkFile.setScene(this);
|
|
544
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, path_1.default.normalize(sdkPath), arkFile, sdkName);
|
|
545
|
+
ModelUtils_1.ModelUtils.getAllClassesInFile(arkFile).forEach(cls => {
|
|
546
|
+
var _a, _b;
|
|
547
|
+
(_a = cls.getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.buildBody();
|
|
548
|
+
(_b = cls.getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.freeBodyBuilder();
|
|
549
|
+
});
|
|
550
|
+
const fileSig = arkFile.getFileSignature().toMapKey();
|
|
551
|
+
this.sdkArkFilesMap.set(fileSig, arkFile);
|
|
552
|
+
SdkUtils_1.SdkUtils.buildGlobalMap(arkFile, this.sdkGlobalMap);
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
logger.error('Error parsing file:', file, error);
|
|
556
|
+
this.unhandledSdkFilePaths.push(file);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
535
559
|
});
|
|
536
560
|
}
|
|
537
561
|
/**
|
|
538
|
-
* Build the scene for harmony project. It resolves the file path of the project first, and then fetches
|
|
539
|
-
* Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally,
|
|
562
|
+
* Build the scene for harmony project. It resolves the file path of the project first, and then fetches
|
|
563
|
+
* dependencies from this file. Next, build a `ModuleScene` for this project to generate {@link ArkFile}. Finally,
|
|
564
|
+
* it build bodies of all methods, generate extended classes, and add DefaultConstructors.
|
|
540
565
|
*/
|
|
541
566
|
buildScene4HarmonyProject() {
|
|
542
567
|
this.buildOhPkgContentMap();
|
|
@@ -655,6 +680,18 @@ class Scene {
|
|
|
655
680
|
return this.sdkArkFilesMap.get(fileSignature.toMapKey()) || null;
|
|
656
681
|
}
|
|
657
682
|
}
|
|
683
|
+
/*
|
|
684
|
+
* Returns the absolute file paths that cannot be handled currently.
|
|
685
|
+
*/
|
|
686
|
+
getUnhandledFilePaths() {
|
|
687
|
+
return this.unhandledFilePaths;
|
|
688
|
+
}
|
|
689
|
+
/*
|
|
690
|
+
* Returns the absolute sdk file paths that cannot be handled currently.
|
|
691
|
+
*/
|
|
692
|
+
getUnhandledSdkFilePaths() {
|
|
693
|
+
return this.unhandledSdkFilePaths;
|
|
694
|
+
}
|
|
658
695
|
setFile(file) {
|
|
659
696
|
this.filesMap.set(file.getFileSignature().toMapKey(), file);
|
|
660
697
|
}
|
|
@@ -662,7 +699,8 @@ class Scene {
|
|
|
662
699
|
return this.sdkArkFilesMap.has(fileSignature.toMapKey());
|
|
663
700
|
}
|
|
664
701
|
/**
|
|
665
|
-
* Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different
|
|
702
|
+
* Get files of a {@link Scene}. Generally, a project includes several ets/ts files that define the different
|
|
703
|
+
* class. We need to generate {@link ArkFile} objects from these ets/ts files.
|
|
666
704
|
* @returns The array of {@link ArkFile} from `scene.filesMap.values()`.
|
|
667
705
|
* @example
|
|
668
706
|
* 1. In inferSimpleTypes() to check arkClass and arkMethod.
|
|
@@ -896,10 +934,10 @@ class Scene {
|
|
|
896
934
|
}
|
|
897
935
|
/**
|
|
898
936
|
* Infer type for each non-default method. It infers the type of each field/local/reference.
|
|
899
|
-
* For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s =
|
|
937
|
+
* For example, the statement `let b = 5;`, the type of local `b` is `NumberType`; and for the statement `let s =
|
|
938
|
+
* 'hello';`, the type of local `s` is `StringType`. The detailed types are defined in the Type.ts file.
|
|
900
939
|
* @example
|
|
901
940
|
* 1. Infer the type of each class field and method field.
|
|
902
|
-
|
|
903
941
|
```typescript
|
|
904
942
|
const scene = new Scene();
|
|
905
943
|
scene.buildSceneFromProjectDir(sceneConfig);
|
|
@@ -1260,11 +1298,18 @@ class ModuleScene {
|
|
|
1260
1298
|
genArkFiles(supportFileExts) {
|
|
1261
1299
|
(0, getAllFiles_1.getAllFiles)(this.modulePath, supportFileExts, this.projectScene.getOptions().ignoreFileNames).forEach((file) => {
|
|
1262
1300
|
logger.info('=== parse file:', file);
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1301
|
+
try {
|
|
1302
|
+
const arkFile = new ArkFile_1.ArkFile();
|
|
1303
|
+
arkFile.setScene(this.projectScene);
|
|
1304
|
+
arkFile.setModuleScene(this);
|
|
1305
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.projectScene.getRealProjectDir(), arkFile, this.projectScene.getProjectName());
|
|
1306
|
+
this.projectScene.setFile(arkFile);
|
|
1307
|
+
}
|
|
1308
|
+
catch (error) {
|
|
1309
|
+
logger.error('Error parsing file:', file, error);
|
|
1310
|
+
this.projectScene.getUnhandledFilePaths().push(file);
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1268
1313
|
});
|
|
1269
1314
|
}
|
|
1270
1315
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PagBuilder.d.ts","sourceRoot":"","sources":["../../../src/callgraph/pointerAnalysis/PagBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAiB,QAAQ,EAA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,cAAc;IAmBtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkB9B,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,cAAc;IAWf,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI;IAO7D,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,IAAI;IAQzE,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK;IAiBrD,MAAM,IAAI,IAAI;IAId,SAAS,IAAI,IAAI;IAIjB,OAAO,IAAI,MAAM;IAIjB,iBAAiB,IAAI,MAAM,EAAE;IAQ7B,eAAe,IAAI,MAAM,EAAE;IAIlC;;;;;OAKG;IACH,OAAO,CAAC,4BAA4B;IAyBpC,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,+BAA+B;IAWvC,OAAO,CAAC,2BAA2B;IA6BnC,OAAO,CAAC,oBAAoB;IAuB5B,OAAO,CAAC,oBAAoB;IAQrB,oBAAoB,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,EAAE;IAKzC,wBAAwB,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO;CAoBvF"}
|
|
@@ -153,7 +153,9 @@ class PagBuilder {
|
|
|
153
153
|
let fpag = new Pag_1.FuncPag();
|
|
154
154
|
for (let stmt of cfg.getStmts()) {
|
|
155
155
|
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
156
|
-
|
|
156
|
+
stmt.getRightOp().getUses().forEach((v) => {
|
|
157
|
+
this.handleValueFromExternalScope(v, funcID);
|
|
158
|
+
});
|
|
157
159
|
// Add non-call edges
|
|
158
160
|
let kind = this.getEdgeKindForAssignStmt(stmt);
|
|
159
161
|
if (kind !== Pag_1.PagEdgeKind.Unknown) {
|
|
@@ -32,6 +32,10 @@ export declare class DummyMainCreater {
|
|
|
32
32
|
constructor(scene: Scene);
|
|
33
33
|
setEntryMethods(methods: ArkMethod[]): void;
|
|
34
34
|
createDummyMain(): void;
|
|
35
|
+
private addStaticInit;
|
|
36
|
+
private addClassInit;
|
|
37
|
+
private addParamInit;
|
|
38
|
+
private addBranches;
|
|
35
39
|
private createDummyMainCfg;
|
|
36
40
|
private addCfg2Stmt;
|
|
37
41
|
getDummyMain(): ArkMethod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAuBpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAQ/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA2C;IAChE,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAa;gBAEvB,KAAK,EAAE,KAAK;IAUjB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI;IAI3C,eAAe,IAAI,IAAI;IAqD9B,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,YAAY;IAyBpB,OAAO,CAAC,WAAW;IAqCnB,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,WAAW;IAYZ,YAAY,IAAI,SAAS;IAIhC,OAAO,CAAC,6BAA6B;IAmBrC,OAAO,CAAC,oBAAoB;IAerB,0BAA0B,IAAI,SAAS,EAAE;IAUzC,kBAAkB,IAAI,SAAS,EAAE;CAiB3C"}
|
|
@@ -93,7 +93,7 @@ class DummyMainCreater {
|
|
|
93
93
|
dummyMainClass.addMethod(this.dummyMain);
|
|
94
94
|
let defaultMethods = [];
|
|
95
95
|
for (const method of this.entryMethods) {
|
|
96
|
-
if (method.getDeclaringArkClass().isDefaultArkClass()) {
|
|
96
|
+
if (method.getDeclaringArkClass().isDefaultArkClass() || method.isStatic()) {
|
|
97
97
|
defaultMethods.push(method);
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
@@ -106,7 +106,7 @@ class DummyMainCreater {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
if (!newLocal) {
|
|
109
|
-
newLocal = new Local_1.Local('
|
|
109
|
+
newLocal = new Local_1.Local('%' + this.tempLocalIndex, new Type_1.ClassType(declaringArkClass.getSignature()));
|
|
110
110
|
this.tempLocalIndex++;
|
|
111
111
|
}
|
|
112
112
|
this.classLocalMap.set(method, newLocal);
|
|
@@ -121,11 +121,7 @@ class DummyMainCreater {
|
|
|
121
121
|
this.addCfg2Stmt();
|
|
122
122
|
this.scene.addToMethodsMap(this.dummyMain);
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
var _a;
|
|
126
|
-
const dummyCfg = new Cfg_1.Cfg();
|
|
127
|
-
dummyCfg.setDeclaringMethod(this.dummyMain);
|
|
128
|
-
const firstBlock = new BasicBlock_1.BasicBlock();
|
|
124
|
+
addStaticInit(dummyCfg, firstBlock) {
|
|
129
125
|
let isStartingStmt = true;
|
|
130
126
|
for (const method of this.scene.getStaticInitMethods()) {
|
|
131
127
|
const staticInvokeExpr = new Expr_1.ArkStaticInvokeExpr(method.getSignature(), []);
|
|
@@ -136,6 +132,8 @@ class DummyMainCreater {
|
|
|
136
132
|
}
|
|
137
133
|
firstBlock.addStmt(invokeStmt);
|
|
138
134
|
}
|
|
135
|
+
}
|
|
136
|
+
addClassInit(firstBlock) {
|
|
139
137
|
const locals = Array.from(new Set(this.classLocalMap.values()));
|
|
140
138
|
for (const local of locals) {
|
|
141
139
|
if (!local) {
|
|
@@ -145,6 +143,7 @@ class DummyMainCreater {
|
|
|
145
143
|
let cls = this.scene.getClass(clsType.getClassSignature());
|
|
146
144
|
const assStmt = new Stmt_1.ArkAssignStmt(local, new Expr_1.ArkNewExpr(clsType));
|
|
147
145
|
firstBlock.addStmt(assStmt);
|
|
146
|
+
local.setDeclaringStmt(assStmt);
|
|
148
147
|
let consMtd = cls.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
149
148
|
if (consMtd) {
|
|
150
149
|
let ivkExpr = new Expr_1.ArkInstanceInvokeExpr(local, consMtd.getSignature(), []);
|
|
@@ -152,20 +151,33 @@ class DummyMainCreater {
|
|
|
152
151
|
firstBlock.addStmt(ivkStmt);
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
}
|
|
155
|
+
addParamInit(method, paramLocals, invokeBlock) {
|
|
156
|
+
var _a;
|
|
157
|
+
let paramIdx = 0;
|
|
158
|
+
for (const param of method.getParameters()) {
|
|
159
|
+
let paramType = param.getType();
|
|
160
|
+
// In ArkIR from abc scenario, param type is undefined in some cases
|
|
161
|
+
// Then try to get it from super class(SDK)
|
|
162
|
+
// TODO - need handle method overload to get the correct method
|
|
163
|
+
if (!paramType) {
|
|
164
|
+
let superCls = method.getDeclaringArkClass().getSuperClass();
|
|
165
|
+
let methodInSuperCls = superCls === null || superCls === void 0 ? void 0 : superCls.getMethodWithName(method.getName());
|
|
166
|
+
if (methodInSuperCls) {
|
|
167
|
+
paramType = (_a = methodInSuperCls.getParameters().at(paramIdx)) === null || _a === void 0 ? void 0 : _a.getType();
|
|
168
|
+
method = methodInSuperCls;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const paramLocal = new Local_1.Local('%' + this.tempLocalIndex++, paramType);
|
|
172
|
+
paramLocals.push(paramLocal);
|
|
173
|
+
if (paramType instanceof Type_1.ClassType) {
|
|
174
|
+
const assStmt = new Stmt_1.ArkAssignStmt(paramLocal, new Expr_1.ArkNewExpr(paramType));
|
|
175
|
+
invokeBlock.addStmt(assStmt);
|
|
176
|
+
}
|
|
177
|
+
paramIdx++;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
addBranches(whileBlock, countLocal, dummyCfg) {
|
|
169
181
|
let lastBlocks = [whileBlock];
|
|
170
182
|
let count = 0;
|
|
171
183
|
for (let method of this.entryMethods) {
|
|
@@ -181,30 +193,15 @@ class DummyMainCreater {
|
|
|
181
193
|
}
|
|
182
194
|
const invokeBlock = new BasicBlock_1.BasicBlock();
|
|
183
195
|
const paramLocals = [];
|
|
184
|
-
|
|
185
|
-
for (const param of method.getParameters()) {
|
|
186
|
-
let paramType = param.getType();
|
|
187
|
-
// In ArkIR from abc scenario, param type is undefined in some cases
|
|
188
|
-
// Then try to get it from super class(SDK)
|
|
189
|
-
// TODO - need handle method overload to get the correct method
|
|
190
|
-
if (!paramType) {
|
|
191
|
-
let superCls = method.getDeclaringArkClass().getSuperClass();
|
|
192
|
-
let methodInSuperCls = superCls === null || superCls === void 0 ? void 0 : superCls.getMethodWithName(method.getName());
|
|
193
|
-
if (methodInSuperCls) {
|
|
194
|
-
paramType = (_a = methodInSuperCls.getParameters().at(paramIdx)) === null || _a === void 0 ? void 0 : _a.getType();
|
|
195
|
-
method = methodInSuperCls;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const paramLocal = new Local_1.Local('temp' + this.tempLocalIndex++, paramType);
|
|
199
|
-
paramLocals.push(paramLocal);
|
|
200
|
-
if (paramType instanceof Type_1.ClassType) {
|
|
201
|
-
const assStmt = new Stmt_1.ArkAssignStmt(paramLocal, new Expr_1.ArkNewExpr(paramType));
|
|
202
|
-
invokeBlock.addStmt(assStmt);
|
|
203
|
-
}
|
|
204
|
-
paramIdx++;
|
|
205
|
-
}
|
|
196
|
+
this.addParamInit(method, paramLocals, invokeBlock);
|
|
206
197
|
const local = this.classLocalMap.get(method);
|
|
207
|
-
let invokeExpr
|
|
198
|
+
let invokeExpr;
|
|
199
|
+
if (local) {
|
|
200
|
+
invokeExpr = new Expr_1.ArkInstanceInvokeExpr(local, method.getSignature(), paramLocals);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
invokeExpr = new Expr_1.ArkStaticInvokeExpr(method.getSignature(), paramLocals);
|
|
204
|
+
}
|
|
208
205
|
const invokeStmt = new Stmt_1.ArkInvokeStmt(invokeExpr);
|
|
209
206
|
invokeBlock.addStmt(invokeStmt);
|
|
210
207
|
dummyCfg.addBlock(invokeBlock);
|
|
@@ -216,6 +213,28 @@ class DummyMainCreater {
|
|
|
216
213
|
block.addSuccessorBlock(whileBlock);
|
|
217
214
|
whileBlock.addPredecessorBlock(block);
|
|
218
215
|
}
|
|
216
|
+
}
|
|
217
|
+
createDummyMainCfg() {
|
|
218
|
+
const dummyCfg = new Cfg_1.Cfg();
|
|
219
|
+
dummyCfg.setDeclaringMethod(this.dummyMain);
|
|
220
|
+
const firstBlock = new BasicBlock_1.BasicBlock();
|
|
221
|
+
this.addStaticInit(dummyCfg, firstBlock);
|
|
222
|
+
this.addClassInit(firstBlock);
|
|
223
|
+
const countLocal = new Local_1.Local('count', Type_1.NumberType.getInstance());
|
|
224
|
+
const zero = ValueUtil_1.ValueUtil.getOrCreateNumberConst(0);
|
|
225
|
+
const countAssignStmt = new Stmt_1.ArkAssignStmt(countLocal, zero);
|
|
226
|
+
const truE = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
227
|
+
const conditionTrue = new Expr_1.ArkConditionExpr(truE, zero, Expr_1.RelationalBinaryOperator.Equality);
|
|
228
|
+
const whileStmt = new Stmt_1.ArkIfStmt(conditionTrue);
|
|
229
|
+
firstBlock.addStmt(countAssignStmt);
|
|
230
|
+
dummyCfg.addBlock(firstBlock);
|
|
231
|
+
dummyCfg.setStartingStmt(firstBlock.getStmts()[0]);
|
|
232
|
+
const whileBlock = new BasicBlock_1.BasicBlock();
|
|
233
|
+
whileBlock.addStmt(whileStmt);
|
|
234
|
+
dummyCfg.addBlock(whileBlock);
|
|
235
|
+
firstBlock.addSuccessorBlock(whileBlock);
|
|
236
|
+
whileBlock.addPredecessorBlock(firstBlock);
|
|
237
|
+
this.addBranches(whileBlock, countLocal, dummyCfg);
|
|
219
238
|
const returnStmt = new Stmt_1.ArkReturnVoidStmt();
|
|
220
239
|
const returnBlock = new BasicBlock_1.BasicBlock();
|
|
221
240
|
returnBlock.addStmt(returnStmt);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Data Flow Analysis Framework
|
|
3
|
+
*
|
|
4
|
+
* This module provides a generic framework for implementing data flow analyses,
|
|
5
|
+
* such as Reaching Definitions, Live Variables, and Available Expressions.
|
|
6
|
+
* The framework is designed to be flexible and extensible, allowing users to
|
|
7
|
+
* define custom flow graphs, transfer functions, and meet operations.
|
|
8
|
+
*
|
|
9
|
+
* Design Notes:
|
|
10
|
+
* - The framework is designed to be generic and reusable, allowing users to
|
|
11
|
+
* implement custom data flow analyses by defining appropriate transfer functions
|
|
12
|
+
* and meet operations.
|
|
13
|
+
* - The solver uses a worklist algorithm to efficiently compute the MFP solution.
|
|
14
|
+
* - The analysis can be configured as either forward or backward, depending on
|
|
15
|
+
* the problem requirements.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Represents a flow graph for data flow analysis.
|
|
20
|
+
* Provides access to nodes in post-order and reverse post-order, as well as
|
|
21
|
+
* methods to retrieve successors and predecessors of a given node.
|
|
22
|
+
*
|
|
23
|
+
* @template T - The type of nodes in the graph (e.g., node IDs or node objects).
|
|
24
|
+
*/
|
|
25
|
+
export interface FlowGraph<T> {
|
|
26
|
+
nodesInReversePostOrder?: T[];
|
|
27
|
+
nodesInPostOrder: T[];
|
|
28
|
+
pred(t: T): T[];
|
|
29
|
+
succ(t: T): T[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* DS (Data Set) is an interface that defines the basic operations for a data set.
|
|
33
|
+
* It requires the data set to be iterable, comparable, and countable.
|
|
34
|
+
*/
|
|
35
|
+
interface DS {
|
|
36
|
+
/**
|
|
37
|
+
* Returns an iterator that allows iterating over the elements of the data set.
|
|
38
|
+
* @returns An iterable iterator over the elements of the data set.
|
|
39
|
+
*/
|
|
40
|
+
[Symbol.iterator](): IterableIterator<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether the current data set is equal to another data set.
|
|
43
|
+
*/
|
|
44
|
+
equals(d: DS): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Counts the number of elements in the data set.
|
|
47
|
+
*/
|
|
48
|
+
count(): number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents the transfer function used in data flow analysis.
|
|
52
|
+
* The transfer function computes the output value (out set) of a node
|
|
53
|
+
* based on its input value (in set) and the node's properties.
|
|
54
|
+
*
|
|
55
|
+
* @template Node - The type of nodes in the graph.
|
|
56
|
+
* @template V - The type of data flow values (e.g., sets, bit vectors).
|
|
57
|
+
*/
|
|
58
|
+
export interface TransferFunction<Node, V> {
|
|
59
|
+
/**
|
|
60
|
+
* Computes the output value for a node based on its input value.
|
|
61
|
+
*
|
|
62
|
+
* @param n - The node for which the output value is computed.
|
|
63
|
+
* @param x - The input value (in set) for the node.
|
|
64
|
+
* @returns The output value (out set) for the node.
|
|
65
|
+
*/
|
|
66
|
+
apply(n: Node, x: V): V;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents a data flow problem, encapsulating all the necessary components
|
|
70
|
+
* for performing data flow analysis, such as the flow graph, transfer function,
|
|
71
|
+
* meet operation, and initialization configuration.
|
|
72
|
+
*
|
|
73
|
+
* @template Node - The type of nodes in the graph.
|
|
74
|
+
* @template V - The type of data flow values.
|
|
75
|
+
*/
|
|
76
|
+
export interface DataFlowProblem<Node, V> {
|
|
77
|
+
/**
|
|
78
|
+
* The flow graph for the data flow analysis.
|
|
79
|
+
*/
|
|
80
|
+
flowGraph: FlowGraph<Node>;
|
|
81
|
+
/**
|
|
82
|
+
* The transfer function used to compute out sets from in sets.
|
|
83
|
+
*/
|
|
84
|
+
transferFunction: TransferFunction<Node, V>;
|
|
85
|
+
/**
|
|
86
|
+
* The meet operation used to combine values from multiple paths (e.g., union or intersection).
|
|
87
|
+
*/
|
|
88
|
+
meet: (a: V, b: V) => V;
|
|
89
|
+
/**
|
|
90
|
+
* The initialization configuration for in and out sets.
|
|
91
|
+
*/
|
|
92
|
+
initIn: Map<Node, V>;
|
|
93
|
+
initOut: Map<Node, V>;
|
|
94
|
+
/**
|
|
95
|
+
* Indicates whether the analysis is forward (true) or backward (false).
|
|
96
|
+
*/
|
|
97
|
+
forward: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The empty value used to initialize in and out sets (e.g., an empty set).
|
|
100
|
+
*/
|
|
101
|
+
empty: V;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Represents the result of a data flow analysis.
|
|
105
|
+
* Contains the in and out sets for each node, as well as the corresponding data flow problem.
|
|
106
|
+
*
|
|
107
|
+
* @template Node - The type of nodes in the graph.
|
|
108
|
+
* @template V - The type of data flow values.
|
|
109
|
+
*/
|
|
110
|
+
export declare class Solution<Node, V> {
|
|
111
|
+
in: Map<Node, V>;
|
|
112
|
+
out: Map<Node, V>;
|
|
113
|
+
problem: DataFlowProblem<Node, V>;
|
|
114
|
+
constructor(i: Map<Node, V>, out: Map<Node, V>, problem: DataFlowProblem<Node, V>);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A solver for data flow analysis problems.
|
|
118
|
+
* Implements forward and backward data flow analysis using a worklist algorithm.
|
|
119
|
+
* The solver computes the Maximum Fixed Point (MFP) solution, which is a safe
|
|
120
|
+
* over-approximation of the ideal Meet-Over-All-Paths (MOP) solution.
|
|
121
|
+
*/
|
|
122
|
+
export declare class MFPDataFlowSolver {
|
|
123
|
+
/**
|
|
124
|
+
* Computes the MFP solution for a forward data flow analysis problem.
|
|
125
|
+
*
|
|
126
|
+
* @template Node - The type of nodes in the graph.
|
|
127
|
+
* @template V - The type of data flow values.
|
|
128
|
+
* @param problem - The data flow problem to solve.
|
|
129
|
+
* @returns The solution containing the in and out sets for all nodes.
|
|
130
|
+
*/
|
|
131
|
+
calculateMopSolutionForwards<Node, V extends DS>(problem: DataFlowProblem<Node, V>): Solution<Node, V>;
|
|
132
|
+
/**
|
|
133
|
+
* Computes the MFP solution for a backward data flow analysis problem.
|
|
134
|
+
*
|
|
135
|
+
* @template Node - The type of nodes in the graph.
|
|
136
|
+
* @template V - The type of data flow values.
|
|
137
|
+
* @param problem - The data flow problem to solve.
|
|
138
|
+
* @returns The solution containing the in and out sets for all nodes.
|
|
139
|
+
*/
|
|
140
|
+
calculateMopSolutionBackwards<Node, T extends DS>(problem: DataFlowProblem<Node, T>): Solution<Node, T>;
|
|
141
|
+
}
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=GenericDataFlow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericDataFlow.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/GenericDataFlow.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAExB,uBAAuB,CAAC,EAAE,CAAC,EAAE,CAAC;IAE9B,gBAAgB,EAAE,CAAC,EAAE,CAAC;IAEtB,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;IAEhB,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;C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