1 //===-- OptionValueUInt64.cpp ------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include "lldb/Interpreter/OptionValueUInt64.h"
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Host/StringConvert.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
23 lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str,
24                                               Error &error) {
25   lldb::OptionValueSP value_sp(new OptionValueUInt64());
26   error = value_sp->SetValueFromString(value_str);
27   if (error.Fail())
28     value_sp.reset();
29   return value_sp;
30 }
31 
32 void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
33                                   uint32_t dump_mask) {
34   if (dump_mask & eDumpOptionType)
35     strm.Printf("(%s)", GetTypeAsCString());
36   if (dump_mask & eDumpOptionValue) {
37     if (dump_mask & eDumpOptionType)
38       strm.PutCString(" = ");
39     strm.Printf("%" PRIu64, m_current_value);
40   }
41 }
42 
43 Error OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
44                                             VarSetOperationType op) {
45   Error error;
46   switch (op) {
47   case eVarSetOperationClear:
48     Clear();
49     NotifyValueChanged();
50     break;
51 
52   case eVarSetOperationReplace:
53   case eVarSetOperationAssign: {
54     bool success = false;
55     std::string value_str = value_ref.trim().str();
56     uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
57     if (success) {
58       m_value_was_set = true;
59       m_current_value = value;
60       NotifyValueChanged();
61     } else {
62       error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
63                                      value_str.c_str());
64     }
65   } break;
66 
67   case eVarSetOperationInsertBefore:
68   case eVarSetOperationInsertAfter:
69   case eVarSetOperationRemove:
70   case eVarSetOperationAppend:
71   case eVarSetOperationInvalid:
72     error = OptionValue::SetValueFromString(value_ref, op);
73     break;
74   }
75   return error;
76 }
77 
78 lldb::OptionValueSP OptionValueUInt64::DeepCopy() const {
79   return OptionValueSP(new OptionValueUInt64(*this));
80 }
81