blob: 8a6482c8df25a9662ec230ffc3401b44fa4f7315 [file] [log] [blame]
Greg Claytoneffe5c92011-05-03 22:09:39 +00001//===-- OptionGroupBoolean.cpp ----------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Greg Claytoneffe5c92011-05-03 22:09:39 +00006//
7//===----------------------------------------------------------------------===//
8
Johnny Chen4bee32e2011-05-13 20:21:08 +00009#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000010
Zachary Turner3eb2b442017-03-22 23:33:16 +000011#include "lldb/Host/OptionParser.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000012
13using namespace lldb;
14using namespace lldb_private;
15
Kate Stoneb9c1b512016-09-06 20:57:50 +000016OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
17 const char *long_option,
18 int short_option, const char *usage_text,
19 bool default_value,
20 bool no_argument_toggle_default)
21 : m_value(default_value, default_value) {
22 m_option_definition.usage_mask = usage_mask;
23 m_option_definition.required = required;
24 m_option_definition.long_option = long_option;
25 m_option_definition.short_option = short_option;
26 m_option_definition.validator = nullptr;
27 m_option_definition.option_has_arg = no_argument_toggle_default
28 ? OptionParser::eNoArgument
29 : OptionParser::eRequiredArgument;
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000030 m_option_definition.enum_values = {};
Kate Stoneb9c1b512016-09-06 20:57:50 +000031 m_option_definition.completion_type = 0;
32 m_option_definition.argument_type = eArgTypeBoolean;
33 m_option_definition.usage_text = usage_text;
Greg Claytoneffe5c92011-05-03 22:09:39 +000034}
35
Kate Stoneb9c1b512016-09-06 20:57:50 +000036OptionGroupBoolean::~OptionGroupBoolean() {}
37
Zachary Turner97206d52017-05-12 04:51:55 +000038Status OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
39 llvm::StringRef option_value,
40 ExecutionContext *execution_context) {
41 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
Adrian Prantl05097242018-04-30 16:49:04 +000043 // Not argument, toggle the default value and mark the option as having
44 // been set
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 m_value.SetCurrentValue(!m_value.GetDefaultValue());
46 m_value.SetOptionWasSet();
47 } else {
Zachary Turner8cef4b02016-09-23 17:48:13 +000048 error = m_value.SetValueFromString(option_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 }
50 return error;
Greg Claytoneffe5c92011-05-03 22:09:39 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053void OptionGroupBoolean::OptionParsingStarting(
54 ExecutionContext *execution_context) {
55 m_value.Clear();
Greg Claytoneffe5c92011-05-03 22:09:39 +000056}