1*80814287SRaphael Isemann //===-- OptionGroupBoolean.cpp --------------------------------------------===//
2effe5c95SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6effe5c95SGreg Clayton //
7effe5c95SGreg Clayton //===----------------------------------------------------------------------===//
8effe5c95SGreg Clayton
94bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupBoolean.h"
10effe5c95SGreg Clayton
113eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h"
12effe5c95SGreg Clayton
13effe5c95SGreg Clayton using namespace lldb;
14effe5c95SGreg Clayton using namespace lldb_private;
15effe5c95SGreg Clayton
OptionGroupBoolean(uint32_t usage_mask,bool required,const char * long_option,int short_option,const char * usage_text,bool default_value,bool no_argument_toggle_default)16b9c1b51eSKate Stone OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
17effe5c95SGreg Clayton const char *long_option,
18b9c1b51eSKate Stone int short_option, const char *usage_text,
19b5f0feabSGreg Clayton bool default_value,
20b9c1b51eSKate Stone bool no_argument_toggle_default)
21b9c1b51eSKate Stone : m_value(default_value, default_value) {
22effe5c95SGreg Clayton m_option_definition.usage_mask = usage_mask;
23effe5c95SGreg Clayton m_option_definition.required = required;
24effe5c95SGreg Clayton m_option_definition.long_option = long_option;
25effe5c95SGreg Clayton m_option_definition.short_option = short_option;
26df734cddSZachary Turner m_option_definition.validator = nullptr;
27b9c1b51eSKate Stone m_option_definition.option_has_arg = no_argument_toggle_default
28b9c1b51eSKate Stone ? OptionParser::eNoArgument
29b9c1b51eSKate Stone : OptionParser::eRequiredArgument;
308fe53c49STatyana Krasnukha m_option_definition.enum_values = {};
31b5f0feabSGreg Clayton m_option_definition.completion_type = 0;
32b5f0feabSGreg Clayton m_option_definition.argument_type = eArgTypeBoolean;
33effe5c95SGreg Clayton m_option_definition.usage_text = usage_text;
34effe5c95SGreg Clayton }
35effe5c95SGreg Clayton
SetOptionValue(uint32_t option_idx,llvm::StringRef option_value,ExecutionContext * execution_context)3697206d57SZachary Turner Status OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
378cef4b0bSZachary Turner llvm::StringRef option_value,
38b9c1b51eSKate Stone ExecutionContext *execution_context) {
3997206d57SZachary Turner Status error;
40b9c1b51eSKate Stone if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
4105097246SAdrian Prantl // Not argument, toggle the default value and mark the option as having
4205097246SAdrian Prantl // been set
43b5f0feabSGreg Clayton m_value.SetCurrentValue(!m_value.GetDefaultValue());
44b5f0feabSGreg Clayton m_value.SetOptionWasSet();
45b9c1b51eSKate Stone } else {
468cef4b0bSZachary Turner error = m_value.SetValueFromString(option_value);
47b5f0feabSGreg Clayton }
48effe5c95SGreg Clayton return error;
49effe5c95SGreg Clayton }
50effe5c95SGreg Clayton
OptionParsingStarting(ExecutionContext * execution_context)51b9c1b51eSKate Stone void OptionGroupBoolean::OptionParsingStarting(
52b9c1b51eSKate Stone ExecutionContext *execution_context) {
53effe5c95SGreg Clayton m_value.Clear();
54effe5c95SGreg Clayton }
55