From 002ab61a47a80f13ff4318d690aa96646f67f257 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Tue, 8 Mar 2016 03:56:12 +0000 Subject: [PATCH] Turn GetAliasOptions() into GetAlias() Eventually, there will be more things that CommandAlias contains, and I don't want accessors for each of them on the CommandIntepreter Eventually, we also won't pass around copies of CommandAlias, but that's for a later patch llvm-svn: 262909 --- .../lldb/Interpreter/CommandInterpreter.h | 22 +++++++++++++++---- .../source/Interpreter/CommandInterpreter.cpp | 21 ++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 5aaeccb7f545..e27cd45c97dd 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -202,13 +202,27 @@ class CommandInterpreter : public: struct CommandAlias { - lldb::CommandObjectSP m_underlying_command_sp; - OptionArgVectorSP m_option_args_sp; + lldb::CommandObjectSP m_underlying_command_sp = nullptr; + OptionArgVectorSP m_option_args_sp = nullptr; + + CommandAlias (lldb::CommandObjectSP cmd_sp = nullptr, + OptionArgVectorSP args_sp = nullptr); static bool ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp, const char *options_args, OptionArgVectorSP &option_arg_vector_sp); + + bool + IsValid () + { + return m_underlying_command_sp && m_option_args_sp; + } + + explicit operator bool () + { + return IsValid(); + } }; typedef std::map CommandAliasMap; @@ -312,8 +326,8 @@ public: m_user_dict.clear(); } - OptionArgVectorSP - GetAliasOptions (const char *alias_name); + CommandAlias + GetAlias (const char *alias_name); CommandObject * BuildAliasResult (const char *alias_name, diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index bfbfabbd469b..2c8699d25795 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -97,6 +97,13 @@ enum eSpaceReplPrompts = 3 }; +CommandInterpreter::CommandAlias::CommandAlias (lldb::CommandObjectSP cmd_sp, + OptionArgVectorSP args_sp) : + m_underlying_command_sp(cmd_sp), + m_option_args_sp(args_sp) +{ +} + bool CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp, const char *options_args, @@ -1170,7 +1177,7 @@ void CommandInterpreter::GetAliasHelp (const char *alias_name, const char *command_name, StreamString &help_string) { help_string.Printf ("'%s", command_name); - OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name); + OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp; if (option_arg_vector_sp) { @@ -1456,7 +1463,7 @@ CommandInterpreter::BuildAliasResult (const char *alias_name, cmd_args.Unshift (alias_name); result_str.Printf ("%s", alias_cmd_obj->GetCommandName ()); - OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name); + OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp; if (option_arg_vector_sp.get()) { @@ -2083,8 +2090,8 @@ CommandInterpreter::Confirm (const char *message, bool default_answer) return confirm->GetResponse(); } -OptionArgVectorSP -CommandInterpreter::GetAliasOptions (const char *alias_name) +CommandInterpreter::CommandAlias +CommandInterpreter::GetAlias (const char *alias_name) { OptionArgVectorSP ret_val; @@ -2092,9 +2099,9 @@ CommandInterpreter::GetAliasOptions (const char *alias_name) auto pos = m_alias_dict.find(alias); if (pos != m_alias_dict.end()) - ret_val = pos->second.m_option_args_sp; + return pos->second; - return ret_val; + return CommandInterpreter::CommandAlias(); } bool @@ -2128,7 +2135,7 @@ CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, std::string &raw_input_string, CommandReturnObject &result) { - OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name); + OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp; bool wants_raw_input = alias_cmd_obj->WantsRawCommandString();