arkanalyzer 1.0.90 → 1.0.91
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/config/arkanalyzer.json +0 -1
- package/lib/Config.d.ts +3 -0
- package/lib/Config.d.ts.map +1 -1
- package/lib/Scene.d.ts +99 -0
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +229 -13
- package/lib/callgraph/common/Statistics.js +2 -2
- package/lib/callgraph/model/CallGraph.d.ts +2 -2
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
- package/lib/callgraph/model/CallGraph.js +6 -6
- package/lib/callgraph/model/CallSite.d.ts +1 -1
- package/lib/callgraph/model/CallSite.d.ts.map +1 -1
- package/lib/callgraph/model/CallSite.js +2 -2
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +6 -1
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +5 -0
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +2 -1
- package/lib/core/common/Const.d.ts +3 -0
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +5 -1
- package/lib/core/common/DummyMainCreater.d.ts +25 -12
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +90 -76
- package/lib/core/common/EtsConst.d.ts +2 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -1
- package/lib/core/common/EtsConst.js +133 -125
- package/lib/core/common/SdkUtils.d.ts +1 -0
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +29 -0
- package/lib/core/graph/BaseExplicitGraph.d.ts +2 -0
- package/lib/core/graph/BaseExplicitGraph.d.ts.map +1 -1
- package/lib/core/graph/BaseExplicitGraph.js +12 -1
- package/lib/core/graph/BaseImplicitGraph.d.ts +16 -0
- package/lib/core/graph/BaseImplicitGraph.d.ts.map +1 -1
- package/lib/core/graph/BaseImplicitGraph.js +21 -0
- package/lib/core/graph/FileDepGraph.d.ts +75 -0
- package/lib/core/graph/FileDepGraph.d.ts.map +1 -0
- package/lib/core/graph/FileDepGraph.js +170 -0
- package/lib/core/graph/GraphTraits.d.ts +2 -0
- package/lib/core/graph/GraphTraits.d.ts.map +1 -1
- package/lib/core/graph/GraphTraits.js +1 -1
- package/lib/core/graph/ModuleDepGraph.d.ts +175 -0
- package/lib/core/graph/ModuleDepGraph.d.ts.map +1 -0
- package/lib/core/graph/ModuleDepGraph.js +421 -0
- package/lib/core/graph/Scc.d.ts +1 -3
- package/lib/core/graph/Scc.d.ts.map +1 -1
- package/lib/core/graph/Scc.js +6 -19
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +7 -1
- package/lib/core/graph/builder/TrapBuilder.d.ts +1 -0
- package/lib/core/graph/builder/TrapBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/TrapBuilder.js +27 -7
- package/lib/core/model/ArkBody.d.ts +1 -0
- package/lib/core/model/ArkBody.d.ts.map +1 -1
- package/lib/core/model/ArkBody.js +7 -0
- package/lib/core/model/ArkClass.d.ts +1 -0
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +37 -0
- package/lib/core/model/ArkExport.d.ts +1 -0
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +6 -0
- package/lib/core/model/ArkField.d.ts +1 -0
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +5 -0
- package/lib/core/model/ArkFile.d.ts +5 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +30 -0
- package/lib/core/model/ArkImport.d.ts +1 -0
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +5 -0
- package/lib/core/model/ArkMethod.d.ts +8 -0
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +22 -0
- package/lib/core/model/ArkModule.d.ts +136 -0
- package/lib/core/model/ArkModule.d.ts.map +1 -0
- package/lib/core/model/ArkModule.js +250 -0
- package/lib/core/model/ArkNamespace.d.ts +1 -0
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +18 -0
- package/lib/core/model/builder/ArkFileBuilder.d.ts +19 -0
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +155 -51
- package/lib/frontend/FrontendBuilder.d.ts +116 -0
- package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
- package/lib/frontend/FrontendBuilder.js +256 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +11 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
- package/lib/frontend/arktsFrontend/ArktsFrontend.js +15 -0
- package/lib/frontend/common/MemoryMonitor.d.ts +62 -0
- package/lib/frontend/common/MemoryMonitor.d.ts.map +1 -0
- package/lib/frontend/common/MemoryMonitor.js +108 -0
- package/lib/frontend/common/ModuleAnalysisConfig.d.ts +92 -0
- package/lib/frontend/common/ModuleAnalysisConfig.d.ts.map +1 -0
- package/lib/frontend/common/ModuleAnalysisConfig.js +144 -0
- package/lib/frontend/common/ModuleBuilder.d.ts +497 -0
- package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -0
- package/lib/frontend/common/ModuleBuilder.js +1458 -0
- package/lib/frontend/common/ModuleCache.d.ts +119 -0
- package/lib/frontend/common/ModuleCache.d.ts.map +1 -0
- package/lib/frontend/common/ModuleCache.js +197 -0
- package/lib/frontend/common/ModuleDepth.d.ts +28 -0
- package/lib/frontend/common/ModuleDepth.d.ts.map +1 -0
- package/lib/frontend/common/ModuleDepth.js +45 -0
- package/lib/frontend/cppFrontend/CppFrontend.d.ts +5 -0
- package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/CppFrontend.js +11 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +8 -0
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +105 -2
- package/lib/index.d.ts +9 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +22 -3
- package/lib/utils/Canonicalizer.d.ts +105 -0
- package/lib/utils/Canonicalizer.d.ts.map +1 -0
- package/lib/utils/Canonicalizer.js +520 -0
- package/lib/utils/ModuleUtils.js +4 -2
- package/lib/utils/entryMethodUtils.d.ts +23 -0
- package/lib/utils/entryMethodUtils.d.ts.map +1 -1
- package/lib/utils/entryMethodUtils.js +53 -1
- package/package.json +1 -1
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.ArkModule = exports.ModuleType = exports.ModuleLoadState = void 0;
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const json5parser_1 = require("../../utils/json5parser");
|
|
24
|
+
/**
|
|
25
|
+
* Lifecycle state of an {@link ArkModule}. Stored in the low 3 bits of {@link ArkModule.tags}.
|
|
26
|
+
*
|
|
27
|
+
* The states form an incremental progression: each state is a superset of the previous one,
|
|
28
|
+
* matching the {@link ModuleDepthLevel} data depth levels.
|
|
29
|
+
*/
|
|
30
|
+
var ModuleLoadState;
|
|
31
|
+
(function (ModuleLoadState) {
|
|
32
|
+
/** No data loaded yet. */
|
|
33
|
+
ModuleLoadState[ModuleLoadState["NOT_LOADED"] = 0] = "NOT_LOADED";
|
|
34
|
+
/** Module metadata + dependency topology + ArkFile path-only basic info. */
|
|
35
|
+
ModuleLoadState[ModuleLoadState["META"] = 1] = "META";
|
|
36
|
+
/** META + export/import info for all ArkFiles + intra-module file dependencies. */
|
|
37
|
+
ModuleLoadState[ModuleLoadState["IMPORTS"] = 2] = "IMPORTS";
|
|
38
|
+
/** IMPORTS + ArkFile content excluding method bodies (namespaces, classes, signatures). */
|
|
39
|
+
ModuleLoadState[ModuleLoadState["SIGNATURES"] = 3] = "SIGNATURES";
|
|
40
|
+
/** SIGNATURES + method bodies (ArkBody, CFG, Stmt/Expr). */
|
|
41
|
+
ModuleLoadState[ModuleLoadState["BODIES"] = 4] = "BODIES";
|
|
42
|
+
})(ModuleLoadState = exports.ModuleLoadState || (exports.ModuleLoadState = {}));
|
|
43
|
+
/**
|
|
44
|
+
* Category of an {@link ArkModule}. Stored in bits 3-4 of {@link ArkModule.tags}.
|
|
45
|
+
*/
|
|
46
|
+
var ModuleType;
|
|
47
|
+
(function (ModuleType) {
|
|
48
|
+
/** In-project module (HAP/HSP/HAR) from build-profile.json5. */
|
|
49
|
+
ModuleType[ModuleType["PROJECT"] = 0] = "PROJECT";
|
|
50
|
+
/** SDK sub-module from the SDK directory (e.g. openharmony/ets/api, ets/kits). */
|
|
51
|
+
ModuleType[ModuleType["SDK"] = 1] = "SDK";
|
|
52
|
+
/** Third-party dependency module under oh_modules. */
|
|
53
|
+
ModuleType[ModuleType["OH_MODULES"] = 2] = "OH_MODULES";
|
|
54
|
+
})(ModuleType = exports.ModuleType || (exports.ModuleType = {}));
|
|
55
|
+
// Bit-field layout of `tags` (modeled after ArkBaseModel.tags):
|
|
56
|
+
// bits 0-2: ModuleLoadState (3 bits, mask 0b111, values 0-4)
|
|
57
|
+
// bits 3-4: ModuleType (2 bits, mask 0b11 << 3, values 0-2)
|
|
58
|
+
const MODULE_LOAD_STATE_MASK = 0b111;
|
|
59
|
+
const MODULE_LOAD_STATE_SHIFT = 0;
|
|
60
|
+
const MODULE_TYPE_MASK = 0b11 << 3;
|
|
61
|
+
const MODULE_TYPE_SHIFT = 3;
|
|
62
|
+
/**
|
|
63
|
+
* ArkModule is the new layer between {@link Scene} and {@link ArkFile}, corresponding to a single
|
|
64
|
+
* module (HAP/HSP/HAR) of an OpenHarmony application.
|
|
65
|
+
*
|
|
66
|
+
* `loadState` and `moduleType` share a single `number` bit-field (`tags`), read/written via
|
|
67
|
+
* {@link setTagValue}/{@link getTagValue}, following the pattern in `ArkBaseModel.tags`.
|
|
68
|
+
* The default `tags` value `0` means `ModuleLoadState.NOT_LOADED | ModuleType.PROJECT`.
|
|
69
|
+
*
|
|
70
|
+
* @category core/model
|
|
71
|
+
*/
|
|
72
|
+
class ArkModule {
|
|
73
|
+
constructor(scene) {
|
|
74
|
+
/** Absolute path of the module (primary identifier). */
|
|
75
|
+
this.modulePath = '';
|
|
76
|
+
/** Module name from oh-package.json5 (e.g. "@ohos/entry"); auxiliary field. */
|
|
77
|
+
this.moduleName = '';
|
|
78
|
+
/** key: {@link FileSignature.toMapKey} */
|
|
79
|
+
this.filesMap = new Map();
|
|
80
|
+
/**
|
|
81
|
+
* Alias-to-id mapping for dependencies, defined at the use site.
|
|
82
|
+
* key: alias in this module's oh-package.json5 dependencies (e.g. "@ohos/library").
|
|
83
|
+
* value: ModuleID of the depended-on module.
|
|
84
|
+
*/
|
|
85
|
+
this.dependencyAliasToId = new Map();
|
|
86
|
+
/**
|
|
87
|
+
* Unresolved dependencies (not participating in inter-module topological sort).
|
|
88
|
+
* key: alias, value: version or path.
|
|
89
|
+
*/
|
|
90
|
+
this.unresolvedDependencies = new Map();
|
|
91
|
+
/**
|
|
92
|
+
* Bit-field encoding loadState (bits 0-2) and moduleType (bits 3-4).
|
|
93
|
+
* Default 0 = ModuleLoadState.NOT_LOADED | ModuleType.PROJECT.
|
|
94
|
+
*/
|
|
95
|
+
this.tags = 0;
|
|
96
|
+
this.scene = scene;
|
|
97
|
+
}
|
|
98
|
+
/** Returns the owning {@link Scene} of this module. */
|
|
99
|
+
getScene() {
|
|
100
|
+
return this.scene;
|
|
101
|
+
}
|
|
102
|
+
// --- Bit-field helpers (modeled after ArkBaseModel.setTagValue/getTagValue) ---
|
|
103
|
+
setTagValue(mask, shift, value) {
|
|
104
|
+
this.tags = (this.tags & ~mask) | ((value << shift) & mask);
|
|
105
|
+
}
|
|
106
|
+
getTagValue(mask, shift) {
|
|
107
|
+
return (this.tags & mask) >>> shift;
|
|
108
|
+
}
|
|
109
|
+
// --- getters/setters ---
|
|
110
|
+
getModulePath() {
|
|
111
|
+
return this.modulePath;
|
|
112
|
+
}
|
|
113
|
+
setModulePath(modulePath) {
|
|
114
|
+
this.modulePath = modulePath;
|
|
115
|
+
}
|
|
116
|
+
getModuleName() {
|
|
117
|
+
return this.moduleName;
|
|
118
|
+
}
|
|
119
|
+
setModuleName(moduleName) {
|
|
120
|
+
this.moduleName = moduleName;
|
|
121
|
+
}
|
|
122
|
+
getFilesMap() {
|
|
123
|
+
return this.filesMap;
|
|
124
|
+
}
|
|
125
|
+
getLoadState() {
|
|
126
|
+
return this.getTagValue(MODULE_LOAD_STATE_MASK, MODULE_LOAD_STATE_SHIFT);
|
|
127
|
+
}
|
|
128
|
+
setLoadState(state) {
|
|
129
|
+
this.setTagValue(MODULE_LOAD_STATE_MASK, MODULE_LOAD_STATE_SHIFT, state);
|
|
130
|
+
}
|
|
131
|
+
getModuleType() {
|
|
132
|
+
return this.getTagValue(MODULE_TYPE_MASK, MODULE_TYPE_SHIFT);
|
|
133
|
+
}
|
|
134
|
+
setModuleType(type) {
|
|
135
|
+
this.setTagValue(MODULE_TYPE_MASK, MODULE_TYPE_SHIFT, type);
|
|
136
|
+
}
|
|
137
|
+
// --- Dependency queries ---
|
|
138
|
+
/**
|
|
139
|
+
* Returns the list of modules this module directly depends on (successor dependencies).
|
|
140
|
+
* Reads from the module dependency graph maintained by the Scene.
|
|
141
|
+
* Returns an empty array when the dependency graph has not been built yet.
|
|
142
|
+
*/
|
|
143
|
+
getDependencies() {
|
|
144
|
+
const depGraph = this.scene.getModuleDepGraph();
|
|
145
|
+
if (!depGraph) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
const moduleId = depGraph.tryGetNodeID(this);
|
|
149
|
+
if (moduleId === undefined) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
const succIds = depGraph.getSuccModuleIds(moduleId);
|
|
153
|
+
const result = [];
|
|
154
|
+
for (const succId of succIds) {
|
|
155
|
+
const mod = depGraph.tryGetNode(succId);
|
|
156
|
+
if (mod) {
|
|
157
|
+
result.push(mod);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns the list of modules that directly depend on this module (predecessor dependents).
|
|
164
|
+
* Reads from the module dependency graph maintained by the Scene.
|
|
165
|
+
* Returns an empty array when the dependency graph has not been built yet.
|
|
166
|
+
*/
|
|
167
|
+
getDependents() {
|
|
168
|
+
const depGraph = this.scene.getModuleDepGraph();
|
|
169
|
+
if (!depGraph) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const moduleId = depGraph.tryGetNodeID(this);
|
|
173
|
+
if (moduleId === undefined) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
const predIds = depGraph.getPredModuleIds(moduleId);
|
|
177
|
+
const result = [];
|
|
178
|
+
for (const predId of predIds) {
|
|
179
|
+
const mod = depGraph.tryGetNode(predId);
|
|
180
|
+
if (mod) {
|
|
181
|
+
result.push(mod);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
// --- Dependency management ---
|
|
187
|
+
/**
|
|
188
|
+
* Record an alias for a depended-on module within this module.
|
|
189
|
+
* For example, given dependencies: { "@ohos/library": "file:../library" } in oh-package.json5,
|
|
190
|
+
* alias = "@ohos/library", depId = ModuleID of the library module.
|
|
191
|
+
*/
|
|
192
|
+
addDependencyAlias(alias, depId) {
|
|
193
|
+
this.dependencyAliasToId.set(alias, depId);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Resolve the ModuleID of a depended-on module by its alias defined in this module.
|
|
197
|
+
*/
|
|
198
|
+
resolveDependencyAlias(alias) {
|
|
199
|
+
return this.dependencyAliasToId.get(alias);
|
|
200
|
+
}
|
|
201
|
+
getDependencyAliasToId() {
|
|
202
|
+
return this.dependencyAliasToId;
|
|
203
|
+
}
|
|
204
|
+
// --- Unresolved dependencies ---
|
|
205
|
+
addUnresolvedDependency(alias, value) {
|
|
206
|
+
this.unresolvedDependencies.set(alias, value);
|
|
207
|
+
}
|
|
208
|
+
getUnresolvedDependencies() {
|
|
209
|
+
return this.unresolvedDependencies;
|
|
210
|
+
}
|
|
211
|
+
// --- File dependency analysis ---
|
|
212
|
+
/** The intra-module file dependency graph, or undefined before analysis. */
|
|
213
|
+
getFileDepGraph() {
|
|
214
|
+
return this.fileDepGraph;
|
|
215
|
+
}
|
|
216
|
+
setFileDepGraph(graph) {
|
|
217
|
+
this.fileDepGraph = graph;
|
|
218
|
+
}
|
|
219
|
+
/** Whether file dependency analysis has produced a topological order. */
|
|
220
|
+
hasFileTopoOrder() {
|
|
221
|
+
return this.fileDepGraph !== undefined && this.fileDepGraph.getTopoOrder().length > 0;
|
|
222
|
+
}
|
|
223
|
+
// --- File management ---
|
|
224
|
+
addFile(arkFile) {
|
|
225
|
+
this.filesMap.set(arkFile.getFileSignature().toMapKey(), arkFile);
|
|
226
|
+
}
|
|
227
|
+
clearFilesMap() {
|
|
228
|
+
this.filesMap.clear();
|
|
229
|
+
}
|
|
230
|
+
// --- oh-package.json5 reading ---
|
|
231
|
+
/**
|
|
232
|
+
* Returns the absolute path of this module's oh-package.json5.
|
|
233
|
+
* Derived from the module path, not stored persistently.
|
|
234
|
+
*/
|
|
235
|
+
getOhPkgPath() {
|
|
236
|
+
return path_1.default.join(this.modulePath, 'oh-package.json5');
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Reads and parses oh-package.json5 on demand (not stored persistently).
|
|
240
|
+
* Used only during the build phase. Returns `{}` if the file does not exist.
|
|
241
|
+
*/
|
|
242
|
+
readOhPkgContent() {
|
|
243
|
+
const ohPkgPath = this.getOhPkgPath();
|
|
244
|
+
if (!fs_1.default.existsSync(ohPkgPath)) {
|
|
245
|
+
return {};
|
|
246
|
+
}
|
|
247
|
+
return (0, json5parser_1.fetchDependenciesFromFile)(ohPkgPath);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.ArkModule = ArkModule;
|
|
@@ -124,5 +124,6 @@ export declare class ArkNamespace extends ArkBaseModel implements ArkExport {
|
|
|
124
124
|
removeArkClass(arkClass: ArkClass): boolean;
|
|
125
125
|
removeNamespace(namespace: ArkNamespace): boolean;
|
|
126
126
|
validate(): ArkError;
|
|
127
|
+
clearAllReferences(): void;
|
|
127
128
|
}
|
|
128
129
|
//# sourceMappingURL=ArkNamespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkNamespace.d.ts","sourceRoot":"","sources":["../../../src/core/model/ArkNamespace.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO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,GAAG,OAAO;IAM3C,eAAe,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO;IAMjD,QAAQ,IAAI,QAAQ;IAIpB,kBAAkB,IAAI,IAAI;CAYpC"}
|
|
@@ -306,5 +306,23 @@ class ArkNamespace extends ArkBaseModel_1.ArkBaseModel {
|
|
|
306
306
|
validate() {
|
|
307
307
|
return this.validateFields(['declaringArkFile', 'declaringInstance', 'namespaceSignature', 'defaultClass']);
|
|
308
308
|
}
|
|
309
|
+
clearAllReferences() {
|
|
310
|
+
for (const cls of this.classes.values()) {
|
|
311
|
+
cls.clearAllReferences();
|
|
312
|
+
}
|
|
313
|
+
for (const ns of this.namespaces.values()) {
|
|
314
|
+
ns.clearAllReferences();
|
|
315
|
+
}
|
|
316
|
+
for (const exp of this.exportInfos.values()) {
|
|
317
|
+
exp.clearAllReferences();
|
|
318
|
+
}
|
|
319
|
+
this.classes.clear();
|
|
320
|
+
this.namespaces.clear();
|
|
321
|
+
this.exportInfos.clear();
|
|
322
|
+
this.defaultClass = undefined;
|
|
323
|
+
this.declaringArkFile = undefined;
|
|
324
|
+
this.declaringArkNamespace = null;
|
|
325
|
+
this.declaringInstance = undefined;
|
|
326
|
+
}
|
|
309
327
|
}
|
|
310
328
|
exports.ArkNamespace = ArkNamespace;
|
|
@@ -7,4 +7,23 @@ export declare const notStmtOrExprKind: string[];
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
export declare function buildArkFileFromFile(absoluteFilePath: string, projectDir: string, arkFile: ArkFile, projectName: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Lightweight entry of building ImportInfo/ExportInfo on ArkFile without building ArkClass/ArkMethod/ArkNamespace/ArkBody.
|
|
12
|
+
*
|
|
13
|
+
* @param arkFile
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildImportExportInfoFromFile(arkFile: ArkFile): void;
|
|
17
|
+
/**
|
|
18
|
+
* Signatures-only upgrade entry: builds ArkClass/ArkMethod/ArkNamespace signatures on top of an
|
|
19
|
+
* ArkFile whose ImportInfo/ExportInfo were already populated (e.g. by {@link buildImportExportInfoFromFile}).
|
|
20
|
+
*
|
|
21
|
+
* Unlike {@link buildArkFileFromFile}, this function calls {@link buildArkFile} with
|
|
22
|
+
* `skipImportExport = true`, so existing import/export data is preserved and not re-parsed. This
|
|
23
|
+
* avoids duplicating `export *` re-export entries whose temp clause keys are process-level
|
|
24
|
+
* auto-increment values that cannot be overwritten by `Map.set`.
|
|
25
|
+
*
|
|
26
|
+
* @param arkFile - The ArkFile to upgrade. Must already have filePath set.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildArkFileSignaturesFromFile(arkFile: ArkFile): void;
|
|
10
29
|
//# sourceMappingURL=ArkFileBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArkFileBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkFileBuilder.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,OAAO,EAAY,MAAM,YAAY,CAAC;AAyB/C,eAAO,MAAM,iBAAiB,UAiB7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CA0B9H"}
|
|
1
|
+
{"version":3,"file":"ArkFileBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/model/builder/ArkFileBuilder.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,OAAO,EAAY,MAAM,YAAY,CAAC;AAyB/C,eAAO,MAAM,iBAAiB,UAiB7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CA0B9H;AAiHD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAWpE;AAgCD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAcrE"}
|
|
@@ -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.buildArkFileFromFile = exports.notStmtOrExprKind = void 0;
|
|
43
|
+
exports.buildArkFileSignaturesFromFile = exports.buildImportExportInfoFromFile = exports.buildArkFileFromFile = exports.notStmtOrExprKind = void 0;
|
|
44
44
|
const fs_1 = __importDefault(require("fs"));
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
46
|
const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
|
|
@@ -113,49 +113,144 @@ function buildArkFileFromFile(absoluteFilePath, projectDir, arkFile, projectName
|
|
|
113
113
|
}
|
|
114
114
|
exports.buildArkFileFromFile = buildArkFileFromFile;
|
|
115
115
|
/**
|
|
116
|
-
* Building ArkFile instance
|
|
116
|
+
* Building ArkFile instance.
|
|
117
117
|
*
|
|
118
|
-
* @param arkFile
|
|
119
|
-
* @param astRoot
|
|
120
|
-
* @
|
|
118
|
+
* @param arkFile - The ArkFile to populate.
|
|
119
|
+
* @param astRoot - The parsed TypeScript source file AST.
|
|
120
|
+
* @param skipImportExport - When true, skip the import/export statement branches so that
|
|
121
|
+
* existing ImportInfo/ExportInfo (populated earlier at IMPORTS level) is preserved and only
|
|
122
|
+
* class/method/namespace signatures are built on top. This avoids re-parsing import/export
|
|
123
|
+
* which would duplicate `export *` entries (their temp keys are process-level auto-increment).
|
|
121
124
|
*/
|
|
122
|
-
function buildArkFile(arkFile, astRoot) {
|
|
123
|
-
const statements = astRoot.statements;
|
|
125
|
+
function buildArkFile(arkFile, astRoot, skipImportExport = false) {
|
|
124
126
|
const namespaces = [];
|
|
125
|
-
|
|
127
|
+
for (const child of astRoot.statements) {
|
|
126
128
|
if (ohos_typescript_1.default.isModuleDeclaration(child)) {
|
|
127
|
-
|
|
128
|
-
ns.setDeclaringArkFile(arkFile);
|
|
129
|
-
(0, ArkNamespaceBuilder_1.buildArkNamespace)(child, arkFile, ns, astRoot);
|
|
130
|
-
namespaces.push(ns);
|
|
131
|
-
if (ns.isExported()) {
|
|
132
|
-
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(ns, arkFile, Position_1.FullPosition.buildFromNode(child, astRoot)));
|
|
133
|
-
}
|
|
129
|
+
buildAndCollectNamespace(child, arkFile, astRoot, namespaces);
|
|
134
130
|
}
|
|
135
131
|
else if (ohos_typescript_1.default.isClassDeclaration(child) || ohos_typescript_1.default.isInterfaceDeclaration(child) || ohos_typescript_1.default.isEnumDeclaration(child) || ohos_typescript_1.default.isStructDeclaration(child)) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
buildAndExportClass(child, arkFile, astRoot);
|
|
133
|
+
}
|
|
134
|
+
else if (ohos_typescript_1.default.isMethodDeclaration(child) || ohos_typescript_1.default.isFunctionDeclaration(child)) {
|
|
135
|
+
buildAndExportMethod(child, arkFile, astRoot);
|
|
136
|
+
}
|
|
137
|
+
else if (!skipImportExport && tryBuildImportExport(child, arkFile, astRoot)) {
|
|
138
|
+
// import/export handled by tryBuildImportExport
|
|
141
139
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
let mthd = new ArkMethod_1.ArkMethod();
|
|
146
|
-
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, arkFile.getDefaultClass(), mthd, astRoot);
|
|
147
|
-
if (mthd.isExported()) {
|
|
148
|
-
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, arkFile, Position_1.FullPosition.buildFromNode(child, astRoot)));
|
|
140
|
+
else if (ohos_typescript_1.default.isExpressionStatement(child) && ohos_typescript_1.default.isStringLiteral(child.expression)) {
|
|
141
|
+
if ((0, StringUtils_1.cloneText)(child.expression.text).trim() === Const_1.ARKTS_STATIC_MARK) {
|
|
142
|
+
arkFile.setLanguage(ArkFile_1.Language.ARKTS1_2);
|
|
149
143
|
}
|
|
150
144
|
}
|
|
151
|
-
else
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
145
|
+
else {
|
|
146
|
+
logger.trace('Child joined default method of arkFile: ', ohos_typescript_1.default.SyntaxKind[child.kind]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
mergeAndAddNamespaces(namespaces, arkFile);
|
|
150
|
+
}
|
|
151
|
+
function buildAndCollectNamespace(child, arkFile, astRoot, namespaces) {
|
|
152
|
+
const ns = new ArkNamespace_1.ArkNamespace();
|
|
153
|
+
ns.setDeclaringArkFile(arkFile);
|
|
154
|
+
(0, ArkNamespaceBuilder_1.buildArkNamespace)(child, arkFile, ns, astRoot);
|
|
155
|
+
namespaces.push(ns);
|
|
156
|
+
if (ns.isExported()) {
|
|
157
|
+
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(ns, arkFile, Position_1.FullPosition.buildFromNode(child, astRoot)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function buildAndExportClass(child, arkFile, astRoot) {
|
|
161
|
+
const cls = new ArkClass_1.ArkClass();
|
|
162
|
+
(0, ArkClassBuilder_1.buildNormalArkClassFromArkFile)(child, arkFile, cls, astRoot);
|
|
163
|
+
if (cls.isExported()) {
|
|
164
|
+
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(cls, arkFile, Position_1.FullPosition.buildFromNode(child, astRoot)));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function buildAndExportMethod(child, arkFile, astRoot) {
|
|
168
|
+
const mthd = new ArkMethod_1.ArkMethod();
|
|
169
|
+
(0, ArkMethodBuilder_1.buildArkMethodFromArkClass)(child, arkFile.getDefaultClass(), mthd, astRoot);
|
|
170
|
+
if (mthd.isExported()) {
|
|
171
|
+
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mthd, arkFile, Position_1.FullPosition.buildFromNode(child, astRoot)));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Attempt to build import/export info from a statement. Returns true if the statement was
|
|
176
|
+
* recognized and handled as an import/export declaration.
|
|
177
|
+
*/
|
|
178
|
+
function tryBuildImportExport(child, arkFile, astRoot) {
|
|
179
|
+
if (ohos_typescript_1.default.isImportEqualsDeclaration(child) || ohos_typescript_1.default.isImportDeclaration(child)) {
|
|
180
|
+
const importInfos = (0, ArkImportBuilder_1.buildImportInfo)(child, astRoot, arkFile);
|
|
181
|
+
importInfos === null || importInfos === void 0 ? void 0 : importInfos.forEach(element => {
|
|
182
|
+
element.setDeclaringArkFile(arkFile);
|
|
183
|
+
arkFile.addImportInfo(element);
|
|
184
|
+
});
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (ohos_typescript_1.default.isExportDeclaration(child)) {
|
|
188
|
+
(0, ArkExportBuilder_1.buildExportDeclaration)(child, astRoot, arkFile).forEach(item => arkFile.addExportInfo(item));
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if (ohos_typescript_1.default.isExportAssignment(child)) {
|
|
192
|
+
(0, ArkExportBuilder_1.buildExportAssignment)(child, astRoot, arkFile).forEach(item => arkFile.addExportInfo(item));
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (ohos_typescript_1.default.isVariableStatement(child) && (0, ArkExportBuilder_1.isExported)(child.modifiers)) {
|
|
196
|
+
(0, ArkExportBuilder_1.buildExportVariableStatement)(child, astRoot, arkFile).forEach(item => arkFile.addExportInfo(item));
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (ohos_typescript_1.default.isTypeAliasDeclaration(child) && (0, ArkExportBuilder_1.isExported)(child.modifiers)) {
|
|
200
|
+
(0, ArkExportBuilder_1.buildExportTypeAliasDeclaration)(child, astRoot, arkFile).forEach(item => arkFile.addExportInfo(item));
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
function mergeAndAddNamespaces(namespaces, arkFile) {
|
|
206
|
+
const merged = (0, ArkNamespaceBuilder_1.mergeNameSpaces)(namespaces);
|
|
207
|
+
merged.forEach(ns => {
|
|
208
|
+
arkFile.addNamespace(ns);
|
|
209
|
+
if (ns.isExport()) {
|
|
210
|
+
const positions = ns.getOriginFullPositions();
|
|
211
|
+
if (positions.length > 0) {
|
|
212
|
+
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(ns, arkFile, positions[0]));
|
|
156
213
|
}
|
|
157
214
|
}
|
|
158
|
-
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function genDefaultArkClass(arkFile, astRoot) {
|
|
218
|
+
let defaultClass = new ArkClass_1.ArkClass();
|
|
219
|
+
(0, ArkClassBuilder_1.buildDefaultArkClassFromArkFile)(arkFile, defaultClass, astRoot);
|
|
220
|
+
arkFile.setDefaultClass(defaultClass);
|
|
221
|
+
arkFile.addArkClass(defaultClass);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Lightweight entry of building ImportInfo/ExportInfo on ArkFile without building ArkClass/ArkMethod/ArkNamespace/ArkBody.
|
|
225
|
+
*
|
|
226
|
+
* @param arkFile
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
function buildImportExportInfoFromFile(arkFile) {
|
|
230
|
+
let sourceText;
|
|
231
|
+
try {
|
|
232
|
+
sourceText = fs_1.default.readFileSync(arkFile.getFilePath(), 'utf8');
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
logger.error('Failed to read file: ${error}');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
arkFile.setCode(sourceText);
|
|
239
|
+
const sourceFile = ohos_typescript_1.default.createSourceFile(arkFile.getName(), sourceText, ohos_typescript_1.default.ScriptTarget.Latest, true, undefined, EtsConst_1.ETS_COMPILER_OPTIONS);
|
|
240
|
+
buildImportExportInfo(arkFile, sourceFile);
|
|
241
|
+
}
|
|
242
|
+
exports.buildImportExportInfoFromFile = buildImportExportInfoFromFile;
|
|
243
|
+
/**
|
|
244
|
+
* Building ImportInfo/ExportInfo on ArkFile from AST, skipping class/interface/enum/struct/namespace declarations.
|
|
245
|
+
*
|
|
246
|
+
* @param arkFile
|
|
247
|
+
* @param astRoot
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
250
|
+
function buildImportExportInfo(arkFile, astRoot) {
|
|
251
|
+
const statements = astRoot.statements;
|
|
252
|
+
statements.forEach(child => {
|
|
253
|
+
if (ohos_typescript_1.default.isImportEqualsDeclaration(child) || ohos_typescript_1.default.isImportDeclaration(child)) {
|
|
159
254
|
let importInfos = (0, ArkImportBuilder_1.buildImportInfo)(child, astRoot, arkFile);
|
|
160
255
|
importInfos === null || importInfos === void 0 ? void 0 : importInfos.forEach(element => {
|
|
161
256
|
element.setDeclaringArkFile(arkFile);
|
|
@@ -177,24 +272,33 @@ function buildArkFile(arkFile, astRoot) {
|
|
|
177
272
|
else if (ohos_typescript_1.default.isExpressionStatement(child) && ohos_typescript_1.default.isStringLiteral(child.expression)) {
|
|
178
273
|
(0, StringUtils_1.cloneText)(child.expression.text).trim() === Const_1.ARKTS_STATIC_MARK && arkFile.setLanguage(ArkFile_1.Language.ARKTS1_2);
|
|
179
274
|
}
|
|
180
|
-
else {
|
|
181
|
-
logger.trace('Child joined default method of arkFile: ', ohos_typescript_1.default.SyntaxKind[child.kind]);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
const mergedNameSpaces = (0, ArkNamespaceBuilder_1.mergeNameSpaces)(namespaces);
|
|
185
|
-
mergedNameSpaces.forEach(mergedNameSpace => {
|
|
186
|
-
arkFile.addNamespace(mergedNameSpace);
|
|
187
|
-
if (mergedNameSpace.isExport()) {
|
|
188
|
-
const positions = mergedNameSpace.getOriginFullPositions();
|
|
189
|
-
if (positions.length > 0) {
|
|
190
|
-
arkFile.addExportInfo((0, ArkExportBuilder_1.buildExportInfo)(mergedNameSpace, arkFile, positions[0]));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
275
|
});
|
|
194
276
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Signatures-only upgrade entry: builds ArkClass/ArkMethod/ArkNamespace signatures on top of an
|
|
279
|
+
* ArkFile whose ImportInfo/ExportInfo were already populated (e.g. by {@link buildImportExportInfoFromFile}).
|
|
280
|
+
*
|
|
281
|
+
* Unlike {@link buildArkFileFromFile}, this function calls {@link buildArkFile} with
|
|
282
|
+
* `skipImportExport = true`, so existing import/export data is preserved and not re-parsed. This
|
|
283
|
+
* avoids duplicating `export *` re-export entries whose temp clause keys are process-level
|
|
284
|
+
* auto-increment values that cannot be overwritten by `Map.set`.
|
|
285
|
+
*
|
|
286
|
+
* @param arkFile - The ArkFile to upgrade. Must already have filePath set.
|
|
287
|
+
*/
|
|
288
|
+
function buildArkFileSignaturesFromFile(arkFile) {
|
|
289
|
+
let sourceText;
|
|
290
|
+
try {
|
|
291
|
+
sourceText = fs_1.default.readFileSync(arkFile.getFilePath(), 'utf8');
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
logger.error('Failed to read file: ${error}');
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const sourceFile = ohos_typescript_1.default.createSourceFile(arkFile.getName(), sourceText, ohos_typescript_1.default.ScriptTarget.Latest, true, undefined, EtsConst_1.ETS_COMPILER_OPTIONS);
|
|
298
|
+
if (arkFile.getScene().getOptions().enableAST && arkFile.getScene().getProjectName() === arkFile.getProjectName()) {
|
|
299
|
+
arkFile.setAST(sourceFile);
|
|
300
|
+
}
|
|
301
|
+
genDefaultArkClass(arkFile, sourceFile);
|
|
302
|
+
buildArkFile(arkFile, sourceFile, true);
|
|
200
303
|
}
|
|
304
|
+
exports.buildArkFileSignaturesFromFile = buildArkFileSignaturesFromFile;
|