blob: 041d8a500a8774f3f846604b6574c9caa930ac44 [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
Kate Stoneb9c1b512016-09-06 20:57:50 +000023void 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 Clayton67cc0632012-08-22 17:17:09 +000028 if (dump_mask & eDumpOptionType)
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 strm.PutCString(" = ");
30 strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
31 }
32}
33
34Error 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 Clayton67cc0632012-08-22 17:17:09 +000051 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 } 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 Clayton67cc0632012-08-22 17:17:09 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065lldb::OptionValueSP OptionValueFormat::DeepCopy() const {
66 return OptionValueSP(new OptionValueFormat(*this));
Greg Clayton67cc0632012-08-22 17:17:09 +000067}