]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValueSInt64.cpp
MFV: r329021
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionValueSInt64.cpp
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
16 #include "lldb/Host/StringConvert.h"
17 #include "lldb/Utility/Stream.h"
18
19 using namespace lldb;
20 using namespace lldb_private;
21
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) {
31     if (dump_mask & eDumpOptionType)
32       strm.PutCString(" = ");
33     strm.Printf("%" PRIi64, m_current_value);
34   }
35 }
36
37 Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,
38                                              VarSetOperationType op) {
39   Status 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());
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 OptionValueSInt64::DeepCopy() const {
79   return OptionValueSP(new OptionValueSInt64(*this));
80 }