• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- OptionValueUInt64.cpp ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Interpreter/OptionValueUInt64.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Core/Stream.h"
17 #include "lldb/Interpreter/Args.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 lldb::OptionValueSP
Create(const char * value_cstr,Error & error)23 OptionValueUInt64::Create (const char *value_cstr, Error &error)
24 {
25     lldb::OptionValueSP value_sp (new OptionValueUInt64());
26     error = value_sp->SetValueFromCString (value_cstr);
27     if (error.Fail())
28         value_sp.reset();
29     return value_sp;
30 }
31 
32 
33 void
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)34 OptionValueUInt64::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
35 {
36     if (dump_mask & eDumpOptionType)
37         strm.Printf ("(%s)", GetTypeAsCString ());
38     if (dump_mask & eDumpOptionValue)
39     {
40         if (dump_mask & eDumpOptionType)
41             strm.PutCString (" = ");
42         strm.Printf ("%" PRIu64, m_current_value);
43     }
44 }
45 
46 Error
SetValueFromCString(const char * value_cstr,VarSetOperationType op)47 OptionValueUInt64::SetValueFromCString (const char *value_cstr, VarSetOperationType op)
48 {
49     Error error;
50     switch (op)
51     {
52         case eVarSetOperationClear:
53             Clear ();
54             break;
55 
56         case eVarSetOperationReplace:
57         case eVarSetOperationAssign:
58         {
59             bool success = false;
60             uint64_t value = Args::StringToUInt64 (value_cstr, 0, 0, &success);
61             if (success)
62             {
63                 m_value_was_set = true;
64                 m_current_value = value;
65             }
66             else
67             {
68                 error.SetErrorStringWithFormat ("invalid uint64_t string value: '%s'", value_cstr);
69             }
70         }
71             break;
72 
73         case eVarSetOperationInsertBefore:
74         case eVarSetOperationInsertAfter:
75         case eVarSetOperationRemove:
76         case eVarSetOperationAppend:
77         case eVarSetOperationInvalid:
78             error = OptionValue::SetValueFromCString (value_cstr, op);
79             break;
80     }
81     return error;
82 }
83 
84 lldb::OptionValueSP
DeepCopy() const85 OptionValueUInt64::DeepCopy () const
86 {
87     return OptionValueSP(new OptionValueUInt64(*this));
88 }
89 
90