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/lldb-python.h" 11 12 #include "lldb/Interpreter/OptionValueFormat.h" 13 14 // C Includes 15 // C++ Includes 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/Core/Stream.h" 19 #include "lldb/DataFormatters/FormatManager.h" 20 #include "lldb/Interpreter/Args.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 void 26 OptionValueFormat::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 27 { 28 if (dump_mask & eDumpOptionType) 29 strm.Printf ("(%s)", GetTypeAsCString ()); 30 if (dump_mask & eDumpOptionValue) 31 { 32 if (dump_mask & eDumpOptionType) 33 strm.PutCString (" = "); 34 strm.PutCString (FormatManager::GetFormatAsCString (m_current_value)); 35 } 36 } 37 38 Error 39 OptionValueFormat::SetValueFromString (llvm::StringRef value, VarSetOperationType op) 40 { 41 Error error; 42 switch (op) 43 { 44 case eVarSetOperationClear: 45 Clear(); 46 NotifyValueChanged(); 47 break; 48 49 case eVarSetOperationReplace: 50 case eVarSetOperationAssign: 51 { 52 Format new_format; 53 error = Args::StringToFormat (value.str().c_str(), new_format, nullptr); 54 if (error.Success()) 55 { 56 m_value_was_set = true; 57 m_current_value = new_format; 58 NotifyValueChanged(); 59 } 60 } 61 break; 62 63 case eVarSetOperationInsertBefore: 64 case eVarSetOperationInsertAfter: 65 case eVarSetOperationRemove: 66 case eVarSetOperationAppend: 67 case eVarSetOperationInvalid: 68 error = OptionValue::SetValueFromString (value, op); 69 break; 70 } 71 return error; 72 } 73 74 75 lldb::OptionValueSP 76 OptionValueFormat::DeepCopy () const 77 { 78 return OptionValueSP(new OptionValueFormat(*this)); 79 } 80 81