Options: Reduce code duplication
authorPavel Labath <pavel@labath.sk>
Wed, 10 Jul 2019 17:09:47 +0000 (17:09 +0000)
committerPavel Labath <pavel@labath.sk>
Wed, 10 Jul 2019 17:09:47 +0000 (17:09 +0000)
commit1abaeece719c99ad9b408257b71c19c62db438cc
tree49f9511a7195ebcdaf27a8c9444181bfcb7bf8a5
parent8728e457065365f8f6fbbf86a665885d9dde082a
Options: Reduce code duplication

Summary:
While investigating breakages caused by D63110, I noticed we were
building the short options strings in three places. Some of them used a
leading ':' to detect missing arguments, and some didn't. This was the
indirect cause of D63110. Here, I move the common code into a utility
function.

Also, unify the code which appends the sentinel value at the end of the
option vector, and make it harder for users to pass invalid argc-argv
combos to getopt (another component of D63110) by having the
OptionParser::Parse function take a (Mutable)ArrayRef.

This unification has uncovered that we don't handle missing arguments
while building aliases, However, it's not possible to write an effective
test for this, as right now it is not possible to return an error out of
the alias parsing code (which means we are printing the generic
"failure" message even after this patch).

Reviewers: mgorny, aprantl

Reviewed By: mgorny

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D63770

llvm-svn: 365665
lldb/include/lldb/Host/OptionParser.h
lldb/source/Host/common/OptionParser.cpp
lldb/source/Interpreter/CommandAlias.cpp
lldb/source/Interpreter/Options.cpp