arkanalyzer 1.0.94 → 2.0.0-beta1
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 +7 -0
- package/lib/Config.d.ts.map +1 -1
- package/lib/Scene.d.ts +134 -170
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +412 -976
- package/lib/callgraph/algorithm/AbstractAnalysis.js +3 -2
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +1 -1
- package/lib/callgraph/model/CallGraph.js +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +1 -3
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +17 -7
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +4 -14
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +2 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +1 -2
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +0 -1
- package/lib/cli/commands/cg.d.ts +1 -0
- package/lib/cli/commands/cg.d.ts.map +1 -1
- package/lib/cli/commands/cg.js +22 -18
- package/lib/cli/commands/ir.d.ts +1 -0
- package/lib/cli/commands/ir.d.ts.map +1 -1
- package/lib/cli/commands/ir.js +5 -2
- package/lib/core/base/Constant.d.ts +5 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +12 -9
- package/lib/core/base/Expr.d.ts +36 -20
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +206 -94
- package/lib/core/base/Local.d.ts +10 -20
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +25 -28
- package/lib/core/base/Position.d.ts +6 -0
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +37 -11
- package/lib/core/base/Ref.d.ts +45 -33
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +225 -51
- package/lib/core/base/Stmt.d.ts +19 -9
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -52
- package/lib/core/base/Type.d.ts +67 -4
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +391 -20
- package/lib/core/base/TypeExpr.d.ts +6 -4
- package/lib/core/base/TypeExpr.d.ts.map +1 -1
- package/lib/core/base/TypeExpr.js +34 -10
- package/lib/core/base/Value.d.ts +20 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/base/Value.js +12 -0
- package/lib/core/common/ArkIRTransformer.d.ts +18 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +94 -75
- package/lib/core/common/ArkValueTransformer.d.ts +21 -3
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +455 -265
- package/lib/core/common/Builtin.d.ts +48 -24
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +90 -52
- package/lib/core/common/CanonicalizerValidator.d.ts +308 -0
- package/lib/core/common/CanonicalizerValidator.d.ts.map +1 -0
- package/lib/core/common/CanonicalizerValidator.js +888 -0
- package/lib/core/common/Const.d.ts +3 -3
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +3 -3
- package/lib/core/common/DummyMainCreater.d.ts +2 -21
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +8 -105
- package/lib/core/common/IRInference.d.ts +55 -3
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +407 -126
- package/lib/core/common/IRUtils.d.ts +1 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +44 -13
- package/lib/core/common/ModelUtils.d.ts +44 -20
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +378 -208
- package/lib/core/common/SdkUtils.d.ts +35 -5
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +181 -53
- package/lib/core/common/SignatureCanonicalizer.d.ts +95 -0
- package/lib/core/common/SignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizer.js +116 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts +176 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.js +343 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts +69 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureModelCanonicalizer.js +109 -0
- package/lib/core/common/StmtUseReplacer.d.ts +1 -0
- package/lib/core/common/StmtUseReplacer.d.ts.map +1 -1
- package/lib/core/common/StmtUseReplacer.js +9 -0
- package/lib/core/common/StringUtils.d.ts +12 -1
- package/lib/core/common/StringUtils.d.ts.map +1 -1
- package/lib/core/common/StringUtils.js +36 -17
- package/lib/core/common/TempSignatureCanonicalizer.d.ts +82 -0
- package/lib/core/common/TempSignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/TempSignatureCanonicalizer.js +177 -0
- package/lib/core/common/TypeInference.d.ts +24 -6
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +243 -117
- package/lib/core/common/ValueUtil.d.ts +2 -1
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +4 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +21 -6
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +46 -33
- package/lib/core/graph/builder/IfBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/IfBuilder.js +6 -2
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -2
- package/lib/core/inference/ModelInference.d.ts +24 -4
- package/lib/core/inference/ModelInference.d.ts.map +1 -1
- package/lib/core/inference/ModelInference.js +273 -79
- package/lib/core/inference/ValueInference.d.ts +3 -2
- package/lib/core/inference/ValueInference.d.ts.map +1 -1
- package/lib/core/inference/ValueInference.js +90 -40
- package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
- package/lib/core/inference/abc/AbcInference.js +28 -15
- package/lib/core/inference/arkts/ArkTsInference.d.ts +9 -3
- package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
- package/lib/core/inference/arkts/ArkTsInference.js +54 -16
- package/lib/core/model/ArkClass.d.ts +192 -18
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +852 -122
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +1 -2
- package/lib/core/model/ArkField.d.ts +34 -2
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +89 -14
- package/lib/core/model/ArkFile.d.ts +72 -12
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +275 -65
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +1 -2
- package/lib/core/model/ArkMethod.d.ts +101 -15
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +252 -39
- package/lib/core/model/ArkModule.d.ts +1 -1
- package/lib/core/model/ArkModule.js +1 -1
- package/lib/core/model/ArkNamespace.d.ts +80 -10
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +309 -76
- package/lib/core/model/ArkSignature.d.ts +242 -18
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +725 -95
- package/lib/core/model/builder/ArkClassBuilder.d.ts +6 -3
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +116 -71
- package/lib/core/model/builder/ArkExportBuilder.d.ts +1 -1
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +0 -2
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +9 -43
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +32 -33
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +10 -3
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +40 -26
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +3 -2
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +45 -77
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkSignatureBuilder.js +26 -3
- package/lib/core/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +37 -11
- package/lib/core/model/builder/builderUtils.d.ts +11 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +124 -90
- package/lib/frontend/FrontendBuilder.d.ts +10 -6
- package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
- package/lib/frontend/FrontendBuilder.js +19 -45
- package/lib/frontend/ModuleScene.d.ts +43 -0
- package/lib/frontend/ModuleScene.d.ts.map +1 -0
- package/lib/frontend/ModuleScene.js +143 -0
- package/lib/frontend/SceneBuildStage.d.ts +15 -0
- package/lib/frontend/SceneBuildStage.d.ts.map +1 -0
- package/lib/frontend/SceneBuildStage.js +32 -0
- package/lib/frontend/SceneBuilder.d.ts +153 -0
- package/lib/frontend/SceneBuilder.d.ts.map +1 -0
- package/lib/frontend/SceneBuilder.js +859 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +0 -2
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
- package/lib/frontend/arktsFrontend/ArktsFrontend.js +0 -18
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts +17 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts.map +1 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.js +187 -0
- package/lib/frontend/common/ModuleBuilder.d.ts +4 -2
- package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -1
- package/lib/frontend/common/ModuleBuilder.js +19 -9
- package/lib/frontend/cppFrontend/CppFrontend.d.ts +0 -6
- package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/CppFrontend.js +0 -56
- package/lib/frontend/cppFrontend/base/Type.d.ts +7 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/base/Type.js +29 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +56 -56
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +124 -113
- package/lib/frontend/cppFrontend/common/Builtin.d.ts +29 -19
- package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/Builtin.js +56 -35
- package/lib/frontend/cppFrontend/common/IRInference.d.ts +7 -2
- package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRInference.js +61 -28
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.js +22 -10
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +19 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ModelUtils.js +84 -3
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/TypeInference.js +44 -54
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +2 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +1 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.js +41 -5
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +18 -28
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +2 -3
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +2 -2
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +31 -24
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +10 -16
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +0 -2
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +19 -37
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +30 -3
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +8 -4
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -2
- package/lib/save/json/JsonSerialization.js +2 -2
- package/lib/save/source/SourceStmt.js +1 -1
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +0 -9
- package/lib/statistics/StageStatistics.d.ts +195 -0
- package/lib/statistics/StageStatistics.d.ts.map +1 -0
- package/lib/statistics/StageStatistics.js +346 -0
- package/lib/statistics/StageStatisticsReporter.d.ts +58 -0
- package/lib/statistics/StageStatisticsReporter.d.ts.map +1 -0
- package/lib/statistics/StageStatisticsReporter.js +255 -0
- package/lib/utils/Canonicalizer.d.ts +9 -2
- package/lib/utils/Canonicalizer.d.ts.map +1 -1
- package/lib/utils/Canonicalizer.js +19 -2
- package/lib/utils/CxxSceneUtils.d.ts +7 -0
- package/lib/utils/CxxSceneUtils.d.ts.map +1 -1
- package/lib/utils/CxxSceneUtils.js +10 -1
- package/lib/utils/FileUtils.d.ts +0 -1
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +1 -9
- package/lib/utils/HashUtils.d.ts +9 -0
- package/lib/utils/HashUtils.d.ts.map +1 -0
- package/lib/utils/HashUtils.js +65 -0
- package/lib/utils/ModuleUtils.d.ts.map +1 -1
- package/lib/utils/ModuleUtils.js +24 -5
- package/lib/utils/VisitedSegment.d.ts +23 -0
- package/lib/utils/VisitedSegment.d.ts.map +1 -0
- package/lib/utils/VisitedSegment.js +64 -0
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -7
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +11 -8
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +16 -0
- package/lib/utils/parseArkSourceFile.d.ts +33 -0
- package/lib/utils/parseArkSourceFile.d.ts.map +1 -0
- package/lib/utils/parseArkSourceFile.js +131 -0
- package/package.json +1 -1
- package/lib/utils/DependenciesSort.d.ts +0 -3
- package/lib/utils/DependenciesSort.d.ts.map +0 -1
- package/lib/utils/DependenciesSort.js +0 -72
- package/lib/utils/crypto_utils.d.ts +0 -6
- package/lib/utils/crypto_utils.d.ts.map +0 -1
- package/lib/utils/crypto_utils.js +0 -57
|
@@ -44,7 +44,6 @@ const Local_1 = require("../base/Local");
|
|
|
44
44
|
const Ref_1 = require("../base/Ref");
|
|
45
45
|
const Stmt_1 = require("../base/Stmt");
|
|
46
46
|
const Type_1 = require("../base/Type");
|
|
47
|
-
const Type_2 = require("../../frontend/cppFrontend/base/Type");
|
|
48
47
|
const ArkMethod_1 = require("../model/ArkMethod");
|
|
49
48
|
const ArkClass_1 = require("../model/ArkClass");
|
|
50
49
|
const ArkField_1 = require("../model/ArkField");
|
|
@@ -61,8 +60,25 @@ const IRInference_1 = require("./IRInference");
|
|
|
61
60
|
const TypeExpr_1 = require("../base/TypeExpr");
|
|
62
61
|
const SdkUtils_1 = require("./SdkUtils");
|
|
63
62
|
const ArkBaseModel_1 = require("../model/ArkBaseModel");
|
|
63
|
+
const SignatureCanonicalizerRegistry_1 = require("./SignatureCanonicalizerRegistry");
|
|
64
|
+
const SignatureCanonicalizer_1 = require("./SignatureCanonicalizer");
|
|
64
65
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'TypeInference');
|
|
65
|
-
const
|
|
66
|
+
const resolveUsesScratch = [null];
|
|
67
|
+
const inferVisited = new Type_1.ArrayUnclearVisited();
|
|
68
|
+
// Builtin stub signatures carry FileSignature.DEFAULT whose fileName is UNKNOWN_FILE_NAME,
|
|
69
|
+
// so a single entry covers both unresolved references and builtin stubs.
|
|
70
|
+
const unknownFileName = [Const_1.UNKNOWN_FILE_NAME];
|
|
71
|
+
const IS_ANY = (t) => t instanceof Type_1.AnyType;
|
|
72
|
+
const IS_UNCLEAR_REF_OR_GENERIC = (t) => t instanceof Type_1.UnclearReferenceType || t instanceof Type_1.GenericType;
|
|
73
|
+
const CAN_RECURSE = (t) => t instanceof Type_1.ClassType ||
|
|
74
|
+
t instanceof Type_1.FunctionType ||
|
|
75
|
+
t instanceof Type_1.UnionType ||
|
|
76
|
+
t instanceof Type_1.IntersectionType ||
|
|
77
|
+
t instanceof Type_1.TupleType ||
|
|
78
|
+
t instanceof Type_1.ArrayType ||
|
|
79
|
+
t instanceof Type_1.AliasType ||
|
|
80
|
+
t instanceof TypeExpr_1.KeyofTypeExpr ||
|
|
81
|
+
t instanceof TypeExpr_1.TypeQueryExpr;
|
|
66
82
|
class TypeInference {
|
|
67
83
|
static inferTypeInArkField(arkField) {
|
|
68
84
|
var _a, _b;
|
|
@@ -93,11 +109,11 @@ class TypeInference {
|
|
|
93
109
|
}
|
|
94
110
|
if (fieldType) {
|
|
95
111
|
arkField.getSignature().setType(fieldType);
|
|
96
|
-
fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.
|
|
112
|
+
fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.graduateToFormal(arkField.getFieldSigID());
|
|
97
113
|
}
|
|
98
114
|
else if (rightType && this.isUnclearType(beforeType) && !this.isUnclearType(rightType)) {
|
|
99
115
|
arkField.getSignature().setType(rightType);
|
|
100
|
-
fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.
|
|
116
|
+
fieldRef === null || fieldRef === void 0 ? void 0 : fieldRef.graduateToFormal(arkField.getFieldSigID());
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
/**
|
|
@@ -108,9 +124,23 @@ class TypeInference {
|
|
|
108
124
|
* @param leftOpType
|
|
109
125
|
* @param declaringArkClass
|
|
110
126
|
* @param visited
|
|
127
|
+
* @param arkMethod - optional; propagated to unclear-name resolution so classes declared
|
|
128
|
+
* inside the method scope chain resolve deterministically (local-class lookup).
|
|
111
129
|
* @returns
|
|
112
130
|
*/
|
|
113
|
-
static inferUnclearedType(leftOpType, declaringArkClass, visited
|
|
131
|
+
static inferUnclearedType(leftOpType, declaringArkClass, visited, arkMethod) {
|
|
132
|
+
if (visited !== undefined) {
|
|
133
|
+
return this.inferUnclearedTypeWithVisited(leftOpType, declaringArkClass, visited, arkMethod);
|
|
134
|
+
}
|
|
135
|
+
const prevBase = inferVisited.enter();
|
|
136
|
+
try {
|
|
137
|
+
return this.inferUnclearedTypeWithVisited(leftOpType, declaringArkClass, inferVisited, arkMethod);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
inferVisited.leave(prevBase);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
static inferUnclearedTypeWithVisited(leftOpType, declaringArkClass, visited, arkMethod) {
|
|
114
144
|
if (visited.has(leftOpType)) {
|
|
115
145
|
return leftOpType;
|
|
116
146
|
}
|
|
@@ -121,7 +151,7 @@ class TypeInference {
|
|
|
121
151
|
if (leftOpType instanceof Type_1.ClassType && unknownFileName.includes(leftOpType.getClassSignature().getDeclaringFileSignature().getFileName())) {
|
|
122
152
|
const realTypes = leftOpType.getRealGenericTypes();
|
|
123
153
|
this.inferRealGenericTypes(realTypes, declaringArkClass);
|
|
124
|
-
let newType = TypeInference.inferUnclearRefName(leftOpType.getClassSignature().getClassName(), declaringArkClass);
|
|
154
|
+
let newType = TypeInference.inferUnclearRefName(leftOpType.getClassSignature().getClassName(), declaringArkClass, arkMethod);
|
|
125
155
|
type = newType ? this.replaceTypeWithReal(newType, realTypes) : null;
|
|
126
156
|
}
|
|
127
157
|
else if (leftOpType instanceof TypeExpr_1.TypeQueryExpr) {
|
|
@@ -140,20 +170,20 @@ class TypeInference {
|
|
|
140
170
|
type = this.inferBaseType(leftOpType.getOriginType(), declaringArkClass);
|
|
141
171
|
}
|
|
142
172
|
else if (leftOpType instanceof Type_1.UnclearReferenceType) {
|
|
143
|
-
type = this.inferUnclearRefType(leftOpType, declaringArkClass);
|
|
173
|
+
type = this.inferUnclearRefType(leftOpType, declaringArkClass, arkMethod);
|
|
144
174
|
}
|
|
145
175
|
if (type) {
|
|
146
176
|
return type;
|
|
147
177
|
}
|
|
148
|
-
return TypeInference.inferUnclearComplexType(leftOpType, declaringArkClass, visited);
|
|
178
|
+
return TypeInference.inferUnclearComplexType(leftOpType, declaringArkClass, visited, arkMethod);
|
|
149
179
|
}
|
|
150
|
-
static inferUnclearComplexType(leftOpType, declaringArkClass, visited) {
|
|
151
|
-
|
|
180
|
+
static inferUnclearComplexType(leftOpType, declaringArkClass, visited, arkMethod) {
|
|
181
|
+
const registry = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
152
182
|
let type;
|
|
153
183
|
if (leftOpType instanceof Type_1.UnionType || leftOpType instanceof Type_1.IntersectionType || leftOpType instanceof Type_1.TupleType) {
|
|
154
184
|
let types = leftOpType.getTypes();
|
|
155
185
|
for (let i = 0; i < types.length; i++) {
|
|
156
|
-
let newType = this.inferUnclearedType(types[i], declaringArkClass, visited);
|
|
186
|
+
let newType = this.inferUnclearedType(types[i], declaringArkClass, visited, arkMethod);
|
|
157
187
|
if (newType) {
|
|
158
188
|
types[i] = newType;
|
|
159
189
|
}
|
|
@@ -161,22 +191,23 @@ class TypeInference {
|
|
|
161
191
|
type = leftOpType;
|
|
162
192
|
}
|
|
163
193
|
else if (leftOpType instanceof Type_1.ArrayType) {
|
|
164
|
-
let baseType = this.inferUnclearedType(leftOpType.getBaseType(), declaringArkClass, visited);
|
|
194
|
+
let baseType = this.inferUnclearedType(leftOpType.getBaseType(), declaringArkClass, visited, arkMethod);
|
|
165
195
|
if (baseType) {
|
|
166
196
|
leftOpType.setBaseType(baseType);
|
|
167
197
|
type = leftOpType;
|
|
168
198
|
}
|
|
169
199
|
}
|
|
170
200
|
else if (leftOpType instanceof Type_1.AliasType) {
|
|
171
|
-
const
|
|
172
|
-
|
|
201
|
+
const defArkMethod = registry.getMethodBySig(leftOpType.getSignature().getDeclaringMethodSignature());
|
|
202
|
+
const defArkClass = defArkMethod === null || defArkMethod === void 0 ? void 0 : defArkMethod.getDeclaringArkClass();
|
|
203
|
+
let baseType = this.inferUnclearedType(leftOpType.getOriginalType(), defArkClass !== null && defArkClass !== void 0 ? defArkClass : declaringArkClass, visited, defArkMethod);
|
|
173
204
|
if (baseType) {
|
|
174
205
|
leftOpType.setOriginalType(baseType);
|
|
175
206
|
type = leftOpType;
|
|
176
207
|
}
|
|
177
208
|
}
|
|
178
209
|
else if (leftOpType instanceof TypeExpr_1.KeyofTypeExpr) {
|
|
179
|
-
let baseType = this.inferUnclearedType(leftOpType.getOpType(), declaringArkClass, visited);
|
|
210
|
+
let baseType = this.inferUnclearedType(leftOpType.getOpType(), declaringArkClass, visited, arkMethod);
|
|
180
211
|
if (baseType) {
|
|
181
212
|
leftOpType.setOpType(baseType);
|
|
182
213
|
type = leftOpType;
|
|
@@ -210,7 +241,10 @@ class TypeInference {
|
|
|
210
241
|
if (value instanceof Ref_1.GlobalRef && !value.getRef()) {
|
|
211
242
|
const arkExport = ModelUtils_1.ModelUtils.findGlobalRef(key, arkMethod);
|
|
212
243
|
if (arkExport instanceof Local_1.Local) {
|
|
213
|
-
|
|
244
|
+
const usedStmts = value.getUsedStmts();
|
|
245
|
+
for (let i = 0; i < usedStmts.length; i++) {
|
|
246
|
+
arkExport.addUsedStmt(usedStmts[i]);
|
|
247
|
+
}
|
|
214
248
|
value.setRef(arkExport);
|
|
215
249
|
}
|
|
216
250
|
}
|
|
@@ -232,7 +266,9 @@ class TypeInference {
|
|
|
232
266
|
this.resolveArkReturnStmt(stmt, arkMethod);
|
|
233
267
|
}
|
|
234
268
|
catch (e) {
|
|
235
|
-
|
|
269
|
+
if (logger_1.default.isWarnEnabled(logger)) {
|
|
270
|
+
logger.warn('stmt is not correct: ' + stmt.toString());
|
|
271
|
+
}
|
|
236
272
|
}
|
|
237
273
|
}
|
|
238
274
|
/**
|
|
@@ -261,21 +297,12 @@ class TypeInference {
|
|
|
261
297
|
* such as ArkInstanceInvokeExpr ArkStaticInvokeExpr ArkNewExpr
|
|
262
298
|
*/
|
|
263
299
|
static resolveExprsInStmt(stmt, arkMethod) {
|
|
264
|
-
var _a;
|
|
265
300
|
for (const expr of stmt.getExprs()) {
|
|
266
301
|
const newExpr = expr.inferType(arkMethod);
|
|
267
302
|
if (stmt.containsInvokeExpr() &&
|
|
268
303
|
((expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) || newExpr instanceof Expr_1.ArkPtrInvokeExpr)) {
|
|
269
304
|
stmt.replaceUse(expr, newExpr);
|
|
270
305
|
}
|
|
271
|
-
// After infer the invoke method, it should replace the super.foo() to this.foo() while the foo is with super class as declaring class.
|
|
272
|
-
if (newExpr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr.getBase().getName() === TSConst_1.SUPER_NAME) {
|
|
273
|
-
const thisLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(TSConst_1.THIS_NAME);
|
|
274
|
-
if (thisLocal) {
|
|
275
|
-
newExpr.setBase(thisLocal);
|
|
276
|
-
thisLocal.addUsedStmt(stmt);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
306
|
}
|
|
280
307
|
if (stmt instanceof Stmt_1.ArkAliasTypeDefineStmt && this.isUnclearType(stmt.getAliasType().getOriginalType())) {
|
|
281
308
|
stmt.getAliasType().setOriginalType(stmt.getAliasTypeExpr().getType());
|
|
@@ -293,7 +320,12 @@ class TypeInference {
|
|
|
293
320
|
* infer type for fieldRefs in stmt.
|
|
294
321
|
*/
|
|
295
322
|
static resolveFieldRefsInStmt(stmt, arkMethod) {
|
|
296
|
-
|
|
323
|
+
while (resolveUsesScratch.length > 1) {
|
|
324
|
+
resolveUsesScratch.pop();
|
|
325
|
+
}
|
|
326
|
+
stmt.getUses(resolveUsesScratch);
|
|
327
|
+
for (let i = 1; i < resolveUsesScratch.length; i++) {
|
|
328
|
+
const use = resolveUsesScratch[i];
|
|
297
329
|
if (use instanceof Ref_1.AbstractRef) {
|
|
298
330
|
this.processRef(use, stmt, arkMethod);
|
|
299
331
|
}
|
|
@@ -394,7 +426,7 @@ class TypeInference {
|
|
|
394
426
|
}
|
|
395
427
|
let rightType = rightOp.getType();
|
|
396
428
|
if (this.isUnclearType(rightType)) {
|
|
397
|
-
rightType = this.inferUnclearedType(rightType, arkClass);
|
|
429
|
+
rightType = this.inferUnclearedType(rightType, arkClass, new Set(), arkMethod);
|
|
398
430
|
if (rightType) {
|
|
399
431
|
this.setValueType(rightOp, rightType);
|
|
400
432
|
}
|
|
@@ -427,7 +459,7 @@ class TypeInference {
|
|
|
427
459
|
const leftOp = stmt.getLeftOp();
|
|
428
460
|
let leftType = leftOp.getType();
|
|
429
461
|
if (this.isUnclearType(leftType)) {
|
|
430
|
-
const newLeftType = this.inferUnclearedType(leftType, arkClass);
|
|
462
|
+
const newLeftType = this.inferUnclearedType(leftType, arkClass, new Set(), arkMethod);
|
|
431
463
|
if (!newLeftType && !this.isUnclearType(rightType)) {
|
|
432
464
|
leftType = rightType;
|
|
433
465
|
}
|
|
@@ -444,7 +476,8 @@ class TypeInference {
|
|
|
444
476
|
leftType = rightType;
|
|
445
477
|
}
|
|
446
478
|
}
|
|
447
|
-
else if (leftType instanceof Type_1.FunctionType &&
|
|
479
|
+
else if (leftType instanceof Type_1.FunctionType &&
|
|
480
|
+
!this.isUnclearType(rightType) &&
|
|
448
481
|
leftType.getMethodSignature().getMethodSubSignature().getMethodName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX)) {
|
|
449
482
|
leftType = rightType;
|
|
450
483
|
}
|
|
@@ -459,56 +492,56 @@ class TypeInference {
|
|
|
459
492
|
}
|
|
460
493
|
}
|
|
461
494
|
static isUnclearType(type) {
|
|
462
|
-
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
|
|
474
|
-
return !!type.getTypes().find(t => this.checkType(t, e => e instanceof Type_1.UnclearReferenceType || e instanceof Type_1.GenericType));
|
|
495
|
+
// Thin delegate to the polymorphic Type.isUnclear() (each subclass owns its own criteria).
|
|
496
|
+
// Null/undefined inputs stay unclear.
|
|
497
|
+
return type === null || type === undefined ? true : type.isUnclear();
|
|
498
|
+
}
|
|
499
|
+
// This is the temporal function to check Type recursively and can be removed after typeInfer supports multiple candidate types.
|
|
500
|
+
static checkType(type, check, visited) {
|
|
501
|
+
if (visited !== undefined) {
|
|
502
|
+
if (visited.has(type)) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
visited.add(type);
|
|
475
506
|
}
|
|
476
|
-
else if (type
|
|
477
|
-
|
|
478
|
-
return this.checkType(baseType, t => t instanceof Type_1.UnclearReferenceType || baseType instanceof Type_1.GenericType);
|
|
507
|
+
else if (!CAN_RECURSE(type)) {
|
|
508
|
+
return check(type);
|
|
479
509
|
}
|
|
480
|
-
|
|
481
|
-
return
|
|
510
|
+
if (check(type)) {
|
|
511
|
+
return true;
|
|
482
512
|
}
|
|
483
|
-
|
|
484
|
-
return this.
|
|
513
|
+
if (visited !== undefined) {
|
|
514
|
+
return this.checkTypeRecursion(type, check, visited);
|
|
485
515
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
516
|
+
const prevBase = inferVisited.enter();
|
|
517
|
+
inferVisited.add(type);
|
|
518
|
+
try {
|
|
519
|
+
return this.checkTypeRecursion(type, check, inferVisited);
|
|
489
520
|
}
|
|
490
|
-
|
|
491
|
-
|
|
521
|
+
finally {
|
|
522
|
+
inferVisited.leave(prevBase);
|
|
492
523
|
}
|
|
493
|
-
return false;
|
|
494
524
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
525
|
+
static checkTypeRecursion(type, check, visited) {
|
|
526
|
+
if (type instanceof Type_1.ClassType || type instanceof Type_1.FunctionType) {
|
|
527
|
+
const realGenericTypes = type.getRealGenericTypes();
|
|
528
|
+
if (realGenericTypes !== undefined) {
|
|
529
|
+
for (let i = 0; i < realGenericTypes.length; i++) {
|
|
530
|
+
if (this.checkType(realGenericTypes[i], check, visited)) {
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
499
535
|
return false;
|
|
500
536
|
}
|
|
501
|
-
else {
|
|
502
|
-
visited.add(type);
|
|
503
|
-
}
|
|
504
|
-
if (check(type)) {
|
|
505
|
-
return true;
|
|
506
|
-
}
|
|
507
|
-
else if (type instanceof Type_1.ClassType || type instanceof Type_1.FunctionType) {
|
|
508
|
-
return !!((_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => this.checkType(t, check, visited)));
|
|
509
|
-
}
|
|
510
537
|
else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
|
|
511
|
-
|
|
538
|
+
const types = type.getTypes();
|
|
539
|
+
for (let i = 0; i < types.length; i++) {
|
|
540
|
+
if (this.checkType(types[i], check, visited)) {
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return false;
|
|
512
545
|
}
|
|
513
546
|
else if (type instanceof Type_1.ArrayType) {
|
|
514
547
|
return this.checkType(type.getBaseType(), check, visited);
|
|
@@ -636,9 +669,9 @@ class TypeInference {
|
|
|
636
669
|
returnType = Type_1.VoidType.getInstance();
|
|
637
670
|
}
|
|
638
671
|
// If the method is async and the return type is not Promise, wrap it with Promise
|
|
639
|
-
if (arkMethod.containsModifier(ArkBaseModel_1.ModifierType.ASYNC) &&
|
|
640
|
-
returnType.getClassSignature().getClassName() !== TSConst_1.PROMISE)) {
|
|
641
|
-
const promise =
|
|
672
|
+
if (arkMethod.containsModifier(ArkBaseModel_1.ModifierType.ASYNC) &&
|
|
673
|
+
(!(returnType instanceof Type_1.ClassType) || returnType.getClassSignature().getClassName() !== TSConst_1.PROMISE)) {
|
|
674
|
+
const promise = SdkUtils_1.SdkUtils.getSdkGlobal(TSConst_1.PROMISE);
|
|
642
675
|
if (promise instanceof ArkClass_1.ArkClass) {
|
|
643
676
|
return new Type_1.ClassType(promise.getSignature(), [returnType]);
|
|
644
677
|
}
|
|
@@ -671,13 +704,13 @@ class TypeInference {
|
|
|
671
704
|
* @param arkClass
|
|
672
705
|
* @returns
|
|
673
706
|
*/
|
|
674
|
-
static inferUnclearRefType(urType, arkClass) {
|
|
707
|
+
static inferUnclearRefType(urType, arkClass, arkMethod) {
|
|
675
708
|
const realTypes = urType.getGenericTypes();
|
|
676
709
|
this.inferRealGenericTypes(realTypes, arkClass);
|
|
677
710
|
if (urType.getName() === Builtin_1.Builtin.ARRAY && realTypes.length > 0) {
|
|
678
711
|
return new Type_1.ArrayType(realTypes[0], 1);
|
|
679
712
|
}
|
|
680
|
-
const type = this.inferUnclearRefName(urType.getName(), arkClass);
|
|
713
|
+
const type = this.inferUnclearRefName(urType.getName(), arkClass, arkMethod);
|
|
681
714
|
return type ? this.replaceTypeWithReal(type, realTypes) : null;
|
|
682
715
|
}
|
|
683
716
|
/**
|
|
@@ -686,24 +719,37 @@ class TypeInference {
|
|
|
686
719
|
* The original type is null if it failed to infer the type.
|
|
687
720
|
* @param refName
|
|
688
721
|
* @param arkClass
|
|
722
|
+
* @param arkMethod - optional; when provided, classes declared inside the method
|
|
723
|
+
* scope chain are resolved first (deterministic local-class lookup) before
|
|
724
|
+
* the generic file-level name search.
|
|
689
725
|
* @returns
|
|
690
726
|
*/
|
|
691
|
-
static inferUnclearRefName(refName, arkClass) {
|
|
727
|
+
static inferUnclearRefName(refName, arkClass, arkMethod) {
|
|
692
728
|
var _a;
|
|
693
729
|
if (!refName) {
|
|
694
730
|
return null;
|
|
695
731
|
}
|
|
732
|
+
if (refName.indexOf('.') < 0 && refName.indexOf(':') < 0 && refName.indexOf('-') < 0 && refName.indexOf('<') < 0) {
|
|
733
|
+
return this.inferFirstNameType(refName, false, arkClass, arkMethod);
|
|
734
|
+
}
|
|
696
735
|
//split and iterate to infer each type. In C++, the operators used to access members also include :: and ->
|
|
697
|
-
const singleNames = refName.split(/\.|::|->/);
|
|
736
|
+
const singleNames = refName.indexOf(':') < 0 && refName.indexOf('-') < 0 ? refName.split('.') : refName.split(/\.|::|->/);
|
|
698
737
|
let type = null;
|
|
699
738
|
for (let i = 0; i < singleNames.length; i++) {
|
|
739
|
+
const singleName = singleNames[i];
|
|
700
740
|
let genericName = ValueUtil_1.EMPTY_STRING;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
741
|
+
let name;
|
|
742
|
+
const openIdx = singleName.indexOf('<');
|
|
743
|
+
const closeIdx = singleName.lastIndexOf('>');
|
|
744
|
+
if (openIdx >= 0 && closeIdx - openIdx >= 2) {
|
|
745
|
+
name = singleName.slice(0, openIdx) + singleName.slice(closeIdx + 1);
|
|
746
|
+
genericName = singleName.slice(openIdx + 1, closeIdx);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
name = singleName;
|
|
750
|
+
}
|
|
705
751
|
if (i === 0) {
|
|
706
|
-
type = singleNames.length > 1
|
|
752
|
+
type = this.inferFirstNameType(name, singleNames.length > 1, arkClass, arkMethod);
|
|
707
753
|
}
|
|
708
754
|
else if (type) {
|
|
709
755
|
type = (_a = this.inferFieldType(type, name, arkClass)) === null || _a === void 0 ? void 0 : _a[1];
|
|
@@ -713,7 +759,7 @@ class TypeInference {
|
|
|
713
759
|
}
|
|
714
760
|
if (genericName) {
|
|
715
761
|
const realTypes = genericName.split(',').map(generic => {
|
|
716
|
-
const realType = this.inferUnclearRefName(generic, arkClass);
|
|
762
|
+
const realType = this.inferUnclearRefName(generic, arkClass, arkMethod);
|
|
717
763
|
return realType !== null && realType !== void 0 ? realType : new Type_1.UnclearReferenceType(generic);
|
|
718
764
|
});
|
|
719
765
|
if (type instanceof Type_1.ClassType) {
|
|
@@ -726,6 +772,18 @@ class TypeInference {
|
|
|
726
772
|
}
|
|
727
773
|
return type;
|
|
728
774
|
}
|
|
775
|
+
/** 首段名解析:方法作用域链局部类优先(确定性查找),未命中回落限定名/单名的通用解析。 */
|
|
776
|
+
static inferFirstNameType(name, isQualifiedName, arkClass, arkMethod) {
|
|
777
|
+
if (arkMethod) {
|
|
778
|
+
// Local-class references resolve deterministically along the method
|
|
779
|
+
// scope chain before falling back to the file-level name search.
|
|
780
|
+
const localClass = ModelUtils_1.ModelUtils.findLocalClassInMethodChain(name, arkMethod);
|
|
781
|
+
if (localClass) {
|
|
782
|
+
return new Type_1.ClassType(localClass.getSignature());
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return isQualifiedName ? this.inferBaseType(name, arkClass) : this.inferTypeByName(name, arkClass);
|
|
786
|
+
}
|
|
729
787
|
/**
|
|
730
788
|
* Find out the original object and type for a given base type and the field name.
|
|
731
789
|
* It returns an array with 2 items, original object and original type.
|
|
@@ -737,6 +795,7 @@ class TypeInference {
|
|
|
737
795
|
* @returns
|
|
738
796
|
*/
|
|
739
797
|
static inferFieldType(baseType, fieldName, declareClass) {
|
|
798
|
+
const registry = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
740
799
|
if (baseType instanceof Type_1.AliasType) {
|
|
741
800
|
baseType = baseType.getOriginalType();
|
|
742
801
|
}
|
|
@@ -746,7 +805,8 @@ class TypeInference {
|
|
|
746
805
|
let propertyAndType = null;
|
|
747
806
|
if (baseType instanceof Type_1.ClassType) {
|
|
748
807
|
if (fieldName === Builtin_1.Builtin.ITERATOR_RESULT_VALUE &&
|
|
749
|
-
baseType.
|
|
808
|
+
baseType.getClassSigID() === -1 &&
|
|
809
|
+
baseType.getClassSignature().getClassName() === Builtin_1.Builtin.ITERATOR_RESULT) {
|
|
750
810
|
const types = baseType.getRealGenericTypes();
|
|
751
811
|
if (types && types.length > 0) {
|
|
752
812
|
return [null, types[0]];
|
|
@@ -759,9 +819,10 @@ class TypeInference {
|
|
|
759
819
|
propertyAndType = this.inferArrayFieldType(declareClass, fieldName);
|
|
760
820
|
}
|
|
761
821
|
else if (baseType instanceof Type_1.AnnotationNamespaceType) {
|
|
762
|
-
const namespace =
|
|
822
|
+
const namespace = registry.getNamespaceBySig(baseType.getNamespaceSignature());
|
|
763
823
|
if (namespace) {
|
|
764
|
-
|
|
824
|
+
// 多实体探测:跨文件同名 ns(Intl 系)的后续文件实体持有该文件声明的成员
|
|
825
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInNamespaces(fieldName, namespace);
|
|
765
826
|
const propertyType = this.parseArkExport2Type(property);
|
|
766
827
|
if (propertyType) {
|
|
767
828
|
propertyAndType = [property, propertyType];
|
|
@@ -769,23 +830,53 @@ class TypeInference {
|
|
|
769
830
|
}
|
|
770
831
|
}
|
|
771
832
|
else {
|
|
772
|
-
|
|
833
|
+
if (logger_1.default.isWarnEnabled(logger)) {
|
|
834
|
+
logger.warn('infer unclear reference type fail: ' + fieldName);
|
|
835
|
+
}
|
|
773
836
|
}
|
|
774
837
|
return propertyAndType;
|
|
775
838
|
}
|
|
776
839
|
static inferClassFieldType(declareClass, baseType, fieldName) {
|
|
777
|
-
const
|
|
840
|
+
const registry = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
841
|
+
const arkClass = registry.getClassBySig(baseType.getClassSignature());
|
|
778
842
|
if (!arkClass) {
|
|
779
843
|
return null;
|
|
780
844
|
}
|
|
781
|
-
|
|
845
|
+
let property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arkClass);
|
|
846
|
+
let ownerClass = arkClass;
|
|
847
|
+
if (!property) {
|
|
848
|
+
// 多实体探测:字段在同名其他全局实体(跨文件 interface 增补 / var 构造器
|
|
849
|
+
// 侧类)上时逐实体查找——命中者签名自然归属真实声明类(等价旧 copyMembers
|
|
850
|
+
// 合并的成员可见性,但成员物理留在声明类)。
|
|
851
|
+
for (const e of SdkUtils_1.SdkUtils.getSdkGlobalMemberClasses(arkClass.getName())) {
|
|
852
|
+
if (e === arkClass) {
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, e);
|
|
856
|
+
if (property) {
|
|
857
|
+
ownerClass = e;
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
// ns 兄弟类探测:跨文件同名 namespace(Intl 系)中,后续文件的同名类持有
|
|
863
|
+
// 该文件声明的成员(等价旧 copyNamespace 互拷的可见性)。
|
|
864
|
+
if (!property) {
|
|
865
|
+
for (const sibling of SdkUtils_1.SdkUtils.getNamespacedSiblingClasses(arkClass)) {
|
|
866
|
+
property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, sibling);
|
|
867
|
+
if (property) {
|
|
868
|
+
ownerClass = sibling;
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
782
873
|
let propertyType = null;
|
|
783
874
|
if (property instanceof ArkField_1.ArkField) {
|
|
784
|
-
if (
|
|
875
|
+
if (ownerClass.getCategory() === ArkClass_1.ClassCategory.ENUM) {
|
|
785
876
|
propertyType = this.getEnumValueType(property);
|
|
786
877
|
}
|
|
787
878
|
else {
|
|
788
|
-
this.repairFieldType(property,
|
|
879
|
+
this.repairFieldType(property, ownerClass);
|
|
789
880
|
propertyType = this.replaceTypeWithReal(property.getType(), baseType.getRealGenericTypes());
|
|
790
881
|
}
|
|
791
882
|
}
|
|
@@ -830,7 +921,7 @@ class TypeInference {
|
|
|
830
921
|
return enumValueType;
|
|
831
922
|
}
|
|
832
923
|
static inferArrayFieldType(declareClass, fieldName) {
|
|
833
|
-
const arrayClass =
|
|
924
|
+
const arrayClass = SdkUtils_1.SdkUtils.getSdkGlobal(Builtin_1.Builtin.ARRAY);
|
|
834
925
|
if (arrayClass instanceof ArkClass_1.ArkClass) {
|
|
835
926
|
const property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arrayClass);
|
|
836
927
|
if (property instanceof ArkField_1.ArkField) {
|
|
@@ -858,10 +949,46 @@ class TypeInference {
|
|
|
858
949
|
}
|
|
859
950
|
let arkExport = (_b = ModelUtils_1.ModelUtils.findSymbolInFileWithName(baseName, arkClass)) !== null && _b !== void 0 ? _b : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
|
|
860
951
|
if (!arkExport && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
|
|
861
|
-
arkExport =
|
|
952
|
+
arkExport = SdkUtils_1.SdkUtils.getSdkGlobal(baseName);
|
|
862
953
|
}
|
|
863
954
|
return this.parseArkExport2Type(arkExport);
|
|
864
955
|
}
|
|
956
|
+
/**
|
|
957
|
+
* Multi-candidate variant of {@link inferBaseType}: expands the SDK-global tier
|
|
958
|
+
* into ALL entities registered under the name (same-name multi-declaration, e.g.
|
|
959
|
+
* `interface Object` + `declare var Object: ObjectConstructor`, or an interface
|
|
960
|
+
* augmented across lib.es20XX files). Member resolution should probe each
|
|
961
|
+
* candidate until a member is found — the hit entity's signature carries the
|
|
962
|
+
* real declaring file. The file-local / import tiers stay single-valued (they
|
|
963
|
+
* resolve to one symbol by scope semantics).
|
|
964
|
+
*/
|
|
965
|
+
static inferBaseTypes(baseName, arkClass) {
|
|
966
|
+
var _a, _b;
|
|
967
|
+
if (TSConst_1.SUPER_NAME === baseName) {
|
|
968
|
+
const t = this.parseArkExport2Type(arkClass.getSuperClass());
|
|
969
|
+
return t ? [t] : [];
|
|
970
|
+
}
|
|
971
|
+
else if (TSConst_1.DEFAULT === baseName) {
|
|
972
|
+
const t = this.parseArkExport2Type((_a = arkClass.getDeclaringArkFile().getExportInfoBy(TSConst_1.DEFAULT)) === null || _a === void 0 ? void 0 : _a.getArkExport());
|
|
973
|
+
return t ? [t] : [];
|
|
974
|
+
}
|
|
975
|
+
let arkExport = (_b = ModelUtils_1.ModelUtils.findSymbolInFileWithName(baseName, arkClass)) !== null && _b !== void 0 ? _b : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
|
|
976
|
+
if (arkExport) {
|
|
977
|
+
const t = this.parseArkExport2Type(arkExport);
|
|
978
|
+
return t ? [t] : [];
|
|
979
|
+
}
|
|
980
|
+
if (arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
|
|
981
|
+
return [];
|
|
982
|
+
}
|
|
983
|
+
const types = [];
|
|
984
|
+
for (const entity of SdkUtils_1.SdkUtils.getSdkGlobals(baseName)) {
|
|
985
|
+
const t = this.parseArkExport2Type(entity);
|
|
986
|
+
if (t) {
|
|
987
|
+
types.push(t);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return types;
|
|
991
|
+
}
|
|
865
992
|
static inferTypeByName(typeName, arkClass) {
|
|
866
993
|
var _a, _b;
|
|
867
994
|
//look up from declared file, if not found then from imports
|
|
@@ -870,7 +997,7 @@ class TypeInference {
|
|
|
870
997
|
//if not found or local in built-in then look up global in sdks
|
|
871
998
|
if ((!arkExport || (arkExport instanceof Local_1.Local && declaredArkFile.getProjectName() === SdkUtils_1.SdkUtils.BUILT_IN_NAME)) &&
|
|
872
999
|
!declaredArkFile.getImportInfoBy(typeName)) {
|
|
873
|
-
const globalVal =
|
|
1000
|
+
const globalVal = SdkUtils_1.SdkUtils.getSdkGlobal(typeName);
|
|
874
1001
|
if (globalVal) {
|
|
875
1002
|
arkExport = globalVal;
|
|
876
1003
|
}
|
|
@@ -882,7 +1009,7 @@ class TypeInference {
|
|
|
882
1009
|
return ((_b = arkClass.getGenericsTypes()) === null || _b === void 0 ? void 0 : _b.find(g => g.getName() === typeName)) || null;
|
|
883
1010
|
}
|
|
884
1011
|
static getTypeByGlobalName(globalName, arkMethod) {
|
|
885
|
-
const arkExport =
|
|
1012
|
+
const arkExport = SdkUtils_1.SdkUtils.getSdkGlobal(globalName);
|
|
886
1013
|
return this.parseArkExport2Type(arkExport);
|
|
887
1014
|
}
|
|
888
1015
|
static inferRealGenericTypes(realTypes, arkClass) {
|
|
@@ -908,12 +1035,12 @@ class TypeInference {
|
|
|
908
1035
|
importInfo.setDeclaringArkFile(arkClass.getDeclaringArkFile());
|
|
909
1036
|
return TypeInference.parseArkExport2Type((_a = importInfo.getLazyExportInfo()) === null || _a === void 0 ? void 0 : _a.getArkExport());
|
|
910
1037
|
}
|
|
911
|
-
static replaceTypeWithReal(type, realTypes, visited
|
|
1038
|
+
static replaceTypeWithReal(type, realTypes, visited) {
|
|
912
1039
|
var _a, _b;
|
|
913
|
-
if (visited
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1040
|
+
if (visited !== undefined) {
|
|
1041
|
+
if (visited.has(type)) {
|
|
1042
|
+
return type;
|
|
1043
|
+
}
|
|
917
1044
|
visited.add(type);
|
|
918
1045
|
}
|
|
919
1046
|
if (type instanceof Type_1.GenericType) {
|
|
@@ -924,7 +1051,9 @@ class TypeInference {
|
|
|
924
1051
|
const realType = realTypes === null || realTypes === void 0 ? void 0 : realTypes[0];
|
|
925
1052
|
return realType !== null && realType !== void 0 ? realType : type;
|
|
926
1053
|
}
|
|
927
|
-
|
|
1054
|
+
const childVisited = visited !== null && visited !== void 0 ? visited : new Set();
|
|
1055
|
+
childVisited.add(type);
|
|
1056
|
+
return this.replaceRecursiveType(type, childVisited, realTypes);
|
|
928
1057
|
}
|
|
929
1058
|
static replaceRecursiveType(type, visited, realTypes) {
|
|
930
1059
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1022,20 +1151,17 @@ class TypeInference {
|
|
|
1022
1151
|
if (isAnonClassType) {
|
|
1023
1152
|
return true;
|
|
1024
1153
|
}
|
|
1025
|
-
return argType instanceof Type_1.FunctionType &&
|
|
1154
|
+
return (argType instanceof Type_1.FunctionType &&
|
|
1026
1155
|
argType.getMethodSignature().getMethodSubSignature().getMethodName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX) &&
|
|
1027
|
-
argType.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature().getProjectName() === projectName;
|
|
1028
|
-
}
|
|
1029
|
-
static isDummyClassType(rightType) {
|
|
1030
|
-
var _a;
|
|
1031
|
-
return rightType instanceof Type_1.ClassType &&
|
|
1032
|
-
rightType.getClassSignature().getDeclaringFileSignature().getFileName() === Builtin_1.Builtin.DUMMY_FILE_NAME &&
|
|
1033
|
-
!!((_a = rightType.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => !(t instanceof Type_1.GenericType)));
|
|
1156
|
+
argType.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature().getProjectName() === projectName);
|
|
1034
1157
|
}
|
|
1035
1158
|
static isTypeCanBeOverride(type) {
|
|
1036
1159
|
var _a, _b;
|
|
1037
|
-
if (type instanceof Type_1.UnknownType ||
|
|
1038
|
-
type instanceof Type_1.
|
|
1160
|
+
if (type instanceof Type_1.UnknownType ||
|
|
1161
|
+
type instanceof Type_1.NullType ||
|
|
1162
|
+
type instanceof Type_1.UndefinedType ||
|
|
1163
|
+
type instanceof Type_1.UnclearReferenceType ||
|
|
1164
|
+
type instanceof Type_1.GenericType) {
|
|
1039
1165
|
return true;
|
|
1040
1166
|
}
|
|
1041
1167
|
else if (type instanceof Type_1.ClassType) {
|
|
@@ -1045,15 +1171,15 @@ class TypeInference {
|
|
|
1045
1171
|
return this.isTypeCanBeOverride(type.getOriginalType()) || !!((_b = type.getRealGenericTypes()) === null || _b === void 0 ? void 0 : _b.find(r => this.isTypeCanBeOverride(r)));
|
|
1046
1172
|
}
|
|
1047
1173
|
else if (type instanceof Type_1.ArrayType) {
|
|
1048
|
-
return TypeInference.checkType(type.getBaseType(),
|
|
1174
|
+
return TypeInference.checkType(type.getBaseType(), IS_UNCLEAR_REF_OR_GENERIC);
|
|
1049
1175
|
}
|
|
1050
1176
|
return false;
|
|
1051
1177
|
}
|
|
1052
1178
|
static union(type1, type2) {
|
|
1053
1179
|
const leftType = TypeInference.replaceAliasType(type1);
|
|
1054
1180
|
const rightType = TypeInference.replaceAliasType(type2);
|
|
1055
|
-
if (this.isSameType(leftType, rightType) ||
|
|
1056
|
-
(rightType instanceof Type_1.ClassType && rightType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)))) {
|
|
1181
|
+
if (this.isSameType(leftType, rightType) ||
|
|
1182
|
+
TypeInference.checkType(rightType, t => t instanceof Type_1.AnyType || (rightType instanceof Type_1.ClassType && rightType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)))) {
|
|
1057
1183
|
return type1;
|
|
1058
1184
|
}
|
|
1059
1185
|
else if (leftType instanceof Type_1.FunctionType) {
|
|
@@ -1076,7 +1202,7 @@ class TypeInference {
|
|
|
1076
1202
|
}
|
|
1077
1203
|
static isSameType(type1, type2) {
|
|
1078
1204
|
if (type1 instanceof Type_1.ClassType && type2 instanceof Type_1.ClassType) {
|
|
1079
|
-
return type1.getClassSignature()
|
|
1205
|
+
return (0, SignatureCanonicalizer_1.signatureEquals)(type1.getClassSignature(), type2.getClassSignature());
|
|
1080
1206
|
}
|
|
1081
1207
|
else if (type1 instanceof Type_1.LiteralType) {
|
|
1082
1208
|
return typeof type1.getLiteralName() === type2.toString();
|
|
@@ -1102,7 +1228,7 @@ class TypeInference {
|
|
|
1102
1228
|
return rightType;
|
|
1103
1229
|
}
|
|
1104
1230
|
let leftType = value.getType();
|
|
1105
|
-
if (rightType && this.checkType(leftType,
|
|
1231
|
+
if (rightType && this.checkType(leftType, IS_ANY)) {
|
|
1106
1232
|
return rightType;
|
|
1107
1233
|
}
|
|
1108
1234
|
if (!rightType || this.isAnonType(rightType, scene.getProjectName())) {
|
|
@@ -1133,7 +1259,7 @@ class TypeInference {
|
|
|
1133
1259
|
}
|
|
1134
1260
|
childClass = childClass === null || childClass === void 0 ? void 0 : childClass.getSuperClass();
|
|
1135
1261
|
}
|
|
1136
|
-
const objectClass =
|
|
1262
|
+
const objectClass = SdkUtils_1.SdkUtils.getSdkGlobal(Builtin_1.Builtin.OBJECT);
|
|
1137
1263
|
return fatherClass === objectClass;
|
|
1138
1264
|
}
|
|
1139
1265
|
static unwrapPromiseType(type) {
|