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,27 @@
|
|
|
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.Printer = void 0;
|
|
18
|
+
const ArkStream_1 = require("./ArkStream");
|
|
19
|
+
/**
|
|
20
|
+
* @category save
|
|
21
|
+
*/
|
|
22
|
+
class Printer {
|
|
23
|
+
constructor(indent = '') {
|
|
24
|
+
this.printer = new ArkStream_1.ArkCodeBuffer(indent);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Printer = Printer;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ArkFile } from '../core/model/ArkFile';
|
|
2
|
+
import { Printer } from './Printer';
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* // dump method IR to ts source
|
|
6
|
+
* let method: Method = xx;
|
|
7
|
+
* let srcPrinter = new SourceMethodPrinter(method);
|
|
8
|
+
* PrinterBuilder.dump(srcPrinter, 'output.ts');
|
|
9
|
+
*
|
|
10
|
+
* // dump method original ts source
|
|
11
|
+
* PrinterBuilder.dumpOriginal(srcPrinter, 'output.ts');
|
|
12
|
+
*
|
|
13
|
+
* // dump method cfg to dot
|
|
14
|
+
* let dotPrinter = new DotMethodPrinter(method);
|
|
15
|
+
* PrinterBuilder.dump(dotPrinter, 'output.dot');
|
|
16
|
+
*
|
|
17
|
+
* // dump method original dot
|
|
18
|
+
* PrinterBuilder.dumpOriginal(dotPrinter, 'output.dot');
|
|
19
|
+
*
|
|
20
|
+
* // dump project
|
|
21
|
+
* let printer = new PrinterBuilder('output');
|
|
22
|
+
* for (let f of scene.getFiles()) {
|
|
23
|
+
* printer.dumpToTs(f);
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @category save
|
|
27
|
+
*/
|
|
28
|
+
export declare class PrinterBuilder {
|
|
29
|
+
outputDir: string;
|
|
30
|
+
constructor(outputDir?: string);
|
|
31
|
+
static dump(source: Printer, output: string): void;
|
|
32
|
+
static dumpOriginal(source: Printer, output: string): void;
|
|
33
|
+
protected getOutputDir(arkFile: ArkFile): string;
|
|
34
|
+
dumpToDot(arkFile: ArkFile, output?: string | undefined): void;
|
|
35
|
+
dumpToTs(arkFile: ArkFile, output?: string | undefined): void;
|
|
36
|
+
dumpToJson(arkFile: ArkFile, output?: string | undefined): void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=PrinterBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrinterBuilder.d.ts","sourceRoot":"","sources":["../../src/save/PrinterBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAc;IACvB,SAAS,EAAE,MAAM,CAAC;gBACN,SAAS,GAAE,MAAW;WAIpB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;WAMpC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;IAM1D,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAQzC,SAAS,CACZ,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,MAAM,GAAG,SAAqB,GACvC,IAAI;IAcA,QAAQ,CACX,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,MAAM,GAAG,SAAqB,GACvC,IAAI;IAWA,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAM,GAAG,SAAqB,GAAG,IAAI;CASpF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.PrinterBuilder = void 0;
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const path_1 = require("path");
|
|
23
|
+
const ArkStream_1 = require("./ArkStream");
|
|
24
|
+
const DotPrinter_1 = require("./DotPrinter");
|
|
25
|
+
const SourceFilePrinter_1 = require("./source/SourceFilePrinter");
|
|
26
|
+
const JsonPrinter_1 = require("./JsonPrinter");
|
|
27
|
+
/**
|
|
28
|
+
* @example
|
|
29
|
+
* // dump method IR to ts source
|
|
30
|
+
* let method: Method = xx;
|
|
31
|
+
* let srcPrinter = new SourceMethodPrinter(method);
|
|
32
|
+
* PrinterBuilder.dump(srcPrinter, 'output.ts');
|
|
33
|
+
*
|
|
34
|
+
* // dump method original ts source
|
|
35
|
+
* PrinterBuilder.dumpOriginal(srcPrinter, 'output.ts');
|
|
36
|
+
*
|
|
37
|
+
* // dump method cfg to dot
|
|
38
|
+
* let dotPrinter = new DotMethodPrinter(method);
|
|
39
|
+
* PrinterBuilder.dump(dotPrinter, 'output.dot');
|
|
40
|
+
*
|
|
41
|
+
* // dump method original dot
|
|
42
|
+
* PrinterBuilder.dumpOriginal(dotPrinter, 'output.dot');
|
|
43
|
+
*
|
|
44
|
+
* // dump project
|
|
45
|
+
* let printer = new PrinterBuilder('output');
|
|
46
|
+
* for (let f of scene.getFiles()) {
|
|
47
|
+
* printer.dumpToTs(f);
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* @category save
|
|
51
|
+
*/
|
|
52
|
+
class PrinterBuilder {
|
|
53
|
+
constructor(outputDir = '') {
|
|
54
|
+
this.outputDir = outputDir;
|
|
55
|
+
}
|
|
56
|
+
static dump(source, output) {
|
|
57
|
+
let streamOut = new ArkStream_1.ArkStream(fs_1.default.createWriteStream(output));
|
|
58
|
+
streamOut.write(source.dump());
|
|
59
|
+
streamOut.close();
|
|
60
|
+
}
|
|
61
|
+
static dumpOriginal(source, output) {
|
|
62
|
+
let streamOut = new ArkStream_1.ArkStream(fs_1.default.createWriteStream(output));
|
|
63
|
+
streamOut.write(source.dumpOriginal());
|
|
64
|
+
streamOut.close();
|
|
65
|
+
}
|
|
66
|
+
getOutputDir(arkFile) {
|
|
67
|
+
if (this.outputDir === '') {
|
|
68
|
+
return (0, path_1.join)(arkFile.getProjectDir(), '..', 'output');
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return (0, path_1.join)(this.outputDir);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
dumpToDot(arkFile, output = undefined) {
|
|
75
|
+
let filename = output;
|
|
76
|
+
if (output === undefined) {
|
|
77
|
+
filename = (0, path_1.join)(this.getOutputDir(arkFile), arkFile.getName() + '.dot');
|
|
78
|
+
}
|
|
79
|
+
fs_1.default.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
|
|
80
|
+
let printer = new DotPrinter_1.DotFilePrinter(arkFile);
|
|
81
|
+
PrinterBuilder.dump(printer, filename);
|
|
82
|
+
}
|
|
83
|
+
dumpToTs(arkFile, output = undefined) {
|
|
84
|
+
let filename = output;
|
|
85
|
+
if (filename === undefined) {
|
|
86
|
+
filename = (0, path_1.join)(this.getOutputDir(arkFile), arkFile.getName());
|
|
87
|
+
}
|
|
88
|
+
fs_1.default.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
|
|
89
|
+
let printer = new SourceFilePrinter_1.SourceFilePrinter(arkFile);
|
|
90
|
+
PrinterBuilder.dump(printer, filename);
|
|
91
|
+
}
|
|
92
|
+
dumpToJson(arkFile, output = undefined) {
|
|
93
|
+
let filename = output;
|
|
94
|
+
if (filename === undefined) {
|
|
95
|
+
filename = (0, path_1.join)(this.getOutputDir(arkFile), arkFile.getName() + '.json');
|
|
96
|
+
}
|
|
97
|
+
fs_1.default.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
|
|
98
|
+
let printer = new JsonPrinter_1.JsonPrinter(arkFile);
|
|
99
|
+
PrinterBuilder.dump(printer, filename);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.PrinterBuilder = PrinterBuilder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializeArkIR.d.ts","sourceRoot":"","sources":["../../src/save/serializeArkIR.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiHpC,eAAO,MAAM,OAAO,SAmCd,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.program = void 0;
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const commander_1 = require("commander");
|
|
24
|
+
const PrinterBuilder_1 = require("./PrinterBuilder");
|
|
25
|
+
const Config_1 = require("../Config");
|
|
26
|
+
const Scene_1 = require("../Scene");
|
|
27
|
+
function serializeTsFile(input, output, verbose = false) {
|
|
28
|
+
if (verbose)
|
|
29
|
+
console.log(`Serializing TS file to JSON: '${input}' -> '${output}'`);
|
|
30
|
+
let filepath = path_1.default.resolve(input);
|
|
31
|
+
let projectDir = path_1.default.dirname(filepath);
|
|
32
|
+
if (verbose)
|
|
33
|
+
console.log("Building scene...");
|
|
34
|
+
let config = new Config_1.SceneConfig();
|
|
35
|
+
config.buildConfig("single-file", projectDir, []);
|
|
36
|
+
config.getProjectFiles().push(filepath);
|
|
37
|
+
let scene = new Scene_1.Scene();
|
|
38
|
+
scene.buildSceneFromProjectDir(config);
|
|
39
|
+
let files = scene.getFiles();
|
|
40
|
+
if (verbose) {
|
|
41
|
+
console.log(`Scene contains ${files.length} files:`);
|
|
42
|
+
for (let f of files) {
|
|
43
|
+
console.log(`- '${f.getName()}'`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (verbose)
|
|
47
|
+
console.log("Extracting single ArkFile...");
|
|
48
|
+
if (files.length === 0) {
|
|
49
|
+
console.error(`ERROR: No files found in the project directory '${projectDir}'.`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
if (files.length > 1) {
|
|
53
|
+
console.error(`ERROR: More than one file found in the project directory '${projectDir}'.`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
// Note: we explicitly push a single path to the project files (in config),
|
|
57
|
+
// so we expect there is only *one* ArkFile in the scene.
|
|
58
|
+
let arkFile = scene.getFiles()[0];
|
|
59
|
+
let outPath;
|
|
60
|
+
if (fs_1.default.existsSync(output) && fs_1.default.statSync(output).isDirectory()) {
|
|
61
|
+
outPath = path_1.default.join(output, arkFile.getName() + '.json');
|
|
62
|
+
}
|
|
63
|
+
else if (!fs_1.default.existsSync(output) && output.endsWith("/")) {
|
|
64
|
+
outPath = path_1.default.join(output, arkFile.getName() + '.json');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
outPath = output;
|
|
68
|
+
}
|
|
69
|
+
console.log(`Serializing ArkIR for '${arkFile.getName()}' to '${outPath}'...`);
|
|
70
|
+
let printer = new PrinterBuilder_1.PrinterBuilder();
|
|
71
|
+
printer.dumpToJson(arkFile, outPath);
|
|
72
|
+
if (verbose)
|
|
73
|
+
console.log("All done!");
|
|
74
|
+
}
|
|
75
|
+
function serializeMultipleTsFiles(inputDir, outDir, verbose = false) {
|
|
76
|
+
console.log(`Serializing multiple TS files to JSON: '${inputDir}' -> '${outDir}'`);
|
|
77
|
+
if (fs_1.default.existsSync(outDir) && !fs_1.default.statSync(outDir).isDirectory()) {
|
|
78
|
+
console.error(`ERROR: Output path must be a directory.`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
if (verbose)
|
|
82
|
+
console.log("Building scene...");
|
|
83
|
+
let config = new Config_1.SceneConfig();
|
|
84
|
+
config.buildFromProjectDir(inputDir);
|
|
85
|
+
let scene = new Scene_1.Scene();
|
|
86
|
+
scene.buildSceneFromProjectDir(config);
|
|
87
|
+
let files = scene.getFiles();
|
|
88
|
+
if (verbose) {
|
|
89
|
+
console.log(`Scene contains ${files.length} files:`);
|
|
90
|
+
for (let f of files) {
|
|
91
|
+
console.log(`- '${f.getName()}'`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (verbose)
|
|
95
|
+
console.log("Serializing...");
|
|
96
|
+
let printer = new PrinterBuilder_1.PrinterBuilder();
|
|
97
|
+
for (let f of files) {
|
|
98
|
+
let filepath = f.getName();
|
|
99
|
+
let outPath = path_1.default.join(outDir, filepath + '.json');
|
|
100
|
+
console.log(`Serializing ArkIR for '${filepath}' to '${outPath}'...`);
|
|
101
|
+
printer.dumpToJson(f, outPath);
|
|
102
|
+
}
|
|
103
|
+
if (verbose)
|
|
104
|
+
console.log("All done!");
|
|
105
|
+
}
|
|
106
|
+
function serializeTsProject(inputDir, outDir, verbose = false) {
|
|
107
|
+
console.log(`Serializing TS project to JSON: '${inputDir}' -> '${outDir}'`);
|
|
108
|
+
if (fs_1.default.existsSync(outDir) && !fs_1.default.statSync(outDir).isDirectory()) {
|
|
109
|
+
console.error(`ERROR: Output path must be a directory.`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
if (verbose)
|
|
113
|
+
console.log("Building scene...");
|
|
114
|
+
let config = new Config_1.SceneConfig();
|
|
115
|
+
config.buildFromProjectDir(inputDir);
|
|
116
|
+
let scene = new Scene_1.Scene();
|
|
117
|
+
scene.buildSceneFromProjectDir(config);
|
|
118
|
+
if (verbose)
|
|
119
|
+
console.log("Serializing...");
|
|
120
|
+
let printer = new PrinterBuilder_1.PrinterBuilder();
|
|
121
|
+
for (let f of scene.getFiles()) {
|
|
122
|
+
let filepath = f.getName();
|
|
123
|
+
let outPath = path_1.default.join(outDir, filepath + '.json');
|
|
124
|
+
console.log(`Serializing ArkIR for '${filepath}' to '${outPath}'...`);
|
|
125
|
+
printer.dumpToJson(f, outPath);
|
|
126
|
+
}
|
|
127
|
+
if (verbose)
|
|
128
|
+
console.log("All done!");
|
|
129
|
+
}
|
|
130
|
+
exports.program = new commander_1.Command()
|
|
131
|
+
.name('serializeArkIR')
|
|
132
|
+
.description('Serialize ArkIR for TypeScript files or projects to JSON')
|
|
133
|
+
.argument('<input>', 'Input file or directory')
|
|
134
|
+
.argument('<output>', 'Output file or directory')
|
|
135
|
+
.option('-m, --multi', 'Flag to indicate the input is a directory', false)
|
|
136
|
+
.option('-p, --project', 'Flag to indicate the input is a project directory', false)
|
|
137
|
+
.option('-v, --verbose', 'Verbose output', false)
|
|
138
|
+
.action((input, output, options) => {
|
|
139
|
+
// Check for invalid combinations of flags
|
|
140
|
+
if (options.multi && options.project) {
|
|
141
|
+
console.error(`ERROR: You cannot provide both the '-m' and '-p' flags.`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
// Ensure the input path exists
|
|
145
|
+
if (!fs_1.default.existsSync(input)) {
|
|
146
|
+
console.error(`ERROR: The input path '${input}' does not exist.`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
// Handle the case where the input is a directory
|
|
150
|
+
if (fs_1.default.statSync(input).isDirectory() && !(options.multi || options.project)) {
|
|
151
|
+
console.error(`ERROR: If the input is a directory, you must provide the '-p' or '-m' flag.`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
if (options.project) {
|
|
155
|
+
serializeTsProject(input, output, options.verbose);
|
|
156
|
+
}
|
|
157
|
+
else if (options.multi) {
|
|
158
|
+
serializeMultipleTsFiles(input, output, options.verbose);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
serializeTsFile(input, output, options.verbose);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
if (require.main === module) {
|
|
165
|
+
exports.program.parse(process.argv);
|
|
166
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Decorator } from '../../core/base/Decorator';
|
|
2
|
+
import { Printer } from '../Printer';
|
|
3
|
+
import { ArkFile } from '../../core/model/ArkFile';
|
|
4
|
+
import { ArkMethod } from '../../core/model/ArkMethod';
|
|
5
|
+
import { ClassSignature, MethodSignature } from '../../core/model/ArkSignature';
|
|
6
|
+
import { ArkClass } from '../../core/model/ArkClass';
|
|
7
|
+
import { ArkCodeBuffer } from '../ArkStream';
|
|
8
|
+
import { Local } from '../../core/base/Local';
|
|
9
|
+
import { TransformerContext } from './SourceTransformer';
|
|
10
|
+
import { ArkNamespace } from '../../core/model/ArkNamespace';
|
|
11
|
+
export interface Dump {
|
|
12
|
+
getLine(): number;
|
|
13
|
+
dump(): string;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class SourceBase extends Printer implements Dump, TransformerContext {
|
|
16
|
+
protected arkFile: ArkFile;
|
|
17
|
+
protected inBuilder: boolean;
|
|
18
|
+
constructor(arkFile: ArkFile, indent?: string);
|
|
19
|
+
getDeclaringArkNamespace(): ArkNamespace | undefined;
|
|
20
|
+
getArkFile(): ArkFile;
|
|
21
|
+
getMethod(signature: MethodSignature): ArkMethod | null;
|
|
22
|
+
getClass(signature: ClassSignature): ArkClass | null;
|
|
23
|
+
getPrinter(): ArkCodeBuffer;
|
|
24
|
+
transTemp2Code(temp: Local): string;
|
|
25
|
+
isInBuilderMethod(): boolean;
|
|
26
|
+
abstract getLine(): number;
|
|
27
|
+
protected printDecorator(modifiers: Set<string | Decorator>): void;
|
|
28
|
+
protected modifiersToString(modifiers: Set<string | Decorator>): string;
|
|
29
|
+
protected resolveKeywordType(keywordStr: string): string;
|
|
30
|
+
protected resolveMethodName(name: string): string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=SourceBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceBase.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceBase.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,IAAI;IACjB,OAAO,IAAI,MAAM,CAAC;IAClB,IAAI,IAAI,MAAM,CAAC;CAClB;AAED,8BAAsB,UAClB,SAAQ,OACR,YAAW,IAAI,EAAE,kBAAkB;IAEnC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,SAAS,EAAE,OAAO,CAAS;gBAElB,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW;IAKjD,wBAAwB,IAAI,YAAY,GAAG,SAAS;IAIpD,UAAU,IAAI,OAAO;IAIrB,SAAS,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI;IAIvD,QAAQ,CAAC,SAAS,EAAE,cAAc,GAAG,QAAQ,GAAG,IAAI;IAIpD,UAAU,IAAI,aAAa;IAI3B,cAAc,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM;IAInC,iBAAiB,IAAI,OAAO;aAInB,OAAO,IAAI,MAAM;IAEjC,SAAS,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI;IAQlE,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM;IAWvE,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAmBxD,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAYpD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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.SourceBase = void 0;
|
|
18
|
+
const Decorator_1 = require("../../core/base/Decorator");
|
|
19
|
+
const Printer_1 = require("../Printer");
|
|
20
|
+
class SourceBase extends Printer_1.Printer {
|
|
21
|
+
constructor(arkFile, indent = '') {
|
|
22
|
+
super(indent);
|
|
23
|
+
this.inBuilder = false;
|
|
24
|
+
this.arkFile = arkFile;
|
|
25
|
+
}
|
|
26
|
+
getDeclaringArkNamespace() {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
getArkFile() {
|
|
30
|
+
return this.arkFile;
|
|
31
|
+
}
|
|
32
|
+
getMethod(signature) {
|
|
33
|
+
return this.getArkFile().getScene().getMethod(signature);
|
|
34
|
+
}
|
|
35
|
+
getClass(signature) {
|
|
36
|
+
return this.getArkFile().getScene().getClass(signature);
|
|
37
|
+
}
|
|
38
|
+
getPrinter() {
|
|
39
|
+
return this.printer;
|
|
40
|
+
}
|
|
41
|
+
transTemp2Code(temp) {
|
|
42
|
+
return temp.getName();
|
|
43
|
+
}
|
|
44
|
+
isInBuilderMethod() {
|
|
45
|
+
return this.inBuilder;
|
|
46
|
+
}
|
|
47
|
+
printDecorator(modifiers) {
|
|
48
|
+
modifiers.forEach((value) => {
|
|
49
|
+
if (value instanceof Decorator_1.Decorator) {
|
|
50
|
+
this.printer.writeIndent().writeLine(`@${value.getContent()}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
modifiersToString(modifiers) {
|
|
55
|
+
let modifiersStr = [];
|
|
56
|
+
modifiers.forEach((value) => {
|
|
57
|
+
if (!(value instanceof Decorator_1.Decorator)) {
|
|
58
|
+
modifiersStr.push(this.resolveKeywordType(value));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return modifiersStr.join(' ');
|
|
62
|
+
}
|
|
63
|
+
resolveKeywordType(keywordStr) {
|
|
64
|
+
// 'NumberKeyword | NullKeyword |
|
|
65
|
+
let types = [];
|
|
66
|
+
for (let keyword of keywordStr.split('|')) {
|
|
67
|
+
keyword = keyword.trim();
|
|
68
|
+
if (keyword.length == 0) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (keyword.endsWith('Keyword')) {
|
|
72
|
+
keyword = keyword
|
|
73
|
+
.substring(0, keyword.length - 'Keyword'.length)
|
|
74
|
+
.toLowerCase();
|
|
75
|
+
}
|
|
76
|
+
types.push(keyword);
|
|
77
|
+
}
|
|
78
|
+
return types.join(' | ');
|
|
79
|
+
}
|
|
80
|
+
resolveMethodName(name) {
|
|
81
|
+
if (name === '_Constructor') {
|
|
82
|
+
return 'constructor';
|
|
83
|
+
}
|
|
84
|
+
if (name.startsWith('Get-')) {
|
|
85
|
+
return name.replace('Get-', 'get ');
|
|
86
|
+
}
|
|
87
|
+
if (name.startsWith('Set-')) {
|
|
88
|
+
return name.replace('Set-', 'set ');
|
|
89
|
+
}
|
|
90
|
+
return name;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.SourceBase = SourceBase;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Local } from '../../core/base/Local';
|
|
2
|
+
import { Stmt } from '../../core/base/Stmt';
|
|
3
|
+
import { ArkMethod } from '../../core/model/ArkMethod';
|
|
4
|
+
import { ArkCodeBuffer } from '../ArkStream';
|
|
5
|
+
import { SourceStmt, StmtPrinterContext } from './SourceStmt';
|
|
6
|
+
import { ArkClass } from '../../core/model/ArkClass';
|
|
7
|
+
import { ArkFile } from '../../core/model/ArkFile';
|
|
8
|
+
import { ClassSignature, MethodSignature } from '../../core/model/ArkSignature';
|
|
9
|
+
import { ArkNamespace } from '../../core/model/ArkNamespace';
|
|
10
|
+
export declare class SourceBody implements StmtPrinterContext {
|
|
11
|
+
protected printer: ArkCodeBuffer;
|
|
12
|
+
private arkBody;
|
|
13
|
+
private stmts;
|
|
14
|
+
private method;
|
|
15
|
+
private cfgUtils;
|
|
16
|
+
private tempCodeMap;
|
|
17
|
+
private tempVisitor;
|
|
18
|
+
private skipStmts;
|
|
19
|
+
private stmtReader;
|
|
20
|
+
private definedLocals;
|
|
21
|
+
private inBuilder;
|
|
22
|
+
private lastStmt;
|
|
23
|
+
constructor(indent: string, method: ArkMethod, inBuilder: boolean);
|
|
24
|
+
setSkipStmt(stmt: Stmt): void;
|
|
25
|
+
isInBuilderMethod(): boolean;
|
|
26
|
+
isInDefaultMethod(): boolean;
|
|
27
|
+
getArkFile(): ArkFile;
|
|
28
|
+
getDeclaringArkNamespace(): ArkNamespace | undefined;
|
|
29
|
+
getMethod(signature: MethodSignature): ArkMethod | null;
|
|
30
|
+
getClass(signature: ClassSignature): ArkClass | null;
|
|
31
|
+
getLocals(): Map<string, Local>;
|
|
32
|
+
defineLocal(local: Local): void;
|
|
33
|
+
isLocalDefined(local: Local): boolean;
|
|
34
|
+
getStmtReader(): StmtReader;
|
|
35
|
+
setTempCode(temp: string, code: string): void;
|
|
36
|
+
transTemp2Code(temp: Local): string;
|
|
37
|
+
getTempCodeMap(): Map<string, string>;
|
|
38
|
+
hasTempVisit(temp: string): boolean;
|
|
39
|
+
setTempVisit(temp: string): void;
|
|
40
|
+
getPrinter(): ArkCodeBuffer;
|
|
41
|
+
dump(): string;
|
|
42
|
+
private buildSourceStmt;
|
|
43
|
+
private buildTypeAliasStmt;
|
|
44
|
+
private buildBasicBlock;
|
|
45
|
+
private printStmts;
|
|
46
|
+
getStmts(): SourceStmt[];
|
|
47
|
+
pushStmt(stmt: SourceStmt): void;
|
|
48
|
+
private getLastLine;
|
|
49
|
+
private sortStmt;
|
|
50
|
+
}
|
|
51
|
+
export declare class StmtReader {
|
|
52
|
+
private stmts;
|
|
53
|
+
private pos;
|
|
54
|
+
constructor(stmts: Stmt[]);
|
|
55
|
+
first(): Stmt;
|
|
56
|
+
hasNext(): boolean;
|
|
57
|
+
next(): Stmt;
|
|
58
|
+
rollback(): void;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=SourceBody.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceBody.d.ts","sourceRoot":"","sources":["../../../src/save/source/SourceBody.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAyD,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EASH,UAAU,EAIV,kBAAkB,EACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAI7D,qBAAa,UAAW,YAAW,kBAAkB;IACjD,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC;IACjC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,QAAQ,CAAO;gBAEJ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO;IAcxE,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI7B,iBAAiB,IAAI,OAAO;IAG5B,iBAAiB,IAAI,OAAO;IAGrB,UAAU,IAAI,OAAO;IAIrB,wBAAwB,IAAI,YAAY,GAAG,SAAS;IAIpD,SAAS,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI;IAQvD,QAAQ,CAAC,SAAS,EAAE,cAAc,GAAG,QAAQ,GAAG,IAAI;IAIpD,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;IAI/B,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI/B,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAIrC,aAAa,IAAI,UAAU;IAI3B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7C,cAAc,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM;IASnC,cAAc,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIrC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIhC,UAAU,IAAI,aAAa;IAI3B,IAAI,IAAI,MAAM;IAKrB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,UAAU;IASX,QAAQ,IAAI,UAAU,EAAE;IAQxB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IASvC,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,QAAQ;CAqCnB;AAED,qBAAa,UAAU;IACnB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,GAAG,CAAS;gBAER,KAAK,EAAE,IAAI,EAAE;IAKzB,KAAK,IAAI,IAAI;IAIb,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,IAAI;IAUZ,QAAQ,IAAI,IAAI;CAOnB"}
|