1 //===-- OptionValueBoolean.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueBoolean.h"
11 #include "lldb/Host/PosixApi.h"
12 #include "lldb/Interpreter/OptionArgParser.h"
13 #include "lldb/Utility/Stream.h"
14 #include "lldb/Utility/StringList.h"
15 #include "llvm/ADT/STLExtras.h"
18 using namespace lldb_private
;
20 void OptionValueBoolean::DumpValue(const ExecutionContext
*exe_ctx
,
21 Stream
&strm
, uint32_t dump_mask
) {
22 if (dump_mask
& eDumpOptionType
)
23 strm
.Printf("(%s)", GetTypeAsCString());
24 // if (dump_mask & eDumpOptionName)
25 // DumpQualifiedName (strm);
26 if (dump_mask
& eDumpOptionValue
) {
27 if (dump_mask
& eDumpOptionType
)
28 strm
.PutCString(" = ");
29 strm
.PutCString(m_current_value
? "true" : "false");
33 Status
OptionValueBoolean::SetValueFromString(llvm::StringRef value_str
,
34 VarSetOperationType op
) {
37 case eVarSetOperationClear
:
42 case eVarSetOperationReplace
:
43 case eVarSetOperationAssign
: {
45 bool value
= OptionArgParser::ToBoolean(value_str
, false, &success
);
47 m_value_was_set
= true;
48 m_current_value
= value
;
51 if (value_str
.size() == 0)
52 error
= Status::FromErrorString("invalid boolean string value <empty>");
54 error
= Status::FromErrorStringWithFormat(
55 "invalid boolean string value: '%s'", value_str
.str().c_str());
59 case eVarSetOperationInsertBefore
:
60 case eVarSetOperationInsertAfter
:
61 case eVarSetOperationRemove
:
62 case eVarSetOperationAppend
:
63 case eVarSetOperationInvalid
:
64 error
= OptionValue::SetValueFromString(value_str
, op
);
70 void OptionValueBoolean::AutoComplete(CommandInterpreter
&interpreter
,
71 CompletionRequest
&request
) {
72 llvm::StringRef autocomplete_entries
[] = {"true", "false", "on", "off",
73 "yes", "no", "1", "0"};
75 auto entries
= llvm::ArrayRef(autocomplete_entries
);
77 // only suggest "true" or "false" by default
78 if (request
.GetCursorArgumentPrefix().empty())
79 entries
= entries
.take_front(2);
81 for (auto entry
: entries
)
82 request
.TryCompleteCurrentArg(entry
);