180814287SRaphael Isemann //===-- OptionValueSInt64.cpp ---------------------------------------------===//
267cc0636SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
667cc0636SGreg Clayton //
767cc0636SGreg Clayton //===----------------------------------------------------------------------===//
867cc0636SGreg Clayton 
967cc0636SGreg Clayton #include "lldb/Interpreter/OptionValueSInt64.h"
1067cc0636SGreg Clayton 
11bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
1267cc0636SGreg Clayton 
1367cc0636SGreg Clayton using namespace lldb;
1467cc0636SGreg Clayton using namespace lldb_private;
1567cc0636SGreg Clayton 
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)16b9c1b51eSKate Stone void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
17b9c1b51eSKate Stone                                   uint32_t dump_mask) {
1805097246SAdrian Prantl   // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %"
1905097246SAdrian Prantl   // PRIi64
20b9c1b51eSKate Stone   // "\n", this, exe_ctx, m_current_value);
2167cc0636SGreg Clayton   if (dump_mask & eDumpOptionType)
2267cc0636SGreg Clayton     strm.Printf("(%s)", GetTypeAsCString());
2367cc0636SGreg Clayton   //    if (dump_mask & eDumpOptionName)
2467cc0636SGreg Clayton   //        DumpQualifiedName (strm);
25b9c1b51eSKate Stone   if (dump_mask & eDumpOptionValue) {
2667cc0636SGreg Clayton     if (dump_mask & eDumpOptionType)
2767cc0636SGreg Clayton       strm.PutCString(" = ");
28d01b2953SDaniel Malea     strm.Printf("%" PRIi64, m_current_value);
2967cc0636SGreg Clayton   }
3067cc0636SGreg Clayton }
3167cc0636SGreg Clayton 
SetValueFromString(llvm::StringRef value_ref,VarSetOperationType op)3297206d57SZachary Turner Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,
33b9c1b51eSKate Stone                                              VarSetOperationType op) {
3497206d57SZachary Turner   Status error;
35b9c1b51eSKate Stone   switch (op) {
3667cc0636SGreg Clayton   case eVarSetOperationClear:
3767cc0636SGreg Clayton     Clear();
38332e8b1cSGreg Clayton     NotifyValueChanged();
3967cc0636SGreg Clayton     break;
4067cc0636SGreg Clayton 
4167cc0636SGreg Clayton   case eVarSetOperationReplace:
42b9c1b51eSKate Stone   case eVarSetOperationAssign: {
43*3a6ba367SMichał Górny     llvm::StringRef value_trimmed = value_ref.trim();
44*3a6ba367SMichał Górny     int64_t value;
45*3a6ba367SMichał Górny     if (llvm::to_integer(value_trimmed, value)) {
46b9c1b51eSKate Stone       if (value >= m_min_value && value <= m_max_value) {
4767cc0636SGreg Clayton         m_value_was_set = true;
4867cc0636SGreg Clayton         m_current_value = value;
49332e8b1cSGreg Clayton         NotifyValueChanged();
50b9c1b51eSKate Stone       } else
51b9c1b51eSKate Stone         error.SetErrorStringWithFormat(
52b9c1b51eSKate Stone             "%" PRIi64 " is out of range, valid values must be between %" PRIi64
53b9c1b51eSKate Stone             " and %" PRIi64 ".",
54b9c1b51eSKate Stone             value, m_min_value, m_max_value);
55b9c1b51eSKate Stone     } else {
56c95f7e2aSPavel Labath       error.SetErrorStringWithFormat("invalid int64_t string value: '%s'",
57c95f7e2aSPavel Labath                                      value_ref.str().c_str());
5867cc0636SGreg Clayton     }
59b9c1b51eSKate Stone   } break;
6067cc0636SGreg Clayton 
6167cc0636SGreg Clayton   case eVarSetOperationInsertBefore:
6267cc0636SGreg Clayton   case eVarSetOperationInsertAfter:
6367cc0636SGreg Clayton   case eVarSetOperationRemove:
6467cc0636SGreg Clayton   case eVarSetOperationAppend:
6567cc0636SGreg Clayton   case eVarSetOperationInvalid:
66c95f7e2aSPavel Labath     error = OptionValue::SetValueFromString(value_ref, op);
6767cc0636SGreg Clayton     break;
6867cc0636SGreg Clayton   }
6967cc0636SGreg Clayton   return error;
7067cc0636SGreg Clayton }
71