Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1 | //===-- OptionValueSInt64.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/OptionValueSInt64.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 16 | #include "lldb/Host/StringConvert.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/Stream.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 23 | uint32_t dump_mask) { |
| 24 | // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" PRIi64 |
| 25 | // "\n", this, exe_ctx, m_current_value); |
| 26 | if (dump_mask & eDumpOptionType) |
| 27 | strm.Printf("(%s)", GetTypeAsCString()); |
| 28 | // if (dump_mask & eDumpOptionName) |
| 29 | // DumpQualifiedName (strm); |
| 30 | if (dump_mask & eDumpOptionValue) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 31 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | strm.PutCString(" = "); |
| 33 | strm.Printf("%" PRIi64, m_current_value); |
| 34 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | Error OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref, |
| 38 | VarSetOperationType op) { |
| 39 | Error error; |
| 40 | switch (op) { |
| 41 | case eVarSetOperationClear: |
| 42 | Clear(); |
| 43 | NotifyValueChanged(); |
| 44 | break; |
| 45 | |
| 46 | case eVarSetOperationReplace: |
| 47 | case eVarSetOperationAssign: { |
| 48 | bool success = false; |
| 49 | std::string value_str = value_ref.trim().str(); |
| 50 | int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success); |
| 51 | if (success) { |
| 52 | if (value >= m_min_value && value <= m_max_value) { |
| 53 | m_value_was_set = true; |
| 54 | m_current_value = value; |
| 55 | NotifyValueChanged(); |
| 56 | } else |
| 57 | error.SetErrorStringWithFormat( |
| 58 | "%" PRIi64 " is out of range, valid values must be between %" PRIi64 |
| 59 | " and %" PRIi64 ".", |
| 60 | value, m_min_value, m_max_value); |
| 61 | } else { |
| 62 | error.SetErrorStringWithFormat("invalid int64_t string value: '%s'", |
| 63 | value_ref.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 OptionValueSInt64::DeepCopy() const { |
| 79 | return OptionValueSP(new OptionValueSInt64(*this)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 80 | } |