brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 00f1cc3 Raw
77 lines · cpp
1//===-- OptionValueSInt64.cpp ---------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Interpreter/OptionValueSInt64.h"10 11#include "lldb/Interpreter/OptionValue.h"12#include "lldb/Utility/Stream.h"13 14using namespace lldb;15using namespace lldb_private;16 17void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,18                                  uint32_t dump_mask) {19  // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %"20  // PRIi6421  // "\n", this, exe_ctx, m_current_value);22  if (dump_mask & eDumpOptionType)23    strm.Printf("(%s)", GetTypeAsCString());24  //    if (dump_mask & eDumpOptionName)25  //        DumpQualifiedName (strm);26  if (dump_mask & eDumpOptionValue) {27    if (dump_mask & eDumpOptionType)28      strm.PutCString(" = ");29    strm.Printf("%" PRIi64, m_current_value);30    if (dump_mask & eDumpOptionDefaultValue &&31        m_current_value != m_default_value) {32      DefaultValueFormat label(strm);33      strm.Printf("%" PRIi64, m_default_value);34    }35  }36}37 38Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,39                                             VarSetOperationType op) {40  Status error;41  switch (op) {42  case eVarSetOperationClear:43    Clear();44    NotifyValueChanged();45    break;46 47  case eVarSetOperationReplace:48  case eVarSetOperationAssign: {49    llvm::StringRef value_trimmed = value_ref.trim();50    int64_t value;51    if (llvm::to_integer(value_trimmed, value)) {52      if (value >= m_min_value && value <= m_max_value) {53        m_value_was_set = true;54        m_current_value = value;55        NotifyValueChanged();56      } else57        error = Status::FromErrorStringWithFormat(58            "%" PRIi64 " is out of range, valid values must be between %" PRIi6459            " and %" PRIi64 ".",60            value, m_min_value, m_max_value);61    } else {62      error = Status::FromErrorStringWithFormat(63          "invalid int64_t string value: '%s'", 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