1 /* 2 * Copyright (c) 2021 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_MODULE_PARSER_H 10 #define OHOS_HDI_MODULE_PARSER_H 11 12 #include <memory> 13 #include <set> 14 #include "ast/ast_module.h" 15 #include "parser/file_detail.h" 16 #include "util/options.h" 17 18 namespace OHOS { 19 namespace HDI { 20 class ModuleParser { 21 public: 22 using FileDetailMap = std::unordered_map<String, std::shared_ptr<FileDetail>, StringHashFunc, StringEqualFunc>; 23 ModuleParser(const Options & option)24 explicit ModuleParser(const Options& option) : option_(option), 25 sourceFiles_(), 26 searchedFile_(), 27 traceFilePtr_(nullptr), 28 allCirclesFile_(), 29 compileFiles_(), 30 module_(new ASTModule()) {} 31 ~ModuleParser()32 ~ModuleParser() {} 33 34 AutoPtr<ASTModule> Parse(); 35 private: 36 // parser file and circular reference 37 bool ParserDependencies(); 38 39 bool CompileFiles(); 40 41 // parse all idl file involved in compilation. 42 bool ParserAllImports(const String& rootFilePath); 43 44 bool ParserAllImportsRecursion(const std::shared_ptr<FileDetail>& fileInfo); 45 46 bool ParserAllidlFile(const std::vector<String>& idlSourceFile); 47 48 // check circular reference and reverse topology sorting of all idl file 49 bool CheckCircularReference(); 50 51 static const char* TAG; 52 53 const Options& option_; 54 FileDetailMap sourceFiles_; 55 56 std::set<String> searchedFile_; 57 std::shared_ptr<std::vector<String>> traceFilePtr_; 58 std::vector<std::vector<String>> allCirclesFile_; 59 60 std::vector<String> compileFiles_; 61 62 AutoPtr<ASTModule> module_; 63 }; 64 } // namespace HDI 65 } // namespace OHOS 66 67 #endif // OHOS_HDI_MODULE_PARSER_H