arkanalyzer 1.0.94 → 2.0.0-beta1
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 +7 -0
- package/lib/Config.d.ts.map +1 -1
- package/lib/Scene.d.ts +134 -170
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +412 -976
- package/lib/callgraph/algorithm/AbstractAnalysis.js +3 -2
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +1 -1
- package/lib/callgraph/model/CallGraph.js +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +1 -3
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +17 -7
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +4 -14
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +2 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +1 -2
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +0 -1
- package/lib/cli/commands/cg.d.ts +1 -0
- package/lib/cli/commands/cg.d.ts.map +1 -1
- package/lib/cli/commands/cg.js +22 -18
- package/lib/cli/commands/ir.d.ts +1 -0
- package/lib/cli/commands/ir.d.ts.map +1 -1
- package/lib/cli/commands/ir.js +5 -2
- package/lib/core/base/Constant.d.ts +5 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +12 -9
- package/lib/core/base/Expr.d.ts +36 -20
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +206 -94
- package/lib/core/base/Local.d.ts +10 -20
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +25 -28
- package/lib/core/base/Position.d.ts +6 -0
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +37 -11
- package/lib/core/base/Ref.d.ts +45 -33
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +225 -51
- package/lib/core/base/Stmt.d.ts +19 -9
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -52
- package/lib/core/base/Type.d.ts +67 -4
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +391 -20
- package/lib/core/base/TypeExpr.d.ts +6 -4
- package/lib/core/base/TypeExpr.d.ts.map +1 -1
- package/lib/core/base/TypeExpr.js +34 -10
- package/lib/core/base/Value.d.ts +20 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/base/Value.js +12 -0
- package/lib/core/common/ArkIRTransformer.d.ts +18 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +94 -75
- package/lib/core/common/ArkValueTransformer.d.ts +21 -3
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +455 -265
- package/lib/core/common/Builtin.d.ts +48 -24
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +90 -52
- package/lib/core/common/CanonicalizerValidator.d.ts +308 -0
- package/lib/core/common/CanonicalizerValidator.d.ts.map +1 -0
- package/lib/core/common/CanonicalizerValidator.js +888 -0
- package/lib/core/common/Const.d.ts +3 -3
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +3 -3
- package/lib/core/common/DummyMainCreater.d.ts +2 -21
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +8 -105
- package/lib/core/common/IRInference.d.ts +55 -3
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +407 -126
- package/lib/core/common/IRUtils.d.ts +1 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +44 -13
- package/lib/core/common/ModelUtils.d.ts +44 -20
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +378 -208
- package/lib/core/common/SdkUtils.d.ts +35 -5
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +181 -53
- package/lib/core/common/SignatureCanonicalizer.d.ts +95 -0
- package/lib/core/common/SignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizer.js +116 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts +176 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.js +343 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts +69 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureModelCanonicalizer.js +109 -0
- package/lib/core/common/StmtUseReplacer.d.ts +1 -0
- package/lib/core/common/StmtUseReplacer.d.ts.map +1 -1
- package/lib/core/common/StmtUseReplacer.js +9 -0
- package/lib/core/common/StringUtils.d.ts +12 -1
- package/lib/core/common/StringUtils.d.ts.map +1 -1
- package/lib/core/common/StringUtils.js +36 -17
- package/lib/core/common/TempSignatureCanonicalizer.d.ts +82 -0
- package/lib/core/common/TempSignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/TempSignatureCanonicalizer.js +177 -0
- package/lib/core/common/TypeInference.d.ts +24 -6
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +243 -117
- package/lib/core/common/ValueUtil.d.ts +2 -1
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +4 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +21 -6
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +46 -33
- package/lib/core/graph/builder/IfBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/IfBuilder.js +6 -2
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -2
- package/lib/core/inference/ModelInference.d.ts +24 -4
- package/lib/core/inference/ModelInference.d.ts.map +1 -1
- package/lib/core/inference/ModelInference.js +273 -79
- package/lib/core/inference/ValueInference.d.ts +3 -2
- package/lib/core/inference/ValueInference.d.ts.map +1 -1
- package/lib/core/inference/ValueInference.js +90 -40
- package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
- package/lib/core/inference/abc/AbcInference.js +28 -15
- package/lib/core/inference/arkts/ArkTsInference.d.ts +9 -3
- package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
- package/lib/core/inference/arkts/ArkTsInference.js +54 -16
- package/lib/core/model/ArkClass.d.ts +192 -18
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +852 -122
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +1 -2
- package/lib/core/model/ArkField.d.ts +34 -2
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +89 -14
- package/lib/core/model/ArkFile.d.ts +72 -12
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +275 -65
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +1 -2
- package/lib/core/model/ArkMethod.d.ts +101 -15
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +252 -39
- package/lib/core/model/ArkModule.d.ts +1 -1
- package/lib/core/model/ArkModule.js +1 -1
- package/lib/core/model/ArkNamespace.d.ts +80 -10
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +309 -76
- package/lib/core/model/ArkSignature.d.ts +242 -18
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +725 -95
- package/lib/core/model/builder/ArkClassBuilder.d.ts +6 -3
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +116 -71
- package/lib/core/model/builder/ArkExportBuilder.d.ts +1 -1
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +0 -2
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +9 -43
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +32 -33
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +10 -3
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +40 -26
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +3 -2
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +45 -77
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkSignatureBuilder.js +26 -3
- package/lib/core/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +37 -11
- package/lib/core/model/builder/builderUtils.d.ts +11 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +124 -90
- package/lib/frontend/FrontendBuilder.d.ts +10 -6
- package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
- package/lib/frontend/FrontendBuilder.js +19 -45
- package/lib/frontend/ModuleScene.d.ts +43 -0
- package/lib/frontend/ModuleScene.d.ts.map +1 -0
- package/lib/frontend/ModuleScene.js +143 -0
- package/lib/frontend/SceneBuildStage.d.ts +15 -0
- package/lib/frontend/SceneBuildStage.d.ts.map +1 -0
- package/lib/frontend/SceneBuildStage.js +32 -0
- package/lib/frontend/SceneBuilder.d.ts +153 -0
- package/lib/frontend/SceneBuilder.d.ts.map +1 -0
- package/lib/frontend/SceneBuilder.js +859 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +0 -2
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
- package/lib/frontend/arktsFrontend/ArktsFrontend.js +0 -18
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts +17 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts.map +1 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.js +187 -0
- package/lib/frontend/common/ModuleBuilder.d.ts +4 -2
- package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -1
- package/lib/frontend/common/ModuleBuilder.js +19 -9
- package/lib/frontend/cppFrontend/CppFrontend.d.ts +0 -6
- package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/CppFrontend.js +0 -56
- package/lib/frontend/cppFrontend/base/Type.d.ts +7 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/base/Type.js +29 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +56 -56
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +124 -113
- package/lib/frontend/cppFrontend/common/Builtin.d.ts +29 -19
- package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/Builtin.js +56 -35
- package/lib/frontend/cppFrontend/common/IRInference.d.ts +7 -2
- package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRInference.js +61 -28
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.js +22 -10
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +19 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ModelUtils.js +84 -3
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/TypeInference.js +44 -54
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +2 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +1 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.js +41 -5
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +18 -28
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +2 -3
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +2 -2
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +31 -24
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +10 -16
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +0 -2
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +19 -37
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +30 -3
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +8 -4
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -2
- package/lib/save/json/JsonSerialization.js +2 -2
- package/lib/save/source/SourceStmt.js +1 -1
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +0 -9
- package/lib/statistics/StageStatistics.d.ts +195 -0
- package/lib/statistics/StageStatistics.d.ts.map +1 -0
- package/lib/statistics/StageStatistics.js +346 -0
- package/lib/statistics/StageStatisticsReporter.d.ts +58 -0
- package/lib/statistics/StageStatisticsReporter.d.ts.map +1 -0
- package/lib/statistics/StageStatisticsReporter.js +255 -0
- package/lib/utils/Canonicalizer.d.ts +9 -2
- package/lib/utils/Canonicalizer.d.ts.map +1 -1
- package/lib/utils/Canonicalizer.js +19 -2
- package/lib/utils/CxxSceneUtils.d.ts +7 -0
- package/lib/utils/CxxSceneUtils.d.ts.map +1 -1
- package/lib/utils/CxxSceneUtils.js +10 -1
- package/lib/utils/FileUtils.d.ts +0 -1
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +1 -9
- package/lib/utils/HashUtils.d.ts +9 -0
- package/lib/utils/HashUtils.d.ts.map +1 -0
- package/lib/utils/HashUtils.js +65 -0
- package/lib/utils/ModuleUtils.d.ts.map +1 -1
- package/lib/utils/ModuleUtils.js +24 -5
- package/lib/utils/VisitedSegment.d.ts +23 -0
- package/lib/utils/VisitedSegment.d.ts.map +1 -0
- package/lib/utils/VisitedSegment.js +64 -0
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -7
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +11 -8
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +16 -0
- package/lib/utils/parseArkSourceFile.d.ts +33 -0
- package/lib/utils/parseArkSourceFile.d.ts.map +1 -0
- package/lib/utils/parseArkSourceFile.js +131 -0
- package/package.json +1 -1
- package/lib/utils/DependenciesSort.d.ts +0 -3
- package/lib/utils/DependenciesSort.d.ts.map +0 -1
- package/lib/utils/DependenciesSort.js +0 -72
- package/lib/utils/crypto_utils.d.ts +0 -6
- package/lib/utils/crypto_utils.d.ts.map +0 -1
- package/lib/utils/crypto_utils.js +0 -57
|
@@ -39,14 +39,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.ArkValueTransformer = void 0;
|
|
41
41
|
const ts = __importStar(require("ohos-typescript"));
|
|
42
|
+
const SdkUtils_1 = require("./SdkUtils");
|
|
42
43
|
const Local_1 = require("../base/Local");
|
|
43
44
|
const Position_1 = require("../base/Position");
|
|
44
45
|
const Stmt_1 = require("../base/Stmt");
|
|
45
46
|
const Expr_1 = require("../base/Expr");
|
|
46
47
|
const ArkClass_1 = require("../model/ArkClass");
|
|
48
|
+
const SignatureCanonicalizerRegistry_1 = require("./SignatureCanonicalizerRegistry");
|
|
47
49
|
const ArkClassBuilder_1 = require("../model/builder/ArkClassBuilder");
|
|
50
|
+
const ArkMethodBuilder_1 = require("../model/builder/ArkMethodBuilder");
|
|
48
51
|
const Type_1 = require("../base/Type");
|
|
49
52
|
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
53
|
+
const builderUtils_1 = require("../model/builder/builderUtils");
|
|
50
54
|
const StringUtils_1 = require("./StringUtils");
|
|
51
55
|
const TSConst_1 = require("./TSConst");
|
|
52
56
|
const ArkSignature_1 = require("../model/ArkSignature");
|
|
@@ -56,7 +60,7 @@ const IRUtils_1 = require("./IRUtils");
|
|
|
56
60
|
const Ref_1 = require("../base/Ref");
|
|
57
61
|
const ModelUtils_1 = require("./ModelUtils");
|
|
58
62
|
const ArkMethod_1 = require("../model/ArkMethod");
|
|
59
|
-
const
|
|
63
|
+
const ArkMethodBuilder_2 = require("../model/builder/ArkMethodBuilder");
|
|
60
64
|
const Builtin_1 = require("./Builtin");
|
|
61
65
|
const Constant_1 = require("../base/Constant");
|
|
62
66
|
const Const_1 = require("./Const");
|
|
@@ -77,6 +81,9 @@ class ArkValueTransformer {
|
|
|
77
81
|
this.thisLocal = new Local_1.Local(TSConst_1.THIS_NAME, declaringMethod.getDeclaringArkClass().getSignature().getType());
|
|
78
82
|
this.locals.set(this.thisLocal.getName(), this.thisLocal);
|
|
79
83
|
this.declaringMethod = declaringMethod;
|
|
84
|
+
this.declaringClass = arkIRTransformer.declaringClass;
|
|
85
|
+
this.declaringNamespace = arkIRTransformer.declaringNamespace;
|
|
86
|
+
this.declaringFile = arkIRTransformer.declaringFile;
|
|
80
87
|
}
|
|
81
88
|
getLocals() {
|
|
82
89
|
return new Set(this.locals.values());
|
|
@@ -201,11 +208,11 @@ class ArkValueTransformer {
|
|
|
201
208
|
};
|
|
202
209
|
}
|
|
203
210
|
tsNodeToSingleAddressValueAndStmts(node) {
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return
|
|
211
|
+
const result = this.tsNodeToValueAndStmts(node);
|
|
212
|
+
const processed = this.arkIRTransformer.handleExpressionValueWithTempVarIfNeeded(result.value, result.valueOriginalPositions, result.stmts);
|
|
213
|
+
result.value = processed.value;
|
|
214
|
+
result.valueOriginalPositions = processed.positions;
|
|
215
|
+
return result;
|
|
209
216
|
}
|
|
210
217
|
thisExpressionToValueAndStmts(thisExpression) {
|
|
211
218
|
return {
|
|
@@ -222,6 +229,9 @@ class ArkValueTransformer {
|
|
|
222
229
|
};
|
|
223
230
|
}
|
|
224
231
|
conditionalExpressionToValueAndStmts(conditionalExpression) {
|
|
232
|
+
if (ModelUtils_1.ModelUtils.isArkUIBuilderMethod(this.declaringMethod)) {
|
|
233
|
+
return this.builderConditionalExpressionToValueAndStmts(conditionalExpression);
|
|
234
|
+
}
|
|
225
235
|
const stmts = [];
|
|
226
236
|
const currConditionalOperatorIndex = this.conditionalOperatorNo++;
|
|
227
237
|
const { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
@@ -250,17 +260,58 @@ class ArkValueTransformer {
|
|
|
250
260
|
stmts: stmts,
|
|
251
261
|
};
|
|
252
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* In ArkUI builder methods, lower `a ? b : c` like statement if:
|
|
265
|
+
* If.create / If.branch(0) / true / If.branch(1) / false / If.pop, still yielding a result local.
|
|
266
|
+
* Stays linear (no CFG diamond); ViewTree reads the If.create protocol.
|
|
267
|
+
*/
|
|
268
|
+
builderConditionalExpressionToValueAndStmts(conditionalExpression) {
|
|
269
|
+
const stmts = [];
|
|
270
|
+
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
271
|
+
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
272
|
+
const { value: conditionLocal, valueOriginalPositions: conditionLocalPositions, stmts: assignConditionStmts, } = this.arkIRTransformer.generateAssignStmtForValue(conditionExpr, conditionExprPositions);
|
|
273
|
+
assignConditionStmts.forEach(stmt => stmts.push(stmt));
|
|
274
|
+
const { stmts: createStmts } = this.generateComponentCreationStmts(EtsConst_1.COMPONENT_IF, [conditionLocal], conditionLocalPositions[0], conditionLocalPositions);
|
|
275
|
+
createStmts.forEach(stmt => stmts.push(stmt));
|
|
276
|
+
stmts.push(this.generateBuilderIfBranch(0, conditionLocalPositions[0]));
|
|
277
|
+
const { value: whenTrueValue, valueOriginalPositions: whenTruePositions, stmts: whenTrueStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenTrue);
|
|
278
|
+
whenTrueStmts.forEach(stmt => stmts.push(stmt));
|
|
279
|
+
const resultLocal = this.generateTempLocal();
|
|
280
|
+
const resultLocalPosition = [whenTruePositions[0]];
|
|
281
|
+
const assignStmtWhenTrue = new Stmt_1.ArkAssignStmt(resultLocal, whenTrueValue);
|
|
282
|
+
assignStmtWhenTrue.setOperandOriginalPositions([...resultLocalPosition, ...whenTruePositions]);
|
|
283
|
+
stmts.push(assignStmtWhenTrue);
|
|
284
|
+
stmts.push(this.generateBuilderIfBranch(1, Position_1.FullPosition.buildFromNode(conditionalExpression.whenFalse, this.sourceFile)));
|
|
285
|
+
const { value: whenFalseValue, valueOriginalPositions: whenFalsePositions, stmts: whenFalseStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenFalse);
|
|
286
|
+
whenFalseStmts.forEach(stmt => stmts.push(stmt));
|
|
287
|
+
const assignStmtWhenFalse = new Stmt_1.ArkAssignStmt(resultLocal, whenFalseValue);
|
|
288
|
+
assignStmtWhenFalse.setOperandOriginalPositions([...resultLocalPosition, ...whenFalsePositions]);
|
|
289
|
+
stmts.push(assignStmtWhenFalse);
|
|
290
|
+
stmts.push(this.generateComponentPopStmts(EtsConst_1.COMPONENT_IF));
|
|
291
|
+
return {
|
|
292
|
+
value: resultLocal,
|
|
293
|
+
valueOriginalPositions: resultLocalPosition,
|
|
294
|
+
stmts: stmts,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
253
297
|
objectLiteralExpresionToValueAndStmts(objectLiteralExpression) {
|
|
254
|
-
|
|
255
|
-
const declaringArkNamespace =
|
|
256
|
-
const anonymousClass = new ArkClass_1.ArkClass();
|
|
298
|
+
var _a;
|
|
299
|
+
const declaringArkNamespace = this.declaringNamespace;
|
|
300
|
+
const anonymousClass = new ArkClass_1.ArkClass(this.declaringFile.getFileSigID(), declaringArkNamespace === null || declaringArkNamespace === void 0 ? void 0 : declaringArkNamespace.getNamespaceSigID());
|
|
257
301
|
if (declaringArkNamespace) {
|
|
258
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(objectLiteralExpression,
|
|
302
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(objectLiteralExpression, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
303
|
+
declaringArkNamespace.addArkClass(anonymousClass);
|
|
259
304
|
}
|
|
260
305
|
else {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
306
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(objectLiteralExpression, this.declaringFile, anonymousClass, this.sourceFile, this.declaringMethod);
|
|
307
|
+
}
|
|
308
|
+
// Build the default constructor at creation time so the constructor invoke expr
|
|
309
|
+
// below probes the formal space with a real (value-equal) signature — a missing
|
|
310
|
+
// probe falls into the temp defensive route with an error log. The on-demand
|
|
311
|
+
// variant (isLibraryClass guard lifted) also covers SDK-file object literals:
|
|
312
|
+
// the registration happens inside the host file's own build stage, so the SDK /
|
|
313
|
+
// project ID-boundary invariant is preserved either way.
|
|
314
|
+
(0, ArkMethodBuilder_1.ensureDefaultConstructor)(anonymousClass);
|
|
264
315
|
const objectLiteralExpressionPosition = Position_1.FullPosition.buildFromNode(objectLiteralExpression, this.sourceFile);
|
|
265
316
|
const stmts = [];
|
|
266
317
|
const anonymousClassSignature = anonymousClass.getSignature();
|
|
@@ -269,7 +320,11 @@ class ArkValueTransformer {
|
|
|
269
320
|
const { value: newExprLocal, valueOriginalPositions: newExprLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [objectLiteralExpressionPosition]);
|
|
270
321
|
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
271
322
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
272
|
-
|
|
323
|
+
// Prefer the real (just-built) default constructor signature so the invoke expr's
|
|
324
|
+
// route hits the formal space directly; the fallback is an unclear (%unk) stub —
|
|
325
|
+
// never a clear unregistered shape (that would hit the clear+miss error route).
|
|
326
|
+
const realConstructor = anonymousClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
327
|
+
const constructorMethodSignature = (_a = realConstructor === null || realConstructor === void 0 ? void 0 : realConstructor.getSignature()) !== null && _a !== void 0 ? _a : new ArkSignature_1.MethodSignature(0, constructorMethodSubSignature);
|
|
273
328
|
const constructorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, []);
|
|
274
329
|
const assignStmt = new Stmt_1.ArkAssignStmt(newExprLocal, constructorInvokeExpr);
|
|
275
330
|
const assignStmtPositions = [newExprLocalPositions[0], newExprLocalPositions[0], ...newExprLocalPositions];
|
|
@@ -294,11 +349,14 @@ class ArkValueTransformer {
|
|
|
294
349
|
return;
|
|
295
350
|
}
|
|
296
351
|
const fieldInitStmts = [];
|
|
297
|
-
let { value: initValue, valueOriginalPositions: initPositions, stmts: initStmts
|
|
352
|
+
let { value: initValue, valueOriginalPositions: initPositions, stmts: initStmts } = this.tsNodeToValueAndStmts(valueNode);
|
|
298
353
|
this.appendInitStmts(stmts, fieldInitStmts, initStmts);
|
|
299
354
|
if (IRUtils_1.IRUtils.moreThanOneAddress(initValue)) {
|
|
300
|
-
({
|
|
301
|
-
|
|
355
|
+
({
|
|
356
|
+
value: initValue,
|
|
357
|
+
valueOriginalPositions: initPositions,
|
|
358
|
+
stmts: initStmts,
|
|
359
|
+
} = this.arkIRTransformer.generateAssignStmtForValue(initValue, initPositions));
|
|
302
360
|
this.appendInitStmts(stmts, fieldInitStmts, initStmts);
|
|
303
361
|
}
|
|
304
362
|
const fieldRef = new Ref_1.ArkInstanceFieldRef(objectLocal, fieldSignature);
|
|
@@ -375,6 +433,8 @@ class ArkValueTransformer {
|
|
|
375
433
|
const { value: newExprLocal, valueOriginalPositions: newExprPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [componentExpressionPosition]);
|
|
376
434
|
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
377
435
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
436
|
+
// Object path: a stub class signature (unclear) is routed to the temp canonicalizer
|
|
437
|
+
// inside the constructor — no formal interning without a model.
|
|
378
438
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
379
439
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, args);
|
|
380
440
|
const assignStmt = new Stmt_1.ArkAssignStmt(newExprLocal, instanceInvokeExpr);
|
|
@@ -389,7 +449,7 @@ class ArkValueTransformer {
|
|
|
389
449
|
anonymous.pos = componentExpression.body.pos;
|
|
390
450
|
// @ts-expect-error: add end info for the created ArrowFunction
|
|
391
451
|
anonymous.end = componentExpression.body.end;
|
|
392
|
-
const { value: builderMethod, valueOriginalPositions: builderMethodPositions
|
|
452
|
+
const { value: builderMethod, valueOriginalPositions: builderMethodPositions } = this.callableNodeToValueAndStmts(anonymous);
|
|
393
453
|
createViewArgs.push(builderMethod);
|
|
394
454
|
createViewArgPositionsAll.push(builderMethodPositions);
|
|
395
455
|
}
|
|
@@ -402,8 +462,10 @@ class ArkValueTransformer {
|
|
|
402
462
|
stmts: stmts,
|
|
403
463
|
};
|
|
404
464
|
}
|
|
465
|
+
/** @internal Emit a component create invocation assigned to a temporary local. */
|
|
405
466
|
generateComponentCreationStmts(componentName, createArgs, componentExpressionPosition, createArgsPositionsAllFlat) {
|
|
406
|
-
|
|
467
|
+
// 组件 create stub 签名 per-(name, method) 缓存。
|
|
468
|
+
const createMethodSignature = ModelUtils_1.ModelUtils.getOrCreateComponentMethodSig(componentName, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
407
469
|
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, createArgs);
|
|
408
470
|
const createInvokeExprPositions = [componentExpressionPosition, ...createArgsPositionsAllFlat];
|
|
409
471
|
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.arkIRTransformer.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
@@ -413,16 +475,30 @@ class ArkValueTransformer {
|
|
|
413
475
|
stmts: componentStmts,
|
|
414
476
|
};
|
|
415
477
|
}
|
|
478
|
+
/** @internal Emit an If.branch invocation for the given branch index. */
|
|
479
|
+
generateBuilderIfBranch(index, position = Position_1.FullPosition.DEFAULT) {
|
|
480
|
+
// If.branch stub per-key 缓存
|
|
481
|
+
const branchMethodSignature = ModelUtils_1.ModelUtils.getOrCreateComponentMethodSig(EtsConst_1.COMPONENT_IF, EtsConst_1.COMPONENT_BRANCH_FUNCTION);
|
|
482
|
+
const branchInvokeExpr = new Expr_1.ArkStaticInvokeExpr(branchMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(index)]);
|
|
483
|
+
const branchInvokeStmt = new Stmt_1.ArkInvokeStmt(branchInvokeExpr);
|
|
484
|
+
branchInvokeStmt.setOperandOriginalPositions([position, Position_1.FullPosition.DEFAULT]);
|
|
485
|
+
return branchInvokeStmt;
|
|
486
|
+
}
|
|
487
|
+
/** @internal Emit a component pop invocation that closes the matching create. */
|
|
416
488
|
generateComponentPopStmts(componentName, componentExpressionPosition) {
|
|
417
489
|
var _a;
|
|
418
490
|
let popMethodSignature = ModelUtils_1.ModelUtils.popMethodSignatureCache.get(componentName);
|
|
419
491
|
if (!popMethodSignature) {
|
|
420
|
-
const cls =
|
|
492
|
+
const cls = SdkUtils_1.SdkUtils.getSdkGlobal(EtsConst_1.COMMON_METHOD);
|
|
421
493
|
if (cls instanceof ArkClass_1.ArkClass) {
|
|
422
494
|
const commonSignature = (_a = cls.getMethodWithName(EtsConst_1.COMPONENT_POP_FUNCTION)) === null || _a === void 0 ? void 0 : _a.getSignature();
|
|
423
495
|
if (commonSignature) {
|
|
496
|
+
// display 归一化:AliasClassSignature 构造即 intern formal + 双注册 origin ArkClass model(display 由 formal canonical 自持)。
|
|
424
497
|
const classSignature = new ArkSignature_1.AliasClassSignature(componentName, commonSignature.getDeclaringClassSignature());
|
|
425
498
|
popMethodSignature = new ArkSignature_1.MethodSignature(classSignature, commonSignature.getMethodSubSignature());
|
|
499
|
+
// methodSig 侧同款 intern + 双注册——expr 的 route() formal 命中持
|
|
500
|
+
// SigID,scene.getMethod 经 getModel 直命中 CommonMethod.pop。
|
|
501
|
+
(0, ArkSignature_1.internAliasMethodSignature)(popMethodSignature, commonSignature);
|
|
426
502
|
}
|
|
427
503
|
}
|
|
428
504
|
popMethodSignature = popMethodSignature !== null && popMethodSignature !== void 0 ? popMethodSignature : ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
@@ -438,22 +514,21 @@ class ArkValueTransformer {
|
|
|
438
514
|
etsComponentExpressionToValueAndStmts(etsComponentExpression) {
|
|
439
515
|
const stmts = [];
|
|
440
516
|
const componentName = (0, StringUtils_1.cloneText)(etsComponentExpression.expression.text);
|
|
441
|
-
const { argValues: argValues, argPositions: argPositions
|
|
517
|
+
const { argValues: argValues, argPositions: argPositions } = this.parseArguments(stmts, etsComponentExpression.arguments);
|
|
442
518
|
if ((0, EtsConst_1.isEtsSystemComponent)(componentName)) {
|
|
443
519
|
return this.generateSystemComponentStmt(componentName, argValues, argPositions, etsComponentExpression, stmts);
|
|
444
520
|
}
|
|
445
521
|
return this.generateCustomViewStmt(componentName, argValues, argPositions, etsComponentExpression, stmts);
|
|
446
522
|
}
|
|
447
523
|
classExpressionToValueAndStmts(classExpression) {
|
|
448
|
-
const
|
|
449
|
-
const
|
|
450
|
-
const newClass = new ArkClass_1.ArkClass();
|
|
524
|
+
const declaringArkNamespace = this.declaringNamespace;
|
|
525
|
+
const newClass = new ArkClass_1.ArkClass(this.declaringFile.getFileSigID(), declaringArkNamespace === null || declaringArkNamespace === void 0 ? void 0 : declaringArkNamespace.getNamespaceSigID());
|
|
451
526
|
if (declaringArkNamespace) {
|
|
452
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression,
|
|
527
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression, newClass, this.sourceFile, this.declaringMethod);
|
|
528
|
+
declaringArkNamespace.addArkClass(newClass);
|
|
453
529
|
}
|
|
454
530
|
else {
|
|
455
|
-
|
|
456
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, declaringArkFile, newClass, this.sourceFile, this.declaringMethod);
|
|
531
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, this.declaringFile, newClass, this.sourceFile, this.declaringMethod);
|
|
457
532
|
}
|
|
458
533
|
const classValue = this.addNewLocal(newClass.getName(), new Type_1.ClassType(newClass.getSignature()));
|
|
459
534
|
return {
|
|
@@ -463,7 +538,7 @@ class ArkValueTransformer {
|
|
|
463
538
|
};
|
|
464
539
|
}
|
|
465
540
|
templateExpressionToValueAndStmts(templateExpression) {
|
|
466
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions
|
|
541
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(templateExpression);
|
|
467
542
|
const { placeholderStringLocals, placeholderStringLocalPositions, newStmts } = this.processTemplatePlaceholders(placeholderValues, placeholderPositions, stmts);
|
|
468
543
|
return this.combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, newStmts);
|
|
469
544
|
}
|
|
@@ -534,7 +609,7 @@ class ArkValueTransformer {
|
|
|
534
609
|
};
|
|
535
610
|
}
|
|
536
611
|
taggedTemplateExpressionToValueAndStmts(taggedTemplateExpression) {
|
|
537
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions
|
|
612
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(taggedTemplateExpression.template);
|
|
538
613
|
const stringTextBaseType = Type_1.StringType.getInstance();
|
|
539
614
|
const stringTextArrayLen = stringTextValues.length;
|
|
540
615
|
const stringTextArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(stringTextArrayLen);
|
|
@@ -546,7 +621,8 @@ class ArkValueTransformer {
|
|
|
546
621
|
const placeholdersArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
547
622
|
const { value: placeholdersLocal, valueOriginalPositions: placeholdersLocalPositions, stmts: placeholdersStmts, } = this.generateArrayExprAndStmts(placeholderBaseType, placeholdersArrayLenValue, placeholdersArrayLenPosition, placeholdersArrayLen, placeholderValues, placeholderPositions, templateObjectStmts, Position_1.FullPosition.DEFAULT, true);
|
|
548
623
|
const taggedFuncArgus = {
|
|
549
|
-
realGenericTypes: undefined,
|
|
624
|
+
realGenericTypes: undefined,
|
|
625
|
+
argValues: [templateObjectLocal, placeholdersLocal],
|
|
550
626
|
argPositions: [templateObjectLocalPositions[0], placeholdersLocalPositions[0]],
|
|
551
627
|
};
|
|
552
628
|
return this.generateInvokeValueAndStmts(taggedTemplateExpression.tag, taggedFuncArgus, placeholdersStmts, taggedTemplateExpression);
|
|
@@ -569,7 +645,7 @@ class ArkValueTransformer {
|
|
|
569
645
|
const stringTextPositions = [Position_1.FullPosition.buildFromNode(head, this.sourceFile)];
|
|
570
646
|
const placeholderPositions = [];
|
|
571
647
|
for (const templateSpan of templateLiteral.templateSpans) {
|
|
572
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
648
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(templateSpan.expression);
|
|
573
649
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
574
650
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
575
651
|
({
|
|
@@ -613,72 +689,78 @@ class ArkValueTransformer {
|
|
|
613
689
|
};
|
|
614
690
|
}
|
|
615
691
|
propertyAccessExpressionToValue(propertyAccessExpression) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
692
|
+
var _a;
|
|
693
|
+
const inner = this.tsNodeToValueAndStmts(propertyAccessExpression.expression);
|
|
694
|
+
const stmts = inner.stmts;
|
|
695
|
+
let value = inner.value;
|
|
696
|
+
let positions = inner.valueOriginalPositions;
|
|
697
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(value)) {
|
|
698
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(value, positions, stmts);
|
|
699
|
+
value = temp.value;
|
|
700
|
+
positions = temp.positions;
|
|
701
|
+
}
|
|
702
|
+
if (!(value instanceof Local_1.Local)) {
|
|
703
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(value, positions, stmts);
|
|
704
|
+
value = temp.value;
|
|
705
|
+
positions = temp.positions;
|
|
706
|
+
}
|
|
707
|
+
const fieldRefPositions = new Array(1 + positions.length);
|
|
708
|
+
fieldRefPositions[0] = Position_1.FullPosition.buildFromNode(propertyAccessExpression, this.sourceFile);
|
|
709
|
+
for (let i = 0; i < positions.length; i++) {
|
|
710
|
+
fieldRefPositions[i + 1] = positions[i];
|
|
634
711
|
}
|
|
635
|
-
const fieldRefPositions = [Position_1.FullPosition.buildFromNode(propertyAccessExpression, this.sourceFile), ...basePositions];
|
|
636
712
|
// this if for the case: const obj: Object = Object.create(Object.prototype);
|
|
637
|
-
if (
|
|
638
|
-
this.locals.delete(
|
|
713
|
+
if (value instanceof Local_1.Local && value.getName() === Builtin_1.Builtin.OBJECT) {
|
|
714
|
+
this.locals.delete(value.getName());
|
|
715
|
+
// Object path: the Object stub is unclear and is routed to the temp
|
|
716
|
+
// canonicalizer inside the constructor — no formal interning without a model.
|
|
639
717
|
const fieldSignature = new ArkSignature_1.FieldSignature((0, StringUtils_1.cloneText)(propertyAccessExpression.name.getText(this.sourceFile)), Builtin_1.Builtin.OBJECT_CLASS_SIGNATURE, Type_1.UnknownType.getInstance(), true);
|
|
640
718
|
const fieldRef = new Ref_1.ArkStaticFieldRef(fieldSignature);
|
|
641
|
-
return {
|
|
642
|
-
value: fieldRef,
|
|
643
|
-
valueOriginalPositions: fieldRefPositions,
|
|
644
|
-
stmts: stmts,
|
|
645
|
-
};
|
|
719
|
+
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
646
720
|
}
|
|
647
721
|
let fieldSignature;
|
|
648
|
-
if (
|
|
649
|
-
|
|
722
|
+
if (value instanceof Local_1.Local && value.getType() instanceof Type_1.ClassType) {
|
|
723
|
+
const baseType = value.getType();
|
|
724
|
+
const fieldName = (0, StringUtils_1.cloneText)(propertyAccessExpression.name.getText(this.sourceFile));
|
|
725
|
+
// Model-level direct lookup: resolve the base type's class and probe its field
|
|
726
|
+
// by name — a hit (the field really is declared on this class) reuses its formal
|
|
727
|
+
// signature directly (route hits formal, zero probe). A miss (field on a base
|
|
728
|
+
// class / static / actually a method / not yet registered due to build order —
|
|
729
|
+
// buildArkClassMembers builds method bodies before fields) builds a %unk stub
|
|
730
|
+
// (declaring 0, unclear semantics) routed to temp without the clear+miss error;
|
|
731
|
+
// inference is base-driven and corrects it via updateFieldSignature (formal hit
|
|
732
|
+
// retires the temp row) once the field is registered / resolved along the base
|
|
733
|
+
// type + heritage chain.
|
|
734
|
+
const baseClass = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance().getClassById(baseType.getClassSigID());
|
|
735
|
+
const field = baseClass === null || baseClass === void 0 ? void 0 : baseClass.getFieldWithName(fieldName);
|
|
736
|
+
fieldSignature = (_a = field === null || field === void 0 ? void 0 : field.getSignature()) !== null && _a !== void 0 ? _a : new ArkSignature_1.FieldSignature(fieldName, 0, Type_1.UnknownType.getInstance());
|
|
650
737
|
}
|
|
651
738
|
else {
|
|
652
739
|
fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName((0, StringUtils_1.cloneText)(propertyAccessExpression.name.getText(this.sourceFile)));
|
|
653
740
|
}
|
|
654
|
-
const fieldRef = new Ref_1.ArkInstanceFieldRef(
|
|
655
|
-
return {
|
|
656
|
-
value: fieldRef,
|
|
657
|
-
valueOriginalPositions: fieldRefPositions,
|
|
658
|
-
stmts: stmts,
|
|
659
|
-
};
|
|
741
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(value, fieldSignature);
|
|
742
|
+
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
660
743
|
}
|
|
661
744
|
elementAccessExpressionToValueAndStmts(elementAccessExpression) {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
745
|
+
const baseResult = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
746
|
+
const stmts = baseResult.stmts;
|
|
747
|
+
let baseValue = baseResult.value;
|
|
748
|
+
let basePositions = baseResult.valueOriginalPositions;
|
|
665
749
|
if (!(baseValue instanceof Local_1.Local)) {
|
|
666
|
-
(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
750
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(baseValue, basePositions, stmts);
|
|
751
|
+
baseValue = temp.value;
|
|
752
|
+
basePositions = temp.positions;
|
|
753
|
+
}
|
|
754
|
+
const argResult = this.tsNodeToValueAndStmts(elementAccessExpression.argumentExpression);
|
|
755
|
+
for (let i = 0; i < argResult.stmts.length; i++) {
|
|
756
|
+
stmts.push(argResult.stmts[i]);
|
|
757
|
+
}
|
|
758
|
+
let argumentValue = argResult.value;
|
|
759
|
+
let arguPositions = argResult.valueOriginalPositions;
|
|
675
760
|
if (IRUtils_1.IRUtils.moreThanOneAddress(argumentValue)) {
|
|
676
|
-
(
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
stmts: argumentStmts,
|
|
680
|
-
} = this.arkIRTransformer.generateAssignStmtForValue(argumentValue, arguPositions));
|
|
681
|
-
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
761
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(argumentValue, arguPositions, stmts);
|
|
762
|
+
argumentValue = temp.value;
|
|
763
|
+
arguPositions = temp.positions;
|
|
682
764
|
}
|
|
683
765
|
let elementAccessExpr;
|
|
684
766
|
const baseType = baseValue.getType();
|
|
@@ -691,7 +773,15 @@ class ArkValueTransformer {
|
|
|
691
773
|
elementAccessExpr = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature, true);
|
|
692
774
|
}
|
|
693
775
|
// reserve positions for field name
|
|
694
|
-
const exprPositions =
|
|
776
|
+
const exprPositions = new Array(1 + basePositions.length + arguPositions.length);
|
|
777
|
+
exprPositions[0] = Position_1.FullPosition.buildFromNode(elementAccessExpression, this.sourceFile);
|
|
778
|
+
let exprPosIdx = 1;
|
|
779
|
+
for (let i = 0; i < basePositions.length; i++) {
|
|
780
|
+
exprPositions[exprPosIdx++] = basePositions[i];
|
|
781
|
+
}
|
|
782
|
+
for (let i = 0; i < arguPositions.length; i++) {
|
|
783
|
+
exprPositions[exprPosIdx++] = arguPositions[i];
|
|
784
|
+
}
|
|
695
785
|
return {
|
|
696
786
|
value: elementAccessExpr,
|
|
697
787
|
valueOriginalPositions: exprPositions,
|
|
@@ -704,52 +794,169 @@ class ArkValueTransformer {
|
|
|
704
794
|
return this.generateInvokeValueAndStmts(callExpression.expression, argus, stmts, callExpression);
|
|
705
795
|
}
|
|
706
796
|
generateInvokeValueAndStmts(functionNameNode, args, currStmts, callExpression) {
|
|
707
|
-
const stmts =
|
|
708
|
-
const { value: calleeValue, valueOriginalPositions: calleePositions, stmts: calleeStmts } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
709
|
-
stmts.push(...calleeStmts);
|
|
797
|
+
const stmts = currStmts;
|
|
710
798
|
const invokeExprPosition = Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile);
|
|
711
|
-
|
|
712
|
-
|
|
799
|
+
let result;
|
|
800
|
+
let calleeNode = functionNameNode;
|
|
801
|
+
while (ts.isParenthesizedExpression(calleeNode)) {
|
|
802
|
+
calleeNode = calleeNode.expression;
|
|
713
803
|
}
|
|
714
|
-
if (
|
|
715
|
-
|
|
804
|
+
if (ts.isPropertyAccessExpression(calleeNode)) {
|
|
805
|
+
result = this.propertyAccessCalleeToInvoke(calleeNode, args, invokeExprPosition, stmts);
|
|
716
806
|
}
|
|
717
|
-
if (
|
|
718
|
-
|
|
807
|
+
else if (ts.isElementAccessExpression(calleeNode)) {
|
|
808
|
+
result = this.elementAccessCalleeToInvoke(calleeNode, args, invokeExprPosition, stmts);
|
|
719
809
|
}
|
|
720
|
-
|
|
810
|
+
else {
|
|
811
|
+
const { value: calleeValue, valueOriginalPositions: calleePositions, stmts: calleeStmts } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
812
|
+
for (let i = 0; i < calleeStmts.length; i++) {
|
|
813
|
+
stmts.push(calleeStmts[i]);
|
|
814
|
+
}
|
|
815
|
+
if (calleeValue instanceof Local_1.Local) {
|
|
816
|
+
result = this.handleLocalInvoke(calleeValue, callExpression, args, invokeExprPosition, calleePositions, stmts);
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
result = this.handleDefaultInvoke(calleeValue, args, invokeExprPosition, calleePositions, stmts);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (result.value instanceof Expr_1.AbstractInvokeExpr) {
|
|
823
|
+
result.value.setInvokeFullPosition(this.buildInvokeFullPosition(functionNameNode, callExpression));
|
|
824
|
+
}
|
|
825
|
+
return result;
|
|
721
826
|
}
|
|
722
|
-
|
|
827
|
+
buildInvokeFullPosition(calleeNode, callExpression) {
|
|
828
|
+
const nameNode = this.getCallNameNode(calleeNode);
|
|
829
|
+
const namePos = Position_1.FullPosition.buildFromNode(nameNode, this.sourceFile);
|
|
830
|
+
const callPos = Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile);
|
|
831
|
+
return new Position_1.FullPosition(namePos.getFirstLine(), namePos.getFirstCol(), callPos.getLastLine(), callPos.getLastCol());
|
|
832
|
+
}
|
|
833
|
+
getCallNameNode(callee) {
|
|
834
|
+
let expr = callee;
|
|
835
|
+
while (true) {
|
|
836
|
+
if (ts.isParenthesizedExpression(expr) || ts.isNonNullExpression(expr) ||
|
|
837
|
+
ts.isAsExpression(expr) || ts.isTypeAssertionExpression(expr)) {
|
|
838
|
+
expr = expr.expression;
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
if (ts.isPropertyAccessExpression(expr)) {
|
|
844
|
+
return expr.name;
|
|
845
|
+
}
|
|
846
|
+
if (ts.isElementAccessExpression(expr)) {
|
|
847
|
+
return expr.argumentExpression;
|
|
848
|
+
}
|
|
849
|
+
return expr;
|
|
850
|
+
}
|
|
851
|
+
propertyAccessCalleeToInvoke(propertyAccessExpression, args, invokeExprPosition, currStmts) {
|
|
852
|
+
// base 转换 + 物化——照搬 propertyAccessExpressionToValue。物化后必为 temp Local,故两个物化条件可并。
|
|
853
|
+
const stmts = currStmts;
|
|
854
|
+
const baseInner = this.tsNodeToValueAndStmts(propertyAccessExpression.expression);
|
|
855
|
+
for (let i = 0; i < baseInner.stmts.length; i++) {
|
|
856
|
+
stmts.push(baseInner.stmts[i]);
|
|
857
|
+
}
|
|
858
|
+
let baseValue = baseInner.value;
|
|
859
|
+
let basePositions = baseInner.valueOriginalPositions;
|
|
860
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(baseValue) || !(baseValue instanceof Local_1.Local)) {
|
|
861
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(baseValue, basePositions, stmts);
|
|
862
|
+
baseValue = temp.value;
|
|
863
|
+
basePositions = temp.positions;
|
|
864
|
+
}
|
|
865
|
+
const methodName = (0, StringUtils_1.cloneText)(propertyAccessExpression.name.getText(this.sourceFile));
|
|
723
866
|
let methodSignature;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
867
|
+
let invokeExpr;
|
|
868
|
+
let invokeExprPositions;
|
|
869
|
+
const argPositions = args.argPositions;
|
|
870
|
+
if (baseValue instanceof Local_1.Local && baseValue.getName() === Builtin_1.Builtin.OBJECT) {
|
|
871
|
+
// Object.xxx() 特判(照搬 propertyAccessExpressionToValue:含 locals.delete 副作用)。
|
|
872
|
+
this.locals.delete(baseValue.getName());
|
|
873
|
+
methodSignature = new ArkSignature_1.MethodSignature(Builtin_1.Builtin.OBJECT_CLASS_SIGNATURE, ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(methodName));
|
|
874
|
+
invokeExpr = new Expr_1.ArkStaticInvokeExpr(methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
875
|
+
invokeExprPositions = new Array(1 + argPositions.length);
|
|
876
|
+
invokeExprPositions[0] = invokeExprPosition;
|
|
728
877
|
}
|
|
729
878
|
else {
|
|
730
|
-
methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.
|
|
879
|
+
methodSignature = new ArkSignature_1.MethodSignature(0, ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(methodName));
|
|
880
|
+
if (baseValue instanceof Local_1.Local && baseValue.getType() instanceof Type_1.ClassType) {
|
|
881
|
+
const baseType = baseValue.getType();
|
|
882
|
+
const sameClass = baseType.getClassSigID() === this.declaringClass.getClassSigID();
|
|
883
|
+
const sameNameMethods = sameClass ? this.declaringClass.getMethodsWithName(methodName) : [];
|
|
884
|
+
const declared = sameNameMethods.length === 1 && sameNameMethods[0].getDeclareSigIDs() === undefined;
|
|
885
|
+
if (declared && sameNameMethods[0].getImplementationSignature() !== null) {
|
|
886
|
+
methodSignature = sameNameMethods[0].getSignature();
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
invokeExpr = new Expr_1.ArkInstanceInvokeExpr(baseValue, methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
890
|
+
invokeExprPositions = new Array(1 + basePositions.length + argPositions.length);
|
|
891
|
+
invokeExprPositions[0] = invokeExprPosition;
|
|
892
|
+
for (let i = 0; i < basePositions.length; i++) {
|
|
893
|
+
invokeExprPositions[1 + i] = basePositions[i];
|
|
894
|
+
}
|
|
731
895
|
}
|
|
732
|
-
let
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
896
|
+
for (let i = 0; i < argPositions.length; i++) {
|
|
897
|
+
invokeExprPositions[invokeExprPositions.length - argPositions.length + i] = argPositions[i];
|
|
898
|
+
}
|
|
899
|
+
return { value: invokeExpr, valueOriginalPositions: invokeExprPositions, stmts };
|
|
900
|
+
}
|
|
901
|
+
elementAccessCalleeToInvoke(elementAccessExpression, args, invokeExprPosition, currStmts) {
|
|
902
|
+
// base 转换 + 物化——照搬 elementAccessExpressionToValueAndStmts。物化后必为 temp Local,故两个物化条件可并。
|
|
903
|
+
const baseInner = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
904
|
+
for (let i = 0; i < baseInner.stmts.length; i++) {
|
|
905
|
+
currStmts.push(baseInner.stmts[i]);
|
|
906
|
+
}
|
|
907
|
+
let baseValue = baseInner.value;
|
|
908
|
+
let basePositions = baseInner.valueOriginalPositions;
|
|
909
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(baseValue) || !(baseValue instanceof Local_1.Local)) {
|
|
910
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(baseValue, basePositions, currStmts);
|
|
911
|
+
baseValue = temp.value;
|
|
912
|
+
basePositions = temp.positions;
|
|
913
|
+
}
|
|
914
|
+
// argument 转换 + 物化——照搬同函数后半。
|
|
915
|
+
const argInner = this.tsNodeToValueAndStmts(elementAccessExpression.argumentExpression);
|
|
916
|
+
for (let i = 0; i < argInner.stmts.length; i++) {
|
|
917
|
+
currStmts.push(argInner.stmts[i]);
|
|
918
|
+
}
|
|
919
|
+
let indexArgValue = argInner.value;
|
|
920
|
+
let indexArgPositions = argInner.valueOriginalPositions;
|
|
921
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(indexArgValue)) {
|
|
922
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(indexArgValue, indexArgPositions, currStmts);
|
|
923
|
+
indexArgValue = temp.value;
|
|
924
|
+
indexArgPositions = temp.positions;
|
|
925
|
+
}
|
|
926
|
+
let methodSignature;
|
|
927
|
+
const argPositions = args.argPositions;
|
|
928
|
+
let invokeExprPositions;
|
|
929
|
+
if (baseValue.getType() instanceof Type_1.ArrayType || baseValue.getType() instanceof Type_1.StringType) {
|
|
930
|
+
// Array/String 分支——复刻 handleArrayRefInvoke(含 stmts.pop() quirk:
|
|
931
|
+
// 方法名用源码文本,argument 物化 stmt 丢弃)。
|
|
932
|
+
const indexText = (0, StringUtils_1.cloneText)(elementAccessExpression.argumentExpression.getText(this.sourceFile));
|
|
933
|
+
methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(indexText);
|
|
934
|
+
currStmts.pop();
|
|
935
|
+
invokeExprPositions = new Array(2 + argPositions.length);
|
|
936
|
+
invokeExprPositions[0] = invokeExprPosition;
|
|
937
|
+
invokeExprPositions[1] = basePositions[0];
|
|
738
938
|
}
|
|
739
939
|
else {
|
|
740
|
-
|
|
940
|
+
// dynamic 分支——复刻原 handleFieldRefInvoke instance 路径。
|
|
941
|
+
methodSignature = new ArkSignature_1.MethodSignature(0, ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(indexArgValue.toString()));
|
|
942
|
+
invokeExprPositions = new Array(1 + basePositions.length + indexArgPositions.length + argPositions.length);
|
|
943
|
+
invokeExprPositions[0] = invokeExprPosition;
|
|
944
|
+
for (let i = 0; i < basePositions.length; i++) {
|
|
945
|
+
invokeExprPositions[1 + i] = basePositions[i];
|
|
946
|
+
}
|
|
947
|
+
for (let i = 0; i < indexArgPositions.length; i++) {
|
|
948
|
+
invokeExprPositions[1 + basePositions.length + i] = indexArgPositions[i];
|
|
949
|
+
}
|
|
741
950
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
};
|
|
951
|
+
const invokeExpr = new Expr_1.ArkInstanceInvokeExpr(baseValue, methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
952
|
+
for (let i = 0; i < argPositions.length; i++) {
|
|
953
|
+
invokeExprPositions[invokeExprPositions.length - argPositions.length + i] = argPositions[i];
|
|
954
|
+
}
|
|
955
|
+
return { value: invokeExpr, valueOriginalPositions: invokeExprPositions, stmts: currStmts };
|
|
748
956
|
}
|
|
749
957
|
handleLocalInvoke(calleeValue, callExpression, args, invokeExprPosition, calleePositions, currStmts) {
|
|
750
958
|
var _a;
|
|
751
959
|
let invokeExpr;
|
|
752
|
-
const invokeExprPositions = [invokeExprPosition];
|
|
753
960
|
const calleeName = calleeValue.getName();
|
|
754
961
|
if (this.isCustomViewCall(calleeName, callExpression)) {
|
|
755
962
|
return this.generateCustomViewStmt(calleeName, args.argValues, args.argPositions, callExpression, currStmts);
|
|
@@ -757,16 +964,25 @@ class ArkValueTransformer {
|
|
|
757
964
|
else if (this.isSystemComponentCall(calleeName, callExpression)) {
|
|
758
965
|
return this.generateSystemComponentStmt(calleeName, args.argValues, args.argPositions, callExpression, currStmts);
|
|
759
966
|
}
|
|
967
|
+
const argPositions = args.argPositions;
|
|
968
|
+
const isPtrInvoke = !((_a = this.getGlobals()) === null || _a === void 0 ? void 0 : _a.has(calleeName)) || calleeValue.getType() instanceof Type_1.FunctionType;
|
|
969
|
+
const invokeExprPositions = new Array(1 + (isPtrInvoke ? Math.max(calleePositions.length - 1, 0) : 0) + argPositions.length);
|
|
970
|
+
let writeIdx = 0;
|
|
971
|
+
invokeExprPositions[writeIdx++] = invokeExprPosition;
|
|
760
972
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(calleeName);
|
|
761
|
-
if (
|
|
973
|
+
if (isPtrInvoke) {
|
|
762
974
|
// the call to the left value or a value of function type should be ptr invoke expr.
|
|
763
975
|
invokeExpr = new Expr_1.ArkPtrInvokeExpr(methodSignature, calleeValue, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
764
|
-
|
|
976
|
+
for (let i = 1; i < calleePositions.length; i++) {
|
|
977
|
+
invokeExprPositions[writeIdx++] = calleePositions[i];
|
|
978
|
+
}
|
|
765
979
|
}
|
|
766
980
|
else {
|
|
767
981
|
invokeExpr = new Expr_1.ArkStaticInvokeExpr(methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
768
982
|
}
|
|
769
|
-
|
|
983
|
+
for (let i = 0; i < argPositions.length; i++) {
|
|
984
|
+
invokeExprPositions[writeIdx++] = argPositions[i];
|
|
985
|
+
}
|
|
770
986
|
return {
|
|
771
987
|
value: invokeExpr,
|
|
772
988
|
valueOriginalPositions: invokeExprPositions,
|
|
@@ -778,34 +994,25 @@ class ArkValueTransformer {
|
|
|
778
994
|
if (!ts.isCallExpression(callExpression)) {
|
|
779
995
|
return false;
|
|
780
996
|
}
|
|
781
|
-
const classSignature =
|
|
997
|
+
const classSignature = new ArkSignature_1.ClassSignature(callerName, this.declaringFile.getFileSigID());
|
|
782
998
|
const cls = ModelUtils_1.ModelUtils.getClass(this.declaringMethod, classSignature);
|
|
783
999
|
return (_a = cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) !== null && _a !== void 0 ? _a : false;
|
|
784
1000
|
}
|
|
785
1001
|
isSystemComponentCall(calleeName, callExpression) {
|
|
786
|
-
return (calleeName === EtsConst_1.COMPONENT_FOR_EACH || calleeName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) &&
|
|
787
|
-
ts.isCallExpression(callExpression);
|
|
788
|
-
}
|
|
789
|
-
handleArrayRefInvoke(calleeValue, functionNameNode, args, invokeExprPosition, calleePositions, currStmts) {
|
|
790
|
-
const stmts = [...currStmts];
|
|
791
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName((0, StringUtils_1.cloneText)(functionNameNode.argumentExpression.getText()));
|
|
792
|
-
stmts.pop();
|
|
793
|
-
const invokeExpr = new Expr_1.ArkInstanceInvokeExpr(calleeValue.getBase(), methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
794
|
-
const invokeExprPositions = [invokeExprPosition, calleePositions.slice(1)[0],
|
|
795
|
-
...args.argPositions];
|
|
796
|
-
return {
|
|
797
|
-
value: invokeExpr,
|
|
798
|
-
valueOriginalPositions: invokeExprPositions,
|
|
799
|
-
stmts: stmts,
|
|
800
|
-
};
|
|
1002
|
+
return (calleeName === EtsConst_1.COMPONENT_FOR_EACH || calleeName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) && ts.isCallExpression(callExpression);
|
|
801
1003
|
}
|
|
802
1004
|
handleDefaultInvoke(calleeValue, args, invokeExprPosition, calleePositions, currStmts) {
|
|
803
|
-
const stmts =
|
|
804
|
-
const
|
|
805
|
-
|
|
1005
|
+
const stmts = currStmts;
|
|
1006
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(calleeValue, calleePositions, stmts);
|
|
1007
|
+
const newCalleeValue = temp.value;
|
|
806
1008
|
const invokeExpr = new Expr_1.ArkPtrInvokeExpr(ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(newCalleeValue.getName()), newCalleeValue, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
807
|
-
const
|
|
808
|
-
|
|
1009
|
+
const argPositions = args.argPositions;
|
|
1010
|
+
const invokeExprPositions = new Array(2 + argPositions.length);
|
|
1011
|
+
invokeExprPositions[0] = invokeExprPosition;
|
|
1012
|
+
invokeExprPositions[1] = calleePositions[1];
|
|
1013
|
+
for (let i = 0; i < argPositions.length; i++) {
|
|
1014
|
+
invokeExprPositions[2 + i] = argPositions[i];
|
|
1015
|
+
}
|
|
809
1016
|
return {
|
|
810
1017
|
value: invokeExpr,
|
|
811
1018
|
valueOriginalPositions: invokeExprPositions,
|
|
@@ -827,16 +1034,17 @@ class ArkValueTransformer {
|
|
|
827
1034
|
builderMethodIndexes = new Set([1]);
|
|
828
1035
|
}
|
|
829
1036
|
}
|
|
830
|
-
const { argValues, argPositions, spreadFlags
|
|
1037
|
+
const { argValues, argPositions, spreadFlags } = this.parseArguments(currStmts, callExpression.arguments, builderMethodIndexes);
|
|
831
1038
|
return { realGenericTypes, argValues, argPositions, spreadFlags };
|
|
832
1039
|
}
|
|
833
1040
|
parseArguments(currStmts, argumentNodes, builderMethodIndexes) {
|
|
834
|
-
const
|
|
835
|
-
const
|
|
1041
|
+
const argCount = argumentNodes ? argumentNodes.length : 0;
|
|
1042
|
+
const argValues = argCount === 0 ? [] : new Array(argCount);
|
|
1043
|
+
const argPositions = argCount === 0 ? [] : new Array(argCount);
|
|
836
1044
|
let spreadFlags = [];
|
|
837
1045
|
if (argumentNodes) {
|
|
838
|
-
spreadFlags = new Array(
|
|
839
|
-
for (let i = 0; i <
|
|
1046
|
+
spreadFlags = new Array(argCount).fill(false);
|
|
1047
|
+
for (let i = 0; i < argCount; i++) {
|
|
840
1048
|
spreadFlags[i] = ts.isSpreadElement(argumentNodes[i]);
|
|
841
1049
|
const argument = argumentNodes[i];
|
|
842
1050
|
const prevBuilderMethodContextFlag = this.builderMethodContextFlag;
|
|
@@ -844,27 +1052,28 @@ class ArkValueTransformer {
|
|
|
844
1052
|
this.builderMethodContextFlag = true;
|
|
845
1053
|
this.arkIRTransformer.setBuilderMethodContextFlag(true);
|
|
846
1054
|
}
|
|
847
|
-
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts
|
|
1055
|
+
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts } = this.tsNodeToSingleAddressValueAndStmts(argument);
|
|
848
1056
|
this.builderMethodContextFlag = prevBuilderMethodContextFlag;
|
|
849
1057
|
this.arkIRTransformer.setBuilderMethodContextFlag(prevBuilderMethodContextFlag);
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1058
|
+
for (let j = 0; j < argStmts.length; j++) {
|
|
1059
|
+
currStmts.push(argStmts[j]);
|
|
1060
|
+
}
|
|
1061
|
+
argValues[i] = argValue;
|
|
1062
|
+
argPositions[i] = argPositionsSingle[0];
|
|
853
1063
|
}
|
|
854
1064
|
}
|
|
855
1065
|
return {
|
|
856
1066
|
argValues,
|
|
857
1067
|
argPositions,
|
|
858
|
-
spreadFlags: spreadFlags.every(
|
|
1068
|
+
spreadFlags: spreadFlags.every(f => f === false) ? undefined : spreadFlags,
|
|
859
1069
|
};
|
|
860
1070
|
}
|
|
861
1071
|
callableNodeToValueAndStmts(callableNode) {
|
|
862
|
-
const
|
|
863
|
-
const arrowArkMethod = new ArkMethod_1.ArkMethod();
|
|
1072
|
+
const arrowArkMethod = new ArkMethod_1.ArkMethod(this.declaringClass.getClassSigID());
|
|
864
1073
|
if (this.builderMethodContextFlag) {
|
|
865
1074
|
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arrowArkMethod);
|
|
866
1075
|
}
|
|
867
|
-
(0,
|
|
1076
|
+
(0, ArkMethodBuilder_2.buildArkMethodFromArkClass)(callableNode, this.declaringClass, arrowArkMethod, this.sourceFile, this.declaringMethod);
|
|
868
1077
|
const callableType = new Type_1.FunctionType(arrowArkMethod.getSignature());
|
|
869
1078
|
const callableValue = this.addNewLocal(arrowArkMethod.getName(), callableType);
|
|
870
1079
|
return {
|
|
@@ -902,6 +1111,8 @@ class ArkValueTransformer {
|
|
|
902
1111
|
const { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [Position_1.FullPosition.buildFromNode(newExpression, this.sourceFile)]);
|
|
903
1112
|
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
904
1113
|
const constructorMethodSubSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSubSignatureFromMethodName(TSConst_1.CONSTRUCTOR_NAME);
|
|
1114
|
+
// Object path: a stub class signature (unclear) is routed to the temp canonicalizer
|
|
1115
|
+
// inside the constructor — no formal interning without a model.
|
|
905
1116
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
906
1117
|
const { argValues: argValues, argPositions: argPositions, } = this.parseArguments(stmts, newExpression.arguments);
|
|
907
1118
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newLocal, constructorMethodSignature, argValues);
|
|
@@ -955,7 +1166,7 @@ class ArkValueTransformer {
|
|
|
955
1166
|
if (ts.isSpreadElement(arrayLiteralExpression.elements[i]) && firstSpreadIdx === -1) {
|
|
956
1167
|
firstSpreadIdx = i;
|
|
957
1168
|
}
|
|
958
|
-
const { value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts } = this.tsNodeToSingleAddressValueAndStmts(arrayLiteralExpression.elements[i]);
|
|
1169
|
+
const { value: elementValue, valueOriginalPositions: elementPosition, stmts: elementStmts, } = this.tsNodeToSingleAddressValueAndStmts(arrayLiteralExpression.elements[i]);
|
|
959
1170
|
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
960
1171
|
elementValues.push(elementValue);
|
|
961
1172
|
elementTypes.push(elementValue.getType());
|
|
@@ -966,7 +1177,7 @@ class ArkValueTransformer {
|
|
|
966
1177
|
return this.generateArrayExprFromLiteral(elementValues, elementTypes, elementPositions, wholePosition, 0, arrayLength, stmts);
|
|
967
1178
|
}
|
|
968
1179
|
else if (firstSpreadIdx === 0) {
|
|
969
|
-
const scene = this.
|
|
1180
|
+
const scene = this.declaringFile.getScene();
|
|
970
1181
|
if (arrayLength === 1) { // only spread element
|
|
971
1182
|
const sliceMethodSignature = Builtin_1.Builtin.buildArrayMethodSignature(Builtin_1.Builtin.SLICE, scene);
|
|
972
1183
|
const sliceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(elementValues[0], sliceMethodSignature, []);
|
|
@@ -982,7 +1193,7 @@ class ArkValueTransformer {
|
|
|
982
1193
|
}
|
|
983
1194
|
else { // contains spread elements and begins with literal elements.
|
|
984
1195
|
const beginLiteralValueAndStmts = this.generateArrayExprFromLiteral(elementValues, elementTypes, elementPositions, wholePosition, 0, firstSpreadIdx, stmts);
|
|
985
|
-
const scene = this.
|
|
1196
|
+
const scene = this.declaringFile.getScene();
|
|
986
1197
|
const concatMethodSignature = Builtin_1.Builtin.buildArrayMethodSignature(Builtin_1.Builtin.CONCAT, scene);
|
|
987
1198
|
const concatInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(beginLiteralValueAndStmts.value, concatMethodSignature, elementValues.slice(firstSpreadIdx));
|
|
988
1199
|
const concatInvokeExprPositions = [wholePosition, beginLiteralValueAndStmts.valueOriginalPositions[0],
|
|
@@ -999,8 +1210,7 @@ class ArkValueTransformer {
|
|
|
999
1210
|
else if (elementTypesSet.size > 1) {
|
|
1000
1211
|
baseType = new Type_1.UnionType(Array.from(elementTypesSet));
|
|
1001
1212
|
}
|
|
1002
|
-
const newArrayExprPosition =
|
|
1003
|
-
? wholePosition : Position_1.FullPosition.merge(elementPositions[0], elementPositions[end - 1]);
|
|
1213
|
+
const newArrayExprPosition = start === end || end - start === elementPositions.length ? wholePosition : Position_1.FullPosition.merge(elementPositions[0], elementPositions[end - 1]);
|
|
1004
1214
|
return this.generateArrayExprAndStmts(baseType, ValueUtil_1.ValueUtil.getOrCreateNumberConst(end - start), Position_1.FullPosition.DEFAULT, end - start, elementValues.slice(start, end), elementPositions.slice(start, end), currStmts, newArrayExprPosition, true);
|
|
1005
1215
|
}
|
|
1006
1216
|
generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, initializerValues, initializerPositions, currStmts, newArrayExprPosition, fromLiteral) {
|
|
@@ -1148,7 +1358,7 @@ class ArkValueTransformer {
|
|
|
1148
1358
|
}
|
|
1149
1359
|
awaitExpressionToValueAndStmts(awaitExpression) {
|
|
1150
1360
|
const stmts = [];
|
|
1151
|
-
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts
|
|
1361
|
+
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts } = this.tsNodeToValueAndStmts(awaitExpression.expression);
|
|
1152
1362
|
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
1153
1363
|
if (IRUtils_1.IRUtils.moreThanOneAddress(promiseValue)) {
|
|
1154
1364
|
({
|
|
@@ -1171,11 +1381,7 @@ class ArkValueTransformer {
|
|
|
1171
1381
|
let yieldPositions = [Position_1.FullPosition.DEFAULT];
|
|
1172
1382
|
let stmts = [];
|
|
1173
1383
|
if (yieldExpression.expression) {
|
|
1174
|
-
({
|
|
1175
|
-
value: yieldValue,
|
|
1176
|
-
valueOriginalPositions: yieldPositions,
|
|
1177
|
-
stmts: stmts,
|
|
1178
|
-
} = this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
1384
|
+
({ value: yieldValue, valueOriginalPositions: yieldPositions, stmts: stmts } = this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
1179
1385
|
}
|
|
1180
1386
|
const yieldExpr = new Expr_1.ArkYieldExpr(yieldValue);
|
|
1181
1387
|
const yieldExprPositions = [Position_1.FullPosition.buildFromNode(yieldExpression, this.sourceFile), ...yieldPositions];
|
|
@@ -1186,7 +1392,7 @@ class ArkValueTransformer {
|
|
|
1186
1392
|
};
|
|
1187
1393
|
}
|
|
1188
1394
|
deleteExpressionToValueAndStmts(deleteExpression) {
|
|
1189
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts
|
|
1395
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(deleteExpression.expression);
|
|
1190
1396
|
const deleteExpr = new Expr_1.ArkDeleteExpr(exprValue);
|
|
1191
1397
|
const deleteExprPositions = [Position_1.FullPosition.buildFromNode(deleteExpression, this.sourceFile), ...exprPositions];
|
|
1192
1398
|
return {
|
|
@@ -1196,7 +1402,7 @@ class ArkValueTransformer {
|
|
|
1196
1402
|
};
|
|
1197
1403
|
}
|
|
1198
1404
|
voidExpressionToValueAndStmts(voidExpression) {
|
|
1199
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts
|
|
1405
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(voidExpression.expression);
|
|
1200
1406
|
const { stmts: exprStmts } = this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions);
|
|
1201
1407
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
1202
1408
|
return {
|
|
@@ -1212,7 +1418,7 @@ class ArkValueTransformer {
|
|
|
1212
1418
|
return this.tsNodeToValueAndStmts(parenthesizedExpression.expression);
|
|
1213
1419
|
}
|
|
1214
1420
|
typeOfExpressionToValueAndStmts(typeOfExpression) {
|
|
1215
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1421
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(typeOfExpression.expression);
|
|
1216
1422
|
const typeOfExpr = new Expr_1.ArkTypeOfExpr(exprValue);
|
|
1217
1423
|
const typeOfExprPositions = [Position_1.FullPosition.buildFromNode(typeOfExpression, this.sourceFile), ...exprPositions];
|
|
1218
1424
|
return {
|
|
@@ -1223,7 +1429,7 @@ class ArkValueTransformer {
|
|
|
1223
1429
|
}
|
|
1224
1430
|
asExpressionToValueAndStmts(asExpression) {
|
|
1225
1431
|
const stmts = [];
|
|
1226
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1432
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(asExpression.expression);
|
|
1227
1433
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
1228
1434
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
1229
1435
|
({
|
|
@@ -1242,7 +1448,7 @@ class ArkValueTransformer {
|
|
|
1242
1448
|
};
|
|
1243
1449
|
}
|
|
1244
1450
|
typeAssertionToValueAndStmts(typeAssertion) {
|
|
1245
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1451
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(typeAssertion.expression);
|
|
1246
1452
|
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(typeAssertion.type));
|
|
1247
1453
|
const castExprPositions = [Position_1.FullPosition.buildFromNode(typeAssertion, this.sourceFile), ...exprPositions];
|
|
1248
1454
|
return {
|
|
@@ -1271,82 +1477,76 @@ class ArkValueTransformer {
|
|
|
1271
1477
|
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, true, isConst, declarationType, needRightOp);
|
|
1272
1478
|
}
|
|
1273
1479
|
assignmentToValueAndStmts(leftOpNode, rightOpNode, variableDefFlag, isConst, declarationType, needRightOp = true) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1480
|
+
const isArrayDestructuring = ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode);
|
|
1481
|
+
const isObjectDestructuring = ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode);
|
|
1482
|
+
// In declarations the destructuring target is a binding pattern, in assignments an array/object literal.
|
|
1483
|
+
const leftResult = ts.isIdentifier(leftOpNode)
|
|
1484
|
+
? this.identifierToValueAndStmts(leftOpNode, variableDefFlag)
|
|
1485
|
+
: isArrayDestructuring
|
|
1486
|
+
? this.arrayDestructuringToValueAndStmts(leftOpNode, isConst)
|
|
1487
|
+
: isObjectDestructuring
|
|
1488
|
+
? this.objectDestructuringToValueAndStmts(leftOpNode, isConst)
|
|
1489
|
+
: this.tsNodeToValueAndStmts(leftOpNode);
|
|
1490
|
+
if (!needRightOp) {
|
|
1491
|
+
return { value: leftResult.value, valueOriginalPositions: leftResult.valueOriginalPositions, stmts: leftResult.stmts };
|
|
1492
|
+
}
|
|
1493
|
+
const rightResult = this.assignmentRightOpToValueAndStmts(rightOpNode, leftResult.value);
|
|
1494
|
+
if (leftResult.value instanceof Local_1.Local) {
|
|
1495
|
+
if (variableDefFlag) {
|
|
1496
|
+
leftResult.value.setConstFlag(isConst);
|
|
1497
|
+
leftResult.value.setType(declarationType);
|
|
1498
|
+
}
|
|
1499
|
+
const rightType = rightResult.value.getType();
|
|
1500
|
+
if (leftResult.value.getType() instanceof Type_1.UnknownType && !(rightType instanceof Type_1.UnknownType) && !(rightType instanceof Type_1.UndefinedType)) {
|
|
1501
|
+
leftResult.value.setType(rightType);
|
|
1502
|
+
}
|
|
1503
|
+
const unifiedType = (0, builderUtils_1.unifyDeclaredTypeWithInitializer)(leftResult.value.getType(), rightType);
|
|
1504
|
+
if (unifiedType !== leftResult.value.getType()) {
|
|
1505
|
+
leftResult.value.setType(unifiedType);
|
|
1506
|
+
}
|
|
1277
1507
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1508
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftResult.value, rightResult.value);
|
|
1509
|
+
const leftPositions = leftResult.valueOriginalPositions;
|
|
1510
|
+
const operandPositions = new Array(leftPositions.length + rightResult.valueOriginalPositions.length);
|
|
1511
|
+
for (let i = 0; i < leftPositions.length; i++) {
|
|
1512
|
+
operandPositions[i] = leftPositions[i];
|
|
1281
1513
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1514
|
+
const rightPositions = rightResult.valueOriginalPositions;
|
|
1515
|
+
for (let i = 0; i < rightPositions.length; i++) {
|
|
1516
|
+
operandPositions[leftPositions.length + i] = rightPositions[i];
|
|
1285
1517
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1518
|
+
assignStmt.setOperandOriginalPositions(operandPositions);
|
|
1519
|
+
const destructuring = isArrayDestructuring || isObjectDestructuring;
|
|
1520
|
+
if (destructuring) {
|
|
1521
|
+
rightResult.stmts.push(assignStmt);
|
|
1288
1522
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
if (needRightOp) {
|
|
1292
|
-
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.assignmentRightOpToValueAndStmts(rightOpNode, leftValue);
|
|
1293
|
-
if (leftValue instanceof Local_1.Local) {
|
|
1294
|
-
if (variableDefFlag) {
|
|
1295
|
-
leftValue.setConstFlag(isConst);
|
|
1296
|
-
leftValue.setType(declarationType);
|
|
1297
|
-
}
|
|
1298
|
-
if (leftValue.getType() instanceof Type_1.UnknownType && !(rightValue.getType() instanceof Type_1.UnknownType) &&
|
|
1299
|
-
!(rightValue.getType() instanceof Type_1.UndefinedType)) {
|
|
1300
|
-
leftValue.setType(rightValue.getType());
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
1304
|
-
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
1305
|
-
if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode) ||
|
|
1306
|
-
ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
1307
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1308
|
-
stmts.push(assignStmt);
|
|
1309
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1310
|
-
}
|
|
1311
|
-
else {
|
|
1312
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1313
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1314
|
-
stmts.push(assignStmt);
|
|
1315
|
-
}
|
|
1523
|
+
for (let i = 0; i < leftResult.stmts.length; i++) {
|
|
1524
|
+
rightResult.stmts.push(leftResult.stmts[i]);
|
|
1316
1525
|
}
|
|
1317
|
-
|
|
1318
|
-
stmts
|
|
1526
|
+
if (!destructuring) {
|
|
1527
|
+
rightResult.stmts.push(assignStmt);
|
|
1319
1528
|
}
|
|
1320
|
-
return {
|
|
1321
|
-
value: leftValue,
|
|
1322
|
-
valueOriginalPositions: leftPositions,
|
|
1323
|
-
stmts: stmts,
|
|
1324
|
-
};
|
|
1529
|
+
return { value: leftResult.value, valueOriginalPositions: leftResult.valueOriginalPositions, stmts: rightResult.stmts };
|
|
1325
1530
|
}
|
|
1326
1531
|
assignmentRightOpToValueAndStmts(rightOpNode, leftValue) {
|
|
1327
1532
|
let rightValue;
|
|
1328
1533
|
let rightPositions;
|
|
1329
|
-
let
|
|
1330
|
-
const rightStmts = [];
|
|
1534
|
+
let rightStmts;
|
|
1331
1535
|
if (rightOpNode) {
|
|
1332
|
-
(
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
} = this.tsNodeToValueAndStmts(rightOpNode));
|
|
1337
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
1536
|
+
const rightResult = this.tsNodeToValueAndStmts(rightOpNode);
|
|
1537
|
+
rightValue = rightResult.value;
|
|
1538
|
+
rightPositions = rightResult.valueOriginalPositions;
|
|
1539
|
+
rightStmts = rightResult.stmts;
|
|
1338
1540
|
}
|
|
1339
1541
|
else {
|
|
1340
1542
|
rightValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1341
1543
|
rightPositions = [Position_1.FullPosition.DEFAULT];
|
|
1544
|
+
rightStmts = [];
|
|
1342
1545
|
}
|
|
1343
1546
|
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
1344
|
-
(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
stmts: tempRightStmts,
|
|
1348
|
-
} = this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions));
|
|
1349
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
1547
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(rightValue, rightPositions, rightStmts);
|
|
1548
|
+
rightValue = temp.value;
|
|
1549
|
+
rightPositions = temp.positions;
|
|
1350
1550
|
}
|
|
1351
1551
|
return {
|
|
1352
1552
|
value: rightValue,
|
|
@@ -1378,8 +1578,7 @@ class ArkValueTransformer {
|
|
|
1378
1578
|
const elementName = (0, StringUtils_1.cloneText)(nodeInsideRest.getText(this.sourceFile));
|
|
1379
1579
|
targetLocal = ts.isBindingElement(element) ? this.addNewLocal(elementName) : this.getOrCreateLocal(elementName);
|
|
1380
1580
|
}
|
|
1381
|
-
const
|
|
1382
|
-
const sliceMethodSignature = new ArkSignature_1.MethodSignature(Builtin_1.Builtin.ARRAY_CLASS_SIGNATURE, sliceMethodSubSignature);
|
|
1581
|
+
const sliceMethodSignature = Builtin_1.Builtin.getOrCreateArrayStubMethodSignature(Builtin_1.Builtin.SLICE);
|
|
1383
1582
|
const sliceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(arrayTempLocal, sliceMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(i)]);
|
|
1384
1583
|
const sliceInvokeExprPositions = [wholePosition, targetLocalPosition];
|
|
1385
1584
|
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, sliceInvokeExpr);
|
|
@@ -1454,47 +1653,39 @@ class ArkValueTransformer {
|
|
|
1454
1653
|
}
|
|
1455
1654
|
const stmts = [];
|
|
1456
1655
|
const binaryExpressionPosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1457
|
-
const
|
|
1458
|
-
|
|
1656
|
+
const leftResult = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.left);
|
|
1657
|
+
leftResult.stmts.forEach(stmt => stmts.push(stmt));
|
|
1459
1658
|
if (operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
1460
|
-
const
|
|
1461
|
-
const
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
return {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
};
|
|
1469
|
-
}
|
|
1470
|
-
const { value: opValue2, valueOriginalPositions: opPositions2, stmts: opStmts2, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1471
|
-
opStmts2.forEach(stmt => stmts.push(stmt));
|
|
1659
|
+
const instOfExpr = new Expr_1.ArkInstanceOfExpr(leftResult.value, new Type_1.UnclearReferenceType((0, StringUtils_1.cloneText)(binaryExpression.right.getText(this.sourceFile))));
|
|
1660
|
+
const instOfExprPositions = [binaryExpressionPosition, ...leftResult.valueOriginalPositions];
|
|
1661
|
+
const instOfResult = this.arkIRTransformer.generateAssignStmtForValue(instOfExpr, instOfExprPositions);
|
|
1662
|
+
instOfResult.stmts.forEach(stmt => stmts.push(stmt));
|
|
1663
|
+
return { value: instOfResult.value, valueOriginalPositions: instOfResult.valueOriginalPositions, stmts: stmts };
|
|
1664
|
+
}
|
|
1665
|
+
const rightResult = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1666
|
+
rightResult.stmts.forEach(stmt => stmts.push(stmt));
|
|
1472
1667
|
let exprValue;
|
|
1473
1668
|
let exprValuePositions = [binaryExpressionPosition];
|
|
1474
1669
|
if (operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
1475
|
-
exprValue =
|
|
1670
|
+
exprValue = rightResult.value;
|
|
1476
1671
|
}
|
|
1477
1672
|
else {
|
|
1478
1673
|
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToBinaryOperator(operatorToken.kind);
|
|
1479
1674
|
if (operator) {
|
|
1480
1675
|
if (this.isRelationalOperator(operator)) {
|
|
1481
|
-
exprValue = new Expr_1.ArkConditionExpr(
|
|
1676
|
+
exprValue = new Expr_1.ArkConditionExpr(leftResult.value, rightResult.value, operator);
|
|
1482
1677
|
}
|
|
1483
1678
|
else {
|
|
1484
|
-
exprValue = new Expr_1.ArkNormalBinopExpr(
|
|
1679
|
+
exprValue = new Expr_1.ArkNormalBinopExpr(leftResult.value, rightResult.value, operator);
|
|
1485
1680
|
}
|
|
1486
|
-
exprValuePositions.push(...
|
|
1681
|
+
exprValuePositions.push(...leftResult.valueOriginalPositions, ...rightResult.valueOriginalPositions);
|
|
1487
1682
|
}
|
|
1488
1683
|
else {
|
|
1489
1684
|
exprValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1490
1685
|
exprValuePositions.push(binaryExpressionPosition);
|
|
1491
1686
|
}
|
|
1492
1687
|
}
|
|
1493
|
-
return {
|
|
1494
|
-
value: exprValue,
|
|
1495
|
-
valueOriginalPositions: exprValuePositions,
|
|
1496
|
-
stmts: stmts,
|
|
1497
|
-
};
|
|
1688
|
+
return { value: exprValue, valueOriginalPositions: exprValuePositions, stmts: stmts };
|
|
1498
1689
|
}
|
|
1499
1690
|
compoundAssignmentToValueAndStmts(binaryExpression) {
|
|
1500
1691
|
const stmts = [];
|
|
@@ -1513,7 +1704,7 @@ class ArkValueTransformer {
|
|
|
1513
1704
|
leftValue = leftValueOrig;
|
|
1514
1705
|
leftPositions = leftPositionsOrig;
|
|
1515
1706
|
}
|
|
1516
|
-
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1707
|
+
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1517
1708
|
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1518
1709
|
const operator = this.compoundAssignmentTokenToBinaryOperator(binaryExpression.operatorToken.kind);
|
|
1519
1710
|
if (operator) {
|
|
@@ -1525,14 +1716,14 @@ class ArkValueTransformer {
|
|
|
1525
1716
|
...(assignTarget === leftValueOrig ? leftPositionsOrig : leftPositions),
|
|
1526
1717
|
exprValuePosition,
|
|
1527
1718
|
...leftPositions,
|
|
1528
|
-
...rightPositions
|
|
1719
|
+
...rightPositions,
|
|
1529
1720
|
]);
|
|
1530
1721
|
stmts.push(assignStmt);
|
|
1531
1722
|
}
|
|
1532
1723
|
return {
|
|
1533
1724
|
value: leftValueOrig,
|
|
1534
1725
|
valueOriginalPositions: leftPositionsOrig,
|
|
1535
|
-
stmts: stmts
|
|
1726
|
+
stmts: stmts,
|
|
1536
1727
|
};
|
|
1537
1728
|
}
|
|
1538
1729
|
compoundAssignmentTokenToBinaryOperator(token) {
|
|
@@ -1573,7 +1764,7 @@ class ArkValueTransformer {
|
|
|
1573
1764
|
}
|
|
1574
1765
|
conditionToValueAndStmts(condition) {
|
|
1575
1766
|
const stmts = [];
|
|
1576
|
-
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts
|
|
1767
|
+
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts } = this.tsNodeToValueAndStmts(condition);
|
|
1577
1768
|
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1578
1769
|
let conditionExpr;
|
|
1579
1770
|
if (conditionValue instanceof Expr_1.AbstractBinopExpr && this.isRelationalOperator(conditionValue.getOperator())) {
|
|
@@ -1756,8 +1947,8 @@ class ArkValueTransformer {
|
|
|
1756
1947
|
if (ts.isQualifiedName(exprNameNode)) {
|
|
1757
1948
|
if ((0, StringUtils_1.cloneText)(exprNameNode.left.getText(this.sourceFile)) === TSConst_1.THIS_NAME) {
|
|
1758
1949
|
const fieldName = (0, StringUtils_1.cloneText)(exprNameNode.right.getText(this.sourceFile));
|
|
1759
|
-
const fieldSignature = (_b = (_a = this.
|
|
1760
|
-
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.
|
|
1950
|
+
const fieldSignature = (_b = (_a = this.declaringClass.getFieldWithName(fieldName)) === null || _a === void 0 ? void 0 : _a.getSignature()) !== null && _b !== void 0 ? _b : ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName(fieldName);
|
|
1951
|
+
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.declaringClass.getSignature(), genericTypes));
|
|
1761
1952
|
opValue = new Ref_1.ArkInstanceFieldRef(baseLocal, fieldSignature);
|
|
1762
1953
|
}
|
|
1763
1954
|
else {
|
|
@@ -1879,21 +2070,20 @@ class ArkValueTransformer {
|
|
|
1879
2070
|
}
|
|
1880
2071
|
}
|
|
1881
2072
|
resolveTypeLiteralNode(typeLiteralNode) {
|
|
1882
|
-
const
|
|
1883
|
-
const
|
|
1884
|
-
const declaringNamespace = declaringClass.getDeclaringArkNamespace();
|
|
2073
|
+
const declaringNamespace = this.declaringNamespace;
|
|
2074
|
+
const anonymousClass = new ArkClass_1.ArkClass(this.declaringFile.getFileSigID(), declaringNamespace === null || declaringNamespace === void 0 ? void 0 : declaringNamespace.getNamespaceSigID());
|
|
1885
2075
|
if (declaringNamespace) {
|
|
1886
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode,
|
|
2076
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode, anonymousClass, this.sourceFile);
|
|
2077
|
+
declaringNamespace.addArkClass(anonymousClass);
|
|
1887
2078
|
}
|
|
1888
2079
|
else {
|
|
1889
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode,
|
|
2080
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode, this.declaringFile, anonymousClass, this.sourceFile);
|
|
1890
2081
|
}
|
|
1891
2082
|
return new Type_1.ClassType(anonymousClass.getSignature());
|
|
1892
2083
|
}
|
|
1893
2084
|
resolveFunctionTypeNode(functionTypeNode) {
|
|
1894
|
-
const anonymousMethod = new ArkMethod_1.ArkMethod();
|
|
1895
|
-
|
|
1896
|
-
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionTypeNode, declaringClass, anonymousMethod, this.sourceFile);
|
|
2085
|
+
const anonymousMethod = new ArkMethod_1.ArkMethod(this.declaringClass.getClassSigID());
|
|
2086
|
+
(0, ArkMethodBuilder_2.buildArkMethodFromArkClass)(functionTypeNode, this.declaringClass, anonymousMethod, this.sourceFile);
|
|
1897
2087
|
return new Type_1.FunctionType(anonymousMethod.getSignature());
|
|
1898
2088
|
}
|
|
1899
2089
|
static isCompoundAssignmentOperator(operator) {
|