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 
13 using namespace lldb;
14 using namespace lldb_private;
15 
16 OptionValueEnumeration::OptionValueEnumeration(
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 
42  Status error;
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 }
lldb_private::eVarSetOperationInsertBefore
@ eVarSetOperationInsertBefore
Definition: lldb-private-enumerations.h:85
lldb_private::eVarSetOperationReplace
@ eVarSetOperationReplace
Definition: lldb-private-enumerations.h:84
lldb_private::OptionValueEnumeration::EnumeratorInfo::value
enum_type value
Definition: OptionValueEnumeration.h:27
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::UniqueCStringMap::Sort
void Sort()
Definition: UniqueCStringMap.h:168
lldb_private::CompletionRequest::TryCompleteCurrentArg
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
Definition: CompletionRequest.h:180
lldb_private::OptionValueEnumeration::EnumerationMapEntry
EnumerationMap::Entry EnumerationMapEntry
Definition: OptionValueEnumeration.h:31
lldb_private::OptionValueEnumeration::SetValueFromString
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
Definition: OptionValueEnumeration.cpp:40
lldb_private::Stream
Definition: Stream.h:28
lldb_private::OptionValueEnumeration::Clear
void Clear() override
Definition: OptionValueEnumeration.h:48
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::OptionValueEnumeration::AutoComplete
void AutoComplete(CommandInterpreter &interpreter, CompletionRequest &request) override
Definition: OptionValueEnumeration.cpp:98
lldb_private::UniqueCStringMap::GetValueAtIndexUnchecked
T GetValueAtIndexUnchecked(uint32_t idx) const
Definition: UniqueCStringMap.h:68
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::OptionValue::NotifyValueChanged
void NotifyValueChanged()
Definition: OptionValue.h:318
lldb_private::UniqueCStringMap::GetSize
size_t GetSize() const
Definition: UniqueCStringMap.h:148
lldb_private::OptionValue::SetValueFromString
virtual Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign)
Definition: OptionValue.cpp:579
OptionValueEnumeration.h
lldb_private::UniqueCStringMap::FindFirstValueForName
const Entry * FindFirstValueForName(ConstString unique_cstr) const
Definition: UniqueCStringMap.h:98
lldb_private::OptionValueEnumeration::DumpValue
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
Definition: OptionValueEnumeration.cpp:22
lldb_private::eVarSetOperationAppend
@ eVarSetOperationAppend
Definition: lldb-private-enumerations.h:88
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::OptionValueEnumeration::m_enumerations
EnumerationMap m_enumerations
Definition: OptionValueEnumeration.h:76
lldb_private::OptionValue::eDumpOptionValue
@ eDumpOptionValue
Definition: OptionValue.h:53
lldb_private::CompletionRequest::GetCursorArgumentPrefix
llvm::StringRef GetCursorArgumentPrefix() const
Definition: CompletionRequest.h:217
StringList.h
lldb_private::OptionValue::GetTypeAsCString
virtual const char * GetTypeAsCString() const
Definition: OptionValue.h:76
lldb_private::UniqueCStringMap::GetCStringAtIndex
ConstString GetCStringAtIndex(uint32_t idx) const
Definition: UniqueCStringMap.h:76
lldb_private::Status
Definition: Status.h:44
lldb_private::UniqueCStringMap::Append
void Append(ConstString unique_cstr, const T &value)
Definition: UniqueCStringMap.h:42
lldb_private::OptionValueEnumeration::enum_type
int64_t enum_type
Definition: OptionValueEnumeration.h:25
uint32_t
lldb_private::OptionValueEnumeration::m_current_value
enum_type m_current_value
Definition: OptionValueEnumeration.h:74
lldb_private::OptionValue::eDumpOptionType
@ eDumpOptionType
Definition: OptionValue.h:52
lldb_private::OptionValueEnumeration::SetEnumerations
void SetEnumerations(const OptionEnumValues &enumerators)
Definition: OptionValueEnumeration.cpp:85
lldb_private::OptionValueEnumeration::EnumeratorInfo
Definition: OptionValueEnumeration.h:26
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb_private::eVarSetOperationRemove
@ eVarSetOperationRemove
Definition: lldb-private-enumerations.h:87
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::CompletionRequest::AddCompletion
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
Definition: CompletionRequest.h:167
lldb_private::eVarSetOperationInvalid
@ eVarSetOperationInvalid
Definition: lldb-private-enumerations.h:91
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::UniqueCStringMap::Clear
void Clear()
Definition: UniqueCStringMap.h:48
lldb
Definition: SBAddress.h:15
lldb_private::eVarSetOperationClear
@ eVarSetOperationClear
Definition: lldb-private-enumerations.h:89
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::eVarSetOperationInsertAfter
@ eVarSetOperationInsertAfter
Definition: lldb-private-enumerations.h:86
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90