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,1478 +1,1478 @@
|
|
|
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.ArkValueTransformer = void 0;
|
|
41
|
-
const ts = __importStar(require("ohos-typescript"));
|
|
42
|
-
const Local_1 = require("../base/Local");
|
|
43
|
-
const Position_1 = require("../base/Position");
|
|
44
|
-
const Stmt_1 = require("../base/Stmt");
|
|
45
|
-
const Expr_1 = require("../base/Expr");
|
|
46
|
-
const ArkClass_1 = require("../model/ArkClass");
|
|
47
|
-
const ArkClassBuilder_1 = require("../model/builder/ArkClassBuilder");
|
|
48
|
-
const Type_1 = require("../base/Type");
|
|
49
|
-
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
50
|
-
const TSConst_1 = require("./TSConst");
|
|
51
|
-
const ArkSignature_1 = require("../model/ArkSignature");
|
|
52
|
-
const EtsConst_1 = require("./EtsConst");
|
|
53
|
-
const ValueUtil_1 = require("./ValueUtil");
|
|
54
|
-
const IRUtils_1 = require("./IRUtils");
|
|
55
|
-
const Ref_1 = require("../base/Ref");
|
|
56
|
-
const ModelUtils_1 = require("./ModelUtils");
|
|
57
|
-
const ArkMethod_1 = require("../model/ArkMethod");
|
|
58
|
-
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
59
|
-
const Builtin_1 = require("./Builtin");
|
|
60
|
-
const Constant_1 = require("../base/Constant");
|
|
61
|
-
const Const_1 = require("./Const");
|
|
62
|
-
const ArkIRTransformer_1 = require("./ArkIRTransformer");
|
|
63
|
-
const logger_1 = __importStar(require("../../utils/logger"));
|
|
64
|
-
const TypeInference_1 = require("./TypeInference");
|
|
65
|
-
const TypeExpr_1 = require("../base/TypeExpr");
|
|
66
|
-
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkValueTransformer');
|
|
67
|
-
class ArkValueTransformer {
|
|
68
|
-
constructor(arkIRTransformer, sourceFile, declaringMethod) {
|
|
69
|
-
this.conditionalOperatorNo = 0;
|
|
70
|
-
this.tempLocalNo = 0;
|
|
71
|
-
this.locals = new Map();
|
|
72
|
-
this.aliasTypeMap = new Map();
|
|
73
|
-
this.builderMethodContextFlag = false;
|
|
74
|
-
this.arkIRTransformer = arkIRTransformer;
|
|
75
|
-
this.sourceFile = sourceFile;
|
|
76
|
-
this.thisLocal = new Local_1.Local(TSConst_1.THIS_NAME, declaringMethod.getDeclaringArkClass().getSignature().getType());
|
|
77
|
-
this.locals.set(this.thisLocal.getName(), this.thisLocal);
|
|
78
|
-
this.declaringMethod = declaringMethod;
|
|
79
|
-
}
|
|
80
|
-
getLocals() {
|
|
81
|
-
return new Set(this.locals.values());
|
|
82
|
-
}
|
|
83
|
-
getThisLocal() {
|
|
84
|
-
return this.thisLocal;
|
|
85
|
-
}
|
|
86
|
-
getAliasTypeMap() {
|
|
87
|
-
return this.aliasTypeMap;
|
|
88
|
-
}
|
|
89
|
-
addNewLocal(localName, localType = Type_1.UnknownType.getInstance()) {
|
|
90
|
-
let local = new Local_1.Local(localName, localType);
|
|
91
|
-
this.locals.set(localName, local);
|
|
92
|
-
return local;
|
|
93
|
-
}
|
|
94
|
-
getGlobals() {
|
|
95
|
-
var _a;
|
|
96
|
-
return (_a = this.globals) !== null && _a !== void 0 ? _a : null;
|
|
97
|
-
}
|
|
98
|
-
addNewGlobal(name, ref) {
|
|
99
|
-
var _a;
|
|
100
|
-
let globalRef = new Ref_1.GlobalRef(name, ref);
|
|
101
|
-
this.globals = (_a = this.globals) !== null && _a !== void 0 ? _a : new Map();
|
|
102
|
-
this.globals.set(name, globalRef);
|
|
103
|
-
return globalRef;
|
|
104
|
-
}
|
|
105
|
-
tsNodeToValueAndStmts(node) {
|
|
106
|
-
if (ts.isBinaryExpression(node)) {
|
|
107
|
-
return this.binaryExpressionToValueAndStmts(node);
|
|
108
|
-
}
|
|
109
|
-
else if (ts.isCallExpression(node)) {
|
|
110
|
-
return this.callExpressionToValueAndStmts(node);
|
|
111
|
-
}
|
|
112
|
-
else if (ts.isVariableDeclarationList(node)) {
|
|
113
|
-
return this.variableDeclarationListToValueAndStmts(node);
|
|
114
|
-
}
|
|
115
|
-
else if (ts.isIdentifier(node)) {
|
|
116
|
-
return this.identifierToValueAndStmts(node);
|
|
117
|
-
}
|
|
118
|
-
else if (ts.isPropertyAccessExpression(node)) {
|
|
119
|
-
return this.propertyAccessExpressionToValue(node);
|
|
120
|
-
}
|
|
121
|
-
else if (ts.isPrefixUnaryExpression(node)) {
|
|
122
|
-
return this.prefixUnaryExpressionToValueAndStmts(node);
|
|
123
|
-
}
|
|
124
|
-
else if (ts.isPostfixUnaryExpression(node)) {
|
|
125
|
-
return this.postfixUnaryExpressionToValueAndStmts(node);
|
|
126
|
-
}
|
|
127
|
-
else if (ts.isTemplateExpression(node)) {
|
|
128
|
-
return this.templateExpressionToValueAndStmts(node);
|
|
129
|
-
}
|
|
130
|
-
else if (ts.isTaggedTemplateExpression(node)) {
|
|
131
|
-
return this.taggedTemplateExpressionToValueAndStmts(node);
|
|
132
|
-
}
|
|
133
|
-
else if (ts.isAwaitExpression(node)) {
|
|
134
|
-
return this.awaitExpressionToValueAndStmts(node);
|
|
135
|
-
}
|
|
136
|
-
else if (ts.isYieldExpression(node)) {
|
|
137
|
-
return this.yieldExpressionToValueAndStmts(node);
|
|
138
|
-
}
|
|
139
|
-
else if (ts.isDeleteExpression(node)) {
|
|
140
|
-
return this.deleteExpressionToValueAndStmts(node);
|
|
141
|
-
}
|
|
142
|
-
else if (ts.isVoidExpression(node)) {
|
|
143
|
-
return this.voidExpressionToValueAndStmts(node);
|
|
144
|
-
}
|
|
145
|
-
else if (ts.isElementAccessExpression(node)) {
|
|
146
|
-
return this.elementAccessExpressionToValueAndStmts(node);
|
|
147
|
-
}
|
|
148
|
-
else if (ts.isNewExpression(node)) {
|
|
149
|
-
return this.newExpressionToValueAndStmts(node);
|
|
150
|
-
}
|
|
151
|
-
else if (ts.isParenthesizedExpression(node)) {
|
|
152
|
-
return this.parenthesizedExpressionToValueAndStmts(node);
|
|
153
|
-
}
|
|
154
|
-
else if (ts.isAsExpression(node)) {
|
|
155
|
-
return this.asExpressionToValueAndStmts(node);
|
|
156
|
-
}
|
|
157
|
-
else if (ts.isNonNullExpression(node)) {
|
|
158
|
-
return this.nonNullExpressionToValueAndStmts(node);
|
|
159
|
-
}
|
|
160
|
-
else if (ts.isTypeAssertionExpression(node)) {
|
|
161
|
-
return this.typeAssertionToValueAndStmts(node);
|
|
162
|
-
}
|
|
163
|
-
else if (ts.isTypeOfExpression(node)) {
|
|
164
|
-
return this.typeOfExpressionToValueAndStmts(node);
|
|
165
|
-
}
|
|
166
|
-
else if (ts.isArrayLiteralExpression(node)) {
|
|
167
|
-
return this.arrayLiteralExpressionToValueAndStmts(node);
|
|
168
|
-
}
|
|
169
|
-
else if (this.isLiteralNode(node)) {
|
|
170
|
-
return this.literalNodeToValueAndStmts(node);
|
|
171
|
-
}
|
|
172
|
-
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
173
|
-
return this.callableNodeToValueAndStmts(node);
|
|
174
|
-
}
|
|
175
|
-
else if (ts.isClassExpression(node)) {
|
|
176
|
-
return this.classExpressionToValueAndStmts(node);
|
|
177
|
-
}
|
|
178
|
-
else if (ts.isEtsComponentExpression(node)) {
|
|
179
|
-
return this.etsComponentExpressionToValueAndStmts(node);
|
|
180
|
-
}
|
|
181
|
-
else if (ts.isObjectLiteralExpression(node)) {
|
|
182
|
-
return this.objectLiteralExpresionToValueAndStmts(node);
|
|
183
|
-
}
|
|
184
|
-
else if (node.kind === ts.SyntaxKind.ThisKeyword) {
|
|
185
|
-
return this.thisExpressionToValueAndStmts(node);
|
|
186
|
-
}
|
|
187
|
-
else if (ts.isConditionalExpression(node)) {
|
|
188
|
-
return this.conditionalExpressionToValueAndStmts(node);
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
value: new Local_1.Local(node.getText(this.sourceFile)),
|
|
192
|
-
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(node, this.sourceFile)],
|
|
193
|
-
stmts: [],
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
tsNodeToSingleAddressValueAndStmts(node) {
|
|
197
|
-
const allStmts = [];
|
|
198
|
-
let { value, valueOriginalPositions, stmts } = this.tsNodeToValueAndStmts(node);
|
|
199
|
-
stmts.forEach(stmt => allStmts.push(stmt));
|
|
200
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(value)) {
|
|
201
|
-
({ value, valueOriginalPositions, stmts } =
|
|
202
|
-
this.arkIRTransformer.generateAssignStmtForValue(value, valueOriginalPositions));
|
|
203
|
-
stmts.forEach(stmt => allStmts.push(stmt));
|
|
204
|
-
}
|
|
205
|
-
return { value, valueOriginalPositions, stmts: allStmts };
|
|
206
|
-
}
|
|
207
|
-
thisExpressionToValueAndStmts(thisExpression) {
|
|
208
|
-
return {
|
|
209
|
-
value: this.getThisLocal(),
|
|
210
|
-
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(thisExpression, this.sourceFile)],
|
|
211
|
-
stmts: [],
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
conditionalExpressionToValueAndStmts(conditionalExpression) {
|
|
215
|
-
const stmts = [];
|
|
216
|
-
const currConditionalOperatorIndex = this.conditionalOperatorNo++;
|
|
217
|
-
const { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
218
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
219
|
-
const ifStmt = new Stmt_1.ArkIfStmt(conditionValue);
|
|
220
|
-
ifStmt.setOperandOriginalPositions(conditionPositions);
|
|
221
|
-
stmts.push(ifStmt);
|
|
222
|
-
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT + currConditionalOperatorIndex));
|
|
223
|
-
const { value: whenTrueValue, valueOriginalPositions: whenTruePositions, stmts: whenTrueStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenTrue);
|
|
224
|
-
whenTrueStmts.forEach(stmt => stmts.push(stmt));
|
|
225
|
-
const resultLocal = this.generateTempLocal();
|
|
226
|
-
const assignStmtWhenTrue = new Stmt_1.ArkAssignStmt(resultLocal, whenTrueValue);
|
|
227
|
-
const resultLocalPosition = [whenTruePositions[0]];
|
|
228
|
-
assignStmtWhenTrue.setOperandOriginalPositions([...resultLocalPosition, ...whenTruePositions]);
|
|
229
|
-
stmts.push(assignStmtWhenTrue);
|
|
230
|
-
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorIndex));
|
|
231
|
-
const { value: whenFalseValue, valueOriginalPositions: whenFalsePositions, stmts: whenFalseStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenFalse);
|
|
232
|
-
whenFalseStmts.forEach(stmt => stmts.push(stmt));
|
|
233
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(resultLocal, whenFalseValue);
|
|
234
|
-
assignStmt.setOperandOriginalPositions([...resultLocalPosition, ...whenFalsePositions]);
|
|
235
|
-
stmts.push(assignStmt);
|
|
236
|
-
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT + currConditionalOperatorIndex));
|
|
237
|
-
return { value: resultLocal, valueOriginalPositions: resultLocalPosition, stmts: stmts };
|
|
238
|
-
}
|
|
239
|
-
objectLiteralExpresionToValueAndStmts(objectLiteralExpression) {
|
|
240
|
-
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
241
|
-
const declaringArkNamespace = declaringArkClass.getDeclaringArkNamespace();
|
|
242
|
-
const anonymousClass = new ArkClass_1.ArkClass();
|
|
243
|
-
if (declaringArkNamespace) {
|
|
244
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(objectLiteralExpression, declaringArkNamespace, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
245
|
-
declaringArkNamespace.addArkClass(anonymousClass);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
const declaringArkFile = declaringArkClass.getDeclaringArkFile();
|
|
249
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(objectLiteralExpression, declaringArkFile, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
250
|
-
declaringArkFile.addArkClass(anonymousClass);
|
|
251
|
-
}
|
|
252
|
-
const objectLiteralExpressionPosition = Position_1.FullPosition.buildFromNode(objectLiteralExpression, this.sourceFile);
|
|
253
|
-
const stmts = [];
|
|
254
|
-
const anonymousClassSignature = anonymousClass.getSignature();
|
|
255
|
-
const anonymousClassType = new Type_1.ClassType(anonymousClassSignature);
|
|
256
|
-
const newExpr = new Expr_1.ArkNewExpr(anonymousClassType);
|
|
257
|
-
const { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [objectLiteralExpressionPosition]);
|
|
258
|
-
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
259
|
-
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
260
|
-
const constructorMethodSignature = new ArkSignature_1.MethodSignature(anonymousClassSignature, constructorMethodSubSignature);
|
|
261
|
-
const constructorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, []);
|
|
262
|
-
const constructorInvokeExprPositions = [objectLiteralExpressionPosition, ...newExprLocalPositions];
|
|
263
|
-
const constructorInvokeStmt = new Stmt_1.ArkInvokeStmt(constructorInvokeExpr);
|
|
264
|
-
constructorInvokeStmt.setOperandOriginalPositions(constructorInvokeExprPositions);
|
|
265
|
-
stmts.push(constructorInvokeStmt);
|
|
266
|
-
return { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: stmts };
|
|
267
|
-
}
|
|
268
|
-
generateSystemComponentStmt(componentName, args, argPositionsAllFlat, componentExpression, currStmts) {
|
|
269
|
-
const stmts = [...currStmts];
|
|
270
|
-
const componentExpressionPosition = Position_1.FullPosition.buildFromNode(componentExpression, this.sourceFile);
|
|
271
|
-
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(componentName, args, componentExpressionPosition, argPositionsAllFlat);
|
|
272
|
-
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
273
|
-
if (ts.isEtsComponentExpression(componentExpression) && componentExpression.body) {
|
|
274
|
-
for (const statement of componentExpression.body.statements) {
|
|
275
|
-
this.arkIRTransformer.tsNodeToStmts(statement).forEach(stmt => stmts.push(stmt));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
stmts.push(this.generateComponentPopStmts(componentName, componentExpressionPosition));
|
|
279
|
-
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: stmts };
|
|
280
|
-
}
|
|
281
|
-
generateCustomViewStmt(componentName, args, argPositionsAllFlat, componentExpression, currStmts) {
|
|
282
|
-
const stmts = [...currStmts];
|
|
283
|
-
const componentExpressionPosition = Position_1.FullPosition.buildFromNode(componentExpression, this.sourceFile);
|
|
284
|
-
const classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(componentName);
|
|
285
|
-
const classType = new Type_1.ClassType(classSignature);
|
|
286
|
-
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
287
|
-
const { value: newExprLocal, valueOriginalPositions: newExprPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [componentExpressionPosition]);
|
|
288
|
-
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
289
|
-
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
290
|
-
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
291
|
-
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, args);
|
|
292
|
-
const instanceInvokeExprPositions = [componentExpressionPosition, ...newExprPositions, ...argPositionsAllFlat];
|
|
293
|
-
const instanceInvokeStmt = new Stmt_1.ArkInvokeStmt(instanceInvokeExpr);
|
|
294
|
-
instanceInvokeStmt.setOperandOriginalPositions(instanceInvokeExprPositions);
|
|
295
|
-
stmts.push(instanceInvokeStmt);
|
|
296
|
-
const createViewArgs = [newExprLocal];
|
|
297
|
-
const createViewArgPositionsAll = [newExprPositions];
|
|
298
|
-
if (ts.isEtsComponentExpression(componentExpression) && componentExpression.body) {
|
|
299
|
-
const anonymous = ts.factory.createArrowFunction([], [], [], undefined, undefined, componentExpression.body);
|
|
300
|
-
// @ts-expect-error: add pos info for the created ArrowFunction
|
|
301
|
-
anonymous.pos = componentExpression.body.pos;
|
|
302
|
-
// @ts-expect-error: add end info for the created ArrowFunction
|
|
303
|
-
anonymous.end = componentExpression.body.end;
|
|
304
|
-
const { value: builderMethod, valueOriginalPositions: builderMethodPositions, } = this.callableNodeToValueAndStmts(anonymous);
|
|
305
|
-
createViewArgs.push(builderMethod);
|
|
306
|
-
createViewArgPositionsAll.push(builderMethodPositions);
|
|
307
|
-
}
|
|
308
|
-
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, createViewArgs, componentExpressionPosition, createViewArgPositionsAll.flat());
|
|
309
|
-
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
310
|
-
stmts.push(this.generateComponentPopStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, componentExpressionPosition));
|
|
311
|
-
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: stmts };
|
|
312
|
-
}
|
|
313
|
-
generateComponentCreationStmts(componentName, createArgs, componentExpressionPosition, createArgsPositionsAllFlat) {
|
|
314
|
-
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
315
|
-
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, createArgs);
|
|
316
|
-
const createInvokeExprPositions = [componentExpressionPosition, ...createArgsPositionsAllFlat];
|
|
317
|
-
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.arkIRTransformer.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
318
|
-
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts };
|
|
319
|
-
}
|
|
320
|
-
generateComponentPopStmts(componentName, componentExpressionPosition) {
|
|
321
|
-
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
322
|
-
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
323
|
-
const popInvokeExprPositions = [componentExpressionPosition];
|
|
324
|
-
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
325
|
-
popInvokeStmt.setOperandOriginalPositions(popInvokeExprPositions);
|
|
326
|
-
return popInvokeStmt;
|
|
327
|
-
}
|
|
328
|
-
etsComponentExpressionToValueAndStmts(etsComponentExpression) {
|
|
329
|
-
const stmts = [];
|
|
330
|
-
const componentName = etsComponentExpression.expression.text;
|
|
331
|
-
const { args: args, argPositions: argPositions } = this.parseArguments(stmts, etsComponentExpression.arguments);
|
|
332
|
-
if ((0, EtsConst_1.isEtsSystemComponent)(componentName)) {
|
|
333
|
-
return this.generateSystemComponentStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
334
|
-
}
|
|
335
|
-
return this.generateCustomViewStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
336
|
-
}
|
|
337
|
-
classExpressionToValueAndStmts(classExpression) {
|
|
338
|
-
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
339
|
-
const declaringArkNamespace = declaringArkClass.getDeclaringArkNamespace();
|
|
340
|
-
const newClass = new ArkClass_1.ArkClass();
|
|
341
|
-
if (declaringArkNamespace) {
|
|
342
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression, declaringArkNamespace, newClass, this.sourceFile, this.declaringMethod);
|
|
343
|
-
declaringArkNamespace.addArkClass(newClass);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
const declaringArkFile = declaringArkClass.getDeclaringArkFile();
|
|
347
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, declaringArkFile, newClass, this.sourceFile, this.declaringMethod);
|
|
348
|
-
declaringArkFile.addArkClass(newClass);
|
|
349
|
-
}
|
|
350
|
-
const classValue = this.addNewLocal(newClass.getName(), new Type_1.ClassType(newClass.getSignature()));
|
|
351
|
-
return {
|
|
352
|
-
value: classValue,
|
|
353
|
-
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(classExpression, this.sourceFile)],
|
|
354
|
-
stmts: [],
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
templateExpressionToValueAndStmts(templateExpression) {
|
|
358
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(templateExpression);
|
|
359
|
-
const { placeholderStringLocals, placeholderStringLocalPositions, newStmts } = this.processTemplatePlaceholders(placeholderValues, placeholderPositions, stmts);
|
|
360
|
-
return this.combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, newStmts);
|
|
361
|
-
}
|
|
362
|
-
processTemplatePlaceholders(placeholderValues, placeholderPositions, currStmts) {
|
|
363
|
-
const placeholderStringLocals = [];
|
|
364
|
-
const placeholderStringLocalPositions = [];
|
|
365
|
-
const newStmts = [...currStmts];
|
|
366
|
-
for (let i = 0; i < placeholderValues.length; i++) {
|
|
367
|
-
let placeholderValue = placeholderValues[i];
|
|
368
|
-
let placeholderPosition = [placeholderPositions[i]];
|
|
369
|
-
let placeholderStmts = [];
|
|
370
|
-
if (!(placeholderValue instanceof Local_1.Local)) {
|
|
371
|
-
({ value: placeholderValue, valueOriginalPositions: placeholderPosition, stmts: placeholderStmts } =
|
|
372
|
-
this.arkIRTransformer.generateAssignStmtForValue(placeholderValue, placeholderPosition));
|
|
373
|
-
}
|
|
374
|
-
placeholderStmts.forEach(stmt => newStmts.push(stmt));
|
|
375
|
-
const toStringExpr = new Expr_1.ArkInstanceInvokeExpr(placeholderValue, Builtin_1.Builtin.TO_STRING_METHOD_SIGNATURE, []);
|
|
376
|
-
const toStringExprPosition = [placeholderPosition[0], placeholderPosition[0]];
|
|
377
|
-
const { value: placeholderStringLocal, valueOriginalPositions: placeholderStringPositions, stmts: toStringStmts, } = this.arkIRTransformer.generateAssignStmtForValue(toStringExpr, toStringExprPosition);
|
|
378
|
-
placeholderStringLocals.push(placeholderStringLocal);
|
|
379
|
-
placeholderStringLocalPositions.push(placeholderStringPositions[0]);
|
|
380
|
-
toStringStmts.forEach(stmt => newStmts.push(stmt));
|
|
381
|
-
}
|
|
382
|
-
return { placeholderStringLocals, placeholderStringLocalPositions, newStmts };
|
|
383
|
-
}
|
|
384
|
-
combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, currStmts) {
|
|
385
|
-
const templateParts = [];
|
|
386
|
-
const templatePartPositions = [];
|
|
387
|
-
for (let i = 0; i < placeholderStringLocals.length; i++) {
|
|
388
|
-
if (stringTextValues[i] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
389
|
-
templateParts.push(stringTextValues[i]);
|
|
390
|
-
templatePartPositions.push(stringTextPositions[i]);
|
|
391
|
-
}
|
|
392
|
-
templateParts.push(placeholderStringLocals[i]);
|
|
393
|
-
templatePartPositions.push(placeholderStringLocalPositions[i]);
|
|
394
|
-
}
|
|
395
|
-
if (stringTextValues[stringTextValues.length - 1] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
396
|
-
templateParts.push(stringTextValues[stringTextValues.length - 1]);
|
|
397
|
-
templatePartPositions.push(stringTextPositions[stringTextPositions.length - 1]);
|
|
398
|
-
}
|
|
399
|
-
let currTemplateResult = templateParts[0];
|
|
400
|
-
let currTemplateResultPosition = templatePartPositions[0];
|
|
401
|
-
const finalStmts = [...currStmts];
|
|
402
|
-
for (let i = 1; i < templateParts.length; i++) {
|
|
403
|
-
const nextTemplatePartPosition = templatePartPositions[i];
|
|
404
|
-
const normalBinopExpr = new Expr_1.ArkNormalBinopExpr(currTemplateResult, templateParts[i], Expr_1.NormalBinaryOperator.Addition);
|
|
405
|
-
const normalBinopExprPositions = [Position_1.FullPosition.merge(currTemplateResultPosition, nextTemplatePartPosition),
|
|
406
|
-
currTemplateResultPosition, nextTemplatePartPosition];
|
|
407
|
-
const { value: combinationValue, valueOriginalPositions: combinationValuePositions, stmts: combinationStmts, } = this.arkIRTransformer.generateAssignStmtForValue(normalBinopExpr, normalBinopExprPositions);
|
|
408
|
-
combinationStmts.forEach(stmt => finalStmts.push(stmt));
|
|
409
|
-
currTemplateResult = combinationValue;
|
|
410
|
-
currTemplateResultPosition = combinationValuePositions[0];
|
|
411
|
-
}
|
|
412
|
-
return { value: currTemplateResult, valueOriginalPositions: [currTemplateResultPosition], stmts: finalStmts };
|
|
413
|
-
}
|
|
414
|
-
taggedTemplateExpressionToValueAndStmts(taggedTemplateExpression) {
|
|
415
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions, } = this.collectTemplateValues(taggedTemplateExpression.template);
|
|
416
|
-
const stringTextBaseType = Type_1.StringType.getInstance();
|
|
417
|
-
const stringTextArrayLen = stringTextValues.length;
|
|
418
|
-
const stringTextArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(stringTextArrayLen);
|
|
419
|
-
const stringTextArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
420
|
-
const { value: templateObjectLocal, valueOriginalPositions: templateObjectLocalPositions, stmts: templateObjectStmts, } = this.generateArrayExprAndStmts(stringTextBaseType, stringTextArrayLenValue, stringTextArrayLenPosition, stringTextArrayLen, stringTextValues, stringTextPositions, stmts, Position_1.FullPosition.DEFAULT, true);
|
|
421
|
-
const placeholderBaseType = Type_1.AnyType.getInstance();
|
|
422
|
-
const placeholdersArrayLen = placeholderValues.length;
|
|
423
|
-
const placeholdersArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(placeholdersArrayLen);
|
|
424
|
-
const placeholdersArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
425
|
-
const { value: placeholdersLocal, valueOriginalPositions: placeholdersLocalPositions, stmts: placeholdersStmts, } = this.generateArrayExprAndStmts(placeholderBaseType, placeholdersArrayLenValue, placeholdersArrayLenPosition, placeholdersArrayLen, placeholderValues, placeholderPositions, templateObjectStmts, Position_1.FullPosition.DEFAULT, true);
|
|
426
|
-
const taggedFuncArgus = {
|
|
427
|
-
realGenericTypes: undefined, args: [templateObjectLocal, placeholdersLocal],
|
|
428
|
-
argPositions: [templateObjectLocalPositions[0], placeholdersLocalPositions[0]],
|
|
429
|
-
};
|
|
430
|
-
return this.generateInvokeValueAndStmts(taggedTemplateExpression.tag, taggedFuncArgus, placeholdersStmts, taggedTemplateExpression);
|
|
431
|
-
}
|
|
432
|
-
collectTemplateValues(templateLiteral) {
|
|
433
|
-
const stmts = [];
|
|
434
|
-
if (ts.isNoSubstitutionTemplateLiteral(templateLiteral)) {
|
|
435
|
-
const templateLiteralString = templateLiteral.getText(this.sourceFile);
|
|
436
|
-
return {
|
|
437
|
-
stmts: [], stringTextValues: [ValueUtil_1.ValueUtil.createStringConst(templateLiteralString)],
|
|
438
|
-
placeholderValues: [],
|
|
439
|
-
stringTextPositions: [Position_1.FullPosition.buildFromNode(templateLiteral, this.sourceFile)],
|
|
440
|
-
placeholderPositions: [],
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
const head = templateLiteral.head;
|
|
444
|
-
const stringTextValues = [ValueUtil_1.ValueUtil.createStringConst(head.rawText || '')];
|
|
445
|
-
const placeholderValues = [];
|
|
446
|
-
const stringTextPositions = [Position_1.FullPosition.buildFromNode(head, this.sourceFile)];
|
|
447
|
-
const placeholderPositions = [];
|
|
448
|
-
for (const templateSpan of templateLiteral.templateSpans) {
|
|
449
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(templateSpan.expression);
|
|
450
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
451
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
452
|
-
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
453
|
-
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
454
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
455
|
-
}
|
|
456
|
-
placeholderValues.push(exprValue);
|
|
457
|
-
placeholderPositions.push(exprPositions[0]);
|
|
458
|
-
stringTextPositions.push(Position_1.FullPosition.buildFromNode(templateSpan.literal, this.sourceFile));
|
|
459
|
-
stringTextValues.push(ValueUtil_1.ValueUtil.createStringConst(templateSpan.literal.rawText || ''));
|
|
460
|
-
}
|
|
461
|
-
return { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions };
|
|
462
|
-
}
|
|
463
|
-
identifierToValueAndStmts(identifier, variableDefFlag = false) {
|
|
464
|
-
let identifierValue;
|
|
465
|
-
let identifierPositions = [Position_1.FullPosition.buildFromNode(identifier, this.sourceFile)];
|
|
466
|
-
if (identifier.text === Type_1.UndefinedType.getInstance().getName()) {
|
|
467
|
-
identifierValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
if (variableDefFlag) {
|
|
471
|
-
identifierValue = this.addNewLocal(identifier.text);
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
identifierValue = this.getOrCreateLocal(identifier.text);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return { value: identifierValue, valueOriginalPositions: identifierPositions, stmts: [] };
|
|
478
|
-
}
|
|
479
|
-
propertyAccessExpressionToValue(propertyAccessExpression) {
|
|
480
|
-
const stmts = [];
|
|
481
|
-
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts, } = this.tsNodeToValueAndStmts(propertyAccessExpression.expression);
|
|
482
|
-
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
483
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(baseValue)) {
|
|
484
|
-
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
485
|
-
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
486
|
-
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
487
|
-
}
|
|
488
|
-
if (!(baseValue instanceof Local_1.Local)) {
|
|
489
|
-
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
490
|
-
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
491
|
-
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
492
|
-
}
|
|
493
|
-
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(propertyAccessExpression.name.getText(this.sourceFile));
|
|
494
|
-
const fieldRef = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature);
|
|
495
|
-
const fieldRefPositions = [Position_1.FullPosition.buildFromNode(propertyAccessExpression, this.sourceFile), ...basePositions];
|
|
496
|
-
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
497
|
-
}
|
|
498
|
-
elementAccessExpressionToValueAndStmts(elementAccessExpression) {
|
|
499
|
-
const stmts = [];
|
|
500
|
-
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
501
|
-
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
502
|
-
if (!(baseValue instanceof Local_1.Local)) {
|
|
503
|
-
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
504
|
-
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
505
|
-
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
506
|
-
}
|
|
507
|
-
let { value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts, } = this.tsNodeToValueAndStmts(elementAccessExpression.argumentExpression);
|
|
508
|
-
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
509
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(argumentValue)) {
|
|
510
|
-
({ value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts } =
|
|
511
|
-
this.arkIRTransformer.generateAssignStmtForValue(argumentValue, arguPositions));
|
|
512
|
-
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
513
|
-
}
|
|
514
|
-
let elementAccessExpr;
|
|
515
|
-
if (baseValue.getType() instanceof Type_1.ArrayType) {
|
|
516
|
-
elementAccessExpr = new Ref_1.ArkArrayRef(baseValue, argumentValue);
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
// TODO: deal with ArkStaticFieldRef
|
|
520
|
-
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(argumentValue.toString());
|
|
521
|
-
elementAccessExpr = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature);
|
|
522
|
-
}
|
|
523
|
-
// reserve positions for field name
|
|
524
|
-
const exprPositions = [Position_1.FullPosition.buildFromNode(elementAccessExpression, this.sourceFile), ...basePositions,
|
|
525
|
-
...arguPositions];
|
|
526
|
-
return { value: elementAccessExpr, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
527
|
-
}
|
|
528
|
-
callExpressionToValueAndStmts(callExpression) {
|
|
529
|
-
const stmts = [];
|
|
530
|
-
const argus = this.parseArgumentsOfCallExpression(stmts, callExpression);
|
|
531
|
-
return this.generateInvokeValueAndStmts(callExpression.expression, argus, stmts, callExpression);
|
|
532
|
-
}
|
|
533
|
-
generateInvokeValueAndStmts(functionNameNode, argus, currStmts, callExpression) {
|
|
534
|
-
const stmts = [...currStmts];
|
|
535
|
-
let { value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts, } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
536
|
-
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
537
|
-
let invokeValue;
|
|
538
|
-
let invokeValuePositions = [Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile)];
|
|
539
|
-
const { args, argPositions, realGenericTypes } = argus;
|
|
540
|
-
if (callerValue instanceof Ref_1.ArkInstanceFieldRef) {
|
|
541
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
542
|
-
invokeValue = new Expr_1.ArkInstanceInvokeExpr(callerValue.getBase(), methodSignature, args, realGenericTypes);
|
|
543
|
-
invokeValuePositions.push(...callerPositions.slice(1), ...argPositions);
|
|
544
|
-
}
|
|
545
|
-
else if (callerValue instanceof Ref_1.ArkStaticFieldRef) {
|
|
546
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
547
|
-
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
548
|
-
invokeValuePositions.push(...argPositions);
|
|
549
|
-
}
|
|
550
|
-
else if (callerValue instanceof Local_1.Local) {
|
|
551
|
-
const callerName = callerValue.getName();
|
|
552
|
-
let classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(callerName);
|
|
553
|
-
let cls = ModelUtils_1.ModelUtils.getClass(this.declaringMethod, classSignature);
|
|
554
|
-
if ((cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) && ts.isCallExpression(callExpression)) {
|
|
555
|
-
return this.generateCustomViewStmt(callerName, args, argPositions, callExpression, stmts);
|
|
556
|
-
}
|
|
557
|
-
else if ((callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) &&
|
|
558
|
-
ts.isCallExpression(callExpression)) { // foreach/lazyforeach will be parsed as ts.callExpression
|
|
559
|
-
return this.generateSystemComponentStmt(callerName, args, argPositions, callExpression, stmts);
|
|
560
|
-
}
|
|
561
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerName);
|
|
562
|
-
if (callerValue.getType() instanceof Type_1.FunctionType) {
|
|
563
|
-
invokeValue = new Expr_1.ArkPtrInvokeExpr(methodSignature, callerValue, args, realGenericTypes);
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
567
|
-
}
|
|
568
|
-
invokeValuePositions.push(...argPositions);
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
({ value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts } =
|
|
572
|
-
this.arkIRTransformer.generateAssignStmtForValue(callerValue, callerPositions));
|
|
573
|
-
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
574
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getName());
|
|
575
|
-
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
576
|
-
invokeValuePositions.push(...argPositions);
|
|
577
|
-
}
|
|
578
|
-
return { value: invokeValue, valueOriginalPositions: invokeValuePositions, stmts: stmts };
|
|
579
|
-
}
|
|
580
|
-
parseArgumentsOfCallExpression(currStmts, callExpression) {
|
|
581
|
-
let realGenericTypes;
|
|
582
|
-
if (callExpression.typeArguments) {
|
|
583
|
-
realGenericTypes = [];
|
|
584
|
-
callExpression.typeArguments.forEach(typeArgument => {
|
|
585
|
-
realGenericTypes.push(this.resolveTypeNode(typeArgument));
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
let builderMethodIndexes;
|
|
589
|
-
if (ts.isIdentifier(callExpression.expression)) {
|
|
590
|
-
const callerName = callExpression.expression.text;
|
|
591
|
-
if (callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) {
|
|
592
|
-
builderMethodIndexes = new Set([1]);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
const { args: args, argPositions: argPositions } = this.parseArguments(currStmts, callExpression.arguments, builderMethodIndexes);
|
|
596
|
-
return { realGenericTypes: realGenericTypes, args: args, argPositions: argPositions };
|
|
597
|
-
}
|
|
598
|
-
parseArguments(currStmts, argumentNodes, builderMethodIndexes) {
|
|
599
|
-
const args = [];
|
|
600
|
-
const argPositions = [];
|
|
601
|
-
if (argumentNodes) {
|
|
602
|
-
for (let i = 0; i < argumentNodes.length; i++) {
|
|
603
|
-
const argument = argumentNodes[i];
|
|
604
|
-
const prevBuilderMethodContextFlag = this.builderMethodContextFlag;
|
|
605
|
-
if (builderMethodIndexes === null || builderMethodIndexes === void 0 ? void 0 : builderMethodIndexes.has(i)) {
|
|
606
|
-
this.builderMethodContextFlag = true;
|
|
607
|
-
this.arkIRTransformer.setBuilderMethodContextFlag(true);
|
|
608
|
-
}
|
|
609
|
-
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts, } = this.tsNodeToValueAndStmts(argument);
|
|
610
|
-
this.builderMethodContextFlag = prevBuilderMethodContextFlag;
|
|
611
|
-
this.arkIRTransformer.setBuilderMethodContextFlag(prevBuilderMethodContextFlag);
|
|
612
|
-
argStmts.forEach(s => currStmts.push(s));
|
|
613
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(argValue)) {
|
|
614
|
-
({ value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts } =
|
|
615
|
-
this.arkIRTransformer.generateAssignStmtForValue(argValue, argPositionsSingle));
|
|
616
|
-
argStmts.forEach(s => currStmts.push(s));
|
|
617
|
-
}
|
|
618
|
-
args.push(argValue);
|
|
619
|
-
argPositions.push(argPositionsSingle[0]);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
return { args: args, argPositions: argPositions };
|
|
623
|
-
}
|
|
624
|
-
callableNodeToValueAndStmts(callableNode) {
|
|
625
|
-
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
626
|
-
const arrowArkMethod = new ArkMethod_1.ArkMethod();
|
|
627
|
-
if (this.builderMethodContextFlag) {
|
|
628
|
-
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arrowArkMethod);
|
|
629
|
-
}
|
|
630
|
-
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(callableNode, declaringClass, arrowArkMethod, this.sourceFile, this.declaringMethod);
|
|
631
|
-
const callableType = new Type_1.FunctionType(arrowArkMethod.getSignature());
|
|
632
|
-
const callableValue = this.addNewLocal(arrowArkMethod.getName(), callableType);
|
|
633
|
-
return {
|
|
634
|
-
value: callableValue,
|
|
635
|
-
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(callableNode, this.sourceFile)],
|
|
636
|
-
stmts: [],
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
newExpressionToValueAndStmts(newExpression) {
|
|
640
|
-
let className = '';
|
|
641
|
-
if (ts.isClassExpression(newExpression.expression) && newExpression.expression.name) {
|
|
642
|
-
className = newExpression.expression.name.text;
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
className = newExpression.expression.getText(this.sourceFile);
|
|
646
|
-
}
|
|
647
|
-
if (className === Builtin_1.Builtin.ARRAY) {
|
|
648
|
-
return this.newArrayExpressionToValueAndStmts(newExpression);
|
|
649
|
-
}
|
|
650
|
-
const stmts = [];
|
|
651
|
-
let realGenericTypes;
|
|
652
|
-
if (newExpression.typeArguments) {
|
|
653
|
-
realGenericTypes = [];
|
|
654
|
-
newExpression.typeArguments.forEach(typeArgument => {
|
|
655
|
-
realGenericTypes.push(this.resolveTypeNode(typeArgument));
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
const classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(className);
|
|
659
|
-
const classType = new Type_1.ClassType(classSignature, realGenericTypes);
|
|
660
|
-
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
661
|
-
const { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [Position_1.FullPosition.buildFromNode(newExpression, this.sourceFile)]);
|
|
662
|
-
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
663
|
-
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
664
|
-
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
665
|
-
const { args: argValues, argPositions: argPositions } = this.parseArguments(stmts, newExpression.arguments);
|
|
666
|
-
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newLocal, constructorMethodSignature, argValues);
|
|
667
|
-
const instanceInvokeExprPositions = [newLocalPositions[0], ...newLocalPositions, ...argPositions];
|
|
668
|
-
const invokeStmt = new Stmt_1.ArkInvokeStmt(instanceInvokeExpr);
|
|
669
|
-
invokeStmt.setOperandOriginalPositions(instanceInvokeExprPositions);
|
|
670
|
-
stmts.push(invokeStmt);
|
|
671
|
-
return { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: stmts };
|
|
672
|
-
}
|
|
673
|
-
newArrayExpressionToValueAndStmts(newArrayExpression) {
|
|
674
|
-
let baseType = Type_1.UnknownType.getInstance();
|
|
675
|
-
if (newArrayExpression.typeArguments && newArrayExpression.typeArguments.length > 0) {
|
|
676
|
-
const argumentType = this.resolveTypeNode(newArrayExpression.typeArguments[0]);
|
|
677
|
-
if (!(argumentType instanceof Type_1.AnyType || argumentType instanceof Type_1.UnknownType)) {
|
|
678
|
-
baseType = argumentType;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
const stmts = [];
|
|
682
|
-
const { args: argumentValues, argPositions: argPositions } = this.parseArguments(stmts, newArrayExpression.arguments);
|
|
683
|
-
let argumentsLength = newArrayExpression.arguments ? newArrayExpression.arguments.length : 0;
|
|
684
|
-
let arrayLengthValue;
|
|
685
|
-
let arrayLength = -1;
|
|
686
|
-
let arrayLengthPosition = Position_1.FullPosition.DEFAULT;
|
|
687
|
-
if ((argumentsLength === 1) &&
|
|
688
|
-
((argumentValues[0].getType() instanceof Type_1.NumberType) || argumentValues[0].getType() instanceof
|
|
689
|
-
Type_1.UnknownType)) {
|
|
690
|
-
arrayLengthValue = argumentValues[0];
|
|
691
|
-
arrayLengthPosition = argPositions[0];
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
arrayLengthValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(argumentsLength);
|
|
695
|
-
arrayLength = argumentsLength;
|
|
696
|
-
}
|
|
697
|
-
if (baseType instanceof Type_1.UnknownType) {
|
|
698
|
-
if ((argumentsLength > 1) && !(argumentValues[0].getType() instanceof Type_1.UnknownType)) {
|
|
699
|
-
baseType = argumentValues[0].getType();
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
baseType = Type_1.AnyType.getInstance();
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(newArrayExpression, this.sourceFile);
|
|
706
|
-
return this.generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, argumentValues, argPositions, stmts, newArrayExprPosition, false);
|
|
707
|
-
}
|
|
708
|
-
arrayLiteralExpressionToValueAndStmts(arrayLiteralExpression) {
|
|
709
|
-
const stmts = [];
|
|
710
|
-
const elementTypes = new Set();
|
|
711
|
-
const elementValues = [];
|
|
712
|
-
const elementPositions = [];
|
|
713
|
-
const arrayLength = arrayLiteralExpression.elements.length;
|
|
714
|
-
for (const element of arrayLiteralExpression.elements) {
|
|
715
|
-
let { value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts, } = this.tsNodeToValueAndStmts(element);
|
|
716
|
-
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
717
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(elementValue)) {
|
|
718
|
-
({ value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts } =
|
|
719
|
-
this.arkIRTransformer.generateAssignStmtForValue(elementValue, elementPosition));
|
|
720
|
-
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
721
|
-
}
|
|
722
|
-
elementValues.push(elementValue);
|
|
723
|
-
elementTypes.add(elementValue.getType());
|
|
724
|
-
elementPositions.push(elementPosition[0]);
|
|
725
|
-
}
|
|
726
|
-
let baseType = Type_1.AnyType.getInstance();
|
|
727
|
-
if (elementTypes.size === 1) {
|
|
728
|
-
baseType = elementTypes.keys().next().value;
|
|
729
|
-
}
|
|
730
|
-
else if (elementTypes.size > 1) {
|
|
731
|
-
baseType = new Type_1.UnionType(Array.from(elementTypes));
|
|
732
|
-
}
|
|
733
|
-
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(arrayLiteralExpression, this.sourceFile);
|
|
734
|
-
return this.generateArrayExprAndStmts(baseType, ValueUtil_1.ValueUtil.getOrCreateNumberConst(arrayLength), Position_1.FullPosition.DEFAULT, arrayLength, elementValues, elementPositions, stmts, newArrayExprPosition, true);
|
|
735
|
-
}
|
|
736
|
-
generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, initializerValues, initializerPositions, currStmts, newArrayExprPosition, fromLiteral) {
|
|
737
|
-
const stmts = [...currStmts];
|
|
738
|
-
const newArrayExpr = new Expr_1.ArkNewArrayExpr(baseType, arrayLengthValue, fromLiteral);
|
|
739
|
-
const newArrayExprPositions = [newArrayExprPosition, arrayLengthPosition];
|
|
740
|
-
const { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: arrayStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newArrayExpr, newArrayExprPositions);
|
|
741
|
-
arrayStmts.forEach(stmt => stmts.push(stmt));
|
|
742
|
-
for (let i = 0; i < arrayLength; i++) {
|
|
743
|
-
const indexValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(i);
|
|
744
|
-
const arrayRef = new Ref_1.ArkArrayRef(arrayLocal, indexValue);
|
|
745
|
-
const arrayRefPositions = [arrayLocalPositions[0], ...arrayLocalPositions, Position_1.FullPosition.DEFAULT];
|
|
746
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(arrayRef, initializerValues[i]);
|
|
747
|
-
assignStmt.setOperandOriginalPositions([...arrayRefPositions, initializerPositions[i]]);
|
|
748
|
-
stmts.push(assignStmt);
|
|
749
|
-
}
|
|
750
|
-
return { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: stmts };
|
|
751
|
-
}
|
|
752
|
-
prefixUnaryExpressionToValueAndStmts(prefixUnaryExpression) {
|
|
753
|
-
const stmts = [];
|
|
754
|
-
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts, } = this.tsNodeToValueAndStmts(prefixUnaryExpression.operand);
|
|
755
|
-
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
756
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
757
|
-
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts } =
|
|
758
|
-
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
759
|
-
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
760
|
-
}
|
|
761
|
-
const operatorToken = prefixUnaryExpression.operator;
|
|
762
|
-
let exprPositions = [Position_1.FullPosition.buildFromNode(prefixUnaryExpression, this.sourceFile)];
|
|
763
|
-
if (operatorToken === ts.SyntaxKind.PlusPlusToken || operatorToken === ts.SyntaxKind.MinusMinusToken) {
|
|
764
|
-
const binaryOperator = operatorToken === ts.SyntaxKind.PlusPlusToken ? Expr_1.NormalBinaryOperator.Addition : Expr_1.NormalBinaryOperator.Subtraction;
|
|
765
|
-
const binopExpr = new Expr_1.ArkNormalBinopExpr(operandValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(1), binaryOperator);
|
|
766
|
-
exprPositions.push(...operandPositions, Position_1.FullPosition.DEFAULT);
|
|
767
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(operandValue, binopExpr);
|
|
768
|
-
assignStmt.setOperandOriginalPositions([...operandPositions, ...exprPositions]);
|
|
769
|
-
stmts.push(assignStmt);
|
|
770
|
-
return { value: operandValue, valueOriginalPositions: operandPositions, stmts: stmts };
|
|
771
|
-
}
|
|
772
|
-
else if (operatorToken === ts.SyntaxKind.PlusToken) {
|
|
773
|
-
return { value: operandValue, valueOriginalPositions: operandPositions, stmts: stmts };
|
|
774
|
-
}
|
|
775
|
-
else {
|
|
776
|
-
let unopExpr;
|
|
777
|
-
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToUnaryOperator(operatorToken);
|
|
778
|
-
if (operator) {
|
|
779
|
-
unopExpr = new Expr_1.ArkUnopExpr(operandValue, operator);
|
|
780
|
-
exprPositions.push(...operandPositions);
|
|
781
|
-
}
|
|
782
|
-
else {
|
|
783
|
-
unopExpr = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
784
|
-
exprPositions = [Position_1.FullPosition.DEFAULT];
|
|
785
|
-
}
|
|
786
|
-
return { value: unopExpr, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
postfixUnaryExpressionToValueAndStmts(postfixUnaryExpression) {
|
|
790
|
-
const stmts = [];
|
|
791
|
-
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(postfixUnaryExpression.operand);
|
|
792
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
793
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
794
|
-
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts } =
|
|
795
|
-
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
796
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
797
|
-
}
|
|
798
|
-
let value;
|
|
799
|
-
let exprPositions = [Position_1.FullPosition.buildFromNode(postfixUnaryExpression, this.sourceFile)];
|
|
800
|
-
const operatorToken = postfixUnaryExpression.operator;
|
|
801
|
-
if (operatorToken === ts.SyntaxKind.PlusPlusToken || operatorToken === ts.SyntaxKind.MinusMinusToken) {
|
|
802
|
-
const binaryOperator = operatorToken === ts.SyntaxKind.PlusPlusToken ? Expr_1.NormalBinaryOperator.Addition : Expr_1.NormalBinaryOperator.Subtraction;
|
|
803
|
-
const binopExpr = new Expr_1.ArkNormalBinopExpr(operandValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(1), binaryOperator);
|
|
804
|
-
exprPositions.push(...operandPositions, Position_1.FullPosition.DEFAULT);
|
|
805
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(operandValue, binopExpr);
|
|
806
|
-
assignStmt.setOperandOriginalPositions([...operandPositions, ...exprPositions]);
|
|
807
|
-
stmts.push(assignStmt);
|
|
808
|
-
value = operandValue;
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
value = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
812
|
-
exprPositions = [Position_1.FullPosition.DEFAULT];
|
|
813
|
-
}
|
|
814
|
-
return { value: value, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
815
|
-
}
|
|
816
|
-
awaitExpressionToValueAndStmts(awaitExpression) {
|
|
817
|
-
const stmts = [];
|
|
818
|
-
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts, } = this.tsNodeToValueAndStmts(awaitExpression.expression);
|
|
819
|
-
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
820
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(promiseValue)) {
|
|
821
|
-
({ value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts } =
|
|
822
|
-
this.arkIRTransformer.generateAssignStmtForValue(promiseValue, promisePositions));
|
|
823
|
-
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
824
|
-
}
|
|
825
|
-
const awaitExpr = new Expr_1.ArkAwaitExpr(promiseValue);
|
|
826
|
-
const awaitExprPositions = [Position_1.FullPosition.buildFromNode(awaitExpression, this.sourceFile), ...promisePositions];
|
|
827
|
-
return { value: awaitExpr, valueOriginalPositions: awaitExprPositions, stmts: stmts };
|
|
828
|
-
}
|
|
829
|
-
yieldExpressionToValueAndStmts(yieldExpression) {
|
|
830
|
-
let yieldValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
831
|
-
let yieldPositions = [Position_1.FullPosition.DEFAULT];
|
|
832
|
-
let stmts = [];
|
|
833
|
-
if (yieldExpression.expression) {
|
|
834
|
-
({ value: yieldValue, valueOriginalPositions: yieldPositions, stmts: stmts } =
|
|
835
|
-
this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
836
|
-
}
|
|
837
|
-
const yieldExpr = new Expr_1.ArkYieldExpr(yieldValue);
|
|
838
|
-
const yieldExprPositions = [Position_1.FullPosition.buildFromNode(yieldExpression, this.sourceFile), ...yieldPositions];
|
|
839
|
-
return { value: yieldExpr, valueOriginalPositions: yieldExprPositions, stmts: stmts };
|
|
840
|
-
}
|
|
841
|
-
deleteExpressionToValueAndStmts(deleteExpression) {
|
|
842
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(deleteExpression.expression);
|
|
843
|
-
const deleteExpr = new Expr_1.ArkDeleteExpr(exprValue);
|
|
844
|
-
const deleteExprPositions = [Position_1.FullPosition.buildFromNode(deleteExpression, this.sourceFile),
|
|
845
|
-
...exprPositions];
|
|
846
|
-
return { value: deleteExpr, valueOriginalPositions: deleteExprPositions, stmts: stmts };
|
|
847
|
-
}
|
|
848
|
-
voidExpressionToValueAndStmts(voidExpression) {
|
|
849
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(voidExpression.expression);
|
|
850
|
-
const { stmts: exprStmts } = this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions);
|
|
851
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
852
|
-
return { value: ValueUtil_1.ValueUtil.getUndefinedConst(), valueOriginalPositions: [Position_1.FullPosition.DEFAULT], stmts: stmts };
|
|
853
|
-
}
|
|
854
|
-
nonNullExpressionToValueAndStmts(nonNullExpression) {
|
|
855
|
-
return this.tsNodeToValueAndStmts(nonNullExpression.expression);
|
|
856
|
-
}
|
|
857
|
-
parenthesizedExpressionToValueAndStmts(parenthesizedExpression) {
|
|
858
|
-
return this.tsNodeToValueAndStmts(parenthesizedExpression.expression);
|
|
859
|
-
}
|
|
860
|
-
typeOfExpressionToValueAndStmts(typeOfExpression) {
|
|
861
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(typeOfExpression.expression);
|
|
862
|
-
const typeOfExpr = new Expr_1.ArkTypeOfExpr(exprValue);
|
|
863
|
-
const typeOfExprPositions = [Position_1.FullPosition.buildFromNode(typeOfExpression, this.sourceFile), ...exprPositions];
|
|
864
|
-
return { value: typeOfExpr, valueOriginalPositions: typeOfExprPositions, stmts: exprStmts };
|
|
865
|
-
}
|
|
866
|
-
asExpressionToValueAndStmts(asExpression) {
|
|
867
|
-
const stmts = [];
|
|
868
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(asExpression.expression);
|
|
869
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
870
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
871
|
-
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
872
|
-
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
873
|
-
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
874
|
-
}
|
|
875
|
-
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(asExpression.type));
|
|
876
|
-
const castExprPositions = [Position_1.FullPosition.buildFromNode(asExpression, this.sourceFile), ...exprPositions];
|
|
877
|
-
return { value: castExpr, valueOriginalPositions: castExprPositions, stmts: stmts };
|
|
878
|
-
}
|
|
879
|
-
typeAssertionToValueAndStmts(typeAssertion) {
|
|
880
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(typeAssertion.expression);
|
|
881
|
-
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(typeAssertion.type));
|
|
882
|
-
const castExprPositions = [Position_1.FullPosition.buildFromNode(typeAssertion, this.sourceFile), ...exprPositions];
|
|
883
|
-
return { value: castExpr, valueOriginalPositions: castExprPositions, stmts: exprStmts };
|
|
884
|
-
}
|
|
885
|
-
variableDeclarationListToValueAndStmts(variableDeclarationList) {
|
|
886
|
-
const stmts = [];
|
|
887
|
-
const isConst = (variableDeclarationList.flags & ts.NodeFlags.Const) !== 0;
|
|
888
|
-
for (const declaration of variableDeclarationList.declarations) {
|
|
889
|
-
const { stmts: declaredStmts } = this.variableDeclarationToValueAndStmts(declaration, isConst);
|
|
890
|
-
declaredStmts.forEach(s => stmts.push(s));
|
|
891
|
-
}
|
|
892
|
-
return { value: ValueUtil_1.ValueUtil.getUndefinedConst(), valueOriginalPositions: [Position_1.FullPosition.DEFAULT], stmts: stmts };
|
|
893
|
-
}
|
|
894
|
-
variableDeclarationToValueAndStmts(variableDeclaration, isConst, needRightOp = true) {
|
|
895
|
-
const leftOpNode = variableDeclaration.name;
|
|
896
|
-
const rightOpNode = variableDeclaration.initializer;
|
|
897
|
-
const declarationType = variableDeclaration.type ? this.resolveTypeNode(variableDeclaration.type) : Type_1.UnknownType.getInstance();
|
|
898
|
-
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, true, isConst, declarationType, needRightOp);
|
|
899
|
-
}
|
|
900
|
-
assignmentToValueAndStmts(leftOpNode, rightOpNode, variableDefFlag, isConst, declarationType, needRightOp = true) {
|
|
901
|
-
let leftValueAndStmts;
|
|
902
|
-
if (ts.isIdentifier(leftOpNode)) {
|
|
903
|
-
leftValueAndStmts = this.identifierToValueAndStmts(leftOpNode, variableDefFlag);
|
|
904
|
-
}
|
|
905
|
-
else if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode)) {
|
|
906
|
-
leftValueAndStmts = this.arrayDestructuringToValueAndStmts(leftOpNode, isConst);
|
|
907
|
-
}
|
|
908
|
-
else if (ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
909
|
-
leftValueAndStmts = this.objectDestructuringToValueAndStmts(leftOpNode, isConst);
|
|
910
|
-
}
|
|
911
|
-
else {
|
|
912
|
-
leftValueAndStmts = this.tsNodeToValueAndStmts(leftOpNode);
|
|
913
|
-
}
|
|
914
|
-
const { value: leftValue, valueOriginalPositions: leftPositions, stmts: leftStmts } = leftValueAndStmts;
|
|
915
|
-
let stmts = [];
|
|
916
|
-
if (needRightOp) {
|
|
917
|
-
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.assignmentRightOpToValueAndStmts(rightOpNode, leftValue);
|
|
918
|
-
if (leftValue instanceof Local_1.Local) {
|
|
919
|
-
if (variableDefFlag) {
|
|
920
|
-
leftValue.setConstFlag(isConst);
|
|
921
|
-
leftValue.setType(declarationType);
|
|
922
|
-
}
|
|
923
|
-
if (leftValue.getType() instanceof Type_1.UnknownType && !(rightValue.getType() instanceof Type_1.UnknownType) &&
|
|
924
|
-
!(rightValue.getType() instanceof Type_1.UndefinedType)) {
|
|
925
|
-
leftValue.setType(rightValue.getType());
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
929
|
-
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
930
|
-
if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode) ||
|
|
931
|
-
ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
932
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
933
|
-
stmts.push(assignStmt);
|
|
934
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
938
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
939
|
-
stmts.push(assignStmt);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
else {
|
|
943
|
-
stmts = leftStmts;
|
|
944
|
-
}
|
|
945
|
-
return { value: leftValue, valueOriginalPositions: leftPositions, stmts: stmts };
|
|
946
|
-
}
|
|
947
|
-
assignmentRightOpToValueAndStmts(rightOpNode, leftValue) {
|
|
948
|
-
let rightValue;
|
|
949
|
-
let rightPositions;
|
|
950
|
-
let tempRightStmts = [];
|
|
951
|
-
const rightStmts = [];
|
|
952
|
-
if (rightOpNode) {
|
|
953
|
-
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
954
|
-
this.tsNodeToValueAndStmts(rightOpNode));
|
|
955
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
956
|
-
}
|
|
957
|
-
else {
|
|
958
|
-
rightValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
959
|
-
rightPositions = [Position_1.FullPosition.DEFAULT];
|
|
960
|
-
}
|
|
961
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
962
|
-
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
963
|
-
this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions));
|
|
964
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
965
|
-
}
|
|
966
|
-
return { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts };
|
|
967
|
-
}
|
|
968
|
-
// In assignment patterns, the left operand will be an array literal expression
|
|
969
|
-
arrayDestructuringToValueAndStmts(arrayDestructuring, isConst = false) {
|
|
970
|
-
const stmts = [];
|
|
971
|
-
const arrayTempLocal = this.generateTempLocal();
|
|
972
|
-
const leftOriginalPosition = Position_1.FullPosition.buildFromNode(arrayDestructuring, this.sourceFile);
|
|
973
|
-
const elements = arrayDestructuring.elements;
|
|
974
|
-
const isArrayBindingPattern = ts.isArrayBindingPattern(arrayDestructuring);
|
|
975
|
-
let index = 0;
|
|
976
|
-
for (const element of elements) {
|
|
977
|
-
const arrayRef = new Ref_1.ArkArrayRef(arrayTempLocal, ValueUtil_1.ValueUtil.getOrCreateNumberConst(index));
|
|
978
|
-
const arrayRefPositions = [leftOriginalPosition, leftOriginalPosition, Position_1.FullPosition.DEFAULT];
|
|
979
|
-
const itemName = element.getText(this.sourceFile);
|
|
980
|
-
const targetLocal = isArrayBindingPattern ? this.addNewLocal(itemName) : this.getOrCreateLocal(itemName);
|
|
981
|
-
const targetLocalPosition = Position_1.FullPosition.buildFromNode(element, this.sourceFile);
|
|
982
|
-
isArrayBindingPattern && targetLocal.setConstFlag(isConst);
|
|
983
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, arrayRef);
|
|
984
|
-
assignStmt.setOperandOriginalPositions([targetLocalPosition, ...arrayRefPositions]);
|
|
985
|
-
stmts.push(assignStmt);
|
|
986
|
-
index++;
|
|
987
|
-
}
|
|
988
|
-
return { value: arrayTempLocal, valueOriginalPositions: [leftOriginalPosition], stmts: stmts };
|
|
989
|
-
}
|
|
990
|
-
// In assignment patterns, the left operand will be an object literal expression
|
|
991
|
-
objectDestructuringToValueAndStmts(objectDestructuring, isConst = false) {
|
|
992
|
-
const stmts = [];
|
|
993
|
-
const objectTempLocal = this.generateTempLocal();
|
|
994
|
-
const leftOriginalPosition = Position_1.FullPosition.buildFromNode(objectDestructuring, this.sourceFile);
|
|
995
|
-
const isObjectBindingPattern = ts.isObjectBindingPattern(objectDestructuring);
|
|
996
|
-
const elements = isObjectBindingPattern ? objectDestructuring.elements : objectDestructuring.properties;
|
|
997
|
-
for (const element of elements) {
|
|
998
|
-
let fieldName = '';
|
|
999
|
-
let targetName = '';
|
|
1000
|
-
if (ts.isBindingElement(element)) {
|
|
1001
|
-
fieldName = element.propertyName ? element.propertyName.getText(this.sourceFile) : element.name.getText(this.sourceFile);
|
|
1002
|
-
targetName = element.name.getText(this.sourceFile);
|
|
1003
|
-
}
|
|
1004
|
-
else if (ts.isPropertyAssignment(element)) {
|
|
1005
|
-
fieldName = element.name.getText(this.sourceFile);
|
|
1006
|
-
targetName = element.initializer.getText(this.sourceFile);
|
|
1007
|
-
}
|
|
1008
|
-
else if (ts.isShorthandPropertyAssignment(element)) {
|
|
1009
|
-
fieldName = element.name.getText(this.sourceFile);
|
|
1010
|
-
targetName = fieldName;
|
|
1011
|
-
}
|
|
1012
|
-
else {
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(fieldName);
|
|
1016
|
-
const fieldRef = new Ref_1.ArkInstanceFieldRef(objectTempLocal, fieldSignature);
|
|
1017
|
-
const fieldRefPositions = [leftOriginalPosition, leftOriginalPosition];
|
|
1018
|
-
const targetLocal = isObjectBindingPattern ? this.addNewLocal(targetName) : this.getOrCreateLocal(targetName);
|
|
1019
|
-
isObjectBindingPattern && targetLocal.setConstFlag(isConst);
|
|
1020
|
-
const targetLocalPosition = Position_1.FullPosition.buildFromNode(element, this.sourceFile);
|
|
1021
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, fieldRef);
|
|
1022
|
-
assignStmt.setOperandOriginalPositions([targetLocalPosition, ...fieldRefPositions]);
|
|
1023
|
-
stmts.push(assignStmt);
|
|
1024
|
-
}
|
|
1025
|
-
return { value: objectTempLocal, valueOriginalPositions: [leftOriginalPosition], stmts: stmts };
|
|
1026
|
-
}
|
|
1027
|
-
binaryExpressionToValueAndStmts(binaryExpression) {
|
|
1028
|
-
const operatorToken = binaryExpression.operatorToken;
|
|
1029
|
-
if (operatorToken.kind === ts.SyntaxKind.FirstAssignment) {
|
|
1030
|
-
const leftOpNode = binaryExpression.left;
|
|
1031
|
-
const rightOpNode = binaryExpression.right;
|
|
1032
|
-
const declarationType = Type_1.UnknownType.getInstance();
|
|
1033
|
-
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, false, false, declarationType, true);
|
|
1034
|
-
}
|
|
1035
|
-
else if (ArkValueTransformer.isCompoundAssignmentOperator(operatorToken.kind)) {
|
|
1036
|
-
return this.compoundAssignmentToValueAndStmts(binaryExpression);
|
|
1037
|
-
}
|
|
1038
|
-
const stmts = [];
|
|
1039
|
-
const binaryExpressionPosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1040
|
-
const { value: opValue1, valueOriginalPositions: opPositions1, stmts: opStmts1, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.left);
|
|
1041
|
-
opStmts1.forEach(stmt => stmts.push(stmt));
|
|
1042
|
-
if (operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
1043
|
-
const instanceOfExpr = new Expr_1.ArkInstanceOfExpr(opValue1, new Type_1.UnclearReferenceType(binaryExpression.right.getText(this.sourceFile)));
|
|
1044
|
-
const instanceOfExprPositions = [binaryExpressionPosition, ...opPositions1];
|
|
1045
|
-
return { value: instanceOfExpr, valueOriginalPositions: instanceOfExprPositions, stmts: stmts };
|
|
1046
|
-
}
|
|
1047
|
-
const { value: opValue2, valueOriginalPositions: opPositions2, stmts: opStmts2, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1048
|
-
opStmts2.forEach(stmt => stmts.push(stmt));
|
|
1049
|
-
let exprValue;
|
|
1050
|
-
let exprValuePositions = [binaryExpressionPosition];
|
|
1051
|
-
if (operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
1052
|
-
exprValue = opValue2;
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToBinaryOperator(operatorToken.kind);
|
|
1056
|
-
if (operator) {
|
|
1057
|
-
if (this.isRelationalOperator(operator)) {
|
|
1058
|
-
exprValue = new Expr_1.ArkConditionExpr(opValue1, opValue2, operator);
|
|
1059
|
-
}
|
|
1060
|
-
else {
|
|
1061
|
-
exprValue = new Expr_1.ArkNormalBinopExpr(opValue1, opValue2, operator);
|
|
1062
|
-
}
|
|
1063
|
-
exprValuePositions.push(...opPositions1, ...opPositions2);
|
|
1064
|
-
}
|
|
1065
|
-
else {
|
|
1066
|
-
exprValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1067
|
-
exprValuePositions.push(binaryExpressionPosition);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
return { value: exprValue, valueOriginalPositions: exprValuePositions, stmts: stmts };
|
|
1071
|
-
}
|
|
1072
|
-
compoundAssignmentToValueAndStmts(binaryExpression) {
|
|
1073
|
-
const stmts = [];
|
|
1074
|
-
let { value: leftValue, valueOriginalPositions: leftPositions, stmts: leftStmts, } = this.tsNodeToValueAndStmts(binaryExpression.left);
|
|
1075
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1076
|
-
let { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToValueAndStmts(binaryExpression.right);
|
|
1077
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1078
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
1079
|
-
const { value: newRightValue, valueOriginalPositions: newRightPositions, stmts: rightStmts, } = this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions);
|
|
1080
|
-
rightValue = newRightValue;
|
|
1081
|
-
rightPositions = newRightPositions;
|
|
1082
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1083
|
-
}
|
|
1084
|
-
let leftOpValue;
|
|
1085
|
-
let leftOpPositions;
|
|
1086
|
-
const operator = this.compoundAssignmentTokenToBinaryOperator(binaryExpression.operatorToken.kind);
|
|
1087
|
-
if (operator) {
|
|
1088
|
-
const exprValue = new Expr_1.ArkNormalBinopExpr(leftValue, rightValue, operator);
|
|
1089
|
-
const exprValuePosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1090
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, exprValue);
|
|
1091
|
-
assignStmt.setOperandOriginalPositions([...leftPositions, exprValuePosition, ...leftPositions, ...rightPositions]);
|
|
1092
|
-
stmts.push(assignStmt);
|
|
1093
|
-
leftOpValue = leftValue;
|
|
1094
|
-
leftOpPositions = leftPositions;
|
|
1095
|
-
}
|
|
1096
|
-
else {
|
|
1097
|
-
leftOpValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1098
|
-
leftOpPositions = [leftPositions[0]];
|
|
1099
|
-
}
|
|
1100
|
-
return { value: leftOpValue, valueOriginalPositions: leftOpPositions, stmts: stmts };
|
|
1101
|
-
}
|
|
1102
|
-
compoundAssignmentTokenToBinaryOperator(token) {
|
|
1103
|
-
switch (token) {
|
|
1104
|
-
case ts.SyntaxKind.QuestionQuestionEqualsToken:
|
|
1105
|
-
return Expr_1.NormalBinaryOperator.NullishCoalescing;
|
|
1106
|
-
case ts.SyntaxKind.AsteriskAsteriskEqualsToken:
|
|
1107
|
-
return Expr_1.NormalBinaryOperator.Exponentiation;
|
|
1108
|
-
case ts.SyntaxKind.SlashEqualsToken:
|
|
1109
|
-
return Expr_1.NormalBinaryOperator.Division;
|
|
1110
|
-
case ts.SyntaxKind.PlusEqualsToken:
|
|
1111
|
-
return Expr_1.NormalBinaryOperator.Addition;
|
|
1112
|
-
case ts.SyntaxKind.MinusEqualsToken:
|
|
1113
|
-
return Expr_1.NormalBinaryOperator.Subtraction;
|
|
1114
|
-
case ts.SyntaxKind.AsteriskEqualsToken:
|
|
1115
|
-
return Expr_1.NormalBinaryOperator.Multiplication;
|
|
1116
|
-
case ts.SyntaxKind.PercentEqualsToken:
|
|
1117
|
-
return Expr_1.NormalBinaryOperator.Remainder;
|
|
1118
|
-
case ts.SyntaxKind.LessThanLessThanEqualsToken:
|
|
1119
|
-
return Expr_1.NormalBinaryOperator.LeftShift;
|
|
1120
|
-
case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
|
|
1121
|
-
return Expr_1.NormalBinaryOperator.RightShift;
|
|
1122
|
-
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
|
|
1123
|
-
return Expr_1.NormalBinaryOperator.UnsignedRightShift;
|
|
1124
|
-
case ts.SyntaxKind.AmpersandEqualsToken:
|
|
1125
|
-
return Expr_1.NormalBinaryOperator.BitwiseAnd;
|
|
1126
|
-
case ts.SyntaxKind.BarEqualsToken:
|
|
1127
|
-
return Expr_1.NormalBinaryOperator.BitwiseOr;
|
|
1128
|
-
case ts.SyntaxKind.CaretEqualsToken:
|
|
1129
|
-
return Expr_1.NormalBinaryOperator.BitwiseXor;
|
|
1130
|
-
case ts.SyntaxKind.AmpersandAmpersandEqualsToken:
|
|
1131
|
-
return Expr_1.NormalBinaryOperator.LogicalAnd;
|
|
1132
|
-
case ts.SyntaxKind.BarBarEqualsToken:
|
|
1133
|
-
return Expr_1.NormalBinaryOperator.LogicalOr;
|
|
1134
|
-
default:
|
|
1135
|
-
;
|
|
1136
|
-
}
|
|
1137
|
-
return null;
|
|
1138
|
-
}
|
|
1139
|
-
conditionToValueAndStmts(condition) {
|
|
1140
|
-
const stmts = [];
|
|
1141
|
-
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.tsNodeToValueAndStmts(condition);
|
|
1142
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1143
|
-
let conditionExpr;
|
|
1144
|
-
if ((conditionValue instanceof Expr_1.AbstractBinopExpr) && this.isRelationalOperator(conditionValue.getOperator())) {
|
|
1145
|
-
const operator = conditionValue.getOperator();
|
|
1146
|
-
conditionExpr = new Expr_1.ArkConditionExpr(conditionValue.getOp1(), conditionValue.getOp2(), operator);
|
|
1147
|
-
}
|
|
1148
|
-
else {
|
|
1149
|
-
if (IRUtils_1.IRUtils.moreThanOneAddress(conditionValue)) {
|
|
1150
|
-
({
|
|
1151
|
-
value: conditionValue,
|
|
1152
|
-
valueOriginalPositions: conditionPositions,
|
|
1153
|
-
stmts: conditionStmts,
|
|
1154
|
-
} = this.arkIRTransformer.generateAssignStmtForValue(conditionValue, conditionPositions));
|
|
1155
|
-
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1156
|
-
}
|
|
1157
|
-
conditionExpr = new Expr_1.ArkConditionExpr(conditionValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(0), Expr_1.RelationalBinaryOperator.InEquality);
|
|
1158
|
-
conditionPositions = [conditionPositions[0], ...conditionPositions, Position_1.FullPosition.DEFAULT];
|
|
1159
|
-
}
|
|
1160
|
-
return { value: conditionExpr, valueOriginalPositions: conditionPositions, stmts: stmts };
|
|
1161
|
-
}
|
|
1162
|
-
literalNodeToValueAndStmts(literalNode) {
|
|
1163
|
-
const syntaxKind = literalNode.kind;
|
|
1164
|
-
let constant = null;
|
|
1165
|
-
switch (syntaxKind) {
|
|
1166
|
-
case ts.SyntaxKind.NumericLiteral:
|
|
1167
|
-
constant = ValueUtil_1.ValueUtil.getOrCreateNumberConst(parseFloat(literalNode.text));
|
|
1168
|
-
break;
|
|
1169
|
-
case ts.SyntaxKind.BigIntLiteral:
|
|
1170
|
-
constant = ValueUtil_1.ValueUtil.getOrCreateNumberConst(parseInt(literalNode.text));
|
|
1171
|
-
break;
|
|
1172
|
-
case ts.SyntaxKind.StringLiteral:
|
|
1173
|
-
constant = ValueUtil_1.ValueUtil.createStringConst(literalNode.text);
|
|
1174
|
-
break;
|
|
1175
|
-
case ts.SyntaxKind.RegularExpressionLiteral:
|
|
1176
|
-
constant = new Constant_1.Constant(literalNode.text, Builtin_1.Builtin.REGEXP_CLASS_TYPE);
|
|
1177
|
-
break;
|
|
1178
|
-
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
1179
|
-
constant = ValueUtil_1.ValueUtil.createStringConst(literalNode.text);
|
|
1180
|
-
break;
|
|
1181
|
-
case ts.SyntaxKind.NullKeyword:
|
|
1182
|
-
constant = ValueUtil_1.ValueUtil.getNullConstant();
|
|
1183
|
-
break;
|
|
1184
|
-
case ts.SyntaxKind.UndefinedKeyword:
|
|
1185
|
-
constant = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1186
|
-
break;
|
|
1187
|
-
case ts.SyntaxKind.TrueKeyword:
|
|
1188
|
-
constant = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
1189
|
-
break;
|
|
1190
|
-
case ts.SyntaxKind.FalseKeyword:
|
|
1191
|
-
constant = ValueUtil_1.ValueUtil.getBooleanConstant(false);
|
|
1192
|
-
break;
|
|
1193
|
-
default:
|
|
1194
|
-
logger.warn(`ast node's syntaxKind is ${ts.SyntaxKind[literalNode.kind]}, not literalNode`);
|
|
1195
|
-
}
|
|
1196
|
-
if (constant === null) {
|
|
1197
|
-
return null;
|
|
1198
|
-
}
|
|
1199
|
-
return {
|
|
1200
|
-
value: constant,
|
|
1201
|
-
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(literalNode, this.sourceFile)],
|
|
1202
|
-
stmts: [],
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
getOrCreateLocal(localName, localType = Type_1.UnknownType.getInstance()) {
|
|
1206
|
-
let local = this.locals.get(localName);
|
|
1207
|
-
if (local !== undefined) {
|
|
1208
|
-
return local;
|
|
1209
|
-
}
|
|
1210
|
-
local = this.addNewLocal(localName, localType);
|
|
1211
|
-
this.addNewGlobal(localName);
|
|
1212
|
-
return local;
|
|
1213
|
-
}
|
|
1214
|
-
generateTempLocal(localType = Type_1.UnknownType.getInstance()) {
|
|
1215
|
-
const tempLocalName = Const_1.TEMP_LOCAL_PREFIX + this.tempLocalNo;
|
|
1216
|
-
this.tempLocalNo++;
|
|
1217
|
-
const tempLocal = new Local_1.Local(tempLocalName, localType);
|
|
1218
|
-
this.locals.set(tempLocalName, tempLocal);
|
|
1219
|
-
return tempLocal;
|
|
1220
|
-
}
|
|
1221
|
-
isRelationalOperator(operator) {
|
|
1222
|
-
return operator === Expr_1.RelationalBinaryOperator.LessThan ||
|
|
1223
|
-
operator === Expr_1.RelationalBinaryOperator.LessThanOrEqual ||
|
|
1224
|
-
operator === Expr_1.RelationalBinaryOperator.GreaterThan ||
|
|
1225
|
-
operator === Expr_1.RelationalBinaryOperator.GreaterThanOrEqual ||
|
|
1226
|
-
operator === Expr_1.RelationalBinaryOperator.Equality ||
|
|
1227
|
-
operator === Expr_1.RelationalBinaryOperator.InEquality ||
|
|
1228
|
-
operator === Expr_1.RelationalBinaryOperator.StrictEquality ||
|
|
1229
|
-
operator === Expr_1.RelationalBinaryOperator.StrictInequality;
|
|
1230
|
-
}
|
|
1231
|
-
isLiteralNode(node) {
|
|
1232
|
-
if (ts.isStringLiteral(node) ||
|
|
1233
|
-
ts.isNumericLiteral(node) ||
|
|
1234
|
-
ts.isBigIntLiteral(node) ||
|
|
1235
|
-
ts.isRegularExpressionLiteral(node) ||
|
|
1236
|
-
ts.isNoSubstitutionTemplateLiteral(node) ||
|
|
1237
|
-
node.kind === ts.SyntaxKind.NullKeyword ||
|
|
1238
|
-
node.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1239
|
-
node.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1240
|
-
node.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
1241
|
-
return true;
|
|
1242
|
-
}
|
|
1243
|
-
return false;
|
|
1244
|
-
}
|
|
1245
|
-
resolveTypeNode(type) {
|
|
1246
|
-
const kind = type.kind;
|
|
1247
|
-
switch (kind) {
|
|
1248
|
-
case ts.SyntaxKind.BooleanKeyword:
|
|
1249
|
-
return Type_1.BooleanType.getInstance();
|
|
1250
|
-
case ts.SyntaxKind.NumberKeyword:
|
|
1251
|
-
return Type_1.NumberType.getInstance();
|
|
1252
|
-
case ts.SyntaxKind.StringKeyword:
|
|
1253
|
-
return Type_1.StringType.getInstance();
|
|
1254
|
-
case ts.SyntaxKind.UndefinedKeyword:
|
|
1255
|
-
return Type_1.UndefinedType.getInstance();
|
|
1256
|
-
case ts.SyntaxKind.AnyKeyword:
|
|
1257
|
-
return Type_1.AnyType.getInstance();
|
|
1258
|
-
case ts.SyntaxKind.VoidKeyword:
|
|
1259
|
-
return Type_1.VoidType.getInstance();
|
|
1260
|
-
case ts.SyntaxKind.NeverKeyword:
|
|
1261
|
-
return Type_1.NeverType.getInstance();
|
|
1262
|
-
case ts.SyntaxKind.TypeReference:
|
|
1263
|
-
return this.resolveTypeReferenceNode(type);
|
|
1264
|
-
case ts.SyntaxKind.ArrayType:
|
|
1265
|
-
return new Type_1.ArrayType(this.resolveTypeNode(type.elementType), 1);
|
|
1266
|
-
case ts.SyntaxKind.UnionType: {
|
|
1267
|
-
const mayTypes = [];
|
|
1268
|
-
type.types.forEach(t => mayTypes.push(this.resolveTypeNode(t)));
|
|
1269
|
-
return new Type_1.UnionType(mayTypes);
|
|
1270
|
-
}
|
|
1271
|
-
case ts.SyntaxKind.IntersectionType: {
|
|
1272
|
-
const intersectionTypes = [];
|
|
1273
|
-
type.types.forEach(t => intersectionTypes.push(this.resolveTypeNode(t)));
|
|
1274
|
-
return new Type_1.IntersectionType(intersectionTypes);
|
|
1275
|
-
}
|
|
1276
|
-
case ts.SyntaxKind.TupleType: {
|
|
1277
|
-
const types = [];
|
|
1278
|
-
type.elements.forEach(element => {
|
|
1279
|
-
types.push(this.resolveTypeNode(element));
|
|
1280
|
-
});
|
|
1281
|
-
return new Type_1.TupleType(types);
|
|
1282
|
-
}
|
|
1283
|
-
case ts.SyntaxKind.NamedTupleMember:
|
|
1284
|
-
return this.resolveTypeNode(type.type);
|
|
1285
|
-
case ts.SyntaxKind.LiteralType:
|
|
1286
|
-
return ArkValueTransformer.resolveLiteralTypeNode(type, this.sourceFile);
|
|
1287
|
-
case ts.SyntaxKind.TemplateLiteralType:
|
|
1288
|
-
return this.resolveTemplateLiteralTypeNode(type);
|
|
1289
|
-
case ts.SyntaxKind.TypeLiteral:
|
|
1290
|
-
return this.resolveTypeLiteralNode(type);
|
|
1291
|
-
case ts.SyntaxKind.FunctionType:
|
|
1292
|
-
return this.resolveFunctionTypeNode(type);
|
|
1293
|
-
case ts.SyntaxKind.ImportType:
|
|
1294
|
-
return Type_1.UnknownType.getInstance();
|
|
1295
|
-
case ts.SyntaxKind.TypeQuery:
|
|
1296
|
-
return this.resolveTypeQueryNode(type);
|
|
1297
|
-
case ts.SyntaxKind.ParenthesizedType:
|
|
1298
|
-
return this.resolveTypeNode(type.type);
|
|
1299
|
-
case ts.SyntaxKind.TypeOperator:
|
|
1300
|
-
return this.resolveTypeOperatorNode(type);
|
|
1301
|
-
default:
|
|
1302
|
-
return Type_1.UnknownType.getInstance();
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
resolveTypeQueryNode(typeQueryNode) {
|
|
1306
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1307
|
-
const genericTypes = [];
|
|
1308
|
-
if (typeQueryNode.typeArguments) {
|
|
1309
|
-
for (const typeArgument of typeQueryNode.typeArguments) {
|
|
1310
|
-
genericTypes.push(this.resolveTypeNode(typeArgument));
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
const exprNameNode = typeQueryNode.exprName;
|
|
1314
|
-
let opValue;
|
|
1315
|
-
if (ts.isQualifiedName(exprNameNode)) {
|
|
1316
|
-
if (exprNameNode.left.getText(this.sourceFile) === TSConst_1.THIS_NAME) {
|
|
1317
|
-
const fieldName = exprNameNode.right.getText(this.sourceFile);
|
|
1318
|
-
const fieldSignature = (_b = (_a = this.declaringMethod.getDeclaringArkClass().getFieldWithName(fieldName)) === null || _a === void 0 ? void 0 : _a.getSignature()) !== null && _b !== void 0 ? _b : ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(fieldName);
|
|
1319
|
-
const baseLocal = (_c = this.locals.get(TSConst_1.THIS_NAME)) !== null && _c !== void 0 ? _c : new Local_1.Local(TSConst_1.THIS_NAME, new Type_1.ClassType(this.declaringMethod.getDeclaringArkClass().getSignature(), genericTypes));
|
|
1320
|
-
opValue = new Ref_1.ArkInstanceFieldRef(baseLocal, fieldSignature);
|
|
1321
|
-
}
|
|
1322
|
-
else {
|
|
1323
|
-
const exprName = exprNameNode.getText(this.sourceFile);
|
|
1324
|
-
opValue = new Local_1.Local(exprName, Type_1.UnknownType.getInstance());
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
else {
|
|
1328
|
-
const exprName = exprNameNode.escapedText.toString();
|
|
1329
|
-
opValue = (_f = (_d = this.locals.get(exprName)) !== null && _d !== void 0 ? _d : (_e = this.globals) === null || _e === void 0 ? void 0 : _e.get(exprName)) !== null && _f !== void 0 ? _f : new Local_1.Local(exprName, Type_1.UnknownType.getInstance());
|
|
1330
|
-
}
|
|
1331
|
-
return new TypeExpr_1.TypeQueryExpr(opValue, genericTypes);
|
|
1332
|
-
}
|
|
1333
|
-
resolveTypeOperatorNode(typeOperatorNode) {
|
|
1334
|
-
let type = this.resolveTypeNode(typeOperatorNode.type);
|
|
1335
|
-
switch (typeOperatorNode.operator) {
|
|
1336
|
-
case ts.SyntaxKind.ReadonlyKeyword: {
|
|
1337
|
-
if (type instanceof Type_1.ArrayType || type instanceof Type_1.TupleType) {
|
|
1338
|
-
type.setReadonlyFlag(true);
|
|
1339
|
-
}
|
|
1340
|
-
return type;
|
|
1341
|
-
}
|
|
1342
|
-
case ts.SyntaxKind.KeyOfKeyword: {
|
|
1343
|
-
return new TypeExpr_1.KeyofTypeExpr(type);
|
|
1344
|
-
}
|
|
1345
|
-
case ts.SyntaxKind.UniqueKeyword: {
|
|
1346
|
-
return Type_1.UnknownType.getInstance();
|
|
1347
|
-
}
|
|
1348
|
-
default:
|
|
1349
|
-
return Type_1.UnknownType.getInstance();
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
static resolveLiteralTypeNode(literalTypeNode, sourceFile) {
|
|
1353
|
-
const literal = literalTypeNode.literal;
|
|
1354
|
-
const kind = literal.kind;
|
|
1355
|
-
switch (kind) {
|
|
1356
|
-
case ts.SyntaxKind.NullKeyword:
|
|
1357
|
-
return Type_1.NullType.getInstance();
|
|
1358
|
-
case ts.SyntaxKind.TrueKeyword:
|
|
1359
|
-
return Type_1.LiteralType.TRUE;
|
|
1360
|
-
case ts.SyntaxKind.FalseKeyword:
|
|
1361
|
-
return Type_1.LiteralType.FALSE;
|
|
1362
|
-
case ts.SyntaxKind.NumericLiteral:
|
|
1363
|
-
return new Type_1.LiteralType(parseFloat(literal.text));
|
|
1364
|
-
case ts.SyntaxKind.PrefixUnaryExpression:
|
|
1365
|
-
return new Type_1.LiteralType(parseFloat(literal.getText(sourceFile)));
|
|
1366
|
-
default:
|
|
1367
|
-
;
|
|
1368
|
-
}
|
|
1369
|
-
return new Type_1.LiteralType(literal.getText(sourceFile));
|
|
1370
|
-
}
|
|
1371
|
-
resolveTemplateLiteralTypeNode(templateLiteralTypeNode) {
|
|
1372
|
-
let stringLiterals = [''];
|
|
1373
|
-
const headString = templateLiteralTypeNode.head.rawText || '';
|
|
1374
|
-
let newStringLiterals = [];
|
|
1375
|
-
for (const stringLiteral of stringLiterals) {
|
|
1376
|
-
newStringLiterals.push(stringLiteral + headString);
|
|
1377
|
-
}
|
|
1378
|
-
stringLiterals = newStringLiterals;
|
|
1379
|
-
newStringLiterals = [];
|
|
1380
|
-
for (const templateSpan of templateLiteralTypeNode.templateSpans) {
|
|
1381
|
-
const templateType = this.resolveTypeNode(templateSpan.type);
|
|
1382
|
-
const unfoldTemplateTypes = [];
|
|
1383
|
-
if (templateType instanceof Type_1.UnionType) {
|
|
1384
|
-
unfoldTemplateTypes.push(...templateType.getTypes());
|
|
1385
|
-
}
|
|
1386
|
-
else {
|
|
1387
|
-
unfoldTemplateTypes.push(templateType);
|
|
1388
|
-
}
|
|
1389
|
-
const unfoldTemplateTypeStrs = [];
|
|
1390
|
-
for (const unfoldTemplateType of unfoldTemplateTypes) {
|
|
1391
|
-
unfoldTemplateTypeStrs.push(unfoldTemplateType instanceof Type_1.AliasType ? unfoldTemplateType.getOriginalType()
|
|
1392
|
-
.toString() : unfoldTemplateType.toString());
|
|
1393
|
-
}
|
|
1394
|
-
const templateSpanString = templateSpan.literal.rawText || '';
|
|
1395
|
-
for (const stringLiteral of stringLiterals) {
|
|
1396
|
-
for (const unfoldTemplateTypeStr of unfoldTemplateTypeStrs) {
|
|
1397
|
-
newStringLiterals.push(stringLiteral + unfoldTemplateTypeStr + templateSpanString);
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
stringLiterals = newStringLiterals;
|
|
1401
|
-
newStringLiterals = [];
|
|
1402
|
-
}
|
|
1403
|
-
const templateTypes = [];
|
|
1404
|
-
for (const stringLiteral of stringLiterals) {
|
|
1405
|
-
templateTypes.push(new Type_1.LiteralType(stringLiteral));
|
|
1406
|
-
}
|
|
1407
|
-
if (templateTypes.length > 0) {
|
|
1408
|
-
return new Type_1.UnionType(templateTypes);
|
|
1409
|
-
}
|
|
1410
|
-
return templateTypes[0];
|
|
1411
|
-
}
|
|
1412
|
-
resolveTypeReferenceNode(typeReferenceNode) {
|
|
1413
|
-
const typeReferenceFullName = typeReferenceNode.typeName.getText(this.sourceFile);
|
|
1414
|
-
const aliasTypeAndStmt = this.aliasTypeMap.get(typeReferenceFullName);
|
|
1415
|
-
const genericTypes = [];
|
|
1416
|
-
if (typeReferenceNode.typeArguments) {
|
|
1417
|
-
for (const typeArgument of typeReferenceNode.typeArguments) {
|
|
1418
|
-
genericTypes.push(this.resolveTypeNode(typeArgument));
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
if (!aliasTypeAndStmt) {
|
|
1422
|
-
const typeName = typeReferenceNode.typeName.getText(this.sourceFile);
|
|
1423
|
-
const local = this.locals.get(typeName);
|
|
1424
|
-
if (local !== undefined) {
|
|
1425
|
-
return local.getType();
|
|
1426
|
-
}
|
|
1427
|
-
return new Type_1.UnclearReferenceType(typeName, genericTypes);
|
|
1428
|
-
}
|
|
1429
|
-
else {
|
|
1430
|
-
if (genericTypes.length > 0) {
|
|
1431
|
-
const oldAlias = aliasTypeAndStmt[0];
|
|
1432
|
-
let alias = new Type_1.AliasType(oldAlias.getName(), TypeInference_1.TypeInference.replaceTypeWithReal(oldAlias.getOriginalType(), genericTypes), oldAlias.getSignature(), oldAlias.getGenericTypes());
|
|
1433
|
-
alias.setRealGenericTypes(genericTypes);
|
|
1434
|
-
return alias;
|
|
1435
|
-
}
|
|
1436
|
-
return aliasTypeAndStmt[0];
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
resolveTypeLiteralNode(typeLiteralNode) {
|
|
1440
|
-
const anonymousClass = new ArkClass_1.ArkClass();
|
|
1441
|
-
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
1442
|
-
const declaringNamespace = declaringClass.getDeclaringArkNamespace();
|
|
1443
|
-
if (declaringNamespace) {
|
|
1444
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode, declaringNamespace, anonymousClass, this.sourceFile);
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode, declaringClass.getDeclaringArkFile(), anonymousClass, this.sourceFile);
|
|
1448
|
-
}
|
|
1449
|
-
return new Type_1.ClassType(anonymousClass.getSignature());
|
|
1450
|
-
}
|
|
1451
|
-
resolveFunctionTypeNode(functionTypeNode) {
|
|
1452
|
-
const anonymousMethod = new ArkMethod_1.ArkMethod();
|
|
1453
|
-
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
1454
|
-
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionTypeNode, declaringClass, anonymousMethod, this.sourceFile);
|
|
1455
|
-
return new Type_1.FunctionType(anonymousMethod.getSignature());
|
|
1456
|
-
}
|
|
1457
|
-
static isCompoundAssignmentOperator(operator) {
|
|
1458
|
-
const compoundAssignmentOperators = [
|
|
1459
|
-
ts.SyntaxKind.PlusEqualsToken,
|
|
1460
|
-
ts.SyntaxKind.MinusEqualsToken,
|
|
1461
|
-
ts.SyntaxKind.AsteriskAsteriskEqualsToken,
|
|
1462
|
-
ts.SyntaxKind.AsteriskEqualsToken,
|
|
1463
|
-
ts.SyntaxKind.SlashEqualsToken,
|
|
1464
|
-
ts.SyntaxKind.PercentEqualsToken,
|
|
1465
|
-
ts.SyntaxKind.AmpersandEqualsToken,
|
|
1466
|
-
ts.SyntaxKind.BarEqualsToken,
|
|
1467
|
-
ts.SyntaxKind.CaretEqualsToken,
|
|
1468
|
-
ts.SyntaxKind.LessThanLessThanEqualsToken,
|
|
1469
|
-
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
|
1470
|
-
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
|
1471
|
-
ts.SyntaxKind.BarBarEqualsToken,
|
|
1472
|
-
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
1473
|
-
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
1474
|
-
];
|
|
1475
|
-
return compoundAssignmentOperators.includes(operator);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
exports.ArkValueTransformer = ArkValueTransformer;
|
|
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.ArkValueTransformer = void 0;
|
|
41
|
+
const ts = __importStar(require("ohos-typescript"));
|
|
42
|
+
const Local_1 = require("../base/Local");
|
|
43
|
+
const Position_1 = require("../base/Position");
|
|
44
|
+
const Stmt_1 = require("../base/Stmt");
|
|
45
|
+
const Expr_1 = require("../base/Expr");
|
|
46
|
+
const ArkClass_1 = require("../model/ArkClass");
|
|
47
|
+
const ArkClassBuilder_1 = require("../model/builder/ArkClassBuilder");
|
|
48
|
+
const Type_1 = require("../base/Type");
|
|
49
|
+
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
50
|
+
const TSConst_1 = require("./TSConst");
|
|
51
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
52
|
+
const EtsConst_1 = require("./EtsConst");
|
|
53
|
+
const ValueUtil_1 = require("./ValueUtil");
|
|
54
|
+
const IRUtils_1 = require("./IRUtils");
|
|
55
|
+
const Ref_1 = require("../base/Ref");
|
|
56
|
+
const ModelUtils_1 = require("./ModelUtils");
|
|
57
|
+
const ArkMethod_1 = require("../model/ArkMethod");
|
|
58
|
+
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
59
|
+
const Builtin_1 = require("./Builtin");
|
|
60
|
+
const Constant_1 = require("../base/Constant");
|
|
61
|
+
const Const_1 = require("./Const");
|
|
62
|
+
const ArkIRTransformer_1 = require("./ArkIRTransformer");
|
|
63
|
+
const logger_1 = __importStar(require("../../utils/logger"));
|
|
64
|
+
const TypeInference_1 = require("./TypeInference");
|
|
65
|
+
const TypeExpr_1 = require("../base/TypeExpr");
|
|
66
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkValueTransformer');
|
|
67
|
+
class ArkValueTransformer {
|
|
68
|
+
constructor(arkIRTransformer, sourceFile, declaringMethod) {
|
|
69
|
+
this.conditionalOperatorNo = 0;
|
|
70
|
+
this.tempLocalNo = 0;
|
|
71
|
+
this.locals = new Map();
|
|
72
|
+
this.aliasTypeMap = new Map();
|
|
73
|
+
this.builderMethodContextFlag = false;
|
|
74
|
+
this.arkIRTransformer = arkIRTransformer;
|
|
75
|
+
this.sourceFile = sourceFile;
|
|
76
|
+
this.thisLocal = new Local_1.Local(TSConst_1.THIS_NAME, declaringMethod.getDeclaringArkClass().getSignature().getType());
|
|
77
|
+
this.locals.set(this.thisLocal.getName(), this.thisLocal);
|
|
78
|
+
this.declaringMethod = declaringMethod;
|
|
79
|
+
}
|
|
80
|
+
getLocals() {
|
|
81
|
+
return new Set(this.locals.values());
|
|
82
|
+
}
|
|
83
|
+
getThisLocal() {
|
|
84
|
+
return this.thisLocal;
|
|
85
|
+
}
|
|
86
|
+
getAliasTypeMap() {
|
|
87
|
+
return this.aliasTypeMap;
|
|
88
|
+
}
|
|
89
|
+
addNewLocal(localName, localType = Type_1.UnknownType.getInstance()) {
|
|
90
|
+
let local = new Local_1.Local(localName, localType);
|
|
91
|
+
this.locals.set(localName, local);
|
|
92
|
+
return local;
|
|
93
|
+
}
|
|
94
|
+
getGlobals() {
|
|
95
|
+
var _a;
|
|
96
|
+
return (_a = this.globals) !== null && _a !== void 0 ? _a : null;
|
|
97
|
+
}
|
|
98
|
+
addNewGlobal(name, ref) {
|
|
99
|
+
var _a;
|
|
100
|
+
let globalRef = new Ref_1.GlobalRef(name, ref);
|
|
101
|
+
this.globals = (_a = this.globals) !== null && _a !== void 0 ? _a : new Map();
|
|
102
|
+
this.globals.set(name, globalRef);
|
|
103
|
+
return globalRef;
|
|
104
|
+
}
|
|
105
|
+
tsNodeToValueAndStmts(node) {
|
|
106
|
+
if (ts.isBinaryExpression(node)) {
|
|
107
|
+
return this.binaryExpressionToValueAndStmts(node);
|
|
108
|
+
}
|
|
109
|
+
else if (ts.isCallExpression(node)) {
|
|
110
|
+
return this.callExpressionToValueAndStmts(node);
|
|
111
|
+
}
|
|
112
|
+
else if (ts.isVariableDeclarationList(node)) {
|
|
113
|
+
return this.variableDeclarationListToValueAndStmts(node);
|
|
114
|
+
}
|
|
115
|
+
else if (ts.isIdentifier(node)) {
|
|
116
|
+
return this.identifierToValueAndStmts(node);
|
|
117
|
+
}
|
|
118
|
+
else if (ts.isPropertyAccessExpression(node)) {
|
|
119
|
+
return this.propertyAccessExpressionToValue(node);
|
|
120
|
+
}
|
|
121
|
+
else if (ts.isPrefixUnaryExpression(node)) {
|
|
122
|
+
return this.prefixUnaryExpressionToValueAndStmts(node);
|
|
123
|
+
}
|
|
124
|
+
else if (ts.isPostfixUnaryExpression(node)) {
|
|
125
|
+
return this.postfixUnaryExpressionToValueAndStmts(node);
|
|
126
|
+
}
|
|
127
|
+
else if (ts.isTemplateExpression(node)) {
|
|
128
|
+
return this.templateExpressionToValueAndStmts(node);
|
|
129
|
+
}
|
|
130
|
+
else if (ts.isTaggedTemplateExpression(node)) {
|
|
131
|
+
return this.taggedTemplateExpressionToValueAndStmts(node);
|
|
132
|
+
}
|
|
133
|
+
else if (ts.isAwaitExpression(node)) {
|
|
134
|
+
return this.awaitExpressionToValueAndStmts(node);
|
|
135
|
+
}
|
|
136
|
+
else if (ts.isYieldExpression(node)) {
|
|
137
|
+
return this.yieldExpressionToValueAndStmts(node);
|
|
138
|
+
}
|
|
139
|
+
else if (ts.isDeleteExpression(node)) {
|
|
140
|
+
return this.deleteExpressionToValueAndStmts(node);
|
|
141
|
+
}
|
|
142
|
+
else if (ts.isVoidExpression(node)) {
|
|
143
|
+
return this.voidExpressionToValueAndStmts(node);
|
|
144
|
+
}
|
|
145
|
+
else if (ts.isElementAccessExpression(node)) {
|
|
146
|
+
return this.elementAccessExpressionToValueAndStmts(node);
|
|
147
|
+
}
|
|
148
|
+
else if (ts.isNewExpression(node)) {
|
|
149
|
+
return this.newExpressionToValueAndStmts(node);
|
|
150
|
+
}
|
|
151
|
+
else if (ts.isParenthesizedExpression(node)) {
|
|
152
|
+
return this.parenthesizedExpressionToValueAndStmts(node);
|
|
153
|
+
}
|
|
154
|
+
else if (ts.isAsExpression(node)) {
|
|
155
|
+
return this.asExpressionToValueAndStmts(node);
|
|
156
|
+
}
|
|
157
|
+
else if (ts.isNonNullExpression(node)) {
|
|
158
|
+
return this.nonNullExpressionToValueAndStmts(node);
|
|
159
|
+
}
|
|
160
|
+
else if (ts.isTypeAssertionExpression(node)) {
|
|
161
|
+
return this.typeAssertionToValueAndStmts(node);
|
|
162
|
+
}
|
|
163
|
+
else if (ts.isTypeOfExpression(node)) {
|
|
164
|
+
return this.typeOfExpressionToValueAndStmts(node);
|
|
165
|
+
}
|
|
166
|
+
else if (ts.isArrayLiteralExpression(node)) {
|
|
167
|
+
return this.arrayLiteralExpressionToValueAndStmts(node);
|
|
168
|
+
}
|
|
169
|
+
else if (this.isLiteralNode(node)) {
|
|
170
|
+
return this.literalNodeToValueAndStmts(node);
|
|
171
|
+
}
|
|
172
|
+
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
173
|
+
return this.callableNodeToValueAndStmts(node);
|
|
174
|
+
}
|
|
175
|
+
else if (ts.isClassExpression(node)) {
|
|
176
|
+
return this.classExpressionToValueAndStmts(node);
|
|
177
|
+
}
|
|
178
|
+
else if (ts.isEtsComponentExpression(node)) {
|
|
179
|
+
return this.etsComponentExpressionToValueAndStmts(node);
|
|
180
|
+
}
|
|
181
|
+
else if (ts.isObjectLiteralExpression(node)) {
|
|
182
|
+
return this.objectLiteralExpresionToValueAndStmts(node);
|
|
183
|
+
}
|
|
184
|
+
else if (node.kind === ts.SyntaxKind.ThisKeyword) {
|
|
185
|
+
return this.thisExpressionToValueAndStmts(node);
|
|
186
|
+
}
|
|
187
|
+
else if (ts.isConditionalExpression(node)) {
|
|
188
|
+
return this.conditionalExpressionToValueAndStmts(node);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
value: new Local_1.Local(node.getText(this.sourceFile)),
|
|
192
|
+
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(node, this.sourceFile)],
|
|
193
|
+
stmts: [],
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
tsNodeToSingleAddressValueAndStmts(node) {
|
|
197
|
+
const allStmts = [];
|
|
198
|
+
let { value, valueOriginalPositions, stmts } = this.tsNodeToValueAndStmts(node);
|
|
199
|
+
stmts.forEach(stmt => allStmts.push(stmt));
|
|
200
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(value)) {
|
|
201
|
+
({ value, valueOriginalPositions, stmts } =
|
|
202
|
+
this.arkIRTransformer.generateAssignStmtForValue(value, valueOriginalPositions));
|
|
203
|
+
stmts.forEach(stmt => allStmts.push(stmt));
|
|
204
|
+
}
|
|
205
|
+
return { value, valueOriginalPositions, stmts: allStmts };
|
|
206
|
+
}
|
|
207
|
+
thisExpressionToValueAndStmts(thisExpression) {
|
|
208
|
+
return {
|
|
209
|
+
value: this.getThisLocal(),
|
|
210
|
+
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(thisExpression, this.sourceFile)],
|
|
211
|
+
stmts: [],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
conditionalExpressionToValueAndStmts(conditionalExpression) {
|
|
215
|
+
const stmts = [];
|
|
216
|
+
const currConditionalOperatorIndex = this.conditionalOperatorNo++;
|
|
217
|
+
const { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
218
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
219
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionValue);
|
|
220
|
+
ifStmt.setOperandOriginalPositions(conditionPositions);
|
|
221
|
+
stmts.push(ifStmt);
|
|
222
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT + currConditionalOperatorIndex));
|
|
223
|
+
const { value: whenTrueValue, valueOriginalPositions: whenTruePositions, stmts: whenTrueStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenTrue);
|
|
224
|
+
whenTrueStmts.forEach(stmt => stmts.push(stmt));
|
|
225
|
+
const resultLocal = this.generateTempLocal();
|
|
226
|
+
const assignStmtWhenTrue = new Stmt_1.ArkAssignStmt(resultLocal, whenTrueValue);
|
|
227
|
+
const resultLocalPosition = [whenTruePositions[0]];
|
|
228
|
+
assignStmtWhenTrue.setOperandOriginalPositions([...resultLocalPosition, ...whenTruePositions]);
|
|
229
|
+
stmts.push(assignStmtWhenTrue);
|
|
230
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorIndex));
|
|
231
|
+
const { value: whenFalseValue, valueOriginalPositions: whenFalsePositions, stmts: whenFalseStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenFalse);
|
|
232
|
+
whenFalseStmts.forEach(stmt => stmts.push(stmt));
|
|
233
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(resultLocal, whenFalseValue);
|
|
234
|
+
assignStmt.setOperandOriginalPositions([...resultLocalPosition, ...whenFalsePositions]);
|
|
235
|
+
stmts.push(assignStmt);
|
|
236
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT + currConditionalOperatorIndex));
|
|
237
|
+
return { value: resultLocal, valueOriginalPositions: resultLocalPosition, stmts: stmts };
|
|
238
|
+
}
|
|
239
|
+
objectLiteralExpresionToValueAndStmts(objectLiteralExpression) {
|
|
240
|
+
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
241
|
+
const declaringArkNamespace = declaringArkClass.getDeclaringArkNamespace();
|
|
242
|
+
const anonymousClass = new ArkClass_1.ArkClass();
|
|
243
|
+
if (declaringArkNamespace) {
|
|
244
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(objectLiteralExpression, declaringArkNamespace, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
245
|
+
declaringArkNamespace.addArkClass(anonymousClass);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const declaringArkFile = declaringArkClass.getDeclaringArkFile();
|
|
249
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(objectLiteralExpression, declaringArkFile, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
250
|
+
declaringArkFile.addArkClass(anonymousClass);
|
|
251
|
+
}
|
|
252
|
+
const objectLiteralExpressionPosition = Position_1.FullPosition.buildFromNode(objectLiteralExpression, this.sourceFile);
|
|
253
|
+
const stmts = [];
|
|
254
|
+
const anonymousClassSignature = anonymousClass.getSignature();
|
|
255
|
+
const anonymousClassType = new Type_1.ClassType(anonymousClassSignature);
|
|
256
|
+
const newExpr = new Expr_1.ArkNewExpr(anonymousClassType);
|
|
257
|
+
const { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [objectLiteralExpressionPosition]);
|
|
258
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
259
|
+
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
260
|
+
const constructorMethodSignature = new ArkSignature_1.MethodSignature(anonymousClassSignature, constructorMethodSubSignature);
|
|
261
|
+
const constructorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, []);
|
|
262
|
+
const constructorInvokeExprPositions = [objectLiteralExpressionPosition, ...newExprLocalPositions];
|
|
263
|
+
const constructorInvokeStmt = new Stmt_1.ArkInvokeStmt(constructorInvokeExpr);
|
|
264
|
+
constructorInvokeStmt.setOperandOriginalPositions(constructorInvokeExprPositions);
|
|
265
|
+
stmts.push(constructorInvokeStmt);
|
|
266
|
+
return { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: stmts };
|
|
267
|
+
}
|
|
268
|
+
generateSystemComponentStmt(componentName, args, argPositionsAllFlat, componentExpression, currStmts) {
|
|
269
|
+
const stmts = [...currStmts];
|
|
270
|
+
const componentExpressionPosition = Position_1.FullPosition.buildFromNode(componentExpression, this.sourceFile);
|
|
271
|
+
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(componentName, args, componentExpressionPosition, argPositionsAllFlat);
|
|
272
|
+
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
273
|
+
if (ts.isEtsComponentExpression(componentExpression) && componentExpression.body) {
|
|
274
|
+
for (const statement of componentExpression.body.statements) {
|
|
275
|
+
this.arkIRTransformer.tsNodeToStmts(statement).forEach(stmt => stmts.push(stmt));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
stmts.push(this.generateComponentPopStmts(componentName, componentExpressionPosition));
|
|
279
|
+
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: stmts };
|
|
280
|
+
}
|
|
281
|
+
generateCustomViewStmt(componentName, args, argPositionsAllFlat, componentExpression, currStmts) {
|
|
282
|
+
const stmts = [...currStmts];
|
|
283
|
+
const componentExpressionPosition = Position_1.FullPosition.buildFromNode(componentExpression, this.sourceFile);
|
|
284
|
+
const classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(componentName);
|
|
285
|
+
const classType = new Type_1.ClassType(classSignature);
|
|
286
|
+
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
287
|
+
const { value: newExprLocal, valueOriginalPositions: newExprPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [componentExpressionPosition]);
|
|
288
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
289
|
+
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
290
|
+
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
291
|
+
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, args);
|
|
292
|
+
const instanceInvokeExprPositions = [componentExpressionPosition, ...newExprPositions, ...argPositionsAllFlat];
|
|
293
|
+
const instanceInvokeStmt = new Stmt_1.ArkInvokeStmt(instanceInvokeExpr);
|
|
294
|
+
instanceInvokeStmt.setOperandOriginalPositions(instanceInvokeExprPositions);
|
|
295
|
+
stmts.push(instanceInvokeStmt);
|
|
296
|
+
const createViewArgs = [newExprLocal];
|
|
297
|
+
const createViewArgPositionsAll = [newExprPositions];
|
|
298
|
+
if (ts.isEtsComponentExpression(componentExpression) && componentExpression.body) {
|
|
299
|
+
const anonymous = ts.factory.createArrowFunction([], [], [], undefined, undefined, componentExpression.body);
|
|
300
|
+
// @ts-expect-error: add pos info for the created ArrowFunction
|
|
301
|
+
anonymous.pos = componentExpression.body.pos;
|
|
302
|
+
// @ts-expect-error: add end info for the created ArrowFunction
|
|
303
|
+
anonymous.end = componentExpression.body.end;
|
|
304
|
+
const { value: builderMethod, valueOriginalPositions: builderMethodPositions, } = this.callableNodeToValueAndStmts(anonymous);
|
|
305
|
+
createViewArgs.push(builderMethod);
|
|
306
|
+
createViewArgPositionsAll.push(builderMethodPositions);
|
|
307
|
+
}
|
|
308
|
+
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.generateComponentCreationStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, createViewArgs, componentExpressionPosition, createViewArgPositionsAll.flat());
|
|
309
|
+
componentStmts.forEach(stmt => stmts.push(stmt));
|
|
310
|
+
stmts.push(this.generateComponentPopStmts(EtsConst_1.COMPONENT_CUSTOMVIEW, componentExpressionPosition));
|
|
311
|
+
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: stmts };
|
|
312
|
+
}
|
|
313
|
+
generateComponentCreationStmts(componentName, createArgs, componentExpressionPosition, createArgsPositionsAllFlat) {
|
|
314
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
315
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, createArgs);
|
|
316
|
+
const createInvokeExprPositions = [componentExpressionPosition, ...createArgsPositionsAllFlat];
|
|
317
|
+
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.arkIRTransformer.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
318
|
+
return { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts };
|
|
319
|
+
}
|
|
320
|
+
generateComponentPopStmts(componentName, componentExpressionPosition) {
|
|
321
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
322
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
323
|
+
const popInvokeExprPositions = [componentExpressionPosition];
|
|
324
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
325
|
+
popInvokeStmt.setOperandOriginalPositions(popInvokeExprPositions);
|
|
326
|
+
return popInvokeStmt;
|
|
327
|
+
}
|
|
328
|
+
etsComponentExpressionToValueAndStmts(etsComponentExpression) {
|
|
329
|
+
const stmts = [];
|
|
330
|
+
const componentName = etsComponentExpression.expression.text;
|
|
331
|
+
const { args: args, argPositions: argPositions } = this.parseArguments(stmts, etsComponentExpression.arguments);
|
|
332
|
+
if ((0, EtsConst_1.isEtsSystemComponent)(componentName)) {
|
|
333
|
+
return this.generateSystemComponentStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
334
|
+
}
|
|
335
|
+
return this.generateCustomViewStmt(componentName, args, argPositions, etsComponentExpression, stmts);
|
|
336
|
+
}
|
|
337
|
+
classExpressionToValueAndStmts(classExpression) {
|
|
338
|
+
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
339
|
+
const declaringArkNamespace = declaringArkClass.getDeclaringArkNamespace();
|
|
340
|
+
const newClass = new ArkClass_1.ArkClass();
|
|
341
|
+
if (declaringArkNamespace) {
|
|
342
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression, declaringArkNamespace, newClass, this.sourceFile, this.declaringMethod);
|
|
343
|
+
declaringArkNamespace.addArkClass(newClass);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
const declaringArkFile = declaringArkClass.getDeclaringArkFile();
|
|
347
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, declaringArkFile, newClass, this.sourceFile, this.declaringMethod);
|
|
348
|
+
declaringArkFile.addArkClass(newClass);
|
|
349
|
+
}
|
|
350
|
+
const classValue = this.addNewLocal(newClass.getName(), new Type_1.ClassType(newClass.getSignature()));
|
|
351
|
+
return {
|
|
352
|
+
value: classValue,
|
|
353
|
+
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(classExpression, this.sourceFile)],
|
|
354
|
+
stmts: [],
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
templateExpressionToValueAndStmts(templateExpression) {
|
|
358
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(templateExpression);
|
|
359
|
+
const { placeholderStringLocals, placeholderStringLocalPositions, newStmts } = this.processTemplatePlaceholders(placeholderValues, placeholderPositions, stmts);
|
|
360
|
+
return this.combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, newStmts);
|
|
361
|
+
}
|
|
362
|
+
processTemplatePlaceholders(placeholderValues, placeholderPositions, currStmts) {
|
|
363
|
+
const placeholderStringLocals = [];
|
|
364
|
+
const placeholderStringLocalPositions = [];
|
|
365
|
+
const newStmts = [...currStmts];
|
|
366
|
+
for (let i = 0; i < placeholderValues.length; i++) {
|
|
367
|
+
let placeholderValue = placeholderValues[i];
|
|
368
|
+
let placeholderPosition = [placeholderPositions[i]];
|
|
369
|
+
let placeholderStmts = [];
|
|
370
|
+
if (!(placeholderValue instanceof Local_1.Local)) {
|
|
371
|
+
({ value: placeholderValue, valueOriginalPositions: placeholderPosition, stmts: placeholderStmts } =
|
|
372
|
+
this.arkIRTransformer.generateAssignStmtForValue(placeholderValue, placeholderPosition));
|
|
373
|
+
}
|
|
374
|
+
placeholderStmts.forEach(stmt => newStmts.push(stmt));
|
|
375
|
+
const toStringExpr = new Expr_1.ArkInstanceInvokeExpr(placeholderValue, Builtin_1.Builtin.TO_STRING_METHOD_SIGNATURE, []);
|
|
376
|
+
const toStringExprPosition = [placeholderPosition[0], placeholderPosition[0]];
|
|
377
|
+
const { value: placeholderStringLocal, valueOriginalPositions: placeholderStringPositions, stmts: toStringStmts, } = this.arkIRTransformer.generateAssignStmtForValue(toStringExpr, toStringExprPosition);
|
|
378
|
+
placeholderStringLocals.push(placeholderStringLocal);
|
|
379
|
+
placeholderStringLocalPositions.push(placeholderStringPositions[0]);
|
|
380
|
+
toStringStmts.forEach(stmt => newStmts.push(stmt));
|
|
381
|
+
}
|
|
382
|
+
return { placeholderStringLocals, placeholderStringLocalPositions, newStmts };
|
|
383
|
+
}
|
|
384
|
+
combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, currStmts) {
|
|
385
|
+
const templateParts = [];
|
|
386
|
+
const templatePartPositions = [];
|
|
387
|
+
for (let i = 0; i < placeholderStringLocals.length; i++) {
|
|
388
|
+
if (stringTextValues[i] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
389
|
+
templateParts.push(stringTextValues[i]);
|
|
390
|
+
templatePartPositions.push(stringTextPositions[i]);
|
|
391
|
+
}
|
|
392
|
+
templateParts.push(placeholderStringLocals[i]);
|
|
393
|
+
templatePartPositions.push(placeholderStringLocalPositions[i]);
|
|
394
|
+
}
|
|
395
|
+
if (stringTextValues[stringTextValues.length - 1] !== ValueUtil_1.ValueUtil.EMPTY_STRING_CONSTANT) {
|
|
396
|
+
templateParts.push(stringTextValues[stringTextValues.length - 1]);
|
|
397
|
+
templatePartPositions.push(stringTextPositions[stringTextPositions.length - 1]);
|
|
398
|
+
}
|
|
399
|
+
let currTemplateResult = templateParts[0];
|
|
400
|
+
let currTemplateResultPosition = templatePartPositions[0];
|
|
401
|
+
const finalStmts = [...currStmts];
|
|
402
|
+
for (let i = 1; i < templateParts.length; i++) {
|
|
403
|
+
const nextTemplatePartPosition = templatePartPositions[i];
|
|
404
|
+
const normalBinopExpr = new Expr_1.ArkNormalBinopExpr(currTemplateResult, templateParts[i], Expr_1.NormalBinaryOperator.Addition);
|
|
405
|
+
const normalBinopExprPositions = [Position_1.FullPosition.merge(currTemplateResultPosition, nextTemplatePartPosition),
|
|
406
|
+
currTemplateResultPosition, nextTemplatePartPosition];
|
|
407
|
+
const { value: combinationValue, valueOriginalPositions: combinationValuePositions, stmts: combinationStmts, } = this.arkIRTransformer.generateAssignStmtForValue(normalBinopExpr, normalBinopExprPositions);
|
|
408
|
+
combinationStmts.forEach(stmt => finalStmts.push(stmt));
|
|
409
|
+
currTemplateResult = combinationValue;
|
|
410
|
+
currTemplateResultPosition = combinationValuePositions[0];
|
|
411
|
+
}
|
|
412
|
+
return { value: currTemplateResult, valueOriginalPositions: [currTemplateResultPosition], stmts: finalStmts };
|
|
413
|
+
}
|
|
414
|
+
taggedTemplateExpressionToValueAndStmts(taggedTemplateExpression) {
|
|
415
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions, } = this.collectTemplateValues(taggedTemplateExpression.template);
|
|
416
|
+
const stringTextBaseType = Type_1.StringType.getInstance();
|
|
417
|
+
const stringTextArrayLen = stringTextValues.length;
|
|
418
|
+
const stringTextArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(stringTextArrayLen);
|
|
419
|
+
const stringTextArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
420
|
+
const { value: templateObjectLocal, valueOriginalPositions: templateObjectLocalPositions, stmts: templateObjectStmts, } = this.generateArrayExprAndStmts(stringTextBaseType, stringTextArrayLenValue, stringTextArrayLenPosition, stringTextArrayLen, stringTextValues, stringTextPositions, stmts, Position_1.FullPosition.DEFAULT, true);
|
|
421
|
+
const placeholderBaseType = Type_1.AnyType.getInstance();
|
|
422
|
+
const placeholdersArrayLen = placeholderValues.length;
|
|
423
|
+
const placeholdersArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(placeholdersArrayLen);
|
|
424
|
+
const placeholdersArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
425
|
+
const { value: placeholdersLocal, valueOriginalPositions: placeholdersLocalPositions, stmts: placeholdersStmts, } = this.generateArrayExprAndStmts(placeholderBaseType, placeholdersArrayLenValue, placeholdersArrayLenPosition, placeholdersArrayLen, placeholderValues, placeholderPositions, templateObjectStmts, Position_1.FullPosition.DEFAULT, true);
|
|
426
|
+
const taggedFuncArgus = {
|
|
427
|
+
realGenericTypes: undefined, args: [templateObjectLocal, placeholdersLocal],
|
|
428
|
+
argPositions: [templateObjectLocalPositions[0], placeholdersLocalPositions[0]],
|
|
429
|
+
};
|
|
430
|
+
return this.generateInvokeValueAndStmts(taggedTemplateExpression.tag, taggedFuncArgus, placeholdersStmts, taggedTemplateExpression);
|
|
431
|
+
}
|
|
432
|
+
collectTemplateValues(templateLiteral) {
|
|
433
|
+
const stmts = [];
|
|
434
|
+
if (ts.isNoSubstitutionTemplateLiteral(templateLiteral)) {
|
|
435
|
+
const templateLiteralString = templateLiteral.getText(this.sourceFile);
|
|
436
|
+
return {
|
|
437
|
+
stmts: [], stringTextValues: [ValueUtil_1.ValueUtil.createStringConst(templateLiteralString)],
|
|
438
|
+
placeholderValues: [],
|
|
439
|
+
stringTextPositions: [Position_1.FullPosition.buildFromNode(templateLiteral, this.sourceFile)],
|
|
440
|
+
placeholderPositions: [],
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
const head = templateLiteral.head;
|
|
444
|
+
const stringTextValues = [ValueUtil_1.ValueUtil.createStringConst(head.rawText || '')];
|
|
445
|
+
const placeholderValues = [];
|
|
446
|
+
const stringTextPositions = [Position_1.FullPosition.buildFromNode(head, this.sourceFile)];
|
|
447
|
+
const placeholderPositions = [];
|
|
448
|
+
for (const templateSpan of templateLiteral.templateSpans) {
|
|
449
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(templateSpan.expression);
|
|
450
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
451
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
452
|
+
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
453
|
+
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
454
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
455
|
+
}
|
|
456
|
+
placeholderValues.push(exprValue);
|
|
457
|
+
placeholderPositions.push(exprPositions[0]);
|
|
458
|
+
stringTextPositions.push(Position_1.FullPosition.buildFromNode(templateSpan.literal, this.sourceFile));
|
|
459
|
+
stringTextValues.push(ValueUtil_1.ValueUtil.createStringConst(templateSpan.literal.rawText || ''));
|
|
460
|
+
}
|
|
461
|
+
return { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions };
|
|
462
|
+
}
|
|
463
|
+
identifierToValueAndStmts(identifier, variableDefFlag = false) {
|
|
464
|
+
let identifierValue;
|
|
465
|
+
let identifierPositions = [Position_1.FullPosition.buildFromNode(identifier, this.sourceFile)];
|
|
466
|
+
if (identifier.text === Type_1.UndefinedType.getInstance().getName()) {
|
|
467
|
+
identifierValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
if (variableDefFlag) {
|
|
471
|
+
identifierValue = this.addNewLocal(identifier.text);
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
identifierValue = this.getOrCreateLocal(identifier.text);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return { value: identifierValue, valueOriginalPositions: identifierPositions, stmts: [] };
|
|
478
|
+
}
|
|
479
|
+
propertyAccessExpressionToValue(propertyAccessExpression) {
|
|
480
|
+
const stmts = [];
|
|
481
|
+
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts, } = this.tsNodeToValueAndStmts(propertyAccessExpression.expression);
|
|
482
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
483
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(baseValue)) {
|
|
484
|
+
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
485
|
+
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
486
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
487
|
+
}
|
|
488
|
+
if (!(baseValue instanceof Local_1.Local)) {
|
|
489
|
+
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
490
|
+
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
491
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
492
|
+
}
|
|
493
|
+
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(propertyAccessExpression.name.getText(this.sourceFile));
|
|
494
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature);
|
|
495
|
+
const fieldRefPositions = [Position_1.FullPosition.buildFromNode(propertyAccessExpression, this.sourceFile), ...basePositions];
|
|
496
|
+
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
497
|
+
}
|
|
498
|
+
elementAccessExpressionToValueAndStmts(elementAccessExpression) {
|
|
499
|
+
const stmts = [];
|
|
500
|
+
let { value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
501
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
502
|
+
if (!(baseValue instanceof Local_1.Local)) {
|
|
503
|
+
({ value: baseValue, valueOriginalPositions: basePositions, stmts: baseStmts } =
|
|
504
|
+
this.arkIRTransformer.generateAssignStmtForValue(baseValue, basePositions));
|
|
505
|
+
baseStmts.forEach(stmt => stmts.push(stmt));
|
|
506
|
+
}
|
|
507
|
+
let { value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts, } = this.tsNodeToValueAndStmts(elementAccessExpression.argumentExpression);
|
|
508
|
+
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
509
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(argumentValue)) {
|
|
510
|
+
({ value: argumentValue, valueOriginalPositions: arguPositions, stmts: argumentStmts } =
|
|
511
|
+
this.arkIRTransformer.generateAssignStmtForValue(argumentValue, arguPositions));
|
|
512
|
+
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
513
|
+
}
|
|
514
|
+
let elementAccessExpr;
|
|
515
|
+
if (baseValue.getType() instanceof Type_1.ArrayType) {
|
|
516
|
+
elementAccessExpr = new Ref_1.ArkArrayRef(baseValue, argumentValue);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
// TODO: deal with ArkStaticFieldRef
|
|
520
|
+
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(argumentValue.toString());
|
|
521
|
+
elementAccessExpr = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature);
|
|
522
|
+
}
|
|
523
|
+
// reserve positions for field name
|
|
524
|
+
const exprPositions = [Position_1.FullPosition.buildFromNode(elementAccessExpression, this.sourceFile), ...basePositions,
|
|
525
|
+
...arguPositions];
|
|
526
|
+
return { value: elementAccessExpr, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
527
|
+
}
|
|
528
|
+
callExpressionToValueAndStmts(callExpression) {
|
|
529
|
+
const stmts = [];
|
|
530
|
+
const argus = this.parseArgumentsOfCallExpression(stmts, callExpression);
|
|
531
|
+
return this.generateInvokeValueAndStmts(callExpression.expression, argus, stmts, callExpression);
|
|
532
|
+
}
|
|
533
|
+
generateInvokeValueAndStmts(functionNameNode, argus, currStmts, callExpression) {
|
|
534
|
+
const stmts = [...currStmts];
|
|
535
|
+
let { value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts, } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
536
|
+
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
537
|
+
let invokeValue;
|
|
538
|
+
let invokeValuePositions = [Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile)];
|
|
539
|
+
const { args, argPositions, realGenericTypes } = argus;
|
|
540
|
+
if (callerValue instanceof Ref_1.ArkInstanceFieldRef) {
|
|
541
|
+
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
542
|
+
invokeValue = new Expr_1.ArkInstanceInvokeExpr(callerValue.getBase(), methodSignature, args, realGenericTypes);
|
|
543
|
+
invokeValuePositions.push(...callerPositions.slice(1), ...argPositions);
|
|
544
|
+
}
|
|
545
|
+
else if (callerValue instanceof Ref_1.ArkStaticFieldRef) {
|
|
546
|
+
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getFieldName());
|
|
547
|
+
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
548
|
+
invokeValuePositions.push(...argPositions);
|
|
549
|
+
}
|
|
550
|
+
else if (callerValue instanceof Local_1.Local) {
|
|
551
|
+
const callerName = callerValue.getName();
|
|
552
|
+
let classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(callerName);
|
|
553
|
+
let cls = ModelUtils_1.ModelUtils.getClass(this.declaringMethod, classSignature);
|
|
554
|
+
if ((cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) && ts.isCallExpression(callExpression)) {
|
|
555
|
+
return this.generateCustomViewStmt(callerName, args, argPositions, callExpression, stmts);
|
|
556
|
+
}
|
|
557
|
+
else if ((callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) &&
|
|
558
|
+
ts.isCallExpression(callExpression)) { // foreach/lazyforeach will be parsed as ts.callExpression
|
|
559
|
+
return this.generateSystemComponentStmt(callerName, args, argPositions, callExpression, stmts);
|
|
560
|
+
}
|
|
561
|
+
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerName);
|
|
562
|
+
if (callerValue.getType() instanceof Type_1.FunctionType) {
|
|
563
|
+
invokeValue = new Expr_1.ArkPtrInvokeExpr(methodSignature, callerValue, args, realGenericTypes);
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
567
|
+
}
|
|
568
|
+
invokeValuePositions.push(...argPositions);
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
({ value: callerValue, valueOriginalPositions: callerPositions, stmts: callerStmts } =
|
|
572
|
+
this.arkIRTransformer.generateAssignStmtForValue(callerValue, callerPositions));
|
|
573
|
+
callerStmts.forEach(stmt => stmts.push(stmt));
|
|
574
|
+
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(callerValue.getName());
|
|
575
|
+
invokeValue = new Expr_1.ArkStaticInvokeExpr(methodSignature, args, realGenericTypes);
|
|
576
|
+
invokeValuePositions.push(...argPositions);
|
|
577
|
+
}
|
|
578
|
+
return { value: invokeValue, valueOriginalPositions: invokeValuePositions, stmts: stmts };
|
|
579
|
+
}
|
|
580
|
+
parseArgumentsOfCallExpression(currStmts, callExpression) {
|
|
581
|
+
let realGenericTypes;
|
|
582
|
+
if (callExpression.typeArguments) {
|
|
583
|
+
realGenericTypes = [];
|
|
584
|
+
callExpression.typeArguments.forEach(typeArgument => {
|
|
585
|
+
realGenericTypes.push(this.resolveTypeNode(typeArgument));
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
let builderMethodIndexes;
|
|
589
|
+
if (ts.isIdentifier(callExpression.expression)) {
|
|
590
|
+
const callerName = callExpression.expression.text;
|
|
591
|
+
if (callerName === EtsConst_1.COMPONENT_FOR_EACH || callerName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) {
|
|
592
|
+
builderMethodIndexes = new Set([1]);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const { args: args, argPositions: argPositions } = this.parseArguments(currStmts, callExpression.arguments, builderMethodIndexes);
|
|
596
|
+
return { realGenericTypes: realGenericTypes, args: args, argPositions: argPositions };
|
|
597
|
+
}
|
|
598
|
+
parseArguments(currStmts, argumentNodes, builderMethodIndexes) {
|
|
599
|
+
const args = [];
|
|
600
|
+
const argPositions = [];
|
|
601
|
+
if (argumentNodes) {
|
|
602
|
+
for (let i = 0; i < argumentNodes.length; i++) {
|
|
603
|
+
const argument = argumentNodes[i];
|
|
604
|
+
const prevBuilderMethodContextFlag = this.builderMethodContextFlag;
|
|
605
|
+
if (builderMethodIndexes === null || builderMethodIndexes === void 0 ? void 0 : builderMethodIndexes.has(i)) {
|
|
606
|
+
this.builderMethodContextFlag = true;
|
|
607
|
+
this.arkIRTransformer.setBuilderMethodContextFlag(true);
|
|
608
|
+
}
|
|
609
|
+
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts, } = this.tsNodeToValueAndStmts(argument);
|
|
610
|
+
this.builderMethodContextFlag = prevBuilderMethodContextFlag;
|
|
611
|
+
this.arkIRTransformer.setBuilderMethodContextFlag(prevBuilderMethodContextFlag);
|
|
612
|
+
argStmts.forEach(s => currStmts.push(s));
|
|
613
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(argValue)) {
|
|
614
|
+
({ value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts } =
|
|
615
|
+
this.arkIRTransformer.generateAssignStmtForValue(argValue, argPositionsSingle));
|
|
616
|
+
argStmts.forEach(s => currStmts.push(s));
|
|
617
|
+
}
|
|
618
|
+
args.push(argValue);
|
|
619
|
+
argPositions.push(argPositionsSingle[0]);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return { args: args, argPositions: argPositions };
|
|
623
|
+
}
|
|
624
|
+
callableNodeToValueAndStmts(callableNode) {
|
|
625
|
+
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
626
|
+
const arrowArkMethod = new ArkMethod_1.ArkMethod();
|
|
627
|
+
if (this.builderMethodContextFlag) {
|
|
628
|
+
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arrowArkMethod);
|
|
629
|
+
}
|
|
630
|
+
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(callableNode, declaringClass, arrowArkMethod, this.sourceFile, this.declaringMethod);
|
|
631
|
+
const callableType = new Type_1.FunctionType(arrowArkMethod.getSignature());
|
|
632
|
+
const callableValue = this.addNewLocal(arrowArkMethod.getName(), callableType);
|
|
633
|
+
return {
|
|
634
|
+
value: callableValue,
|
|
635
|
+
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(callableNode, this.sourceFile)],
|
|
636
|
+
stmts: [],
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
newExpressionToValueAndStmts(newExpression) {
|
|
640
|
+
let className = '';
|
|
641
|
+
if (ts.isClassExpression(newExpression.expression) && newExpression.expression.name) {
|
|
642
|
+
className = newExpression.expression.name.text;
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
className = newExpression.expression.getText(this.sourceFile);
|
|
646
|
+
}
|
|
647
|
+
if (className === Builtin_1.Builtin.ARRAY) {
|
|
648
|
+
return this.newArrayExpressionToValueAndStmts(newExpression);
|
|
649
|
+
}
|
|
650
|
+
const stmts = [];
|
|
651
|
+
let realGenericTypes;
|
|
652
|
+
if (newExpression.typeArguments) {
|
|
653
|
+
realGenericTypes = [];
|
|
654
|
+
newExpression.typeArguments.forEach(typeArgument => {
|
|
655
|
+
realGenericTypes.push(this.resolveTypeNode(typeArgument));
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const classSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildClassSignatureFromClassName(className);
|
|
659
|
+
const classType = new Type_1.ClassType(classSignature, realGenericTypes);
|
|
660
|
+
const newExpr = new Expr_1.ArkNewExpr(classType);
|
|
661
|
+
const { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [Position_1.FullPosition.buildFromNode(newExpression, this.sourceFile)]);
|
|
662
|
+
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
663
|
+
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
664
|
+
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
665
|
+
const { args: argValues, argPositions: argPositions } = this.parseArguments(stmts, newExpression.arguments);
|
|
666
|
+
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newLocal, constructorMethodSignature, argValues);
|
|
667
|
+
const instanceInvokeExprPositions = [newLocalPositions[0], ...newLocalPositions, ...argPositions];
|
|
668
|
+
const invokeStmt = new Stmt_1.ArkInvokeStmt(instanceInvokeExpr);
|
|
669
|
+
invokeStmt.setOperandOriginalPositions(instanceInvokeExprPositions);
|
|
670
|
+
stmts.push(invokeStmt);
|
|
671
|
+
return { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: stmts };
|
|
672
|
+
}
|
|
673
|
+
newArrayExpressionToValueAndStmts(newArrayExpression) {
|
|
674
|
+
let baseType = Type_1.UnknownType.getInstance();
|
|
675
|
+
if (newArrayExpression.typeArguments && newArrayExpression.typeArguments.length > 0) {
|
|
676
|
+
const argumentType = this.resolveTypeNode(newArrayExpression.typeArguments[0]);
|
|
677
|
+
if (!(argumentType instanceof Type_1.AnyType || argumentType instanceof Type_1.UnknownType)) {
|
|
678
|
+
baseType = argumentType;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
const stmts = [];
|
|
682
|
+
const { args: argumentValues, argPositions: argPositions } = this.parseArguments(stmts, newArrayExpression.arguments);
|
|
683
|
+
let argumentsLength = newArrayExpression.arguments ? newArrayExpression.arguments.length : 0;
|
|
684
|
+
let arrayLengthValue;
|
|
685
|
+
let arrayLength = -1;
|
|
686
|
+
let arrayLengthPosition = Position_1.FullPosition.DEFAULT;
|
|
687
|
+
if ((argumentsLength === 1) &&
|
|
688
|
+
((argumentValues[0].getType() instanceof Type_1.NumberType) || argumentValues[0].getType() instanceof
|
|
689
|
+
Type_1.UnknownType)) {
|
|
690
|
+
arrayLengthValue = argumentValues[0];
|
|
691
|
+
arrayLengthPosition = argPositions[0];
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
arrayLengthValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(argumentsLength);
|
|
695
|
+
arrayLength = argumentsLength;
|
|
696
|
+
}
|
|
697
|
+
if (baseType instanceof Type_1.UnknownType) {
|
|
698
|
+
if ((argumentsLength > 1) && !(argumentValues[0].getType() instanceof Type_1.UnknownType)) {
|
|
699
|
+
baseType = argumentValues[0].getType();
|
|
700
|
+
}
|
|
701
|
+
else {
|
|
702
|
+
baseType = Type_1.AnyType.getInstance();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(newArrayExpression, this.sourceFile);
|
|
706
|
+
return this.generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, argumentValues, argPositions, stmts, newArrayExprPosition, false);
|
|
707
|
+
}
|
|
708
|
+
arrayLiteralExpressionToValueAndStmts(arrayLiteralExpression) {
|
|
709
|
+
const stmts = [];
|
|
710
|
+
const elementTypes = new Set();
|
|
711
|
+
const elementValues = [];
|
|
712
|
+
const elementPositions = [];
|
|
713
|
+
const arrayLength = arrayLiteralExpression.elements.length;
|
|
714
|
+
for (const element of arrayLiteralExpression.elements) {
|
|
715
|
+
let { value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts, } = this.tsNodeToValueAndStmts(element);
|
|
716
|
+
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
717
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(elementValue)) {
|
|
718
|
+
({ value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts } =
|
|
719
|
+
this.arkIRTransformer.generateAssignStmtForValue(elementValue, elementPosition));
|
|
720
|
+
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
721
|
+
}
|
|
722
|
+
elementValues.push(elementValue);
|
|
723
|
+
elementTypes.add(elementValue.getType());
|
|
724
|
+
elementPositions.push(elementPosition[0]);
|
|
725
|
+
}
|
|
726
|
+
let baseType = Type_1.AnyType.getInstance();
|
|
727
|
+
if (elementTypes.size === 1) {
|
|
728
|
+
baseType = elementTypes.keys().next().value;
|
|
729
|
+
}
|
|
730
|
+
else if (elementTypes.size > 1) {
|
|
731
|
+
baseType = new Type_1.UnionType(Array.from(elementTypes));
|
|
732
|
+
}
|
|
733
|
+
const newArrayExprPosition = Position_1.FullPosition.buildFromNode(arrayLiteralExpression, this.sourceFile);
|
|
734
|
+
return this.generateArrayExprAndStmts(baseType, ValueUtil_1.ValueUtil.getOrCreateNumberConst(arrayLength), Position_1.FullPosition.DEFAULT, arrayLength, elementValues, elementPositions, stmts, newArrayExprPosition, true);
|
|
735
|
+
}
|
|
736
|
+
generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, initializerValues, initializerPositions, currStmts, newArrayExprPosition, fromLiteral) {
|
|
737
|
+
const stmts = [...currStmts];
|
|
738
|
+
const newArrayExpr = new Expr_1.ArkNewArrayExpr(baseType, arrayLengthValue, fromLiteral);
|
|
739
|
+
const newArrayExprPositions = [newArrayExprPosition, arrayLengthPosition];
|
|
740
|
+
const { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: arrayStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newArrayExpr, newArrayExprPositions);
|
|
741
|
+
arrayStmts.forEach(stmt => stmts.push(stmt));
|
|
742
|
+
for (let i = 0; i < arrayLength; i++) {
|
|
743
|
+
const indexValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(i);
|
|
744
|
+
const arrayRef = new Ref_1.ArkArrayRef(arrayLocal, indexValue);
|
|
745
|
+
const arrayRefPositions = [arrayLocalPositions[0], ...arrayLocalPositions, Position_1.FullPosition.DEFAULT];
|
|
746
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(arrayRef, initializerValues[i]);
|
|
747
|
+
assignStmt.setOperandOriginalPositions([...arrayRefPositions, initializerPositions[i]]);
|
|
748
|
+
stmts.push(assignStmt);
|
|
749
|
+
}
|
|
750
|
+
return { value: arrayLocal, valueOriginalPositions: arrayLocalPositions, stmts: stmts };
|
|
751
|
+
}
|
|
752
|
+
prefixUnaryExpressionToValueAndStmts(prefixUnaryExpression) {
|
|
753
|
+
const stmts = [];
|
|
754
|
+
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts, } = this.tsNodeToValueAndStmts(prefixUnaryExpression.operand);
|
|
755
|
+
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
756
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
757
|
+
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: operandStmts } =
|
|
758
|
+
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
759
|
+
operandStmts.forEach(stmt => stmts.push(stmt));
|
|
760
|
+
}
|
|
761
|
+
const operatorToken = prefixUnaryExpression.operator;
|
|
762
|
+
let exprPositions = [Position_1.FullPosition.buildFromNode(prefixUnaryExpression, this.sourceFile)];
|
|
763
|
+
if (operatorToken === ts.SyntaxKind.PlusPlusToken || operatorToken === ts.SyntaxKind.MinusMinusToken) {
|
|
764
|
+
const binaryOperator = operatorToken === ts.SyntaxKind.PlusPlusToken ? Expr_1.NormalBinaryOperator.Addition : Expr_1.NormalBinaryOperator.Subtraction;
|
|
765
|
+
const binopExpr = new Expr_1.ArkNormalBinopExpr(operandValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(1), binaryOperator);
|
|
766
|
+
exprPositions.push(...operandPositions, Position_1.FullPosition.DEFAULT);
|
|
767
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(operandValue, binopExpr);
|
|
768
|
+
assignStmt.setOperandOriginalPositions([...operandPositions, ...exprPositions]);
|
|
769
|
+
stmts.push(assignStmt);
|
|
770
|
+
return { value: operandValue, valueOriginalPositions: operandPositions, stmts: stmts };
|
|
771
|
+
}
|
|
772
|
+
else if (operatorToken === ts.SyntaxKind.PlusToken) {
|
|
773
|
+
return { value: operandValue, valueOriginalPositions: operandPositions, stmts: stmts };
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
let unopExpr;
|
|
777
|
+
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToUnaryOperator(operatorToken);
|
|
778
|
+
if (operator) {
|
|
779
|
+
unopExpr = new Expr_1.ArkUnopExpr(operandValue, operator);
|
|
780
|
+
exprPositions.push(...operandPositions);
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
unopExpr = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
784
|
+
exprPositions = [Position_1.FullPosition.DEFAULT];
|
|
785
|
+
}
|
|
786
|
+
return { value: unopExpr, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
postfixUnaryExpressionToValueAndStmts(postfixUnaryExpression) {
|
|
790
|
+
const stmts = [];
|
|
791
|
+
let { value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(postfixUnaryExpression.operand);
|
|
792
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
793
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(operandValue)) {
|
|
794
|
+
({ value: operandValue, valueOriginalPositions: operandPositions, stmts: exprStmts } =
|
|
795
|
+
this.arkIRTransformer.generateAssignStmtForValue(operandValue, operandPositions));
|
|
796
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
797
|
+
}
|
|
798
|
+
let value;
|
|
799
|
+
let exprPositions = [Position_1.FullPosition.buildFromNode(postfixUnaryExpression, this.sourceFile)];
|
|
800
|
+
const operatorToken = postfixUnaryExpression.operator;
|
|
801
|
+
if (operatorToken === ts.SyntaxKind.PlusPlusToken || operatorToken === ts.SyntaxKind.MinusMinusToken) {
|
|
802
|
+
const binaryOperator = operatorToken === ts.SyntaxKind.PlusPlusToken ? Expr_1.NormalBinaryOperator.Addition : Expr_1.NormalBinaryOperator.Subtraction;
|
|
803
|
+
const binopExpr = new Expr_1.ArkNormalBinopExpr(operandValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(1), binaryOperator);
|
|
804
|
+
exprPositions.push(...operandPositions, Position_1.FullPosition.DEFAULT);
|
|
805
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(operandValue, binopExpr);
|
|
806
|
+
assignStmt.setOperandOriginalPositions([...operandPositions, ...exprPositions]);
|
|
807
|
+
stmts.push(assignStmt);
|
|
808
|
+
value = operandValue;
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
value = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
812
|
+
exprPositions = [Position_1.FullPosition.DEFAULT];
|
|
813
|
+
}
|
|
814
|
+
return { value: value, valueOriginalPositions: exprPositions, stmts: stmts };
|
|
815
|
+
}
|
|
816
|
+
awaitExpressionToValueAndStmts(awaitExpression) {
|
|
817
|
+
const stmts = [];
|
|
818
|
+
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts, } = this.tsNodeToValueAndStmts(awaitExpression.expression);
|
|
819
|
+
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
820
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(promiseValue)) {
|
|
821
|
+
({ value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts } =
|
|
822
|
+
this.arkIRTransformer.generateAssignStmtForValue(promiseValue, promisePositions));
|
|
823
|
+
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
824
|
+
}
|
|
825
|
+
const awaitExpr = new Expr_1.ArkAwaitExpr(promiseValue);
|
|
826
|
+
const awaitExprPositions = [Position_1.FullPosition.buildFromNode(awaitExpression, this.sourceFile), ...promisePositions];
|
|
827
|
+
return { value: awaitExpr, valueOriginalPositions: awaitExprPositions, stmts: stmts };
|
|
828
|
+
}
|
|
829
|
+
yieldExpressionToValueAndStmts(yieldExpression) {
|
|
830
|
+
let yieldValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
831
|
+
let yieldPositions = [Position_1.FullPosition.DEFAULT];
|
|
832
|
+
let stmts = [];
|
|
833
|
+
if (yieldExpression.expression) {
|
|
834
|
+
({ value: yieldValue, valueOriginalPositions: yieldPositions, stmts: stmts } =
|
|
835
|
+
this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
836
|
+
}
|
|
837
|
+
const yieldExpr = new Expr_1.ArkYieldExpr(yieldValue);
|
|
838
|
+
const yieldExprPositions = [Position_1.FullPosition.buildFromNode(yieldExpression, this.sourceFile), ...yieldPositions];
|
|
839
|
+
return { value: yieldExpr, valueOriginalPositions: yieldExprPositions, stmts: stmts };
|
|
840
|
+
}
|
|
841
|
+
deleteExpressionToValueAndStmts(deleteExpression) {
|
|
842
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(deleteExpression.expression);
|
|
843
|
+
const deleteExpr = new Expr_1.ArkDeleteExpr(exprValue);
|
|
844
|
+
const deleteExprPositions = [Position_1.FullPosition.buildFromNode(deleteExpression, this.sourceFile),
|
|
845
|
+
...exprPositions];
|
|
846
|
+
return { value: deleteExpr, valueOriginalPositions: deleteExprPositions, stmts: stmts };
|
|
847
|
+
}
|
|
848
|
+
voidExpressionToValueAndStmts(voidExpression) {
|
|
849
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(voidExpression.expression);
|
|
850
|
+
const { stmts: exprStmts } = this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions);
|
|
851
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
852
|
+
return { value: ValueUtil_1.ValueUtil.getUndefinedConst(), valueOriginalPositions: [Position_1.FullPosition.DEFAULT], stmts: stmts };
|
|
853
|
+
}
|
|
854
|
+
nonNullExpressionToValueAndStmts(nonNullExpression) {
|
|
855
|
+
return this.tsNodeToValueAndStmts(nonNullExpression.expression);
|
|
856
|
+
}
|
|
857
|
+
parenthesizedExpressionToValueAndStmts(parenthesizedExpression) {
|
|
858
|
+
return this.tsNodeToValueAndStmts(parenthesizedExpression.expression);
|
|
859
|
+
}
|
|
860
|
+
typeOfExpressionToValueAndStmts(typeOfExpression) {
|
|
861
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(typeOfExpression.expression);
|
|
862
|
+
const typeOfExpr = new Expr_1.ArkTypeOfExpr(exprValue);
|
|
863
|
+
const typeOfExprPositions = [Position_1.FullPosition.buildFromNode(typeOfExpression, this.sourceFile), ...exprPositions];
|
|
864
|
+
return { value: typeOfExpr, valueOriginalPositions: typeOfExprPositions, stmts: exprStmts };
|
|
865
|
+
}
|
|
866
|
+
asExpressionToValueAndStmts(asExpression) {
|
|
867
|
+
const stmts = [];
|
|
868
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(asExpression.expression);
|
|
869
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
870
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
871
|
+
({ value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } =
|
|
872
|
+
this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions));
|
|
873
|
+
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
874
|
+
}
|
|
875
|
+
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(asExpression.type));
|
|
876
|
+
const castExprPositions = [Position_1.FullPosition.buildFromNode(asExpression, this.sourceFile), ...exprPositions];
|
|
877
|
+
return { value: castExpr, valueOriginalPositions: castExprPositions, stmts: stmts };
|
|
878
|
+
}
|
|
879
|
+
typeAssertionToValueAndStmts(typeAssertion) {
|
|
880
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.tsNodeToValueAndStmts(typeAssertion.expression);
|
|
881
|
+
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(typeAssertion.type));
|
|
882
|
+
const castExprPositions = [Position_1.FullPosition.buildFromNode(typeAssertion, this.sourceFile), ...exprPositions];
|
|
883
|
+
return { value: castExpr, valueOriginalPositions: castExprPositions, stmts: exprStmts };
|
|
884
|
+
}
|
|
885
|
+
variableDeclarationListToValueAndStmts(variableDeclarationList) {
|
|
886
|
+
const stmts = [];
|
|
887
|
+
const isConst = (variableDeclarationList.flags & ts.NodeFlags.Const) !== 0;
|
|
888
|
+
for (const declaration of variableDeclarationList.declarations) {
|
|
889
|
+
const { stmts: declaredStmts } = this.variableDeclarationToValueAndStmts(declaration, isConst);
|
|
890
|
+
declaredStmts.forEach(s => stmts.push(s));
|
|
891
|
+
}
|
|
892
|
+
return { value: ValueUtil_1.ValueUtil.getUndefinedConst(), valueOriginalPositions: [Position_1.FullPosition.DEFAULT], stmts: stmts };
|
|
893
|
+
}
|
|
894
|
+
variableDeclarationToValueAndStmts(variableDeclaration, isConst, needRightOp = true) {
|
|
895
|
+
const leftOpNode = variableDeclaration.name;
|
|
896
|
+
const rightOpNode = variableDeclaration.initializer;
|
|
897
|
+
const declarationType = variableDeclaration.type ? this.resolveTypeNode(variableDeclaration.type) : Type_1.UnknownType.getInstance();
|
|
898
|
+
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, true, isConst, declarationType, needRightOp);
|
|
899
|
+
}
|
|
900
|
+
assignmentToValueAndStmts(leftOpNode, rightOpNode, variableDefFlag, isConst, declarationType, needRightOp = true) {
|
|
901
|
+
let leftValueAndStmts;
|
|
902
|
+
if (ts.isIdentifier(leftOpNode)) {
|
|
903
|
+
leftValueAndStmts = this.identifierToValueAndStmts(leftOpNode, variableDefFlag);
|
|
904
|
+
}
|
|
905
|
+
else if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode)) {
|
|
906
|
+
leftValueAndStmts = this.arrayDestructuringToValueAndStmts(leftOpNode, isConst);
|
|
907
|
+
}
|
|
908
|
+
else if (ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
909
|
+
leftValueAndStmts = this.objectDestructuringToValueAndStmts(leftOpNode, isConst);
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
leftValueAndStmts = this.tsNodeToValueAndStmts(leftOpNode);
|
|
913
|
+
}
|
|
914
|
+
const { value: leftValue, valueOriginalPositions: leftPositions, stmts: leftStmts } = leftValueAndStmts;
|
|
915
|
+
let stmts = [];
|
|
916
|
+
if (needRightOp) {
|
|
917
|
+
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.assignmentRightOpToValueAndStmts(rightOpNode, leftValue);
|
|
918
|
+
if (leftValue instanceof Local_1.Local) {
|
|
919
|
+
if (variableDefFlag) {
|
|
920
|
+
leftValue.setConstFlag(isConst);
|
|
921
|
+
leftValue.setType(declarationType);
|
|
922
|
+
}
|
|
923
|
+
if (leftValue.getType() instanceof Type_1.UnknownType && !(rightValue.getType() instanceof Type_1.UnknownType) &&
|
|
924
|
+
!(rightValue.getType() instanceof Type_1.UndefinedType)) {
|
|
925
|
+
leftValue.setType(rightValue.getType());
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
929
|
+
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
930
|
+
if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode) ||
|
|
931
|
+
ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
932
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
933
|
+
stmts.push(assignStmt);
|
|
934
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
938
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
939
|
+
stmts.push(assignStmt);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
stmts = leftStmts;
|
|
944
|
+
}
|
|
945
|
+
return { value: leftValue, valueOriginalPositions: leftPositions, stmts: stmts };
|
|
946
|
+
}
|
|
947
|
+
assignmentRightOpToValueAndStmts(rightOpNode, leftValue) {
|
|
948
|
+
let rightValue;
|
|
949
|
+
let rightPositions;
|
|
950
|
+
let tempRightStmts = [];
|
|
951
|
+
const rightStmts = [];
|
|
952
|
+
if (rightOpNode) {
|
|
953
|
+
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
954
|
+
this.tsNodeToValueAndStmts(rightOpNode));
|
|
955
|
+
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
rightValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
959
|
+
rightPositions = [Position_1.FullPosition.DEFAULT];
|
|
960
|
+
}
|
|
961
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
962
|
+
({ value: rightValue, valueOriginalPositions: rightPositions, stmts: tempRightStmts } =
|
|
963
|
+
this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions));
|
|
964
|
+
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
965
|
+
}
|
|
966
|
+
return { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts };
|
|
967
|
+
}
|
|
968
|
+
// In assignment patterns, the left operand will be an array literal expression
|
|
969
|
+
arrayDestructuringToValueAndStmts(arrayDestructuring, isConst = false) {
|
|
970
|
+
const stmts = [];
|
|
971
|
+
const arrayTempLocal = this.generateTempLocal();
|
|
972
|
+
const leftOriginalPosition = Position_1.FullPosition.buildFromNode(arrayDestructuring, this.sourceFile);
|
|
973
|
+
const elements = arrayDestructuring.elements;
|
|
974
|
+
const isArrayBindingPattern = ts.isArrayBindingPattern(arrayDestructuring);
|
|
975
|
+
let index = 0;
|
|
976
|
+
for (const element of elements) {
|
|
977
|
+
const arrayRef = new Ref_1.ArkArrayRef(arrayTempLocal, ValueUtil_1.ValueUtil.getOrCreateNumberConst(index));
|
|
978
|
+
const arrayRefPositions = [leftOriginalPosition, leftOriginalPosition, Position_1.FullPosition.DEFAULT];
|
|
979
|
+
const itemName = element.getText(this.sourceFile);
|
|
980
|
+
const targetLocal = isArrayBindingPattern ? this.addNewLocal(itemName) : this.getOrCreateLocal(itemName);
|
|
981
|
+
const targetLocalPosition = Position_1.FullPosition.buildFromNode(element, this.sourceFile);
|
|
982
|
+
isArrayBindingPattern && targetLocal.setConstFlag(isConst);
|
|
983
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, arrayRef);
|
|
984
|
+
assignStmt.setOperandOriginalPositions([targetLocalPosition, ...arrayRefPositions]);
|
|
985
|
+
stmts.push(assignStmt);
|
|
986
|
+
index++;
|
|
987
|
+
}
|
|
988
|
+
return { value: arrayTempLocal, valueOriginalPositions: [leftOriginalPosition], stmts: stmts };
|
|
989
|
+
}
|
|
990
|
+
// In assignment patterns, the left operand will be an object literal expression
|
|
991
|
+
objectDestructuringToValueAndStmts(objectDestructuring, isConst = false) {
|
|
992
|
+
const stmts = [];
|
|
993
|
+
const objectTempLocal = this.generateTempLocal();
|
|
994
|
+
const leftOriginalPosition = Position_1.FullPosition.buildFromNode(objectDestructuring, this.sourceFile);
|
|
995
|
+
const isObjectBindingPattern = ts.isObjectBindingPattern(objectDestructuring);
|
|
996
|
+
const elements = isObjectBindingPattern ? objectDestructuring.elements : objectDestructuring.properties;
|
|
997
|
+
for (const element of elements) {
|
|
998
|
+
let fieldName = '';
|
|
999
|
+
let targetName = '';
|
|
1000
|
+
if (ts.isBindingElement(element)) {
|
|
1001
|
+
fieldName = element.propertyName ? element.propertyName.getText(this.sourceFile) : element.name.getText(this.sourceFile);
|
|
1002
|
+
targetName = element.name.getText(this.sourceFile);
|
|
1003
|
+
}
|
|
1004
|
+
else if (ts.isPropertyAssignment(element)) {
|
|
1005
|
+
fieldName = element.name.getText(this.sourceFile);
|
|
1006
|
+
targetName = element.initializer.getText(this.sourceFile);
|
|
1007
|
+
}
|
|
1008
|
+
else if (ts.isShorthandPropertyAssignment(element)) {
|
|
1009
|
+
fieldName = element.name.getText(this.sourceFile);
|
|
1010
|
+
targetName = fieldName;
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
const fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(fieldName);
|
|
1016
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(objectTempLocal, fieldSignature);
|
|
1017
|
+
const fieldRefPositions = [leftOriginalPosition, leftOriginalPosition];
|
|
1018
|
+
const targetLocal = isObjectBindingPattern ? this.addNewLocal(targetName) : this.getOrCreateLocal(targetName);
|
|
1019
|
+
isObjectBindingPattern && targetLocal.setConstFlag(isConst);
|
|
1020
|
+
const targetLocalPosition = Position_1.FullPosition.buildFromNode(element, this.sourceFile);
|
|
1021
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, fieldRef);
|
|
1022
|
+
assignStmt.setOperandOriginalPositions([targetLocalPosition, ...fieldRefPositions]);
|
|
1023
|
+
stmts.push(assignStmt);
|
|
1024
|
+
}
|
|
1025
|
+
return { value: objectTempLocal, valueOriginalPositions: [leftOriginalPosition], stmts: stmts };
|
|
1026
|
+
}
|
|
1027
|
+
binaryExpressionToValueAndStmts(binaryExpression) {
|
|
1028
|
+
const operatorToken = binaryExpression.operatorToken;
|
|
1029
|
+
if (operatorToken.kind === ts.SyntaxKind.FirstAssignment) {
|
|
1030
|
+
const leftOpNode = binaryExpression.left;
|
|
1031
|
+
const rightOpNode = binaryExpression.right;
|
|
1032
|
+
const declarationType = Type_1.UnknownType.getInstance();
|
|
1033
|
+
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, false, false, declarationType, true);
|
|
1034
|
+
}
|
|
1035
|
+
else if (ArkValueTransformer.isCompoundAssignmentOperator(operatorToken.kind)) {
|
|
1036
|
+
return this.compoundAssignmentToValueAndStmts(binaryExpression);
|
|
1037
|
+
}
|
|
1038
|
+
const stmts = [];
|
|
1039
|
+
const binaryExpressionPosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1040
|
+
const { value: opValue1, valueOriginalPositions: opPositions1, stmts: opStmts1, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.left);
|
|
1041
|
+
opStmts1.forEach(stmt => stmts.push(stmt));
|
|
1042
|
+
if (operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
1043
|
+
const instanceOfExpr = new Expr_1.ArkInstanceOfExpr(opValue1, new Type_1.UnclearReferenceType(binaryExpression.right.getText(this.sourceFile)));
|
|
1044
|
+
const instanceOfExprPositions = [binaryExpressionPosition, ...opPositions1];
|
|
1045
|
+
return { value: instanceOfExpr, valueOriginalPositions: instanceOfExprPositions, stmts: stmts };
|
|
1046
|
+
}
|
|
1047
|
+
const { value: opValue2, valueOriginalPositions: opPositions2, stmts: opStmts2, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1048
|
+
opStmts2.forEach(stmt => stmts.push(stmt));
|
|
1049
|
+
let exprValue;
|
|
1050
|
+
let exprValuePositions = [binaryExpressionPosition];
|
|
1051
|
+
if (operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
1052
|
+
exprValue = opValue2;
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToBinaryOperator(operatorToken.kind);
|
|
1056
|
+
if (operator) {
|
|
1057
|
+
if (this.isRelationalOperator(operator)) {
|
|
1058
|
+
exprValue = new Expr_1.ArkConditionExpr(opValue1, opValue2, operator);
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
exprValue = new Expr_1.ArkNormalBinopExpr(opValue1, opValue2, operator);
|
|
1062
|
+
}
|
|
1063
|
+
exprValuePositions.push(...opPositions1, ...opPositions2);
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
exprValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1067
|
+
exprValuePositions.push(binaryExpressionPosition);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return { value: exprValue, valueOriginalPositions: exprValuePositions, stmts: stmts };
|
|
1071
|
+
}
|
|
1072
|
+
compoundAssignmentToValueAndStmts(binaryExpression) {
|
|
1073
|
+
const stmts = [];
|
|
1074
|
+
let { value: leftValue, valueOriginalPositions: leftPositions, stmts: leftStmts, } = this.tsNodeToValueAndStmts(binaryExpression.left);
|
|
1075
|
+
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1076
|
+
let { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToValueAndStmts(binaryExpression.right);
|
|
1077
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1078
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
1079
|
+
const { value: newRightValue, valueOriginalPositions: newRightPositions, stmts: rightStmts, } = this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions);
|
|
1080
|
+
rightValue = newRightValue;
|
|
1081
|
+
rightPositions = newRightPositions;
|
|
1082
|
+
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1083
|
+
}
|
|
1084
|
+
let leftOpValue;
|
|
1085
|
+
let leftOpPositions;
|
|
1086
|
+
const operator = this.compoundAssignmentTokenToBinaryOperator(binaryExpression.operatorToken.kind);
|
|
1087
|
+
if (operator) {
|
|
1088
|
+
const exprValue = new Expr_1.ArkNormalBinopExpr(leftValue, rightValue, operator);
|
|
1089
|
+
const exprValuePosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1090
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, exprValue);
|
|
1091
|
+
assignStmt.setOperandOriginalPositions([...leftPositions, exprValuePosition, ...leftPositions, ...rightPositions]);
|
|
1092
|
+
stmts.push(assignStmt);
|
|
1093
|
+
leftOpValue = leftValue;
|
|
1094
|
+
leftOpPositions = leftPositions;
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
leftOpValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1098
|
+
leftOpPositions = [leftPositions[0]];
|
|
1099
|
+
}
|
|
1100
|
+
return { value: leftOpValue, valueOriginalPositions: leftOpPositions, stmts: stmts };
|
|
1101
|
+
}
|
|
1102
|
+
compoundAssignmentTokenToBinaryOperator(token) {
|
|
1103
|
+
switch (token) {
|
|
1104
|
+
case ts.SyntaxKind.QuestionQuestionEqualsToken:
|
|
1105
|
+
return Expr_1.NormalBinaryOperator.NullishCoalescing;
|
|
1106
|
+
case ts.SyntaxKind.AsteriskAsteriskEqualsToken:
|
|
1107
|
+
return Expr_1.NormalBinaryOperator.Exponentiation;
|
|
1108
|
+
case ts.SyntaxKind.SlashEqualsToken:
|
|
1109
|
+
return Expr_1.NormalBinaryOperator.Division;
|
|
1110
|
+
case ts.SyntaxKind.PlusEqualsToken:
|
|
1111
|
+
return Expr_1.NormalBinaryOperator.Addition;
|
|
1112
|
+
case ts.SyntaxKind.MinusEqualsToken:
|
|
1113
|
+
return Expr_1.NormalBinaryOperator.Subtraction;
|
|
1114
|
+
case ts.SyntaxKind.AsteriskEqualsToken:
|
|
1115
|
+
return Expr_1.NormalBinaryOperator.Multiplication;
|
|
1116
|
+
case ts.SyntaxKind.PercentEqualsToken:
|
|
1117
|
+
return Expr_1.NormalBinaryOperator.Remainder;
|
|
1118
|
+
case ts.SyntaxKind.LessThanLessThanEqualsToken:
|
|
1119
|
+
return Expr_1.NormalBinaryOperator.LeftShift;
|
|
1120
|
+
case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
|
|
1121
|
+
return Expr_1.NormalBinaryOperator.RightShift;
|
|
1122
|
+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
|
|
1123
|
+
return Expr_1.NormalBinaryOperator.UnsignedRightShift;
|
|
1124
|
+
case ts.SyntaxKind.AmpersandEqualsToken:
|
|
1125
|
+
return Expr_1.NormalBinaryOperator.BitwiseAnd;
|
|
1126
|
+
case ts.SyntaxKind.BarEqualsToken:
|
|
1127
|
+
return Expr_1.NormalBinaryOperator.BitwiseOr;
|
|
1128
|
+
case ts.SyntaxKind.CaretEqualsToken:
|
|
1129
|
+
return Expr_1.NormalBinaryOperator.BitwiseXor;
|
|
1130
|
+
case ts.SyntaxKind.AmpersandAmpersandEqualsToken:
|
|
1131
|
+
return Expr_1.NormalBinaryOperator.LogicalAnd;
|
|
1132
|
+
case ts.SyntaxKind.BarBarEqualsToken:
|
|
1133
|
+
return Expr_1.NormalBinaryOperator.LogicalOr;
|
|
1134
|
+
default:
|
|
1135
|
+
;
|
|
1136
|
+
}
|
|
1137
|
+
return null;
|
|
1138
|
+
}
|
|
1139
|
+
conditionToValueAndStmts(condition) {
|
|
1140
|
+
const stmts = [];
|
|
1141
|
+
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.tsNodeToValueAndStmts(condition);
|
|
1142
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1143
|
+
let conditionExpr;
|
|
1144
|
+
if ((conditionValue instanceof Expr_1.AbstractBinopExpr) && this.isRelationalOperator(conditionValue.getOperator())) {
|
|
1145
|
+
const operator = conditionValue.getOperator();
|
|
1146
|
+
conditionExpr = new Expr_1.ArkConditionExpr(conditionValue.getOp1(), conditionValue.getOp2(), operator);
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(conditionValue)) {
|
|
1150
|
+
({
|
|
1151
|
+
value: conditionValue,
|
|
1152
|
+
valueOriginalPositions: conditionPositions,
|
|
1153
|
+
stmts: conditionStmts,
|
|
1154
|
+
} = this.arkIRTransformer.generateAssignStmtForValue(conditionValue, conditionPositions));
|
|
1155
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1156
|
+
}
|
|
1157
|
+
conditionExpr = new Expr_1.ArkConditionExpr(conditionValue, ValueUtil_1.ValueUtil.getOrCreateNumberConst(0), Expr_1.RelationalBinaryOperator.InEquality);
|
|
1158
|
+
conditionPositions = [conditionPositions[0], ...conditionPositions, Position_1.FullPosition.DEFAULT];
|
|
1159
|
+
}
|
|
1160
|
+
return { value: conditionExpr, valueOriginalPositions: conditionPositions, stmts: stmts };
|
|
1161
|
+
}
|
|
1162
|
+
literalNodeToValueAndStmts(literalNode) {
|
|
1163
|
+
const syntaxKind = literalNode.kind;
|
|
1164
|
+
let constant = null;
|
|
1165
|
+
switch (syntaxKind) {
|
|
1166
|
+
case ts.SyntaxKind.NumericLiteral:
|
|
1167
|
+
constant = ValueUtil_1.ValueUtil.getOrCreateNumberConst(parseFloat(literalNode.text));
|
|
1168
|
+
break;
|
|
1169
|
+
case ts.SyntaxKind.BigIntLiteral:
|
|
1170
|
+
constant = ValueUtil_1.ValueUtil.getOrCreateNumberConst(parseInt(literalNode.text));
|
|
1171
|
+
break;
|
|
1172
|
+
case ts.SyntaxKind.StringLiteral:
|
|
1173
|
+
constant = ValueUtil_1.ValueUtil.createStringConst(literalNode.text);
|
|
1174
|
+
break;
|
|
1175
|
+
case ts.SyntaxKind.RegularExpressionLiteral:
|
|
1176
|
+
constant = new Constant_1.Constant(literalNode.text, Builtin_1.Builtin.REGEXP_CLASS_TYPE);
|
|
1177
|
+
break;
|
|
1178
|
+
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
1179
|
+
constant = ValueUtil_1.ValueUtil.createStringConst(literalNode.text);
|
|
1180
|
+
break;
|
|
1181
|
+
case ts.SyntaxKind.NullKeyword:
|
|
1182
|
+
constant = ValueUtil_1.ValueUtil.getNullConstant();
|
|
1183
|
+
break;
|
|
1184
|
+
case ts.SyntaxKind.UndefinedKeyword:
|
|
1185
|
+
constant = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1186
|
+
break;
|
|
1187
|
+
case ts.SyntaxKind.TrueKeyword:
|
|
1188
|
+
constant = ValueUtil_1.ValueUtil.getBooleanConstant(true);
|
|
1189
|
+
break;
|
|
1190
|
+
case ts.SyntaxKind.FalseKeyword:
|
|
1191
|
+
constant = ValueUtil_1.ValueUtil.getBooleanConstant(false);
|
|
1192
|
+
break;
|
|
1193
|
+
default:
|
|
1194
|
+
logger.warn(`ast node's syntaxKind is ${ts.SyntaxKind[literalNode.kind]}, not literalNode`);
|
|
1195
|
+
}
|
|
1196
|
+
if (constant === null) {
|
|
1197
|
+
return null;
|
|
1198
|
+
}
|
|
1199
|
+
return {
|
|
1200
|
+
value: constant,
|
|
1201
|
+
valueOriginalPositions: [Position_1.FullPosition.buildFromNode(literalNode, this.sourceFile)],
|
|
1202
|
+
stmts: [],
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
getOrCreateLocal(localName, localType = Type_1.UnknownType.getInstance()) {
|
|
1206
|
+
let local = this.locals.get(localName);
|
|
1207
|
+
if (local !== undefined) {
|
|
1208
|
+
return local;
|
|
1209
|
+
}
|
|
1210
|
+
local = this.addNewLocal(localName, localType);
|
|
1211
|
+
this.addNewGlobal(localName);
|
|
1212
|
+
return local;
|
|
1213
|
+
}
|
|
1214
|
+
generateTempLocal(localType = Type_1.UnknownType.getInstance()) {
|
|
1215
|
+
const tempLocalName = Const_1.TEMP_LOCAL_PREFIX + this.tempLocalNo;
|
|
1216
|
+
this.tempLocalNo++;
|
|
1217
|
+
const tempLocal = new Local_1.Local(tempLocalName, localType);
|
|
1218
|
+
this.locals.set(tempLocalName, tempLocal);
|
|
1219
|
+
return tempLocal;
|
|
1220
|
+
}
|
|
1221
|
+
isRelationalOperator(operator) {
|
|
1222
|
+
return operator === Expr_1.RelationalBinaryOperator.LessThan ||
|
|
1223
|
+
operator === Expr_1.RelationalBinaryOperator.LessThanOrEqual ||
|
|
1224
|
+
operator === Expr_1.RelationalBinaryOperator.GreaterThan ||
|
|
1225
|
+
operator === Expr_1.RelationalBinaryOperator.GreaterThanOrEqual ||
|
|
1226
|
+
operator === Expr_1.RelationalBinaryOperator.Equality ||
|
|
1227
|
+
operator === Expr_1.RelationalBinaryOperator.InEquality ||
|
|
1228
|
+
operator === Expr_1.RelationalBinaryOperator.StrictEquality ||
|
|
1229
|
+
operator === Expr_1.RelationalBinaryOperator.StrictInequality;
|
|
1230
|
+
}
|
|
1231
|
+
isLiteralNode(node) {
|
|
1232
|
+
if (ts.isStringLiteral(node) ||
|
|
1233
|
+
ts.isNumericLiteral(node) ||
|
|
1234
|
+
ts.isBigIntLiteral(node) ||
|
|
1235
|
+
ts.isRegularExpressionLiteral(node) ||
|
|
1236
|
+
ts.isNoSubstitutionTemplateLiteral(node) ||
|
|
1237
|
+
node.kind === ts.SyntaxKind.NullKeyword ||
|
|
1238
|
+
node.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1239
|
+
node.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1240
|
+
node.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
1241
|
+
return true;
|
|
1242
|
+
}
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
resolveTypeNode(type) {
|
|
1246
|
+
const kind = type.kind;
|
|
1247
|
+
switch (kind) {
|
|
1248
|
+
case ts.SyntaxKind.BooleanKeyword:
|
|
1249
|
+
return Type_1.BooleanType.getInstance();
|
|
1250
|
+
case ts.SyntaxKind.NumberKeyword:
|
|
1251
|
+
return Type_1.NumberType.getInstance();
|
|
1252
|
+
case ts.SyntaxKind.StringKeyword:
|
|
1253
|
+
return Type_1.StringType.getInstance();
|
|
1254
|
+
case ts.SyntaxKind.UndefinedKeyword:
|
|
1255
|
+
return Type_1.UndefinedType.getInstance();
|
|
1256
|
+
case ts.SyntaxKind.AnyKeyword:
|
|
1257
|
+
return Type_1.AnyType.getInstance();
|
|
1258
|
+
case ts.SyntaxKind.VoidKeyword:
|
|
1259
|
+
return Type_1.VoidType.getInstance();
|
|
1260
|
+
case ts.SyntaxKind.NeverKeyword:
|
|
1261
|
+
return Type_1.NeverType.getInstance();
|
|
1262
|
+
case ts.SyntaxKind.TypeReference:
|
|
1263
|
+
return this.resolveTypeReferenceNode(type);
|
|
1264
|
+
case ts.SyntaxKind.ArrayType:
|
|
1265
|
+
return new Type_1.ArrayType(this.resolveTypeNode(type.elementType), 1);
|
|
1266
|
+
case ts.SyntaxKind.UnionType: {
|
|
1267
|
+
const mayTypes = [];
|
|
1268
|
+
type.types.forEach(t => mayTypes.push(this.resolveTypeNode(t)));
|
|
1269
|
+
return new Type_1.UnionType(mayTypes);
|
|
1270
|
+
}
|
|
1271
|
+
case ts.SyntaxKind.IntersectionType: {
|
|
1272
|
+
const intersectionTypes = [];
|
|
1273
|
+
type.types.forEach(t => intersectionTypes.push(this.resolveTypeNode(t)));
|
|
1274
|
+
return new Type_1.IntersectionType(intersectionTypes);
|
|
1275
|
+
}
|
|
1276
|
+
case ts.SyntaxKind.TupleType: {
|
|
1277
|
+
const types = [];
|
|
1278
|
+
type.elements.forEach(element => {
|
|
1279
|
+
types.push(this.resolveTypeNode(element));
|
|
1280
|
+
});
|
|
1281
|
+
return new Type_1.TupleType(types);
|
|
1282
|
+
}
|
|
1283
|
+
case ts.SyntaxKind.NamedTupleMember:
|
|
1284
|
+
return this.resolveTypeNode(type.type);
|
|
1285
|
+
case ts.SyntaxKind.LiteralType:
|
|
1286
|
+
return ArkValueTransformer.resolveLiteralTypeNode(type, this.sourceFile);
|
|
1287
|
+
case ts.SyntaxKind.TemplateLiteralType:
|
|
1288
|
+
return this.resolveTemplateLiteralTypeNode(type);
|
|
1289
|
+
case ts.SyntaxKind.TypeLiteral:
|
|
1290
|
+
return this.resolveTypeLiteralNode(type);
|
|
1291
|
+
case ts.SyntaxKind.FunctionType:
|
|
1292
|
+
return this.resolveFunctionTypeNode(type);
|
|
1293
|
+
case ts.SyntaxKind.ImportType:
|
|
1294
|
+
return Type_1.UnknownType.getInstance();
|
|
1295
|
+
case ts.SyntaxKind.TypeQuery:
|
|
1296
|
+
return this.resolveTypeQueryNode(type);
|
|
1297
|
+
case ts.SyntaxKind.ParenthesizedType:
|
|
1298
|
+
return this.resolveTypeNode(type.type);
|
|
1299
|
+
case ts.SyntaxKind.TypeOperator:
|
|
1300
|
+
return this.resolveTypeOperatorNode(type);
|
|
1301
|
+
default:
|
|
1302
|
+
return Type_1.UnknownType.getInstance();
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
resolveTypeQueryNode(typeQueryNode) {
|
|
1306
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1307
|
+
const genericTypes = [];
|
|
1308
|
+
if (typeQueryNode.typeArguments) {
|
|
1309
|
+
for (const typeArgument of typeQueryNode.typeArguments) {
|
|
1310
|
+
genericTypes.push(this.resolveTypeNode(typeArgument));
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
const exprNameNode = typeQueryNode.exprName;
|
|
1314
|
+
let opValue;
|
|
1315
|
+
if (ts.isQualifiedName(exprNameNode)) {
|
|
1316
|
+
if (exprNameNode.left.getText(this.sourceFile) === TSConst_1.THIS_NAME) {
|
|
1317
|
+
const fieldName = exprNameNode.right.getText(this.sourceFile);
|
|
1318
|
+
const fieldSignature = (_b = (_a = this.declaringMethod.getDeclaringArkClass().getFieldWithName(fieldName)) === null || _a === void 0 ? void 0 : _a.getSignature()) !== null && _b !== void 0 ? _b : ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(fieldName);
|
|
1319
|
+
const baseLocal = (_c = this.locals.get(TSConst_1.THIS_NAME)) !== null && _c !== void 0 ? _c : new Local_1.Local(TSConst_1.THIS_NAME, new Type_1.ClassType(this.declaringMethod.getDeclaringArkClass().getSignature(), genericTypes));
|
|
1320
|
+
opValue = new Ref_1.ArkInstanceFieldRef(baseLocal, fieldSignature);
|
|
1321
|
+
}
|
|
1322
|
+
else {
|
|
1323
|
+
const exprName = exprNameNode.getText(this.sourceFile);
|
|
1324
|
+
opValue = new Local_1.Local(exprName, Type_1.UnknownType.getInstance());
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
else {
|
|
1328
|
+
const exprName = exprNameNode.escapedText.toString();
|
|
1329
|
+
opValue = (_f = (_d = this.locals.get(exprName)) !== null && _d !== void 0 ? _d : (_e = this.globals) === null || _e === void 0 ? void 0 : _e.get(exprName)) !== null && _f !== void 0 ? _f : new Local_1.Local(exprName, Type_1.UnknownType.getInstance());
|
|
1330
|
+
}
|
|
1331
|
+
return new TypeExpr_1.TypeQueryExpr(opValue, genericTypes);
|
|
1332
|
+
}
|
|
1333
|
+
resolveTypeOperatorNode(typeOperatorNode) {
|
|
1334
|
+
let type = this.resolveTypeNode(typeOperatorNode.type);
|
|
1335
|
+
switch (typeOperatorNode.operator) {
|
|
1336
|
+
case ts.SyntaxKind.ReadonlyKeyword: {
|
|
1337
|
+
if (type instanceof Type_1.ArrayType || type instanceof Type_1.TupleType) {
|
|
1338
|
+
type.setReadonlyFlag(true);
|
|
1339
|
+
}
|
|
1340
|
+
return type;
|
|
1341
|
+
}
|
|
1342
|
+
case ts.SyntaxKind.KeyOfKeyword: {
|
|
1343
|
+
return new TypeExpr_1.KeyofTypeExpr(type);
|
|
1344
|
+
}
|
|
1345
|
+
case ts.SyntaxKind.UniqueKeyword: {
|
|
1346
|
+
return Type_1.UnknownType.getInstance();
|
|
1347
|
+
}
|
|
1348
|
+
default:
|
|
1349
|
+
return Type_1.UnknownType.getInstance();
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
static resolveLiteralTypeNode(literalTypeNode, sourceFile) {
|
|
1353
|
+
const literal = literalTypeNode.literal;
|
|
1354
|
+
const kind = literal.kind;
|
|
1355
|
+
switch (kind) {
|
|
1356
|
+
case ts.SyntaxKind.NullKeyword:
|
|
1357
|
+
return Type_1.NullType.getInstance();
|
|
1358
|
+
case ts.SyntaxKind.TrueKeyword:
|
|
1359
|
+
return Type_1.LiteralType.TRUE;
|
|
1360
|
+
case ts.SyntaxKind.FalseKeyword:
|
|
1361
|
+
return Type_1.LiteralType.FALSE;
|
|
1362
|
+
case ts.SyntaxKind.NumericLiteral:
|
|
1363
|
+
return new Type_1.LiteralType(parseFloat(literal.text));
|
|
1364
|
+
case ts.SyntaxKind.PrefixUnaryExpression:
|
|
1365
|
+
return new Type_1.LiteralType(parseFloat(literal.getText(sourceFile)));
|
|
1366
|
+
default:
|
|
1367
|
+
;
|
|
1368
|
+
}
|
|
1369
|
+
return new Type_1.LiteralType(literal.getText(sourceFile));
|
|
1370
|
+
}
|
|
1371
|
+
resolveTemplateLiteralTypeNode(templateLiteralTypeNode) {
|
|
1372
|
+
let stringLiterals = [''];
|
|
1373
|
+
const headString = templateLiteralTypeNode.head.rawText || '';
|
|
1374
|
+
let newStringLiterals = [];
|
|
1375
|
+
for (const stringLiteral of stringLiterals) {
|
|
1376
|
+
newStringLiterals.push(stringLiteral + headString);
|
|
1377
|
+
}
|
|
1378
|
+
stringLiterals = newStringLiterals;
|
|
1379
|
+
newStringLiterals = [];
|
|
1380
|
+
for (const templateSpan of templateLiteralTypeNode.templateSpans) {
|
|
1381
|
+
const templateType = this.resolveTypeNode(templateSpan.type);
|
|
1382
|
+
const unfoldTemplateTypes = [];
|
|
1383
|
+
if (templateType instanceof Type_1.UnionType) {
|
|
1384
|
+
unfoldTemplateTypes.push(...templateType.getTypes());
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
unfoldTemplateTypes.push(templateType);
|
|
1388
|
+
}
|
|
1389
|
+
const unfoldTemplateTypeStrs = [];
|
|
1390
|
+
for (const unfoldTemplateType of unfoldTemplateTypes) {
|
|
1391
|
+
unfoldTemplateTypeStrs.push(unfoldTemplateType instanceof Type_1.AliasType ? unfoldTemplateType.getOriginalType()
|
|
1392
|
+
.toString() : unfoldTemplateType.toString());
|
|
1393
|
+
}
|
|
1394
|
+
const templateSpanString = templateSpan.literal.rawText || '';
|
|
1395
|
+
for (const stringLiteral of stringLiterals) {
|
|
1396
|
+
for (const unfoldTemplateTypeStr of unfoldTemplateTypeStrs) {
|
|
1397
|
+
newStringLiterals.push(stringLiteral + unfoldTemplateTypeStr + templateSpanString);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
stringLiterals = newStringLiterals;
|
|
1401
|
+
newStringLiterals = [];
|
|
1402
|
+
}
|
|
1403
|
+
const templateTypes = [];
|
|
1404
|
+
for (const stringLiteral of stringLiterals) {
|
|
1405
|
+
templateTypes.push(new Type_1.LiteralType(stringLiteral));
|
|
1406
|
+
}
|
|
1407
|
+
if (templateTypes.length > 0) {
|
|
1408
|
+
return new Type_1.UnionType(templateTypes);
|
|
1409
|
+
}
|
|
1410
|
+
return templateTypes[0];
|
|
1411
|
+
}
|
|
1412
|
+
resolveTypeReferenceNode(typeReferenceNode) {
|
|
1413
|
+
const typeReferenceFullName = typeReferenceNode.typeName.getText(this.sourceFile);
|
|
1414
|
+
const aliasTypeAndStmt = this.aliasTypeMap.get(typeReferenceFullName);
|
|
1415
|
+
const genericTypes = [];
|
|
1416
|
+
if (typeReferenceNode.typeArguments) {
|
|
1417
|
+
for (const typeArgument of typeReferenceNode.typeArguments) {
|
|
1418
|
+
genericTypes.push(this.resolveTypeNode(typeArgument));
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
if (!aliasTypeAndStmt) {
|
|
1422
|
+
const typeName = typeReferenceNode.typeName.getText(this.sourceFile);
|
|
1423
|
+
const local = this.locals.get(typeName);
|
|
1424
|
+
if (local !== undefined) {
|
|
1425
|
+
return local.getType();
|
|
1426
|
+
}
|
|
1427
|
+
return new Type_1.UnclearReferenceType(typeName, genericTypes);
|
|
1428
|
+
}
|
|
1429
|
+
else {
|
|
1430
|
+
if (genericTypes.length > 0) {
|
|
1431
|
+
const oldAlias = aliasTypeAndStmt[0];
|
|
1432
|
+
let alias = new Type_1.AliasType(oldAlias.getName(), TypeInference_1.TypeInference.replaceTypeWithReal(oldAlias.getOriginalType(), genericTypes), oldAlias.getSignature(), oldAlias.getGenericTypes());
|
|
1433
|
+
alias.setRealGenericTypes(genericTypes);
|
|
1434
|
+
return alias;
|
|
1435
|
+
}
|
|
1436
|
+
return aliasTypeAndStmt[0];
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
resolveTypeLiteralNode(typeLiteralNode) {
|
|
1440
|
+
const anonymousClass = new ArkClass_1.ArkClass();
|
|
1441
|
+
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
1442
|
+
const declaringNamespace = declaringClass.getDeclaringArkNamespace();
|
|
1443
|
+
if (declaringNamespace) {
|
|
1444
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode, declaringNamespace, anonymousClass, this.sourceFile);
|
|
1445
|
+
}
|
|
1446
|
+
else {
|
|
1447
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode, declaringClass.getDeclaringArkFile(), anonymousClass, this.sourceFile);
|
|
1448
|
+
}
|
|
1449
|
+
return new Type_1.ClassType(anonymousClass.getSignature());
|
|
1450
|
+
}
|
|
1451
|
+
resolveFunctionTypeNode(functionTypeNode) {
|
|
1452
|
+
const anonymousMethod = new ArkMethod_1.ArkMethod();
|
|
1453
|
+
const declaringClass = this.declaringMethod.getDeclaringArkClass();
|
|
1454
|
+
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionTypeNode, declaringClass, anonymousMethod, this.sourceFile);
|
|
1455
|
+
return new Type_1.FunctionType(anonymousMethod.getSignature());
|
|
1456
|
+
}
|
|
1457
|
+
static isCompoundAssignmentOperator(operator) {
|
|
1458
|
+
const compoundAssignmentOperators = [
|
|
1459
|
+
ts.SyntaxKind.PlusEqualsToken,
|
|
1460
|
+
ts.SyntaxKind.MinusEqualsToken,
|
|
1461
|
+
ts.SyntaxKind.AsteriskAsteriskEqualsToken,
|
|
1462
|
+
ts.SyntaxKind.AsteriskEqualsToken,
|
|
1463
|
+
ts.SyntaxKind.SlashEqualsToken,
|
|
1464
|
+
ts.SyntaxKind.PercentEqualsToken,
|
|
1465
|
+
ts.SyntaxKind.AmpersandEqualsToken,
|
|
1466
|
+
ts.SyntaxKind.BarEqualsToken,
|
|
1467
|
+
ts.SyntaxKind.CaretEqualsToken,
|
|
1468
|
+
ts.SyntaxKind.LessThanLessThanEqualsToken,
|
|
1469
|
+
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
|
1470
|
+
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
|
1471
|
+
ts.SyntaxKind.BarBarEqualsToken,
|
|
1472
|
+
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
1473
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
1474
|
+
];
|
|
1475
|
+
return compoundAssignmentOperators.includes(operator);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
exports.ArkValueTransformer = ArkValueTransformer;
|