blob: 10b97463842d20a638f7fd80ed676d1fbf8be80a [file] [log] [blame]
Greg Claytoneffe5c92011-05-03 22:09:39 +00001//===-- OptionGroupBoolean.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
Johnny Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17using namespace lldb;
18using namespace lldb_private;
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
21 const char *long_option,
22 int short_option, const char *usage_text,
23 bool default_value,
24 bool no_argument_toggle_default)
25 : m_value(default_value, default_value) {
26 m_option_definition.usage_mask = usage_mask;
27 m_option_definition.required = required;
28 m_option_definition.long_option = long_option;
29 m_option_definition.short_option = short_option;
30 m_option_definition.validator = nullptr;
31 m_option_definition.option_has_arg = no_argument_toggle_default
32 ? OptionParser::eNoArgument
33 : OptionParser::eRequiredArgument;
34 m_option_definition.enum_values = nullptr;
35 m_option_definition.completion_type = 0;
36 m_option_definition.argument_type = eArgTypeBoolean;
37 m_option_definition.usage_text = usage_text;
Greg Claytoneffe5c92011-05-03 22:09:39 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040OptionGroupBoolean::~OptionGroupBoolean() {}
41
42Error OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
Zachary Turner8cef4b02016-09-23 17:48:13 +000043 llvm::StringRef option_value,
Kate Stoneb9c1b512016-09-06 20:57:50 +000044 ExecutionContext *execution_context) {
45 Error error;
46 if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
47 // Not argument, toggle the default value and mark the option as having been
48 // set
49 m_value.SetCurrentValue(!m_value.GetDefaultValue());
50 m_value.SetOptionWasSet();
51 } else {
Zachary Turner8cef4b02016-09-23 17:48:13 +000052 error = m_value.SetValueFromString(option_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 }
54 return error;
Greg Claytoneffe5c92011-05-03 22:09:39 +000055}
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057void OptionGroupBoolean::OptionParsingStarting(
58 ExecutionContext *execution_context) {
59 m_value.Clear();
Greg Claytoneffe5c92011-05-03 22:09:39 +000060}