1254721Semaste//===-- OptionValueSInt64.cpp -----------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/Interpreter/OptionValueSInt64.h"
11254721Semaste
12254721Semaste// C Includes
13254721Semaste// C++ Includes
14254721Semaste// Other libraries and framework includes
15254721Semaste// Project includes
16254721Semaste#include "lldb/Core/Stream.h"
17254721Semaste#include "lldb/Interpreter/Args.h"
18254721Semaste
19254721Semasteusing namespace lldb;
20254721Semasteusing namespace lldb_private;
21254721Semaste
22254721Semastevoid
23254721SemasteOptionValueSInt64::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
24254721Semaste{
25254721Semaste    //printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" PRIi64 "\n", this, exe_ctx, m_current_value);
26254721Semaste    if (dump_mask & eDumpOptionType)
27254721Semaste        strm.Printf ("(%s)", GetTypeAsCString ());
28254721Semaste//    if (dump_mask & eDumpOptionName)
29254721Semaste//        DumpQualifiedName (strm);
30254721Semaste    if (dump_mask & eDumpOptionValue)
31254721Semaste    {
32254721Semaste        if (dump_mask & eDumpOptionType)
33254721Semaste            strm.PutCString (" = ");
34254721Semaste        strm.Printf ("%" PRIi64, m_current_value);
35254721Semaste    }
36254721Semaste}
37254721Semaste
38254721SemasteError
39254721SemasteOptionValueSInt64::SetValueFromCString (const char *value_cstr, VarSetOperationType op)
40254721Semaste{
41254721Semaste    //printf ("%p: SetValueFromCString (s=\"%s\", op=%i)\n", this, value_cstr, op);
42254721Semaste    Error error;
43254721Semaste    switch (op)
44254721Semaste    {
45254721Semaste        case eVarSetOperationClear:
46254721Semaste            Clear();
47254721Semaste            break;
48254721Semaste
49254721Semaste        case eVarSetOperationReplace:
50254721Semaste        case eVarSetOperationAssign:
51254721Semaste            {
52254721Semaste                bool success = false;
53254721Semaste                int64_t value = Args::StringToSInt64 (value_cstr, 0, 0, &success);
54254721Semaste                if (success)
55254721Semaste                {
56254721Semaste                    if (value >= m_min_value && value <= m_max_value)
57254721Semaste                    {
58254721Semaste                        m_value_was_set = true;
59254721Semaste                        m_current_value = value;
60254721Semaste                    }
61254721Semaste                    else
62254721Semaste                        error.SetErrorStringWithFormat ("%" PRIi64 " is out of range, valid values must be between %" PRIi64 " and %" PRIi64 ".",
63254721Semaste                                                        value,
64254721Semaste                                                        m_min_value,
65254721Semaste                                                        m_max_value);
66254721Semaste                }
67254721Semaste                else
68254721Semaste                {
69254721Semaste                    error.SetErrorStringWithFormat ("invalid int64_t string value: '%s'", value_cstr);
70254721Semaste                }
71254721Semaste            }
72254721Semaste            break;
73254721Semaste
74254721Semaste        case eVarSetOperationInsertBefore:
75254721Semaste        case eVarSetOperationInsertAfter:
76254721Semaste        case eVarSetOperationRemove:
77254721Semaste        case eVarSetOperationAppend:
78254721Semaste        case eVarSetOperationInvalid:
79254721Semaste            error = OptionValue::SetValueFromCString (value_cstr, op);
80254721Semaste            break;
81254721Semaste    }
82254721Semaste    return error;
83254721Semaste}
84254721Semaste
85254721Semastelldb::OptionValueSP
86254721SemasteOptionValueSInt64::DeepCopy () const
87254721Semaste{
88254721Semaste    return OptionValueSP(new OptionValueSInt64(*this));
89254721Semaste}
90