xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Interpreter/OptionArgParser.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- OptionArgParser.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_INTERPRETER_OPTIONARGPARSER_H
10 #define LLDB_INTERPRETER_OPTIONARGPARSER_H
11 
12 #include "lldb/lldb-private-types.h"
13 
14 #include <optional>
15 
16 namespace lldb_private {
17 
18 struct OptionArgParser {
19   /// Try to parse an address. If it succeeds return the address with the
20   /// non-address bits removed.
21   static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx,
22                                 llvm::StringRef s, lldb::addr_t fail_value,
23                                 Status *error_ptr);
24 
25   /// As for ToAddress but do not remove non-address bits from the result.
26   static lldb::addr_t ToRawAddress(const ExecutionContext *exe_ctx,
27                                    llvm::StringRef s, lldb::addr_t fail_value,
28                                    Status *error_ptr);
29 
30   static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr);
31 
32   static llvm::Expected<bool> ToBoolean(llvm::StringRef option_name,
33                                         llvm::StringRef option_arg);
34 
35   static char ToChar(llvm::StringRef s, char fail_value, bool *success_ptr);
36 
37   static int64_t ToOptionEnum(llvm::StringRef s,
38                               const OptionEnumValues &enum_values,
39                               int32_t fail_value, Status &error);
40 
41   static lldb::ScriptLanguage ToScriptLanguage(llvm::StringRef s,
42                                                lldb::ScriptLanguage fail_value,
43                                                bool *success_ptr);
44 
45   // TODO: Use StringRef
46   static Status ToFormat(const char *s, lldb::Format &format,
47                          size_t *byte_size_ptr); // If non-NULL, then a
48                                                  // byte size can precede
49                                                  // the format character
50 
51 private:
52   static std::optional<lldb::addr_t>
53   DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
54               Status *error);
55 };
56 
57 } // namespace lldb_private
58 
59 #endif // LLDB_INTERPRETER_OPTIONARGPARSER_H
60