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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 24 | uint32_t dump_mask) { |
| 25 | if (dump_mask & eDumpOptionType) |
| 26 | strm.Printf("(%s)", GetTypeAsCString()); |
| 27 | if (dump_mask & eDumpOptionValue) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 28 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | strm.PutCString(" = "); |
| 30 | strm.PutCString(FormatManager::GetFormatAsCString(m_current_value)); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | Error OptionValueFormat::SetValueFromString(llvm::StringRef value, |
| 35 | VarSetOperationType op) { |
| 36 | Error error; |
| 37 | switch (op) { |
| 38 | case eVarSetOperationClear: |
| 39 | Clear(); |
| 40 | NotifyValueChanged(); |
| 41 | break; |
| 42 | |
| 43 | case eVarSetOperationReplace: |
| 44 | case eVarSetOperationAssign: { |
| 45 | Format new_format; |
| 46 | error = Args::StringToFormat(value.str().c_str(), new_format, nullptr); |
| 47 | if (error.Success()) { |
| 48 | m_value_was_set = true; |
| 49 | m_current_value = new_format; |
| 50 | NotifyValueChanged(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 51 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | } break; |
| 53 | |
| 54 | case eVarSetOperationInsertBefore: |
| 55 | case eVarSetOperationInsertAfter: |
| 56 | case eVarSetOperationRemove: |
| 57 | case eVarSetOperationAppend: |
| 58 | case eVarSetOperationInvalid: |
| 59 | error = OptionValue::SetValueFromString(value, op); |
| 60 | break; |
| 61 | } |
| 62 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | lldb::OptionValueSP OptionValueFormat::DeepCopy() const { |
| 66 | return OptionValueSP(new OptionValueFormat(*this)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 67 | } |