[PATCH] D24489: [Support][CommandLine] Add cl::getRegisteredSubcommands()

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 14 07:45:39 PDT 2016


On Tue, Sep 13, 2016 at 6:37 PM Dean Michael Berris <dberris at google.com>
wrote:

> On Wed, Sep 14, 2016 at 3:13 AM David Blaikie <dblaikie at gmail.com> wrote:
>
> On Mon, Sep 12, 2016 at 6:57 PM Dean Michael Berris <dberris at google.com>
> wrote:
>
> dberris created this revision.
> dberris added reviewers: zturner, dblaikie, echristo.
> dberris added a subscriber: llvm-commits.
> Herald added a subscriber: mehdi_amini.
>
> This should allow users of the library to get a range to iterate through
> all the subcommands that are registered to the global parser. This
> allows users to define subcommands in libraries that self-register to
> have dispatch done at a different stage (like main). It allows for
> writing code like the following:
>
>     for (auto *S : cl::getRegisteredSubcommands()) {
>       if (*S) {
>         // Dispatch on S->getName().
>       }
>     }
>
>
> FWIW: I wasn't expecting/suggesting we should have to compare by strings
> (stringly typed isn't ideal, of course) - I was hoping/figuring we could
> declaer the subcommand in the header (along with the single entry point
> function) and then define it over in the file that defines the single entry
> point along with the subcommand's flags.
>
>
> Unfortunately that doesn't remove the dispatch, which would be manual, as
> opposed to doing this which would be automatic -- i.e. all the
> implementations can register a function to invoke to a global map, which is
> used to dispatch, makes extending easier/simpler than having to manually
> add if statements.
>

Ah, OK - that's more fuss/bother than I was thinking of for a handful of
things - a switch/if chain in main that was pretty mechanical/repetitive
didn't seem like a big burden, but I don't mind a registration system if
you prefer that (it trips into my "potentially overengineering" bucket - so
if you want to save some time/work, don't feel like I'm pushing you to
build such a registration system).

(but mostly it was the suggested string comparison that I was extra
uncomfortable with here - so long as the registration system used the
Subcommand + dispatch function, rather than the name + dispatch function,
I'd be more or less comfortable with it)


>
>
>
> Did this not work for some reason?
>
>
>
> I could make it work, but that's mutually exclusive to this functionality.
> :)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160914/353253fd/attachment.html>


More information about the llvm-commits mailing list