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
package/lib/Scene.js
ADDED
|
@@ -0,0 +1,762 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.ModuleScene = exports.Scene = void 0;
|
|
44
|
+
const fs_1 = __importDefault(require("fs"));
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const ModelUtils_1 = require("./core/common/ModelUtils");
|
|
47
|
+
const TypeInference_1 = require("./core/common/TypeInference");
|
|
48
|
+
const VisibleValue_1 = require("./core/common/VisibleValue");
|
|
49
|
+
const ArkFile_1 = require("./core/model/ArkFile");
|
|
50
|
+
const ArkNamespace_1 = require("./core/model/ArkNamespace");
|
|
51
|
+
const logger_1 = __importStar(require("./utils/logger"));
|
|
52
|
+
const ArkFileBuilder_1 = require("./core/model/builder/ArkFileBuilder");
|
|
53
|
+
const json5parser_1 = require("./utils/json5parser");
|
|
54
|
+
const getAllFiles_1 = require("./utils/getAllFiles");
|
|
55
|
+
const FileUtils_1 = require("./utils/FileUtils");
|
|
56
|
+
const ArkExport_1 = require("./core/model/ArkExport");
|
|
57
|
+
const ArkMethodBuilder_1 = require("./core/model/builder/ArkMethodBuilder");
|
|
58
|
+
const Const_1 = require("./core/common/Const");
|
|
59
|
+
const CallGraph_1 = require("./callgraph/model/CallGraph");
|
|
60
|
+
const CallGraphBuilder_1 = require("./callgraph/model/builder/CallGraphBuilder");
|
|
61
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'Scene');
|
|
62
|
+
var SceneBuildStage;
|
|
63
|
+
(function (SceneBuildStage) {
|
|
64
|
+
SceneBuildStage[SceneBuildStage["BUILD_INIT"] = 0] = "BUILD_INIT";
|
|
65
|
+
SceneBuildStage[SceneBuildStage["CLASS_DONE"] = 1] = "CLASS_DONE";
|
|
66
|
+
SceneBuildStage[SceneBuildStage["METHOD_DONE"] = 2] = "METHOD_DONE";
|
|
67
|
+
})(SceneBuildStage || (SceneBuildStage = {}));
|
|
68
|
+
;
|
|
69
|
+
/**
|
|
70
|
+
* The Scene class includes everything in the analyzed project.
|
|
71
|
+
* We should be able to re-generate the project's code based on this class.
|
|
72
|
+
*/
|
|
73
|
+
class Scene {
|
|
74
|
+
constructor() {
|
|
75
|
+
this.projectName = '';
|
|
76
|
+
this.projectFiles = [];
|
|
77
|
+
this.realProjectDir = '';
|
|
78
|
+
this.moduleScenesMap = new Map();
|
|
79
|
+
this.modulePath2NameMap = new Map();
|
|
80
|
+
this.globalImportInfos = [];
|
|
81
|
+
this.moduleSdkMap = new Map();
|
|
82
|
+
this.projectSdkMap = new Map();
|
|
83
|
+
// values that are visible in curr scope
|
|
84
|
+
this.visibleValue = new VisibleValue_1.VisibleValue();
|
|
85
|
+
// signature string to model
|
|
86
|
+
this.filesMap = new Map();
|
|
87
|
+
this.namespacesMap = new Map();
|
|
88
|
+
this.classesMap = new Map();
|
|
89
|
+
this.methodsMap = new Map();
|
|
90
|
+
// TODO: type of key should be signature object
|
|
91
|
+
this.sdkArkFilesMap = new Map();
|
|
92
|
+
this.sdkGlobalMap = new Map();
|
|
93
|
+
this.ohPkgContentMap = new Map();
|
|
94
|
+
this.ohPkgFilePath = '';
|
|
95
|
+
this.ohPkgContent = {};
|
|
96
|
+
this.buildStage = SceneBuildStage.BUILD_INIT;
|
|
97
|
+
}
|
|
98
|
+
getStage() {
|
|
99
|
+
return this.buildStage;
|
|
100
|
+
}
|
|
101
|
+
buildSceneFromProjectDir(sceneConfig) {
|
|
102
|
+
this.buildBasicInfo(sceneConfig);
|
|
103
|
+
this.genArkFiles();
|
|
104
|
+
this.collectProjectImportInfos();
|
|
105
|
+
}
|
|
106
|
+
buildBasicInfo(sceneConfig) {
|
|
107
|
+
var _a;
|
|
108
|
+
this.projectName = sceneConfig.getTargetProjectName();
|
|
109
|
+
this.realProjectDir = fs_1.default.realpathSync(sceneConfig.getTargetProjectDirectory());
|
|
110
|
+
this.projectFiles = sceneConfig.getProjectFiles();
|
|
111
|
+
const buildProfile = path_1.default.join(this.realProjectDir, './build-profile.json5');
|
|
112
|
+
if (fs_1.default.existsSync(buildProfile)) {
|
|
113
|
+
let configurationsText;
|
|
114
|
+
try {
|
|
115
|
+
configurationsText = fs_1.default.readFileSync(buildProfile, 'utf-8');
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
logger.error(`Error reading file: ${error}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const buildProfileJson = (0, json5parser_1.parseJsonText)(configurationsText);
|
|
122
|
+
const modules = buildProfileJson.modules;
|
|
123
|
+
if (modules instanceof Array) {
|
|
124
|
+
modules.forEach((module) => {
|
|
125
|
+
this.modulePath2NameMap.set(path_1.default.resolve(this.realProjectDir, path_1.default.join(module.srcPath)), module.name);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
logger.warn('There is no build-profile.json5 for this project.');
|
|
131
|
+
}
|
|
132
|
+
const OhPkgFilePath = path_1.default.join(this.realProjectDir, './oh-package.json5');
|
|
133
|
+
if (fs_1.default.existsSync(OhPkgFilePath)) {
|
|
134
|
+
this.ohPkgFilePath = OhPkgFilePath;
|
|
135
|
+
this.ohPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(this.ohPkgFilePath);
|
|
136
|
+
this.ohPkgContentMap.set(OhPkgFilePath, this.ohPkgContent);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
logger.warn('This project has no oh-package.json5!');
|
|
140
|
+
}
|
|
141
|
+
// handle sdks
|
|
142
|
+
(_a = sceneConfig.getSdksObj()) === null || _a === void 0 ? void 0 : _a.forEach((sdk) => {
|
|
143
|
+
if (!sdk.moduleName) {
|
|
144
|
+
this.buildSdk(sdk.name, sdk.path);
|
|
145
|
+
this.projectSdkMap.set(sdk.name, sdk);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
let moduleSdks = this.moduleSdkMap.get(sdk.moduleName);
|
|
149
|
+
if (moduleSdks) {
|
|
150
|
+
moduleSdks.push(sdk);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.moduleSdkMap.set(sdk.moduleName, [sdk]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
addDefaultConstructors() {
|
|
159
|
+
for (const file of this.getFiles()) {
|
|
160
|
+
for (const cls of ModelUtils_1.ModelUtils.getAllClassesInFile(file)) {
|
|
161
|
+
(0, ArkMethodBuilder_1.buildDefaultConstructor)(cls);
|
|
162
|
+
(0, ArkMethodBuilder_1.addInitInConstructor)(cls);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
buildAllMethodBody() {
|
|
167
|
+
this.buildStage = SceneBuildStage.CLASS_DONE;
|
|
168
|
+
for (const file of this.getFiles()) {
|
|
169
|
+
for (const cls of file.getClasses()) {
|
|
170
|
+
for (const method of cls.getMethods(true)) {
|
|
171
|
+
method.buildBody();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const namespace of this.getNamespacesMap().values()) {
|
|
176
|
+
for (const cls of namespace.getClasses()) {
|
|
177
|
+
for (const method of cls.getMethods(true)) {
|
|
178
|
+
method.buildBody();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
this.buildStage = SceneBuildStage.METHOD_DONE;
|
|
183
|
+
}
|
|
184
|
+
genArkFiles() {
|
|
185
|
+
this.projectFiles.forEach((file) => {
|
|
186
|
+
logger.info('=== parse file:', file);
|
|
187
|
+
let arkFile = new ArkFile_1.ArkFile();
|
|
188
|
+
arkFile.setScene(this);
|
|
189
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.realProjectDir, arkFile, this.projectName);
|
|
190
|
+
this.filesMap.set(arkFile.getFileSignature().toString(), arkFile);
|
|
191
|
+
});
|
|
192
|
+
this.buildAllMethodBody();
|
|
193
|
+
this.addDefaultConstructors();
|
|
194
|
+
}
|
|
195
|
+
buildSdk(sdkName, sdkPath) {
|
|
196
|
+
const allFiles = (0, getAllFiles_1.getAllFiles)(sdkPath, ['.ets', '.ts']);
|
|
197
|
+
allFiles.forEach((file) => {
|
|
198
|
+
logger.info('=== parse sdk file:', file);
|
|
199
|
+
let arkFile = new ArkFile_1.ArkFile();
|
|
200
|
+
arkFile.setScene(this);
|
|
201
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, path_1.default.normalize(sdkPath), arkFile, sdkName);
|
|
202
|
+
ModelUtils_1.ModelUtils.getAllClassesInFile(arkFile).forEach(cls => { var _a; return (_a = cls.getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.buildBody(); });
|
|
203
|
+
const fileSig = arkFile.getFileSignature().toString();
|
|
204
|
+
this.sdkArkFilesMap.set(fileSig, arkFile);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
buildScene4HarmonyProject() {
|
|
208
|
+
this.modulePath2NameMap.forEach((value, key) => {
|
|
209
|
+
const moduleOhPkgFilePath = path_1.default.resolve(key, './oh-package.json5');
|
|
210
|
+
if (fs_1.default.existsSync(moduleOhPkgFilePath)) {
|
|
211
|
+
const moduleOhPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(moduleOhPkgFilePath);
|
|
212
|
+
this.ohPkgContentMap.set(moduleOhPkgFilePath, moduleOhPkgContent);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
this.modulePath2NameMap.forEach((value, key) => {
|
|
216
|
+
let moduleScene = new ModuleScene();
|
|
217
|
+
moduleScene.ModuleScenBuilder(value, key, this);
|
|
218
|
+
this.moduleScenesMap.set(value, moduleScene);
|
|
219
|
+
});
|
|
220
|
+
this.buildAllMethodBody();
|
|
221
|
+
this.addDefaultConstructors();
|
|
222
|
+
}
|
|
223
|
+
buildModuleScene(moduleName, modulePath) {
|
|
224
|
+
if (this.moduleScenesMap.get(moduleName)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
// get oh-package.json5
|
|
228
|
+
const moduleOhPkgFilePath = path_1.default.resolve(this.realProjectDir, path_1.default.join(modulePath, './oh-package.json5'));
|
|
229
|
+
if (fs_1.default.existsSync(moduleOhPkgFilePath)) {
|
|
230
|
+
const moduleOhPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(moduleOhPkgFilePath);
|
|
231
|
+
this.ohPkgContentMap.set(moduleOhPkgFilePath, moduleOhPkgContent);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
logger.warn('Module: ', moduleName, 'has no oh-package.json5.');
|
|
235
|
+
}
|
|
236
|
+
// parse moduleOhPkgContent, get dependencies and build dependent module
|
|
237
|
+
const moduleOhPkgContent = this.ohPkgContentMap.get(moduleOhPkgFilePath);
|
|
238
|
+
if (moduleOhPkgContent) {
|
|
239
|
+
if (moduleOhPkgContent.dependencies instanceof Object) {
|
|
240
|
+
Object.entries(moduleOhPkgContent.dependencies).forEach(([k, v]) => {
|
|
241
|
+
const pattern = new RegExp('^(\\.\\.\\/\|\\.\\/)');
|
|
242
|
+
if (typeof (v) === 'string') {
|
|
243
|
+
let dependencyModulePath = '';
|
|
244
|
+
if (pattern.test(v)) {
|
|
245
|
+
dependencyModulePath = path_1.default.join(moduleOhPkgFilePath, v);
|
|
246
|
+
}
|
|
247
|
+
else if (v.startsWith('file:')) {
|
|
248
|
+
const dependencyFilePath = path_1.default.join(moduleOhPkgFilePath, v.replace(/^file:/, ''));
|
|
249
|
+
const dependencyOhPkgPath = (0, FileUtils_1.getFileRecursively)(path_1.default.dirname(dependencyFilePath), 'oh-package.json5');
|
|
250
|
+
dependencyModulePath = path_1.default.dirname(dependencyOhPkgPath);
|
|
251
|
+
}
|
|
252
|
+
logger.info('Dependency path: ', dependencyModulePath);
|
|
253
|
+
const dependencyModuleName = this.modulePath2NameMap.get(dependencyModulePath);
|
|
254
|
+
if (dependencyModuleName) {
|
|
255
|
+
this.buildModuleScene(dependencyModuleName, dependencyModulePath);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
let moduleScene = new ModuleScene();
|
|
262
|
+
moduleScene.ModuleScenBuilder(moduleName, modulePath, this);
|
|
263
|
+
this.moduleScenesMap.set(moduleName, moduleScene);
|
|
264
|
+
this.buildAllMethodBody();
|
|
265
|
+
}
|
|
266
|
+
getRealProjectDir() {
|
|
267
|
+
return this.realProjectDir;
|
|
268
|
+
}
|
|
269
|
+
getProjectName() {
|
|
270
|
+
return this.projectName;
|
|
271
|
+
}
|
|
272
|
+
getProjectFiles() {
|
|
273
|
+
return this.projectFiles;
|
|
274
|
+
}
|
|
275
|
+
getSdkGlobal(globalName) {
|
|
276
|
+
return this.sdkGlobalMap.get(globalName) || null;
|
|
277
|
+
}
|
|
278
|
+
getFile(fileSignature) {
|
|
279
|
+
if (this.projectName === fileSignature.getProjectName()) {
|
|
280
|
+
return this.filesMap.get(fileSignature.toString()) || null;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return this.sdkArkFilesMap.get(fileSignature.toString()) || null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
getFiles() {
|
|
287
|
+
return Array.from(this.filesMap.values());
|
|
288
|
+
}
|
|
289
|
+
getSdkArkFilesMap() {
|
|
290
|
+
return this.sdkArkFilesMap;
|
|
291
|
+
}
|
|
292
|
+
getModuleSdkMap() {
|
|
293
|
+
return this.moduleSdkMap;
|
|
294
|
+
}
|
|
295
|
+
getProjectSdkMap() {
|
|
296
|
+
return this.projectSdkMap;
|
|
297
|
+
}
|
|
298
|
+
getFilesMap() {
|
|
299
|
+
return this.filesMap;
|
|
300
|
+
}
|
|
301
|
+
getNamespace(namespaceSignature) {
|
|
302
|
+
if (this.projectName === namespaceSignature.getDeclaringFileSignature().getProjectName()) {
|
|
303
|
+
return this.getNamespacesMap().get(namespaceSignature.toString()) || null;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
const arkFile = this.sdkArkFilesMap.get(namespaceSignature.getDeclaringFileSignature().toString());
|
|
307
|
+
return (arkFile === null || arkFile === void 0 ? void 0 : arkFile.getNamespace(namespaceSignature)) || null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
getNamespacesMap() {
|
|
311
|
+
if (this.namespacesMap.size == 0) {
|
|
312
|
+
for (const file of this.getFiles()) {
|
|
313
|
+
ModelUtils_1.ModelUtils.getAllNamespacesInFile(file).forEach((namespace) => {
|
|
314
|
+
this.namespacesMap.set(namespace.getNamespaceSignature().toString(), namespace);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return this.namespacesMap;
|
|
319
|
+
}
|
|
320
|
+
getNamespaces() {
|
|
321
|
+
return Array.from(this.getNamespacesMap().values());
|
|
322
|
+
}
|
|
323
|
+
getClass(classSignature, refresh) {
|
|
324
|
+
var _a;
|
|
325
|
+
if (this.projectName === classSignature.getDeclaringFileSignature().getProjectName()) {
|
|
326
|
+
return this.getClassesMap(refresh).get(classSignature.toString()) || null;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const arkFile = this.sdkArkFilesMap.get(classSignature.getDeclaringFileSignature().toString());
|
|
330
|
+
const namespaceSignature = classSignature.getDeclaringNamespaceSignature();
|
|
331
|
+
if (namespaceSignature) {
|
|
332
|
+
return ((_a = arkFile === null || arkFile === void 0 ? void 0 : arkFile.getNamespace(namespaceSignature)) === null || _a === void 0 ? void 0 : _a.getClass(classSignature)) || null;
|
|
333
|
+
}
|
|
334
|
+
return (arkFile === null || arkFile === void 0 ? void 0 : arkFile.getClass(classSignature)) || null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
getClassesMap(refresh) {
|
|
338
|
+
if (refresh || (this.classesMap.size === 0 && this.buildStage >= SceneBuildStage.CLASS_DONE)) {
|
|
339
|
+
this.classesMap.clear();
|
|
340
|
+
for (const file of this.getFiles()) {
|
|
341
|
+
for (const cls of file.getClasses()) {
|
|
342
|
+
this.classesMap.set(cls.getSignature().toString(), cls);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
for (const namespace of this.getNamespacesMap().values()) {
|
|
346
|
+
for (const cls of namespace.getClasses()) {
|
|
347
|
+
this.classesMap.set(cls.getSignature().toString(), cls);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return this.classesMap;
|
|
352
|
+
}
|
|
353
|
+
getClasses(refresh) {
|
|
354
|
+
return Array.from(this.getClassesMap(refresh).values());
|
|
355
|
+
}
|
|
356
|
+
getMethod(methodSignature, refresh) {
|
|
357
|
+
var _a;
|
|
358
|
+
if (this.projectName === methodSignature.getDeclaringClassSignature().getDeclaringFileSignature().getProjectName()) {
|
|
359
|
+
return this.getMethodsMap(refresh).get(methodSignature.toString()) || null;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
return ((_a = this.getClass(methodSignature.getDeclaringClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethod(methodSignature)) || null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
getMethodsMap(refresh) {
|
|
366
|
+
if (refresh || (this.methodsMap.size === 0 && this.buildStage >= SceneBuildStage.METHOD_DONE)) {
|
|
367
|
+
this.methodsMap.clear();
|
|
368
|
+
for (const cls of this.getClassesMap().values()) {
|
|
369
|
+
for (const method of cls.getMethods(true)) {
|
|
370
|
+
this.methodsMap.set(method.getSignature().toString(), method);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return this.methodsMap;
|
|
375
|
+
}
|
|
376
|
+
getMethods(refresh) {
|
|
377
|
+
return Array.from(this.getMethodsMap(refresh).values());
|
|
378
|
+
}
|
|
379
|
+
addToMethodsMap(method) {
|
|
380
|
+
this.methodsMap.set(method.getSignature().toString(), method);
|
|
381
|
+
}
|
|
382
|
+
hasMainMethod() {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
//Get the set of entry points that are used to build the call graph.
|
|
386
|
+
getEntryPoints() {
|
|
387
|
+
return [];
|
|
388
|
+
}
|
|
389
|
+
/** get values that is visible in curr scope */
|
|
390
|
+
getVisibleValue() {
|
|
391
|
+
return this.visibleValue;
|
|
392
|
+
}
|
|
393
|
+
getOhPkgContent() {
|
|
394
|
+
return this.ohPkgContent;
|
|
395
|
+
}
|
|
396
|
+
getOhPkgContentMap() {
|
|
397
|
+
return this.ohPkgContentMap;
|
|
398
|
+
}
|
|
399
|
+
getOhPkgFilePath() {
|
|
400
|
+
return this.ohPkgFilePath;
|
|
401
|
+
}
|
|
402
|
+
makeCallGraphCHA(entryPoints) {
|
|
403
|
+
let callGraph = new CallGraph_1.CallGraph(this);
|
|
404
|
+
let callGraphBuilder = new CallGraphBuilder_1.CallGraphBuilder(callGraph, this);
|
|
405
|
+
callGraphBuilder.buildClassHierarchyCallGraph(entryPoints);
|
|
406
|
+
return callGraph;
|
|
407
|
+
}
|
|
408
|
+
makeCallGraphRTA(entryPoints) {
|
|
409
|
+
let callGraph = new CallGraph_1.CallGraph(this);
|
|
410
|
+
let callGraphBuilder = new CallGraphBuilder_1.CallGraphBuilder(callGraph, this);
|
|
411
|
+
callGraphBuilder.buildRapidTypeCallGraph(entryPoints);
|
|
412
|
+
return callGraph;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* inference type for each non-default method
|
|
416
|
+
* because default and generated method was finished
|
|
417
|
+
*/
|
|
418
|
+
inferTypes() {
|
|
419
|
+
this.sdkArkFilesMap.forEach(file => {
|
|
420
|
+
ModelUtils_1.ModelUtils.buildGlobalMap(file, this.sdkGlobalMap);
|
|
421
|
+
});
|
|
422
|
+
this.filesMap.forEach(file => {
|
|
423
|
+
ModelUtils_1.ModelUtils.getAllClassesInFile(file).forEach(arkClass => {
|
|
424
|
+
TypeInference_1.TypeInference.inferGenericType(arkClass.getGenericsTypes(), arkClass);
|
|
425
|
+
arkClass.getFields().forEach(arkField => TypeInference_1.TypeInference.inferTypeInArkField(arkField));
|
|
426
|
+
const defaultArkMethod = arkClass.getDefaultArkMethod();
|
|
427
|
+
if (defaultArkMethod) {
|
|
428
|
+
TypeInference_1.TypeInference.inferTypeInMethod(defaultArkMethod);
|
|
429
|
+
}
|
|
430
|
+
arkClass.getMethods().forEach(arkMethod => TypeInference_1.TypeInference.inferTypeInMethod(arkMethod));
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
this.getClassesMap(true);
|
|
434
|
+
this.getMethodsMap(true);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* @Deprecated
|
|
438
|
+
*/
|
|
439
|
+
inferSimpleTypes() {
|
|
440
|
+
for (let arkFile of this.getFiles()) {
|
|
441
|
+
for (let arkClass of arkFile.getClasses()) {
|
|
442
|
+
for (let arkMethod of arkClass.getMethods()) {
|
|
443
|
+
TypeInference_1.TypeInference.inferSimpleTypeInMethod(arkMethod);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
collectProjectImportInfos() {
|
|
449
|
+
this.getFiles().forEach((arkFile) => {
|
|
450
|
+
arkFile.getImportInfos().forEach((importInfo) => {
|
|
451
|
+
this.globalImportInfos.push(importInfo);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
getClassMap() {
|
|
456
|
+
var _a, _b, _c, _d;
|
|
457
|
+
const classMap = new Map();
|
|
458
|
+
for (const file of this.getFiles()) {
|
|
459
|
+
const fileClass = [];
|
|
460
|
+
const namespaceStack = [];
|
|
461
|
+
const parentMap = new Map();
|
|
462
|
+
const finalNamespaces = [];
|
|
463
|
+
for (const arkClass of file.getClasses()) {
|
|
464
|
+
fileClass.push(arkClass);
|
|
465
|
+
}
|
|
466
|
+
for (const ns of file.getNamespaces()) {
|
|
467
|
+
namespaceStack.push(ns);
|
|
468
|
+
parentMap.set(ns, file);
|
|
469
|
+
}
|
|
470
|
+
classMap.set(file.getFileSignature(), fileClass);
|
|
471
|
+
// 第一轮遍历,加上每个namespace自己的class
|
|
472
|
+
while (namespaceStack.length > 0) {
|
|
473
|
+
const ns = namespaceStack.shift();
|
|
474
|
+
const nsClass = [];
|
|
475
|
+
for (const arkClass of ns.getClasses()) {
|
|
476
|
+
nsClass.push(arkClass);
|
|
477
|
+
}
|
|
478
|
+
classMap.set(ns.getNamespaceSignature(), nsClass);
|
|
479
|
+
if (ns.getNamespaces().length == 0) {
|
|
480
|
+
finalNamespaces.push(ns);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
for (const nsns of ns.getNamespaces()) {
|
|
484
|
+
namespaceStack.push(nsns);
|
|
485
|
+
parentMap.set(nsns, ns);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// 第二轮遍历,父节点加上子节点的export的class
|
|
490
|
+
while (finalNamespaces.length > 0) {
|
|
491
|
+
const finalNS = finalNamespaces.shift();
|
|
492
|
+
const exportClass = [];
|
|
493
|
+
for (const arkClass of finalNS.getClasses()) {
|
|
494
|
+
if (arkClass.isExported()) {
|
|
495
|
+
exportClass.push(arkClass);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const parent = parentMap.get(finalNS);
|
|
499
|
+
if (parent instanceof ArkNamespace_1.ArkNamespace) {
|
|
500
|
+
(_a = classMap.get(parent.getNamespaceSignature())) === null || _a === void 0 ? void 0 : _a.push(...exportClass);
|
|
501
|
+
}
|
|
502
|
+
else if (parent instanceof ArkFile_1.ArkFile) {
|
|
503
|
+
(_b = classMap.get(parent.getFileSignature())) === null || _b === void 0 ? void 0 : _b.push(...exportClass);
|
|
504
|
+
}
|
|
505
|
+
let p = finalNS;
|
|
506
|
+
while (!(parentMap.get(p) instanceof ArkFile_1.ArkFile) && p.isExported()) {
|
|
507
|
+
const grandParent = parentMap.get(parentMap.get(p));
|
|
508
|
+
if (grandParent instanceof ArkNamespace_1.ArkNamespace) {
|
|
509
|
+
(_c = classMap.get(grandParent.getNamespaceSignature())) === null || _c === void 0 ? void 0 : _c.push(...exportClass);
|
|
510
|
+
p = parentMap.get(p);
|
|
511
|
+
}
|
|
512
|
+
else if (grandParent instanceof ArkFile_1.ArkFile) {
|
|
513
|
+
(_d = classMap.get(grandParent.getFileSignature())) === null || _d === void 0 ? void 0 : _d.push(...exportClass);
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (parent instanceof ArkNamespace_1.ArkNamespace && !finalNamespaces.includes(parent)) {
|
|
518
|
+
finalNamespaces.push(parent);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
for (const file of this.getFiles()) {
|
|
523
|
+
// 文件加上import的class,包括ns的
|
|
524
|
+
const importClasses = [];
|
|
525
|
+
const importNameSpaces = [];
|
|
526
|
+
for (const importInfo of file.getImportInfos()) {
|
|
527
|
+
const importClass = ModelUtils_1.ModelUtils.getClassInImportInfoWithName(importInfo.getImportClauseName(), file);
|
|
528
|
+
if (importClass && !importClasses.includes(importClass)) {
|
|
529
|
+
importClasses.push(importClass);
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
const importNameSpace = ModelUtils_1.ModelUtils.getNamespaceInImportInfoWithName(importInfo.getImportClauseName(), file);
|
|
533
|
+
if (importNameSpace && !importNameSpaces.includes(importNameSpace)) {
|
|
534
|
+
try {
|
|
535
|
+
// 遗留问题:只统计了项目文件的namespace,没统计sdk文件内部的引入
|
|
536
|
+
const importNameSpaceClasses = classMap.get(importNameSpace.getNamespaceSignature());
|
|
537
|
+
importClasses.push(...importNameSpaceClasses.filter(c => !importClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
|
|
538
|
+
}
|
|
539
|
+
catch (_e) {
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const fileClasses = classMap.get(file.getFileSignature());
|
|
544
|
+
fileClasses.push(...importClasses.filter(c => !fileClasses.includes(c)));
|
|
545
|
+
// 子节点加上父节点的class
|
|
546
|
+
const namespaceStack = [...file.getNamespaces()];
|
|
547
|
+
for (const ns of namespaceStack) {
|
|
548
|
+
const nsClasses = classMap.get(ns.getNamespaceSignature());
|
|
549
|
+
nsClasses.push(...fileClasses.filter(c => !nsClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
|
|
550
|
+
}
|
|
551
|
+
while (namespaceStack.length > 0) {
|
|
552
|
+
const ns = namespaceStack.shift();
|
|
553
|
+
const nsClasses = classMap.get(ns.getNamespaceSignature());
|
|
554
|
+
for (const nsns of ns.getNamespaces()) {
|
|
555
|
+
const nsnsClasses = classMap.get(nsns.getNamespaceSignature());
|
|
556
|
+
nsnsClasses.push(...nsClasses.filter(c => !nsnsClasses.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
|
|
557
|
+
namespaceStack.push(nsns);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return classMap;
|
|
562
|
+
}
|
|
563
|
+
getGlobalVariableMap() {
|
|
564
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
565
|
+
const globalVariableMap = new Map();
|
|
566
|
+
for (const file of this.getFiles()) {
|
|
567
|
+
const namespaceStack = [];
|
|
568
|
+
const parentMap = new Map();
|
|
569
|
+
const finalNamespaces = [];
|
|
570
|
+
const globalLocals = [];
|
|
571
|
+
(_b = (_a = file.getDefaultClass()) === null || _a === void 0 ? void 0 : _a.getDefaultArkMethod().getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().forEach(local => {
|
|
572
|
+
if (local.getDeclaringStmt() && local.getName() != 'this' && local.getName()[0] != '$') {
|
|
573
|
+
globalLocals.push(local);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
globalVariableMap.set(file.getFileSignature(), globalLocals);
|
|
577
|
+
for (const ns of file.getNamespaces()) {
|
|
578
|
+
namespaceStack.push(ns);
|
|
579
|
+
parentMap.set(ns, file);
|
|
580
|
+
}
|
|
581
|
+
// 第一轮遍历,加上每个namespace自己的local
|
|
582
|
+
while (namespaceStack.length > 0) {
|
|
583
|
+
const ns = namespaceStack.shift();
|
|
584
|
+
const nsGlobalLocals = [];
|
|
585
|
+
(_c = ns.getDefaultClass().getDefaultArkMethod().getBody()) === null || _c === void 0 ? void 0 : _c.getLocals().forEach(local => {
|
|
586
|
+
if (local.getDeclaringStmt() && local.getName() != 'this' && local.getName()[0] != '$') {
|
|
587
|
+
nsGlobalLocals.push(local);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
globalVariableMap.set(ns.getNamespaceSignature(), nsGlobalLocals);
|
|
591
|
+
if (ns.getNamespaces().length == 0) {
|
|
592
|
+
finalNamespaces.push(ns);
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
for (const nsns of ns.getNamespaces()) {
|
|
596
|
+
namespaceStack.push(nsns);
|
|
597
|
+
parentMap.set(nsns, ns);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
// 第二轮遍历,父节点加上子节点的export的local
|
|
602
|
+
while (finalNamespaces.length > 0) {
|
|
603
|
+
const finalNS = finalNamespaces.shift();
|
|
604
|
+
const exportLocal = [];
|
|
605
|
+
for (const exportInfo of finalNS.getExportInfos()) {
|
|
606
|
+
if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.LOCAL && exportInfo.getArkExport()) {
|
|
607
|
+
exportLocal.push(exportInfo.getArkExport());
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
const parent = parentMap.get(finalNS);
|
|
611
|
+
if (parent instanceof ArkNamespace_1.ArkNamespace) {
|
|
612
|
+
(_d = globalVariableMap.get(parent.getNamespaceSignature())) === null || _d === void 0 ? void 0 : _d.push(...exportLocal);
|
|
613
|
+
}
|
|
614
|
+
else if (parent instanceof ArkFile_1.ArkFile) {
|
|
615
|
+
(_e = globalVariableMap.get(parent.getFileSignature())) === null || _e === void 0 ? void 0 : _e.push(...exportLocal);
|
|
616
|
+
}
|
|
617
|
+
let p = finalNS;
|
|
618
|
+
while (!(parentMap.get(p) instanceof ArkFile_1.ArkFile) && p.isExported()) {
|
|
619
|
+
const grandParent = parentMap.get(parentMap.get(p));
|
|
620
|
+
if (grandParent instanceof ArkNamespace_1.ArkNamespace) {
|
|
621
|
+
(_f = globalVariableMap.get(grandParent.getNamespaceSignature())) === null || _f === void 0 ? void 0 : _f.push(...exportLocal);
|
|
622
|
+
p = parentMap.get(p);
|
|
623
|
+
}
|
|
624
|
+
else if (grandParent instanceof ArkFile_1.ArkFile) {
|
|
625
|
+
(_g = globalVariableMap.get(grandParent.getFileSignature())) === null || _g === void 0 ? void 0 : _g.push(...exportLocal);
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (parent instanceof ArkNamespace_1.ArkNamespace && !finalNamespaces.includes(parent)) {
|
|
630
|
+
finalNamespaces.push(parent);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
for (const file of this.getFiles()) {
|
|
635
|
+
// 文件加上import的local,包括ns的
|
|
636
|
+
const importLocals = [];
|
|
637
|
+
const importNameSpaces = [];
|
|
638
|
+
for (const importInfo of file.getImportInfos()) {
|
|
639
|
+
const importLocal = ModelUtils_1.ModelUtils.getLocalInImportInfoWithName(importInfo.getImportClauseName(), file);
|
|
640
|
+
if (importLocal && !importLocals.includes(importLocal)) {
|
|
641
|
+
importLocals.push(importLocal);
|
|
642
|
+
}
|
|
643
|
+
const importNameSpace = ModelUtils_1.ModelUtils.getNamespaceInImportInfoWithName(importInfo.getImportClauseName(), file);
|
|
644
|
+
if (importNameSpace && !importNameSpaces.includes(importNameSpace)) {
|
|
645
|
+
try {
|
|
646
|
+
// 遗留问题:只统计了项目文件,没统计sdk文件内部的引入
|
|
647
|
+
const importNameSpaceClasses = globalVariableMap.get(importNameSpace.getNamespaceSignature());
|
|
648
|
+
importLocals.push(...importNameSpaceClasses.filter(c => !importLocals.includes(c) && c.getName() != '_DEFAULT_ARK_CLASS'));
|
|
649
|
+
}
|
|
650
|
+
catch (_h) {
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const fileLocals = globalVariableMap.get(file.getFileSignature());
|
|
655
|
+
fileLocals.push(...importLocals.filter(c => !fileLocals.includes(c)));
|
|
656
|
+
// 子节点加上父节点的local
|
|
657
|
+
const namespaceStack = [...file.getNamespaces()];
|
|
658
|
+
for (const ns of namespaceStack) {
|
|
659
|
+
const nsLocals = globalVariableMap.get(ns.getNamespaceSignature());
|
|
660
|
+
const nsLocalNameSet = new Set(nsLocals.map(item => item.getName()));
|
|
661
|
+
for (const local of fileLocals) {
|
|
662
|
+
if (!nsLocalNameSet.has(local.getName())) {
|
|
663
|
+
nsLocals.push(local);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
while (namespaceStack.length > 0) {
|
|
668
|
+
const ns = namespaceStack.shift();
|
|
669
|
+
const nsLocals = globalVariableMap.get(ns.getNamespaceSignature());
|
|
670
|
+
for (const nsns of ns.getNamespaces()) {
|
|
671
|
+
const nsnsLocals = globalVariableMap.get(nsns.getNamespaceSignature());
|
|
672
|
+
const nsnsLocalNameSet = new Set(nsnsLocals.map(item => item.getName()));
|
|
673
|
+
for (const local of nsLocals) {
|
|
674
|
+
if (!nsnsLocalNameSet.has(local.getName())) {
|
|
675
|
+
nsnsLocals.push(local);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
namespaceStack.push(nsns);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return globalVariableMap;
|
|
683
|
+
}
|
|
684
|
+
getStaticInitMethods() {
|
|
685
|
+
const staticInitMethods = [];
|
|
686
|
+
for (const method of Array.from(this.getMethodsMap(true).values())) {
|
|
687
|
+
if (method.getName() == Const_1.STATIC_INIT_METHOD_NAME) {
|
|
688
|
+
staticInitMethods.push(method);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return staticInitMethods;
|
|
692
|
+
}
|
|
693
|
+
buildClassDone() {
|
|
694
|
+
return this.buildStage >= SceneBuildStage.CLASS_DONE;
|
|
695
|
+
}
|
|
696
|
+
getModuleScene(moduleName) {
|
|
697
|
+
return this.moduleScenesMap.get(moduleName);
|
|
698
|
+
}
|
|
699
|
+
getModuleSceneMap() {
|
|
700
|
+
return this.moduleScenesMap;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
exports.Scene = Scene;
|
|
704
|
+
class ModuleScene {
|
|
705
|
+
constructor() {
|
|
706
|
+
this.projectScene = new Scene();
|
|
707
|
+
this.moduleName = '';
|
|
708
|
+
this.modulePath = '';
|
|
709
|
+
this.moduleOhPkgFilePath = '';
|
|
710
|
+
this.ohPkgContent = {};
|
|
711
|
+
}
|
|
712
|
+
ModuleScenBuilder(moduleName, modulePath, projectScene, recursively = false) {
|
|
713
|
+
this.moduleName = moduleName;
|
|
714
|
+
this.modulePath = modulePath;
|
|
715
|
+
this.projectScene = projectScene;
|
|
716
|
+
this.getModuleOhPkgFilePath();
|
|
717
|
+
if (this.moduleOhPkgFilePath) {
|
|
718
|
+
this.ohPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(this.moduleOhPkgFilePath);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
logger.warn('This module has no oh-package.json5!');
|
|
722
|
+
}
|
|
723
|
+
this.genArkFiles();
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* get oh-package.json5
|
|
727
|
+
*/
|
|
728
|
+
getModuleOhPkgFilePath() {
|
|
729
|
+
const moduleOhPkgFilePath = path_1.default.resolve(this.projectScene.getRealProjectDir(), path_1.default.join(this.modulePath, './oh-package.json5'));
|
|
730
|
+
if (fs_1.default.existsSync(moduleOhPkgFilePath)) {
|
|
731
|
+
this.moduleOhPkgFilePath = moduleOhPkgFilePath;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* get nodule name
|
|
736
|
+
* @returns return module name
|
|
737
|
+
*/
|
|
738
|
+
getModuleName() {
|
|
739
|
+
return this.moduleName;
|
|
740
|
+
}
|
|
741
|
+
getModulePath() {
|
|
742
|
+
return this.modulePath;
|
|
743
|
+
}
|
|
744
|
+
getOhPkgFilePath() {
|
|
745
|
+
return this.moduleOhPkgFilePath;
|
|
746
|
+
}
|
|
747
|
+
getOhPkgContent() {
|
|
748
|
+
return this.ohPkgContent;
|
|
749
|
+
}
|
|
750
|
+
genArkFiles() {
|
|
751
|
+
(0, getAllFiles_1.getAllFiles)(this.modulePath, ['.ets', '.ts']).forEach((file) => {
|
|
752
|
+
logger.info('=== parse file:', file);
|
|
753
|
+
let arkFile = new ArkFile_1.ArkFile();
|
|
754
|
+
arkFile.setScene(this.projectScene);
|
|
755
|
+
arkFile.setModuleScene(this);
|
|
756
|
+
(0, ArkFileBuilder_1.buildArkFileFromFile)(file, this.projectScene.getRealProjectDir(), arkFile, this.projectScene.getProjectName());
|
|
757
|
+
const fileSig = arkFile.getFileSignature().toString();
|
|
758
|
+
this.projectScene.getFilesMap().set(fileSig, arkFile);
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
exports.ModuleScene = ModuleScene;
|