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,925 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.ArkCxxIRTransformer = void 0;
|
|
41
|
+
const Expr_1 = require("../../../core/base/Expr");
|
|
42
|
+
const Ref_1 = require("../../../core/base/Ref");
|
|
43
|
+
const Local_1 = require("../../../core/base/Local");
|
|
44
|
+
const Stmt_1 = require("../../../core/base/Stmt");
|
|
45
|
+
const Type_1 = require("../../../core/base/Type");
|
|
46
|
+
const ValueUtil_1 = require("./ValueUtil");
|
|
47
|
+
const IRUtils_1 = require("./IRUtils");
|
|
48
|
+
const EtsConst_1 = require("../../../core/common/EtsConst");
|
|
49
|
+
const Position_1 = require("../../../core/base/Position");
|
|
50
|
+
const ArkValueTransformer_1 = require("./ArkValueTransformer");
|
|
51
|
+
const ArkSignature_1 = require("../../../core/model/ArkSignature");
|
|
52
|
+
const Builtin_1 = require("./Builtin");
|
|
53
|
+
const ArkSignatureBuilder_1 = require("../../../core/model/builder/ArkSignatureBuilder");
|
|
54
|
+
const ArkIRTransformer_1 = require("../../../core/common/ArkIRTransformer");
|
|
55
|
+
const TypeExpr_1 = require("../../../core/base/TypeExpr");
|
|
56
|
+
const builderUtils_1 = require("../model/builder/builderUtils");
|
|
57
|
+
const ModelUtils_1 = require("../../../core/common/ModelUtils");
|
|
58
|
+
const ArkClass_1 = require("../../../core/model/ArkClass");
|
|
59
|
+
const ArkClassBuilder_1 = require("../model/builder/ArkClassBuilder");
|
|
60
|
+
const ArkCxxAstNode_1 = require("../ast/ArkCxxAstNode");
|
|
61
|
+
const ValueUtil_2 = require("../../../core/common/ValueUtil");
|
|
62
|
+
const Type_2 = require("../base/Type");
|
|
63
|
+
const builderUtils_2 = require("../../../core/model/builder/builderUtils");
|
|
64
|
+
const logger_1 = __importStar(require("../../../utils/logger"));
|
|
65
|
+
const ArkFileBuilder_1 = require("../model/builder/ArkFileBuilder");
|
|
66
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkIRTransformer');
|
|
67
|
+
function nodeInnerNode(node) {
|
|
68
|
+
if (node.inner && node.inner.length > 0) {
|
|
69
|
+
return node.inner[0];
|
|
70
|
+
}
|
|
71
|
+
console.log('unsupported node !');
|
|
72
|
+
return { kind: 'unsupported kind' };
|
|
73
|
+
}
|
|
74
|
+
class ArkCxxIRTransformer extends ArkIRTransformer_1.ArkIRTransformer {
|
|
75
|
+
constructor(sourceFile, declaringMethod) {
|
|
76
|
+
super(sourceFile, declaringMethod);
|
|
77
|
+
this.catchedExceptions = [];
|
|
78
|
+
this.cxxSourceFile = sourceFile;
|
|
79
|
+
this.ArkCxxValueTransformer = new ArkValueTransformer_1.ArkCxxValueTransformer(this, this.cxxSourceFile, this.declaringMethod);
|
|
80
|
+
}
|
|
81
|
+
getLocals() {
|
|
82
|
+
return this.ArkCxxValueTransformer.getLocals();
|
|
83
|
+
}
|
|
84
|
+
getGlobals() {
|
|
85
|
+
return this.ArkCxxValueTransformer.getGlobals();
|
|
86
|
+
}
|
|
87
|
+
getThisLocal() {
|
|
88
|
+
return this.ArkCxxValueTransformer.getThisLocal();
|
|
89
|
+
}
|
|
90
|
+
getAliasTypeMap() {
|
|
91
|
+
return this.ArkCxxValueTransformer.getAliasTypeMap();
|
|
92
|
+
}
|
|
93
|
+
prebuildStmts() {
|
|
94
|
+
const stmts = [];
|
|
95
|
+
let index = 0;
|
|
96
|
+
for (const methodParameter of this.declaringMethod.getParameters()) {
|
|
97
|
+
const parameterRef = new Ref_1.ArkParameterRef(index, methodParameter.getType());
|
|
98
|
+
stmts.push(new Stmt_1.ArkAssignStmt(this.ArkCxxValueTransformer.addNewLocal(methodParameter.getName(), parameterRef.getType()), parameterRef));
|
|
99
|
+
index++;
|
|
100
|
+
}
|
|
101
|
+
const thisRef = new Ref_1.ArkThisRef(this.ArkCxxValueTransformer.getThisLocal().getType());
|
|
102
|
+
stmts.push(new Stmt_1.ArkAssignStmt(this.ArkCxxValueTransformer.getThisLocal(), thisRef));
|
|
103
|
+
return stmts;
|
|
104
|
+
}
|
|
105
|
+
// Determine whether to generate temporary variable assignment statement based on operator
|
|
106
|
+
shouldGenerateCxxExtraAssignStmt(expression) {
|
|
107
|
+
if (expression.kind === ArkCxxAstNode_1.astKind.ParentExpr) {
|
|
108
|
+
return this.shouldGenerateCxxExtraAssignStmt(expression.inner[0]);
|
|
109
|
+
}
|
|
110
|
+
return !((expression.kind === ArkCxxAstNode_1.astKind.BinaryOperator && expression.opcode === '=') ||
|
|
111
|
+
ArkValueTransformer_1.ArkCxxValueTransformer.isCxxCompoundAssignmentOperator(expression.opcode) ||
|
|
112
|
+
expression.kind === ArkCxxAstNode_1.astKind.CXXNewExpr ||
|
|
113
|
+
expression.kind === ArkCxxAstNode_1.astKind.CallExpr ||
|
|
114
|
+
(expression.kind === ArkCxxAstNode_1.astKind.UnaryOperator && (expression.opcode === '++' || expression.opcode === '--')) ||
|
|
115
|
+
expression.kind === ArkCxxAstNode_1.astKind.CXXOperatorCallExpr ||
|
|
116
|
+
expression.kind === ArkCxxAstNode_1.astKind.CXXConstructExpr ||
|
|
117
|
+
expression.kind === ArkCxxAstNode_1.astKind.CXXCtorInitializer);
|
|
118
|
+
}
|
|
119
|
+
/** The main function for converting C++ AST nodes to Stmts */
|
|
120
|
+
cxxNodeToStmts(node) {
|
|
121
|
+
let stmts = [];
|
|
122
|
+
switch (node.kind) {
|
|
123
|
+
case ArkCxxAstNode_1.astKind.ParmVarDecl:
|
|
124
|
+
stmts = this.cxxParameterToStmts(node);
|
|
125
|
+
break;
|
|
126
|
+
case ArkCxxAstNode_1.astKind.BreakStmt:
|
|
127
|
+
case ArkCxxAstNode_1.astKind.ContinueStmt:
|
|
128
|
+
case ArkCxxAstNode_1.astKind.GotoStmt:
|
|
129
|
+
stmts = [];
|
|
130
|
+
break;
|
|
131
|
+
case ArkCxxAstNode_1.astKind.CXXRewrittenBinaryOperator:
|
|
132
|
+
case ArkCxxAstNode_1.astKind.BinaryOperator:
|
|
133
|
+
case ArkCxxAstNode_1.astKind.CallExpr:
|
|
134
|
+
case ArkCxxAstNode_1.astKind.CompoundAssignOperator:
|
|
135
|
+
case ArkCxxAstNode_1.astKind.CXXConstructExpr:
|
|
136
|
+
case ArkCxxAstNode_1.astKind.CXXOperatorCallExpr:
|
|
137
|
+
case ArkCxxAstNode_1.astKind.UnaryOperator:
|
|
138
|
+
case ArkCxxAstNode_1.astKind.RecoveryExpr:
|
|
139
|
+
case ArkCxxAstNode_1.astKind.CXXDeleteExpr:
|
|
140
|
+
case ArkCxxAstNode_1.astKind.AtomicCallExpr:
|
|
141
|
+
case ArkCxxAstNode_1.astKind.CXXCtorInitializer:
|
|
142
|
+
stmts = this.cxxExpressionStatementToStmts(node);
|
|
143
|
+
break;
|
|
144
|
+
case ArkCxxAstNode_1.astKind.DeclStmt:
|
|
145
|
+
stmts = this.cxxDeclStatementToStmts(node);
|
|
146
|
+
break;
|
|
147
|
+
case ArkCxxAstNode_1.astKind.VarDecl:
|
|
148
|
+
stmts = this.cxxVariableDeclarationListToStmts(node);
|
|
149
|
+
break;
|
|
150
|
+
case ArkCxxAstNode_1.astKind.CompoundStmt:
|
|
151
|
+
stmts = this.compoundToStmts(node);
|
|
152
|
+
break;
|
|
153
|
+
case ArkCxxAstNode_1.astKind.CXXMemberCallExpr:
|
|
154
|
+
stmts = this.memberCallExprToStmts(node);
|
|
155
|
+
break;
|
|
156
|
+
case ArkCxxAstNode_1.astKind.CXXCatchStmt:
|
|
157
|
+
stmts = this.cxxCatchClauseToStmts(node);
|
|
158
|
+
break;
|
|
159
|
+
case ArkCxxAstNode_1.astKind.CXXThrowExpr:
|
|
160
|
+
stmts = this.cxxThrowStatementToStmts(node);
|
|
161
|
+
break;
|
|
162
|
+
case ArkCxxAstNode_1.astKind.DoStmt:
|
|
163
|
+
stmts = this.cxxDoStatementToStmts(node);
|
|
164
|
+
break;
|
|
165
|
+
case ArkCxxAstNode_1.astKind.ExprWithCleanups:
|
|
166
|
+
stmts = this.expressionWithCleanup(node);
|
|
167
|
+
break;
|
|
168
|
+
case ArkCxxAstNode_1.astKind.ForStmt:
|
|
169
|
+
stmts = this.cxxForStatementToStmts(node);
|
|
170
|
+
break;
|
|
171
|
+
case ArkCxxAstNode_1.astKind.IfStmt:
|
|
172
|
+
stmts = this.cxxIfStatementToStmts(node);
|
|
173
|
+
break;
|
|
174
|
+
case ArkCxxAstNode_1.astKind.ReturnStmt:
|
|
175
|
+
stmts = this.cxxReturnStatementToStmts(node);
|
|
176
|
+
break;
|
|
177
|
+
case ArkCxxAstNode_1.astKind.WhileStmt:
|
|
178
|
+
stmts = this.cxxWhileStatementToStmts(node);
|
|
179
|
+
break;
|
|
180
|
+
case ArkCxxAstNode_1.astKind.CXXForRangeStmt:
|
|
181
|
+
stmts = this.forRangeStatementToStmts(node);
|
|
182
|
+
break;
|
|
183
|
+
case ArkCxxAstNode_1.astKind.TypedefDecl:
|
|
184
|
+
case ArkCxxAstNode_1.astKind.TypeAliasDecl:
|
|
185
|
+
stmts = this.typeDefDeclToStmts(node);
|
|
186
|
+
break;
|
|
187
|
+
case ArkCxxAstNode_1.astKind.TypeAliasTemplateDecl:
|
|
188
|
+
stmts = this.typeDefDeclToStmts(node);
|
|
189
|
+
break;
|
|
190
|
+
case ArkCxxAstNode_1.astKind.EnumDecl:
|
|
191
|
+
case ArkCxxAstNode_1.astKind.CXXRecordDecl:
|
|
192
|
+
stmts = this.cxxClassDeclarationToStmts(node);
|
|
193
|
+
break;
|
|
194
|
+
case ArkCxxAstNode_1.astKind.DecompositionDecl:
|
|
195
|
+
stmts = this.decompositionDeclToStmts(node);
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
logger.warn('this ' + node.kind + ' is not supported');
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
this.cxxMapStmtsToTsStmt(stmts, node);
|
|
202
|
+
if (stmts.length > 0) {
|
|
203
|
+
IRUtils_1.IRUtils.setComments(stmts[0], node, this.cxxSourceFile, this.declaringMethod.getDeclaringArkFile().getScene().getOptions());
|
|
204
|
+
}
|
|
205
|
+
return stmts;
|
|
206
|
+
}
|
|
207
|
+
cxxClassDeclarationToStmts(node) {
|
|
208
|
+
const cls = new ArkClass_1.ArkClass();
|
|
209
|
+
const declaringArkNamespace = this.declaringMethod.getDeclaringArkClass().getDeclaringArkNamespace();
|
|
210
|
+
if (declaringArkNamespace) {
|
|
211
|
+
cls.setDeclaringArkNamespace(declaringArkNamespace);
|
|
212
|
+
}
|
|
213
|
+
cls.setDeclaringArkFile(this.declaringMethod.getDeclaringArkFile());
|
|
214
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkMethod)(node, cls, this.cxxSourceFile, this.declaringMethod);
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
typeDefDeclToStmts(typeAliasDeclaration) {
|
|
218
|
+
// 1. Preprocess node to get the actual declaration and type string
|
|
219
|
+
const { rightOp, typeNode } = this.preprocessTypeAlias(typeAliasDeclaration);
|
|
220
|
+
// 2. Resolve the underlying type (handling anonymous types and AbstractTypeExpr)
|
|
221
|
+
let rightType = this.resolveInitialRightType(typeAliasDeclaration);
|
|
222
|
+
// 3. Create the AliasType instance
|
|
223
|
+
const aliasName = typeAliasDeclaration.name;
|
|
224
|
+
const aliasType = new Type_1.AliasType(aliasName, rightType, new ArkSignature_1.AliasTypeSignature(aliasName, this.declaringMethod.getSignature()));
|
|
225
|
+
// 4. Handle Template definitions and 'typename' keyword logic
|
|
226
|
+
this.configureTemplateAndTypename(typeAliasDeclaration, aliasType, rightOp, rightType);
|
|
227
|
+
// 5. Generate the type expression
|
|
228
|
+
const expr = this.cxxGenerateAliasTypeExpr(rightOp, aliasType);
|
|
229
|
+
// 6. Populate real generic types if it is a template declaration
|
|
230
|
+
this.populateRealGenericTypes(typeAliasDeclaration, expr);
|
|
231
|
+
// 7. Set modifiers
|
|
232
|
+
aliasType.setModifiers((0, builderUtils_1.buildModifiers)(typeAliasDeclaration));
|
|
233
|
+
// 8. Create and return the statement
|
|
234
|
+
const stmt = this.createAliasStmt(aliasType, expr, typeAliasDeclaration, typeNode);
|
|
235
|
+
this.getAliasTypeMap().set(aliasName, [aliasType, stmt]);
|
|
236
|
+
return [stmt];
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Extracts the target declaration node and the type string (right operand).
|
|
240
|
+
*/
|
|
241
|
+
preprocessTypeAlias(node) {
|
|
242
|
+
var _a, _b;
|
|
243
|
+
let targetDecl = node;
|
|
244
|
+
if (node.kind === ArkCxxAstNode_1.astKind.TypeAliasTemplateDecl) {
|
|
245
|
+
targetDecl = node.inner[node.inner.length - 1];
|
|
246
|
+
}
|
|
247
|
+
const typeNode = Array.isArray(targetDecl.inner) ? targetDecl.inner[0] : undefined;
|
|
248
|
+
let rightOp = (_b = (_a = node.type) === null || _a === void 0 ? void 0 : _a.desugaredQualType) !== null && _b !== void 0 ? _b : 'unknown';
|
|
249
|
+
if (rightOp === 'unknown') {
|
|
250
|
+
logger.warn(`${node} is a new style that is not supported.`);
|
|
251
|
+
}
|
|
252
|
+
return { targetDecl, rightOp, typeNode };
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Resolves the basic right-hand side type, handling anonymous structs/unions/enums.
|
|
256
|
+
*/
|
|
257
|
+
resolveInitialRightType(node) {
|
|
258
|
+
let rightType = this.getAnonymousInformation(node);
|
|
259
|
+
if (rightType instanceof TypeExpr_1.AbstractTypeExpr) {
|
|
260
|
+
rightType = rightType.getType();
|
|
261
|
+
}
|
|
262
|
+
return rightType;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Configures generics for template aliases and handles the 'typename' keyword.
|
|
266
|
+
*/
|
|
267
|
+
configureTemplateAndTypename(node, aliasType, rightOp, initialRightType) {
|
|
268
|
+
var _a;
|
|
269
|
+
// Handle Template Alias
|
|
270
|
+
if (node.kind === ArkCxxAstNode_1.astKind.TypeAliasTemplateDecl) {
|
|
271
|
+
const genericTypes = (0, builderUtils_1.buildTypeParameters)(node, this.cxxSourceFile, this.declaringMethod);
|
|
272
|
+
aliasType.setGenericTypes(genericTypes);
|
|
273
|
+
aliasType.setOriginalType((0, builderUtils_2.buildGenericType)(initialRightType, aliasType));
|
|
274
|
+
}
|
|
275
|
+
// Handle scenario: template<typename T> using value_type_t = typename T::value_type;
|
|
276
|
+
if (rightOp.startsWith(Builtin_1.BuiltinCxx.TYPENAME_KEYWORD)) {
|
|
277
|
+
const firstGeneric = (_a = aliasType.getGenericTypes()) === null || _a === void 0 ? void 0 : _a[0];
|
|
278
|
+
if (firstGeneric) {
|
|
279
|
+
aliasType.setOriginalType(firstGeneric);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Extracts real generic types from TemplateTypeParmDecl nodes and sets them on the expression.
|
|
285
|
+
*/
|
|
286
|
+
populateRealGenericTypes(node, expr) {
|
|
287
|
+
if (node.kind === ArkCxxAstNode_1.astKind.TypeAliasTemplateDecl) {
|
|
288
|
+
const realGenericTypes = [];
|
|
289
|
+
node.inner.filter(inn => inn.kind === ArkCxxAstNode_1.astKind.TemplateTypeParmDecl)
|
|
290
|
+
.forEach(typeArgument => {
|
|
291
|
+
realGenericTypes.push((0, builderUtils_1.cxxNode2Type)(typeArgument, this.declaringMethod));
|
|
292
|
+
});
|
|
293
|
+
expr.setRealGenericTypes(realGenericTypes);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Constructs the final ArkAliasTypeDefineStmt and sets source positions.
|
|
298
|
+
*/
|
|
299
|
+
createAliasStmt(aliasType, expr, node, typeNode) {
|
|
300
|
+
const stmt = new Stmt_1.ArkAliasTypeDefineStmt(aliasType, expr);
|
|
301
|
+
const leftPosition = Position_1.FullPosition.cxxBuildFromNode(node, this.cxxSourceFile);
|
|
302
|
+
const rightPosition = Position_1.FullPosition.cxxBuildFromNode(typeNode, this.cxxSourceFile);
|
|
303
|
+
stmt.setOperandOriginalPositions([leftPosition, rightPosition]);
|
|
304
|
+
return stmt;
|
|
305
|
+
}
|
|
306
|
+
getAnonymousInformation(node) {
|
|
307
|
+
if (node.inner.length === 0 && node.originalId) {
|
|
308
|
+
const cls = ArkFileBuilder_1.classMap.get(node.originalId);
|
|
309
|
+
if (cls) {
|
|
310
|
+
return new Type_1.ClassType(cls.getSignature());
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return (0, builderUtils_1.cxxNode2Type)(node, this.declaringMethod);
|
|
314
|
+
}
|
|
315
|
+
// When there are default parameters, how to handle them
|
|
316
|
+
cxxParameterToStmts(parameter) {
|
|
317
|
+
const stmts = [];
|
|
318
|
+
let paramName = parameter.name;
|
|
319
|
+
const paramLocal = Array.from(this.getLocals()).find(local => local.getName() === paramName);
|
|
320
|
+
if (paramLocal === undefined) {
|
|
321
|
+
return stmts;
|
|
322
|
+
}
|
|
323
|
+
// Inner contains only one element, indicating that no default value has been declared
|
|
324
|
+
const length = parameter.inner.length;
|
|
325
|
+
if (parameter.inner[0].code === 'maybe_unused' && length === 1) {
|
|
326
|
+
return stmts;
|
|
327
|
+
}
|
|
328
|
+
// The last element is the default value
|
|
329
|
+
const { value: paramInitValue, valueOriginalPositions: paramInitPositions, stmts: paramInitStmts, } = this.cxxNodeToValueAndStmts(parameter.inner[length - 1]);
|
|
330
|
+
stmts.push(...paramInitStmts);
|
|
331
|
+
const ifStmt = new Stmt_1.ArkIfStmt(new Expr_1.ArkConditionExpr(paramLocal, ValueUtil_2.ValueUtil.getUndefinedConst(), Expr_1.RelationalBinaryOperator.Equality));
|
|
332
|
+
ifStmt.setOperandOriginalPositions([Position_1.FullPosition.DEFAULT, Position_1.FullPosition.DEFAULT]);
|
|
333
|
+
stmts.push(ifStmt);
|
|
334
|
+
const currConditionalOperatorIndex = this.arkValueTransformer.conditionalOperatorNo++;
|
|
335
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT + currConditionalOperatorIndex));
|
|
336
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(paramLocal, paramInitValue);
|
|
337
|
+
assignStmt.setOperandOriginalPositions([Position_1.FullPosition.DEFAULT, ...paramInitPositions]);
|
|
338
|
+
stmts.push(assignStmt);
|
|
339
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorIndex));
|
|
340
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT + currConditionalOperatorIndex));
|
|
341
|
+
return stmts;
|
|
342
|
+
}
|
|
343
|
+
cxxGenerateAliasTypeExpr(rightOp, aliasType) {
|
|
344
|
+
let rightType = aliasType.getOriginalType();
|
|
345
|
+
let expr;
|
|
346
|
+
expr = new Expr_1.AliasTypeExpr(rightType, false);
|
|
347
|
+
// For statements like type A = {x:1, y:2}, the ClassType can be accurately obtained at this stage,
|
|
348
|
+
// and the corresponding ArkClass needs to be found as originalObject.
|
|
349
|
+
// For other cases, this is UnclearReferenceType here and will be found and processed by type inference
|
|
350
|
+
if (rightType instanceof Type_1.ClassType) {
|
|
351
|
+
const classObject = ModelUtils_1.ModelUtils.getClassWithName(rightType.getClassSignature().getClassName(), this.declaringMethod.getDeclaringArkClass());
|
|
352
|
+
if (classObject) {
|
|
353
|
+
expr.setOriginalObject(classObject);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return expr;
|
|
357
|
+
}
|
|
358
|
+
forRangeStatementToStmts(forOfStatement) {
|
|
359
|
+
const stmts = [];
|
|
360
|
+
let entry = forOfStatement.inner[1];
|
|
361
|
+
// Handle iterable initialization
|
|
362
|
+
let { iterablePositions, iteratorInvokeExpr, iteratorInvokeExprPositions, } = this.handleForRangeIterInit(entry, stmts);
|
|
363
|
+
const base = iteratorInvokeExpr.getBase();
|
|
364
|
+
// Handle iterable begin
|
|
365
|
+
const { iterator, doneFieldRef, doneFieldRefPositions, } = this.handleForRangeIterBegin(iteratorInvokeExpr, iteratorInvokeExprPositions, stmts, iterablePositions, base);
|
|
366
|
+
// Handle iterable end
|
|
367
|
+
const { iteratorNextInvokeExpr, iteratorNextInvokeExprPositions, } = this.handleForRangeIterEnd(doneFieldRef, doneFieldRefPositions, stmts, iterator);
|
|
368
|
+
// Handle iterable result value
|
|
369
|
+
const { valueFieldRef, valueFieldRefPositions, } = this.handleForRangeIterResult(iteratorNextInvokeExpr, iteratorNextInvokeExprPositions, stmts, iterator);
|
|
370
|
+
// Handle whether iterable is finished
|
|
371
|
+
const { value: yieldValue, valueOriginalPositions: yieldValuePositions, stmts: yieldValueStmts, } = this.generateAssignStmtForValue(valueFieldRef, valueFieldRefPositions);
|
|
372
|
+
stmts.push(...yieldValueStmts);
|
|
373
|
+
const castExpr = new Expr_1.ArkCastExpr(yieldValue, Type_1.UnknownType.getInstance());
|
|
374
|
+
const castExprPositions = [yieldValuePositions[0], ...yieldValuePositions];
|
|
375
|
+
let declStmts = forOfStatement.inner[0];
|
|
376
|
+
declStmts = declStmts.kind === ArkCxxAstNode_1.astKind.DeclStmt ? declStmts.inner[0] : declStmts;
|
|
377
|
+
if (declStmts.kind === ArkCxxAstNode_1.astKind.VarDecl) {
|
|
378
|
+
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.ArkCxxValueTransformer.cxxVariableDeclarationToValueAndStmts(declStmts, false);
|
|
379
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
380
|
+
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
381
|
+
stmts.push(assignStmt);
|
|
382
|
+
stmts.push(...initStmts);
|
|
383
|
+
// Processing structured binding under cyclic conditions
|
|
384
|
+
}
|
|
385
|
+
else if (declStmts.kind === ArkCxxAstNode_1.astKind.DecompositionDecl) {
|
|
386
|
+
const { stmts: initStmts, } = this.ArkCxxValueTransformer.bindingNodeToValueAndStmts(declStmts, yieldValue);
|
|
387
|
+
stmts.push(...initStmts);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const { value: initValue, valueOriginalPositions: initOriPos, stmts: initStmts, } = this.cxxNodeToValueAndStmts(declStmts);
|
|
391
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(initValue, castExpr);
|
|
392
|
+
assignStmt.setOperandOriginalPositions([...initOriPos, ...castExprPositions]);
|
|
393
|
+
stmts.push(...initStmts);
|
|
394
|
+
stmts.push(assignStmt);
|
|
395
|
+
}
|
|
396
|
+
return stmts;
|
|
397
|
+
}
|
|
398
|
+
handleForRangeIterInit(entry, stmts) {
|
|
399
|
+
let { value: iterableValue, valueOriginalPositions: iterablePositions, stmts: iterableStmts, } = this.cxxNodeToValueAndStmts(entry);
|
|
400
|
+
stmts.push(...iterableStmts);
|
|
401
|
+
if (!(iterableValue instanceof Local_1.Local)) {
|
|
402
|
+
({
|
|
403
|
+
value: iterableValue,
|
|
404
|
+
valueOriginalPositions: iterablePositions,
|
|
405
|
+
stmts: iterableStmts,
|
|
406
|
+
} = this.generateAssignStmtForValue(iterableValue, iterablePositions));
|
|
407
|
+
stmts.push(...iterableStmts);
|
|
408
|
+
}
|
|
409
|
+
const iteratorMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.BuiltinCxx.ITERATOR_FUNCTION, [], Builtin_1.BuiltinCxx.ITERATOR_CLASS_TYPE);
|
|
410
|
+
const iteratorMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, iteratorMethodSubSignature);
|
|
411
|
+
const iteratorInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterableValue, iteratorMethodSignature, []);
|
|
412
|
+
const iteratorInvokeExprPositions = [iterablePositions[0], ...iterablePositions];
|
|
413
|
+
return { iterablePositions, iteratorInvokeExpr, iteratorInvokeExprPositions };
|
|
414
|
+
}
|
|
415
|
+
handleForRangeIterBegin(iteratorInvokeExpr, iteratorInvokeExprPositions, stmts, iterablePositions, base) {
|
|
416
|
+
const { value: iterator, valueOriginalPositions: iteratorPositions, stmts: iteratorStmts, } = this.generateAssignStmtForValue(iteratorInvokeExpr, iteratorInvokeExprPositions);
|
|
417
|
+
stmts.push(...iteratorStmts);
|
|
418
|
+
if (iterator instanceof Local_1.Local) {
|
|
419
|
+
iterator.setType(Builtin_1.BuiltinCxx.ITERATOR_CLASS_TYPE);
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
logger.error(logger_1.LOG_MODULE_TYPE.DEFAULT, 'iterator is not a local');
|
|
423
|
+
}
|
|
424
|
+
const baseType = base.getType();
|
|
425
|
+
const beginFieldSignature = baseType instanceof Type_1.ClassType ? new ArkSignature_1.FieldSignature(Builtin_1.BuiltinCxx.ITERATOR_RESULT_BEGIN, baseType.getClassSignature(), Type_1.BooleanType.getInstance(), false) :
|
|
426
|
+
new ArkSignature_1.FieldSignature(Builtin_1.BuiltinCxx.ITERATOR_RESULT_BEGIN, Builtin_1.BuiltinCxx.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.BooleanType.getInstance(), false);
|
|
427
|
+
const beginFieldRef = new Ref_1.ArkInstanceFieldRef(base, beginFieldSignature);
|
|
428
|
+
const beginStmt = new Stmt_1.ArkAssignStmt(iterator, beginFieldRef);
|
|
429
|
+
stmts.push(beginStmt);
|
|
430
|
+
const dummyInitializerStmt = new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
431
|
+
stmts.push(dummyInitializerStmt);
|
|
432
|
+
const doneFieldSignature = baseType instanceof Type_1.ClassType ? new ArkSignature_1.FieldSignature(Builtin_1.BuiltinCxx.ITERATOR_RESULT_END, baseType.getClassSignature(), Type_1.BooleanType.getInstance(), false) :
|
|
433
|
+
new ArkSignature_1.FieldSignature(Builtin_1.BuiltinCxx.ITERATOR_RESULT_END, Builtin_1.BuiltinCxx.ITERATOR_RESULT_CLASS_SIGNATURE, Type_1.BooleanType.getInstance(), false);
|
|
434
|
+
const doneFieldRef = new Ref_1.ArkInstanceFieldRef(base, doneFieldSignature);
|
|
435
|
+
const doneFieldRefPositions = [iteratorPositions[0], ...iterablePositions];
|
|
436
|
+
return { iterator, doneFieldRef, doneFieldRefPositions };
|
|
437
|
+
}
|
|
438
|
+
handleForRangeIterEnd(doneFieldRef, doneFieldRefPositions, stmts, iterator) {
|
|
439
|
+
const { value: doneFlag, valueOriginalPositions: doneFlagPositions, stmts: doneFlagStmts, } = this.generateAssignStmtForValue(doneFieldRef, doneFieldRefPositions);
|
|
440
|
+
stmts.push(...doneFlagStmts);
|
|
441
|
+
doneFlag.setType(Type_1.BooleanType.getInstance());
|
|
442
|
+
const conditionExpr = new Expr_1.ArkConditionExpr(iterator, doneFlag, Expr_1.RelationalBinaryOperator.Equality);
|
|
443
|
+
const conditionExprPositions = [doneFlagPositions[0], ...doneFlagPositions, Position_1.FullPosition.DEFAULT];
|
|
444
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
445
|
+
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
446
|
+
stmts.push(ifStmt);
|
|
447
|
+
const nextMethodSubSignature = new ArkSignature_1.MethodSubSignature(Builtin_1.BuiltinCxx.ITERATOR_NEXT, [], Builtin_1.BuiltinCxx.ITERATOR_RESULT_CLASS_TYPE);
|
|
448
|
+
const nextMethodSignature = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, nextMethodSubSignature);
|
|
449
|
+
const iteratorNextInvokeExpr = new Expr_1.ArkInstanceInvokeExpr(iterator, nextMethodSignature, []);
|
|
450
|
+
const iteratorNextInvokeExprPositions = [doneFieldRefPositions[0], ...doneFieldRefPositions];
|
|
451
|
+
return { iteratorNextInvokeExpr, iteratorNextInvokeExprPositions };
|
|
452
|
+
}
|
|
453
|
+
handleForRangeIterResult(iteratorNextInvokeExpr, iteratorNextInvokeExprPositions, stmts, iterator) {
|
|
454
|
+
const nextStmt = new Stmt_1.ArkAssignStmt(iterator, iteratorNextInvokeExpr);
|
|
455
|
+
stmts.push(nextStmt);
|
|
456
|
+
const valueFieldSignature = new ArkSignature_1.FieldSignature(Builtin_1.BuiltinCxx.ITERATOR_VALUE, Builtin_1.BuiltinCxx.ITERATOR_CLASS_SIGNATURE, Type_1.UnknownType.getInstance(), false);
|
|
457
|
+
const valueFieldRef = new Ref_1.ArkInstanceFieldRef(iterator, valueFieldSignature);
|
|
458
|
+
const valueFieldRefPositions = [iteratorNextInvokeExprPositions[0], ...iteratorNextInvokeExprPositions];
|
|
459
|
+
return { valueFieldRef, valueFieldRefPositions };
|
|
460
|
+
}
|
|
461
|
+
cxxCatchClauseToStmts(catchClause) {
|
|
462
|
+
const stmts = [];
|
|
463
|
+
// When the scenario is catch (...), inner [0] is the exception handling content, and in other cases, it is the exception type
|
|
464
|
+
if (catchClause.inner && catchClause.inner.length > 1) {
|
|
465
|
+
const { value: catchValue, valueOriginalPositions: catchOriPos, stmts: catchStmts, } = this.ArkCxxValueTransformer.cxxVariableDeclarationToValueAndStmts(catchClause.inner[0], false);
|
|
466
|
+
this.catchedExceptions.push(catchValue);
|
|
467
|
+
const caughtExceptionRef = new Ref_1.ArkCaughtExceptionRef(catchValue.getType());
|
|
468
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(catchValue, caughtExceptionRef);
|
|
469
|
+
assignStmt.setOperandOriginalPositions(catchOriPos);
|
|
470
|
+
stmts.push(assignStmt);
|
|
471
|
+
stmts.push(...catchStmts);
|
|
472
|
+
}
|
|
473
|
+
else { // When the scenario is catch (...)
|
|
474
|
+
const caughtExceptionRef = new Ref_1.ArkCaughtExceptionRef(Type_1.AnyType.getInstance());
|
|
475
|
+
const catchValue = new Local_1.Local('error');
|
|
476
|
+
this.catchedExceptions.push(catchValue);
|
|
477
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(catchValue, caughtExceptionRef);
|
|
478
|
+
assignStmt.setOriginPositionInfo(Position_1.LineColPosition.cxxBuildFromNode(catchClause));
|
|
479
|
+
stmts.push(assignStmt);
|
|
480
|
+
}
|
|
481
|
+
return stmts;
|
|
482
|
+
}
|
|
483
|
+
/** The main function for converting C++ AST nodes to ValueAndStmts */
|
|
484
|
+
cxxNodeToValueAndStmts(node) {
|
|
485
|
+
return this.ArkCxxValueTransformer.cxxNodeToValueAndStmts(node);
|
|
486
|
+
}
|
|
487
|
+
cxxReturnStatementToStmts(returnStatement) {
|
|
488
|
+
const stmts = [];
|
|
489
|
+
if (returnStatement.inner.length > 0) {
|
|
490
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprStmts, } = this.cxxNodeToValueAndStmts(returnStatement.inner[0]);
|
|
491
|
+
stmts.push(...exprStmts);
|
|
492
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
493
|
+
({
|
|
494
|
+
value: exprValue,
|
|
495
|
+
valueOriginalPositions: exprPositions,
|
|
496
|
+
stmts: exprStmts,
|
|
497
|
+
} = this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
498
|
+
stmts.push(...exprStmts);
|
|
499
|
+
}
|
|
500
|
+
const returnStmt = new Stmt_1.ArkReturnStmt(exprValue);
|
|
501
|
+
returnStmt.setOperandOriginalPositions(exprPositions);
|
|
502
|
+
stmts.push(returnStmt);
|
|
503
|
+
if (this.declaringMethod.getSubSignature().getReturnType() instanceof Type_1.UnknownType) {
|
|
504
|
+
this.declaringMethod.getSubSignature().setReturnType(exprValue.getType());
|
|
505
|
+
}
|
|
506
|
+
return stmts;
|
|
507
|
+
}
|
|
508
|
+
stmts.push(new Stmt_1.ArkReturnVoidStmt());
|
|
509
|
+
if (this.declaringMethod.getSubSignature().getReturnType() instanceof Type_1.UnknownType) {
|
|
510
|
+
this.declaringMethod.getSubSignature().setReturnType(Type_1.VoidType.getInstance());
|
|
511
|
+
}
|
|
512
|
+
return stmts;
|
|
513
|
+
}
|
|
514
|
+
cxxExpressionStatementToStmts(expressionStatement) {
|
|
515
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts, } = this.cxxNodeToValueAndStmts(expressionStatement);
|
|
516
|
+
if (exprValue instanceof Expr_1.AbstractInvokeExpr) {
|
|
517
|
+
this.cxxAddInvokeStmts(exprValue, exprPositions, stmts);
|
|
518
|
+
}
|
|
519
|
+
else if (this.shouldGenerateCxxExtraAssignStmt(expressionStatement)) {
|
|
520
|
+
const { stmts: exprStmts } = this.generateAssignStmtForValue(exprValue, exprPositions);
|
|
521
|
+
stmts.push(...exprStmts);
|
|
522
|
+
}
|
|
523
|
+
return stmts;
|
|
524
|
+
}
|
|
525
|
+
cxxAddInvokeStmts(invokeExpr, exprPositions, stmts) {
|
|
526
|
+
const invokeStmt = new Stmt_1.ArkInvokeStmt(invokeExpr);
|
|
527
|
+
invokeStmt.setOperandOriginalPositions(exprPositions);
|
|
528
|
+
stmts.push(invokeStmt);
|
|
529
|
+
let hasRepeat = false;
|
|
530
|
+
for (const stmt of stmts) {
|
|
531
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
532
|
+
const rightOp = stmt.getRightOp();
|
|
533
|
+
if (rightOp.getMethodSignature().getMethodSubSignature().getMethodName() === EtsConst_1.COMPONENT_REPEAT) {
|
|
534
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
535
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, rightOp.getArgs());
|
|
536
|
+
stmt.setRightOp(createInvokeExpr);
|
|
537
|
+
hasRepeat = true;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (hasRepeat) {
|
|
542
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
543
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
544
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
545
|
+
stmts.push(popInvokeStmt);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/** Convert C++ switch statements to ValueAndStmts */
|
|
549
|
+
cxxSwitchStatementToValueAndStmts(switchStatement) {
|
|
550
|
+
// switchNode.inner[length - 2] is the value
|
|
551
|
+
const valueAndStmtsOfSwitchAndCases = [];
|
|
552
|
+
const exprStmts = [];
|
|
553
|
+
for (let i = 0; i < switchStatement.inner.length - 2; i++) {
|
|
554
|
+
exprStmts.push(...this.cxxNodeToValueAndStmts(switchStatement.inner[i]).stmts);
|
|
555
|
+
}
|
|
556
|
+
let { value: exprValue, valueOriginalPositions: exprPositions, stmts: exprTempStmts, } = this.cxxNodeToValueAndStmts(switchStatement.inner[switchStatement.inner.length - 2]);
|
|
557
|
+
exprStmts.push(...exprTempStmts);
|
|
558
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(exprValue)) {
|
|
559
|
+
({
|
|
560
|
+
value: exprValue,
|
|
561
|
+
valueOriginalPositions: exprPositions,
|
|
562
|
+
stmts: exprTempStmts,
|
|
563
|
+
} = this.generateAssignStmtForValue(exprValue, exprPositions));
|
|
564
|
+
exprStmts.push(...exprTempStmts);
|
|
565
|
+
}
|
|
566
|
+
valueAndStmtsOfSwitchAndCases.push({
|
|
567
|
+
value: exprValue,
|
|
568
|
+
valueOriginalPositions: exprPositions,
|
|
569
|
+
stmts: exprStmts,
|
|
570
|
+
});
|
|
571
|
+
// switchNode.inner[length - 1] is the cases
|
|
572
|
+
for (const clause of switchStatement.inner[switchStatement.inner.length - 1].inner) {
|
|
573
|
+
if (clause.kind.toString() === ArkCxxAstNode_1.astKind.CaseStmt) {
|
|
574
|
+
const clauseStmts = [];
|
|
575
|
+
let { value: clauseValue, valueOriginalPositions: clausePositions, stmts: clauseTempStmts, } = this.cxxNodeToValueAndStmts(clause.inner[0]);
|
|
576
|
+
clauseStmts.push(...clauseTempStmts);
|
|
577
|
+
if (IRUtils_1.IRUtils.moreThanOneAddress(clauseValue)) {
|
|
578
|
+
({
|
|
579
|
+
value: clauseValue,
|
|
580
|
+
valueOriginalPositions: clausePositions,
|
|
581
|
+
stmts: clauseTempStmts,
|
|
582
|
+
} = this.generateAssignStmtForValue(clauseValue, clausePositions));
|
|
583
|
+
clauseStmts.push(...clauseTempStmts);
|
|
584
|
+
}
|
|
585
|
+
valueAndStmtsOfSwitchAndCases.push({
|
|
586
|
+
value: clauseValue,
|
|
587
|
+
valueOriginalPositions: clausePositions,
|
|
588
|
+
stmts: clauseStmts,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return valueAndStmtsOfSwitchAndCases;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Convert C++for statement nodes to Ark IR statement arrays
|
|
596
|
+
* Under forStmt, there will be 5 child nodes. Taking for (a ; b; c) as an example,
|
|
597
|
+
* the content of block a is at node 0, if block b contains assignments, it will be at node 1,
|
|
598
|
+
* the Boolean judgment of block b is at node 2, the successor operation of block c's loop body is at node 3,
|
|
599
|
+
* and the loop body is at node 4
|
|
600
|
+
* @param forStatement -The for statement node in C++AST
|
|
601
|
+
* @returns Converted Ark IR statement array
|
|
602
|
+
*/
|
|
603
|
+
cxxForStatementToStmts(forStatement) {
|
|
604
|
+
const stmts = [];
|
|
605
|
+
let initNode;
|
|
606
|
+
let conditionNoe;
|
|
607
|
+
let incrementor;
|
|
608
|
+
// The complete for structure allocates corresponding statements in order, so we need to process them in order.
|
|
609
|
+
if (forStatement.inner.length === 5) {
|
|
610
|
+
initNode = forStatement.inner.slice(0, 2);
|
|
611
|
+
conditionNoe = forStatement.inner[2];
|
|
612
|
+
incrementor = forStatement.inner[3];
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
logger.error('Current node syntax tree generation error');
|
|
616
|
+
return stmts;
|
|
617
|
+
}
|
|
618
|
+
if (initNode) {
|
|
619
|
+
initNode.forEach(node => this.cxxNodeToStmts(node).forEach(stmt => stmts.push(stmt)));
|
|
620
|
+
}
|
|
621
|
+
const dummyInitializerStmt = new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
622
|
+
stmts.push(dummyInitializerStmt);
|
|
623
|
+
if (conditionNoe.kind === undefined) {
|
|
624
|
+
// The omitted condition always evaluates to true.
|
|
625
|
+
const trueConstant = ValueUtil_1.CxxValueUtil.getBooleanConstant(true);
|
|
626
|
+
const conditionExpr = new Expr_1.ArkConditionExpr(trueConstant, trueConstant, Expr_1.RelationalBinaryOperator.Equality);
|
|
627
|
+
stmts.push(new Stmt_1.ArkIfStmt(conditionExpr));
|
|
628
|
+
}
|
|
629
|
+
else if (conditionNoe) {
|
|
630
|
+
stmts.push(...this.cxxIfStatementToStmts(conditionNoe));
|
|
631
|
+
}
|
|
632
|
+
if (incrementor) {
|
|
633
|
+
stmts.push(...this.cxxNodeToValueAndStmts(incrementor).stmts);
|
|
634
|
+
}
|
|
635
|
+
return stmts;
|
|
636
|
+
}
|
|
637
|
+
cxxWhileStatementToStmts(whileStatement) {
|
|
638
|
+
const stmts = [];
|
|
639
|
+
const dummyInitializerStmt = new ArkIRTransformer_1.DummyStmt(ArkIRTransformer_1.ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT);
|
|
640
|
+
stmts.push(dummyInitializerStmt);
|
|
641
|
+
stmts.push(...this.cxxIfStatementToStmts(whileStatement.inner[0]));
|
|
642
|
+
return stmts;
|
|
643
|
+
}
|
|
644
|
+
cxxDoStatementToStmts(doStatement) {
|
|
645
|
+
const stmts = [];
|
|
646
|
+
stmts.push(...this.cxxIfStatementToStmts(doStatement.inner[1]));
|
|
647
|
+
return stmts;
|
|
648
|
+
}
|
|
649
|
+
expressionWithCleanup(exprWithCleanup) {
|
|
650
|
+
return this.expressionToStmts(nodeInnerNode(exprWithCleanup));
|
|
651
|
+
}
|
|
652
|
+
compoundToStmts(expressionStatement) {
|
|
653
|
+
return this.memberCallExpressionToStmts(expressionStatement.inner[0]);
|
|
654
|
+
}
|
|
655
|
+
memberCallExprToStmts(expressionStatement) {
|
|
656
|
+
return this.memberCallExpressionToStmts(expressionStatement);
|
|
657
|
+
}
|
|
658
|
+
memberCallExpressionToStmts(expression) {
|
|
659
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts, } = this.cxxNodeToValueAndStmts(expression);
|
|
660
|
+
if (exprValue instanceof Expr_1.AbstractInvokeExpr) {
|
|
661
|
+
const invokeStmt = new Stmt_1.ArkInvokeStmt(exprValue);
|
|
662
|
+
invokeStmt.setOperandOriginalPositions(exprPositions);
|
|
663
|
+
stmts.push(invokeStmt);
|
|
664
|
+
let hasRepeat = false;
|
|
665
|
+
for (const stmt of stmts) {
|
|
666
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (!(stmt.getRightOp() instanceof Expr_1.ArkStaticInvokeExpr)) {
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
const rightOp = stmt.getRightOp();
|
|
673
|
+
if (rightOp.getMethodSignature().getMethodSubSignature().getMethodName() !== EtsConst_1.COMPONENT_REPEAT) {
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
677
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, rightOp.getArgs());
|
|
678
|
+
stmt.setRightOp(createInvokeExpr);
|
|
679
|
+
hasRepeat = true;
|
|
680
|
+
}
|
|
681
|
+
if (hasRepeat) {
|
|
682
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
683
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
684
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
685
|
+
stmts.push(popInvokeStmt);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
else if (exprValue instanceof Expr_1.AbstractExpr) {
|
|
689
|
+
const { stmts: exprStmts } = this.generateAssignStmtForValue(exprValue, exprPositions);
|
|
690
|
+
stmts.push(...exprStmts);
|
|
691
|
+
}
|
|
692
|
+
return stmts;
|
|
693
|
+
}
|
|
694
|
+
expressionToStmts(expression) {
|
|
695
|
+
var _a;
|
|
696
|
+
const { value: exprValue, valueOriginalPositions: exprPositions, stmts: stmts, } = this.cxxNodeToValueAndStmts(expression);
|
|
697
|
+
if (exprValue instanceof Expr_1.AbstractInvokeExpr) {
|
|
698
|
+
const invokeStmt = new Stmt_1.ArkInvokeStmt(exprValue);
|
|
699
|
+
invokeStmt.setOperandOriginalPositions(exprPositions);
|
|
700
|
+
stmts.push(invokeStmt);
|
|
701
|
+
let hasRepeat = false;
|
|
702
|
+
for (const stmt of stmts) {
|
|
703
|
+
// Not an assignment statement: skip
|
|
704
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const rightOp = (_a = stmt.getRightOp) === null || _a === void 0 ? void 0 : _a.call(stmt); // 如果可能没有这个方法,用可选调用更安全
|
|
708
|
+
// Right side does not exist or is not a static call: skip
|
|
709
|
+
if (!(rightOp instanceof Expr_1.ArkStaticInvokeExpr)) {
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
const methodName = rightOp.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
713
|
+
// Not COMPONENT_REPEAT: skip
|
|
714
|
+
if (methodName !== EtsConst_1.COMPONENT_REPEAT) {
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
const createMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_CREATE_FUNCTION);
|
|
718
|
+
const createInvokeExpr = new Expr_1.ArkStaticInvokeExpr(createMethodSignature, rightOp.getArgs());
|
|
719
|
+
stmt.setRightOp(createInvokeExpr);
|
|
720
|
+
hasRepeat = true;
|
|
721
|
+
}
|
|
722
|
+
if (hasRepeat) {
|
|
723
|
+
const popMethodSignature = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(EtsConst_1.COMPONENT_REPEAT, EtsConst_1.COMPONENT_POP_FUNCTION);
|
|
724
|
+
const popInvokeExpr = new Expr_1.ArkStaticInvokeExpr(popMethodSignature, []);
|
|
725
|
+
const popInvokeStmt = new Stmt_1.ArkInvokeStmt(popInvokeExpr);
|
|
726
|
+
stmts.push(popInvokeStmt);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else if (exprValue instanceof Expr_1.AbstractExpr) {
|
|
730
|
+
const { stmts: exprStmts } = this.generateAssignStmtForValue(exprValue, exprPositions);
|
|
731
|
+
stmts.push(...exprStmts);
|
|
732
|
+
}
|
|
733
|
+
return stmts;
|
|
734
|
+
}
|
|
735
|
+
cxxDeclStatementToStmts(declStatement) {
|
|
736
|
+
const stmts = [];
|
|
737
|
+
if (declStatement.inner.length === 0) {
|
|
738
|
+
return this.ArkCxxValueTransformer.cxxVariableDeclarationToValueAndStmts(declStatement).stmts;
|
|
739
|
+
}
|
|
740
|
+
for (const child of declStatement.inner) {
|
|
741
|
+
const childStmts = this.cxxNodeToStmts(child);
|
|
742
|
+
stmts.push(...childStmts);
|
|
743
|
+
}
|
|
744
|
+
return stmts;
|
|
745
|
+
}
|
|
746
|
+
decompositionDeclToStmts(decompositionDecl) {
|
|
747
|
+
return this.ArkCxxValueTransformer.bindingNodeToValueAndStmts(decompositionDecl).stmts;
|
|
748
|
+
}
|
|
749
|
+
cxxVariableDeclarationListToStmts(variableDeclarationList) {
|
|
750
|
+
return this.ArkCxxValueTransformer.cxxVariableDeclarationToValueAndStmts(variableDeclarationList).stmts;
|
|
751
|
+
}
|
|
752
|
+
cxxIfStatementToStmts(ifStatement, depth = 0, context) {
|
|
753
|
+
const stmts = [];
|
|
754
|
+
if (ifStatement.kind === ArkCxxAstNode_1.astKind.IfStmt) {
|
|
755
|
+
return this.cxxIfStatementToStmts(ifStatement.inner[0], depth);
|
|
756
|
+
}
|
|
757
|
+
else if (ifStatement.kind === ArkCxxAstNode_1.astKind.BinaryOperator && ifStatement.opcode === '||') {
|
|
758
|
+
// || The child of a node must have two child nodes
|
|
759
|
+
stmts.push(...this.cxxIfStatementToStmts(ifStatement.inner[0], depth + 1));
|
|
760
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkCxxIRTransformer.DUMMY_IF_OPERATOR_OR_SIGNAL + depth));
|
|
761
|
+
stmts.push(...this.cxxIfStatementToStmts(ifStatement.inner[1], depth + 1));
|
|
762
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkCxxIRTransformer.DUMMY_IF_OPERATOR_END + depth));
|
|
763
|
+
}
|
|
764
|
+
else if (ifStatement.kind === ArkCxxAstNode_1.astKind.BinaryOperator && ifStatement.opcode === '&&') {
|
|
765
|
+
// && The child of a node must have two child nodes
|
|
766
|
+
stmts.push(...this.cxxIfStatementToStmts(ifStatement.inner[0], depth + 1));
|
|
767
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkCxxIRTransformer.DUMMY_IF_OPERATOR_AND_SIGNAL + depth));
|
|
768
|
+
stmts.push(...this.cxxIfStatementToStmts(ifStatement.inner[1], depth + 1));
|
|
769
|
+
stmts.push(new ArkIRTransformer_1.DummyStmt(ArkCxxIRTransformer.DUMMY_IF_OPERATOR_END + depth));
|
|
770
|
+
}
|
|
771
|
+
else if (ifStatement.kind === ArkCxxAstNode_1.astKind.ParenExpr) {
|
|
772
|
+
return this.cxxIfStatementToStmts(ifStatement.inner[0], depth);
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
const { value: conditionExpr, valueOriginalPositions: conditionExprPositions, stmts: conditionStmts } = this.ArkCxxValueTransformer.cxxConditionToValueAndStmts(ifStatement);
|
|
776
|
+
stmts.push(...conditionStmts);
|
|
777
|
+
const ifStmt = new Stmt_1.ArkIfStmt(conditionExpr);
|
|
778
|
+
ifStmt.setOperandOriginalPositions(conditionExprPositions);
|
|
779
|
+
stmts.push(ifStmt);
|
|
780
|
+
if (context) {
|
|
781
|
+
context.conditionExpr = conditionExpr;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return stmts;
|
|
785
|
+
}
|
|
786
|
+
cxxThrowStatementToStmts(throwStatement) {
|
|
787
|
+
const stmts = [];
|
|
788
|
+
let { value: throwValue, valueOriginalPositions: throwValuePositions, stmts: throwStmts, } = this.cxxNodeToValueAndStmts(throwStatement.inner[0]);
|
|
789
|
+
if (throwStatement.inner.length === 0 && this.catchedExceptions.length !== 0) {
|
|
790
|
+
throwValue = this.catchedExceptions[this.catchedExceptions.length - 1];
|
|
791
|
+
}
|
|
792
|
+
stmts.push(...throwStmts);
|
|
793
|
+
const throwStmt = new Stmt_1.ArkThrowStmt(throwValue);
|
|
794
|
+
throwStmt.setOperandOriginalPositions(throwValuePositions);
|
|
795
|
+
stmts.push(throwStmt);
|
|
796
|
+
return stmts;
|
|
797
|
+
}
|
|
798
|
+
cxxMapStmtsToTsStmt(stmts, node) {
|
|
799
|
+
for (const stmt of stmts) {
|
|
800
|
+
if (!this.stmtsHaveOriginalText.has(stmt)) {
|
|
801
|
+
this.stmtsHaveOriginalText.add(stmt);
|
|
802
|
+
stmt.setOriginPositionInfo(Position_1.LineColPosition.cxxBuildFromNode(node));
|
|
803
|
+
stmt.setOriginalText(node.code);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Converts a C++ token to the corresponding unary operator.
|
|
809
|
+
*
|
|
810
|
+
* @param token - The C++ token to be converted.
|
|
811
|
+
* @returns - The corresponding `UnaryOperator` if the token matches, otherwise `null`.
|
|
812
|
+
*/
|
|
813
|
+
static cxxTokenToUnaryOperator(token) {
|
|
814
|
+
switch (token) {
|
|
815
|
+
case '-':
|
|
816
|
+
return Expr_1.UnaryOperator.Neg;
|
|
817
|
+
case '~':
|
|
818
|
+
return Expr_1.UnaryOperator.BitwiseNot;
|
|
819
|
+
case '!':
|
|
820
|
+
return Expr_1.UnaryOperator.LogicalNot;
|
|
821
|
+
case '&':
|
|
822
|
+
return Expr_1.UnaryOperator.Addr;
|
|
823
|
+
case '*':
|
|
824
|
+
return Expr_1.UnaryOperator.Deref;
|
|
825
|
+
default:
|
|
826
|
+
}
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
generateAssignStmtForValue(value, valueOriginalPositions) {
|
|
830
|
+
let valueType;
|
|
831
|
+
if (value instanceof Expr_1.ArkUnopExpr) {
|
|
832
|
+
valueType = this.buildTypeForUnopExpr(value);
|
|
833
|
+
}
|
|
834
|
+
else if (value instanceof Expr_1.ArkNormalBinopExpr) {
|
|
835
|
+
valueType = this.buildTypeForBinOpExpr(value);
|
|
836
|
+
}
|
|
837
|
+
else if (value instanceof Ref_1.ArkArrayRef) {
|
|
838
|
+
valueType = this.buildTypeForArrayRefExpr(value);
|
|
839
|
+
}
|
|
840
|
+
else if (value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
841
|
+
valueType = value.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
valueType = value.getType();
|
|
845
|
+
}
|
|
846
|
+
const leftOp = this.ArkCxxValueTransformer.generateTempLocal(valueType);
|
|
847
|
+
const leftOpPosition = valueOriginalPositions[0];
|
|
848
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(leftOp, value);
|
|
849
|
+
assignStmt.setOperandOriginalPositions([leftOpPosition, ...valueOriginalPositions]);
|
|
850
|
+
return {
|
|
851
|
+
value: leftOp,
|
|
852
|
+
valueOriginalPositions: [leftOpPosition],
|
|
853
|
+
stmts: [assignStmt],
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
buildTypeForUnopExpr(value) {
|
|
857
|
+
const opType = value.getOp().getType();
|
|
858
|
+
const opCode = value.getOperator();
|
|
859
|
+
let valueType;
|
|
860
|
+
switch (opCode) {
|
|
861
|
+
case Expr_1.UnaryOperator.Addr:
|
|
862
|
+
if (opType instanceof Type_2.PointerType) {
|
|
863
|
+
valueType = new Type_2.PointerType(opType.getBaseType(), opType.getLevel() + 1);
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
valueType = new Type_2.PointerType(opType, 1);
|
|
867
|
+
}
|
|
868
|
+
break;
|
|
869
|
+
case Expr_1.UnaryOperator.Deref:
|
|
870
|
+
valueType = this.buildTypeForDerefExpr(opType);
|
|
871
|
+
break;
|
|
872
|
+
default:
|
|
873
|
+
valueType = opType;
|
|
874
|
+
}
|
|
875
|
+
return valueType;
|
|
876
|
+
}
|
|
877
|
+
buildTypeForDerefExpr(opType) {
|
|
878
|
+
if (opType instanceof Type_2.PointerType) {
|
|
879
|
+
if (opType.getLevel() === 1) {
|
|
880
|
+
return opType.getBaseType();
|
|
881
|
+
}
|
|
882
|
+
else {
|
|
883
|
+
return new Type_2.PointerType(opType.getBaseType(), opType.getLevel() - 1);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return opType;
|
|
887
|
+
}
|
|
888
|
+
buildTypeForBinOpExpr(value) {
|
|
889
|
+
const valueOpCode = value.getOperator();
|
|
890
|
+
if (valueOpCode !== Expr_1.NormalBinaryOperator.Addition && valueOpCode !== Expr_1.NormalBinaryOperator.Subtraction) {
|
|
891
|
+
return value.getType();
|
|
892
|
+
}
|
|
893
|
+
const opValue1Type = value.getOp1().getType();
|
|
894
|
+
const opValue2Type = value.getOp2().getType();
|
|
895
|
+
if (opValue1Type instanceof Type_2.PointerType) {
|
|
896
|
+
return opValue1Type;
|
|
897
|
+
}
|
|
898
|
+
else if (opValue2Type instanceof Type_2.PointerType) {
|
|
899
|
+
return opValue2Type;
|
|
900
|
+
}
|
|
901
|
+
return value.getType();
|
|
902
|
+
}
|
|
903
|
+
buildTypeForArrayRefExpr(value) {
|
|
904
|
+
const valueBaseType = value.getBase().getType();
|
|
905
|
+
if (valueBaseType instanceof Type_1.ArrayType) {
|
|
906
|
+
const dimension = valueBaseType.getDimension();
|
|
907
|
+
const baseTypeOfArray = valueBaseType.getBaseType();
|
|
908
|
+
if (dimension === 1) {
|
|
909
|
+
return baseTypeOfArray;
|
|
910
|
+
}
|
|
911
|
+
// Handle multi-dimension array
|
|
912
|
+
return new Type_1.ArrayType(baseTypeOfArray, dimension - 1);
|
|
913
|
+
}
|
|
914
|
+
else if (valueBaseType instanceof Type_1.StringType) {
|
|
915
|
+
return Type_2.CxxCharType.getInstance(Type_2.CxxTypeSigned.UNKNOWN, Type_2.CxxTypeBitWidth.EIGHT_BITS, Type_2.CxxStdTypeName.CHAR);
|
|
916
|
+
}
|
|
917
|
+
return value.getBase().getType();
|
|
918
|
+
}
|
|
919
|
+
setBuilderMethodContextFlag(builderMethodContextFlag) {
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
exports.ArkCxxIRTransformer = ArkCxxIRTransformer;
|
|
923
|
+
ArkCxxIRTransformer.DUMMY_IF_OPERATOR_AND_SIGNAL = 'If(&&)';
|
|
924
|
+
ArkCxxIRTransformer.DUMMY_IF_OPERATOR_END = 'IfEnd';
|
|
925
|
+
ArkCxxIRTransformer.DUMMY_IF_OPERATOR_OR_SIGNAL = 'If(||)';
|