• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef OHOS_HDI_PREPROCESSOR_H
10 #define OHOS_HDI_PREPROCESSOR_H
11 
12 #include <unordered_map>
13 #include <unordered_set>
14 #include <vector>
15 
16 #include "lexer/lexer.h"
17 #include "util/string_helper.h"
18 
19 namespace OHOS {
20 namespace HDI {
21 class FileDetail {
22 public:
GetFullName()23     inline std::string GetFullName() const
24     {
25         return StringHelper::Format("%s.%s", packageName_.c_str(), fileName_.c_str());
26     }
27 
28     std::string Dump() const;
29 
30 public:
31     std::string filePath_;
32     std::string fileName_;
33     std::string packageName_;
34     std::unordered_set<std::string> imports_;
35 };
36 
37 class Preprocessor {
38 public:
39     using FileDetailMap = std::unordered_map<std::string, FileDetail>;
40 
41     // analyze idl files and return sorted ids files
42     bool Preprocess(std::vector<std::string> &compileSourceFiles);
43 
44 private:
45     bool CheckAllFilesPath(const std::vector<std::string> &sourceFiles);
46 
47     bool AnalyseImportInfo(const std::vector<std::string> &sourceFiles, FileDetailMap &allFileDetails);
48 
49     bool ParseFileDetail(const std::string &sourceFile, FileDetail &info);
50 
51     bool ParsePackage(Lexer &lexer, FileDetail &info);
52 
53     bool ParseImports(Lexer &lexer, FileDetail &info);
54 
55     bool LoadOtherIdlFiles(const FileDetail &ownerFileDetail, FileDetailMap &allFileDetails);
56 
57     bool CheckCircularReference(FileDetailMap &allFileDetails, std::vector<std::string> &compileSourceFiles);
58 
59     void PrintCyclefInfo(FileDetailMap &allFileDetails);
60 
61     void FindCycle(const std::string &curNode, FileDetailMap &allFiles, std::vector<std::string> &trace);
62 };
63 } // namespace HDI
64 } // namespace OHOS
65 
66 #endif // OHOS_HDI_PREPROCESSOR_H