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 char ToChar(llvm::StringRef s, char fail_value, bool *success_ptr); |
33 | |
34 | static int64_t ToOptionEnum(llvm::StringRef s, |
35 | const OptionEnumValues &enum_values, |
36 | int32_t fail_value, Status &error); |
37 | |
38 | static lldb::ScriptLanguage ToScriptLanguage(llvm::StringRef s, |
39 | lldb::ScriptLanguage fail_value, |
40 | bool *success_ptr); |
41 | |
42 | // TODO: Use StringRef |
43 | static Status ToFormat(const char *s, lldb::Format &format, |
44 | size_t *byte_size_ptr); // If non-NULL, then a |
45 | // byte size can precede |
46 | // the format character |
47 | |
48 | private: |
49 | static std::optional<lldb::addr_t> |
50 | DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s, |
51 | Status *error); |
52 | }; |
53 | |
54 | } // namespace lldb_private |
55 | |
56 | #endif // LLDB_INTERPRETER_OPTIONARGPARSER_H |
57 | |