arkanalyzer 1.0.20 → 1.0.21
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/Config.d.ts +70 -70
- package/lib/Config.js +198 -198
- package/lib/Scene.d.ts +316 -316
- package/lib/Scene.js +1316 -1316
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
- package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
- package/lib/callgraph/common/Statistics.d.ts +57 -57
- package/lib/callgraph/common/Statistics.js +228 -228
- package/lib/callgraph/model/CallGraph.d.ts +96 -96
- package/lib/callgraph/model/CallGraph.js +354 -354
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
- package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
- package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
- package/lib/callgraph/pointerAnalysis/Context.js +155 -155
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
- package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
- package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
- package/lib/core/base/Constant.d.ts +48 -48
- package/lib/core/base/Constant.js +103 -103
- package/lib/core/base/Decorator.d.ts +15 -15
- package/lib/core/base/Decorator.js +46 -46
- package/lib/core/base/DefUseChain.d.ts +8 -8
- package/lib/core/base/DefUseChain.js +25 -25
- package/lib/core/base/Expr.d.ts +340 -340
- package/lib/core/base/Expr.js +917 -917
- package/lib/core/base/Local.d.ts +104 -104
- package/lib/core/base/Local.js +176 -176
- package/lib/core/base/Position.d.ts +30 -30
- package/lib/core/base/Position.js +147 -147
- package/lib/core/base/Ref.d.ts +173 -173
- package/lib/core/base/Ref.js +374 -374
- package/lib/core/base/Stmt.d.ts +237 -237
- package/lib/core/base/Stmt.js +525 -525
- package/lib/core/base/Trap.d.ts +8 -8
- package/lib/core/base/Trap.js +30 -30
- package/lib/core/base/Type.d.ts +308 -308
- package/lib/core/base/Type.js +639 -639
- package/lib/core/base/TypeExpr.d.ts +71 -71
- package/lib/core/base/TypeExpr.js +155 -155
- package/lib/core/base/Value.d.ts +32 -32
- package/lib/core/base/Value.js +16 -16
- package/lib/core/common/ArkError.d.ts +14 -14
- package/lib/core/common/ArkError.js +28 -28
- package/lib/core/common/ArkIRTransformer.d.ts +67 -67
- package/lib/core/common/ArkIRTransformer.js +690 -690
- package/lib/core/common/ArkValueTransformer.d.ts +89 -89
- package/lib/core/common/ArkValueTransformer.js +1478 -1478
- package/lib/core/common/Builtin.d.ts +36 -36
- package/lib/core/common/Builtin.js +81 -81
- package/lib/core/common/Const.d.ts +21 -21
- package/lib/core/common/Const.js +43 -43
- package/lib/core/common/DummyMainCreater.d.ts +46 -46
- package/lib/core/common/DummyMainCreater.js +319 -319
- package/lib/core/common/EtsConst.d.ts +73 -73
- package/lib/core/common/EtsConst.js +1021 -1021
- package/lib/core/common/ExprUseReplacer.d.ts +21 -21
- package/lib/core/common/ExprUseReplacer.js +124 -124
- package/lib/core/common/IRInference.d.ts +36 -36
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +651 -648
- package/lib/core/common/IRUtils.d.ts +18 -18
- package/lib/core/common/IRUtils.js +141 -141
- package/lib/core/common/ModelUtils.d.ts +70 -70
- package/lib/core/common/ModelUtils.js +712 -712
- package/lib/core/common/RefUseReplacer.d.ts +13 -13
- package/lib/core/common/RefUseReplacer.js +52 -52
- package/lib/core/common/SdkUtils.d.ts +8 -8
- package/lib/core/common/SdkUtils.js +105 -105
- package/lib/core/common/StmtDefReplacer.d.ts +12 -12
- package/lib/core/common/StmtDefReplacer.js +41 -41
- package/lib/core/common/StmtUseReplacer.d.ts +16 -16
- package/lib/core/common/StmtUseReplacer.js +108 -108
- package/lib/core/common/TSConst.d.ts +18 -18
- package/lib/core/common/TSConst.js +36 -36
- package/lib/core/common/TypeInference.d.ts +102 -102
- package/lib/core/common/TypeInference.js +748 -748
- package/lib/core/common/ValueUtil.d.ts +12 -12
- package/lib/core/common/ValueUtil.js +54 -54
- package/lib/core/common/VisibleValue.d.ts +36 -36
- package/lib/core/common/VisibleValue.js +212 -212
- package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
- package/lib/core/dataflow/DataflowProblem.js +20 -20
- package/lib/core/dataflow/DataflowResult.d.ts +7 -7
- package/lib/core/dataflow/DataflowResult.js +26 -26
- package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
- package/lib/core/dataflow/DataflowSolver.js +307 -307
- package/lib/core/dataflow/Edge.d.ts +11 -11
- package/lib/core/dataflow/Edge.js +31 -31
- package/lib/core/dataflow/Fact.d.ts +6 -6
- package/lib/core/dataflow/Fact.js +24 -24
- package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
- package/lib/core/dataflow/GenericDataFlow.js +109 -109
- package/lib/core/dataflow/ReachingDef.d.ts +62 -62
- package/lib/core/dataflow/ReachingDef.js +168 -168
- package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
- package/lib/core/dataflow/UndefinedVariable.js +288 -288
- package/lib/core/dataflow/Util.d.ts +9 -9
- package/lib/core/dataflow/Util.js +64 -64
- package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
- package/lib/core/graph/BaseExplicitGraph.js +157 -157
- package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
- package/lib/core/graph/BaseImplicitGraph.js +78 -78
- package/lib/core/graph/BasicBlock.d.ts +104 -104
- package/lib/core/graph/BasicBlock.js +280 -280
- package/lib/core/graph/Cfg.d.ts +59 -59
- package/lib/core/graph/Cfg.js +282 -282
- package/lib/core/graph/DependsGraph.d.ts +35 -35
- package/lib/core/graph/DependsGraph.js +87 -87
- package/lib/core/graph/DominanceFinder.d.ts +15 -15
- package/lib/core/graph/DominanceFinder.js +121 -121
- package/lib/core/graph/DominanceTree.d.ts +12 -12
- package/lib/core/graph/DominanceTree.js +70 -70
- package/lib/core/graph/GraphTraits.d.ts +7 -7
- package/lib/core/graph/GraphTraits.js +16 -16
- package/lib/core/graph/Scc.d.ts +61 -61
- package/lib/core/graph/Scc.js +222 -222
- package/lib/core/graph/ViewTree.d.ts +114 -114
- package/lib/core/graph/ViewTree.js +16 -16
- package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
- package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
- package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
- package/lib/core/graph/builder/ConditionBuilder.js +252 -252
- package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
- package/lib/core/graph/builder/LoopBuilder.js +251 -251
- package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
- package/lib/core/graph/builder/SwitchBuilder.js +152 -152
- package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
- package/lib/core/graph/builder/TrapBuilder.js +272 -272
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
- package/lib/core/graph/builder/ViewTreeBuilder.js +1055 -1055
- package/lib/core/model/ArkBaseModel.d.ts +59 -59
- package/lib/core/model/ArkBaseModel.js +274 -274
- package/lib/core/model/ArkBody.d.ts +24 -24
- package/lib/core/model/ArkBody.js +65 -65
- package/lib/core/model/ArkClass.d.ts +206 -206
- package/lib/core/model/ArkClass.js +439 -439
- package/lib/core/model/ArkExport.d.ts +72 -72
- package/lib/core/model/ArkExport.js +147 -147
- package/lib/core/model/ArkField.d.ts +62 -62
- package/lib/core/model/ArkField.js +113 -113
- package/lib/core/model/ArkFile.d.ts +131 -131
- package/lib/core/model/ArkFile.js +267 -267
- package/lib/core/model/ArkImport.d.ts +44 -44
- package/lib/core/model/ArkImport.js +108 -108
- package/lib/core/model/ArkMetadata.d.ts +31 -31
- package/lib/core/model/ArkMetadata.js +55 -55
- package/lib/core/model/ArkMethod.d.ts +261 -261
- package/lib/core/model/ArkMethod.js +592 -592
- package/lib/core/model/ArkNamespace.d.ts +66 -66
- package/lib/core/model/ArkNamespace.js +209 -209
- package/lib/core/model/ArkSignature.d.ts +162 -162
- package/lib/core/model/ArkSignature.js +379 -379
- package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
- package/lib/core/model/builder/ArkClassBuilder.js +454 -454
- package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
- package/lib/core/model/builder/ArkExportBuilder.js +210 -210
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
- package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
- package/lib/core/model/builder/ArkFileBuilder.js +165 -165
- package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
- package/lib/core/model/builder/ArkImportBuilder.js +128 -128
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
- package/lib/core/model/builder/ArkMethodBuilder.js +486 -486
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
- package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
- package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +542 -371
- package/lib/core/model/builder/builderUtils.d.ts +18 -18
- package/lib/core/model/builder/builderUtils.js +558 -558
- package/lib/index.d.ts +82 -80
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +201 -196
- package/lib/save/ArkStream.d.ts +23 -23
- package/lib/save/ArkStream.js +83 -83
- package/lib/save/DotPrinter.d.ts +43 -43
- package/lib/save/DotPrinter.js +170 -170
- package/lib/save/GraphPrinter.d.ts +16 -16
- package/lib/save/GraphPrinter.js +134 -134
- package/lib/save/JsonPrinter.d.ts +30 -30
- package/lib/save/JsonPrinter.js +580 -580
- package/lib/save/Printer.d.ts +12 -12
- package/lib/save/Printer.js +27 -27
- package/lib/save/PrinterBuilder.d.ts +53 -53
- package/lib/save/PrinterBuilder.js +145 -145
- package/lib/save/ViewTreePrinter.d.ts +14 -14
- package/lib/save/ViewTreePrinter.js +123 -123
- package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
- package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
- package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
- package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
- package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
- package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
- package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
- package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
- package/lib/save/base/BasePrinter.d.ts +23 -23
- package/lib/save/base/BasePrinter.js +70 -70
- package/lib/save/base/ExportPrinter.d.ts +8 -8
- package/lib/save/base/ExportPrinter.js +67 -67
- package/lib/save/base/ImportPrinter.d.ts +9 -9
- package/lib/save/base/ImportPrinter.js +92 -92
- package/lib/save/base/PrinterUtils.d.ts +24 -24
- package/lib/save/base/PrinterUtils.js +208 -208
- package/lib/save/serializeArkIR.d.ts +8 -8
- package/lib/save/serializeArkIR.js +294 -294
- package/lib/save/source/SourceBase.d.ts +22 -22
- package/lib/save/source/SourceBase.js +64 -64
- package/lib/save/source/SourceBody.d.ts +58 -58
- package/lib/save/source/SourceBody.js +296 -296
- package/lib/save/source/SourceClass.d.ts +25 -25
- package/lib/save/source/SourceClass.js +187 -187
- package/lib/save/source/SourceField.d.ts +13 -13
- package/lib/save/source/SourceField.js +73 -73
- package/lib/save/source/SourceFilePrinter.d.ts +12 -12
- package/lib/save/source/SourceFilePrinter.js +69 -69
- package/lib/save/source/SourceMethod.d.ts +22 -22
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +196 -193
- package/lib/save/source/SourceNamespace.d.ts +11 -11
- package/lib/save/source/SourceNamespace.js +83 -83
- package/lib/save/source/SourceStmt.d.ts +178 -178
- package/lib/save/source/SourceStmt.js +838 -838
- package/lib/save/source/SourceTransformer.d.ts +46 -46
- package/lib/save/source/SourceTransformer.js +446 -446
- package/lib/transformer/FunctionTransformer.d.ts +2 -2
- package/lib/transformer/FunctionTransformer.js +17 -17
- package/lib/transformer/SceneTransformer.d.ts +2 -2
- package/lib/transformer/SceneTransformer.js +17 -17
- package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
- package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
- package/lib/transformer/Transformer.d.ts +6 -6
- package/lib/transformer/Transformer.js +22 -22
- package/lib/utils/AstTreeUtils.d.ts +4 -4
- package/lib/utils/AstTreeUtils.js +26 -26
- package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
- package/lib/utils/CfgStructualAnalysis.js +1277 -1277
- package/lib/utils/FileUtils.d.ts +18 -18
- package/lib/utils/FileUtils.js +135 -135
- package/lib/utils/SparseBitVector.d.ts +100 -100
- package/lib/utils/SparseBitVector.js +445 -445
- package/lib/utils/callGraphUtils.d.ts +30 -30
- package/lib/utils/callGraphUtils.js +205 -205
- package/lib/utils/crypto_utils.d.ts +5 -5
- package/lib/utils/crypto_utils.js +57 -57
- package/lib/utils/entryMethodUtils.d.ts +13 -13
- package/lib/utils/entryMethodUtils.js +110 -110
- package/lib/utils/getAllFiles.d.ts +9 -9
- package/lib/utils/getAllFiles.js +90 -90
- package/lib/utils/json5parser.d.ts +6 -6
- package/lib/utils/json5parser.js +146 -146
- package/lib/utils/logger.d.ts +18 -18
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +97 -90
- package/lib/utils/pathTransfer.d.ts +1 -1
- package/lib/utils/pathTransfer.js +25 -25
- package/node_modules/json5/lib/cli.js +0 -0
- package/node_modules/ohos-typescript/bin/tsc +0 -0
- package/node_modules/ohos-typescript/bin/tsserver +0 -0
- package/package.json +3 -3
|
@@ -1,838 +1,838 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2024-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
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
-
}
|
|
22
|
-
Object.defineProperty(o, k2, desc);
|
|
23
|
-
}) : (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
}));
|
|
27
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
-
}) : function(o, v) {
|
|
30
|
-
o["default"] = v;
|
|
31
|
-
});
|
|
32
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.stmt2SourceStmt = exports.SourceNewArrayExpr = exports.SourceFinallyStmt = exports.SourceCatchStmt = exports.SourceTryStmt = exports.SourceTypeAliasStmt = exports.SourceThrowStmt = exports.SourceCommonStmt = exports.SourceCompoundEndStmt = exports.SourceReturnVoidStmt = exports.SourceReturnStmt = exports.SourceBreakStmt = exports.SourceContinueStmt = exports.SourceElseStmt = exports.SourceDoWhileStmt = exports.SourceDoStmt = exports.SourceForStmt = exports.SourceWhileStmt = exports.SourceIfStmt = exports.SourceInvokeStmt = exports.SourceAssignStmt = exports.SourceStmt = void 0;
|
|
41
|
-
const Constant_1 = require("../../core/base/Constant");
|
|
42
|
-
const Expr_1 = require("../../core/base/Expr");
|
|
43
|
-
const Local_1 = require("../../core/base/Local");
|
|
44
|
-
const Ref_1 = require("../../core/base/Ref");
|
|
45
|
-
const Stmt_1 = require("../../core/base/Stmt");
|
|
46
|
-
const Type_1 = require("../../core/base/Type");
|
|
47
|
-
const logger_1 = __importStar(require("../../utils/logger"));
|
|
48
|
-
const SourceBody_1 = require("./SourceBody");
|
|
49
|
-
const SourceTransformer_1 = require("./SourceTransformer");
|
|
50
|
-
const PrinterUtils_1 = require("../base/PrinterUtils");
|
|
51
|
-
const ValueUtil_1 = require("../../core/common/ValueUtil");
|
|
52
|
-
const ArkClass_1 = require("../../core/model/ArkClass");
|
|
53
|
-
const ArkBaseModel_1 = require("../../core/model/ArkBaseModel");
|
|
54
|
-
const ArkMetadata_1 = require("../../core/model/ArkMetadata");
|
|
55
|
-
const ArkImport_1 = require("../../core/model/ArkImport");
|
|
56
|
-
const ArkMethod_1 = require("../../core/model/ArkMethod");
|
|
57
|
-
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SourceStmt');
|
|
58
|
-
const IGNOR_TYPES = new Set(['any', 'Map', 'Set']);
|
|
59
|
-
class SourceStmt {
|
|
60
|
-
constructor(context, original) {
|
|
61
|
-
this.text = '';
|
|
62
|
-
this.original = original;
|
|
63
|
-
this.context = context;
|
|
64
|
-
this.line = original.getOriginPositionInfo().getLineNo();
|
|
65
|
-
this.transformer = new SourceTransformer_1.SourceTransformer(context);
|
|
66
|
-
}
|
|
67
|
-
getLine() {
|
|
68
|
-
return this.line;
|
|
69
|
-
}
|
|
70
|
-
setLine(line) {
|
|
71
|
-
this.line = line;
|
|
72
|
-
}
|
|
73
|
-
dump() {
|
|
74
|
-
this.beforeDump();
|
|
75
|
-
let code = this.dumpTs();
|
|
76
|
-
this.afterDump();
|
|
77
|
-
return code;
|
|
78
|
-
}
|
|
79
|
-
beforeDump() { }
|
|
80
|
-
afterDump() { }
|
|
81
|
-
dumpTs() {
|
|
82
|
-
let content = [];
|
|
83
|
-
const commentsMetadata = this.original.getMetadata(ArkMetadata_1.ArkMetadataKind.LEADING_COMMENTS);
|
|
84
|
-
if (commentsMetadata instanceof ArkMetadata_1.CommentsMetadata) {
|
|
85
|
-
const comments = commentsMetadata.getComments();
|
|
86
|
-
comments.forEach((comment) => {
|
|
87
|
-
content.push(`${this.printer.getIndent()}${comment.content}\n`);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (this.text.length > 0) {
|
|
91
|
-
content.push(`${this.printer.getIndent()}${this.text}\n`);
|
|
92
|
-
}
|
|
93
|
-
return content.join('');
|
|
94
|
-
}
|
|
95
|
-
get printer() {
|
|
96
|
-
return this.context.getPrinter();
|
|
97
|
-
}
|
|
98
|
-
toString() {
|
|
99
|
-
return this.text;
|
|
100
|
-
}
|
|
101
|
-
setText(text) {
|
|
102
|
-
this.text = text;
|
|
103
|
-
}
|
|
104
|
-
getIntent() {
|
|
105
|
-
return this.context.getPrinter().getIndent();
|
|
106
|
-
}
|
|
107
|
-
isLocalTempValue(value) {
|
|
108
|
-
if (!(value instanceof Local_1.Local)) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
return PrinterUtils_1.PrinterUtils.isTemp(value.getName());
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.SourceStmt = SourceStmt;
|
|
115
|
-
var AssignStmtDumpType;
|
|
116
|
-
(function (AssignStmtDumpType) {
|
|
117
|
-
AssignStmtDumpType[AssignStmtDumpType["NORMAL"] = 0] = "NORMAL";
|
|
118
|
-
AssignStmtDumpType[AssignStmtDumpType["TEMP_REPLACE"] = 1] = "TEMP_REPLACE";
|
|
119
|
-
AssignStmtDumpType[AssignStmtDumpType["COMPONENT_CREATE"] = 2] = "COMPONENT_CREATE";
|
|
120
|
-
})(AssignStmtDumpType || (AssignStmtDumpType = {}));
|
|
121
|
-
class SourceAssignStmt extends SourceStmt {
|
|
122
|
-
constructor(context, original) {
|
|
123
|
-
super(context, original);
|
|
124
|
-
this.leftOp = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
125
|
-
this.rightOp = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
126
|
-
this.leftCode = '';
|
|
127
|
-
this.rightCode = '';
|
|
128
|
-
this.leftTypeCode = '';
|
|
129
|
-
}
|
|
130
|
-
transfer2ts() {
|
|
131
|
-
this.leftOp = this.original.getLeftOp();
|
|
132
|
-
this.rightOp = this.original.getRightOp();
|
|
133
|
-
if ((this.leftOp instanceof Local_1.Local && this.leftOp.getName() === 'this') ||
|
|
134
|
-
(this.rightOp instanceof Constant_1.Constant && this.rightOp.getValue() === 'undefined') ||
|
|
135
|
-
this.rightOp instanceof Ref_1.ArkParameterRef) {
|
|
136
|
-
this.setText('');
|
|
137
|
-
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.leftCode = this.transformer.valueToString(this.leftOp);
|
|
141
|
-
if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewExpr) {
|
|
142
|
-
this.transferRightNewExpr();
|
|
143
|
-
}
|
|
144
|
-
else if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewArrayExpr) {
|
|
145
|
-
this.transferRightNewArrayExpr();
|
|
146
|
-
}
|
|
147
|
-
else if (this.rightOp instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentCreate(this.rightOp)) {
|
|
148
|
-
this.transferRightComponentCreate();
|
|
149
|
-
}
|
|
150
|
-
else if (this.rightOp instanceof Expr_1.ArkInstanceInvokeExpr &&
|
|
151
|
-
PrinterUtils_1.PrinterUtils.isComponentAttributeInvoke(this.rightOp)) {
|
|
152
|
-
this.transferRightComponentAttribute();
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
156
|
-
}
|
|
157
|
-
if (this.isLocalTempValue(this.leftOp)) {
|
|
158
|
-
this.context.setTempCode(this.leftOp.getName(), this.rightCode);
|
|
159
|
-
}
|
|
160
|
-
if ((this.leftOp instanceof Ref_1.ArkInstanceFieldRef && this.leftOp.getBase().getName() === 'this') ||
|
|
161
|
-
this.leftOp instanceof Ref_1.ArkStaticFieldRef) {
|
|
162
|
-
this.context.setTempCode(this.leftOp.getFieldName(), this.rightCode);
|
|
163
|
-
}
|
|
164
|
-
if (this.dumpType === undefined) {
|
|
165
|
-
this.setText(`${this.leftCode} = ${this.rightCode}`);
|
|
166
|
-
this.dumpType = AssignStmtDumpType.TEMP_REPLACE;
|
|
167
|
-
}
|
|
168
|
-
let leftOpType = this.leftOp.getType();
|
|
169
|
-
if (leftOpType instanceof Type_1.ClassType) {
|
|
170
|
-
let name = leftOpType.getClassSignature().getClassName();
|
|
171
|
-
if (PrinterUtils_1.PrinterUtils.isAnonymousClass(name)) {
|
|
172
|
-
this.leftTypeCode = 'any';
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
this.leftTypeCode = name;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.leftTypeCode = this.transformer.typeToString(leftOpType);
|
|
180
|
-
}
|
|
181
|
-
if (IGNOR_TYPES.has(this.leftTypeCode)) {
|
|
182
|
-
this.leftTypeCode = '';
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
beforeDump() {
|
|
186
|
-
if (this.dumpType !== AssignStmtDumpType.TEMP_REPLACE) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (this.context.hasTempVisit(this.leftCode)) {
|
|
190
|
-
this.setText('');
|
|
191
|
-
}
|
|
192
|
-
else if (PrinterUtils_1.PrinterUtils.isTemp(this.leftCode)) {
|
|
193
|
-
this.setText(`${this.rightCode};`);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
if (this.leftOp instanceof Local_1.Local &&
|
|
197
|
-
this.context.getLocals().has(this.leftOp.getName()) &&
|
|
198
|
-
!this.isLocalTempValue(this.leftOp)) {
|
|
199
|
-
if (this.context.isLocalDefined(this.leftOp)) {
|
|
200
|
-
this.setText(`${this.leftCode} = ${this.rightCode};`);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
let flag = this.leftOp.getConstFlag() ? 'const' : 'let';
|
|
204
|
-
if (this.context.getArkFile().getExportInfoBy(this.leftCode) && this.context.isInDefaultMethod()) {
|
|
205
|
-
this.setText(`export ${flag} ${this.leftCode} = ${this.rightCode};`);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
if (this.leftTypeCode.length > 0) {
|
|
209
|
-
this.setText(`${flag} ${this.leftCode}: ${this.leftTypeCode} = ${this.rightCode};`);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
this.setText(`${flag} ${this.leftCode} = ${this.rightCode};`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
this.context.defineLocal(this.leftOp);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
this.setText(`${this.leftCode} = ${this.rightCode};`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
afterDump() {
|
|
224
|
-
if (this.dumpType === AssignStmtDumpType.COMPONENT_CREATE) {
|
|
225
|
-
this.printer.incIndent();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
getClassOriginType(type) {
|
|
229
|
-
if (!(type instanceof Type_1.ClassType)) {
|
|
230
|
-
return undefined;
|
|
231
|
-
}
|
|
232
|
-
let signature = type.getClassSignature();
|
|
233
|
-
let cls = this.context.getClass(signature);
|
|
234
|
-
if (!cls) {
|
|
235
|
-
return undefined;
|
|
236
|
-
}
|
|
237
|
-
return PrinterUtils_1.PrinterUtils.getOriginType(cls);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* temp1 = new Person
|
|
241
|
-
* temp1.constructor(10)
|
|
242
|
-
*/
|
|
243
|
-
transferRightNewExpr() {
|
|
244
|
-
let originType = this.getClassOriginType(this.rightOp.getType());
|
|
245
|
-
if (this.context.getStmtReader().hasNext()) {
|
|
246
|
-
let stmt = this.context.getStmtReader().next();
|
|
247
|
-
let rollback = true;
|
|
248
|
-
if (stmt instanceof Stmt_1.ArkInvokeStmt && stmt.getInvokeExpr()) {
|
|
249
|
-
let instanceInvokeExpr = stmt.getInvokeExpr();
|
|
250
|
-
if ('constructor' === instanceInvokeExpr.getMethodSignature().getMethodSubSignature().getMethodName() &&
|
|
251
|
-
instanceInvokeExpr.getBase().getName() === this.leftOp.getName()) {
|
|
252
|
-
let args = [];
|
|
253
|
-
instanceInvokeExpr.getArgs().forEach((v) => {
|
|
254
|
-
args.push(this.transformer.valueToString(v));
|
|
255
|
-
});
|
|
256
|
-
if (originType === PrinterUtils_1.CLASS_CATEGORY_COMPONENT) {
|
|
257
|
-
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
|
|
258
|
-
}
|
|
259
|
-
else if (originType === ArkClass_1.ClassCategory.TYPE_LITERAL || originType === ArkClass_1.ClassCategory.OBJECT) {
|
|
260
|
-
this.rightCode = `${this.transformer.literalObjectToString(this.rightOp.getType())}`;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (rollback) {
|
|
269
|
-
this.context.getStmtReader().rollback();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (originType === PrinterUtils_1.CLASS_CATEGORY_COMPONENT) {
|
|
273
|
-
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}()`;
|
|
274
|
-
}
|
|
275
|
-
else if (originType === ArkClass_1.ClassCategory.TYPE_LITERAL || originType === ArkClass_1.ClassCategory.OBJECT) {
|
|
276
|
-
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}`;
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}()`;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* $temp0 = newarray[4]
|
|
284
|
-
* $temp0[0] = 1
|
|
285
|
-
* $temp0[1] = 2
|
|
286
|
-
* $temp0[2] = 3
|
|
287
|
-
*/
|
|
288
|
-
transferRightNewArrayExpr() {
|
|
289
|
-
let arrayExpr = new SourceNewArrayExpr(this.rightOp);
|
|
290
|
-
let localName = this.leftOp.getName();
|
|
291
|
-
while (this.context.getStmtReader().hasNext()) {
|
|
292
|
-
let stmt = this.context.getStmtReader().next();
|
|
293
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
294
|
-
let left = stmt.getLeftOp();
|
|
295
|
-
if (left instanceof Ref_1.ArkArrayRef && left.getBase().getName() === localName) {
|
|
296
|
-
arrayExpr.addInitValue(this.transformer.valueToString(stmt.getRightOp()));
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
this.context.getStmtReader().rollback();
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this.context.getStmtReader().rollback();
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
this.rightCode = arrayExpr.toString();
|
|
309
|
-
}
|
|
310
|
-
transferRightComponentCreate() {
|
|
311
|
-
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
312
|
-
if (this.context.getStmtReader().hasNext()) {
|
|
313
|
-
let stmt = this.context.getStmtReader().next();
|
|
314
|
-
if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
315
|
-
let expr = stmt.getInvokeExpr();
|
|
316
|
-
if (expr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentPop(expr)) {
|
|
317
|
-
this.setText(`${this.rightCode}`);
|
|
318
|
-
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
this.context.getStmtReader().rollback();
|
|
323
|
-
}
|
|
324
|
-
this.setText(`${this.rightCode} {`);
|
|
325
|
-
this.dumpType = AssignStmtDumpType.COMPONENT_CREATE;
|
|
326
|
-
}
|
|
327
|
-
transferRightComponentAttribute() {
|
|
328
|
-
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
329
|
-
this.setText(`${this.rightCode}`);
|
|
330
|
-
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.SourceAssignStmt = SourceAssignStmt;
|
|
334
|
-
class SourceInvokeStmt extends SourceStmt {
|
|
335
|
-
constructor(context, original) {
|
|
336
|
-
super(context, original);
|
|
337
|
-
}
|
|
338
|
-
transfer2ts() {
|
|
339
|
-
let invokeExpr = this.original.getInvokeExpr();
|
|
340
|
-
let code = '';
|
|
341
|
-
let isAttr = false;
|
|
342
|
-
if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
343
|
-
if (PrinterUtils_1.PrinterUtils.isComponentPop(invokeExpr)) {
|
|
344
|
-
code = '}';
|
|
345
|
-
isAttr = true;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
code = this.transformer.staticInvokeExprToString(invokeExpr);
|
|
349
|
-
isAttr = PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
else if (invokeExpr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
353
|
-
code = this.transformer.instanceInvokeExprToString(invokeExpr);
|
|
354
|
-
isAttr = PrinterUtils_1.PrinterUtils.isComponentAttributeInvoke(invokeExpr);
|
|
355
|
-
}
|
|
356
|
-
if (code.length > 0 && !isAttr) {
|
|
357
|
-
this.setText(`${code};`);
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
this.setText(`${code}`);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
beforeDump() {
|
|
364
|
-
let invokeExpr = this.original.getInvokeExpr();
|
|
365
|
-
if ((invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentPop(invokeExpr)) ||
|
|
366
|
-
(invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr))) {
|
|
367
|
-
this.printer.decIndent();
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
afterDump() {
|
|
372
|
-
let invokeExpr = this.original.getInvokeExpr();
|
|
373
|
-
if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr)) {
|
|
374
|
-
this.printer.incIndent();
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
exports.SourceInvokeStmt = SourceInvokeStmt;
|
|
380
|
-
class SourceIfStmt extends SourceStmt {
|
|
381
|
-
constructor(context, original) {
|
|
382
|
-
super(context, original);
|
|
383
|
-
}
|
|
384
|
-
transfer2ts() {
|
|
385
|
-
let code;
|
|
386
|
-
let expr = this.original.getConditionExpr();
|
|
387
|
-
code = `if (${this.transformer.valueToString(expr.getOp1())}`;
|
|
388
|
-
code += ` ${expr.getOperator()} `;
|
|
389
|
-
code += `${this.transformer.valueToString(expr.getOp2())}) {`;
|
|
390
|
-
this.setText(code);
|
|
391
|
-
}
|
|
392
|
-
afterDump() {
|
|
393
|
-
this.printer.incIndent();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
exports.SourceIfStmt = SourceIfStmt;
|
|
397
|
-
class SourceWhileStmt extends SourceStmt {
|
|
398
|
-
constructor(context, original, block) {
|
|
399
|
-
super(context, original);
|
|
400
|
-
this.block = block;
|
|
401
|
-
}
|
|
402
|
-
afterDump() {
|
|
403
|
-
this.printer.incIndent();
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* $temp2 = $temp1.next()
|
|
407
|
-
* $temp3 = $temp2.done()
|
|
408
|
-
* if $temp3 === true
|
|
409
|
-
* $temp4 = $temp2.value
|
|
410
|
-
* $temp5 = <> cast
|
|
411
|
-
* @returns
|
|
412
|
-
*/
|
|
413
|
-
forOf2ts() {
|
|
414
|
-
let expr = this.original.getConditionExpr();
|
|
415
|
-
let temp3 = expr.getOp1();
|
|
416
|
-
let op2 = expr.getOp2();
|
|
417
|
-
let firstStmt = this.context.getStmtReader().first();
|
|
418
|
-
if (!(firstStmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
if (!(this.isLocalTempValue(temp3) && op2 instanceof Constant_1.Constant && op2.getValue() === 'true')) {
|
|
422
|
-
return false;
|
|
423
|
-
}
|
|
424
|
-
let stmt = temp3.getDeclaringStmt();
|
|
425
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
let done = stmt.getRightOp();
|
|
429
|
-
if (!(done instanceof Ref_1.ArkInstanceFieldRef)) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
if (done.getFieldSignature().toString() !== '@ES2015/BuiltinClass: IteratorResult.done') {
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
let temp2 = done.getBase();
|
|
436
|
-
if (!(temp2 instanceof Local_1.Local)) {
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
stmt = temp2.getDeclaringStmt();
|
|
440
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
let next = stmt.getRightOp();
|
|
444
|
-
if (!(next instanceof Expr_1.ArkInstanceInvokeExpr)) {
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
if (next.getMethodSignature().getMethodSubSignature().getMethodName() !== 'next') {
|
|
448
|
-
return false;
|
|
449
|
-
}
|
|
450
|
-
let temp1 = next.getBase();
|
|
451
|
-
if (!(temp1 instanceof Local_1.Local)) {
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
454
|
-
stmt = temp1.getDeclaringStmt();
|
|
455
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
456
|
-
return false;
|
|
457
|
-
}
|
|
458
|
-
let iterator = stmt.getRightOp();
|
|
459
|
-
if (!(iterator instanceof Expr_1.ArkInstanceInvokeExpr)) {
|
|
460
|
-
return false;
|
|
461
|
-
}
|
|
462
|
-
if (iterator.getMethodSignature().getMethodSubSignature().getMethodName() !== 'iterator') {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
let successors = this.block.getSuccessors();
|
|
466
|
-
if (successors.length !== 2) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
let stmts = successors[0].getStmts();
|
|
470
|
-
if (stmts.length < 2) {
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
stmt = stmts[1];
|
|
474
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
this.context.setSkipStmt(stmts[0]);
|
|
478
|
-
this.context.setSkipStmt(stmts[1]);
|
|
479
|
-
while (this.context.getStmtReader().hasNext()) {
|
|
480
|
-
this.context.getStmtReader().next();
|
|
481
|
-
}
|
|
482
|
-
let v = stmt.getLeftOp();
|
|
483
|
-
let valueName = v.getName();
|
|
484
|
-
if (!this.isLocalTempValue(v)) {
|
|
485
|
-
this.setText(`for (let ${valueName} of ${this.transformer.valueToString(iterator.getBase())}) {`);
|
|
486
|
-
this.context.setTempVisit(temp1.getName());
|
|
487
|
-
this.context.setTempVisit(temp3.getName());
|
|
488
|
-
return true;
|
|
489
|
-
}
|
|
490
|
-
// iterate map 'for (let [key, value] of map)'
|
|
491
|
-
let stmtReader = new SourceBody_1.StmtReader(stmts);
|
|
492
|
-
stmtReader.next();
|
|
493
|
-
stmtReader.next();
|
|
494
|
-
let arrayValueNames = [];
|
|
495
|
-
while (stmtReader.hasNext()) {
|
|
496
|
-
stmt = stmtReader.next();
|
|
497
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
let ref = stmt.getRightOp();
|
|
501
|
-
if (!(ref instanceof Ref_1.ArkArrayRef)) {
|
|
502
|
-
break;
|
|
503
|
-
}
|
|
504
|
-
if (ref.getBase().getName() !== valueName) {
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
let name = stmt.getLeftOp().getName();
|
|
508
|
-
arrayValueNames.push(name);
|
|
509
|
-
this.context.setTempVisit(name);
|
|
510
|
-
}
|
|
511
|
-
this.setText(`for (let [${arrayValueNames.join(', ')}] of ${this.transformer.valueToString(iterator.getBase())}) {`);
|
|
512
|
-
this.context.setTempVisit(temp3.getName());
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
transfer2ts() {
|
|
516
|
-
if (this.forOf2ts()) {
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
let code;
|
|
520
|
-
let expr = this.original.getConditionExpr();
|
|
521
|
-
code = `while (${this.valueToString(expr.getOp1())}`;
|
|
522
|
-
code += ` ${expr.getOperator().trim()} `;
|
|
523
|
-
code += `${this.valueToString(expr.getOp2())}) {`;
|
|
524
|
-
this.setText(code);
|
|
525
|
-
}
|
|
526
|
-
valueToString(value) {
|
|
527
|
-
if (!(value instanceof Local_1.Local)) {
|
|
528
|
-
return this.transformer.valueToString(value);
|
|
529
|
-
}
|
|
530
|
-
for (const stmt of this.block.getStmts()) {
|
|
531
|
-
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
532
|
-
continue;
|
|
533
|
-
}
|
|
534
|
-
if (PrinterUtils_1.PrinterUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Addition) &&
|
|
535
|
-
stmt.getLeftOp().getName() === value.getName()) {
|
|
536
|
-
this.context.setSkipStmt(stmt);
|
|
537
|
-
return `${value.getName()}++`;
|
|
538
|
-
}
|
|
539
|
-
if (PrinterUtils_1.PrinterUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Subtraction) &&
|
|
540
|
-
stmt.getLeftOp().getName() === value.getName()) {
|
|
541
|
-
this.context.setSkipStmt(stmt);
|
|
542
|
-
return `${value.getName()}--`;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
return this.transformer.valueToString(value);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
exports.SourceWhileStmt = SourceWhileStmt;
|
|
549
|
-
class SourceForStmt extends SourceWhileStmt {
|
|
550
|
-
constructor(context, original, block, incBlock) {
|
|
551
|
-
super(context, original, block);
|
|
552
|
-
this.incBlock = incBlock;
|
|
553
|
-
}
|
|
554
|
-
transfer2ts() {
|
|
555
|
-
let code;
|
|
556
|
-
let expr = this.original.getConditionExpr();
|
|
557
|
-
code = `for (; ${this.transformer.valueToString(expr.getOp1())}`;
|
|
558
|
-
code += ` ${expr.getOperator().trim()} `;
|
|
559
|
-
code += `${this.transformer.valueToString(expr.getOp2())}; `;
|
|
560
|
-
let stmtReader = new SourceBody_1.StmtReader(this.incBlock.getStmts());
|
|
561
|
-
while (stmtReader.hasNext()) {
|
|
562
|
-
let sourceStmt = stmt2SourceStmt(this.context, stmtReader.next());
|
|
563
|
-
sourceStmt.transfer2ts();
|
|
564
|
-
code += sourceStmt.toString();
|
|
565
|
-
if (stmtReader.hasNext()) {
|
|
566
|
-
code += ', ';
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
code += `) {`;
|
|
570
|
-
this.setText(code);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
exports.SourceForStmt = SourceForStmt;
|
|
574
|
-
class SourceDoStmt extends SourceStmt {
|
|
575
|
-
constructor(context, stmt) {
|
|
576
|
-
super(context, stmt);
|
|
577
|
-
}
|
|
578
|
-
transfer2ts() {
|
|
579
|
-
this.setText('do {');
|
|
580
|
-
}
|
|
581
|
-
afterDump() {
|
|
582
|
-
this.printer.incIndent();
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
exports.SourceDoStmt = SourceDoStmt;
|
|
586
|
-
class SourceDoWhileStmt extends SourceWhileStmt {
|
|
587
|
-
constructor(context, stmt, block) {
|
|
588
|
-
super(context, stmt, block);
|
|
589
|
-
}
|
|
590
|
-
transfer2ts() {
|
|
591
|
-
let code;
|
|
592
|
-
let expr = this.original.getConditionExpr();
|
|
593
|
-
code = `} while (${this.valueToString(expr.getOp1())}`;
|
|
594
|
-
code += ` ${expr.getOperator().trim()} `;
|
|
595
|
-
code += `${this.valueToString(expr.getOp2())})`;
|
|
596
|
-
this.setText(code);
|
|
597
|
-
}
|
|
598
|
-
beforeDump() {
|
|
599
|
-
this.printer.decIndent();
|
|
600
|
-
}
|
|
601
|
-
afterDump() { }
|
|
602
|
-
}
|
|
603
|
-
exports.SourceDoWhileStmt = SourceDoWhileStmt;
|
|
604
|
-
class SourceElseStmt extends SourceStmt {
|
|
605
|
-
constructor(context, original) {
|
|
606
|
-
super(context, original);
|
|
607
|
-
}
|
|
608
|
-
transfer2ts() {
|
|
609
|
-
this.setText('} else {');
|
|
610
|
-
}
|
|
611
|
-
beforeDump() {
|
|
612
|
-
this.printer.decIndent();
|
|
613
|
-
}
|
|
614
|
-
afterDump() {
|
|
615
|
-
this.printer.incIndent();
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
exports.SourceElseStmt = SourceElseStmt;
|
|
619
|
-
class SourceContinueStmt extends SourceStmt {
|
|
620
|
-
constructor(context, original) {
|
|
621
|
-
super(context, original);
|
|
622
|
-
}
|
|
623
|
-
// trans 2 break or continue
|
|
624
|
-
transfer2ts() {
|
|
625
|
-
this.setText('continue;');
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
exports.SourceContinueStmt = SourceContinueStmt;
|
|
629
|
-
class SourceBreakStmt extends SourceStmt {
|
|
630
|
-
constructor(context, original) {
|
|
631
|
-
super(context, original);
|
|
632
|
-
}
|
|
633
|
-
// trans 2 break or continue
|
|
634
|
-
transfer2ts() {
|
|
635
|
-
this.setText('break;');
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
exports.SourceBreakStmt = SourceBreakStmt;
|
|
639
|
-
class SourceReturnStmt extends SourceStmt {
|
|
640
|
-
constructor(context, original) {
|
|
641
|
-
super(context, original);
|
|
642
|
-
}
|
|
643
|
-
transfer2ts() {
|
|
644
|
-
this.setText(`return ${this.transformer.valueToString(this.original.getOp())};`);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
exports.SourceReturnStmt = SourceReturnStmt;
|
|
648
|
-
class SourceReturnVoidStmt extends SourceStmt {
|
|
649
|
-
constructor(context, original) {
|
|
650
|
-
super(context, original);
|
|
651
|
-
}
|
|
652
|
-
transfer2ts() {
|
|
653
|
-
if (this.original.getOriginPositionInfo().getLineNo() <= 0) {
|
|
654
|
-
this.setText('');
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
this.setText('return;');
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
exports.SourceReturnVoidStmt = SourceReturnVoidStmt;
|
|
662
|
-
class SourceCompoundEndStmt extends SourceStmt {
|
|
663
|
-
constructor(context, stmt, text) {
|
|
664
|
-
super(context, stmt);
|
|
665
|
-
this.setText(text);
|
|
666
|
-
}
|
|
667
|
-
transfer2ts() { }
|
|
668
|
-
beforeDump() {
|
|
669
|
-
this.printer.decIndent();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
exports.SourceCompoundEndStmt = SourceCompoundEndStmt;
|
|
673
|
-
class SourceCommonStmt extends SourceStmt {
|
|
674
|
-
constructor(context, stmt) {
|
|
675
|
-
super(context, stmt);
|
|
676
|
-
}
|
|
677
|
-
transfer2ts() {
|
|
678
|
-
this.setText(this.original.toString());
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
exports.SourceCommonStmt = SourceCommonStmt;
|
|
682
|
-
class SourceThrowStmt extends SourceStmt {
|
|
683
|
-
constructor(context, original) {
|
|
684
|
-
super(context, original);
|
|
685
|
-
}
|
|
686
|
-
transfer2ts() {
|
|
687
|
-
this.setText(`throw ${this.transformer.valueToString(this.original.getOp())};`);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
exports.SourceThrowStmt = SourceThrowStmt;
|
|
691
|
-
class SourceTypeAliasStmt extends SourceStmt {
|
|
692
|
-
constructor(context, original, aliasType) {
|
|
693
|
-
super(context, original);
|
|
694
|
-
this.aliasType = aliasType;
|
|
695
|
-
}
|
|
696
|
-
transfer2ts() {
|
|
697
|
-
let modifiersArray = (0, ArkBaseModel_1.modifiers2stringArray)(this.aliasType.getModifiers());
|
|
698
|
-
let modifier = modifiersArray.length > 0 ? `${modifiersArray.join(' ')} ` : '';
|
|
699
|
-
const expr = this.original.getAliasTypeExpr();
|
|
700
|
-
let typeOf = expr.getTransferWithTypeOf() ? 'typeof ' : '';
|
|
701
|
-
let realGenericTypes = expr.getRealGenericTypes() ? `<${expr.getRealGenericTypes().join(', ')}>` : '';
|
|
702
|
-
let genericTypes = this.aliasType.getGenericTypes() ? `<${this.transformer.typeArrayToString(this.aliasType.getGenericTypes())}>` : '';
|
|
703
|
-
let typeObject = expr.getOriginalObject();
|
|
704
|
-
if (typeObject instanceof Type_1.Type) {
|
|
705
|
-
if (typeObject instanceof Type_1.AliasType) {
|
|
706
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
707
|
-
}
|
|
708
|
-
else {
|
|
709
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${this.transformer.typeToString(typeObject)}${realGenericTypes};`);
|
|
710
|
-
}
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (typeObject instanceof ArkImport_1.ImportInfo) {
|
|
714
|
-
let exprStr = `import('${typeObject.getFrom()}')`;
|
|
715
|
-
if (typeObject.getImportClauseName() !== '') {
|
|
716
|
-
exprStr = `${exprStr}.${typeObject.getImportClauseName()}`;
|
|
717
|
-
}
|
|
718
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${exprStr}${realGenericTypes};`);
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
if (typeObject instanceof Local_1.Local) {
|
|
722
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${this.transformer.valueToString(typeObject)}${realGenericTypes};`);
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
if (typeObject instanceof ArkClass_1.ArkClass) {
|
|
726
|
-
let classTS = this.generateClassTS(typeObject);
|
|
727
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${classTS}${realGenericTypes};`);
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
if (typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
731
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
735
|
-
}
|
|
736
|
-
generateClassTS(arkClass) {
|
|
737
|
-
let res = '';
|
|
738
|
-
let classType = new Type_1.ClassType(arkClass.getSignature());
|
|
739
|
-
if (arkClass.getCategory() === ArkClass_1.ClassCategory.TYPE_LITERAL || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
|
|
740
|
-
res = this.transformer.literalObjectToString(classType);
|
|
741
|
-
}
|
|
742
|
-
else {
|
|
743
|
-
res = this.transformer.typeToString(classType);
|
|
744
|
-
}
|
|
745
|
-
return res;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
exports.SourceTypeAliasStmt = SourceTypeAliasStmt;
|
|
749
|
-
class SourceTryStmt extends SourceStmt {
|
|
750
|
-
constructor(context, stmt) {
|
|
751
|
-
super(context, stmt);
|
|
752
|
-
}
|
|
753
|
-
transfer2ts() {
|
|
754
|
-
this.setText('try {');
|
|
755
|
-
}
|
|
756
|
-
afterDump() {
|
|
757
|
-
this.printer.incIndent();
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
exports.SourceTryStmt = SourceTryStmt;
|
|
761
|
-
class SourceCatchStmt extends SourceStmt {
|
|
762
|
-
constructor(context, stmt, block) {
|
|
763
|
-
super(context, stmt);
|
|
764
|
-
this.block = block;
|
|
765
|
-
}
|
|
766
|
-
transfer2ts() {
|
|
767
|
-
if (this.block) {
|
|
768
|
-
let stmt = this.block.getStmts()[0];
|
|
769
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
770
|
-
if (stmt.getLeftOp() instanceof Local_1.Local) {
|
|
771
|
-
let name = stmt.getLeftOp().getName();
|
|
772
|
-
this.setText(`} catch (${name}) {`);
|
|
773
|
-
this.context.setSkipStmt(stmt);
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
this.setText('} catch (e) {');
|
|
779
|
-
}
|
|
780
|
-
beforeDump() {
|
|
781
|
-
this.printer.decIndent();
|
|
782
|
-
}
|
|
783
|
-
afterDump() {
|
|
784
|
-
this.printer.incIndent();
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
exports.SourceCatchStmt = SourceCatchStmt;
|
|
788
|
-
class SourceFinallyStmt extends SourceStmt {
|
|
789
|
-
constructor(context, stmt) {
|
|
790
|
-
super(context, stmt);
|
|
791
|
-
}
|
|
792
|
-
transfer2ts() {
|
|
793
|
-
this.setText('} finally {');
|
|
794
|
-
}
|
|
795
|
-
beforeDump() {
|
|
796
|
-
this.printer.decIndent();
|
|
797
|
-
}
|
|
798
|
-
afterDump() {
|
|
799
|
-
this.printer.incIndent();
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
exports.SourceFinallyStmt = SourceFinallyStmt;
|
|
803
|
-
class SourceNewArrayExpr {
|
|
804
|
-
constructor(expr) {
|
|
805
|
-
this.expr = expr;
|
|
806
|
-
this.values = [];
|
|
807
|
-
}
|
|
808
|
-
addInitValue(value) {
|
|
809
|
-
this.values.push(value);
|
|
810
|
-
}
|
|
811
|
-
toString() {
|
|
812
|
-
return `[${this.values.join(', ')}]`;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
exports.SourceNewArrayExpr = SourceNewArrayExpr;
|
|
816
|
-
function stmt2SourceStmt(context, stmt) {
|
|
817
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
818
|
-
return new SourceAssignStmt(context, stmt);
|
|
819
|
-
}
|
|
820
|
-
if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
821
|
-
return new SourceInvokeStmt(context, stmt);
|
|
822
|
-
}
|
|
823
|
-
if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
|
|
824
|
-
return new SourceReturnVoidStmt(context, stmt);
|
|
825
|
-
}
|
|
826
|
-
if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
827
|
-
return new SourceReturnStmt(context, stmt);
|
|
828
|
-
}
|
|
829
|
-
if (stmt instanceof Stmt_1.ArkThrowStmt) {
|
|
830
|
-
return new SourceThrowStmt(context, stmt);
|
|
831
|
-
}
|
|
832
|
-
if (stmt instanceof Stmt_1.ArkAliasTypeDefineStmt) {
|
|
833
|
-
return new SourceTypeAliasStmt(context, stmt, stmt.getAliasType());
|
|
834
|
-
}
|
|
835
|
-
logger.info(`stmt2SourceStmt ${stmt.constructor} not support.`);
|
|
836
|
-
return new SourceCommonStmt(context, stmt);
|
|
837
|
-
}
|
|
838
|
-
exports.stmt2SourceStmt = stmt2SourceStmt;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024-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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.stmt2SourceStmt = exports.SourceNewArrayExpr = exports.SourceFinallyStmt = exports.SourceCatchStmt = exports.SourceTryStmt = exports.SourceTypeAliasStmt = exports.SourceThrowStmt = exports.SourceCommonStmt = exports.SourceCompoundEndStmt = exports.SourceReturnVoidStmt = exports.SourceReturnStmt = exports.SourceBreakStmt = exports.SourceContinueStmt = exports.SourceElseStmt = exports.SourceDoWhileStmt = exports.SourceDoStmt = exports.SourceForStmt = exports.SourceWhileStmt = exports.SourceIfStmt = exports.SourceInvokeStmt = exports.SourceAssignStmt = exports.SourceStmt = void 0;
|
|
41
|
+
const Constant_1 = require("../../core/base/Constant");
|
|
42
|
+
const Expr_1 = require("../../core/base/Expr");
|
|
43
|
+
const Local_1 = require("../../core/base/Local");
|
|
44
|
+
const Ref_1 = require("../../core/base/Ref");
|
|
45
|
+
const Stmt_1 = require("../../core/base/Stmt");
|
|
46
|
+
const Type_1 = require("../../core/base/Type");
|
|
47
|
+
const logger_1 = __importStar(require("../../utils/logger"));
|
|
48
|
+
const SourceBody_1 = require("./SourceBody");
|
|
49
|
+
const SourceTransformer_1 = require("./SourceTransformer");
|
|
50
|
+
const PrinterUtils_1 = require("../base/PrinterUtils");
|
|
51
|
+
const ValueUtil_1 = require("../../core/common/ValueUtil");
|
|
52
|
+
const ArkClass_1 = require("../../core/model/ArkClass");
|
|
53
|
+
const ArkBaseModel_1 = require("../../core/model/ArkBaseModel");
|
|
54
|
+
const ArkMetadata_1 = require("../../core/model/ArkMetadata");
|
|
55
|
+
const ArkImport_1 = require("../../core/model/ArkImport");
|
|
56
|
+
const ArkMethod_1 = require("../../core/model/ArkMethod");
|
|
57
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SourceStmt');
|
|
58
|
+
const IGNOR_TYPES = new Set(['any', 'Map', 'Set']);
|
|
59
|
+
class SourceStmt {
|
|
60
|
+
constructor(context, original) {
|
|
61
|
+
this.text = '';
|
|
62
|
+
this.original = original;
|
|
63
|
+
this.context = context;
|
|
64
|
+
this.line = original.getOriginPositionInfo().getLineNo();
|
|
65
|
+
this.transformer = new SourceTransformer_1.SourceTransformer(context);
|
|
66
|
+
}
|
|
67
|
+
getLine() {
|
|
68
|
+
return this.line;
|
|
69
|
+
}
|
|
70
|
+
setLine(line) {
|
|
71
|
+
this.line = line;
|
|
72
|
+
}
|
|
73
|
+
dump() {
|
|
74
|
+
this.beforeDump();
|
|
75
|
+
let code = this.dumpTs();
|
|
76
|
+
this.afterDump();
|
|
77
|
+
return code;
|
|
78
|
+
}
|
|
79
|
+
beforeDump() { }
|
|
80
|
+
afterDump() { }
|
|
81
|
+
dumpTs() {
|
|
82
|
+
let content = [];
|
|
83
|
+
const commentsMetadata = this.original.getMetadata(ArkMetadata_1.ArkMetadataKind.LEADING_COMMENTS);
|
|
84
|
+
if (commentsMetadata instanceof ArkMetadata_1.CommentsMetadata) {
|
|
85
|
+
const comments = commentsMetadata.getComments();
|
|
86
|
+
comments.forEach((comment) => {
|
|
87
|
+
content.push(`${this.printer.getIndent()}${comment.content}\n`);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (this.text.length > 0) {
|
|
91
|
+
content.push(`${this.printer.getIndent()}${this.text}\n`);
|
|
92
|
+
}
|
|
93
|
+
return content.join('');
|
|
94
|
+
}
|
|
95
|
+
get printer() {
|
|
96
|
+
return this.context.getPrinter();
|
|
97
|
+
}
|
|
98
|
+
toString() {
|
|
99
|
+
return this.text;
|
|
100
|
+
}
|
|
101
|
+
setText(text) {
|
|
102
|
+
this.text = text;
|
|
103
|
+
}
|
|
104
|
+
getIntent() {
|
|
105
|
+
return this.context.getPrinter().getIndent();
|
|
106
|
+
}
|
|
107
|
+
isLocalTempValue(value) {
|
|
108
|
+
if (!(value instanceof Local_1.Local)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return PrinterUtils_1.PrinterUtils.isTemp(value.getName());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.SourceStmt = SourceStmt;
|
|
115
|
+
var AssignStmtDumpType;
|
|
116
|
+
(function (AssignStmtDumpType) {
|
|
117
|
+
AssignStmtDumpType[AssignStmtDumpType["NORMAL"] = 0] = "NORMAL";
|
|
118
|
+
AssignStmtDumpType[AssignStmtDumpType["TEMP_REPLACE"] = 1] = "TEMP_REPLACE";
|
|
119
|
+
AssignStmtDumpType[AssignStmtDumpType["COMPONENT_CREATE"] = 2] = "COMPONENT_CREATE";
|
|
120
|
+
})(AssignStmtDumpType || (AssignStmtDumpType = {}));
|
|
121
|
+
class SourceAssignStmt extends SourceStmt {
|
|
122
|
+
constructor(context, original) {
|
|
123
|
+
super(context, original);
|
|
124
|
+
this.leftOp = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
125
|
+
this.rightOp = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
126
|
+
this.leftCode = '';
|
|
127
|
+
this.rightCode = '';
|
|
128
|
+
this.leftTypeCode = '';
|
|
129
|
+
}
|
|
130
|
+
transfer2ts() {
|
|
131
|
+
this.leftOp = this.original.getLeftOp();
|
|
132
|
+
this.rightOp = this.original.getRightOp();
|
|
133
|
+
if ((this.leftOp instanceof Local_1.Local && this.leftOp.getName() === 'this') ||
|
|
134
|
+
(this.rightOp instanceof Constant_1.Constant && this.rightOp.getValue() === 'undefined') ||
|
|
135
|
+
this.rightOp instanceof Ref_1.ArkParameterRef || this.rightOp instanceof Ref_1.ClosureFieldRef) {
|
|
136
|
+
this.setText('');
|
|
137
|
+
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.leftCode = this.transformer.valueToString(this.leftOp);
|
|
141
|
+
if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewExpr) {
|
|
142
|
+
this.transferRightNewExpr();
|
|
143
|
+
}
|
|
144
|
+
else if (this.leftOp instanceof Local_1.Local && this.rightOp instanceof Expr_1.ArkNewArrayExpr) {
|
|
145
|
+
this.transferRightNewArrayExpr();
|
|
146
|
+
}
|
|
147
|
+
else if (this.rightOp instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentCreate(this.rightOp)) {
|
|
148
|
+
this.transferRightComponentCreate();
|
|
149
|
+
}
|
|
150
|
+
else if (this.rightOp instanceof Expr_1.ArkInstanceInvokeExpr &&
|
|
151
|
+
PrinterUtils_1.PrinterUtils.isComponentAttributeInvoke(this.rightOp)) {
|
|
152
|
+
this.transferRightComponentAttribute();
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
156
|
+
}
|
|
157
|
+
if (this.isLocalTempValue(this.leftOp)) {
|
|
158
|
+
this.context.setTempCode(this.leftOp.getName(), this.rightCode);
|
|
159
|
+
}
|
|
160
|
+
if ((this.leftOp instanceof Ref_1.ArkInstanceFieldRef && this.leftOp.getBase().getName() === 'this') ||
|
|
161
|
+
this.leftOp instanceof Ref_1.ArkStaticFieldRef) {
|
|
162
|
+
this.context.setTempCode(this.leftOp.getFieldName(), this.rightCode);
|
|
163
|
+
}
|
|
164
|
+
if (this.dumpType === undefined) {
|
|
165
|
+
this.setText(`${this.leftCode} = ${this.rightCode}`);
|
|
166
|
+
this.dumpType = AssignStmtDumpType.TEMP_REPLACE;
|
|
167
|
+
}
|
|
168
|
+
let leftOpType = this.leftOp.getType();
|
|
169
|
+
if (leftOpType instanceof Type_1.ClassType) {
|
|
170
|
+
let name = leftOpType.getClassSignature().getClassName();
|
|
171
|
+
if (PrinterUtils_1.PrinterUtils.isAnonymousClass(name)) {
|
|
172
|
+
this.leftTypeCode = 'any';
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
this.leftTypeCode = name;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.leftTypeCode = this.transformer.typeToString(leftOpType);
|
|
180
|
+
}
|
|
181
|
+
if (IGNOR_TYPES.has(this.leftTypeCode)) {
|
|
182
|
+
this.leftTypeCode = '';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
beforeDump() {
|
|
186
|
+
if (this.dumpType !== AssignStmtDumpType.TEMP_REPLACE) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (this.context.hasTempVisit(this.leftCode)) {
|
|
190
|
+
this.setText('');
|
|
191
|
+
}
|
|
192
|
+
else if (PrinterUtils_1.PrinterUtils.isTemp(this.leftCode)) {
|
|
193
|
+
this.setText(`${this.rightCode};`);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
if (this.leftOp instanceof Local_1.Local &&
|
|
197
|
+
this.context.getLocals().has(this.leftOp.getName()) &&
|
|
198
|
+
!this.isLocalTempValue(this.leftOp)) {
|
|
199
|
+
if (this.context.isLocalDefined(this.leftOp)) {
|
|
200
|
+
this.setText(`${this.leftCode} = ${this.rightCode};`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
let flag = this.leftOp.getConstFlag() ? 'const' : 'let';
|
|
204
|
+
if (this.context.getArkFile().getExportInfoBy(this.leftCode) && this.context.isInDefaultMethod()) {
|
|
205
|
+
this.setText(`export ${flag} ${this.leftCode} = ${this.rightCode};`);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (this.leftTypeCode.length > 0) {
|
|
209
|
+
this.setText(`${flag} ${this.leftCode}: ${this.leftTypeCode} = ${this.rightCode};`);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.setText(`${flag} ${this.leftCode} = ${this.rightCode};`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
this.context.defineLocal(this.leftOp);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
this.setText(`${this.leftCode} = ${this.rightCode};`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
afterDump() {
|
|
224
|
+
if (this.dumpType === AssignStmtDumpType.COMPONENT_CREATE) {
|
|
225
|
+
this.printer.incIndent();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
getClassOriginType(type) {
|
|
229
|
+
if (!(type instanceof Type_1.ClassType)) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
let signature = type.getClassSignature();
|
|
233
|
+
let cls = this.context.getClass(signature);
|
|
234
|
+
if (!cls) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
return PrinterUtils_1.PrinterUtils.getOriginType(cls);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* temp1 = new Person
|
|
241
|
+
* temp1.constructor(10)
|
|
242
|
+
*/
|
|
243
|
+
transferRightNewExpr() {
|
|
244
|
+
let originType = this.getClassOriginType(this.rightOp.getType());
|
|
245
|
+
if (this.context.getStmtReader().hasNext()) {
|
|
246
|
+
let stmt = this.context.getStmtReader().next();
|
|
247
|
+
let rollback = true;
|
|
248
|
+
if (stmt instanceof Stmt_1.ArkInvokeStmt && stmt.getInvokeExpr()) {
|
|
249
|
+
let instanceInvokeExpr = stmt.getInvokeExpr();
|
|
250
|
+
if ('constructor' === instanceInvokeExpr.getMethodSignature().getMethodSubSignature().getMethodName() &&
|
|
251
|
+
instanceInvokeExpr.getBase().getName() === this.leftOp.getName()) {
|
|
252
|
+
let args = [];
|
|
253
|
+
instanceInvokeExpr.getArgs().forEach((v) => {
|
|
254
|
+
args.push(this.transformer.valueToString(v));
|
|
255
|
+
});
|
|
256
|
+
if (originType === PrinterUtils_1.CLASS_CATEGORY_COMPONENT) {
|
|
257
|
+
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
|
|
258
|
+
}
|
|
259
|
+
else if (originType === ArkClass_1.ClassCategory.TYPE_LITERAL || originType === ArkClass_1.ClassCategory.OBJECT) {
|
|
260
|
+
this.rightCode = `${this.transformer.literalObjectToString(this.rightOp.getType())}`;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}(${args.join(', ')})`;
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (rollback) {
|
|
269
|
+
this.context.getStmtReader().rollback();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (originType === PrinterUtils_1.CLASS_CATEGORY_COMPONENT) {
|
|
273
|
+
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}()`;
|
|
274
|
+
}
|
|
275
|
+
else if (originType === ArkClass_1.ClassCategory.TYPE_LITERAL || originType === ArkClass_1.ClassCategory.OBJECT) {
|
|
276
|
+
this.rightCode = `${this.transformer.typeToString(this.rightOp.getType())}`;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
this.rightCode = `new ${this.transformer.typeToString(this.rightOp.getType())}()`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* $temp0 = newarray[4]
|
|
284
|
+
* $temp0[0] = 1
|
|
285
|
+
* $temp0[1] = 2
|
|
286
|
+
* $temp0[2] = 3
|
|
287
|
+
*/
|
|
288
|
+
transferRightNewArrayExpr() {
|
|
289
|
+
let arrayExpr = new SourceNewArrayExpr(this.rightOp);
|
|
290
|
+
let localName = this.leftOp.getName();
|
|
291
|
+
while (this.context.getStmtReader().hasNext()) {
|
|
292
|
+
let stmt = this.context.getStmtReader().next();
|
|
293
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
294
|
+
let left = stmt.getLeftOp();
|
|
295
|
+
if (left instanceof Ref_1.ArkArrayRef && left.getBase().getName() === localName) {
|
|
296
|
+
arrayExpr.addInitValue(this.transformer.valueToString(stmt.getRightOp()));
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this.context.getStmtReader().rollback();
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
this.context.getStmtReader().rollback();
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this.rightCode = arrayExpr.toString();
|
|
309
|
+
}
|
|
310
|
+
transferRightComponentCreate() {
|
|
311
|
+
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
312
|
+
if (this.context.getStmtReader().hasNext()) {
|
|
313
|
+
let stmt = this.context.getStmtReader().next();
|
|
314
|
+
if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
315
|
+
let expr = stmt.getInvokeExpr();
|
|
316
|
+
if (expr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentPop(expr)) {
|
|
317
|
+
this.setText(`${this.rightCode}`);
|
|
318
|
+
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
this.context.getStmtReader().rollback();
|
|
323
|
+
}
|
|
324
|
+
this.setText(`${this.rightCode} {`);
|
|
325
|
+
this.dumpType = AssignStmtDumpType.COMPONENT_CREATE;
|
|
326
|
+
}
|
|
327
|
+
transferRightComponentAttribute() {
|
|
328
|
+
this.rightCode = this.transformer.valueToString(this.rightOp);
|
|
329
|
+
this.setText(`${this.rightCode}`);
|
|
330
|
+
this.dumpType = AssignStmtDumpType.NORMAL;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.SourceAssignStmt = SourceAssignStmt;
|
|
334
|
+
class SourceInvokeStmt extends SourceStmt {
|
|
335
|
+
constructor(context, original) {
|
|
336
|
+
super(context, original);
|
|
337
|
+
}
|
|
338
|
+
transfer2ts() {
|
|
339
|
+
let invokeExpr = this.original.getInvokeExpr();
|
|
340
|
+
let code = '';
|
|
341
|
+
let isAttr = false;
|
|
342
|
+
if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
343
|
+
if (PrinterUtils_1.PrinterUtils.isComponentPop(invokeExpr)) {
|
|
344
|
+
code = '}';
|
|
345
|
+
isAttr = true;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
code = this.transformer.staticInvokeExprToString(invokeExpr);
|
|
349
|
+
isAttr = PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else if (invokeExpr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
353
|
+
code = this.transformer.instanceInvokeExprToString(invokeExpr);
|
|
354
|
+
isAttr = PrinterUtils_1.PrinterUtils.isComponentAttributeInvoke(invokeExpr);
|
|
355
|
+
}
|
|
356
|
+
if (code.length > 0 && !isAttr) {
|
|
357
|
+
this.setText(`${code};`);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.setText(`${code}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
beforeDump() {
|
|
364
|
+
let invokeExpr = this.original.getInvokeExpr();
|
|
365
|
+
if ((invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentPop(invokeExpr)) ||
|
|
366
|
+
(invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr))) {
|
|
367
|
+
this.printer.decIndent();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
afterDump() {
|
|
372
|
+
let invokeExpr = this.original.getInvokeExpr();
|
|
373
|
+
if (invokeExpr instanceof Expr_1.ArkStaticInvokeExpr && PrinterUtils_1.PrinterUtils.isComponentIfElseInvoke(invokeExpr)) {
|
|
374
|
+
this.printer.incIndent();
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
exports.SourceInvokeStmt = SourceInvokeStmt;
|
|
380
|
+
class SourceIfStmt extends SourceStmt {
|
|
381
|
+
constructor(context, original) {
|
|
382
|
+
super(context, original);
|
|
383
|
+
}
|
|
384
|
+
transfer2ts() {
|
|
385
|
+
let code;
|
|
386
|
+
let expr = this.original.getConditionExpr();
|
|
387
|
+
code = `if (${this.transformer.valueToString(expr.getOp1())}`;
|
|
388
|
+
code += ` ${expr.getOperator()} `;
|
|
389
|
+
code += `${this.transformer.valueToString(expr.getOp2())}) {`;
|
|
390
|
+
this.setText(code);
|
|
391
|
+
}
|
|
392
|
+
afterDump() {
|
|
393
|
+
this.printer.incIndent();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
exports.SourceIfStmt = SourceIfStmt;
|
|
397
|
+
class SourceWhileStmt extends SourceStmt {
|
|
398
|
+
constructor(context, original, block) {
|
|
399
|
+
super(context, original);
|
|
400
|
+
this.block = block;
|
|
401
|
+
}
|
|
402
|
+
afterDump() {
|
|
403
|
+
this.printer.incIndent();
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* $temp2 = $temp1.next()
|
|
407
|
+
* $temp3 = $temp2.done()
|
|
408
|
+
* if $temp3 === true
|
|
409
|
+
* $temp4 = $temp2.value
|
|
410
|
+
* $temp5 = <> cast
|
|
411
|
+
* @returns
|
|
412
|
+
*/
|
|
413
|
+
forOf2ts() {
|
|
414
|
+
let expr = this.original.getConditionExpr();
|
|
415
|
+
let temp3 = expr.getOp1();
|
|
416
|
+
let op2 = expr.getOp2();
|
|
417
|
+
let firstStmt = this.context.getStmtReader().first();
|
|
418
|
+
if (!(firstStmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
if (!(this.isLocalTempValue(temp3) && op2 instanceof Constant_1.Constant && op2.getValue() === 'true')) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
let stmt = temp3.getDeclaringStmt();
|
|
425
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
let done = stmt.getRightOp();
|
|
429
|
+
if (!(done instanceof Ref_1.ArkInstanceFieldRef)) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
if (done.getFieldSignature().toString() !== '@ES2015/BuiltinClass: IteratorResult.done') {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
let temp2 = done.getBase();
|
|
436
|
+
if (!(temp2 instanceof Local_1.Local)) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
stmt = temp2.getDeclaringStmt();
|
|
440
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
let next = stmt.getRightOp();
|
|
444
|
+
if (!(next instanceof Expr_1.ArkInstanceInvokeExpr)) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
if (next.getMethodSignature().getMethodSubSignature().getMethodName() !== 'next') {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
let temp1 = next.getBase();
|
|
451
|
+
if (!(temp1 instanceof Local_1.Local)) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
stmt = temp1.getDeclaringStmt();
|
|
455
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
let iterator = stmt.getRightOp();
|
|
459
|
+
if (!(iterator instanceof Expr_1.ArkInstanceInvokeExpr)) {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
if (iterator.getMethodSignature().getMethodSubSignature().getMethodName() !== 'iterator') {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
let successors = this.block.getSuccessors();
|
|
466
|
+
if (successors.length !== 2) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
let stmts = successors[0].getStmts();
|
|
470
|
+
if (stmts.length < 2) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
stmt = stmts[1];
|
|
474
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
this.context.setSkipStmt(stmts[0]);
|
|
478
|
+
this.context.setSkipStmt(stmts[1]);
|
|
479
|
+
while (this.context.getStmtReader().hasNext()) {
|
|
480
|
+
this.context.getStmtReader().next();
|
|
481
|
+
}
|
|
482
|
+
let v = stmt.getLeftOp();
|
|
483
|
+
let valueName = v.getName();
|
|
484
|
+
if (!this.isLocalTempValue(v)) {
|
|
485
|
+
this.setText(`for (let ${valueName} of ${this.transformer.valueToString(iterator.getBase())}) {`);
|
|
486
|
+
this.context.setTempVisit(temp1.getName());
|
|
487
|
+
this.context.setTempVisit(temp3.getName());
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
// iterate map 'for (let [key, value] of map)'
|
|
491
|
+
let stmtReader = new SourceBody_1.StmtReader(stmts);
|
|
492
|
+
stmtReader.next();
|
|
493
|
+
stmtReader.next();
|
|
494
|
+
let arrayValueNames = [];
|
|
495
|
+
while (stmtReader.hasNext()) {
|
|
496
|
+
stmt = stmtReader.next();
|
|
497
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
let ref = stmt.getRightOp();
|
|
501
|
+
if (!(ref instanceof Ref_1.ArkArrayRef)) {
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
if (ref.getBase().getName() !== valueName) {
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
let name = stmt.getLeftOp().getName();
|
|
508
|
+
arrayValueNames.push(name);
|
|
509
|
+
this.context.setTempVisit(name);
|
|
510
|
+
}
|
|
511
|
+
this.setText(`for (let [${arrayValueNames.join(', ')}] of ${this.transformer.valueToString(iterator.getBase())}) {`);
|
|
512
|
+
this.context.setTempVisit(temp3.getName());
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
transfer2ts() {
|
|
516
|
+
if (this.forOf2ts()) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
let code;
|
|
520
|
+
let expr = this.original.getConditionExpr();
|
|
521
|
+
code = `while (${this.valueToString(expr.getOp1())}`;
|
|
522
|
+
code += ` ${expr.getOperator().trim()} `;
|
|
523
|
+
code += `${this.valueToString(expr.getOp2())}) {`;
|
|
524
|
+
this.setText(code);
|
|
525
|
+
}
|
|
526
|
+
valueToString(value) {
|
|
527
|
+
if (!(value instanceof Local_1.Local)) {
|
|
528
|
+
return this.transformer.valueToString(value);
|
|
529
|
+
}
|
|
530
|
+
for (const stmt of this.block.getStmts()) {
|
|
531
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
if (PrinterUtils_1.PrinterUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Addition) &&
|
|
535
|
+
stmt.getLeftOp().getName() === value.getName()) {
|
|
536
|
+
this.context.setSkipStmt(stmt);
|
|
537
|
+
return `${value.getName()}++`;
|
|
538
|
+
}
|
|
539
|
+
if (PrinterUtils_1.PrinterUtils.isDeIncrementStmt(stmt, Expr_1.NormalBinaryOperator.Subtraction) &&
|
|
540
|
+
stmt.getLeftOp().getName() === value.getName()) {
|
|
541
|
+
this.context.setSkipStmt(stmt);
|
|
542
|
+
return `${value.getName()}--`;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return this.transformer.valueToString(value);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
exports.SourceWhileStmt = SourceWhileStmt;
|
|
549
|
+
class SourceForStmt extends SourceWhileStmt {
|
|
550
|
+
constructor(context, original, block, incBlock) {
|
|
551
|
+
super(context, original, block);
|
|
552
|
+
this.incBlock = incBlock;
|
|
553
|
+
}
|
|
554
|
+
transfer2ts() {
|
|
555
|
+
let code;
|
|
556
|
+
let expr = this.original.getConditionExpr();
|
|
557
|
+
code = `for (; ${this.transformer.valueToString(expr.getOp1())}`;
|
|
558
|
+
code += ` ${expr.getOperator().trim()} `;
|
|
559
|
+
code += `${this.transformer.valueToString(expr.getOp2())}; `;
|
|
560
|
+
let stmtReader = new SourceBody_1.StmtReader(this.incBlock.getStmts());
|
|
561
|
+
while (stmtReader.hasNext()) {
|
|
562
|
+
let sourceStmt = stmt2SourceStmt(this.context, stmtReader.next());
|
|
563
|
+
sourceStmt.transfer2ts();
|
|
564
|
+
code += sourceStmt.toString();
|
|
565
|
+
if (stmtReader.hasNext()) {
|
|
566
|
+
code += ', ';
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
code += `) {`;
|
|
570
|
+
this.setText(code);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
exports.SourceForStmt = SourceForStmt;
|
|
574
|
+
class SourceDoStmt extends SourceStmt {
|
|
575
|
+
constructor(context, stmt) {
|
|
576
|
+
super(context, stmt);
|
|
577
|
+
}
|
|
578
|
+
transfer2ts() {
|
|
579
|
+
this.setText('do {');
|
|
580
|
+
}
|
|
581
|
+
afterDump() {
|
|
582
|
+
this.printer.incIndent();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
exports.SourceDoStmt = SourceDoStmt;
|
|
586
|
+
class SourceDoWhileStmt extends SourceWhileStmt {
|
|
587
|
+
constructor(context, stmt, block) {
|
|
588
|
+
super(context, stmt, block);
|
|
589
|
+
}
|
|
590
|
+
transfer2ts() {
|
|
591
|
+
let code;
|
|
592
|
+
let expr = this.original.getConditionExpr();
|
|
593
|
+
code = `} while (${this.valueToString(expr.getOp1())}`;
|
|
594
|
+
code += ` ${expr.getOperator().trim()} `;
|
|
595
|
+
code += `${this.valueToString(expr.getOp2())})`;
|
|
596
|
+
this.setText(code);
|
|
597
|
+
}
|
|
598
|
+
beforeDump() {
|
|
599
|
+
this.printer.decIndent();
|
|
600
|
+
}
|
|
601
|
+
afterDump() { }
|
|
602
|
+
}
|
|
603
|
+
exports.SourceDoWhileStmt = SourceDoWhileStmt;
|
|
604
|
+
class SourceElseStmt extends SourceStmt {
|
|
605
|
+
constructor(context, original) {
|
|
606
|
+
super(context, original);
|
|
607
|
+
}
|
|
608
|
+
transfer2ts() {
|
|
609
|
+
this.setText('} else {');
|
|
610
|
+
}
|
|
611
|
+
beforeDump() {
|
|
612
|
+
this.printer.decIndent();
|
|
613
|
+
}
|
|
614
|
+
afterDump() {
|
|
615
|
+
this.printer.incIndent();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
exports.SourceElseStmt = SourceElseStmt;
|
|
619
|
+
class SourceContinueStmt extends SourceStmt {
|
|
620
|
+
constructor(context, original) {
|
|
621
|
+
super(context, original);
|
|
622
|
+
}
|
|
623
|
+
// trans 2 break or continue
|
|
624
|
+
transfer2ts() {
|
|
625
|
+
this.setText('continue;');
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
exports.SourceContinueStmt = SourceContinueStmt;
|
|
629
|
+
class SourceBreakStmt extends SourceStmt {
|
|
630
|
+
constructor(context, original) {
|
|
631
|
+
super(context, original);
|
|
632
|
+
}
|
|
633
|
+
// trans 2 break or continue
|
|
634
|
+
transfer2ts() {
|
|
635
|
+
this.setText('break;');
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
exports.SourceBreakStmt = SourceBreakStmt;
|
|
639
|
+
class SourceReturnStmt extends SourceStmt {
|
|
640
|
+
constructor(context, original) {
|
|
641
|
+
super(context, original);
|
|
642
|
+
}
|
|
643
|
+
transfer2ts() {
|
|
644
|
+
this.setText(`return ${this.transformer.valueToString(this.original.getOp())};`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
exports.SourceReturnStmt = SourceReturnStmt;
|
|
648
|
+
class SourceReturnVoidStmt extends SourceStmt {
|
|
649
|
+
constructor(context, original) {
|
|
650
|
+
super(context, original);
|
|
651
|
+
}
|
|
652
|
+
transfer2ts() {
|
|
653
|
+
if (this.original.getOriginPositionInfo().getLineNo() <= 0) {
|
|
654
|
+
this.setText('');
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
this.setText('return;');
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
exports.SourceReturnVoidStmt = SourceReturnVoidStmt;
|
|
662
|
+
class SourceCompoundEndStmt extends SourceStmt {
|
|
663
|
+
constructor(context, stmt, text) {
|
|
664
|
+
super(context, stmt);
|
|
665
|
+
this.setText(text);
|
|
666
|
+
}
|
|
667
|
+
transfer2ts() { }
|
|
668
|
+
beforeDump() {
|
|
669
|
+
this.printer.decIndent();
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
exports.SourceCompoundEndStmt = SourceCompoundEndStmt;
|
|
673
|
+
class SourceCommonStmt extends SourceStmt {
|
|
674
|
+
constructor(context, stmt) {
|
|
675
|
+
super(context, stmt);
|
|
676
|
+
}
|
|
677
|
+
transfer2ts() {
|
|
678
|
+
this.setText(this.original.toString());
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
exports.SourceCommonStmt = SourceCommonStmt;
|
|
682
|
+
class SourceThrowStmt extends SourceStmt {
|
|
683
|
+
constructor(context, original) {
|
|
684
|
+
super(context, original);
|
|
685
|
+
}
|
|
686
|
+
transfer2ts() {
|
|
687
|
+
this.setText(`throw ${this.transformer.valueToString(this.original.getOp())};`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
exports.SourceThrowStmt = SourceThrowStmt;
|
|
691
|
+
class SourceTypeAliasStmt extends SourceStmt {
|
|
692
|
+
constructor(context, original, aliasType) {
|
|
693
|
+
super(context, original);
|
|
694
|
+
this.aliasType = aliasType;
|
|
695
|
+
}
|
|
696
|
+
transfer2ts() {
|
|
697
|
+
let modifiersArray = (0, ArkBaseModel_1.modifiers2stringArray)(this.aliasType.getModifiers());
|
|
698
|
+
let modifier = modifiersArray.length > 0 ? `${modifiersArray.join(' ')} ` : '';
|
|
699
|
+
const expr = this.original.getAliasTypeExpr();
|
|
700
|
+
let typeOf = expr.getTransferWithTypeOf() ? 'typeof ' : '';
|
|
701
|
+
let realGenericTypes = expr.getRealGenericTypes() ? `<${expr.getRealGenericTypes().join(', ')}>` : '';
|
|
702
|
+
let genericTypes = this.aliasType.getGenericTypes() ? `<${this.transformer.typeArrayToString(this.aliasType.getGenericTypes())}>` : '';
|
|
703
|
+
let typeObject = expr.getOriginalObject();
|
|
704
|
+
if (typeObject instanceof Type_1.Type) {
|
|
705
|
+
if (typeObject instanceof Type_1.AliasType) {
|
|
706
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${this.transformer.typeToString(typeObject)}${realGenericTypes};`);
|
|
710
|
+
}
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (typeObject instanceof ArkImport_1.ImportInfo) {
|
|
714
|
+
let exprStr = `import('${typeObject.getFrom()}')`;
|
|
715
|
+
if (typeObject.getImportClauseName() !== '') {
|
|
716
|
+
exprStr = `${exprStr}.${typeObject.getImportClauseName()}`;
|
|
717
|
+
}
|
|
718
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${exprStr}${realGenericTypes};`);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (typeObject instanceof Local_1.Local) {
|
|
722
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${this.transformer.valueToString(typeObject)}${realGenericTypes};`);
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (typeObject instanceof ArkClass_1.ArkClass) {
|
|
726
|
+
let classTS = this.generateClassTS(typeObject);
|
|
727
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${classTS}${realGenericTypes};`);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (typeObject instanceof ArkMethod_1.ArkMethod) {
|
|
731
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
this.setText(`${modifier}type ${this.aliasType.getName()}${genericTypes} = ${typeOf}${typeObject.getName()}${realGenericTypes};`);
|
|
735
|
+
}
|
|
736
|
+
generateClassTS(arkClass) {
|
|
737
|
+
let res = '';
|
|
738
|
+
let classType = new Type_1.ClassType(arkClass.getSignature());
|
|
739
|
+
if (arkClass.getCategory() === ArkClass_1.ClassCategory.TYPE_LITERAL || arkClass.getCategory() === ArkClass_1.ClassCategory.OBJECT) {
|
|
740
|
+
res = this.transformer.literalObjectToString(classType);
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
res = this.transformer.typeToString(classType);
|
|
744
|
+
}
|
|
745
|
+
return res;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
exports.SourceTypeAliasStmt = SourceTypeAliasStmt;
|
|
749
|
+
class SourceTryStmt extends SourceStmt {
|
|
750
|
+
constructor(context, stmt) {
|
|
751
|
+
super(context, stmt);
|
|
752
|
+
}
|
|
753
|
+
transfer2ts() {
|
|
754
|
+
this.setText('try {');
|
|
755
|
+
}
|
|
756
|
+
afterDump() {
|
|
757
|
+
this.printer.incIndent();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
exports.SourceTryStmt = SourceTryStmt;
|
|
761
|
+
class SourceCatchStmt extends SourceStmt {
|
|
762
|
+
constructor(context, stmt, block) {
|
|
763
|
+
super(context, stmt);
|
|
764
|
+
this.block = block;
|
|
765
|
+
}
|
|
766
|
+
transfer2ts() {
|
|
767
|
+
if (this.block) {
|
|
768
|
+
let stmt = this.block.getStmts()[0];
|
|
769
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
770
|
+
if (stmt.getLeftOp() instanceof Local_1.Local) {
|
|
771
|
+
let name = stmt.getLeftOp().getName();
|
|
772
|
+
this.setText(`} catch (${name}) {`);
|
|
773
|
+
this.context.setSkipStmt(stmt);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
this.setText('} catch (e) {');
|
|
779
|
+
}
|
|
780
|
+
beforeDump() {
|
|
781
|
+
this.printer.decIndent();
|
|
782
|
+
}
|
|
783
|
+
afterDump() {
|
|
784
|
+
this.printer.incIndent();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
exports.SourceCatchStmt = SourceCatchStmt;
|
|
788
|
+
class SourceFinallyStmt extends SourceStmt {
|
|
789
|
+
constructor(context, stmt) {
|
|
790
|
+
super(context, stmt);
|
|
791
|
+
}
|
|
792
|
+
transfer2ts() {
|
|
793
|
+
this.setText('} finally {');
|
|
794
|
+
}
|
|
795
|
+
beforeDump() {
|
|
796
|
+
this.printer.decIndent();
|
|
797
|
+
}
|
|
798
|
+
afterDump() {
|
|
799
|
+
this.printer.incIndent();
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
exports.SourceFinallyStmt = SourceFinallyStmt;
|
|
803
|
+
class SourceNewArrayExpr {
|
|
804
|
+
constructor(expr) {
|
|
805
|
+
this.expr = expr;
|
|
806
|
+
this.values = [];
|
|
807
|
+
}
|
|
808
|
+
addInitValue(value) {
|
|
809
|
+
this.values.push(value);
|
|
810
|
+
}
|
|
811
|
+
toString() {
|
|
812
|
+
return `[${this.values.join(', ')}]`;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
exports.SourceNewArrayExpr = SourceNewArrayExpr;
|
|
816
|
+
function stmt2SourceStmt(context, stmt) {
|
|
817
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
818
|
+
return new SourceAssignStmt(context, stmt);
|
|
819
|
+
}
|
|
820
|
+
if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
821
|
+
return new SourceInvokeStmt(context, stmt);
|
|
822
|
+
}
|
|
823
|
+
if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
|
|
824
|
+
return new SourceReturnVoidStmt(context, stmt);
|
|
825
|
+
}
|
|
826
|
+
if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
827
|
+
return new SourceReturnStmt(context, stmt);
|
|
828
|
+
}
|
|
829
|
+
if (stmt instanceof Stmt_1.ArkThrowStmt) {
|
|
830
|
+
return new SourceThrowStmt(context, stmt);
|
|
831
|
+
}
|
|
832
|
+
if (stmt instanceof Stmt_1.ArkAliasTypeDefineStmt) {
|
|
833
|
+
return new SourceTypeAliasStmt(context, stmt, stmt.getAliasType());
|
|
834
|
+
}
|
|
835
|
+
logger.info(`stmt2SourceStmt ${stmt.constructor} not support.`);
|
|
836
|
+
return new SourceCommonStmt(context, stmt);
|
|
837
|
+
}
|
|
838
|
+
exports.stmt2SourceStmt = stmt2SourceStmt;
|