ArgList flag values

I've come across a need to know whether an option was set true, false or
unspecified. If it is true I want to do one thing, if it is false I
want to do something else and if it is unspecified I want to do nothing.

ArgList::hasFlag is a convenient way to check true/false with a default
value. An ArgList::hasFlag that returned Optional<bool> would allow
checking the unspecified case. Returning some kind Tribool class object
would allow the same.

Both Optional<bool> and Tribool are somewhat overkill for this kind of
thing as I really wouldn't need to do comparisons and logical operations
on the value. A three-state enum (class) would do just as well.

Is there an existing way to handle this kind of flag? If not, would
there be interest in adding support for it?

                         -David

From: llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] On Behalf Of David
Greene via llvm-dev
Sent: Thursday, August 09, 2018 5:28 PM
To: llvm-dev@lists.llvm.org
Subject: [llvm-dev] ArgList flag values

I've come across a need to know whether an option was set true, false or
unspecified. If it is true I want to do one thing, if it is false I
want to do something else and if it is unspecified I want to do nothing.

ArgList::hasFlag is a convenient way to check true/false with a default
value. An ArgList::hasFlag that returned Optional<bool> would allow
checking the unspecified case. Returning some kind Tribool class object
would allow the same.

Both Optional<bool> and Tribool are somewhat overkill for this kind of
thing as I really wouldn't need to do comparisons and logical operations
on the value. A three-state enum (class) would do just as well.

Is there an existing way to handle this kind of flag? If not, would
there be interest in adding support for it?

I'd be inclined to use getLastArg for this, which returns nullptr if you
don't have any of the specified options.
--paulr

<paul.robinson@sony.com> writes:

ArgList::hasFlag is a convenient way to check true/false with a default
value. An ArgList::hasFlag that returned Optional<bool> would allow
checking the unspecified case. Returning some kind Tribool class object
would allow the same.

I'd be inclined to use getLastArg for this, which returns nullptr if you
don't have any of the specified options.

Thanks for the pointer!

                           -David