arkanalyzer 1.0.21 → 1.0.23
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/README.en.md +8 -0
- package/README.md +9 -0
- package/config/arkanalyzer.json +14 -13
- package/lib/Scene.js +4 -4
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.js +4 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +3 -2
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +58 -26
- package/lib/core/base/Expr.d.ts +24 -5
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +49 -9
- package/lib/core/base/Ref.d.ts +1 -0
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +17 -17
- package/lib/core/base/Type.d.ts +1 -1
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +1 -0
- package/lib/core/common/ArkIRTransformer.d.ts +1 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +15 -0
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +3 -3
- package/lib/core/common/Const.d.ts +1 -0
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +3 -1
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +1 -1
- package/lib/core/common/IRInference.d.ts +11 -2
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +125 -29
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +26 -17
- package/lib/core/common/SdkUtils.d.ts +3 -0
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +26 -4
- package/lib/core/common/TSConst.d.ts +2 -0
- package/lib/core/common/TSConst.d.ts.map +1 -1
- package/lib/core/common/TSConst.js +4 -2
- package/lib/core/common/TypeInference.d.ts +6 -3
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +107 -46
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts +1 -0
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +48 -0
- package/lib/core/model/ArkClass.d.ts +11 -2
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +28 -6
- package/lib/core/model/ArkExport.d.ts +5 -1
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +6 -0
- package/lib/core/model/ArkField.d.ts +5 -0
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +6 -0
- package/lib/core/model/ArkFile.d.ts +13 -1
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +19 -2
- package/lib/core/model/ArkImport.d.ts +5 -1
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +6 -0
- package/lib/core/model/ArkMethod.d.ts +8 -0
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +13 -0
- package/lib/core/model/ArkNamespace.d.ts +5 -1
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +6 -0
- package/lib/core/model/ArkSignature.d.ts +7 -2
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +20 -5
- package/lib/core/model/builder/ArkClassBuilder.d.ts +1 -1
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +16 -47
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +5 -0
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +5 -6
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +1 -0
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +15 -2
- package/lib/utils/FileUtils.d.ts +2 -0
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +12 -0
- package/lib/utils/getAllFiles.js +2 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -18,13 +18,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.SdkUtils = void 0;
|
|
21
|
+
const ArkExport_1 = require("../model/ArkExport");
|
|
21
22
|
const EtsConst_1 = require("./EtsConst");
|
|
22
23
|
const TSConst_1 = require("./TSConst");
|
|
23
24
|
const Const_1 = require("./Const");
|
|
24
25
|
const ArkClass_1 = require("../model/ArkClass");
|
|
25
26
|
const ArkSignature_1 = require("../model/ArkSignature");
|
|
26
27
|
const ModelUtils_1 = require("./ModelUtils");
|
|
28
|
+
const Local_1 = require("../base/Local");
|
|
27
29
|
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const IRInference_1 = require("./IRInference");
|
|
31
|
+
const Type_1 = require("../base/Type");
|
|
32
|
+
const ArkNamespace_1 = require("../model/ArkNamespace");
|
|
28
33
|
class SdkUtils {
|
|
29
34
|
static buildGlobalMap(file, globalMap) {
|
|
30
35
|
var _a, _b, _c, _d;
|
|
@@ -36,6 +41,7 @@ class SdkUtils {
|
|
|
36
41
|
if (!isGlobalPath) {
|
|
37
42
|
return;
|
|
38
43
|
}
|
|
44
|
+
IRInference_1.IRInference.inferFile(file);
|
|
39
45
|
ModelUtils_1.ModelUtils.getAllClassesInFile(file).forEach(cls => {
|
|
40
46
|
if (!cls.isAnonymousClass() && !cls.isDefaultArkClass()) {
|
|
41
47
|
SdkUtils.loadClass(globalMap, cls);
|
|
@@ -49,11 +55,12 @@ class SdkUtils {
|
|
|
49
55
|
const defaultArkMethod = file.getDefaultClass().getDefaultArkMethod();
|
|
50
56
|
(_b = defaultArkMethod === null || defaultArkMethod === void 0 ? void 0 : defaultArkMethod.getBody()) === null || _b === void 0 ? void 0 : _b.getLocals().forEach(local => {
|
|
51
57
|
const name = local.getName();
|
|
52
|
-
if (name !== TSConst_1.THIS_NAME && !name.startsWith(Const_1.TEMP_LOCAL_PREFIX)
|
|
58
|
+
if (name !== TSConst_1.THIS_NAME && !name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
53
59
|
this.loadGlobalLocal(local, defaultArkMethod, globalMap);
|
|
54
60
|
}
|
|
55
61
|
});
|
|
56
62
|
(_d = (_c = defaultArkMethod === null || defaultArkMethod === void 0 ? void 0 : defaultArkMethod.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeMap()) === null || _d === void 0 ? void 0 : _d.forEach(a => globalMap.set(a[0].getName(), a[0]));
|
|
63
|
+
ModelUtils_1.ModelUtils.getAllNamespacesInFile(file).forEach(ns => globalMap.set(ns.getName(), ns));
|
|
57
64
|
}
|
|
58
65
|
static loadClass(globalMap, cls) {
|
|
59
66
|
const old = globalMap.get(cls.getName());
|
|
@@ -74,11 +81,12 @@ class SdkUtils {
|
|
|
74
81
|
static loadGlobalLocal(local, defaultArkMethod, globalMap) {
|
|
75
82
|
const name = local.getName();
|
|
76
83
|
local.setSignature(new ArkSignature_1.LocalSignature(name, defaultArkMethod.getSignature()));
|
|
77
|
-
|
|
84
|
+
const scene = defaultArkMethod.getDeclaringArkFile().getScene();
|
|
85
|
+
if (scene.getOptions().isScanAbc) {
|
|
78
86
|
const instance = globalMap.get(name + 'Interface');
|
|
79
87
|
const attr = globalMap.get(name + EtsConst_1.COMPONENT_ATTRIBUTE);
|
|
80
88
|
if (attr instanceof ArkClass_1.ArkClass && instance instanceof ArkClass_1.ArkClass) {
|
|
81
|
-
instance.getMethods().forEach(m => attr.addMethod(m));
|
|
89
|
+
instance.getMethods().filter(m => !instance.getMethodWithName(m.getName())).forEach(m => attr.addMethod(m));
|
|
82
90
|
globalMap.set(name, attr);
|
|
83
91
|
return;
|
|
84
92
|
}
|
|
@@ -87,6 +95,12 @@ class SdkUtils {
|
|
|
87
95
|
if (!old) {
|
|
88
96
|
globalMap.set(name, local);
|
|
89
97
|
}
|
|
98
|
+
else if (old instanceof ArkClass_1.ArkClass && local.getType() instanceof Type_1.ClassType) {
|
|
99
|
+
const localConstructor = scene.getClass(local.getType().getClassSignature());
|
|
100
|
+
if (localConstructor) {
|
|
101
|
+
localConstructor.getMethods().filter(m => !old.getMethodWithName(m.getName())).forEach(m => old.addMethod(m));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
static copyMethod(from, to) {
|
|
92
106
|
from.getMethods().forEach(method => {
|
|
@@ -101,5 +115,13 @@ class SdkUtils {
|
|
|
101
115
|
}
|
|
102
116
|
});
|
|
103
117
|
}
|
|
118
|
+
static computeGlobalThis(leftOp, arkMethod) {
|
|
119
|
+
const globalThis = arkMethod.getDeclaringArkFile().getScene().getSdkGlobal(TSConst_1.GLOBAL_THIS_NAME);
|
|
120
|
+
if (globalThis instanceof ArkNamespace_1.ArkNamespace) {
|
|
121
|
+
const exportInfo = new ArkExport_1.ExportInfo.Builder().exportClauseName(leftOp.getFieldName())
|
|
122
|
+
.arkExport(new Local_1.Local(leftOp.getFieldName(), leftOp.getType())).build();
|
|
123
|
+
globalThis.addExportInfo(exportInfo);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
104
126
|
}
|
|
105
127
|
exports.SdkUtils = SdkUtils;
|
|
@@ -5,6 +5,8 @@ export declare const GLOBAL_THIS_NAME: string;
|
|
|
5
5
|
export declare const DEFAULT = "default";
|
|
6
6
|
export declare const ALL = "*";
|
|
7
7
|
export declare const IMPORT = "import";
|
|
8
|
+
export declare const PROMISE = "Promise";
|
|
9
|
+
export declare const FUNCTION = "Function";
|
|
8
10
|
export declare const DECLARE_KEYWORD = "DeclareKeyword";
|
|
9
11
|
export declare const NULL_KEYWORD = "null";
|
|
10
12
|
export declare const UNDEFINED_KEYWORD = "undefined";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TSConst.d.ts","sourceRoot":"","sources":["../../../src/core/common/TSConst.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,SAAS,SAAS,CAAC;AAChC,eAAO,MAAM,gBAAgB,EAAE,MAAqB,CAAA;AAEpD,eAAO,MAAM,OAAO,YAAY,CAAC;AAEjC,eAAO,MAAM,GAAG,MAAM,CAAC;AAEvB,eAAO,MAAM,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"TSConst.d.ts","sourceRoot":"","sources":["../../../src/core/common/TSConst.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,SAAS,SAAS,CAAC;AAChC,eAAO,MAAM,gBAAgB,EAAE,MAAqB,CAAA;AAEpD,eAAO,MAAM,OAAO,YAAY,CAAC;AAEjC,eAAO,MAAM,GAAG,MAAM,CAAC;AAEvB,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,QAAQ,aAAa,CAAC;AAGnC,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAChD,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,WAAW,QAAQ,CAAC;AACjC,eAAO,MAAM,eAAe,YAAY,CAAC;AACzC,eAAO,MAAM,eAAe,YAAY,CAAC;AACzC,eAAO,MAAM,cAAc,WAAW,CAAC;AACvC,eAAO,MAAM,cAAc,WAAW,CAAC;AACvC,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,aAAa,UAAU,CAAC;AACrC,eAAO,MAAM,aAAa,kBAAkB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.TSCONFIG_JSON = exports.NEVER_KEYWORD = exports.VOID_KEYWORD = exports.STRING_KEYWORD = exports.NUMBER_KEYWORD = exports.BOOLEAN_KEYWORD = exports.UNKNOWN_KEYWORD = exports.ANY_KEYWORD = exports.UNDEFINED_KEYWORD = exports.NULL_KEYWORD = exports.DECLARE_KEYWORD = exports.IMPORT = exports.ALL = exports.DEFAULT = exports.GLOBAL_THIS_NAME = exports.THIS_NAME = exports.SUPER_NAME = exports.CONSTRUCTOR_NAME = void 0;
|
|
17
|
+
exports.TSCONFIG_JSON = exports.NEVER_KEYWORD = exports.VOID_KEYWORD = exports.STRING_KEYWORD = exports.NUMBER_KEYWORD = exports.BOOLEAN_KEYWORD = exports.UNKNOWN_KEYWORD = exports.ANY_KEYWORD = exports.UNDEFINED_KEYWORD = exports.NULL_KEYWORD = exports.DECLARE_KEYWORD = exports.FUNCTION = exports.PROMISE = exports.IMPORT = exports.ALL = exports.DEFAULT = exports.GLOBAL_THIS_NAME = exports.THIS_NAME = exports.SUPER_NAME = exports.CONSTRUCTOR_NAME = void 0;
|
|
18
18
|
exports.CONSTRUCTOR_NAME = 'constructor';
|
|
19
19
|
exports.SUPER_NAME = 'super';
|
|
20
20
|
exports.THIS_NAME = 'this';
|
|
@@ -22,6 +22,8 @@ exports.GLOBAL_THIS_NAME = 'globalThis';
|
|
|
22
22
|
exports.DEFAULT = 'default';
|
|
23
23
|
exports.ALL = '*';
|
|
24
24
|
exports.IMPORT = 'import';
|
|
25
|
+
exports.PROMISE = 'Promise';
|
|
26
|
+
exports.FUNCTION = 'Function';
|
|
25
27
|
// ast const
|
|
26
28
|
exports.DECLARE_KEYWORD = 'DeclareKeyword';
|
|
27
29
|
exports.NULL_KEYWORD = 'null';
|
|
@@ -5,8 +5,7 @@ import { ArkExport } from '../model/ArkExport';
|
|
|
5
5
|
import { ArkClass } from '../model/ArkClass';
|
|
6
6
|
import { ArkField } from '../model/ArkField';
|
|
7
7
|
import { Value } from '../base/Value';
|
|
8
|
-
import { MethodSignature } from '../model/ArkSignature';
|
|
9
|
-
import { MethodParameter } from '../model/builder/ArkMethodBuilder';
|
|
8
|
+
import { MethodSignature, MethodSubSignature } from '../model/ArkSignature';
|
|
10
9
|
export declare class TypeInference {
|
|
11
10
|
static inferTypeInArkField(arkField: ArkField): void;
|
|
12
11
|
/**
|
|
@@ -21,6 +20,7 @@ export declare class TypeInference {
|
|
|
21
20
|
*/
|
|
22
21
|
static inferUnclearedType(leftOpType: Type, declaringArkClass: ArkClass, rightType?: Type): Type | null | undefined;
|
|
23
22
|
static inferTypeInMethod(arkMethod: ArkMethod): void;
|
|
23
|
+
private static resolveStmt;
|
|
24
24
|
/**
|
|
25
25
|
* @Deprecated
|
|
26
26
|
* @param arkMethod
|
|
@@ -47,6 +47,7 @@ export declare class TypeInference {
|
|
|
47
47
|
* @param arkMethod
|
|
48
48
|
*/
|
|
49
49
|
static resolveArkAssignStmt(stmt: Stmt, arkMethod: ArkMethod): void;
|
|
50
|
+
private static resolveLeftOp;
|
|
50
51
|
private static setValueType;
|
|
51
52
|
static isUnclearType(type: Type | null | undefined): boolean;
|
|
52
53
|
private static hasUnclearReferenceType;
|
|
@@ -55,6 +56,7 @@ export declare class TypeInference {
|
|
|
55
56
|
static inferValueType(value: Value, arkMethod: ArkMethod): Type | null;
|
|
56
57
|
private static inferParameterType;
|
|
57
58
|
static inferSignatureReturnType(oldSignature: MethodSignature, arkMethod: ArkMethod): void;
|
|
59
|
+
private static inferReturnType;
|
|
58
60
|
static inferGenericType(types: GenericType[] | undefined, arkClass: ArkClass): void;
|
|
59
61
|
/**
|
|
60
62
|
* Infer type for a given {@link UnclearReferenceType} type.
|
|
@@ -98,6 +100,7 @@ export declare class TypeInference {
|
|
|
98
100
|
static inferDynamicImportType(from: string, arkClass: ArkClass): Type | null;
|
|
99
101
|
static replaceTypeWithReal(type: Type, realTypes?: Type[]): Type;
|
|
100
102
|
static replaceAliasType(type: Type): Type;
|
|
101
|
-
static inferFunctionType(argType: FunctionType,
|
|
103
|
+
static inferFunctionType(argType: FunctionType, paramSubSignature: MethodSubSignature | undefined, realTypes: Type[] | undefined): void;
|
|
104
|
+
private static resolveArkReturnStmt;
|
|
102
105
|
}
|
|
103
106
|
//# sourceMappingURL=TypeInference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeInference.d.ts","sourceRoot":"","sources":["../../../src/core/common/TypeInference.ts"],"names":[],"mappings":"AA0BA,OAAO,
|
|
1
|
+
{"version":3,"file":"TypeInference.d.ts","sourceRoot":"","sources":["../../../src/core/common/TypeInference.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAwD,IAAI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AAG,IAAI,GAAG,IAAI;WAUrE,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI;WA4CzD,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;WASlC,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,GAAG,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,SAAS,GAAG,IAAI;IAuB9I,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAatC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -52,11 +52,14 @@ const ArkNamespace_1 = require("../model/ArkNamespace");
|
|
|
52
52
|
const TSConst_1 = require("./TSConst");
|
|
53
53
|
const ModelUtils_1 = require("./ModelUtils");
|
|
54
54
|
const Builtin_1 = require("./Builtin");
|
|
55
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
55
56
|
const Const_1 = require("./Const");
|
|
56
57
|
const ValueUtil_1 = require("./ValueUtil");
|
|
57
58
|
const ArkImport_1 = require("../model/ArkImport");
|
|
58
59
|
const IRInference_1 = require("./IRInference");
|
|
59
60
|
const TypeExpr_1 = require("../base/TypeExpr");
|
|
61
|
+
const SdkUtils_1 = require("./SdkUtils");
|
|
62
|
+
const ArkBaseModel_1 = require("../model/ArkBaseModel");
|
|
60
63
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'TypeInference');
|
|
61
64
|
class TypeInference {
|
|
62
65
|
static inferTypeInArkField(arkField) {
|
|
@@ -66,10 +69,7 @@ class TypeInference {
|
|
|
66
69
|
const method = (_a = arkClass.getMethodWithName(Const_1.INSTANCE_INIT_METHOD_NAME)) !== null && _a !== void 0 ? _a : arkClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
67
70
|
for (const stmt of stmts) {
|
|
68
71
|
if (method) {
|
|
69
|
-
this.
|
|
70
|
-
this.resolveExprsInStmt(stmt, method);
|
|
71
|
-
this.resolveFieldRefsInStmt(stmt, method);
|
|
72
|
-
this.resolveArkAssignStmt(stmt, method);
|
|
72
|
+
this.resolveStmt(stmt, method);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
const beforeType = arkField.getType();
|
|
@@ -160,21 +160,31 @@ class TypeInference {
|
|
|
160
160
|
s.getMethodSubSignature().getParameters().forEach(p => {
|
|
161
161
|
this.inferParameterType(p, arkMethod);
|
|
162
162
|
});
|
|
163
|
-
this.inferSignatureReturnType(s, arkMethod);
|
|
164
163
|
});
|
|
165
164
|
const body = arkMethod.getBody();
|
|
166
165
|
if (!body) {
|
|
166
|
+
signatures.forEach(s => this.inferSignatureReturnType(s, arkMethod));
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
169
|
const cfg = body.getCfg();
|
|
170
170
|
for (const block of cfg.getBlocks()) {
|
|
171
171
|
for (const stmt of block.getStmts()) {
|
|
172
|
-
this.
|
|
173
|
-
this.resolveExprsInStmt(stmt, arkMethod);
|
|
174
|
-
this.resolveFieldRefsInStmt(stmt, arkMethod);
|
|
175
|
-
this.resolveArkAssignStmt(stmt, arkMethod);
|
|
172
|
+
this.resolveStmt(stmt, arkMethod);
|
|
176
173
|
}
|
|
177
174
|
}
|
|
175
|
+
signatures.forEach(s => this.inferSignatureReturnType(s, arkMethod));
|
|
176
|
+
}
|
|
177
|
+
static resolveStmt(stmt, arkMethod) {
|
|
178
|
+
try {
|
|
179
|
+
this.resolveTypeExprsInStmt(stmt, arkMethod);
|
|
180
|
+
this.resolveExprsInStmt(stmt, arkMethod);
|
|
181
|
+
this.resolveFieldRefsInStmt(stmt, arkMethod);
|
|
182
|
+
this.resolveArkAssignStmt(stmt, arkMethod);
|
|
183
|
+
this.resolveArkReturnStmt(stmt, arkMethod);
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
logger.warn('stmt is not correct: ' + stmt.toString());
|
|
187
|
+
}
|
|
178
188
|
}
|
|
179
189
|
/**
|
|
180
190
|
* @Deprecated
|
|
@@ -200,7 +210,8 @@ class TypeInference {
|
|
|
200
210
|
static resolveExprsInStmt(stmt, arkMethod) {
|
|
201
211
|
for (const expr of stmt.getExprs()) {
|
|
202
212
|
const newExpr = expr.inferType(arkMethod);
|
|
203
|
-
if (stmt.containsInvokeExpr() && expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr)
|
|
213
|
+
if (stmt.containsInvokeExpr() && ((expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) ||
|
|
214
|
+
newExpr instanceof Expr_1.ArkPtrInvokeExpr)) {
|
|
204
215
|
stmt.replaceUse(expr, newExpr);
|
|
205
216
|
}
|
|
206
217
|
}
|
|
@@ -280,25 +291,25 @@ class TypeInference {
|
|
|
280
291
|
* @param arkMethod
|
|
281
292
|
*/
|
|
282
293
|
static resolveArkAssignStmt(stmt, arkMethod) {
|
|
283
|
-
var _a;
|
|
284
294
|
if (!(stmt instanceof Stmt_1.ArkAssignStmt)) {
|
|
285
295
|
return;
|
|
286
296
|
}
|
|
287
297
|
const arkClass = arkMethod.getDeclaringArkClass();
|
|
288
298
|
const rightOp = stmt.getRightOp();
|
|
299
|
+
if (rightOp instanceof Local_1.Local && rightOp.getType() instanceof Type_1.UnknownType) {
|
|
300
|
+
IRInference_1.IRInference.inferLocal(rightOp, arkMethod);
|
|
301
|
+
}
|
|
289
302
|
let rightType = rightOp.getType();
|
|
290
303
|
if (this.isUnclearType(rightType)) {
|
|
291
304
|
rightType = this.inferUnclearedType(rightType, arkClass);
|
|
292
305
|
if (rightType) {
|
|
293
306
|
this.setValueType(rightOp, rightType);
|
|
294
307
|
}
|
|
295
|
-
else {
|
|
296
|
-
if (rightOp instanceof Local_1.Local) {
|
|
297
|
-
IRInference_1.IRInference.inferLocal(rightOp, arkMethod);
|
|
298
|
-
rightType = rightOp.getType();
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
308
|
}
|
|
309
|
+
TypeInference.resolveLeftOp(stmt, arkClass, rightType, arkMethod);
|
|
310
|
+
}
|
|
311
|
+
static resolveLeftOp(stmt, arkClass, rightType, arkMethod) {
|
|
312
|
+
var _a;
|
|
302
313
|
const leftOp = stmt.getLeftOp();
|
|
303
314
|
let leftType = leftOp.getType();
|
|
304
315
|
if (this.isUnclearType(leftType)) {
|
|
@@ -310,6 +321,9 @@ class TypeInference {
|
|
|
310
321
|
leftType = newLeftType;
|
|
311
322
|
}
|
|
312
323
|
}
|
|
324
|
+
else if (leftOp instanceof Local_1.Local && leftOp.getName() === TSConst_1.THIS_NAME) {
|
|
325
|
+
leftType = rightType;
|
|
326
|
+
}
|
|
313
327
|
if (leftType && !this.isUnclearType(leftType)) {
|
|
314
328
|
this.setValueType(leftOp, leftType);
|
|
315
329
|
if (leftOp instanceof Local_1.Local && ((_a = stmt.getOriginalText()) === null || _a === void 0 ? void 0 : _a.startsWith(leftOp.getName()))) {
|
|
@@ -321,6 +335,12 @@ class TypeInference {
|
|
|
321
335
|
if (rightType) {
|
|
322
336
|
IRInference_1.IRInference.inferRightWithSdkType(leftType, rightType, arkClass);
|
|
323
337
|
}
|
|
338
|
+
if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
339
|
+
const declaringSignature = leftOp.getFieldSignature().getDeclaringSignature();
|
|
340
|
+
if (declaringSignature instanceof ArkSignature_1.NamespaceSignature && declaringSignature.getNamespaceName() === TSConst_1.GLOBAL_THIS_NAME) {
|
|
341
|
+
SdkUtils_1.SdkUtils.computeGlobalThis(leftOp, arkMethod);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
324
344
|
}
|
|
325
345
|
}
|
|
326
346
|
static setValueType(value, type) {
|
|
@@ -332,20 +352,23 @@ class TypeInference {
|
|
|
332
352
|
}
|
|
333
353
|
}
|
|
334
354
|
static isUnclearType(type) {
|
|
355
|
+
var _a;
|
|
335
356
|
// TODO: For UnionType, IntersectionType and TupleType, it should recurse check every item of them.
|
|
336
357
|
if (!type || type instanceof Type_1.UnknownType || type instanceof Type_1.UnclearReferenceType
|
|
337
358
|
|| type instanceof Type_1.NullType || type instanceof Type_1.UndefinedType) {
|
|
338
359
|
return true;
|
|
339
360
|
}
|
|
340
|
-
else if (type instanceof Type_1.ClassType
|
|
341
|
-
|
|
361
|
+
else if (type instanceof Type_1.ClassType && (type.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME ||
|
|
362
|
+
(type.getClassSignature().getDeclaringFileSignature().getFileName() === Builtin_1.Builtin.DUMMY_FILE_NAME &&
|
|
363
|
+
((_a = type.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.find(t => t instanceof Type_1.GenericType))))) {
|
|
342
364
|
return true;
|
|
343
365
|
}
|
|
344
366
|
else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
|
|
345
367
|
return !!type.getTypes().find(t => this.hasUnclearReferenceType(t));
|
|
346
368
|
}
|
|
347
369
|
else if (type instanceof Type_1.ArrayType) {
|
|
348
|
-
|
|
370
|
+
const baseType = type.getBaseType();
|
|
371
|
+
return this.hasUnclearReferenceType(baseType) || baseType instanceof Type_1.AnyType || baseType instanceof Type_1.GenericType;
|
|
349
372
|
}
|
|
350
373
|
else if (type instanceof Type_1.AliasType) {
|
|
351
374
|
return this.isUnclearType(type.getOriginalType());
|
|
@@ -430,14 +453,19 @@ class TypeInference {
|
|
|
430
453
|
}
|
|
431
454
|
static inferParameterType(param, arkMethod) {
|
|
432
455
|
let pType = param.getType();
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
456
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
457
|
+
let type;
|
|
458
|
+
if (pType instanceof TypeExpr_1.AbstractTypeExpr) {
|
|
459
|
+
pType.inferType(arkMethod);
|
|
460
|
+
}
|
|
461
|
+
else if (param.getName() === 'value' && arkClass.hasComponentDecorator() && arkMethod.getName() === TSConst_1.CONSTRUCTOR_NAME) {
|
|
462
|
+
type = this.parseArkExport2Type(arkClass);
|
|
436
463
|
}
|
|
437
464
|
else {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
465
|
+
type = TypeInference.inferUnclearedType(pType, arkClass);
|
|
466
|
+
}
|
|
467
|
+
if (type) {
|
|
468
|
+
param.setType(type);
|
|
441
469
|
}
|
|
442
470
|
}
|
|
443
471
|
static inferSignatureReturnType(oldSignature, arkMethod) {
|
|
@@ -463,21 +491,35 @@ class TypeInference {
|
|
|
463
491
|
oldSignature.getMethodSubSignature().setReturnType(newReturnType);
|
|
464
492
|
}
|
|
465
493
|
else if (arkMethod.getBody()) {
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (type instanceof Type_1.UnionType) {
|
|
470
|
-
type.flatType().filter(t => !TypeInference.isUnclearType(t)).forEach(t => typeMap.set(t.toString(), t));
|
|
471
|
-
}
|
|
472
|
-
else if (!TypeInference.isUnclearType(type)) {
|
|
473
|
-
typeMap.set(type.toString(), type);
|
|
474
|
-
}
|
|
494
|
+
const returnType = TypeInference.inferReturnType(arkMethod);
|
|
495
|
+
if (returnType) {
|
|
496
|
+
oldSignature.getMethodSubSignature().setReturnType(returnType);
|
|
475
497
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
static inferReturnType(arkMethod) {
|
|
501
|
+
const typeMap = new Map();
|
|
502
|
+
for (let returnValue of arkMethod.getReturnValues()) {
|
|
503
|
+
const type = returnValue.getType();
|
|
504
|
+
if (type instanceof Type_1.UnionType) {
|
|
505
|
+
type.flatType().filter(t => !TypeInference.isUnclearType(t)).forEach(t => typeMap.set(t.toString(), t));
|
|
506
|
+
}
|
|
507
|
+
else if (!TypeInference.isUnclearType(type)) {
|
|
508
|
+
typeMap.set(type.toString(), type);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (typeMap.size > 0) {
|
|
512
|
+
const types = Array.from(typeMap.values());
|
|
513
|
+
let returnType = types.length === 1 ? types[0] : new Type_1.UnionType(types);
|
|
514
|
+
if (arkMethod.containsModifier(ArkBaseModel_1.ModifierType.ASYNC)) {
|
|
515
|
+
const promise = arkMethod.getDeclaringArkFile().getScene().getSdkGlobal(TSConst_1.PROMISE);
|
|
516
|
+
if (promise instanceof ArkClass_1.ArkClass) {
|
|
517
|
+
returnType = new Type_1.ClassType(promise.getSignature(), [returnType]);
|
|
518
|
+
}
|
|
479
519
|
}
|
|
520
|
+
return returnType;
|
|
480
521
|
}
|
|
522
|
+
return null;
|
|
481
523
|
}
|
|
482
524
|
static inferGenericType(types, arkClass) {
|
|
483
525
|
types === null || types === void 0 ? void 0 : types.forEach(type => {
|
|
@@ -512,7 +554,7 @@ class TypeInference {
|
|
|
512
554
|
if (urType.getName() === Builtin_1.Builtin.ARRAY) {
|
|
513
555
|
return new Type_1.ArrayType((_a = realTypes[0]) !== null && _a !== void 0 ? _a : Type_1.AnyType.getInstance(), 1);
|
|
514
556
|
}
|
|
515
|
-
|
|
557
|
+
const type = this.inferUnclearRefName(urType.getName(), arkClass);
|
|
516
558
|
return type ? this.replaceTypeWithReal(type, realTypes) : null;
|
|
517
559
|
}
|
|
518
560
|
/**
|
|
@@ -591,10 +633,6 @@ class TypeInference {
|
|
|
591
633
|
if (!arkClass) {
|
|
592
634
|
return propertyAndType;
|
|
593
635
|
}
|
|
594
|
-
if (arkClass.isAnonymousClass()) {
|
|
595
|
-
const fieldType = this.inferUnclearRefName(fieldName, arkClass);
|
|
596
|
-
return fieldType ? [null, fieldType] : null;
|
|
597
|
-
}
|
|
598
636
|
const property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arkClass);
|
|
599
637
|
let propertyType = null;
|
|
600
638
|
if (property instanceof ArkField_1.ArkField) {
|
|
@@ -606,6 +644,10 @@ class TypeInference {
|
|
|
606
644
|
if (propertyType) {
|
|
607
645
|
propertyAndType = [property, propertyType];
|
|
608
646
|
}
|
|
647
|
+
else if (arkClass.isAnonymousClass()) {
|
|
648
|
+
const fieldType = this.inferUnclearRefName(fieldName, arkClass);
|
|
649
|
+
propertyAndType = fieldType ? [null, fieldType] : null;
|
|
650
|
+
}
|
|
609
651
|
}
|
|
610
652
|
else if (baseType instanceof Type_1.AnnotationNamespaceType) {
|
|
611
653
|
const namespace = declareClass.getDeclaringArkFile().getScene().getNamespace(baseType.getNamespaceSignature());
|
|
@@ -703,7 +745,7 @@ class TypeInference {
|
|
|
703
745
|
}
|
|
704
746
|
else if (type instanceof Type_1.TupleType && realTypes) {
|
|
705
747
|
let replacedTypes = [];
|
|
706
|
-
type.getTypes().forEach(t =>
|
|
748
|
+
type.getTypes().forEach(t => replacedTypes.push(this.replaceTypeWithReal(t, realTypes)));
|
|
707
749
|
return new Type_1.TupleType(replacedTypes);
|
|
708
750
|
}
|
|
709
751
|
else if (type instanceof Type_1.GenericType) {
|
|
@@ -727,7 +769,13 @@ class TypeInference {
|
|
|
727
769
|
}
|
|
728
770
|
return aliasType;
|
|
729
771
|
}
|
|
730
|
-
static inferFunctionType(argType,
|
|
772
|
+
static inferFunctionType(argType, paramSubSignature, realTypes) {
|
|
773
|
+
const returnType = argType.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
774
|
+
const declareType = paramSubSignature === null || paramSubSignature === void 0 ? void 0 : paramSubSignature.getReturnType();
|
|
775
|
+
if (declareType instanceof Type_1.GenericType && realTypes && !this.isUnclearType(returnType)) {
|
|
776
|
+
realTypes[declareType.getIndex()] = returnType;
|
|
777
|
+
}
|
|
778
|
+
const params = paramSubSignature === null || paramSubSignature === void 0 ? void 0 : paramSubSignature.getParameters();
|
|
731
779
|
if (!params) {
|
|
732
780
|
return;
|
|
733
781
|
}
|
|
@@ -744,5 +792,18 @@ class TypeInference {
|
|
|
744
792
|
}
|
|
745
793
|
});
|
|
746
794
|
}
|
|
795
|
+
static resolveArkReturnStmt(stmt, arkMethod) {
|
|
796
|
+
var _a;
|
|
797
|
+
if (!(stmt instanceof Stmt_1.ArkReturnStmt)) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
let returnType = arkMethod.getSignature().getType();
|
|
801
|
+
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getClassName() === TSConst_1.PROMISE) {
|
|
802
|
+
returnType = (_a = returnType.getRealGenericTypes()) === null || _a === void 0 ? void 0 : _a.at(0);
|
|
803
|
+
}
|
|
804
|
+
if (returnType) {
|
|
805
|
+
IRInference_1.IRInference.inferRightWithSdkType(returnType, stmt.getOp().getType(), arkMethod.getDeclaringArkClass());
|
|
806
|
+
}
|
|
807
|
+
}
|
|
747
808
|
}
|
|
748
809
|
exports.TypeInference = TypeInference;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewTreeBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/graph/builder/ViewTreeBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ViewTreeBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/graph/builder/ViewTreeBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAWjD,OAAO,EAAe,mBAAmB,EAAc,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAgC,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACrE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,sBAAsB;IAK9B,OAAO,CAAC,wBAAwB,CAU7B;IAEH,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,qBAAqB;IAkC7B;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAgD/B,OAAO,CAAC,kBAAkB;IA+C1B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,oBAAoB;CAmB/B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAEzD"}
|
|
@@ -62,6 +62,9 @@ function backtraceLocalInitValue(value) {
|
|
|
62
62
|
else if (rightOp instanceof Ref_1.ArkInstanceFieldRef && rightOp.getBase().getName().startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
63
63
|
return backtraceLocalInitValue(rightOp.getBase());
|
|
64
64
|
}
|
|
65
|
+
else if (rightOp instanceof Ref_1.ArkArrayRef) {
|
|
66
|
+
return backtraceLocalInitValue(rightOp.getBase());
|
|
67
|
+
}
|
|
65
68
|
return rightOp;
|
|
66
69
|
}
|
|
67
70
|
return value;
|
|
@@ -988,6 +991,45 @@ class ViewTreeImpl extends TreeNodeStack {
|
|
|
988
991
|
}
|
|
989
992
|
return undefined;
|
|
990
993
|
}
|
|
994
|
+
parsePtrInvokeExpr(local2Node, stmt, expr) {
|
|
995
|
+
let temp = expr.getFuncPtrLocal();
|
|
996
|
+
if (temp instanceof Local_1.Local && local2Node.has(temp)) {
|
|
997
|
+
let component = local2Node.get(temp);
|
|
998
|
+
if ((component === null || component === void 0 ? void 0 : component.name) === EtsConst_1.COMPONENT_REPEAT &&
|
|
999
|
+
expr.getMethodSignature().getMethodSubSignature().getMethodName() === 'each') {
|
|
1000
|
+
let arg = expr.getArg(0);
|
|
1001
|
+
let type = arg.getType();
|
|
1002
|
+
if (type instanceof Type_1.FunctionType) {
|
|
1003
|
+
let method = this.findMethod(type.getMethodSignature());
|
|
1004
|
+
this.buildViewTreeFromCfg(method === null || method === void 0 ? void 0 : method.getCfg());
|
|
1005
|
+
}
|
|
1006
|
+
this.pop();
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
component === null || component === void 0 ? void 0 : component.addStmt(this, stmt);
|
|
1010
|
+
}
|
|
1011
|
+
return component;
|
|
1012
|
+
}
|
|
1013
|
+
else if (temp instanceof Ref_1.ArkInstanceFieldRef) {
|
|
1014
|
+
let name = temp.getBase().getName();
|
|
1015
|
+
if (name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
1016
|
+
let initValue = backtraceLocalInitValue(temp.getBase());
|
|
1017
|
+
if (initValue instanceof Ref_1.ArkThisRef) {
|
|
1018
|
+
name = 'this';
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
let methodName = temp.getFieldName();
|
|
1022
|
+
let field = this.getDeclaringArkClass().getFieldWithName(methodName);
|
|
1023
|
+
if (name === 'this' && (field === null || field === void 0 ? void 0 : field.hasBuilderParamDecorator())) {
|
|
1024
|
+
return this.addBuilderParamNode(field);
|
|
1025
|
+
}
|
|
1026
|
+
let method = this.findMethod(expr.getMethodSignature());
|
|
1027
|
+
if (name === 'this' && (method === null || method === void 0 ? void 0 : method.hasBuilderDecorator())) {
|
|
1028
|
+
return this.addBuilderNode(method);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
return undefined;
|
|
1032
|
+
}
|
|
991
1033
|
/**
|
|
992
1034
|
* $temp3 = View.create($temp2);
|
|
993
1035
|
* $temp4 = View.pop();
|
|
@@ -1015,6 +1057,9 @@ class ViewTreeImpl extends TreeNodeStack {
|
|
|
1015
1057
|
else if (right instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
1016
1058
|
component = this.parseInstanceInvokeExpr(local2Node, stmt, right);
|
|
1017
1059
|
}
|
|
1060
|
+
else if (right instanceof Expr_1.ArkPtrInvokeExpr) {
|
|
1061
|
+
component = this.parsePtrInvokeExpr(local2Node, stmt, right);
|
|
1062
|
+
}
|
|
1018
1063
|
if (component) {
|
|
1019
1064
|
local2Node.set(left, component);
|
|
1020
1065
|
}
|
|
@@ -1027,6 +1072,9 @@ class ViewTreeImpl extends TreeNodeStack {
|
|
|
1027
1072
|
else if (expr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
1028
1073
|
this.parseInstanceInvokeExpr(local2Node, stmt, expr);
|
|
1029
1074
|
}
|
|
1075
|
+
else if (expr instanceof Expr_1.ArkPtrInvokeExpr) {
|
|
1076
|
+
this.parsePtrInvokeExpr(local2Node, stmt, expr);
|
|
1077
|
+
}
|
|
1030
1078
|
}
|
|
1031
1079
|
buildViewTreeFromCfg(cfg, local2Node = new Map()) {
|
|
1032
1080
|
if (!cfg) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GenericType, Type } from '../base/Type';
|
|
2
2
|
import { ViewTree } from '../graph/ViewTree';
|
|
3
3
|
import { ArkField } from './ArkField';
|
|
4
|
-
import { ArkFile } from './ArkFile';
|
|
4
|
+
import { ArkFile, Language } from './ArkFile';
|
|
5
5
|
import { ArkMethod } from './ArkMethod';
|
|
6
6
|
import { ArkNamespace } from './ArkNamespace';
|
|
7
7
|
import { ClassSignature, FieldSignature, FileSignature, MethodSignature, NamespaceSignature } from './ArkSignature';
|
|
@@ -47,6 +47,10 @@ export declare class ArkClass extends ArkBaseModel implements ArkExport {
|
|
|
47
47
|
private indexSignatureNumber;
|
|
48
48
|
private viewTree?;
|
|
49
49
|
constructor();
|
|
50
|
+
/**
|
|
51
|
+
* Returns the program language of the file where this class defined.
|
|
52
|
+
*/
|
|
53
|
+
getLanguage(): Language;
|
|
50
54
|
/**
|
|
51
55
|
* Returns the **string**name of this class.
|
|
52
56
|
* @returns The name of this class.
|
|
@@ -152,7 +156,12 @@ export declare class ArkClass extends ArkBaseModel implements ArkExport {
|
|
|
152
156
|
getMethod(methodSignature: MethodSignature): ArkMethod | null;
|
|
153
157
|
getMethodWithName(methodName: string): ArkMethod | null;
|
|
154
158
|
getStaticMethodWithName(methodName: string): ArkMethod | null;
|
|
155
|
-
|
|
159
|
+
/**
|
|
160
|
+
* add a method in class.
|
|
161
|
+
* when a nested method with declare name, add both the declare origin name and signature name
|
|
162
|
+
* %${declare name}$${outer method name} in class.
|
|
163
|
+
*/
|
|
164
|
+
addMethod(method: ArkMethod, originName?: string): void;
|
|
156
165
|
setDefaultArkMethod(defaultMethod: ArkMethod): void;
|
|
157
166
|
getDefaultArkMethod(): ArkMethod | null;
|
|
158
167
|
setViewTree(viewTree: ViewTree): void;
|