forked from OSchip/llvm-project
Uniquify all the type X delete commands via one common base class
This removes a lot of code, which is A Good Thing(TM) llvm-svn: 253140
This commit is contained in:
parent
7bfbb5912e
commit
4fc8416181
|
@ -84,7 +84,7 @@ class CppDataFormatterTestCase(TestBase):
|
|||
|
||||
# Delete type format for 'Speed', we should expect an error message.
|
||||
self.expect("type format delete Speed", error=True,
|
||||
substrs = ['no custom format for Speed'])
|
||||
substrs = ['no custom formatter for Speed'])
|
||||
|
||||
self.runCmd("type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v")
|
||||
|
||||
|
|
|
@ -906,14 +906,9 @@ CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
|
|||
return sizeof(g_option_table) / sizeof (OptionDefinition);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// CommandObjectTypeFormatDelete
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class CommandObjectTypeFormatDelete : public CommandObjectParsed
|
||||
class CommandObjectTypeFormatterDelete : public CommandObjectParsed
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
class CommandOptions : public Options
|
||||
{
|
||||
public:
|
||||
|
@ -976,6 +971,7 @@ private:
|
|||
};
|
||||
|
||||
CommandOptions m_options;
|
||||
uint32_t m_formatter_kind_mask;
|
||||
|
||||
Options *
|
||||
GetOptions () override
|
||||
|
@ -984,12 +980,16 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
|
||||
CommandObjectParsed (interpreter,
|
||||
"type format delete",
|
||||
"Delete an existing formatting style for a type.",
|
||||
NULL),
|
||||
m_options(interpreter)
|
||||
CommandObjectTypeFormatterDelete (CommandInterpreter &interpreter,
|
||||
uint32_t formatter_kind_mask,
|
||||
const char* name,
|
||||
const char* help) :
|
||||
CommandObjectParsed (interpreter,
|
||||
name,
|
||||
help,
|
||||
NULL),
|
||||
m_options(interpreter),
|
||||
m_formatter_kind_mask(formatter_kind_mask)
|
||||
{
|
||||
CommandArgumentEntry type_arg;
|
||||
CommandArgumentData type_style_arg;
|
||||
|
@ -1003,11 +1003,15 @@ public:
|
|||
|
||||
}
|
||||
|
||||
~CommandObjectTypeFormatDelete () override
|
||||
{
|
||||
}
|
||||
~CommandObjectTypeFormatterDelete () override = default;
|
||||
|
||||
protected:
|
||||
virtual bool
|
||||
FormatterSpecificDeletion (ConstString typeCS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
DoExecute (Args& command, CommandReturnObject &result) override
|
||||
{
|
||||
|
@ -1032,8 +1036,8 @@ protected:
|
|||
|
||||
if (m_options.m_delete_all)
|
||||
{
|
||||
DataVisualization::Categories::ForEach( [typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
|
||||
category_sp->Delete(typeCS, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
|
||||
DataVisualization::Categories::ForEach( [this, typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
|
||||
category_sp->Delete(typeCS, m_formatter_kind_mask);
|
||||
return true;
|
||||
});
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
|
@ -1041,30 +1045,33 @@ protected:
|
|||
}
|
||||
|
||||
bool delete_category = false;
|
||||
bool extra_deletion = false;
|
||||
|
||||
if (m_options.m_language != lldb::eLanguageTypeUnknown)
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(m_options.m_language, category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
|
||||
delete_category = category->Delete(typeCS, m_formatter_kind_mask);
|
||||
extra_deletion = FormatterSpecificDeletion(typeCS);
|
||||
}
|
||||
else
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
|
||||
delete_category = category->Delete(typeCS, m_formatter_kind_mask);
|
||||
extra_deletion = FormatterSpecificDeletion(typeCS);
|
||||
}
|
||||
|
||||
if (delete_category)
|
||||
if (delete_category || extra_deletion)
|
||||
{
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
|
||||
result.AppendErrorWithFormat ("no custom formatter for %s.\n", typeA);
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
@ -1074,7 +1081,7 @@ protected:
|
|||
};
|
||||
|
||||
OptionDefinition
|
||||
CommandObjectTypeFormatDelete::CommandOptions::g_option_table[] =
|
||||
CommandObjectTypeFormatterDelete::CommandOptions::g_option_table[] =
|
||||
{
|
||||
{ LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
|
||||
{ LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
|
||||
|
@ -1082,6 +1089,31 @@ CommandObjectTypeFormatDelete::CommandOptions::g_option_table[] =
|
|||
{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// CommandObjectTypeFormatDelete
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class CommandObjectTypeFormatDelete : public CommandObjectTypeFormatterDelete
|
||||
{
|
||||
public:
|
||||
CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
|
||||
CommandObjectTypeFormatterDelete (interpreter,
|
||||
eFormatCategoryItemValue | eFormatCategoryItemRegexValue,
|
||||
"type format delete",
|
||||
"Delete an existing formatting style for a type.")
|
||||
{
|
||||
}
|
||||
|
||||
~CommandObjectTypeFormatDelete () override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// CommandObjectTypeFormatClear
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -1936,96 +1968,15 @@ CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
|
|||
// CommandObjectTypeSummaryDelete
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class CommandObjectTypeSummaryDelete : public CommandObjectParsed
|
||||
class CommandObjectTypeSummaryDelete : public CommandObjectTypeFormatterDelete
|
||||
{
|
||||
private:
|
||||
class CommandOptions : public Options
|
||||
{
|
||||
public:
|
||||
|
||||
CommandOptions (CommandInterpreter &interpreter) :
|
||||
Options (interpreter)
|
||||
{
|
||||
}
|
||||
|
||||
~CommandOptions () override {}
|
||||
|
||||
Error
|
||||
SetOptionValue (uint32_t option_idx, const char *option_arg) override
|
||||
{
|
||||
Error error;
|
||||
const int short_option = m_getopt_table[option_idx].val;
|
||||
|
||||
switch (short_option)
|
||||
{
|
||||
case 'a':
|
||||
m_delete_all = true;
|
||||
break;
|
||||
case 'w':
|
||||
m_category = std::string(option_arg);
|
||||
break;
|
||||
case 'l':
|
||||
m_language = Language::GetLanguageTypeFromString(option_arg);
|
||||
break;
|
||||
default:
|
||||
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void
|
||||
OptionParsingStarting () override
|
||||
{
|
||||
m_delete_all = false;
|
||||
m_category = "default";
|
||||
m_language = lldb::eLanguageTypeUnknown;
|
||||
}
|
||||
|
||||
const OptionDefinition*
|
||||
GetDefinitions () override
|
||||
{
|
||||
return g_option_table;
|
||||
}
|
||||
|
||||
// Options table: Required for subclasses of Options.
|
||||
|
||||
static OptionDefinition g_option_table[];
|
||||
|
||||
// Instance variables to hold the values for command options.
|
||||
|
||||
bool m_delete_all;
|
||||
std::string m_category;
|
||||
lldb::LanguageType m_language;
|
||||
};
|
||||
|
||||
CommandOptions m_options;
|
||||
|
||||
Options *
|
||||
GetOptions () override
|
||||
{
|
||||
return &m_options;
|
||||
}
|
||||
|
||||
public:
|
||||
CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
|
||||
CommandObjectParsed (interpreter,
|
||||
"type summary delete",
|
||||
"Delete an existing summary style for a type.",
|
||||
NULL),
|
||||
m_options(interpreter)
|
||||
CommandObjectTypeFormatterDelete (interpreter,
|
||||
eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary,
|
||||
"type summary delete",
|
||||
"Delete an existing summary for a type.")
|
||||
{
|
||||
CommandArgumentEntry type_arg;
|
||||
CommandArgumentData type_style_arg;
|
||||
|
||||
type_style_arg.arg_type = eArgTypeName;
|
||||
type_style_arg.arg_repetition = eArgRepeatPlain;
|
||||
|
||||
type_arg.push_back (type_style_arg);
|
||||
|
||||
m_arguments.push_back (type_arg);
|
||||
|
||||
}
|
||||
|
||||
~CommandObjectTypeSummaryDelete () override
|
||||
|
@ -2034,80 +1985,14 @@ public:
|
|||
|
||||
protected:
|
||||
bool
|
||||
DoExecute (Args& command, CommandReturnObject &result) override
|
||||
FormatterSpecificDeletion (ConstString typeCS) override
|
||||
{
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* typeA = command.GetArgumentAtIndex(0);
|
||||
ConstString typeCS(typeA);
|
||||
|
||||
if (!typeCS)
|
||||
{
|
||||
result.AppendError("empty typenames not allowed");
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_options.m_delete_all)
|
||||
{
|
||||
DataVisualization::Categories::ForEach( [typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
|
||||
category_sp->Delete(typeCS, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
|
||||
return true;
|
||||
});
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
|
||||
bool delete_category = false;
|
||||
bool delete_named = false;
|
||||
|
||||
if (m_options.m_language != lldb::eLanguageTypeUnknown)
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(m_options.m_language, category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
|
||||
}
|
||||
else
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
|
||||
delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
|
||||
}
|
||||
|
||||
if (delete_category || delete_named)
|
||||
{
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat ("no custom summary for %s.\n", typeA);
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
return DataVisualization::NamedSummaryFormats::Delete(typeCS);
|
||||
}
|
||||
};
|
||||
|
||||
OptionDefinition
|
||||
CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] =
|
||||
{
|
||||
{ LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
|
||||
{ LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
|
||||
{ LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage, "Delete from given language's category."},
|
||||
{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
|
||||
};
|
||||
|
||||
class CommandObjectTypeSummaryClear : public CommandObjectParsed
|
||||
{
|
||||
private:
|
||||
|
@ -3483,173 +3368,20 @@ CommandObjectTypeSynthList::CommandOptions::g_option_table[] =
|
|||
// CommandObjectTypeFilterDelete
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class CommandObjectTypeFilterDelete : public CommandObjectParsed
|
||||
class CommandObjectTypeFilterDelete : public CommandObjectTypeFormatterDelete
|
||||
{
|
||||
private:
|
||||
class CommandOptions : public Options
|
||||
{
|
||||
public:
|
||||
|
||||
CommandOptions (CommandInterpreter &interpreter) :
|
||||
Options (interpreter)
|
||||
{
|
||||
}
|
||||
|
||||
~CommandOptions () override {}
|
||||
|
||||
Error
|
||||
SetOptionValue (uint32_t option_idx, const char *option_arg) override
|
||||
{
|
||||
Error error;
|
||||
const int short_option = m_getopt_table[option_idx].val;
|
||||
|
||||
switch (short_option)
|
||||
{
|
||||
case 'a':
|
||||
m_delete_all = true;
|
||||
break;
|
||||
case 'w':
|
||||
m_category = std::string(option_arg);
|
||||
break;
|
||||
case 'l':
|
||||
m_language = Language::GetLanguageTypeFromString(option_arg);
|
||||
break;
|
||||
default:
|
||||
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void
|
||||
OptionParsingStarting () override
|
||||
{
|
||||
m_delete_all = false;
|
||||
m_category = "default";
|
||||
m_language = lldb::eLanguageTypeUnknown;
|
||||
}
|
||||
|
||||
const OptionDefinition*
|
||||
GetDefinitions () override
|
||||
{
|
||||
return g_option_table;
|
||||
}
|
||||
|
||||
// Options table: Required for subclasses of Options.
|
||||
|
||||
static OptionDefinition g_option_table[];
|
||||
|
||||
// Instance variables to hold the values for command options.
|
||||
|
||||
bool m_delete_all;
|
||||
std::string m_category;
|
||||
lldb::LanguageType m_language;
|
||||
};
|
||||
|
||||
CommandOptions m_options;
|
||||
|
||||
Options *
|
||||
GetOptions () override
|
||||
{
|
||||
return &m_options;
|
||||
}
|
||||
|
||||
public:
|
||||
CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
|
||||
CommandObjectParsed (interpreter,
|
||||
"type filter delete",
|
||||
"Delete an existing filter for a type.",
|
||||
NULL),
|
||||
m_options(interpreter)
|
||||
CommandObjectTypeFormatterDelete (interpreter,
|
||||
eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
|
||||
"type filter delete",
|
||||
"Delete an existing filter for a type.")
|
||||
{
|
||||
CommandArgumentEntry type_arg;
|
||||
CommandArgumentData type_style_arg;
|
||||
|
||||
type_style_arg.arg_type = eArgTypeName;
|
||||
type_style_arg.arg_repetition = eArgRepeatPlain;
|
||||
|
||||
type_arg.push_back (type_style_arg);
|
||||
|
||||
m_arguments.push_back (type_arg);
|
||||
|
||||
}
|
||||
|
||||
~CommandObjectTypeFilterDelete () override
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool
|
||||
DoExecute (Args& command, CommandReturnObject &result) override
|
||||
{
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* typeA = command.GetArgumentAtIndex(0);
|
||||
ConstString typeCS(typeA);
|
||||
|
||||
if (!typeCS)
|
||||
{
|
||||
result.AppendError("empty typenames not allowed");
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_options.m_delete_all)
|
||||
{
|
||||
DataVisualization::Categories::ForEach( [typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
|
||||
category_sp->Delete(typeCS, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
|
||||
return true;
|
||||
});
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
|
||||
bool delete_category = false;
|
||||
|
||||
if (m_options.m_language != lldb::eLanguageTypeUnknown)
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(m_options.m_language, category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
|
||||
}
|
||||
else
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
|
||||
}
|
||||
|
||||
if (delete_category)
|
||||
{
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat ("no custom filter for %s.\n", typeA);
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OptionDefinition
|
||||
CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
|
||||
{
|
||||
{ LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
|
||||
{ LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
|
||||
{ LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage, "Delete from given language's category."},
|
||||
{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
|
||||
};
|
||||
|
||||
#ifndef LLDB_DISABLE_PYTHON
|
||||
|
@ -3658,173 +3390,20 @@ CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
|
|||
// CommandObjectTypeSynthDelete
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class CommandObjectTypeSynthDelete : public CommandObjectParsed
|
||||
class CommandObjectTypeSynthDelete : public CommandObjectTypeFormatterDelete
|
||||
{
|
||||
private:
|
||||
class CommandOptions : public Options
|
||||
{
|
||||
public:
|
||||
|
||||
CommandOptions (CommandInterpreter &interpreter) :
|
||||
Options (interpreter)
|
||||
{
|
||||
}
|
||||
|
||||
~CommandOptions () override {}
|
||||
|
||||
Error
|
||||
SetOptionValue (uint32_t option_idx, const char *option_arg) override
|
||||
{
|
||||
Error error;
|
||||
const int short_option = m_getopt_table[option_idx].val;
|
||||
|
||||
switch (short_option)
|
||||
{
|
||||
case 'a':
|
||||
m_delete_all = true;
|
||||
break;
|
||||
case 'w':
|
||||
m_category = std::string(option_arg);
|
||||
break;
|
||||
case 'l':
|
||||
m_language = Language::GetLanguageTypeFromString(option_arg);
|
||||
break;
|
||||
default:
|
||||
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void
|
||||
OptionParsingStarting () override
|
||||
{
|
||||
m_delete_all = false;
|
||||
m_category = "default";
|
||||
m_language = lldb::eLanguageTypeUnknown;
|
||||
}
|
||||
|
||||
const OptionDefinition*
|
||||
GetDefinitions () override
|
||||
{
|
||||
return g_option_table;
|
||||
}
|
||||
|
||||
// Options table: Required for subclasses of Options.
|
||||
|
||||
static OptionDefinition g_option_table[];
|
||||
|
||||
// Instance variables to hold the values for command options.
|
||||
|
||||
bool m_delete_all;
|
||||
std::string m_category;
|
||||
lldb::LanguageType m_language;
|
||||
};
|
||||
|
||||
CommandOptions m_options;
|
||||
|
||||
Options *
|
||||
GetOptions () override
|
||||
{
|
||||
return &m_options;
|
||||
}
|
||||
|
||||
public:
|
||||
CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
|
||||
CommandObjectParsed (interpreter,
|
||||
"type synthetic delete",
|
||||
"Delete an existing synthetic provider for a type.",
|
||||
NULL),
|
||||
m_options(interpreter)
|
||||
CommandObjectTypeFormatterDelete (interpreter,
|
||||
eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
|
||||
"type synthetic delete",
|
||||
"Delete an existing synthetic provider for a type.")
|
||||
{
|
||||
CommandArgumentEntry type_arg;
|
||||
CommandArgumentData type_style_arg;
|
||||
|
||||
type_style_arg.arg_type = eArgTypeName;
|
||||
type_style_arg.arg_repetition = eArgRepeatPlain;
|
||||
|
||||
type_arg.push_back (type_style_arg);
|
||||
|
||||
m_arguments.push_back (type_arg);
|
||||
|
||||
}
|
||||
|
||||
~CommandObjectTypeSynthDelete () override
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool
|
||||
DoExecute (Args& command, CommandReturnObject &result) override
|
||||
{
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* typeA = command.GetArgumentAtIndex(0);
|
||||
ConstString typeCS(typeA);
|
||||
|
||||
if (!typeCS)
|
||||
{
|
||||
result.AppendError("empty typenames not allowed");
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_options.m_delete_all)
|
||||
{
|
||||
DataVisualization::Categories::ForEach( [typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
|
||||
category_sp->Delete(typeCS, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
|
||||
return true;
|
||||
});
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
|
||||
bool delete_category = false;
|
||||
|
||||
if (m_options.m_language != lldb::eLanguageTypeUnknown)
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(m_options.m_language, category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
|
||||
}
|
||||
else
|
||||
{
|
||||
lldb::TypeCategoryImplSP category;
|
||||
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
|
||||
if (category)
|
||||
delete_category = category->Delete(typeCS, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
|
||||
}
|
||||
|
||||
if (delete_category)
|
||||
{
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
return result.Succeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OptionDefinition
|
||||
CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] =
|
||||
{
|
||||
{ LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
|
||||
{ LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
|
||||
{ LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage, "Delete from given language's category."},
|
||||
{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
|
||||
};
|
||||
|
||||
#endif // #ifndef LLDB_DISABLE_PYTHON
|
||||
|
|
Loading…
Reference in New Issue