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_OPTION_H 10 #define OHOS_HDI_OPTION_H 11 12 #include <map> 13 #include <string> 14 #include <unordered_map> 15 #include <set> 16 17 #include "util/common.h" 18 19 namespace OHOS { 20 namespace HDI { 21 class Options { 22 public: 23 using PkgPathMap = std::unordered_map<std::string, std::string>; 24 25 static Options &GetInstance(); 26 27 Options(const Options &other) = delete; 28 Options operator=(const Options &other) = delete; 29 30 bool Parse(int argc, char *argv[]); 31 32 ~Options() = default; 33 DoShowUsage()34 inline bool DoShowUsage() const 35 { 36 return doShowUsage; 37 } 38 DoShowVersion()39 inline bool DoShowVersion() const 40 { 41 return doShowVersion; 42 } 43 DoCompile()44 inline bool DoCompile() const 45 { 46 return doCompile; 47 } 48 DoDumpAST()49 inline bool DoDumpAST() const 50 { 51 return doDumpAST; 52 } 53 DoGetHashKey()54 inline bool DoGetHashKey() const 55 { 56 return doHashKey; 57 } 58 DoGenerateCode()59 inline bool DoGenerateCode() const 60 { 61 return doGenerateCode; 62 } 63 DoGenerateKernelCode()64 inline bool DoGenerateKernelCode() const 65 { 66 return genMode == GenMode::KERNEL; 67 } 68 DoPassthrough()69 inline bool DoPassthrough() const 70 { 71 return genMode == GenMode::PASSTHROUGH; 72 } 73 GetSourceFiles()74 inline std::set<std::string> GetSourceFiles() const 75 { 76 return sourceFiles; 77 } 78 GetPackagePathMap()79 inline PkgPathMap GetPackagePathMap() const 80 { 81 return packagePathMap; 82 } 83 GetPackage()84 inline std::string GetPackage() const 85 { 86 return idlPackage; 87 } 88 GetGenerationDirectory()89 inline std::string GetGenerationDirectory() const 90 { 91 return genDir; 92 } 93 GetOutPutFile()94 inline std::string GetOutPutFile() const 95 { 96 return outPutFile; 97 } 98 99 void ShowVersion() const; 100 101 void ShowUsage() const; 102 103 std::string GetRootPackage(const std::string &package) const; 104 105 std::string GetRootPath(const std::string &package) const; 106 107 std::string GetSubPackage(const std::string &package) const; 108 109 std::string GetPackagePath(const std::string &package) const; 110 111 std::string GetImportFilePath(const std::string &import) const; 112 GetSystemLevel()113 inline SystemLevel GetSystemLevel() const 114 { 115 return systemLevel; 116 } 117 GetGenMode()118 inline GenMode GetGenMode() const 119 { 120 return genMode; 121 } 122 GetLanguage()123 inline Language GetLanguage() const 124 { 125 return genLanguage; 126 } 127 128 private: Options()129 Options() 130 : program(), 131 systemLevel(SystemLevel::FULL), 132 genMode(GenMode::IPC), 133 genLanguage(Language::CPP), 134 idlPackage(), 135 sourceFiles(), 136 genDir(), 137 packagePathMap(), 138 outPutFile(), 139 doShowUsage(false), 140 doShowVersion(false), 141 doCompile(false), 142 doDumpAST(false), 143 doHashKey(false), 144 doGenerateCode(false), 145 doOutDir(false) 146 { 147 } 148 149 void SetLongOption(char op); 150 151 bool SetSystemLevel(const std::string &system); 152 153 bool SetGenerateMode(const std::string &mode); 154 155 bool SetLanguage(const std::string &language); 156 157 void SetPackage(const std::string &package); 158 159 bool AddPackagePath(const std::string &packagePath); 160 161 void AddSources(const std::string &sourceFile); 162 163 void AddSourcesByDir(const std::string &dir); 164 165 void SetOutDir(const std::string &dir); 166 167 void SetCodePart(const std::string &part); 168 169 bool CheckOptions(); 170 171 static const char *optSupportArgs; 172 static constexpr int OPT_END = -1; 173 174 static constexpr int VERSION_MAJOR = 1; 175 static constexpr int VERSION_MINOR = 0; 176 177 std::string program; 178 SystemLevel systemLevel; 179 GenMode genMode; 180 Language genLanguage; 181 std::string idlPackage; 182 std::set<std::string> sourceFiles; 183 std::string genDir; 184 PkgPathMap packagePathMap; 185 std::string outPutFile; 186 bool doShowUsage; 187 bool doShowVersion; 188 bool doCompile; 189 bool doDumpAST; 190 bool doHashKey; 191 bool doGenerateCode; 192 bool doOutDir; 193 }; 194 } // namespace HDI 195 } // namespace OHOS 196 197 #endif // OHOS_HDIL_OPTION_H