1 //===-- OptionValueFormatEntity.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/OptionValueFormatEntity.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Module.h" 17 #include "lldb/Core/Stream.h" 18 #include "lldb/Core/StringList.h" 19 #include "lldb/Interpreter/CommandInterpreter.h" 20 using namespace lldb; 21 using namespace lldb_private; 22 23 24 OptionValueFormatEntity::OptionValueFormatEntity (const char *default_format) : 25 OptionValue(), 26 m_current_format (), 27 m_default_format (), 28 m_current_entry (), 29 m_default_entry () 30 { 31 if (default_format && default_format[0]) 32 { 33 llvm::StringRef default_format_str(default_format); 34 Error error = FormatEntity::Parse(default_format_str, m_default_entry); 35 if (error.Success()) 36 { 37 m_default_format = default_format; 38 m_current_format = default_format; 39 m_current_entry = m_default_entry; 40 } 41 } 42 } 43 44 bool 45 OptionValueFormatEntity::Clear () 46 { 47 m_current_entry = m_default_entry; 48 m_current_format = m_default_format; 49 m_value_was_set = false; 50 return true; 51 } 52 53 54 void 55 OptionValueFormatEntity::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 56 { 57 if (dump_mask & eDumpOptionType) 58 strm.Printf ("(%s)", GetTypeAsCString ()); 59 if (dump_mask & eDumpOptionValue) 60 { 61 if (dump_mask & eDumpOptionType) 62 strm.PutCString (" = \""); 63 strm << m_current_format.c_str() << '"'; 64 } 65 } 66 67 Error 68 OptionValueFormatEntity::SetValueFromString (llvm::StringRef value_str, 69 VarSetOperationType op) 70 { 71 Error error; 72 switch (op) 73 { 74 case eVarSetOperationClear: 75 Clear(); 76 NotifyValueChanged(); 77 break; 78 79 case eVarSetOperationReplace: 80 case eVarSetOperationAssign: 81 { 82 FormatEntity::Entry entry; 83 error = FormatEntity::Parse(value_str, entry); 84 if (error.Success()) 85 { 86 m_current_entry = std::move(entry); 87 m_current_format = value_str; 88 m_value_was_set = true; 89 NotifyValueChanged(); 90 } 91 } 92 break; 93 94 case eVarSetOperationInsertBefore: 95 case eVarSetOperationInsertAfter: 96 case eVarSetOperationRemove: 97 case eVarSetOperationAppend: 98 case eVarSetOperationInvalid: 99 error = OptionValue::SetValueFromString (value_str, op); 100 break; 101 } 102 return error; 103 } 104 105 lldb::OptionValueSP 106 OptionValueFormatEntity::DeepCopy () const 107 { 108 return OptionValueSP(new OptionValueFormatEntity(*this)); 109 } 110 111 size_t 112 OptionValueFormatEntity::AutoComplete (CommandInterpreter &interpreter, 113 const char *s, 114 int match_start_point, 115 int max_return_elements, 116 bool &word_complete, 117 StringList &matches) 118 { 119 return FormatEntity::AutoComplete (s, match_start_point, max_return_elements, word_complete, matches); 120 } 121 122