diff options
author | Pavel Labath <labath@google.com> | 2018-03-09 10:39:40 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-03-09 10:39:40 +0000 |
commit | 5f56fca4e10ab421775e155b669608d8c49cd5fd (patch) | |
tree | 5e51a1ea841d8722df69123e74cb89639279c713 /lldb/source/Interpreter/CommandAlias.cpp | |
parent | 6b62039bb0c035bea854d68a86394d42fb15256b (diff) | |
download | bcm5719-llvm-5f56fca4e10ab421775e155b669608d8c49cd5fd.tar.gz bcm5719-llvm-5f56fca4e10ab421775e155b669608d8c49cd5fd.zip |
Move option parsing out of the Args class
Summary:
The args class is used in plenty of places (a lot of them in the lower lldb
layers) for representing a list of arguments, and most of these places don't
care about option parsing. Moving the option parsing out of the class removes
the largest external dependency (there are a couple more, but these are in
static functions), and brings us closer to being able to move it to the
Utility module).
The new home for these functions is the Options class, which was already used
as an argument to the parse calls, so this just inverts the dependency between
the two.
The functions are themselves are mainly just copied -- the biggest functional
change I've made to them is to avoid modifying the input Args argument (getopt
likes to permute the argument vector), as it was weird to have another class
reorder the entries in Args class. So now the functions don't modify the input
arguments, and (for those where it makes sense) return a new Args vector
instead. I've also made the addition of a "fake arg0" (required for getopt
compatibility) an implementation detail rather than a part of interface.
While doing that I noticed that ParseForCompletion function was recording the
option indexes in the shuffled vector, but then the consumer was looking up the
entries in the unshuffled one. This manifested itself as us not being able to
complete "watchpoint set variable foo --" (because getopt would move "foo" to
the end). Surprisingly all other completions (e.g. "watchpoint set variable foo
--w") were not affected by this. However, I couldn't find a comprehensive test
for command argument completion, so I consolidated the existing tests and added
a bunch of new ones.
Reviewers: davide, jingham, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D43837
llvm-svn: 327110
Diffstat (limited to 'lldb/source/Interpreter/CommandAlias.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandAlias.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp index 2db7460611c..e785f22cce2 100644 --- a/lldb/source/Interpreter/CommandAlias.cpp +++ b/lldb/source/Interpreter/CommandAlias.cpp @@ -40,12 +40,17 @@ static bool ProcessAliasOptionsArgs(lldb::CommandObjectSP &cmd_obj_sp, ExecutionContext exe_ctx = cmd_obj_sp->GetCommandInterpreter().GetExecutionContext(); options->NotifyOptionParsingStarting(&exe_ctx); - args.Unshift(llvm::StringRef("dummy_arg")); - options_string = args.ParseAliasOptions(*options, result, option_arg_vector, - options_args); - args.Shift(); - if (result.Succeeded()) - options->VerifyPartialOptions(result); + + llvm::Expected<Args> args_or = + options->ParseAlias(args, option_arg_vector, options_string); + if (!args_or) { + result.AppendError(toString(args_or.takeError())); + result.AppendError("Unable to create requested alias.\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + args = std::move(*args_or); + options->VerifyPartialOptions(result); if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted) { result.AppendError("Unable to create requested alias.\n"); |