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 <unordered_map> 13 #include <vector> 14 #include "util/string.h" 15 16 namespace OHOS { 17 namespace HDI { 18 class Options { 19 public: 20 using PkgPathMap = std::unordered_map<String, String, StringHashFunc, StringEqualFunc>; 21 22 static Options& GetInstance(); 23 24 Options(const Options& other) = delete; 25 Options operator=(const Options& other) = delete; 26 27 Options& Parse(int argc, char *argv[]); 28 29 ~Options() = default; 30 DoShowUsage()31 inline bool DoShowUsage() const 32 { 33 return doShowUsage_; 34 } 35 DoShowVersion()36 inline bool DoShowVersion() const 37 { 38 return doShowVersion_; 39 } 40 DoCompile()41 inline bool DoCompile() const 42 { 43 return doCompile_; 44 } 45 DoDumpAST()46 inline bool DoDumpAST() const 47 { 48 return doDumpAST_; 49 } 50 DoGetHashKey()51 inline bool DoGetHashKey() const 52 { 53 return doGetHashKey_; 54 } 55 DoGenerateCode()56 inline bool DoGenerateCode() const 57 { 58 return doGenerateCode_; 59 } 60 DoGenerateKernelCode()61 inline bool DoGenerateKernelCode() const 62 { 63 return doModeKernel_; 64 } 65 HasErrors()66 inline bool HasErrors() const 67 { 68 return !errors_.empty(); 69 } 70 GetSourceFiles()71 inline std::vector<String> GetSourceFiles() const 72 { 73 return sourceFiles_; 74 } 75 GetPackagePath()76 inline PkgPathMap GetPackagePath() const 77 { 78 return packagePath_; 79 } 80 GetTargetLanguage()81 inline String GetTargetLanguage() const 82 { 83 return targetLanguage_; 84 } 85 GetCodePart()86 inline String GetCodePart() const 87 { 88 return codePart_; 89 } 90 GetModuleName()91 inline String GetModuleName() const 92 { 93 return doSetModuleName_ ? moduleName_ : "sample"; 94 } 95 GetGenerationDirectory()96 inline String GetGenerationDirectory() const 97 { 98 return generationDirectory_; 99 } 100 101 void ShowErrors() const; 102 103 void ShowVersion() const; 104 105 void ShowUsage() const; 106 107 String GetRootPackage(const String& package); 108 109 String GetSubPackage(const String& package); 110 111 String GetPackagePath(const String& package); 112 private: Options()113 Options() : program_(), 114 sourceFiles_(0), 115 targetLanguage_(), 116 codePart_("all"), 117 generationDirectory_(), 118 illegalOptions_(), 119 errors_(), 120 doShowUsage_(false), 121 doShowVersion_(false), 122 doCompile_(false), 123 doDumpAST_(false), 124 doGetHashKey_(false), 125 doGenerateCode_(false), 126 doModeKernel_(false), 127 doGeneratePart_(false), 128 doSetModuleName_(false), 129 doOutDir_(false) {} 130 131 void SetOptionData(char op); 132 133 void AddPackagePath(const String& packagePath); 134 135 void SetLanguage(const String& language); 136 137 void SetCodePart(const String& part); 138 139 void CheckOptions(); 140 141 static const char* optSupportArgs; 142 static constexpr int OPT_END = -1; 143 144 static constexpr int VERSION_MAJOR = 0; 145 static constexpr int VERSION_MINOR = 1; 146 147 String program_; 148 std::vector<String> sourceFiles_; 149 String targetLanguage_; 150 String codePart_; 151 String moduleName_; 152 String generationDirectory_; 153 String illegalOptions_; 154 std::vector<String> errors_; 155 PkgPathMap packagePath_; 156 157 bool doShowUsage_; 158 bool doShowVersion_; 159 bool doCompile_; 160 bool doDumpAST_; 161 bool doGetHashKey_; 162 bool doGenerateCode_; 163 bool doModeKernel_; 164 bool doGeneratePart_; 165 bool doSetModuleName_; 166 bool doOutDir_; 167 }; 168 } // namespace HDI 169 } // namespace OHOS 170 171 #endif // OHOS_HDIL_OPTION_H