This is an archive of the discontinued LLVM Phabricator instance.

[NFCI] Clean up enum FormatCategoryItem.
ClosedPublic

Authored by jgorbe on Sep 19 2022, 5:03 PM.

Details

Summary
  • Merge pairs like eFormatCategoryItemSummary and eFormatCategoryItemRegexSummary into a single value. See explanation below.
  • Rename eFormatCategoryItemValue to eFormatCategoryItemFormat. This makes the enum match the names used elsewhere for formatter kinds (format, summary, filter, synth).
  • Delete unused values eFormatCategoryItemValidator and eFormatCategoryItemRegexValidator.

This enum is only used to reuse some code in CommandObjectType.cpp. For
example, instead of having separate implementations for `type summary
delete`, type format delete, and so on, there's a single generic
implementation that takes an enum value, and then the specific commands
derive from it and set the right flags for the specific kind of
formatter.

Even though the enum distinguishes between regular and regex matches for
every kind of formatter, this distinction is never used: enum values are
always specified in pairs like
eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary.

This causes some ugly code duplication in TypeCategory.cpp. In order to
handle every flag combination some code appears 8 times:

{format, summary, synth, filter} x {exact, regex}

Diff Detail

Event Timeline

jgorbe created this revision.Sep 19 2022, 5:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 5:03 PM
jgorbe requested review of this revision.Sep 19 2022, 5:03 PM
JDevlieghere accepted this revision.Sep 20 2022, 8:18 AM

Makes sense. LGTM modulo the enum values.

lldb/include/lldb/lldb-private-enumerations.h
130–134

As these are private we don't have to skip values I think. Also let's use left shift operators to make it more obvious that these are flags.

This revision is now accepted and ready to land.Sep 20 2022, 8:18 AM
This revision was automatically updated to reflect the committed changes.
jgorbe marked an inline comment as done.Sep 20 2022, 10:45 AM
jgorbe added inline comments.
lldb/include/lldb/lldb-private-enumerations.h
130–134

Done, thanks! :)