OptionValueSInt64.cpp revision 355940
1101776Stjr//===-- OptionValueSInt64.cpp -----------------------------------*- C++ -*-===//
2129583Stjr//
3101776Stjr// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4101776Stjr// See https://llvm.org/LICENSE.txt for license information.
5227753Stheraven// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6227753Stheraven//
7227753Stheraven//===----------------------------------------------------------------------===//
8227753Stheraven
9227753Stheraven#include "lldb/Interpreter/OptionValueSInt64.h"
10101776Stjr
11101776Stjr#include "lldb/Host/StringConvert.h"
12101776Stjr#include "lldb/Utility/Stream.h"
13101776Stjr
14101776Stjrusing namespace lldb;
15101776Stjrusing namespace lldb_private;
16101776Stjr
17101776Stjrvoid OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
18101776Stjr                                  uint32_t dump_mask) {
19101776Stjr  // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %"
20101776Stjr  // PRIi64
21101776Stjr  // "\n", this, exe_ctx, m_current_value);
22101776Stjr  if (dump_mask & eDumpOptionType)
23101776Stjr    strm.Printf("(%s)", GetTypeAsCString());
24101776Stjr  //    if (dump_mask & eDumpOptionName)
25101776Stjr  //        DumpQualifiedName (strm);
26101776Stjr  if (dump_mask & eDumpOptionValue) {
27101776Stjr    if (dump_mask & eDumpOptionType)
28101776Stjr      strm.PutCString(" = ");
29101776Stjr    strm.Printf("%" PRIi64, m_current_value);
30101776Stjr  }
31101776Stjr}
32101776Stjr
33101776StjrStatus OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,
34101776Stjr                                             VarSetOperationType op) {
35101776Stjr  Status error;
36101776Stjr  switch (op) {
37101776Stjr  case eVarSetOperationClear:
38103523Stjr    Clear();
39101776Stjr    NotifyValueChanged();
40101776Stjr    break;
41101776Stjr
42101776Stjr  case eVarSetOperationReplace:
43132442Stjr  case eVarSetOperationAssign: {
44227753Stheraven    bool success = false;
45101776Stjr    std::string value_str = value_ref.trim().str();
46103676Stjr    int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success);
47103676Stjr    if (success) {
48103676Stjr      if (value >= m_min_value && value <= m_max_value) {
49103676Stjr        m_value_was_set = true;
50227753Stheraven        m_current_value = value;
51103676Stjr        NotifyValueChanged();
52103676Stjr      } else
53227753Stheraven        error.SetErrorStringWithFormat(
54103676Stjr            "%" PRIi64 " is out of range, valid values must be between %" PRIi64
55103676Stjr            " and %" PRIi64 ".",
56103676Stjr            value, m_min_value, m_max_value);
57227753Stheraven    } else {
58103676Stjr      error.SetErrorStringWithFormat("invalid int64_t string value: '%s'",
59103676Stjr                                     value_ref.str().c_str());
60103676Stjr    }
61103676Stjr  } break;
62234799Sdas
63227753Stheraven  case eVarSetOperationInsertBefore:
64227753Stheraven  case eVarSetOperationInsertAfter:
65227753Stheraven  case eVarSetOperationRemove:
66227753Stheraven  case eVarSetOperationAppend:
67227753Stheraven  case eVarSetOperationInvalid:
68103676Stjr    error = OptionValue::SetValueFromString(value_ref, op);
69131880Stjr    break;
70234799Sdas  }
71234799Sdas  return error;
72234799Sdas}
73234799Sdas
74131880Stjrlldb::OptionValueSP OptionValueSInt64::DeepCopy() const {
75234799Sdas  return OptionValueSP(new OptionValueSInt64(*this));
76234799Sdas}
77103539Stjr