arkanalyzer 1.0.17 → 1.0.19

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.
Files changed (134) hide show
  1. package/lib/callgraph/pointerAnalysis/Pag.d.ts +3 -2
  2. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
  3. package/lib/callgraph/pointerAnalysis/Pag.js +5 -3
  4. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +4 -4
  5. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
  6. package/lib/callgraph/pointerAnalysis/PagBuilder.js +5 -4
  7. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +2 -0
  8. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
  9. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +11 -9
  10. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +8 -1
  11. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts.map +1 -1
  12. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +27 -3
  13. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +30 -6
  14. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -1
  15. package/lib/callgraph/pointerAnalysis/PtsDS.js +86 -5
  16. package/lib/core/base/Decorator.d.ts +1 -0
  17. package/lib/core/base/Decorator.d.ts.map +1 -1
  18. package/lib/core/base/Decorator.js +4 -1
  19. package/lib/core/base/Stmt.d.ts +3 -0
  20. package/lib/core/base/Stmt.d.ts.map +1 -1
  21. package/lib/core/base/Stmt.js +34 -0
  22. package/lib/core/base/Type.d.ts +45 -3
  23. package/lib/core/base/Type.d.ts.map +1 -1
  24. package/lib/core/base/Type.js +84 -4
  25. package/lib/core/base/TypeExpr.d.ts +72 -0
  26. package/lib/core/base/TypeExpr.d.ts.map +1 -0
  27. package/lib/core/base/TypeExpr.js +155 -0
  28. package/lib/core/common/ArkIRTransformer.d.ts +1 -0
  29. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  30. package/lib/core/common/ArkIRTransformer.js +46 -23
  31. package/lib/core/common/ArkValueTransformer.d.ts +1 -0
  32. package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
  33. package/lib/core/common/ArkValueTransformer.js +66 -16
  34. package/lib/core/common/IRInference.d.ts +5 -1
  35. package/lib/core/common/IRInference.d.ts.map +1 -1
  36. package/lib/core/common/IRInference.js +71 -0
  37. package/lib/core/common/ModelUtils.d.ts +3 -1
  38. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  39. package/lib/core/common/ModelUtils.js +23 -1
  40. package/lib/core/common/TypeInference.d.ts +6 -0
  41. package/lib/core/common/TypeInference.d.ts.map +1 -1
  42. package/lib/core/common/TypeInference.js +82 -14
  43. package/lib/core/{common → graph/builder}/CfgBuilder.d.ts +34 -46
  44. package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -0
  45. package/lib/core/graph/builder/CfgBuilder.js +1139 -0
  46. package/lib/core/graph/builder/ConditionBuilder.d.ts +16 -0
  47. package/lib/core/graph/builder/ConditionBuilder.d.ts.map +1 -0
  48. package/lib/core/graph/builder/ConditionBuilder.js +252 -0
  49. package/lib/core/graph/builder/LoopBuilder.d.ts +21 -0
  50. package/lib/core/graph/builder/LoopBuilder.d.ts.map +1 -0
  51. package/lib/core/graph/builder/LoopBuilder.js +251 -0
  52. package/lib/core/graph/builder/SwitchBuilder.d.ts +12 -0
  53. package/lib/core/graph/builder/SwitchBuilder.d.ts.map +1 -0
  54. package/lib/core/graph/builder/SwitchBuilder.js +152 -0
  55. package/lib/core/graph/builder/TrapBuilder.d.ts +17 -0
  56. package/lib/core/graph/builder/TrapBuilder.d.ts.map +1 -0
  57. package/lib/core/graph/builder/TrapBuilder.js +272 -0
  58. package/lib/core/model/ArkMethod.d.ts +1 -1
  59. package/lib/core/model/ArkMethod.js +1 -1
  60. package/lib/core/model/ArkSignature.d.ts +9 -1
  61. package/lib/core/model/ArkSignature.d.ts.map +1 -1
  62. package/lib/core/model/ArkSignature.js +17 -1
  63. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  64. package/lib/core/model/builder/ArkClassBuilder.js +2 -1
  65. package/lib/core/model/builder/ArkMethodBuilder.js +1 -1
  66. package/lib/core/{common → model/builder}/BodyBuilder.d.ts +5 -5
  67. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -0
  68. package/lib/core/{common → model/builder}/BodyBuilder.js +12 -12
  69. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  70. package/lib/core/model/builder/builderUtils.js +79 -5
  71. package/lib/save/JsonPrinter.d.ts +1 -1
  72. package/lib/save/JsonPrinter.d.ts.map +1 -1
  73. package/lib/save/JsonPrinter.js +2 -2
  74. package/lib/save/PrinterBuilder.d.ts +22 -0
  75. package/lib/save/PrinterBuilder.d.ts.map +1 -1
  76. package/lib/save/PrinterBuilder.js +54 -1
  77. package/lib/save/arkir/ArkIRClassPrinter.d.ts +14 -0
  78. package/lib/save/arkir/ArkIRClassPrinter.d.ts.map +1 -0
  79. package/lib/save/arkir/ArkIRClassPrinter.js +92 -0
  80. package/lib/save/arkir/ArkIRFieldPrinter.d.ts +12 -0
  81. package/lib/save/arkir/ArkIRFieldPrinter.d.ts.map +1 -0
  82. package/lib/save/arkir/ArkIRFieldPrinter.js +64 -0
  83. package/lib/save/arkir/ArkIRFilePrinter.d.ts +13 -0
  84. package/lib/save/arkir/ArkIRFilePrinter.d.ts.map +1 -0
  85. package/lib/save/arkir/ArkIRFilePrinter.js +54 -0
  86. package/lib/save/arkir/ArkIRMethodPrinter.d.ts +17 -0
  87. package/lib/save/arkir/ArkIRMethodPrinter.d.ts.map +1 -0
  88. package/lib/save/arkir/ArkIRMethodPrinter.js +159 -0
  89. package/lib/save/arkir/ArkIRNamespacePrinter.d.ts +12 -0
  90. package/lib/save/arkir/ArkIRNamespacePrinter.d.ts.map +1 -0
  91. package/lib/save/arkir/ArkIRNamespacePrinter.js +66 -0
  92. package/lib/save/base/BasePrinter.d.ts +24 -0
  93. package/lib/save/base/BasePrinter.d.ts.map +1 -0
  94. package/lib/save/base/BasePrinter.js +70 -0
  95. package/lib/save/base/ExportPrinter.d.ts +9 -0
  96. package/lib/save/base/ExportPrinter.d.ts.map +1 -0
  97. package/lib/save/base/ExportPrinter.js +67 -0
  98. package/lib/save/base/ImportPrinter.d.ts +10 -0
  99. package/lib/save/base/ImportPrinter.d.ts.map +1 -0
  100. package/lib/save/base/ImportPrinter.js +92 -0
  101. package/lib/save/{source/SourceUtils.d.ts → base/PrinterUtils.d.ts} +2 -2
  102. package/lib/save/{source/SourceUtils.d.ts.map → base/PrinterUtils.d.ts.map} +1 -1
  103. package/lib/save/{source/SourceUtils.js → base/PrinterUtils.js} +10 -10
  104. package/lib/save/source/SourceBase.d.ts +2 -11
  105. package/lib/save/source/SourceBase.d.ts.map +1 -1
  106. package/lib/save/source/SourceBase.js +3 -25
  107. package/lib/save/source/SourceBody.js +3 -3
  108. package/lib/save/source/SourceClass.d.ts +2 -1
  109. package/lib/save/source/SourceClass.d.ts.map +1 -1
  110. package/lib/save/source/SourceClass.js +18 -17
  111. package/lib/save/source/SourceFilePrinter.d.ts +1 -1
  112. package/lib/save/source/SourceFilePrinter.d.ts.map +1 -1
  113. package/lib/save/source/SourceFilePrinter.js +9 -10
  114. package/lib/save/source/SourceMethod.d.ts +1 -1
  115. package/lib/save/source/SourceMethod.d.ts.map +1 -1
  116. package/lib/save/source/SourceMethod.js +37 -22
  117. package/lib/save/source/SourceNamespace.d.ts.map +1 -1
  118. package/lib/save/source/SourceNamespace.js +6 -6
  119. package/lib/save/source/SourceStmt.d.ts +1 -1
  120. package/lib/save/source/SourceStmt.d.ts.map +1 -1
  121. package/lib/save/source/SourceStmt.js +29 -42
  122. package/lib/save/source/SourceTransformer.d.ts +5 -1
  123. package/lib/save/source/SourceTransformer.d.ts.map +1 -1
  124. package/lib/save/source/SourceTransformer.js +107 -33
  125. package/lib/utils/SparseBitVector.d.ts +11 -2
  126. package/lib/utils/SparseBitVector.d.ts.map +1 -1
  127. package/lib/utils/SparseBitVector.js +70 -3
  128. package/package.json +1 -1
  129. package/lib/core/common/BodyBuilder.d.ts.map +0 -1
  130. package/lib/core/common/CfgBuilder.d.ts.map +0 -1
  131. package/lib/core/common/CfgBuilder.js +0 -1886
  132. package/lib/save/source/SourceModule.d.ts +0 -16
  133. package/lib/save/source/SourceModule.d.ts.map +0 -1
  134. package/lib/save/source/SourceModule.js +0 -125
@@ -56,6 +56,7 @@ const Const_1 = require("./Const");
56
56
  const ValueUtil_1 = require("./ValueUtil");
57
57
  const ArkImport_1 = require("../model/ArkImport");
58
58
  const IRInference_1 = require("./IRInference");
59
+ const TypeExpr_1 = require("../base/TypeExpr");
59
60
  const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'TypeInference');
60
61
  class TypeInference {
61
62
  static inferTypeInArkField(arkField) {
@@ -65,6 +66,7 @@ class TypeInference {
65
66
  const method = (_a = arkClass.getMethodWithName(Const_1.INSTANCE_INIT_METHOD_NAME)) !== null && _a !== void 0 ? _a : arkClass.getMethodWithName(TSConst_1.CONSTRUCTOR_NAME);
66
67
  for (const stmt of stmts) {
67
68
  if (method) {
69
+ this.resolveTypeExprsInStmt(stmt, method);
68
70
  this.resolveExprsInStmt(stmt, method);
69
71
  this.resolveFieldRefsInStmt(stmt, method);
70
72
  this.resolveArkAssignStmt(stmt, method);
@@ -112,7 +114,7 @@ class TypeInference {
112
114
  leftOpType.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
113
115
  type = TypeInference.inferUnclearRefName(leftOpType.getClassSignature().getClassName(), declaringArkClass);
114
116
  }
115
- else if (leftOpType instanceof Type_1.UnionType) {
117
+ else if (leftOpType instanceof Type_1.UnionType || leftOpType instanceof Type_1.IntersectionType || leftOpType instanceof Type_1.TupleType) {
116
118
  let types = leftOpType.getTypes();
117
119
  for (let i = 0; i < types.length; i++) {
118
120
  let newType = this.inferUnclearedType(types[i], declaringArkClass);
@@ -156,10 +158,7 @@ class TypeInference {
156
158
  }
157
159
  signatures.forEach(s => {
158
160
  s.getMethodSubSignature().getParameters().forEach(p => {
159
- const type = TypeInference.inferUnclearedType(p.getType(), arkClass);
160
- if (type) {
161
- p.setType(type);
162
- }
161
+ this.inferParameterType(p, arkMethod);
163
162
  });
164
163
  this.inferSignatureReturnType(s, arkMethod);
165
164
  });
@@ -170,6 +169,7 @@ class TypeInference {
170
169
  const cfg = body.getCfg();
171
170
  for (const block of cfg.getBlocks()) {
172
171
  for (const stmt of block.getStmts()) {
172
+ this.resolveTypeExprsInStmt(stmt, arkMethod);
173
173
  this.resolveExprsInStmt(stmt, arkMethod);
174
174
  this.resolveFieldRefsInStmt(stmt, arkMethod);
175
175
  this.resolveArkAssignStmt(stmt, arkMethod);
@@ -208,6 +208,14 @@ class TypeInference {
208
208
  stmt.getAliasType().setOriginalType(stmt.getAliasTypeExpr().getType());
209
209
  }
210
210
  }
211
+ /**
212
+ * infer value type for TypeExprs in stmt which specify the type such as TypeQueryExpr
213
+ */
214
+ static resolveTypeExprsInStmt(stmt, arkMethod) {
215
+ for (let typeExpr of stmt.getTypeExprs()) {
216
+ typeExpr.inferType(arkMethod);
217
+ }
218
+ }
211
219
  /**
212
220
  * infer type for fieldRefs in stmt.
213
221
  */
@@ -284,14 +292,23 @@ class TypeInference {
284
292
  if (rightType) {
285
293
  this.setValueType(rightOp, rightType);
286
294
  }
295
+ else {
296
+ if (rightOp instanceof Local_1.Local) {
297
+ IRInference_1.IRInference.inferLocal(rightOp, arkMethod);
298
+ rightType = rightOp.getType();
299
+ }
300
+ }
287
301
  }
288
302
  const leftOp = stmt.getLeftOp();
289
303
  let leftType = leftOp.getType();
290
304
  if (this.isUnclearType(leftType)) {
291
- leftType = this.inferUnclearedType(leftType, arkClass);
292
- if (!leftType && !this.isUnclearType(rightType)) {
305
+ const newLeftType = this.inferUnclearedType(leftType, arkClass);
306
+ if (!newLeftType && !this.isUnclearType(rightType)) {
293
307
  leftType = rightType;
294
308
  }
309
+ else if (newLeftType) {
310
+ leftType = newLeftType;
311
+ }
295
312
  }
296
313
  if (leftType && !this.isUnclearType(leftType)) {
297
314
  this.setValueType(leftOp, leftType);
@@ -315,6 +332,7 @@ class TypeInference {
315
332
  }
316
333
  }
317
334
  static isUnclearType(type) {
335
+ // TODO: For UnionType, IntersectionType and TupleType, it should recurse check every item of them.
318
336
  if (!type || type instanceof Type_1.UnknownType || type instanceof Type_1.UnclearReferenceType
319
337
  || type instanceof Type_1.NullType || type instanceof Type_1.UndefinedType) {
320
338
  return true;
@@ -323,14 +341,42 @@ class TypeInference {
323
341
  && type.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
324
342
  return true;
325
343
  }
326
- else if (type instanceof Type_1.UnionType) {
327
- return !!type.getTypes().find(t => t instanceof Type_1.UnclearReferenceType);
344
+ else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
345
+ return !!type.getTypes().find(t => this.hasUnclearReferenceType(t));
328
346
  }
329
347
  else if (type instanceof Type_1.ArrayType) {
330
- return (type.getBaseType() instanceof Type_1.UnclearReferenceType);
348
+ return this.hasUnclearReferenceType(type.getBaseType());
331
349
  }
332
350
  else if (type instanceof Type_1.AliasType) {
333
- return (type.getOriginalType() instanceof Type_1.UnclearReferenceType);
351
+ return this.isUnclearType(type.getOriginalType());
352
+ }
353
+ else if (type instanceof TypeExpr_1.KeyofTypeExpr) {
354
+ return this.isUnclearType(type.getOpType());
355
+ }
356
+ else if (type instanceof TypeExpr_1.TypeQueryExpr) {
357
+ return this.isUnclearType(type.getType());
358
+ }
359
+ return false;
360
+ }
361
+ // This is the temporally function to check unclearReferenceType recursively and can be removed after typeInfer supports multiple candidate types.
362
+ static hasUnclearReferenceType(type) {
363
+ if (type instanceof Type_1.UnclearReferenceType) {
364
+ return true;
365
+ }
366
+ else if (type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType || type instanceof Type_1.TupleType) {
367
+ return !!type.getTypes().find(t => this.hasUnclearReferenceType(t));
368
+ }
369
+ else if (type instanceof Type_1.ArrayType) {
370
+ return this.hasUnclearReferenceType(type.getBaseType());
371
+ }
372
+ else if (type instanceof Type_1.AliasType) {
373
+ return this.hasUnclearReferenceType(type.getOriginalType());
374
+ }
375
+ else if (type instanceof TypeExpr_1.KeyofTypeExpr) {
376
+ return this.hasUnclearReferenceType(type.getOpType());
377
+ }
378
+ else if (type instanceof TypeExpr_1.TypeQueryExpr) {
379
+ return this.hasUnclearReferenceType(type.getType());
334
380
  }
335
381
  return false;
336
382
  }
@@ -382,6 +428,18 @@ class TypeInference {
382
428
  }
383
429
  return value.getType();
384
430
  }
431
+ static inferParameterType(param, arkMethod) {
432
+ let pType = param.getType();
433
+ const type = TypeInference.inferUnclearedType(pType, arkMethod.getDeclaringArkClass());
434
+ if (type) {
435
+ param.setType(type);
436
+ }
437
+ else {
438
+ if (pType instanceof TypeExpr_1.AbstractTypeExpr) {
439
+ pType.inferType(arkMethod);
440
+ }
441
+ }
442
+ }
385
443
  static inferSignatureReturnType(oldSignature, arkMethod) {
386
444
  if (oldSignature.getMethodSubSignature().getMethodName() === TSConst_1.CONSTRUCTOR_NAME) {
387
445
  const newReturnType = new Type_1.ClassType(oldSignature.getDeclaringClassSignature());
@@ -392,6 +450,14 @@ class TypeInference {
392
450
  if (!this.isUnclearType(currReturnType)) {
393
451
  return;
394
452
  }
453
+ if (currReturnType instanceof TypeExpr_1.AbstractTypeExpr) {
454
+ currReturnType.inferType(arkMethod);
455
+ return;
456
+ }
457
+ if (currReturnType instanceof Type_1.ArrayType && currReturnType.getBaseType() instanceof TypeExpr_1.AbstractTypeExpr) {
458
+ currReturnType.getBaseType().inferType(arkMethod);
459
+ return;
460
+ }
395
461
  const newReturnType = this.inferUnclearedType(currReturnType, arkMethod.getDeclaringArkClass());
396
462
  if (newReturnType) {
397
463
  oldSignature.getMethodSubSignature().setReturnType(newReturnType);
@@ -447,9 +513,6 @@ class TypeInference {
447
513
  return new Type_1.ArrayType((_a = realTypes[0]) !== null && _a !== void 0 ? _a : Type_1.AnyType.getInstance(), 1);
448
514
  }
449
515
  let type = this.inferUnclearRefName(urType.getName(), arkClass);
450
- if (type instanceof Type_1.AliasType) {
451
- return type;
452
- }
453
516
  return type ? this.replaceTypeWithReal(type, realTypes) : null;
454
517
  }
455
518
  /**
@@ -629,6 +692,11 @@ class TypeInference {
629
692
  type.flatType().forEach(t => types.push(this.replaceTypeWithReal(t, realTypes)));
630
693
  return new Type_1.UnionType(types, this.replaceTypeWithReal(type.getCurrType(), realTypes));
631
694
  }
695
+ else if (type instanceof Type_1.IntersectionType && realTypes) {
696
+ const types = [];
697
+ type.getTypes().forEach(t => types.push(this.replaceTypeWithReal(t, realTypes)));
698
+ return new Type_1.IntersectionType(types);
699
+ }
632
700
  else if (type instanceof Type_1.ArrayType && realTypes) {
633
701
  const replacedBaseType = this.replaceTypeWithReal(type.getBaseType(), realTypes);
634
702
  return new Type_1.ArrayType(replacedBaseType, type.getDimension());
@@ -1,12 +1,12 @@
1
1
  import * as ts from 'ohos-typescript';
2
- import { Local } from '../base/Local';
3
- import { ArkAliasTypeDefineStmt } from '../base/Stmt';
4
- import { Cfg } from '../graph/Cfg';
5
- import { ArkClass } from '../model/ArkClass';
6
- import { ArkMethod } from '../model/ArkMethod';
7
- import { AliasType } from '../base/Type';
8
- import { Trap } from '../base/Trap';
9
- import { GlobalRef } from '../base/Ref';
2
+ import { Local } from '../../base/Local';
3
+ import { ArkAliasTypeDefineStmt } from '../../base/Stmt';
4
+ import { Cfg } from '../Cfg';
5
+ import { ArkClass } from '../../model/ArkClass';
6
+ import { ArkMethod } from '../../model/ArkMethod';
7
+ import { AliasType } from '../../base/Type';
8
+ import { Trap } from '../../base/Trap';
9
+ import { GlobalRef } from '../../base/Ref';
10
10
  declare class StatementBuilder {
11
11
  type: string;
12
12
  code: string;
@@ -19,7 +19,7 @@ declare class StatementBuilder {
19
19
  astNode: ts.Node | null;
20
20
  scopeID: number;
21
21
  addressCode3: string[];
22
- block: Block | null;
22
+ block: BlockBuilder | null;
23
23
  ifExitPass: boolean;
24
24
  passTmies: number;
25
25
  numOfIdentifier: number;
@@ -29,18 +29,27 @@ declare class StatementBuilder {
29
29
  declare class ConditionStatementBuilder extends StatementBuilder {
30
30
  nextT: StatementBuilder | null;
31
31
  nextF: StatementBuilder | null;
32
- loopBlock: Block | null;
32
+ loopBlock: BlockBuilder | null;
33
33
  condition: string;
34
34
  doStatement: StatementBuilder | null;
35
35
  constructor(type: string, code: string, astNode: ts.Node, scopeID: number);
36
36
  }
37
- declare class SwitchStatementBuilder extends StatementBuilder {
37
+ export declare class SwitchStatementBuilder extends StatementBuilder {
38
38
  nexts: StatementBuilder[];
39
39
  cases: Case[];
40
40
  default: StatementBuilder | null;
41
41
  afterSwitch: StatementBuilder | null;
42
42
  constructor(type: string, code: string, astNode: ts.Node, scopeID: number);
43
43
  }
44
+ export declare class TryStatementBuilder extends StatementBuilder {
45
+ tryFirst: StatementBuilder | null;
46
+ tryExit: StatementBuilder | null;
47
+ catchStatement: StatementBuilder | null;
48
+ catchError: string;
49
+ finallyStatement: StatementBuilder | null;
50
+ afterFinal: StatementBuilder | null;
51
+ constructor(type: string, code: string, astNode: ts.Node, scopeID: number);
52
+ }
44
53
  declare class Case {
45
54
  value: string;
46
55
  stmt: StatementBuilder;
@@ -64,11 +73,11 @@ declare class Scope {
64
73
  id: number;
65
74
  constructor(id: number);
66
75
  }
67
- declare class Block {
76
+ export declare class BlockBuilder {
68
77
  id: number;
69
78
  stmts: StatementBuilder[];
70
- nexts: Block[];
71
- lasts: Block[];
79
+ nexts: BlockBuilder[];
80
+ lasts: BlockBuilder[];
72
81
  walked: boolean;
73
82
  constructor(id: number, stmts: StatementBuilder[]);
74
83
  }
@@ -93,7 +102,7 @@ export declare class CfgBuilder {
93
102
  scopes: Scope[];
94
103
  tempVariableNum: number;
95
104
  current3ACstm: StatementBuilder;
96
- blocks: Block[];
105
+ blocks: BlockBuilder[];
97
106
  currentDeclarationKeyword: string;
98
107
  variables: Variable[];
99
108
  declaringClass: ArkClass;
@@ -122,9 +131,9 @@ export declare class CfgBuilder {
122
131
  addStmt2BlockStmtQueueInSpecialCase(stmt: StatementBuilder, stmtQueue: StatementBuilder[]): StatementBuilder | null;
123
132
  addStmt2BlockStmtQueue(stmt: StatementBuilder, stmtQueue: StatementBuilder[]): StatementBuilder | null;
124
133
  buildBlocks(): void;
125
- buildConditionNextBlocks(originStatement: ConditionStatementBuilder, block: Block, isLastStatement: boolean): void;
126
- buildSwitchNextBlocks(originStatement: SwitchStatementBuilder, block: Block, isLastStatement: boolean): void;
127
- buildNormalNextBlocks(originStatement: StatementBuilder, block: Block, isLastStatement: boolean): void;
134
+ buildConditionNextBlocks(originStatement: ConditionStatementBuilder, block: BlockBuilder, isLastStatement: boolean): void;
135
+ buildSwitchNextBlocks(originStatement: SwitchStatementBuilder, block: BlockBuilder, isLastStatement: boolean): void;
136
+ buildNormalNextBlocks(originStatement: StatementBuilder, block: BlockBuilder, isLastStatement: boolean): void;
128
137
  buildBlocksNextLast(): void;
129
138
  addReturnBlock(returnStatement: StatementBuilder, notReturnStmts: StatementBuilder[]): void;
130
139
  addReturnStmt(): void;
@@ -133,57 +142,36 @@ export declare class CfgBuilder {
133
142
  CfgBuilder2Array(stmt: StatementBuilder): void;
134
143
  getDotEdges(stmt: StatementBuilder): void;
135
144
  errorTest(stmt: StatementBuilder): void;
136
- printBlocks(): string;
137
145
  buildStatementBuilder4ArrowFunction(stmt: ts.Node): void;
138
146
  buildCfgBuilder(): void;
139
147
  private handleBuilder;
140
148
  isBodyEmpty(): boolean;
141
- buildCfgAndOriginalCfg(): {
149
+ buildCfg(): {
142
150
  cfg: Cfg;
143
151
  locals: Set<Local>;
144
152
  globals: Map<string, GlobalRef> | null;
145
153
  aliasTypeMap: Map<string, [AliasType, ArkAliasTypeDefineStmt]>;
146
154
  traps: Trap[];
147
155
  };
148
- buildCfgAndOriginalCfgForSimpleArrowFunction(): {
156
+ buildCfgForSimpleArrowFunction(): {
149
157
  cfg: Cfg;
150
158
  locals: Set<Local>;
151
159
  globals: Map<string, GlobalRef> | null;
152
160
  aliasTypeMap: Map<string, [AliasType, ArkAliasTypeDefineStmt]>;
153
161
  traps: Trap[];
154
162
  };
155
- buildNormalCfgAndOriginalCfg(): {
163
+ buildNormalCfg(): {
156
164
  cfg: Cfg;
157
165
  locals: Set<Local>;
158
166
  globals: Map<string, GlobalRef> | null;
159
167
  aliasTypeMap: Map<string, [AliasType, ArkAliasTypeDefineStmt]>;
160
168
  traps: Trap[];
161
169
  };
170
+ private initializeBuild;
171
+ private processBlocks;
172
+ private adjustBlocks;
173
+ private createCfg;
162
174
  private linkBasicBlocks;
163
- private rebuildBlocksContainConditionalOperator;
164
- private relinkPrevAndSuccOfBlockContainConditionalOperator;
165
- private generateBlocksContainConditionalOperatorGroup;
166
- private generateBlocksContainSingleConditionalOperator;
167
- private generateBlockWithoutConditionalOperator;
168
- private deleteDummyConditionalOperatorStmt;
169
- private findFirstConditionalOperator;
170
- private removeUnnecessaryBlocksInConditionalOperator;
171
- private replaceTempRecursively;
172
- private rebuildBlocksInLoop;
173
- private doesPrevBlockBuilderContainLoop;
174
- private insertBeforeConditionBlockBuilder;
175
- private findIteratorIdx;
176
- private adjustIncrementorStmts;
177
- private buildTraps;
178
- private buildTrapsIfNoFinally;
179
- private buildTrapsIfFinallyExist;
180
- private getAllBlocksBFS;
181
- private copyFinallyBlocks;
182
- private copyBlocks;
183
- private copyStmt;
184
- private buildSwitch;
185
- private generateIfBlocksForCases;
186
- private linkIfBlockAndCaseBlock;
187
175
  }
188
176
  export {};
189
177
  //# sourceMappingURL=CfgBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CfgBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/graph/builder/Cf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