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
|
@@ -1,592 +1,592 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ArkMethod = exports.arkMethodNodeKind = void 0;
|
|
18
|
-
const Ref_1 = require("../base/Ref");
|
|
19
|
-
const Stmt_1 = require("../base/Stmt");
|
|
20
|
-
const Type_1 = require("../base/Type");
|
|
21
|
-
const ArkClass_1 = require("./ArkClass");
|
|
22
|
-
const ArkExport_1 = require("./ArkExport");
|
|
23
|
-
const Const_1 = require("../common/Const");
|
|
24
|
-
const Position_1 = require("../base/Position");
|
|
25
|
-
const ArkBaseModel_1 = require("./ArkBaseModel");
|
|
26
|
-
const ArkError_1 = require("../common/ArkError");
|
|
27
|
-
const EtsConst_1 = require("../common/EtsConst");
|
|
28
|
-
const Constant_1 = require("../base/Constant");
|
|
29
|
-
const Local_1 = require("../base/Local");
|
|
30
|
-
exports.arkMethodNodeKind = ['MethodDeclaration', 'Constructor', 'FunctionDeclaration', 'GetAccessor',
|
|
31
|
-
'SetAccessor', 'ArrowFunction', 'FunctionExpression', 'MethodSignature', 'ConstructSignature', 'CallSignature'];
|
|
32
|
-
/**
|
|
33
|
-
* @category core/model
|
|
34
|
-
*/
|
|
35
|
-
class ArkMethod extends ArkBaseModel_1.ArkBaseModel {
|
|
36
|
-
constructor() {
|
|
37
|
-
super();
|
|
38
|
-
this.isGeneratedFlag = false;
|
|
39
|
-
this.asteriskToken = false;
|
|
40
|
-
}
|
|
41
|
-
getExportType() {
|
|
42
|
-
return ArkExport_1.ExportType.METHOD;
|
|
43
|
-
}
|
|
44
|
-
getName() {
|
|
45
|
-
return this.getSignature().getMethodSubSignature().getMethodName();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Returns the codes of method as a **string.**
|
|
49
|
-
* @returns the codes of method.
|
|
50
|
-
*/
|
|
51
|
-
getCode() {
|
|
52
|
-
return this.code;
|
|
53
|
-
}
|
|
54
|
-
setCode(code) {
|
|
55
|
-
this.code = code;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Get all lines of the method's declarations or null if the method has no seperated declaration.
|
|
59
|
-
* @returns null or the lines of the method's declarations with number type.
|
|
60
|
-
*/
|
|
61
|
-
getDeclareLines() {
|
|
62
|
-
if (this.methodDeclareLineCols === undefined) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
let lines = [];
|
|
66
|
-
this.methodDeclareLineCols.forEach(lineCol => {
|
|
67
|
-
lines.push((0, Position_1.getLineNo)(lineCol));
|
|
68
|
-
});
|
|
69
|
-
return lines;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get all columns of the method's declarations or null if the method has no seperated declaration.
|
|
73
|
-
* @returns null or the columns of the method's declarations with number type.
|
|
74
|
-
*/
|
|
75
|
-
getDeclareColumns() {
|
|
76
|
-
if (this.methodDeclareLineCols === undefined) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
let columns = [];
|
|
80
|
-
this.methodDeclareLineCols.forEach(lineCol => {
|
|
81
|
-
columns.push((0, Position_1.getColNo)(lineCol));
|
|
82
|
-
});
|
|
83
|
-
return columns;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Set lines and columns of the declarations with number type inputs and then encoded them to LineCol type.
|
|
87
|
-
* The length of lines and columns should be the same otherwise they cannot be encoded together.
|
|
88
|
-
* @param lines - the number of lines.
|
|
89
|
-
* @param columns - the number of columns.
|
|
90
|
-
* @returns
|
|
91
|
-
*/
|
|
92
|
-
setDeclareLinesAndCols(lines, columns) {
|
|
93
|
-
if ((lines === null || lines === void 0 ? void 0 : lines.length) !== (columns === null || columns === void 0 ? void 0 : columns.length)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.methodDeclareLineCols = [];
|
|
97
|
-
lines.forEach((line, index) => {
|
|
98
|
-
let lineCol = 0;
|
|
99
|
-
lineCol = (0, Position_1.setLine)(lineCol, line);
|
|
100
|
-
lineCol = (0, Position_1.setCol)(lineCol, columns[index]);
|
|
101
|
-
this.methodDeclareLineCols.push(lineCol);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Set lineCols of the declarations directly with LineCol type input.
|
|
106
|
-
* @param lineCols - the encoded lines and columns with LineCol type.
|
|
107
|
-
* @returns
|
|
108
|
-
*/
|
|
109
|
-
setDeclareLineCols(lineCols) {
|
|
110
|
-
this.methodDeclareLineCols = lineCols;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get encoded lines and columns of the method's declarations or null if the method has no seperated declaration.
|
|
114
|
-
* @returns null or the encoded lines and columns of the method's declarations with LineCol type.
|
|
115
|
-
*/
|
|
116
|
-
getDeclareLineCols() {
|
|
117
|
-
var _a;
|
|
118
|
-
return (_a = this.methodDeclareLineCols) !== null && _a !== void 0 ? _a : null;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Get line of the method's implementation or null if the method has no implementation.
|
|
122
|
-
* @returns null or the number of the line.
|
|
123
|
-
*/
|
|
124
|
-
getLine() {
|
|
125
|
-
if (this.lineCol === undefined) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
return (0, Position_1.getLineNo)(this.lineCol);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Set line of the implementation with line number input.
|
|
132
|
-
* The line number will be encoded together with the original column number.
|
|
133
|
-
* @param line - the line number of the method implementation.
|
|
134
|
-
* @returns
|
|
135
|
-
*/
|
|
136
|
-
setLine(line) {
|
|
137
|
-
if (this.lineCol === undefined) {
|
|
138
|
-
this.lineCol = 0;
|
|
139
|
-
}
|
|
140
|
-
this.lineCol = (0, Position_1.setLine)(this.lineCol, line);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get column of the method's implementation or null if the method has no implementation.
|
|
144
|
-
* @returns null or the number of the column.
|
|
145
|
-
*/
|
|
146
|
-
getColumn() {
|
|
147
|
-
if (this.lineCol === undefined) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
return (0, Position_1.getColNo)(this.lineCol);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Set column of the implementation with column number input.
|
|
154
|
-
* The column number will be encoded together with the original line number.
|
|
155
|
-
* @param column - the column number of the method implementation.
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
setColumn(column) {
|
|
159
|
-
if (this.lineCol === undefined) {
|
|
160
|
-
this.lineCol = 0;
|
|
161
|
-
}
|
|
162
|
-
this.lineCol = (0, Position_1.setCol)(this.lineCol, column);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get encoded line and column of the method's implementation or null if the method has no implementation.
|
|
166
|
-
* @returns null or the encoded line and column of the method's implementation with LineCol type.
|
|
167
|
-
*/
|
|
168
|
-
getLineCol() {
|
|
169
|
-
var _a;
|
|
170
|
-
return (_a = this.lineCol) !== null && _a !== void 0 ? _a : null;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Set lineCol of the implementation directly with LineCol type input.
|
|
174
|
-
* @param lineCol - the encoded line and column with LineCol type.
|
|
175
|
-
* @returns
|
|
176
|
-
*/
|
|
177
|
-
setLineCol(lineCol) {
|
|
178
|
-
this.lineCol = lineCol;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Returns the declaring class of the method.
|
|
182
|
-
* @returns The declaring class of the method.
|
|
183
|
-
*/
|
|
184
|
-
getDeclaringArkClass() {
|
|
185
|
-
return this.declaringArkClass;
|
|
186
|
-
}
|
|
187
|
-
setDeclaringArkClass(declaringArkClass) {
|
|
188
|
-
this.declaringArkClass = declaringArkClass;
|
|
189
|
-
}
|
|
190
|
-
getDeclaringArkFile() {
|
|
191
|
-
return this.declaringArkClass.getDeclaringArkFile();
|
|
192
|
-
}
|
|
193
|
-
isDefaultArkMethod() {
|
|
194
|
-
return this.getName() === Const_1.DEFAULT_ARK_METHOD_NAME;
|
|
195
|
-
}
|
|
196
|
-
isAnonymousMethod() {
|
|
197
|
-
return this.getName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX);
|
|
198
|
-
}
|
|
199
|
-
getParameters() {
|
|
200
|
-
return this.getSignature().getMethodSubSignature().getParameters();
|
|
201
|
-
}
|
|
202
|
-
getReturnType() {
|
|
203
|
-
return this.getSignature().getType();
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get all declare signatures.
|
|
207
|
-
* The results could be null if there is no seperated declaration of the method.
|
|
208
|
-
* @returns null or the method declare signatures.
|
|
209
|
-
*/
|
|
210
|
-
getDeclareSignatures() {
|
|
211
|
-
var _a;
|
|
212
|
-
return (_a = this.methodDeclareSignatures) !== null && _a !== void 0 ? _a : null;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get the index of the matched method declare signature among all declare signatures.
|
|
216
|
-
* The index will be -1 if there is no matched signature found.
|
|
217
|
-
* @param targetSignature - the target declare signature want to search.
|
|
218
|
-
* @returns -1 or the index of the matched signature.
|
|
219
|
-
*/
|
|
220
|
-
getDeclareSignatureIndex(targetSignature) {
|
|
221
|
-
let declareSignatures = this.methodDeclareSignatures;
|
|
222
|
-
if (declareSignatures === undefined) {
|
|
223
|
-
return -1;
|
|
224
|
-
}
|
|
225
|
-
for (let i = 0; i < declareSignatures.length; i++) {
|
|
226
|
-
if (declareSignatures[i].isMatch(targetSignature)) {
|
|
227
|
-
return i;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return -1;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Get the method signature of the implementation.
|
|
234
|
-
* The signature could be null if the method is only a declaration which body is undefined.
|
|
235
|
-
* @returns null or the method implementation signature.
|
|
236
|
-
*/
|
|
237
|
-
getImplementationSignature() {
|
|
238
|
-
var _a;
|
|
239
|
-
return (_a = this.methodSignature) !== null && _a !== void 0 ? _a : null;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Get the method signature of the implementation or the first declaration if there is no implementation.
|
|
243
|
-
* For a method, the implementation and declaration signatures must not be undefined at the same time.
|
|
244
|
-
* A {@link MethodSignature} includes:
|
|
245
|
-
* - Class Signature: indicates which class this method belong to.
|
|
246
|
-
* - Method SubSignature: indicates the detail info of this method such as method name, parameters, returnType, etc.
|
|
247
|
-
* @returns The method signature.
|
|
248
|
-
* @example
|
|
249
|
-
* 1. Get the signature of method mtd.
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
let signature = mtd.getSignature();
|
|
253
|
-
// ... ...
|
|
254
|
-
```
|
|
255
|
-
*/
|
|
256
|
-
getSignature() {
|
|
257
|
-
var _a;
|
|
258
|
-
return (_a = this.methodSignature) !== null && _a !== void 0 ? _a : this.methodDeclareSignatures[0];
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Set signatures of all declarations.
|
|
262
|
-
* It will reset the declaration signatures if they are already defined before.
|
|
263
|
-
* @param signatures - one signature or a list of signatures.
|
|
264
|
-
* @returns
|
|
265
|
-
*/
|
|
266
|
-
setDeclareSignatures(signatures) {
|
|
267
|
-
if (Array.isArray(signatures)) {
|
|
268
|
-
this.methodDeclareSignatures = signatures;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
this.methodDeclareSignatures = [signatures];
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Reset signature of one declaration with the specified index.
|
|
276
|
-
* Will do nothing if the index doesn't exist.
|
|
277
|
-
* @param signature - new signature want to set.
|
|
278
|
-
* @param index - index of signature want to set.
|
|
279
|
-
* @returns
|
|
280
|
-
*/
|
|
281
|
-
setDeclareSignatureWithIndex(signature, index) {
|
|
282
|
-
if (this.methodDeclareSignatures === undefined || this.methodDeclareSignatures.length <= index) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
this.methodDeclareSignatures[index] = signature;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Set signature of implementation.
|
|
289
|
-
* It will reset the implementation signature if it is already defined before.
|
|
290
|
-
* @param signature - signature of implementation.
|
|
291
|
-
* @returns
|
|
292
|
-
*/
|
|
293
|
-
setImplementationSignature(signature) {
|
|
294
|
-
this.methodSignature = signature;
|
|
295
|
-
}
|
|
296
|
-
getSubSignature() {
|
|
297
|
-
return this.getSignature().getMethodSubSignature();
|
|
298
|
-
}
|
|
299
|
-
getGenericTypes() {
|
|
300
|
-
return this.genericTypes;
|
|
301
|
-
}
|
|
302
|
-
isGenericsMethod() {
|
|
303
|
-
return this.genericTypes !== undefined;
|
|
304
|
-
}
|
|
305
|
-
setGenericTypes(genericTypes) {
|
|
306
|
-
this.genericTypes = genericTypes;
|
|
307
|
-
}
|
|
308
|
-
getBodyBuilder() {
|
|
309
|
-
return this.bodyBuilder;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Get {@link ArkBody} of a Method.
|
|
313
|
-
* A {@link ArkBody} contains the CFG and actual instructions or operations to be executed for a method.
|
|
314
|
-
* It is analogous to the body of a function or method in high-level programming languages,
|
|
315
|
-
* which contains the statements and expressions that define what the function does.
|
|
316
|
-
* @returns The {@link ArkBody} of a method.
|
|
317
|
-
* @example
|
|
318
|
-
* 1. Get cfg or stmt through ArkBody.
|
|
319
|
-
|
|
320
|
-
```typescript
|
|
321
|
-
let cfg = this.scene.getMethod()?.getBody().getCfg();
|
|
322
|
-
const body = arkMethod.getBody()
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
2. Get local variable through ArkBody.
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
arkClass.getDefaultArkMethod()?.getBody().getLocals.forEach(local=>{...})
|
|
329
|
-
let locals = arkFile().getDefaultClass().getDefaultArkMethod()?.getBody()?.getLocals();
|
|
330
|
-
```
|
|
331
|
-
*/
|
|
332
|
-
getBody() {
|
|
333
|
-
return this.body;
|
|
334
|
-
}
|
|
335
|
-
setBody(body) {
|
|
336
|
-
this.body = body;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Get the CFG (i.e., control flow graph) of a method.
|
|
340
|
-
* The CFG is a graphical representation of all possible control flow paths within a method's body.
|
|
341
|
-
* A CFG consists of blocks, statements and goto control jumps.
|
|
342
|
-
* @returns The CFG (i.e., control flow graph) of a method.
|
|
343
|
-
* @example
|
|
344
|
-
* 1. get stmt through ArkBody cfg.
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
body = arkMethod.getBody();
|
|
348
|
-
const cfg = body.getCfg();
|
|
349
|
-
for (const threeAddressStmt of cfg.getStmts()) {
|
|
350
|
-
... ...
|
|
351
|
-
}
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
2. get blocks through ArkBody cfg.
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
const body = arkMethod.getBody();
|
|
358
|
-
const blocks = [...body.getCfg().getBlocks()];
|
|
359
|
-
for (let i=0; i<blocks.length; i++) {
|
|
360
|
-
const block = blocks[i];
|
|
361
|
-
... ...
|
|
362
|
-
for (const stmt of block.getStmts()) {
|
|
363
|
-
... ...
|
|
364
|
-
}
|
|
365
|
-
let text = "next;"
|
|
366
|
-
for (const next of block.getSuccessors()) {
|
|
367
|
-
text += blocks.indexOf(next) + ' ';
|
|
368
|
-
}
|
|
369
|
-
// ... ...
|
|
370
|
-
}
|
|
371
|
-
```
|
|
372
|
-
*/
|
|
373
|
-
getCfg() {
|
|
374
|
-
var _a;
|
|
375
|
-
return (_a = this.body) === null || _a === void 0 ? void 0 : _a.getCfg();
|
|
376
|
-
}
|
|
377
|
-
getOriginalCfg() {
|
|
378
|
-
return undefined;
|
|
379
|
-
}
|
|
380
|
-
getParameterRefs() {
|
|
381
|
-
var _a;
|
|
382
|
-
let paramRefs = [];
|
|
383
|
-
const blocks = (_a = this.getBody()) === null || _a === void 0 ? void 0 : _a.getCfg().getBlocks();
|
|
384
|
-
if (blocks === undefined) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
const stmts = Array.from(blocks)[0].getStmts();
|
|
388
|
-
for (let stmt of stmts) {
|
|
389
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Ref_1.ArkParameterRef) {
|
|
390
|
-
paramRefs.push(stmt.getRightOp());
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return paramRefs;
|
|
394
|
-
}
|
|
395
|
-
getParameterInstances() {
|
|
396
|
-
// 获取方法体中参数Local实例
|
|
397
|
-
let stmts = [];
|
|
398
|
-
if (this.getCfg()) {
|
|
399
|
-
const cfg = this.getCfg();
|
|
400
|
-
cfg.getStmts().forEach(stmt => stmts.push(stmt));
|
|
401
|
-
}
|
|
402
|
-
let results = [];
|
|
403
|
-
for (let stmt of stmts) {
|
|
404
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
405
|
-
if (stmt.getRightOp() instanceof Ref_1.ArkParameterRef) {
|
|
406
|
-
results.push(stmt.getLeftOp());
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (results.length === this.getParameters().length) {
|
|
410
|
-
return results;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return results;
|
|
414
|
-
}
|
|
415
|
-
getThisInstance() {
|
|
416
|
-
// 获取方法体中This实例
|
|
417
|
-
let stmts = [];
|
|
418
|
-
if (this.getCfg()) {
|
|
419
|
-
const cfg = this.getCfg();
|
|
420
|
-
cfg.getStmts().forEach(stmt => stmts.push(stmt));
|
|
421
|
-
}
|
|
422
|
-
for (let stmt of stmts) {
|
|
423
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
424
|
-
if (stmt.getRightOp() instanceof Ref_1.ArkThisRef) {
|
|
425
|
-
return stmt.getLeftOp();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
|
-
getReturnValues() {
|
|
432
|
-
var _a;
|
|
433
|
-
// 获取方法体中return值实例
|
|
434
|
-
let resultValues = [];
|
|
435
|
-
(_a = this.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts().forEach(stmt => {
|
|
436
|
-
if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
437
|
-
resultValues.push(stmt.getOp());
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
return resultValues;
|
|
441
|
-
}
|
|
442
|
-
getReturnStmt() {
|
|
443
|
-
return this.getCfg().getStmts().filter(stmt => stmt instanceof Stmt_1.ArkReturnStmt);
|
|
444
|
-
}
|
|
445
|
-
setViewTree(viewTree) {
|
|
446
|
-
this.viewTree = viewTree;
|
|
447
|
-
}
|
|
448
|
-
getViewTree() {
|
|
449
|
-
return this.viewTree;
|
|
450
|
-
}
|
|
451
|
-
hasViewTree() {
|
|
452
|
-
return this.viewTree !== undefined;
|
|
453
|
-
}
|
|
454
|
-
setBodyBuilder(bodyBuilder) {
|
|
455
|
-
this.bodyBuilder = bodyBuilder;
|
|
456
|
-
if (this.getDeclaringArkFile().getScene().buildClassDone()) {
|
|
457
|
-
this.buildBody();
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
freeBodyBuilder() {
|
|
461
|
-
this.bodyBuilder = undefined;
|
|
462
|
-
}
|
|
463
|
-
buildBody() {
|
|
464
|
-
if (this.bodyBuilder) {
|
|
465
|
-
const arkBody = this.bodyBuilder.build();
|
|
466
|
-
if (arkBody) {
|
|
467
|
-
this.setBody(arkBody);
|
|
468
|
-
arkBody.getCfg().setDeclaringMethod(this);
|
|
469
|
-
if (this.getOuterMethod() === undefined) {
|
|
470
|
-
this.bodyBuilder.handleGlobalAndClosure();
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
isGenerated() {
|
|
476
|
-
return this.isGeneratedFlag;
|
|
477
|
-
}
|
|
478
|
-
setIsGeneratedFlag(isGeneratedFlag) {
|
|
479
|
-
this.isGeneratedFlag = isGeneratedFlag;
|
|
480
|
-
}
|
|
481
|
-
getAsteriskToken() {
|
|
482
|
-
return this.asteriskToken;
|
|
483
|
-
}
|
|
484
|
-
setAsteriskToken(asteriskToken) {
|
|
485
|
-
this.asteriskToken = asteriskToken;
|
|
486
|
-
}
|
|
487
|
-
validate() {
|
|
488
|
-
const declareSignatures = this.getDeclareSignatures();
|
|
489
|
-
const declareLineCols = this.getDeclareLineCols();
|
|
490
|
-
const signature = this.getImplementationSignature();
|
|
491
|
-
const lineCol = this.getLineCol();
|
|
492
|
-
if (declareSignatures === null && signature === null) {
|
|
493
|
-
return {
|
|
494
|
-
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_UNDEFINED,
|
|
495
|
-
errMsg: 'methodDeclareSignatures and methodSignature are both undefined.'
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
if ((declareSignatures === null) !== (declareLineCols === null)) {
|
|
499
|
-
return {
|
|
500
|
-
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
501
|
-
errMsg: 'methodDeclareSignatures and methodDeclareLineCols are not matched.'
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
if (declareSignatures !== null && declareLineCols !== null && declareSignatures.length !== declareLineCols.length) {
|
|
505
|
-
return {
|
|
506
|
-
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
507
|
-
errMsg: 'methodDeclareSignatures and methodDeclareLineCols are not matched.'
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
if ((signature === null) !== (lineCol === null)) {
|
|
511
|
-
return {
|
|
512
|
-
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
513
|
-
errMsg: 'methodSignature and lineCol are not matched.'
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
return this.validateFields(['declaringArkClass']);
|
|
517
|
-
}
|
|
518
|
-
matchMethodSignature(args) {
|
|
519
|
-
var _a, _b, _c;
|
|
520
|
-
const signatures = (_a = this.methodDeclareSignatures) === null || _a === void 0 ? void 0 : _a.filter(f => {
|
|
521
|
-
const parameters = f.getMethodSubSignature().getParameters();
|
|
522
|
-
const max = parameters.length;
|
|
523
|
-
let min = 0;
|
|
524
|
-
while (min < max && !parameters[min].isOptional()) {
|
|
525
|
-
min++;
|
|
526
|
-
}
|
|
527
|
-
return args.length >= min && args.length <= max;
|
|
528
|
-
});
|
|
529
|
-
const scene = this.getDeclaringArkFile().getScene();
|
|
530
|
-
return (_c = (_b = signatures === null || signatures === void 0 ? void 0 : signatures.find(p => {
|
|
531
|
-
const parameters = p.getMethodSubSignature().getParameters();
|
|
532
|
-
for (let i = 0; i < parameters.length; i++) {
|
|
533
|
-
if (!args[i]) {
|
|
534
|
-
return parameters[i].isOptional();
|
|
535
|
-
}
|
|
536
|
-
const isMatched = this.matchParam(parameters[i].getType(), args[i], scene);
|
|
537
|
-
if (!isMatched) {
|
|
538
|
-
return false;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return true;
|
|
542
|
-
})) !== null && _b !== void 0 ? _b : signatures === null || signatures === void 0 ? void 0 : signatures[0]) !== null && _c !== void 0 ? _c : this.getSignature();
|
|
543
|
-
}
|
|
544
|
-
matchParam(paramType, arg, scene) {
|
|
545
|
-
var _a;
|
|
546
|
-
const argType = arg.getType();
|
|
547
|
-
if (arg instanceof Local_1.Local) {
|
|
548
|
-
const stmt = arg.getDeclaringStmt();
|
|
549
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Constant_1.Constant) {
|
|
550
|
-
arg = stmt.getRightOp();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
if (paramType instanceof Type_1.UnionType) {
|
|
554
|
-
let matched = false;
|
|
555
|
-
for (const e of paramType.getTypes()) {
|
|
556
|
-
if (argType.constructor === e.constructor) {
|
|
557
|
-
matched = true;
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
return matched;
|
|
562
|
-
}
|
|
563
|
-
else if (argType instanceof Type_1.FunctionType && paramType instanceof Type_1.FunctionType) {
|
|
564
|
-
return argType.getMethodSignature().getParamLength() === paramType.getMethodSignature().getParamLength();
|
|
565
|
-
}
|
|
566
|
-
else if (argType instanceof Type_1.FunctionType && paramType instanceof Type_1.ClassType &&
|
|
567
|
-
paramType.getClassSignature().getClassName().includes(EtsConst_1.CALL_BACK)) {
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
else if (paramType instanceof Type_1.LiteralType && arg instanceof Constant_1.Constant) {
|
|
571
|
-
return arg.getValue().replace(/[\"|\']/g, '') === paramType.getLiteralName()
|
|
572
|
-
.toString().replace(/[\"|\']/g, '');
|
|
573
|
-
}
|
|
574
|
-
else if (paramType instanceof Type_1.NumberType && argType instanceof Type_1.ClassType && ArkClass_1.ClassCategory.ENUM ===
|
|
575
|
-
((_a = scene.getClass(argType.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getCategory())) {
|
|
576
|
-
return true;
|
|
577
|
-
}
|
|
578
|
-
return argType.constructor === paramType.constructor;
|
|
579
|
-
}
|
|
580
|
-
getOuterMethod() {
|
|
581
|
-
return this.outerMethod;
|
|
582
|
-
}
|
|
583
|
-
setOuterMethod(method) {
|
|
584
|
-
this.outerMethod = method;
|
|
585
|
-
}
|
|
586
|
-
getFunctionLocal(name) {
|
|
587
|
-
var _a;
|
|
588
|
-
const local = (_a = this.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
|
|
589
|
-
return (local === null || local === void 0 ? void 0 : local.getType()) instanceof Type_1.FunctionType ? local : null;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
exports.ArkMethod = ArkMethod;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ArkMethod = exports.arkMethodNodeKind = void 0;
|
|
18
|
+
const Ref_1 = require("../base/Ref");
|
|
19
|
+
const Stmt_1 = require("../base/Stmt");
|
|
20
|
+
const Type_1 = require("../base/Type");
|
|
21
|
+
const ArkClass_1 = require("./ArkClass");
|
|
22
|
+
const ArkExport_1 = require("./ArkExport");
|
|
23
|
+
const Const_1 = require("../common/Const");
|
|
24
|
+
const Position_1 = require("../base/Position");
|
|
25
|
+
const ArkBaseModel_1 = require("./ArkBaseModel");
|
|
26
|
+
const ArkError_1 = require("../common/ArkError");
|
|
27
|
+
const EtsConst_1 = require("../common/EtsConst");
|
|
28
|
+
const Constant_1 = require("../base/Constant");
|
|
29
|
+
const Local_1 = require("../base/Local");
|
|
30
|
+
exports.arkMethodNodeKind = ['MethodDeclaration', 'Constructor', 'FunctionDeclaration', 'GetAccessor',
|
|
31
|
+
'SetAccessor', 'ArrowFunction', 'FunctionExpression', 'MethodSignature', 'ConstructSignature', 'CallSignature'];
|
|
32
|
+
/**
|
|
33
|
+
* @category core/model
|
|
34
|
+
*/
|
|
35
|
+
class ArkMethod extends ArkBaseModel_1.ArkBaseModel {
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
38
|
+
this.isGeneratedFlag = false;
|
|
39
|
+
this.asteriskToken = false;
|
|
40
|
+
}
|
|
41
|
+
getExportType() {
|
|
42
|
+
return ArkExport_1.ExportType.METHOD;
|
|
43
|
+
}
|
|
44
|
+
getName() {
|
|
45
|
+
return this.getSignature().getMethodSubSignature().getMethodName();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the codes of method as a **string.**
|
|
49
|
+
* @returns the codes of method.
|
|
50
|
+
*/
|
|
51
|
+
getCode() {
|
|
52
|
+
return this.code;
|
|
53
|
+
}
|
|
54
|
+
setCode(code) {
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get all lines of the method's declarations or null if the method has no seperated declaration.
|
|
59
|
+
* @returns null or the lines of the method's declarations with number type.
|
|
60
|
+
*/
|
|
61
|
+
getDeclareLines() {
|
|
62
|
+
if (this.methodDeclareLineCols === undefined) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
let lines = [];
|
|
66
|
+
this.methodDeclareLineCols.forEach(lineCol => {
|
|
67
|
+
lines.push((0, Position_1.getLineNo)(lineCol));
|
|
68
|
+
});
|
|
69
|
+
return lines;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get all columns of the method's declarations or null if the method has no seperated declaration.
|
|
73
|
+
* @returns null or the columns of the method's declarations with number type.
|
|
74
|
+
*/
|
|
75
|
+
getDeclareColumns() {
|
|
76
|
+
if (this.methodDeclareLineCols === undefined) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let columns = [];
|
|
80
|
+
this.methodDeclareLineCols.forEach(lineCol => {
|
|
81
|
+
columns.push((0, Position_1.getColNo)(lineCol));
|
|
82
|
+
});
|
|
83
|
+
return columns;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Set lines and columns of the declarations with number type inputs and then encoded them to LineCol type.
|
|
87
|
+
* The length of lines and columns should be the same otherwise they cannot be encoded together.
|
|
88
|
+
* @param lines - the number of lines.
|
|
89
|
+
* @param columns - the number of columns.
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
setDeclareLinesAndCols(lines, columns) {
|
|
93
|
+
if ((lines === null || lines === void 0 ? void 0 : lines.length) !== (columns === null || columns === void 0 ? void 0 : columns.length)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.methodDeclareLineCols = [];
|
|
97
|
+
lines.forEach((line, index) => {
|
|
98
|
+
let lineCol = 0;
|
|
99
|
+
lineCol = (0, Position_1.setLine)(lineCol, line);
|
|
100
|
+
lineCol = (0, Position_1.setCol)(lineCol, columns[index]);
|
|
101
|
+
this.methodDeclareLineCols.push(lineCol);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set lineCols of the declarations directly with LineCol type input.
|
|
106
|
+
* @param lineCols - the encoded lines and columns with LineCol type.
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
setDeclareLineCols(lineCols) {
|
|
110
|
+
this.methodDeclareLineCols = lineCols;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get encoded lines and columns of the method's declarations or null if the method has no seperated declaration.
|
|
114
|
+
* @returns null or the encoded lines and columns of the method's declarations with LineCol type.
|
|
115
|
+
*/
|
|
116
|
+
getDeclareLineCols() {
|
|
117
|
+
var _a;
|
|
118
|
+
return (_a = this.methodDeclareLineCols) !== null && _a !== void 0 ? _a : null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get line of the method's implementation or null if the method has no implementation.
|
|
122
|
+
* @returns null or the number of the line.
|
|
123
|
+
*/
|
|
124
|
+
getLine() {
|
|
125
|
+
if (this.lineCol === undefined) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return (0, Position_1.getLineNo)(this.lineCol);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Set line of the implementation with line number input.
|
|
132
|
+
* The line number will be encoded together with the original column number.
|
|
133
|
+
* @param line - the line number of the method implementation.
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
setLine(line) {
|
|
137
|
+
if (this.lineCol === undefined) {
|
|
138
|
+
this.lineCol = 0;
|
|
139
|
+
}
|
|
140
|
+
this.lineCol = (0, Position_1.setLine)(this.lineCol, line);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get column of the method's implementation or null if the method has no implementation.
|
|
144
|
+
* @returns null or the number of the column.
|
|
145
|
+
*/
|
|
146
|
+
getColumn() {
|
|
147
|
+
if (this.lineCol === undefined) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return (0, Position_1.getColNo)(this.lineCol);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Set column of the implementation with column number input.
|
|
154
|
+
* The column number will be encoded together with the original line number.
|
|
155
|
+
* @param column - the column number of the method implementation.
|
|
156
|
+
* @returns
|
|
157
|
+
*/
|
|
158
|
+
setColumn(column) {
|
|
159
|
+
if (this.lineCol === undefined) {
|
|
160
|
+
this.lineCol = 0;
|
|
161
|
+
}
|
|
162
|
+
this.lineCol = (0, Position_1.setCol)(this.lineCol, column);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get encoded line and column of the method's implementation or null if the method has no implementation.
|
|
166
|
+
* @returns null or the encoded line and column of the method's implementation with LineCol type.
|
|
167
|
+
*/
|
|
168
|
+
getLineCol() {
|
|
169
|
+
var _a;
|
|
170
|
+
return (_a = this.lineCol) !== null && _a !== void 0 ? _a : null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Set lineCol of the implementation directly with LineCol type input.
|
|
174
|
+
* @param lineCol - the encoded line and column with LineCol type.
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
setLineCol(lineCol) {
|
|
178
|
+
this.lineCol = lineCol;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns the declaring class of the method.
|
|
182
|
+
* @returns The declaring class of the method.
|
|
183
|
+
*/
|
|
184
|
+
getDeclaringArkClass() {
|
|
185
|
+
return this.declaringArkClass;
|
|
186
|
+
}
|
|
187
|
+
setDeclaringArkClass(declaringArkClass) {
|
|
188
|
+
this.declaringArkClass = declaringArkClass;
|
|
189
|
+
}
|
|
190
|
+
getDeclaringArkFile() {
|
|
191
|
+
return this.declaringArkClass.getDeclaringArkFile();
|
|
192
|
+
}
|
|
193
|
+
isDefaultArkMethod() {
|
|
194
|
+
return this.getName() === Const_1.DEFAULT_ARK_METHOD_NAME;
|
|
195
|
+
}
|
|
196
|
+
isAnonymousMethod() {
|
|
197
|
+
return this.getName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX);
|
|
198
|
+
}
|
|
199
|
+
getParameters() {
|
|
200
|
+
return this.getSignature().getMethodSubSignature().getParameters();
|
|
201
|
+
}
|
|
202
|
+
getReturnType() {
|
|
203
|
+
return this.getSignature().getType();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get all declare signatures.
|
|
207
|
+
* The results could be null if there is no seperated declaration of the method.
|
|
208
|
+
* @returns null or the method declare signatures.
|
|
209
|
+
*/
|
|
210
|
+
getDeclareSignatures() {
|
|
211
|
+
var _a;
|
|
212
|
+
return (_a = this.methodDeclareSignatures) !== null && _a !== void 0 ? _a : null;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get the index of the matched method declare signature among all declare signatures.
|
|
216
|
+
* The index will be -1 if there is no matched signature found.
|
|
217
|
+
* @param targetSignature - the target declare signature want to search.
|
|
218
|
+
* @returns -1 or the index of the matched signature.
|
|
219
|
+
*/
|
|
220
|
+
getDeclareSignatureIndex(targetSignature) {
|
|
221
|
+
let declareSignatures = this.methodDeclareSignatures;
|
|
222
|
+
if (declareSignatures === undefined) {
|
|
223
|
+
return -1;
|
|
224
|
+
}
|
|
225
|
+
for (let i = 0; i < declareSignatures.length; i++) {
|
|
226
|
+
if (declareSignatures[i].isMatch(targetSignature)) {
|
|
227
|
+
return i;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return -1;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get the method signature of the implementation.
|
|
234
|
+
* The signature could be null if the method is only a declaration which body is undefined.
|
|
235
|
+
* @returns null or the method implementation signature.
|
|
236
|
+
*/
|
|
237
|
+
getImplementationSignature() {
|
|
238
|
+
var _a;
|
|
239
|
+
return (_a = this.methodSignature) !== null && _a !== void 0 ? _a : null;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Get the method signature of the implementation or the first declaration if there is no implementation.
|
|
243
|
+
* For a method, the implementation and declaration signatures must not be undefined at the same time.
|
|
244
|
+
* A {@link MethodSignature} includes:
|
|
245
|
+
* - Class Signature: indicates which class this method belong to.
|
|
246
|
+
* - Method SubSignature: indicates the detail info of this method such as method name, parameters, returnType, etc.
|
|
247
|
+
* @returns The method signature.
|
|
248
|
+
* @example
|
|
249
|
+
* 1. Get the signature of method mtd.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
let signature = mtd.getSignature();
|
|
253
|
+
// ... ...
|
|
254
|
+
```
|
|
255
|
+
*/
|
|
256
|
+
getSignature() {
|
|
257
|
+
var _a;
|
|
258
|
+
return (_a = this.methodSignature) !== null && _a !== void 0 ? _a : this.methodDeclareSignatures[0];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Set signatures of all declarations.
|
|
262
|
+
* It will reset the declaration signatures if they are already defined before.
|
|
263
|
+
* @param signatures - one signature or a list of signatures.
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
setDeclareSignatures(signatures) {
|
|
267
|
+
if (Array.isArray(signatures)) {
|
|
268
|
+
this.methodDeclareSignatures = signatures;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
this.methodDeclareSignatures = [signatures];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Reset signature of one declaration with the specified index.
|
|
276
|
+
* Will do nothing if the index doesn't exist.
|
|
277
|
+
* @param signature - new signature want to set.
|
|
278
|
+
* @param index - index of signature want to set.
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
setDeclareSignatureWithIndex(signature, index) {
|
|
282
|
+
if (this.methodDeclareSignatures === undefined || this.methodDeclareSignatures.length <= index) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
this.methodDeclareSignatures[index] = signature;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Set signature of implementation.
|
|
289
|
+
* It will reset the implementation signature if it is already defined before.
|
|
290
|
+
* @param signature - signature of implementation.
|
|
291
|
+
* @returns
|
|
292
|
+
*/
|
|
293
|
+
setImplementationSignature(signature) {
|
|
294
|
+
this.methodSignature = signature;
|
|
295
|
+
}
|
|
296
|
+
getSubSignature() {
|
|
297
|
+
return this.getSignature().getMethodSubSignature();
|
|
298
|
+
}
|
|
299
|
+
getGenericTypes() {
|
|
300
|
+
return this.genericTypes;
|
|
301
|
+
}
|
|
302
|
+
isGenericsMethod() {
|
|
303
|
+
return this.genericTypes !== undefined;
|
|
304
|
+
}
|
|
305
|
+
setGenericTypes(genericTypes) {
|
|
306
|
+
this.genericTypes = genericTypes;
|
|
307
|
+
}
|
|
308
|
+
getBodyBuilder() {
|
|
309
|
+
return this.bodyBuilder;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get {@link ArkBody} of a Method.
|
|
313
|
+
* A {@link ArkBody} contains the CFG and actual instructions or operations to be executed for a method.
|
|
314
|
+
* It is analogous to the body of a function or method in high-level programming languages,
|
|
315
|
+
* which contains the statements and expressions that define what the function does.
|
|
316
|
+
* @returns The {@link ArkBody} of a method.
|
|
317
|
+
* @example
|
|
318
|
+
* 1. Get cfg or stmt through ArkBody.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
let cfg = this.scene.getMethod()?.getBody().getCfg();
|
|
322
|
+
const body = arkMethod.getBody()
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
2. Get local variable through ArkBody.
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
arkClass.getDefaultArkMethod()?.getBody().getLocals.forEach(local=>{...})
|
|
329
|
+
let locals = arkFile().getDefaultClass().getDefaultArkMethod()?.getBody()?.getLocals();
|
|
330
|
+
```
|
|
331
|
+
*/
|
|
332
|
+
getBody() {
|
|
333
|
+
return this.body;
|
|
334
|
+
}
|
|
335
|
+
setBody(body) {
|
|
336
|
+
this.body = body;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get the CFG (i.e., control flow graph) of a method.
|
|
340
|
+
* The CFG is a graphical representation of all possible control flow paths within a method's body.
|
|
341
|
+
* A CFG consists of blocks, statements and goto control jumps.
|
|
342
|
+
* @returns The CFG (i.e., control flow graph) of a method.
|
|
343
|
+
* @example
|
|
344
|
+
* 1. get stmt through ArkBody cfg.
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
body = arkMethod.getBody();
|
|
348
|
+
const cfg = body.getCfg();
|
|
349
|
+
for (const threeAddressStmt of cfg.getStmts()) {
|
|
350
|
+
... ...
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
2. get blocks through ArkBody cfg.
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
const body = arkMethod.getBody();
|
|
358
|
+
const blocks = [...body.getCfg().getBlocks()];
|
|
359
|
+
for (let i=0; i<blocks.length; i++) {
|
|
360
|
+
const block = blocks[i];
|
|
361
|
+
... ...
|
|
362
|
+
for (const stmt of block.getStmts()) {
|
|
363
|
+
... ...
|
|
364
|
+
}
|
|
365
|
+
let text = "next;"
|
|
366
|
+
for (const next of block.getSuccessors()) {
|
|
367
|
+
text += blocks.indexOf(next) + ' ';
|
|
368
|
+
}
|
|
369
|
+
// ... ...
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
*/
|
|
373
|
+
getCfg() {
|
|
374
|
+
var _a;
|
|
375
|
+
return (_a = this.body) === null || _a === void 0 ? void 0 : _a.getCfg();
|
|
376
|
+
}
|
|
377
|
+
getOriginalCfg() {
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
getParameterRefs() {
|
|
381
|
+
var _a;
|
|
382
|
+
let paramRefs = [];
|
|
383
|
+
const blocks = (_a = this.getBody()) === null || _a === void 0 ? void 0 : _a.getCfg().getBlocks();
|
|
384
|
+
if (blocks === undefined) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const stmts = Array.from(blocks)[0].getStmts();
|
|
388
|
+
for (let stmt of stmts) {
|
|
389
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Ref_1.ArkParameterRef) {
|
|
390
|
+
paramRefs.push(stmt.getRightOp());
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return paramRefs;
|
|
394
|
+
}
|
|
395
|
+
getParameterInstances() {
|
|
396
|
+
// 获取方法体中参数Local实例
|
|
397
|
+
let stmts = [];
|
|
398
|
+
if (this.getCfg()) {
|
|
399
|
+
const cfg = this.getCfg();
|
|
400
|
+
cfg.getStmts().forEach(stmt => stmts.push(stmt));
|
|
401
|
+
}
|
|
402
|
+
let results = [];
|
|
403
|
+
for (let stmt of stmts) {
|
|
404
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
405
|
+
if (stmt.getRightOp() instanceof Ref_1.ArkParameterRef) {
|
|
406
|
+
results.push(stmt.getLeftOp());
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (results.length === this.getParameters().length) {
|
|
410
|
+
return results;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return results;
|
|
414
|
+
}
|
|
415
|
+
getThisInstance() {
|
|
416
|
+
// 获取方法体中This实例
|
|
417
|
+
let stmts = [];
|
|
418
|
+
if (this.getCfg()) {
|
|
419
|
+
const cfg = this.getCfg();
|
|
420
|
+
cfg.getStmts().forEach(stmt => stmts.push(stmt));
|
|
421
|
+
}
|
|
422
|
+
for (let stmt of stmts) {
|
|
423
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
424
|
+
if (stmt.getRightOp() instanceof Ref_1.ArkThisRef) {
|
|
425
|
+
return stmt.getLeftOp();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
getReturnValues() {
|
|
432
|
+
var _a;
|
|
433
|
+
// 获取方法体中return值实例
|
|
434
|
+
let resultValues = [];
|
|
435
|
+
(_a = this.getCfg()) === null || _a === void 0 ? void 0 : _a.getStmts().forEach(stmt => {
|
|
436
|
+
if (stmt instanceof Stmt_1.ArkReturnStmt) {
|
|
437
|
+
resultValues.push(stmt.getOp());
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return resultValues;
|
|
441
|
+
}
|
|
442
|
+
getReturnStmt() {
|
|
443
|
+
return this.getCfg().getStmts().filter(stmt => stmt instanceof Stmt_1.ArkReturnStmt);
|
|
444
|
+
}
|
|
445
|
+
setViewTree(viewTree) {
|
|
446
|
+
this.viewTree = viewTree;
|
|
447
|
+
}
|
|
448
|
+
getViewTree() {
|
|
449
|
+
return this.viewTree;
|
|
450
|
+
}
|
|
451
|
+
hasViewTree() {
|
|
452
|
+
return this.viewTree !== undefined;
|
|
453
|
+
}
|
|
454
|
+
setBodyBuilder(bodyBuilder) {
|
|
455
|
+
this.bodyBuilder = bodyBuilder;
|
|
456
|
+
if (this.getDeclaringArkFile().getScene().buildClassDone()) {
|
|
457
|
+
this.buildBody();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
freeBodyBuilder() {
|
|
461
|
+
this.bodyBuilder = undefined;
|
|
462
|
+
}
|
|
463
|
+
buildBody() {
|
|
464
|
+
if (this.bodyBuilder) {
|
|
465
|
+
const arkBody = this.bodyBuilder.build();
|
|
466
|
+
if (arkBody) {
|
|
467
|
+
this.setBody(arkBody);
|
|
468
|
+
arkBody.getCfg().setDeclaringMethod(this);
|
|
469
|
+
if (this.getOuterMethod() === undefined) {
|
|
470
|
+
this.bodyBuilder.handleGlobalAndClosure();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
isGenerated() {
|
|
476
|
+
return this.isGeneratedFlag;
|
|
477
|
+
}
|
|
478
|
+
setIsGeneratedFlag(isGeneratedFlag) {
|
|
479
|
+
this.isGeneratedFlag = isGeneratedFlag;
|
|
480
|
+
}
|
|
481
|
+
getAsteriskToken() {
|
|
482
|
+
return this.asteriskToken;
|
|
483
|
+
}
|
|
484
|
+
setAsteriskToken(asteriskToken) {
|
|
485
|
+
this.asteriskToken = asteriskToken;
|
|
486
|
+
}
|
|
487
|
+
validate() {
|
|
488
|
+
const declareSignatures = this.getDeclareSignatures();
|
|
489
|
+
const declareLineCols = this.getDeclareLineCols();
|
|
490
|
+
const signature = this.getImplementationSignature();
|
|
491
|
+
const lineCol = this.getLineCol();
|
|
492
|
+
if (declareSignatures === null && signature === null) {
|
|
493
|
+
return {
|
|
494
|
+
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_UNDEFINED,
|
|
495
|
+
errMsg: 'methodDeclareSignatures and methodSignature are both undefined.'
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
if ((declareSignatures === null) !== (declareLineCols === null)) {
|
|
499
|
+
return {
|
|
500
|
+
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
501
|
+
errMsg: 'methodDeclareSignatures and methodDeclareLineCols are not matched.'
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
if (declareSignatures !== null && declareLineCols !== null && declareSignatures.length !== declareLineCols.length) {
|
|
505
|
+
return {
|
|
506
|
+
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
507
|
+
errMsg: 'methodDeclareSignatures and methodDeclareLineCols are not matched.'
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
if ((signature === null) !== (lineCol === null)) {
|
|
511
|
+
return {
|
|
512
|
+
errCode: ArkError_1.ArkErrorCode.METHOD_SIGNATURE_LINE_UNMATCHED,
|
|
513
|
+
errMsg: 'methodSignature and lineCol are not matched.'
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return this.validateFields(['declaringArkClass']);
|
|
517
|
+
}
|
|
518
|
+
matchMethodSignature(args) {
|
|
519
|
+
var _a, _b, _c;
|
|
520
|
+
const signatures = (_a = this.methodDeclareSignatures) === null || _a === void 0 ? void 0 : _a.filter(f => {
|
|
521
|
+
const parameters = f.getMethodSubSignature().getParameters();
|
|
522
|
+
const max = parameters.length;
|
|
523
|
+
let min = 0;
|
|
524
|
+
while (min < max && !parameters[min].isOptional()) {
|
|
525
|
+
min++;
|
|
526
|
+
}
|
|
527
|
+
return args.length >= min && args.length <= max;
|
|
528
|
+
});
|
|
529
|
+
const scene = this.getDeclaringArkFile().getScene();
|
|
530
|
+
return (_c = (_b = signatures === null || signatures === void 0 ? void 0 : signatures.find(p => {
|
|
531
|
+
const parameters = p.getMethodSubSignature().getParameters();
|
|
532
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
533
|
+
if (!args[i]) {
|
|
534
|
+
return parameters[i].isOptional();
|
|
535
|
+
}
|
|
536
|
+
const isMatched = this.matchParam(parameters[i].getType(), args[i], scene);
|
|
537
|
+
if (!isMatched) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return true;
|
|
542
|
+
})) !== null && _b !== void 0 ? _b : signatures === null || signatures === void 0 ? void 0 : signatures[0]) !== null && _c !== void 0 ? _c : this.getSignature();
|
|
543
|
+
}
|
|
544
|
+
matchParam(paramType, arg, scene) {
|
|
545
|
+
var _a;
|
|
546
|
+
const argType = arg.getType();
|
|
547
|
+
if (arg instanceof Local_1.Local) {
|
|
548
|
+
const stmt = arg.getDeclaringStmt();
|
|
549
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Constant_1.Constant) {
|
|
550
|
+
arg = stmt.getRightOp();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (paramType instanceof Type_1.UnionType) {
|
|
554
|
+
let matched = false;
|
|
555
|
+
for (const e of paramType.getTypes()) {
|
|
556
|
+
if (argType.constructor === e.constructor) {
|
|
557
|
+
matched = true;
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return matched;
|
|
562
|
+
}
|
|
563
|
+
else if (argType instanceof Type_1.FunctionType && paramType instanceof Type_1.FunctionType) {
|
|
564
|
+
return argType.getMethodSignature().getParamLength() === paramType.getMethodSignature().getParamLength();
|
|
565
|
+
}
|
|
566
|
+
else if (argType instanceof Type_1.FunctionType && paramType instanceof Type_1.ClassType &&
|
|
567
|
+
paramType.getClassSignature().getClassName().includes(EtsConst_1.CALL_BACK)) {
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
else if (paramType instanceof Type_1.LiteralType && arg instanceof Constant_1.Constant) {
|
|
571
|
+
return arg.getValue().replace(/[\"|\']/g, '') === paramType.getLiteralName()
|
|
572
|
+
.toString().replace(/[\"|\']/g, '');
|
|
573
|
+
}
|
|
574
|
+
else if (paramType instanceof Type_1.NumberType && argType instanceof Type_1.ClassType && ArkClass_1.ClassCategory.ENUM ===
|
|
575
|
+
((_a = scene.getClass(argType.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getCategory())) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
return argType.constructor === paramType.constructor;
|
|
579
|
+
}
|
|
580
|
+
getOuterMethod() {
|
|
581
|
+
return this.outerMethod;
|
|
582
|
+
}
|
|
583
|
+
setOuterMethod(method) {
|
|
584
|
+
this.outerMethod = method;
|
|
585
|
+
}
|
|
586
|
+
getFunctionLocal(name) {
|
|
587
|
+
var _a;
|
|
588
|
+
const local = (_a = this.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
|
|
589
|
+
return (local === null || local === void 0 ? void 0 : local.getType()) instanceof Type_1.FunctionType ? local : null;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
exports.ArkMethod = ArkMethod;
|