brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 05990fb Raw
70 lines · cpp
1//===-- OptionValueFormat.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/OptionValueFormat.h"10 11#include "lldb/DataFormatters/FormatManager.h"12#include "lldb/Interpreter/OptionArgParser.h"13#include "lldb/Interpreter/OptionValue.h"14#include "lldb/Utility/Stream.h"15 16using namespace lldb;17using namespace lldb_private;18 19void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,20                                  uint32_t dump_mask) {21  if (dump_mask & eDumpOptionType)22    strm.Printf("(%s)", GetTypeAsCString());23  if (dump_mask & eDumpOptionValue) {24    if (dump_mask & eDumpOptionType)25      strm.PutCString(" = ");26    strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));27    if (dump_mask & eDumpOptionDefaultValue &&28        m_current_value != m_default_value) {29      DefaultValueFormat label(strm);30      strm.PutCString(FormatManager::GetFormatAsCString(m_default_value));31    }32  }33}34 35llvm::json::Value36OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) const {37  return FormatManager::GetFormatAsCString(m_current_value);38}39 40Status OptionValueFormat::SetValueFromString(llvm::StringRef value,41                                             VarSetOperationType op) {42  Status error;43  switch (op) {44  case eVarSetOperationClear:45    Clear();46    NotifyValueChanged();47    break;48 49  case eVarSetOperationReplace:50  case eVarSetOperationAssign: {51    Format new_format;52    error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);53    if (error.Success()) {54      m_value_was_set = true;55      m_current_value = new_format;56      NotifyValueChanged();57    }58  } break;59 60  case eVarSetOperationInsertBefore:61  case eVarSetOperationInsertAfter:62  case eVarSetOperationRemove:63  case eVarSetOperationAppend:64  case eVarSetOperationInvalid:65    error = OptionValue::SetValueFromString(value, op);66    break;67  }68  return error;69}70