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