]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValueBoolean.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionValueBoolean.cpp
1 //===-- OptionValueBoolean.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/OptionValueBoolean.h"
11
12 #include "lldb/Host/PosixApi.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/Utility/Stream.h"
15 #include "lldb/Utility/StringList.h"
16 #include "llvm/ADT/STLExtras.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 void OptionValueBoolean::DumpValue(const ExecutionContext *exe_ctx,
22                                    Stream &strm, uint32_t dump_mask) {
23   if (dump_mask & eDumpOptionType)
24     strm.Printf("(%s)", GetTypeAsCString());
25   //    if (dump_mask & eDumpOptionName)
26   //        DumpQualifiedName (strm);
27   if (dump_mask & eDumpOptionValue) {
28     if (dump_mask & eDumpOptionType)
29       strm.PutCString(" = ");
30     strm.PutCString(m_current_value ? "true" : "false");
31   }
32 }
33
34 Status OptionValueBoolean::SetValueFromString(llvm::StringRef value_str,
35                                               VarSetOperationType op) {
36   Status error;
37   switch (op) {
38   case eVarSetOperationClear:
39     Clear();
40     NotifyValueChanged();
41     break;
42
43   case eVarSetOperationReplace:
44   case eVarSetOperationAssign: {
45     bool success = false;
46     bool value = OptionArgParser::ToBoolean(value_str, false, &success);
47     if (success) {
48       m_value_was_set = true;
49       m_current_value = value;
50       NotifyValueChanged();
51     } else {
52       if (value_str.size() == 0)
53         error.SetErrorString("invalid boolean string value <empty>");
54       else
55         error.SetErrorStringWithFormat("invalid boolean string value: '%s'",
56                                        value_str.str().c_str());
57     }
58   } break;
59
60   case eVarSetOperationInsertBefore:
61   case eVarSetOperationInsertAfter:
62   case eVarSetOperationRemove:
63   case eVarSetOperationAppend:
64   case eVarSetOperationInvalid:
65     error = OptionValue::SetValueFromString(value_str, op);
66     break;
67   }
68   return error;
69 }
70
71 lldb::OptionValueSP OptionValueBoolean::DeepCopy() const {
72   return OptionValueSP(new OptionValueBoolean(*this));
73 }
74
75 size_t OptionValueBoolean::AutoComplete(CommandInterpreter &interpreter,
76                                         CompletionRequest &request) {
77   request.SetWordComplete(false);
78   static const llvm::StringRef g_autocomplete_entries[] = {
79       "true", "false", "on", "off", "yes", "no", "1", "0"};
80
81   auto entries = llvm::makeArrayRef(g_autocomplete_entries);
82
83   // only suggest "true" or "false" by default
84   if (request.GetCursorArgumentPrefix().empty())
85     entries = entries.take_front(2);
86
87   for (auto entry : entries) {
88     if (entry.startswith_lower(request.GetCursorArgumentPrefix()))
89       request.AddCompletion(entry);
90   }
91   return request.GetNumberOfMatches();
92 }