Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 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::SetValueFromCString (const char *value_cstr, |
| 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 | llvm::StringRef value_str(value_cstr); |
| 86 | error = FormatEntity::Parse(value_str, entry); |
| 87 | if (error.Success()) |
| 88 | { |
| 89 | m_current_entry = std::move(entry); |
| 90 | m_current_format = value_cstr; |
| 91 | m_value_was_set = true; |
| 92 | NotifyValueChanged(); |
| 93 | } |
| 94 | } |
| 95 | break; |
| 96 | |
| 97 | case eVarSetOperationInsertBefore: |
| 98 | case eVarSetOperationInsertAfter: |
| 99 | case eVarSetOperationRemove: |
| 100 | case eVarSetOperationAppend: |
| 101 | case eVarSetOperationInvalid: |
| 102 | error = OptionValue::SetValueFromCString (value_cstr, op); |
| 103 | break; |
| 104 | } |
| 105 | return error; |
| 106 | } |
| 107 | |
| 108 | lldb::OptionValueSP |
| 109 | OptionValueFormatEntity::DeepCopy () const |
| 110 | { |
| 111 | return OptionValueSP(new OptionValueFormatEntity(*this)); |
| 112 | } |
| 113 | |
| 114 | size_t |
| 115 | OptionValueFormatEntity::AutoComplete (CommandInterpreter &interpreter, |
| 116 | const char *s, |
| 117 | int match_start_point, |
| 118 | int max_return_elements, |
| 119 | bool &word_complete, |
| 120 | StringList &matches) |
| 121 | { |
| 122 | return FormatEntity::AutoComplete (s, match_start_point, max_return_elements, word_complete, matches); |
| 123 | } |
| 124 | |