arkanalyzer 1.0.8 → 1.0.9
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/callgraph/model/CallGraph.js +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +4 -4
- package/lib/core/base/Expr.js +3 -3
- package/lib/core/common/ArkError.js +1 -1
- package/lib/core/common/ArkIRTransformer.d.ts +2 -6
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +13 -23
- package/lib/core/common/Builtin.js +1 -1
- package/lib/core/common/CfgBuilder.d.ts +0 -12
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +61 -284
- package/lib/core/common/IRUtils.d.ts +0 -1
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +0 -5
- package/lib/core/model/ArkBaseModel.js +1 -1
- package/lib/core/model/ArkClass.js +1 -1
- package/lib/core/model/ArkExport.js +1 -1
- package/lib/core/model/ArkField.js +1 -1
- package/lib/core/model/ArkMetadata.js +1 -1
- package/lib/utils/CfgStructualAnalysis.js +1 -1
- package/lib/utils/entryMethodUtils.js +23 -23
- package/lib/utils/logger.js +2 -2
- package/package.json +1 -1
- package/docs/IR2ts-stmt.md +0 -81
- package/docs/IR2ts.md +0 -82
|
@@ -26,7 +26,7 @@ var CallGraphNodeKind;
|
|
|
26
26
|
CallGraphNodeKind[CallGraphNodeKind["vitual"] = 1] = "vitual";
|
|
27
27
|
CallGraphNodeKind[CallGraphNodeKind["intrinsic"] = 2] = "intrinsic";
|
|
28
28
|
CallGraphNodeKind[CallGraphNodeKind["constructor"] = 3] = "constructor";
|
|
29
|
-
})(CallGraphNodeKind
|
|
29
|
+
})(CallGraphNodeKind || (exports.CallGraphNodeKind = CallGraphNodeKind = {}));
|
|
30
30
|
class CallSite {
|
|
31
31
|
constructor(s, a, ce, cr) {
|
|
32
32
|
this.callStmt = s;
|
|
@@ -64,21 +64,21 @@ var PagEdgeKind;
|
|
|
64
64
|
PagEdgeKind[PagEdgeKind["This"] = 4] = "This";
|
|
65
65
|
PagEdgeKind[PagEdgeKind["Unknown"] = 5] = "Unknown";
|
|
66
66
|
PagEdgeKind[PagEdgeKind["InterProceduralCopy"] = 6] = "InterProceduralCopy";
|
|
67
|
-
})(PagEdgeKind
|
|
67
|
+
})(PagEdgeKind || (exports.PagEdgeKind = PagEdgeKind = {}));
|
|
68
68
|
;
|
|
69
69
|
var StorageType;
|
|
70
70
|
(function (StorageType) {
|
|
71
71
|
StorageType[StorageType["APP_STORAGE"] = 0] = "APP_STORAGE";
|
|
72
72
|
StorageType[StorageType["LOCAL_STORAGE"] = 1] = "LOCAL_STORAGE";
|
|
73
73
|
StorageType[StorageType["Undefined"] = 2] = "Undefined";
|
|
74
|
-
})(StorageType
|
|
74
|
+
})(StorageType || (exports.StorageType = StorageType = {}));
|
|
75
75
|
;
|
|
76
76
|
var StorageLinkEdgeType;
|
|
77
77
|
(function (StorageLinkEdgeType) {
|
|
78
78
|
StorageLinkEdgeType[StorageLinkEdgeType["Property2Local"] = 0] = "Property2Local";
|
|
79
79
|
StorageLinkEdgeType[StorageLinkEdgeType["Local2Property"] = 1] = "Local2Property";
|
|
80
80
|
StorageLinkEdgeType[StorageLinkEdgeType["TwoWay"] = 2] = "TwoWay";
|
|
81
|
-
})(StorageLinkEdgeType
|
|
81
|
+
})(StorageLinkEdgeType || (exports.StorageLinkEdgeType = StorageLinkEdgeType = {}));
|
|
82
82
|
class PagEdge extends BaseGraph_1.BaseEdge {
|
|
83
83
|
constructor(n, d, k, s) {
|
|
84
84
|
super(n, d, k);
|
|
@@ -154,7 +154,7 @@ var PagNodeKind;
|
|
|
154
154
|
PagNodeKind[PagNodeKind["Function"] = 5] = "Function";
|
|
155
155
|
PagNodeKind[PagNodeKind["GlobalThis"] = 6] = "GlobalThis";
|
|
156
156
|
PagNodeKind[PagNodeKind["ExportInfo"] = 7] = "ExportInfo";
|
|
157
|
-
})(PagNodeKind
|
|
157
|
+
})(PagNodeKind || (exports.PagNodeKind = PagNodeKind = {}));
|
|
158
158
|
class PagNode extends BaseGraph_1.BaseNode {
|
|
159
159
|
constructor(id, cid = undefined, value, k, s) {
|
|
160
160
|
super(id, k);
|
package/lib/core/base/Expr.js
CHANGED
|
@@ -710,7 +710,7 @@ var NormalBinaryOperator;
|
|
|
710
710
|
// Logical
|
|
711
711
|
NormalBinaryOperator["LogicalAnd"] = "&&";
|
|
712
712
|
NormalBinaryOperator["LogicalOr"] = "||";
|
|
713
|
-
})(NormalBinaryOperator
|
|
713
|
+
})(NormalBinaryOperator || (exports.NormalBinaryOperator = NormalBinaryOperator = {}));
|
|
714
714
|
var RelationalBinaryOperator;
|
|
715
715
|
(function (RelationalBinaryOperator) {
|
|
716
716
|
RelationalBinaryOperator["LessThan"] = "<";
|
|
@@ -721,7 +721,7 @@ var RelationalBinaryOperator;
|
|
|
721
721
|
RelationalBinaryOperator["InEquality"] = "!=";
|
|
722
722
|
RelationalBinaryOperator["StrictEquality"] = "===";
|
|
723
723
|
RelationalBinaryOperator["StrictInequality"] = "!==";
|
|
724
|
-
})(RelationalBinaryOperator
|
|
724
|
+
})(RelationalBinaryOperator || (exports.RelationalBinaryOperator = RelationalBinaryOperator = {}));
|
|
725
725
|
// 二元运算表达式
|
|
726
726
|
class AbstractBinopExpr extends AbstractExpr {
|
|
727
727
|
constructor(op1, op2, operator) {
|
|
@@ -1030,7 +1030,7 @@ var UnaryOperator;
|
|
|
1030
1030
|
UnaryOperator["Neg"] = "-";
|
|
1031
1031
|
UnaryOperator["BitwiseNot"] = "~";
|
|
1032
1032
|
UnaryOperator["LogicalNot"] = "!";
|
|
1033
|
-
})(UnaryOperator
|
|
1033
|
+
})(UnaryOperator || (exports.UnaryOperator = UnaryOperator = {}));
|
|
1034
1034
|
// unary operation expression
|
|
1035
1035
|
class ArkUnopExpr extends AbstractExpr {
|
|
1036
1036
|
constructor(op, operator) {
|
|
@@ -25,4 +25,4 @@ var ArkErrorCode;
|
|
|
25
25
|
ArkErrorCode[ArkErrorCode["CFG_HAS_UNREACHABLE_BLOCK"] = -5] = "CFG_HAS_UNREACHABLE_BLOCK";
|
|
26
26
|
ArkErrorCode[ArkErrorCode["METHOD_SIGNATURE_UNDEFINED"] = -6] = "METHOD_SIGNATURE_UNDEFINED";
|
|
27
27
|
ArkErrorCode[ArkErrorCode["METHOD_SIGNATURE_LINE_UNMATCHED"] = -7] = "METHOD_SIGNATURE_LINE_UNMATCHED";
|
|
28
|
-
})(ArkErrorCode
|
|
28
|
+
})(ArkErrorCode || (exports.ArkErrorCode = ArkErrorCode = {}));
|
|
@@ -6,6 +6,7 @@ import { Stmt } from '../base/Stmt';
|
|
|
6
6
|
import { AliasType, AliasTypeDeclaration } from '../base/Type';
|
|
7
7
|
import { ArkMethod } from '../model/ArkMethod';
|
|
8
8
|
import { FullPosition } from '../base/Position';
|
|
9
|
+
export declare const DUMMY_INITIALIZER_STMT = "dummyInitializerStmt";
|
|
9
10
|
type ValueAndStmts = {
|
|
10
11
|
value: Value;
|
|
11
12
|
valueOriginalPositions: FullPosition[];
|
|
@@ -16,12 +17,7 @@ export declare class DummyStmt extends Stmt {
|
|
|
16
17
|
toString(): string;
|
|
17
18
|
}
|
|
18
19
|
export declare class ArkIRTransformer {
|
|
19
|
-
|
|
20
|
-
static readonly DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT = "ConditionalOperatorIfTrue";
|
|
21
|
-
static readonly DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT = "ConditionalOperatorIfFalse";
|
|
22
|
-
static readonly DUMMY_CONDITIONAL_OPERATOR_END_STMT = "ConditionalOperatorEnd";
|
|
23
|
-
private conditionalOperatorNo;
|
|
24
|
-
private tempLocalNo;
|
|
20
|
+
private tempLocalIndex;
|
|
25
21
|
private locals;
|
|
26
22
|
private sourceFile;
|
|
27
23
|
private declaringMethod;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkIRTransformer.d.ts","sourceRoot":"","sources":["../../../src/core/common/ArkIRTransformer.ts"],"names":[],"mappings":"AAeA,OAAO,EAkBH,cAAc,EAGd,aAAa,EAChB,MAAM,cAAc,CAAC;AAUtB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAOH,IAAI,EACP,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,SAAS,EACT,oBAAoB,EAkBvB,MAAM,cAAc,CAAC;AAYtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ArkIRTransformer.d.ts","sourceRoot":"","sources":["../../../src/core/common/ArkIRTransformer.ts"],"names":[],"mappings":"AAeA,OAAO,EAkBH,cAAc,EAGd,aAAa,EAChB,MAAM,cAAc,CAAC;AAUtB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAOH,IAAI,EACP,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,SAAS,EACT,oBAAoB,EAkBvB,MAAM,cAAc,CAAC;AAYtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAc/C,OAAO,EAAE,YAAY,EAAmB,MAAM,kBAAkB,CAAC;AASjE,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAE7D,KAAK,aAAa,GAAG;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,sBAAsB,EAAE,YAAY,EAAE,CAAC;IACvC,KAAK,EAAE,IAAI,EAAE,CAAA;CAChB,CAAC;AAEF,qBAAa,SAAU,SAAQ,IAAI;gBACnB,IAAI,EAAE,MAAM;IAKjB,QAAQ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sBAAsB;IAY9B,OAAO,CAAC,uBAAuB;IAO/B,OAAO,CAAC,aAAa;IAed,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI;WAU7C,oBAAoB,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,GAAG,aAAa,GAAG,IAAI;WAchE,qBAAqB,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,GAAG,cAAc,GAAG,IAAI;CAqDnF"}
|
|
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
37
|
return result;
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.ArkIRTransformer = exports.DummyStmt = void 0;
|
|
40
|
+
exports.ArkIRTransformer = exports.DummyStmt = exports.DUMMY_INITIALIZER_STMT = void 0;
|
|
41
41
|
const Expr_1 = require("../base/Expr");
|
|
42
42
|
const Ref_1 = require("../base/Ref");
|
|
43
43
|
const ts = __importStar(require("ohos-typescript"));
|
|
@@ -62,6 +62,7 @@ const TSConst_1 = require("./TSConst");
|
|
|
62
62
|
const builderUtils_1 = require("../model/builder/builderUtils");
|
|
63
63
|
const Const_1 = require("./Const");
|
|
64
64
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ArkIRTransformer');
|
|
65
|
+
exports.DUMMY_INITIALIZER_STMT = 'dummyInitializerStmt';
|
|
65
66
|
class DummyStmt extends Stmt_1.Stmt {
|
|
66
67
|
constructor(text) {
|
|
67
68
|
super();
|
|
@@ -74,8 +75,7 @@ class DummyStmt extends Stmt_1.Stmt {
|
|
|
74
75
|
exports.DummyStmt = DummyStmt;
|
|
75
76
|
class ArkIRTransformer {
|
|
76
77
|
constructor(sourceFile, declaringMethod) {
|
|
77
|
-
this.
|
|
78
|
-
this.tempLocalNo = 0;
|
|
78
|
+
this.tempLocalIndex = 0;
|
|
79
79
|
this.locals = new Map();
|
|
80
80
|
this.inBuilderMethod = false;
|
|
81
81
|
this.aliasTypeMap = new Map();
|
|
@@ -277,7 +277,7 @@ class ArkIRTransformer {
|
|
|
277
277
|
if (forStatement.initializer) {
|
|
278
278
|
stmts.push(...this.tsNodeToValueAndStmts(forStatement.initializer).stmts);
|
|
279
279
|
}
|
|
280
|
-
const dummyInitializerStmt = new DummyStmt(
|
|
280
|
+
const dummyInitializerStmt = new DummyStmt(exports.DUMMY_INITIALIZER_STMT);
|
|
281
281
|
stmts.push(dummyInitializerStmt);
|
|
282
282
|
if (forStatement.condition) {
|
|
283
283
|
const { value: conditionValue, stmts: conditionStmts, } = this.conditionToValueAndStmts(forStatement.condition);
|
|
@@ -387,7 +387,7 @@ class ArkIRTransformer {
|
|
|
387
387
|
}
|
|
388
388
|
whileStatementToStmts(whileStatement) {
|
|
389
389
|
const stmts = [];
|
|
390
|
-
const dummyInitializerStmt = new DummyStmt(
|
|
390
|
+
const dummyInitializerStmt = new DummyStmt(exports.DUMMY_INITIALIZER_STMT);
|
|
391
391
|
stmts.push(dummyInitializerStmt);
|
|
392
392
|
const { value: conditionExpr, stmts: conditionStmts, } = this.conditionToValueAndStmts(whileStatement.expression);
|
|
393
393
|
stmts.push(...conditionStmts);
|
|
@@ -569,29 +569,23 @@ class ArkIRTransformer {
|
|
|
569
569
|
};
|
|
570
570
|
}
|
|
571
571
|
conditionalExpressionToValueAndStmts(conditionalExpression) {
|
|
572
|
+
// TODO: separated by blocks
|
|
572
573
|
const stmts = [];
|
|
573
|
-
const currConditionalOperatorIndex = this.conditionalOperatorNo++;
|
|
574
574
|
const { value: conditionValue, valueOriginalPositions: conditionPositions, stmts: conditionStmts, } = this.conditionToValueAndStmts(conditionalExpression.condition);
|
|
575
575
|
stmts.push(...conditionStmts);
|
|
576
576
|
const ifStmt = new Stmt_1.ArkIfStmt(conditionValue);
|
|
577
577
|
ifStmt.setOperandOriginalPositions(conditionPositions);
|
|
578
578
|
stmts.push(ifStmt);
|
|
579
|
-
stmts.push(new DummyStmt(ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT + currConditionalOperatorIndex));
|
|
580
579
|
const { value: whenTrueValue, valueOriginalPositions: whenTruePositions, stmts: whenTrueStmts } = this.tsNodeToValueAndStmts(conditionalExpression.whenTrue);
|
|
581
580
|
stmts.push(...whenTrueStmts);
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
const resultLocalPosition = [whenTruePositions[0]];
|
|
585
|
-
assignStmtWhenTrue.setOperandOriginalPositions([...resultLocalPosition, ...whenTruePositions]);
|
|
586
|
-
stmts.push(assignStmtWhenTrue);
|
|
587
|
-
stmts.push(new DummyStmt(ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorIndex));
|
|
581
|
+
const { value: resultValue, valueOriginalPositions: resultPositions, stmts: tempStmts, } = this.generateAssignStmtForValue(whenTrueValue, whenTruePositions);
|
|
582
|
+
stmts.push(...tempStmts);
|
|
588
583
|
const { value: whenFalseValue, valueOriginalPositions: whenFalsePositions, stmts: whenFalseStmts, } = this.tsNodeToValueAndStmts(conditionalExpression.whenFalse);
|
|
589
584
|
stmts.push(...whenFalseStmts);
|
|
590
|
-
const assignStmt = new Stmt_1.ArkAssignStmt(
|
|
591
|
-
assignStmt.setOperandOriginalPositions([...
|
|
585
|
+
const assignStmt = new Stmt_1.ArkAssignStmt(resultValue, whenFalseValue);
|
|
586
|
+
assignStmt.setOperandOriginalPositions([...resultPositions, ...whenFalsePositions]);
|
|
592
587
|
stmts.push(assignStmt);
|
|
593
|
-
stmts
|
|
594
|
-
return { value: resultLocal, valueOriginalPositions: resultLocalPosition, stmts: stmts };
|
|
588
|
+
return { value: resultValue, valueOriginalPositions: resultPositions, stmts: stmts };
|
|
595
589
|
}
|
|
596
590
|
objectLiteralExpresionToValueAndStmts(objectLiteralExpression) {
|
|
597
591
|
const declaringArkClass = this.declaringMethod.getDeclaringArkClass();
|
|
@@ -1454,8 +1448,8 @@ class ArkIRTransformer {
|
|
|
1454
1448
|
return local;
|
|
1455
1449
|
}
|
|
1456
1450
|
generateTempLocal(localType = Type_1.UnknownType.getInstance()) {
|
|
1457
|
-
const tempLocalName = Const_1.TEMP_LOCAL_PREFIX + this.
|
|
1458
|
-
this.
|
|
1451
|
+
const tempLocalName = Const_1.TEMP_LOCAL_PREFIX + this.tempLocalIndex;
|
|
1452
|
+
this.tempLocalIndex++;
|
|
1459
1453
|
const tempLocal = new Local_1.Local(tempLocalName, localType);
|
|
1460
1454
|
this.locals.set(tempLocalName, tempLocal);
|
|
1461
1455
|
return tempLocal;
|
|
@@ -1713,7 +1707,3 @@ class ArkIRTransformer {
|
|
|
1713
1707
|
}
|
|
1714
1708
|
}
|
|
1715
1709
|
exports.ArkIRTransformer = ArkIRTransformer;
|
|
1716
|
-
ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT = 'LoopInitializer';
|
|
1717
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT = 'ConditionalOperatorIfTrue';
|
|
1718
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT = 'ConditionalOperatorIfFalse';
|
|
1719
|
-
ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT = 'ConditionalOperatorEnd';
|
|
@@ -57,7 +57,7 @@ Builtin.BUILT_IN_CLASSES = _a.buildBuiltInClasses();
|
|
|
57
57
|
// signature for built-in class
|
|
58
58
|
Builtin.DUMMY_PROJECT_NAME = 'ES2015';
|
|
59
59
|
Builtin.DUMMY_FILE_NAME = 'BuiltinClass';
|
|
60
|
-
Builtin.BUILT_IN_CLASSES_FILE_SIGNATURE =
|
|
60
|
+
Builtin.BUILT_IN_CLASSES_FILE_SIGNATURE = _a.buildBuiltInClassesFileSignature();
|
|
61
61
|
Builtin.OBJECT_CLASS_SIGNATURE = _a.buildBuiltInClassSignature(_a.OBJECT);
|
|
62
62
|
Builtin.ARRAY_CLASS_SIGNATURE = _a.buildBuiltInClassSignature(_a.ARRAY);
|
|
63
63
|
Builtin.SET_CLASS_SIGNATURE = _a.buildBuiltInClassSignature(_a.SET);
|
|
@@ -123,19 +123,7 @@ export declare class CfgBuilder {
|
|
|
123
123
|
locals: Set<Local>;
|
|
124
124
|
aliasTypeMap: Map<string, [AliasType, AliasTypeDeclaration]>;
|
|
125
125
|
};
|
|
126
|
-
private linkBasicBlocks;
|
|
127
|
-
private rebuildBlocksInConditionalOperator;
|
|
128
|
-
private traverseAndRebuildConditionalOperator;
|
|
129
|
-
private findConditionalOperator;
|
|
130
|
-
private adjustSuccessorOfConditionalOperator;
|
|
131
|
-
private removeUnnecessaryBlocksInConditionalOperator;
|
|
132
|
-
private replaceTempResultcursively;
|
|
133
|
-
private isNewDefLocal;
|
|
134
|
-
private rebuildBlocksInLoop;
|
|
135
|
-
private doesPrevBlockBuilderContainLoop;
|
|
136
126
|
private insertBeforeConditionBlockBuilder;
|
|
137
|
-
private findIteratorIdx;
|
|
138
|
-
private adjustIncrementorStmts;
|
|
139
127
|
}
|
|
140
128
|
export {};
|
|
141
129
|
//# sourceMappingURL=CfgBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CfgBuilder.d.ts","sourceRoot":"","sources":["../../../src/core/common/CfgBuilder.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM/C,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAE/D,cAAM,gBAAgB;IAClB,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,M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AA;KAC/D;IAyCM,4BAA4B,IAAI;QACnC,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAA;KAC/D;IAiKD,OAAO,CAAC,iCAAiC;CAqE5C"}
|
|
@@ -39,7 +39,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.CfgBuilder = void 0;
|
|
41
41
|
const ts = __importStar(require("ohos-typescript"));
|
|
42
|
-
const Local_1 = require("../base/Local");
|
|
43
42
|
const Stmt_1 = require("../base/Stmt");
|
|
44
43
|
const BasicBlock_1 = require("../graph/BasicBlock");
|
|
45
44
|
const Cfg_1 = require("../graph/Cfg");
|
|
@@ -1033,31 +1032,7 @@ class CfgBuilder {
|
|
|
1033
1032
|
blockBuilderToCfgBlock.set(this.blocks[i], blockInCfg);
|
|
1034
1033
|
}
|
|
1035
1034
|
let currBlockId = this.blocks.length;
|
|
1036
|
-
|
|
1037
|
-
this.rebuildBlocksInLoop(blockBuilderToCfgBlock, blocksContainLoopCondition, cfg);
|
|
1038
|
-
this.rebuildBlocksInConditionalOperator(cfg);
|
|
1039
|
-
for (const blockBuilder of this.blocks) {
|
|
1040
|
-
if (blockBuilder.id === -1) {
|
|
1041
|
-
blockBuilder.id = currBlockId++;
|
|
1042
|
-
const block = blockBuilderToCfgBlock.get(blockBuilder);
|
|
1043
|
-
block.setId(blockBuilder.id);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
for (const block of cfg.getBlocks()) {
|
|
1047
|
-
if (block.getId() === -1) {
|
|
1048
|
-
block.setId(currBlockId++);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
for (const stmt of cfg.getStmts()) {
|
|
1052
|
-
stmt.setCfg(cfg);
|
|
1053
|
-
}
|
|
1054
|
-
return {
|
|
1055
|
-
cfg: cfg,
|
|
1056
|
-
locals: arkIRTransformer.getLocals(),
|
|
1057
|
-
aliasTypeMap: arkIRTransformer.getAliasTypeMap(),
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
linkBasicBlocks(blockBuilderToCfgBlock) {
|
|
1035
|
+
// link blocks
|
|
1061
1036
|
for (const [blockBuilder, cfgBlock] of blockBuilderToCfgBlock) {
|
|
1062
1037
|
for (const successorBlockBuilder of blockBuilder.nexts) {
|
|
1063
1038
|
if (!blockBuilderToCfgBlock.get(successorBlockBuilder)) {
|
|
@@ -1074,204 +1049,7 @@ class CfgBuilder {
|
|
|
1074
1049
|
cfgBlock.addPredecessorBlock(predecessorBlock);
|
|
1075
1050
|
}
|
|
1076
1051
|
}
|
|
1077
|
-
|
|
1078
|
-
rebuildBlocksInConditionalOperator(cfg) {
|
|
1079
|
-
var _a;
|
|
1080
|
-
for (const basicBlock of cfg.getBlocks()) {
|
|
1081
|
-
const stmts = Array.from(basicBlock.getStmts());
|
|
1082
|
-
const stmtCnt = stmts.length;
|
|
1083
|
-
let endPos = -1;
|
|
1084
|
-
for (let i = stmtCnt - 1; i >= 0; i--) {
|
|
1085
|
-
const stmt = stmts[i];
|
|
1086
|
-
if (stmt instanceof ArkIRTransformer_1.DummyStmt && ((_a = stmt.toString()) === null || _a === void 0 ? void 0 : _a.startsWith(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT))) {
|
|
1087
|
-
endPos = i;
|
|
1088
|
-
break;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
if (endPos === -1) {
|
|
1092
|
-
continue;
|
|
1093
|
-
}
|
|
1094
|
-
const { topBlock, bottomBlocks, allBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, 0, endPos);
|
|
1095
|
-
basicBlock.getStmts().splice(topBlock.getStmts().length);
|
|
1096
|
-
const succBlocksOfIfBlock = topBlock.getSuccessors();
|
|
1097
|
-
succBlocksOfIfBlock.forEach((block) => {
|
|
1098
|
-
block.setPredecessorBlock(0, basicBlock);
|
|
1099
|
-
});
|
|
1100
|
-
const conditionalOperatorBlockSet = new Set(allBlocks);
|
|
1101
|
-
this.adjustSuccessorOfConditionalOperator(basicBlock, succBlocksOfIfBlock, stmts, bottomBlocks, endPos, conditionalOperatorBlockSet);
|
|
1102
|
-
conditionalOperatorBlockSet.forEach((block) => {
|
|
1103
|
-
if (block !== topBlock) {
|
|
1104
|
-
cfg.addBlock(block);
|
|
1105
|
-
}
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
traverseAndRebuildConditionalOperator(stmts, beginPos, endPos) {
|
|
1110
|
-
const { ifTruePos, ifFalsePos, conditionalOperatorEndPos } = this.findConditionalOperator(stmts, beginPos, endPos);
|
|
1111
|
-
if (ifTruePos === -1) {
|
|
1112
|
-
const block = new BasicBlock_1.BasicBlock();
|
|
1113
|
-
block.getStmts().push(...stmts.slice(beginPos, endPos + 1));
|
|
1114
|
-
return { topBlock: block, bottomBlocks: [], allBlocks: [block] };
|
|
1115
|
-
}
|
|
1116
|
-
const allBlocks = [];
|
|
1117
|
-
const topBlock = new BasicBlock_1.BasicBlock();
|
|
1118
|
-
topBlock.getStmts().push(...stmts.slice(beginPos, ifTruePos));
|
|
1119
|
-
allBlocks.push(topBlock);
|
|
1120
|
-
const { topBlock: ifTrueTopBlock, bottomBlocks: ifTrueBottomBlocks, allBlocks: ifTrueAllBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, ifTruePos + 1, ifFalsePos - 1);
|
|
1121
|
-
allBlocks.push(...ifTrueAllBlocks);
|
|
1122
|
-
const { topBlock: ifFalseTopBlock, bottomBlocks: ifFalseBottomBlocks, allBlocks: ifFalseAllBlocks, } = this.traverseAndRebuildConditionalOperator(stmts, ifFalsePos + 1, conditionalOperatorEndPos - 1);
|
|
1123
|
-
allBlocks.push(...ifFalseAllBlocks);
|
|
1124
|
-
topBlock.addSuccessorBlock(ifTrueTopBlock);
|
|
1125
|
-
topBlock.addSuccessorBlock(ifFalseTopBlock);
|
|
1126
|
-
ifTrueTopBlock.addPredecessorBlock(topBlock);
|
|
1127
|
-
ifFalseTopBlock.addPredecessorBlock(topBlock);
|
|
1128
|
-
let bottomBlocks = [];
|
|
1129
|
-
bottomBlocks.push(...(ifTrueBottomBlocks.length > 0 ? ifTrueBottomBlocks : [ifTrueTopBlock]));
|
|
1130
|
-
bottomBlocks.push(...(ifFalseBottomBlocks.length > 0 ? ifFalseBottomBlocks : [ifFalseTopBlock]));
|
|
1131
|
-
if (conditionalOperatorEndPos !== endPos) {
|
|
1132
|
-
const bottomBlock = new BasicBlock_1.BasicBlock();
|
|
1133
|
-
bottomBlock.getStmts().push(...stmts.slice(conditionalOperatorEndPos + 1, endPos + 1));
|
|
1134
|
-
bottomBlocks.forEach(block => {
|
|
1135
|
-
block.addSuccessorBlock(bottomBlock);
|
|
1136
|
-
bottomBlock.addPredecessorBlock(block);
|
|
1137
|
-
});
|
|
1138
|
-
bottomBlocks = [bottomBlock];
|
|
1139
|
-
allBlocks.push(bottomBlock);
|
|
1140
|
-
}
|
|
1141
|
-
return { topBlock: topBlock, bottomBlocks: bottomBlocks, allBlocks: allBlocks };
|
|
1142
|
-
}
|
|
1143
|
-
findConditionalOperator(stmts, beginPos, endPos) {
|
|
1144
|
-
let ifTruePos = -1;
|
|
1145
|
-
let ifFalsePos = -1;
|
|
1146
|
-
let conditionalOperatorEndPos = -1;
|
|
1147
|
-
let currConditionalOperatorNo = '';
|
|
1148
|
-
for (let i = beginPos; i <= endPos; i++) {
|
|
1149
|
-
const stmt = stmts[i];
|
|
1150
|
-
if (stmt instanceof ArkIRTransformer_1.DummyStmt) {
|
|
1151
|
-
if (stmt.toString()
|
|
1152
|
-
.startsWith(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT) && ifTruePos === -1) {
|
|
1153
|
-
ifTruePos = i;
|
|
1154
|
-
currConditionalOperatorNo =
|
|
1155
|
-
stmt.toString().replace(ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_TRUE_STMT, '');
|
|
1156
|
-
}
|
|
1157
|
-
else if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_IF_FALSE_STMT + currConditionalOperatorNo) {
|
|
1158
|
-
ifFalsePos = i;
|
|
1159
|
-
}
|
|
1160
|
-
else if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_CONDITIONAL_OPERATOR_END_STMT + currConditionalOperatorNo) {
|
|
1161
|
-
conditionalOperatorEndPos = i;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
return { ifTruePos: ifTruePos, ifFalsePos: ifFalsePos, conditionalOperatorEndPos: conditionalOperatorEndPos };
|
|
1166
|
-
}
|
|
1167
|
-
adjustSuccessorOfConditionalOperator(currBasicBlock, succBlocksOfIfBlock, stmts, bottomBlocks, conditionalOperatorEndPos, conditionalOperatorBlockSet) {
|
|
1168
|
-
const oldSuccBlocks = Array.from(currBasicBlock.getSuccessors());
|
|
1169
|
-
currBasicBlock.getSuccessors().splice(0, oldSuccBlocks.length, ...succBlocksOfIfBlock);
|
|
1170
|
-
oldSuccBlocks.forEach((succBlock) => {
|
|
1171
|
-
const originalPreds = succBlock.getPredecessors();
|
|
1172
|
-
for (let i = 0; i < originalPreds.length; i++) {
|
|
1173
|
-
if (originalPreds[i] === currBasicBlock) {
|
|
1174
|
-
succBlock.getPredecessors().splice(i, 1);
|
|
1175
|
-
break;
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
});
|
|
1179
|
-
if (conditionalOperatorEndPos === stmts.length - 1) {
|
|
1180
|
-
oldSuccBlocks.forEach((oldSuccBlock) => {
|
|
1181
|
-
bottomBlocks.forEach((bottomBlock) => {
|
|
1182
|
-
bottomBlock.addSuccessorBlock(oldSuccBlock);
|
|
1183
|
-
oldSuccBlock.addSuccessorBlock(bottomBlock);
|
|
1184
|
-
});
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
else {
|
|
1188
|
-
const insertSuccBlock = new BasicBlock_1.BasicBlock();
|
|
1189
|
-
insertSuccBlock.getStmts().push(...stmts.slice(conditionalOperatorEndPos + 1, stmts.length));
|
|
1190
|
-
oldSuccBlocks.forEach((oldSuccBlock) => {
|
|
1191
|
-
insertSuccBlock.addSuccessorBlock(oldSuccBlock);
|
|
1192
|
-
oldSuccBlock.addPredecessorBlock(insertSuccBlock);
|
|
1193
|
-
});
|
|
1194
|
-
bottomBlocks.forEach((bottomBlock) => {
|
|
1195
|
-
bottomBlock.addSuccessorBlock(insertSuccBlock);
|
|
1196
|
-
insertSuccBlock.addPredecessorBlock(bottomBlock);
|
|
1197
|
-
});
|
|
1198
|
-
conditionalOperatorBlockSet.add(insertSuccBlock);
|
|
1199
|
-
this.removeUnnecessaryBlocksInConditionalOperator(insertSuccBlock, conditionalOperatorBlockSet);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
removeUnnecessaryBlocksInConditionalOperator(bottomBlock, allBlocks) {
|
|
1203
|
-
const firstStmtInBottom = bottomBlock.getStmts()[0];
|
|
1204
|
-
if (!(firstStmtInBottom instanceof Stmt_1.ArkAssignStmt)) {
|
|
1205
|
-
return;
|
|
1206
|
-
}
|
|
1207
|
-
const targetValue = firstStmtInBottom.getLeftOp();
|
|
1208
|
-
const tempResultValue = firstStmtInBottom.getRightOp();
|
|
1209
|
-
if (!(targetValue instanceof Local_1.Local && IRUtils_1.IRUtils.isTempLocal(tempResultValue))) {
|
|
1210
|
-
return;
|
|
1211
|
-
}
|
|
1212
|
-
bottomBlock.remove(firstStmtInBottom);
|
|
1213
|
-
const oldPredecessors = bottomBlock.getPredecessors();
|
|
1214
|
-
const newPredecessors = [];
|
|
1215
|
-
for (const predecessor of oldPredecessors) {
|
|
1216
|
-
newPredecessors.push(...this.replaceTempResultcursively(predecessor, targetValue, tempResultValue, allBlocks));
|
|
1217
|
-
}
|
|
1218
|
-
bottomBlock.getPredecessors().splice(0, oldPredecessors.length, ...newPredecessors);
|
|
1219
|
-
newPredecessors.forEach((newPredecessor) => {
|
|
1220
|
-
newPredecessor.setSuccessorBlock(0, bottomBlock);
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
replaceTempResultcursively(currBottomBlock, targetLocal, tempResultLocal, allBlocks) {
|
|
1224
|
-
const stmts = currBottomBlock.getStmts();
|
|
1225
|
-
const stmtsCnt = stmts.length;
|
|
1226
|
-
let tempResultReassignStmt = null;
|
|
1227
|
-
for (let i = stmtsCnt - 1; i >= 0; i--) {
|
|
1228
|
-
const stmt = stmts[i];
|
|
1229
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getLeftOp() === tempResultLocal) {
|
|
1230
|
-
if (IRUtils_1.IRUtils.isTempLocal(stmt.getRightOp()) && this.isNewDefLocal(stmt.getRightOp(), stmts, i)) {
|
|
1231
|
-
tempResultReassignStmt = stmt;
|
|
1232
|
-
}
|
|
1233
|
-
else {
|
|
1234
|
-
stmt.setLeftOp(targetLocal);
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
let newBottomBlocks = [];
|
|
1239
|
-
if (tempResultReassignStmt) {
|
|
1240
|
-
const oldPredecessors = currBottomBlock.getPredecessors();
|
|
1241
|
-
const newPredecessors = [];
|
|
1242
|
-
const prevTempResultLocal = tempResultReassignStmt.getRightOp();
|
|
1243
|
-
for (const predecessor of oldPredecessors) {
|
|
1244
|
-
newPredecessors.push(...this.replaceTempResultcursively(predecessor, targetLocal, prevTempResultLocal, allBlocks));
|
|
1245
|
-
}
|
|
1246
|
-
currBottomBlock.remove(tempResultReassignStmt);
|
|
1247
|
-
if (currBottomBlock.getStmts().length === 0) {
|
|
1248
|
-
// remove this block
|
|
1249
|
-
newBottomBlocks = newPredecessors;
|
|
1250
|
-
allBlocks.delete(currBottomBlock);
|
|
1251
|
-
}
|
|
1252
|
-
else {
|
|
1253
|
-
currBottomBlock.getPredecessors().splice(0, oldPredecessors.length, ...newPredecessors);
|
|
1254
|
-
newPredecessors.forEach((newPredecessor) => {
|
|
1255
|
-
newPredecessor.setSuccessorBlock(0, currBottomBlock);
|
|
1256
|
-
});
|
|
1257
|
-
newBottomBlocks = [currBottomBlock];
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
else {
|
|
1261
|
-
newBottomBlocks = [currBottomBlock];
|
|
1262
|
-
}
|
|
1263
|
-
return newBottomBlocks;
|
|
1264
|
-
}
|
|
1265
|
-
isNewDefLocal(local, stmts, pos) {
|
|
1266
|
-
for (let i = pos - 1; i >= 0; i++) {
|
|
1267
|
-
const stmt = stmts[i];
|
|
1268
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getLeftOp() === local) {
|
|
1269
|
-
return false;
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
return true;
|
|
1273
|
-
}
|
|
1274
|
-
rebuildBlocksInLoop(blockBuilderToCfgBlock, blocksContainLoopCondition, cfg) {
|
|
1052
|
+
// put statements within loop in right position
|
|
1275
1053
|
for (const blockBuilder of blocksContainLoopCondition) {
|
|
1276
1054
|
if (!blockBuilderToCfgBlock.get(blockBuilder)) {
|
|
1277
1055
|
continue;
|
|
@@ -1280,11 +1058,38 @@ class CfgBuilder {
|
|
|
1280
1058
|
const blockId = block.getId();
|
|
1281
1059
|
const stmts = block.getStmts();
|
|
1282
1060
|
const stmtsCnt = stmts.length;
|
|
1283
|
-
|
|
1061
|
+
let ifStmtIdx = -1;
|
|
1062
|
+
let iteratorNextStmtIdx = -1;
|
|
1063
|
+
let dummyInitializerStmtIdx = -1;
|
|
1064
|
+
for (let i = 0; i < stmtsCnt; i++) {
|
|
1065
|
+
const stmt = stmts[i];
|
|
1066
|
+
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.AbstractInvokeExpr) {
|
|
1067
|
+
const invokeExpr = stmt.getRightOp();
|
|
1068
|
+
if (invokeExpr.getMethodSignature().getMethodSubSignature().getMethodName() === Builtin_1.Builtin.ITERATOR_NEXT) {
|
|
1069
|
+
iteratorNextStmtIdx = i;
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
if (stmt.toString() === ArkIRTransformer_1.DUMMY_INITIALIZER_STMT) {
|
|
1074
|
+
dummyInitializerStmtIdx = i;
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
1078
|
+
ifStmtIdx = i;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1284
1082
|
if (iteratorNextStmtIdx !== -1 || dummyInitializerStmtIdx !== -1) {
|
|
1083
|
+
// put statements into block before condition
|
|
1285
1084
|
const lastStmtIdxBeforeCondition = iteratorNextStmtIdx !== -1 ? iteratorNextStmtIdx : dummyInitializerStmtIdx;
|
|
1286
1085
|
const stmtsInsertBeforeCondition = stmts.slice(0, lastStmtIdxBeforeCondition);
|
|
1287
|
-
let prevBlockBuilderContainsLoop =
|
|
1086
|
+
let prevBlockBuilderContainsLoop = false;
|
|
1087
|
+
for (const prevBlockBuilder of blockBuilder.lasts) {
|
|
1088
|
+
if (prevBlockBuilder.id < blockId && blocksContainLoopCondition.has(prevBlockBuilder)) {
|
|
1089
|
+
prevBlockBuilderContainsLoop = true;
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1288
1093
|
if (prevBlockBuilderContainsLoop) {
|
|
1289
1094
|
// should create an extra block when previous block contains loop condition
|
|
1290
1095
|
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, blockBuilder, stmtsInsertBeforeCondition, false, cfg);
|
|
@@ -1296,7 +1101,23 @@ class CfgBuilder {
|
|
|
1296
1101
|
}
|
|
1297
1102
|
if (dummyInitializerStmtIdx !== -1 && ifStmtIdx !== stmtsCnt - 1) {
|
|
1298
1103
|
// put incrementor statements into block which reenters condition
|
|
1299
|
-
|
|
1104
|
+
const stmtsReenterCondition = stmts.slice(ifStmtIdx + 1);
|
|
1105
|
+
const blockBuildersReenterCondition = [];
|
|
1106
|
+
for (const prevBlockBuilder of blockBuilder.lasts) {
|
|
1107
|
+
const prevBlock = blockBuilderToCfgBlock.get(prevBlockBuilder);
|
|
1108
|
+
if (prevBlock.getId() > blockId) {
|
|
1109
|
+
blockBuildersReenterCondition.push(prevBlockBuilder);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (blockBuildersReenterCondition.length > 1 || blocksContainLoopCondition.has(blockBuildersReenterCondition[0])) {
|
|
1113
|
+
// put incrementor statements into an extra block
|
|
1114
|
+
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, blockBuilder, stmtsReenterCondition, true, cfg);
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
// put incrementor statements into prev reenter block
|
|
1118
|
+
const blockReenterCondition = blockBuilderToCfgBlock.get(blockBuildersReenterCondition[0]);
|
|
1119
|
+
blockReenterCondition === null || blockReenterCondition === void 0 ? void 0 : blockReenterCondition.getStmts().push(...stmtsReenterCondition);
|
|
1120
|
+
}
|
|
1300
1121
|
}
|
|
1301
1122
|
else if (iteratorNextStmtIdx !== -1) {
|
|
1302
1123
|
// put statements which get value of iterator into block after condition
|
|
@@ -1311,16 +1132,21 @@ class CfgBuilder {
|
|
|
1311
1132
|
stmts.splice(ifStmtIdx - firstStmtIdxInCondition + 1);
|
|
1312
1133
|
}
|
|
1313
1134
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
prevBlockBuilderContainsLoop = true;
|
|
1320
|
-
break;
|
|
1135
|
+
for (const blockBuilder of this.blocks) {
|
|
1136
|
+
if (blockBuilder.id === -1) {
|
|
1137
|
+
blockBuilder.id = currBlockId++;
|
|
1138
|
+
const block = blockBuilderToCfgBlock.get(blockBuilder);
|
|
1139
|
+
block.setId(blockBuilder.id);
|
|
1321
1140
|
}
|
|
1322
1141
|
}
|
|
1323
|
-
|
|
1142
|
+
for (const stmt of cfg.getStmts()) {
|
|
1143
|
+
stmt.setCfg(cfg);
|
|
1144
|
+
}
|
|
1145
|
+
return {
|
|
1146
|
+
cfg: cfg,
|
|
1147
|
+
locals: arkIRTransformer.getLocals(),
|
|
1148
|
+
aliasTypeMap: arkIRTransformer.getAliasTypeMap(),
|
|
1149
|
+
};
|
|
1324
1150
|
}
|
|
1325
1151
|
insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, conditionBlockBuilder, stmtsInsertBeforeCondition, collectReenter, cfg) {
|
|
1326
1152
|
const blockId = conditionBlockBuilder.id;
|
|
@@ -1384,54 +1210,5 @@ class CfgBuilder {
|
|
|
1384
1210
|
cfg.addBlock(blockInsertBeforeCondition);
|
|
1385
1211
|
blockBuilderToCfgBlock.set(blockBuilderInsertBeforeCondition, blockInsertBeforeCondition);
|
|
1386
1212
|
}
|
|
1387
|
-
findIteratorIdx(stmts) {
|
|
1388
|
-
let ifStmtIdx = -1;
|
|
1389
|
-
let iteratorNextStmtIdx = -1;
|
|
1390
|
-
let dummyInitializerStmtIdx = -1;
|
|
1391
|
-
const stmtsCnt = stmts.length;
|
|
1392
|
-
for (let i = 0; i < stmtsCnt; i++) {
|
|
1393
|
-
const stmt = stmts[i];
|
|
1394
|
-
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.AbstractInvokeExpr) {
|
|
1395
|
-
const invokeExpr = stmt.getRightOp();
|
|
1396
|
-
if (invokeExpr.getMethodSignature().getMethodSubSignature()
|
|
1397
|
-
.getMethodName() === Builtin_1.Builtin.ITERATOR_NEXT) {
|
|
1398
|
-
iteratorNextStmtIdx = i;
|
|
1399
|
-
continue;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
if (stmt.toString() === ArkIRTransformer_1.ArkIRTransformer.DUMMY_LOOP_INITIALIZER_STMT) {
|
|
1403
|
-
dummyInitializerStmtIdx = i;
|
|
1404
|
-
continue;
|
|
1405
|
-
}
|
|
1406
|
-
if (stmt instanceof Stmt_1.ArkIfStmt) {
|
|
1407
|
-
ifStmtIdx = i;
|
|
1408
|
-
break;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
return {
|
|
1412
|
-
ifStmtIdx: ifStmtIdx,
|
|
1413
|
-
iteratorNextStmtIdx: iteratorNextStmtIdx,
|
|
1414
|
-
dummyInitializerStmtIdx: dummyInitializerStmtIdx,
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
adjustIncrementorStmts(stmts, ifStmtIdx, currBlockBuilder, currBlockId, blockBuilderToCfgBlock, blocksContainLoopCondition, cfg) {
|
|
1418
|
-
const stmtsReenterCondition = stmts.slice(ifStmtIdx + 1);
|
|
1419
|
-
const blockBuildersReenterCondition = [];
|
|
1420
|
-
for (const prevBlockBuilder of currBlockBuilder.lasts) {
|
|
1421
|
-
const prevBlock = blockBuilderToCfgBlock.get(prevBlockBuilder);
|
|
1422
|
-
if (prevBlock.getId() > currBlockId) {
|
|
1423
|
-
blockBuildersReenterCondition.push(prevBlockBuilder);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (blockBuildersReenterCondition.length > 1 || blocksContainLoopCondition.has(blockBuildersReenterCondition[0])) {
|
|
1427
|
-
// put incrementor statements into an extra block
|
|
1428
|
-
this.insertBeforeConditionBlockBuilder(blockBuilderToCfgBlock, currBlockBuilder, stmtsReenterCondition, true, cfg);
|
|
1429
|
-
}
|
|
1430
|
-
else {
|
|
1431
|
-
// put incrementor statements into prev reenter block
|
|
1432
|
-
const blockReenterCondition = blockBuilderToCfgBlock.get(blockBuildersReenterCondition[0]);
|
|
1433
|
-
blockReenterCondition === null || blockReenterCondition === void 0 ? void 0 : blockReenterCondition.getStmts().push(...stmtsReenterCondition);
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
1213
|
}
|
|
1437
1214
|
exports.CfgBuilder = CfgBuilder;
|
|
@@ -9,6 +9,5 @@ export declare class IRUtils {
|
|
|
9
9
|
static generateTextForStmt(scene: Scene): void;
|
|
10
10
|
static setLeadingComments(metadata: Stmt | ArkBaseModel, node: ts.Node, sourceFile: ts.SourceFile, options: SceneOptions): void;
|
|
11
11
|
static getLeadingComments(node: ts.Node, sourceFile: ts.SourceFile, options: SceneOptions): string[];
|
|
12
|
-
static isTempLocal(value: Value): boolean;
|
|
13
12
|
}
|
|
14
13
|
//# sourceMappingURL=IRUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IRUtils.d.ts","sourceRoot":"","sources":["../../../src/core/common/IRUtils.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"IRUtils.d.ts","sourceRoot":"","sources":["../../../src/core/common/IRUtils.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,OAAO;IAChB,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAchD,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAW9C,MAAM,CAAC,kBAAkB,CACrB,QAAQ,EAAE,IAAI,GAAG,YAAY,EAC7B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,OAAO,EAAE,YAAY,GACtB,IAAI;IAOP,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,EAAE;CAYvG"}
|
|
@@ -22,8 +22,6 @@ const Expr_1 = require("../base/Expr");
|
|
|
22
22
|
const Ref_1 = require("../base/Ref");
|
|
23
23
|
const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
|
|
24
24
|
const ArkMetadata_1 = require("../model/ArkMetadata");
|
|
25
|
-
const Local_1 = require("../base/Local");
|
|
26
|
-
const Const_1 = require("./Const");
|
|
27
25
|
class IRUtils {
|
|
28
26
|
static moreThanOneAddress(value) {
|
|
29
27
|
if (value instanceof Expr_1.AbstractBinopExpr ||
|
|
@@ -64,8 +62,5 @@ class IRUtils {
|
|
|
64
62
|
}
|
|
65
63
|
return comments;
|
|
66
64
|
}
|
|
67
|
-
static isTempLocal(value) {
|
|
68
|
-
return value instanceof Local_1.Local && value.getName().startsWith(Const_1.NAME_PREFIX);
|
|
69
|
-
}
|
|
70
65
|
}
|
|
71
66
|
exports.IRUtils = IRUtils;
|
|
@@ -81,7 +81,7 @@ var ModifierType;
|
|
|
81
81
|
ModifierType[ModifierType["OUT"] = 4096] = "OUT";
|
|
82
82
|
ModifierType[ModifierType["OVERRIDE"] = 8192] = "OVERRIDE";
|
|
83
83
|
ModifierType[ModifierType["DECLARE"] = 16384] = "DECLARE";
|
|
84
|
-
})(ModifierType
|
|
84
|
+
})(ModifierType || (exports.ModifierType = ModifierType = {}));
|
|
85
85
|
exports.MODIFIER_TYPE_MASK = 0xffff;
|
|
86
86
|
const MODIFIER_TYPE_STRINGS = [
|
|
87
87
|
'private',
|
|
@@ -30,7 +30,7 @@ var ClassCategory;
|
|
|
30
30
|
ClassCategory[ClassCategory["ENUM"] = 3] = "ENUM";
|
|
31
31
|
ClassCategory[ClassCategory["TYPE_LITERAL"] = 4] = "TYPE_LITERAL";
|
|
32
32
|
ClassCategory[ClassCategory["OBJECT"] = 5] = "OBJECT";
|
|
33
|
-
})(ClassCategory
|
|
33
|
+
})(ClassCategory || (exports.ClassCategory = ClassCategory = {}));
|
|
34
34
|
/**
|
|
35
35
|
* @category core/model
|
|
36
36
|
*/
|
|
@@ -27,7 +27,7 @@ var ExportType;
|
|
|
27
27
|
ExportType[ExportType["LOCAL"] = 3] = "LOCAL";
|
|
28
28
|
ExportType[ExportType["TYPE"] = 4] = "TYPE";
|
|
29
29
|
ExportType[ExportType["UNKNOWN"] = 9] = "UNKNOWN";
|
|
30
|
-
})(ExportType
|
|
30
|
+
})(ExportType || (exports.ExportType = ExportType = {}));
|
|
31
31
|
/**
|
|
32
32
|
* @category core/model
|
|
33
33
|
*/
|
|
@@ -27,7 +27,7 @@ var FieldCategory;
|
|
|
27
27
|
FieldCategory[FieldCategory["ENUM_MEMBER"] = 5] = "ENUM_MEMBER";
|
|
28
28
|
FieldCategory[FieldCategory["INDEX_SIGNATURE"] = 6] = "INDEX_SIGNATURE";
|
|
29
29
|
FieldCategory[FieldCategory["GET_ACCESSOR"] = 7] = "GET_ACCESSOR";
|
|
30
|
-
})(FieldCategory
|
|
30
|
+
})(FieldCategory || (exports.FieldCategory = FieldCategory = {}));
|
|
31
31
|
/**
|
|
32
32
|
* @category core/model
|
|
33
33
|
*/
|
|
@@ -18,7 +18,7 @@ exports.ArkMetadata = exports.ArkMetadataKind = void 0;
|
|
|
18
18
|
var ArkMetadataKind;
|
|
19
19
|
(function (ArkMetadataKind) {
|
|
20
20
|
ArkMetadataKind[ArkMetadataKind["LEADING_COMMENTS"] = 0] = "LEADING_COMMENTS";
|
|
21
|
-
})(ArkMetadataKind
|
|
21
|
+
})(ArkMetadataKind || (exports.ArkMetadataKind = ArkMetadataKind = {}));
|
|
22
22
|
/**
|
|
23
23
|
* ArkMetadata
|
|
24
24
|
* @example
|
|
@@ -28,7 +28,7 @@ var CodeBlockType;
|
|
|
28
28
|
CodeBlockType[CodeBlockType["WHILE"] = 7] = "WHILE";
|
|
29
29
|
CodeBlockType[CodeBlockType["FOR"] = 8] = "FOR";
|
|
30
30
|
CodeBlockType[CodeBlockType["COMPOUND_END"] = 9] = "COMPOUND_END";
|
|
31
|
-
})(CodeBlockType
|
|
31
|
+
})(CodeBlockType || (exports.CodeBlockType = CodeBlockType = {}));
|
|
32
32
|
class AbstractFlowGraph {
|
|
33
33
|
constructor(cfg) {
|
|
34
34
|
this.nodes = [];
|
|
@@ -21,14 +21,14 @@ exports.addCfg2Stmt = exports.getCallbackMethodFromStmt = exports.getAbilities =
|
|
|
21
21
|
const path_1 = __importDefault(require("path"));
|
|
22
22
|
const Type_1 = require("../core/base/Type");
|
|
23
23
|
exports.LIFECYCLE_METHOD_NAME = [
|
|
24
|
-
'onCreate',
|
|
25
|
-
'onDestroy',
|
|
26
|
-
'onWindowStageCreate',
|
|
27
|
-
'onWindowStageDestroy',
|
|
28
|
-
'onForeground',
|
|
29
|
-
'onBackground',
|
|
30
|
-
'onBackup',
|
|
31
|
-
'onRestore',
|
|
24
|
+
'onCreate', // 组件实例创建
|
|
25
|
+
'onDestroy', // 组件实例销毁
|
|
26
|
+
'onWindowStageCreate', // 窗口创建
|
|
27
|
+
'onWindowStageDestroy', // 窗口销毁
|
|
28
|
+
'onForeground', // 应用进入前台
|
|
29
|
+
'onBackground', // 应用进入后台
|
|
30
|
+
'onBackup', // 应用数据备份
|
|
31
|
+
'onRestore', // 应用数据恢复
|
|
32
32
|
'onContinue',
|
|
33
33
|
'onNewWant',
|
|
34
34
|
'onDump',
|
|
@@ -49,21 +49,21 @@ exports.LIFECYCLE_METHOD_NAME = [
|
|
|
49
49
|
'onWindowStageWillDestroy',
|
|
50
50
|
];
|
|
51
51
|
exports.CALLBACK_METHOD_NAME = [
|
|
52
|
-
"onClick",
|
|
53
|
-
"onTouch",
|
|
54
|
-
"onAppear",
|
|
55
|
-
"onDisAppear",
|
|
56
|
-
"onDragStart",
|
|
57
|
-
"onDragEnter",
|
|
58
|
-
"onDragMove",
|
|
59
|
-
"onDragLeave",
|
|
60
|
-
"onDrop",
|
|
61
|
-
"onKeyEvent",
|
|
62
|
-
"onFocus",
|
|
63
|
-
"onBlur",
|
|
64
|
-
"onHover",
|
|
65
|
-
"onMouse",
|
|
66
|
-
"onAreaChange",
|
|
52
|
+
"onClick", // 点击事件,当用户点击组件时触发
|
|
53
|
+
"onTouch", // 触摸事件,当手指在组件上按下、滑动、抬起时触发
|
|
54
|
+
"onAppear", // 组件挂载显示时触发
|
|
55
|
+
"onDisAppear", // 组件卸载消失时触发
|
|
56
|
+
"onDragStart", // 拖拽开始事件,当组件被长按后开始拖拽时触发
|
|
57
|
+
"onDragEnter", // 拖拽进入组件范围时触发
|
|
58
|
+
"onDragMove", // 拖拽在组件范围内移动时触发
|
|
59
|
+
"onDragLeave", // 拖拽离开组件范围内时触发
|
|
60
|
+
"onDrop", // 拖拽释放目标,当在本组件范围内停止拖拽行为时触发
|
|
61
|
+
"onKeyEvent", // 按键事件,当组件获焦后,按键动作触发
|
|
62
|
+
"onFocus", // 焦点事件,当组件获取焦点时触发
|
|
63
|
+
"onBlur", // 当组件失去焦点时触发的回调
|
|
64
|
+
"onHover", // 鼠标悬浮事件,鼠标进入或退出组件时触发
|
|
65
|
+
"onMouse", // 鼠标事件,当鼠标按键点击或在组件上移动时触发
|
|
66
|
+
"onAreaChange", // 组件区域变化事件,组件尺寸、位置变化时触发
|
|
67
67
|
"onVisibleAreaChange", // 组件可见区域变化事件,组件在屏幕中的显示区域面积变化时触发
|
|
68
68
|
];
|
|
69
69
|
exports.COMPONENT_LIFECYCLE_METHOD_NAME = [
|
package/lib/utils/logger.js
CHANGED
|
@@ -23,14 +23,14 @@ var LOG_LEVEL;
|
|
|
23
23
|
LOG_LEVEL["INFO"] = "INFO";
|
|
24
24
|
LOG_LEVEL["DEBUG"] = "DEBUG";
|
|
25
25
|
LOG_LEVEL["TRACE"] = "TRACE";
|
|
26
|
-
})(LOG_LEVEL
|
|
26
|
+
})(LOG_LEVEL || (exports.LOG_LEVEL = LOG_LEVEL = {}));
|
|
27
27
|
var LOG_MODULE_TYPE;
|
|
28
28
|
(function (LOG_MODULE_TYPE) {
|
|
29
29
|
LOG_MODULE_TYPE["DEFAULT"] = "default";
|
|
30
30
|
LOG_MODULE_TYPE["ARKANALYZER"] = "ArkAnalyzer";
|
|
31
31
|
LOG_MODULE_TYPE["HOMECHECK"] = "HomeCheck";
|
|
32
32
|
LOG_MODULE_TYPE["TOOL"] = "Tool";
|
|
33
|
-
})(LOG_MODULE_TYPE
|
|
33
|
+
})(LOG_MODULE_TYPE || (exports.LOG_MODULE_TYPE = LOG_MODULE_TYPE = {}));
|
|
34
34
|
class ConsoleLogger {
|
|
35
35
|
static configure(logFilePath, arkanalyzer_level = LOG_LEVEL.ERROR, tool_level = LOG_LEVEL.INFO) {
|
|
36
36
|
(0, log4js_1.configure)({
|
package/package.json
CHANGED
package/docs/IR2ts-stmt.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
```Mermaid
|
|
2
|
-
classDiagram
|
|
3
|
-
class TransformerContext {
|
|
4
|
-
getDeclaringArkNamespace(): ArkNamespace | undefined;
|
|
5
|
-
getMethod(signature: MethodSignature): ArkMethod | null;
|
|
6
|
-
getClass(signature: ClassSignature): ArkClass | null;
|
|
7
|
-
getPrinter(): ArkCodeBuffer;
|
|
8
|
-
transTemp2Code(temp: Local): string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
<<Interface>> TransformerContext
|
|
12
|
-
|
|
13
|
-
class StmtPrinterContext {
|
|
14
|
-
getStmtReader(): StmtReader;
|
|
15
|
-
setSkipStmt(stmt: Stmt): void;
|
|
16
|
-
|
|
17
|
-
setTempCode(temp: string, code: string): void;
|
|
18
|
-
hasTempVisit(temp: string): boolean;
|
|
19
|
-
setTempVisit(temp: string): void;
|
|
20
|
-
}
|
|
21
|
-
StmtPrinterContext --|> TransformerContext
|
|
22
|
-
<<Interface>> StmtPrinterContext
|
|
23
|
-
|
|
24
|
-
class SourceStmt {
|
|
25
|
-
constructor(context: StmtPrinterContext, original: Stmt);
|
|
26
|
-
getLine(): number;
|
|
27
|
-
dump(): string;
|
|
28
|
-
}
|
|
29
|
-
<<Abstract>> SourceStmt
|
|
30
|
-
SourceStmt --> StmtPrinterContext
|
|
31
|
-
|
|
32
|
-
class SourceAssignStmt {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
SourceAssignStmt --|> SourceStmt
|
|
36
|
-
|
|
37
|
-
class SourceInvokeStmt {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
SourceInvokeStmt --|> SourceStmt
|
|
42
|
-
|
|
43
|
-
class SourceIfStmt {
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
SourceIfStmt --|> SourceStmt
|
|
47
|
-
|
|
48
|
-
class SourceWhileStmt {
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
SourceWhileStmt --|> SourceStmt
|
|
53
|
-
|
|
54
|
-
class SourceForStmt {
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
SourceForStmt --|> SourceStmt
|
|
58
|
-
class SourceDoWhileStmt {
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
SourceDoWhileStmt --|> SourceStmt
|
|
62
|
-
|
|
63
|
-
class SourceDoStmt {
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
SourceDoStmt --|> SourceStmt
|
|
67
|
-
|
|
68
|
-
class SourceBody {
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
SourceBody --|> StmtPrinterContext
|
|
72
|
-
SourceBody --> SourceStmt
|
|
73
|
-
|
|
74
|
-
class AbstractFlowGraph {
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
AbstractFlowGraph o-- BasicBlock
|
|
79
|
-
|
|
80
|
-
SourceBody --> AbstractFlowGraph
|
|
81
|
-
```
|
package/docs/IR2ts.md
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
```Mermaid
|
|
2
|
-
classDiagram
|
|
3
|
-
class ArkCodeBuffer {
|
|
4
|
-
write(s: string) this
|
|
5
|
-
toString() string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class ArkStream {
|
|
9
|
-
write(s: string) this
|
|
10
|
-
close() void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
ArkStream --|> ArkCodeBuffer
|
|
14
|
-
|
|
15
|
-
class Printer {
|
|
16
|
-
abstract dump(): string
|
|
17
|
-
}
|
|
18
|
-
<<Abstract>> Printer
|
|
19
|
-
Printer --> ArkCodeBuffer
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class DotMethodPrinter {
|
|
23
|
-
constructor(method: ArkMethod)
|
|
24
|
-
dump(): string
|
|
25
|
-
}
|
|
26
|
-
DotMethodPrinter --|> Printer
|
|
27
|
-
|
|
28
|
-
class SourceFilePrinter {
|
|
29
|
-
constructor(arkFile: ArkFile)
|
|
30
|
-
public dump(): string
|
|
31
|
-
}
|
|
32
|
-
SourceFilePrinter --|> Printer
|
|
33
|
-
|
|
34
|
-
class SourceBase {
|
|
35
|
-
constructor(arkFile: ArkFile, indent: string = '')
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
SourceBase --|> Printer
|
|
39
|
-
|
|
40
|
-
class SourceNamespace {
|
|
41
|
-
constructor(ns: ArkNamespace, indent: string = '')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
SourceNamespace --|> SourceBase
|
|
45
|
-
|
|
46
|
-
class SourceClass {
|
|
47
|
-
constructor(cls: ArkClass, indent: string = '')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
SourceClass --|> SourceBase
|
|
51
|
-
|
|
52
|
-
class SourceField {
|
|
53
|
-
constructor(field: ArkField, indent: string = '', initializer: Map<string, string>)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
SourceField --|> SourceBase
|
|
57
|
-
|
|
58
|
-
class SourceMethod {
|
|
59
|
-
constructor(method: ArkMethod, indent: string = '')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
SourceMethod --|> SourceBase
|
|
63
|
-
|
|
64
|
-
class SourceExportInfo {
|
|
65
|
-
constructor(info: ExportInfo, indent: string = '')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
SourceExportInfo --|> SourceBase
|
|
69
|
-
|
|
70
|
-
class SourceImportInfo {
|
|
71
|
-
constructor(info: ImportInfo, indent: string = '')
|
|
72
|
-
}
|
|
73
|
-
SourceImportInfo --|> SourceBase
|
|
74
|
-
|
|
75
|
-
class TransformerContext {
|
|
76
|
-
getPrinter(): ArkCodeBuffer
|
|
77
|
-
transTemp2Code(temp: Local): string
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
<<Interface>> TransformerContext
|
|
81
|
-
SourceBase --|> TransformerContext
|
|
82
|
-
```
|