arkanalyzer 1.0.20 → 1.0.21
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/lib/Config.d.ts +70 -70
- package/lib/Config.js +198 -198
- package/lib/Scene.d.ts +316 -316
- package/lib/Scene.js +1316 -1316
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -28
- package/lib/callgraph/algorithm/AbstractAnalysis.js +144 -144
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +10 -10
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +69 -69
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +15 -15
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +146 -146
- package/lib/callgraph/common/Statistics.d.ts +57 -57
- package/lib/callgraph/common/Statistics.js +228 -228
- package/lib/callgraph/model/CallGraph.d.ts +96 -96
- package/lib/callgraph/model/CallGraph.js +354 -354
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +15 -15
- package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -106
- package/lib/callgraph/pointerAnalysis/Context.d.ts +37 -37
- package/lib/callgraph/pointerAnalysis/Context.js +155 -155
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +22 -22
- package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -104
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +5 -5
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +46 -46
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +261 -261
- package/lib/callgraph/pointerAnalysis/Pag.js +930 -930
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +157 -157
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +1399 -1399
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +72 -72
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +573 -573
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +15 -15
- package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +81 -81
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +80 -80
- package/lib/callgraph/pointerAnalysis/PtsDS.js +308 -308
- package/lib/core/base/Constant.d.ts +48 -48
- package/lib/core/base/Constant.js +103 -103
- package/lib/core/base/Decorator.d.ts +15 -15
- package/lib/core/base/Decorator.js +46 -46
- package/lib/core/base/DefUseChain.d.ts +8 -8
- package/lib/core/base/DefUseChain.js +25 -25
- package/lib/core/base/Expr.d.ts +340 -340
- package/lib/core/base/Expr.js +917 -917
- package/lib/core/base/Local.d.ts +104 -104
- package/lib/core/base/Local.js +176 -176
- package/lib/core/base/Position.d.ts +30 -30
- package/lib/core/base/Position.js +147 -147
- package/lib/core/base/Ref.d.ts +173 -173
- package/lib/core/base/Ref.js +374 -374
- package/lib/core/base/Stmt.d.ts +237 -237
- package/lib/core/base/Stmt.js +525 -525
- package/lib/core/base/Trap.d.ts +8 -8
- package/lib/core/base/Trap.js +30 -30
- package/lib/core/base/Type.d.ts +308 -308
- package/lib/core/base/Type.js +639 -639
- package/lib/core/base/TypeExpr.d.ts +71 -71
- package/lib/core/base/TypeExpr.js +155 -155
- package/lib/core/base/Value.d.ts +32 -32
- package/lib/core/base/Value.js +16 -16
- package/lib/core/common/ArkError.d.ts +14 -14
- package/lib/core/common/ArkError.js +28 -28
- package/lib/core/common/ArkIRTransformer.d.ts +67 -67
- package/lib/core/common/ArkIRTransformer.js +690 -690
- package/lib/core/common/ArkValueTransformer.d.ts +89 -89
- package/lib/core/common/ArkValueTransformer.js +1478 -1478
- package/lib/core/common/Builtin.d.ts +36 -36
- package/lib/core/common/Builtin.js +81 -81
- package/lib/core/common/Const.d.ts +21 -21
- package/lib/core/common/Const.js +43 -43
- package/lib/core/common/DummyMainCreater.d.ts +46 -46
- package/lib/core/common/DummyMainCreater.js +319 -319
- package/lib/core/common/EtsConst.d.ts +73 -73
- package/lib/core/common/EtsConst.js +1021 -1021
- package/lib/core/common/ExprUseReplacer.d.ts +21 -21
- package/lib/core/common/ExprUseReplacer.js +124 -124
- package/lib/core/common/IRInference.d.ts +36 -36
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +651 -648
- package/lib/core/common/IRUtils.d.ts +18 -18
- package/lib/core/common/IRUtils.js +141 -141
- package/lib/core/common/ModelUtils.d.ts +70 -70
- package/lib/core/common/ModelUtils.js +712 -712
- package/lib/core/common/RefUseReplacer.d.ts +13 -13
- package/lib/core/common/RefUseReplacer.js +52 -52
- package/lib/core/common/SdkUtils.d.ts +8 -8
- package/lib/core/common/SdkUtils.js +105 -105
- package/lib/core/common/StmtDefReplacer.d.ts +12 -12
- package/lib/core/common/StmtDefReplacer.js +41 -41
- package/lib/core/common/StmtUseReplacer.d.ts +16 -16
- package/lib/core/common/StmtUseReplacer.js +108 -108
- package/lib/core/common/TSConst.d.ts +18 -18
- package/lib/core/common/TSConst.js +36 -36
- package/lib/core/common/TypeInference.d.ts +102 -102
- package/lib/core/common/TypeInference.js +748 -748
- package/lib/core/common/ValueUtil.d.ts +12 -12
- package/lib/core/common/ValueUtil.js +54 -54
- package/lib/core/common/VisibleValue.d.ts +36 -36
- package/lib/core/common/VisibleValue.js +212 -212
- package/lib/core/dataflow/DataflowProblem.d.ts +20 -20
- package/lib/core/dataflow/DataflowProblem.js +20 -20
- package/lib/core/dataflow/DataflowResult.d.ts +7 -7
- package/lib/core/dataflow/DataflowResult.js +26 -26
- package/lib/core/dataflow/DataflowSolver.d.ts +43 -43
- package/lib/core/dataflow/DataflowSolver.js +307 -307
- package/lib/core/dataflow/Edge.d.ts +11 -11
- package/lib/core/dataflow/Edge.js +31 -31
- package/lib/core/dataflow/Fact.d.ts +6 -6
- package/lib/core/dataflow/Fact.js +24 -24
- package/lib/core/dataflow/GenericDataFlow.d.ts +142 -142
- package/lib/core/dataflow/GenericDataFlow.js +109 -109
- package/lib/core/dataflow/ReachingDef.d.ts +62 -62
- package/lib/core/dataflow/ReachingDef.js +168 -168
- package/lib/core/dataflow/UndefinedVariable.d.ts +45 -45
- package/lib/core/dataflow/UndefinedVariable.js +288 -288
- package/lib/core/dataflow/Util.d.ts +9 -9
- package/lib/core/dataflow/Util.js +64 -64
- package/lib/core/graph/BaseExplicitGraph.d.ts +58 -58
- package/lib/core/graph/BaseExplicitGraph.js +157 -157
- package/lib/core/graph/BaseImplicitGraph.d.ts +77 -77
- package/lib/core/graph/BaseImplicitGraph.js +78 -78
- package/lib/core/graph/BasicBlock.d.ts +104 -104
- package/lib/core/graph/BasicBlock.js +280 -280
- package/lib/core/graph/Cfg.d.ts +59 -59
- package/lib/core/graph/Cfg.js +282 -282
- package/lib/core/graph/DependsGraph.d.ts +35 -35
- package/lib/core/graph/DependsGraph.js +87 -87
- package/lib/core/graph/DominanceFinder.d.ts +15 -15
- package/lib/core/graph/DominanceFinder.js +121 -121
- package/lib/core/graph/DominanceTree.d.ts +12 -12
- package/lib/core/graph/DominanceTree.js +70 -70
- package/lib/core/graph/GraphTraits.d.ts +7 -7
- package/lib/core/graph/GraphTraits.js +16 -16
- package/lib/core/graph/Scc.d.ts +61 -61
- package/lib/core/graph/Scc.js +222 -222
- package/lib/core/graph/ViewTree.d.ts +114 -114
- package/lib/core/graph/ViewTree.js +16 -16
- package/lib/core/graph/builder/CfgBuilder.d.ts +176 -176
- package/lib/core/graph/builder/CfgBuilder.js +1139 -1139
- package/lib/core/graph/builder/ConditionBuilder.d.ts +15 -15
- package/lib/core/graph/builder/ConditionBuilder.js +252 -252
- package/lib/core/graph/builder/LoopBuilder.d.ts +20 -20
- package/lib/core/graph/builder/LoopBuilder.js +251 -251
- package/lib/core/graph/builder/SwitchBuilder.d.ts +11 -11
- package/lib/core/graph/builder/SwitchBuilder.js +152 -152
- package/lib/core/graph/builder/TrapBuilder.d.ts +16 -16
- package/lib/core/graph/builder/TrapBuilder.js +272 -272
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts +203 -203
- package/lib/core/graph/builder/ViewTreeBuilder.js +1055 -1055
- package/lib/core/model/ArkBaseModel.d.ts +59 -59
- package/lib/core/model/ArkBaseModel.js +274 -274
- package/lib/core/model/ArkBody.d.ts +24 -24
- package/lib/core/model/ArkBody.js +65 -65
- package/lib/core/model/ArkClass.d.ts +206 -206
- package/lib/core/model/ArkClass.js +439 -439
- package/lib/core/model/ArkExport.d.ts +72 -72
- package/lib/core/model/ArkExport.js +147 -147
- package/lib/core/model/ArkField.d.ts +62 -62
- package/lib/core/model/ArkField.js +113 -113
- package/lib/core/model/ArkFile.d.ts +131 -131
- package/lib/core/model/ArkFile.js +267 -267
- package/lib/core/model/ArkImport.d.ts +44 -44
- package/lib/core/model/ArkImport.js +108 -108
- package/lib/core/model/ArkMetadata.d.ts +31 -31
- package/lib/core/model/ArkMetadata.js +55 -55
- package/lib/core/model/ArkMethod.d.ts +261 -261
- package/lib/core/model/ArkMethod.js +592 -592
- package/lib/core/model/ArkNamespace.d.ts +66 -66
- package/lib/core/model/ArkNamespace.js +209 -209
- package/lib/core/model/ArkSignature.d.ts +162 -162
- package/lib/core/model/ArkSignature.js +379 -379
- package/lib/core/model/builder/ArkClassBuilder.d.ts +12 -12
- package/lib/core/model/builder/ArkClassBuilder.js +454 -454
- package/lib/core/model/builder/ArkExportBuilder.d.ts +24 -24
- package/lib/core/model/builder/ArkExportBuilder.js +210 -210
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkFieldBuilder.js +193 -193
- package/lib/core/model/builder/ArkFileBuilder.d.ts +9 -9
- package/lib/core/model/builder/ArkFileBuilder.js +165 -165
- package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -4
- package/lib/core/model/builder/ArkImportBuilder.js +128 -128
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +63 -63
- package/lib/core/model/builder/ArkMethodBuilder.js +486 -486
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -5
- package/lib/core/model/builder/ArkNamespaceBuilder.js +205 -205
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +8 -8
- package/lib/core/model/builder/ArkSignatureBuilder.js +40 -40
- package/lib/core/model/builder/BodyBuilder.d.ts +55 -30
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +542 -371
- package/lib/core/model/builder/builderUtils.d.ts +18 -18
- package/lib/core/model/builder/builderUtils.js +558 -558
- package/lib/index.d.ts +82 -80
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +201 -196
- package/lib/save/ArkStream.d.ts +23 -23
- package/lib/save/ArkStream.js +83 -83
- package/lib/save/DotPrinter.d.ts +43 -43
- package/lib/save/DotPrinter.js +170 -170
- package/lib/save/GraphPrinter.d.ts +16 -16
- package/lib/save/GraphPrinter.js +134 -134
- package/lib/save/JsonPrinter.d.ts +30 -30
- package/lib/save/JsonPrinter.js +580 -580
- package/lib/save/Printer.d.ts +12 -12
- package/lib/save/Printer.js +27 -27
- package/lib/save/PrinterBuilder.d.ts +53 -53
- package/lib/save/PrinterBuilder.js +145 -145
- package/lib/save/ViewTreePrinter.d.ts +14 -14
- package/lib/save/ViewTreePrinter.js +123 -123
- package/lib/save/arkir/ArkIRClassPrinter.d.ts +13 -13
- package/lib/save/arkir/ArkIRClassPrinter.js +92 -92
- package/lib/save/arkir/ArkIRFieldPrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRFieldPrinter.js +64 -64
- package/lib/save/arkir/ArkIRFilePrinter.d.ts +12 -12
- package/lib/save/arkir/ArkIRFilePrinter.js +54 -54
- package/lib/save/arkir/ArkIRMethodPrinter.d.ts +16 -16
- package/lib/save/arkir/ArkIRMethodPrinter.js +159 -159
- package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +11 -11
- package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -66
- package/lib/save/base/BasePrinter.d.ts +23 -23
- package/lib/save/base/BasePrinter.js +70 -70
- package/lib/save/base/ExportPrinter.d.ts +8 -8
- package/lib/save/base/ExportPrinter.js +67 -67
- package/lib/save/base/ImportPrinter.d.ts +9 -9
- package/lib/save/base/ImportPrinter.js +92 -92
- package/lib/save/base/PrinterUtils.d.ts +24 -24
- package/lib/save/base/PrinterUtils.js +208 -208
- package/lib/save/serializeArkIR.d.ts +8 -8
- package/lib/save/serializeArkIR.js +294 -294
- package/lib/save/source/SourceBase.d.ts +22 -22
- package/lib/save/source/SourceBase.js +64 -64
- package/lib/save/source/SourceBody.d.ts +58 -58
- package/lib/save/source/SourceBody.js +296 -296
- package/lib/save/source/SourceClass.d.ts +25 -25
- package/lib/save/source/SourceClass.js +187 -187
- package/lib/save/source/SourceField.d.ts +13 -13
- package/lib/save/source/SourceField.js +73 -73
- package/lib/save/source/SourceFilePrinter.d.ts +12 -12
- package/lib/save/source/SourceFilePrinter.js +69 -69
- package/lib/save/source/SourceMethod.d.ts +22 -22
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +196 -193
- package/lib/save/source/SourceNamespace.d.ts +11 -11
- package/lib/save/source/SourceNamespace.js +83 -83
- package/lib/save/source/SourceStmt.d.ts +178 -178
- package/lib/save/source/SourceStmt.js +838 -838
- package/lib/save/source/SourceTransformer.d.ts +46 -46
- package/lib/save/source/SourceTransformer.js +446 -446
- package/lib/transformer/FunctionTransformer.d.ts +2 -2
- package/lib/transformer/FunctionTransformer.js +17 -17
- package/lib/transformer/SceneTransformer.d.ts +2 -2
- package/lib/transformer/SceneTransformer.js +17 -17
- package/lib/transformer/StaticSingleAssignmentFormer.d.ts +12 -12
- package/lib/transformer/StaticSingleAssignmentFormer.js +259 -259
- package/lib/transformer/Transformer.d.ts +6 -6
- package/lib/transformer/Transformer.js +22 -22
- package/lib/utils/AstTreeUtils.d.ts +4 -4
- package/lib/utils/AstTreeUtils.js +26 -26
- package/lib/utils/CfgStructualAnalysis.d.ts +110 -110
- package/lib/utils/CfgStructualAnalysis.js +1277 -1277
- package/lib/utils/FileUtils.d.ts +18 -18
- package/lib/utils/FileUtils.js +135 -135
- package/lib/utils/SparseBitVector.d.ts +100 -100
- package/lib/utils/SparseBitVector.js +445 -445
- package/lib/utils/callGraphUtils.d.ts +30 -30
- package/lib/utils/callGraphUtils.js +205 -205
- package/lib/utils/crypto_utils.d.ts +5 -5
- package/lib/utils/crypto_utils.js +57 -57
- package/lib/utils/entryMethodUtils.d.ts +13 -13
- package/lib/utils/entryMethodUtils.js +110 -110
- package/lib/utils/getAllFiles.d.ts +9 -9
- package/lib/utils/getAllFiles.js +90 -90
- package/lib/utils/json5parser.d.ts +6 -6
- package/lib/utils/json5parser.js +146 -146
- package/lib/utils/logger.d.ts +18 -18
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +97 -90
- package/lib/utils/pathTransfer.d.ts +1 -1
- package/lib/utils/pathTransfer.js +25 -25
- package/node_modules/json5/lib/cli.js +0 -0
- package/node_modules/ohos-typescript/bin/tsc +0 -0
- package/node_modules/ohos-typescript/bin/tsserver +0 -0
- package/package.json +3 -3
package/lib/save/JsonPrinter.js
CHANGED
|
@@ -1,580 +1,580 @@
|
|
|
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.JsonPrinter = void 0;
|
|
21
|
-
const Printer_1 = require("./Printer");
|
|
22
|
-
const Type_1 = require("../core/base/Type");
|
|
23
|
-
const Stmt_1 = require("../core/base/Stmt");
|
|
24
|
-
const Expr_1 = require("../core/base/Expr");
|
|
25
|
-
const Constant_1 = require("../core/base/Constant");
|
|
26
|
-
const ArkSignature_1 = require("../core/model/ArkSignature");
|
|
27
|
-
const Ref_1 = require("../core/base/Ref");
|
|
28
|
-
const Local_1 = require("../core/base/Local");
|
|
29
|
-
const util_1 = __importDefault(require("util"));
|
|
30
|
-
class JsonPrinter extends Printer_1.Printer {
|
|
31
|
-
constructor(arkFile) {
|
|
32
|
-
super();
|
|
33
|
-
this.arkFile = arkFile;
|
|
34
|
-
}
|
|
35
|
-
dump() {
|
|
36
|
-
const jsonObject = this.serializeArkFile(this.arkFile);
|
|
37
|
-
return JSON.stringify(jsonObject, null, 2);
|
|
38
|
-
}
|
|
39
|
-
serializeArkFile(file) {
|
|
40
|
-
return {
|
|
41
|
-
signature: this.serializeFileSignature(file.getFileSignature()),
|
|
42
|
-
namespaces: file.getNamespaces().map((ns) => this.serializeNamespace(ns)),
|
|
43
|
-
classes: file.getClasses().map((cls) => this.serializeClass(cls)),
|
|
44
|
-
importInfos: file.getImportInfos().map((info) => this.serializeImportInfo(info)),
|
|
45
|
-
exportInfos: file.getExportInfos().map((info) => this.serializeExportInfo(info)),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
serializeNamespace(namespace) {
|
|
49
|
-
return {
|
|
50
|
-
signature: this.serializeNamespaceSignature(namespace.getSignature()),
|
|
51
|
-
classes: namespace.getClasses().map((cls) => this.serializeClass(cls)),
|
|
52
|
-
namespaces: namespace.getNamespaces().map((ns) => this.serializeNamespace(ns)),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
serializeClass(clazz) {
|
|
56
|
-
var _a;
|
|
57
|
-
return {
|
|
58
|
-
signature: this.serializeClassSignature(clazz.getSignature()),
|
|
59
|
-
modifiers: clazz.getModifiers(),
|
|
60
|
-
decorators: clazz.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
61
|
-
typeParameters: (_a = clazz.getGenericsTypes()) === null || _a === void 0 ? void 0 : _a.map((type) => this.serializeType(type)),
|
|
62
|
-
superClassName: clazz.getSuperClassName(),
|
|
63
|
-
implementedInterfaceNames: clazz.getImplementedInterfaceNames(),
|
|
64
|
-
fields: clazz.getFields().map((field) => this.serializeField(field)),
|
|
65
|
-
methods: clazz.getMethods(true).map((method) => this.serializeMethod(method)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
serializeField(field) {
|
|
69
|
-
return {
|
|
70
|
-
signature: this.serializeFieldSignature(field.getSignature()),
|
|
71
|
-
modifiers: field.getModifiers(),
|
|
72
|
-
decorators: field.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
73
|
-
questionToken: field.getQuestionToken(),
|
|
74
|
-
exclamationToken: field.getExclamationToken(),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
serializeMethod(method) {
|
|
78
|
-
var _a;
|
|
79
|
-
let body = method.getBody();
|
|
80
|
-
return {
|
|
81
|
-
signature: this.serializeMethodSignature(method.getSignature()),
|
|
82
|
-
modifiers: method.getModifiers(),
|
|
83
|
-
decorators: method.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
84
|
-
typeParameters: (_a = method.getGenericTypes()) === null || _a === void 0 ? void 0 : _a.map(type => this.serializeType(type)),
|
|
85
|
-
body: body && this.serializeMethodBody(body),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
serializeMethodBody(body) {
|
|
89
|
-
return {
|
|
90
|
-
locals: Array.from(body.getLocals().values()).map((local) => this.serializeLocal(local)),
|
|
91
|
-
cfg: this.serializeCfg(body.getCfg()),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
serializeMethodParameter(parameter) {
|
|
95
|
-
return {
|
|
96
|
-
name: parameter.getName(),
|
|
97
|
-
type: this.serializeType(parameter.getType()),
|
|
98
|
-
isOptional: parameter.isOptional(),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
serializeImportInfo(importInfo) {
|
|
102
|
-
return {
|
|
103
|
-
importClauseName: importInfo.getImportClauseName(),
|
|
104
|
-
importType: importInfo.getImportType(),
|
|
105
|
-
importFrom: importInfo.getFrom(),
|
|
106
|
-
nameBeforeAs: importInfo.getNameBeforeAs(),
|
|
107
|
-
modifiers: importInfo.getModifiers(),
|
|
108
|
-
originTsPosition: this.serializeLineColPosition(importInfo.getOriginTsPosition()),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
serializeExportInfo(exportInfo) {
|
|
112
|
-
return {
|
|
113
|
-
exportClauseName: exportInfo.getExportClauseName(),
|
|
114
|
-
exportClauseType: exportInfo.getExportClauseType(),
|
|
115
|
-
exportFrom: exportInfo.getFrom(),
|
|
116
|
-
nameBeforeAs: exportInfo.getNameBeforeAs(),
|
|
117
|
-
isDefault: exportInfo.isDefault(),
|
|
118
|
-
modifiers: exportInfo.getModifiers(),
|
|
119
|
-
originTsPosition: this.serializeLineColPosition(exportInfo.getOriginTsPosition()),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
serializeDecorator(decorator) {
|
|
123
|
-
return {
|
|
124
|
-
kind: decorator.getKind(),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
serializeLineColPosition(position) {
|
|
128
|
-
return {
|
|
129
|
-
line: position.getLineNo(),
|
|
130
|
-
col: position.getColNo(),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
serializeType(type) {
|
|
134
|
-
var _a, _b;
|
|
135
|
-
if (type === undefined) {
|
|
136
|
-
throw new Error('Type is undefined');
|
|
137
|
-
}
|
|
138
|
-
if (type instanceof Type_1.AnyType) {
|
|
139
|
-
return {
|
|
140
|
-
_: 'AnyType',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
else if (type instanceof Type_1.UnknownType) {
|
|
144
|
-
return {
|
|
145
|
-
_: 'UnknownType',
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
else if (type instanceof Type_1.VoidType) {
|
|
149
|
-
return {
|
|
150
|
-
_: 'VoidType',
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
else if (type instanceof Type_1.NeverType) {
|
|
154
|
-
return {
|
|
155
|
-
_: 'NeverType',
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
else if (type instanceof Type_1.UnionType) {
|
|
159
|
-
return {
|
|
160
|
-
_: 'UnionType',
|
|
161
|
-
types: type.getTypes().map((type) => this.serializeType(type)),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
else if (type instanceof Type_1.TupleType) {
|
|
165
|
-
return {
|
|
166
|
-
_: 'TupleType',
|
|
167
|
-
types: type.getTypes().map((type) => this.serializeType(type)),
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
else if (type instanceof Type_1.BooleanType) {
|
|
171
|
-
return {
|
|
172
|
-
_: 'BooleanType',
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
else if (type instanceof Type_1.NumberType) {
|
|
176
|
-
return {
|
|
177
|
-
_: 'NumberType',
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
else if (type instanceof Type_1.StringType) {
|
|
181
|
-
return {
|
|
182
|
-
_: 'StringType',
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
else if (type instanceof Type_1.NullType) {
|
|
186
|
-
return {
|
|
187
|
-
_: 'NullType',
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
else if (type instanceof Type_1.UndefinedType) {
|
|
191
|
-
return {
|
|
192
|
-
_: 'UndefinedType',
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
else if (type instanceof Type_1.LiteralType) {
|
|
196
|
-
return {
|
|
197
|
-
_: 'LiteralType',
|
|
198
|
-
literal: type.getLiteralName(),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
else if (type instanceof Type_1.PrimitiveType) {
|
|
202
|
-
throw new Error('Unhandled PrimitiveType: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
203
|
-
}
|
|
204
|
-
else if (type instanceof Type_1.ClassType) {
|
|
205
|
-
return {
|
|
206
|
-
_: 'ClassType',
|
|
207
|
-
signature: this.serializeClassSignature(type.getClassSignature()),
|
|
208
|
-
typeParameters: (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.map((type) => this.serializeType(type)),
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
else if (type instanceof Type_1.FunctionType) {
|
|
212
|
-
return {
|
|
213
|
-
_: 'FunctionType',
|
|
214
|
-
signature: this.serializeMethodSignature(type.getMethodSignature()),
|
|
215
|
-
typeParameters: (_b = type.getRealGenericTypes()) === null || _b === void 0 ? void 0 : _b.map((type) => this.serializeType(type)),
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
else if (type instanceof Type_1.ArrayType) {
|
|
219
|
-
return {
|
|
220
|
-
_: 'ArrayType',
|
|
221
|
-
elementType: this.serializeType(type.getBaseType()),
|
|
222
|
-
dimensions: type.getDimension(),
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else if (type instanceof Type_1.UnclearReferenceType) {
|
|
226
|
-
return {
|
|
227
|
-
_: 'UnclearReferenceType',
|
|
228
|
-
name: type.getName(),
|
|
229
|
-
typeParameters: type.getGenericTypes().map((type) => this.serializeType(type)),
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
else if (type instanceof Type_1.GenericType) {
|
|
233
|
-
let defaultType = type.getDefaultType();
|
|
234
|
-
let constraint = type.getConstraint();
|
|
235
|
-
return {
|
|
236
|
-
_: 'GenericType',
|
|
237
|
-
name: type.getName(),
|
|
238
|
-
defaultType: defaultType && this.serializeType(defaultType),
|
|
239
|
-
constraint: constraint && this.serializeType(constraint),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
else if (type instanceof Type_1.AliasType) {
|
|
243
|
-
return {
|
|
244
|
-
_: 'AliasType',
|
|
245
|
-
name: type.getName(),
|
|
246
|
-
originalType: this.serializeType(type.getOriginalType()),
|
|
247
|
-
signature: this.serializeAliasTypeSignature(type.getSignature()),
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
else if (type instanceof Type_1.AnnotationNamespaceType) {
|
|
251
|
-
return {
|
|
252
|
-
_: 'AnnotationNamespaceType',
|
|
253
|
-
originType: type.getOriginType(),
|
|
254
|
-
namespaceSignature: this.serializeNamespaceSignature(type.getNamespaceSignature()),
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
else if (type instanceof Type_1.AnnotationTypeQueryType) {
|
|
258
|
-
return {
|
|
259
|
-
_: 'AnnotationTypeQueryType',
|
|
260
|
-
originType: type.getOriginType(),
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
else if (type instanceof Type_1.AnnotationType) {
|
|
264
|
-
throw new Error('Unhandled AnnotationType: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
throw new Error('Unhandled Type: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
serializeFileSignature(file) {
|
|
271
|
-
return {
|
|
272
|
-
projectName: file.getProjectName(),
|
|
273
|
-
fileName: file.getFileName(),
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
serializeNamespaceSignature(namespace) {
|
|
277
|
-
let dns = namespace.getDeclaringNamespaceSignature();
|
|
278
|
-
return {
|
|
279
|
-
name: namespace.getNamespaceName(),
|
|
280
|
-
declaringFile: this.serializeFileSignature(namespace.getDeclaringFileSignature()),
|
|
281
|
-
declaringNamespace: dns && this.serializeNamespaceSignature(dns),
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
serializeClassSignature(clazz) {
|
|
285
|
-
let dns = clazz.getDeclaringNamespaceSignature();
|
|
286
|
-
return {
|
|
287
|
-
name: clazz.getClassName(),
|
|
288
|
-
declaringFile: this.serializeFileSignature(clazz.getDeclaringFileSignature()),
|
|
289
|
-
declaringNamespace: dns && this.serializeNamespaceSignature(dns),
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
serializeFieldSignature(field) {
|
|
293
|
-
let declaringSignature = field.getDeclaringSignature();
|
|
294
|
-
let declaringClass;
|
|
295
|
-
if (declaringSignature instanceof ArkSignature_1.ClassSignature) {
|
|
296
|
-
declaringClass = this.serializeClassSignature(declaringSignature);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
declaringClass = this.serializeNamespaceSignature(declaringSignature);
|
|
300
|
-
}
|
|
301
|
-
return {
|
|
302
|
-
declaringClass,
|
|
303
|
-
name: field.getFieldName(),
|
|
304
|
-
type: this.serializeType(field.getType()),
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
serializeMethodSignature(method) {
|
|
308
|
-
return {
|
|
309
|
-
declaringClass: this.serializeClassSignature(method.getDeclaringClassSignature()),
|
|
310
|
-
name: method.getMethodSubSignature().getMethodName(),
|
|
311
|
-
parameters: method
|
|
312
|
-
.getMethodSubSignature()
|
|
313
|
-
.getParameters()
|
|
314
|
-
.map((param) => this.serializeMethodParameter(param)),
|
|
315
|
-
returnType: this.serializeType(method.getType()),
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
serializeAliasTypeSignature(signature) {
|
|
319
|
-
return {
|
|
320
|
-
name: signature.getName(),
|
|
321
|
-
method: this.serializeMethodSignature(signature.getDeclaringMethodSignature()),
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
serializeCfg(cfg) {
|
|
325
|
-
const visited = new Set();
|
|
326
|
-
const stack = [];
|
|
327
|
-
const startingBlock = cfg.getStartingBlock();
|
|
328
|
-
if (startingBlock) {
|
|
329
|
-
stack.push(startingBlock);
|
|
330
|
-
}
|
|
331
|
-
let id = 0;
|
|
332
|
-
while (stack.length > 0) {
|
|
333
|
-
const block = stack.pop();
|
|
334
|
-
if (visited.has(block)) {
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
visited.add(block);
|
|
338
|
-
block.setId(id++);
|
|
339
|
-
stack.push(...block.getSuccessors());
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
blocks: Array.from(visited).map((block) => this.serializeBasicBlock(block)),
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
serializeBasicBlock(block) {
|
|
346
|
-
const successors = block.getSuccessors().map((succ) => succ.getId());
|
|
347
|
-
successors.sort((a, b) => a - b);
|
|
348
|
-
const predecessors = block.getPredecessors().map((pred) => pred.getId());
|
|
349
|
-
predecessors.sort((a, b) => a - b);
|
|
350
|
-
return {
|
|
351
|
-
id: block.getId(),
|
|
352
|
-
successors,
|
|
353
|
-
predecessors,
|
|
354
|
-
stmts: block.getStmts().map((stmt) => this.serializeStmt(stmt)),
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
serializeLocal(local) {
|
|
358
|
-
return {
|
|
359
|
-
name: local.getName(),
|
|
360
|
-
type: this.serializeType(local.getType()),
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
serializeValue(value) {
|
|
364
|
-
if (value === undefined) {
|
|
365
|
-
throw new Error('Value is undefined');
|
|
366
|
-
}
|
|
367
|
-
if (value instanceof Local_1.Local) {
|
|
368
|
-
return Object.assign({ _: 'Local' }, this.serializeLocal(value));
|
|
369
|
-
}
|
|
370
|
-
else if (value instanceof Constant_1.Constant) {
|
|
371
|
-
return {
|
|
372
|
-
_: 'Constant',
|
|
373
|
-
value: value.getValue(),
|
|
374
|
-
type: this.serializeType(value.getType()),
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
else if (value instanceof Expr_1.ArkNewExpr) {
|
|
378
|
-
return {
|
|
379
|
-
_: 'NewExpr',
|
|
380
|
-
classType: this.serializeType(value.getClassType()),
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
else if (value instanceof Expr_1.ArkNewArrayExpr) {
|
|
384
|
-
return {
|
|
385
|
-
_: 'NewArrayExpr',
|
|
386
|
-
elementType: this.serializeType(value.getBaseType()),
|
|
387
|
-
size: this.serializeValue(value.getSize()),
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
else if (value instanceof Expr_1.ArkDeleteExpr) {
|
|
391
|
-
return {
|
|
392
|
-
_: 'DeleteExpr',
|
|
393
|
-
arg: this.serializeValue(value.getField()),
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
else if (value instanceof Expr_1.ArkAwaitExpr) {
|
|
397
|
-
return {
|
|
398
|
-
_: 'AwaitExpr',
|
|
399
|
-
arg: this.serializeValue(value.getPromise()),
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
else if (value instanceof Expr_1.ArkYieldExpr) {
|
|
403
|
-
return {
|
|
404
|
-
_: 'YieldExpr',
|
|
405
|
-
arg: this.serializeValue(value.getYieldValue()),
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
else if (value instanceof Expr_1.ArkTypeOfExpr) {
|
|
409
|
-
return {
|
|
410
|
-
_: 'TypeOfExpr',
|
|
411
|
-
arg: this.serializeValue(value.getOp()),
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
else if (value instanceof Expr_1.ArkInstanceOfExpr) {
|
|
415
|
-
return {
|
|
416
|
-
_: 'InstanceOfExpr',
|
|
417
|
-
arg: this.serializeValue(value.getOp()),
|
|
418
|
-
checkType: this.serializeType(value.getCheckType()),
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
else if (value instanceof Expr_1.ArkCastExpr) {
|
|
422
|
-
return {
|
|
423
|
-
_: 'CastExpr',
|
|
424
|
-
arg: this.serializeValue(value.getOp()),
|
|
425
|
-
type: this.serializeType(value.getType()),
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
else if (value instanceof Expr_1.ArkPhiExpr) {
|
|
429
|
-
const args = value.getArgs();
|
|
430
|
-
const argToBlock = value.getArgToBlock();
|
|
431
|
-
return {
|
|
432
|
-
_: 'PhiExpr',
|
|
433
|
-
args: args.map((arg) => this.serializeValue(arg)),
|
|
434
|
-
blocks: args.map((arg) => argToBlock.get(arg).getId()),
|
|
435
|
-
type: this.serializeType(value.getType()),
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
else if (value instanceof Expr_1.ArkConditionExpr) {
|
|
439
|
-
return {
|
|
440
|
-
_: 'ConditionExpr',
|
|
441
|
-
op: value.getOperator(),
|
|
442
|
-
left: this.serializeValue(value.getOp1()),
|
|
443
|
-
right: this.serializeValue(value.getOp2()),
|
|
444
|
-
type: this.serializeType(value.getType()),
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
else if (value instanceof Expr_1.ArkNormalBinopExpr) {
|
|
448
|
-
return {
|
|
449
|
-
_: 'BinopExpr',
|
|
450
|
-
op: value.getOperator(),
|
|
451
|
-
left: this.serializeValue(value.getOp1()),
|
|
452
|
-
right: this.serializeValue(value.getOp2()),
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
else if (value instanceof Expr_1.AbstractBinopExpr) {
|
|
456
|
-
return new Error('Unhandled BinopExpr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
457
|
-
}
|
|
458
|
-
else if (value instanceof Expr_1.ArkUnopExpr) {
|
|
459
|
-
return {
|
|
460
|
-
_: 'UnopExpr',
|
|
461
|
-
op: value.getOperator(),
|
|
462
|
-
arg: this.serializeValue(value.getOp()),
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
else if (value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
466
|
-
return {
|
|
467
|
-
_: 'InstanceCallExpr',
|
|
468
|
-
instance: this.serializeValue(value.getBase()),
|
|
469
|
-
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
470
|
-
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
else if (value instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
474
|
-
return {
|
|
475
|
-
_: 'StaticCallExpr',
|
|
476
|
-
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
477
|
-
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
else if (value instanceof Expr_1.ArkPtrInvokeExpr) {
|
|
481
|
-
return {
|
|
482
|
-
_: 'PtrCallExpr',
|
|
483
|
-
ptr: this.serializeValue(value.getFuncPtrLocal()),
|
|
484
|
-
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
485
|
-
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
else if (value instanceof Expr_1.AbstractInvokeExpr) {
|
|
489
|
-
throw new Error('Unhandled CallExpr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
490
|
-
}
|
|
491
|
-
else if (value instanceof Ref_1.ArkThisRef) {
|
|
492
|
-
return {
|
|
493
|
-
_: 'ThisRef',
|
|
494
|
-
type: this.serializeType(value.getType()),
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
else if (value instanceof Ref_1.ArkParameterRef) {
|
|
498
|
-
return {
|
|
499
|
-
_: 'ParameterRef',
|
|
500
|
-
index: value.getIndex(),
|
|
501
|
-
type: this.serializeType(value.getType()),
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
else if (value instanceof Ref_1.ArkArrayRef) {
|
|
505
|
-
return {
|
|
506
|
-
_: 'ArrayRef',
|
|
507
|
-
array: this.serializeValue(value.getBase()),
|
|
508
|
-
index: this.serializeValue(value.getIndex()),
|
|
509
|
-
type: this.serializeType(value.getType()),
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
else if (value instanceof Ref_1.ArkInstanceFieldRef) {
|
|
513
|
-
return {
|
|
514
|
-
_: 'InstanceFieldRef',
|
|
515
|
-
instance: this.serializeValue(value.getBase()),
|
|
516
|
-
field: this.serializeFieldSignature(value.getFieldSignature()),
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
else if (value instanceof Ref_1.ArkStaticFieldRef) {
|
|
520
|
-
return {
|
|
521
|
-
_: 'StaticFieldRef',
|
|
522
|
-
field: this.serializeFieldSignature(value.getFieldSignature()),
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
else if (value instanceof Ref_1.AbstractFieldRef) {
|
|
526
|
-
throw new Error('Unhandled FieldRef: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
527
|
-
}
|
|
528
|
-
else if (value instanceof Ref_1.AbstractRef) {
|
|
529
|
-
throw new Error('Unhandled Ref: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
530
|
-
}
|
|
531
|
-
else if (value instanceof Expr_1.AbstractExpr) {
|
|
532
|
-
throw new Error('Unhandled Expr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
throw new Error('Unhandled Value: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
serializeStmt(stmt) {
|
|
539
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
540
|
-
return {
|
|
541
|
-
_: 'AssignStmt',
|
|
542
|
-
left: this.serializeValue(stmt.getLeftOp()),
|
|
543
|
-
right: this.serializeValue(stmt.getRightOp()),
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
547
|
-
return {
|
|
548
|
-
_: 'CallStmt',
|
|
549
|
-
expr: this.serializeValue(stmt.getInvokeExpr()),
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
else if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
553
|
-
return {
|
|
554
|
-
_: 'IfStmt',
|
|
555
|
-
condition: this.serializeValue(stmt.getConditionExpr()),
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
else if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
|
|
559
|
-
return {
|
|
560
|
-
_: 'ReturnVoidStmt',
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
else if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
564
|
-
return {
|
|
565
|
-
_: 'ReturnStmt',
|
|
566
|
-
arg: this.serializeValue(stmt.getOp()),
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
else if (stmt instanceof Stmt_1.ArkThrowStmt) {
|
|
570
|
-
return {
|
|
571
|
-
_: 'ThrowStmt',
|
|
572
|
-
arg: this.serializeValue(stmt.getOp()),
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
throw new Error('Unhandled Stmt: ' + util_1.default.inspect(stmt, { showHidden: true, depth: null }));
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
exports.JsonPrinter = JsonPrinter;
|
|
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.JsonPrinter = void 0;
|
|
21
|
+
const Printer_1 = require("./Printer");
|
|
22
|
+
const Type_1 = require("../core/base/Type");
|
|
23
|
+
const Stmt_1 = require("../core/base/Stmt");
|
|
24
|
+
const Expr_1 = require("../core/base/Expr");
|
|
25
|
+
const Constant_1 = require("../core/base/Constant");
|
|
26
|
+
const ArkSignature_1 = require("../core/model/ArkSignature");
|
|
27
|
+
const Ref_1 = require("../core/base/Ref");
|
|
28
|
+
const Local_1 = require("../core/base/Local");
|
|
29
|
+
const util_1 = __importDefault(require("util"));
|
|
30
|
+
class JsonPrinter extends Printer_1.Printer {
|
|
31
|
+
constructor(arkFile) {
|
|
32
|
+
super();
|
|
33
|
+
this.arkFile = arkFile;
|
|
34
|
+
}
|
|
35
|
+
dump() {
|
|
36
|
+
const jsonObject = this.serializeArkFile(this.arkFile);
|
|
37
|
+
return JSON.stringify(jsonObject, null, 2);
|
|
38
|
+
}
|
|
39
|
+
serializeArkFile(file) {
|
|
40
|
+
return {
|
|
41
|
+
signature: this.serializeFileSignature(file.getFileSignature()),
|
|
42
|
+
namespaces: file.getNamespaces().map((ns) => this.serializeNamespace(ns)),
|
|
43
|
+
classes: file.getClasses().map((cls) => this.serializeClass(cls)),
|
|
44
|
+
importInfos: file.getImportInfos().map((info) => this.serializeImportInfo(info)),
|
|
45
|
+
exportInfos: file.getExportInfos().map((info) => this.serializeExportInfo(info)),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
serializeNamespace(namespace) {
|
|
49
|
+
return {
|
|
50
|
+
signature: this.serializeNamespaceSignature(namespace.getSignature()),
|
|
51
|
+
classes: namespace.getClasses().map((cls) => this.serializeClass(cls)),
|
|
52
|
+
namespaces: namespace.getNamespaces().map((ns) => this.serializeNamespace(ns)),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
serializeClass(clazz) {
|
|
56
|
+
var _a;
|
|
57
|
+
return {
|
|
58
|
+
signature: this.serializeClassSignature(clazz.getSignature()),
|
|
59
|
+
modifiers: clazz.getModifiers(),
|
|
60
|
+
decorators: clazz.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
61
|
+
typeParameters: (_a = clazz.getGenericsTypes()) === null || _a === void 0 ? void 0 : _a.map((type) => this.serializeType(type)),
|
|
62
|
+
superClassName: clazz.getSuperClassName(),
|
|
63
|
+
implementedInterfaceNames: clazz.getImplementedInterfaceNames(),
|
|
64
|
+
fields: clazz.getFields().map((field) => this.serializeField(field)),
|
|
65
|
+
methods: clazz.getMethods(true).map((method) => this.serializeMethod(method)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
serializeField(field) {
|
|
69
|
+
return {
|
|
70
|
+
signature: this.serializeFieldSignature(field.getSignature()),
|
|
71
|
+
modifiers: field.getModifiers(),
|
|
72
|
+
decorators: field.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
73
|
+
questionToken: field.getQuestionToken(),
|
|
74
|
+
exclamationToken: field.getExclamationToken(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
serializeMethod(method) {
|
|
78
|
+
var _a;
|
|
79
|
+
let body = method.getBody();
|
|
80
|
+
return {
|
|
81
|
+
signature: this.serializeMethodSignature(method.getSignature()),
|
|
82
|
+
modifiers: method.getModifiers(),
|
|
83
|
+
decorators: method.getDecorators().map((decorator) => this.serializeDecorator(decorator)),
|
|
84
|
+
typeParameters: (_a = method.getGenericTypes()) === null || _a === void 0 ? void 0 : _a.map(type => this.serializeType(type)),
|
|
85
|
+
body: body && this.serializeMethodBody(body),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
serializeMethodBody(body) {
|
|
89
|
+
return {
|
|
90
|
+
locals: Array.from(body.getLocals().values()).map((local) => this.serializeLocal(local)),
|
|
91
|
+
cfg: this.serializeCfg(body.getCfg()),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
serializeMethodParameter(parameter) {
|
|
95
|
+
return {
|
|
96
|
+
name: parameter.getName(),
|
|
97
|
+
type: this.serializeType(parameter.getType()),
|
|
98
|
+
isOptional: parameter.isOptional(),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
serializeImportInfo(importInfo) {
|
|
102
|
+
return {
|
|
103
|
+
importClauseName: importInfo.getImportClauseName(),
|
|
104
|
+
importType: importInfo.getImportType(),
|
|
105
|
+
importFrom: importInfo.getFrom(),
|
|
106
|
+
nameBeforeAs: importInfo.getNameBeforeAs(),
|
|
107
|
+
modifiers: importInfo.getModifiers(),
|
|
108
|
+
originTsPosition: this.serializeLineColPosition(importInfo.getOriginTsPosition()),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
serializeExportInfo(exportInfo) {
|
|
112
|
+
return {
|
|
113
|
+
exportClauseName: exportInfo.getExportClauseName(),
|
|
114
|
+
exportClauseType: exportInfo.getExportClauseType(),
|
|
115
|
+
exportFrom: exportInfo.getFrom(),
|
|
116
|
+
nameBeforeAs: exportInfo.getNameBeforeAs(),
|
|
117
|
+
isDefault: exportInfo.isDefault(),
|
|
118
|
+
modifiers: exportInfo.getModifiers(),
|
|
119
|
+
originTsPosition: this.serializeLineColPosition(exportInfo.getOriginTsPosition()),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
serializeDecorator(decorator) {
|
|
123
|
+
return {
|
|
124
|
+
kind: decorator.getKind(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
serializeLineColPosition(position) {
|
|
128
|
+
return {
|
|
129
|
+
line: position.getLineNo(),
|
|
130
|
+
col: position.getColNo(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
serializeType(type) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
if (type === undefined) {
|
|
136
|
+
throw new Error('Type is undefined');
|
|
137
|
+
}
|
|
138
|
+
if (type instanceof Type_1.AnyType) {
|
|
139
|
+
return {
|
|
140
|
+
_: 'AnyType',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else if (type instanceof Type_1.UnknownType) {
|
|
144
|
+
return {
|
|
145
|
+
_: 'UnknownType',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
else if (type instanceof Type_1.VoidType) {
|
|
149
|
+
return {
|
|
150
|
+
_: 'VoidType',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
else if (type instanceof Type_1.NeverType) {
|
|
154
|
+
return {
|
|
155
|
+
_: 'NeverType',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else if (type instanceof Type_1.UnionType) {
|
|
159
|
+
return {
|
|
160
|
+
_: 'UnionType',
|
|
161
|
+
types: type.getTypes().map((type) => this.serializeType(type)),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else if (type instanceof Type_1.TupleType) {
|
|
165
|
+
return {
|
|
166
|
+
_: 'TupleType',
|
|
167
|
+
types: type.getTypes().map((type) => this.serializeType(type)),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
else if (type instanceof Type_1.BooleanType) {
|
|
171
|
+
return {
|
|
172
|
+
_: 'BooleanType',
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
else if (type instanceof Type_1.NumberType) {
|
|
176
|
+
return {
|
|
177
|
+
_: 'NumberType',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
else if (type instanceof Type_1.StringType) {
|
|
181
|
+
return {
|
|
182
|
+
_: 'StringType',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
else if (type instanceof Type_1.NullType) {
|
|
186
|
+
return {
|
|
187
|
+
_: 'NullType',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
else if (type instanceof Type_1.UndefinedType) {
|
|
191
|
+
return {
|
|
192
|
+
_: 'UndefinedType',
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else if (type instanceof Type_1.LiteralType) {
|
|
196
|
+
return {
|
|
197
|
+
_: 'LiteralType',
|
|
198
|
+
literal: type.getLiteralName(),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
else if (type instanceof Type_1.PrimitiveType) {
|
|
202
|
+
throw new Error('Unhandled PrimitiveType: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
203
|
+
}
|
|
204
|
+
else if (type instanceof Type_1.ClassType) {
|
|
205
|
+
return {
|
|
206
|
+
_: 'ClassType',
|
|
207
|
+
signature: this.serializeClassSignature(type.getClassSignature()),
|
|
208
|
+
typeParameters: (_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.map((type) => this.serializeType(type)),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
else if (type instanceof Type_1.FunctionType) {
|
|
212
|
+
return {
|
|
213
|
+
_: 'FunctionType',
|
|
214
|
+
signature: this.serializeMethodSignature(type.getMethodSignature()),
|
|
215
|
+
typeParameters: (_b = type.getRealGenericTypes()) === null || _b === void 0 ? void 0 : _b.map((type) => this.serializeType(type)),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
else if (type instanceof Type_1.ArrayType) {
|
|
219
|
+
return {
|
|
220
|
+
_: 'ArrayType',
|
|
221
|
+
elementType: this.serializeType(type.getBaseType()),
|
|
222
|
+
dimensions: type.getDimension(),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
else if (type instanceof Type_1.UnclearReferenceType) {
|
|
226
|
+
return {
|
|
227
|
+
_: 'UnclearReferenceType',
|
|
228
|
+
name: type.getName(),
|
|
229
|
+
typeParameters: type.getGenericTypes().map((type) => this.serializeType(type)),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
else if (type instanceof Type_1.GenericType) {
|
|
233
|
+
let defaultType = type.getDefaultType();
|
|
234
|
+
let constraint = type.getConstraint();
|
|
235
|
+
return {
|
|
236
|
+
_: 'GenericType',
|
|
237
|
+
name: type.getName(),
|
|
238
|
+
defaultType: defaultType && this.serializeType(defaultType),
|
|
239
|
+
constraint: constraint && this.serializeType(constraint),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
else if (type instanceof Type_1.AliasType) {
|
|
243
|
+
return {
|
|
244
|
+
_: 'AliasType',
|
|
245
|
+
name: type.getName(),
|
|
246
|
+
originalType: this.serializeType(type.getOriginalType()),
|
|
247
|
+
signature: this.serializeAliasTypeSignature(type.getSignature()),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
else if (type instanceof Type_1.AnnotationNamespaceType) {
|
|
251
|
+
return {
|
|
252
|
+
_: 'AnnotationNamespaceType',
|
|
253
|
+
originType: type.getOriginType(),
|
|
254
|
+
namespaceSignature: this.serializeNamespaceSignature(type.getNamespaceSignature()),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
else if (type instanceof Type_1.AnnotationTypeQueryType) {
|
|
258
|
+
return {
|
|
259
|
+
_: 'AnnotationTypeQueryType',
|
|
260
|
+
originType: type.getOriginType(),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
else if (type instanceof Type_1.AnnotationType) {
|
|
264
|
+
throw new Error('Unhandled AnnotationType: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
throw new Error('Unhandled Type: ' + util_1.default.inspect(type, { showHidden: true, depth: null }));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
serializeFileSignature(file) {
|
|
271
|
+
return {
|
|
272
|
+
projectName: file.getProjectName(),
|
|
273
|
+
fileName: file.getFileName(),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
serializeNamespaceSignature(namespace) {
|
|
277
|
+
let dns = namespace.getDeclaringNamespaceSignature();
|
|
278
|
+
return {
|
|
279
|
+
name: namespace.getNamespaceName(),
|
|
280
|
+
declaringFile: this.serializeFileSignature(namespace.getDeclaringFileSignature()),
|
|
281
|
+
declaringNamespace: dns && this.serializeNamespaceSignature(dns),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
serializeClassSignature(clazz) {
|
|
285
|
+
let dns = clazz.getDeclaringNamespaceSignature();
|
|
286
|
+
return {
|
|
287
|
+
name: clazz.getClassName(),
|
|
288
|
+
declaringFile: this.serializeFileSignature(clazz.getDeclaringFileSignature()),
|
|
289
|
+
declaringNamespace: dns && this.serializeNamespaceSignature(dns),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
serializeFieldSignature(field) {
|
|
293
|
+
let declaringSignature = field.getDeclaringSignature();
|
|
294
|
+
let declaringClass;
|
|
295
|
+
if (declaringSignature instanceof ArkSignature_1.ClassSignature) {
|
|
296
|
+
declaringClass = this.serializeClassSignature(declaringSignature);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
declaringClass = this.serializeNamespaceSignature(declaringSignature);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
declaringClass,
|
|
303
|
+
name: field.getFieldName(),
|
|
304
|
+
type: this.serializeType(field.getType()),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
serializeMethodSignature(method) {
|
|
308
|
+
return {
|
|
309
|
+
declaringClass: this.serializeClassSignature(method.getDeclaringClassSignature()),
|
|
310
|
+
name: method.getMethodSubSignature().getMethodName(),
|
|
311
|
+
parameters: method
|
|
312
|
+
.getMethodSubSignature()
|
|
313
|
+
.getParameters()
|
|
314
|
+
.map((param) => this.serializeMethodParameter(param)),
|
|
315
|
+
returnType: this.serializeType(method.getType()),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
serializeAliasTypeSignature(signature) {
|
|
319
|
+
return {
|
|
320
|
+
name: signature.getName(),
|
|
321
|
+
method: this.serializeMethodSignature(signature.getDeclaringMethodSignature()),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
serializeCfg(cfg) {
|
|
325
|
+
const visited = new Set();
|
|
326
|
+
const stack = [];
|
|
327
|
+
const startingBlock = cfg.getStartingBlock();
|
|
328
|
+
if (startingBlock) {
|
|
329
|
+
stack.push(startingBlock);
|
|
330
|
+
}
|
|
331
|
+
let id = 0;
|
|
332
|
+
while (stack.length > 0) {
|
|
333
|
+
const block = stack.pop();
|
|
334
|
+
if (visited.has(block)) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
visited.add(block);
|
|
338
|
+
block.setId(id++);
|
|
339
|
+
stack.push(...block.getSuccessors());
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
blocks: Array.from(visited).map((block) => this.serializeBasicBlock(block)),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
serializeBasicBlock(block) {
|
|
346
|
+
const successors = block.getSuccessors().map((succ) => succ.getId());
|
|
347
|
+
successors.sort((a, b) => a - b);
|
|
348
|
+
const predecessors = block.getPredecessors().map((pred) => pred.getId());
|
|
349
|
+
predecessors.sort((a, b) => a - b);
|
|
350
|
+
return {
|
|
351
|
+
id: block.getId(),
|
|
352
|
+
successors,
|
|
353
|
+
predecessors,
|
|
354
|
+
stmts: block.getStmts().map((stmt) => this.serializeStmt(stmt)),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
serializeLocal(local) {
|
|
358
|
+
return {
|
|
359
|
+
name: local.getName(),
|
|
360
|
+
type: this.serializeType(local.getType()),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
serializeValue(value) {
|
|
364
|
+
if (value === undefined) {
|
|
365
|
+
throw new Error('Value is undefined');
|
|
366
|
+
}
|
|
367
|
+
if (value instanceof Local_1.Local) {
|
|
368
|
+
return Object.assign({ _: 'Local' }, this.serializeLocal(value));
|
|
369
|
+
}
|
|
370
|
+
else if (value instanceof Constant_1.Constant) {
|
|
371
|
+
return {
|
|
372
|
+
_: 'Constant',
|
|
373
|
+
value: value.getValue(),
|
|
374
|
+
type: this.serializeType(value.getType()),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
else if (value instanceof Expr_1.ArkNewExpr) {
|
|
378
|
+
return {
|
|
379
|
+
_: 'NewExpr',
|
|
380
|
+
classType: this.serializeType(value.getClassType()),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
else if (value instanceof Expr_1.ArkNewArrayExpr) {
|
|
384
|
+
return {
|
|
385
|
+
_: 'NewArrayExpr',
|
|
386
|
+
elementType: this.serializeType(value.getBaseType()),
|
|
387
|
+
size: this.serializeValue(value.getSize()),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
else if (value instanceof Expr_1.ArkDeleteExpr) {
|
|
391
|
+
return {
|
|
392
|
+
_: 'DeleteExpr',
|
|
393
|
+
arg: this.serializeValue(value.getField()),
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
else if (value instanceof Expr_1.ArkAwaitExpr) {
|
|
397
|
+
return {
|
|
398
|
+
_: 'AwaitExpr',
|
|
399
|
+
arg: this.serializeValue(value.getPromise()),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
else if (value instanceof Expr_1.ArkYieldExpr) {
|
|
403
|
+
return {
|
|
404
|
+
_: 'YieldExpr',
|
|
405
|
+
arg: this.serializeValue(value.getYieldValue()),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
else if (value instanceof Expr_1.ArkTypeOfExpr) {
|
|
409
|
+
return {
|
|
410
|
+
_: 'TypeOfExpr',
|
|
411
|
+
arg: this.serializeValue(value.getOp()),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
else if (value instanceof Expr_1.ArkInstanceOfExpr) {
|
|
415
|
+
return {
|
|
416
|
+
_: 'InstanceOfExpr',
|
|
417
|
+
arg: this.serializeValue(value.getOp()),
|
|
418
|
+
checkType: this.serializeType(value.getCheckType()),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
else if (value instanceof Expr_1.ArkCastExpr) {
|
|
422
|
+
return {
|
|
423
|
+
_: 'CastExpr',
|
|
424
|
+
arg: this.serializeValue(value.getOp()),
|
|
425
|
+
type: this.serializeType(value.getType()),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
else if (value instanceof Expr_1.ArkPhiExpr) {
|
|
429
|
+
const args = value.getArgs();
|
|
430
|
+
const argToBlock = value.getArgToBlock();
|
|
431
|
+
return {
|
|
432
|
+
_: 'PhiExpr',
|
|
433
|
+
args: args.map((arg) => this.serializeValue(arg)),
|
|
434
|
+
blocks: args.map((arg) => argToBlock.get(arg).getId()),
|
|
435
|
+
type: this.serializeType(value.getType()),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
else if (value instanceof Expr_1.ArkConditionExpr) {
|
|
439
|
+
return {
|
|
440
|
+
_: 'ConditionExpr',
|
|
441
|
+
op: value.getOperator(),
|
|
442
|
+
left: this.serializeValue(value.getOp1()),
|
|
443
|
+
right: this.serializeValue(value.getOp2()),
|
|
444
|
+
type: this.serializeType(value.getType()),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
else if (value instanceof Expr_1.ArkNormalBinopExpr) {
|
|
448
|
+
return {
|
|
449
|
+
_: 'BinopExpr',
|
|
450
|
+
op: value.getOperator(),
|
|
451
|
+
left: this.serializeValue(value.getOp1()),
|
|
452
|
+
right: this.serializeValue(value.getOp2()),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
else if (value instanceof Expr_1.AbstractBinopExpr) {
|
|
456
|
+
return new Error('Unhandled BinopExpr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
457
|
+
}
|
|
458
|
+
else if (value instanceof Expr_1.ArkUnopExpr) {
|
|
459
|
+
return {
|
|
460
|
+
_: 'UnopExpr',
|
|
461
|
+
op: value.getOperator(),
|
|
462
|
+
arg: this.serializeValue(value.getOp()),
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
else if (value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
466
|
+
return {
|
|
467
|
+
_: 'InstanceCallExpr',
|
|
468
|
+
instance: this.serializeValue(value.getBase()),
|
|
469
|
+
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
470
|
+
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
else if (value instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
474
|
+
return {
|
|
475
|
+
_: 'StaticCallExpr',
|
|
476
|
+
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
477
|
+
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
else if (value instanceof Expr_1.ArkPtrInvokeExpr) {
|
|
481
|
+
return {
|
|
482
|
+
_: 'PtrCallExpr',
|
|
483
|
+
ptr: this.serializeValue(value.getFuncPtrLocal()),
|
|
484
|
+
method: this.serializeMethodSignature(value.getMethodSignature()),
|
|
485
|
+
args: value.getArgs().map((arg) => this.serializeValue(arg)),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
else if (value instanceof Expr_1.AbstractInvokeExpr) {
|
|
489
|
+
throw new Error('Unhandled CallExpr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
490
|
+
}
|
|
491
|
+
else if (value instanceof Ref_1.ArkThisRef) {
|
|
492
|
+
return {
|
|
493
|
+
_: 'ThisRef',
|
|
494
|
+
type: this.serializeType(value.getType()),
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
else if (value instanceof Ref_1.ArkParameterRef) {
|
|
498
|
+
return {
|
|
499
|
+
_: 'ParameterRef',
|
|
500
|
+
index: value.getIndex(),
|
|
501
|
+
type: this.serializeType(value.getType()),
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
else if (value instanceof Ref_1.ArkArrayRef) {
|
|
505
|
+
return {
|
|
506
|
+
_: 'ArrayRef',
|
|
507
|
+
array: this.serializeValue(value.getBase()),
|
|
508
|
+
index: this.serializeValue(value.getIndex()),
|
|
509
|
+
type: this.serializeType(value.getType()),
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
else if (value instanceof Ref_1.ArkInstanceFieldRef) {
|
|
513
|
+
return {
|
|
514
|
+
_: 'InstanceFieldRef',
|
|
515
|
+
instance: this.serializeValue(value.getBase()),
|
|
516
|
+
field: this.serializeFieldSignature(value.getFieldSignature()),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
else if (value instanceof Ref_1.ArkStaticFieldRef) {
|
|
520
|
+
return {
|
|
521
|
+
_: 'StaticFieldRef',
|
|
522
|
+
field: this.serializeFieldSignature(value.getFieldSignature()),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
else if (value instanceof Ref_1.AbstractFieldRef) {
|
|
526
|
+
throw new Error('Unhandled FieldRef: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
527
|
+
}
|
|
528
|
+
else if (value instanceof Ref_1.AbstractRef) {
|
|
529
|
+
throw new Error('Unhandled Ref: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
530
|
+
}
|
|
531
|
+
else if (value instanceof Expr_1.AbstractExpr) {
|
|
532
|
+
throw new Error('Unhandled Expr: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
throw new Error('Unhandled Value: ' + util_1.default.inspect(value, { showHidden: true, depth: null }));
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
serializeStmt(stmt) {
|
|
539
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
540
|
+
return {
|
|
541
|
+
_: 'AssignStmt',
|
|
542
|
+
left: this.serializeValue(stmt.getLeftOp()),
|
|
543
|
+
right: this.serializeValue(stmt.getRightOp()),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
else if (stmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
547
|
+
return {
|
|
548
|
+
_: 'CallStmt',
|
|
549
|
+
expr: this.serializeValue(stmt.getInvokeExpr()),
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
else if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
553
|
+
return {
|
|
554
|
+
_: 'IfStmt',
|
|
555
|
+
condition: this.serializeValue(stmt.getConditionExpr()),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
else if (stmt instanceof Stmt_1.ArkReturnVoidStmt) {
|
|
559
|
+
return {
|
|
560
|
+
_: 'ReturnVoidStmt',
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
else if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
564
|
+
return {
|
|
565
|
+
_: 'ReturnStmt',
|
|
566
|
+
arg: this.serializeValue(stmt.getOp()),
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
else if (stmt instanceof Stmt_1.ArkThrowStmt) {
|
|
570
|
+
return {
|
|
571
|
+
_: 'ThrowStmt',
|
|
572
|
+
arg: this.serializeValue(stmt.getOp()),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
throw new Error('Unhandled Stmt: ' + util_1.default.inspect(stmt, { showHidden: true, depth: null }));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
exports.JsonPrinter = JsonPrinter;
|