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

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 18:37:11 PDT 2016


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.


>
> 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/ea4f9d54/attachment.html>


More information about the llvm-commits mailing list