[Lldb-commits] [lldb] 930c8ac - Improve the help output for `type XXX delete` where XXX is summary, format,
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Mon May 1 14:22:08 PDT 2023
Author: Jim Ingham
Date: 2023-05-01T14:21:27-07:00
New Revision: 930c8ac5f56122251fc5fe7cb8584360924af62f
URL: https://github.com/llvm/llvm-project/commit/930c8ac5f56122251fc5fe7cb8584360924af62f
DIFF: https://github.com/llvm/llvm-project/commit/930c8ac5f56122251fc5fe7cb8584360924af62f.diff
LOG: Improve the help output for `type XXX delete` where XXX is summary, format,
etc...
Differential Revision: https://reviews.llvm.org/D148282
Added:
Modified:
lldb/source/Commands/CommandObjectType.cpp
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index ae52808793660..2c2973a6272f3 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -39,9 +39,6 @@
#include <functional>
#include <memory>
-#define CHECK_FORMATTER_KIND_MASK(VAL) \
- ((m_formatter_kind_mask & (VAL)) == (VAL))
-
using namespace lldb;
using namespace lldb_private;
@@ -100,6 +97,22 @@ static bool WarnOnPotentialUnquotedUnsignedType(Args &command,
return false;
}
+const char *FormatCategoryToString(FormatCategoryItem item, bool long_name) {
+ switch (item) {
+ case eFormatCategoryItemSummary:
+ return "summary";
+ case eFormatCategoryItemFilter:
+ return "filter";
+ case eFormatCategoryItemSynth:
+ if (long_name)
+ return "synthetic child provider";
+ return "synthetic";
+ case eFormatCategoryItemFormat:
+ return "format";
+ }
+ llvm_unreachable("Fully covered switch above!");
+};
+
#define LLDB_OPTIONS_type_summary_add
#include "CommandOptions.inc"
@@ -754,16 +767,25 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
};
CommandOptions m_options;
- uint32_t m_formatter_kind_mask;
+ FormatCategoryItem m_formatter_kind;
Options *GetOptions() override { return &m_options; }
+
+ static constexpr const char *g_short_help_template =
+ "Delete an existing %s for a type.";
+
+ static constexpr const char *g_long_help_template =
+ "Delete an existing %s for a type. Unless you specify a "
+ "specific category or all categories, only the "
+ "'default' category is searched. The names must be exactly as "
+ "shown in the 'type %s list' output";
public:
CommandObjectTypeFormatterDelete(CommandInterpreter &interpreter,
- uint32_t formatter_kind_mask,
- const char *name, const char *help)
- : CommandObjectParsed(interpreter, name, help, nullptr),
- m_formatter_kind_mask(formatter_kind_mask) {
+ FormatCategoryItem formatter_kind)
+ : CommandObjectParsed(interpreter,
+ FormatCategoryToString(formatter_kind, false)),
+ m_formatter_kind(formatter_kind) {
CommandArgumentEntry type_arg;
CommandArgumentData type_style_arg;
@@ -773,6 +795,19 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
type_arg.push_back(type_style_arg);
m_arguments.push_back(type_arg);
+
+ const char *kind = FormatCategoryToString(formatter_kind, true);
+ const char *short_kind = FormatCategoryToString(formatter_kind, false);
+
+ StreamString s;
+ s.Printf(g_short_help_template, kind);
+ SetHelp(s.GetData());
+ s.Clear();
+ s.Printf(g_long_help_template, kind, short_kind);
+ SetHelpLong(s.GetData());
+ s.Clear();
+ s.Printf("type %s delete", short_kind);
+ SetCommandName(s.GetData());
}
~CommandObjectTypeFormatterDelete() override = default;
@@ -785,7 +820,7 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
DataVisualization::Categories::ForEach(
[this, &request](const lldb::TypeCategoryImplSP &category_sp) {
- category_sp->AutoComplete(request, m_formatter_kind_mask);
+ category_sp->AutoComplete(request, m_formatter_kind);
return true;
});
}
@@ -812,7 +847,7 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
if (m_options.m_delete_all) {
DataVisualization::Categories::ForEach(
[this, typeCS](const lldb::TypeCategoryImplSP &category_sp) -> bool {
- category_sp->Delete(typeCS, m_formatter_kind_mask);
+ category_sp->Delete(typeCS, m_formatter_kind);
return true;
});
result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -827,14 +862,14 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
DataVisualization::Categories::GetCategory(m_options.m_language,
category);
if (category)
- delete_category = category->Delete(typeCS, m_formatter_kind_mask);
+ delete_category = category->Delete(typeCS, m_formatter_kind);
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, m_formatter_kind_mask);
+ delete_category = category->Delete(typeCS, m_formatter_kind);
extra_deletion = FormatterSpecificDeletion(typeCS);
}
@@ -888,16 +923,16 @@ class CommandObjectTypeFormatterClear : public CommandObjectParsed {
};
CommandOptions m_options;
- uint32_t m_formatter_kind_mask;
+ FormatCategoryItem m_formatter_kind;
Options *GetOptions() override { return &m_options; }
public:
CommandObjectTypeFormatterClear(CommandInterpreter &interpreter,
- uint32_t formatter_kind_mask,
+ FormatCategoryItem formatter_kind,
const char *name, const char *help)
: CommandObjectParsed(interpreter, name, help, nullptr),
- m_formatter_kind_mask(formatter_kind_mask) {
+ m_formatter_kind(formatter_kind) {
CommandArgumentData category_arg{eArgTypeName, eArgRepeatOptional};
m_arguments.push_back({category_arg});
}
@@ -911,7 +946,7 @@ class CommandObjectTypeFormatterClear : public CommandObjectParsed {
if (m_options.m_delete_all) {
DataVisualization::Categories::ForEach(
[this](const TypeCategoryImplSP &category_sp) -> bool {
- category_sp->Clear(m_formatter_kind_mask);
+ category_sp->Clear(m_formatter_kind);
return true;
});
} else {
@@ -924,7 +959,7 @@ class CommandObjectTypeFormatterClear : public CommandObjectParsed {
DataVisualization::Categories::GetCategory(ConstString(nullptr),
category);
}
- category->Clear(m_formatter_kind_mask);
+ category->Clear(m_formatter_kind);
}
FormatterSpecificDeletion();
@@ -940,8 +975,7 @@ class CommandObjectTypeFormatDelete : public CommandObjectTypeFormatterDelete {
public:
CommandObjectTypeFormatDelete(CommandInterpreter &interpreter)
: CommandObjectTypeFormatterDelete(
- interpreter, eFormatCategoryItemFormat, "type format delete",
- "Delete an existing formatting style for a type.") {}
+ interpreter, eFormatCategoryItemFormat) {}
~CommandObjectTypeFormatDelete() override = default;
};
@@ -1609,8 +1643,7 @@ class CommandObjectTypeSummaryDelete : public CommandObjectTypeFormatterDelete {
public:
CommandObjectTypeSummaryDelete(CommandInterpreter &interpreter)
: CommandObjectTypeFormatterDelete(
- interpreter, eFormatCategoryItemSummary, "type summary delete",
- "Delete an existing summary for a type.") {}
+ interpreter, eFormatCategoryItemSummary) {}
~CommandObjectTypeSummaryDelete() override = default;
@@ -2159,8 +2192,7 @@ class CommandObjectTypeFilterDelete : public CommandObjectTypeFormatterDelete {
public:
CommandObjectTypeFilterDelete(CommandInterpreter &interpreter)
: CommandObjectTypeFormatterDelete(
- interpreter, eFormatCategoryItemFilter, "type filter delete",
- "Delete an existing filter for a type.") {}
+ interpreter, eFormatCategoryItemFilter) {}
~CommandObjectTypeFilterDelete() override = default;
};
@@ -2173,8 +2205,7 @@ class CommandObjectTypeSynthDelete : public CommandObjectTypeFormatterDelete {
public:
CommandObjectTypeSynthDelete(CommandInterpreter &interpreter)
: CommandObjectTypeFormatterDelete(
- interpreter, eFormatCategoryItemSynth, "type synthetic delete",
- "Delete an existing synthetic provider for a type.") {}
+ interpreter, eFormatCategoryItemSynth) {}
~CommandObjectTypeSynthDelete() override = default;
};
More information about the lldb-commits
mailing list