brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 595dcba Raw
70 lines · cpp
1//===-- OptionValueChar.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/OptionValueChar.h"10 11#include "lldb/Interpreter/OptionArgParser.h"12#include "lldb/Interpreter/OptionValue.h"13#include "lldb/Utility/Stream.h"14#include "lldb/Utility/StringList.h"15#include "llvm/ADT/STLExtras.h"16 17using namespace lldb;18using namespace lldb_private;19 20static void DumpChar(Stream &strm, char value) {21  if (value != '\0')22    strm.PutChar(value);23  else24    strm.PutCString("(null)");25}26 27void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,28                                uint32_t dump_mask) {29  if (dump_mask & eDumpOptionType)30    strm.Printf("(%s)", GetTypeAsCString());31 32  if (dump_mask & eDumpOptionValue) {33    if (dump_mask & eDumpOptionType)34      strm.PutCString(" = ");35    DumpChar(strm, m_current_value);36    if (dump_mask & eDumpOptionDefaultValue &&37        m_current_value != m_default_value) {38      DefaultValueFormat label(strm);39      DumpChar(strm, m_default_value);40    }41  }42}43 44Status OptionValueChar::SetValueFromString(llvm::StringRef value,45                                           VarSetOperationType op) {46  Status error;47  switch (op) {48  case eVarSetOperationClear:49    Clear();50    break;51 52  case eVarSetOperationReplace:53  case eVarSetOperationAssign: {54    bool success = false;55    char char_value = OptionArgParser::ToChar(value, '\0', &success);56    if (success) {57      m_current_value = char_value;58      m_value_was_set = true;59    } else60      return Status::FromErrorStringWithFormatv(61          "'{0}' cannot be longer than 1 character", value);62  } break;63 64  default:65    error = OptionValue::SetValueFromString(value, op);66    break;67  }68  return error;69}70