Currently in LLDB we handle options like this:
switch(short_option) { case 'g': m_force = true; break; case 'f': m_global = true; supportGlobal(); break; default: error.SetErrorStringWithFormat("unrecognized options '%c'", short_option); break;
This format has a two problems:
- If we don't handle an option in this switch statement (because of a typo, a changed short-option
name, or because someone just forgot to implement it), we only find out when we have a test or user
that notices we get an error when using this option. There is no compile-time verification of this.
- It's not very easy to read unless you know all the short options for all commands.
This patch makes our tablegen emit an enum that represents the options, which changes the code above to this (using SettingsSet as an example):
auto opt = toSettingsSetEnum(short_option, error); if (!opt) return error; switch (opt) { case SettingsSet::Global: m_force = true; break; case SettingsSet::Force: m_global = true; supportGlobal(); break; // No default with error handling, already handled in toSettingsSetEnum. // If you don't implement an option, this will trigger a compiler warning for unhandled enum value. }
Can we use the option name instead, like I did for the properties? Or would that cause conflicts?