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 |
| 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required, |
| 21 | const char *long_option, |
| 22 | int short_option, const char *usage_text, |
| 23 | bool default_value, |
| 24 | bool no_argument_toggle_default) |
| 25 | : m_value(default_value, default_value) { |
| 26 | m_option_definition.usage_mask = usage_mask; |
| 27 | m_option_definition.required = required; |
| 28 | m_option_definition.long_option = long_option; |
| 29 | m_option_definition.short_option = short_option; |
| 30 | m_option_definition.validator = nullptr; |
| 31 | m_option_definition.option_has_arg = no_argument_toggle_default |
| 32 | ? OptionParser::eNoArgument |
| 33 | : OptionParser::eRequiredArgument; |
| 34 | m_option_definition.enum_values = nullptr; |
| 35 | m_option_definition.completion_type = 0; |
| 36 | m_option_definition.argument_type = eArgTypeBoolean; |
| 37 | m_option_definition.usage_text = usage_text; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | OptionGroupBoolean::~OptionGroupBoolean() {} |
| 41 | |
| 42 | Error OptionGroupBoolean::SetOptionValue(uint32_t option_idx, |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 43 | llvm::StringRef option_value, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | ExecutionContext *execution_context) { |
| 45 | Error error; |
| 46 | if (m_option_definition.option_has_arg == OptionParser::eNoArgument) { |
| 47 | // Not argument, toggle the default value and mark the option as having been |
| 48 | // set |
| 49 | m_value.SetCurrentValue(!m_value.GetDefaultValue()); |
| 50 | m_value.SetOptionWasSet(); |
| 51 | } else { |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 52 | error = m_value.SetValueFromString(option_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | } |
| 54 | return error; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | void OptionGroupBoolean::OptionParsingStarting( |
| 58 | ExecutionContext *execution_context) { |
| 59 | m_value.Clear(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 60 | } |