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
|
@@ -60,6 +60,8 @@ const ArkValueTransformer_1 = require("./ArkValueTransformer");
|
|
|
60
60
|
const ArkImport_1 = require("../model/ArkImport");
|
|
61
61
|
const TypeInference_1 = require("./TypeInference");
|
|
62
62
|
const TypeExpr_1 = require("../base/TypeExpr");
|
|
63
|
+
const ArkClassBuilder_1 = require("../model/builder/ArkClassBuilder");
|
|
64
|
+
const ArkClass_1 = require("../model/ArkClass");
|
|
63
65
|
class DummyStmt extends Stmt_1.Stmt {
|
|
64
66
|
constructor(text) {
|
|
65
67
|
super();
|
|
@@ -154,6 +156,9 @@ class ArkIRTransformer {
|
|
|
154
156
|
else if (ts.isExportAssignment(node)) {
|
|
155
157
|
stmts = this.expressionInExportToStmts(node.expression);
|
|
156
158
|
}
|
|
159
|
+
else if (ts.isClassDeclaration(node)) {
|
|
160
|
+
stmts = this.classDeclarationToStmts(node);
|
|
161
|
+
}
|
|
157
162
|
this.mapStmtsToTsStmt(stmts, node);
|
|
158
163
|
if (stmts.length > 0) {
|
|
159
164
|
IRUtils_1.IRUtils.setComments(stmts[0], node, this.sourceFile, this.declaringMethod.getDeclaringArkFile().getScene().getOptions());
|
|
@@ -172,6 +177,16 @@ class ArkIRTransformer {
|
|
|
172
177
|
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(functionDeclarationNode, declaringClass, arkMethod, this.sourceFile, this.declaringMethod);
|
|
173
178
|
return [];
|
|
174
179
|
}
|
|
180
|
+
classDeclarationToStmts(node) {
|
|
181
|
+
const cls = new ArkClass_1.ArkClass();
|
|
182
|
+
const declaringArkNamespace = this.declaringMethod.getDeclaringArkClass().getDeclaringArkNamespace();
|
|
183
|
+
if (declaringArkNamespace) {
|
|
184
|
+
cls.setDeclaringArkNamespace(declaringArkNamespace);
|
|
185
|
+
}
|
|
186
|
+
cls.setDeclaringArkFile(this.declaringMethod.getDeclaringArkFile());
|
|
187
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkMethod)(node, cls, this.sourceFile, this.declaringMethod);
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
175
190
|
returnStatementToStmts(returnStatement) {
|
|
176
191
|
const stmts = [];
|
|
177
192
|
if (returnStatement.expression) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Builtin.d.ts","sourceRoot":"","sources":["../../../src/core/common/Builtin.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAsB,MAAM,uBAAuB,CAAC;AAC3G,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"Builtin.d.ts","sourceRoot":"","sources":["../../../src/core/common/Builtin.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAsB,MAAM,uBAAuB,CAAC;AAC3G,OAAO,EAAE,SAAS,EAA2B,MAAM,cAAc,CAAC;AAElE,qBAAa,OAAO;IAGhB,OAAc,MAAM,SAAY;IAChC,OAAc,KAAK,SAAW;IAC9B,OAAc,GAAG,SAAS;IAC1B,OAAc,GAAG,SAAS;IAC1B,OAAc,MAAM,SAAY;IAEhC,OAAc,gBAAgB,cAA8B;IAG5D,OAAc,kBAAkB,SAAY;IAC5C,OAAc,eAAe,SAAkB;IAE/C,OAAc,+BAA+B,gBAA8C;IAC3F,OAAc,sBAAsB,iBAAgD;IACpF,OAAc,qBAAqB,iBAA+C;IAClF,OAAc,mBAAmB,iBAA6C;IAC9E,OAAc,mBAAmB,iBAA6C;IAC9E,OAAc,sBAAsB,iBAAgD;IACpF,OAAc,iBAAiB,YAA8C;IAC7E,OAAc,4BAA4B,8BAAwC;IAGlF,OAAc,iBAAiB,SAAc;IAC7C,OAAc,QAAQ,SAAc;IACpC,OAAc,aAAa,SAAU;IACrC,OAAc,eAAe,SAAoB;IACjD,OAAc,oBAAoB,SAAU;IAC5C,OAAc,qBAAqB,SAAW;IAE9C,OAAc,wBAAwB,iBAAkD;IACxF,OAAc,+BAA+B,iBAAyD;IACtG,OAAc,mBAAmB,YAAwE;IACzG,OAAc,0BAA0B,YAA+E;IAGvH,OAAc,SAAS,SAAc;IACrC,OAAc,0BAA0B,kBACyC;IAEjF,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAUlC,OAAO,CAAC,MAAM,CAAC,gCAAgC;WAIjC,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc;IAI3E,OAAO,CAAC,MAAM,CAAC,6BAA6B;CAS/C"}
|
|
@@ -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
|
|
@@ -74,8 +74,8 @@ Builtin.ITERATOR_RESULT_DONE = 'done';
|
|
|
74
74
|
Builtin.ITERATOR_RESULT_VALUE = 'value';
|
|
75
75
|
Builtin.ITERATOR_CLASS_SIGNATURE = _a.buildBuiltInClassSignature(_a.ITERATOR);
|
|
76
76
|
Builtin.ITERATOR_RESULT_CLASS_SIGNATURE = _a.buildBuiltInClassSignature(_a.ITERATOR_RESULT);
|
|
77
|
-
Builtin.ITERATOR_CLASS_TYPE = new Type_1.ClassType(_a.ITERATOR_CLASS_SIGNATURE);
|
|
78
|
-
Builtin.ITERATOR_RESULT_CLASS_TYPE = new Type_1.ClassType(_a.ITERATOR_RESULT_CLASS_SIGNATURE);
|
|
77
|
+
Builtin.ITERATOR_CLASS_TYPE = new Type_1.ClassType(_a.ITERATOR_CLASS_SIGNATURE, [new Type_1.GenericType('T')]);
|
|
78
|
+
Builtin.ITERATOR_RESULT_CLASS_TYPE = new Type_1.ClassType(_a.ITERATOR_RESULT_CLASS_SIGNATURE, [new Type_1.GenericType('T')]);
|
|
79
79
|
// constants for string
|
|
80
80
|
Builtin.TO_STRING = 'toString';
|
|
81
81
|
Builtin.TO_STRING_METHOD_SIGNATURE = new ArkSignature_1.MethodSignature(ArkSignature_1.ClassSignature.DEFAULT, new ArkSignature_1.MethodSubSignature(_a.TO_STRING, [], Type_1.StringType.getInstance(), false));
|
|
@@ -19,4 +19,5 @@ export declare const UNKNOWN_FIELD_NAME = "";
|
|
|
19
19
|
export declare const UNKNOWN_METHOD_NAME = "";
|
|
20
20
|
export declare const TEMP_LOCAL_PREFIX = "%";
|
|
21
21
|
export declare const LEXICAL_ENV_NAME_PREFIX: string;
|
|
22
|
+
export declare const ARKTS_STATIC_MARK = "use static";
|
|
22
23
|
//# sourceMappingURL=Const.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Const.d.ts","sourceRoot":"","sources":["../../../src/core/common/Const.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,SAAS,CAAC;AAGnC,eAAO,MAAM,sBAAsB,QAA6B,CAAC;AACjE,eAAO,MAAM,sBAAsB,QAAqB,CAAC;AACzD,eAAO,MAAM,yBAAyB,MAAiB,CAAC;AAGxD,eAAO,MAAM,uBAAuB,QAA6B,CAAC;AAClE,eAAO,MAAM,yBAAyB,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KAAK,CAAC;AACrC,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAGtC,eAAO,MAAM,iBAAiB,MAAc,CAAC;AAC7C,eAAO,MAAM,uBAAuB,QAAiC,CAAC;AAGtE,eAAO,MAAM,iBAAiB,eAAe,CAAC"}
|
package/lib/core/common/Const.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX = exports.UNKNOWN_METHOD_NAME = exports.UNKNOWN_FIELD_NAME = exports.UNKNOWN_CLASS_NAME = exports.UNKNOWN_NAMESPACE_NAME = exports.UNKNOWN_FILE_NAME = exports.UNKNOWN_PROJECT_NAME = exports.CALL_SIGNATURE_NAME = exports.ANONYMOUS_METHOD_PREFIX = exports.STATIC_BLOCK_METHOD_NAME_PREFIX = exports.STATIC_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.DEFAULT_ARK_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_CLASS_NAME = exports.DEFAULT_NAME = exports.UNKNOWN_NAME = exports.NAME_PREFIX = exports.NAME_DELIMITER = void 0;
|
|
17
|
+
exports.ARKTS_STATIC_MARK = exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX = exports.UNKNOWN_METHOD_NAME = exports.UNKNOWN_FIELD_NAME = exports.UNKNOWN_CLASS_NAME = exports.UNKNOWN_NAMESPACE_NAME = exports.UNKNOWN_FILE_NAME = exports.UNKNOWN_PROJECT_NAME = exports.CALL_SIGNATURE_NAME = exports.ANONYMOUS_METHOD_PREFIX = exports.STATIC_BLOCK_METHOD_NAME_PREFIX = exports.STATIC_INIT_METHOD_NAME = exports.INSTANCE_INIT_METHOD_NAME = exports.DEFAULT_ARK_METHOD_NAME = exports.ANONYMOUS_CLASS_DELIMITER = exports.ANONYMOUS_CLASS_PREFIX = exports.DEFAULT_ARK_CLASS_NAME = exports.DEFAULT_NAME = exports.UNKNOWN_NAME = exports.NAME_PREFIX = exports.NAME_DELIMITER = void 0;
|
|
18
18
|
// names
|
|
19
19
|
exports.NAME_DELIMITER = '$';
|
|
20
20
|
exports.NAME_PREFIX = '%';
|
|
@@ -41,3 +41,5 @@ exports.UNKNOWN_METHOD_NAME = ''; // temp for being compatible with existing typ
|
|
|
41
41
|
// IR const
|
|
42
42
|
exports.TEMP_LOCAL_PREFIX = exports.NAME_PREFIX;
|
|
43
43
|
exports.LEXICAL_ENV_NAME_PREFIX = exports.TEMP_LOCAL_PREFIX + 'closures';
|
|
44
|
+
// ArkTS version
|
|
45
|
+
exports.ARKTS_STATIC_MARK = 'use static';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"DummyMainCreater.d.ts","sourceRoot":"","sources":["../../../src/core/common/DummyMainCreater.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAmBpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAQ/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA2C;IAChE,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAAa;gBAEvB,KAAK,EAAE,KAAK;IAUjB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI;IAI3C,eAAe,IAAI,IAAI;IAqD9B,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,YAAY;IAyBpB,OAAO,CAAC,WAAW;IAqCnB,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,WAAW;IAYZ,YAAY,IAAI,SAAS;IAIhC,OAAO,CAAC,6BAA6B;IAmBrC,OAAO,CAAC,oBAAoB;IAerB,0BAA0B,IAAI,SAAS,EAAE;IAUzC,kBAAkB,IAAI,SAAS,EAAE;CAiB3C"}
|
|
@@ -73,7 +73,7 @@ class DummyMainCreater {
|
|
|
73
73
|
}
|
|
74
74
|
createDummyMain() {
|
|
75
75
|
var _a;
|
|
76
|
-
const dummyMainFile = new ArkFile_1.ArkFile();
|
|
76
|
+
const dummyMainFile = new ArkFile_1.ArkFile(ArkFile_1.Language.UNKNOWN);
|
|
77
77
|
dummyMainFile.setScene(this.scene);
|
|
78
78
|
const dummyMainFileSignature = new ArkSignature_1.FileSignature(this.scene.getProjectName(), '@dummyFile');
|
|
79
79
|
dummyMainFile.setFileSignature(dummyMainFileSignature);
|
|
@@ -5,7 +5,7 @@ import { AbstractExpr, AbstractInvokeExpr, AliasTypeExpr, ArkInstanceInvokeExpr,
|
|
|
5
5
|
import { Scene } from '../../Scene';
|
|
6
6
|
import { ArkClass } from '../model/ArkClass';
|
|
7
7
|
import { ClassSignature, MethodSignature } from '../model/ArkSignature';
|
|
8
|
-
import { AbstractRef, ArkInstanceFieldRef } from '../base/Ref';
|
|
8
|
+
import { AbstractRef, ArkInstanceFieldRef, ArkParameterRef } from '../base/Ref';
|
|
9
9
|
import { ArkFile } from '../model/ArkFile';
|
|
10
10
|
import { KeyofTypeExpr, TypeQueryExpr } from '../base/TypeExpr';
|
|
11
11
|
export declare class IRInference {
|
|
@@ -14,14 +14,22 @@ export declare class IRInference {
|
|
|
14
14
|
static inferFile(file: ArkFile): void;
|
|
15
15
|
static inferStaticInvokeExpr(expr: ArkStaticInvokeExpr, arkMethod: ArkMethod): AbstractInvokeExpr;
|
|
16
16
|
private static inferStaticInvokeExprByMethodName;
|
|
17
|
-
private static generateNewMethodSignature;
|
|
18
17
|
static inferInstanceInvokeExpr(expr: ArkInstanceInvokeExpr, arkMethod: ArkMethod): AbstractInvokeExpr;
|
|
18
|
+
/**
|
|
19
|
+
* process arkUI function with Annotation @Extend @Styles @AnimatableExtend
|
|
20
|
+
* @param expr
|
|
21
|
+
* @param arkMethod
|
|
22
|
+
* @param methodName
|
|
23
|
+
*/
|
|
24
|
+
private static processExtendFunc;
|
|
19
25
|
static inferFieldRef(ref: ArkInstanceFieldRef, arkMethod: ArkMethod): AbstractRef;
|
|
20
26
|
private static inferArgs;
|
|
21
27
|
private static inferArg;
|
|
22
28
|
static inferRightWithSdkType(leftType: Type, rightType: Type, ackClass: ArkClass): void;
|
|
23
29
|
static inferArgTypeWithSdk(sdkType: ClassType, scene: Scene, argType: Type): void;
|
|
24
30
|
private static inferInvokeExpr;
|
|
31
|
+
private static inferInvokeExprWithArray;
|
|
32
|
+
private static inferInvokeExprWithFunction;
|
|
25
33
|
private static inferInvokeExprWithDeclaredClass;
|
|
26
34
|
private static getRealTypes;
|
|
27
35
|
static replaceMethodSignature(init: MethodSignature, declared: MethodSignature): MethodSignature;
|
|
@@ -33,5 +41,6 @@ export declare class IRInference {
|
|
|
33
41
|
static inferAliasTypeExpr(expr: AliasTypeExpr, arkMethod: ArkMethod): AbstractExpr;
|
|
34
42
|
static inferTypeQueryExpr(expr: TypeQueryExpr, arkMethod: ArkMethod): void;
|
|
35
43
|
static inferKeyofTypeExpr(expr: KeyofTypeExpr, arkMethod: ArkMethod): void;
|
|
44
|
+
static inferParameterRef(ref: ArkParameterRef, arkMethod: ArkMethod): AbstractRef;
|
|
36
45
|
}
|
|
37
46
|
//# sourceMappingURL=IRInference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IRInference.d.ts","sourceRoot":"","sources":["../../../src/core/common/I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S,GAAG,WAAW;CAmB3F"}
|
|
@@ -126,8 +126,7 @@ class IRInference {
|
|
|
126
126
|
}
|
|
127
127
|
return expr;
|
|
128
128
|
}
|
|
129
|
-
this.inferStaticInvokeExprByMethodName(methodName, arkMethod, expr);
|
|
130
|
-
return expr;
|
|
129
|
+
return this.inferStaticInvokeExprByMethodName(methodName, arkMethod, expr);
|
|
131
130
|
}
|
|
132
131
|
static inferStaticInvokeExprByMethodName(methodName, arkMethod, expr) {
|
|
133
132
|
var _a, _b, _c, _d, _e;
|
|
@@ -159,31 +158,36 @@ class IRInference {
|
|
|
159
158
|
TypeInference_1.TypeInference.inferSignatureReturnType(signature, method);
|
|
160
159
|
}
|
|
161
160
|
if (signature) {
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
if (arkExport instanceof Local_1.Local) {
|
|
162
|
+
expr = new Expr_1.ArkPtrInvokeExpr(signature, arkExport, expr.getArgs(), expr.getRealGenericTypes());
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
expr.setMethodSignature(signature);
|
|
166
|
+
}
|
|
164
167
|
this.inferArgs(expr, arkMethod);
|
|
165
168
|
}
|
|
166
|
-
|
|
167
|
-
static generateNewMethodSignature(methodName, signature) {
|
|
168
|
-
if (signature.getMethodSubSignature().getMethodName().startsWith(Const_1.ANONYMOUS_METHOD_PREFIX)) {
|
|
169
|
-
const subSignature = signature.getMethodSubSignature();
|
|
170
|
-
const newSubSignature = new ArkSignature_1.MethodSubSignature(methodName, subSignature.getParameters(), subSignature.getReturnType(), subSignature.isStatic());
|
|
171
|
-
return new ArkSignature_1.MethodSignature(signature.getDeclaringClassSignature(), newSubSignature);
|
|
172
|
-
}
|
|
173
|
-
return signature;
|
|
169
|
+
return expr;
|
|
174
170
|
}
|
|
175
171
|
static inferInstanceInvokeExpr(expr, arkMethod) {
|
|
172
|
+
var _a, _b, _c;
|
|
176
173
|
const arkClass = arkMethod.getDeclaringArkClass();
|
|
177
174
|
TypeInference_1.TypeInference.inferRealGenericTypes(expr.getRealGenericTypes(), arkClass);
|
|
178
175
|
this.inferLocal(expr.getBase(), arkMethod);
|
|
179
176
|
const baseType = TypeInference_1.TypeInference.replaceAliasType(expr.getBase().getType());
|
|
180
|
-
|
|
177
|
+
let methodName = expr.getMethodSignature().getMethodSubSignature().getMethodName();
|
|
178
|
+
if (methodName.startsWith(Const_1.NAME_PREFIX)) {
|
|
179
|
+
const declaringStmt = (_b = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(methodName)) === null || _b === void 0 ? void 0 : _b.getDeclaringStmt();
|
|
180
|
+
if (declaringStmt instanceof Stmt_1.ArkAssignStmt && declaringStmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
181
|
+
const rightOp = declaringStmt.getRightOp();
|
|
182
|
+
methodName = rightOp.getBase().getName() + '.' + rightOp.getFieldName();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
181
185
|
const scene = arkClass.getDeclaringArkFile().getScene();
|
|
182
186
|
if ((methodName === 'forEach') && (baseType instanceof Type_1.ArrayType)) {
|
|
183
187
|
this.processForEach(expr.getArg(0), baseType, scene);
|
|
184
188
|
return expr;
|
|
185
189
|
}
|
|
186
|
-
let result = this.inferInvokeExpr(expr, baseType, methodName, scene);
|
|
190
|
+
let result = (_c = this.inferInvokeExpr(expr, baseType, methodName, scene)) !== null && _c !== void 0 ? _c : this.processExtendFunc(expr, arkMethod, methodName);
|
|
187
191
|
if (result) {
|
|
188
192
|
this.inferArgs(result, arkMethod);
|
|
189
193
|
return result;
|
|
@@ -191,6 +195,28 @@ class IRInference {
|
|
|
191
195
|
logger.warn('invoke ArkInstanceInvokeExpr MethodSignature type fail: ', expr.toString());
|
|
192
196
|
return expr;
|
|
193
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* process arkUI function with Annotation @Extend @Styles @AnimatableExtend
|
|
200
|
+
* @param expr
|
|
201
|
+
* @param arkMethod
|
|
202
|
+
* @param methodName
|
|
203
|
+
*/
|
|
204
|
+
static processExtendFunc(expr, arkMethod, methodName) {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
const type = TypeInference_1.TypeInference.inferBaseType(methodName, arkMethod.getDeclaringArkClass());
|
|
207
|
+
if (type instanceof Type_1.FunctionType) {
|
|
208
|
+
const methodSignature = type.getMethodSignature();
|
|
209
|
+
// because of last stmt is ArkReturnVoidStmt, the ArkInvokeStmt at -2 before ArkReturnVoidStmt.
|
|
210
|
+
const endIndex = -2;
|
|
211
|
+
const endStmt = (_b = (_a = arkMethod.getDeclaringArkFile().getScene().getMethod(methodSignature)) === null || _a === void 0 ? void 0 : _a.getCfg()) === null || _b === void 0 ? void 0 : _b.getStmts().at(endIndex);
|
|
212
|
+
if (endStmt instanceof Stmt_1.ArkInvokeStmt) {
|
|
213
|
+
methodSignature.getMethodSubSignature().setReturnType(endStmt.getInvokeExpr().getType());
|
|
214
|
+
}
|
|
215
|
+
expr.setMethodSignature(methodSignature);
|
|
216
|
+
return expr;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
194
220
|
static inferFieldRef(ref, arkMethod) {
|
|
195
221
|
this.inferLocal(ref.getBase(), arkMethod);
|
|
196
222
|
const baseType = TypeInference_1.TypeInference.replaceAliasType(ref.getBase().getType());
|
|
@@ -236,6 +262,11 @@ class IRInference {
|
|
|
236
262
|
else if (paramType instanceof Type_1.ArrayType && argType instanceof Type_1.ArrayType) {
|
|
237
263
|
this.inferArg(expr, argType.getBaseType(), paramType.getBaseType(), scene, realTypes);
|
|
238
264
|
}
|
|
265
|
+
else if (expr instanceof Expr_1.ArkInstanceInvokeExpr && expr.getBase().getType() instanceof Type_1.ArrayType) {
|
|
266
|
+
if (paramType instanceof Type_1.ArrayType && paramType.getBaseType() instanceof Type_1.GenericType) {
|
|
267
|
+
this.inferArg(expr, argType, expr.getBase().getType().getBaseType(), scene, realTypes);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
239
270
|
if (paramType instanceof Type_1.ClassType && scene.getProjectSdkMap().has(paramType.getClassSignature()
|
|
240
271
|
.getDeclaringFileSignature().getProjectName())) {
|
|
241
272
|
this.inferArgTypeWithSdk(paramType, scene, argType);
|
|
@@ -244,9 +275,12 @@ class IRInference {
|
|
|
244
275
|
realTypes.push(argType);
|
|
245
276
|
}
|
|
246
277
|
else if (paramType instanceof Type_1.FunctionType && argType instanceof Type_1.FunctionType) {
|
|
247
|
-
const
|
|
278
|
+
const method = scene.getMethod(argType.getMethodSignature());
|
|
279
|
+
if (method) {
|
|
280
|
+
TypeInference_1.TypeInference.inferTypeInMethod(method);
|
|
281
|
+
}
|
|
248
282
|
const realTypes = expr.getRealGenericTypes();
|
|
249
|
-
TypeInference_1.TypeInference.inferFunctionType(argType,
|
|
283
|
+
TypeInference_1.TypeInference.inferFunctionType(argType, paramType.getMethodSignature().getMethodSubSignature(), realTypes);
|
|
250
284
|
}
|
|
251
285
|
}
|
|
252
286
|
static inferRightWithSdkType(leftType, rightType, ackClass) {
|
|
@@ -262,7 +296,7 @@ class IRInference {
|
|
|
262
296
|
else if (rightType instanceof Type_1.ArrayType && leftType instanceof Type_1.ArrayType) {
|
|
263
297
|
const baseType = TypeInference_1.TypeInference.replaceAliasType(leftType.getBaseType());
|
|
264
298
|
if (baseType instanceof Type_1.ClassType) {
|
|
265
|
-
IRInference.inferArgTypeWithSdk(baseType, ackClass.getDeclaringArkFile().getScene(), rightType);
|
|
299
|
+
IRInference.inferArgTypeWithSdk(baseType, ackClass.getDeclaringArkFile().getScene(), rightType.getBaseType());
|
|
266
300
|
}
|
|
267
301
|
}
|
|
268
302
|
}
|
|
@@ -278,9 +312,9 @@ class IRInference {
|
|
|
278
312
|
this.inferAnonymousClass(scene.getClass(argType.getClassSignature()), sdkType.getClassSignature());
|
|
279
313
|
}
|
|
280
314
|
else if (argType instanceof Type_1.FunctionType) {
|
|
281
|
-
const
|
|
315
|
+
const param = (_b = (_a = scene.getClass(sdkType.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethodWithName(Const_1.CALL_SIGNATURE_NAME)) === null || _b === void 0 ? void 0 : _b.getSignature().getMethodSubSignature();
|
|
282
316
|
const realTypes = sdkType.getRealGenericTypes();
|
|
283
|
-
TypeInference_1.TypeInference.inferFunctionType(argType,
|
|
317
|
+
TypeInference_1.TypeInference.inferFunctionType(argType, param, realTypes);
|
|
284
318
|
}
|
|
285
319
|
}
|
|
286
320
|
static inferInvokeExpr(expr, baseType, methodName, scene) {
|
|
@@ -315,14 +349,41 @@ class IRInference {
|
|
|
315
349
|
}
|
|
316
350
|
}
|
|
317
351
|
else if (baseType instanceof Type_1.FunctionType) {
|
|
318
|
-
|
|
319
|
-
|
|
352
|
+
return IRInference.inferInvokeExprWithFunction(methodName, expr, baseType, scene);
|
|
353
|
+
}
|
|
354
|
+
else if (baseType instanceof Type_1.ArrayType) {
|
|
355
|
+
return IRInference.inferInvokeExprWithArray(methodName, expr, baseType, scene);
|
|
320
356
|
}
|
|
321
|
-
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
static inferInvokeExprWithArray(methodName, expr, baseType, scene) {
|
|
360
|
+
if (methodName === Builtin_1.Builtin.ITERATOR_FUNCTION) {
|
|
322
361
|
const returnType = expr.getMethodSignature().getMethodSubSignature().getReturnType();
|
|
323
362
|
if (returnType instanceof Type_1.ClassType && returnType.getClassSignature().getDeclaringFileSignature()
|
|
324
363
|
.getProjectName() === Builtin_1.Builtin.DUMMY_PROJECT_NAME) {
|
|
325
|
-
|
|
364
|
+
expr.setRealGenericTypes([baseType.getBaseType()]);
|
|
365
|
+
return expr;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
const arrayInterface = scene.getSdkGlobal(Builtin_1.Builtin.ARRAY);
|
|
370
|
+
if (arrayInterface instanceof ArkClass_1.ArkClass) {
|
|
371
|
+
return this.inferInvokeExpr(expr, new Type_1.ClassType(arrayInterface.getSignature(), [baseType.getBaseType()]), methodName, scene);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
static inferInvokeExprWithFunction(methodName, expr, baseType, scene) {
|
|
377
|
+
if (methodName === Const_1.CALL_SIGNATURE_NAME) {
|
|
378
|
+
expr.setMethodSignature(baseType.getMethodSignature());
|
|
379
|
+
return expr;
|
|
380
|
+
}
|
|
381
|
+
const funcInterface = scene.getSdkGlobal(TSConst_1.FUNCTION);
|
|
382
|
+
if (funcInterface instanceof ArkClass_1.ArkClass) {
|
|
383
|
+
const method = ModelUtils_1.ModelUtils.findPropertyInClass(methodName, funcInterface);
|
|
384
|
+
if (method instanceof ArkMethod_1.ArkMethod) {
|
|
385
|
+
expr.setRealGenericTypes([baseType]);
|
|
386
|
+
expr.setMethodSignature(method.getSignature());
|
|
326
387
|
return expr;
|
|
327
388
|
}
|
|
328
389
|
}
|
|
@@ -350,17 +411,22 @@ class IRInference {
|
|
|
350
411
|
}
|
|
351
412
|
else if (method instanceof ArkField_1.ArkField) {
|
|
352
413
|
const type = method.getType();
|
|
414
|
+
let methodSignature;
|
|
353
415
|
if (type instanceof Type_1.FunctionType) {
|
|
354
|
-
|
|
355
|
-
return expr;
|
|
416
|
+
methodSignature = type.getMethodSignature();
|
|
356
417
|
}
|
|
357
418
|
else if (type instanceof Type_1.ClassType && type.getClassSignature().getClassName().endsWith(EtsConst_1.CALL_BACK)) {
|
|
358
419
|
const callback = (_a = scene.getClass(type.getClassSignature())) === null || _a === void 0 ? void 0 : _a.getMethodWithName(Const_1.CALL_SIGNATURE_NAME);
|
|
359
420
|
if (callback) {
|
|
360
|
-
|
|
361
|
-
return expr;
|
|
421
|
+
methodSignature = callback.getSignature();
|
|
362
422
|
}
|
|
363
423
|
}
|
|
424
|
+
if (methodSignature) {
|
|
425
|
+
const ptr = expr instanceof Expr_1.ArkInstanceInvokeExpr ?
|
|
426
|
+
new Ref_1.ArkInstanceFieldRef(expr.getBase(), method.getSignature()) : new Ref_1.ArkStaticFieldRef(method.getSignature());
|
|
427
|
+
expr = new Expr_1.ArkPtrInvokeExpr(methodSignature, ptr, expr.getArgs(), expr.getRealGenericTypes());
|
|
428
|
+
}
|
|
429
|
+
return expr;
|
|
364
430
|
}
|
|
365
431
|
else if (methodName === TSConst_1.CONSTRUCTOR_NAME) { //sdk隐式构造
|
|
366
432
|
const subSignature = new ArkSignature_1.MethodSubSignature(methodName, [], new Type_1.ClassType(baseType.getClassSignature()));
|
|
@@ -429,7 +495,13 @@ class IRInference {
|
|
|
429
495
|
var _a, _b, _c;
|
|
430
496
|
const arkClass = arkMethod.getDeclaringArkClass();
|
|
431
497
|
if (base.getName() === TSConst_1.THIS_NAME) {
|
|
432
|
-
if (
|
|
498
|
+
if (arkClass.isAnonymousClass()) {
|
|
499
|
+
const thisType = TypeInference_1.TypeInference.inferBaseType(arkClass.getSignature().getDeclaringClassName(), arkClass);
|
|
500
|
+
if (thisType instanceof Type_1.ClassType) {
|
|
501
|
+
base.setType(thisType);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
433
505
|
base.setType(new Type_1.ClassType(arkClass.getSignature(), arkClass.getGenericsTypes()));
|
|
434
506
|
}
|
|
435
507
|
return;
|
|
@@ -444,7 +516,7 @@ class IRInference {
|
|
|
444
516
|
baseType = (_c = (_b = ModelUtils_1.ModelUtils.findDeclaredLocal(base, arkMethod)) === null || _b === void 0 ? void 0 : _b.getType()) !== null && _c !== void 0 ? _c : TypeInference_1.TypeInference.inferBaseType(base.getName(), arkClass);
|
|
445
517
|
}
|
|
446
518
|
}
|
|
447
|
-
if (baseType && !TypeInference_1.TypeInference.isUnclearType(baseType)) {
|
|
519
|
+
if (baseType instanceof Type_1.UnionType || (baseType && !TypeInference_1.TypeInference.isUnclearType(baseType))) {
|
|
448
520
|
base.setType(baseType);
|
|
449
521
|
}
|
|
450
522
|
}
|
|
@@ -547,6 +619,9 @@ class IRInference {
|
|
|
547
619
|
deepInfer(rightType.getBaseType(), classSignature);
|
|
548
620
|
}
|
|
549
621
|
}
|
|
622
|
+
else if (type instanceof Type_1.FunctionType && rightType instanceof Type_1.FunctionType) {
|
|
623
|
+
TypeInference_1.TypeInference.inferFunctionType(rightType, type.getMethodSignature().getMethodSubSignature(), type.getRealGenericTypes());
|
|
624
|
+
}
|
|
550
625
|
const leftOp = lastStmt.getLeftOp();
|
|
551
626
|
if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
552
627
|
leftOp.setFieldSignature(property.getSignature());
|
|
@@ -647,5 +722,26 @@ class IRInference {
|
|
|
647
722
|
}
|
|
648
723
|
}
|
|
649
724
|
}
|
|
725
|
+
static inferParameterRef(ref, arkMethod) {
|
|
726
|
+
var _a;
|
|
727
|
+
const paramType = ref.getType();
|
|
728
|
+
if (paramType instanceof Type_1.UnknownType || paramType instanceof Type_1.UnclearReferenceType) {
|
|
729
|
+
const type1 = (_a = arkMethod.getSignature().getMethodSubSignature().getParameters()[ref.getIndex()]) === null || _a === void 0 ? void 0 : _a.getType();
|
|
730
|
+
if (!TypeInference_1.TypeInference.isUnclearType(type1)) {
|
|
731
|
+
ref.setType(type1);
|
|
732
|
+
return ref;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
else if (paramType instanceof Type_1.LexicalEnvType) {
|
|
736
|
+
paramType.getClosures().filter(c => TypeInference_1.TypeInference.isUnclearType(c.getType()))
|
|
737
|
+
.forEach(e => this.inferLocal(e, arkMethod));
|
|
738
|
+
return ref;
|
|
739
|
+
}
|
|
740
|
+
let type = TypeInference_1.TypeInference.inferUnclearedType(paramType, arkMethod.getDeclaringArkClass());
|
|
741
|
+
if (type) {
|
|
742
|
+
ref.setType(type);
|
|
743
|
+
}
|
|
744
|
+
return ref;
|
|
745
|
+
}
|
|
650
746
|
}
|
|
651
747
|
exports.IRInference = IRInference;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelUtils.d.ts","sourceRoot":"","sources":["../../../src/core/common/ModelUtils.ts"],"names":[],"mappings":"AAeA,OAAO,E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qB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,IAAI;WA4BvF,uBAAuB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,IAAI;WAyBxF,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI;CAehF;AAKD,eAAO,MAAM,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAA8B,CAAC;AAE7E;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CA6BnE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,IAAI,CA4BpE;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CA4BlF;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAiB7F;AAqED,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,GAAG,IAAI,CAK9F"}
|
|
@@ -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
|
|
@@ -56,6 +56,8 @@ const ArkExportBuilder_1 = require("../model/builder/ArkExportBuilder");
|
|
|
56
56
|
const Type_1 = require("../base/Type");
|
|
57
57
|
const Const_1 = require("./Const");
|
|
58
58
|
const ValueUtil_1 = require("./ValueUtil");
|
|
59
|
+
const Stmt_1 = require("../base/Stmt");
|
|
60
|
+
const Ref_1 = require("../base/Ref");
|
|
59
61
|
class ModelUtils {
|
|
60
62
|
static getMethodSignatureFromArkClass(arkClass, methodName) {
|
|
61
63
|
for (const arkMethod of arkClass.getMethods()) {
|
|
@@ -346,7 +348,7 @@ class ModelUtils {
|
|
|
346
348
|
return null;
|
|
347
349
|
}
|
|
348
350
|
static findDeclaredLocal(local, arkMethod, times = 0) {
|
|
349
|
-
var _a, _b, _c;
|
|
351
|
+
var _a, _b, _c, _d;
|
|
350
352
|
if (arkMethod.getDeclaringArkFile().getScene().getOptions().isScanAbc) {
|
|
351
353
|
return null;
|
|
352
354
|
}
|
|
@@ -354,13 +356,14 @@ class ModelUtils {
|
|
|
354
356
|
if (name === TSConst_1.THIS_NAME || name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
355
357
|
return null;
|
|
356
358
|
}
|
|
359
|
+
const parameter = arkMethod.getParameters().find(p => p.getName() === name);
|
|
360
|
+
if (parameter) {
|
|
361
|
+
return new Local_1.Local(parameter.getName(), parameter.getType());
|
|
362
|
+
}
|
|
357
363
|
if (times > 0) {
|
|
358
|
-
const parameter = arkMethod.getParameters().find(p => p.getName() === name);
|
|
359
|
-
if (parameter) {
|
|
360
|
-
return new Local_1.Local(parameter.getName(), parameter.getType());
|
|
361
|
-
}
|
|
362
364
|
const declaredLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
|
|
363
|
-
if (declaredLocal && declaredLocal.getDeclaringStmt()
|
|
365
|
+
if (declaredLocal && declaredLocal.getDeclaringStmt() instanceof Stmt_1.ArkAssignStmt &&
|
|
366
|
+
!(declaredLocal.getDeclaringStmt().getRightOp() instanceof Ref_1.ClosureFieldRef)) {
|
|
364
367
|
return declaredLocal;
|
|
365
368
|
}
|
|
366
369
|
}
|
|
@@ -368,15 +371,18 @@ class ModelUtils {
|
|
|
368
371
|
if (parentName === Const_1.DEFAULT_ARK_METHOD_NAME) {
|
|
369
372
|
return null;
|
|
370
373
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
374
|
+
let invokeMethod = arkMethod.getOuterMethod();
|
|
375
|
+
if (!invokeMethod) {
|
|
376
|
+
const className = arkMethod.getDeclaringArkClass().getName();
|
|
377
|
+
const outerStart = className.indexOf(Const_1.NAME_DELIMITER);
|
|
378
|
+
const outerEnd = className.lastIndexOf('.');
|
|
379
|
+
if (outerStart > -1 && outerEnd > -1) {
|
|
380
|
+
invokeMethod = (_b = arkMethod.getDeclaringArkFile().getClassWithName(className.substring(outerStart + 1, outerEnd))) === null || _b === void 0 ? void 0 : _b.getMethodWithName(className.substring(outerEnd + 1));
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const cls = arkMethod.getDeclaringArkClass();
|
|
384
|
+
invokeMethod = (_c = cls.getDefaultArkMethod()) !== null && _c !== void 0 ? _c : (_d = cls.getDeclaringArkFile().getDefaultClass()) === null || _d === void 0 ? void 0 : _d.getDefaultArkMethod();
|
|
385
|
+
}
|
|
380
386
|
}
|
|
381
387
|
if (invokeMethod) {
|
|
382
388
|
return this.findDeclaredLocal(local, invokeMethod, ++times);
|
|
@@ -478,7 +484,6 @@ exports.ModelUtils = ModelUtils;
|
|
|
478
484
|
ModelUtils.implicitArkUIBuilderMethods = new Set();
|
|
479
485
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ModelUtils');
|
|
480
486
|
let moduleMap;
|
|
481
|
-
const fileSuffixArray = ['.ets', '.ts', '.d.ets', '.d.ts'];
|
|
482
487
|
exports.sdkImportMap = new Map();
|
|
483
488
|
/**
|
|
484
489
|
* find arkFile by from info
|
|
@@ -626,6 +631,10 @@ function getArkFileFormMap(projectName, filePath, scene) {
|
|
|
626
631
|
if (/\.e?ts$/.test(filePath)) {
|
|
627
632
|
return scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath));
|
|
628
633
|
}
|
|
634
|
+
const fileSuffixArray = scene.getOptions().supportFileExts;
|
|
635
|
+
if (!fileSuffixArray) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
629
638
|
for (const suffix of fileSuffixArray) {
|
|
630
639
|
const arkFile = scene.getFile(new ArkSignature_1.FileSignature(projectName, filePath + suffix));
|
|
631
640
|
if (arkFile) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ArkFile } from '../model/ArkFile';
|
|
2
2
|
import { ArkExport } from '../model/ArkExport';
|
|
3
|
+
import { ArkMethod } from '../model/ArkMethod';
|
|
4
|
+
import { AbstractFieldRef } from '../base/Ref';
|
|
3
5
|
export declare class SdkUtils {
|
|
4
6
|
static buildGlobalMap(file: ArkFile, globalMap: Map<string, ArkExport>): void;
|
|
5
7
|
private static loadClass;
|
|
6
8
|
private static loadGlobalLocal;
|
|
7
9
|
private static copyMethod;
|
|
10
|
+
static computeGlobalThis(leftOp: AbstractFieldRef, arkMethod: ArkMethod): void;
|
|
8
11
|
}
|
|
9
12
|
//# sourceMappingURL=SdkUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdkUtils.d.ts","sourceRoot":"","sources":["../../../src/core/common/SdkUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"SdkUtils.d.ts","sourceRoot":"","sources":["../../../src/core/common/SdkUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAQ3D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,qBAAa,QAAQ;WAEH,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI;IAiCpF,OAAO,CAAC,MAAM,CAAC,SAAS;IAexB,OAAO,CAAC,MAAM,CAAC,eAAe;IAyB9B,OAAO,CAAC,MAAM,CAAC,UAAU;WAYX,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;CAQxF"}
|