diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-07-10 20:17:38 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-07-10 20:17:38 +0000 |
commit | 3a0e12700bc775be452cf40f9226e535683864b7 (patch) | |
tree | 30cdbbb9b4db69ff611c07f2c3c7ac4b4dabc0cd /lldb/source/Commands/CommandObjectCommands.cpp | |
parent | 01ce144ddf03df18c2259eb2d6e827511c0068c8 (diff) | |
download | bcm5719-llvm-3a0e12700bc775be452cf40f9226e535683864b7.tar.gz bcm5719-llvm-3a0e12700bc775be452cf40f9226e535683864b7.zip |
Refactor parsing of option lists with a raw string suffix.
Summary:
A subset of the LLDB commands follows this command line interface style:
<command name> [arguments] -- <string suffix>
The parsing code for this interface has been so far been duplicated into the different
command objects which makes it hard to maintain and reuse elsewhere.
This patches improves the situation by adding a OptionsWithRaw class that centralizes
the parsing logic and allows easier testing. The different commands now just call this class to
extract the arguments and the raw suffix from the provided user input.
Reviewers: jingham
Reviewed By: jingham
Subscribers: mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D49106
llvm-svn: 336723
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 584e081c6e8..5e7f272ec22 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -553,42 +553,13 @@ protected: ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_option_group.NotifyOptionParsingStarting(&exe_ctx); - const char *remainder = nullptr; - - if (raw_command_line[0] == '-') { - // We have some options and these options MUST end with --. - const char *end_options = nullptr; - const char *s = raw_command_line; - while (s && s[0]) { - end_options = ::strstr(s, "--"); - if (end_options) { - end_options += 2; // Get past the "--" - if (::isspace(end_options[0])) { - remainder = end_options; - while (::isspace(*remainder)) - ++remainder; - break; - } - } - s = end_options; - } + OptionsWithRaw args_with_suffix(raw_command_line); + const char *remainder = args_with_suffix.GetRawPart().c_str(); - if (end_options) { - Args args( - llvm::StringRef(raw_command_line, end_options - raw_command_line)); - if (!ParseOptions(args, result)) - return false; - - Status error(m_option_group.NotifyOptionParsingFinished(&exe_ctx)); - if (error.Fail()) { - result.AppendError(error.AsCString()); - result.SetStatus(eReturnStatusFailed); - return false; - } - } - } - if (nullptr == remainder) - remainder = raw_command_line; + if (args_with_suffix.HasArgs()) + if (!ParseOptionsAndNotify(args_with_suffix.GetArgs(), result, + m_option_group, exe_ctx)) + return false; llvm::StringRef raw_command_string(remainder); Args args(raw_command_string); |