arkanalyzer 1.0.93 → 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.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
- 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 +458 -266
- 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 +203 -59
- 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 +119 -73
- 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/node_modules/ohos-typescript/README.OpenSource +0 -11
- package/lib/node_modules/ohos-typescript/README.md +0 -81
- package/lib/node_modules/ohos-typescript/SECURITY.md +0 -41
- package/lib/node_modules/ohos-typescript/ThirdPartyNoticeText.txt +0 -193
- package/lib/node_modules/ohos-typescript/bin/tsc +0 -2
- package/lib/node_modules/ohos-typescript/bin/tsserver +0 -2
- package/lib/node_modules/ohos-typescript/lib/README.md +0 -5
- package/lib/node_modules/ohos-typescript/lib/cancellationToken.js +0 -86
- package/lib/node_modules/ohos-typescript/lib/cs/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/de/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/es/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/fr/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/it/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ja/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ko/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/lib.dom.d.ts +0 -18505
- package/lib/node_modules/ohos-typescript/lib/lib.dom.iterable.d.ts +0 -341
- package/lib/node_modules/ohos-typescript/lib/lib.scripthost.d.ts +0 -327
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.d.ts +0 -6192
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.importscripts.d.ts +0 -26
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.iterable.d.ts +0 -175
- package/lib/node_modules/ohos-typescript/lib/pl/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/pt-br/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ru/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/tr/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/tsc.js +0 -114551
- package/lib/node_modules/ohos-typescript/lib/tsserver.js +0 -179691
- package/lib/node_modules/ohos-typescript/lib/tsserverlibrary.d.ts +0 -13648
- package/lib/node_modules/ohos-typescript/lib/tsserverlibrary.js +0 -178688
- package/lib/node_modules/ohos-typescript/lib/typesMap.json +0 -497
- package/lib/node_modules/ohos-typescript/lib/typingsInstaller.js +0 -39871
- package/lib/node_modules/ohos-typescript/lib/watchGuard.js +0 -49
- package/lib/node_modules/ohos-typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -1880
- 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);
|
|
@@ -311,7 +369,9 @@ class ArkValueTransformer {
|
|
|
311
369
|
appendInitStmts(stmts, fieldInitStmts, initStmts) {
|
|
312
370
|
initStmts.forEach(stmt => {
|
|
313
371
|
stmts.push(stmt);
|
|
314
|
-
|
|
372
|
+
if (!(stmt instanceof ArkIRTransformer_1.DummyStmt)) {
|
|
373
|
+
fieldInitStmts.push(stmt);
|
|
374
|
+
}
|
|
315
375
|
});
|
|
316
376
|
}
|
|
317
377
|
setFieldInitializerWithPosition(field, fieldInitStmts, initValue) {
|
|
@@ -373,6 +433,8 @@ class ArkValueTransformer {
|
|
|
373
433
|
const { value: newExprLocal, valueOriginalPositions: newExprPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [componentExpressionPosition]);
|
|
374
434
|
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
375
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.
|
|
376
438
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
377
439
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newExprLocal, constructorMethodSignature, args);
|
|
378
440
|
const assignStmt = new Stmt_1.ArkAssignStmt(newExprLocal, instanceInvokeExpr);
|
|
@@ -387,7 +449,7 @@ class ArkValueTransformer {
|
|
|
387
449
|
anonymous.pos = componentExpression.body.pos;
|
|
388
450
|
// @ts-expect-error: add end info for the created ArrowFunction
|
|
389
451
|
anonymous.end = componentExpression.body.end;
|
|
390
|
-
const { value: builderMethod, valueOriginalPositions: builderMethodPositions
|
|
452
|
+
const { value: builderMethod, valueOriginalPositions: builderMethodPositions } = this.callableNodeToValueAndStmts(anonymous);
|
|
391
453
|
createViewArgs.push(builderMethod);
|
|
392
454
|
createViewArgPositionsAll.push(builderMethodPositions);
|
|
393
455
|
}
|
|
@@ -400,8 +462,10 @@ class ArkValueTransformer {
|
|
|
400
462
|
stmts: stmts,
|
|
401
463
|
};
|
|
402
464
|
}
|
|
465
|
+
/** @internal Emit a component create invocation assigned to a temporary local. */
|
|
403
466
|
generateComponentCreationStmts(componentName, createArgs, componentExpressionPosition, createArgsPositionsAllFlat) {
|
|
404
|
-
|
|
467
|
+
// 组件 create stub 签名 per-(name, method) 缓存。
|
|
468
|
+
const createMethodSignature = ModelUtils_1.ModelUtils.getOrCreateComponentMethodSig(componentName, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
405
469
|
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, createArgs);
|
|
406
470
|
const createInvokeExprPositions = [componentExpressionPosition, ...createArgsPositionsAllFlat];
|
|
407
471
|
const { value: componentValue, valueOriginalPositions: componentPositions, stmts: componentStmts, } = this.arkIRTransformer.generateAssignStmtForValue(createInvokeExpr, createInvokeExprPositions);
|
|
@@ -411,16 +475,30 @@ class ArkValueTransformer {
|
|
|
411
475
|
stmts: componentStmts,
|
|
412
476
|
};
|
|
413
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. */
|
|
414
488
|
generateComponentPopStmts(componentName, componentExpressionPosition) {
|
|
415
489
|
var _a;
|
|
416
490
|
let popMethodSignature = ModelUtils_1.ModelUtils.popMethodSignatureCache.get(componentName);
|
|
417
491
|
if (!popMethodSignature) {
|
|
418
|
-
const cls =
|
|
492
|
+
const cls = SdkUtils_1.SdkUtils.getSdkGlobal(EtsConst_1.COMMON_METHOD);
|
|
419
493
|
if (cls instanceof ArkClass_1.ArkClass) {
|
|
420
494
|
const commonSignature = (_a = cls.getMethodWithName(EtsConst_1.COMPONENT_POP_FUNCTION)) === null || _a === void 0 ? void 0 : _a.getSignature();
|
|
421
495
|
if (commonSignature) {
|
|
496
|
+
// display 归一化:AliasClassSignature 构造即 intern formal + 双注册 origin ArkClass model(display 由 formal canonical 自持)。
|
|
422
497
|
const classSignature = new ArkSignature_1.AliasClassSignature(componentName, commonSignature.getDeclaringClassSignature());
|
|
423
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);
|
|
424
502
|
}
|
|
425
503
|
}
|
|
426
504
|
popMethodSignature = popMethodSignature !== null && popMethodSignature !== void 0 ? popMethodSignature : ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(componentName, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
@@ -436,22 +514,21 @@ class ArkValueTransformer {
|
|
|
436
514
|
etsComponentExpressionToValueAndStmts(etsComponentExpression) {
|
|
437
515
|
const stmts = [];
|
|
438
516
|
const componentName = (0, StringUtils_1.cloneText)(etsComponentExpression.expression.text);
|
|
439
|
-
const { argValues: argValues, argPositions: argPositions
|
|
517
|
+
const { argValues: argValues, argPositions: argPositions } = this.parseArguments(stmts, etsComponentExpression.arguments);
|
|
440
518
|
if ((0, EtsConst_1.isEtsSystemComponent)(componentName)) {
|
|
441
519
|
return this.generateSystemComponentStmt(componentName, argValues, argPositions, etsComponentExpression, stmts);
|
|
442
520
|
}
|
|
443
521
|
return this.generateCustomViewStmt(componentName, argValues, argPositions, etsComponentExpression, stmts);
|
|
444
522
|
}
|
|
445
523
|
classExpressionToValueAndStmts(classExpression) {
|
|
446
|
-
const
|
|
447
|
-
const
|
|
448
|
-
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());
|
|
449
526
|
if (declaringArkNamespace) {
|
|
450
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression,
|
|
527
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(classExpression, newClass, this.sourceFile, this.declaringMethod);
|
|
528
|
+
declaringArkNamespace.addArkClass(newClass);
|
|
451
529
|
}
|
|
452
530
|
else {
|
|
453
|
-
|
|
454
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, declaringArkFile, newClass, this.sourceFile, this.declaringMethod);
|
|
531
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(classExpression, this.declaringFile, newClass, this.sourceFile, this.declaringMethod);
|
|
455
532
|
}
|
|
456
533
|
const classValue = this.addNewLocal(newClass.getName(), new Type_1.ClassType(newClass.getSignature()));
|
|
457
534
|
return {
|
|
@@ -461,7 +538,7 @@ class ArkValueTransformer {
|
|
|
461
538
|
};
|
|
462
539
|
}
|
|
463
540
|
templateExpressionToValueAndStmts(templateExpression) {
|
|
464
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions
|
|
541
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(templateExpression);
|
|
465
542
|
const { placeholderStringLocals, placeholderStringLocalPositions, newStmts } = this.processTemplatePlaceholders(placeholderValues, placeholderPositions, stmts);
|
|
466
543
|
return this.combineTemplateParts(stringTextValues, stringTextPositions, placeholderStringLocals, placeholderStringLocalPositions, newStmts);
|
|
467
544
|
}
|
|
@@ -532,7 +609,7 @@ class ArkValueTransformer {
|
|
|
532
609
|
};
|
|
533
610
|
}
|
|
534
611
|
taggedTemplateExpressionToValueAndStmts(taggedTemplateExpression) {
|
|
535
|
-
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions
|
|
612
|
+
const { stmts, stringTextValues, placeholderValues, stringTextPositions, placeholderPositions } = this.collectTemplateValues(taggedTemplateExpression.template);
|
|
536
613
|
const stringTextBaseType = Type_1.StringType.getInstance();
|
|
537
614
|
const stringTextArrayLen = stringTextValues.length;
|
|
538
615
|
const stringTextArrayLenValue = ValueUtil_1.ValueUtil.getOrCreateNumberConst(stringTextArrayLen);
|
|
@@ -544,7 +621,8 @@ class ArkValueTransformer {
|
|
|
544
621
|
const placeholdersArrayLenPosition = Position_1.FullPosition.DEFAULT;
|
|
545
622
|
const { value: placeholdersLocal, valueOriginalPositions: placeholdersLocalPositions, stmts: placeholdersStmts, } = this.generateArrayExprAndStmts(placeholderBaseType, placeholdersArrayLenValue, placeholdersArrayLenPosition, placeholdersArrayLen, placeholderValues, placeholderPositions, templateObjectStmts, Position_1.FullPosition.DEFAULT, true);
|
|
546
623
|
const taggedFuncArgus = {
|
|
547
|
-
realGenericTypes: undefined,
|
|
624
|
+
realGenericTypes: undefined,
|
|
625
|
+
argValues: [templateObjectLocal, placeholdersLocal],
|
|
548
626
|
argPositions: [templateObjectLocalPositions[0], placeholdersLocalPositions[0]],
|
|
549
627
|
};
|
|
550
628
|
return this.generateInvokeValueAndStmts(taggedTemplateExpression.tag, taggedFuncArgus, placeholdersStmts, taggedTemplateExpression);
|
|
@@ -567,7 +645,7 @@ class ArkValueTransformer {
|
|
|
567
645
|
const stringTextPositions = [Position_1.FullPosition.buildFromNode(head, this.sourceFile)];
|
|
568
646
|
const placeholderPositions = [];
|
|
569
647
|
for (const templateSpan of templateLiteral.templateSpans) {
|
|
570
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
648
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(templateSpan.expression);
|
|
571
649
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
572
650
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
573
651
|
({
|
|
@@ -611,72 +689,78 @@ class ArkValueTransformer {
|
|
|
611
689
|
};
|
|
612
690
|
}
|
|
613
691
|
propertyAccessExpressionToValue(propertyAccessExpression) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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];
|
|
632
711
|
}
|
|
633
|
-
const fieldRefPositions = [Position_1.FullPosition.buildFromNode(propertyAccessExpression, this.sourceFile), ...basePositions];
|
|
634
712
|
// this if for the case: const obj: Object = Object.create(Object.prototype);
|
|
635
|
-
if (
|
|
636
|
-
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.
|
|
637
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);
|
|
638
718
|
const fieldRef = new Ref_1.ArkStaticFieldRef(fieldSignature);
|
|
639
|
-
return {
|
|
640
|
-
value: fieldRef,
|
|
641
|
-
valueOriginalPositions: fieldRefPositions,
|
|
642
|
-
stmts: stmts,
|
|
643
|
-
};
|
|
719
|
+
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
644
720
|
}
|
|
645
721
|
let fieldSignature;
|
|
646
|
-
if (
|
|
647
|
-
|
|
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());
|
|
648
737
|
}
|
|
649
738
|
else {
|
|
650
739
|
fieldSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildFieldSignatureFromFieldName((0, StringUtils_1.cloneText)(propertyAccessExpression.name.getText(this.sourceFile)));
|
|
651
740
|
}
|
|
652
|
-
const fieldRef = new Ref_1.ArkInstanceFieldRef(
|
|
653
|
-
return {
|
|
654
|
-
value: fieldRef,
|
|
655
|
-
valueOriginalPositions: fieldRefPositions,
|
|
656
|
-
stmts: stmts,
|
|
657
|
-
};
|
|
741
|
+
const fieldRef = new Ref_1.ArkInstanceFieldRef(value, fieldSignature);
|
|
742
|
+
return { value: fieldRef, valueOriginalPositions: fieldRefPositions, stmts: stmts };
|
|
658
743
|
}
|
|
659
744
|
elementAccessExpressionToValueAndStmts(elementAccessExpression) {
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
745
|
+
const baseResult = this.tsNodeToValueAndStmts(elementAccessExpression.expression);
|
|
746
|
+
const stmts = baseResult.stmts;
|
|
747
|
+
let baseValue = baseResult.value;
|
|
748
|
+
let basePositions = baseResult.valueOriginalPositions;
|
|
663
749
|
if (!(baseValue instanceof Local_1.Local)) {
|
|
664
|
-
(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
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;
|
|
673
760
|
if (IRUtils_1.IRUtils.moreThanOneAddress(argumentValue)) {
|
|
674
|
-
(
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
stmts: argumentStmts,
|
|
678
|
-
} = this.arkIRTransformer.generateAssignStmtForValue(argumentValue, arguPositions));
|
|
679
|
-
argumentStmts.forEach(stmt => stmts.push(stmt));
|
|
761
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(argumentValue, arguPositions, stmts);
|
|
762
|
+
argumentValue = temp.value;
|
|
763
|
+
arguPositions = temp.positions;
|
|
680
764
|
}
|
|
681
765
|
let elementAccessExpr;
|
|
682
766
|
const baseType = baseValue.getType();
|
|
@@ -689,7 +773,15 @@ class ArkValueTransformer {
|
|
|
689
773
|
elementAccessExpr = new Ref_1.ArkInstanceFieldRef(baseValue, fieldSignature, true);
|
|
690
774
|
}
|
|
691
775
|
// reserve positions for field name
|
|
692
|
-
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
|
+
}
|
|
693
785
|
return {
|
|
694
786
|
value: elementAccessExpr,
|
|
695
787
|
valueOriginalPositions: exprPositions,
|
|
@@ -702,52 +794,169 @@ class ArkValueTransformer {
|
|
|
702
794
|
return this.generateInvokeValueAndStmts(callExpression.expression, argus, stmts, callExpression);
|
|
703
795
|
}
|
|
704
796
|
generateInvokeValueAndStmts(functionNameNode, args, currStmts, callExpression) {
|
|
705
|
-
const stmts =
|
|
706
|
-
const { value: calleeValue, valueOriginalPositions: calleePositions, stmts: calleeStmts } = this.tsNodeToValueAndStmts(functionNameNode);
|
|
707
|
-
stmts.push(...calleeStmts);
|
|
797
|
+
const stmts = currStmts;
|
|
708
798
|
const invokeExprPosition = Position_1.FullPosition.buildFromNode(callExpression, this.sourceFile);
|
|
709
|
-
|
|
710
|
-
|
|
799
|
+
let result;
|
|
800
|
+
let calleeNode = functionNameNode;
|
|
801
|
+
while (ts.isParenthesizedExpression(calleeNode)) {
|
|
802
|
+
calleeNode = calleeNode.expression;
|
|
711
803
|
}
|
|
712
|
-
if (
|
|
713
|
-
|
|
804
|
+
if (ts.isPropertyAccessExpression(calleeNode)) {
|
|
805
|
+
result = this.propertyAccessCalleeToInvoke(calleeNode, args, invokeExprPosition, stmts);
|
|
714
806
|
}
|
|
715
|
-
if (
|
|
716
|
-
|
|
807
|
+
else if (ts.isElementAccessExpression(calleeNode)) {
|
|
808
|
+
result = this.elementAccessCalleeToInvoke(calleeNode, args, invokeExprPosition, stmts);
|
|
717
809
|
}
|
|
718
|
-
|
|
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;
|
|
826
|
+
}
|
|
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());
|
|
719
832
|
}
|
|
720
|
-
|
|
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));
|
|
721
866
|
let methodSignature;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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;
|
|
726
877
|
}
|
|
727
878
|
else {
|
|
728
|
-
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
|
+
}
|
|
729
895
|
}
|
|
730
|
-
let
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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];
|
|
736
938
|
}
|
|
737
939
|
else {
|
|
738
|
-
|
|
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
|
+
}
|
|
739
950
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
};
|
|
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 };
|
|
746
956
|
}
|
|
747
957
|
handleLocalInvoke(calleeValue, callExpression, args, invokeExprPosition, calleePositions, currStmts) {
|
|
748
958
|
var _a;
|
|
749
959
|
let invokeExpr;
|
|
750
|
-
const invokeExprPositions = [invokeExprPosition];
|
|
751
960
|
const calleeName = calleeValue.getName();
|
|
752
961
|
if (this.isCustomViewCall(calleeName, callExpression)) {
|
|
753
962
|
return this.generateCustomViewStmt(calleeName, args.argValues, args.argPositions, callExpression, currStmts);
|
|
@@ -755,16 +964,25 @@ class ArkValueTransformer {
|
|
|
755
964
|
else if (this.isSystemComponentCall(calleeName, callExpression)) {
|
|
756
965
|
return this.generateSystemComponentStmt(calleeName, args.argValues, args.argPositions, callExpression, currStmts);
|
|
757
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;
|
|
758
972
|
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(calleeName);
|
|
759
|
-
if (
|
|
973
|
+
if (isPtrInvoke) {
|
|
760
974
|
// the call to the left value or a value of function type should be ptr invoke expr.
|
|
761
975
|
invokeExpr = new Expr_1.ArkPtrInvokeExpr(methodSignature, calleeValue, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
762
|
-
|
|
976
|
+
for (let i = 1; i < calleePositions.length; i++) {
|
|
977
|
+
invokeExprPositions[writeIdx++] = calleePositions[i];
|
|
978
|
+
}
|
|
763
979
|
}
|
|
764
980
|
else {
|
|
765
981
|
invokeExpr = new Expr_1.ArkStaticInvokeExpr(methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
766
982
|
}
|
|
767
|
-
|
|
983
|
+
for (let i = 0; i < argPositions.length; i++) {
|
|
984
|
+
invokeExprPositions[writeIdx++] = argPositions[i];
|
|
985
|
+
}
|
|
768
986
|
return {
|
|
769
987
|
value: invokeExpr,
|
|
770
988
|
valueOriginalPositions: invokeExprPositions,
|
|
@@ -776,34 +994,25 @@ class ArkValueTransformer {
|
|
|
776
994
|
if (!ts.isCallExpression(callExpression)) {
|
|
777
995
|
return false;
|
|
778
996
|
}
|
|
779
|
-
const classSignature =
|
|
997
|
+
const classSignature = new ArkSignature_1.ClassSignature(callerName, this.declaringFile.getFileSigID());
|
|
780
998
|
const cls = ModelUtils_1.ModelUtils.getClass(this.declaringMethod, classSignature);
|
|
781
999
|
return (_a = cls === null || cls === void 0 ? void 0 : cls.hasComponentDecorator()) !== null && _a !== void 0 ? _a : false;
|
|
782
1000
|
}
|
|
783
1001
|
isSystemComponentCall(calleeName, callExpression) {
|
|
784
|
-
return (calleeName === EtsConst_1.COMPONENT_FOR_EACH || calleeName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) &&
|
|
785
|
-
ts.isCallExpression(callExpression);
|
|
786
|
-
}
|
|
787
|
-
handleArrayRefInvoke(calleeValue, functionNameNode, args, invokeExprPosition, calleePositions, currStmts) {
|
|
788
|
-
const stmts = [...currStmts];
|
|
789
|
-
const methodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName((0, StringUtils_1.cloneText)(functionNameNode.argumentExpression.getText()));
|
|
790
|
-
stmts.pop();
|
|
791
|
-
const invokeExpr = new Expr_1.ArkInstanceInvokeExpr(calleeValue.getBase(), methodSignature, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
792
|
-
const invokeExprPositions = [invokeExprPosition, calleePositions.slice(1)[0],
|
|
793
|
-
...args.argPositions];
|
|
794
|
-
return {
|
|
795
|
-
value: invokeExpr,
|
|
796
|
-
valueOriginalPositions: invokeExprPositions,
|
|
797
|
-
stmts: stmts,
|
|
798
|
-
};
|
|
1002
|
+
return (calleeName === EtsConst_1.COMPONENT_FOR_EACH || calleeName === EtsConst_1.COMPONENT_LAZY_FOR_EACH) && ts.isCallExpression(callExpression);
|
|
799
1003
|
}
|
|
800
1004
|
handleDefaultInvoke(calleeValue, args, invokeExprPosition, calleePositions, currStmts) {
|
|
801
|
-
const stmts =
|
|
802
|
-
const
|
|
803
|
-
|
|
1005
|
+
const stmts = currStmts;
|
|
1006
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(calleeValue, calleePositions, stmts);
|
|
1007
|
+
const newCalleeValue = temp.value;
|
|
804
1008
|
const invokeExpr = new Expr_1.ArkPtrInvokeExpr(ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromMethodName(newCalleeValue.getName()), newCalleeValue, args.argValues, args.realGenericTypes, args.spreadFlags);
|
|
805
|
-
const
|
|
806
|
-
|
|
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
|
+
}
|
|
807
1016
|
return {
|
|
808
1017
|
value: invokeExpr,
|
|
809
1018
|
valueOriginalPositions: invokeExprPositions,
|
|
@@ -825,16 +1034,17 @@ class ArkValueTransformer {
|
|
|
825
1034
|
builderMethodIndexes = new Set([1]);
|
|
826
1035
|
}
|
|
827
1036
|
}
|
|
828
|
-
const { argValues, argPositions, spreadFlags
|
|
1037
|
+
const { argValues, argPositions, spreadFlags } = this.parseArguments(currStmts, callExpression.arguments, builderMethodIndexes);
|
|
829
1038
|
return { realGenericTypes, argValues, argPositions, spreadFlags };
|
|
830
1039
|
}
|
|
831
1040
|
parseArguments(currStmts, argumentNodes, builderMethodIndexes) {
|
|
832
|
-
const
|
|
833
|
-
const
|
|
1041
|
+
const argCount = argumentNodes ? argumentNodes.length : 0;
|
|
1042
|
+
const argValues = argCount === 0 ? [] : new Array(argCount);
|
|
1043
|
+
const argPositions = argCount === 0 ? [] : new Array(argCount);
|
|
834
1044
|
let spreadFlags = [];
|
|
835
1045
|
if (argumentNodes) {
|
|
836
|
-
spreadFlags = new Array(
|
|
837
|
-
for (let i = 0; i <
|
|
1046
|
+
spreadFlags = new Array(argCount).fill(false);
|
|
1047
|
+
for (let i = 0; i < argCount; i++) {
|
|
838
1048
|
spreadFlags[i] = ts.isSpreadElement(argumentNodes[i]);
|
|
839
1049
|
const argument = argumentNodes[i];
|
|
840
1050
|
const prevBuilderMethodContextFlag = this.builderMethodContextFlag;
|
|
@@ -842,27 +1052,28 @@ class ArkValueTransformer {
|
|
|
842
1052
|
this.builderMethodContextFlag = true;
|
|
843
1053
|
this.arkIRTransformer.setBuilderMethodContextFlag(true);
|
|
844
1054
|
}
|
|
845
|
-
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts
|
|
1055
|
+
let { value: argValue, valueOriginalPositions: argPositionsSingle, stmts: argStmts } = this.tsNodeToSingleAddressValueAndStmts(argument);
|
|
846
1056
|
this.builderMethodContextFlag = prevBuilderMethodContextFlag;
|
|
847
1057
|
this.arkIRTransformer.setBuilderMethodContextFlag(prevBuilderMethodContextFlag);
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1058
|
+
for (let j = 0; j < argStmts.length; j++) {
|
|
1059
|
+
currStmts.push(argStmts[j]);
|
|
1060
|
+
}
|
|
1061
|
+
argValues[i] = argValue;
|
|
1062
|
+
argPositions[i] = argPositionsSingle[0];
|
|
851
1063
|
}
|
|
852
1064
|
}
|
|
853
1065
|
return {
|
|
854
1066
|
argValues,
|
|
855
1067
|
argPositions,
|
|
856
|
-
spreadFlags: spreadFlags.every(
|
|
1068
|
+
spreadFlags: spreadFlags.every(f => f === false) ? undefined : spreadFlags,
|
|
857
1069
|
};
|
|
858
1070
|
}
|
|
859
1071
|
callableNodeToValueAndStmts(callableNode) {
|
|
860
|
-
const
|
|
861
|
-
const arrowArkMethod = new ArkMethod_1.ArkMethod();
|
|
1072
|
+
const arrowArkMethod = new ArkMethod_1.ArkMethod(this.declaringClass.getClassSigID());
|
|
862
1073
|
if (this.builderMethodContextFlag) {
|
|
863
1074
|
ModelUtils_1.ModelUtils.implicitArkUIBuilderMethods.add(arrowArkMethod);
|
|
864
1075
|
}
|
|
865
|
-
(0,
|
|
1076
|
+
(0, ArkMethodBuilder_2.buildArkMethodFromArkClass)(callableNode, this.declaringClass, arrowArkMethod, this.sourceFile, this.declaringMethod);
|
|
866
1077
|
const callableType = new Type_1.FunctionType(arrowArkMethod.getSignature());
|
|
867
1078
|
const callableValue = this.addNewLocal(arrowArkMethod.getName(), callableType);
|
|
868
1079
|
return {
|
|
@@ -900,6 +1111,8 @@ class ArkValueTransformer {
|
|
|
900
1111
|
const { value: newLocal, valueOriginalPositions: newLocalPositions, stmts: newExprStmts, } = this.arkIRTransformer.generateAssignStmtForValue(newExpr, [Position_1.FullPosition.buildFromNode(newExpression, this.sourceFile)]);
|
|
901
1112
|
newExprStmts.forEach(stmt => stmts.push(stmt));
|
|
902
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.
|
|
903
1116
|
const constructorMethodSignature = new ArkSignature_1.MethodSignature(classSignature, constructorMethodSubSignature);
|
|
904
1117
|
const { argValues: argValues, argPositions: argPositions, } = this.parseArguments(stmts, newExpression.arguments);
|
|
905
1118
|
const instanceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(newLocal, constructorMethodSignature, argValues);
|
|
@@ -953,7 +1166,7 @@ class ArkValueTransformer {
|
|
|
953
1166
|
if (ts.isSpreadElement(arrayLiteralExpression.elements[i]) && firstSpreadIdx === -1) {
|
|
954
1167
|
firstSpreadIdx = i;
|
|
955
1168
|
}
|
|
956
|
-
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]);
|
|
957
1170
|
elementStmts.forEach(stmt => stmts.push(stmt));
|
|
958
1171
|
elementValues.push(elementValue);
|
|
959
1172
|
elementTypes.push(elementValue.getType());
|
|
@@ -964,7 +1177,7 @@ class ArkValueTransformer {
|
|
|
964
1177
|
return this.generateArrayExprFromLiteral(elementValues, elementTypes, elementPositions, wholePosition, 0, arrayLength, stmts);
|
|
965
1178
|
}
|
|
966
1179
|
else if (firstSpreadIdx === 0) {
|
|
967
|
-
const scene = this.
|
|
1180
|
+
const scene = this.declaringFile.getScene();
|
|
968
1181
|
if (arrayLength === 1) { // only spread element
|
|
969
1182
|
const sliceMethodSignature = Builtin_1.Builtin.buildArrayMethodSignature(Builtin_1.Builtin.SLICE, scene);
|
|
970
1183
|
const sliceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(elementValues[0], sliceMethodSignature, []);
|
|
@@ -980,7 +1193,7 @@ class ArkValueTransformer {
|
|
|
980
1193
|
}
|
|
981
1194
|
else { // contains spread elements and begins with literal elements.
|
|
982
1195
|
const beginLiteralValueAndStmts = this.generateArrayExprFromLiteral(elementValues, elementTypes, elementPositions, wholePosition, 0, firstSpreadIdx, stmts);
|
|
983
|
-
const scene = this.
|
|
1196
|
+
const scene = this.declaringFile.getScene();
|
|
984
1197
|
const concatMethodSignature = Builtin_1.Builtin.buildArrayMethodSignature(Builtin_1.Builtin.CONCAT, scene);
|
|
985
1198
|
const concatInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(beginLiteralValueAndStmts.value, concatMethodSignature, elementValues.slice(firstSpreadIdx));
|
|
986
1199
|
const concatInvokeExprPositions = [wholePosition, beginLiteralValueAndStmts.valueOriginalPositions[0],
|
|
@@ -997,8 +1210,7 @@ class ArkValueTransformer {
|
|
|
997
1210
|
else if (elementTypesSet.size > 1) {
|
|
998
1211
|
baseType = new Type_1.UnionType(Array.from(elementTypesSet));
|
|
999
1212
|
}
|
|
1000
|
-
const newArrayExprPosition =
|
|
1001
|
-
? 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]);
|
|
1002
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);
|
|
1003
1215
|
}
|
|
1004
1216
|
generateArrayExprAndStmts(baseType, arrayLengthValue, arrayLengthPosition, arrayLength, initializerValues, initializerPositions, currStmts, newArrayExprPosition, fromLiteral) {
|
|
@@ -1146,7 +1358,7 @@ class ArkValueTransformer {
|
|
|
1146
1358
|
}
|
|
1147
1359
|
awaitExpressionToValueAndStmts(awaitExpression) {
|
|
1148
1360
|
const stmts = [];
|
|
1149
|
-
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts
|
|
1361
|
+
let { value: promiseValue, valueOriginalPositions: promisePositions, stmts: promiseStmts } = this.tsNodeToValueAndStmts(awaitExpression.expression);
|
|
1150
1362
|
promiseStmts.forEach(stmt => stmts.push(stmt));
|
|
1151
1363
|
if (IRUtils_1.IRUtils.moreThanOneAddress(promiseValue)) {
|
|
1152
1364
|
({
|
|
@@ -1169,11 +1381,7 @@ class ArkValueTransformer {
|
|
|
1169
1381
|
let yieldPositions = [Position_1.FullPosition.DEFAULT];
|
|
1170
1382
|
let stmts = [];
|
|
1171
1383
|
if (yieldExpression.expression) {
|
|
1172
|
-
({
|
|
1173
|
-
value: yieldValue,
|
|
1174
|
-
valueOriginalPositions: yieldPositions,
|
|
1175
|
-
stmts: stmts,
|
|
1176
|
-
} = this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
1384
|
+
({ value: yieldValue, valueOriginalPositions: yieldPositions, stmts: stmts } = this.tsNodeToValueAndStmts(yieldExpression.expression));
|
|
1177
1385
|
}
|
|
1178
1386
|
const yieldExpr = new Expr_1.ArkYieldExpr(yieldValue);
|
|
1179
1387
|
const yieldExprPositions = [Position_1.FullPosition.buildFromNode(yieldExpression, this.sourceFile), ...yieldPositions];
|
|
@@ -1184,7 +1392,7 @@ class ArkValueTransformer {
|
|
|
1184
1392
|
};
|
|
1185
1393
|
}
|
|
1186
1394
|
deleteExpressionToValueAndStmts(deleteExpression) {
|
|
1187
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts
|
|
1395
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(deleteExpression.expression);
|
|
1188
1396
|
const deleteExpr = new Expr_1.ArkDeleteExpr(exprValue);
|
|
1189
1397
|
const deleteExprPositions = [Position_1.FullPosition.buildFromNode(deleteExpression, this.sourceFile), ...exprPositions];
|
|
1190
1398
|
return {
|
|
@@ -1194,7 +1402,7 @@ class ArkValueTransformer {
|
|
|
1194
1402
|
};
|
|
1195
1403
|
}
|
|
1196
1404
|
voidExpressionToValueAndStmts(voidExpression) {
|
|
1197
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts
|
|
1405
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts } = this.tsNodeToValueAndStmts(voidExpression.expression);
|
|
1198
1406
|
const { stmts: exprStmts } = this.arkIRTransformer.generateAssignStmtForValue(exprValue, exprPositions);
|
|
1199
1407
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
1200
1408
|
return {
|
|
@@ -1210,7 +1418,7 @@ class ArkValueTransformer {
|
|
|
1210
1418
|
return this.tsNodeToValueAndStmts(parenthesizedExpression.expression);
|
|
1211
1419
|
}
|
|
1212
1420
|
typeOfExpressionToValueAndStmts(typeOfExpression) {
|
|
1213
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1421
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(typeOfExpression.expression);
|
|
1214
1422
|
const typeOfExpr = new Expr_1.ArkTypeOfExpr(exprValue);
|
|
1215
1423
|
const typeOfExprPositions = [Position_1.FullPosition.buildFromNode(typeOfExpression, this.sourceFile), ...exprPositions];
|
|
1216
1424
|
return {
|
|
@@ -1221,7 +1429,7 @@ class ArkValueTransformer {
|
|
|
1221
1429
|
}
|
|
1222
1430
|
asExpressionToValueAndStmts(asExpression) {
|
|
1223
1431
|
const stmts = [];
|
|
1224
|
-
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1432
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(asExpression.expression);
|
|
1225
1433
|
exprStmts.forEach(stmt => stmts.push(stmt));
|
|
1226
1434
|
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
1227
1435
|
({
|
|
@@ -1240,7 +1448,7 @@ class ArkValueTransformer {
|
|
|
1240
1448
|
};
|
|
1241
1449
|
}
|
|
1242
1450
|
typeAssertionToValueAndStmts(typeAssertion) {
|
|
1243
|
-
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts
|
|
1451
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts } = this.tsNodeToValueAndStmts(typeAssertion.expression);
|
|
1244
1452
|
const castExpr = new Expr_1.ArkCastExpr(exprValue, this.resolveTypeNode(typeAssertion.type));
|
|
1245
1453
|
const castExprPositions = [Position_1.FullPosition.buildFromNode(typeAssertion, this.sourceFile), ...exprPositions];
|
|
1246
1454
|
return {
|
|
@@ -1269,82 +1477,76 @@ class ArkValueTransformer {
|
|
|
1269
1477
|
return this.assignmentToValueAndStmts(leftOpNode, rightOpNode, true, isConst, declarationType, needRightOp);
|
|
1270
1478
|
}
|
|
1271
1479
|
assignmentToValueAndStmts(leftOpNode, rightOpNode, variableDefFlag, isConst, declarationType, needRightOp = true) {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
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
|
+
}
|
|
1275
1507
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
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];
|
|
1279
1513
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1514
|
+
const rightPositions = rightResult.valueOriginalPositions;
|
|
1515
|
+
for (let i = 0; i < rightPositions.length; i++) {
|
|
1516
|
+
operandPositions[leftPositions.length + i] = rightPositions[i];
|
|
1283
1517
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1518
|
+
assignStmt.setOperandOriginalPositions(operandPositions);
|
|
1519
|
+
const destructuring = isArrayDestructuring || isObjectDestructuring;
|
|
1520
|
+
if (destructuring) {
|
|
1521
|
+
rightResult.stmts.push(assignStmt);
|
|
1286
1522
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
if (needRightOp) {
|
|
1290
|
-
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.assignmentRightOpToValueAndStmts(rightOpNode, leftValue);
|
|
1291
|
-
if (leftValue instanceof Local_1.Local) {
|
|
1292
|
-
if (variableDefFlag) {
|
|
1293
|
-
leftValue.setConstFlag(isConst);
|
|
1294
|
-
leftValue.setType(declarationType);
|
|
1295
|
-
}
|
|
1296
|
-
if (leftValue.getType() instanceof Type_1.UnknownType && !(rightValue.getType() instanceof Type_1.UnknownType) &&
|
|
1297
|
-
!(rightValue.getType() instanceof Type_1.UndefinedType)) {
|
|
1298
|
-
leftValue.setType(rightValue.getType());
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(leftValue, rightValue);
|
|
1302
|
-
assignStmt.setOperandOriginalPositions([...leftPositions, ...rightPositions]);
|
|
1303
|
-
if (ts.isArrayBindingPattern(leftOpNode) || ts.isArrayLiteralExpression(leftOpNode) ||
|
|
1304
|
-
ts.isObjectBindingPattern(leftOpNode) || ts.isObjectLiteralExpression(leftOpNode)) {
|
|
1305
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1306
|
-
stmts.push(assignStmt);
|
|
1307
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1308
|
-
}
|
|
1309
|
-
else {
|
|
1310
|
-
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1311
|
-
leftStmts.forEach(stmt => stmts.push(stmt));
|
|
1312
|
-
stmts.push(assignStmt);
|
|
1313
|
-
}
|
|
1523
|
+
for (let i = 0; i < leftResult.stmts.length; i++) {
|
|
1524
|
+
rightResult.stmts.push(leftResult.stmts[i]);
|
|
1314
1525
|
}
|
|
1315
|
-
|
|
1316
|
-
stmts
|
|
1526
|
+
if (!destructuring) {
|
|
1527
|
+
rightResult.stmts.push(assignStmt);
|
|
1317
1528
|
}
|
|
1318
|
-
return {
|
|
1319
|
-
value: leftValue,
|
|
1320
|
-
valueOriginalPositions: leftPositions,
|
|
1321
|
-
stmts: stmts,
|
|
1322
|
-
};
|
|
1529
|
+
return { value: leftResult.value, valueOriginalPositions: leftResult.valueOriginalPositions, stmts: rightResult.stmts };
|
|
1323
1530
|
}
|
|
1324
1531
|
assignmentRightOpToValueAndStmts(rightOpNode, leftValue) {
|
|
1325
1532
|
let rightValue;
|
|
1326
1533
|
let rightPositions;
|
|
1327
|
-
let
|
|
1328
|
-
const rightStmts = [];
|
|
1534
|
+
let rightStmts;
|
|
1329
1535
|
if (rightOpNode) {
|
|
1330
|
-
(
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
} = this.tsNodeToValueAndStmts(rightOpNode));
|
|
1335
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
1536
|
+
const rightResult = this.tsNodeToValueAndStmts(rightOpNode);
|
|
1537
|
+
rightValue = rightResult.value;
|
|
1538
|
+
rightPositions = rightResult.valueOriginalPositions;
|
|
1539
|
+
rightStmts = rightResult.stmts;
|
|
1336
1540
|
}
|
|
1337
1541
|
else {
|
|
1338
1542
|
rightValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1339
1543
|
rightPositions = [Position_1.FullPosition.DEFAULT];
|
|
1544
|
+
rightStmts = [];
|
|
1340
1545
|
}
|
|
1341
1546
|
if (IRUtils_1.IRUtils.moreThanOneAddress(leftValue) && IRUtils_1.IRUtils.moreThanOneAddress(rightValue)) {
|
|
1342
|
-
(
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
stmts: tempRightStmts,
|
|
1346
|
-
} = this.arkIRTransformer.generateAssignStmtForValue(rightValue, rightPositions));
|
|
1347
|
-
tempRightStmts.forEach(stmt => rightStmts.push(stmt));
|
|
1547
|
+
const temp = this.arkIRTransformer.generateAssignStmtForValueInto(rightValue, rightPositions, rightStmts);
|
|
1548
|
+
rightValue = temp.value;
|
|
1549
|
+
rightPositions = temp.positions;
|
|
1348
1550
|
}
|
|
1349
1551
|
return {
|
|
1350
1552
|
value: rightValue,
|
|
@@ -1376,8 +1578,7 @@ class ArkValueTransformer {
|
|
|
1376
1578
|
const elementName = (0, StringUtils_1.cloneText)(nodeInsideRest.getText(this.sourceFile));
|
|
1377
1579
|
targetLocal = ts.isBindingElement(element) ? this.addNewLocal(elementName) : this.getOrCreateLocal(elementName);
|
|
1378
1580
|
}
|
|
1379
|
-
const
|
|
1380
|
-
const sliceMethodSignature = new ArkSignature_1.MethodSignature(Builtin_1.Builtin.ARRAY_CLASS_SIGNATURE, sliceMethodSubSignature);
|
|
1581
|
+
const sliceMethodSignature = Builtin_1.Builtin.getOrCreateArrayStubMethodSignature(Builtin_1.Builtin.SLICE);
|
|
1381
1582
|
const sliceInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(arrayTempLocal, sliceMethodSignature, [ValueUtil_1.ValueUtil.getOrCreateNumberConst(i)]);
|
|
1382
1583
|
const sliceInvokeExprPositions = [wholePosition, targetLocalPosition];
|
|
1383
1584
|
const assignStmt = new Stmt_1.ArkAssignStmt(targetLocal, sliceInvokeExpr);
|
|
@@ -1452,47 +1653,39 @@ class ArkValueTransformer {
|
|
|
1452
1653
|
}
|
|
1453
1654
|
const stmts = [];
|
|
1454
1655
|
const binaryExpressionPosition = Position_1.FullPosition.buildFromNode(binaryExpression, this.sourceFile);
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1656
|
+
const leftResult = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.left);
|
|
1657
|
+
leftResult.stmts.forEach(stmt => stmts.push(stmt));
|
|
1457
1658
|
if (operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword) {
|
|
1458
|
-
const
|
|
1459
|
-
const
|
|
1460
|
-
const
|
|
1461
|
-
|
|
1462
|
-
return {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
|
-
const { value: opValue2, valueOriginalPositions: opPositions2, stmts: opStmts2, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1469
|
-
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));
|
|
1470
1667
|
let exprValue;
|
|
1471
1668
|
let exprValuePositions = [binaryExpressionPosition];
|
|
1472
1669
|
if (operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
1473
|
-
exprValue =
|
|
1670
|
+
exprValue = rightResult.value;
|
|
1474
1671
|
}
|
|
1475
1672
|
else {
|
|
1476
1673
|
const operator = ArkIRTransformer_1.ArkIRTransformer.tokenToBinaryOperator(operatorToken.kind);
|
|
1477
1674
|
if (operator) {
|
|
1478
1675
|
if (this.isRelationalOperator(operator)) {
|
|
1479
|
-
exprValue = new Expr_1.ArkConditionExpr(
|
|
1676
|
+
exprValue = new Expr_1.ArkConditionExpr(leftResult.value, rightResult.value, operator);
|
|
1480
1677
|
}
|
|
1481
1678
|
else {
|
|
1482
|
-
exprValue = new Expr_1.ArkNormalBinopExpr(
|
|
1679
|
+
exprValue = new Expr_1.ArkNormalBinopExpr(leftResult.value, rightResult.value, operator);
|
|
1483
1680
|
}
|
|
1484
|
-
exprValuePositions.push(...
|
|
1681
|
+
exprValuePositions.push(...leftResult.valueOriginalPositions, ...rightResult.valueOriginalPositions);
|
|
1485
1682
|
}
|
|
1486
1683
|
else {
|
|
1487
1684
|
exprValue = ValueUtil_1.ValueUtil.getUndefinedConst();
|
|
1488
1685
|
exprValuePositions.push(binaryExpressionPosition);
|
|
1489
1686
|
}
|
|
1490
1687
|
}
|
|
1491
|
-
return {
|
|
1492
|
-
value: exprValue,
|
|
1493
|
-
valueOriginalPositions: exprValuePositions,
|
|
1494
|
-
stmts: stmts,
|
|
1495
|
-
};
|
|
1688
|
+
return { value: exprValue, valueOriginalPositions: exprValuePositions, stmts: stmts };
|
|
1496
1689
|
}
|
|
1497
1690
|
compoundAssignmentToValueAndStmts(binaryExpression) {
|
|
1498
1691
|
const stmts = [];
|
|
@@ -1511,7 +1704,7 @@ class ArkValueTransformer {
|
|
|
1511
1704
|
leftValue = leftValueOrig;
|
|
1512
1705
|
leftPositions = leftPositionsOrig;
|
|
1513
1706
|
}
|
|
1514
|
-
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1707
|
+
const { value: rightValue, valueOriginalPositions: rightPositions, stmts: rightStmts, } = this.tsNodeToSingleAddressValueAndStmts(binaryExpression.right);
|
|
1515
1708
|
rightStmts.forEach(stmt => stmts.push(stmt));
|
|
1516
1709
|
const operator = this.compoundAssignmentTokenToBinaryOperator(binaryExpression.operatorToken.kind);
|
|
1517
1710
|
if (operator) {
|
|
@@ -1523,14 +1716,14 @@ class ArkValueTransformer {
|
|
|
1523
1716
|
...(assignTarget === leftValueOrig ? leftPositionsOrig : leftPositions),
|
|
1524
1717
|
exprValuePosition,
|
|
1525
1718
|
...leftPositions,
|
|
1526
|
-
...rightPositions
|
|
1719
|
+
...rightPositions,
|
|
1527
1720
|
]);
|
|
1528
1721
|
stmts.push(assignStmt);
|
|
1529
1722
|
}
|
|
1530
1723
|
return {
|
|
1531
1724
|
value: leftValueOrig,
|
|
1532
1725
|
valueOriginalPositions: leftPositionsOrig,
|
|
1533
|
-
stmts: stmts
|
|
1726
|
+
stmts: stmts,
|
|
1534
1727
|
};
|
|
1535
1728
|
}
|
|
1536
1729
|
compoundAssignmentTokenToBinaryOperator(token) {
|
|
@@ -1571,7 +1764,7 @@ class ArkValueTransformer {
|
|
|
1571
1764
|
}
|
|
1572
1765
|
conditionToValueAndStmts(condition) {
|
|
1573
1766
|
const stmts = [];
|
|
1574
|
-
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts
|
|
1767
|
+
let { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts } = this.tsNodeToValueAndStmts(condition);
|
|
1575
1768
|
conditionStmts.forEach(stmt => stmts.push(stmt));
|
|
1576
1769
|
let conditionExpr;
|
|
1577
1770
|
if (conditionValue instanceof Expr_1.AbstractBinopExpr && this.isRelationalOperator(conditionValue.getOperator())) {
|
|
@@ -1754,8 +1947,8 @@ class ArkValueTransformer {
|
|
|
1754
1947
|
if (ts.isQualifiedName(exprNameNode)) {
|
|
1755
1948
|
if ((0, StringUtils_1.cloneText)(exprNameNode.left.getText(this.sourceFile)) === TSConst_1.THIS_NAME) {
|
|
1756
1949
|
const fieldName = (0, StringUtils_1.cloneText)(exprNameNode.right.getText(this.sourceFile));
|
|
1757
|
-
const fieldSignature = (_b = (_a = this.
|
|
1758
|
-
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));
|
|
1759
1952
|
opValue = new Ref_1.ArkInstanceFieldRef(baseLocal, fieldSignature);
|
|
1760
1953
|
}
|
|
1761
1954
|
else {
|
|
@@ -1877,21 +2070,20 @@ class ArkValueTransformer {
|
|
|
1877
2070
|
}
|
|
1878
2071
|
}
|
|
1879
2072
|
resolveTypeLiteralNode(typeLiteralNode) {
|
|
1880
|
-
const
|
|
1881
|
-
const
|
|
1882
|
-
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());
|
|
1883
2075
|
if (declaringNamespace) {
|
|
1884
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode,
|
|
2076
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkNamespace)(typeLiteralNode, anonymousClass, this.sourceFile);
|
|
2077
|
+
declaringNamespace.addArkClass(anonymousClass);
|
|
1885
2078
|
}
|
|
1886
2079
|
else {
|
|
1887
|
-
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode,
|
|
2080
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(typeLiteralNode, this.declaringFile, anonymousClass, this.sourceFile);
|
|
1888
2081
|
}
|
|
1889
2082
|
return new Type_1.ClassType(anonymousClass.getSignature());
|
|
1890
2083
|
}
|
|
1891
2084
|
resolveFunctionTypeNode(functionTypeNode) {
|
|
1892
|
-
const anonymousMethod = new ArkMethod_1.ArkMethod();
|
|
1893
|
-
|
|
1894
|
-
(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);
|
|
1895
2087
|
return new Type_1.FunctionType(anonymousMethod.getSignature());
|
|
1896
2088
|
}
|
|
1897
2089
|
static isCompoundAssignmentOperator(operator) {
|