OptionValueFormat.cpp revision 314564
1//===-- OptionValueFormat.cpp -----------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "lldb/Interpreter/OptionValueFormat.h" 11 12// C Includes 13// C++ Includes 14// Other libraries and framework includes 15// Project includes 16#include "lldb/Core/Stream.h" 17#include "lldb/DataFormatters/FormatManager.h" 18#include "lldb/Interpreter/Args.h" 19 20using namespace lldb; 21using namespace lldb_private; 22 23void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 24 uint32_t dump_mask) { 25 if (dump_mask & eDumpOptionType) 26 strm.Printf("(%s)", GetTypeAsCString()); 27 if (dump_mask & eDumpOptionValue) { 28 if (dump_mask & eDumpOptionType) 29 strm.PutCString(" = "); 30 strm.PutCString(FormatManager::GetFormatAsCString(m_current_value)); 31 } 32} 33 34Error OptionValueFormat::SetValueFromString(llvm::StringRef value, 35 VarSetOperationType op) { 36 Error error; 37 switch (op) { 38 case eVarSetOperationClear: 39 Clear(); 40 NotifyValueChanged(); 41 break; 42 43 case eVarSetOperationReplace: 44 case eVarSetOperationAssign: { 45 Format new_format; 46 error = Args::StringToFormat(value.str().c_str(), new_format, nullptr); 47 if (error.Success()) { 48 m_value_was_set = true; 49 m_current_value = new_format; 50 NotifyValueChanged(); 51 } 52 } break; 53 54 case eVarSetOperationInsertBefore: 55 case eVarSetOperationInsertAfter: 56 case eVarSetOperationRemove: 57 case eVarSetOperationAppend: 58 case eVarSetOperationInvalid: 59 error = OptionValue::SetValueFromString(value, op); 60 break; 61 } 62 return error; 63} 64 65lldb::OptionValueSP OptionValueFormat::DeepCopy() const { 66 return OptionValueSP(new OptionValueFormat(*this)); 67} 68