blob: 1d73d58ce8e16b12edee9a9b96c216252d4f3030 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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 Clayton67cc0632012-08-22 17:17:09 +000010#include "lldb/Interpreter/OptionValueFormat.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Greg Clayton67cc0632012-08-22 17:17:09 +000016#include "lldb/Core/Stream.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000017#include "lldb/DataFormatters/FormatManager.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000018#include "lldb/Interpreter/Args.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23void
24OptionValueFormat::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
36Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000037OptionValueFormat::SetValueFromString (llvm::StringRef value, VarSetOperationType op)
Greg Clayton67cc0632012-08-22 17:17:09 +000038{
39 Error error;
40 switch (op)
41 {
42 case eVarSetOperationClear:
43 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000044 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000045 break;
46
47 case eVarSetOperationReplace:
48 case eVarSetOperationAssign:
49 {
50 Format new_format;
Pavel Labathc95f7e22015-02-20 11:14:59 +000051 error = Args::StringToFormat (value.str().c_str(), new_format, nullptr);
Greg Clayton67cc0632012-08-22 17:17:09 +000052 if (error.Success())
53 {
54 m_value_was_set = true;
55 m_current_value = new_format;
Greg Clayton332e8b12015-01-13 21:13:08 +000056 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000057 }
58 }
59 break;
60
61 case eVarSetOperationInsertBefore:
62 case eVarSetOperationInsertAfter:
63 case eVarSetOperationRemove:
64 case eVarSetOperationAppend:
65 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +000066 error = OptionValue::SetValueFromString (value, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000067 break;
68 }
69 return error;
70}
71
72
73lldb::OptionValueSP
74OptionValueFormat::DeepCopy () const
75{
76 return OptionValueSP(new OptionValueFormat(*this));
77}
78