LLDB mainline
OptionValueEnumeration.cpp
Go to the documentation of this file.
1//===-- OptionValueEnumeration.cpp ----------------------------------------===//
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
10
12
13using namespace lldb;
14using namespace lldb_private;
15
17 const OptionEnumValues &enumerators, enum_type value)
18 : m_current_value(value), m_default_value(value) {
19 SetEnumerations(enumerators);
20}
21
23 Stream &strm, uint32_t dump_mask) {
24 if (dump_mask & eDumpOptionType)
25 strm.Printf("(%s)", GetTypeAsCString());
26 if (dump_mask & eDumpOptionValue) {
27 if (dump_mask & eDumpOptionType)
28 strm.PutCString(" = ");
29 const size_t count = m_enumerations.GetSize();
30 for (size_t i = 0; i < count; ++i) {
33 return;
34 }
35 }
36 strm.Printf("%" PRIu64, (uint64_t)m_current_value);
37 }
38}
39
43 switch (op) {
45 Clear();
47 break;
48
51 ConstString const_enumerator_name(value.trim());
52 const EnumerationMapEntry *enumerator_entry =
53 m_enumerations.FindFirstValueForName(const_enumerator_name);
54 if (enumerator_entry) {
55 m_current_value = enumerator_entry->value.value;
57 } else {
58 StreamString error_strm;
59 error_strm.Printf("invalid enumeration value '%s'", value.str().c_str());
60 const size_t count = m_enumerations.GetSize();
61 if (count) {
62 error_strm.Printf(", valid values are: %s",
64 for (size_t i = 1; i < count; ++i) {
65 error_strm.Printf(", %s",
67 }
68 }
69 error.SetErrorString(error_strm.GetString());
70 }
71 break;
72 }
73
80 break;
81 }
82 return error;
83}
84
86 const OptionEnumValues &enumerators) {
88
89 for (const auto &enumerator : enumerators) {
90 ConstString const_enumerator_name(enumerator.string_value);
91 EnumeratorInfo enumerator_info = {enumerator.value, enumerator.usage};
92 m_enumerations.Append(const_enumerator_name, enumerator_info);
93 }
94
96}
97
99 CompletionRequest &request) {
100 const uint32_t num_enumerators = m_enumerations.GetSize();
101 if (!request.GetCursorArgumentPrefix().empty()) {
102 for (size_t i = 0; i < num_enumerators; ++i) {
103 llvm::StringRef name = m_enumerations.GetCStringAtIndex(i).GetStringRef();
104 request.TryCompleteCurrentArg(name);
105 }
106 return;
107 }
108 for (size_t i = 0; i < num_enumerators; ++i)
110}
static llvm::raw_ostream & error(Stream &strm)
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
llvm::StringRef GetCursorArgumentPrefix() const
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
A uniqued constant string class.
Definition: ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetEnumerations(const OptionEnumValues &enumerators)
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
OptionValueEnumeration(const OptionEnumValues &enumerators, enum_type value)
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:87
An error handling class.
Definition: Status.h:44
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
ConstString GetCStringAtIndex(uint32_t idx) const
const Entry * FindFirstValueForName(ConstString unique_cstr) const
T GetValueAtIndexUnchecked(uint32_t idx) const
void Append(ConstString unique_cstr, const T &value)
A class that represents a running process on the host machine.
VarSetOperationType
Settable state variable types.
llvm::ArrayRef< OptionEnumValueElement > OptionEnumValues
Definition: SBAddress.h:15