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 #include "lldb/Host/StringConvert.h"
14 #include "lldb/Utility/Stream.h"
15
16 using namespace lldb;
17 using namespace lldb_private;
18
Create(llvm::StringRef value_str,Status & error)19 lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str,
20 Status &error) {
21 lldb::OptionValueSP value_sp(new OptionValueUInt64());
22 error = value_sp->SetValueFromString(value_str);
23 if (error.Fail())
24 value_sp.reset();
25 return value_sp;
26 }
27
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)28 void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
29 uint32_t dump_mask) {
30 if (dump_mask & eDumpOptionType)
31 strm.Printf("(%s)", GetTypeAsCString());
32 if (dump_mask & eDumpOptionValue) {
33 if (dump_mask & eDumpOptionType)
34 strm.PutCString(" = ");
35 strm.Printf("%" PRIu64, m_current_value);
36 }
37 }
38
SetValueFromString(llvm::StringRef value_ref,VarSetOperationType op)39 Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
40 VarSetOperationType op) {
41 Status error;
42 switch (op) {
43 case eVarSetOperationClear:
44 Clear();
45 NotifyValueChanged();
46 break;
47
48 case eVarSetOperationReplace:
49 case eVarSetOperationAssign: {
50 bool success = false;
51 std::string value_str = value_ref.trim().str();
52 uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
53 if (success) {
54 m_value_was_set = true;
55 m_current_value = value;
56 NotifyValueChanged();
57 } else {
58 error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
59 value_str.c_str());
60 }
61 } break;
62
63 case eVarSetOperationInsertBefore:
64 case eVarSetOperationInsertAfter:
65 case eVarSetOperationRemove:
66 case eVarSetOperationAppend:
67 case eVarSetOperationInvalid:
68 error = OptionValue::SetValueFromString(value_ref, op);
69 break;
70 }
71 return error;
72 }
73
DeepCopy() const74 lldb::OptionValueSP OptionValueUInt64::DeepCopy() const {
75 return OptionValueSP(new OptionValueUInt64(*this));
76 }
77