]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValueFormat.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionValueFormat.cpp
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
10 #include "lldb/Interpreter/OptionValueFormat.h"
11
12 #include "lldb/DataFormatters/FormatManager.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/Utility/Stream.h"
15
16 using namespace lldb;
17 using namespace lldb_private;
18
19 void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
20                                   uint32_t dump_mask) {
21   if (dump_mask & eDumpOptionType)
22     strm.Printf("(%s)", GetTypeAsCString());
23   if (dump_mask & eDumpOptionValue) {
24     if (dump_mask & eDumpOptionType)
25       strm.PutCString(" = ");
26     strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
27   }
28 }
29
30 Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
31                                              VarSetOperationType op) {
32   Status error;
33   switch (op) {
34   case eVarSetOperationClear:
35     Clear();
36     NotifyValueChanged();
37     break;
38
39   case eVarSetOperationReplace:
40   case eVarSetOperationAssign: {
41     Format new_format;
42     error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
43     if (error.Success()) {
44       m_value_was_set = true;
45       m_current_value = new_format;
46       NotifyValueChanged();
47     }
48   } break;
49
50   case eVarSetOperationInsertBefore:
51   case eVarSetOperationInsertAfter:
52   case eVarSetOperationRemove:
53   case eVarSetOperationAppend:
54   case eVarSetOperationInvalid:
55     error = OptionValue::SetValueFromString(value, op);
56     break;
57   }
58   return error;
59 }
60
61 lldb::OptionValueSP OptionValueFormat::DeepCopy() const {
62   return OptionValueSP(new OptionValueFormat(*this));
63 }