[Lldb-commits] [lldb] r262901 - Move ProcessAliasOptionsArgs to be a static on CommandAlias; it wasn't using any instance data on the CommandInterpreter anyway
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 7 19:00:28 PST 2016
Author: enrico
Date: Mon Mar 7 21:00:27 2016
New Revision: 262901
URL: http://llvm.org/viewvc/llvm-project?rev=262901&view=rev
Log:
Move ProcessAliasOptionsArgs to be a static on CommandAlias; it wasn't using any instance data on the CommandInterpreter anyway
This small step removes one piece of alias machinery from the CommandInterpreter into the CommandAlias
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=262901&r1=262900&r2=262901&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Mon Mar 7 21:00:27 2016
@@ -204,6 +204,11 @@ public:
{
lldb::CommandObjectSP m_underlying_command_sp;
OptionArgVectorSP m_option_args_sp;
+
+ static bool
+ ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
+ const char *options_args,
+ OptionArgVectorSP &option_arg_vector_sp);
};
typedef std::map<std::string, CommandAlias> CommandAliasMap;
@@ -310,11 +315,6 @@ public:
OptionArgVectorSP
GetAliasOptions (const char *alias_name);
- bool
- ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
- const char *options_args,
- OptionArgVectorSP &option_arg_vector_sp);
-
CommandObject *
BuildAliasResult (const char *alias_name,
std::string &raw_input_string,
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=262901&r1=262900&r2=262901&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Mon Mar 7 21:00:27 2016
@@ -620,11 +620,10 @@ protected:
// Verify & handle any options/arguments passed to the alias command
OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
- OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
-
+
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false);
- if (!m_interpreter.ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp))
+ if (!CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp))
{
result.AppendError ("Unable to create requested alias.\n");
result.SetStatus (eReturnStatusFailed);
@@ -688,7 +687,6 @@ protected:
CommandObject *cmd_obj = command_obj_sp.get();
CommandObject *sub_cmd_obj = nullptr;
OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
- OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
while (cmd_obj->IsMultiwordObject() && args.GetArgumentCount() > 0)
{
@@ -726,7 +724,7 @@ protected:
std::string args_string;
args.GetCommandString (args_string);
- if (!m_interpreter.ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp))
+ if (!CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp))
{
result.AppendError ("Unable to create requested alias.\n");
result.SetStatus (eReturnStatusFailed);
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=262901&r1=262900&r2=262901&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Mar 7 21:00:27 2016
@@ -97,6 +97,59 @@ enum
eSpaceReplPrompts = 3
};
+bool
+CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
+ const char *options_args,
+ OptionArgVectorSP &option_arg_vector_sp)
+{
+ bool success = true;
+ OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
+
+ if (!options_args || (strlen (options_args) < 1))
+ return true;
+
+ std::string options_string (options_args);
+ Args args (options_args);
+ CommandReturnObject result;
+ // Check to see if the command being aliased can take any command options.
+ Options *options = cmd_obj_sp->GetOptions ();
+ if (options)
+ {
+ // See if any options were specified as part of the alias; if so, handle them appropriately.
+ options->NotifyOptionParsingStarting ();
+ args.Unshift ("dummy_arg");
+ args.ParseAliasOptions (*options, result, option_arg_vector, options_string);
+ args.Shift ();
+ if (result.Succeeded())
+ options->VerifyPartialOptions (result);
+ if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
+ {
+ result.AppendError ("Unable to create requested alias.\n");
+ return false;
+ }
+ }
+
+ if (!options_string.empty())
+ {
+ if (cmd_obj_sp->WantsRawCommandString ())
+ option_arg_vector->push_back (OptionArgPair ("<argument>",
+ OptionArgValue (-1,
+ options_string)));
+ else
+ {
+ const size_t argc = args.GetArgumentCount();
+ for (size_t i = 0; i < argc; ++i)
+ if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
+ option_arg_vector->push_back
+ (OptionArgPair ("<argument>",
+ OptionArgValue (-1,
+ std::string (args.GetArgumentAtIndex (i)))));
+ }
+ }
+
+ return success;
+}
+
ConstString &
CommandInterpreter::GetStaticBroadcasterClass ()
{
@@ -244,7 +297,7 @@ CommandInterpreter::Initialize ()
AddAlias ("step", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset (new OptionArgVector);
- ProcessAliasOptionsArgs (cmd_obj_sp, "--end-linenumber block --step-in-target %1", alias_arguments_vector_sp);
+ CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--end-linenumber block --step-in-target %1", alias_arguments_vector_sp);
AddAlias ("sif", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
@@ -342,12 +395,12 @@ CommandInterpreter::Initialize ()
cmd_obj_sp = GetCommandSPExact ("expression", false);
if (cmd_obj_sp)
{
- ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
+ CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp);
AddAlias ("p", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("print", cmd_obj_sp, alias_arguments_vector_sp);
AddAlias ("call", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset (new OptionArgVector);
- ProcessAliasOptionsArgs (cmd_obj_sp, "-O -- ", alias_arguments_vector_sp);
+ CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "-O -- ", alias_arguments_vector_sp);
AddAlias ("po", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
@@ -370,7 +423,7 @@ CommandInterpreter::Initialize ()
shell_option.append("--shell-expand-args");
shell_option.append(" true");
shell_option.append(" --");
- ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
+ CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, shell_option.c_str(), alias_arguments_vector_sp);
#else
std::string shell_option;
shell_option.append("--shell=");
@@ -394,7 +447,7 @@ CommandInterpreter::Initialize ()
if (cmd_obj_sp)
{
alias_arguments_vector_sp.reset (new OptionArgVector);
- ProcessAliasOptionsArgs (cmd_obj_sp, "--func-regex %1", alias_arguments_vector_sp);
+ CommandAlias::ProcessAliasOptionsArgs (cmd_obj_sp, "--func-regex %1", alias_arguments_vector_sp);
AddAlias ("rbreak", cmd_obj_sp, alias_arguments_vector_sp);
alias_arguments_vector_sp.reset(new OptionArgVector);
}
@@ -1017,59 +1070,6 @@ CommandInterpreter::CommandExists (const
}
bool
-CommandInterpreter::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
- const char *options_args,
- OptionArgVectorSP &option_arg_vector_sp)
-{
- bool success = true;
- OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
-
- if (!options_args || (strlen (options_args) < 1))
- return true;
-
- std::string options_string (options_args);
- Args args (options_args);
- CommandReturnObject result;
- // Check to see if the command being aliased can take any command options.
- Options *options = cmd_obj_sp->GetOptions ();
- if (options)
- {
- // See if any options were specified as part of the alias; if so, handle them appropriately.
- options->NotifyOptionParsingStarting ();
- args.Unshift ("dummy_arg");
- args.ParseAliasOptions (*options, result, option_arg_vector, options_string);
- args.Shift ();
- if (result.Succeeded())
- options->VerifyPartialOptions (result);
- if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
- {
- result.AppendError ("Unable to create requested alias.\n");
- return false;
- }
- }
-
- if (!options_string.empty())
- {
- if (cmd_obj_sp->WantsRawCommandString ())
- option_arg_vector->push_back (OptionArgPair ("<argument>",
- OptionArgValue (-1,
- options_string)));
- else
- {
- const size_t argc = args.GetArgumentCount();
- for (size_t i = 0; i < argc; ++i)
- if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
- option_arg_vector->push_back
- (OptionArgPair ("<argument>",
- OptionArgValue (-1,
- std::string (args.GetArgumentAtIndex (i)))));
- }
- }
-
- return success;
-}
-
-bool
CommandInterpreter::GetAliasFullName (const char *cmd, std::string &full_name)
{
bool exact_match = (m_alias_dict.find(cmd) != m_alias_dict.end());
More information about the lldb-commits
mailing list