1 //===-- OptionValueBoolean.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionValueBoolean.h"
12 #include "lldb/Host/PosixApi.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/Utility/Stream.h"
15 #include "lldb/Utility/StringList.h"
16 #include "llvm/ADT/STLExtras.h"
19 using namespace lldb_private;
21 void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
22 Stream &strm, uint32_t dump_mask) {
23 if (dump_mask & eDumpOptionType)
24 strm.Printf("(%s)", GetTypeAsCString());
25 // if (dump_mask & eDumpOptionName)
26 // DumpQualifiedName (strm);
27 if (dump_mask & eDumpOptionValue) {
28 if (dump_mask & eDumpOptionType)
29 strm.PutCString(" = ");
30 strm.PutCString(m_current_value ? "true" : "false");
34 Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,
35 VarSetOperationType op) {
38 case eVarSetOperationClear:
43 case eVarSetOperationReplace:
44 case eVarSetOperationAssign: {
46 bool value = OptionArgParser::ToBoolean(value_str, false, &success);
48 m_value_was_set = true;
49 m_current_value = value;
52 if (value_str.size() == 0)
53 error.SetErrorString("invalid boolean string value <empty>");
55 error.SetErrorStringWithFormat("invalid boolean string value: '%s'",
56 value_str.str().c_str());
60 case eVarSetOperationInsertBefore:
61 case eVarSetOperationInsertAfter:
62 case eVarSetOperationRemove:
63 case eVarSetOperationAppend:
64 case eVarSetOperationInvalid:
65 error = OptionValue::SetValueFromString(value_str, op);
71 lldb::OptionValueSP OptionValueBoolean::DeepCopy() const {
72 return OptionValueSP(new OptionValueBoolean(*this));
75 size_t OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
76 CompletionRequest &request) {
77 request.SetWordComplete(false);
78 static const llvm::StringRef g_autocomplete_entries[] = {
79 "true", "false", "on", "off", "yes", "no", "1", "0"};
81 auto entries = llvm::makeArrayRef(g_autocomplete_entries);
83 // only suggest "true" or "false" by default
84 if (request.GetCursorArgumentPrefix().empty())
85 entries = entries.take_front(2);
87 for (auto entry : entries) {
88 if (entry.startswith_lower(request.GetCursorArgumentPrefix()))
89 request.AddCompletion(entry);
91 return request.GetNumberOfMatches();