]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValueChar.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionValueChar.cpp
1 //===-- OptionValueChar.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/OptionValueChar.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Interpreter/OptionArgParser.h"
17 #include "lldb/Utility/Stream.h"
18 #include "lldb/Utility/StringList.h"
19 #include "llvm/ADT/STLExtras.h"
20
21 using namespace lldb;
22 using namespace lldb_private;
23
24 void OptionValueChar::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
25                                 uint32_t dump_mask) {
26   if (dump_mask & eDumpOptionType)
27     strm.Printf("(%s)", GetTypeAsCString());
28
29   if (dump_mask & eDumpOptionValue) {
30     if (dump_mask & eDumpOptionType)
31       strm.PutCString(" = ");
32     if (m_current_value != '\0')
33       strm.PutChar(m_current_value);
34     else
35       strm.PutCString("(null)");
36   }
37 }
38
39 Status OptionValueChar::SetValueFromString(llvm::StringRef value,
40                                            VarSetOperationType op) {
41   Status error;
42   switch (op) {
43   case eVarSetOperationClear:
44     Clear();
45     break;
46
47   case eVarSetOperationReplace:
48   case eVarSetOperationAssign: {
49     bool success = false;
50     char char_value = OptionArgParser::ToChar(value, '\0', &success);
51     if (success) {
52       m_current_value = char_value;
53       m_value_was_set = true;
54     } else
55       error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character",
56                                      value.str().c_str());
57   } break;
58
59   default:
60     error = OptionValue::SetValueFromString(value, op);
61     break;
62   }
63   return error;
64 }
65
66 lldb::OptionValueSP OptionValueChar::DeepCopy() const {
67   return OptionValueSP(new OptionValueChar(*this));
68 }