[clang] [clang-tools-extra] [lld] [llvm] [llvm] Add subcommand support for OptTable (PR #155026)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 10:06:13 PDT 2025


================
@@ -98,7 +98,23 @@ class HelpTextVariant<list<OptionVisibility> visibilities, string text> {
   string Text = text;
 }
 
-class Option<list<string> prefixes, string name, OptionKind kind> {
+// Base class for TopLevelCommand and Subcommands.
+class Command<string name> { string Name = name; }
+
+// Class definition for positional subcommands.
+class Subcommand<string name, string helpText, string usage = "">
+    : Command<name> {
+  string HelpText = helpText;
+  string Usage = usage;
+}
+
+// Compile time representation for top level command (aka toolname).
+// Offers backward compatibility with existing Option class definitions before
+// introduction of commandGroup in Option class to support subcommands.
+def TopLevelCommand : Command<"TopLevelCommand">;
----------------
PiJoules wrote:

What happens if a user would define a `Subcommand` with the name `"TopLevelCommand"`? I'm assuming there should only be one with this name assuming it's like a sentinel. If only one should be defined, are there any checks that would assert this or diagnose if more than one was provided?

https://github.com/llvm/llvm-project/pull/155026


More information about the cfe-commits mailing list