arkanalyzer 1.0.5
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/LICENSE +201 -0
- package/README.en.md +88 -0
- package/README.md +98 -0
- package/docs/HowToCreatePR.md +55 -0
- package/docs/HowToHandleIssues.md +155 -0
- package/docs/quickstart.pdf +0 -0
- package/lib/Config.d.ts +26 -0
- package/lib/Config.d.ts.map +1 -0
- package/lib/Config.js +128 -0
- package/lib/Scene.d.ts +125 -0
- package/lib/Scene.d.ts.map +1 -0
- package/lib/Scene.js +762 -0
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -0
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -0
- package/lib/callgraph/algorithm/AbstractAnalysis.js +137 -0
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +11 -0
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -0
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +71 -0
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +16 -0
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -0
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +147 -0
- package/lib/callgraph/common/Statistics.d.ts +58 -0
- package/lib/callgraph/common/Statistics.d.ts.map +1 -0
- package/lib/callgraph/common/Statistics.js +203 -0
- package/lib/callgraph/model/BaseGraph.d.ts +62 -0
- package/lib/callgraph/model/BaseGraph.d.ts.map +1 -0
- package/lib/callgraph/model/BaseGraph.js +158 -0
- package/lib/callgraph/model/CallGraph.d.ts +94 -0
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -0
- package/lib/callgraph/model/CallGraph.js +339 -0
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +16 -0
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -0
- package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -0
- package/lib/callgraph/pointerAnalysis/Context.d.ts +38 -0
- package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/Context.js +156 -0
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +23 -0
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -0
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +209 -0
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/Pag.js +774 -0
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +88 -0
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +821 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +64 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +502 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +9 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +57 -0
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +58 -0
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -0
- package/lib/callgraph/pointerAnalysis/PtsDS.js +234 -0
- package/lib/core/base/Constant.d.ts +17 -0
- package/lib/core/base/Constant.d.ts.map +1 -0
- package/lib/core/base/Constant.js +53 -0
- package/lib/core/base/Decorator.d.ts +15 -0
- package/lib/core/base/Decorator.d.ts.map +1 -0
- package/lib/core/base/Decorator.js +43 -0
- package/lib/core/base/DefUseChain.d.ts +9 -0
- package/lib/core/base/DefUseChain.d.ts.map +1 -0
- package/lib/core/base/DefUseChain.js +25 -0
- package/lib/core/base/Expr.d.ts +219 -0
- package/lib/core/base/Expr.d.ts.map +1 -0
- package/lib/core/base/Expr.js +896 -0
- package/lib/core/base/Local.d.ts +40 -0
- package/lib/core/base/Local.d.ts.map +1 -0
- package/lib/core/base/Local.js +101 -0
- package/lib/core/base/Position.d.ts +39 -0
- package/lib/core/base/Position.d.ts.map +1 -0
- package/lib/core/base/Position.js +86 -0
- package/lib/core/base/Ref.d.ts +75 -0
- package/lib/core/base/Ref.d.ts.map +1 -0
- package/lib/core/base/Ref.js +286 -0
- package/lib/core/base/Stmt.d.ts +109 -0
- package/lib/core/base/Stmt.d.ts.map +1 -0
- package/lib/core/base/Stmt.js +374 -0
- package/lib/core/base/Type.d.ts +220 -0
- package/lib/core/base/Type.d.ts.map +1 -0
- package/lib/core/base/Type.js +477 -0
- package/lib/core/base/Value.d.ts +11 -0
- package/lib/core/base/Value.d.ts.map +1 -0
- package/lib/core/base/Value.js +16 -0
- package/lib/core/common/ArkIRTransformer.d.ts +101 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -0
- package/lib/core/common/ArkIRTransformer.js +1674 -0
- package/lib/core/common/BodyBuilder.d.ts +10 -0
- package/lib/core/common/BodyBuilder.d.ts.map +1 -0
- package/lib/core/common/BodyBuilder.js +34 -0
- package/lib/core/common/Builtin.d.ts +35 -0
- package/lib/core/common/Builtin.d.ts.map +1 -0
- package/lib/core/common/Builtin.js +78 -0
- package/lib/core/common/CfgBuilder.d.ts +136 -0
- package/lib/core/common/CfgBuilder.d.ts.map +1 -0
- package/lib/core/common/CfgBuilder.js +1241 -0
- package/lib/core/common/Const.d.ts +15 -0
- package/lib/core/common/Const.d.ts.map +1 -0
- package/lib/core/common/Const.js +34 -0
- package/lib/core/common/DummyMainCreater.d.ts +48 -0
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -0
- package/lib/core/common/DummyMainCreater.js +433 -0
- package/lib/core/common/EtsConst.d.ts +65 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -0
- package/lib/core/common/EtsConst.js +918 -0
- package/lib/core/common/ExprUseReplacer.d.ts +18 -0
- package/lib/core/common/ExprUseReplacer.d.ts.map +1 -0
- package/lib/core/common/ExprUseReplacer.js +88 -0
- package/lib/core/common/IRUtils.d.ts +7 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -0
- package/lib/core/common/IRUtils.js +39 -0
- package/lib/core/common/ModelUtils.d.ts +61 -0
- package/lib/core/common/ModelUtils.d.ts.map +1 -0
- package/lib/core/common/ModelUtils.js +628 -0
- package/lib/core/common/RefUseReplacer.d.ts +14 -0
- package/lib/core/common/RefUseReplacer.d.ts.map +1 -0
- package/lib/core/common/RefUseReplacer.js +50 -0
- package/lib/core/common/StmtUseReplacer.d.ts +16 -0
- package/lib/core/common/StmtUseReplacer.d.ts.map +1 -0
- package/lib/core/common/StmtUseReplacer.js +88 -0
- package/lib/core/common/TSConst.d.ts +11 -0
- package/lib/core/common/TSConst.d.ts.map +1 -0
- package/lib/core/common/TSConst.js +28 -0
- package/lib/core/common/TypeInference.d.ts +44 -0
- package/lib/core/common/TypeInference.d.ts.map +1 -0
- package/lib/core/common/TypeInference.js +519 -0
- package/lib/core/common/ValueUtil.d.ts +17 -0
- package/lib/core/common/ValueUtil.d.ts.map +1 -0
- package/lib/core/common/ValueUtil.js +71 -0
- package/lib/core/common/VisibleValue.d.ts +37 -0
- package/lib/core/common/VisibleValue.d.ts.map +1 -0
- package/lib/core/common/VisibleValue.js +212 -0
- package/lib/core/dataflow/DataflowProblem.d.ts +21 -0
- package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -0
- package/lib/core/dataflow/DataflowProblem.js +33 -0
- package/lib/core/dataflow/DataflowResult.d.ts +8 -0
- package/lib/core/dataflow/DataflowResult.d.ts.map +1 -0
- package/lib/core/dataflow/DataflowResult.js +26 -0
- package/lib/core/dataflow/DataflowSolver.d.ts +40 -0
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -0
- package/lib/core/dataflow/DataflowSolver.js +318 -0
- package/lib/core/dataflow/Edge.d.ts +16 -0
- package/lib/core/dataflow/Edge.d.ts.map +1 -0
- package/lib/core/dataflow/Edge.js +40 -0
- package/lib/core/dataflow/Fact.d.ts +7 -0
- package/lib/core/dataflow/Fact.d.ts.map +1 -0
- package/lib/core/dataflow/Fact.js +24 -0
- package/lib/core/dataflow/TiantAnalysis.d.ts +37 -0
- package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -0
- package/lib/core/dataflow/TiantAnalysis.js +326 -0
- package/lib/core/dataflow/UndefinedVariable.d.ts +32 -0
- package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -0
- package/lib/core/dataflow/UndefinedVariable.js +235 -0
- package/lib/core/dataflow/Util.d.ts +8 -0
- package/lib/core/dataflow/Util.d.ts.map +1 -0
- package/lib/core/dataflow/Util.js +137 -0
- package/lib/core/graph/BasicBlock.d.ts +26 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -0
- package/lib/core/graph/BasicBlock.js +92 -0
- package/lib/core/graph/Cfg.d.ts +29 -0
- package/lib/core/graph/Cfg.d.ts.map +1 -0
- package/lib/core/graph/Cfg.js +154 -0
- package/lib/core/graph/DominanceFinder.d.ts +16 -0
- package/lib/core/graph/DominanceFinder.d.ts.map +1 -0
- package/lib/core/graph/DominanceFinder.js +121 -0
- package/lib/core/graph/DominanceTree.d.ts +13 -0
- package/lib/core/graph/DominanceTree.d.ts.map +1 -0
- package/lib/core/graph/DominanceTree.js +70 -0
- package/lib/core/graph/ViewTree.d.ts +115 -0
- package/lib/core/graph/ViewTree.d.ts.map +1 -0
- package/lib/core/graph/ViewTree.js +16 -0
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts +204 -0
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -0
- package/lib/core/graph/builder/ViewTreeBuilder.js +1046 -0
- package/lib/core/model/ArkBody.d.ts +22 -0
- package/lib/core/model/ArkBody.d.ts.map +1 -0
- package/lib/core/model/ArkBody.js +63 -0
- package/lib/core/model/ArkClass.d.ts +110 -0
- package/lib/core/model/ArkClass.d.ts.map +1 -0
- package/lib/core/model/ArkClass.js +315 -0
- package/lib/core/model/ArkExport.d.ts +70 -0
- package/lib/core/model/ArkExport.d.ts.map +1 -0
- package/lib/core/model/ArkExport.js +143 -0
- package/lib/core/model/ArkField.d.ts +60 -0
- package/lib/core/model/ArkField.d.ts.map +1 -0
- package/lib/core/model/ArkField.js +157 -0
- package/lib/core/model/ArkFile.d.ts +62 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -0
- package/lib/core/model/ArkFile.js +160 -0
- package/lib/core/model/ArkImport.d.ts +43 -0
- package/lib/core/model/ArkImport.d.ts.map +1 -0
- package/lib/core/model/ArkImport.js +109 -0
- package/lib/core/model/ArkMethod.d.ts +76 -0
- package/lib/core/model/ArkMethod.d.ts.map +1 -0
- package/lib/core/model/ArkMethod.js +235 -0
- package/lib/core/model/ArkNamespace.d.ts +65 -0
- package/lib/core/model/ArkNamespace.d.ts.map +1 -0
- package/lib/core/model/ArkNamespace.js +182 -0
- package/lib/core/model/ArkSignature.d.ts +98 -0
- package/lib/core/model/ArkSignature.d.ts.map +1 -0
- package/lib/core/model/ArkSignature.js +281 -0
- package/lib/core/model/builder/ArkClassBuilder.d.ts +13 -0
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkClassBuilder.js +422 -0
- package/lib/core/model/builder/ArkExportBuilder.d.ts +25 -0
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkExportBuilder.js +207 -0
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkFieldBuilder.js +189 -0
- package/lib/core/model/builder/ArkFileBuilder.d.ts +10 -0
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkFileBuilder.js +164 -0
- package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -0
- package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkImportBuilder.js +125 -0
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +60 -0
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkMethodBuilder.js +419 -0
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -0
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkNamespaceBuilder.js +171 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -0
- package/lib/core/model/builder/ArkSignatureBuilder.js +40 -0
- package/lib/core/model/builder/builderUtils.d.ts +18 -0
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -0
- package/lib/core/model/builder/builderUtils.js +449 -0
- package/lib/index.d.ts +77 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +190 -0
- package/lib/save/ArkStream.d.ts +24 -0
- package/lib/save/ArkStream.d.ts.map +1 -0
- package/lib/save/ArkStream.js +83 -0
- package/lib/save/DotPrinter.d.ts +48 -0
- package/lib/save/DotPrinter.d.ts.map +1 -0
- package/lib/save/DotPrinter.js +229 -0
- package/lib/save/GraphPrinter.d.ts +17 -0
- package/lib/save/GraphPrinter.d.ts.map +1 -0
- package/lib/save/GraphPrinter.js +135 -0
- package/lib/save/JsonPrinter.d.ts +28 -0
- package/lib/save/JsonPrinter.d.ts.map +1 -0
- package/lib/save/JsonPrinter.js +511 -0
- package/lib/save/Printer.d.ts +17 -0
- package/lib/save/Printer.d.ts.map +1 -0
- package/lib/save/Printer.js +27 -0
- package/lib/save/PrinterBuilder.d.ts +38 -0
- package/lib/save/PrinterBuilder.d.ts.map +1 -0
- package/lib/save/PrinterBuilder.js +102 -0
- package/lib/save/serializeArkIR.d.ts +3 -0
- package/lib/save/serializeArkIR.d.ts.map +1 -0
- package/lib/save/serializeArkIR.js +166 -0
- package/lib/save/source/SourceBase.d.ts +32 -0
- package/lib/save/source/SourceBase.d.ts.map +1 -0
- package/lib/save/source/SourceBase.js +93 -0
- package/lib/save/source/SourceBody.d.ts +60 -0
- package/lib/save/source/SourceBody.d.ts.map +1 -0
- package/lib/save/source/SourceBody.js +292 -0
- package/lib/save/source/SourceClass.d.ts +27 -0
- package/lib/save/source/SourceClass.d.ts.map +1 -0
- package/lib/save/source/SourceClass.js +202 -0
- package/lib/save/source/SourceField.d.ts +15 -0
- package/lib/save/source/SourceField.d.ts.map +1 -0
- package/lib/save/source/SourceField.js +68 -0
- package/lib/save/source/SourceFilePrinter.d.ts +14 -0
- package/lib/save/source/SourceFilePrinter.d.ts.map +1 -0
- package/lib/save/source/SourceFilePrinter.js +73 -0
- package/lib/save/source/SourceMethod.d.ts +24 -0
- package/lib/save/source/SourceMethod.d.ts.map +1 -0
- package/lib/save/source/SourceMethod.js +170 -0
- package/lib/save/source/SourceModule.d.ts +18 -0
- package/lib/save/source/SourceModule.d.ts.map +1 -0
- package/lib/save/source/SourceModule.js +120 -0
- package/lib/save/source/SourceNamespace.d.ts +13 -0
- package/lib/save/source/SourceNamespace.d.ts.map +1 -0
- package/lib/save/source/SourceNamespace.js +80 -0
- package/lib/save/source/SourceStmt.d.ts +172 -0
- package/lib/save/source/SourceStmt.d.ts.map +1 -0
- package/lib/save/source/SourceStmt.js +757 -0
- package/lib/save/source/SourceTransformer.d.ts +37 -0
- package/lib/save/source/SourceTransformer.d.ts.map +1 -0
- package/lib/save/source/SourceTransformer.js +338 -0
- package/lib/save/source/SourceUtils.d.ts +25 -0
- package/lib/save/source/SourceUtils.d.ts.map +1 -0
- package/lib/save/source/SourceUtils.js +201 -0
- package/lib/transformer/FunctionTransformer.d.ts +3 -0
- package/lib/transformer/FunctionTransformer.d.ts.map +1 -0
- package/lib/transformer/FunctionTransformer.js +17 -0
- package/lib/transformer/SceneTransformer.d.ts +3 -0
- package/lib/transformer/SceneTransformer.d.ts.map +1 -0
- package/lib/transformer/SceneTransformer.js +17 -0
- package/lib/transformer/StaticSingleAssignmentFormer.d.ts +13 -0
- package/lib/transformer/StaticSingleAssignmentFormer.d.ts.map +1 -0
- package/lib/transformer/StaticSingleAssignmentFormer.js +259 -0
- package/lib/transformer/Transformer.d.ts +7 -0
- package/lib/transformer/Transformer.d.ts.map +1 -0
- package/lib/transformer/Transformer.js +22 -0
- package/lib/utils/CfgStructualAnalysis.d.ts +93 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -0
- package/lib/utils/CfgStructualAnalysis.js +955 -0
- package/lib/utils/FileUtils.d.ts +18 -0
- package/lib/utils/FileUtils.d.ts.map +1 -0
- package/lib/utils/FileUtils.js +131 -0
- package/lib/utils/callGraphUtils.d.ts +31 -0
- package/lib/utils/callGraphUtils.d.ts.map +1 -0
- package/lib/utils/callGraphUtils.js +208 -0
- package/lib/utils/entryMethodUtils.d.ts +16 -0
- package/lib/utils/entryMethodUtils.d.ts.map +1 -0
- package/lib/utils/entryMethodUtils.js +139 -0
- package/lib/utils/getAllFiles.d.ts +10 -0
- package/lib/utils/getAllFiles.d.ts.map +1 -0
- package/lib/utils/getAllFiles.js +91 -0
- package/lib/utils/json5parser.d.ts +7 -0
- package/lib/utils/json5parser.d.ts.map +1 -0
- package/lib/utils/json5parser.js +146 -0
- package/lib/utils/logger.d.ts +19 -0
- package/lib/utils/logger.d.ts.map +1 -0
- package/lib/utils/logger.js +90 -0
- package/lib/utils/pathTransfer.d.ts +2 -0
- package/lib/utils/pathTransfer.d.ts.map +1 -0
- package/lib/utils/pathTransfer.js +25 -0
- package/package.json +29 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 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.TypeInference = void 0;
|
|
41
|
+
const logger_1 = __importStar(require("../../utils/logger"));
|
|
42
|
+
const Expr_1 = require("../base/Expr");
|
|
43
|
+
const Local_1 = require("../base/Local");
|
|
44
|
+
const Ref_1 = require("../base/Ref");
|
|
45
|
+
const Stmt_1 = require("../base/Stmt");
|
|
46
|
+
const Type_1 = require("../base/Type");
|
|
47
|
+
const ArkMethod_1 = require("../model/ArkMethod");
|
|
48
|
+
const ArkClass_1 = require("../model/ArkClass");
|
|
49
|
+
const ArkField_1 = require("../model/ArkField");
|
|
50
|
+
const Constant_1 = require("../base/Constant");
|
|
51
|
+
const ArkNamespace_1 = require("../model/ArkNamespace");
|
|
52
|
+
const TSConst_1 = require("./TSConst");
|
|
53
|
+
const ModelUtils_1 = require("./ModelUtils");
|
|
54
|
+
const Builtin_1 = require("./Builtin");
|
|
55
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
56
|
+
const Const_1 = require("./Const");
|
|
57
|
+
const ValueUtil_1 = require("./ValueUtil");
|
|
58
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'TypeInference');
|
|
59
|
+
class TypeInference {
|
|
60
|
+
static inferTypeInArkField(arkField) {
|
|
61
|
+
const arkClass = arkField.getDeclaringArkClass();
|
|
62
|
+
const stmts = arkField.getInitializer();
|
|
63
|
+
for (const stmt of stmts) {
|
|
64
|
+
this.resolveExprsInStmt(stmt, arkClass);
|
|
65
|
+
this.resolveFieldRefsInStmt(stmt, arkClass, arkClass.getMethodWithName('@instance_init'));
|
|
66
|
+
this.resolveArkAssignStmt(stmt, arkClass);
|
|
67
|
+
}
|
|
68
|
+
if (!this.isUnclearType(arkField.getType())) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const lastStmt = stmts[stmts.length - 1];
|
|
72
|
+
let fieldRef;
|
|
73
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt && lastStmt.getLeftOp() instanceof Ref_1.AbstractFieldRef) {
|
|
74
|
+
fieldRef = lastStmt.getLeftOp();
|
|
75
|
+
}
|
|
76
|
+
const fieldType = this.inferUnclearedType(arkField.getType(), arkClass, fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.getType());
|
|
77
|
+
if (fieldType) {
|
|
78
|
+
const old = arkField.getSignature();
|
|
79
|
+
arkField.setSignature(new ArkSignature_1.FieldSignature(old.getFieldName(), old.getDeclaringSignature(), fieldType, old.isStatic()));
|
|
80
|
+
}
|
|
81
|
+
else if (fieldRef && !this.isUnclearType(fieldRef.getType())) {
|
|
82
|
+
arkField.setSignature(fieldRef.getFieldSignature());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
static inferUnclearedType(leftOpType, declaringArkClass, rightType) {
|
|
86
|
+
let type;
|
|
87
|
+
if (leftOpType instanceof Type_1.UnclearReferenceType) {
|
|
88
|
+
type = this.inferUnclearReferenceType(leftOpType.getName(), declaringArkClass);
|
|
89
|
+
}
|
|
90
|
+
else if (leftOpType instanceof Type_1.ClassType
|
|
91
|
+
&& leftOpType.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
92
|
+
type = TypeInference.inferUnclearReferenceType(leftOpType.getClassSignature().getClassName(), declaringArkClass);
|
|
93
|
+
}
|
|
94
|
+
else if (leftOpType instanceof Type_1.UnionType) {
|
|
95
|
+
let types = leftOpType.getTypes();
|
|
96
|
+
for (let i = 0; i < types.length; i++) {
|
|
97
|
+
let optionType = types[i];
|
|
98
|
+
let newType;
|
|
99
|
+
if (optionType instanceof Type_1.ClassType) {
|
|
100
|
+
newType = TypeInference.inferUnclearReferenceType(optionType.getClassSignature().getClassName(), declaringArkClass);
|
|
101
|
+
}
|
|
102
|
+
else if (optionType instanceof Type_1.UnclearReferenceType) {
|
|
103
|
+
newType = TypeInference.inferUnclearReferenceType(optionType.getName(), declaringArkClass);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
newType = optionType;
|
|
107
|
+
}
|
|
108
|
+
if (newType && newType != optionType) {
|
|
109
|
+
types[i] = newType;
|
|
110
|
+
}
|
|
111
|
+
if (rightType && newType && newType === rightType) {
|
|
112
|
+
leftOpType.setCurrType(rightType);
|
|
113
|
+
type = leftOpType;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (leftOpType instanceof Type_1.ArrayType) {
|
|
118
|
+
let baseType = this.inferUnclearedType(leftOpType.getBaseType(), declaringArkClass);
|
|
119
|
+
if (baseType) {
|
|
120
|
+
leftOpType.setBaseType(baseType);
|
|
121
|
+
type = leftOpType;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (leftOpType instanceof Type_1.AliasType) {
|
|
125
|
+
let baseType = this.inferUnclearedType(leftOpType.getOriginalType(), declaringArkClass);
|
|
126
|
+
if (baseType) {
|
|
127
|
+
leftOpType.setOriginalType(baseType);
|
|
128
|
+
type = leftOpType;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (leftOpType instanceof Type_1.AnnotationNamespaceType) {
|
|
132
|
+
type = this.inferUnclearReferenceType(leftOpType.getOriginType(), declaringArkClass);
|
|
133
|
+
}
|
|
134
|
+
return type;
|
|
135
|
+
}
|
|
136
|
+
static inferTypeInMethod(arkMethod) {
|
|
137
|
+
var _a;
|
|
138
|
+
const body = arkMethod.getBody();
|
|
139
|
+
if (!body) {
|
|
140
|
+
logger.warn('empty body');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
144
|
+
(_a = body.getAliasTypeMap()) === null || _a === void 0 ? void 0 : _a.forEach((value) => this.inferUnclearedType(value[0], arkClass));
|
|
145
|
+
this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
|
|
146
|
+
const cfg = body.getCfg();
|
|
147
|
+
for (const block of cfg.getBlocks()) {
|
|
148
|
+
for (const stmt of block.getStmts()) {
|
|
149
|
+
this.resolveExprsInStmt(stmt, arkClass);
|
|
150
|
+
this.resolveFieldRefsInStmt(stmt, arkClass, arkMethod);
|
|
151
|
+
this.resolveArkAssignStmt(stmt, arkClass);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
this.inferMethodReturnType(arkMethod);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @Deprecated
|
|
158
|
+
* @param arkMethod
|
|
159
|
+
*/
|
|
160
|
+
static inferSimpleTypeInMethod(arkMethod) {
|
|
161
|
+
const body = arkMethod.getBody();
|
|
162
|
+
if (!body) {
|
|
163
|
+
logger.warn('empty body');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const cfg = body.getCfg();
|
|
167
|
+
for (const block of cfg.getBlocks()) {
|
|
168
|
+
for (const stmt of block.getStmts()) {
|
|
169
|
+
TypeInference.inferSimpleTypeInStmt(stmt);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* infer type for Exprs in stmt which invoke method.
|
|
175
|
+
* such as ArkInstanceInvokeExpr ArkStaticInvokeExpr ArkNewExpr
|
|
176
|
+
*/
|
|
177
|
+
static resolveExprsInStmt(stmt, arkClass) {
|
|
178
|
+
const exprs = stmt.getExprs();
|
|
179
|
+
for (const expr of exprs) {
|
|
180
|
+
const newExpr = expr.inferType(arkClass);
|
|
181
|
+
if (stmt.containsInvokeExpr() && expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
182
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
183
|
+
stmt.setRightOp(newExpr);
|
|
184
|
+
}
|
|
185
|
+
else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
186
|
+
stmt.replaceInvokeExpr(newExpr);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* infer type for fieldRefs in stmt.
|
|
193
|
+
*/
|
|
194
|
+
static resolveFieldRefsInStmt(stmt, arkClass, arkMethod) {
|
|
195
|
+
var _a;
|
|
196
|
+
for (const use of stmt.getUses()) {
|
|
197
|
+
if (use instanceof Ref_1.AbstractRef) {
|
|
198
|
+
const fieldRef = use.inferType(arkClass);
|
|
199
|
+
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
200
|
+
if (stmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
201
|
+
stmt.setRightOp(fieldRef);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
stmt.replaceUse(use, fieldRef);
|
|
205
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
209
|
+
const index = fieldRef.getIndex();
|
|
210
|
+
if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
|
|
211
|
+
const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(index.getValue());
|
|
212
|
+
if (local) {
|
|
213
|
+
fieldRef.setIndex(local);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
stmt.replaceUse(use, fieldRef);
|
|
217
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const stmtDef = stmt.getDef();
|
|
222
|
+
if (stmtDef && stmtDef instanceof Ref_1.AbstractRef) {
|
|
223
|
+
const fieldRef = stmtDef.inferType(arkClass);
|
|
224
|
+
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
225
|
+
stmt.setLeftOp(fieldRef);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
static parseArkExport2Type(arkExport) {
|
|
230
|
+
var _a;
|
|
231
|
+
if (!arkExport) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
235
|
+
return new Type_1.ClassType(arkExport.getSignature(), (_a = arkExport.getGenericsTypes()) === null || _a === void 0 ? void 0 : _a.map((x, index) => {
|
|
236
|
+
let defaultType = x.getDefaultType();
|
|
237
|
+
if (defaultType instanceof Type_1.UnclearReferenceType) {
|
|
238
|
+
const newType = TypeInference.inferUnclearReferenceType(defaultType.getName(), arkExport);
|
|
239
|
+
if (newType) {
|
|
240
|
+
defaultType = newType;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return defaultType !== null && defaultType !== void 0 ? defaultType : Type_1.UndefinedType.getInstance();
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
else if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
|
|
247
|
+
let namespaceType = new Type_1.AnnotationNamespaceType(arkExport.getName());
|
|
248
|
+
namespaceType.setNamespaceSignature(arkExport.getSignature());
|
|
249
|
+
return namespaceType;
|
|
250
|
+
}
|
|
251
|
+
else if (arkExport instanceof ArkMethod_1.ArkMethod) {
|
|
252
|
+
return new Type_1.FunctionType(arkExport.getSignature());
|
|
253
|
+
}
|
|
254
|
+
else if (arkExport instanceof Local_1.Local) {
|
|
255
|
+
if (arkExport.getType() instanceof Type_1.UnknownType || arkExport.getType() instanceof Type_1.UnclearReferenceType) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
return arkExport.getType();
|
|
259
|
+
}
|
|
260
|
+
else if (arkExport instanceof Type_1.AliasType) {
|
|
261
|
+
return arkExport;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* infer and pass type for ArkAssignStmt right and left
|
|
269
|
+
* @param stmt
|
|
270
|
+
* @param arkClass
|
|
271
|
+
*/
|
|
272
|
+
static resolveArkAssignStmt(stmt, arkClass) {
|
|
273
|
+
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const rightOp = stmt.getRightOp();
|
|
277
|
+
if (rightOp instanceof Local_1.Local && rightOp.getType() instanceof Type_1.UnknownType) {
|
|
278
|
+
const type = this.inferUnclearReferenceType(rightOp.getName(), arkClass);
|
|
279
|
+
if (type) {
|
|
280
|
+
rightOp.setType(type);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else if (rightOp.getType() instanceof Type_1.UnclearReferenceType) {
|
|
284
|
+
const type = this.inferUnclearReferenceType(rightOp.getType().getName(), arkClass);
|
|
285
|
+
if (type && rightOp instanceof Ref_1.ArkParameterRef) {
|
|
286
|
+
rightOp.setType(type);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const leftOp = stmt.getLeftOp();
|
|
290
|
+
if (leftOp instanceof Local_1.Local) {
|
|
291
|
+
const leftOpType = leftOp.getType();
|
|
292
|
+
let type = this.inferUnclearedType(leftOpType, arkClass, rightOp.getType());
|
|
293
|
+
if (type) {
|
|
294
|
+
leftOp.setType(type);
|
|
295
|
+
}
|
|
296
|
+
else if (rightOp instanceof Ref_1.ArkThisRef) {
|
|
297
|
+
leftOp.setType(rightOp.getType());
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if ((this.isUnclearType(leftOp.getType()) || leftOp.getType() instanceof Type_1.FunctionType) &&
|
|
301
|
+
!this.isUnclearType(rightOp.getType())) {
|
|
302
|
+
if (leftOp instanceof Local_1.Local) {
|
|
303
|
+
leftOp.setType(rightOp.getType());
|
|
304
|
+
}
|
|
305
|
+
else if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
306
|
+
leftOp.getFieldSignature().setType(rightOp.getType());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
static isUnclearType(type) {
|
|
311
|
+
if (!type || type instanceof Type_1.UnknownType || type instanceof Type_1.UnclearReferenceType) {
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
else if (type instanceof Type_1.ClassType
|
|
315
|
+
&& type.getClassSignature().getDeclaringFileSignature().getFileName() === '_UnknownFileName') {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
static inferSimpleTypeInStmt(stmt) {
|
|
321
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
322
|
+
const leftOp = stmt.getLeftOp();
|
|
323
|
+
if (leftOp instanceof Local_1.Local) {
|
|
324
|
+
const leftOpType = leftOp.getType();
|
|
325
|
+
if (leftOpType instanceof Type_1.UnknownType) {
|
|
326
|
+
const rightOp = stmt.getRightOp();
|
|
327
|
+
leftOp.setType(rightOp.getType());
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// Deal only with simple situations
|
|
333
|
+
static buildTypeFromStr(typeStr) {
|
|
334
|
+
switch (typeStr) {
|
|
335
|
+
case 'boolean':
|
|
336
|
+
return Type_1.BooleanType.getInstance();
|
|
337
|
+
case 'number':
|
|
338
|
+
return Type_1.NumberType.getInstance();
|
|
339
|
+
case 'string':
|
|
340
|
+
return Type_1.StringType.getInstance();
|
|
341
|
+
case 'undefined':
|
|
342
|
+
return Type_1.UndefinedType.getInstance();
|
|
343
|
+
case 'null':
|
|
344
|
+
return Type_1.NullType.getInstance();
|
|
345
|
+
case 'any':
|
|
346
|
+
return Type_1.AnyType.getInstance();
|
|
347
|
+
case 'void':
|
|
348
|
+
return Type_1.VoidType.getInstance();
|
|
349
|
+
case 'never':
|
|
350
|
+
return Type_1.NeverType.getInstance();
|
|
351
|
+
case 'RegularExpression':
|
|
352
|
+
const classSignature = Builtin_1.Builtin.REGEXP_CLASS_SIGNATURE;
|
|
353
|
+
return new Type_1.ClassType(classSignature);
|
|
354
|
+
default:
|
|
355
|
+
return new Type_1.UnclearReferenceType(typeStr);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
static inferValueType(value, arkClass) {
|
|
359
|
+
if (value instanceof Ref_1.ArkInstanceFieldRef || value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
360
|
+
this.inferValueType(value.getBase(), arkClass);
|
|
361
|
+
}
|
|
362
|
+
if (value instanceof Ref_1.AbstractRef || value instanceof Expr_1.AbstractExpr || value instanceof Local_1.Local) {
|
|
363
|
+
value.inferType(arkClass);
|
|
364
|
+
}
|
|
365
|
+
return value.getType();
|
|
366
|
+
}
|
|
367
|
+
static inferMethodReturnType(method) {
|
|
368
|
+
const oldMethodSignature = method.getSignature();
|
|
369
|
+
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
370
|
+
if (method.getName() === TSConst_1.CONSTRUCTOR_NAME) {
|
|
371
|
+
const newReturnType = new Type_1.ClassType(method.getDeclaringArkClass().getSignature());
|
|
372
|
+
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldMethodSubSignature.getMethodName(), oldMethodSubSignature.getParameters(), newReturnType, oldMethodSubSignature.isStatic());
|
|
373
|
+
method.setSignature(new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), newMethodSubSignature));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const returnType = method.getReturnType();
|
|
377
|
+
let inferType;
|
|
378
|
+
if (returnType instanceof Type_1.UnclearReferenceType) {
|
|
379
|
+
inferType = this.inferUnclearReferenceType(returnType.getName(), method.getDeclaringArkClass());
|
|
380
|
+
}
|
|
381
|
+
if (inferType) {
|
|
382
|
+
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldMethodSubSignature.getMethodName(), oldMethodSubSignature.getParameters(), inferType, oldMethodSubSignature.isStatic());
|
|
383
|
+
method.setSignature(new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), newMethodSubSignature));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
static inferGenericType(types, arkClass) {
|
|
387
|
+
types === null || types === void 0 ? void 0 : types.forEach(type => {
|
|
388
|
+
const defaultType = type.getDefaultType();
|
|
389
|
+
if (defaultType instanceof Type_1.UnclearReferenceType) {
|
|
390
|
+
const newDefaultType = TypeInference.inferUnclearReferenceType(defaultType.getName(), arkClass);
|
|
391
|
+
if (newDefaultType) {
|
|
392
|
+
type.setDefaultType(newDefaultType);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const constraint = type.getConstraint();
|
|
396
|
+
if (constraint instanceof Type_1.UnclearReferenceType) {
|
|
397
|
+
const newConstraint = TypeInference.inferUnclearReferenceType(constraint.getName(), arkClass);
|
|
398
|
+
if (newConstraint) {
|
|
399
|
+
type.setConstraint(newConstraint);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
static inferUnclearReferenceType(refName, arkClass) {
|
|
405
|
+
var _a;
|
|
406
|
+
if (!refName) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
//split and iterate to infer each type
|
|
410
|
+
const singleNames = refName.split('.');
|
|
411
|
+
let type = null;
|
|
412
|
+
for (let i = 0; i < singleNames.length; i++) {
|
|
413
|
+
let genericName = ValueUtil_1.EMPTY_STRING;
|
|
414
|
+
const name = singleNames[i].replace(/<(\w+)>/, function (match, group1) {
|
|
415
|
+
genericName = group1;
|
|
416
|
+
return ValueUtil_1.EMPTY_STRING;
|
|
417
|
+
});
|
|
418
|
+
if (i === 0) {
|
|
419
|
+
type = this.inferBaseType(name, arkClass);
|
|
420
|
+
}
|
|
421
|
+
else if (type) {
|
|
422
|
+
type = (_a = this.inferFieldType(type, name, arkClass)) === null || _a === void 0 ? void 0 : _a[1];
|
|
423
|
+
}
|
|
424
|
+
if (!type) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
if (genericName) {
|
|
428
|
+
const realTypes = genericName.split(',').map(generic => {
|
|
429
|
+
const realType = this.inferBaseType(generic, arkClass);
|
|
430
|
+
return realType !== null && realType !== void 0 ? realType : new Type_1.UnclearReferenceType(generic);
|
|
431
|
+
});
|
|
432
|
+
if (type instanceof Type_1.ClassType) {
|
|
433
|
+
type = new Type_1.ClassType(type.getClassSignature(), realTypes);
|
|
434
|
+
}
|
|
435
|
+
else if (type instanceof Type_1.FunctionType) {
|
|
436
|
+
type = new Type_1.FunctionType(type.getMethodSignature(), realTypes);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return type;
|
|
441
|
+
}
|
|
442
|
+
static inferFieldType(baseType, fieldName, declareClass) {
|
|
443
|
+
if (baseType instanceof Type_1.AliasType) {
|
|
444
|
+
baseType = baseType.getOriginalType();
|
|
445
|
+
}
|
|
446
|
+
else if (baseType instanceof Type_1.UnionType && baseType.getCurrType()) {
|
|
447
|
+
baseType = baseType.getCurrType();
|
|
448
|
+
}
|
|
449
|
+
let propertyAndType = null;
|
|
450
|
+
if (baseType instanceof Type_1.ClassType) {
|
|
451
|
+
const arkClass = declareClass.getDeclaringArkFile().getScene().getClass(baseType.getClassSignature());
|
|
452
|
+
if (!arkClass) {
|
|
453
|
+
if (fieldName === Builtin_1.Builtin.ITERATOR_RESULT_VALUE && baseType.getClassSignature()
|
|
454
|
+
.getDeclaringFileSignature().getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
455
|
+
const types = baseType.getRealGenericTypes();
|
|
456
|
+
if (types && types.length > 0) {
|
|
457
|
+
propertyAndType = [null, types[0]];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return propertyAndType;
|
|
461
|
+
}
|
|
462
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arkClass);
|
|
463
|
+
let propertyType = null;
|
|
464
|
+
if (property instanceof ArkField_1.ArkField) {
|
|
465
|
+
propertyType = property.getType();
|
|
466
|
+
}
|
|
467
|
+
else if (property) {
|
|
468
|
+
propertyType = this.parseArkExport2Type(property);
|
|
469
|
+
}
|
|
470
|
+
if (propertyType) {
|
|
471
|
+
propertyAndType = [property, propertyType];
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else if (baseType instanceof Type_1.AnnotationNamespaceType) {
|
|
475
|
+
const namespace = declareClass.getDeclaringArkFile().getScene().getNamespace(baseType.getNamespaceSignature());
|
|
476
|
+
if (namespace) {
|
|
477
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInNamespace(fieldName, namespace);
|
|
478
|
+
const propertyType = this.parseArkExport2Type(property);
|
|
479
|
+
if (propertyType) {
|
|
480
|
+
propertyAndType = [property, propertyType];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
logger.warn('infer unclear reference type fail: ' + fieldName);
|
|
486
|
+
}
|
|
487
|
+
return propertyAndType;
|
|
488
|
+
}
|
|
489
|
+
static inferBaseType(baseName, arkClass) {
|
|
490
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
491
|
+
if (TSConst_1.SUPER_NAME === baseName) {
|
|
492
|
+
return this.parseArkExport2Type(arkClass.getSuperClass());
|
|
493
|
+
}
|
|
494
|
+
const field = (_c = (_b = (_a = arkClass.getDeclaringArkFile().getDefaultClass().getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.getBody()) === null || _b === void 0 ? void 0 : _b.getLocals()) === null || _c === void 0 ? void 0 : _c.get(baseName);
|
|
495
|
+
if (field && !this.isUnclearType(field.getType())) {
|
|
496
|
+
return field.getType();
|
|
497
|
+
}
|
|
498
|
+
let arkExport = (_l = (_g = (_e = (_d = ModelUtils_1.ModelUtils.getClassWithName(baseName, arkClass)) !== null && _d !== void 0 ? _d : ModelUtils_1.ModelUtils.getNamespaceWithName(baseName, arkClass)) !== null && _e !== void 0 ? _e : (_f = ModelUtils_1.ModelUtils.getDefaultClass(arkClass)) === null || _f === void 0 ? void 0 : _f.getMethodWithName(baseName)) !== null && _g !== void 0 ? _g : (_k = (_j = (_h = ModelUtils_1.ModelUtils.getDefaultClass(arkClass)) === null || _h === void 0 ? void 0 : _h.getDefaultArkMethod()) === null || _j === void 0 ? void 0 : _j.getBody()) === null || _k === void 0 ? void 0 : _k.getAliasTypeByName(baseName)) !== null && _l !== void 0 ? _l : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
|
|
499
|
+
if (!arkExport && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
|
|
500
|
+
arkExport = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(baseName);
|
|
501
|
+
}
|
|
502
|
+
return this.parseArkExport2Type(arkExport);
|
|
503
|
+
}
|
|
504
|
+
static inferRealGenericTypes(realTypes, arkClass) {
|
|
505
|
+
if (!realTypes) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
for (let i = 0; i < realTypes.length; i++) {
|
|
509
|
+
const mayType = realTypes[i];
|
|
510
|
+
if (this.isUnclearType(mayType)) {
|
|
511
|
+
const newType = this.inferUnclearedType(mayType, arkClass);
|
|
512
|
+
if (newType) {
|
|
513
|
+
realTypes[i] = newType;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
exports.TypeInference = TypeInference;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Constant } from '../base/Constant';
|
|
2
|
+
export declare const EMPTY_STRING = "";
|
|
3
|
+
export declare class ValueUtil {
|
|
4
|
+
private static readonly NumberConstantCache;
|
|
5
|
+
private static readonly UndefinedConstant;
|
|
6
|
+
private static readonly NullConstant;
|
|
7
|
+
private static readonly TrueConstant;
|
|
8
|
+
private static readonly FalseConstant;
|
|
9
|
+
private static readonly EMPTY_STRING_CONSTANT;
|
|
10
|
+
static getOrCreateNumberConst(n: number): Constant;
|
|
11
|
+
static createStringConst(str: string): Constant;
|
|
12
|
+
static createConst(str: string): Constant;
|
|
13
|
+
static getUndefinedConst(): Constant;
|
|
14
|
+
static getNullConstant(): Constant;
|
|
15
|
+
static getBooleanConstant(value: boolean): Constant;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ValueUtil.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValueUtil.d.ts","sourceRoot":"","sources":["../../../src/core/common/ValueUtil.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAYxC;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAA0D;IACnG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAgD;IACpF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAmD;IACvF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAoD;IACzF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAwD;WAEvF,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;WAS3C,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAOxC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAQlC,iBAAiB,IAAI,QAAQ;WAI7B,eAAe,IAAI,QAAQ;WAI3B,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;CAG7D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ValueUtil = exports.EMPTY_STRING = void 0;
|
|
18
|
+
const Constant_1 = require("../base/Constant");
|
|
19
|
+
const Type_1 = require("../base/Type");
|
|
20
|
+
exports.EMPTY_STRING = '';
|
|
21
|
+
class ValueUtil {
|
|
22
|
+
static getOrCreateNumberConst(n) {
|
|
23
|
+
let constant = this.NumberConstantCache.get(n);
|
|
24
|
+
if (constant == undefined) {
|
|
25
|
+
constant = new Constant_1.Constant(n.toString(), Type_1.NumberType.getInstance());
|
|
26
|
+
this.NumberConstantCache.set(n, constant);
|
|
27
|
+
}
|
|
28
|
+
return constant;
|
|
29
|
+
}
|
|
30
|
+
static createStringConst(str) {
|
|
31
|
+
if (str == exports.EMPTY_STRING) {
|
|
32
|
+
return this.EMPTY_STRING_CONSTANT;
|
|
33
|
+
}
|
|
34
|
+
return new Constant_1.Constant(str, Type_1.StringType.getInstance());
|
|
35
|
+
}
|
|
36
|
+
static createConst(str) {
|
|
37
|
+
const n = Number(str);
|
|
38
|
+
if (!isNaN(n)) {
|
|
39
|
+
return this.getOrCreateNumberConst(n);
|
|
40
|
+
}
|
|
41
|
+
return new Constant_1.Constant(str, Type_1.StringType.getInstance());
|
|
42
|
+
}
|
|
43
|
+
static getUndefinedConst() {
|
|
44
|
+
return this.UndefinedConstant;
|
|
45
|
+
}
|
|
46
|
+
static getNullConstant() {
|
|
47
|
+
return this.NullConstant;
|
|
48
|
+
}
|
|
49
|
+
static getBooleanConstant(value) {
|
|
50
|
+
return value ? this.TrueConstant : this.FalseConstant;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ValueUtil = ValueUtil;
|
|
54
|
+
ValueUtil.NumberConstantCache = new Map([
|
|
55
|
+
[0, new Constant_1.Constant('0', Type_1.NumberType.getInstance())],
|
|
56
|
+
[1, new Constant_1.Constant('1', Type_1.NumberType.getInstance())],
|
|
57
|
+
[2, new Constant_1.Constant('2', Type_1.NumberType.getInstance())],
|
|
58
|
+
[3, new Constant_1.Constant('3', Type_1.NumberType.getInstance())],
|
|
59
|
+
[4, new Constant_1.Constant('4', Type_1.NumberType.getInstance())],
|
|
60
|
+
[5, new Constant_1.Constant('5', Type_1.NumberType.getInstance())],
|
|
61
|
+
[6, new Constant_1.Constant('6', Type_1.NumberType.getInstance())],
|
|
62
|
+
[7, new Constant_1.Constant('7', Type_1.NumberType.getInstance())],
|
|
63
|
+
[8, new Constant_1.Constant('8', Type_1.NumberType.getInstance())],
|
|
64
|
+
[9, new Constant_1.Constant('9', Type_1.NumberType.getInstance())],
|
|
65
|
+
[10, new Constant_1.Constant('10', Type_1.NumberType.getInstance())],
|
|
66
|
+
]);
|
|
67
|
+
ValueUtil.UndefinedConstant = new Constant_1.Constant('undefined', Type_1.UndefinedType.getInstance());
|
|
68
|
+
ValueUtil.NullConstant = new Constant_1.Constant('null', Type_1.NullType.getInstance());
|
|
69
|
+
ValueUtil.TrueConstant = new Constant_1.Constant('true', Type_1.BooleanType.getInstance());
|
|
70
|
+
ValueUtil.FalseConstant = new Constant_1.Constant('false', Type_1.BooleanType.getInstance());
|
|
71
|
+
ValueUtil.EMPTY_STRING_CONSTANT = new Constant_1.Constant(exports.EMPTY_STRING, Type_1.StringType.getInstance());
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Value } from '../base/Value';
|
|
2
|
+
import { BasicBlock } from '../graph/BasicBlock';
|
|
3
|
+
import { ArkClass } from '../model/ArkClass';
|
|
4
|
+
import { ArkFile } from '../model/ArkFile';
|
|
5
|
+
import { ArkMethod } from '../model/ArkMethod';
|
|
6
|
+
import { ArkNamespace } from '../model/ArkNamespace';
|
|
7
|
+
export declare class VisibleValue {
|
|
8
|
+
private scopeChain;
|
|
9
|
+
private currScope;
|
|
10
|
+
private currVisibleValues;
|
|
11
|
+
constructor();
|
|
12
|
+
/** get values that is visible in curr scope */
|
|
13
|
+
getCurrVisibleValues(): Value[];
|
|
14
|
+
getScopeChain(): Scope[];
|
|
15
|
+
/** udpate visible values after entered a scope, only support step by step */
|
|
16
|
+
updateIntoScope(model: ArkModel): void;
|
|
17
|
+
/** udpate visible values after left a scope, only support step by step */
|
|
18
|
+
updateOutScope(): void;
|
|
19
|
+
/** clear up previous scope */
|
|
20
|
+
private deleteScope;
|
|
21
|
+
/** add this scope to scope chain and update visible values */
|
|
22
|
+
private addScope;
|
|
23
|
+
private getTargetDepth;
|
|
24
|
+
private getVisibleValuesIntoFileOrNameSpace;
|
|
25
|
+
private getVisibleValuesIntoClass;
|
|
26
|
+
private getVisibleValuesIntoMethod;
|
|
27
|
+
private getVisibleValuesIntoBasicBlock;
|
|
28
|
+
}
|
|
29
|
+
type ArkModel = ArkFile | ArkNamespace | ArkClass | ArkMethod | BasicBlock;
|
|
30
|
+
export declare class Scope {
|
|
31
|
+
values: Value[];
|
|
32
|
+
depth: number;
|
|
33
|
+
arkModel: ArkModel | null;
|
|
34
|
+
constructor(values: Value[], depth?: number, arkModel?: ArkModel | null);
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=VisibleValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisibleValue.d.ts","sourceRoot":"","sources":["../../../src/core/common/VisibleValue.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,qBAAa,YAAY;IACrB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,iBAAiB,CAAU;;IASnC,+CAA+C;IACxC,oBAAoB,IAAI,KAAK,EAAE;IAI/B,aAAa,IAAI,KAAK,EAAE;IAI/B,6EAA6E;IACtE,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IA2B7C,0EAA0E;IACnE,cAAc,IAAI,IAAI;IAuB7B,8BAA8B;IAC9B,OAAO,CAAC,WAAW;IAsBnB,8DAA8D;IAC9D,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,mCAAmC;IAM3C,OAAO,CAAC,yBAAyB;IAgBjC,OAAO,CAAC,0BAA0B;IAKlC,OAAO,CAAC,8BAA8B;CASzC;AAGD,KAAK,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAE3E,qBAAa,KAAK;IACP,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;gBACrB,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,GAAE,MAAW,EAAE,QAAQ,GAAE,QAAQ,GAAG,IAAW;CAKpF"}
|