| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1 | //===-- 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 Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 16 | #include "lldb/Host/OptionParser.h" |
| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | OptionGroupBoolean::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 Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 35 | m_option_definition.enum_values = {}; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | m_option_definition.completion_type = 0; |
| 37 | m_option_definition.argument_type = eArgTypeBoolean; |
| 38 | m_option_definition.usage_text = usage_text; |
| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | OptionGroupBoolean::~OptionGroupBoolean() {} |
| 42 | |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 43 | Status OptionGroupBoolean::SetOptionValue(uint32_t option_idx, |
| 44 | llvm::StringRef option_value, |
| 45 | ExecutionContext *execution_context) { |
| 46 | Status error; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | if (m_option_definition.option_has_arg == OptionParser::eNoArgument) { |
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 48 | // Not argument, toggle the default value and mark the option as having |
| 49 | // been set |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | m_value.SetCurrentValue(!m_value.GetDefaultValue()); |
| 51 | m_value.SetOptionWasSet(); |
| 52 | } else { |
| Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 53 | error = m_value.SetValueFromString(option_value); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | } |
| 55 | return error; |
| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | void OptionGroupBoolean::OptionParsingStarting( |
| 59 | ExecutionContext *execution_context) { |
| 60 | m_value.Clear(); |
| Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 61 | } |