arkanalyzer 1.0.7 → 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 +9 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +24 -11
- package/lib/Scene.d.ts +49 -42
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +124 -93
- package/lib/callgraph/algorithm/AbstractAnalysis.js +1 -1
- package/lib/callgraph/common/Statistics.js +1 -1
- 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 +16 -6
- package/lib/callgraph/model/builder/CallGraphBuilder.js +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +35 -8
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +93 -12
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +32 -5
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +378 -83
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +3 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +71 -18
- package/lib/core/base/Constant.d.ts +25 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +46 -8
- package/lib/core/base/Expr.d.ts +45 -40
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +239 -153
- package/lib/core/base/Local.d.ts +2 -2
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +2 -2
- package/lib/core/base/Ref.d.ts +38 -37
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +102 -70
- package/lib/core/base/Stmt.d.ts +4 -0
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +12 -1
- package/lib/core/base/Type.d.ts +4 -0
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +41 -17
- 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 +7 -3
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +46 -20
- package/lib/core/common/Builtin.js +1 -1
- package/lib/core/common/CfgBuilder.d.ts +12 -0
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +289 -61
- 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 +2 -1
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +28 -15
- 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/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 +32 -32
- 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 +218 -87
- 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 +8 -25
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowSolver.js +2 -4
- package/lib/core/dataflow/TiantAnalysis.js +2 -1
- package/lib/core/dataflow/Util.d.ts +1 -1
- package/lib/core/dataflow/Util.d.ts.map +1 -1
- package/lib/core/dataflow/Util.js +8 -7
- package/lib/core/graph/BasicBlock.d.ts +41 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +132 -1
- 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 +129 -6
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +3 -2
- package/lib/core/model/ArkBaseModel.d.ts +8 -0
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -1
- package/lib/core/model/ArkBaseModel.js +56 -4
- package/lib/core/model/ArkClass.d.ts +36 -30
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +79 -40
- package/lib/core/model/ArkExport.d.ts +3 -0
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +11 -1
- package/lib/core/model/ArkField.d.ts +2 -0
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +4 -1
- package/lib/core/model/ArkFile.d.ts +4 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +20 -0
- package/lib/core/model/ArkImport.d.ts +2 -0
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +3 -0
- 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 +156 -53
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +309 -54
- package/lib/core/model/ArkNamespace.d.ts +4 -0
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +13 -0
- package/lib/core/model/ArkSignature.d.ts +11 -5
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +38 -18
- package/lib/core/model/builder/ArkClassBuilder.d.ts +0 -1
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +9 -34
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +6 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +3 -0
- package/lib/core/model/builder/ArkFileBuilder.js +1 -1
- 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 +12 -5
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +2 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +87 -47
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +2 -0
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +25 -2
- package/lib/save/source/SourceClass.d.ts.map +1 -1
- package/lib/save/source/SourceClass.js +4 -0
- package/lib/save/source/SourceField.d.ts.map +1 -1
- package/lib/save/source/SourceField.js +4 -0
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +7 -0
- package/lib/save/source/SourceModule.d.ts.map +1 -1
- package/lib/save/source/SourceModule.js +14 -9
- 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.map +1 -1
- package/lib/save/source/SourceStmt.js +15 -3
- 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 +72 -41
- package/lib/save/source/SourceUtils.d.ts.map +1 -1
- package/lib/save/source/SourceUtils.js +3 -2
- package/lib/transformer/StaticSingleAssignmentFormer.js +1 -1
- package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
- package/lib/utils/CfgStructualAnalysis.js +42 -8
- 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.js +23 -23
- 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
|
@@ -39,6 +39,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.CfgBuilder = void 0;
|
|
41
41
|
const ts = __importStar(require("ohos-typescript"));
|
|
42
|
+
const Local_1 = require("../base/Local");
|
|
42
43
|
const Stmt_1 = require("../base/Stmt");
|
|
43
44
|
const BasicBlock_1 = require("../graph/BasicBlock");
|
|
44
45
|
const Cfg_1 = require("../graph/Cfg");
|
|
@@ -222,6 +223,11 @@ class CfgBuilder {
|
|
|
222
223
|
judgeLastType(s);
|
|
223
224
|
lastStatement = s;
|
|
224
225
|
}
|
|
226
|
+
else if (!this.declaringMethod.isDefaultArkMethod() && ts.isFunctionDeclaration(c)) {
|
|
227
|
+
let s = new StatementBuilder('functionDeclarationStatement', c.getText(this.sourceFile), c, scope.id);
|
|
228
|
+
judgeLastType(s);
|
|
229
|
+
lastStatement = s;
|
|
230
|
+
}
|
|
225
231
|
else if (ts.isReturnStatement(c)) {
|
|
226
232
|
let s = new StatementBuilder('returnStatement', c.getText(this.sourceFile), c, scope.id);
|
|
227
233
|
judgeLastType(s);
|
|
@@ -1027,7 +1033,31 @@ class CfgBuilder {
|
|
|
1027
1033
|
blockBuilderToCfgBlock.set(this.blocks[i], blockInCfg);
|
|
1028
1034
|
}
|
|
1029
1035
|
let currBlockId = this.blocks.length;
|
|
1030
|
-
|
|
1036
|
+
this.linkBasicBlocks(blockBuilderToCfgBlock);
|
|
1037
|
+
this.rebuildBlocksInLoop(blockBuilderToCfgBlock, blocksContainLoopCondition, cfg);
|
|
1038
|
+
this.rebuildBlocksInConditionalOperator(cfg);
|
|
1039
|
+
for (const blockBuilder of this.blocks) {
|
|
1040
|
+
if (blockBuilder.id === -1) {
|
|
1041
|
+
blockBuilder.id = currBlockId++;
|
|
1042
|
+
const block = blockBuilderToCfgBlock.get(blockBuilder);
|
|
1043
|
+
block.setId(blockBuilder.id);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
for (const block of cfg.getBlocks()) {
|
|
1047
|
+
if (block.getId() === -1) {
|
|
1048
|
+
block.setId(currBlockId++);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
for (const stmt of cfg.getStmts()) {
|
|
1052
|
+
stmt.setCfg(cfg);
|
|
1053
|
+
}
|
|
1054
|
+
return {
|
|
1055
|
+
cfg: cfg,
|
|
1056
|
+
locals: arkIRTransformer.getLocals(),
|
|
1057
|
+
aliasTypeMap: arkIRTransformer.getAliasTypeMap(),
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
linkBasicBlocks(blockBuilderToCfgBlock) {
|
|
1031
1061
|
for (const [blockBuilder, cfgBlock] of blockBuilderToCfgBlock) {
|
|
1032
1062
|
for (const successorBlockBuilder of blockBuilder.nexts) {
|
|
1033
1063
|
if (!blockBuilderToCfgBlock.get(successorBlockBuilder)) {
|
|
@@ -1044,7 +1074,204 @@ class CfgBuilder {
|
|
|
1044
1074
|
cfgBlock.addPredecessorBlock(predecessorBlock);
|
|
1045
1075
|
}
|
|
1046
1076
|
}
|
|
1047
|
-
|
|
1077
|
+
}
|
|
1078
|
+
rebuildBlocksInConditionalOperator(cfg) {
|
|
1079
|
+
var _a;
|
|
1080
|
+
for (const basicBlock of cfg.getBlocks()) {
|
|
1081
|
+
const stmts = Array.from(basicBlock.getStmts());
|
|
1082
|
+
const stmtCnt = stmts.length;
|
|
1083
|
+
let endPos = -1;
|
|
1084
|
+
for (let i = stmtCnt - 1; i >= 0; i--) {
|
|
1085
|
+
const stmt = stmts[i];
|
|
1086
|
+
if (stmt instanceof ArkIRTransformer_1.DummyStmt && ((_a = stmt.toString()) === null || _a === void 0 ? void 0 : _a.startsWith(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT))) {
|
|
1087
|
+
endPos = i;
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (endPos === -1) {
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
const { topBlock, bottomBlocks, allBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, 0, endPos);
|
|
1095
|
+
basicBlock.getStmts().splice(topBlock.getStmts().length);
|
|
1096
|
+
const succBlocksOfIfBlock = topBlock.getSuccessors();
|
|
1097
|
+
succBlocksOfIfBlock.forEach((block) => {
|
|
1098
|
+
block.setPredecessorBlock(0, basicBlock);
|
|
1099
|
+
});
|
|
1100
|
+
const conditionalOperatorBlockSet = new Set(allBlocks);
|
|
1101
|
+
this.adjustSuccessorOfConditionalOperator(basicBlock, succBlocksOfIfBlock, stmts, bottomBlocks, endPos, conditionalOperatorBlockSet);
|
|
1102
|
+
conditionalOperatorBlockSet.forEach((block) => {
|
|
1103
|
+
if (block !== topBlock) {
|
|
1104
|
+
cfg.addBlock(block);
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
traverseAndRebuildConditionalOperator(stmts, beginPos, endPos) {
|
|
1110
|
+
const { ifTruePos, ifFalsePos, conditionalOperatorEndPos } = this.findConditionalOperator(stmts, beginPos, endPos);
|
|
1111
|
+
if (ifTruePos === -1) {
|
|
1112
|
+
const block = new BasicBlock_1.BasicBlock();
|
|
1113
|
+
block.getStmts().push(...stmts.slice(beginPos, endPos + 1));
|
|
1114
|
+
return { topBlock: block, bottomBlocks: [], allBlocks: [block] };
|
|
1115
|
+
}
|
|
1116
|
+
const allBlocks = [];
|
|
1117
|
+
const topBlock = new BasicBlock_1.BasicBlock();
|
|
1118
|
+
topBlock.getStmts().push(...stmts.slice(beginPos, ifTruePos));
|
|
1119
|
+
allBlocks.push(topBlock);
|
|
1120
|
+
const { topBlock: ifTrueTopBlock, bottomBlocks: ifTrueBottomBlocks, allBlocks: ifTrueAllBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, ifTruePos + 1, ifFalsePos - 1);
|
|
1121
|
+
allBlocks.push(...ifTrueAllBlocks);
|
|
1122
|
+
const { topBlock: ifFalseTopBlock, bottomBlocks: ifFalseBottomBlocks, allBlocks: ifFalseAllBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, ifFalsePos + 1, conditionalOperatorEndPos - 1);
|
|
1123
|
+
allBlocks.push(...ifFalseAllBlocks);
|
|
1124
|
+
topBlock.addSuccessorBlock(ifTrueTopBlock);
|
|
1125
|
+
topBlock.addSuccessorBlock(ifFalseTopBlock);
|
|
1126
|
+
ifTrueTopBlock.addPredecessorBlock(topBlock);
|
|
1127
|
+
ifFalseTopBlock.addPredecessorBlock(topBlock);
|
|
1128
|
+
let bottomBlocks = [];
|
|
1129
|
+
bottomBlocks.push(...(ifTrueBottomBlocks.length > 0 ? ifTrueBottomBlocks : [ifTrueTopBlock]));
|
|
1130
|
+
bottomBlocks.push(...(ifFalseBottomBlocks.length > 0 ? ifFalseBottomBlocks : [ifFalseTopBlock]));
|
|
1131
|
+
if (conditionalOperatorEndPos !== endPos) {
|
|
1132
|
+
const bottomBlock = new BasicBlock_1.BasicBlock();
|
|
1133
|
+
bottomBlock.getStmts().push(...stmts.slice(conditionalOperatorEndPos + 1, endPos + 1));
|
|
1134
|
+
bottomBlocks.forEach(block => {
|
|
1135
|
+
block.addSuccessorBlock(bottomBlock);
|
|
1136
|
+
bottomBlock.addPredecessorBlock(block);
|
|
1137
|
+
});
|
|
1138
|
+
bottomBlocks = [bottomBlock];
|
|
1139
|
+
allBlocks.push(bottomBlock);
|
|
1140
|
+
}
|
|
1141
|
+
return { topBlock: topBlock, bottomBlocks: bottomBlocks, allBlocks: allBlocks };
|
|
1142
|
+
}
|
|
1143
|
+
findConditionalOperator(stmts, beginPos, endPos) {
|
|
1144
|
+
let ifTruePos = -1;
|
|
1145
|
+
let ifFalsePos = -1;
|
|
1146
|
+
let conditionalOperatorEndPos = -1;
|
|
1147
|
+
let currConditionalOperatorNo = '';
|
|
1148
|
+
for (let i = beginPos; i <= endPos; i++) {
|
|
1149
|
+
const stmt = stmts[i];
|
|
1150
|
+
if (stmt instanceof ArkIRTransformer_1.DummyStmt) {
|
|
1151
|
+
if (stmt.toString()
|
|
1152
|
+
.startsWith(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT) && ifTruePos === -1) {
|
|
1153
|
+
ifTruePos = i;
|
|
1154
|
+
currConditionalOperatorNo =
|
|
1155
|
+
stmt.toString().replace(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT, '');
|
|
1156
|
+
}
|
|
1157
|
+
else if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorNo) {
|
|
1158
|
+
ifFalsePos = i;
|
|
1159
|
+
}
|
|
1160
|
+
else if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT + currConditionalOperatorNo) {
|
|
1161
|
+
conditionalOperatorEndPos = i;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
return { ifTruePos: ifTruePos, ifFalsePos: ifFalsePos, conditionalOperatorEndPos: conditionalOperatorEndPos };
|
|
1166
|
+
}
|
|
1167
|
+
adjustSuccessorOfConditionalOperator(currBasicBlock, succBlocksOfIfBlock, stmts, bottomBlocks, conditionalOperatorEndPos, conditionalOperatorBlockSet) {
|
|
1168
|
+
const oldSuccBlocks = Array.from(currBasicBlock.getSuccessors());
|
|
1169
|
+
currBasicBlock.getSuccessors().splice(0, oldSuccBlocks.length, ...succBlocksOfIfBlock);
|
|
1170
|
+
oldSuccBlocks.forEach((succBlock) => {
|
|
1171
|
+
const originalPreds = succBlock.getPredecessors();
|
|
1172
|
+
for (let i = 0; i < originalPreds.length; i++) {
|
|
1173
|
+
if (originalPreds[i] === currBasicBlock) {
|
|
1174
|
+
succBlock.getPredecessors().splice(i, 1);
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
if (conditionalOperatorEndPos === stmts.length - 1) {
|
|
1180
|
+
oldSuccBlocks.forEach((oldSuccBlock) => {
|
|
1181
|
+
bottomBlocks.forEach((bottomBlock) => {
|
|
1182
|
+
bottomBlock.addSuccessorBlock(oldSuccBlock);
|
|
1183
|
+
oldSuccBlock.addSuccessorBlock(bottomBlock);
|
|
1184
|
+
});
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
else {
|
|
1188
|
+
const insertSuccBlock = new BasicBlock_1.BasicBlock();
|
|
1189
|
+
insertSuccBlock.getStmts().push(...stmts.slice(conditionalOperatorEndPos + 1, stmts.length));
|
|
1190
|
+
oldSuccBlocks.forEach((oldSuccBlock) => {
|
|
1191
|
+
insertSuccBlock.addSuccessorBlock(oldSuccBlock);
|
|
1192
|
+
oldSuccBlock.addPredecessorBlock(insertSuccBlock);
|
|
1193
|
+
});
|
|
1194
|
+
bottomBlocks.forEach((bottomBlock) => {
|
|
1195
|
+
bottomBlock.addSuccessorBlock(insertSuccBlock);
|
|
1196
|
+
insertSuccBlock.addPredecessorBlock(bottomBlock);
|
|
1197
|
+
});
|
|
1198
|
+
conditionalOperatorBlockSet.add(insertSuccBlock);
|
|
1199
|
+
this.removeUnnecessaryBlocksInConditionalOperator(insertSuccBlock, conditionalOperatorBlockSet);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
removeUnnecessaryBlocksInConditionalOperator(bottomBlock, allBlocks) {
|
|
1203
|
+
const firstStmtInBottom = bottomBlock.getStmts()[0];
|
|
1204
|
+
if (!(firstStmtInBottom instanceof Stmt_1.ArkAssignStmt)) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
const targetValue = firstStmtInBottom.getLeftOp();
|
|
1208
|
+
const tempResultValue = firstStmtInBottom.getRightOp();
|
|
1209
|
+
if (!(targetValue instanceof Local_1.Local && IRUtils_1.IRUtils.isTempLocal(tempResultValue))) {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
bottomBlock.remove(firstStmtInBottom);
|
|
1213
|
+
const oldPredecessors = bottomBlock.getPredecessors();
|
|
1214
|
+
const newPredecessors = [];
|
|
1215
|
+
for (const predecessor of oldPredecessors) {
|
|
1216
|
+
newPredecessors.push(...this.replaceTempResultcursively(predecessor, targetValue, tempResultValue, allBlocks));
|
|
1217
|
+
}
|
|
1218
|
+
bottomBlock.getPredecessors().splice(0, oldPredecessors.length, ...newPredecessors);
|
|
1219
|
+
newPredecessors.forEach((newPredecessor) => {
|
|
1220
|
+
newPredecessor.setSuccessorBlock(0, bottomBlock);
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
replaceTempResultcursively(currBottomBlock, targetLocal, tempResultLocal, allBlocks) {
|
|
1224
|
+
const stmts = currBottomBlock.getStmts();
|
|
1225
|
+
const stmtsCnt = stmts.length;
|
|
1226
|
+
let tempResultReassignStmt = null;
|
|
1227
|
+
for (let i = stmtsCnt - 1; i >= 0; i--) {
|
|
1228
|
+
const stmt = stmts[i];
|
|
1229
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getLeftOp() === tempResultLocal) {
|
|
1230
|
+
if (IRUtils_1.IRUtils.isTempLocal(stmt.getRightOp()) && this.isNewDefLocal(stmt.getRightOp(), stmts, i)) {
|
|
1231
|
+
tempResultReassignStmt = stmt;
|
|
1232
|
+
}
|
|
1233
|
+
else {
|
|
1234
|
+
stmt.setLeftOp(targetLocal);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
let newBottomBlocks = [];
|
|
1239
|
+
if (tempResultReassignStmt) {
|
|
1240
|
+
const oldPredecessors = currBottomBlock.getPredecessors();
|
|
1241
|
+
const newPredecessors = [];
|
|
1242
|
+
const prevTempResultLocal = tempResultReassignStmt.getRightOp();
|
|
1243
|
+
for (const predecessor of oldPredecessors) {
|
|
1244
|
+
newPredecessors.push(...this.replaceTempResultcursively(predecessor, targetLocal, prevTempResultLocal, allBlocks));
|
|
1245
|
+
}
|
|
1246
|
+
currBottomBlock.remove(tempResultReassignStmt);
|
|
1247
|
+
if (currBottomBlock.getStmts().length === 0) {
|
|
1248
|
+
// remove this block
|
|
1249
|
+
newBottomBlocks = newPredecessors;
|
|
1250
|
+
allBlocks.delete(currBottomBlock);
|
|
1251
|
+
}
|
|
1252
|
+
else {
|
|
1253
|
+
currBottomBlock.getPredecessors().splice(0, oldPredecessors.length, ...newPredecessors);
|
|
1254
|
+
newPredecessors.forEach((newPredecessor) => {
|
|
1255
|
+
newPredecessor.setSuccessorBlock(0, currBottomBlock);
|
|
1256
|
+
});
|
|
1257
|
+
newBottomBlocks = [currBottomBlock];
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
else {
|
|
1261
|
+
newBottomBlocks = [currBottomBlock];
|
|
1262
|
+
}
|
|
1263
|
+
return newBottomBlocks;
|
|
1264
|
+
}
|
|
1265
|
+
isNewDefLocal(local, stmts, pos) {
|
|
1266
|
+
for (let i = pos - 1; i >= 0; i++) {
|
|
1267
|
+
const stmt = stmts[i];
|
|
1268
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getLeftOp() === local) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return true;
|
|
1273
|
+
}
|
|
1274
|
+
rebuildBlocksInLoop(blockBuilderToCfgBlock, blocksContainLoopCondition, cfg) {
|
|
1048
1275
|
for (const blockBuilder of blocksContainLoopCondition) {
|
|
1049
1276
|
if (!blockBuilderToCfgBlock.get(blockBuilder)) {
|
|
1050
1277
|
continue;
|
|
@@ -1053,38 +1280,11 @@ class CfgBuilder {
|
|
|
1053
1280
|
const blockId = block.getId();
|
|
1054
1281
|
const stmts = block.getStmts();
|
|
1055
1282
|
const stmtsCnt = stmts.length;
|
|
1056
|
-
|
|
1057
|
-
let iteratorNextStmtIdx = -1;
|
|
1058
|
-
let dummyInitializerStmtIdx = -1;
|
|
1059
|
-
for (let i = 0; i < stmtsCnt; i++) {
|
|
1060
|
-
const stmt = stmts[i];
|
|
1061
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.AbstractInvokeExpr) {
|
|
1062
|
-
const invokeExpr = stmt.getRightOp();
|
|
1063
|
-
if (invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName() === Builtin_1.Builtin.ITERATOR_NEXT) {
|
|
1064
|
-
iteratorNextStmtIdx = i;
|
|
1065
|
-
continue;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
if (stmt.toString() === ArkIRTransformer_1.DUMMY_INITIALIZER_STMT) {
|
|
1069
|
-
dummyInitializerStmtIdx = i;
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
1073
|
-
ifStmtIdx = i;
|
|
1074
|
-
break;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1283
|
+
const { ifStmtIdx, iteratorNextStmtIdx, dummyInitializerStmtIdx } = this.findIteratorIdx(stmts);
|
|
1077
1284
|
if (iteratorNextStmtIdx !== -1 || dummyInitializerStmtIdx !== -1) {
|
|
1078
|
-
// put statements into block before condition
|
|
1079
1285
|
const lastStmtIdxBeforeCondition = iteratorNextStmtIdx !== -1 ? iteratorNextStmtIdx : dummyInitializerStmtIdx;
|
|
1080
1286
|
const stmtsInsertBeforeCondition = stmts.slice(0, lastStmtIdxBeforeCondition);
|
|
1081
|
-
let prevBlockBuilderContainsLoop =
|
|
1082
|
-
for (const prevBlockBuilder of blockBuilder.lasts) {
|
|
1083
|
-
if (prevBlockBuilder.id < blockId && blocksContainLoopCondition.has(prevBlockBuilder)) {
|
|
1084
|
-
prevBlockBuilderContainsLoop = true;
|
|
1085
|
-
break;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1287
|
+
let prevBlockBuilderContainsLoop = this.doesPrevBlockBuilderContainLoop(blockBuilder, blockId, blocksContainLoopCondition);
|
|
1088
1288
|
if (prevBlockBuilderContainsLoop) {
|
|
1089
1289
|
// should create an extra block when previous block contains loop condition
|
|
1090
1290
|
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, blockBuilder, stmtsInsertBeforeCondition, false, cfg);
|
|
@@ -1096,23 +1296,7 @@ class CfgBuilder {
|
|
|
1096
1296
|
}
|
|
1097
1297
|
if (dummyInitializerStmtIdx !== -1 && ifStmtIdx !== stmtsCnt - 1) {
|
|
1098
1298
|
// put incrementor statements into block which reenters condition
|
|
1099
|
-
|
|
1100
|
-
const blockBuildersReenterCondition = [];
|
|
1101
|
-
for (const prevBlockBuilder of blockBuilder.lasts) {
|
|
1102
|
-
const prevBlock = blockBuilderToCfgBlock.get(prevBlockBuilder);
|
|
1103
|
-
if (prevBlock.getId() > blockId) {
|
|
1104
|
-
blockBuildersReenterCondition.push(prevBlockBuilder);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
if (blockBuildersReenterCondition.length > 1 || blocksContainLoopCondition.has(blockBuildersReenterCondition[0])) {
|
|
1108
|
-
// put incrementor statements into an extra block
|
|
1109
|
-
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, blockBuilder, stmtsReenterCondition, true, cfg);
|
|
1110
|
-
}
|
|
1111
|
-
else {
|
|
1112
|
-
// put incrementor statements into prev reenter block
|
|
1113
|
-
const blockReenterCondition = blockBuilderToCfgBlock.get(blockBuildersReenterCondition[0]);
|
|
1114
|
-
blockReenterCondition === null || blockReenterCondition === void 0 ? void 0 : blockReenterCondition.getStmts().push(...stmtsReenterCondition);
|
|
1115
|
-
}
|
|
1299
|
+
this.adjustIncrementorStmts(stmts, ifStmtIdx, blockBuilder, blockId, blockBuilderToCfgBlock, blocksContainLoopCondition, cfg);
|
|
1116
1300
|
}
|
|
1117
1301
|
else if (iteratorNextStmtIdx !== -1) {
|
|
1118
1302
|
// put statements which get value of iterator into block after condition
|
|
@@ -1127,21 +1311,16 @@ class CfgBuilder {
|
|
|
1127
1311
|
stmts.splice(ifStmtIdx - firstStmtIdxInCondition + 1);
|
|
1128
1312
|
}
|
|
1129
1313
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1314
|
+
}
|
|
1315
|
+
doesPrevBlockBuilderContainLoop(currBlockBuilder, currBlockId, blocksContainLoopCondition) {
|
|
1316
|
+
let prevBlockBuilderContainsLoop = false;
|
|
1317
|
+
for (const prevBlockBuilder of currBlockBuilder.lasts) {
|
|
1318
|
+
if (prevBlockBuilder.id < currBlockId && blocksContainLoopCondition.has(prevBlockBuilder)) {
|
|
1319
|
+
prevBlockBuilderContainsLoop = true;
|
|
1320
|
+
break;
|
|
1135
1321
|
}
|
|
1136
1322
|
}
|
|
1137
|
-
|
|
1138
|
-
stmt.setCfg(cfg);
|
|
1139
|
-
}
|
|
1140
|
-
return {
|
|
1141
|
-
cfg: cfg,
|
|
1142
|
-
locals: arkIRTransformer.getLocals(),
|
|
1143
|
-
aliasTypeMap: arkIRTransformer.getAliasTypeMap(),
|
|
1144
|
-
};
|
|
1323
|
+
return prevBlockBuilderContainsLoop;
|
|
1145
1324
|
}
|
|
1146
1325
|
insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, conditionBlockBuilder, stmtsInsertBeforeCondition, collectReenter, cfg) {
|
|
1147
1326
|
const blockId = conditionBlockBuilder.id;
|
|
@@ -1205,5 +1384,54 @@ class CfgBuilder {
|
|
|
1205
1384
|
cfg.addBlock(blockInsertBeforeCondition);
|
|
1206
1385
|
blockBuilderToCfgBlock.set(blockBuilderInsertBeforeCondition, blockInsertBeforeCondition);
|
|
1207
1386
|
}
|
|
1387
|
+
findIteratorIdx(stmts) {
|
|
1388
|
+
let ifStmtIdx = -1;
|
|
1389
|
+
let iteratorNextStmtIdx = -1;
|
|
1390
|
+
let dummyInitializerStmtIdx = -1;
|
|
1391
|
+
const stmtsCnt = stmts.length;
|
|
1392
|
+
for (let i = 0; i < stmtsCnt; i++) {
|
|
1393
|
+
const stmt = stmts[i];
|
|
1394
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.AbstractInvokeExpr) {
|
|
1395
|
+
const invokeExpr = stmt.getRightOp();
|
|
1396
|
+
if (invokeExpr.getMethodSignature().getMethodSubSignature()
|
|
1397
|
+
.getMethodName() === Builtin_1.Builtin.ITERATOR_NEXT) {
|
|
1398
|
+
iteratorNextStmtIdx = i;
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT) {
|
|
1403
|
+
dummyInitializerStmtIdx = i;
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
1407
|
+
ifStmtIdx = i;
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return {
|
|
1412
|
+
ifStmtIdx: ifStmtIdx,
|
|
1413
|
+
iteratorNextStmtIdx: iteratorNextStmtIdx,
|
|
1414
|
+
dummyInitializerStmtIdx: dummyInitializerStmtIdx,
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
adjustIncrementorStmts(stmts, ifStmtIdx, currBlockBuilder, currBlockId, blockBuilderToCfgBlock, blocksContainLoopCondition, cfg) {
|
|
1418
|
+
const stmtsReenterCondition = stmts.slice(ifStmtIdx + 1);
|
|
1419
|
+
const blockBuildersReenterCondition = [];
|
|
1420
|
+
for (const prevBlockBuilder of currBlockBuilder.lasts) {
|
|
1421
|
+
const prevBlock = blockBuilderToCfgBlock.get(prevBlockBuilder);
|
|
1422
|
+
if (prevBlock.getId() > currBlockId) {
|
|
1423
|
+
blockBuildersReenterCondition.push(prevBlockBuilder);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (blockBuildersReenterCondition.length > 1 || blocksContainLoopCondition.has(blockBuildersReenterCondition[0])) {
|
|
1427
|
+
// put incrementor statements into an extra block
|
|
1428
|
+
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, currBlockBuilder, stmtsReenterCondition, true, cfg);
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
// put incrementor statements into prev reenter block
|
|
1432
|
+
const blockReenterCondition = blockBuilderToCfgBlock.get(blockBuildersReenterCondition[0]);
|
|
1433
|
+
blockReenterCondition === null || blockReenterCondition === void 0 ? void 0 : blockReenterCondition.getStmts().push(...stmtsReenterCondition);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1208
1436
|
}
|
|
1209
1437
|
exports.CfgBuilder = CfgBuilder;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
1
|
+
export declare const NAME_DELIMITER = "$";
|
|
2
|
+
export declare const NAME_PREFIX = "%";
|
|
3
|
+
export declare const UNKNOWN_NAME = "unk";
|
|
4
|
+
export declare const DEFAULT_NAME = "dflt";
|
|
5
|
+
export declare const DEFAULT_ARK_CLASS_NAME: string;
|
|
6
|
+
export declare const DEFAULT_ARK_METHOD_NAME: string;
|
|
7
|
+
export declare const ANONYMOUS_CLASS_PREFIX: string;
|
|
8
|
+
export declare const ANONYMOUS_CLASS_DELIMITER = "$";
|
|
9
|
+
export declare const INSTANCE_INIT_METHOD_NAME: string;
|
|
10
|
+
export declare const STATIC_INIT_METHOD_NAME: string;
|
|
11
|
+
export declare const ANONYMOUS_METHOD_PREFIX: string;
|
|
8
12
|
export declare const CALL_SIGNATURE_NAME = "create";
|
|
9
|
-
export declare const UNKNOWN_PROJECT_NAME
|
|
10
|
-
export declare const UNKNOWN_FILE_NAME
|
|
11
|
-
export declare const UNKNOWN_NAMESPACE_NAME
|
|
13
|
+
export declare const UNKNOWN_PROJECT_NAME: string;
|
|
14
|
+
export declare const UNKNOWN_FILE_NAME: string;
|
|
15
|
+
export declare const UNKNOWN_NAMESPACE_NAME: string;
|
|
12
16
|
export declare const UNKNOWN_CLASS_NAME = "";
|
|
13
17
|
export declare const UNKNOWN_FIELD_NAME = "";
|
|
14
18
|
export declare const UNKNOWN_METHOD_NAME = "";
|
|
19
|
+
export declare const TEMP_LOCAL_PREFIX = "%";
|
|
15
20
|
//# 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,sBAAsB,
|
|
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,uBAAuB,QAA6B,CAAC;AAClE,eAAO,MAAM,sBAAsB,QAAqB,CAAC;AACzD,eAAO,MAAM,yBAAyB,MAAiB,CAAC;AAGxD,eAAO,MAAM,yBAAyB,QAA2B,CAAC;AAClE,eAAO,MAAM,uBAAuB,QAA2B,CAAC;AAChE,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"}
|
package/lib/core/common/Const.js
CHANGED
|
@@ -14,21 +14,28 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
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_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_METHOD_NAME = exports.DEFAULT_ARK_CLASS_NAME = void 0;
|
|
17
|
+
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_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_METHOD_NAME = exports.DEFAULT_ARK_CLASS_NAME = exports.DEFAULT_NAME = exports.UNKNOWN_NAME = exports.NAME_PREFIX = exports.NAME_DELIMITER = void 0;
|
|
18
|
+
// names
|
|
19
|
+
exports.NAME_DELIMITER = '$';
|
|
20
|
+
exports.NAME_PREFIX = '%';
|
|
21
|
+
exports.UNKNOWN_NAME = 'unk';
|
|
22
|
+
exports.DEFAULT_NAME = 'dflt';
|
|
18
23
|
// ArkClass const
|
|
19
|
-
exports.DEFAULT_ARK_CLASS_NAME =
|
|
20
|
-
exports.DEFAULT_ARK_METHOD_NAME =
|
|
21
|
-
exports.ANONYMOUS_CLASS_PREFIX = '
|
|
22
|
-
exports.ANONYMOUS_CLASS_DELIMITER =
|
|
24
|
+
exports.DEFAULT_ARK_CLASS_NAME = exports.NAME_PREFIX + exports.DEFAULT_NAME;
|
|
25
|
+
exports.DEFAULT_ARK_METHOD_NAME = exports.NAME_PREFIX + exports.DEFAULT_NAME;
|
|
26
|
+
exports.ANONYMOUS_CLASS_PREFIX = exports.NAME_PREFIX + 'AC';
|
|
27
|
+
exports.ANONYMOUS_CLASS_DELIMITER = exports.NAME_DELIMITER;
|
|
23
28
|
// ArkMethod const
|
|
24
|
-
exports.INSTANCE_INIT_METHOD_NAME = '
|
|
25
|
-
exports.STATIC_INIT_METHOD_NAME = '
|
|
26
|
-
exports.ANONYMOUS_METHOD_PREFIX = '
|
|
29
|
+
exports.INSTANCE_INIT_METHOD_NAME = exports.NAME_PREFIX + 'instInit';
|
|
30
|
+
exports.STATIC_INIT_METHOD_NAME = exports.NAME_PREFIX + 'statInit';
|
|
31
|
+
exports.ANONYMOUS_METHOD_PREFIX = exports.NAME_PREFIX + 'AM';
|
|
27
32
|
exports.CALL_SIGNATURE_NAME = 'create';
|
|
28
33
|
// ArkSignature const
|
|
29
|
-
exports.UNKNOWN_PROJECT_NAME =
|
|
30
|
-
exports.UNKNOWN_FILE_NAME =
|
|
31
|
-
exports.UNKNOWN_NAMESPACE_NAME =
|
|
34
|
+
exports.UNKNOWN_PROJECT_NAME = exports.NAME_PREFIX + exports.UNKNOWN_NAME;
|
|
35
|
+
exports.UNKNOWN_FILE_NAME = exports.NAME_PREFIX + exports.UNKNOWN_NAME;
|
|
36
|
+
exports.UNKNOWN_NAMESPACE_NAME = exports.NAME_PREFIX + exports.UNKNOWN_NAME;
|
|
32
37
|
exports.UNKNOWN_CLASS_NAME = ''; // temp for being compatible with existing type inference
|
|
33
38
|
exports.UNKNOWN_FIELD_NAME = ''; // temp for being compatible with existing type inference
|
|
34
39
|
exports.UNKNOWN_METHOD_NAME = ''; // temp for being compatible with existing type inference
|
|
40
|
+
// IR const
|
|
41
|
+
exports.TEMP_LOCAL_PREFIX = exports.NAME_PREFIX;
|
|
@@ -3,7 +3,7 @@ import { ArkClass } from '../model/ArkClass';
|
|
|
3
3
|
import { ArkMethod } from '../model/ArkMethod';
|
|
4
4
|
/**
|
|
5
5
|
收集所有的onCreate,onStart等函数,构造一个虚拟函数,具体为:
|
|
6
|
-
|
|
6
|
+
%statInit()
|
|
7
7
|
...
|
|
8
8
|
count = 0
|
|
9
9
|
while (true) {
|
|
@@ -40,6 +40,7 @@ export declare class DummyMainCreater {
|
|
|
40
40
|
private addCfg2Stmt;
|
|
41
41
|
getDummyMain(): ArkMethod;
|
|
42
42
|
private getEntryMethodsFromComponents;
|
|
43
|
+
private classInheritsAbility;
|
|
43
44
|
getMethodsFromAllAbilities(): ArkMethod[];
|
|
44
45
|
getEntryMethodsFromModuleJson5(): ArkMethod[];
|
|
45
46
|
getAbilitiesByParseModuleJson(modulePath: string): ArkClass[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAsBpC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAY/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;IACnC,OAAO,CAAC,YAAY,CAAkC;gBAE1C,KAAK,EAAE,KAAK;IAUxB,OAAO,CAAC,iBAAiB;IASlB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI;IAI3C,eAAe,IAAI,IAAI;IAiD9B,OAAO,CAAC,kBAAkB;IAkI1B,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,WAAW;IAYZ,YAAY,IAAI,SAAS;IAIhC,OAAO,CAAC,6BAA6B;IAmBrC,OAAO,CAAC,oBAAoB;IAYrB,0BAA0B,IAAI,SAAS,EAAE;IAUzC,8BAA8B,IAAI,SAAS,EAAE;IAkD7C,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,EAAE;IA2B7D,kBAAkB,IAAI,SAAS,EAAE;CAiB3C"}
|
|
@@ -61,11 +61,12 @@ const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
|
61
61
|
const TSConst_1 = require("./TSConst");
|
|
62
62
|
const json5parser_1 = require("../../utils/json5parser");
|
|
63
63
|
const logger_1 = __importStar(require("../../utils/logger"));
|
|
64
|
-
const
|
|
64
|
+
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
65
|
+
const ValueUtil_1 = require("./ValueUtil");
|
|
65
66
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'Scene');
|
|
66
67
|
/**
|
|
67
68
|
收集所有的onCreate,onStart等函数,构造一个虚拟函数,具体为:
|
|
68
|
-
|
|
69
|
+
%statInit()
|
|
69
70
|
...
|
|
70
71
|
count = 0
|
|
71
72
|
while (true) {
|
|
@@ -102,7 +103,7 @@ class DummyMainCreater {
|
|
|
102
103
|
this.buildBuiltInClass();
|
|
103
104
|
}
|
|
104
105
|
buildBuiltInClass() {
|
|
105
|
-
for (const sdkFile of this.scene.
|
|
106
|
+
for (const sdkFile of this.scene.getSdkArkFiles()) {
|
|
106
107
|
if (sdkFile.getName() === 'api\\@ohos.app.ability.Want.d.ts') {
|
|
107
108
|
const arkClass = sdkFile.getClassWithName('Want');
|
|
108
109
|
this.builtInClass.set('Want', arkClass);
|
|
@@ -118,7 +119,7 @@ class DummyMainCreater {
|
|
|
118
119
|
dummyMainFile.setScene(this.scene);
|
|
119
120
|
const dummyMainFileSignature = new ArkSignature_1.FileSignature(this.scene.getProjectName(), '@dummyFile');
|
|
120
121
|
dummyMainFile.setFileSignature(dummyMainFileSignature);
|
|
121
|
-
this.scene.
|
|
122
|
+
this.scene.setFile(dummyMainFile);
|
|
122
123
|
const dummyMainClass = new ArkClass_1.ArkClass();
|
|
123
124
|
dummyMainClass.setDeclaringArkFile(dummyMainFile);
|
|
124
125
|
const dummyMainClassSignature = new ArkSignature_1.ClassSignature('@dummyClass', dummyMainClass.getDeclaringArkFile().getFileSignature(), ((_a = dummyMainClass.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getSignature()) || null);
|
|
@@ -128,8 +129,9 @@ class DummyMainCreater {
|
|
|
128
129
|
this.dummyMain.setDeclaringArkClass(dummyMainClass);
|
|
129
130
|
const methodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName('@dummyMain');
|
|
130
131
|
const methodSignature = new ArkSignature_1.MethodSignature(this.dummyMain.getDeclaringArkClass().getSignature(), methodSubSignature);
|
|
131
|
-
this.dummyMain.
|
|
132
|
-
|
|
132
|
+
this.dummyMain.setImplementationSignature(methodSignature);
|
|
133
|
+
this.dummyMain.setLineCol(0);
|
|
134
|
+
(0, ArkMethodBuilder_1.checkAndUpdateMethod)(this.dummyMain, dummyMainClass);
|
|
133
135
|
dummyMainClass.addMethod(this.dummyMain);
|
|
134
136
|
for (const method of this.entryMethods) {
|
|
135
137
|
if (method.getDeclaringArkClass().isDefaultArkClass()) {
|
|
@@ -162,7 +164,6 @@ class DummyMainCreater {
|
|
|
162
164
|
const dummyCfg = new Cfg_1.Cfg();
|
|
163
165
|
dummyCfg.setDeclaringMethod(this.dummyMain);
|
|
164
166
|
const firstBlock = new BasicBlock_1.BasicBlock();
|
|
165
|
-
dummyCfg.addBlock(firstBlock);
|
|
166
167
|
let isStartingStmt = true;
|
|
167
168
|
for (const method of this.scene.getStaticInitMethods()) {
|
|
168
169
|
const staticInvokeExpr = new Expr_1.ArkStaticInvokeExpr(method.getSignature(), []);
|
|
@@ -193,15 +194,17 @@ class DummyMainCreater {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
const countLocal = new Local_1.Local('count', Type_1.NumberType.getInstance());
|
|
196
|
-
const zero =
|
|
197
|
+
const zero = ValueUtil_1.ValueUtil.getOrCreateNumberConst(0);
|
|
197
198
|
const countAssignStmt = new Stmt_1.ArkAssignStmt(countLocal, zero);
|
|
198
|
-
const truE =
|
|
199
|
+
const truE = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
199
200
|
const conditionTrue = new Expr_1.ArkConditionExpr(truE, zero, Expr_1.RelationalBinaryOperator.Equality);
|
|
200
201
|
const whileStmt = new Stmt_1.ArkIfStmt(conditionTrue);
|
|
201
202
|
firstBlock.addStmt(countAssignStmt);
|
|
203
|
+
dummyCfg.addBlock(firstBlock);
|
|
204
|
+
dummyCfg.setStartingStmt(firstBlock.getStmts()[0]);
|
|
202
205
|
const whileBlock = new BasicBlock_1.BasicBlock();
|
|
203
|
-
dummyCfg.addBlock(whileBlock);
|
|
204
206
|
whileBlock.addStmt(whileStmt);
|
|
207
|
+
dummyCfg.addBlock(whileBlock);
|
|
205
208
|
firstBlock.addSuccessorBlock(whileBlock);
|
|
206
209
|
whileBlock.addPredecessorBlock(firstBlock);
|
|
207
210
|
let lastBlocks = [whileBlock];
|
|
@@ -211,8 +214,8 @@ class DummyMainCreater {
|
|
|
211
214
|
const condition = new Expr_1.ArkConditionExpr(countLocal, new Constant_1.Constant(count.toString(), Type_1.NumberType.getInstance()), Expr_1.RelationalBinaryOperator.Equality);
|
|
212
215
|
const ifStmt = new Stmt_1.ArkIfStmt(condition);
|
|
213
216
|
const ifBlock = new BasicBlock_1.BasicBlock();
|
|
214
|
-
dummyCfg.addBlock(ifBlock);
|
|
215
217
|
ifBlock.addStmt(ifStmt);
|
|
218
|
+
dummyCfg.addBlock(ifBlock);
|
|
216
219
|
for (const block of lastBlocks) {
|
|
217
220
|
ifBlock.addPredecessorBlock(block);
|
|
218
221
|
block.addSuccessorBlock(ifBlock);
|
|
@@ -260,8 +263,8 @@ class DummyMainCreater {
|
|
|
260
263
|
invokeExpr = new Expr_1.ArkStaticInvokeExpr(method.getSignature(), paramLocals);
|
|
261
264
|
}
|
|
262
265
|
const invokeStmt = new Stmt_1.ArkInvokeStmt(invokeExpr);
|
|
263
|
-
dummyCfg.addBlock(invokeBlock);
|
|
264
266
|
invokeBlock.addStmt(invokeStmt);
|
|
267
|
+
dummyCfg.addBlock(invokeBlock);
|
|
265
268
|
ifBlock.addSuccessorBlock(invokeBlock);
|
|
266
269
|
invokeBlock.addPredecessorBlock(ifBlock);
|
|
267
270
|
lastBlocks = [ifBlock, invokeBlock];
|
|
@@ -272,8 +275,8 @@ class DummyMainCreater {
|
|
|
272
275
|
}
|
|
273
276
|
const returnStmt = new Stmt_1.ArkReturnVoidStmt();
|
|
274
277
|
const returnBlock = new BasicBlock_1.BasicBlock();
|
|
275
|
-
dummyCfg.addBlock(returnBlock);
|
|
276
278
|
returnBlock.addStmt(returnStmt);
|
|
279
|
+
dummyCfg.addBlock(returnBlock);
|
|
277
280
|
whileBlock.addSuccessorBlock(returnBlock);
|
|
278
281
|
returnBlock.addPredecessorBlock(whileBlock);
|
|
279
282
|
return dummyCfg;
|
|
@@ -333,11 +336,21 @@ class DummyMainCreater {
|
|
|
333
336
|
});
|
|
334
337
|
return methods;
|
|
335
338
|
}
|
|
336
|
-
|
|
339
|
+
classInheritsAbility(arkClass) {
|
|
337
340
|
const ABILITY_BASE_CLASSES = ['UIExtensionAbility', 'Ability', 'FormExtensionAbility', 'UIAbility', 'BackupExtensionAbility'];
|
|
341
|
+
let superClass = arkClass.getSuperClass();
|
|
342
|
+
while (superClass) {
|
|
343
|
+
if (ABILITY_BASE_CLASSES.includes(superClass.getName())) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
superClass = superClass.getSuperClass();
|
|
347
|
+
}
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
getMethodsFromAllAbilities() {
|
|
338
351
|
let methods = [];
|
|
339
352
|
this.scene.getClasses()
|
|
340
|
-
.filter(cls =>
|
|
353
|
+
.filter(cls => this.classInheritsAbility(cls))
|
|
341
354
|
.forEach(cls => {
|
|
342
355
|
methods.push(...cls.getMethods().filter(mtd => entryMethodUtils_1.LIFECYCLE_METHOD_NAME.includes(mtd.getName())));
|
|
343
356
|
});
|
|
@@ -62,4 +62,5 @@ export declare const COMPONENT_COMMON: string;
|
|
|
62
62
|
export declare const COMPONENT_INSTANCE: string;
|
|
63
63
|
export declare const API_INTERNAL: string;
|
|
64
64
|
export declare const COMPONENT_ATTRIBUTE: string;
|
|
65
|
+
export declare const CALL_BACK: string;
|
|
65
66
|
//# sourceMappingURL=EtsConst.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EtsConst.d.ts","sourceRoot":"","sources":["../../../src/core/common/EtsConst.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoyBhC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAgD,CAAC;AAElG,eAAO,MAAM,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAqD/C,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAqE,CAAC;AAClH,eAAO,MAAM,eAAe,EAAE,MAAgB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,EAAE,MAAkB,CAAC;AACnD,eAAO,MAAM,uBAAuB,EAAE,MAAuB,CAAC;AAE9D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,eAAO,MAAM,yBAAyB,EAAE,MAAiB,CAAC;AAC1D,eAAO,MAAM,sBAAsB,EAAE,MAAc,CAAC;AACpD,eAAO,MAAM,oBAAoB,EAAE,MAAe,CAAC;AACnD,eAAO,MAAM,gBAAgB,EAAE,MAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,EAAE,MAAkB,CAAC;AACpD,eAAO,MAAM,uBAAuB,EAAE,MAAsB,CAAC;AAE7D,eAAO,MAAM,YAAY,EAAE,MAAa,CAAC;AACzC,eAAO,MAAM,mBAAmB,EAAE,MAAmB,CAAC;AACtD,eAAO,MAAM,yBAAyB,EAAE,MAAiB,CAAC;AAC1D,eAAO,MAAM,wBAAwB,EAAE,MAAgB,CAAC;AAExD,eAAO,MAAM,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAKlD,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,MAA0C,CAAC;AACxE,eAAO,MAAM,gBAAgB,EAAE,MAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,EAAE,MAAmB,CAAC;AACrD,eAAO,MAAM,YAAY,EAAE,MAA0C,CAAC;AAEtE,eAAO,MAAM,mBAAmB,EAAE,MAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"EtsConst.d.ts","sourceRoot":"","sources":["../../../src/core/common/EtsConst.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoyBhC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAgD,CAAC;AAElG,eAAO,MAAM,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAqD/C,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAqE,CAAC;AAClH,eAAO,MAAM,eAAe,EAAE,MAAgB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,EAAE,MAAkB,CAAC;AACnD,eAAO,MAAM,uBAAuB,EAAE,MAAuB,CAAC;AAE9D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,eAAO,MAAM,yBAAyB,EAAE,MAAiB,CAAC;AAC1D,eAAO,MAAM,sBAAsB,EAAE,MAAc,CAAC;AACpD,eAAO,MAAM,oBAAoB,EAAE,MAAe,CAAC;AACnD,eAAO,MAAM,gBAAgB,EAAE,MAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,EAAE,MAAkB,CAAC;AACpD,eAAO,MAAM,uBAAuB,EAAE,MAAsB,CAAC;AAE7D,eAAO,MAAM,YAAY,EAAE,MAAa,CAAC;AACzC,eAAO,MAAM,mBAAmB,EAAE,MAAmB,CAAC;AACtD,eAAO,MAAM,yBAAyB,EAAE,MAAiB,CAAC;AAC1D,eAAO,MAAM,wBAAwB,EAAE,MAAgB,CAAC;AAExD,eAAO,MAAM,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAKlD,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,MAA0C,CAAC;AACxE,eAAO,MAAM,gBAAgB,EAAE,MAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,EAAE,MAAmB,CAAC;AACrD,eAAO,MAAM,YAAY,EAAE,MAA0C,CAAC;AAEtE,eAAO,MAAM,mBAAmB,EAAE,MAAoB,CAAC;AACvD,eAAO,MAAM,SAAS,EAAE,MAAmB,CAAC"}
|