brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 63f83cb Raw
82 lines · cpp
1//===-- OptionValueUInt64.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/OptionValueUInt64.h"10 11#include "lldb/Interpreter/OptionValue.h"12#include "lldb/Utility/Stream.h"13 14using namespace lldb;15using namespace lldb_private;16 17lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str,18                                              Status &error) {19  lldb::OptionValueSP value_sp(new OptionValueUInt64());20  error = value_sp->SetValueFromString(value_str);21  if (error.Fail())22    value_sp.reset();23  return value_sp;24}25 26void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,27                                  uint32_t dump_mask) {28  if (dump_mask & eDumpOptionType)29    strm.Printf("(%s)", GetTypeAsCString());30  if (dump_mask & eDumpOptionValue) {31    if (dump_mask & eDumpOptionType)32      strm.PutCString(" = ");33    strm.Printf("%" PRIu64, m_current_value);34    if (dump_mask & eDumpOptionDefaultValue &&35        m_current_value != m_default_value) {36      DefaultValueFormat label(strm);37      strm.Printf("%" PRIu64, m_default_value);38    }39  }40}41 42Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,43                                             VarSetOperationType op) {44  Status error;45  switch (op) {46  case eVarSetOperationClear:47    Clear();48    NotifyValueChanged();49    break;50 51  case eVarSetOperationReplace:52  case eVarSetOperationAssign: {53    llvm::StringRef value_trimmed = value_ref.trim();54    uint64_t value;55    if (llvm::to_integer(value_trimmed, value)) {56      if (value >= m_min_value && value <= m_max_value) {57        m_value_was_set = true;58        m_current_value = value;59        NotifyValueChanged();60      } else {61        error = Status::FromErrorStringWithFormat(62            "%" PRIu64 " is out of range, valid values must be between %" PRIu6463            " and %" PRIu64 ".",64            value, m_min_value, m_max_value);65      }66    } else {67      error = Status::FromErrorStringWithFormat(68          "invalid uint64_t string value: '%s'", value_ref.str().c_str());69    }70  } break;71 72  case eVarSetOperationInsertBefore:73  case eVarSetOperationInsertAfter:74  case eVarSetOperationRemove:75  case eVarSetOperationAppend:76  case eVarSetOperationInvalid:77    error = OptionValue::SetValueFromString(value_ref, op);78    break;79  }80  return error;81}82