arkanalyzer 1.0.85 → 1.0.87
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/README.en.md +69 -65
- package/README.md +56 -70
- package/config/arkanalyzer.json +7 -2
- package/docs/cppFrontend/ArkAnalyzer-cpp_usage_guide.md +245 -0
- package/docs/cppFrontend/cpp_frontend_build_guide.md +126 -0
- package/docs/cppFrontend/cpp_frontend_user_guide.md +175 -0
- package/docs/cppFrontend/img.png +0 -0
- package/docs/cppFrontend/img_1.png +0 -0
- package/docs/cppFrontend/img_10.png +0 -0
- package/docs/cppFrontend/img_11.png +0 -0
- package/docs/cppFrontend/img_12.png +0 -0
- package/docs/cppFrontend/img_13.png +0 -0
- package/docs/cppFrontend/img_14.png +0 -0
- package/docs/cppFrontend/img_15.png +0 -0
- package/docs/cppFrontend/img_16.png +0 -0
- package/docs/cppFrontend/img_17.png +0 -0
- package/docs/cppFrontend/img_18.png +0 -0
- package/docs/cppFrontend/img_19.png +0 -0
- package/docs/cppFrontend/img_2.png +0 -0
- package/docs/cppFrontend/img_20.png +0 -0
- package/docs/cppFrontend/img_21.png +0 -0
- package/docs/cppFrontend/img_22.png +0 -0
- package/docs/cppFrontend/img_23.png +0 -0
- package/docs/cppFrontend/img_3.png +0 -0
- package/docs/cppFrontend/img_4.png +0 -0
- package/docs/cppFrontend/img_5.png +0 -0
- package/docs/cppFrontend/img_6.png +0 -0
- package/docs/cppFrontend/img_7.png +0 -0
- package/docs/cppFrontend/img_8.png +0 -0
- package/docs/cppFrontend/img_9.png +0 -0
- package/docs/sig_programanalysis.en.md +66 -0
- package/docs/sig_programanalysis.md +73 -0
- package/lib/Config.d.ts +32 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +76 -2
- package/lib/Scene.d.ts +25 -2
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +148 -40
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +4 -3
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.js +17 -17
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +6 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +117 -14
- package/lib/callgraph/common/Statistics.d.ts +4 -2
- package/lib/callgraph/common/Statistics.d.ts.map +1 -1
- package/lib/callgraph/common/Statistics.js +14 -2
- package/lib/callgraph/model/CallGraph.d.ts +12 -8
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
- package/lib/callgraph/model/CallGraph.js +53 -29
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +1 -0
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -1
- package/lib/callgraph/model/builder/CallGraphBuilder.js +5 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +3 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +4 -2
- package/lib/cli/cli.d.ts +3 -0
- package/lib/cli/cli.d.ts.map +1 -0
- package/lib/cli/cli.js +82 -0
- package/lib/cli/commands/cg.d.ts +32 -0
- package/lib/cli/commands/cg.d.ts.map +1 -0
- package/lib/cli/commands/cg.js +401 -0
- package/lib/cli/commands/index.d.ts +6 -0
- package/lib/cli/commands/index.d.ts.map +1 -0
- package/lib/cli/commands/index.js +64 -0
- package/lib/cli/commands/ir.d.ts +26 -0
- package/lib/cli/commands/ir.d.ts.map +1 -0
- package/lib/cli/commands/ir.js +94 -0
- package/lib/core/base/Constant.d.ts +1 -1
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +1 -1
- package/lib/core/base/Expr.d.ts +29 -5
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +144 -22
- package/lib/core/base/Position.d.ts +14 -0
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +27 -0
- package/lib/core/base/Ref.d.ts +1 -0
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +4 -1
- package/lib/core/base/Type.d.ts +64 -24
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +144 -49
- package/lib/core/common/ArkError.d.ts +26 -2
- package/lib/core/common/ArkError.d.ts.map +1 -1
- package/lib/core/common/ArkError.js +56 -2
- package/lib/core/common/ArkIRTransformer.d.ts +11 -10
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +1 -1
- package/lib/core/common/ArkValueTransformer.d.ts +14 -12
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +1 -5
- package/lib/core/common/Const.d.ts +3 -0
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +4 -1
- package/lib/core/common/DummyMainCreater.d.ts +23 -13
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +66 -43
- package/lib/core/common/EtsConst.d.ts +11 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -1
- package/lib/core/common/EtsConst.js +12 -1
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +5 -1
- package/lib/core/common/ModelUtils.d.ts +4 -7
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +77 -110
- package/lib/core/common/SdkUtils.d.ts +1 -1
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +14 -5
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +9 -3
- package/lib/core/graph/BaseExplicitGraph.d.ts +4 -4
- package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
- package/lib/core/graph/BaseExplicitGraph.js +15 -8
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/Scc.d.ts.map +1 -1
- package/lib/core/graph/Scc.js +7 -2
- package/lib/core/graph/builder/CfgBuilder.d.ts +10 -7
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +12 -5
- package/lib/core/inference/Inference.d.ts.map +1 -1
- package/lib/core/inference/Inference.js +7 -0
- package/lib/core/inference/ModelInference.d.ts +1 -1
- package/lib/core/inference/ModelInference.d.ts.map +1 -1
- 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 +64 -12
- package/lib/core/inference/abc/AbcInference.d.ts +28 -2
- package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
- package/lib/core/inference/abc/AbcInference.js +105 -4
- package/lib/core/model/ArkBaseModel.d.ts +14 -1
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -1
- package/lib/core/model/ArkBaseModel.js +61 -2
- package/lib/core/model/ArkBody.d.ts.map +1 -1
- package/lib/core/model/ArkBody.js +1 -3
- package/lib/core/model/ArkClass.d.ts +22 -2
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +59 -28
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +3 -1
- package/lib/core/model/ArkFile.d.ts +4 -1
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +44 -3
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +9 -1
- package/lib/core/model/ArkMethod.d.ts +5 -0
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +33 -1
- package/lib/core/model/ArkNamespace.d.ts +2 -0
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +11 -0
- package/lib/core/model/ArkSignature.d.ts +3 -3
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +14 -9
- package/lib/core/model/builder/ArkClassBuilder.d.ts +2 -0
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +3 -3
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +4 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +19 -6
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +1 -0
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +2 -1
- package/lib/core/model/builder/BodyBuilder.d.ts +4 -0
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.d.ts +1 -0
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +7 -3
- package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.d.ts +296 -0
- package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/ArkCxxAstNode.js +145 -0
- package/lib/frontend/cppFrontend/ast/astUtils.d.ts +51 -0
- package/lib/frontend/cppFrontend/ast/astUtils.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/astUtils.js +470 -0
- package/lib/frontend/cppFrontend/ast/const.d.ts +30 -0
- package/lib/frontend/cppFrontend/ast/const.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/ast/const.js +134 -0
- package/lib/frontend/cppFrontend/base/Constant.d.ts +9 -0
- package/lib/frontend/cppFrontend/base/Constant.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/base/Constant.js +33 -0
- package/lib/frontend/cppFrontend/base/Expr.d.ts +174 -0
- package/lib/frontend/cppFrontend/base/Expr.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/base/Expr.js +530 -0
- package/lib/frontend/cppFrontend/base/Ref.d.ts +25 -0
- package/lib/frontend/cppFrontend/base/Ref.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/base/Ref.js +53 -0
- package/lib/frontend/cppFrontend/base/Trap.d.ts +8 -0
- package/lib/frontend/cppFrontend/base/Trap.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/base/Trap.js +28 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts +264 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/base/Type.js +600 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts +109 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +925 -0
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +477 -0
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +2746 -0
- package/lib/frontend/cppFrontend/common/Builtin.d.ts +57 -0
- package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/Builtin.js +106 -0
- package/lib/frontend/cppFrontend/common/IRInference.d.ts +94 -0
- package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/IRInference.js +1087 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +23 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/IRUtils.js +168 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +44 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.js +567 -0
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts +278 -0
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/TypeInference.js +1354 -0
- package/lib/frontend/cppFrontend/common/ValueUtil.d.ts +16 -0
- package/lib/frontend/cppFrontend/common/ValueUtil.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/common/ValueUtil.js +61 -0
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts +182 -0
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +1435 -0
- package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.d.ts +21 -0
- package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/ConditionBuilder.js +303 -0
- package/lib/frontend/cppFrontend/graph/builder/IfBuilder.d.ts +15 -0
- package/lib/frontend/cppFrontend/graph/builder/IfBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/IfBuilder.js +161 -0
- package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.d.ts +21 -0
- package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/LoopBuilder.js +261 -0
- package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.d.ts +12 -0
- package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/SwitchBuilder.js +155 -0
- package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.d.ts +29 -0
- package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/graph/builder/TrapBuilder.js +302 -0
- package/lib/frontend/cppFrontend/inference/CxxInference.d.ts +10 -0
- package/lib/frontend/cppFrontend/inference/CxxInference.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/inference/CxxInference.js +41 -0
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +28 -0
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/inference/CxxModelInference.js +98 -0
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts +20 -0
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/inference/CxxValueInference.js +128 -0
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts +11 -0
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +413 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts +5 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +61 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +17 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +285 -0
- package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts +6 -0
- package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkImportBuilder.js +57 -0
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts +14 -0
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +422 -0
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +8 -0
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +194 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +59 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +605 -0
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts +46 -0
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +499 -0
- package/lib/frontend/cppFrontend/utils/cmakeUtils.d.ts +44 -0
- package/lib/frontend/cppFrontend/utils/cmakeUtils.d.ts.map +1 -0
- package/lib/frontend/cppFrontend/utils/cmakeUtils.js +240 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -1
- package/lib/node_modules/ohos-typescript/.ohos-typescript-version +1 -0
- package/{node_modules → lib/node_modules}/ohos-typescript/package.json +2 -1
- package/lib/save/CGJsonPrinter.d.ts +8 -0
- package/lib/save/CGJsonPrinter.d.ts.map +1 -0
- package/lib/save/CGJsonPrinter.js +41 -0
- package/lib/save/GraphPrinter.js +2 -2
- package/lib/save/json/JsonDto.d.ts +86 -2
- package/lib/save/json/JsonDto.d.ts.map +1 -1
- package/lib/save/json/JsonSerialization.d.ts +1 -1
- package/lib/save/json/JsonSerialization.d.ts.map +1 -1
- package/lib/save/json/JsonSerialization.js +235 -145
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +0 -3
- package/lib/utils/CxxSceneUtils.d.ts +11 -0
- package/lib/utils/CxxSceneUtils.d.ts.map +1 -0
- package/lib/utils/CxxSceneUtils.js +178 -0
- package/lib/utils/FileUtils.d.ts +7 -8
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +27 -45
- package/lib/utils/LRUCacheDecorator.d.ts +20 -0
- package/lib/utils/LRUCacheDecorator.d.ts.map +1 -0
- package/lib/utils/LRUCacheDecorator.js +89 -0
- package/lib/utils/ModuleUtils.d.ts +39 -0
- package/lib/utils/ModuleUtils.d.ts.map +1 -0
- package/lib/utils/ModuleUtils.js +261 -0
- package/package.json +15 -12
- /package/{node_modules → lib/node_modules}/ohos-typescript/LICENSE +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/README.OpenSource +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/README.md +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/SECURITY.md +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/ThirdPartyNoticeText.txt +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/bin/tsc +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/bin/tsserver +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/README.md +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/cancellationToken.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/cs/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/de/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/es/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/fr/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/it/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ja/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ko/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.dom.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.dom.iterable.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.collection.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.core.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.generator.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.iterable.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.promise.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.proxy.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.reflect.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.symbol.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.array.include.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2016.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.object.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.sharedmemory.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.string.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2017.typedarrays.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.asynciterable.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.promise.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2018.regexp.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.array.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.object.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.string.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2019.symbol.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.bigint.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.date.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.number.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.promise.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.sharedmemory.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.string.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.promise.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.string.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2021.weakref.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.array.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.error.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.object.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.sharedmemory.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es2022.string.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es5.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.es6.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.full.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.esnext.intl.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.scripthost.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.importscripts.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/lib.webworker.iterable.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/pl/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/pt-br/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/ru/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tr/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsc.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserver.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserverlibrary.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/tsserverlibrary.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typesMap.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typescript.d.ts +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typescript.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/typingsInstaller.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/watchGuard.js +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -0
- /package/{node_modules → lib/node_modules}/ohos-typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -0
|
@@ -0,0 +1,1087 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.IRInference = void 0;
|
|
30
|
+
/*
|
|
31
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
32
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
33
|
+
* you may not use this file except in compliance with the License.
|
|
34
|
+
* You may obtain a copy of the License at
|
|
35
|
+
*
|
|
36
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
37
|
+
*
|
|
38
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
+
* See the License for the specific language governing permissions and
|
|
42
|
+
* limitations under the License.
|
|
43
|
+
*/
|
|
44
|
+
const fs_1 = __importDefault(require("fs"));
|
|
45
|
+
const path_1 = __importStar(require("path"));
|
|
46
|
+
const const_1 = require("../ast/const");
|
|
47
|
+
const ArkMethod_1 = require("../../../core/model/ArkMethod");
|
|
48
|
+
const Type_1 = require("../../../core/base/Type");
|
|
49
|
+
const Local_1 = require("../../../core/base/Local");
|
|
50
|
+
const TypeInference_1 = require("./TypeInference");
|
|
51
|
+
const Expr_1 = require("../../../core/base/Expr");
|
|
52
|
+
const logger_1 = __importStar(require("../../../utils/logger"));
|
|
53
|
+
const ArkClass_1 = require("../../../core/model/ArkClass");
|
|
54
|
+
const ModelUtils_1 = require("../../../core/common/ModelUtils");
|
|
55
|
+
const ArkField_1 = require("../../../core/model/ArkField");
|
|
56
|
+
const EtsConst_1 = require("../../../core/common/EtsConst");
|
|
57
|
+
const ArkSignature_1 = require("../../../core/model/ArkSignature");
|
|
58
|
+
const TSConst_1 = require("../../../core/common/TSConst");
|
|
59
|
+
const Builtin_1 = require("../../../core/common/Builtin");
|
|
60
|
+
const Stmt_1 = require("../../../core/base/Stmt");
|
|
61
|
+
const Ref_1 = require("../../../core/base/Ref");
|
|
62
|
+
const Constant_1 = require("../../../core/base/Constant");
|
|
63
|
+
const Const_1 = require("../../../core/common/Const");
|
|
64
|
+
const ValueUtil_1 = require("../../../core/common/ValueUtil");
|
|
65
|
+
const TypeExpr_1 = require("../../../core/base/TypeExpr");
|
|
66
|
+
const ArkBaseModel_1 = require("../../../core/model/ArkBaseModel");
|
|
67
|
+
const FileUtils_1 = require("../../../utils/FileUtils");
|
|
68
|
+
const Type_2 = require("../base/Type");
|
|
69
|
+
const SdkUtils_1 = require("../../../core/common/SdkUtils");
|
|
70
|
+
const ModelUtils_2 = require("./ModelUtils");
|
|
71
|
+
const Builtin_2 = require("./Builtin");
|
|
72
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'IRInference');
|
|
73
|
+
class IRInference {
|
|
74
|
+
static inferExportInfos(file) {
|
|
75
|
+
file.getExportInfos().forEach(exportInfo => {
|
|
76
|
+
if (exportInfo.getArkExport() === undefined) {
|
|
77
|
+
let arkExport = (0, ModelUtils_1.findArkExport)(exportInfo);
|
|
78
|
+
exportInfo.setArkExport(arkExport);
|
|
79
|
+
if (arkExport) {
|
|
80
|
+
exportInfo.setExportClauseType(arkExport.getExportType());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
file.getNamespaces().forEach(namespace => {
|
|
85
|
+
namespace.getExportInfos().forEach(exportInfo => {
|
|
86
|
+
if (exportInfo.getArkExport() === undefined) {
|
|
87
|
+
let arkExport = (0, ModelUtils_1.findArkExport)(exportInfo);
|
|
88
|
+
exportInfo.setArkExport(arkExport);
|
|
89
|
+
arkExport !== null ? exportInfo.setExportClauseType(arkExport.getExportType()) : true;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
static inferImportInfos(file) {
|
|
95
|
+
file.getImportInfos().forEach(importInfo => {
|
|
96
|
+
importInfo.getLazyExportInfo();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
static inferFile(file) {
|
|
100
|
+
this.inferImportInfos(file);
|
|
101
|
+
ModelUtils_1.ModelUtils.getAllClassesInFile(file).forEach(arkClass => {
|
|
102
|
+
TypeInference_1.TypeInference.inferGenericType(arkClass.getGenericsTypes(), arkClass);
|
|
103
|
+
arkClass.getAllHeritageClasses();
|
|
104
|
+
arkClass.getFields().forEach(arkField => TypeInference_1.TypeInference.inferTypeInArkField(arkField));
|
|
105
|
+
const methods = arkClass.getMethods().sort((a, b) => {
|
|
106
|
+
const name = a.getName().split(Const_1.NAME_DELIMITER).reverse().join();
|
|
107
|
+
const anotherName = b.getName().split(Const_1.NAME_DELIMITER).reverse().join();
|
|
108
|
+
if (name.startsWith(anotherName)) {
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
else if (anotherName.startsWith(name)) {
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
});
|
|
116
|
+
methods.forEach(arkMethod => TypeInference_1.TypeInference.inferTypeInMethod(arkMethod));
|
|
117
|
+
});
|
|
118
|
+
this.inferExportInfos(file);
|
|
119
|
+
}
|
|
120
|
+
static inferStaticInvokeExpr(expr, arkMethod) {
|
|
121
|
+
const fileSignature = expr.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature();
|
|
122
|
+
if (fileSignature !== ArkSignature_1.FileSignature.DEFAULT && fileSignature !== Builtin_1.Builtin.BUILT_IN_CLASSES_FILE_SIGNATURE) {
|
|
123
|
+
return expr;
|
|
124
|
+
}
|
|
125
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
126
|
+
const methodName = expr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
127
|
+
expr.getArgs().forEach(arg => TypeInference_1.TypeInference.inferValueType(arg, arkMethod));
|
|
128
|
+
if (methodName === TSConst_1.IMPORT) {
|
|
129
|
+
const arg = expr.getArg(0);
|
|
130
|
+
let type;
|
|
131
|
+
if (arg instanceof Constant_1.Constant) {
|
|
132
|
+
type = TypeInference_1.TypeInference.inferDynamicImportType(arg.getValue(), arkClass);
|
|
133
|
+
}
|
|
134
|
+
if (type) {
|
|
135
|
+
expr.getMethodSignature().getMethodSubSignature().setReturnType(type);
|
|
136
|
+
}
|
|
137
|
+
return expr;
|
|
138
|
+
}
|
|
139
|
+
else if (methodName === TSConst_1.SUPER_NAME) {
|
|
140
|
+
const superClass = arkClass.getSuperClass();
|
|
141
|
+
if (superClass !== null) {
|
|
142
|
+
const newMethodSignature = new ArkSignature_1.MethodSignature(superClass.getSignature(), expr.getMethodSignature().getMethodSubSignature());
|
|
143
|
+
expr.setMethodSignature(newMethodSignature);
|
|
144
|
+
}
|
|
145
|
+
return expr;
|
|
146
|
+
}
|
|
147
|
+
const className = expr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
148
|
+
if (className && className !== Const_1.UNKNOWN_CLASS_NAME) {
|
|
149
|
+
const baseType = TypeInference_1.TypeInference.inferBaseType(className, arkClass);
|
|
150
|
+
if (baseType) {
|
|
151
|
+
let result = this.inferInvokeExpr(expr, baseType, methodName, arkClass.getDeclaringArkFile().getScene());
|
|
152
|
+
if (result) {
|
|
153
|
+
this.inferArgs(result, arkMethod);
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return expr;
|
|
158
|
+
}
|
|
159
|
+
return this.inferStaticInvokeExprByMethodName(methodName, arkMethod, expr);
|
|
160
|
+
}
|
|
161
|
+
static inferStaticInvokeExprByMethodName(methodName, arkMethod, expr) {
|
|
162
|
+
var _a, _b, _c, _d;
|
|
163
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
164
|
+
const arkExport = (_d = (_c = (_b = (_a = ModelUtils_2.CxxModelUtils.getStaticMethodWithName(methodName, arkClass)) !== null && _a !== void 0 ? _a : arkMethod.getFunctionLocal(methodName)) !== null && _b !== void 0 ? _b : ModelUtils_1.ModelUtils.findDeclaredLocal(new Local_1.Local(methodName), arkMethod)) !== null && _c !== void 0 ? _c : ModelUtils_2.CxxModelUtils.getArkExportInImportInfoWithName(methodName, arkClass.getDeclaringArkFile(), arkClass)) !== null && _d !== void 0 ? _d : arkClass.getDeclaringArkFile().getScene().getSdkGlobal(methodName);
|
|
165
|
+
let { mtd: method, sig: signature } = this.processArkExportForMethodAndSignature(arkExport, arkClass);
|
|
166
|
+
if (method) {
|
|
167
|
+
signature = method.matchMethodSignature(expr.getArgs());
|
|
168
|
+
// Handle Standard Operator Overloading
|
|
169
|
+
if ([Builtin_2.BuiltinCxx.OPERATOR_ISTREAM, Builtin_2.BuiltinCxx.OPERATOR_OSTREAM].includes(methodName) &&
|
|
170
|
+
!ModelUtils_2.CxxModelUtils.isIOStreamObjectMatched(signature.getMethodSubSignature().getParameters(), expr.getArgs(), method.getDeclaringArkFile().getScene())) {
|
|
171
|
+
signature = undefined;
|
|
172
|
+
}
|
|
173
|
+
if (signature) {
|
|
174
|
+
TypeInference_1.TypeInference.inferSignatureReturnType(signature, method);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (signature) {
|
|
178
|
+
if (arkExport instanceof Local_1.Local) {
|
|
179
|
+
expr = new Expr_1.ArkPtrInvokeExpr(signature, arkExport, expr.getArgs(), expr.getRealGenericTypes());
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
expr.setMethodSignature(signature);
|
|
183
|
+
}
|
|
184
|
+
this.inferArgs(expr, arkMethod);
|
|
185
|
+
}
|
|
186
|
+
return expr;
|
|
187
|
+
}
|
|
188
|
+
static processArkExportForMethodAndSignature(arkExport, arkClass) {
|
|
189
|
+
var _a;
|
|
190
|
+
let method;
|
|
191
|
+
let signature;
|
|
192
|
+
if (arkExport instanceof ArkMethod_1.ArkMethod) {
|
|
193
|
+
method = arkExport;
|
|
194
|
+
}
|
|
195
|
+
else if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
196
|
+
method = arkExport.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
197
|
+
}
|
|
198
|
+
else if (arkExport instanceof Local_1.Local) {
|
|
199
|
+
const type = TypeInference_1.TypeInference.replaceAliasType(arkExport.getType());
|
|
200
|
+
if (type instanceof Type_1.ClassType) {
|
|
201
|
+
const cls = arkClass.getDeclaringArkFile().getScene().getClass(type.getClassSignature());
|
|
202
|
+
method = (_a = cls === null || cls === void 0 ? void 0 : cls.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME)) !== null && _a !== void 0 ? _a : cls === null || cls === void 0 ? void 0 : cls.getMethodWithName(Const_1.CALL_SIGNATURE_NAME);
|
|
203
|
+
}
|
|
204
|
+
else if (type instanceof Type_1.FunctionType) {
|
|
205
|
+
signature = type.getMethodSignature();
|
|
206
|
+
}
|
|
207
|
+
else if (type instanceof Type_2.PointerType && type.getBaseType() instanceof Type_1.FunctionType) {
|
|
208
|
+
// The type of a function pointer in CXX is 'PointerType(FunctionType, 1)'
|
|
209
|
+
signature = type.getBaseType().getMethodSignature();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (arkExport instanceof Type_1.AliasType && arkExport.getOriginalType() instanceof Type_1.FunctionType) {
|
|
213
|
+
signature = arkExport.getOriginalType().getMethodSignature();
|
|
214
|
+
}
|
|
215
|
+
return { mtd: method, sig: signature };
|
|
216
|
+
}
|
|
217
|
+
static inferInstanceInvokeExpr(expr, arkMethod) {
|
|
218
|
+
var _a, _b, _c;
|
|
219
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
220
|
+
TypeInference_1.TypeInference.inferRealGenericTypes(expr.getRealGenericTypes(), arkClass);
|
|
221
|
+
this.inferBase(expr, arkMethod);
|
|
222
|
+
const baseType = TypeInference_1.TypeInference.replaceAliasType(expr.getBase().getType());
|
|
223
|
+
let methodName = expr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
224
|
+
if (methodName === TSConst_1.CONSTRUCTOR_NAME &&
|
|
225
|
+
expr.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature().getFileName() !== Const_1.UNKNOWN_FILE_NAME) {
|
|
226
|
+
return expr;
|
|
227
|
+
}
|
|
228
|
+
if (methodName.startsWith(Const_1.NAME_PREFIX)) {
|
|
229
|
+
const declaringStmt = (_b = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(methodName)) === null || _b === void 0 ? void 0 : _b.getDeclaringStmt();
|
|
230
|
+
if (declaringStmt instanceof Stmt_1.ArkAssignStmt && declaringStmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
231
|
+
const rightOp = declaringStmt.getRightOp();
|
|
232
|
+
methodName = rightOp.getBase().getName() + '.' + rightOp.getFieldName();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const scene = arkClass.getDeclaringArkFile().getScene();
|
|
236
|
+
if (methodName === 'forEach' && baseType instanceof Type_1.ArrayType) {
|
|
237
|
+
this.processForEach(expr.getArg(0), baseType, scene);
|
|
238
|
+
return expr;
|
|
239
|
+
}
|
|
240
|
+
expr.getArgs().forEach(arg => TypeInference_1.TypeInference.inferValueType(arg, arkMethod));
|
|
241
|
+
let result = (_c = this.inferInvokeExpr(expr, baseType, methodName, scene)) !== null && _c !== void 0 ? _c : this.processExtendFunc(expr, arkMethod, methodName);
|
|
242
|
+
if (result) {
|
|
243
|
+
this.inferArgs(result, arkMethod);
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
logger.warn('invoke ArkInstanceInvokeExpr MethodSignature type fail: ', expr.toString());
|
|
247
|
+
return expr;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* process arkUI function with Annotation @Extend @Styles @AnimatableExtend
|
|
251
|
+
* @param expr
|
|
252
|
+
* @param arkMethod
|
|
253
|
+
* @param methodName
|
|
254
|
+
*/
|
|
255
|
+
static processExtendFunc(expr, arkMethod, methodName) {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
const type = TypeInference_1.TypeInference.inferBaseType(methodName, arkMethod.getDeclaringArkClass());
|
|
258
|
+
if (type instanceof Type_1.FunctionType) {
|
|
259
|
+
const methodSignature = type.getMethodSignature();
|
|
260
|
+
// because of last stmt is ArkReturnVoidStmt, the ArkInvokeStmt at -2 before ArkReturnVoidStmt.
|
|
261
|
+
const stmts = (_b = (_a = arkMethod.getDeclaringArkFile().getScene().getMethod(methodSignature)) === null || _a === void 0 ? void 0 : _a.getCfg()) === null || _b === void 0 ? void 0 : _b.getStmts();
|
|
262
|
+
if (stmts) {
|
|
263
|
+
const endStmt = stmts[stmts.length - 2];
|
|
264
|
+
if (endStmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
265
|
+
methodSignature.getMethodSubSignature().setReturnType(endStmt.getInvokeExpr().getType());
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
expr.setMethodSignature(methodSignature);
|
|
269
|
+
return expr;
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
static inferFieldRef(ref, arkMethod) {
|
|
274
|
+
this.inferBase(ref, arkMethod);
|
|
275
|
+
const baseType = TypeInference_1.TypeInference.replaceAliasType(ref.getBase().getType());
|
|
276
|
+
if (baseType instanceof Type_1.ArrayType && ref.getFieldName() !== 'length') {
|
|
277
|
+
return new Ref_1.ArkArrayRef(ref.getBase(), ValueUtil_1.ValueUtil.createConst(ref.getFieldName()));
|
|
278
|
+
}
|
|
279
|
+
let newFieldSignature = this.generateNewFieldSignature(ref, arkMethod.getDeclaringArkClass(), baseType);
|
|
280
|
+
if (newFieldSignature) {
|
|
281
|
+
if (newFieldSignature.isStatic()) {
|
|
282
|
+
return new Ref_1.ArkStaticFieldRef(newFieldSignature);
|
|
283
|
+
}
|
|
284
|
+
ref.setFieldSignature(newFieldSignature);
|
|
285
|
+
}
|
|
286
|
+
return ref;
|
|
287
|
+
}
|
|
288
|
+
static inferBase(instance, arkMethod) {
|
|
289
|
+
const base = instance.getBase();
|
|
290
|
+
if (base.getName() === TSConst_1.THIS_NAME) {
|
|
291
|
+
const name = instance instanceof Ref_1.ArkInstanceFieldRef ? instance.getFieldName() : instance.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
292
|
+
if (name.includes('.')) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const declaringArkClass = arkMethod.getDeclaringArkClass();
|
|
296
|
+
if (declaringArkClass.isAnonymousClass()) {
|
|
297
|
+
let newBase = this.inferThisLocal(arkMethod);
|
|
298
|
+
if (newBase) {
|
|
299
|
+
instance.setBase(newBase);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else if (base.getType() instanceof Type_1.UnknownType) {
|
|
303
|
+
base.setType(new Type_1.ClassType(declaringArkClass.getSignature(), declaringArkClass.getRealTypes()));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.inferLocal(instance.getBase(), arkMethod);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
static inferThisLocal(arkMethod) {
|
|
311
|
+
var _a, _b, _c, _d;
|
|
312
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
313
|
+
if (!arkClass.isAnonymousClass()) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
const value = (_b = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getUsedGlobals()) === null || _b === void 0 ? void 0 : _b.get(TSConst_1.THIS_NAME);
|
|
317
|
+
if (value instanceof Local_1.Local) {
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
const thisType = TypeInference_1.TypeInference.inferBaseType(arkClass.getSignature().getDeclaringClassName(), arkClass);
|
|
322
|
+
if (thisType instanceof Type_1.ClassType) {
|
|
323
|
+
const newBase = new Local_1.Local(TSConst_1.THIS_NAME, thisType);
|
|
324
|
+
let usedGlobals = (_c = arkMethod.getBody()) === null || _c === void 0 ? void 0 : _c.getUsedGlobals();
|
|
325
|
+
if (!usedGlobals) {
|
|
326
|
+
usedGlobals = new Map();
|
|
327
|
+
(_d = arkMethod.getBody()) === null || _d === void 0 ? void 0 : _d.setUsedGlobals(usedGlobals);
|
|
328
|
+
}
|
|
329
|
+
usedGlobals.set(TSConst_1.THIS_NAME, newBase);
|
|
330
|
+
return newBase;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
static inferArgs(expr, arkMethod) {
|
|
336
|
+
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
337
|
+
const parameters = expr.getMethodSignature().getMethodSubSignature().getParameters();
|
|
338
|
+
let realTypes = [];
|
|
339
|
+
const len = expr.getArgs().length;
|
|
340
|
+
for (let index = 0; index < len; index++) {
|
|
341
|
+
const arg = expr.getArg(index);
|
|
342
|
+
if (index >= parameters.length) {
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
const argType = arg.getType();
|
|
346
|
+
const paramType = parameters[index].getType();
|
|
347
|
+
this.inferArg(expr, argType, paramType, scene, realTypes);
|
|
348
|
+
}
|
|
349
|
+
if (realTypes.length > 0 && !expr.getRealGenericTypes()) {
|
|
350
|
+
expr.setRealGenericTypes(realTypes);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
static inferArg(expr, argType, paramType, scene, realTypes) {
|
|
354
|
+
var _a;
|
|
355
|
+
if (paramType instanceof Type_1.UnionType) {
|
|
356
|
+
paramType.getTypes().forEach(t => this.inferArg(expr, argType, t, scene, realTypes));
|
|
357
|
+
}
|
|
358
|
+
else if (paramType instanceof Type_1.AliasType) {
|
|
359
|
+
this.inferArg(expr, argType, paramType.getOriginalType(), scene, realTypes);
|
|
360
|
+
}
|
|
361
|
+
else if (paramType instanceof Type_1.ArrayType && argType instanceof Type_1.ArrayType) {
|
|
362
|
+
this.inferArg(expr, argType.getBaseType(), paramType.getBaseType(), scene, realTypes);
|
|
363
|
+
}
|
|
364
|
+
else if (expr instanceof Expr_1.ArkInstanceInvokeExpr && expr.getBase().getType() instanceof Type_1.ArrayType) {
|
|
365
|
+
if (paramType instanceof Type_1.ArrayType && paramType.getBaseType() instanceof Type_1.GenericType) {
|
|
366
|
+
this.inferArg(expr, argType, expr.getBase().getType().getBaseType(), scene, realTypes);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (paramType instanceof Type_1.ClassType && scene.getProjectSdkMap().has(paramType.getClassSignature().getDeclaringFileSignature().getProjectName())) {
|
|
370
|
+
this.inferArgTypeWithSdk(paramType, scene, argType);
|
|
371
|
+
}
|
|
372
|
+
else if (paramType instanceof Type_1.GenericType || paramType instanceof Type_1.AnyType) {
|
|
373
|
+
realTypes.push(argType);
|
|
374
|
+
}
|
|
375
|
+
else if (paramType instanceof Type_1.FunctionType && argType instanceof Type_1.FunctionType) {
|
|
376
|
+
const returnType = paramType.getMethodSignature().getType();
|
|
377
|
+
if (paramType.getMethodSignature().getParamLength() > 0 && returnType instanceof Type_1.GenericType) {
|
|
378
|
+
const paramMethod = scene.getMethod(expr.getMethodSignature());
|
|
379
|
+
const argMethod = scene.getMethod(argType.getMethodSignature());
|
|
380
|
+
if (argMethod && ((_a = paramMethod === null || paramMethod === void 0 ? void 0 : paramMethod.getGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => t === returnType))) {
|
|
381
|
+
TypeInference_1.TypeInference.inferTypeInMethod(argMethod);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const realTypes = expr.getRealGenericTypes();
|
|
385
|
+
TypeInference_1.TypeInference.inferFunctionType(argType, paramType.getMethodSignature().getMethodSubSignature(), realTypes);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
static inferRightWithSdkType(leftType, rightType, ackClass) {
|
|
389
|
+
if (leftType instanceof Type_1.AliasType) {
|
|
390
|
+
this.inferRightWithSdkType(TypeInference_1.TypeInference.replaceAliasType(leftType), rightType, ackClass);
|
|
391
|
+
}
|
|
392
|
+
else if (leftType instanceof Type_1.UnionType) {
|
|
393
|
+
leftType.getTypes().forEach(t => this.inferRightWithSdkType(t, rightType, ackClass));
|
|
394
|
+
}
|
|
395
|
+
else if (leftType instanceof Type_1.ClassType) {
|
|
396
|
+
IRInference.inferArgTypeWithSdk(leftType, ackClass.getDeclaringArkFile().getScene(), rightType);
|
|
397
|
+
}
|
|
398
|
+
else if (rightType instanceof Type_1.ArrayType && leftType instanceof Type_1.ArrayType) {
|
|
399
|
+
const baseType = TypeInference_1.TypeInference.replaceAliasType(leftType.getBaseType());
|
|
400
|
+
if (baseType instanceof Type_1.ClassType) {
|
|
401
|
+
IRInference.inferArgTypeWithSdk(baseType, ackClass.getDeclaringArkFile().getScene(), rightType.getBaseType());
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
static inferArgTypeWithSdk(sdkType, scene, argType) {
|
|
406
|
+
var _a, _b;
|
|
407
|
+
const sdkProjectName = sdkType.getClassSignature().getDeclaringFileSignature().getProjectName();
|
|
408
|
+
const className = sdkType.getClassSignature().getClassName();
|
|
409
|
+
// When leftOp is local with Function annotation, the rightOp is a lambda function, which should be inferred as method later.
|
|
410
|
+
if (!scene.getProjectSdkMap().has(sdkProjectName) || (sdkProjectName === SdkUtils_1.SdkUtils.BUILT_IN_NAME && className === 'Function')) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (argType instanceof Type_1.UnionType) {
|
|
414
|
+
argType.getTypes().forEach(t => this.inferArgTypeWithSdk(sdkType, scene, t));
|
|
415
|
+
}
|
|
416
|
+
else if (argType instanceof Type_1.ClassType && argType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)) {
|
|
417
|
+
this.inferAnonymousClass(scene.getClass(argType.getClassSignature()), sdkType.getClassSignature());
|
|
418
|
+
}
|
|
419
|
+
else if (argType instanceof Type_1.FunctionType) {
|
|
420
|
+
const param = (_b = (_a = scene.getClass(sdkType.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethodWithName(Const_1.CALL_SIGNATURE_NAME)) === null || _b === void 0 ? void 0 : _b.getSignature().getMethodSubSignature();
|
|
421
|
+
const realTypes = sdkType.getRealGenericTypes();
|
|
422
|
+
TypeInference_1.TypeInference.inferFunctionType(argType, param, realTypes);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
static inferInvokeExpr(expr, baseType, methodName, scene) {
|
|
426
|
+
let typeWithoutPtrOrRef = baseType;
|
|
427
|
+
// If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
|
|
428
|
+
if (baseType instanceof Type_2.PointerType || baseType instanceof Type_2.ReferenceType) {
|
|
429
|
+
typeWithoutPtrOrRef = baseType.getBaseType();
|
|
430
|
+
}
|
|
431
|
+
if (typeWithoutPtrOrRef instanceof Type_1.AliasType) {
|
|
432
|
+
return this.inferInvokeExpr(expr, typeWithoutPtrOrRef.getOriginalType(), methodName, scene);
|
|
433
|
+
}
|
|
434
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.UnionType) {
|
|
435
|
+
for (let type of typeWithoutPtrOrRef.flatType()) {
|
|
436
|
+
if (type instanceof Type_1.UndefinedType || type instanceof Type_1.NullType) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
let result = this.inferInvokeExpr(expr, type, methodName, scene);
|
|
440
|
+
if (result) {
|
|
441
|
+
return result;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (typeWithoutPtrOrRef instanceof Type_1.ClassType) {
|
|
446
|
+
return this.inferInvokeExprWithDeclaredClass(expr, typeWithoutPtrOrRef, methodName, scene);
|
|
447
|
+
}
|
|
448
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.AnnotationNamespaceType) {
|
|
449
|
+
const namespace = scene.getNamespace(typeWithoutPtrOrRef.getNamespaceSignature());
|
|
450
|
+
if (namespace) {
|
|
451
|
+
const foundMethod = ModelUtils_2.CxxModelUtils.findPropertyInNamespace(methodName, namespace);
|
|
452
|
+
if (foundMethod instanceof ArkMethod_1.ArkMethod) {
|
|
453
|
+
let signature = foundMethod.matchMethodSignature(expr.getArgs());
|
|
454
|
+
TypeInference_1.TypeInference.inferSignatureReturnType(signature, foundMethod);
|
|
455
|
+
expr.setMethodSignature(signature);
|
|
456
|
+
return expr instanceof Expr_1.ArkInstanceInvokeExpr ? new Expr_1.ArkStaticInvokeExpr(signature, expr.getArgs(), expr.getRealGenericTypes()) : expr;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.FunctionType) {
|
|
461
|
+
return IRInference.inferInvokeExprWithFunction(methodName, expr, typeWithoutPtrOrRef, scene);
|
|
462
|
+
}
|
|
463
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.ArrayType) {
|
|
464
|
+
return IRInference.inferInvokeExprWithArray(methodName, expr, typeWithoutPtrOrRef, scene);
|
|
465
|
+
}
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
static inferInvokeExprWithArray(methodName, expr, baseType, scene) {
|
|
469
|
+
const arrayInterface = scene.getSdkGlobal(Builtin_1.Builtin.ARRAY);
|
|
470
|
+
if (arrayInterface instanceof ArkClass_1.ArkClass) {
|
|
471
|
+
return this.inferInvokeExpr(expr, new Type_1.ClassType(arrayInterface.getSignature(), [baseType.getBaseType()]), methodName, scene);
|
|
472
|
+
}
|
|
473
|
+
else if (methodName === Builtin_1.Builtin.ITERATOR_FUNCTION) {
|
|
474
|
+
expr.getMethodSignature().getMethodSubSignature().setReturnType(Builtin_1.Builtin.ITERATOR_CLASS_TYPE);
|
|
475
|
+
expr.setRealGenericTypes([baseType.getBaseType()]);
|
|
476
|
+
return expr;
|
|
477
|
+
}
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
static inferInvokeExprWithFunction(methodName, expr, baseType, scene) {
|
|
481
|
+
if (methodName === Const_1.CALL_SIGNATURE_NAME) {
|
|
482
|
+
expr.setMethodSignature(baseType.getMethodSignature());
|
|
483
|
+
return expr;
|
|
484
|
+
}
|
|
485
|
+
const funcInterface = scene.getSdkGlobal(TSConst_1.FUNCTION);
|
|
486
|
+
if (funcInterface instanceof ArkClass_1.ArkClass) {
|
|
487
|
+
const method = ModelUtils_1.ModelUtils.findPropertyInClass(methodName, funcInterface);
|
|
488
|
+
if (method instanceof ArkMethod_1.ArkMethod) {
|
|
489
|
+
expr.setRealGenericTypes([baseType]);
|
|
490
|
+
expr.setMethodSignature(method.getSignature());
|
|
491
|
+
return expr;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
static inferInvokeExprWithDeclaredClass(expr, baseType, methodName, scene) {
|
|
497
|
+
var _a, _b;
|
|
498
|
+
let declaredClass = scene.getClass(baseType.getClassSignature());
|
|
499
|
+
if (!declaredClass) {
|
|
500
|
+
const globalClass = scene.getSdkGlobal(baseType.getClassSignature().getClassName());
|
|
501
|
+
if (globalClass instanceof ArkClass_1.ArkClass) {
|
|
502
|
+
declaredClass = globalClass;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const method = declaredClass ? ModelUtils_1.ModelUtils.findPropertyInClass(methodName, declaredClass) : null;
|
|
506
|
+
if (method instanceof ArkMethod_1.ArkMethod) {
|
|
507
|
+
const methodSignature = method.matchMethodSignature(expr.getArgs());
|
|
508
|
+
TypeInference_1.TypeInference.inferSignatureReturnType(methodSignature, method);
|
|
509
|
+
expr.setMethodSignature(this.replaceMethodSignature(expr.getMethodSignature(), methodSignature));
|
|
510
|
+
expr.setRealGenericTypes(IRInference.getRealTypes(expr, declaredClass, baseType, method));
|
|
511
|
+
if (method.isStatic() && expr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
512
|
+
return new Expr_1.ArkStaticInvokeExpr(methodSignature, expr.getArgs(), expr.getRealGenericTypes());
|
|
513
|
+
}
|
|
514
|
+
return expr;
|
|
515
|
+
}
|
|
516
|
+
else if (method instanceof ArkField_1.ArkField) {
|
|
517
|
+
return (_a = this.changePtrInvokeExpr(method, scene, expr)) !== null && _a !== void 0 ? _a : expr;
|
|
518
|
+
}
|
|
519
|
+
else if (methodName === TSConst_1.CONSTRUCTOR_NAME) {
|
|
520
|
+
const constructor = (_b = declaredClass === null || declaredClass === void 0 ? void 0 : declaredClass.getMethodWithName('construct-signature')) !== null && _b !== void 0 ? _b : declaredClass === null || declaredClass === void 0 ? void 0 : declaredClass.getMethodWithName(Const_1.CALL_SIGNATURE_NAME);
|
|
521
|
+
if (constructor) {
|
|
522
|
+
const methodSignature = constructor.matchMethodSignature(expr.getArgs());
|
|
523
|
+
TypeInference_1.TypeInference.inferSignatureReturnType(methodSignature, constructor);
|
|
524
|
+
expr.setMethodSignature(this.replaceMethodSignature(expr.getMethodSignature(), methodSignature));
|
|
525
|
+
expr.setRealGenericTypes(IRInference.getRealTypes(expr, declaredClass, baseType, constructor));
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], new Type_1.ClassType(baseType.getClassSignature()));
|
|
529
|
+
expr.setMethodSignature(new ArkSignature_1.MethodSignature(baseType.getClassSignature(), subSignature));
|
|
530
|
+
}
|
|
531
|
+
return expr;
|
|
532
|
+
}
|
|
533
|
+
else if (methodName === Builtin_1.Builtin.ITERATOR_NEXT &&
|
|
534
|
+
baseType.getClassSignature().getDeclaringFileSignature().getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
535
|
+
expr.getMethodSignature().getMethodSubSignature().setReturnType(Builtin_1.Builtin.ITERATOR_RESULT_CLASS_TYPE);
|
|
536
|
+
expr.setRealGenericTypes(baseType.getRealGenericTypes());
|
|
537
|
+
return expr;
|
|
538
|
+
}
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
static changePtrInvokeExpr(method, scene, expr) {
|
|
542
|
+
var _a;
|
|
543
|
+
const type = method.getType();
|
|
544
|
+
let methodSignature;
|
|
545
|
+
if (type instanceof Type_1.FunctionType) {
|
|
546
|
+
methodSignature = type.getMethodSignature();
|
|
547
|
+
}
|
|
548
|
+
else if (type instanceof Type_1.ClassType && type.getClassSignature().getClassName().endsWith(EtsConst_1.CALL_BACK)) {
|
|
549
|
+
const callback = (_a = scene.getClass(type.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethodWithName(Const_1.CALL_SIGNATURE_NAME);
|
|
550
|
+
if (callback) {
|
|
551
|
+
methodSignature = callback.getSignature();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (methodSignature) {
|
|
555
|
+
const ptr = expr instanceof Expr_1.ArkInstanceInvokeExpr
|
|
556
|
+
? new Ref_1.ArkInstanceFieldRef(expr.getBase(), method.getSignature())
|
|
557
|
+
: new Ref_1.ArkStaticFieldRef(method.getSignature());
|
|
558
|
+
return new Expr_1.ArkPtrInvokeExpr(methodSignature, ptr, expr.getArgs(), expr.getRealGenericTypes());
|
|
559
|
+
}
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
static getRealTypes(expr, declaredClass, baseType, method) {
|
|
563
|
+
var _a;
|
|
564
|
+
let realTypes;
|
|
565
|
+
const tmp = [];
|
|
566
|
+
if (method.getGenericTypes()) {
|
|
567
|
+
expr.getMethodSignature()
|
|
568
|
+
.getMethodSubSignature()
|
|
569
|
+
.getParameters()
|
|
570
|
+
.filter(p => !p.getName().startsWith(Const_1.LEXICAL_ENV_NAME_PREFIX))
|
|
571
|
+
.forEach((p, i) => {
|
|
572
|
+
if (TypeInference_1.TypeInference.checkType(p.getType(), t => t instanceof Type_1.GenericType)) {
|
|
573
|
+
tmp.push(expr.getArg(i).getType());
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
if (tmp.length > 0) {
|
|
578
|
+
realTypes = tmp;
|
|
579
|
+
}
|
|
580
|
+
else if (declaredClass === null || declaredClass === void 0 ? void 0 : declaredClass.hasComponentDecorator()) {
|
|
581
|
+
realTypes = [new Type_1.ClassType(declaredClass === null || declaredClass === void 0 ? void 0 : declaredClass.getSignature())];
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
realTypes = (_a = baseType.getRealGenericTypes()) !== null && _a !== void 0 ? _a : declaredClass === null || declaredClass === void 0 ? void 0 : declaredClass.getRealTypes();
|
|
585
|
+
}
|
|
586
|
+
return realTypes;
|
|
587
|
+
}
|
|
588
|
+
static replaceMethodSignature(init, declared) {
|
|
589
|
+
const className = init.getDeclaringClassSignature().getClassName();
|
|
590
|
+
let classSignature;
|
|
591
|
+
if (declared.getDeclaringClassSignature().getClassName().endsWith('Interface')) {
|
|
592
|
+
classSignature = new ArkSignature_1.AliasClassSignature(className, declared.getDeclaringClassSignature());
|
|
593
|
+
}
|
|
594
|
+
let newSubSignature;
|
|
595
|
+
if (classSignature || newSubSignature) {
|
|
596
|
+
return new ArkSignature_1.MethodSignature(classSignature !== null && classSignature !== void 0 ? classSignature : declared.getDeclaringClassSignature(), newSubSignature !== null && newSubSignature !== void 0 ? newSubSignature : declared.getMethodSubSignature());
|
|
597
|
+
}
|
|
598
|
+
return declared;
|
|
599
|
+
}
|
|
600
|
+
static processForEach(arg, baseType, scene) {
|
|
601
|
+
const argType = arg.getType();
|
|
602
|
+
if (argType instanceof Type_1.FunctionType) {
|
|
603
|
+
const argMethodSignature = argType.getMethodSignature();
|
|
604
|
+
const argMethod = scene.getMethod(argMethodSignature);
|
|
605
|
+
if (argMethod !== null && argMethod.getBody()) {
|
|
606
|
+
const body = argMethod.getBody();
|
|
607
|
+
const firstStmt = body.getCfg().getStartingStmt();
|
|
608
|
+
if (firstStmt instanceof Stmt_1.ArkAssignStmt && firstStmt.getRightOp() instanceof Ref_1.ArkParameterRef) {
|
|
609
|
+
const parameterRef = firstStmt.getRightOp();
|
|
610
|
+
parameterRef.setType(baseType.getBaseType());
|
|
611
|
+
const argMethodParams = argMethod.getSignature().getMethodSubSignature().getParameters();
|
|
612
|
+
const actualParam = argMethodParams[argMethodParams.length - 1];
|
|
613
|
+
actualParam.setType(baseType.getBaseType());
|
|
614
|
+
}
|
|
615
|
+
TypeInference_1.TypeInference.inferTypeInMethod(argMethod);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
logger.warn(`arg of forEach must be callable`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
static inferLocal(base, arkMethod) {
|
|
623
|
+
var _a, _b, _c;
|
|
624
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
625
|
+
let baseType = base.getType();
|
|
626
|
+
if (baseType instanceof Type_1.UnclearReferenceType) {
|
|
627
|
+
baseType = TypeInference_1.TypeInference.inferUnclearRefName(baseType.getName(), arkClass);
|
|
628
|
+
}
|
|
629
|
+
if (TypeInference_1.TypeInference.isUnclearType(baseType)) {
|
|
630
|
+
const declaringStmt = base.getDeclaringStmt();
|
|
631
|
+
if (!declaringStmt || !declaringStmt.getOriginalText() || ((_a = declaringStmt.getOriginalText()) === null || _a === void 0 ? void 0 : _a.startsWith(base.getName()))) {
|
|
632
|
+
baseType = (_c = (_b = ModelUtils_1.ModelUtils.findDeclaredLocal(base, arkMethod)) === null || _b === void 0 ? void 0 : _b.getType()) !== null && _c !== void 0 ? _c : TypeInference_1.TypeInference.inferBaseType(base.getName(), arkClass);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (baseType && !TypeInference_1.TypeInference.isUnclearType(baseType)) {
|
|
636
|
+
base.setType(baseType);
|
|
637
|
+
}
|
|
638
|
+
// If the type of value is functionType and the current file is a CXX file,
|
|
639
|
+
// it should be represented as a CXX function pointer type ==> PointerType(FunctionType, 1).
|
|
640
|
+
if (baseType instanceof Type_1.FunctionType) {
|
|
641
|
+
base.setType(new Type_2.PointerType(baseType, 1));
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
static generateNewFieldSignature(ref, arkClass, baseType) {
|
|
645
|
+
if (baseType instanceof Type_1.AliasType) {
|
|
646
|
+
return this.generateNewFieldSignature(ref, arkClass, baseType.getOriginalType());
|
|
647
|
+
}
|
|
648
|
+
const fieldName = ref.getFieldName().replace(/[\"|\']/g, '');
|
|
649
|
+
const propertyAndType = TypeInference_1.TypeInference.inferFieldType(baseType, fieldName, arkClass);
|
|
650
|
+
let propertyType = IRInference.repairType(propertyAndType === null || propertyAndType === void 0 ? void 0 : propertyAndType[1], fieldName, arkClass);
|
|
651
|
+
let staticFlag;
|
|
652
|
+
let signature;
|
|
653
|
+
let typeWithoutPtrOrRef = baseType;
|
|
654
|
+
// If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
|
|
655
|
+
if (baseType instanceof Type_2.PointerType || baseType instanceof Type_2.ReferenceType) {
|
|
656
|
+
typeWithoutPtrOrRef = baseType.getBaseType();
|
|
657
|
+
}
|
|
658
|
+
if (typeWithoutPtrOrRef instanceof Type_1.ClassType) {
|
|
659
|
+
const property = propertyAndType === null || propertyAndType === void 0 ? void 0 : propertyAndType[0];
|
|
660
|
+
if (property instanceof ArkField_1.ArkField && property.getCategory() !== ArkField_1.FieldCategory.ENUM_MEMBER && !(property.getType() instanceof Type_1.GenericType)) {
|
|
661
|
+
return property.getSignature();
|
|
662
|
+
}
|
|
663
|
+
staticFlag =
|
|
664
|
+
typeWithoutPtrOrRef.getClassSignature().getClassName() === Const_1.DEFAULT_ARK_CLASS_NAME ||
|
|
665
|
+
((property instanceof ArkField_1.ArkField || property instanceof ArkMethod_1.ArkMethod) && property.isStatic());
|
|
666
|
+
signature = property instanceof ArkMethod_1.ArkMethod ? property.getSignature().getDeclaringClassSignature() : typeWithoutPtrOrRef.getClassSignature();
|
|
667
|
+
}
|
|
668
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.ArrayType) {
|
|
669
|
+
const property = propertyAndType === null || propertyAndType === void 0 ? void 0 : propertyAndType[0];
|
|
670
|
+
if (property instanceof ArkField_1.ArkField) {
|
|
671
|
+
return property.getSignature();
|
|
672
|
+
}
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
else if (typeWithoutPtrOrRef instanceof Type_1.AnnotationNamespaceType) {
|
|
676
|
+
staticFlag = true;
|
|
677
|
+
signature = typeWithoutPtrOrRef.getNamespaceSignature();
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
return new ArkSignature_1.FieldSignature(fieldName, signature, propertyType !== null && propertyType !== void 0 ? propertyType : ref.getType(), staticFlag);
|
|
683
|
+
}
|
|
684
|
+
static repairType(propertyType, fieldName, arkClass) {
|
|
685
|
+
if (!propertyType || propertyType instanceof Type_1.UnknownType) {
|
|
686
|
+
const newType = TypeInference_1.TypeInference.inferBaseType(fieldName, arkClass);
|
|
687
|
+
if (newType) {
|
|
688
|
+
propertyType = newType;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
else if (TypeInference_1.TypeInference.isUnclearType(propertyType)) {
|
|
692
|
+
const newType = TypeInference_1.TypeInference.inferUnclearedType(propertyType, arkClass);
|
|
693
|
+
if (newType) {
|
|
694
|
+
propertyType = newType;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return propertyType;
|
|
698
|
+
}
|
|
699
|
+
static inferAnonymousClass(anon, declaredSignature, set = new Set()) {
|
|
700
|
+
if (!anon) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const key = anon.getSignature().toString();
|
|
704
|
+
if (set.has(key)) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
set.add(key);
|
|
709
|
+
}
|
|
710
|
+
const scene = anon.getDeclaringArkFile().getScene();
|
|
711
|
+
const declaredClass = scene.getClass(declaredSignature);
|
|
712
|
+
if (!declaredClass) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
for (const anonField of anon.getFields()) {
|
|
716
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInClass(anonField.getName(), declaredClass);
|
|
717
|
+
if (property instanceof ArkField_1.ArkField) {
|
|
718
|
+
this.assignAnonField(property, anonField, scene, set);
|
|
719
|
+
}
|
|
720
|
+
else if (property instanceof ArkMethod_1.ArkMethod) {
|
|
721
|
+
const type = anonField.getType();
|
|
722
|
+
if (type instanceof Type_1.FunctionType) {
|
|
723
|
+
this.assignAnonMethod(scene.getMethod(type.getMethodSignature()), property);
|
|
724
|
+
}
|
|
725
|
+
if (type instanceof Type_1.UnknownType) {
|
|
726
|
+
anonField.setSignature(new ArkSignature_1.FieldSignature(anonField.getName(), property.getDeclaringArkClass().getSignature(), new Type_1.FunctionType(property.getSignature())));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
for (const anonMethod of anon.getMethods()) {
|
|
731
|
+
this.assignAnonMethod(anonMethod, declaredClass.getMethodWithName(anonMethod.getName()));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
static assignAnonMethod(anonMethod, declaredMethod) {
|
|
735
|
+
if (declaredMethod && anonMethod) {
|
|
736
|
+
anonMethod.setDeclareSignatures(declaredMethod.matchMethodSignature(anonMethod.getSubSignature().getParameters()));
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
static assignAnonField(property, anonField, scene, set) {
|
|
740
|
+
function deepInfer(anonType, declaredSignature) {
|
|
741
|
+
if (anonType instanceof Type_1.ClassType && anonType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)) {
|
|
742
|
+
IRInference.inferAnonymousClass(scene.getClass(anonType.getClassSignature()), declaredSignature, set);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const type = property.getSignature().getType();
|
|
746
|
+
const fieldInitializer = anonField.getInitializer();
|
|
747
|
+
const lastStmt = fieldInitializer[fieldInitializer.length - 1];
|
|
748
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
749
|
+
const rightType = lastStmt.getRightOp().getType();
|
|
750
|
+
if (type instanceof Type_1.ClassType) {
|
|
751
|
+
deepInfer(rightType, type.getClassSignature());
|
|
752
|
+
}
|
|
753
|
+
else if (type instanceof Type_1.ArrayType && type.getBaseType() instanceof Type_1.ClassType && rightType instanceof Type_1.ArrayType) {
|
|
754
|
+
const baseType = rightType.getBaseType();
|
|
755
|
+
const classSignature = type.getBaseType().getClassSignature();
|
|
756
|
+
if (baseType instanceof Type_1.UnionType) {
|
|
757
|
+
baseType.getTypes().forEach(t => deepInfer(t, classSignature));
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
deepInfer(rightType.getBaseType(), classSignature);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else if (type instanceof Type_1.FunctionType && rightType instanceof Type_1.FunctionType) {
|
|
764
|
+
TypeInference_1.TypeInference.inferFunctionType(rightType, type.getMethodSignature().getMethodSubSignature(), type.getRealGenericTypes());
|
|
765
|
+
}
|
|
766
|
+
const leftOp = lastStmt.getLeftOp();
|
|
767
|
+
if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
768
|
+
leftOp.setFieldSignature(property.getSignature());
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
anonField.setSignature(property.getSignature());
|
|
772
|
+
}
|
|
773
|
+
static inferAliasTypeExpr(expr, arkMethod) {
|
|
774
|
+
const originalObject = expr.getOriginalObject();
|
|
775
|
+
let model;
|
|
776
|
+
if (originalObject instanceof Local_1.Local) {
|
|
777
|
+
model = ModelUtils_1.ModelUtils.findArkModelByRefName(originalObject.getName(), arkMethod.getDeclaringArkClass());
|
|
778
|
+
}
|
|
779
|
+
else if (originalObject instanceof TypeExpr_1.AbstractTypeExpr) {
|
|
780
|
+
originalObject.inferType(arkMethod);
|
|
781
|
+
model = originalObject;
|
|
782
|
+
}
|
|
783
|
+
else if (originalObject instanceof Type_1.Type) {
|
|
784
|
+
const type = TypeInference_1.TypeInference.inferUnclearedType(originalObject, arkMethod.getDeclaringArkClass());
|
|
785
|
+
// If original Object is ClassType, AliasType or UnclearReferenceType with real generic types,
|
|
786
|
+
// the type after infer should be revert back to the object itself.
|
|
787
|
+
if (type instanceof Type_1.ClassType) {
|
|
788
|
+
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
789
|
+
model = ModelUtils_1.ModelUtils.findArkModelBySignature(type.getClassSignature(), scene);
|
|
790
|
+
}
|
|
791
|
+
else if (type instanceof Type_1.AliasType) {
|
|
792
|
+
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
793
|
+
model = ModelUtils_1.ModelUtils.findArkModelBySignature(type.getSignature(), scene);
|
|
794
|
+
}
|
|
795
|
+
else if (type) {
|
|
796
|
+
model = type;
|
|
797
|
+
}
|
|
798
|
+
if (expr.getRealGenericTypes() !== undefined && originalObject instanceof Type_1.UnclearReferenceType) {
|
|
799
|
+
expr.setRealGenericTypes(originalObject.getGenericTypes());
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (Expr_1.AliasTypeExpr.isAliasTypeOriginalModel(model)) {
|
|
803
|
+
expr.setOriginalObject(model);
|
|
804
|
+
}
|
|
805
|
+
return expr;
|
|
806
|
+
}
|
|
807
|
+
static inferTypeQueryExpr(expr, arkMethod) {
|
|
808
|
+
var _a;
|
|
809
|
+
let gTypes = expr.getGenerateTypes();
|
|
810
|
+
if (gTypes) {
|
|
811
|
+
for (let i = 0; i < gTypes.length; i++) {
|
|
812
|
+
const newType = TypeInference_1.TypeInference.inferUnclearedType(gTypes[i], arkMethod.getDeclaringArkClass());
|
|
813
|
+
if (newType) {
|
|
814
|
+
gTypes[i] = newType;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
const opValue = expr.getOpValue();
|
|
819
|
+
let opValueType;
|
|
820
|
+
if (opValue instanceof ArkBaseModel_1.ArkBaseModel) {
|
|
821
|
+
opValueType = (_a = ModelUtils_1.ModelUtils.parseArkBaseModel2Type(opValue)) !== null && _a !== void 0 ? _a : Type_1.UnknownType.getInstance();
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
opValueType = opValue.getType();
|
|
825
|
+
}
|
|
826
|
+
if (!TypeInference_1.TypeInference.isUnclearType(opValueType)) {
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
if (opValue instanceof Local_1.Local) {
|
|
830
|
+
const newOpValueType = TypeInference_1.TypeInference.inferBaseType(opValue.getName(), arkMethod.getDeclaringArkClass());
|
|
831
|
+
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
832
|
+
if (newOpValueType instanceof Type_1.ClassType) {
|
|
833
|
+
const newOpValue = ModelUtils_1.ModelUtils.findArkModelBySignature(newOpValueType.getClassSignature(), scene);
|
|
834
|
+
if (newOpValue instanceof ArkBaseModel_1.ArkBaseModel) {
|
|
835
|
+
expr.setOpValue(newOpValue);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
else if (newOpValueType instanceof Type_1.FunctionType) {
|
|
839
|
+
const newOpValue = ModelUtils_1.ModelUtils.findArkModelBySignature(newOpValueType.getMethodSignature(), scene);
|
|
840
|
+
if (newOpValue instanceof ArkBaseModel_1.ArkBaseModel) {
|
|
841
|
+
expr.setOpValue(newOpValue);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
this.inferLocal(opValue, arkMethod);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
else if (opValue instanceof Ref_1.AbstractRef || opValue instanceof Expr_1.AbstractExpr) {
|
|
849
|
+
expr.setOpValue(opValue.inferType(arkMethod));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
static inferKeyofTypeExpr(expr, arkMethod) {
|
|
853
|
+
const opType = expr.getOpType();
|
|
854
|
+
if (TypeInference_1.TypeInference.isUnclearType(opType)) {
|
|
855
|
+
if (opType instanceof TypeExpr_1.TypeQueryExpr) {
|
|
856
|
+
this.inferTypeQueryExpr(opType, arkMethod);
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
const type = TypeInference_1.TypeInference.inferUnclearedType(opType, arkMethod.getDeclaringArkClass());
|
|
860
|
+
if (type) {
|
|
861
|
+
expr.setOpType(type);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
static inferParameterRef(ref, arkMethod) {
|
|
867
|
+
var _a, _b, _c;
|
|
868
|
+
const paramType = ref.getType();
|
|
869
|
+
let baseType;
|
|
870
|
+
// If it is a Cxx pointer or reference type, it is necessary to obtain its baseType and determine whether type inference is required.
|
|
871
|
+
if (paramType instanceof Type_2.PointerType || paramType instanceof Type_2.ReferenceType) {
|
|
872
|
+
baseType = paramType.getBaseType();
|
|
873
|
+
if (TypeInference_1.TypeInference.isUnclearType(baseType)) {
|
|
874
|
+
baseType = TypeInference_1.TypeInference.inferUnclearedType(baseType, arkMethod.getDeclaringArkClass());
|
|
875
|
+
if (baseType) {
|
|
876
|
+
paramType.setBaseType(baseType);
|
|
877
|
+
return ref;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (paramType instanceof Type_1.UnknownType || paramType instanceof Type_1.UnclearReferenceType) {
|
|
882
|
+
const signature = (_b = (_a = arkMethod.getDeclareSignatures()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : arkMethod.getSignature();
|
|
883
|
+
const type1 = (_c = signature.getMethodSubSignature().getParameters()[ref.getIndex()]) === null || _c === void 0 ? void 0 : _c.getType();
|
|
884
|
+
if (!TypeInference_1.TypeInference.isUnclearType(type1)) {
|
|
885
|
+
ref.setType(type1);
|
|
886
|
+
return ref;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
else if (paramType instanceof Type_1.LexicalEnvType) {
|
|
890
|
+
paramType
|
|
891
|
+
.getClosures()
|
|
892
|
+
.filter(c => TypeInference_1.TypeInference.isUnclearType(c.getType()))
|
|
893
|
+
.forEach(e => this.inferLocal(e, arkMethod));
|
|
894
|
+
return ref;
|
|
895
|
+
}
|
|
896
|
+
let type = TypeInference_1.TypeInference.inferUnclearedType(paramType, arkMethod.getDeclaringArkClass());
|
|
897
|
+
if (type) {
|
|
898
|
+
ref.setType(type);
|
|
899
|
+
}
|
|
900
|
+
return ref;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* map c++ function declaration to Implementation.
|
|
904
|
+
*
|
|
905
|
+
*This function traverses all C++header files to find the corresponding implementation file for each class and method,
|
|
906
|
+
*And establish the mapping relationship between methods and implementation files
|
|
907
|
+
*/
|
|
908
|
+
static mapCxxDeclAndImpl(scene) {
|
|
909
|
+
const headerFileRefMap = this.getCxxHeaderFileRefMap(scene.getFiles(), scene.getIncludeDirs());
|
|
910
|
+
for (const [headerPath, refFiles] of headerFileRefMap) {
|
|
911
|
+
const headerArkFile = scene.getFile(new ArkSignature_1.FileSignature(scene.getProjectName(), path_1.default.relative(scene.getRealProjectDir(), headerPath)));
|
|
912
|
+
if (!headerArkFile) {
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
const sortedRefFiles = this.sortRefFiles(headerPath, refFiles);
|
|
916
|
+
for (const cls of ModelUtils_1.ModelUtils.getAllClassesInFile(headerArkFile)) {
|
|
917
|
+
const implClasses = this.mapClassDeclAndImpl(sortedRefFiles, cls);
|
|
918
|
+
for (const mtd of cls.getMethods(true)) {
|
|
919
|
+
this.findMtdImpl(mtd, implClasses);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
static mapClassDeclAndImpl(cppFiles, clsInHeader) {
|
|
925
|
+
var _a;
|
|
926
|
+
const implClasses = [];
|
|
927
|
+
const tgtClsName = clsInHeader.getName();
|
|
928
|
+
const tgtNamespaceName = (_a = clsInHeader.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getName();
|
|
929
|
+
for (const cppFile of cppFiles) {
|
|
930
|
+
const refArkClasses = this.getClassWithNameAndNamespace(tgtClsName, cppFile, tgtNamespaceName);
|
|
931
|
+
if (refArkClasses.length !== 1) {
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
implClasses.push(refArkClasses[0]);
|
|
935
|
+
if (tgtClsName === Const_1.DEFAULT_ARK_CLASS_NAME) {
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
refArkClasses[0].setDeclareSignature(clsInHeader.getSignature());
|
|
939
|
+
}
|
|
940
|
+
return implClasses;
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
*Implementation method of search method
|
|
944
|
+
*@ param mtd - Ark method object
|
|
945
|
+
*@ param headerPath - Header file path
|
|
946
|
+
*@ param sortedRefFiles - sorted reference file array
|
|
947
|
+
*/
|
|
948
|
+
static findMtdImpl(mtd, implClasses) {
|
|
949
|
+
if (mtd.getImplementationSignature() || mtd.isDefaultArkMethod() ||
|
|
950
|
+
mtd.getName() === Const_1.INSTANCE_INIT_METHOD_NAME || mtd.getName() === Const_1.STATIC_INIT_METHOD_NAME) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
this.mapHeaderToSource(mtd, implClasses);
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
*Get the C++header file reference mapping table
|
|
957
|
+
*
|
|
958
|
+
*This function traverses all files and filters out C++source files (.cpp ,.c,.cxx),
|
|
959
|
+
*Then analyze the import information in these source files, and establish the reference relationship mapping from the header file to the source file.
|
|
960
|
+
*
|
|
961
|
+
*@ returns Map<string, string []>The mapping from the header file path to the source file path array that references the header file
|
|
962
|
+
*/
|
|
963
|
+
static getCxxHeaderFileRefMap(files, includeDirs) {
|
|
964
|
+
const headerFileRefMap = new Map();
|
|
965
|
+
const cxxSuffixes = (0, const_1.getCxxImplementationFileExtensions)();
|
|
966
|
+
files.forEach(file => {
|
|
967
|
+
const filePath = (0, path_1.normalize)(file.getFilePath());
|
|
968
|
+
const extension = path_1.default.extname(filePath).toLowerCase();
|
|
969
|
+
if (!cxxSuffixes.some(suffix => extension === suffix)) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const importInfos = file.getImportInfos();
|
|
973
|
+
importInfos.forEach(im => {
|
|
974
|
+
this.processImportInfo(im, filePath, headerFileRefMap, includeDirs);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
return headerFileRefMap;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
*Process import information and establish header file reference relationship mapping
|
|
981
|
+
*@ param im Import information object, including imported module information
|
|
982
|
+
*@ param filePath Path of the current file
|
|
983
|
+
*@ param headerFileRefMap header file reference relationship mapping table, used to record which files are referenced by each header file
|
|
984
|
+
*/
|
|
985
|
+
static processImportInfo(im, filePath, headerFileRefMap, includeDirs) {
|
|
986
|
+
let imFrom = im.getFrom();
|
|
987
|
+
if (!imFrom) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (!fs_1.default.existsSync(imFrom)) {
|
|
991
|
+
// If the path does not exist, try to use includeDirs to find the relative path
|
|
992
|
+
imFrom = (0, FileUtils_1.getFileAbsPath)(includeDirs, imFrom);
|
|
993
|
+
if (!imFrom) {
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (!headerFileRefMap.has(imFrom)) {
|
|
998
|
+
headerFileRefMap.set(imFrom, []);
|
|
999
|
+
}
|
|
1000
|
+
headerFileRefMap.get(imFrom).push(im.getDeclaringArkFile());
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
*Sort the reference file array, and prioritize the reference files with the same name as the target file
|
|
1004
|
+
*@ param headerFilePath Destination header file path
|
|
1005
|
+
*@ param refFiles Array of reference file paths to be sorted
|
|
1006
|
+
*@ returns The array of reference file paths sorted, with files with the same name first and other files second
|
|
1007
|
+
*/
|
|
1008
|
+
static sortRefFiles(headerFilePath, refFiles) {
|
|
1009
|
+
const targetFileName = path_1.default.parse(headerFilePath).name;
|
|
1010
|
+
const prioritized = [];
|
|
1011
|
+
const others = [];
|
|
1012
|
+
for (const refFile of refFiles) {
|
|
1013
|
+
if (path_1.default.parse(refFile.getFilePath()).name === targetFileName) {
|
|
1014
|
+
prioritized.push(refFile);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
others.push(refFile);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return [...prioritized, ...others];
|
|
1021
|
+
}
|
|
1022
|
+
static mapHeaderToSource(mtdDecl, implClasses) {
|
|
1023
|
+
const tgtMtdSubSig = mtdDecl.getSubSignature();
|
|
1024
|
+
const matchKey = tgtMtdSubSig.toString().replace('[static]', '');
|
|
1025
|
+
const matchedMtdImpl = this.getMatchedMtdImpl(mtdDecl, implClasses, matchKey);
|
|
1026
|
+
if (matchedMtdImpl) {
|
|
1027
|
+
this.processMethodDeclAndImpl(mtdDecl, matchedMtdImpl);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
static getClassWithNameAndNamespace(clsName, file, namespaceName) {
|
|
1032
|
+
let tgtNamespacesInFile = [];
|
|
1033
|
+
if (namespaceName) {
|
|
1034
|
+
tgtNamespacesInFile = ModelUtils_1.ModelUtils.getAllNamespacesInFile(file).filter(ns => ns.getName() === namespaceName);
|
|
1035
|
+
}
|
|
1036
|
+
const searchedClasses = [];
|
|
1037
|
+
if (tgtNamespacesInFile.length !== 0) {
|
|
1038
|
+
for (const ns of tgtNamespacesInFile) {
|
|
1039
|
+
const classInNamespaceWithName = ns.getClassWithName(clsName);
|
|
1040
|
+
if (classInNamespaceWithName) {
|
|
1041
|
+
searchedClasses.push(classInNamespaceWithName);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
const classInFileWithName = file.getClassWithName(clsName);
|
|
1047
|
+
if (classInFileWithName) {
|
|
1048
|
+
searchedClasses.push(classInFileWithName);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return searchedClasses;
|
|
1052
|
+
}
|
|
1053
|
+
static getMatchedMtdImpl(mtdDecl, refArkClasses, matchKey) {
|
|
1054
|
+
for (const refArkClass of refArkClasses) {
|
|
1055
|
+
const nameMatchingMtds = refArkClass.getAllMethodsWithName(mtdDecl.getName());
|
|
1056
|
+
if (nameMatchingMtds.length === 0) {
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
if (nameMatchingMtds.length === 1) {
|
|
1060
|
+
return nameMatchingMtds[0];
|
|
1061
|
+
}
|
|
1062
|
+
for (const mtdImpl of nameMatchingMtds) {
|
|
1063
|
+
const matchingMtdSubSig = mtdImpl.getSubSignature().toString().replace('[static]', '');
|
|
1064
|
+
if (mtdImpl.getBody() && matchingMtdSubSig === matchKey) {
|
|
1065
|
+
return mtdImpl;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
static processMethodDeclAndImpl(mtdDecl, mtdImpl) {
|
|
1072
|
+
// 1. Set the signature of the function implementation corresponding to the current function declaration
|
|
1073
|
+
const mtdImplSignature = mtdImpl.getImplementationSignature();
|
|
1074
|
+
if (mtdImplSignature) {
|
|
1075
|
+
mtdDecl.setImplementationSignature(mtdImplSignature);
|
|
1076
|
+
}
|
|
1077
|
+
// 2. Set the signature of the function Declaration corresponding to the current function Implementation
|
|
1078
|
+
const declSignature = mtdDecl.getDeclareSignatures();
|
|
1079
|
+
const declSignatureInMtdImpl = mtdImpl.getDeclareSignatures();
|
|
1080
|
+
if (declSignature) {
|
|
1081
|
+
declSignatureInMtdImpl ? declSignatureInMtdImpl.push(...declSignature) : mtdImpl.setDeclareSignatures(declSignature);
|
|
1082
|
+
}
|
|
1083
|
+
// 3.The function implementation may be missing the existing modifiers (such as static) in the function declaration. Here we add
|
|
1084
|
+
mtdImpl.setModifiers(mtdDecl.getModifiers() | mtdImpl.getModifiers());
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
exports.IRInference = IRInference;
|