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