Skip to content

Commit c16fef1

Browse files
committed
[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 <[email protected]>
1 parent 1900503 commit c16fef1

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

lldb/include/lldb/Interpreter/OptionGroupPythonClassWithDict.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- OptionGroupPythonClassWithDict.h -------------------------------------*- C++ -*-===//
1+
//===-- OptionGroupPythonClassWithDict.h ------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,9 +9,10 @@
99
#ifndef LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
1010
#define LLDB_INTERPRETER_OPTIONGROUPPYTHONCLASSWITHDICT_H
1111

12-
#include "lldb/lldb-types.h"
1312
#include "lldb/Interpreter/Options.h"
13+
#include "lldb/Utility/Flags.h"
1414
#include "lldb/Utility/StructuredData.h"
15+
#include "lldb/lldb-types.h"
1516

1617
namespace lldb_private {
1718

@@ -23,12 +24,20 @@ namespace lldb_private {
2324
// StructuredData::Dictionary is constructed with those pairs.
2425
class OptionGroupPythonClassWithDict : public OptionGroup {
2526
public:
26-
OptionGroupPythonClassWithDict(const char *class_use,
27-
bool is_class = true,
28-
int class_option = 'C',
29-
int key_option = 'k',
30-
int value_option = 'v');
31-
27+
enum OptionKind {
28+
eScriptClass = 1 << 0,
29+
eDictKey = 1 << 1,
30+
eDictValue = 1 << 2,
31+
ePythonFunction = 1 << 3,
32+
eAllOptions = (eScriptClass | eDictKey | eDictValue | ePythonFunction)
33+
};
34+
35+
OptionGroupPythonClassWithDict(const char *class_use, bool is_class = true,
36+
int class_option = 'C', int key_option = 'k',
37+
int value_option = 'v',
38+
uint16_t required_options = eScriptClass |
39+
ePythonFunction);
40+
3241
~OptionGroupPythonClassWithDict() override = default;
3342

3443
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
@@ -55,6 +64,7 @@ class OptionGroupPythonClassWithDict : public OptionGroup {
5564
std::string m_class_usage_text, m_key_usage_text, m_value_usage_text;
5665
bool m_is_class;
5766
OptionDefinition m_option_definition[4];
67+
Flags m_required_options;
5868
};
5969

6070
} // namespace lldb_private

lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
using namespace lldb;
1414
using namespace lldb_private;
1515

16-
OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
17-
(const char *class_use,
18-
bool is_class,
19-
int class_option,
20-
int key_option,
21-
int value_option) : m_is_class(is_class) {
16+
OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict(
17+
const char *class_use, bool is_class, int class_option, int key_option,
18+
int value_option, uint16_t required_options)
19+
: m_is_class(is_class), m_required_options(required_options) {
2220
m_key_usage_text.assign("The key for a key/value pair passed to the "
2321
"implementation of a ");
2422
m_key_usage_text.append(class_use);
@@ -36,7 +34,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
3634
m_class_usage_text.append(".");
3735

3836
m_option_definition[0].usage_mask = LLDB_OPT_SET_1;
39-
m_option_definition[0].required = true;
37+
m_option_definition[0].required = m_required_options.Test(eScriptClass);
4038
m_option_definition[0].long_option = "script-class";
4139
m_option_definition[0].short_option = class_option;
4240
m_option_definition[0].validator = nullptr;
@@ -47,7 +45,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
4745
m_option_definition[0].usage_text = m_class_usage_text.data();
4846

4947
m_option_definition[1].usage_mask = LLDB_OPT_SET_2;
50-
m_option_definition[1].required = false;
48+
m_option_definition[1].required = m_required_options.Test(eDictKey);
5149
m_option_definition[1].long_option = "structured-data-key";
5250
m_option_definition[1].short_option = key_option;
5351
m_option_definition[1].validator = nullptr;
@@ -58,7 +56,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
5856
m_option_definition[1].usage_text = m_key_usage_text.data();
5957

6058
m_option_definition[2].usage_mask = LLDB_OPT_SET_2;
61-
m_option_definition[2].required = false;
59+
m_option_definition[2].required = m_required_options.Test(eDictValue);
6260
m_option_definition[2].long_option = "structured-data-value";
6361
m_option_definition[2].short_option = value_option;
6462
m_option_definition[2].validator = nullptr;
@@ -69,7 +67,7 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
6967
m_option_definition[2].usage_text = m_value_usage_text.data();
7068

7169
m_option_definition[3].usage_mask = LLDB_OPT_SET_3;
72-
m_option_definition[3].required = true;
70+
m_option_definition[3].required = m_required_options.Test(ePythonFunction);
7371
m_option_definition[3].long_option = "python-function";
7472
m_option_definition[3].short_option = class_option;
7573
m_option_definition[3].validator = nullptr;
@@ -78,7 +76,6 @@ OptionGroupPythonClassWithDict::OptionGroupPythonClassWithDict
7876
m_option_definition[3].completion_type = 0;
7977
m_option_definition[3].argument_type = eArgTypePythonFunction;
8078
m_option_definition[3].usage_text = m_class_usage_text.data();
81-
8279
}
8380

8481
Status OptionGroupPythonClassWithDict::SetOptionValue(

0 commit comments

Comments
 (0)