• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ES2PANDA_DEPENDENCY_ANALYZER_H
17 #define ES2PANDA_DEPENDENCY_ANALYZER_H
18 
19 #include "public/es2panda_lib.h"
20 #include "public/public.h"
21 #include "parser/parserImpl.h"
22 #include "util/options.h"
23 #include <iostream>
24 #include <vector>
25 
26 struct DepAnalyzerArgs {
27     std::string programName;
28     std::string arktsconfig;
29     std::vector<std::string> fileList;
30 };
31 
32 class DepAnalyzer {
33 public:
34     int AnalyzeDeps(int argc, const char **argv);
35     int AnalyzeDepsForMultiFiles(const char *exec, std::vector<std::string> &fileList, std::string &arktsconfig);
36     std::string ConvertPath(const std::string &path) const;
37     void Dump(std::string &outFilePath);
38     void Dump(std::ostream &ostr = std::cout);
39 
GetSourcePaths()40     const std::vector<std::string> &GetSourcePaths()
41     {
42         return sourcePaths_;
43     }
44 
GetFileDirectDependencies()45     std::unordered_map<std::string, std::unordered_set<std::string>> &GetFileDirectDependencies()
46     {
47         return fileDirectDependencies_;
48     }
49 
GetFileDirectDependants()50     std::unordered_map<std::string, std::unordered_set<std::string>> &GetFileDirectDependants()
51     {
52         return fileDirectDependants_;
53     }
54 
55 private:
56     void AddImports(ark::es2panda::parser::ETSParser *parser);
57     bool ShouldSkipFile(const std::string &filePath) const;
58     void MergeFileDeps(ark::es2panda::parser::Program *mainProgram);
59 
60     std::vector<std::string> sourcePaths_;
61     std::vector<std::string> skipPatterns_;
62     std::unordered_map<std::string, std::unordered_set<std::string>> fileDirectDependencies_;
63     std::unordered_map<std::string, std::unordered_set<std::string>> fileDirectDependants_;
64 };
65 
66 #endif  // ES2PANDA_DEPENDENCY_ANALYZER_H
67