arkanalyzer 1.0.94 → 2.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Config.d.ts +7 -0
- package/lib/Config.d.ts.map +1 -1
- package/lib/Scene.d.ts +134 -170
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +412 -976
- package/lib/callgraph/algorithm/AbstractAnalysis.js +3 -2
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +1 -1
- package/lib/callgraph/model/CallGraph.js +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +1 -3
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +17 -7
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +4 -14
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +2 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +1 -2
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +0 -1
- package/lib/cli/commands/cg.d.ts +1 -0
- package/lib/cli/commands/cg.d.ts.map +1 -1
- package/lib/cli/commands/cg.js +22 -18
- package/lib/cli/commands/ir.d.ts +1 -0
- package/lib/cli/commands/ir.d.ts.map +1 -1
- package/lib/cli/commands/ir.js +5 -2
- package/lib/core/base/Constant.d.ts +5 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +12 -9
- package/lib/core/base/Expr.d.ts +36 -20
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +206 -94
- package/lib/core/base/Local.d.ts +10 -20
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +25 -28
- package/lib/core/base/Position.d.ts +6 -0
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +37 -11
- package/lib/core/base/Ref.d.ts +45 -33
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +225 -51
- package/lib/core/base/Stmt.d.ts +19 -9
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -52
- package/lib/core/base/Type.d.ts +67 -4
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +391 -20
- package/lib/core/base/TypeExpr.d.ts +6 -4
- package/lib/core/base/TypeExpr.d.ts.map +1 -1
- package/lib/core/base/TypeExpr.js +34 -10
- package/lib/core/base/Value.d.ts +20 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/base/Value.js +12 -0
- package/lib/core/common/ArkIRTransformer.d.ts +18 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +94 -75
- package/lib/core/common/ArkValueTransformer.d.ts +21 -3
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +455 -265
- package/lib/core/common/Builtin.d.ts +48 -24
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +90 -52
- package/lib/core/common/CanonicalizerValidator.d.ts +308 -0
- package/lib/core/common/CanonicalizerValidator.d.ts.map +1 -0
- package/lib/core/common/CanonicalizerValidator.js +888 -0
- package/lib/core/common/Const.d.ts +3 -3
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +3 -3
- package/lib/core/common/DummyMainCreater.d.ts +2 -21
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +8 -105
- package/lib/core/common/IRInference.d.ts +55 -3
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +407 -126
- package/lib/core/common/IRUtils.d.ts +1 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +44 -13
- package/lib/core/common/ModelUtils.d.ts +44 -20
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +378 -208
- package/lib/core/common/SdkUtils.d.ts +35 -5
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +181 -53
- package/lib/core/common/SignatureCanonicalizer.d.ts +95 -0
- package/lib/core/common/SignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizer.js +116 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts +176 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.js +343 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts +69 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureModelCanonicalizer.js +109 -0
- package/lib/core/common/StmtUseReplacer.d.ts +1 -0
- package/lib/core/common/StmtUseReplacer.d.ts.map +1 -1
- package/lib/core/common/StmtUseReplacer.js +9 -0
- package/lib/core/common/StringUtils.d.ts +12 -1
- package/lib/core/common/StringUtils.d.ts.map +1 -1
- package/lib/core/common/StringUtils.js +36 -17
- package/lib/core/common/TempSignatureCanonicalizer.d.ts +82 -0
- package/lib/core/common/TempSignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/TempSignatureCanonicalizer.js +177 -0
- package/lib/core/common/TypeInference.d.ts +24 -6
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +243 -117
- package/lib/core/common/ValueUtil.d.ts +2 -1
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +4 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +21 -6
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +46 -33
- package/lib/core/graph/builder/IfBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/IfBuilder.js +6 -2
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -2
- package/lib/core/inference/ModelInference.d.ts +24 -4
- package/lib/core/inference/ModelInference.d.ts.map +1 -1
- package/lib/core/inference/ModelInference.js +273 -79
- package/lib/core/inference/ValueInference.d.ts +3 -2
- package/lib/core/inference/ValueInference.d.ts.map +1 -1
- package/lib/core/inference/ValueInference.js +90 -40
- package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
- package/lib/core/inference/abc/AbcInference.js +28 -15
- package/lib/core/inference/arkts/ArkTsInference.d.ts +9 -3
- package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
- package/lib/core/inference/arkts/ArkTsInference.js +54 -16
- package/lib/core/model/ArkClass.d.ts +192 -18
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +852 -122
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +1 -2
- package/lib/core/model/ArkField.d.ts +34 -2
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +89 -14
- package/lib/core/model/ArkFile.d.ts +72 -12
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +275 -65
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +1 -2
- package/lib/core/model/ArkMethod.d.ts +101 -15
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +252 -39
- package/lib/core/model/ArkModule.d.ts +1 -1
- package/lib/core/model/ArkModule.js +1 -1
- package/lib/core/model/ArkNamespace.d.ts +80 -10
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +309 -76
- package/lib/core/model/ArkSignature.d.ts +242 -18
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +725 -95
- package/lib/core/model/builder/ArkClassBuilder.d.ts +6 -3
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +116 -71
- package/lib/core/model/builder/ArkExportBuilder.d.ts +1 -1
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +0 -2
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +9 -43
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +32 -33
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +10 -3
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +40 -26
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +3 -2
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +45 -77
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkSignatureBuilder.js +26 -3
- package/lib/core/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +37 -11
- package/lib/core/model/builder/builderUtils.d.ts +11 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +124 -90
- package/lib/frontend/FrontendBuilder.d.ts +10 -6
- package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
- package/lib/frontend/FrontendBuilder.js +19 -45
- package/lib/frontend/ModuleScene.d.ts +43 -0
- package/lib/frontend/ModuleScene.d.ts.map +1 -0
- package/lib/frontend/ModuleScene.js +143 -0
- package/lib/frontend/SceneBuildStage.d.ts +15 -0
- package/lib/frontend/SceneBuildStage.d.ts.map +1 -0
- package/lib/frontend/SceneBuildStage.js +32 -0
- package/lib/frontend/SceneBuilder.d.ts +153 -0
- package/lib/frontend/SceneBuilder.d.ts.map +1 -0
- package/lib/frontend/SceneBuilder.js +859 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +0 -2
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
- package/lib/frontend/arktsFrontend/ArktsFrontend.js +0 -18
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts +17 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts.map +1 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.js +187 -0
- package/lib/frontend/common/ModuleBuilder.d.ts +4 -2
- package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -1
- package/lib/frontend/common/ModuleBuilder.js +19 -9
- package/lib/frontend/cppFrontend/CppFrontend.d.ts +0 -6
- package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/CppFrontend.js +0 -56
- package/lib/frontend/cppFrontend/base/Type.d.ts +7 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/base/Type.js +29 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +56 -56
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +124 -113
- package/lib/frontend/cppFrontend/common/Builtin.d.ts +29 -19
- package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/Builtin.js +56 -35
- package/lib/frontend/cppFrontend/common/IRInference.d.ts +7 -2
- package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRInference.js +61 -28
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.js +22 -10
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +19 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ModelUtils.js +84 -3
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/TypeInference.js +44 -54
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +2 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +1 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.js +41 -5
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +18 -28
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +2 -3
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +2 -2
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +31 -24
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +10 -16
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +0 -2
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +19 -37
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +30 -3
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +8 -4
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -2
- package/lib/save/json/JsonSerialization.js +2 -2
- package/lib/save/source/SourceStmt.js +1 -1
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +0 -9
- package/lib/statistics/StageStatistics.d.ts +195 -0
- package/lib/statistics/StageStatistics.d.ts.map +1 -0
- package/lib/statistics/StageStatistics.js +346 -0
- package/lib/statistics/StageStatisticsReporter.d.ts +58 -0
- package/lib/statistics/StageStatisticsReporter.d.ts.map +1 -0
- package/lib/statistics/StageStatisticsReporter.js +255 -0
- package/lib/utils/Canonicalizer.d.ts +9 -2
- package/lib/utils/Canonicalizer.d.ts.map +1 -1
- package/lib/utils/Canonicalizer.js +19 -2
- package/lib/utils/CxxSceneUtils.d.ts +7 -0
- package/lib/utils/CxxSceneUtils.d.ts.map +1 -1
- package/lib/utils/CxxSceneUtils.js +10 -1
- package/lib/utils/FileUtils.d.ts +0 -1
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +1 -9
- package/lib/utils/HashUtils.d.ts +9 -0
- package/lib/utils/HashUtils.d.ts.map +1 -0
- package/lib/utils/HashUtils.js +65 -0
- package/lib/utils/ModuleUtils.d.ts.map +1 -1
- package/lib/utils/ModuleUtils.js +24 -5
- package/lib/utils/VisitedSegment.d.ts +23 -0
- package/lib/utils/VisitedSegment.d.ts.map +1 -0
- package/lib/utils/VisitedSegment.js +64 -0
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -7
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +11 -8
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +16 -0
- package/lib/utils/parseArkSourceFile.d.ts +33 -0
- package/lib/utils/parseArkSourceFile.d.ts.map +1 -0
- package/lib/utils/parseArkSourceFile.js +131 -0
- package/package.json +1 -1
- package/lib/utils/DependenciesSort.d.ts +0 -3
- package/lib/utils/DependenciesSort.d.ts.map +0 -1
- package/lib/utils/DependenciesSort.js +0 -72
- package/lib/utils/crypto_utils.d.ts +0 -6
- package/lib/utils/crypto_utils.d.ts.map +0 -1
- package/lib/utils/crypto_utils.js +0 -57
|
@@ -0,0 +1,859 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.SceneBuilder = void 0;
|
|
44
|
+
const fs_1 = __importDefault(require("fs"));
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const ArkFile_1 = require("../core/model/ArkFile");
|
|
47
|
+
const ArkSignature_1 = require("../core/model/ArkSignature");
|
|
48
|
+
const ModuleScene_1 = require("./ModuleScene");
|
|
49
|
+
const FrontendBuilder_1 = require("./FrontendBuilder");
|
|
50
|
+
const ArktsFrontend_1 = require("./arktsFrontend/ArktsFrontend");
|
|
51
|
+
const FileBodyRemount_1 = require("./arktsFrontend/FileBodyRemount");
|
|
52
|
+
const ModuleUtils_1 = require("../utils/ModuleUtils");
|
|
53
|
+
const json5parser_1 = require("../utils/json5parser");
|
|
54
|
+
const getAllFiles_1 = require("../utils/getAllFiles");
|
|
55
|
+
const FileUtils_1 = require("../utils/FileUtils");
|
|
56
|
+
const TSConst_1 = require("../core/common/TSConst");
|
|
57
|
+
const EtsConst_1 = require("../core/common/EtsConst");
|
|
58
|
+
const SdkUtils_1 = require("../core/common/SdkUtils");
|
|
59
|
+
const ModelUtils_1 = require("../core/common/ModelUtils");
|
|
60
|
+
const Inference_1 = require("../core/inference/Inference");
|
|
61
|
+
const ArkMethodBuilder_1 = require("../core/model/builder/ArkMethodBuilder");
|
|
62
|
+
const ArkMethodBuilder_2 = require("./cppFrontend/model/builder/ArkMethodBuilder");
|
|
63
|
+
const SignatureCanonicalizerRegistry_1 = require("../core/common/SignatureCanonicalizerRegistry");
|
|
64
|
+
const SceneBuildStage_1 = require("./SceneBuildStage");
|
|
65
|
+
const StageStatistics_1 = require("../statistics/StageStatistics");
|
|
66
|
+
const logger_1 = __importStar(require("../utils/logger"));
|
|
67
|
+
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'SceneBuilder');
|
|
68
|
+
/**
|
|
69
|
+
* 完整构建路径的一次性构建上下文(BuildContext)。
|
|
70
|
+
*
|
|
71
|
+
* 承接构建机械与构建期工作态:配置解析族(build-profile / oh-package / tsconfig)与 project 文件 DFS 族(getDependencyFilesDeeply 及全部
|
|
72
|
+
* 依赖发现辅助)。
|
|
73
|
+
*
|
|
74
|
+
* 生命周期:由 Scene 在构建入口创建并持有(scene.activeBuilder),构建结束由入口方法释放(置 undefined)——工作态随本实例被 GC 回收,不驻留
|
|
75
|
+
* Scene。Scene 仅保留构建产物(builtFileOrder / moduleScenesMap / overRides / 失败文件摘要等)与查询侧状态。
|
|
76
|
+
*
|
|
77
|
+
* 注意:本类不承载模块化增量路径(analyseByModule/loadModule 走 ModuleBuilder,其构建态常驻 Scene,不受本上下文生命周期影响)。
|
|
78
|
+
*/
|
|
79
|
+
class SceneBuilder {
|
|
80
|
+
constructor(scene, sceneConfig) {
|
|
81
|
+
// --- 构建期工作态(构建结束随本实例回收,不回填 Scene)---
|
|
82
|
+
/** oh-package.json5 内容表(绝对路径 → 内容),依赖解析(parseFrom 族)的输入。 */
|
|
83
|
+
this.ohPkgContentMap = new Map();
|
|
84
|
+
this.ohPkgFilePath = '';
|
|
85
|
+
this.ohPkgContent = {};
|
|
86
|
+
/**
|
|
87
|
+
* from → 直接解析出的物理文件路径列表(性能缓存)。key 精确对齐
|
|
88
|
+
* {@link getOriginPath} 的解析语义:相对形式(`./`、`../`)带声明文件
|
|
89
|
+
* 所在目录前缀(`dirname + '\x00' + from`——同目录文件的相同相对 from 才允许共享);模块名形式(`@ohos/xxx`、裸名)用 from 本身(解析只走
|
|
90
|
+
* ohPkgContentMap / projectDir / tsconfig 全局映射,与声明文件位置无关)。空数组也缓存(负缓存——避免失败 from 重复走全部分支)。
|
|
91
|
+
* **只缓存纯函数结果(from → paths),绝不缓存"文件要不要构建"的决策**——
|
|
92
|
+
* 后者依赖 filesMap/unhandledFilePaths 等可变状态,命中后必须逐个经
|
|
93
|
+
* {@link getDependencyFilesDeeply} 的三重防重入入口重新仲裁。
|
|
94
|
+
*/
|
|
95
|
+
this.fromResolutionCache = new Map();
|
|
96
|
+
/**
|
|
97
|
+
* 解析产出收集栈(嵌套隔离):parseFrom 未命中时 push 新槽,嵌套递归构建
|
|
98
|
+
* 触发的 parseFrom 各归各的槽;pop 时整槽写入 fromResolutionCache——
|
|
99
|
+
* 条目只含该 from 的"直接"产出,不含递归依赖自身的解析结果。
|
|
100
|
+
*/
|
|
101
|
+
this.fromResolutionStack = [];
|
|
102
|
+
/**
|
|
103
|
+
* inner oh-package 内容缓存(兜底):不同 from 首次解析触达同一 inner
|
|
104
|
+
* oh-package 的残余重复读盘。独立于 ohPkgContentMap——后者正被
|
|
105
|
+
* for...of 遍历,遍历中插入 key 会改变迭代行为(JS Map 迭代可见新增项)。
|
|
106
|
+
*/
|
|
107
|
+
this.resolvedOhPkgCache = new Map();
|
|
108
|
+
this.scene = scene;
|
|
109
|
+
this.sceneConfig = sceneConfig;
|
|
110
|
+
this.registry = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
111
|
+
this.unhandledFilePaths = scene.getUnhandledFileSet();
|
|
112
|
+
}
|
|
113
|
+
// --- 配置解析族(原 Scene.parseBuildProfile / parseOhPackage / tsconfig 族 / buildOhPkgContentMap)---
|
|
114
|
+
/**
|
|
115
|
+
* 解析项目配置:build-profile.json5(ES 版本 + 模块表)、oh-package.json5
|
|
116
|
+
* (含 overrides)、tsconfig(paths/baseUrl,extends 链递归)、模块 oh-package 表,
|
|
117
|
+
* 最后生成模块映射(ModuleUtils.generateModuleMap)。
|
|
118
|
+
*/
|
|
119
|
+
parseProjectConfigs() {
|
|
120
|
+
var _a, _b, _c;
|
|
121
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.startStage(StageStatistics_1.StageName.BuilderParseConfigs);
|
|
122
|
+
this.parseBuildProfile();
|
|
123
|
+
this.parseOhPackage();
|
|
124
|
+
const tsConfigOption = (_b = this.scene.getOptions().tsconfig) !== null && _b !== void 0 ? _b : TSConst_1.TSCONFIG_JSON;
|
|
125
|
+
const tsConfigFilePath = path_1.default.join(this.sceneConfig.getTargetProjectDirectory(), tsConfigOption);
|
|
126
|
+
if (fs_1.default.existsSync(tsConfigFilePath)) {
|
|
127
|
+
const tsConfigObj = (0, json5parser_1.fetchDependenciesFromFile)(tsConfigFilePath);
|
|
128
|
+
this.findTsConfigInfoDeeply(tsConfigObj, tsConfigFilePath);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
logger.warn('This project has no tsconfig.json!');
|
|
132
|
+
}
|
|
133
|
+
this.buildOhPkgContentMap();
|
|
134
|
+
ModuleUtils_1.ModuleUtils.generateModuleMap(this.ohPkgContentMap);
|
|
135
|
+
// 配置产物快照回填(tsconfig paths/baseUrl 构建后仍可查询)。
|
|
136
|
+
this.scene.setTsConfigSnapshot(this.globalModule2PathMapping, this.baseUrl);
|
|
137
|
+
(_c = this.scene.getStageStatisticsCollector()) === null || _c === void 0 ? void 0 : _c.endStage(StageStatistics_1.StageName.BuilderParseConfigs);
|
|
138
|
+
}
|
|
139
|
+
/** @internal 供 Scene.buildBasicInfo 的 SDK 阶段读取(P3 迁移后内化)。 */
|
|
140
|
+
getOhPkgContentMap() {
|
|
141
|
+
return this.ohPkgContentMap;
|
|
142
|
+
}
|
|
143
|
+
/** @internal 追加模块 oh-package 内容(Scene.buildModuleScene 的依赖解析输入,P3 迁移后内化)。 */
|
|
144
|
+
addOhPkgContent(ohPkgFilePath, content) {
|
|
145
|
+
this.ohPkgContentMap.set(ohPkgFilePath, content);
|
|
146
|
+
}
|
|
147
|
+
/** @internal tsconfig baseUrl(构建期值;仅在活跃构建上下文中可查)。 */
|
|
148
|
+
getBaseUrl() {
|
|
149
|
+
return this.baseUrl;
|
|
150
|
+
}
|
|
151
|
+
parseBuildProfile() {
|
|
152
|
+
const buildProfile = path_1.default.join(this.scene.getRealProjectDir(), EtsConst_1.BUILD_PROFILE_JSON5);
|
|
153
|
+
if (fs_1.default.existsSync(buildProfile)) {
|
|
154
|
+
let configurationsText;
|
|
155
|
+
try {
|
|
156
|
+
configurationsText = fs_1.default.readFileSync(buildProfile, 'utf-8');
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
logger.error(`Error reading file: ${error}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const buildProfileJson = (0, json5parser_1.parseJsonText)(configurationsText);
|
|
163
|
+
SdkUtils_1.SdkUtils.setEsVersion(buildProfileJson);
|
|
164
|
+
const modules = buildProfileJson.modules;
|
|
165
|
+
if (modules instanceof Array) {
|
|
166
|
+
modules.forEach(module => {
|
|
167
|
+
this.scene.getModulePath2NameMap().set(path_1.default.resolve(this.scene.getRealProjectDir(), path_1.default.join(module.srcPath)), module.name);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
logger.warn('There is no build-profile.json5 for this project.');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
parseOhPackage() {
|
|
176
|
+
const OhPkgFilePath = path_1.default.join(this.scene.getRealProjectDir(), EtsConst_1.OH_PACKAGE_JSON5);
|
|
177
|
+
if (fs_1.default.existsSync(OhPkgFilePath)) {
|
|
178
|
+
this.ohPkgFilePath = OhPkgFilePath;
|
|
179
|
+
this.ohPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(this.ohPkgFilePath);
|
|
180
|
+
this.ohPkgContentMap.set(OhPkgFilePath, this.ohPkgContent);
|
|
181
|
+
if (this.ohPkgContent.overrides) {
|
|
182
|
+
let overRides = this.ohPkgContent.overrides;
|
|
183
|
+
for (const [key, value] of Object.entries(overRides)) {
|
|
184
|
+
this.scene.getOverRides().set(key, value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (this.ohPkgContent.overrideDependencyMap) {
|
|
188
|
+
let globalOverRideDependencyMap = this.ohPkgContent.overrideDependencyMap;
|
|
189
|
+
for (const [key, value] of Object.entries(globalOverRideDependencyMap)) {
|
|
190
|
+
let globalDependency = (0, json5parser_1.fetchDependenciesFromFile)(value);
|
|
191
|
+
this.scene.getOverRideDependencyMap().set(key, globalDependency);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
logger.warn('This project has no oh-package.json5!');
|
|
197
|
+
}
|
|
198
|
+
// 配置产物快照回填(对齐 setTsConfigSnapshot 模式):根 oh-package 内容在
|
|
199
|
+
// 构建结束后仍可经 Scene.getOhPkgContent() 查询(构建期上下文已释放)。
|
|
200
|
+
this.scene.setOhPkgContentSnapshot(this.ohPkgContent);
|
|
201
|
+
}
|
|
202
|
+
findTsConfigInfoDeeply(tsConfigObj, tsConfigFilePath) {
|
|
203
|
+
if (tsConfigObj.extends) {
|
|
204
|
+
const extTsConfigFilePath = path_1.default.join(path_1.default.dirname(tsConfigFilePath), tsConfigObj.extends);
|
|
205
|
+
const extTsConfigObj = (0, json5parser_1.fetchDependenciesFromFile)(extTsConfigFilePath);
|
|
206
|
+
this.findTsConfigInfoDeeply(extTsConfigObj, extTsConfigFilePath);
|
|
207
|
+
if (!this.baseUrl && !this.globalModule2PathMapping) {
|
|
208
|
+
this.addTsConfigInfo(extTsConfigObj);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!this.baseUrl && !this.globalModule2PathMapping) {
|
|
212
|
+
this.addTsConfigInfo(tsConfigObj);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
addTsConfigInfo(tsConfigObj) {
|
|
216
|
+
if (tsConfigObj.compilerOptions && tsConfigObj.compilerOptions.paths) {
|
|
217
|
+
const paths = tsConfigObj.compilerOptions.paths;
|
|
218
|
+
if (paths) {
|
|
219
|
+
this.globalModule2PathMapping = paths;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (tsConfigObj.compilerOptions && tsConfigObj.compilerOptions.baseUrl) {
|
|
223
|
+
this.baseUrl = tsConfigObj.compilerOptions.baseUrl;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
buildOhPkgContentMap() {
|
|
227
|
+
this.scene.getModulePath2NameMap().forEach((value, key) => {
|
|
228
|
+
const moduleOhPkgFilePath = path_1.default.resolve(key, EtsConst_1.OH_PACKAGE_JSON5);
|
|
229
|
+
if (fs_1.default.existsSync(moduleOhPkgFilePath)) {
|
|
230
|
+
const moduleOhPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(moduleOhPkgFilePath);
|
|
231
|
+
this.ohPkgContentMap.set(moduleOhPkgFilePath, moduleOhPkgContent);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// --- project 文件 DFS 族(原 Scene.getDependencyFilesDeeply 及依赖发现辅助)---
|
|
236
|
+
/**
|
|
237
|
+
* 对每个 projectFile 执行 {@link getDependencyFilesDeeply}(DFS):
|
|
238
|
+
* 完整构建自己(intern FileSigID)→ 递归拉入 import/export 依赖 → 全部依赖
|
|
239
|
+
* 完成后 setFile。**setFile 后序 = 严格拓扑序**(被依赖者在前),由 Scene 的
|
|
240
|
+
* builtFileOrder 记录,推断期按其正序遍历即零排序。
|
|
241
|
+
*/
|
|
242
|
+
buildProjectFiles() {
|
|
243
|
+
var _a, _b, _c;
|
|
244
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.startStage(StageStatistics_1.StageName.BuilderFiles);
|
|
245
|
+
for (const projectFile of this.sceneConfig.getProjectFiles()) {
|
|
246
|
+
this.getDependencyFilesDeeply(projectFile);
|
|
247
|
+
(_b = this.scene.getStageStatisticsCollector()) === null || _b === void 0 ? void 0 : _b.recordMemoryCheckpoint();
|
|
248
|
+
}
|
|
249
|
+
(_c = this.scene.getStageStatisticsCollector()) === null || _c === void 0 ? void 0 : _c.endStage(StageStatistics_1.StageName.BuilderFiles);
|
|
250
|
+
}
|
|
251
|
+
getDependencyFilesDeeply(projectFile) {
|
|
252
|
+
var _a;
|
|
253
|
+
if (!this.scene.getOptions().supportFileExts.includes(path_1.default.extname(projectFile))) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// 范围守卫:只构建/递归项目目录内的文件。越界文件(tsconfig paths、ohpkg
|
|
257
|
+
// 外部链等解析出的绝对路径)不属本 Scene 的 project 文件——其
|
|
258
|
+
// FileSignature 将产生 "../../../xxx" 畸形相对名,且目录扫描原生语义
|
|
259
|
+
// 本就只覆盖项目目录。
|
|
260
|
+
const relativeToProject = path_1.default.relative(this.scene.getRealProjectDir(), projectFile);
|
|
261
|
+
if (relativeToProject.startsWith('..') || path_1.default.isAbsolute(relativeToProject)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const fileSignature = new ArkSignature_1.FileSignature(this.scene.getProjectName(), relativeToProject);
|
|
265
|
+
const existingId = this.registry.fileSigCanonicalizer.getExistingId(fileSignature);
|
|
266
|
+
// 注意:早退基于全局 registry model(单 Scene 单次构建生命周期下 registry
|
|
267
|
+
// 内条目均属本次构建)。共享 registry 的二次构建为不支持场景——不做
|
|
268
|
+
// 场景归属判定适配;遇该场景的测试应自行 dispose 隔离。
|
|
269
|
+
if ((existingId !== -1 && this.registry.fileSigCanonicalizer.getModel(existingId) !== undefined) ||
|
|
270
|
+
this.isRepeatBuildFile(projectFile) ||
|
|
271
|
+
this.unhandledFilePaths.has(projectFile)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
// Here use unhandledFilePaths to temporarily store current file until add it to fileMaps to avoid recursively import issue.
|
|
275
|
+
this.unhandledFilePaths.add(projectFile);
|
|
276
|
+
try {
|
|
277
|
+
const arkFile = new ArkFile_1.ArkFile(FileUtils_1.FileUtils.getFileLanguage(projectFile, this.scene.getFileLanguages()));
|
|
278
|
+
arkFile.setScene(this.scene);
|
|
279
|
+
FrontendBuilder_1.FrontendBuilder.buildProjectFileIntoArkFile(this.scene, projectFile, arkFile);
|
|
280
|
+
if (arkFile.getLanguage() !== ArkFile_1.Language.CXX) {
|
|
281
|
+
// %dflt's builder is mounted on a node a re-parse cannot address by position, so
|
|
282
|
+
// build it now; the remaining builders are rebuilt per file in the body phase.
|
|
283
|
+
if ((_a = this.scene.getOptions().enableMethodBodyBuild) !== null && _a !== void 0 ? _a : true) {
|
|
284
|
+
FrontendBuilder_1.FrontendBuilder.buildDefaultMethodBodies(arkFile);
|
|
285
|
+
}
|
|
286
|
+
FrontendBuilder_1.FrontendBuilder.freeBodyBuildersInFile(arkFile);
|
|
287
|
+
}
|
|
288
|
+
for (const [modulePath, moduleName] of this.scene.getModulePath2NameMap()) {
|
|
289
|
+
if (arkFile.getFilePath().startsWith(modulePath)) {
|
|
290
|
+
this.addArkFile2ModuleScene(modulePath, moduleName, arkFile);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const importInfos = arkFile.getImportInfos();
|
|
295
|
+
const repeatFroms = [];
|
|
296
|
+
this.findDependencyFiles(importInfos, arkFile, repeatFroms);
|
|
297
|
+
const exportInfos = arkFile.getExportInfos();
|
|
298
|
+
this.findDependencyFiles(exportInfos, arkFile, repeatFroms);
|
|
299
|
+
// add currently file to files map after adding all its dependencies, and remove it from unhandledFilePaths
|
|
300
|
+
this.scene.setFile(arkFile);
|
|
301
|
+
this.unhandledFilePaths.delete(projectFile);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
logger.error('Error parsing file:', projectFile, error);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
isRepeatBuildFile(projectFile) {
|
|
309
|
+
const relativePath = path_1.default.relative(this.scene.getRealProjectDir(), projectFile);
|
|
310
|
+
if (!relativePath.startsWith('..') && !path_1.default.isAbsolute(relativePath)) {
|
|
311
|
+
const fileSig = new ArkSignature_1.FileSignature(this.scene.getProjectName(), relativePath);
|
|
312
|
+
const id = this.registry.fileSigCanonicalizer.getExistingId(fileSig);
|
|
313
|
+
return id !== -1 && this.registry.fileSigCanonicalizer.getModel(id) !== undefined;
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
addArkFile2ModuleScene(modulePath, moduleName, arkFile) {
|
|
318
|
+
const moduleScenesMap = this.scene.getModuleSceneMap();
|
|
319
|
+
if (moduleScenesMap.has(moduleName)) {
|
|
320
|
+
let curModuleScene = moduleScenesMap.get(moduleName);
|
|
321
|
+
if (curModuleScene) {
|
|
322
|
+
curModuleScene.addArkFile(arkFile);
|
|
323
|
+
arkFile.setModuleScene(curModuleScene);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
let moduleScene = new ModuleScene_1.ModuleScene(this.scene);
|
|
328
|
+
moduleScene.ModuleScenePartiallyBuilder(moduleName, modulePath);
|
|
329
|
+
moduleScene.addArkFile(arkFile);
|
|
330
|
+
moduleScenesMap.set(moduleName, moduleScene);
|
|
331
|
+
arkFile.setModuleScene(moduleScene);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
findDependencyFiles(importOrExportInfos, arkFile, repeatFroms) {
|
|
335
|
+
for (const importOrExportInfo of importOrExportInfos) {
|
|
336
|
+
const from = importOrExportInfo.getFrom();
|
|
337
|
+
if (from && !repeatFroms.includes(from)) {
|
|
338
|
+
this.parseFrom(from, arkFile);
|
|
339
|
+
repeatFroms.push(from);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
parseFrom(from, arkFile) {
|
|
344
|
+
// from 解析缓存(性能优化,行为等价):相同 (上下文, from) 的定位链
|
|
345
|
+
// (全量 ohPkgContentMap 遍历 + existsSync + 目录枚举 + 可能的 JSON5
|
|
346
|
+
// 读盘)只执行一次,重复 from 以 O(1) Map 查找复用解析结果。键设计
|
|
347
|
+
// 对齐 getOriginPath 的语义(相对 from 依赖声明文件目录,模块名形式
|
|
348
|
+
// 全项目一致)——勿改动该判定正则。命中后必须逐个经
|
|
349
|
+
// getDependencyFilesDeeply 重新仲裁(不缓存构建决策,防 disposeModule
|
|
350
|
+
// 等状态变化下静默丢构建)。
|
|
351
|
+
const isRelative = /^\.{1,2}\//.test(from);
|
|
352
|
+
const cacheKey = isRelative ? path_1.default.dirname(arkFile.getFilePath()) + '\x00' + from : from;
|
|
353
|
+
const cached = this.fromResolutionCache.get(cacheKey);
|
|
354
|
+
if (cached) {
|
|
355
|
+
for (const resolvedPath of cached) {
|
|
356
|
+
this.getDependencyFilesDeeply(resolvedPath);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const resolvedPaths = [];
|
|
361
|
+
this.fromResolutionStack.push(resolvedPaths);
|
|
362
|
+
try {
|
|
363
|
+
// —— 以下为原有三分支逻辑,逐字保留,不做任何修改 ——
|
|
364
|
+
if (/^@[a-z|\-]+?\/?/.test(from) || /^[a-z][a-z0-9._-]*[a-z0-9]$/.test(from)) {
|
|
365
|
+
// TODO: if there are more than one modules with the same name e.g. @lib1, here may got the wrong dependency
|
|
366
|
+
// It is better to loop all oh pkg with priority rather than the map key order. But it should be very complicated.
|
|
367
|
+
// Currently it is ok because it's with low probability and order error only affects type accuracy but has no other impact.
|
|
368
|
+
for (const [ohPkgContentPath, ohPkgContent] of this.ohPkgContentMap) {
|
|
369
|
+
this.findDependenciesByOhPkg(ohPkgContentPath, ohPkgContent, from);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else if (/^([^@]*\/)([^\/]*)$/.test(from) || /^[\.\./|\.\.]+$/.test(from)) {
|
|
373
|
+
this.findRelativeDependenciesByOhPkg(from, arkFile);
|
|
374
|
+
}
|
|
375
|
+
else if (/^[@a-zA-Z0-9]+(\/[a-zA-Z0-9]+)*$/.test(from)) {
|
|
376
|
+
this.findDependenciesByTsConfig(from);
|
|
377
|
+
}
|
|
378
|
+
// —— 原有逻辑结束 ——
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
this.fromResolutionStack.pop();
|
|
382
|
+
}
|
|
383
|
+
this.fromResolutionCache.set(cacheKey, resolvedPaths);
|
|
384
|
+
}
|
|
385
|
+
findDependenciesByTsConfig(from) {
|
|
386
|
+
if (this.globalModule2PathMapping) {
|
|
387
|
+
const paths = this.globalModule2PathMapping;
|
|
388
|
+
Object.keys(paths).forEach(key => this.parseTsConfigParms(paths, key, from));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
parseTsConfigParms(paths, key, from) {
|
|
392
|
+
const module2pathMapping = paths[key];
|
|
393
|
+
if (key.includes(TSConst_1.ALL)) {
|
|
394
|
+
this.processFuzzyMapping(key, from, module2pathMapping);
|
|
395
|
+
}
|
|
396
|
+
else if (from.startsWith(key)) {
|
|
397
|
+
let tail = from.substring(key.length, from.length);
|
|
398
|
+
module2pathMapping.forEach(pathMapping => {
|
|
399
|
+
let originPath = path_1.default.join(this.scene.getRealProjectDir(), pathMapping, tail);
|
|
400
|
+
if (this.baseUrl) {
|
|
401
|
+
originPath = path_1.default.resolve(this.baseUrl, originPath);
|
|
402
|
+
}
|
|
403
|
+
this.findDependenciesByRule(originPath);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
processFuzzyMapping(key, from, module2pathMapping) {
|
|
408
|
+
key = key.substring(0, key.indexOf(TSConst_1.ALL) - 1);
|
|
409
|
+
if (from.substring(0, key.indexOf(TSConst_1.ALL) - 1) === key) {
|
|
410
|
+
let tail = from.substring(key.indexOf(TSConst_1.ALL) - 1, from.length);
|
|
411
|
+
module2pathMapping.forEach(pathMapping => {
|
|
412
|
+
pathMapping = pathMapping.substring(0, pathMapping.indexOf(TSConst_1.ALL) - 1);
|
|
413
|
+
let originPath = path_1.default.join(this.scene.getRealProjectDir(), pathMapping, tail);
|
|
414
|
+
if (this.baseUrl) {
|
|
415
|
+
originPath = path_1.default.join(this.baseUrl, originPath);
|
|
416
|
+
}
|
|
417
|
+
this.findDependenciesByRule(originPath);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
findDependenciesByRule(originPath) {
|
|
422
|
+
if (!this.findFilesByPathArray(originPath) && !this.findFilesByExtNameArray(originPath, this.scene.getOptions().supportFileExts)) {
|
|
423
|
+
logger.trace(originPath + 'module mapperInfo is not found!');
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
findFilesByPathArray(originPath) {
|
|
427
|
+
if (!fs_1.default.existsSync(originPath)) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
const dirname = path_1.default.dirname(originPath);
|
|
431
|
+
const indexFileName = FileUtils_1.FileUtils.getIndexFileName(dirname);
|
|
432
|
+
if (indexFileName === '') {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
const curPath = path_1.default.join(dirname, indexFileName);
|
|
436
|
+
if (!this.isRepeatBuildFile(curPath)) {
|
|
437
|
+
this.addFileNode2DependencyGrap(curPath);
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
findFilesByExtNameArray(originPath, pathArray) {
|
|
443
|
+
for (const pathInfo of pathArray) {
|
|
444
|
+
const curPath = originPath + pathInfo;
|
|
445
|
+
if (fs_1.default.existsSync(curPath) && !this.isRepeatBuildFile(curPath)) {
|
|
446
|
+
this.addFileNode2DependencyGrap(curPath);
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
findRelativeDependenciesByOhPkg(from, arkFile) {
|
|
453
|
+
//relative path ../from ./from
|
|
454
|
+
//order
|
|
455
|
+
//1. ../from/oh-package.json5 -> [[name]] -> overRides/overRideDependencyMap? ->
|
|
456
|
+
//[[main]] -> file path ->dependencies(priority)+devDependencies? dynamicDependencies(not support) ->
|
|
457
|
+
//key overRides/overRideDependencyMap?
|
|
458
|
+
//2. ../from/index.ets(ts)
|
|
459
|
+
//3. ../from/index.d.ets(ts)
|
|
460
|
+
//4. ../from.ets(ts)
|
|
461
|
+
//5. ../from.d.ets(ts)
|
|
462
|
+
//2.3.4.5 random order
|
|
463
|
+
let originPath = this.getOriginPath(from, arkFile);
|
|
464
|
+
if (fs_1.default.existsSync(path_1.default.join(originPath, EtsConst_1.OH_PACKAGE_JSON5))) {
|
|
465
|
+
for (const [ohPkgContentPath, ohPkgContent] of this.ohPkgContentMap) {
|
|
466
|
+
this.findDependenciesByOhPkg(ohPkgContentPath, ohPkgContent, from);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
this.findDependenciesByRule(originPath);
|
|
470
|
+
}
|
|
471
|
+
findDependenciesByOhPkg(ohPkgContentPath, ohPkgContentInfo, from) {
|
|
472
|
+
//module name @ohos/from
|
|
473
|
+
const ohPkgContent = ohPkgContentInfo;
|
|
474
|
+
//module main name is must be
|
|
475
|
+
if (ohPkgContent && ohPkgContent.name && from.startsWith(ohPkgContent.name.toString())) {
|
|
476
|
+
let originPath = ohPkgContentPath.toString().replace(EtsConst_1.OH_PACKAGE_JSON5, '');
|
|
477
|
+
if (ohPkgContent.main) {
|
|
478
|
+
originPath = path_1.default.join(ohPkgContentPath.toString().replace(EtsConst_1.OH_PACKAGE_JSON5, ''), ohPkgContent.main.toString());
|
|
479
|
+
if (ohPkgContent.dependencies) {
|
|
480
|
+
this.getDependenciesMapping(ohPkgContent.dependencies, ohPkgContentPath, from);
|
|
481
|
+
}
|
|
482
|
+
else if (ohPkgContent.devDependencies) {
|
|
483
|
+
this.getDependenciesMapping(ohPkgContent.devDependencies, ohPkgContentPath, from);
|
|
484
|
+
}
|
|
485
|
+
else if (ohPkgContent.dynamicDependencies) {
|
|
486
|
+
// dynamicDependencies not support
|
|
487
|
+
}
|
|
488
|
+
this.addFileNode2DependencyGrap(originPath);
|
|
489
|
+
}
|
|
490
|
+
if (!this.findFilesByPathArray(originPath)) {
|
|
491
|
+
logger.trace(originPath + 'module mapperInfo is not found!');
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
getDependenciesMapping(dependencies, ohPkgContentPath, from) {
|
|
496
|
+
for (let [moduleName, modulePath] of Object.entries(dependencies)) {
|
|
497
|
+
logger.debug('dependencies:' + moduleName);
|
|
498
|
+
if (modulePath.startsWith('file:')) {
|
|
499
|
+
modulePath = modulePath.replace(/^file:/, '');
|
|
500
|
+
}
|
|
501
|
+
const innerOhpackagePath = path_1.default.join(ohPkgContentPath.replace(EtsConst_1.OH_PACKAGE_JSON5, ''), modulePath.toString(), EtsConst_1.OH_PACKAGE_JSON5);
|
|
502
|
+
if (!this.ohPkgContentMap.has(innerOhpackagePath)) {
|
|
503
|
+
// inner oh-package 内容缓存(同步读盘 + JSON5 解析只做一次)。
|
|
504
|
+
// 特意不写回 ohPkgContentMap——parseFrom/findRelativeDependenciesByOhPkg
|
|
505
|
+
// 正在 for...of 遍历它,遍历中插入 key 会改变迭代行为;独立 Map 零风险。
|
|
506
|
+
let innerModuleOhPkgContent = this.resolvedOhPkgCache.get(innerOhpackagePath);
|
|
507
|
+
if (!innerModuleOhPkgContent) {
|
|
508
|
+
innerModuleOhPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(innerOhpackagePath);
|
|
509
|
+
this.resolvedOhPkgCache.set(innerOhpackagePath, innerModuleOhPkgContent);
|
|
510
|
+
}
|
|
511
|
+
this.findDependenciesByOhPkg(innerOhpackagePath, innerModuleOhPkgContent, from);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
getOriginPath(from, arkFile) {
|
|
516
|
+
const parentPath = /^\.{1,2}\//.test(from) ? path_1.default.dirname(arkFile.getFilePath()) : arkFile.getProjectDir();
|
|
517
|
+
return path_1.default.resolve(parentPath, from);
|
|
518
|
+
}
|
|
519
|
+
addFileNode2DependencyGrap(filePath) {
|
|
520
|
+
// 汇点收集:三个解析产出路径(findFilesByPathArray / findFilesByExtNameArray /
|
|
521
|
+
// findDependenciesByOhPkg)都经过本方法——当前 parseFrom 槽(若在解析中)
|
|
522
|
+
// 记录产出供缓存条目。getDependencyFilesDeeply 照常执行(构建决策与
|
|
523
|
+
// 缓存收集正交,命中路径在 parseFrom 内直接调用它)。
|
|
524
|
+
const current = this.fromResolutionStack[this.fromResolutionStack.length - 1];
|
|
525
|
+
if (current) {
|
|
526
|
+
current.push(filePath);
|
|
527
|
+
}
|
|
528
|
+
this.getDependencyFilesDeeply(filePath);
|
|
529
|
+
}
|
|
530
|
+
// --- SDK 构建族(原 Scene.buildBasicInfo 的 SDK 段 + buildSdk 族,P3 迁移)---
|
|
531
|
+
/**
|
|
532
|
+
* SDK 阶段:注册/构建全部 SDK 源、SDK 推断 + global API 合并、记录语言表、extendArkUI、标记 project/SDK ID 边界。
|
|
533
|
+
* 顺序语义:fileLanguages 在 SDK 构建之后才生效。
|
|
534
|
+
*/
|
|
535
|
+
buildSdkStage() {
|
|
536
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
537
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.startStage(StageStatistics_1.StageName.BuilderSdk);
|
|
538
|
+
const scene = this.scene;
|
|
539
|
+
const sceneConfig = this.sceneConfig;
|
|
540
|
+
// 子阶段 1:SDK 源文件注册构建(逐文件解析 + 注册 formal 空间)。
|
|
541
|
+
(_b = this.scene.getStageStatisticsCollector()) === null || _b === void 0 ? void 0 : _b.startStage(StageStatistics_1.StageName.BuilderSdkFiles);
|
|
542
|
+
// handle sdks
|
|
543
|
+
if (scene.getOptions().enableBuiltIn && !sceneConfig.getSdksObj().find(sdk => sdk.name === SdkUtils_1.SdkUtils.BUILT_IN_NAME)) {
|
|
544
|
+
sceneConfig.getSdksObj().unshift(SdkUtils_1.SdkUtils.getBuiltInSdk());
|
|
545
|
+
}
|
|
546
|
+
(_c = sceneConfig.getSdksObj()) === null || _c === void 0 ? void 0 : _c.forEach(sdk => {
|
|
547
|
+
if (!sdk.moduleName) {
|
|
548
|
+
this.buildSdk(sdk.name, path_1.default.normalize(sdk.path), sdk.name !== SdkUtils_1.SdkUtils.BUILT_IN_NAME);
|
|
549
|
+
scene.getProjectSdkMap().set(sdk.name, sdk);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
let moduleSdks = scene.getModuleSdkMap().get(sdk.moduleName);
|
|
553
|
+
if (moduleSdks) {
|
|
554
|
+
moduleSdks.push(sdk);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
scene.getModuleSdkMap().set(sdk.moduleName, [sdk]);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
(_d = this.scene.getStageStatisticsCollector()) === null || _d === void 0 ? void 0 : _d.endStage(StageStatistics_1.StageName.BuilderSdkFiles);
|
|
562
|
+
// 子阶段 2:SDK 类型推导与 global API 合并。
|
|
563
|
+
(_e = this.scene.getStageStatisticsCollector()) === null || _e === void 0 ? void 0 : _e.startStage(StageStatistics_1.StageName.BuilderSdkInfer);
|
|
564
|
+
if (scene.getBuildStage() < SceneBuildStage_1.SceneBuildStage.SDK_INFERRED) {
|
|
565
|
+
this.registry.fileSigCanonicalizer
|
|
566
|
+
.getModels()
|
|
567
|
+
.filter(f => !f.isProjectFile())
|
|
568
|
+
.forEach(file => {
|
|
569
|
+
// CXXTodo: C++ does not handle SDK files.
|
|
570
|
+
if (file.getLanguage() === ArkFile_1.Language.CXX) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
Inference_1.InferenceManager.getInstance().getInference(file.getLanguage()).doInfer(file);
|
|
574
|
+
SdkUtils_1.SdkUtils.mergeGlobalAPI(file, SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance().sdkGlobalMap);
|
|
575
|
+
});
|
|
576
|
+
this.registry.fileSigCanonicalizer
|
|
577
|
+
.getModels()
|
|
578
|
+
.filter(f => !f.isProjectFile())
|
|
579
|
+
.forEach(file => {
|
|
580
|
+
SdkUtils_1.SdkUtils.postInferredSdk(file, SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance().sdkGlobalMap);
|
|
581
|
+
});
|
|
582
|
+
scene.setBuildStage(SceneBuildStage_1.SceneBuildStage.SDK_INFERRED);
|
|
583
|
+
}
|
|
584
|
+
(_f = this.scene.getStageStatisticsCollector()) === null || _f === void 0 ? void 0 : _f.endStage(StageStatistics_1.StageName.BuilderSdkInfer);
|
|
585
|
+
scene.setFileLanguages(sceneConfig.getFileLanguages());
|
|
586
|
+
SdkUtils_1.SdkUtils.extendArkUI(scene);
|
|
587
|
+
// SDK 阶段结束:标记 project/SDK FileSigID 边界,此后注册的文件均为 project 文件。
|
|
588
|
+
this.registry.markProjectFileBoundary();
|
|
589
|
+
(_g = this.scene.getStageStatisticsCollector()) === null || _g === void 0 ? void 0 : _g.endStage(StageStatistics_1.StageName.BuilderSdk);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Loads SDK sources into the scene. C++ SDK files are intentionally skipped: they are not parsed or registered
|
|
593
|
+
* here (only non-C++ SDK sources are processed).
|
|
594
|
+
*
|
|
595
|
+
* When {@link createDefaultConstructor} is set, default constructors are ensured for every
|
|
596
|
+
* class registered by this SDK batch right here — before the SDK/project ID boundary is
|
|
597
|
+
* marked — so their method formal IDs stay on the SDK side of the (future class/method-level)
|
|
598
|
+
* boundary invariant. The built-in lib (var-side XxxConstructor pattern + interface-only
|
|
599
|
+
* classes) is excluded by the caller for that reason; library classes must NOT receive
|
|
600
|
+
* models after the boundary (the project-stage batch pass keeps the isLibraryClass guard).
|
|
601
|
+
*/
|
|
602
|
+
buildSdk(sdkName, sdkPath, createDefaultConstructor) {
|
|
603
|
+
const classIdBefore = this.registry.classSigCanonicalizer.size();
|
|
604
|
+
const allFiles = this.collectSdkFiles(sdkName, sdkPath);
|
|
605
|
+
allFiles.forEach(file => {
|
|
606
|
+
if (FileUtils_1.FileUtils.getFileLanguage(file, this.scene.getFileLanguages()) === ArkFile_1.Language.CXX) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
this.parseAndRegisterSdkFile(file, sdkPath, sdkName);
|
|
610
|
+
});
|
|
611
|
+
if (createDefaultConstructor) {
|
|
612
|
+
const size = this.registry.classSigCanonicalizer.size();
|
|
613
|
+
for (let id = classIdBefore; id < size; id++) {
|
|
614
|
+
const cls = this.registry.classSigCanonicalizer.getModel(id);
|
|
615
|
+
if (cls) {
|
|
616
|
+
(0, ArkMethodBuilder_1.ensureDefaultConstructor)(cls);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
collectSdkFiles(sdkName, sdkPath) {
|
|
622
|
+
var _a;
|
|
623
|
+
if (sdkName === SdkUtils_1.SdkUtils.BUILT_IN_NAME) {
|
|
624
|
+
const builtInFiles = SdkUtils_1.SdkUtils.fetchBuiltInFiles(sdkPath);
|
|
625
|
+
if (builtInFiles.length > 0) {
|
|
626
|
+
(_a = this.scene.getOptions().sdkGlobalFolders) === null || _a === void 0 ? void 0 : _a.push(sdkPath);
|
|
627
|
+
}
|
|
628
|
+
return builtInFiles;
|
|
629
|
+
}
|
|
630
|
+
SdkUtils_1.SdkUtils.loadSystemComponentsFromSdk(sdkPath);
|
|
631
|
+
return (0, getAllFiles_1.getAllFiles)(sdkPath, this.scene.getOptions().supportFileExts, this.scene.getOptions().ignoreFileNames);
|
|
632
|
+
}
|
|
633
|
+
parseAndRegisterSdkFile(file, sdkPath, sdkName) {
|
|
634
|
+
var _a, _b;
|
|
635
|
+
logger.trace('=== parse sdk file:', file);
|
|
636
|
+
try {
|
|
637
|
+
const arkFile = new ArkFile_1.ArkFile(FileUtils_1.FileUtils.getFileLanguage(file, this.scene.getFileLanguages()));
|
|
638
|
+
arkFile.setScene(this.scene);
|
|
639
|
+
ArktsFrontend_1.ArktsFrontend.buildArkFileFromSdkPath(file, sdkPath, arkFile, sdkName);
|
|
640
|
+
const allClasses = ModelUtils_1.ModelUtils.getAllClassesInFile(arkFile);
|
|
641
|
+
for (let i = 0; i < allClasses.length; i++) {
|
|
642
|
+
const cls = allClasses[i];
|
|
643
|
+
(_a = cls.getDefaultArkMethod()) === null || _a === void 0 ? void 0 : _a.buildBody();
|
|
644
|
+
(_b = cls.getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.freeBodyBuilder();
|
|
645
|
+
}
|
|
646
|
+
// Release all method builders in SDK file to avoid retaining AST/build context in memory.
|
|
647
|
+
ModelUtils_1.ModelUtils.getAllMethodsInFile(arkFile).forEach(method => {
|
|
648
|
+
var _a;
|
|
649
|
+
if (((_a = method.getDeclaringArkFile()) === null || _a === void 0 ? void 0 : _a.getLanguage()) === ArkFile_1.Language.CXX) {
|
|
650
|
+
method.freeCxxBodyBuilder();
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
method.freeBodyBuilder();
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
arkFile.setProjectFile(false);
|
|
657
|
+
SdkUtils_1.SdkUtils.buildSdkImportMap(arkFile);
|
|
658
|
+
SdkUtils_1.SdkUtils.loadGlobalAPI(arkFile, SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance().sdkGlobalMap);
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
logger.error('Error parsing file:', file, error);
|
|
662
|
+
this.scene.getUnhandledSdkFilePaths().push(file);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
// --- body 构建族(原 Scene.buildAllMethodBody 族,P3 迁移)---
|
|
666
|
+
/**
|
|
667
|
+
* 方法体构建段(原 genArkFiles 尾段):enableMethodBodyBuild 分支——
|
|
668
|
+
* 全量 buildBody + 默认构造器补全,或仅释放 builder。
|
|
669
|
+
*/
|
|
670
|
+
buildAllMethodBodies() {
|
|
671
|
+
var _a, _b, _c;
|
|
672
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.startStage(StageStatistics_1.StageName.BuilderBodies);
|
|
673
|
+
if ((_b = this.scene.getOptions().enableMethodBodyBuild) !== null && _b !== void 0 ? _b : true) {
|
|
674
|
+
this.buildAllMethodBody();
|
|
675
|
+
this.updateOrAddDefaultConstructors();
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
this.freeAllBodyBuilders();
|
|
679
|
+
ModelUtils_1.ModelUtils.dispose();
|
|
680
|
+
this.scene.setBuildStage(SceneBuildStage_1.SceneBuildStage.METHOD_DONE);
|
|
681
|
+
}
|
|
682
|
+
(_c = this.scene.getStageStatisticsCollector()) === null || _c === void 0 ? void 0 : _c.endStage(StageStatistics_1.StageName.BuilderBodies);
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Update or add default constructors for all classes in the scene.
|
|
686
|
+
*/
|
|
687
|
+
updateOrAddDefaultConstructors() {
|
|
688
|
+
// 直接遍历 getClasses()(registry 平面遍历,project 类全量),语言判定随之
|
|
689
|
+
// 移到类级别(类可能来自不同语言的文件)。顺序从结构序变为 classSigID 升序。
|
|
690
|
+
for (const cls of this.scene.getClasses()) {
|
|
691
|
+
// CXXTodo: Select the appropriate initialization function based on file type
|
|
692
|
+
const initInConstructorFn = cls.getDeclaringArkFile().getLanguage() === ArkFile_1.Language.CXX ? ArkMethodBuilder_2.addInitInConstructor : ArkMethodBuilder_1.addInitInConstructor;
|
|
693
|
+
(0, ArkMethodBuilder_1.buildDefaultConstructor)(cls);
|
|
694
|
+
// CXXTodo: Use the interface 'getAllMethodsWithName' for obtaining all methods with the same name.
|
|
695
|
+
const constructors = cls.getAllMethodsWithName(TSConst_1.CONSTRUCTOR_NAME);
|
|
696
|
+
if (cls.isDefaultArkClass()) {
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
constructors.forEach(constructor => {
|
|
700
|
+
(0, ArkMethodBuilder_1.replaceSuper2Constructor)(constructor);
|
|
701
|
+
initInConstructorFn(constructor);
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* 遍历全部 project 文件的 ArkMethod(不含 SDK 方法),逐个回调处理。
|
|
707
|
+
*
|
|
708
|
+
* 直接平面遍历 methodSigCanonicalizer(registry 为事实源),过滤规则:
|
|
709
|
+
* ① getModel(id) 为 undefined 跳过——declare-only 方法(无 model)及
|
|
710
|
+
* BodyBuilder/JsonSerialization 重签名产生的无 model 条目;
|
|
711
|
+
* ② 非 project 文件跳过(SDK 文件,按 file 的 projectFile 标志判定);
|
|
712
|
+
* ③ !enableOhModulesBody 时,oh_modules 文件仅保留 defaultArkMethod。
|
|
713
|
+
* 处理顺序为 methodSigID 升序(buildBody 逐方法独立、无序敏感)。
|
|
714
|
+
*/
|
|
715
|
+
forEachProjectMethod(callback) {
|
|
716
|
+
const size = this.registry.methodSigCanonicalizer.size();
|
|
717
|
+
for (let id = 1; id < size; id++) {
|
|
718
|
+
const method = this.registry.methodSigCanonicalizer.getModel(id);
|
|
719
|
+
if (method === undefined) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
const file = method.getDeclaringArkFile();
|
|
723
|
+
if (!file.isProjectFile()) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if (!this.scene.getOptions().enableOhModulesBody && file.getName().includes(EtsConst_1.OH_MODULES)) {
|
|
727
|
+
if (method !== method.getDeclaringArkClass().getDefaultArkMethod()) {
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
callback(method);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
static freeMethodBodyBuilder(method) {
|
|
735
|
+
var _a;
|
|
736
|
+
const isCxxFile = ((_a = method.getDeclaringArkFile()) === null || _a === void 0 ? void 0 : _a.getLanguage()) === ArkFile_1.Language.CXX;
|
|
737
|
+
if (isCxxFile) {
|
|
738
|
+
method.freeCxxBodyBuilder();
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
method.freeBodyBuilder();
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
buildAllMethodBody() {
|
|
745
|
+
var _a;
|
|
746
|
+
this.scene.setBuildStage(SceneBuildStage_1.SceneBuildStage.CLASS_DONE);
|
|
747
|
+
// C++ has no re-parse body path and keeps building from the signature round's builders.
|
|
748
|
+
this.forEachProjectMethod(method => {
|
|
749
|
+
var _a;
|
|
750
|
+
if (method.getDeclaringArkFile().getLanguage() !== ArkFile_1.Language.CXX) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
try {
|
|
754
|
+
method.buildBody();
|
|
755
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.recordMemoryCheckpoint();
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
logger.error('Error building body:', method.getSignature(), error);
|
|
759
|
+
}
|
|
760
|
+
finally {
|
|
761
|
+
SceneBuilder.freeMethodBodyBuilder(method);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
// ArkTS/TS: rebuild each file's builders from a fresh parse so no file's AST outlives its
|
|
765
|
+
// own body build (the signature round released every builder it mounted).
|
|
766
|
+
for (const arkFile of this.scene.getFiles()) {
|
|
767
|
+
if (!arkFile.isProjectFile() || arkFile.getLanguage() === ArkFile_1.Language.CXX) {
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
if (!this.scene.getOptions().enableOhModulesBody && arkFile.getName().includes(EtsConst_1.OH_MODULES)) {
|
|
771
|
+
// OH module files contribute only their %dflt body, built with the signatures.
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
(0, FileBodyRemount_1.buildFileBodies)(arkFile);
|
|
775
|
+
(_a = this.scene.getStageStatisticsCollector()) === null || _a === void 0 ? void 0 : _a.recordMemoryCheckpoint();
|
|
776
|
+
}
|
|
777
|
+
ModelUtils_1.ModelUtils.dispose();
|
|
778
|
+
this.scene.setBuildStage(SceneBuildStage_1.SceneBuildStage.METHOD_DONE);
|
|
779
|
+
}
|
|
780
|
+
freeAllBodyBuilders() {
|
|
781
|
+
this.forEachProjectMethod(method => {
|
|
782
|
+
SceneBuilder.freeMethodBodyBuilder(method);
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
// --- harmony 模块构建族(原 Scene.buildScene4HarmonyProject / buildModuleScene,P3 迁移)---
|
|
786
|
+
/**
|
|
787
|
+
* harmony 项目构建(原 buildScene4HarmonyProject 主体):逐模块注册
|
|
788
|
+
* ModuleScene(先注册后构建,保证 DFS 归属正确)→ 模块文件 DFS → body 构建。
|
|
789
|
+
*/
|
|
790
|
+
buildScene4HarmonyProject() {
|
|
791
|
+
this.scene.getModulePath2NameMap().forEach((value, key) => {
|
|
792
|
+
// 先注册(复用其他模块 DFS 依赖递归期可能已创建的 partial 实例):
|
|
793
|
+
// 构建期 addArkFile2ModuleScene 依据 moduleScenesMap 归属文件,
|
|
794
|
+
// 注册必须先于 genArkFiles 的 DFS,否则文件会归属到被覆盖的孤儿实例。
|
|
795
|
+
let moduleScene = this.scene.getModuleSceneMap().get(value);
|
|
796
|
+
if (!moduleScene) {
|
|
797
|
+
moduleScene = new ModuleScene_1.ModuleScene(this.scene);
|
|
798
|
+
this.scene.getModuleSceneMap().set(value, moduleScene);
|
|
799
|
+
}
|
|
800
|
+
moduleScene.ModuleSceneBuilder(value, key, this.scene.getOptions().supportFileExts);
|
|
801
|
+
});
|
|
802
|
+
this.buildAllMethodBodies();
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* 单模块构建(原 buildModuleScene 主体,增量式入口):ohpkg 依赖递归 + 模块
|
|
806
|
+
* DFS + body 构建。可能被连续调用构建多个模块——不释放构建上下文(释放交给
|
|
807
|
+
* clear / 完整构建入口)。
|
|
808
|
+
*/
|
|
809
|
+
buildModuleScene(moduleName, modulePath, supportFileExts) {
|
|
810
|
+
const moduleScenesMap = this.scene.getModuleSceneMap();
|
|
811
|
+
if (moduleScenesMap.get(moduleName)) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
// 先注册:构建期 addArkFile2ModuleScene 依据 moduleScenesMap 归属文件,
|
|
815
|
+
// 注册必须先于 ModuleSceneBuilder 内的 DFS;同时兼作 ohpkg 依赖环的递归终止
|
|
816
|
+
// (构建中即已注册,环上重入直接命中上方守卫)。
|
|
817
|
+
const moduleScene = new ModuleScene_1.ModuleScene(this.scene);
|
|
818
|
+
moduleScenesMap.set(moduleName, moduleScene);
|
|
819
|
+
// get oh-package.json5
|
|
820
|
+
const moduleOhPkgFilePath = path_1.default.resolve(this.scene.getRealProjectDir(), path_1.default.join(modulePath, EtsConst_1.OH_PACKAGE_JSON5));
|
|
821
|
+
if (fs_1.default.existsSync(moduleOhPkgFilePath)) {
|
|
822
|
+
const moduleOhPkgContent = (0, json5parser_1.fetchDependenciesFromFile)(moduleOhPkgFilePath);
|
|
823
|
+
this.addOhPkgContent(moduleOhPkgFilePath, moduleOhPkgContent);
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
logger.warn('Module: ', moduleName, 'has no oh-package.json5.');
|
|
827
|
+
}
|
|
828
|
+
// parse moduleOhPkgContent, get dependencies and build dependent module
|
|
829
|
+
const moduleOhPkgContent = this.ohPkgContentMap.get(moduleOhPkgFilePath);
|
|
830
|
+
if (moduleOhPkgContent) {
|
|
831
|
+
if (moduleOhPkgContent.dependencies instanceof Object) {
|
|
832
|
+
this.processModuleOhPkgContent(moduleOhPkgContent.dependencies, moduleOhPkgFilePath, supportFileExts);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
moduleScene.ModuleSceneBuilder(moduleName, modulePath, supportFileExts);
|
|
836
|
+
this.buildAllMethodBodies();
|
|
837
|
+
}
|
|
838
|
+
processModuleOhPkgContent(dependencies, moduleOhPkgFilePath, supportFileExts) {
|
|
839
|
+
Object.entries(dependencies).forEach(([k, v]) => {
|
|
840
|
+
const pattern = new RegExp('^(\\.\\.\\/|\\.\\/)');
|
|
841
|
+
if (typeof v === 'string') {
|
|
842
|
+
let dependencyModulePath = '';
|
|
843
|
+
if (pattern.test(v)) {
|
|
844
|
+
dependencyModulePath = path_1.default.join(moduleOhPkgFilePath, v);
|
|
845
|
+
}
|
|
846
|
+
else if (v.startsWith('file:')) {
|
|
847
|
+
const dependencyFilePath = path_1.default.join(moduleOhPkgFilePath, v.replace(/^file:/, ''));
|
|
848
|
+
const dependencyOhPkgPath = (0, FileUtils_1.getFileRecursively)(path_1.default.dirname(dependencyFilePath), EtsConst_1.OH_PACKAGE_JSON5);
|
|
849
|
+
dependencyModulePath = path_1.default.dirname(dependencyOhPkgPath);
|
|
850
|
+
}
|
|
851
|
+
const dependencyModuleName = this.scene.getModulePath2NameMap().get(dependencyModulePath);
|
|
852
|
+
if (dependencyModuleName) {
|
|
853
|
+
this.buildModuleScene(dependencyModuleName, dependencyModulePath, supportFileExts);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
exports.SceneBuilder = SceneBuilder;
|