blob: 37c63f65995db8bad460d2c83c20fb3b0fa6c167 [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
Zachary Turner3eb2b442017-03-22 23:33:16 +000016#include "lldb/Host/OptionParser.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000017
18using namespace lldb;
19using namespace lldb_private;
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required,
22 const char *long_option,
23 int short_option, const char *usage_text,
24 bool default_value,
25 bool no_argument_toggle_default)
26 : m_value(default_value, default_value) {
27 m_option_definition.usage_mask = usage_mask;
28 m_option_definition.required = required;
29 m_option_definition.long_option = long_option;
30 m_option_definition.short_option = short_option;
31 m_option_definition.validator = nullptr;
32 m_option_definition.option_has_arg = no_argument_toggle_default
33 ? OptionParser::eNoArgument
34 : OptionParser::eRequiredArgument;
Tatyana Krasnukha8fe53c492018-09-26 18:50:19 +000035 m_option_definition.enum_values = {};
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 m_option_definition.completion_type = 0;
37 m_option_definition.argument_type = eArgTypeBoolean;
38 m_option_definition.usage_text = usage_text;
Greg Claytoneffe5c92011-05-03 22:09:39 +000039}
40
Kate Stoneb9c1b512016-09-06 20:57:50 +000041OptionGroupBoolean::~OptionGroupBoolean() {}
42
Zachary Turner97206d52017-05-12 04:51:55 +000043Status OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
44 llvm::StringRef option_value,
45 ExecutionContext *execution_context) {
46 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 if (m_option_definition.option_has_arg == OptionParser::eNoArgument) {
Adrian Prantl05097242018-04-30 16:49:04 +000048 // Not argument, toggle the default value and mark the option as having
49 // been set
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 m_value.SetCurrentValue(!m_value.GetDefaultValue());
51 m_value.SetOptionWasSet();
52 } else {
Zachary Turner8cef4b02016-09-23 17:48:13 +000053 error = m_value.SetValueFromString(option_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 }
55 return error;
Greg Claytoneffe5c92011-05-03 22:09:39 +000056}
57
Kate Stoneb9c1b512016-09-06 20:57:50 +000058void OptionGroupBoolean::OptionParsingStarting(
59 ExecutionContext *execution_context) {
60 m_value.Clear();
Greg Claytoneffe5c92011-05-03 22:09:39 +000061}