brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 023c243 Raw
90 lines · cpp
1//===-- OptionValueBoolean.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Interpreter/OptionValueBoolean.h"10 11#include "lldb/Host/PosixApi.h"12#include "lldb/Interpreter/OptionArgParser.h"13#include "lldb/Interpreter/OptionValue.h"14#include "lldb/Utility/Stream.h"15#include "lldb/Utility/StringList.h"16#include "llvm/ADT/STLExtras.h"17 18using namespace lldb;19using namespace lldb_private;20 21void 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");31    if (dump_mask & eDumpOptionDefaultValue &&32        m_current_value != m_default_value) {33      DefaultValueFormat label(strm);34      strm.PutCString(m_default_value ? "true" : "false");35    }36  }37}38 39Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,40                                              VarSetOperationType op) {41  Status error;42  switch (op) {43  case eVarSetOperationClear:44    Clear();45    NotifyValueChanged();46    break;47 48  case eVarSetOperationReplace:49  case eVarSetOperationAssign: {50    bool success = false;51    bool value = OptionArgParser::ToBoolean(value_str, false, &success);52    if (success) {53      m_value_was_set = true;54      m_current_value = value;55      NotifyValueChanged();56    } else {57      if (value_str.size() == 0)58        error = Status::FromErrorString("invalid boolean string value <empty>");59      else60        error = Status::FromErrorStringWithFormat(61            "invalid boolean string value: '%s'", value_str.str().c_str());62    }63  } break;64 65  case eVarSetOperationInsertBefore:66  case eVarSetOperationInsertAfter:67  case eVarSetOperationRemove:68  case eVarSetOperationAppend:69  case eVarSetOperationInvalid:70    error = OptionValue::SetValueFromString(value_str, op);71    break;72  }73  return error;74}75 76void OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,77                                      CompletionRequest &request) {78  llvm::StringRef autocomplete_entries[] = {"true", "false", "on", "off",79                                            "yes",  "no",    "1",  "0"};80 81  auto entries = llvm::ArrayRef(autocomplete_entries);82 83  // only suggest "true" or "false" by default84  if (request.GetCursorArgumentPrefix().empty())85    entries = entries.take_front(2);86 87  for (auto entry : entries)88    request.TryCompleteCurrentArg(entry);89}90