[all-commits] [llvm/llvm-project] f8a29b: [OptTable] Support grouped short options
Fangrui Song via All-commits
all-commits at lists.llvm.org
Fri Jul 17 09:33:05 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: f8a29b174a965acb942dd3ef5f8ef2c32620777b
https://github.com/llvm/llvm-project/commit/f8a29b174a965acb942dd3ef5f8ef2c32620777b
Author: Fangrui Song <maskray at google.com>
Date: 2020-07-17 (Fri, 17 Jul 2020)
Changed paths:
M llvm/include/llvm/Option/ArgList.h
M llvm/include/llvm/Option/OptTable.h
M llvm/include/llvm/Option/Option.h
M llvm/lib/Option/OptTable.cpp
M llvm/lib/Option/Option.cpp
M llvm/unittests/Option/OptionParsingTest.cpp
M llvm/unittests/Option/Opts.td
Log Message:
-----------
[OptTable] Support grouped short options
POSIX.1-2017 12.2 Utility Syntax Guidelines, Guideline 5 says:
> One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.
i.e. -abc represents -a -b -c. The grouped short options are very common. Many
utilities extend the syntax by allowing (an option with an argument) following a
sequence of short options.
This patch adds the support to OptTable, similar to cl::Group for CommandLine
(D58711). llvm-symbolizer will use the feature (D83530). CommandLine is exotic
in some aspects. OptTable is preferred if the user wants to get rid of the
behaviors.
* `cl::opt<bool> i(...)` can be disabled via -i=false or -i=0, which is
different from conventional --no-i.
* Handling --foo & --no-foo requires a comparison of argument positions,
which is a bit clumsy in user code.
OptTable::parseOneArg (non-const reference InputArgList) is added along with
ParseOneArg (const ArgList &). The duplicate does not look great at first
glance. However, The implementation can be simpler if ArgList is mutable.
(ParseOneArg is used by clang-cl (FlagsToInclude/FlagsToExclude) and lld COFF
(case-insensitive). Adding grouped short options can make the function even more
complex.)
The implementation allows a long option following a group of short options. We
probably should refine the code to disallow this in the future. Allowing this
seems benign for now.
Reviewed By: grimar, jhenderson
Differential Revision: https://reviews.llvm.org/D83639
More information about the All-commits
mailing list