1ac7ddfbfSEd Maste //===-- OptionGroupBoolean.cpp ----------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Interpreter/OptionGroupBoolean.h"
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste // C Includes
13ac7ddfbfSEd Maste // C++ Includes
14ac7ddfbfSEd Maste // Other libraries and framework includes
15ac7ddfbfSEd Maste // Project includes
16ac7ddfbfSEd Maste 
17ac7ddfbfSEd Maste using namespace lldb;
18ac7ddfbfSEd Maste using namespace lldb_private;
19ac7ddfbfSEd Maste 
20435933ddSDimitry Andric OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
21ac7ddfbfSEd Maste                                        const char *long_option,
22435933ddSDimitry Andric                                        int short_option, const char *usage_text,
23ac7ddfbfSEd Maste                                        bool default_value,
24435933ddSDimitry Andric                                        bool no_argument_toggle_default)
25435933ddSDimitry Andric     : m_value(default_value, default_value) {
26ac7ddfbfSEd Maste   m_option_definition.usage_mask = usage_mask;
27ac7ddfbfSEd Maste   m_option_definition.required = required;
28ac7ddfbfSEd Maste   m_option_definition.long_option = long_option;
29ac7ddfbfSEd Maste   m_option_definition.short_option = short_option;
300127ef0fSEd Maste   m_option_definition.validator = nullptr;
31435933ddSDimitry Andric   m_option_definition.option_has_arg = no_argument_toggle_default
32435933ddSDimitry Andric                                            ? OptionParser::eNoArgument
33435933ddSDimitry Andric                                            : OptionParser::eRequiredArgument;
340127ef0fSEd Maste   m_option_definition.enum_values = nullptr;
35ac7ddfbfSEd Maste   m_option_definition.completion_type = 0;
36ac7ddfbfSEd Maste   m_option_definition.argument_type = eArgTypeBoolean;
37ac7ddfbfSEd Maste   m_option_definition.usage_text = usage_text;
38ac7ddfbfSEd Maste }
39ac7ddfbfSEd Maste 
40435933ddSDimitry Andric OptionGroupBoolean::~OptionGroupBoolean() {}
41ac7ddfbfSEd Maste 
42435933ddSDimitry Andric Error OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
43435933ddSDimitry Andric                                          llvm::StringRef option_value,
44435933ddSDimitry Andric                                          ExecutionContext *execution_context) {
45ac7ddfbfSEd Maste   Error error;
46435933ddSDimitry Andric   if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
47435933ddSDimitry Andric     // Not argument, toggle the default value and mark the option as having been
48435933ddSDimitry Andric     // set
49ac7ddfbfSEd Maste     m_value.SetCurrentValue(!m_value.GetDefaultValue());
50ac7ddfbfSEd Maste     m_value.SetOptionWasSet();
51435933ddSDimitry Andric   } else {
52435933ddSDimitry Andric     error = m_value.SetValueFromString(option_value);
53ac7ddfbfSEd Maste   }
54ac7ddfbfSEd Maste   return error;
55ac7ddfbfSEd Maste }
56ac7ddfbfSEd Maste 
57435933ddSDimitry Andric void OptionGroupBoolean::OptionParsingStarting(
58435933ddSDimitry Andric     ExecutionContext *execution_context) {
59ac7ddfbfSEd Maste   m_value.Clear();
60ac7ddfbfSEd Maste }
61