[lldb/Interpreter] Make OptionGroupPythonClassWithDict options non-required
When using `OptionGroupPythonClassWithDict` options in an `OptionGroup` with other `Options`, it can happen that the combinaison of some options of each group makes the command invalid. To solve that issue, this patch adds a bitmask argument to the `OptionGroupPythonClassWithDict` constuctor that is used to mark each option as required (or not). If the `required_options` bitmask isn't passed to the constructor, the class will keep its default behaviour, making the `--script-class` and `--python-function` required. rdar://65508855 Differential Revision: https://reviews.llvm.org/D97910 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
This commit is contained in:
parent
1900503595
commit
c16fef19f6
|
@ -1,4 +1,4 @@
|
||||||
//===-- OptionGroupPythonClassWithDict.h -------------------------------------*- C++ -*-===//
|
//===-- OptionGroupPythonClassWithDict.h ------------------------*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
// See https://llvm.org/LICENSE.txt for license information.
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
@ -9,9 +9,10 @@
|
||||||
#ifndef LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
|
#ifndef LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
|
||||||
#define LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
|
#define LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
|
||||||
|
|
||||||
#include "lldb/lldb-types.h"
|
|
||||||
#include "lldb/Interpreter/Options.h"
|
#include "lldb/Interpreter/Options.h"
|
||||||
|
#include "lldb/Utility/Flags.h"
|
||||||
#include "lldb/Utility/StructuredData.h"
|
#include "lldb/Utility/StructuredData.h"
|
||||||
|
#include "lldb/lldb-types.h"
|
||||||
|
|
||||||
namespace lldb_private {
|
namespace lldb_private {
|
||||||
|
|
||||||
|
@ -23,12 +24,20 @@ namespace lldb_private {
|
||||||
// StructuredData::Dictionary is constructed with those pairs.
|
// StructuredData::Dictionary is constructed with those pairs.
|
||||||
class OptionGroupPythonClassWithDict : public OptionGroup {
|
class OptionGroupPythonClassWithDict : public OptionGroup {
|
||||||
public:
|
public:
|
||||||
OptionGroupPythonClassWithDict(const char *class_use,
|
enum OptionKind {
|
||||||
bool is_class = true,
|
eScriptClass = 1 << 0,
|
||||||
int class_option = 'C',
|
eDictKey = 1 << 1,
|
||||||
int key_option = 'k',
|
eDictValue = 1 << 2,
|
||||||
int value_option = 'v');
|
ePythonFunction = 1 << 3,
|
||||||
|
eAllOptions = (eScriptClass | eDictKey | eDictValue | ePythonFunction)
|
||||||
|
};
|
||||||
|
|
||||||
|
OptionGroupPythonClassWithDict(const char *class_use, bool is_class = true,
|
||||||
|
int class_option = 'C', int key_option = 'k',
|
||||||
|
int value_option = 'v',
|
||||||
|
uint16_t required_options = eScriptClass |
|
||||||
|
ePythonFunction);
|
||||||
|
|
||||||
~OptionGroupPythonClassWithDict() override = default;
|
~OptionGroupPythonClassWithDict() override = default;
|
||||||
|
|
||||||
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
||||||
|
@ -55,6 +64,7 @@ protected:
|
||||||
std::string m_class_usage_text, m_key_usage_text, m_value_usage_text;
|
std::string m_class_usage_text, m_key_usage_text, m_value_usage_text;
|
||||||
bool m_is_class;
|
bool m_is_class;
|
||||||
OptionDefinition m_option_definition[4];
|
OptionDefinition m_option_definition[4];
|
||||||
|
Flags m_required_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lldb_private
|
} // namespace lldb_private
|
||||||
|
|
|
@ -13,12 +13,10 @@
|
||||||
using namespace lldb;
|
using namespace lldb;
|
||||||
using namespace lldb_private;
|
using namespace lldb_private;
|
||||||
|
|
||||||
OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict(
|
||||||
(const char *class_use,
|
const char *class_use, bool is_class, int class_option, int key_option,
|
||||||
bool is_class,
|
int value_option, uint16_t required_options)
|
||||||
int class_option,
|
: m_is_class(is_class), m_required_options(required_options) {
|
||||||
int key_option,
|
|
||||||
int value_option) : m_is_class(is_class) {
|
|
||||||
m_key_usage_text.assign("The key for a key/value pair passed to the "
|
m_key_usage_text.assign("The key for a key/value pair passed to the "
|
||||||
"implementation of a ");
|
"implementation of a ");
|
||||||
m_key_usage_text.append(class_use);
|
m_key_usage_text.append(class_use);
|
||||||
|
@ -36,7 +34,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
||||||
m_class_usage_text.append(".");
|
m_class_usage_text.append(".");
|
||||||
|
|
||||||
m_option_definition[0].usage_mask = LLDB_OPT_SET_1;
|
m_option_definition[0].usage_mask = LLDB_OPT_SET_1;
|
||||||
m_option_definition[0].required = true;
|
m_option_definition[0].required = m_required_options.Test(eScriptClass);
|
||||||
m_option_definition[0].long_option = "script-class";
|
m_option_definition[0].long_option = "script-class";
|
||||||
m_option_definition[0].short_option = class_option;
|
m_option_definition[0].short_option = class_option;
|
||||||
m_option_definition[0].validator = nullptr;
|
m_option_definition[0].validator = nullptr;
|
||||||
|
@ -47,7 +45,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
||||||
m_option_definition[0].usage_text = m_class_usage_text.data();
|
m_option_definition[0].usage_text = m_class_usage_text.data();
|
||||||
|
|
||||||
m_option_definition[1].usage_mask = LLDB_OPT_SET_2;
|
m_option_definition[1].usage_mask = LLDB_OPT_SET_2;
|
||||||
m_option_definition[1].required = false;
|
m_option_definition[1].required = m_required_options.Test(eDictKey);
|
||||||
m_option_definition[1].long_option = "structured-data-key";
|
m_option_definition[1].long_option = "structured-data-key";
|
||||||
m_option_definition[1].short_option = key_option;
|
m_option_definition[1].short_option = key_option;
|
||||||
m_option_definition[1].validator = nullptr;
|
m_option_definition[1].validator = nullptr;
|
||||||
|
@ -58,7 +56,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
||||||
m_option_definition[1].usage_text = m_key_usage_text.data();
|
m_option_definition[1].usage_text = m_key_usage_text.data();
|
||||||
|
|
||||||
m_option_definition[2].usage_mask = LLDB_OPT_SET_2;
|
m_option_definition[2].usage_mask = LLDB_OPT_SET_2;
|
||||||
m_option_definition[2].required = false;
|
m_option_definition[2].required = m_required_options.Test(eDictValue);
|
||||||
m_option_definition[2].long_option = "structured-data-value";
|
m_option_definition[2].long_option = "structured-data-value";
|
||||||
m_option_definition[2].short_option = value_option;
|
m_option_definition[2].short_option = value_option;
|
||||||
m_option_definition[2].validator = nullptr;
|
m_option_definition[2].validator = nullptr;
|
||||||
|
@ -69,7 +67,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
||||||
m_option_definition[2].usage_text = m_value_usage_text.data();
|
m_option_definition[2].usage_text = m_value_usage_text.data();
|
||||||
|
|
||||||
m_option_definition[3].usage_mask = LLDB_OPT_SET_3;
|
m_option_definition[3].usage_mask = LLDB_OPT_SET_3;
|
||||||
m_option_definition[3].required = true;
|
m_option_definition[3].required = m_required_options.Test(ePythonFunction);
|
||||||
m_option_definition[3].long_option = "python-function";
|
m_option_definition[3].long_option = "python-function";
|
||||||
m_option_definition[3].short_option = class_option;
|
m_option_definition[3].short_option = class_option;
|
||||||
m_option_definition[3].validator = nullptr;
|
m_option_definition[3].validator = nullptr;
|
||||||
|
@ -78,7 +76,6 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
|
||||||
m_option_definition[3].completion_type = 0;
|
m_option_definition[3].completion_type = 0;
|
||||||
m_option_definition[3].argument_type = eArgTypePythonFunction;
|
m_option_definition[3].argument_type = eArgTypePythonFunction;
|
||||||
m_option_definition[3].usage_text = m_class_usage_text.data();
|
m_option_definition[3].usage_text = m_class_usage_text.data();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Status OptionGroupPythonClassWithDict::SetOptionValue(
|
Status OptionGroupPythonClassWithDict::SetOptionValue(
|
||||||
|
|
Loading…
Reference in New Issue