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