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,690 +1,690 @@
|
|
|
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.ArkIRTransformer = exports.DummyStmt = void 0;
|
|
41
|
-
const Expr_1 = require("../base/Expr");
|
|
42
|
-
const Ref_1 = require("../base/Ref");
|
|
43
|
-
const ts = __importStar(require("ohos-typescript"));
|
|
44
|
-
const Local_1 = require("../base/Local");
|
|
45
|
-
const Stmt_1 = require("../base/Stmt");
|
|
46
|
-
const Type_1 = require("../base/Type");
|
|
47
|
-
const ValueUtil_1 = require("./ValueUtil");
|
|
48
|
-
const ArkSignature_1 = require("../model/ArkSignature");
|
|
49
|
-
const IRUtils_1 = require("./IRUtils");
|
|
50
|
-
const ArkMethod_1 = require("../model/ArkMethod");
|
|
51
|
-
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
52
|
-
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
53
|
-
const EtsConst_1 = require("./EtsConst");
|
|
54
|
-
const Position_1 = require("../base/Position");
|
|
55
|
-
const ModelUtils_1 = require("./ModelUtils");
|
|
56
|
-
const Builtin_1 = require("./Builtin");
|
|
57
|
-
const TSConst_1 = require("./TSConst");
|
|
58
|
-
const builderUtils_1 = require("../model/builder/builderUtils");
|
|
59
|
-
const ArkValueTransformer_1 = require("./ArkValueTransformer");
|
|
60
|
-
const ArkImport_1 = require("../model/ArkImport");
|
|
61
|
-
const TypeInference_1 = require("./TypeInference");
|
|
62
|
-
const TypeExpr_1 = require("../base/TypeExpr");
|
|
63
|
-
class DummyStmt extends Stmt_1.Stmt {
|
|
64
|
-
constructor(text) {
|
|
65
|
-
super();
|
|
66
|
-
this.text = text;
|
|
67
|
-
}
|
|
68
|
-
toString() {
|
|
69
|
-
return this.text;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.DummyStmt = DummyStmt;
|
|
73
|
-
class ArkIRTransformer {
|
|
74
|
-
constructor(sourceFile, declaringMethod) {
|
|
75
|
-
this.inBuilderMethod = false;
|
|
76
|
-
this.builderMethodContextFlag = false;
|
|
77
|
-
this.stmtsHaveOriginalText = new Set();
|
|
78
|
-
this.sourceFile = sourceFile;
|
|
79
|
-
this.declaringMethod = declaringMethod;
|
|
80
|
-
this.inBuilderMethod = ModelUtils_1.ModelUtils.isArkUIBuilderMethod(declaringMethod);
|
|
81
|
-
this.arkValueTransformer = new ArkValueTransformer_1.ArkValueTransformer(this, sourceFile, this.declaringMethod);
|
|
82
|
-
}
|
|
83
|
-
getLocals() {
|
|
84
|
-
return this.arkValueTransformer.getLocals();
|
|
85
|
-
}
|
|
86
|
-
getGlobals() {
|
|
87
|
-
return this.arkValueTransformer.getGlobals();
|
|
88
|
-
}
|
|
89
|
-
getThisLocal() {
|
|
90
|
-
return this.arkValueTransformer.getThisLocal();
|
|
91
|
-
}
|
|
92
|
-
getAliasTypeMap() {
|
|
93
|
-
return this.arkValueTransformer.getAliasTypeMap();
|
|
94
|
-
}
|
|
95
|
-
prebuildStmts() {
|
|
96
|
-
const stmts = [];
|
|
97
|
-
let index = 0;
|
|
98
|
-
for (const methodParameter of this.declaringMethod.getParameters()) {
|
|
99
|
-
const parameterRef = new Ref_1.ArkParameterRef(index, methodParameter.getType());
|
|
100
|
-
stmts.push(new Stmt_1.ArkAssignStmt(this.arkValueTransformer.addNewLocal(methodParameter.getName(), parameterRef.getType()), parameterRef));
|
|
101
|
-
index++;
|
|
102
|
-
}
|
|
103
|
-
const thisRef = new Ref_1.ArkThisRef(this.arkValueTransformer.getThisLocal().getType());
|
|
104
|
-
stmts.push(new Stmt_1.ArkAssignStmt(this.arkValueTransformer.getThisLocal(), thisRef));
|
|
105
|
-
return stmts;
|
|
106
|
-
}
|
|
107
|
-
tsNodeToStmts(node) {
|
|
108
|
-
let stmts = [];
|
|
109
|
-
if (ts.isExpressionStatement(node)) {
|
|
110
|
-
stmts = this.expressionStatementToStmts(node);
|
|
111
|
-
}
|
|
112
|
-
else if (ts.isTypeAliasDeclaration(node)) {
|
|
113
|
-
stmts = this.typeAliasDeclarationToStmts(node);
|
|
114
|
-
}
|
|
115
|
-
else if (ts.isBlock(node)) {
|
|
116
|
-
stmts = this.blockToStmts(node);
|
|
117
|
-
}
|
|
118
|
-
else if (ts.isForStatement(node)) {
|
|
119
|
-
stmts = this.forStatementToStmts(node);
|
|
120
|
-
}
|
|
121
|
-
else if (ts.isForInStatement(node) || ts.isForOfStatement(node)) {
|
|
122
|
-
stmts = this.rangeForStatementToStmts(node);
|
|
123
|
-
}
|
|
124
|
-
else if (ts.isWhileStatement(node)) {
|
|
125
|
-
stmts = this.whileStatementToStmts(node);
|
|
126
|
-
}
|
|
127
|
-
else if (ts.isDoStatement(node)) {
|
|
128
|
-
stmts = this.doStatementToStmts(node);
|
|
129
|
-
}
|
|
130
|
-
else if (ts.isVariableStatement(node)) {
|
|
131
|
-
stmts = this.variableStatementToStmts(node);
|
|
132
|
-
}
|
|
133
|
-
else if (ts.isVariableDeclarationList(node)) {
|
|
134
|
-
stmts = this.variableDeclarationListToStmts(node);
|
|
135
|
-
}
|
|
136
|
-
else if (ts.isIfStatement(node)) {
|
|
137
|
-
stmts = this.ifStatementToStmts(node);
|
|
138
|
-
}
|
|
139
|
-
else if (ts.isBreakStatement(node) || ts.isContinueStatement(node)) {
|
|
140
|
-
stmts = this.gotoStatementToStmts(node);
|
|
141
|
-
}
|
|
142
|
-
else if (ts.isThrowStatement(node)) {
|
|
143
|
-
stmts = this.throwStatementToStmts(node);
|
|
144
|
-
}
|
|
145
|
-
else if (ts.isCatchClause(node)) {
|
|
146
|
-
stmts = this.catchClauseToStmts(node);
|
|
147
|
-
}
|
|
148
|
-
else if (ts.isReturnStatement(node)) {
|
|
149
|
-
stmts = this.returnStatementToStmts(node);
|
|
150
|
-
}
|
|
151
|
-
else if (ts.isFunctionDeclaration(node)) {
|
|
152
|
-
stmts = this.functionDeclarationToStmts(node);
|
|
153
|
-
}
|
|
154
|
-
else if (ts.isExportAssignment(node)) {
|
|
155
|
-
stmts = this.expressionInExportToStmts(node.expression);
|
|
156
|
-
}
|
|
157
|
-
this.mapStmtsToTsStmt(stmts, node);
|
|
158
|
-
if (stmts.length > 0) {
|
|
159
|
-
IRUtils_1.IRUtils.setComments(stmts[0], node, this.sourceFile, this.declaringMethod.getDeclaringArkFile().getScene().getOptions());
|
|
160
|
-
}
|
|
161
|
-
return stmts;
|
|
162
|
-
}
|
|
163
|
-
tsNodeToValueAndStmts(node) {
|
|
164
|
-
return this.arkValueTransformer.tsNodeToValueAndStmts(node);
|
|
165
|
-
}
|
|
166
|
-
functionDeclarationToStmts(functionDeclarationNode) {
|
|
167
|
-
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
168
|
-
const arkMethod = new ArkMethod_1.ArkMethod();
|
|
169
|
-
if (this.builderMethodContextFlag) {
|
|
170
|
-
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arkMethod);
|
|
171
|
-
}
|
|
172
|
-
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionDeclarationNode, declaringClass, arkMethod, this.sourceFile, this.declaringMethod);
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
returnStatementToStmts(returnStatement) {
|
|
176
|
-
const stmts = [];
|
|
177
|
-
if (returnStatement.expression) {
|
|
178
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(returnStatement.expression);
|
|
179
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
180
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
181
|
-
({
|
|
182
|
-
value: exprValue,
|
|
183
|
-
valueOriginalPositions: exprPositions,
|
|
184
|
-
stmts: exprStmts,
|
|
185
|
-
} = this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
186
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
187
|
-
}
|
|
188
|
-
const returnStmt = new Stmt_1.ArkReturnStmt(exprValue);
|
|
189
|
-
returnStmt.setOperandOriginalPositions(exprPositions);
|
|
190
|
-
stmts.push(returnStmt);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
stmts.push(new Stmt_1.ArkReturnVoidStmt());
|
|
194
|
-
}
|
|
195
|
-
return stmts;
|
|
196
|
-
}
|
|
197
|
-
blockToStmts(block) {
|
|
198
|
-
const stmts = [];
|
|
199
|
-
for (const statement of block.statements) {
|
|
200
|
-
this.tsNodeToStmts(statement).forEach(stmt => stmts.push(stmt));
|
|
201
|
-
}
|
|
202
|
-
return stmts;
|
|
203
|
-
}
|
|
204
|
-
expressionStatementToStmts(expressionStatement) {
|
|
205
|
-
const exprNode = expressionStatement.expression;
|
|
206
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts, } = this.tsNodeToValueAndStmts(exprNode);
|
|
207
|
-
if (exprValue instanceof Expr_1.AbstractInvokeExpr) {
|
|
208
|
-
this.addInvokeStmts(exprValue, exprPositions, stmts);
|
|
209
|
-
}
|
|
210
|
-
else if (this.shouldGenerateExtraAssignStmt(exprNode)) {
|
|
211
|
-
const { stmts: exprStmts } = this.generateAssignStmtForValue(exprValue, exprPositions);
|
|
212
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
213
|
-
}
|
|
214
|
-
return stmts;
|
|
215
|
-
}
|
|
216
|
-
addInvokeStmts(invokeExpr, exprPositions, stmts) {
|
|
217
|
-
const invokeStmt = new Stmt_1.ArkInvokeStmt(invokeExpr);
|
|
218
|
-
invokeStmt.setOperandOriginalPositions(exprPositions);
|
|
219
|
-
stmts.push(invokeStmt);
|
|
220
|
-
let hasRepeat = false;
|
|
221
|
-
for (const stmt of stmts) {
|
|
222
|
-
if ((stmt instanceof Stmt_1.ArkAssignStmt) && (stmt.getRightOp() instanceof Expr_1.ArkStaticInvokeExpr)) {
|
|
223
|
-
const rightOp = stmt.getRightOp();
|
|
224
|
-
if (rightOp.getMethodSignature().getMethodSubSignature().getMethodName() === EtsConst_1.COMPONENT_REPEAT) {
|
|
225
|
-
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
226
|
-
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, rightOp.getArgs());
|
|
227
|
-
stmt.setRightOp(createInvokeExpr);
|
|
228
|
-
hasRepeat = true;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (hasRepeat) {
|
|
233
|
-
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
234
|
-
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
235
|
-
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
236
|
-
stmts.push(popInvokeStmt);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
shouldGenerateExtraAssignStmt(expression) {
|
|
240
|
-
if (ts.isParenthesizedExpression(expression)) {
|
|
241
|
-
return this.shouldGenerateExtraAssignStmt(expression.expression);
|
|
242
|
-
}
|
|
243
|
-
if ((ts.isBinaryExpression(expression) && (expression.operatorToken.kind === ts.SyntaxKind.FirstAssignment ||
|
|
244
|
-
ArkValueTransformer_1.ArkValueTransformer.isCompoundAssignmentOperator(expression.operatorToken.kind))) ||
|
|
245
|
-
ts.isEtsComponentExpression(expression) || ts.isVoidExpression(expression) ||
|
|
246
|
-
ts.isNewExpression(expression) || ts.isCallExpression(expression) ||
|
|
247
|
-
(ts.isPrefixUnaryExpression(expression) &&
|
|
248
|
-
(expression.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
249
|
-
expression.operator === ts.SyntaxKind.MinusMinusToken)) ||
|
|
250
|
-
(ts.isPostfixUnaryExpression(expression) &&
|
|
251
|
-
(expression.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
252
|
-
expression.operator === ts.SyntaxKind.MinusMinusToken))) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
typeAliasDeclarationToStmts(typeAliasDeclaration) {
|
|
258
|
-
const aliasName = typeAliasDeclaration.name.text;
|
|
259
|
-
const rightOp = typeAliasDeclaration.type;
|
|
260
|
-
let rightType = this.arkValueTransformer.resolveTypeNode(rightOp);
|
|
261
|
-
if (rightType instanceof TypeExpr_1.AbstractTypeExpr) {
|
|
262
|
-
rightType = rightType.getType();
|
|
263
|
-
}
|
|
264
|
-
const aliasType = new Type_1.AliasType(aliasName, rightType, new ArkSignature_1.AliasTypeSignature(aliasName, this.declaringMethod.getSignature()));
|
|
265
|
-
if (typeAliasDeclaration.typeParameters) {
|
|
266
|
-
const genericTypes = (0, builderUtils_1.buildTypeParameters)(typeAliasDeclaration.typeParameters, this.sourceFile, this.declaringMethod);
|
|
267
|
-
aliasType.setGenericTypes(genericTypes);
|
|
268
|
-
aliasType.setOriginalType((0, builderUtils_1.buildGenericType)(rightType, aliasType));
|
|
269
|
-
rightType = aliasType.getOriginalType();
|
|
270
|
-
}
|
|
271
|
-
let expr = this.generateAliasTypeExpr(rightOp, aliasType);
|
|
272
|
-
if ((ts.isTypeQueryNode(rightOp) || ts.isTypeReferenceNode(rightOp)) && rightOp.typeArguments) {
|
|
273
|
-
let realGenericTypes = [];
|
|
274
|
-
rightOp.typeArguments.forEach(typeArgument => {
|
|
275
|
-
realGenericTypes.push(this.arkValueTransformer.resolveTypeNode(typeArgument));
|
|
276
|
-
});
|
|
277
|
-
expr.setRealGenericTypes(realGenericTypes);
|
|
278
|
-
}
|
|
279
|
-
const modifiers = typeAliasDeclaration.modifiers ? (0, builderUtils_1.buildModifiers)(typeAliasDeclaration) : 0;
|
|
280
|
-
aliasType.setModifiers(modifiers);
|
|
281
|
-
const aliasTypeDefineStmt = new Stmt_1.ArkAliasTypeDefineStmt(aliasType, expr);
|
|
282
|
-
const leftPosition = Position_1.FullPosition.buildFromNode(typeAliasDeclaration.name, this.sourceFile);
|
|
283
|
-
const rightPosition = Position_1.FullPosition.buildFromNode(rightOp, this.sourceFile);
|
|
284
|
-
const operandOriginalPositions = [leftPosition, rightPosition];
|
|
285
|
-
aliasTypeDefineStmt.setOperandOriginalPositions(operandOriginalPositions);
|
|
286
|
-
this.getAliasTypeMap().set(aliasName, [aliasType, aliasTypeDefineStmt]);
|
|
287
|
-
return [aliasTypeDefineStmt];
|
|
288
|
-
}
|
|
289
|
-
generateAliasTypeExpr(rightOp, aliasType) {
|
|
290
|
-
var _a;
|
|
291
|
-
let rightType = aliasType.getOriginalType();
|
|
292
|
-
let expr;
|
|
293
|
-
if (ts.isImportTypeNode(rightOp)) {
|
|
294
|
-
expr = this.resolveImportTypeNode(rightOp);
|
|
295
|
-
const typeObject = expr.getOriginalObject();
|
|
296
|
-
if (typeObject instanceof ArkImport_1.ImportInfo && typeObject.getLazyExportInfo() !== null) {
|
|
297
|
-
const arkExport = typeObject.getLazyExportInfo().getArkExport();
|
|
298
|
-
rightType = (_a = TypeInference_1.TypeInference.parseArkExport2Type(arkExport)) !== null && _a !== void 0 ? _a : Type_1.UnknownType.getInstance();
|
|
299
|
-
aliasType.setOriginalType(rightType);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else if (ts.isTypeQueryNode(rightOp)) {
|
|
303
|
-
const localName = rightOp.exprName.getText(this.sourceFile);
|
|
304
|
-
const originalLocal = Array.from(this.arkValueTransformer.getLocals()).find(local => local.getName() === localName);
|
|
305
|
-
if (originalLocal === undefined || rightType instanceof Type_1.UnclearReferenceType) {
|
|
306
|
-
expr = new Expr_1.AliasTypeExpr(new Local_1.Local(localName, rightType), true);
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
expr = new Expr_1.AliasTypeExpr(originalLocal, true);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else if (ts.isTypeReferenceNode(rightOp)) {
|
|
313
|
-
// For type A = B<number> stmt and B is also an alias type with the same scope of A,
|
|
314
|
-
// rightType here is AliasType with real generic type number.
|
|
315
|
-
// The originalObject in expr should be the object without real generic type, so try to find it in this scope.
|
|
316
|
-
if (rightType instanceof Type_1.AliasType) {
|
|
317
|
-
const existAliasType = this.getAliasTypeMap().get(rightType.getName());
|
|
318
|
-
if (existAliasType) {
|
|
319
|
-
expr = new Expr_1.AliasTypeExpr(existAliasType[0], false);
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
331
|
-
// 对于type A = {x:1, y:2}语句,当前阶段即可精确获取ClassType类型,需找到对应的ArkClass作为originalObject
|
|
332
|
-
// 对于其他情况此处为UnclearReferenceTye并由类型推导进行查找和处理
|
|
333
|
-
if (rightType instanceof Type_1.ClassType) {
|
|
334
|
-
const classObject = ModelUtils_1.ModelUtils.getClassWithName(rightType.getClassSignature().getClassName(), this.declaringMethod.getDeclaringArkClass());
|
|
335
|
-
if (classObject) {
|
|
336
|
-
expr.setOriginalObject(classObject);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return expr;
|
|
341
|
-
}
|
|
342
|
-
resolveImportTypeNode(importTypeNode) {
|
|
343
|
-
const importType = 'typeAliasDefine';
|
|
344
|
-
let importFrom = '';
|
|
345
|
-
let importClauseName = '';
|
|
346
|
-
if (ts.isLiteralTypeNode(importTypeNode.argument)) {
|
|
347
|
-
if (ts.isStringLiteral(importTypeNode.argument.literal)) {
|
|
348
|
-
importFrom = importTypeNode.argument.literal.text;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const importQualifier = importTypeNode.qualifier;
|
|
352
|
-
if (importQualifier !== undefined) {
|
|
353
|
-
importClauseName = importQualifier.getText(this.sourceFile);
|
|
354
|
-
}
|
|
355
|
-
let importInfo = new ArkImport_1.ImportInfo();
|
|
356
|
-
importInfo.build(importClauseName, importType, importFrom, Position_1.LineColPosition.buildFromNode(importTypeNode, this.sourceFile), 0);
|
|
357
|
-
importInfo.setDeclaringArkFile(this.declaringMethod.getDeclaringArkFile());
|
|
358
|
-
// Function getLazyExportInfo will automatically try to infer the export info if it's undefined at the beginning.
|
|
359
|
-
importInfo.getLazyExportInfo();
|
|
360
|
-
return new Expr_1.AliasTypeExpr(importInfo, importTypeNode.isTypeOf);
|
|
361
|
-
}
|
|
362
|
-
switchStatementToValueAndStmts(switchStatement) {
|
|
363
|
-
const valueAndStmtsOfSwitchAndCases = [];
|
|
364
|
-
const exprStmts = [];
|
|
365
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprTempStmts, } = this.tsNodeToValueAndStmts(switchStatement.expression);
|
|
366
|
-
exprTempStmts.forEach(stmt => exprStmts.push(stmt));
|
|
367
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
368
|
-
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprTempStmts } =
|
|
369
|
-
this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
370
|
-
exprTempStmts.forEach(stmt => exprStmts.push(stmt));
|
|
371
|
-
}
|
|
372
|
-
valueAndStmtsOfSwitchAndCases.push({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts });
|
|
373
|
-
for (const clause of switchStatement.caseBlock.clauses) {
|
|
374
|
-
if (ts.isCaseClause(clause)) {
|
|
375
|
-
const clauseStmts = [];
|
|
376
|
-
let { value: clauseValue, valueOriginalPositions: clausePositions, stmts: clauseTempStmts, } = this.tsNodeToValueAndStmts(clause.expression);
|
|
377
|
-
clauseTempStmts.forEach(stmt => clauseStmts.push(stmt));
|
|
378
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(clauseValue)) {
|
|
379
|
-
({
|
|
380
|
-
value: clauseValue,
|
|
381
|
-
valueOriginalPositions: clausePositions,
|
|
382
|
-
stmts: clauseTempStmts,
|
|
383
|
-
} = this.generateAssignStmtForValue(clauseValue, clausePositions));
|
|
384
|
-
clauseTempStmts.forEach(stmt => clauseStmts.push(stmt));
|
|
385
|
-
}
|
|
386
|
-
valueAndStmtsOfSwitchAndCases.push({ value: clauseValue, valueOriginalPositions: clausePositions, stmts: clauseStmts });
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return valueAndStmtsOfSwitchAndCases;
|
|
390
|
-
}
|
|
391
|
-
forStatementToStmts(forStatement) {
|
|
392
|
-
const stmts = [];
|
|
393
|
-
if (forStatement.initializer) {
|
|
394
|
-
this.tsNodeToValueAndStmts(forStatement.initializer).stmts.forEach(stmt => stmts.push(stmt));
|
|
395
|
-
}
|
|
396
|
-
const dummyInitializerStmt = new DummyStmt(ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
397
|
-
stmts.push(dummyInitializerStmt);
|
|
398
|
-
if (forStatement.condition) {
|
|
399
|
-
const { value: conditionValue, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(forStatement.condition);
|
|
400
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
401
|
-
stmts.push(new Stmt_1.ArkIfStmt(conditionValue));
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
// The omitted condition always evaluates to true.
|
|
405
|
-
const trueConstant = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
406
|
-
const conditionExpr = new Expr_1.ArkConditionExpr(trueConstant, trueConstant, Expr_1.RelationalBinaryOperator.Equality);
|
|
407
|
-
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
408
|
-
}
|
|
409
|
-
if (forStatement.incrementor) {
|
|
410
|
-
this.tsNodeToValueAndStmts(forStatement.incrementor).stmts.forEach(stmt => stmts.push(stmt));
|
|
411
|
-
}
|
|
412
|
-
return stmts;
|
|
413
|
-
}
|
|
414
|
-
rangeForStatementToStmts(forOfStatement) {
|
|
415
|
-
const stmts = [];
|
|
416
|
-
let { value: iterableValue, valueOriginalPositions: iterablePositions, stmts: iterableStmts, } = this.tsNodeToValueAndStmts(forOfStatement.expression);
|
|
417
|
-
iterableStmts.forEach(stmt => stmts.push(stmt));
|
|
418
|
-
if (!(iterableValue instanceof Local_1.Local)) {
|
|
419
|
-
({ value: iterableValue, valueOriginalPositions: iterablePositions, stmts: iterableStmts } =
|
|
420
|
-
this.generateAssignStmtForValue(iterableValue, iterablePositions));
|
|
421
|
-
iterableStmts.forEach(stmt => stmts.push(stmt));
|
|
422
|
-
}
|
|
423
|
-
const iteratorMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.Builtin.ITERATOR_FUNCTION, [], Builtin_1.Builtin.ITERATOR_CLASS_TYPE);
|
|
424
|
-
const iteratorMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, iteratorMethodSubSignature);
|
|
425
|
-
const iteratorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterableValue, iteratorMethodSignature, []);
|
|
426
|
-
const iteratorInvokeExprPositions = [iterablePositions[0], ...iterablePositions];
|
|
427
|
-
const { value: iterator, valueOriginalPositions: iteratorPositions, stmts: iteratorStmts, } = this.generateAssignStmtForValue(iteratorInvokeExpr, iteratorInvokeExprPositions);
|
|
428
|
-
iteratorStmts.forEach(stmt => stmts.push(stmt));
|
|
429
|
-
iterator.setType(Builtin_1.Builtin.ITERATOR_CLASS_TYPE);
|
|
430
|
-
const nextMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.Builtin.ITERATOR_NEXT, [], Builtin_1.Builtin.ITERATOR_RESULT_CLASS_TYPE);
|
|
431
|
-
const nextMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, nextMethodSubSignature);
|
|
432
|
-
const iteratorNextInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterator, nextMethodSignature, []);
|
|
433
|
-
const iteratorNextInvokeExprPositions = [iteratorPositions[0], ...iteratorPositions];
|
|
434
|
-
const { value: iteratorResult, valueOriginalPositions: iteratorResultPositions, stmts: iteratorResultStmts, } = this.generateAssignStmtForValue(iteratorNextInvokeExpr, iteratorNextInvokeExprPositions);
|
|
435
|
-
iteratorResultStmts.forEach(stmt => stmts.push(stmt));
|
|
436
|
-
iteratorResult.setType(Builtin_1.Builtin.ITERATOR_RESULT_CLASS_TYPE);
|
|
437
|
-
const doneFieldSignature = new ArkSignature_1.FieldSignature(Builtin_1.Builtin.ITERATOR_RESULT_DONE, Builtin_1.Builtin.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.BooleanType.getInstance(), false);
|
|
438
|
-
const doneFieldRef = new Ref_1.ArkInstanceFieldRef(iteratorResult, doneFieldSignature);
|
|
439
|
-
const doneFieldRefPositions = [iteratorResultPositions[0], ...iteratorResultPositions];
|
|
440
|
-
const { value: doneFlag, valueOriginalPositions: doneFlagPositions, stmts: doneFlagStmts, } = this.generateAssignStmtForValue(doneFieldRef, doneFieldRefPositions);
|
|
441
|
-
doneFlagStmts.forEach(stmt => stmts.push(stmt));
|
|
442
|
-
doneFlag.setType(Type_1.BooleanType.getInstance());
|
|
443
|
-
const conditionExpr = new Expr_1.ArkConditionExpr(doneFlag, ValueUtil_1.ValueUtil.getBooleanConstant(true), Expr_1.RelationalBinaryOperator.Equality);
|
|
444
|
-
const conditionExprPositions = [doneFlagPositions[0], ...doneFlagPositions, Position_1.FullPosition.DEFAULT];
|
|
445
|
-
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
446
|
-
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
447
|
-
stmts.push(ifStmt);
|
|
448
|
-
const valueFieldSignature = new ArkSignature_1.FieldSignature(Builtin_1.Builtin.ITERATOR_RESULT_VALUE, Builtin_1.Builtin.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.UnknownType.getInstance(), false);
|
|
449
|
-
const valueFieldRef = new Ref_1.ArkInstanceFieldRef(iteratorResult, valueFieldSignature);
|
|
450
|
-
const valueFieldRefPositions = [iteratorResultPositions[0], ...iteratorResultPositions];
|
|
451
|
-
const { value: yieldValue, valueOriginalPositions: yieldValuePositions, stmts: yieldValueStmts, } = this.generateAssignStmtForValue(valueFieldRef, valueFieldRefPositions);
|
|
452
|
-
yieldValueStmts.forEach(stmt => stmts.push(stmt));
|
|
453
|
-
const castExpr = new Expr_1.ArkCastExpr(yieldValue, Type_1.UnknownType.getInstance());
|
|
454
|
-
const castExprPositions = [yieldValuePositions[0], ...yieldValuePositions];
|
|
455
|
-
const initializerNode = forOfStatement.initializer;
|
|
456
|
-
if (ts.isVariableDeclarationList(initializerNode)) {
|
|
457
|
-
const isConst = (initializerNode.flags & ts.NodeFlags.Const) !== 0;
|
|
458
|
-
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.arkValueTransformer.variableDeclarationToValueAndStmts(initializerNode.declarations[0], isConst, false);
|
|
459
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
460
|
-
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
461
|
-
stmts.push(assignStmt);
|
|
462
|
-
initStmts.forEach(stmt => stmts.push(stmt));
|
|
463
|
-
}
|
|
464
|
-
else { // initializer maybe an expression
|
|
465
|
-
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.tsNodeToValueAndStmts(initializerNode);
|
|
466
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
467
|
-
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
468
|
-
initStmts.forEach(stmt => stmts.push(stmt));
|
|
469
|
-
stmts.push(assignStmt);
|
|
470
|
-
}
|
|
471
|
-
return stmts;
|
|
472
|
-
}
|
|
473
|
-
whileStatementToStmts(whileStatement) {
|
|
474
|
-
const stmts = [];
|
|
475
|
-
const dummyInitializerStmt = new DummyStmt(ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
476
|
-
stmts.push(dummyInitializerStmt);
|
|
477
|
-
const { value: conditionExpr, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(whileStatement.expression);
|
|
478
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
479
|
-
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
480
|
-
return stmts;
|
|
481
|
-
}
|
|
482
|
-
doStatementToStmts(doStatement) {
|
|
483
|
-
const stmts = [];
|
|
484
|
-
const { value: conditionExpr, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(doStatement.expression);
|
|
485
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
486
|
-
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
487
|
-
return stmts;
|
|
488
|
-
}
|
|
489
|
-
variableStatementToStmts(variableStatement) {
|
|
490
|
-
return this.variableDeclarationListToStmts(variableStatement.declarationList);
|
|
491
|
-
}
|
|
492
|
-
variableDeclarationListToStmts(variableDeclarationList) {
|
|
493
|
-
return this.arkValueTransformer.variableDeclarationListToValueAndStmts(variableDeclarationList).stmts;
|
|
494
|
-
}
|
|
495
|
-
ifStatementToStmts(ifStatement) {
|
|
496
|
-
const stmts = [];
|
|
497
|
-
if (this.inBuilderMethod) {
|
|
498
|
-
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(ifStatement.expression);
|
|
499
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
500
|
-
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
501
|
-
const { value: conditionLocal, valueOriginalPositions: conditionLocalPositions, stmts: assignConditionStmts } = this.generateAssignStmtForValue(conditionExpr, conditionExprPositions);
|
|
502
|
-
assignConditionStmts.forEach(stmt => stmts.push(stmt));
|
|
503
|
-
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, [conditionLocal]);
|
|
504
|
-
const createInvokeExprPositions = [conditionLocalPositions[0], ...conditionLocalPositions];
|
|
505
|
-
const { stmts: createStmts } = this.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
506
|
-
createStmts.forEach(stmt => stmts.push(stmt));
|
|
507
|
-
const branchMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_BRANCH_FUNCTION);
|
|
508
|
-
const branchInvokeExpr = new Expr_1.ArkStaticInvokeExpr(branchMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)]);
|
|
509
|
-
const branchInvokeExprPositions = [conditionLocalPositions[0], Position_1.FullPosition.DEFAULT];
|
|
510
|
-
const branchInvokeStmt = new Stmt_1.ArkInvokeStmt(branchInvokeExpr);
|
|
511
|
-
branchInvokeStmt.setOperandOriginalPositions(branchInvokeExprPositions);
|
|
512
|
-
stmts.push(branchInvokeStmt);
|
|
513
|
-
this.tsNodeToStmts(ifStatement.thenStatement).forEach(stmt => stmts.push(stmt));
|
|
514
|
-
if (ifStatement.elseStatement) {
|
|
515
|
-
const branchElseMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_BRANCH_FUNCTION);
|
|
516
|
-
const branchElseInvokeExpr = new Expr_1.ArkStaticInvokeExpr(branchElseMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(1)]);
|
|
517
|
-
const branchElseInvokeExprPositions = [Position_1.FullPosition.buildFromNode(ifStatement.elseStatement, this.sourceFile), Position_1.FullPosition.DEFAULT];
|
|
518
|
-
const branchElseInvokeStmt = new Stmt_1.ArkInvokeStmt(branchElseInvokeExpr);
|
|
519
|
-
branchElseInvokeStmt.setOperandOriginalPositions(branchElseInvokeExprPositions);
|
|
520
|
-
stmts.push(branchElseInvokeStmt);
|
|
521
|
-
this.tsNodeToStmts(ifStatement.elseStatement).forEach(stmt => stmts.push(stmt));
|
|
522
|
-
}
|
|
523
|
-
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
524
|
-
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
525
|
-
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
526
|
-
stmts.push(popInvokeStmt);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(ifStatement.expression);
|
|
530
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
531
|
-
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
532
|
-
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
533
|
-
stmts.push(ifStmt);
|
|
534
|
-
}
|
|
535
|
-
return stmts;
|
|
536
|
-
}
|
|
537
|
-
gotoStatementToStmts(gotoStatement) {
|
|
538
|
-
return [];
|
|
539
|
-
}
|
|
540
|
-
throwStatementToStmts(throwStatement) {
|
|
541
|
-
const stmts = [];
|
|
542
|
-
const { value: throwValue, valueOriginalPositions: throwValuePositions, stmts: throwStmts, } = this.tsNodeToValueAndStmts(throwStatement.expression);
|
|
543
|
-
throwStmts.forEach(stmt => stmts.push(stmt));
|
|
544
|
-
const throwStmt = new Stmt_1.ArkThrowStmt(throwValue);
|
|
545
|
-
throwStmt.setOperandOriginalPositions(throwValuePositions);
|
|
546
|
-
stmts.push(throwStmt);
|
|
547
|
-
return stmts;
|
|
548
|
-
}
|
|
549
|
-
catchClauseToStmts(catchClause) {
|
|
550
|
-
const stmts = [];
|
|
551
|
-
if (catchClause.variableDeclaration) {
|
|
552
|
-
const { value: catchValue, valueOriginalPositions: catchOriPos, stmts: catchStmts, } = this.arkValueTransformer.variableDeclarationToValueAndStmts(catchClause.variableDeclaration, false, false);
|
|
553
|
-
const caughtExceptionRef = new Ref_1.ArkCaughtExceptionRef(Type_1.UnknownType.getInstance());
|
|
554
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(catchValue, caughtExceptionRef);
|
|
555
|
-
assignStmt.setOperandOriginalPositions(catchOriPos);
|
|
556
|
-
stmts.push(assignStmt);
|
|
557
|
-
catchStmts.forEach(stmt => stmts.push(stmt));
|
|
558
|
-
}
|
|
559
|
-
return stmts;
|
|
560
|
-
}
|
|
561
|
-
expressionInExportToStmts(expression) {
|
|
562
|
-
if (ts.isNewExpression(expression) || ts.isObjectLiteralExpression(expression)) {
|
|
563
|
-
return this.newClassInExportToStmts(expression);
|
|
564
|
-
}
|
|
565
|
-
return [];
|
|
566
|
-
}
|
|
567
|
-
newClassInExportToStmts(expression) {
|
|
568
|
-
let stmts = [];
|
|
569
|
-
let { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToValueAndStmts(expression);
|
|
570
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
571
|
-
let leftValue = this.arkValueTransformer.addNewLocal(TSConst_1.DEFAULT);
|
|
572
|
-
let leftPositions = rightPositions;
|
|
573
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
574
|
-
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
575
|
-
stmts.push(assignStmt);
|
|
576
|
-
return stmts;
|
|
577
|
-
}
|
|
578
|
-
mapStmtsToTsStmt(stmts, node) {
|
|
579
|
-
for (const stmt of stmts) {
|
|
580
|
-
if (!this.stmtsHaveOriginalText.has(stmt)) {
|
|
581
|
-
this.stmtsHaveOriginalText.add(stmt);
|
|
582
|
-
stmt.setOriginPositionInfo(Position_1.LineColPosition.buildFromNode(node, this.sourceFile));
|
|
583
|
-
stmt.setOriginalText(node.getText(this.sourceFile));
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
static tokenToUnaryOperator(token) {
|
|
588
|
-
switch (token) {
|
|
589
|
-
case ts.SyntaxKind.MinusToken:
|
|
590
|
-
return Expr_1.UnaryOperator.Neg;
|
|
591
|
-
case ts.SyntaxKind.TildeToken:
|
|
592
|
-
return Expr_1.UnaryOperator.BitwiseNot;
|
|
593
|
-
case ts.SyntaxKind.ExclamationToken:
|
|
594
|
-
return Expr_1.UnaryOperator.LogicalNot;
|
|
595
|
-
default:
|
|
596
|
-
;
|
|
597
|
-
}
|
|
598
|
-
return null;
|
|
599
|
-
}
|
|
600
|
-
static tokenToBinaryOperator(token) {
|
|
601
|
-
switch (token) {
|
|
602
|
-
case ts.SyntaxKind.QuestionQuestionToken:
|
|
603
|
-
return Expr_1.NormalBinaryOperator.NullishCoalescing;
|
|
604
|
-
case ts.SyntaxKind.AsteriskAsteriskToken:
|
|
605
|
-
return Expr_1.NormalBinaryOperator.Exponentiation;
|
|
606
|
-
case ts.SyntaxKind.SlashToken:
|
|
607
|
-
return Expr_1.NormalBinaryOperator.Division;
|
|
608
|
-
case ts.SyntaxKind.PlusToken:
|
|
609
|
-
return Expr_1.NormalBinaryOperator.Addition;
|
|
610
|
-
case ts.SyntaxKind.MinusToken:
|
|
611
|
-
return Expr_1.NormalBinaryOperator.Subtraction;
|
|
612
|
-
case ts.SyntaxKind.AsteriskToken:
|
|
613
|
-
return Expr_1.NormalBinaryOperator.Multiplication;
|
|
614
|
-
case ts.SyntaxKind.PercentToken:
|
|
615
|
-
return Expr_1.NormalBinaryOperator.Remainder;
|
|
616
|
-
case ts.SyntaxKind.LessThanLessThanToken:
|
|
617
|
-
return Expr_1.NormalBinaryOperator.LeftShift;
|
|
618
|
-
case ts.SyntaxKind.GreaterThanGreaterThanToken:
|
|
619
|
-
return Expr_1.NormalBinaryOperator.RightShift;
|
|
620
|
-
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
|
|
621
|
-
return Expr_1.NormalBinaryOperator.UnsignedRightShift;
|
|
622
|
-
case ts.SyntaxKind.AmpersandToken:
|
|
623
|
-
return Expr_1.NormalBinaryOperator.BitwiseAnd;
|
|
624
|
-
case ts.SyntaxKind.BarToken:
|
|
625
|
-
return Expr_1.NormalBinaryOperator.BitwiseOr;
|
|
626
|
-
case ts.SyntaxKind.CaretToken:
|
|
627
|
-
return Expr_1.NormalBinaryOperator.BitwiseXor;
|
|
628
|
-
case ts.SyntaxKind.AmpersandAmpersandToken:
|
|
629
|
-
return Expr_1.NormalBinaryOperator.LogicalAnd;
|
|
630
|
-
case ts.SyntaxKind.BarBarToken:
|
|
631
|
-
return Expr_1.NormalBinaryOperator.LogicalOr;
|
|
632
|
-
case ts.SyntaxKind.LessThanToken:
|
|
633
|
-
return Expr_1.RelationalBinaryOperator.LessThan;
|
|
634
|
-
case ts.SyntaxKind.LessThanEqualsToken:
|
|
635
|
-
return Expr_1.RelationalBinaryOperator.LessThanOrEqual;
|
|
636
|
-
case ts.SyntaxKind.GreaterThanToken:
|
|
637
|
-
return Expr_1.RelationalBinaryOperator.GreaterThan;
|
|
638
|
-
case ts.SyntaxKind.GreaterThanEqualsToken:
|
|
639
|
-
return Expr_1.RelationalBinaryOperator.GreaterThanOrEqual;
|
|
640
|
-
case ts.SyntaxKind.EqualsEqualsToken:
|
|
641
|
-
return Expr_1.RelationalBinaryOperator.Equality;
|
|
642
|
-
case ts.SyntaxKind.ExclamationEqualsToken:
|
|
643
|
-
return Expr_1.RelationalBinaryOperator.InEquality;
|
|
644
|
-
case ts.SyntaxKind.EqualsEqualsEqualsToken:
|
|
645
|
-
return Expr_1.RelationalBinaryOperator.StrictEquality;
|
|
646
|
-
case ts.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
647
|
-
return Expr_1.RelationalBinaryOperator.StrictInequality;
|
|
648
|
-
default:
|
|
649
|
-
;
|
|
650
|
-
}
|
|
651
|
-
return null;
|
|
652
|
-
}
|
|
653
|
-
generateAssignStmtForValue(value, valueOriginalPositions) {
|
|
654
|
-
const leftOp = this.arkValueTransformer.generateTempLocal(value.getType());
|
|
655
|
-
const leftOpPosition = valueOriginalPositions[0];
|
|
656
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftOp, value);
|
|
657
|
-
assignStmt.setOperandOriginalPositions([leftOpPosition, ...valueOriginalPositions]);
|
|
658
|
-
return { value: leftOp, valueOriginalPositions: [leftOpPosition], stmts: [assignStmt] };
|
|
659
|
-
}
|
|
660
|
-
generateIfStmtForValues(leftValue, leftOpOriginalPositions, rightValue, rightOpOriginalPositions) {
|
|
661
|
-
const stmts = [];
|
|
662
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue)) {
|
|
663
|
-
const { value: tempLeftValue, valueOriginalPositions: tempLeftPositions, stmts: leftStmts, } = this.generateAssignStmtForValue(leftValue, leftOpOriginalPositions);
|
|
664
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
665
|
-
leftValue = tempLeftValue;
|
|
666
|
-
leftOpOriginalPositions = tempLeftPositions;
|
|
667
|
-
}
|
|
668
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
669
|
-
const { value: tempRightValue, valueOriginalPositions: tempRightPositions, stmts: rightStmts, } = this.generateAssignStmtForValue(rightValue, rightOpOriginalPositions);
|
|
670
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
671
|
-
rightValue = tempRightValue;
|
|
672
|
-
rightOpOriginalPositions = tempRightPositions;
|
|
673
|
-
}
|
|
674
|
-
const conditionExpr = new Expr_1.ArkConditionExpr(leftValue, rightValue, Expr_1.RelationalBinaryOperator.Equality);
|
|
675
|
-
const conditionPositions = [...leftOpOriginalPositions, ...rightOpOriginalPositions];
|
|
676
|
-
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
677
|
-
ifStmt.setOperandOriginalPositions([...conditionPositions]);
|
|
678
|
-
stmts.push(ifStmt);
|
|
679
|
-
return stmts;
|
|
680
|
-
}
|
|
681
|
-
setBuilderMethodContextFlag(builderMethodContextFlag) {
|
|
682
|
-
this.builderMethodContextFlag = builderMethodContextFlag;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
exports.ArkIRTransformer = ArkIRTransformer;
|
|
686
|
-
ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT = 'LoopInitializer';
|
|
687
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR = 'ConditionalOperator';
|
|
688
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'IfTrue';
|
|
689
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'IfFalse';
|
|
690
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'End';
|
|
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.ArkIRTransformer = exports.DummyStmt = void 0;
|
|
41
|
+
const Expr_1 = require("../base/Expr");
|
|
42
|
+
const Ref_1 = require("../base/Ref");
|
|
43
|
+
const ts = __importStar(require("ohos-typescript"));
|
|
44
|
+
const Local_1 = require("../base/Local");
|
|
45
|
+
const Stmt_1 = require("../base/Stmt");
|
|
46
|
+
const Type_1 = require("../base/Type");
|
|
47
|
+
const ValueUtil_1 = require("./ValueUtil");
|
|
48
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
49
|
+
const IRUtils_1 = require("./IRUtils");
|
|
50
|
+
const ArkMethod_1 = require("../model/ArkMethod");
|
|
51
|
+
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
52
|
+
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
53
|
+
const EtsConst_1 = require("./EtsConst");
|
|
54
|
+
const Position_1 = require("../base/Position");
|
|
55
|
+
const ModelUtils_1 = require("./ModelUtils");
|
|
56
|
+
const Builtin_1 = require("./Builtin");
|
|
57
|
+
const TSConst_1 = require("./TSConst");
|
|
58
|
+
const builderUtils_1 = require("../model/builder/builderUtils");
|
|
59
|
+
const ArkValueTransformer_1 = require("./ArkValueTransformer");
|
|
60
|
+
const ArkImport_1 = require("../model/ArkImport");
|
|
61
|
+
const TypeInference_1 = require("./TypeInference");
|
|
62
|
+
const TypeExpr_1 = require("../base/TypeExpr");
|
|
63
|
+
class DummyStmt extends Stmt_1.Stmt {
|
|
64
|
+
constructor(text) {
|
|
65
|
+
super();
|
|
66
|
+
this.text = text;
|
|
67
|
+
}
|
|
68
|
+
toString() {
|
|
69
|
+
return this.text;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.DummyStmt = DummyStmt;
|
|
73
|
+
class ArkIRTransformer {
|
|
74
|
+
constructor(sourceFile, declaringMethod) {
|
|
75
|
+
this.inBuilderMethod = false;
|
|
76
|
+
this.builderMethodContextFlag = false;
|
|
77
|
+
this.stmtsHaveOriginalText = new Set();
|
|
78
|
+
this.sourceFile = sourceFile;
|
|
79
|
+
this.declaringMethod = declaringMethod;
|
|
80
|
+
this.inBuilderMethod = ModelUtils_1.ModelUtils.isArkUIBuilderMethod(declaringMethod);
|
|
81
|
+
this.arkValueTransformer = new ArkValueTransformer_1.ArkValueTransformer(this, sourceFile, this.declaringMethod);
|
|
82
|
+
}
|
|
83
|
+
getLocals() {
|
|
84
|
+
return this.arkValueTransformer.getLocals();
|
|
85
|
+
}
|
|
86
|
+
getGlobals() {
|
|
87
|
+
return this.arkValueTransformer.getGlobals();
|
|
88
|
+
}
|
|
89
|
+
getThisLocal() {
|
|
90
|
+
return this.arkValueTransformer.getThisLocal();
|
|
91
|
+
}
|
|
92
|
+
getAliasTypeMap() {
|
|
93
|
+
return this.arkValueTransformer.getAliasTypeMap();
|
|
94
|
+
}
|
|
95
|
+
prebuildStmts() {
|
|
96
|
+
const stmts = [];
|
|
97
|
+
let index = 0;
|
|
98
|
+
for (const methodParameter of this.declaringMethod.getParameters()) {
|
|
99
|
+
const parameterRef = new Ref_1.ArkParameterRef(index, methodParameter.getType());
|
|
100
|
+
stmts.push(new Stmt_1.ArkAssignStmt(this.arkValueTransformer.addNewLocal(methodParameter.getName(), parameterRef.getType()), parameterRef));
|
|
101
|
+
index++;
|
|
102
|
+
}
|
|
103
|
+
const thisRef = new Ref_1.ArkThisRef(this.arkValueTransformer.getThisLocal().getType());
|
|
104
|
+
stmts.push(new Stmt_1.ArkAssignStmt(this.arkValueTransformer.getThisLocal(), thisRef));
|
|
105
|
+
return stmts;
|
|
106
|
+
}
|
|
107
|
+
tsNodeToStmts(node) {
|
|
108
|
+
let stmts = [];
|
|
109
|
+
if (ts.isExpressionStatement(node)) {
|
|
110
|
+
stmts = this.expressionStatementToStmts(node);
|
|
111
|
+
}
|
|
112
|
+
else if (ts.isTypeAliasDeclaration(node)) {
|
|
113
|
+
stmts = this.typeAliasDeclarationToStmts(node);
|
|
114
|
+
}
|
|
115
|
+
else if (ts.isBlock(node)) {
|
|
116
|
+
stmts = this.blockToStmts(node);
|
|
117
|
+
}
|
|
118
|
+
else if (ts.isForStatement(node)) {
|
|
119
|
+
stmts = this.forStatementToStmts(node);
|
|
120
|
+
}
|
|
121
|
+
else if (ts.isForInStatement(node) || ts.isForOfStatement(node)) {
|
|
122
|
+
stmts = this.rangeForStatementToStmts(node);
|
|
123
|
+
}
|
|
124
|
+
else if (ts.isWhileStatement(node)) {
|
|
125
|
+
stmts = this.whileStatementToStmts(node);
|
|
126
|
+
}
|
|
127
|
+
else if (ts.isDoStatement(node)) {
|
|
128
|
+
stmts = this.doStatementToStmts(node);
|
|
129
|
+
}
|
|
130
|
+
else if (ts.isVariableStatement(node)) {
|
|
131
|
+
stmts = this.variableStatementToStmts(node);
|
|
132
|
+
}
|
|
133
|
+
else if (ts.isVariableDeclarationList(node)) {
|
|
134
|
+
stmts = this.variableDeclarationListToStmts(node);
|
|
135
|
+
}
|
|
136
|
+
else if (ts.isIfStatement(node)) {
|
|
137
|
+
stmts = this.ifStatementToStmts(node);
|
|
138
|
+
}
|
|
139
|
+
else if (ts.isBreakStatement(node) || ts.isContinueStatement(node)) {
|
|
140
|
+
stmts = this.gotoStatementToStmts(node);
|
|
141
|
+
}
|
|
142
|
+
else if (ts.isThrowStatement(node)) {
|
|
143
|
+
stmts = this.throwStatementToStmts(node);
|
|
144
|
+
}
|
|
145
|
+
else if (ts.isCatchClause(node)) {
|
|
146
|
+
stmts = this.catchClauseToStmts(node);
|
|
147
|
+
}
|
|
148
|
+
else if (ts.isReturnStatement(node)) {
|
|
149
|
+
stmts = this.returnStatementToStmts(node);
|
|
150
|
+
}
|
|
151
|
+
else if (ts.isFunctionDeclaration(node)) {
|
|
152
|
+
stmts = this.functionDeclarationToStmts(node);
|
|
153
|
+
}
|
|
154
|
+
else if (ts.isExportAssignment(node)) {
|
|
155
|
+
stmts = this.expressionInExportToStmts(node.expression);
|
|
156
|
+
}
|
|
157
|
+
this.mapStmtsToTsStmt(stmts, node);
|
|
158
|
+
if (stmts.length > 0) {
|
|
159
|
+
IRUtils_1.IRUtils.setComments(stmts[0], node, this.sourceFile, this.declaringMethod.getDeclaringArkFile().getScene().getOptions());
|
|
160
|
+
}
|
|
161
|
+
return stmts;
|
|
162
|
+
}
|
|
163
|
+
tsNodeToValueAndStmts(node) {
|
|
164
|
+
return this.arkValueTransformer.tsNodeToValueAndStmts(node);
|
|
165
|
+
}
|
|
166
|
+
functionDeclarationToStmts(functionDeclarationNode) {
|
|
167
|
+
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
168
|
+
const arkMethod = new ArkMethod_1.ArkMethod();
|
|
169
|
+
if (this.builderMethodContextFlag) {
|
|
170
|
+
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arkMethod);
|
|
171
|
+
}
|
|
172
|
+
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionDeclarationNode, declaringClass, arkMethod, this.sourceFile, this.declaringMethod);
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
returnStatementToStmts(returnStatement) {
|
|
176
|
+
const stmts = [];
|
|
177
|
+
if (returnStatement.expression) {
|
|
178
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(returnStatement.expression);
|
|
179
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
180
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
181
|
+
({
|
|
182
|
+
value: exprValue,
|
|
183
|
+
valueOriginalPositions: exprPositions,
|
|
184
|
+
stmts: exprStmts,
|
|
185
|
+
} = this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
186
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
187
|
+
}
|
|
188
|
+
const returnStmt = new Stmt_1.ArkReturnStmt(exprValue);
|
|
189
|
+
returnStmt.setOperandOriginalPositions(exprPositions);
|
|
190
|
+
stmts.push(returnStmt);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
stmts.push(new Stmt_1.ArkReturnVoidStmt());
|
|
194
|
+
}
|
|
195
|
+
return stmts;
|
|
196
|
+
}
|
|
197
|
+
blockToStmts(block) {
|
|
198
|
+
const stmts = [];
|
|
199
|
+
for (const statement of block.statements) {
|
|
200
|
+
this.tsNodeToStmts(statement).forEach(stmt => stmts.push(stmt));
|
|
201
|
+
}
|
|
202
|
+
return stmts;
|
|
203
|
+
}
|
|
204
|
+
expressionStatementToStmts(expressionStatement) {
|
|
205
|
+
const exprNode = expressionStatement.expression;
|
|
206
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts, } = this.tsNodeToValueAndStmts(exprNode);
|
|
207
|
+
if (exprValue instanceof Expr_1.AbstractInvokeExpr) {
|
|
208
|
+
this.addInvokeStmts(exprValue, exprPositions, stmts);
|
|
209
|
+
}
|
|
210
|
+
else if (this.shouldGenerateExtraAssignStmt(exprNode)) {
|
|
211
|
+
const { stmts: exprStmts } = this.generateAssignStmtForValue(exprValue, exprPositions);
|
|
212
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
213
|
+
}
|
|
214
|
+
return stmts;
|
|
215
|
+
}
|
|
216
|
+
addInvokeStmts(invokeExpr, exprPositions, stmts) {
|
|
217
|
+
const invokeStmt = new Stmt_1.ArkInvokeStmt(invokeExpr);
|
|
218
|
+
invokeStmt.setOperandOriginalPositions(exprPositions);
|
|
219
|
+
stmts.push(invokeStmt);
|
|
220
|
+
let hasRepeat = false;
|
|
221
|
+
for (const stmt of stmts) {
|
|
222
|
+
if ((stmt instanceof Stmt_1.ArkAssignStmt) && (stmt.getRightOp() instanceof Expr_1.ArkStaticInvokeExpr)) {
|
|
223
|
+
const rightOp = stmt.getRightOp();
|
|
224
|
+
if (rightOp.getMethodSignature().getMethodSubSignature().getMethodName() === EtsConst_1.COMPONENT_REPEAT) {
|
|
225
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
226
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, rightOp.getArgs());
|
|
227
|
+
stmt.setRightOp(createInvokeExpr);
|
|
228
|
+
hasRepeat = true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (hasRepeat) {
|
|
233
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
234
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
235
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
236
|
+
stmts.push(popInvokeStmt);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
shouldGenerateExtraAssignStmt(expression) {
|
|
240
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
241
|
+
return this.shouldGenerateExtraAssignStmt(expression.expression);
|
|
242
|
+
}
|
|
243
|
+
if ((ts.isBinaryExpression(expression) && (expression.operatorToken.kind === ts.SyntaxKind.FirstAssignment ||
|
|
244
|
+
ArkValueTransformer_1.ArkValueTransformer.isCompoundAssignmentOperator(expression.operatorToken.kind))) ||
|
|
245
|
+
ts.isEtsComponentExpression(expression) || ts.isVoidExpression(expression) ||
|
|
246
|
+
ts.isNewExpression(expression) || ts.isCallExpression(expression) ||
|
|
247
|
+
(ts.isPrefixUnaryExpression(expression) &&
|
|
248
|
+
(expression.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
249
|
+
expression.operator === ts.SyntaxKind.MinusMinusToken)) ||
|
|
250
|
+
(ts.isPostfixUnaryExpression(expression) &&
|
|
251
|
+
(expression.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
252
|
+
expression.operator === ts.SyntaxKind.MinusMinusToken))) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
typeAliasDeclarationToStmts(typeAliasDeclaration) {
|
|
258
|
+
const aliasName = typeAliasDeclaration.name.text;
|
|
259
|
+
const rightOp = typeAliasDeclaration.type;
|
|
260
|
+
let rightType = this.arkValueTransformer.resolveTypeNode(rightOp);
|
|
261
|
+
if (rightType instanceof TypeExpr_1.AbstractTypeExpr) {
|
|
262
|
+
rightType = rightType.getType();
|
|
263
|
+
}
|
|
264
|
+
const aliasType = new Type_1.AliasType(aliasName, rightType, new ArkSignature_1.AliasTypeSignature(aliasName, this.declaringMethod.getSignature()));
|
|
265
|
+
if (typeAliasDeclaration.typeParameters) {
|
|
266
|
+
const genericTypes = (0, builderUtils_1.buildTypeParameters)(typeAliasDeclaration.typeParameters, this.sourceFile, this.declaringMethod);
|
|
267
|
+
aliasType.setGenericTypes(genericTypes);
|
|
268
|
+
aliasType.setOriginalType((0, builderUtils_1.buildGenericType)(rightType, aliasType));
|
|
269
|
+
rightType = aliasType.getOriginalType();
|
|
270
|
+
}
|
|
271
|
+
let expr = this.generateAliasTypeExpr(rightOp, aliasType);
|
|
272
|
+
if ((ts.isTypeQueryNode(rightOp) || ts.isTypeReferenceNode(rightOp)) && rightOp.typeArguments) {
|
|
273
|
+
let realGenericTypes = [];
|
|
274
|
+
rightOp.typeArguments.forEach(typeArgument => {
|
|
275
|
+
realGenericTypes.push(this.arkValueTransformer.resolveTypeNode(typeArgument));
|
|
276
|
+
});
|
|
277
|
+
expr.setRealGenericTypes(realGenericTypes);
|
|
278
|
+
}
|
|
279
|
+
const modifiers = typeAliasDeclaration.modifiers ? (0, builderUtils_1.buildModifiers)(typeAliasDeclaration) : 0;
|
|
280
|
+
aliasType.setModifiers(modifiers);
|
|
281
|
+
const aliasTypeDefineStmt = new Stmt_1.ArkAliasTypeDefineStmt(aliasType, expr);
|
|
282
|
+
const leftPosition = Position_1.FullPosition.buildFromNode(typeAliasDeclaration.name, this.sourceFile);
|
|
283
|
+
const rightPosition = Position_1.FullPosition.buildFromNode(rightOp, this.sourceFile);
|
|
284
|
+
const operandOriginalPositions = [leftPosition, rightPosition];
|
|
285
|
+
aliasTypeDefineStmt.setOperandOriginalPositions(operandOriginalPositions);
|
|
286
|
+
this.getAliasTypeMap().set(aliasName, [aliasType, aliasTypeDefineStmt]);
|
|
287
|
+
return [aliasTypeDefineStmt];
|
|
288
|
+
}
|
|
289
|
+
generateAliasTypeExpr(rightOp, aliasType) {
|
|
290
|
+
var _a;
|
|
291
|
+
let rightType = aliasType.getOriginalType();
|
|
292
|
+
let expr;
|
|
293
|
+
if (ts.isImportTypeNode(rightOp)) {
|
|
294
|
+
expr = this.resolveImportTypeNode(rightOp);
|
|
295
|
+
const typeObject = expr.getOriginalObject();
|
|
296
|
+
if (typeObject instanceof ArkImport_1.ImportInfo && typeObject.getLazyExportInfo() !== null) {
|
|
297
|
+
const arkExport = typeObject.getLazyExportInfo().getArkExport();
|
|
298
|
+
rightType = (_a = TypeInference_1.TypeInference.parseArkExport2Type(arkExport)) !== null && _a !== void 0 ? _a : Type_1.UnknownType.getInstance();
|
|
299
|
+
aliasType.setOriginalType(rightType);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else if (ts.isTypeQueryNode(rightOp)) {
|
|
303
|
+
const localName = rightOp.exprName.getText(this.sourceFile);
|
|
304
|
+
const originalLocal = Array.from(this.arkValueTransformer.getLocals()).find(local => local.getName() === localName);
|
|
305
|
+
if (originalLocal === undefined || rightType instanceof Type_1.UnclearReferenceType) {
|
|
306
|
+
expr = new Expr_1.AliasTypeExpr(new Local_1.Local(localName, rightType), true);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
expr = new Expr_1.AliasTypeExpr(originalLocal, true);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else if (ts.isTypeReferenceNode(rightOp)) {
|
|
313
|
+
// For type A = B<number> stmt and B is also an alias type with the same scope of A,
|
|
314
|
+
// rightType here is AliasType with real generic type number.
|
|
315
|
+
// The originalObject in expr should be the object without real generic type, so try to find it in this scope.
|
|
316
|
+
if (rightType instanceof Type_1.AliasType) {
|
|
317
|
+
const existAliasType = this.getAliasTypeMap().get(rightType.getName());
|
|
318
|
+
if (existAliasType) {
|
|
319
|
+
expr = new Expr_1.AliasTypeExpr(existAliasType[0], false);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
331
|
+
// 对于type A = {x:1, y:2}语句,当前阶段即可精确获取ClassType类型,需找到对应的ArkClass作为originalObject
|
|
332
|
+
// 对于其他情况此处为UnclearReferenceTye并由类型推导进行查找和处理
|
|
333
|
+
if (rightType instanceof Type_1.ClassType) {
|
|
334
|
+
const classObject = ModelUtils_1.ModelUtils.getClassWithName(rightType.getClassSignature().getClassName(), this.declaringMethod.getDeclaringArkClass());
|
|
335
|
+
if (classObject) {
|
|
336
|
+
expr.setOriginalObject(classObject);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return expr;
|
|
341
|
+
}
|
|
342
|
+
resolveImportTypeNode(importTypeNode) {
|
|
343
|
+
const importType = 'typeAliasDefine';
|
|
344
|
+
let importFrom = '';
|
|
345
|
+
let importClauseName = '';
|
|
346
|
+
if (ts.isLiteralTypeNode(importTypeNode.argument)) {
|
|
347
|
+
if (ts.isStringLiteral(importTypeNode.argument.literal)) {
|
|
348
|
+
importFrom = importTypeNode.argument.literal.text;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const importQualifier = importTypeNode.qualifier;
|
|
352
|
+
if (importQualifier !== undefined) {
|
|
353
|
+
importClauseName = importQualifier.getText(this.sourceFile);
|
|
354
|
+
}
|
|
355
|
+
let importInfo = new ArkImport_1.ImportInfo();
|
|
356
|
+
importInfo.build(importClauseName, importType, importFrom, Position_1.LineColPosition.buildFromNode(importTypeNode, this.sourceFile), 0);
|
|
357
|
+
importInfo.setDeclaringArkFile(this.declaringMethod.getDeclaringArkFile());
|
|
358
|
+
// Function getLazyExportInfo will automatically try to infer the export info if it's undefined at the beginning.
|
|
359
|
+
importInfo.getLazyExportInfo();
|
|
360
|
+
return new Expr_1.AliasTypeExpr(importInfo, importTypeNode.isTypeOf);
|
|
361
|
+
}
|
|
362
|
+
switchStatementToValueAndStmts(switchStatement) {
|
|
363
|
+
const valueAndStmtsOfSwitchAndCases = [];
|
|
364
|
+
const exprStmts = [];
|
|
365
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprTempStmts, } = this.tsNodeToValueAndStmts(switchStatement.expression);
|
|
366
|
+
exprTempStmts.forEach(stmt => exprStmts.push(stmt));
|
|
367
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
368
|
+
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprTempStmts } =
|
|
369
|
+
this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
370
|
+
exprTempStmts.forEach(stmt => exprStmts.push(stmt));
|
|
371
|
+
}
|
|
372
|
+
valueAndStmtsOfSwitchAndCases.push({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts });
|
|
373
|
+
for (const clause of switchStatement.caseBlock.clauses) {
|
|
374
|
+
if (ts.isCaseClause(clause)) {
|
|
375
|
+
const clauseStmts = [];
|
|
376
|
+
let { value: clauseValue, valueOriginalPositions: clausePositions, stmts: clauseTempStmts, } = this.tsNodeToValueAndStmts(clause.expression);
|
|
377
|
+
clauseTempStmts.forEach(stmt => clauseStmts.push(stmt));
|
|
378
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(clauseValue)) {
|
|
379
|
+
({
|
|
380
|
+
value: clauseValue,
|
|
381
|
+
valueOriginalPositions: clausePositions,
|
|
382
|
+
stmts: clauseTempStmts,
|
|
383
|
+
} = this.generateAssignStmtForValue(clauseValue, clausePositions));
|
|
384
|
+
clauseTempStmts.forEach(stmt => clauseStmts.push(stmt));
|
|
385
|
+
}
|
|
386
|
+
valueAndStmtsOfSwitchAndCases.push({ value: clauseValue, valueOriginalPositions: clausePositions, stmts: clauseStmts });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return valueAndStmtsOfSwitchAndCases;
|
|
390
|
+
}
|
|
391
|
+
forStatementToStmts(forStatement) {
|
|
392
|
+
const stmts = [];
|
|
393
|
+
if (forStatement.initializer) {
|
|
394
|
+
this.tsNodeToValueAndStmts(forStatement.initializer).stmts.forEach(stmt => stmts.push(stmt));
|
|
395
|
+
}
|
|
396
|
+
const dummyInitializerStmt = new DummyStmt(ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
397
|
+
stmts.push(dummyInitializerStmt);
|
|
398
|
+
if (forStatement.condition) {
|
|
399
|
+
const { value: conditionValue, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(forStatement.condition);
|
|
400
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
401
|
+
stmts.push(new Stmt_1.ArkIfStmt(conditionValue));
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
// The omitted condition always evaluates to true.
|
|
405
|
+
const trueConstant = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
406
|
+
const conditionExpr = new Expr_1.ArkConditionExpr(trueConstant, trueConstant, Expr_1.RelationalBinaryOperator.Equality);
|
|
407
|
+
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
408
|
+
}
|
|
409
|
+
if (forStatement.incrementor) {
|
|
410
|
+
this.tsNodeToValueAndStmts(forStatement.incrementor).stmts.forEach(stmt => stmts.push(stmt));
|
|
411
|
+
}
|
|
412
|
+
return stmts;
|
|
413
|
+
}
|
|
414
|
+
rangeForStatementToStmts(forOfStatement) {
|
|
415
|
+
const stmts = [];
|
|
416
|
+
let { value: iterableValue, valueOriginalPositions: iterablePositions, stmts: iterableStmts, } = this.tsNodeToValueAndStmts(forOfStatement.expression);
|
|
417
|
+
iterableStmts.forEach(stmt => stmts.push(stmt));
|
|
418
|
+
if (!(iterableValue instanceof Local_1.Local)) {
|
|
419
|
+
({ value: iterableValue, valueOriginalPositions: iterablePositions, stmts: iterableStmts } =
|
|
420
|
+
this.generateAssignStmtForValue(iterableValue, iterablePositions));
|
|
421
|
+
iterableStmts.forEach(stmt => stmts.push(stmt));
|
|
422
|
+
}
|
|
423
|
+
const iteratorMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.Builtin.ITERATOR_FUNCTION, [], Builtin_1.Builtin.ITERATOR_CLASS_TYPE);
|
|
424
|
+
const iteratorMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, iteratorMethodSubSignature);
|
|
425
|
+
const iteratorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterableValue, iteratorMethodSignature, []);
|
|
426
|
+
const iteratorInvokeExprPositions = [iterablePositions[0], ...iterablePositions];
|
|
427
|
+
const { value: iterator, valueOriginalPositions: iteratorPositions, stmts: iteratorStmts, } = this.generateAssignStmtForValue(iteratorInvokeExpr, iteratorInvokeExprPositions);
|
|
428
|
+
iteratorStmts.forEach(stmt => stmts.push(stmt));
|
|
429
|
+
iterator.setType(Builtin_1.Builtin.ITERATOR_CLASS_TYPE);
|
|
430
|
+
const nextMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.Builtin.ITERATOR_NEXT, [], Builtin_1.Builtin.ITERATOR_RESULT_CLASS_TYPE);
|
|
431
|
+
const nextMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, nextMethodSubSignature);
|
|
432
|
+
const iteratorNextInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterator, nextMethodSignature, []);
|
|
433
|
+
const iteratorNextInvokeExprPositions = [iteratorPositions[0], ...iteratorPositions];
|
|
434
|
+
const { value: iteratorResult, valueOriginalPositions: iteratorResultPositions, stmts: iteratorResultStmts, } = this.generateAssignStmtForValue(iteratorNextInvokeExpr, iteratorNextInvokeExprPositions);
|
|
435
|
+
iteratorResultStmts.forEach(stmt => stmts.push(stmt));
|
|
436
|
+
iteratorResult.setType(Builtin_1.Builtin.ITERATOR_RESULT_CLASS_TYPE);
|
|
437
|
+
const doneFieldSignature = new ArkSignature_1.FieldSignature(Builtin_1.Builtin.ITERATOR_RESULT_DONE, Builtin_1.Builtin.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.BooleanType.getInstance(), false);
|
|
438
|
+
const doneFieldRef = new Ref_1.ArkInstanceFieldRef(iteratorResult, doneFieldSignature);
|
|
439
|
+
const doneFieldRefPositions = [iteratorResultPositions[0], ...iteratorResultPositions];
|
|
440
|
+
const { value: doneFlag, valueOriginalPositions: doneFlagPositions, stmts: doneFlagStmts, } = this.generateAssignStmtForValue(doneFieldRef, doneFieldRefPositions);
|
|
441
|
+
doneFlagStmts.forEach(stmt => stmts.push(stmt));
|
|
442
|
+
doneFlag.setType(Type_1.BooleanType.getInstance());
|
|
443
|
+
const conditionExpr = new Expr_1.ArkConditionExpr(doneFlag, ValueUtil_1.ValueUtil.getBooleanConstant(true), Expr_1.RelationalBinaryOperator.Equality);
|
|
444
|
+
const conditionExprPositions = [doneFlagPositions[0], ...doneFlagPositions, Position_1.FullPosition.DEFAULT];
|
|
445
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
446
|
+
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
447
|
+
stmts.push(ifStmt);
|
|
448
|
+
const valueFieldSignature = new ArkSignature_1.FieldSignature(Builtin_1.Builtin.ITERATOR_RESULT_VALUE, Builtin_1.Builtin.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.UnknownType.getInstance(), false);
|
|
449
|
+
const valueFieldRef = new Ref_1.ArkInstanceFieldRef(iteratorResult, valueFieldSignature);
|
|
450
|
+
const valueFieldRefPositions = [iteratorResultPositions[0], ...iteratorResultPositions];
|
|
451
|
+
const { value: yieldValue, valueOriginalPositions: yieldValuePositions, stmts: yieldValueStmts, } = this.generateAssignStmtForValue(valueFieldRef, valueFieldRefPositions);
|
|
452
|
+
yieldValueStmts.forEach(stmt => stmts.push(stmt));
|
|
453
|
+
const castExpr = new Expr_1.ArkCastExpr(yieldValue, Type_1.UnknownType.getInstance());
|
|
454
|
+
const castExprPositions = [yieldValuePositions[0], ...yieldValuePositions];
|
|
455
|
+
const initializerNode = forOfStatement.initializer;
|
|
456
|
+
if (ts.isVariableDeclarationList(initializerNode)) {
|
|
457
|
+
const isConst = (initializerNode.flags & ts.NodeFlags.Const) !== 0;
|
|
458
|
+
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.arkValueTransformer.variableDeclarationToValueAndStmts(initializerNode.declarations[0], isConst, false);
|
|
459
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
460
|
+
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
461
|
+
stmts.push(assignStmt);
|
|
462
|
+
initStmts.forEach(stmt => stmts.push(stmt));
|
|
463
|
+
}
|
|
464
|
+
else { // initializer maybe an expression
|
|
465
|
+
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.tsNodeToValueAndStmts(initializerNode);
|
|
466
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
467
|
+
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
468
|
+
initStmts.forEach(stmt => stmts.push(stmt));
|
|
469
|
+
stmts.push(assignStmt);
|
|
470
|
+
}
|
|
471
|
+
return stmts;
|
|
472
|
+
}
|
|
473
|
+
whileStatementToStmts(whileStatement) {
|
|
474
|
+
const stmts = [];
|
|
475
|
+
const dummyInitializerStmt = new DummyStmt(ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
476
|
+
stmts.push(dummyInitializerStmt);
|
|
477
|
+
const { value: conditionExpr, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(whileStatement.expression);
|
|
478
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
479
|
+
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
480
|
+
return stmts;
|
|
481
|
+
}
|
|
482
|
+
doStatementToStmts(doStatement) {
|
|
483
|
+
const stmts = [];
|
|
484
|
+
const { value: conditionExpr, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(doStatement.expression);
|
|
485
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
486
|
+
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
487
|
+
return stmts;
|
|
488
|
+
}
|
|
489
|
+
variableStatementToStmts(variableStatement) {
|
|
490
|
+
return this.variableDeclarationListToStmts(variableStatement.declarationList);
|
|
491
|
+
}
|
|
492
|
+
variableDeclarationListToStmts(variableDeclarationList) {
|
|
493
|
+
return this.arkValueTransformer.variableDeclarationListToValueAndStmts(variableDeclarationList).stmts;
|
|
494
|
+
}
|
|
495
|
+
ifStatementToStmts(ifStatement) {
|
|
496
|
+
const stmts = [];
|
|
497
|
+
if (this.inBuilderMethod) {
|
|
498
|
+
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(ifStatement.expression);
|
|
499
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
500
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
501
|
+
const { value: conditionLocal, valueOriginalPositions: conditionLocalPositions, stmts: assignConditionStmts } = this.generateAssignStmtForValue(conditionExpr, conditionExprPositions);
|
|
502
|
+
assignConditionStmts.forEach(stmt => stmts.push(stmt));
|
|
503
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, [conditionLocal]);
|
|
504
|
+
const createInvokeExprPositions = [conditionLocalPositions[0], ...conditionLocalPositions];
|
|
505
|
+
const { stmts: createStmts } = this.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
506
|
+
createStmts.forEach(stmt => stmts.push(stmt));
|
|
507
|
+
const branchMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_BRANCH_FUNCTION);
|
|
508
|
+
const branchInvokeExpr = new Expr_1.ArkStaticInvokeExpr(branchMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(0)]);
|
|
509
|
+
const branchInvokeExprPositions = [conditionLocalPositions[0], Position_1.FullPosition.DEFAULT];
|
|
510
|
+
const branchInvokeStmt = new Stmt_1.ArkInvokeStmt(branchInvokeExpr);
|
|
511
|
+
branchInvokeStmt.setOperandOriginalPositions(branchInvokeExprPositions);
|
|
512
|
+
stmts.push(branchInvokeStmt);
|
|
513
|
+
this.tsNodeToStmts(ifStatement.thenStatement).forEach(stmt => stmts.push(stmt));
|
|
514
|
+
if (ifStatement.elseStatement) {
|
|
515
|
+
const branchElseMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_BRANCH_FUNCTION);
|
|
516
|
+
const branchElseInvokeExpr = new Expr_1.ArkStaticInvokeExpr(branchElseMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(1)]);
|
|
517
|
+
const branchElseInvokeExprPositions = [Position_1.FullPosition.buildFromNode(ifStatement.elseStatement, this.sourceFile), Position_1.FullPosition.DEFAULT];
|
|
518
|
+
const branchElseInvokeStmt = new Stmt_1.ArkInvokeStmt(branchElseInvokeExpr);
|
|
519
|
+
branchElseInvokeStmt.setOperandOriginalPositions(branchElseInvokeExprPositions);
|
|
520
|
+
stmts.push(branchElseInvokeStmt);
|
|
521
|
+
this.tsNodeToStmts(ifStatement.elseStatement).forEach(stmt => stmts.push(stmt));
|
|
522
|
+
}
|
|
523
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
524
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
525
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
526
|
+
stmts.push(popInvokeStmt);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts, } = this.arkValueTransformer.conditionToValueAndStmts(ifStatement.expression);
|
|
530
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
531
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
532
|
+
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
533
|
+
stmts.push(ifStmt);
|
|
534
|
+
}
|
|
535
|
+
return stmts;
|
|
536
|
+
}
|
|
537
|
+
gotoStatementToStmts(gotoStatement) {
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
throwStatementToStmts(throwStatement) {
|
|
541
|
+
const stmts = [];
|
|
542
|
+
const { value: throwValue, valueOriginalPositions: throwValuePositions, stmts: throwStmts, } = this.tsNodeToValueAndStmts(throwStatement.expression);
|
|
543
|
+
throwStmts.forEach(stmt => stmts.push(stmt));
|
|
544
|
+
const throwStmt = new Stmt_1.ArkThrowStmt(throwValue);
|
|
545
|
+
throwStmt.setOperandOriginalPositions(throwValuePositions);
|
|
546
|
+
stmts.push(throwStmt);
|
|
547
|
+
return stmts;
|
|
548
|
+
}
|
|
549
|
+
catchClauseToStmts(catchClause) {
|
|
550
|
+
const stmts = [];
|
|
551
|
+
if (catchClause.variableDeclaration) {
|
|
552
|
+
const { value: catchValue, valueOriginalPositions: catchOriPos, stmts: catchStmts, } = this.arkValueTransformer.variableDeclarationToValueAndStmts(catchClause.variableDeclaration, false, false);
|
|
553
|
+
const caughtExceptionRef = new Ref_1.ArkCaughtExceptionRef(Type_1.UnknownType.getInstance());
|
|
554
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(catchValue, caughtExceptionRef);
|
|
555
|
+
assignStmt.setOperandOriginalPositions(catchOriPos);
|
|
556
|
+
stmts.push(assignStmt);
|
|
557
|
+
catchStmts.forEach(stmt => stmts.push(stmt));
|
|
558
|
+
}
|
|
559
|
+
return stmts;
|
|
560
|
+
}
|
|
561
|
+
expressionInExportToStmts(expression) {
|
|
562
|
+
if (ts.isNewExpression(expression) || ts.isObjectLiteralExpression(expression)) {
|
|
563
|
+
return this.newClassInExportToStmts(expression);
|
|
564
|
+
}
|
|
565
|
+
return [];
|
|
566
|
+
}
|
|
567
|
+
newClassInExportToStmts(expression) {
|
|
568
|
+
let stmts = [];
|
|
569
|
+
let { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToValueAndStmts(expression);
|
|
570
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
571
|
+
let leftValue = this.arkValueTransformer.addNewLocal(TSConst_1.DEFAULT);
|
|
572
|
+
let leftPositions = rightPositions;
|
|
573
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
574
|
+
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
575
|
+
stmts.push(assignStmt);
|
|
576
|
+
return stmts;
|
|
577
|
+
}
|
|
578
|
+
mapStmtsToTsStmt(stmts, node) {
|
|
579
|
+
for (const stmt of stmts) {
|
|
580
|
+
if (!this.stmtsHaveOriginalText.has(stmt)) {
|
|
581
|
+
this.stmtsHaveOriginalText.add(stmt);
|
|
582
|
+
stmt.setOriginPositionInfo(Position_1.LineColPosition.buildFromNode(node, this.sourceFile));
|
|
583
|
+
stmt.setOriginalText(node.getText(this.sourceFile));
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
static tokenToUnaryOperator(token) {
|
|
588
|
+
switch (token) {
|
|
589
|
+
case ts.SyntaxKind.MinusToken:
|
|
590
|
+
return Expr_1.UnaryOperator.Neg;
|
|
591
|
+
case ts.SyntaxKind.TildeToken:
|
|
592
|
+
return Expr_1.UnaryOperator.BitwiseNot;
|
|
593
|
+
case ts.SyntaxKind.ExclamationToken:
|
|
594
|
+
return Expr_1.UnaryOperator.LogicalNot;
|
|
595
|
+
default:
|
|
596
|
+
;
|
|
597
|
+
}
|
|
598
|
+
return null;
|
|
599
|
+
}
|
|
600
|
+
static tokenToBinaryOperator(token) {
|
|
601
|
+
switch (token) {
|
|
602
|
+
case ts.SyntaxKind.QuestionQuestionToken:
|
|
603
|
+
return Expr_1.NormalBinaryOperator.NullishCoalescing;
|
|
604
|
+
case ts.SyntaxKind.AsteriskAsteriskToken:
|
|
605
|
+
return Expr_1.NormalBinaryOperator.Exponentiation;
|
|
606
|
+
case ts.SyntaxKind.SlashToken:
|
|
607
|
+
return Expr_1.NormalBinaryOperator.Division;
|
|
608
|
+
case ts.SyntaxKind.PlusToken:
|
|
609
|
+
return Expr_1.NormalBinaryOperator.Addition;
|
|
610
|
+
case ts.SyntaxKind.MinusToken:
|
|
611
|
+
return Expr_1.NormalBinaryOperator.Subtraction;
|
|
612
|
+
case ts.SyntaxKind.AsteriskToken:
|
|
613
|
+
return Expr_1.NormalBinaryOperator.Multiplication;
|
|
614
|
+
case ts.SyntaxKind.PercentToken:
|
|
615
|
+
return Expr_1.NormalBinaryOperator.Remainder;
|
|
616
|
+
case ts.SyntaxKind.LessThanLessThanToken:
|
|
617
|
+
return Expr_1.NormalBinaryOperator.LeftShift;
|
|
618
|
+
case ts.SyntaxKind.GreaterThanGreaterThanToken:
|
|
619
|
+
return Expr_1.NormalBinaryOperator.RightShift;
|
|
620
|
+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
|
|
621
|
+
return Expr_1.NormalBinaryOperator.UnsignedRightShift;
|
|
622
|
+
case ts.SyntaxKind.AmpersandToken:
|
|
623
|
+
return Expr_1.NormalBinaryOperator.BitwiseAnd;
|
|
624
|
+
case ts.SyntaxKind.BarToken:
|
|
625
|
+
return Expr_1.NormalBinaryOperator.BitwiseOr;
|
|
626
|
+
case ts.SyntaxKind.CaretToken:
|
|
627
|
+
return Expr_1.NormalBinaryOperator.BitwiseXor;
|
|
628
|
+
case ts.SyntaxKind.AmpersandAmpersandToken:
|
|
629
|
+
return Expr_1.NormalBinaryOperator.LogicalAnd;
|
|
630
|
+
case ts.SyntaxKind.BarBarToken:
|
|
631
|
+
return Expr_1.NormalBinaryOperator.LogicalOr;
|
|
632
|
+
case ts.SyntaxKind.LessThanToken:
|
|
633
|
+
return Expr_1.RelationalBinaryOperator.LessThan;
|
|
634
|
+
case ts.SyntaxKind.LessThanEqualsToken:
|
|
635
|
+
return Expr_1.RelationalBinaryOperator.LessThanOrEqual;
|
|
636
|
+
case ts.SyntaxKind.GreaterThanToken:
|
|
637
|
+
return Expr_1.RelationalBinaryOperator.GreaterThan;
|
|
638
|
+
case ts.SyntaxKind.GreaterThanEqualsToken:
|
|
639
|
+
return Expr_1.RelationalBinaryOperator.GreaterThanOrEqual;
|
|
640
|
+
case ts.SyntaxKind.EqualsEqualsToken:
|
|
641
|
+
return Expr_1.RelationalBinaryOperator.Equality;
|
|
642
|
+
case ts.SyntaxKind.ExclamationEqualsToken:
|
|
643
|
+
return Expr_1.RelationalBinaryOperator.InEquality;
|
|
644
|
+
case ts.SyntaxKind.EqualsEqualsEqualsToken:
|
|
645
|
+
return Expr_1.RelationalBinaryOperator.StrictEquality;
|
|
646
|
+
case ts.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
647
|
+
return Expr_1.RelationalBinaryOperator.StrictInequality;
|
|
648
|
+
default:
|
|
649
|
+
;
|
|
650
|
+
}
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
generateAssignStmtForValue(value, valueOriginalPositions) {
|
|
654
|
+
const leftOp = this.arkValueTransformer.generateTempLocal(value.getType());
|
|
655
|
+
const leftOpPosition = valueOriginalPositions[0];
|
|
656
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftOp, value);
|
|
657
|
+
assignStmt.setOperandOriginalPositions([leftOpPosition, ...valueOriginalPositions]);
|
|
658
|
+
return { value: leftOp, valueOriginalPositions: [leftOpPosition], stmts: [assignStmt] };
|
|
659
|
+
}
|
|
660
|
+
generateIfStmtForValues(leftValue, leftOpOriginalPositions, rightValue, rightOpOriginalPositions) {
|
|
661
|
+
const stmts = [];
|
|
662
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue)) {
|
|
663
|
+
const { value: tempLeftValue, valueOriginalPositions: tempLeftPositions, stmts: leftStmts, } = this.generateAssignStmtForValue(leftValue, leftOpOriginalPositions);
|
|
664
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
665
|
+
leftValue = tempLeftValue;
|
|
666
|
+
leftOpOriginalPositions = tempLeftPositions;
|
|
667
|
+
}
|
|
668
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
669
|
+
const { value: tempRightValue, valueOriginalPositions: tempRightPositions, stmts: rightStmts, } = this.generateAssignStmtForValue(rightValue, rightOpOriginalPositions);
|
|
670
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
671
|
+
rightValue = tempRightValue;
|
|
672
|
+
rightOpOriginalPositions = tempRightPositions;
|
|
673
|
+
}
|
|
674
|
+
const conditionExpr = new Expr_1.ArkConditionExpr(leftValue, rightValue, Expr_1.RelationalBinaryOperator.Equality);
|
|
675
|
+
const conditionPositions = [...leftOpOriginalPositions, ...rightOpOriginalPositions];
|
|
676
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
677
|
+
ifStmt.setOperandOriginalPositions([...conditionPositions]);
|
|
678
|
+
stmts.push(ifStmt);
|
|
679
|
+
return stmts;
|
|
680
|
+
}
|
|
681
|
+
setBuilderMethodContextFlag(builderMethodContextFlag) {
|
|
682
|
+
this.builderMethodContextFlag = builderMethodContextFlag;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
exports.ArkIRTransformer = ArkIRTransformer;
|
|
686
|
+
ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT = 'LoopInitializer';
|
|
687
|
+
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR = 'ConditionalOperator';
|
|
688
|
+
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'IfTrue';
|
|
689
|
+
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'IfFalse';
|
|
690
|
+
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT = ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR + 'End';
|