]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValueFormat.cpp
Merge clang 7.0.1 and several follow-up changes
[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 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/DataFormatters/FormatManager.h"
17 #include "lldb/Interpreter/OptionArgParser.h"
18 #include "lldb/Utility/Stream.h"
19
20 using namespace lldb;
21 using namespace lldb_private;
22
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) {
28     if (dump_mask & eDumpOptionType)
29       strm.PutCString(" = ");
30     strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
31   }
32 }
33
34 Status OptionValueFormat::SetValueFromString(llvm::StringRef value,
35                                              VarSetOperationType op) {
36   Status 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 = OptionArgParser::ToFormat(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();
51     }
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;
63 }
64
65 lldb::OptionValueSP OptionValueFormat::DeepCopy() const {
66   return OptionValueSP(new OptionValueFormat(*this));
67 }