arkanalyzer 1.0.90 → 1.0.92

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 (126) hide show
  1. package/config/arkanalyzer.json +0 -1
  2. package/lib/Config.d.ts +3 -0
  3. package/lib/Config.d.ts.map +1 -1
  4. package/lib/Scene.d.ts +114 -0
  5. package/lib/Scene.d.ts.map +1 -1
  6. package/lib/Scene.js +268 -13
  7. package/lib/callgraph/common/Statistics.js +2 -2
  8. package/lib/callgraph/model/CallGraph.d.ts +2 -2
  9. package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
  10. package/lib/callgraph/model/CallGraph.js +6 -6
  11. package/lib/callgraph/model/CallSite.d.ts +1 -1
  12. package/lib/callgraph/model/CallSite.d.ts.map +1 -1
  13. package/lib/callgraph/model/CallSite.js +2 -2
  14. package/lib/core/base/Ref.d.ts.map +1 -1
  15. package/lib/core/base/Ref.js +6 -1
  16. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  17. package/lib/core/common/ArkIRTransformer.js +5 -0
  18. package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
  19. package/lib/core/common/ArkValueTransformer.js +2 -1
  20. package/lib/core/common/Const.d.ts +3 -0
  21. package/lib/core/common/Const.d.ts.map +1 -1
  22. package/lib/core/common/Const.js +5 -1
  23. package/lib/core/common/DummyMainCreater.d.ts +25 -12
  24. package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
  25. package/lib/core/common/DummyMainCreater.js +90 -76
  26. package/lib/core/common/EtsConst.d.ts +2 -0
  27. package/lib/core/common/EtsConst.d.ts.map +1 -1
  28. package/lib/core/common/EtsConst.js +133 -125
  29. package/lib/core/common/SdkUtils.d.ts +1 -0
  30. package/lib/core/common/SdkUtils.d.ts.map +1 -1
  31. package/lib/core/common/SdkUtils.js +29 -0
  32. package/lib/core/graph/BaseExplicitGraph.d.ts +2 -0
  33. package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
  34. package/lib/core/graph/BaseExplicitGraph.js +12 -1
  35. package/lib/core/graph/BaseImplicitGraph.d.ts +16 -0
  36. package/lib/core/graph/BaseImplicitGraph.d.ts.map +1 -1
  37. package/lib/core/graph/BaseImplicitGraph.js +21 -0
  38. package/lib/core/graph/FileDepGraph.d.ts +75 -0
  39. package/lib/core/graph/FileDepGraph.d.ts.map +1 -0
  40. package/lib/core/graph/FileDepGraph.js +170 -0
  41. package/lib/core/graph/GraphTraits.d.ts +2 -0
  42. package/lib/core/graph/GraphTraits.d.ts.map +1 -1
  43. package/lib/core/graph/GraphTraits.js +1 -1
  44. package/lib/core/graph/ModuleDepGraph.d.ts +175 -0
  45. package/lib/core/graph/ModuleDepGraph.d.ts.map +1 -0
  46. package/lib/core/graph/ModuleDepGraph.js +421 -0
  47. package/lib/core/graph/Scc.d.ts +1 -3
  48. package/lib/core/graph/Scc.d.ts.map +1 -1
  49. package/lib/core/graph/Scc.js +6 -19
  50. package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
  51. package/lib/core/graph/builder/CfgBuilder.js +7 -1
  52. package/lib/core/graph/builder/TrapBuilder.d.ts +1 -0
  53. package/lib/core/graph/builder/TrapBuilder.d.ts.map +1 -1
  54. package/lib/core/graph/builder/TrapBuilder.js +27 -7
  55. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +13 -3
  56. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
  57. package/lib/core/graph/builder/ViewTreeBuilder.js +271 -86
  58. package/lib/core/model/ArkBody.d.ts +1 -0
  59. package/lib/core/model/ArkBody.d.ts.map +1 -1
  60. package/lib/core/model/ArkBody.js +7 -0
  61. package/lib/core/model/ArkClass.d.ts +1 -0
  62. package/lib/core/model/ArkClass.d.ts.map +1 -1
  63. package/lib/core/model/ArkClass.js +37 -0
  64. package/lib/core/model/ArkExport.d.ts +1 -0
  65. package/lib/core/model/ArkExport.d.ts.map +1 -1
  66. package/lib/core/model/ArkExport.js +6 -0
  67. package/lib/core/model/ArkField.d.ts +1 -0
  68. package/lib/core/model/ArkField.d.ts.map +1 -1
  69. package/lib/core/model/ArkField.js +5 -0
  70. package/lib/core/model/ArkFile.d.ts +5 -0
  71. package/lib/core/model/ArkFile.d.ts.map +1 -1
  72. package/lib/core/model/ArkFile.js +30 -0
  73. package/lib/core/model/ArkImport.d.ts +1 -0
  74. package/lib/core/model/ArkImport.d.ts.map +1 -1
  75. package/lib/core/model/ArkImport.js +5 -0
  76. package/lib/core/model/ArkMethod.d.ts +8 -0
  77. package/lib/core/model/ArkMethod.d.ts.map +1 -1
  78. package/lib/core/model/ArkMethod.js +22 -0
  79. package/lib/core/model/ArkModule.d.ts +133 -0
  80. package/lib/core/model/ArkModule.d.ts.map +1 -0
  81. package/lib/core/model/ArkModule.js +247 -0
  82. package/lib/core/model/ArkNamespace.d.ts +1 -0
  83. package/lib/core/model/ArkNamespace.d.ts.map +1 -1
  84. package/lib/core/model/ArkNamespace.js +18 -0
  85. package/lib/core/model/builder/ArkClassBuilder.js +6 -0
  86. package/lib/core/model/builder/ArkFileBuilder.d.ts +19 -0
  87. package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
  88. package/lib/core/model/builder/ArkFileBuilder.js +155 -51
  89. package/lib/frontend/FrontendBuilder.d.ts +114 -0
  90. package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
  91. package/lib/frontend/FrontendBuilder.js +248 -0
  92. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +11 -0
  93. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
  94. package/lib/frontend/arktsFrontend/ArktsFrontend.js +15 -0
  95. package/lib/frontend/common/MemoryMonitor.d.ts +62 -0
  96. package/lib/frontend/common/MemoryMonitor.d.ts.map +1 -0
  97. package/lib/frontend/common/MemoryMonitor.js +108 -0
  98. package/lib/frontend/common/ModuleAnalysisConfig.d.ts +99 -0
  99. package/lib/frontend/common/ModuleAnalysisConfig.d.ts.map +1 -0
  100. package/lib/frontend/common/ModuleAnalysisConfig.js +153 -0
  101. package/lib/frontend/common/ModuleBuilder.d.ts +508 -0
  102. package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -0
  103. package/lib/frontend/common/ModuleBuilder.js +1587 -0
  104. package/lib/frontend/common/ModuleCache.d.ts +120 -0
  105. package/lib/frontend/common/ModuleCache.d.ts.map +1 -0
  106. package/lib/frontend/common/ModuleCache.js +198 -0
  107. package/lib/frontend/common/ModuleDepth.d.ts +33 -0
  108. package/lib/frontend/common/ModuleDepth.d.ts.map +1 -0
  109. package/lib/frontend/common/ModuleDepth.js +55 -0
  110. package/lib/frontend/cppFrontend/CppFrontend.d.ts +5 -0
  111. package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
  112. package/lib/frontend/cppFrontend/CppFrontend.js +11 -1
  113. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +8 -0
  114. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
  115. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +105 -2
  116. package/lib/index.d.ts +9 -1
  117. package/lib/index.d.ts.map +1 -1
  118. package/lib/index.js +22 -3
  119. package/lib/utils/Canonicalizer.d.ts +105 -0
  120. package/lib/utils/Canonicalizer.d.ts.map +1 -0
  121. package/lib/utils/Canonicalizer.js +520 -0
  122. package/lib/utils/ModuleUtils.js +4 -2
  123. package/lib/utils/entryMethodUtils.d.ts +23 -0
  124. package/lib/utils/entryMethodUtils.d.ts.map +1 -1
  125. package/lib/utils/entryMethodUtils.js +53 -1
  126. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ import type { ModuleID } from '../../core/model/ArkModule';
2
+ import type { MemoryMonitor } from './MemoryMonitor';
3
+ import { ModuleDepthLevel } from './ModuleDepth';
4
+ /**
5
+ * Mutable heapUsed estimate tracking state used during eviction.
6
+ *
7
+ * `estimate` starts at the actual heapUsed measured before eviction and is
8
+ * decremented by the heapUsed table value of each unloaded/downgraded module.
9
+ * Eviction stops when `estimate` falls to or below `limit`.
10
+ */
11
+ export interface HeapUsedEstimateState {
12
+ estimate: number;
13
+ limit: number;
14
+ }
15
+ /**
16
+ * Maintains the set of currently-loaded modules and evicts them when memory pressure
17
+ * exceeds the threshold.
18
+ *
19
+ * This class performs Phase 1 only: evicting modules that are neither in the hard nor soft
20
+ * protected set (not depended on by the current or subsequent modules), in LRU order. The
21
+ * caller ({@link ModuleBuilder.evictIfNeeded}) handles the subsequent phases:
22
+ * - **Phase 2** — downgrade protected dependencies to dependencyLoadLevel (release method
23
+ * bodies/AST, keep signatures), in reverse-topo order.
24
+ * - **Phase 2b** — further downgrade protected deps to INDEX (hollow in-place IR).
25
+ * - **Phase 3** — if still over threshold, evict the protected dependencies (full unload),
26
+ * in reverse-topo order.
27
+ *
28
+ * The hard protected set contains modules that must never be evicted (the current target
29
+ * module and its dependency closure). The soft protected set contains modules that are
30
+ * directly depended on by not-yet-loaded modules (evicting them causes reload overhead
31
+ * but is safe).
32
+ *
33
+ * SCC groups: if a module belongs to a cyclic dependency group (size > 1), the entire
34
+ * group is treated as a unit — either all members are evictable or none is evicted.
35
+ *
36
+ * ## heapUsed Table
37
+ *
38
+ * A heapUsed table ({@link heapUsedTable}) records the heapUsed increment observed during
39
+ * the first load of each module at each depth level. This table is:
40
+ * - Populated on first load only (subsequent reloads do not update it).
41
+ * - Not cleared on module unload (persists across load/unload cycles).
42
+ * - Cleared only on full cache reset ({@link clear}).
43
+ *
44
+ * During eviction, the table provides estimated heapUsed decreases for unload/downgrade
45
+ * via the `getHeapUsedDecrease` callback — only one actual heapUsed measurement is taken
46
+ * at the start of eviction, and all subsequent tracking uses table values.
47
+ *
48
+ * @category frontend/common
49
+ */
50
+ export declare class ModuleCache {
51
+ private loadedModules;
52
+ private accessOrder;
53
+ /**
54
+ * Per-module heapUsed table, indexed by depth level.
55
+ * Records the heapUsed increment (bytes) from the first load of each module at each level.
56
+ * Persists across unload/load cycles; cleared only by {@link clear}.
57
+ */
58
+ private heapUsedTable;
59
+ /** Register a module as loaded. */
60
+ register(moduleId: ModuleID): void;
61
+ /** Unregister a module (called after it has been unloaded). Does NOT clear the heapUsed table. */
62
+ unregister(moduleId: ModuleID): void;
63
+ /** Whether the given module is currently loaded. */
64
+ has(moduleId: ModuleID): boolean;
65
+ /** Number of currently loaded modules. */
66
+ size(): number;
67
+ /** All currently loaded module IDs. */
68
+ getLoadedModules(): ModuleID[];
69
+ /** Remove all entries from the cache, including the heapUsed table. */
70
+ clear(): void;
71
+ /**
72
+ * Record the heapUsed increment for a module at the given depth level.
73
+ *
74
+ * Only records on the first load (when no entry exists for this module+level pair).
75
+ * Subsequent reloads do not update the value. Module unload does not erase it.
76
+ *
77
+ * @param moduleId - The module ID.
78
+ * @param level - The depth level at which the module was loaded.
79
+ * @param heapUsedBytes - The heapUsed increment (bytes) observed during loading.
80
+ */
81
+ recordHeapUsed(moduleId: ModuleID, level: ModuleDepthLevel, heapUsedBytes: number): void;
82
+ /**
83
+ * Get the recorded heapUsed for a module at the given depth level.
84
+ *
85
+ * @returns The recorded heapUsed in bytes, or `undefined` if not yet recorded.
86
+ */
87
+ getHeapUsed(moduleId: ModuleID, level: ModuleDepthLevel): number | undefined;
88
+ /**
89
+ * Evict loaded modules until the heapUsed estimate is below the limit (or no more candidates remain).
90
+ *
91
+ * This performs Phase 1 only: evicting modules that are neither in the hard nor soft protected
92
+ * set. Downgrading (Phase 2) and evicting protected dependencies (Phase 3) are handled by
93
+ * the caller (ModuleBuilder.evictIfNeeded).
94
+ *
95
+ * Instead of calling `process.memoryUsage()` after each unload, this method uses the
96
+ * {@link HeapUsedEstimateState} to track the estimated heapUsed. The `getHeapUsedDecrease`
97
+ * callback provides the estimated heapUsed decrease for each module (from the heapUsed table
98
+ * or fallback).
99
+ *
100
+ * @param hardProtectedSet - Modules that must never be evicted.
101
+ * @param softProtectedSet - Modules that should not be evicted in Phase 1.
102
+ * @param monitor - The memory monitor (used only for `isEnabled()` guard).
103
+ * @param unloadFn - Callback to unload a module by ID.
104
+ * @param sccGroups - Optional SCC group map; members of the same group are evicted together.
105
+ * @param heapUsedState - Mutable heapUsed estimate state; `estimate` is decremented as modules are evicted.
106
+ * @param getHeapUsedDecrease - Callback returning the estimated heapUsed decrease (bytes) for a module.
107
+ */
108
+ evict(hardProtectedSet: Set<ModuleID>, softProtectedSet: Set<ModuleID>, monitor: MemoryMonitor, unloadFn: (moduleId: ModuleID) => void, sccGroups: Map<ModuleID, ModuleID[]> | undefined, heapUsedState: HeapUsedEstimateState, getHeapUsedDecrease: (moduleId: ModuleID) => number): void;
109
+ private evictFromList;
110
+ /**
111
+ * Try to evict an SCC group as a unit. Returns true if the module belongs to an SCC group
112
+ * (size > 1) and the group was handled (either evicted or skipped due to protected members).
113
+ * Returns false if the module is not part of a multi-member SCC group.
114
+ *
115
+ * When evicting, the heapUsed decrease for each group member is obtained from
116
+ * `getHeapUsedDecrease` and subtracted from `heapUsedState.estimate`.
117
+ */
118
+ private tryEvictSCCGroup;
119
+ }
120
+ //# sourceMappingURL=ModuleCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModuleCache.d.ts","sourceRoot":"","sources":["../../../src/frontend/common/ModuleCache.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,WAAW,CAAkB;IAErC;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAA2D;IAEhF,mCAAmC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAOzC,kGAAkG;IAC3F,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAS3C,oDAAoD;IAC7C,GAAG,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAIvC,0CAA0C;IACnC,IAAI,IAAI,MAAM;IAIrB,uCAAuC;IAChC,gBAAgB,IAAI,QAAQ,EAAE;IAIrC,uEAAuE;IAChE,KAAK,IAAI,IAAI;IAMpB;;;;;;;;;OASG;IACI,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAW/F;;;;OAIG;IACI,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS;IAInF;;;;;;;;;;;;;;;;;;;OAmBG;IACI,KAAK,CACR,gBAAgB,EAAE,GAAG,CAAC,QAAQ,CAAC,EAC/B,gBAAgB,EAAE,GAAG,CAAC,QAAQ,CAAC,EAC/B,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,EACtC,SAAS,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,EAChD,aAAa,EAAE,qBAAqB,EACpC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,GACpD,IAAI;IAUP,OAAO,CAAC,aAAa;IA2BrB;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;CAwB3B"}
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ModuleCache = void 0;
18
+ /**
19
+ * Maintains the set of currently-loaded modules and evicts them when memory pressure
20
+ * exceeds the threshold.
21
+ *
22
+ * This class performs Phase 1 only: evicting modules that are neither in the hard nor soft
23
+ * protected set (not depended on by the current or subsequent modules), in LRU order. The
24
+ * caller ({@link ModuleBuilder.evictIfNeeded}) handles the subsequent phases:
25
+ * - **Phase 2** — downgrade protected dependencies to dependencyLoadLevel (release method
26
+ * bodies/AST, keep signatures), in reverse-topo order.
27
+ * - **Phase 2b** — further downgrade protected deps to INDEX (hollow in-place IR).
28
+ * - **Phase 3** — if still over threshold, evict the protected dependencies (full unload),
29
+ * in reverse-topo order.
30
+ *
31
+ * The hard protected set contains modules that must never be evicted (the current target
32
+ * module and its dependency closure). The soft protected set contains modules that are
33
+ * directly depended on by not-yet-loaded modules (evicting them causes reload overhead
34
+ * but is safe).
35
+ *
36
+ * SCC groups: if a module belongs to a cyclic dependency group (size > 1), the entire
37
+ * group is treated as a unit — either all members are evictable or none is evicted.
38
+ *
39
+ * ## heapUsed Table
40
+ *
41
+ * A heapUsed table ({@link heapUsedTable}) records the heapUsed increment observed during
42
+ * the first load of each module at each depth level. This table is:
43
+ * - Populated on first load only (subsequent reloads do not update it).
44
+ * - Not cleared on module unload (persists across load/unload cycles).
45
+ * - Cleared only on full cache reset ({@link clear}).
46
+ *
47
+ * During eviction, the table provides estimated heapUsed decreases for unload/downgrade
48
+ * via the `getHeapUsedDecrease` callback — only one actual heapUsed measurement is taken
49
+ * at the start of eviction, and all subsequent tracking uses table values.
50
+ *
51
+ * @category frontend/common
52
+ */
53
+ class ModuleCache {
54
+ constructor() {
55
+ this.loadedModules = new Set();
56
+ this.accessOrder = [];
57
+ /**
58
+ * Per-module heapUsed table, indexed by depth level.
59
+ * Records the heapUsed increment (bytes) from the first load of each module at each level.
60
+ * Persists across unload/load cycles; cleared only by {@link clear}.
61
+ */
62
+ this.heapUsedTable = new Map();
63
+ }
64
+ /** Register a module as loaded. */
65
+ register(moduleId) {
66
+ if (!this.loadedModules.has(moduleId)) {
67
+ this.loadedModules.add(moduleId);
68
+ this.accessOrder.push(moduleId);
69
+ }
70
+ }
71
+ /** Unregister a module (called after it has been unloaded). Does NOT clear the heapUsed table. */
72
+ unregister(moduleId) {
73
+ if (this.loadedModules.delete(moduleId)) {
74
+ const idx = this.accessOrder.indexOf(moduleId);
75
+ if (idx >= 0) {
76
+ this.accessOrder.splice(idx, 1);
77
+ }
78
+ }
79
+ }
80
+ /** Whether the given module is currently loaded. */
81
+ has(moduleId) {
82
+ return this.loadedModules.has(moduleId);
83
+ }
84
+ /** Number of currently loaded modules. */
85
+ size() {
86
+ return this.loadedModules.size;
87
+ }
88
+ /** All currently loaded module IDs. */
89
+ getLoadedModules() {
90
+ return Array.from(this.loadedModules);
91
+ }
92
+ /** Remove all entries from the cache, including the heapUsed table. */
93
+ clear() {
94
+ this.loadedModules.clear();
95
+ this.accessOrder.length = 0;
96
+ this.heapUsedTable.clear();
97
+ }
98
+ /**
99
+ * Record the heapUsed increment for a module at the given depth level.
100
+ *
101
+ * Only records on the first load (when no entry exists for this module+level pair).
102
+ * Subsequent reloads do not update the value. Module unload does not erase it.
103
+ *
104
+ * @param moduleId - The module ID.
105
+ * @param level - The depth level at which the module was loaded.
106
+ * @param heapUsedBytes - The heapUsed increment (bytes) observed during loading.
107
+ */
108
+ recordHeapUsed(moduleId, level, heapUsedBytes) {
109
+ let levelMap = this.heapUsedTable.get(moduleId);
110
+ if (!levelMap) {
111
+ levelMap = new Map();
112
+ this.heapUsedTable.set(moduleId, levelMap);
113
+ }
114
+ if (!levelMap.has(level)) {
115
+ levelMap.set(level, heapUsedBytes);
116
+ }
117
+ }
118
+ /**
119
+ * Get the recorded heapUsed for a module at the given depth level.
120
+ *
121
+ * @returns The recorded heapUsed in bytes, or `undefined` if not yet recorded.
122
+ */
123
+ getHeapUsed(moduleId, level) {
124
+ var _a;
125
+ return (_a = this.heapUsedTable.get(moduleId)) === null || _a === void 0 ? void 0 : _a.get(level);
126
+ }
127
+ /**
128
+ * Evict loaded modules until the heapUsed estimate is below the limit (or no more candidates remain).
129
+ *
130
+ * This performs Phase 1 only: evicting modules that are neither in the hard nor soft protected
131
+ * set. Downgrading (Phase 2) and evicting protected dependencies (Phase 3) are handled by
132
+ * the caller (ModuleBuilder.evictIfNeeded).
133
+ *
134
+ * Instead of calling `process.memoryUsage()` after each unload, this method uses the
135
+ * {@link HeapUsedEstimateState} to track the estimated heapUsed. The `getHeapUsedDecrease`
136
+ * callback provides the estimated heapUsed decrease for each module (from the heapUsed table
137
+ * or fallback).
138
+ *
139
+ * @param hardProtectedSet - Modules that must never be evicted.
140
+ * @param softProtectedSet - Modules that should not be evicted in Phase 1.
141
+ * @param monitor - The memory monitor (used only for `isEnabled()` guard).
142
+ * @param unloadFn - Callback to unload a module by ID.
143
+ * @param sccGroups - Optional SCC group map; members of the same group are evicted together.
144
+ * @param heapUsedState - Mutable heapUsed estimate state; `estimate` is decremented as modules are evicted.
145
+ * @param getHeapUsedDecrease - Callback returning the estimated heapUsed decrease (bytes) for a module.
146
+ */
147
+ evict(hardProtectedSet, softProtectedSet, monitor, unloadFn, sccGroups, heapUsedState, getHeapUsedDecrease) {
148
+ if (!monitor.isEnabled() || heapUsedState.estimate <= heapUsedState.limit) {
149
+ return;
150
+ }
151
+ // Phase 1: evict modules not in hard or soft protected set, in LRU order
152
+ const phase1Protected = new Set([...hardProtectedSet, ...softProtectedSet]);
153
+ this.evictFromList([...this.accessOrder], phase1Protected, unloadFn, sccGroups, heapUsedState, getHeapUsedDecrease);
154
+ }
155
+ evictFromList(list, protectedSet, unloadFn, sccGroups, heapUsedState, getHeapUsedDecrease) {
156
+ for (const moduleId of list) {
157
+ if (heapUsedState.estimate <= heapUsedState.limit) {
158
+ return;
159
+ }
160
+ if (!this.loadedModules.has(moduleId) || protectedSet.has(moduleId)) {
161
+ continue;
162
+ }
163
+ if (sccGroups && this.tryEvictSCCGroup(moduleId, protectedSet, unloadFn, sccGroups, heapUsedState, getHeapUsedDecrease)) {
164
+ continue;
165
+ }
166
+ const decrease = getHeapUsedDecrease(moduleId);
167
+ unloadFn(moduleId);
168
+ this.unregister(moduleId);
169
+ heapUsedState.estimate -= decrease;
170
+ }
171
+ }
172
+ /**
173
+ * Try to evict an SCC group as a unit. Returns true if the module belongs to an SCC group
174
+ * (size > 1) and the group was handled (either evicted or skipped due to protected members).
175
+ * Returns false if the module is not part of a multi-member SCC group.
176
+ *
177
+ * When evicting, the heapUsed decrease for each group member is obtained from
178
+ * `getHeapUsedDecrease` and subtracted from `heapUsedState.estimate`.
179
+ */
180
+ tryEvictSCCGroup(moduleId, protectedSet, unloadFn, sccGroups, heapUsedState, getHeapUsedDecrease) {
181
+ const group = sccGroups.get(moduleId);
182
+ if (!group || group.length <= 1) {
183
+ return false;
184
+ }
185
+ // All members must be evictable and currently loaded
186
+ const blocked = group.some(m => protectedSet.has(m) || !this.loadedModules.has(m));
187
+ if (!blocked) {
188
+ for (const m of group) {
189
+ const decrease = getHeapUsedDecrease(m);
190
+ unloadFn(m);
191
+ this.unregister(m);
192
+ heapUsedState.estimate -= decrease;
193
+ }
194
+ }
195
+ return true;
196
+ }
197
+ }
198
+ exports.ModuleCache = ModuleCache;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Module data depth levels controlling how much data is retained for an {@link ArkModule}.
3
+ * Higher levels are supersets of lower levels (incremental relationship).
4
+ *
5
+ * Valid direct load targets ({@link ModuleAnalysisConfig} / {@link ModuleBuilder.loadModule}):
6
+ * {@link SIGNATURES} and {@link BODIES} only.
7
+ *
8
+ * {@link INDEX} is downgrade/fallback only: hollowed in-place ArkFile IR (export-reachable
9
+ * shells kept so import/type/RTA lookup APIs still work). Passing it to setLoadLevel /
10
+ * setDependencyLoadLevel / loadModule throws — do not use as a load target.
11
+ *
12
+ * @category core/model
13
+ */
14
+ export declare enum ModuleDepthLevel {
15
+ /**
16
+ * Downgrade / fallback only: in-place hollow IR — bodies/AST/source stripped and
17
+ * non-exported classes pruned; {@link ArkFile}/{@link ArkClass}/{@link ArkMethod}
18
+ * shells remain queryable via the same Scene APIs as SIGNATURES.
19
+ * Not a valid direct load target.
20
+ */
21
+ INDEX = 0,
22
+ /**
23
+ * Export/import info + namespaces/classes/method signatures (no method bodies).
24
+ */
25
+ SIGNATURES = 1,
26
+ /**
27
+ * SIGNATURES + method bodies (ArkBody, CFG, Stmt/Expr).
28
+ */
29
+ BODIES = 2
30
+ }
31
+ /** Throws if `level` is {@link ModuleDepthLevel.INDEX} (downgrade-only). */
32
+ export declare function assertDirectLoadLevel(level: ModuleDepthLevel): void;
33
+ //# sourceMappingURL=ModuleDepth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModuleDepth.d.ts","sourceRoot":"","sources":["../../../src/frontend/common/ModuleDepth.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;GAYG;AACH,oBAAY,gBAAgB;IACxB;;;;;OAKG;IACH,KAAK,IAAI;IAET;;OAEG;IACH,UAAU,IAAI;IAEd;;OAEG;IACH,MAAM,IAAI;CACb;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAInE"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.assertDirectLoadLevel = exports.ModuleDepthLevel = void 0;
18
+ /**
19
+ * Module data depth levels controlling how much data is retained for an {@link ArkModule}.
20
+ * Higher levels are supersets of lower levels (incremental relationship).
21
+ *
22
+ * Valid direct load targets ({@link ModuleAnalysisConfig} / {@link ModuleBuilder.loadModule}):
23
+ * {@link SIGNATURES} and {@link BODIES} only.
24
+ *
25
+ * {@link INDEX} is downgrade/fallback only: hollowed in-place ArkFile IR (export-reachable
26
+ * shells kept so import/type/RTA lookup APIs still work). Passing it to setLoadLevel /
27
+ * setDependencyLoadLevel / loadModule throws — do not use as a load target.
28
+ *
29
+ * @category core/model
30
+ */
31
+ var ModuleDepthLevel;
32
+ (function (ModuleDepthLevel) {
33
+ /**
34
+ * Downgrade / fallback only: in-place hollow IR — bodies/AST/source stripped and
35
+ * non-exported classes pruned; {@link ArkFile}/{@link ArkClass}/{@link ArkMethod}
36
+ * shells remain queryable via the same Scene APIs as SIGNATURES.
37
+ * Not a valid direct load target.
38
+ */
39
+ ModuleDepthLevel[ModuleDepthLevel["INDEX"] = 0] = "INDEX";
40
+ /**
41
+ * Export/import info + namespaces/classes/method signatures (no method bodies).
42
+ */
43
+ ModuleDepthLevel[ModuleDepthLevel["SIGNATURES"] = 1] = "SIGNATURES";
44
+ /**
45
+ * SIGNATURES + method bodies (ArkBody, CFG, Stmt/Expr).
46
+ */
47
+ ModuleDepthLevel[ModuleDepthLevel["BODIES"] = 2] = "BODIES";
48
+ })(ModuleDepthLevel = exports.ModuleDepthLevel || (exports.ModuleDepthLevel = {}));
49
+ /** Throws if `level` is {@link ModuleDepthLevel.INDEX} (downgrade-only). */
50
+ function assertDirectLoadLevel(level) {
51
+ if (level === ModuleDepthLevel.INDEX) {
52
+ throw new Error('ModuleDepthLevel.INDEX is not a direct load target; use SIGNATURES or BODIES');
53
+ }
54
+ }
55
+ exports.assertDirectLoadLevel = assertDirectLoadLevel;
@@ -8,6 +8,11 @@ export declare class CppFrontend {
8
8
  private static readonly AUTO_MAX_PARALLEL_PROCESSES;
9
9
  private static readonly AUTO_MAX_PENDING_AST_RESULTS;
10
10
  buildProjectFile(scene: Scene, filePath: string, arkFile: ArkFile): void;
11
+ /**
12
+ * Imports-only build for a single C++ file: parses #include directives and fills
13
+ * ImportInfo without building ArkClass/ArkMethod/ArkBody.
14
+ */
15
+ buildProjectFileForImports(arkFile: ArkFile): void;
11
16
  buildProjectFiles(scene: Scene, filePaths: string[]): FrontendParseResult;
12
17
  /** Returns true if astJsonDumper and cxx-ast-parser are available; otherwise logs a warning. */
13
18
  private requireAstJsonDumper;
@@ -1 +1 @@
1
- {"version":3,"file":"CppFrontend.d.ts","sourceRoot":"","sources":["../../../src/frontend/cppFrontend/CppFrontend.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,EAAwB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAM/E;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAAM;IAEnD,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAOxE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,mBAAmB;IAYhF,gGAAgG;IAChG,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,2BAA2B;IAsBnC,OAAO,CAAC,2BAA2B;IAoBnC,OAAO,CAAC,iBAAiB;CAG5B"}
1
+ {"version":3,"file":"CppFrontend.d.ts","sourceRoot":"","sources":["../../../src/frontend/cppFrontend/CppFrontend.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,EAAwB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK/E;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAAM;IAEnD,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAO/E;;;OAGG;IACI,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAOlD,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,mBAAmB;IAYhF,gGAAgG;IAChG,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,2BAA2B;IAsBnC,OAAO,CAAC,2BAA2B;IAoBnC,OAAO,CAAC,iBAAiB;CAG5B"}
@@ -41,10 +41,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.CppFrontend = void 0;
44
+ const os_1 = __importDefault(require("os"));
44
45
  const logger_1 = __importStar(require("../../utils/logger"));
45
46
  const ArkFileBuilder_1 = require("./model/builder/ArkFileBuilder");
46
47
  const cxxAstParserTypes_1 = require("./utils/cxxAstParserTypes");
47
- const os_1 = __importDefault(require("os"));
48
48
  const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'CppFrontend');
49
49
  /**
50
50
  * C++ language frontend. Matches the former {@link Scene} branches for {@link Language#CXX}.
@@ -56,6 +56,16 @@ class CppFrontend {
56
56
  }
57
57
  (0, ArkFileBuilder_1.prepareArkFile)(scene, filePath, arkFile, this.resolveLogAstInfo(scene));
58
58
  }
59
+ /**
60
+ * Imports-only build for a single C++ file: parses #include directives and fills
61
+ * ImportInfo without building ArkClass/ArkMethod/ArkBody.
62
+ */
63
+ buildProjectFileForImports(arkFile) {
64
+ if (!this.requireAstJsonDumper()) {
65
+ return;
66
+ }
67
+ (0, ArkFileBuilder_1.buildImportExportInfoFromFile)(arkFile);
68
+ }
59
69
  buildProjectFiles(scene, filePaths) {
60
70
  if (!this.requireAstJsonDumper()) {
61
71
  return { arkFiles: [], failedFiles: [] };
@@ -12,6 +12,14 @@ export interface CppStreamBuildResult {
12
12
  */
13
13
  export declare function prepareArkFiles(scene: Scene, absoluteSourceFiles: string[], maxParallelProcesses?: number, maxPendingAstResults?: number, logAstInfo?: boolean): CppStreamBuildResult;
14
14
  export declare function prepareArkFile(scene: Scene, absoluteFilePath: string, targetArkFile: ArkFile, logAstInfo?: boolean): void;
15
+ /**
16
+ * Imports-only variant of {@link prepareArkFile}. Parses the C++ AST for the given
17
+ * file and populates only basic file metadata and ImportInfo (#include directives
18
+ * and using-namespace declarations). Does NOT build ArkClass/ArkMethod/ArkNamespace/ArkBody.
19
+ *
20
+ * @param arkFile - Pre-allocated ArkFile to populate (must have scene and file path set).
21
+ */
22
+ export declare function buildImportExportInfoFromFile(arkFile: ArkFile): void;
15
23
  export declare const classMap: Map<string, ArkClass>;
16
24
  export declare function buildArkClassFromCxxClass(classNode: CxxAstNode, arkFile: ArkFile, astRoot: CxxAstNode): void;
17
25
  //# sourceMappingURL=ArkFileBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ArkFileBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/frontend/cppFrontend/model/builder/ArkFileBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAY,MAAM,gCAAgC,CAAC;AAMnE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAS3D,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAyBhE,MAAM,WAAW,oBAAoB;IACjC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,KAAK,EACZ,mBAAmB,EAAE,MAAM,EAAE,EAC7B,oBAAoB,GAAE,MAAU,EAChC,oBAAoB,GAAE,MAAU,EAChC,UAAU,GAAE,OAAe,GAC5B,oBAAoB,CAkCtB;AAED,wBAAgB,cAAc,CAC1B,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,OAAO,EACtB,UAAU,GAAE,OAAe,GAC5B,IAAI,CA0BN;AAED,eAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAA+B,CAAC;AAE3E,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI,CAU5G"}
1
+ {"version":3,"file":"ArkFileBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/frontend/cppFrontend/model/builder/ArkFileBuilder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAY,MAAM,gCAAgC,CAAC;AAMnE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAS3D,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAwFhE,MAAM,WAAW,oBAAoB;IACjC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,KAAK,EACZ,mBAAmB,EAAE,MAAM,EAAE,EAC7B,oBAAoB,GAAE,MAAU,EAChC,oBAAoB,GAAE,MAAU,EAChC,UAAU,GAAE,OAAe,GAC5B,oBAAoB,CAkCtB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,GAAE,OAAe,GAAG,IAAI,CA0BhI;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4BpE;AAED,eAAO,MAAM,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAA+B,CAAC;AAE3E,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI,CAU5G"}
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  return (mod && mod.__esModule) ? mod : { "default": mod };
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.buildArkClassFromCxxClass = exports.classMap = exports.prepareArkFile = exports.prepareArkFiles = void 0;
43
+ exports.buildArkClassFromCxxClass = exports.classMap = exports.buildImportExportInfoFromFile = exports.prepareArkFile = exports.prepareArkFiles = void 0;
44
44
  const fs_1 = __importDefault(require("fs"));
45
45
  const path_1 = __importDefault(require("path"));
46
46
  const ArkFile_1 = require("../../../../core/model/ArkFile");
@@ -83,13 +83,77 @@ function applyArkFile(arkFile, sourceFile, astRoot) {
83
83
  genDefaultArkClass(arkFile, astRoot);
84
84
  buildArkFile(arkFile, astRoot);
85
85
  }
86
+ /**
87
+ * Lightweight variant of {@link applyArkFile} that only sets basic file metadata and
88
+ * fills ImportInfo from #include / using-namespace directives. It does NOT build
89
+ * ArkClass, ArkMethod, ArkNamespace, or ArkBody.
90
+ *
91
+ * @param arkFile - Target ArkFile to populate.
92
+ * @param sourceFile - Absolute path of the C++ source file.
93
+ * @param astRoot - Root AST node returned by the C++ AST parser.
94
+ */
95
+ function applyArkFileForImports(arkFile, sourceFile, astRoot) {
96
+ var _a;
97
+ const scene = arkFile.getScene();
98
+ const projectDir = scene.getRealProjectDir();
99
+ const projectName = scene.getProjectName();
100
+ arkFile.setFilePath(sourceFile);
101
+ arkFile.setProjectDir(projectDir);
102
+ arkFile.setFileSignature(new ArkSignature_1.FileSignature(projectName, path_1.default.relative(projectDir, sourceFile)));
103
+ const sourceText = fs_1.default.readFileSync(arkFile.getFilePath(), 'utf8');
104
+ const options = scene.getOptions();
105
+ const eagerLoad = (_a = options.saveSourceCodeByDefault) !== null && _a !== void 0 ? _a : false;
106
+ if (eagerLoad && scene.getProjectName() === arkFile.getProjectName()) {
107
+ arkFile.setCode(sourceText);
108
+ }
109
+ buildImportsOnly(arkFile, astRoot);
110
+ }
111
+ /**
112
+ * Imports-only subset of {@link buildArkFile}. Processes #include directives from
113
+ * header units and using-namespace directives from the top-level statement list.
114
+ * Recurses into LinkageSpecDecl nodes which may contain their own includes/usings.
115
+ *
116
+ * @param arkFile - Target ArkFile to populate with ImportInfo.
117
+ * @param astRoot - Root AST node returned by the C++ AST parser.
118
+ */
119
+ function buildImportsOnly(arkFile, astRoot) {
120
+ var _a, _b;
121
+ // handle header units - process #include directives
122
+ (_a = astRoot.headerUnits) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
123
+ var _a;
124
+ if (!child.includes) {
125
+ return;
126
+ }
127
+ for (const includeInfo of child.includes) {
128
+ if (includeInfo.kind !== ArkCxxAstNode_1.AstKind.InclusionDirective) {
129
+ logger.trace('Unprocess kind of header unit: ', (_a = includeInfo.kind) !== null && _a !== void 0 ? _a : includeInfo.includeName);
130
+ continue;
131
+ }
132
+ buildImportInfoFromInclude(includeInfo, child, astRoot, arkFile);
133
+ }
134
+ });
135
+ // handle non-header unit - only import-related declarations
136
+ const statements = (_b = astRoot.inner) !== null && _b !== void 0 ? _b : [];
137
+ statements.forEach((child) => {
138
+ switch (child.kind) {
139
+ case ArkCxxAstNode_1.AstKind.UsingDirectiveDecl:
140
+ buildImportInfoFromUsing(child, astRoot, arkFile);
141
+ break;
142
+ case ArkCxxAstNode_1.AstKind.LinkageSpecDecl:
143
+ buildImportsOnly(arkFile, child);
144
+ break;
145
+ default:
146
+ break;
147
+ }
148
+ });
149
+ }
86
150
  /**
87
151
  * C++ AST manifest pipeline: addon emits per-TU records, consumed synchronously per record.
88
152
  */
89
153
  function prepareArkFiles(scene, absoluteSourceFiles, maxParallelProcesses = 1, maxPendingAstResults = 2, logAstInfo = false) {
90
154
  const arkFiles = [];
91
155
  const failedFiles = [];
92
- const sources = absoluteSourceFiles.map((f) => path_1.default.resolve(f));
156
+ const sources = absoluteSourceFiles.map(f => path_1.default.resolve(f));
93
157
  if (sources.length === 0) {
94
158
  return { arkFiles, failedFiles };
95
159
  }
@@ -150,6 +214,45 @@ function prepareArkFile(scene, absoluteFilePath, targetArkFile, logAstInfo = fal
150
214
  }
151
215
  }
152
216
  exports.prepareArkFile = prepareArkFile;
217
+ /**
218
+ * Imports-only variant of {@link prepareArkFile}. Parses the C++ AST for the given
219
+ * file and populates only basic file metadata and ImportInfo (#include directives
220
+ * and using-namespace declarations). Does NOT build ArkClass/ArkMethod/ArkNamespace/ArkBody.
221
+ *
222
+ * @param arkFile - Pre-allocated ArkFile to populate (must have scene and file path set).
223
+ */
224
+ function buildImportExportInfoFromFile(arkFile) {
225
+ var _a, _b;
226
+ const scene = arkFile.getScene();
227
+ const sourceFile = path_1.default.resolve(arkFile.getFilePath());
228
+ const projectDir = scene.getRealProjectDir();
229
+ const includeDirs = scene.getIncludeDirs();
230
+ const logAstInfo = ((_b = (_a = scene.getOptions().languages) === null || _a === void 0 ? void 0 : _a.cpp) === null || _b === void 0 ? void 0 : _b.logAstInfo) === true;
231
+ const result = getAstParser().runCppAst({
232
+ scene,
233
+ sources: [sourceFile],
234
+ projectDir,
235
+ includeDirs,
236
+ maxParallelProcesses: 1,
237
+ maxPendingAstResults: 2,
238
+ logAstInfo,
239
+ onSourceAst: (source, astRoot) => {
240
+ try {
241
+ applyArkFileForImports(arkFile, source, astRoot);
242
+ }
243
+ catch (err) {
244
+ logger.warn(`Failed to apply C++ AST (imports-only) to ArkFile: ${source}`, err);
245
+ }
246
+ },
247
+ });
248
+ for (const e of result.dumpErrors) {
249
+ logger.warn(`C++ AST dump error for ${e.filePath}`, e.reason);
250
+ }
251
+ if (result.exitCode !== 0) {
252
+ logger.warn(`C++ single-file AST parse not completed successfully: ${sourceFile}`);
253
+ }
254
+ }
255
+ exports.buildImportExportInfoFromFile = buildImportExportInfoFromFile;
153
256
  exports.classMap = new Map();
154
257
  function buildArkClassFromCxxClass(classNode, arkFile, astRoot) {
155
258
  let cls = new ArkClass_1.ArkClass();
package/lib/index.d.ts CHANGED
@@ -42,8 +42,15 @@ export { ViewTree, ViewTreeNode } from './core/graph/ViewTree';
42
42
  export { DominanceFinder } from './core/graph/DominanceFinder';
43
43
  export { DominanceTree } from './core/graph/DominanceTree';
44
44
  export { NodeID, Kind, BaseEdge, BaseNode, BaseExplicitGraph } from './core/graph/BaseExplicitGraph';
45
+ export { BaseImplicitGraph } from './core/graph/BaseImplicitGraph';
45
46
  export { SCCDetection } from './core/graph/Scc';
47
+ export { ModuleDepGraph, DependencyType } from './core/graph/ModuleDepGraph';
48
+ export { FileDepGraph } from './core/graph/FileDepGraph';
46
49
  export { ArkFile } from './core/model/ArkFile';
50
+ export { ArkModule, ModuleLoadState, ModuleType, ModuleID } from './core/model/ArkModule';
51
+ export { ModuleDepthLevel } from './frontend/common/ModuleDepth';
52
+ export { ModuleAnalysisConfig, ModuleAnalysisCallback } from './frontend/common/ModuleAnalysisConfig';
53
+ export { ModuleBuilder } from './frontend/common/ModuleBuilder';
47
54
  export { ArkNamespace } from './core/model/ArkNamespace';
48
55
  export { ArkClass } from './core/model/ArkClass';
49
56
  export { ArkMethod } from './core/model/ArkMethod';
@@ -53,7 +60,7 @@ export { ImportInfo } from './core/model/ArkImport';
53
60
  export { ArkBody } from './core/model/ArkBody';
54
61
  export * from './core/model/ArkSignature';
55
62
  export * from './core/model/builder/ArkSignatureBuilder';
56
- export { SceneConfig, SceneOptions, buildSceneConfigFromProject, LanguageOptions, SceneLanguagesOptions, } from './Config';
63
+ export { SceneConfig, SceneOptions, buildSceneConfigFromProject, LanguageOptions, SceneLanguagesOptions } from './Config';
57
64
  export { Scene } from './Scene';
58
65
  export { FrontendBuilder, FrontendParseFailure, FrontendParseResult } from './frontend/FrontendBuilder';
59
66
  export { ArktsFrontend } from './frontend/arktsFrontend/ArktsFrontend';
@@ -82,6 +89,7 @@ export { default as Logger } from './utils/logger';
82
89
  export { IntMap } from './utils/IntMap';
83
90
  export { IntWorkList } from './utils/IntWorkList';
84
91
  export { PackedSparseMap } from './utils/PackedSparseMap';
92
+ export { Canonicalizer } from './utils/Canonicalizer';
85
93
  import ts from 'ohos-typescript';
86
94
  export { ts };
87
95
  //# sourceMappingURL=index.d.ts.map