Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1 | //===-- OptionValueUInt64.cpp ------------------------------------*- C++ |
| 2 | //-*-===// |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 18 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 23 | lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | Error &error) { |
| 25 | lldb::OptionValueSP value_sp(new OptionValueUInt64()); |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 26 | error = value_sp->SetValueFromString(value_str); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | if (error.Fail()) |
| 28 | value_sp.reset(); |
| 29 | return value_sp; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 37 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 64 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | lldb::OptionValueSP OptionValueUInt64::DeepCopy() const { |
| 79 | return OptionValueSP(new OptionValueUInt64(*this)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 80 | } |