Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionValueBoolean.cpp
39587 views
//===-- OptionValueBoolean.cpp --------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionValueBoolean.h"910#include "lldb/Host/PosixApi.h"11#include "lldb/Interpreter/OptionArgParser.h"12#include "lldb/Utility/Stream.h"13#include "lldb/Utility/StringList.h"14#include "llvm/ADT/STLExtras.h"1516using namespace lldb;17using namespace lldb_private;1819void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,20Stream &strm, uint32_t dump_mask) {21if (dump_mask & eDumpOptionType)22strm.Printf("(%s)", GetTypeAsCString());23// if (dump_mask & eDumpOptionName)24// DumpQualifiedName (strm);25if (dump_mask & eDumpOptionValue) {26if (dump_mask & eDumpOptionType)27strm.PutCString(" = ");28strm.PutCString(m_current_value ? "true" : "false");29}30}3132Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,33VarSetOperationType op) {34Status error;35switch (op) {36case eVarSetOperationClear:37Clear();38NotifyValueChanged();39break;4041case eVarSetOperationReplace:42case eVarSetOperationAssign: {43bool success = false;44bool value = OptionArgParser::ToBoolean(value_str, false, &success);45if (success) {46m_value_was_set = true;47m_current_value = value;48NotifyValueChanged();49} else {50if (value_str.size() == 0)51error.SetErrorString("invalid boolean string value <empty>");52else53error.SetErrorStringWithFormat("invalid boolean string value: '%s'",54value_str.str().c_str());55}56} break;5758case eVarSetOperationInsertBefore:59case eVarSetOperationInsertAfter:60case eVarSetOperationRemove:61case eVarSetOperationAppend:62case eVarSetOperationInvalid:63error = OptionValue::SetValueFromString(value_str, op);64break;65}66return error;67}6869void OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,70CompletionRequest &request) {71llvm::StringRef autocomplete_entries[] = {"true", "false", "on", "off",72"yes", "no", "1", "0"};7374auto entries = llvm::ArrayRef(autocomplete_entries);7576// only suggest "true" or "false" by default77if (request.GetCursorArgumentPrefix().empty())78entries = entries.take_front(2);7980for (auto entry : entries)81request.TryCompleteCurrentArg(entry);82}838485