blob: 97cdf10b7c75b02248e51d1169d1054bfb1d68f7 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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
16#include "lldb/Core/Stream.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000017#include "lldb/Host/StringConvert.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000018
19using namespace lldb;
20using namespace lldb_private;
21
22void
23OptionValueSInt64::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
24{
Daniel Malead01b2952012-11-29 21:49:15 +000025 //printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" PRIi64 "\n", this, exe_ctx, m_current_value);
Greg Clayton67cc0632012-08-22 17:17:09 +000026 if (dump_mask & eDumpOptionType)
27 strm.Printf ("(%s)", GetTypeAsCString ());
28// if (dump_mask & eDumpOptionName)
29// DumpQualifiedName (strm);
30 if (dump_mask & eDumpOptionValue)
31 {
32 if (dump_mask & eDumpOptionType)
33 strm.PutCString (" = ");
Daniel Malead01b2952012-11-29 21:49:15 +000034 strm.Printf ("%" PRIi64, m_current_value);
Greg Clayton67cc0632012-08-22 17:17:09 +000035 }
36}
37
38Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000039OptionValueSInt64::SetValueFromString (llvm::StringRef value_ref, VarSetOperationType op)
Greg Clayton67cc0632012-08-22 17:17:09 +000040{
Greg Clayton67cc0632012-08-22 17:17:09 +000041 Error error;
42 switch (op)
43 {
44 case eVarSetOperationClear:
45 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000046 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000047 break;
48
49 case eVarSetOperationReplace:
50 case eVarSetOperationAssign:
51 {
52 bool success = false;
Pavel Labathc95f7e22015-02-20 11:14:59 +000053 std::string value_str = value_ref.trim().str();
Pavel Labathdf50f942015-02-16 13:13:39 +000054 int64_t value = StringConvert::ToSInt64 (value_str.c_str(), 0, 0, &success);
Greg Clayton67cc0632012-08-22 17:17:09 +000055 if (success)
56 {
57 if (value >= m_min_value && value <= m_max_value)
58 {
59 m_value_was_set = true;
60 m_current_value = value;
Greg Clayton332e8b12015-01-13 21:13:08 +000061 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000062 }
63 else
Daniel Malead01b2952012-11-29 21:49:15 +000064 error.SetErrorStringWithFormat ("%" PRIi64 " is out of range, valid values must be between %" PRIi64 " and %" PRIi64 ".",
Greg Clayton67cc0632012-08-22 17:17:09 +000065 value,
66 m_min_value,
67 m_max_value);
68 }
69 else
70 {
Pavel Labathc95f7e22015-02-20 11:14:59 +000071 error.SetErrorStringWithFormat ("invalid int64_t string value: '%s'",
72 value_ref.str().c_str());
Greg Clayton67cc0632012-08-22 17:17:09 +000073 }
74 }
75 break;
76
77 case eVarSetOperationInsertBefore:
78 case eVarSetOperationInsertAfter:
79 case eVarSetOperationRemove:
80 case eVarSetOperationAppend:
81 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +000082 error = OptionValue::SetValueFromString (value_ref, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000083 break;
84 }
85 return error;
86}
87
88lldb::OptionValueSP
89OptionValueSInt64::DeepCopy () const
90{
91 return OptionValueSP(new OptionValueSInt64(*this));
92}