1 //===-- OptionParser.h ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_HOST_OPTIONPARSER_H 10 #define LLDB_HOST_OPTIONPARSER_H 11 12 #include <mutex> 13 #include <string> 14 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/ADT/ArrayRef.h" 17 18 struct option; 19 20 namespace lldb_private { 21 22 struct OptionDefinition; 23 24 struct Option { 25 // The definition of the option that this refers to. 26 const OptionDefinition *definition; 27 // if not NULL, set *flag to val when option found 28 int *flag; 29 // if flag not NULL, value to set *flag to; else return value 30 int val; 31 }; 32 33 class OptionParser { 34 public: 35 enum OptionArgument { eNoArgument = 0, eRequiredArgument, eOptionalArgument }; 36 37 static void Prepare(std::unique_lock<std::mutex> &lock); 38 39 static void EnableError(bool error); 40 41 /// Argv must be an argument vector "as passed to main", i.e. terminated with 42 /// a nullptr. 43 static int Parse(llvm::MutableArrayRef<char *> argv, 44 llvm::StringRef optstring, const Option *longopts, 45 int *longindex); 46 47 static char *GetOptionArgument(); 48 static int GetOptionIndex(); 49 static int GetOptionErrorCause(); 50 static std::string GetShortOptionString(struct option *long_options); 51 }; 52 } 53 54 #endif // LLDB_HOST_OPTIONPARSER_H 55