arkanalyzer 1.0.69 → 1.0.71
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/callgraph/pointerAnalysis/plugins/PluginManager.d.ts +5 -0
- package/lib/callgraph/pointerAnalysis/plugins/PluginManager.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/plugins/PluginManager.js +15 -0
- package/lib/callgraph/pointerAnalysis/plugins/TaskPoolPlugin.d.ts +35 -0
- package/lib/callgraph/pointerAnalysis/plugins/TaskPoolPlugin.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/plugins/TaskPoolPlugin.js +199 -0
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts +27 -0
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +171 -0
- package/lib/core/common/Const.d.ts +4 -0
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +5 -1
- package/lib/core/model/ArkMetadata.d.ts +7 -1
- package/lib/core/model/ArkMetadata.d.ts.map +1 -1
- package/lib/core/model/ArkMetadata.js +11 -1
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +50 -17
- package/package.json +2 -2
|
@@ -6,6 +6,8 @@ import { IPagPlugin } from './IPagPlugin';
|
|
|
6
6
|
import { NodeID } from '../../../core/graph/GraphTraits';
|
|
7
7
|
import { ArkMethod } from '../../../core/model/ArkMethod';
|
|
8
8
|
import { Value } from '../../../core/base/Value';
|
|
9
|
+
import { Local } from '../../../core/base/Local';
|
|
10
|
+
import { Stmt } from '../../../core/base/Stmt';
|
|
9
11
|
export declare class PluginManager {
|
|
10
12
|
private plugins;
|
|
11
13
|
constructor(pag: Pag, pagBuilder: PagBuilder, cg: CallGraph);
|
|
@@ -21,5 +23,8 @@ export declare class PluginManager {
|
|
|
21
23
|
handled: boolean;
|
|
22
24
|
};
|
|
23
25
|
getSDKParamValue(method: ArkMethod): Value[] | undefined;
|
|
26
|
+
getTaskObj2CGNodeMap(): Map<Local, CallGraphNode>;
|
|
27
|
+
getTaskObj2ConstructorStmtMap(): Map<Local, Stmt>;
|
|
28
|
+
getWorkerObj2CGNodeMap(): Map<Local, CallGraphNode>;
|
|
24
29
|
}
|
|
25
30
|
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../../../src/callgraph/pointerAnalysis/plugins/PluginManager.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAKzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGjD,qBAAa,aAAa;IACtB,OAAO,CAAC,OAAO,CAAoB;gBAEvB,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS;IAI3D,OAAO,CAAC,IAAI;
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../../../src/callgraph/pointerAnalysis/plugins/PluginManager.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO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AE,aAAa,CAAC;CAG7D"}
|
|
@@ -19,6 +19,8 @@ const ContainerPlugin_1 = require("./ContainerPlugin");
|
|
|
19
19
|
const FunctionPlugin_1 = require("./FunctionPlugin");
|
|
20
20
|
const SdkPlugin_1 = require("./SdkPlugin");
|
|
21
21
|
const StoragePlugin_1 = require("./StoragePlugin");
|
|
22
|
+
const TaskPoolPlugin_1 = require("./TaskPoolPlugin");
|
|
23
|
+
const WorkerPlugin_1 = require("./WorkerPlugin");
|
|
22
24
|
// plugins/PluginManager.ts
|
|
23
25
|
class PluginManager {
|
|
24
26
|
constructor(pag, pagBuilder, cg) {
|
|
@@ -28,6 +30,8 @@ class PluginManager {
|
|
|
28
30
|
init(pag, pagBuilder, cg) {
|
|
29
31
|
this.registerPlugin(new StoragePlugin_1.StoragePlugin(pag, pagBuilder, cg));
|
|
30
32
|
this.registerPlugin(new FunctionPlugin_1.FunctionPlugin(pag, pagBuilder, cg));
|
|
33
|
+
this.registerPlugin(new TaskPoolPlugin_1.TaskPoolPlugin(pag, pagBuilder, cg));
|
|
34
|
+
this.registerPlugin(new WorkerPlugin_1.WorkerPlugin(pag, pagBuilder, cg));
|
|
31
35
|
this.registerPlugin(new SdkPlugin_1.SdkPlugin(pag, pagBuilder, cg));
|
|
32
36
|
this.registerPlugin(new ContainerPlugin_1.ContainerPlugin(pag, pagBuilder, cg));
|
|
33
37
|
}
|
|
@@ -62,5 +66,16 @@ class PluginManager {
|
|
|
62
66
|
getSDKParamValue(method) {
|
|
63
67
|
return this.plugins.find(p => p.getName() === 'SdkPlugin').getParamValues(method);
|
|
64
68
|
}
|
|
69
|
+
// taskpool plugin interfaces
|
|
70
|
+
getTaskObj2CGNodeMap() {
|
|
71
|
+
return this.plugins.find(p => p.getName() === 'TaskPoolPlugin').getTaskObj2CGNodeMap();
|
|
72
|
+
}
|
|
73
|
+
getTaskObj2ConstructorStmtMap() {
|
|
74
|
+
return this.plugins.find(p => p.getName() === 'TaskPoolPlugin').getTaskObj2ConstructorStmtMap();
|
|
75
|
+
}
|
|
76
|
+
// worker plugin interfaces
|
|
77
|
+
getWorkerObj2CGNodeMap() {
|
|
78
|
+
return this.plugins.find(p => p.getName() === 'WorkerPlugin').getWorkerObj2CGNodeMap();
|
|
79
|
+
}
|
|
65
80
|
}
|
|
66
81
|
exports.PluginManager = PluginManager;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Local } from '../../../core/base/Local';
|
|
2
|
+
import { Stmt } from '../../../core/base/Stmt';
|
|
3
|
+
import { NodeID } from '../../../core/graph/GraphTraits';
|
|
4
|
+
import { ArkMethod } from '../../../core/model/ArkMethod';
|
|
5
|
+
import { CallGraph, CallGraphNode, FuncID, ICallSite } from '../../model/CallGraph';
|
|
6
|
+
import { ContextID } from '../context/Context';
|
|
7
|
+
import { Pag } from '../Pag';
|
|
8
|
+
import { PagBuilder } from '../PagBuilder';
|
|
9
|
+
import { IPagPlugin } from './IPagPlugin';
|
|
10
|
+
export declare class TaskPoolPlugin implements IPagPlugin {
|
|
11
|
+
pag: Pag;
|
|
12
|
+
pagBuilder: PagBuilder;
|
|
13
|
+
cg: CallGraph;
|
|
14
|
+
private sdkMethodReturnValueMap;
|
|
15
|
+
private methodParamValueMap;
|
|
16
|
+
private fakeSdkMethodParamDeclaringStmt;
|
|
17
|
+
private taskObj2CGNodeMap;
|
|
18
|
+
private taskObj2ConstructorStmtMap;
|
|
19
|
+
constructor(pag: Pag, pagBuilder: PagBuilder, cg: CallGraph);
|
|
20
|
+
getName(): string;
|
|
21
|
+
canHandle(cs: ICallSite, cgNode: CallGraphNode): boolean;
|
|
22
|
+
processCallSite(cs: ICallSite, cid: ContextID, basePTNode: NodeID): NodeID[];
|
|
23
|
+
private addTaskPoolMethodPagCallEdge;
|
|
24
|
+
/**
|
|
25
|
+
* will not create real funcPag, only create param values
|
|
26
|
+
*/
|
|
27
|
+
buildSDKFuncPag(funcID: FuncID, sdkMethod: ArkMethod): void;
|
|
28
|
+
private createDummyParamValue;
|
|
29
|
+
private addSDKMethodReturnPagEdge;
|
|
30
|
+
private addTaskPoolMethodParamPagEdge;
|
|
31
|
+
addTaskObj2CGNodeMap(cs: ICallSite, index: number): void;
|
|
32
|
+
getTaskObj2CGNodeMap(): Map<Local, CallGraphNode>;
|
|
33
|
+
getTaskObj2ConstructorStmtMap(): Map<Local, Stmt>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=TaskPoolPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskPoolPlugin.d.ts","sourceRoot":"","sources":["../../../../src/callgraph/pointerAnalysis/plugins/TaskPoolPlugin.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAgC,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAI7E,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAA6B,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW1C,qBAAa,cAAe,YAAW,UAAU;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,UAAU,EAAE,UAAU,CAAC;IACvB,EAAE,EAAE,SAAS,CAAC;IACd,OAAO,CAAC,uBAAuB,CAA6C;IAE5E,OAAO,CAAC,mBAAmB,CAAuB;IAElD,OAAO,CAAC,+BAA+B,CAAO;IAE9C,OAAO,CAAC,iBAAiB,CAA4B;IAErD,OAAO,CAAC,0BAA0B,CAAmB;gBAEzC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS;IAW3D,OAAO,IAAI,MAAM;IAIjB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO;IAMxD,eAAe,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAiC5E,OAAO,CAAC,4BAA4B;IAoBpC;;OAEG;IACI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAMlE,OAAO,CAAC,qBAAqB;IAiB7B,OAAO,CAAC,yBAAyB;IA6BjC,OAAO,CAAC,6BAA6B;IAoC9B,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAcxD,oBAAoB,IAAI,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC;IAIjD,6BAA6B,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC;CAG3D"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 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.TaskPoolPlugin = void 0;
|
|
18
|
+
const Constant_1 = require("../../../core/base/Constant");
|
|
19
|
+
const Expr_1 = require("../../../core/base/Expr");
|
|
20
|
+
const Local_1 = require("../../../core/base/Local");
|
|
21
|
+
const Stmt_1 = require("../../../core/base/Stmt");
|
|
22
|
+
const Type_1 = require("../../../core/base/Type");
|
|
23
|
+
const Const_1 = require("../../../core/common/Const");
|
|
24
|
+
const Pag_1 = require("../Pag");
|
|
25
|
+
const taskpoolMethodNames = new Set([
|
|
26
|
+
'execute',
|
|
27
|
+
'executeDelayed',
|
|
28
|
+
'executePeriodically',
|
|
29
|
+
'addTask',
|
|
30
|
+
'constructor'
|
|
31
|
+
]);
|
|
32
|
+
class TaskPoolPlugin {
|
|
33
|
+
constructor(pag, pagBuilder, cg) {
|
|
34
|
+
this.pag = pag;
|
|
35
|
+
this.pagBuilder = pagBuilder;
|
|
36
|
+
this.cg = cg;
|
|
37
|
+
this.sdkMethodReturnValueMap = new Map();
|
|
38
|
+
this.methodParamValueMap = new Map();
|
|
39
|
+
this.fakeSdkMethodParamDeclaringStmt = new Stmt_1.ArkAssignStmt(new Local_1.Local(''), new Local_1.Local(''));
|
|
40
|
+
this.taskObj2ConstructorStmtMap = new Map();
|
|
41
|
+
this.taskObj2CGNodeMap = new Map();
|
|
42
|
+
}
|
|
43
|
+
getName() {
|
|
44
|
+
return 'TaskPoolPlugin';
|
|
45
|
+
}
|
|
46
|
+
canHandle(cs, cgNode) {
|
|
47
|
+
var _a;
|
|
48
|
+
// if namespace is 'taskpool', then can handle
|
|
49
|
+
let namespacename = (_a = cgNode.getMethod().getDeclaringClassSignature().getDeclaringNamespaceSignature()) === null || _a === void 0 ? void 0 : _a.getNamespaceName();
|
|
50
|
+
return namespacename === 'taskpool';
|
|
51
|
+
}
|
|
52
|
+
processCallSite(cs, cid, basePTNode) {
|
|
53
|
+
let srcNodes = [];
|
|
54
|
+
let calleeFuncID = cs.getCalleeFuncID();
|
|
55
|
+
if (!calleeFuncID) {
|
|
56
|
+
return srcNodes;
|
|
57
|
+
}
|
|
58
|
+
const calleeMethod = this.cg.getArkMethodByFuncID(calleeFuncID);
|
|
59
|
+
if (!calleeMethod) {
|
|
60
|
+
return srcNodes;
|
|
61
|
+
}
|
|
62
|
+
let methodname = calleeMethod.getSubSignature().getMethodName();
|
|
63
|
+
const calleeCid = this.pagBuilder.getContextSelector().selectContext(cid, cs, basePTNode, calleeFuncID);
|
|
64
|
+
if (methodname === Const_1.CONSTRUCTORFUCNNAME && cs.args !== undefined) {
|
|
65
|
+
// match the constructor function so that update the taskObj2CGNodeMap
|
|
66
|
+
for (let i = 0; i < cs.args.length; i++) {
|
|
67
|
+
if (cs.args[i] instanceof Local_1.Local && cs.args[i].getType() instanceof Type_1.FunctionType) {
|
|
68
|
+
this.addTaskObj2CGNodeMap(cs, i);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (taskpoolMethodNames.has(methodname) && cs.args !== undefined) {
|
|
74
|
+
// transfer the param function pag to the task thread function pag
|
|
75
|
+
for (let i = 0; i < cs.args.length; i++) {
|
|
76
|
+
if (cs.args[i] instanceof Local_1.Local && cs.args[i].getType() instanceof Type_1.FunctionType) {
|
|
77
|
+
this.addTaskPoolMethodPagCallEdge(cs, cid, calleeCid, srcNodes, i);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return srcNodes;
|
|
83
|
+
}
|
|
84
|
+
addTaskPoolMethodPagCallEdge(cs, callerCid, calleeCid, srcNodes, index) {
|
|
85
|
+
let calleeFuncID = cs.getCalleeFuncID();
|
|
86
|
+
if (!calleeFuncID) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let calleeNode = this.cg.getNode(calleeFuncID);
|
|
90
|
+
let calleeMethod = this.cg.getArkMethodByFuncID(calleeFuncID);
|
|
91
|
+
if (!calleeMethod) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!this.methodParamValueMap.has(calleeNode.getID())) {
|
|
95
|
+
this.buildSDKFuncPag(calleeNode.getID(), calleeMethod);
|
|
96
|
+
}
|
|
97
|
+
this.addSDKMethodReturnPagEdge(cs, callerCid, calleeCid, calleeMethod, srcNodes);
|
|
98
|
+
this.addTaskPoolMethodParamPagEdge(cs, callerCid, calleeCid, calleeNode.getID(), srcNodes, index);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* will not create real funcPag, only create param values
|
|
103
|
+
*/
|
|
104
|
+
buildSDKFuncPag(funcID, sdkMethod) {
|
|
105
|
+
let paramArr = this.createDummyParamValue(sdkMethod);
|
|
106
|
+
this.methodParamValueMap.set(funcID, paramArr);
|
|
107
|
+
}
|
|
108
|
+
createDummyParamValue(sdkMethod) {
|
|
109
|
+
let args = sdkMethod.getParameters();
|
|
110
|
+
let paramArr = [];
|
|
111
|
+
if (!args) {
|
|
112
|
+
return paramArr;
|
|
113
|
+
}
|
|
114
|
+
// Local
|
|
115
|
+
args.forEach((arg) => {
|
|
116
|
+
let argInstance = new Local_1.Local(arg.getName(), arg.getType());
|
|
117
|
+
argInstance.setDeclaringStmt(this.fakeSdkMethodParamDeclaringStmt);
|
|
118
|
+
paramArr.push(argInstance);
|
|
119
|
+
});
|
|
120
|
+
return paramArr;
|
|
121
|
+
}
|
|
122
|
+
addSDKMethodReturnPagEdge(cs, callerCid, calleeCid, calleeMethod, srcNodes) {
|
|
123
|
+
let returnType = calleeMethod.getReturnType();
|
|
124
|
+
if (!(returnType instanceof Type_1.ClassType) || !(cs.callStmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// check fake heap object exists or not
|
|
128
|
+
let cidMap = this.sdkMethodReturnValueMap.get(calleeMethod);
|
|
129
|
+
if (!cidMap) {
|
|
130
|
+
cidMap = new Map();
|
|
131
|
+
}
|
|
132
|
+
let newExpr = cidMap.get(calleeCid);
|
|
133
|
+
if (!newExpr && returnType instanceof Type_1.ClassType) {
|
|
134
|
+
newExpr = new Expr_1.ArkNewExpr(returnType);
|
|
135
|
+
}
|
|
136
|
+
if (newExpr === undefined) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
cidMap.set(calleeCid, newExpr);
|
|
140
|
+
this.sdkMethodReturnValueMap.set(calleeMethod, cidMap);
|
|
141
|
+
let srcPagNode = this.pagBuilder.getOrNewPagNode(calleeCid, newExpr);
|
|
142
|
+
let dstPagNode = this.pagBuilder.getOrNewPagNode(callerCid, cs.callStmt.getLeftOp(), cs.callStmt);
|
|
143
|
+
this.pag.addPagEdge(srcPagNode, dstPagNode, Pag_1.PagEdgeKind.Address, cs.callStmt);
|
|
144
|
+
srcNodes.push(srcPagNode.getID());
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
addTaskPoolMethodParamPagEdge(cs, callerCid, calleeCid, funcID, srcNodes, index) {
|
|
148
|
+
var _a;
|
|
149
|
+
let paramValue = (_a = this.methodParamValueMap.get(funcID)) === null || _a === void 0 ? void 0 : _a[0];
|
|
150
|
+
if (paramValue === undefined || cs.args === undefined) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let srcPagNode = this.pagBuilder.getOrNewPagNode(callerCid, cs.args[index], cs.callStmt);
|
|
154
|
+
let dstPagNode = this.pagBuilder.getOrNewPagNode(calleeCid, paramValue, cs.callStmt);
|
|
155
|
+
let args = cs.args.slice(index + 1);
|
|
156
|
+
if (dstPagNode instanceof Pag_1.PagLocalNode) {
|
|
157
|
+
dstPagNode.setSdkParam();
|
|
158
|
+
// add related dyn callsite
|
|
159
|
+
let arkPtrInvokeExpr = new Expr_1.ArkPtrInvokeExpr(cs.args[index].getType().getMethodSignature(), paramValue, args);
|
|
160
|
+
let sdkParamInvokeStmt = new Stmt_1.ArkInvokeStmt(arkPtrInvokeExpr);
|
|
161
|
+
let calleeNode = this.cg.getCallGraphNodeByMethod(cs.args[index].getType().getMethodSignature());
|
|
162
|
+
let sdkParamCallSite = this.cg.getCallSiteManager().newDynCallSite(sdkParamInvokeStmt, args, calleeNode.getID(), funcID);
|
|
163
|
+
dstPagNode.addRelatedDynCallSite(sdkParamCallSite);
|
|
164
|
+
}
|
|
165
|
+
this.pag.addPagEdge(srcPagNode, dstPagNode, Pag_1.PagEdgeKind.Copy, cs.callStmt);
|
|
166
|
+
srcNodes.push(srcPagNode.getID());
|
|
167
|
+
// passed the cid of args
|
|
168
|
+
for (let arg of args) {
|
|
169
|
+
if (arg instanceof Constant_1.Constant || arg instanceof Expr_1.AbstractExpr) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
srcPagNode = this.pagBuilder.getOrNewPagNode(callerCid, arg, cs.callStmt);
|
|
173
|
+
dstPagNode = this.pagBuilder.getOrNewPagNode(calleeCid, arg, cs.callStmt);
|
|
174
|
+
this.pag.addPagEdge(srcPagNode, dstPagNode, Pag_1.PagEdgeKind.Copy, cs.callStmt);
|
|
175
|
+
srcNodes.push(srcPagNode.getID());
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
addTaskObj2CGNodeMap(cs, index) {
|
|
180
|
+
// Obtain the function that the task thread is going to execute through the param function.
|
|
181
|
+
let invokeExpr = cs.callStmt.getInvokeExpr();
|
|
182
|
+
if (cs.args === undefined) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let arg_type = cs.args[index].getType();
|
|
186
|
+
if (arg_type instanceof Type_1.FunctionType) {
|
|
187
|
+
let cgnode = this.cg.getCallGraphNodeByMethod(arg_type.getMethodSignature());
|
|
188
|
+
this.taskObj2CGNodeMap.set(invokeExpr.getBase(), cgnode);
|
|
189
|
+
this.taskObj2ConstructorStmtMap.set(invokeExpr.getBase(), cs.callStmt);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
getTaskObj2CGNodeMap() {
|
|
193
|
+
return this.taskObj2CGNodeMap;
|
|
194
|
+
}
|
|
195
|
+
getTaskObj2ConstructorStmtMap() {
|
|
196
|
+
return this.taskObj2ConstructorStmtMap;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.TaskPoolPlugin = TaskPoolPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ArkFile } from '../../..';
|
|
2
|
+
import { StringConstant } from '../../../core/base/Constant';
|
|
3
|
+
import { Local } from '../../../core/base/Local';
|
|
4
|
+
import { Stmt } from '../../../core/base/Stmt';
|
|
5
|
+
import { NodeID } from '../../../core/graph/GraphTraits';
|
|
6
|
+
import { CallGraph, CallGraphNode, ICallSite } from '../../model/CallGraph';
|
|
7
|
+
import { ContextID } from '../context/Context';
|
|
8
|
+
import { Pag } from '../Pag';
|
|
9
|
+
import { PagBuilder } from '../PagBuilder';
|
|
10
|
+
import { IPagPlugin } from './IPagPlugin';
|
|
11
|
+
export declare class WorkerPlugin implements IPagPlugin {
|
|
12
|
+
pag: Pag;
|
|
13
|
+
pagBuilder: PagBuilder;
|
|
14
|
+
cg: CallGraph;
|
|
15
|
+
private workerObj2CGNodeMap;
|
|
16
|
+
constructor(pag: Pag, pagBuilder: PagBuilder, cg: CallGraph);
|
|
17
|
+
getName(): string;
|
|
18
|
+
canHandle(cs: ICallSite, cgNode: CallGraphNode): boolean;
|
|
19
|
+
processCallSite(cs: ICallSite, cid: ContextID, basePTNode: NodeID): NodeID[];
|
|
20
|
+
private addWorkerPagCallEdge;
|
|
21
|
+
private addPostMessagePagCallEdge;
|
|
22
|
+
private ProcessPostMessagePagCallEdge;
|
|
23
|
+
addWorkerObj2CGNodeMap(cs: ICallSite): void;
|
|
24
|
+
getWorkerObj2CGNodeMap(): Map<Local, CallGraphNode>;
|
|
25
|
+
getFileByPath(callstmt: Stmt, filePath: StringConstant): ArkFile | null;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=WorkerPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerPlugin.d.ts","sourceRoot":"","sources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,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,GAAG,IAAI;CAWjF"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 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.WorkerPlugin = void 0;
|
|
18
|
+
const __1 = require("../../..");
|
|
19
|
+
const Constant_1 = require("../../../core/base/Constant");
|
|
20
|
+
const Local_1 = require("../../../core/base/Local");
|
|
21
|
+
const Ref_1 = require("../../../core/base/Ref");
|
|
22
|
+
const Stmt_1 = require("../../../core/base/Stmt");
|
|
23
|
+
const Const_1 = require("../../../core/common/Const");
|
|
24
|
+
const ContextSelector_1 = require("../context/ContextSelector");
|
|
25
|
+
const Pag_1 = require("../Pag");
|
|
26
|
+
const PagBuilder_1 = require("../PagBuilder");
|
|
27
|
+
class WorkerPlugin {
|
|
28
|
+
constructor(pag, pagBuilder, cg) {
|
|
29
|
+
this.workerObj2CGNodeMap = new Map();
|
|
30
|
+
this.pag = pag;
|
|
31
|
+
this.pagBuilder = pagBuilder;
|
|
32
|
+
this.cg = cg;
|
|
33
|
+
}
|
|
34
|
+
getName() {
|
|
35
|
+
return 'WorkerPlugin';
|
|
36
|
+
}
|
|
37
|
+
canHandle(cs, cgNode) {
|
|
38
|
+
var _a;
|
|
39
|
+
let namespacename = (_a = cgNode.getMethod().getDeclaringClassSignature().getDeclaringNamespaceSignature()) === null || _a === void 0 ? void 0 : _a.getNamespaceName();
|
|
40
|
+
return namespacename === 'worker';
|
|
41
|
+
}
|
|
42
|
+
processCallSite(cs, cid, basePTNode) {
|
|
43
|
+
let srcNodes = [];
|
|
44
|
+
let calleeFuncID = cs.getCalleeFuncID();
|
|
45
|
+
if (!calleeFuncID) {
|
|
46
|
+
return srcNodes;
|
|
47
|
+
}
|
|
48
|
+
const calleeMethod = this.cg.getArkMethodByFuncID(calleeFuncID);
|
|
49
|
+
if (!calleeMethod) {
|
|
50
|
+
return srcNodes;
|
|
51
|
+
}
|
|
52
|
+
let methodname = calleeMethod.getSubSignature().getMethodName();
|
|
53
|
+
if (methodname === Const_1.CONSTRUCTORFUCNNAME) {
|
|
54
|
+
this.addWorkerObj2CGNodeMap(cs);
|
|
55
|
+
}
|
|
56
|
+
if (methodname === Const_1.POSTMESSAGEFUNCNAME || methodname === Const_1.POSTMESSAGEWITHSHAREDSENDABLEFUNCNAME) {
|
|
57
|
+
this.addWorkerPagCallEdge(cs, cid, srcNodes);
|
|
58
|
+
}
|
|
59
|
+
return srcNodes;
|
|
60
|
+
}
|
|
61
|
+
addWorkerPagCallEdge(cs, callerCid, srcNodes) {
|
|
62
|
+
let myworker = cs.callStmt.getInvokeExpr().getBase();
|
|
63
|
+
let nodes = this.pag.getNodesByValue(myworker);
|
|
64
|
+
let pointto = new Set();
|
|
65
|
+
if (nodes === undefined) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (let node of nodes) {
|
|
69
|
+
if (node[0] !== callerCid) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
let ptcollection = this.pag.getNode(node[1]).getPointTo();
|
|
73
|
+
for (let id of ptcollection) {
|
|
74
|
+
pointto.add(this.pag.getNode(id));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (let obj of pointto) {
|
|
78
|
+
let cgnode = this.workerObj2CGNodeMap.get(obj.getStmt().getLeftOp());
|
|
79
|
+
if (cgnode === undefined) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
this.addPostMessagePagCallEdge(cs, callerCid, cgnode.getID(), srcNodes);
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
addPostMessagePagCallEdge(cs, callerCid, calleeFuncID, srcNodes) {
|
|
87
|
+
var _a;
|
|
88
|
+
let cgnode = this.cg.getNode(calleeFuncID);
|
|
89
|
+
let calleeMethod = this.cg.getArkMethodByFuncID(cgnode.getID());
|
|
90
|
+
if (calleeMethod === null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let calleeCid = this.pagBuilder.getContextSelector().selectContext(callerCid, cs, ContextSelector_1.emptyID, cgnode.getID());
|
|
94
|
+
this.pagBuilder.buildFuncPagAndAddToWorklist(new PagBuilder_1.CSFuncID(calleeCid, cgnode.getID()));
|
|
95
|
+
let params = calleeMethod.getCfg().getStmts()
|
|
96
|
+
.filter(stmt => stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Ref_1.ArkParameterRef)
|
|
97
|
+
.map(stmt => stmt.getRightOp());
|
|
98
|
+
(_a = calleeMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().forEach((local) => {
|
|
99
|
+
if (local.getDeclaringStmt() instanceof Stmt_1.ArkAssignStmt && local.getDeclaringStmt().getRightOp() === params[0]) {
|
|
100
|
+
// find the local corresponding to the first parameter
|
|
101
|
+
this.ProcessPostMessagePagCallEdge(cs, callerCid, calleeCid, local, srcNodes);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
ProcessPostMessagePagCallEdge(cs, callerCid, calleeCid, local, srcNodes) {
|
|
107
|
+
let usedstmts = local.getUsedStmts().filter(usedstmt => usedstmt instanceof Stmt_1.ArkAssignStmt && usedstmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef);
|
|
108
|
+
for (let usedstmt of usedstmts) {
|
|
109
|
+
let fieldref = usedstmt.getRightOp();
|
|
110
|
+
// find the fieldref whose fieldname is 'data', then add pag edge between the argument and the leftop of the assignstmt
|
|
111
|
+
// of the fieldref
|
|
112
|
+
if (fieldref.getBase() === local && fieldref.getFieldName() === 'data' && cs.args !== undefined && cs.args[0] instanceof Local_1.Local) {
|
|
113
|
+
let srcPagNode = this.pagBuilder.getOrNewPagNode(callerCid, cs.args[0], cs.callStmt);
|
|
114
|
+
let dstPagNode = this.pagBuilder.getOrNewPagNode(calleeCid, usedstmt.getLeftOp(), cs.callStmt);
|
|
115
|
+
this.pag.addPagEdge(srcPagNode, dstPagNode, Pag_1.PagEdgeKind.Copy, cs.callStmt);
|
|
116
|
+
srcNodes.push(srcPagNode.getID());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
addWorkerObj2CGNodeMap(cs) {
|
|
122
|
+
// Obtain the function that the worker sub-thread is going to execute through the file path.
|
|
123
|
+
let callstmt = cs.callStmt;
|
|
124
|
+
callstmt.getCfg().getDeclaringMethod().getDeclaringArkClass().getDeclaringArkFile().getScene();
|
|
125
|
+
let invokeExpr = cs.callStmt.getInvokeExpr();
|
|
126
|
+
if (cs.args === undefined) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (cs.args[0] instanceof Constant_1.StringConstant) {
|
|
130
|
+
let workerfile = this.getFileByPath(callstmt, cs.args[0]);
|
|
131
|
+
if (workerfile === null) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let defaultArkMethod = workerfile.getDefaultClass().getDefaultArkMethod();
|
|
135
|
+
if (defaultArkMethod === null) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let cfg = defaultArkMethod.getCfg();
|
|
139
|
+
if (cfg === undefined) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
let stmts = cfg.getStmts();
|
|
143
|
+
for (let stmt of stmts) {
|
|
144
|
+
// Find the assignment statement where the onmessage function is assigned to the worker object.
|
|
145
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (stmt.getLeftOp() instanceof Ref_1.ArkInstanceFieldRef && stmt.getLeftOp().getFieldName() === Const_1.ONMESSAGEFUNCNAME) {
|
|
149
|
+
let cgnode = this.cg.getCallGraphNodeByMethod(stmt.getRightOp().getType().getMethodSignature());
|
|
150
|
+
this.workerObj2CGNodeMap.set(invokeExpr.getBase(), cgnode);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
getWorkerObj2CGNodeMap() {
|
|
157
|
+
return this.workerObj2CGNodeMap;
|
|
158
|
+
}
|
|
159
|
+
getFileByPath(callstmt, filePath) {
|
|
160
|
+
let declaringarkfile = callstmt.getCfg().getDeclaringMethod().getDeclaringArkClass().getDeclaringArkFile();
|
|
161
|
+
const scene = declaringarkfile.getScene();
|
|
162
|
+
let filepath = filePath.toString().replace('../', '').replace('./', '').replace("'", '').replace("'", '');
|
|
163
|
+
filepath = filepath.substring(filepath.indexOf('ets'));
|
|
164
|
+
if (/\.e?ts$/.test(filepath)) {
|
|
165
|
+
const fileSignature = new __1.FileSignature(declaringarkfile.getFileSignature().getProjectName(), filepath);
|
|
166
|
+
return scene.getFile(fileSignature);
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.WorkerPlugin = WorkerPlugin;
|
|
@@ -21,4 +21,8 @@ export declare const TEMP_LOCAL_PREFIX = "%";
|
|
|
21
21
|
export declare const LEXICAL_ENV_NAME_PREFIX: string;
|
|
22
22
|
export declare const ARKTS_STATIC_MARK = "use static";
|
|
23
23
|
export declare const MAKEOBSERVED = "makeObserved";
|
|
24
|
+
export declare const CONSTRUCTORFUCNNAME = "constructor";
|
|
25
|
+
export declare const POSTMESSAGEFUNCNAME = "postMessage";
|
|
26
|
+
export declare const POSTMESSAGEWITHSHAREDSENDABLEFUNCNAME = "postMessageWithSharedSendable";
|
|
27
|
+
export declare const ONMESSAGEFUNCNAME = "onmessage";
|
|
24
28
|
//# sourceMappingURL=Const.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Const.d.ts","sourceRoot":"","sources":["../../../src/core/common/Const.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,SAAS,CAAC;AAGnC,eAAO,MAAM,sBAAsB,QAA6B,CAAC;AACjE,eAAO,MAAM,sBAAsB,QAAqB,CAAC;AACzD,eAAO,MAAM,yBAAyB,MAAiB,CAAC;AAGxD,eAAO,MAAM,uBAAuB,QAA6B,CAAC;AAClE,eAAO,MAAM,yBAAyB,QAA2B,CAAC;AAClE,eAAO,MAAM,uBAAuB,QAA2B,CAAC;AAChE,eAAO,MAAM,+BAA+B,QAA4B,CAAC;AACzE,eAAO,MAAM,uBAAuB,QAAqB,CAAC;AAC1D,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAG5C,eAAO,MAAM,oBAAoB,QAA6B,CAAC;AAC/D,eAAO,MAAM,iBAAiB,QAA6B,CAAC;AAC5D,eAAO,MAAM,sBAAsB,QAA6B,CAAC;AACjE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAGtC,eAAO,MAAM,iBAAiB,MAAc,CAAC;AAC7C,eAAO,MAAM,uBAAuB,QAAiC,CAAC;AAGtE,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAG9C,e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@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MAKEOBSERVED = exports.ARKTS_STATIC_MARK = exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX = exports.UNKNOWN_METHOD_NAME = exports.UNKNOWN_FIELD_NAME = exports.UNKNOWN_CLASS_NAME = exports.UNKNOWN_NAMESPACE_NAME = exports.UNKNOWN_FILE_NAME = exports.UNKNOWN_PROJECT_NAME = exports.CALL_SIGNATURE_NAME = exports.ANONYMOUS_METHOD_PREFIX = exports.STATIC_BLOCK_METHOD_NAME_PREFIX = exports.STATIC_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.DEFAULT_ARK_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_CLASS_NAME = exports.DEFAULT_NAME = exports.UNKNOWN_NAME = exports.NAME_PREFIX = exports.NAME_DELIMITER = void 0;
|
|
17
|
+
exports.ONMESSAGEFUNCNAME = exports.POSTMESSAGEWITHSHAREDSENDABLEFUNCNAME = exports.POSTMESSAGEFUNCNAME = exports.CONSTRUCTORFUCNNAME = exports.MAKEOBSERVED = exports.ARKTS_STATIC_MARK = exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX = exports.UNKNOWN_METHOD_NAME = exports.UNKNOWN_FIELD_NAME = exports.UNKNOWN_CLASS_NAME = exports.UNKNOWN_NAMESPACE_NAME = exports.UNKNOWN_FILE_NAME = exports.UNKNOWN_PROJECT_NAME = exports.CALL_SIGNATURE_NAME = exports.ANONYMOUS_METHOD_PREFIX = exports.STATIC_BLOCK_METHOD_NAME_PREFIX = exports.STATIC_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.DEFAULT_ARK_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_CLASS_NAME = exports.DEFAULT_NAME = exports.UNKNOWN_NAME = exports.NAME_PREFIX = exports.NAME_DELIMITER = void 0;
|
|
18
18
|
// names
|
|
19
19
|
exports.NAME_DELIMITER = '$';
|
|
20
20
|
exports.NAME_PREFIX = '%';
|
|
@@ -45,3 +45,7 @@ exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX + 'closures';
|
|
|
45
45
|
exports.ARKTS_STATIC_MARK = 'use static';
|
|
46
46
|
// Concurrent const
|
|
47
47
|
exports.MAKEOBSERVED = 'makeObserved';
|
|
48
|
+
exports.CONSTRUCTORFUCNNAME = 'constructor';
|
|
49
|
+
exports.POSTMESSAGEFUNCNAME = 'postMessage';
|
|
50
|
+
exports.POSTMESSAGEWITHSHAREDSENDABLEFUNCNAME = 'postMessageWithSharedSendable';
|
|
51
|
+
exports.ONMESSAGEFUNCNAME = 'onmessage';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FullPosition } from '../base/Position';
|
|
2
2
|
export declare enum ArkMetadataKind {
|
|
3
3
|
LEADING_COMMENTS = 0,
|
|
4
|
-
TRAILING_COMMENTS = 1
|
|
4
|
+
TRAILING_COMMENTS = 1,
|
|
5
|
+
ENUM_INIT_TYPE_USER = 2
|
|
5
6
|
}
|
|
6
7
|
export interface ArkMetadataType {
|
|
7
8
|
}
|
|
@@ -29,4 +30,9 @@ export declare class CommentsMetadata implements ArkMetadataType {
|
|
|
29
30
|
constructor(comments: CommentItem[]);
|
|
30
31
|
getComments(): CommentItem[];
|
|
31
32
|
}
|
|
33
|
+
export declare class EnumInitTypeUserMetadata implements ArkMetadataType {
|
|
34
|
+
private originTypeUser;
|
|
35
|
+
constructor(originTypeUser: boolean);
|
|
36
|
+
isUserDefined(): boolean;
|
|
37
|
+
}
|
|
32
38
|
//# sourceMappingURL=ArkMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkMetadata.d.ts","sourceRoot":"","sources":["../../../src/core/model/ArkMetadata.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,oBAAY,eAAe;IACvB,gBAAgB,IAAA;IAChB,iBAAiB,IAAA;
|
|
1
|
+
{"version":3,"file":"ArkMetadata.d.ts","sourceRoot":"","sources":["../../../src/core/model/ArkMetadata.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,oBAAY,eAAe;IACvB,gBAAgB,IAAA;IAChB,iBAAiB,IAAA;IACjB,mBAAmB,IAAA;CACtB;AAED,MAAM,WAAW,eAAe;CAAI;AAEpC;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACpB,SAAS,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;IAEpD,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;IAI/D,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI;CAM1E;AAED,MAAM,MAAM,WAAW,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,YAAY,CAAC;CAC1B,CAAC;AAEF,qBAAa,gBAAiB,YAAW,eAAe;IACpD,OAAO,CAAC,QAAQ,CAAqB;gBAEzB,QAAQ,EAAE,WAAW,EAAE;IAI5B,WAAW,IAAI,WAAW,EAAE;CAGtC;AAED,qBAAa,wBAAyB,YAAW,eAAe;IAC5D,OAAO,CAAC,cAAc,CAAU;gBAEpB,cAAc,EAAE,OAAO;IAI5B,aAAa,IAAI,OAAO;CAGlC"}
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CommentsMetadata = exports.ArkMetadata = exports.ArkMetadataKind = void 0;
|
|
17
|
+
exports.EnumInitTypeUserMetadata = exports.CommentsMetadata = exports.ArkMetadata = exports.ArkMetadataKind = void 0;
|
|
18
18
|
var ArkMetadataKind;
|
|
19
19
|
(function (ArkMetadataKind) {
|
|
20
20
|
ArkMetadataKind[ArkMetadataKind["LEADING_COMMENTS"] = 0] = "LEADING_COMMENTS";
|
|
21
21
|
ArkMetadataKind[ArkMetadataKind["TRAILING_COMMENTS"] = 1] = "TRAILING_COMMENTS";
|
|
22
|
+
ArkMetadataKind[ArkMetadataKind["ENUM_INIT_TYPE_USER"] = 2] = "ENUM_INIT_TYPE_USER";
|
|
22
23
|
})(ArkMetadataKind = exports.ArkMetadataKind || (exports.ArkMetadataKind = {}));
|
|
23
24
|
/**
|
|
24
25
|
* ArkMetadata
|
|
@@ -53,3 +54,12 @@ class CommentsMetadata {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
exports.CommentsMetadata = CommentsMetadata;
|
|
57
|
+
class EnumInitTypeUserMetadata {
|
|
58
|
+
constructor(originTypeUser) {
|
|
59
|
+
this.originTypeUser = originTypeUser;
|
|
60
|
+
}
|
|
61
|
+
isUserDefined() {
|
|
62
|
+
return this.originTypeUser;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.EnumInitTypeUserMetadata = EnumInitTypeUserMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkClassBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkClassBuilder.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAmE,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkClassBuilder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G,EAAE,QAAQ,EACb,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,eAAe,CAAC,EAAE,SAAS,GAC5B,IAAI,CAUN;AAmBD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,EAAE,SAAS,GAAG,IAAI,CA0BvI"}
|
|
@@ -61,6 +61,10 @@ const Type_1 = require("../../base/Type");
|
|
|
61
61
|
const BodyBuilder_1 = require("./BodyBuilder");
|
|
62
62
|
const Expr_1 = require("../../base/Expr");
|
|
63
63
|
const ArkBaseModel_1 = require("../ArkBaseModel");
|
|
64
|
+
const Constant_1 = require("../../base/Constant");
|
|
65
|
+
const ValueUtil_1 = require("../../common/ValueUtil");
|
|
66
|
+
const Local_1 = require("../../base/Local");
|
|
67
|
+
const ArkMetadata_1 = require("../ArkMetadata");
|
|
64
68
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkClassBuilder');
|
|
65
69
|
function buildDefaultArkClassFromArkFile(arkFile, defaultClass, astRoot) {
|
|
66
70
|
defaultClass.setDeclaringArkFile(arkFile);
|
|
@@ -317,6 +321,7 @@ function buildArkClassMembers(clsNode, cls, sourceFile) {
|
|
|
317
321
|
const staticInitStmts = [];
|
|
318
322
|
const instanceInitStmts = [];
|
|
319
323
|
let staticBlockId = 0;
|
|
324
|
+
const enumFieldInfo = { lastFieldName: '', curValue: 0, isCurValueValid: true };
|
|
320
325
|
clsNode.members.forEach(member => {
|
|
321
326
|
if (isClassMethod(member)) {
|
|
322
327
|
// these node types have been handled at the beginning of this function by calling buildMethodsForClass
|
|
@@ -341,7 +346,7 @@ function buildArkClassMembers(clsNode, cls, sourceFile) {
|
|
|
341
346
|
}
|
|
342
347
|
if (ohos_typescript_1.default.isEnumMember(member)) {
|
|
343
348
|
const arkField = (0, ArkFieldBuilder_1.buildProperty2ArkField)(member, sourceFile, cls);
|
|
344
|
-
getInitStmts(staticIRTransformer, arkField, member.initializer);
|
|
349
|
+
getInitStmts(staticIRTransformer, arkField, member.initializer, enumFieldInfo);
|
|
345
350
|
arkField.getInitializer().forEach(stmt => staticInitStmts.push(stmt));
|
|
346
351
|
}
|
|
347
352
|
else if (ohos_typescript_1.default.isIndexSignatureDeclaration(member)) {
|
|
@@ -466,29 +471,57 @@ function buildStaticBlocksForClass(clsNode, cls, sourceFile) {
|
|
|
466
471
|
});
|
|
467
472
|
return staticBlockMethodSignatures;
|
|
468
473
|
}
|
|
469
|
-
function getInitStmts(transformer, field, initNode) {
|
|
474
|
+
function getInitStmts(transformer, field, initNode, enumFieldInfo) {
|
|
475
|
+
let initValue;
|
|
476
|
+
let initPositions;
|
|
477
|
+
const stmts = [];
|
|
470
478
|
if (initNode) {
|
|
471
|
-
|
|
472
|
-
|
|
479
|
+
let initStmts = [];
|
|
480
|
+
({ value: initValue, valueOriginalPositions: initPositions, stmts: initStmts } = transformer.tsNodeToValueAndStmts(initNode));
|
|
473
481
|
initStmts.forEach(stmt => stmts.push(stmt));
|
|
474
482
|
if (IRUtils_1.IRUtils.moreThanOneAddress(initValue)) {
|
|
475
483
|
({ value: initValue, valueOriginalPositions: initPositions, stmts: initStmts } = transformer.generateAssignStmtForValue(initValue, initPositions));
|
|
476
484
|
initStmts.forEach(stmt => stmts.push(stmt));
|
|
477
485
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
stmt.setOriginalText(fieldSourceCode);
|
|
486
|
+
if (enumFieldInfo !== undefined) {
|
|
487
|
+
if (initValue instanceof Constant_1.NumberConstant) {
|
|
488
|
+
enumFieldInfo.curValue = parseFloat(initValue.getValue()) + 1;
|
|
489
|
+
enumFieldInfo.isCurValueValid = true;
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
enumFieldInfo.lastFieldName = field.getName();
|
|
493
|
+
enumFieldInfo.isCurValueValid = false;
|
|
494
|
+
}
|
|
488
495
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
496
|
+
}
|
|
497
|
+
else if (enumFieldInfo !== undefined) {
|
|
498
|
+
if (enumFieldInfo.isCurValueValid) {
|
|
499
|
+
initValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(enumFieldInfo.curValue);
|
|
500
|
+
enumFieldInfo.curValue += 1;
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
initValue = new Expr_1.ArkNormalBinopExpr(new Local_1.Local(enumFieldInfo.lastFieldName), ValueUtil_1.ValueUtil.getOrCreateNumberConst(1), Expr_1.NormalBinaryOperator.Addition);
|
|
504
|
+
enumFieldInfo.lastFieldName = field.getName();
|
|
492
505
|
}
|
|
506
|
+
initPositions = [Position_1.FullPosition.DEFAULT];
|
|
507
|
+
field.setMetadata(ArkMetadata_1.ArkMetadataKind.ENUM_INIT_TYPE_USER, new ArkMetadata_1.EnumInitTypeUserMetadata(false));
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(transformer.getThisLocal(), field.getSignature());
|
|
513
|
+
const fieldRefPositions = [Position_1.FullPosition.DEFAULT, Position_1.FullPosition.DEFAULT];
|
|
514
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(fieldRef, initValue);
|
|
515
|
+
assignStmt.setOperandOriginalPositions([...fieldRefPositions, ...initPositions]);
|
|
516
|
+
stmts.push(assignStmt);
|
|
517
|
+
const fieldSourceCode = field.getCode();
|
|
518
|
+
const fieldOriginPosition = field.getOriginPosition();
|
|
519
|
+
for (const stmt of stmts) {
|
|
520
|
+
stmt.setOriginPositionInfo(fieldOriginPosition);
|
|
521
|
+
stmt.setOriginalText(fieldSourceCode);
|
|
522
|
+
}
|
|
523
|
+
field.setInitializer(stmts);
|
|
524
|
+
if (field.getType() instanceof Type_1.UnknownType) {
|
|
525
|
+
field.getSignature().setType(initValue.getType());
|
|
493
526
|
}
|
|
494
527
|
}
|