Update some command aliasing functions to use StringRef.
authorZachary Turner <zturner@google.com>
Wed, 5 Oct 2016 21:14:49 +0000 (21:14 +0000)
committerZachary Turner <zturner@google.com>
Wed, 5 Oct 2016 21:14:49 +0000 (21:14 +0000)
llvm-svn: 283385

lldb/include/lldb/Interpreter/CommandAlias.h
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/source/Commands/CommandObjectHelp.cpp
lldb/source/Interpreter/CommandAlias.cpp
lldb/source/Interpreter/CommandInterpreter.cpp

index 69e5d2d..049d54f 100644 (file)
@@ -30,11 +30,11 @@ public:
                llvm::StringRef help = llvm::StringRef(),
                llvm::StringRef syntax = llvm::StringRef(), uint32_t flags = 0);
 
-  void GetAliasExpansion(StreamString &help_string);
+  void GetAliasExpansion(StreamString &help_string) const;
 
-  bool IsValid() { return m_underlying_command_sp && m_option_args_sp; }
+  bool IsValid() const { return m_underlying_command_sp && m_option_args_sp; }
 
-  explicit operator bool() { return IsValid(); }
+  explicit operator bool() const { return IsValid(); }
 
   bool WantsRawCommandString() override;
 
@@ -71,7 +71,7 @@ public:
   lldb::CommandObjectSP GetUnderlyingCommand() {
     return m_underlying_command_sp;
   }
-  OptionArgVectorSP GetOptionArguments() { return m_option_args_sp; }
+  OptionArgVectorSP GetOptionArguments() const { return m_option_args_sp; }
   const char *GetOptionString() { return m_option_string.c_str(); }
 
   // this takes an alias - potentially nested (i.e. an alias to an alias)
index 820731a..c57d743 100644 (file)
@@ -197,9 +197,8 @@ public:
 
   bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
                   bool can_replace);
-  bool AddCommand(const char *, const lldb::CommandObjectSP &, bool) = delete;
 
-  bool AddUserCommand(std::string name, const lldb::CommandObjectSP &cmd_sp,
+  bool AddUserCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
                       bool can_replace);
 
   lldb::CommandObjectSP GetCommandSPExact(llvm::StringRef cmd,
@@ -208,30 +207,30 @@ public:
   CommandObject *GetCommandObject(llvm::StringRef cmd,
                                   StringList *matches = nullptr) const;
 
-  bool CommandExists(const char *cmd);
+  bool CommandExists(llvm::StringRef cmd) const;
 
-  bool AliasExists(const char *cmd);
+  bool AliasExists(llvm::StringRef cmd) const;
 
-  bool UserCommandExists(const char *cmd);
+  bool UserCommandExists(llvm::StringRef cmd) const;
 
-  CommandAlias *AddAlias(const char *alias_name,
+  CommandAlias *AddAlias(llvm::StringRef alias_name,
                          lldb::CommandObjectSP &command_obj_sp,
-                         const char *args_string = nullptr);
+                         llvm::StringRef args_string = llvm::StringRef());
 
   // Remove a command if it is removable (python or regex command)
-  bool RemoveCommand(const char *cmd);
+  bool RemoveCommand(llvm::StringRef cmd);
 
-  bool RemoveAlias(const char *alias_name);
+  bool RemoveAlias(llvm::StringRef alias_name);
 
-  bool GetAliasFullName(const char *cmd, std::string &full_name);
+  bool GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const;
 
-  bool RemoveUser(const char *alias_name);
+  bool RemoveUser(llvm::StringRef alias_name);
 
   void RemoveAllUser() { m_user_dict.clear(); }
 
-  CommandAlias *GetAlias(const char *alias_name);
+  const CommandAlias *GetAlias(llvm::StringRef alias_name) const;
 
-  CommandObject *BuildAliasResult(const char *alias_name,
+  CommandObject *BuildAliasResult(llvm::StringRef alias_name,
                                   std::string &raw_input_string,
                                   std::string &alias_result,
                                   CommandReturnObject &result);
index 1495e93..7d1fdcf 100644 (file)
@@ -174,7 +174,7 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
 
       if (is_alias_command) {
         StreamString sstr;
-        m_interpreter.GetAlias(alias_name.c_str())->GetAliasExpansion(sstr);
+        m_interpreter.GetAlias(alias_name)->GetAliasExpansion(sstr);
         result.GetOutputStream().Printf("\n'%s' is an abbreviation for %s\n",
                                         alias_name.c_str(), sstr.GetData());
       }
index 8fba076..c75615f 100644 (file)
@@ -143,7 +143,7 @@ bool CommandAlias::Execute(const char *args_string,
   llvm_unreachable("CommandAlias::Execute is not to be called");
 }
 
-void CommandAlias::GetAliasExpansion(StreamString &help_string) {
+void CommandAlias::GetAliasExpansion(StreamString &help_string) const {
   llvm::StringRef command_name = m_underlying_command_sp->GetCommandName();
   help_string.Printf("'%*s", (int)command_name.size(), command_name.data());
 
index fa0560a..1850f87 100644 (file)
@@ -906,7 +906,7 @@ bool CommandInterpreter::AddCommand(llvm::StringRef name,
   return true;
 }
 
-bool CommandInterpreter::AddUserCommand(std::string name,
+bool CommandInterpreter::AddUserCommand(llvm::StringRef name,
                                         const lldb::CommandObjectSP &cmd_sp,
                                         bool can_replace) {
   if (cmd_sp.get())
@@ -914,17 +914,15 @@ bool CommandInterpreter::AddUserCommand(std::string name,
            "tried to add a CommandObject from a different interpreter");
 
   if (!name.empty()) {
-    const char *name_cstr = name.c_str();
-
     // do not allow replacement of internal commands
-    if (CommandExists(name_cstr)) {
+    if (CommandExists(name)) {
       if (can_replace == false)
         return false;
       if (m_command_dict[name]->IsRemovable() == false)
         return false;
     }
 
-    if (UserCommandExists(name_cstr)) {
+    if (UserCommandExists(name)) {
       if (can_replace == false)
         return false;
       if (m_user_dict[name]->IsRemovable() == false)
@@ -1015,12 +1013,12 @@ CommandObject *CommandInterpreter::GetCommandObject(llvm::StringRef cmd_str,
   return GetCommandSP(cmd_str, true, false, matches).get();
 }
 
-bool CommandInterpreter::CommandExists(const char *cmd) {
+bool CommandInterpreter::CommandExists(llvm::StringRef cmd) const {
   return m_command_dict.find(cmd) != m_command_dict.end();
 }
 
-bool CommandInterpreter::GetAliasFullName(const char *cmd,
-                                          std::string &full_name) {
+bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd,
+                                          std::string &full_name) const {
   bool exact_match = (m_alias_dict.find(cmd) != m_alias_dict.end());
   if (exact_match) {
     full_name.assign(cmd);
@@ -1048,18 +1046,18 @@ bool CommandInterpreter::GetAliasFullName(const char *cmd,
   }
 }
 
-bool CommandInterpreter::AliasExists(const char *cmd) {
+bool CommandInterpreter::AliasExists(llvm::StringRef cmd) const {
   return m_alias_dict.find(cmd) != m_alias_dict.end();
 }
 
-bool CommandInterpreter::UserCommandExists(const char *cmd) {
+bool CommandInterpreter::UserCommandExists(llvm::StringRef cmd) const {
   return m_user_dict.find(cmd) != m_user_dict.end();
 }
 
 CommandAlias *
-CommandInterpreter::AddAlias(const char *alias_name,
+CommandInterpreter::AddAlias(llvm::StringRef alias_name,
                              lldb::CommandObjectSP &command_obj_sp,
-                             const char *args_string) {
+                             llvm::StringRef args_string) {
   if (command_obj_sp.get())
     assert((this == &command_obj_sp->GetCommandInterpreter()) &&
            "tried to add a CommandObject from a different interpreter");
@@ -1075,7 +1073,7 @@ CommandInterpreter::AddAlias(const char *alias_name,
   return nullptr;
 }
 
-bool CommandInterpreter::RemoveAlias(const char *alias_name) {
+bool CommandInterpreter::RemoveAlias(llvm::StringRef alias_name) {
   auto pos = m_alias_dict.find(alias_name);
   if (pos != m_alias_dict.end()) {
     m_alias_dict.erase(pos);
@@ -1084,7 +1082,7 @@ bool CommandInterpreter::RemoveAlias(const char *alias_name) {
   return false;
 }
 
-bool CommandInterpreter::RemoveCommand(const char *cmd) {
+bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd) {
   auto pos = m_command_dict.find(cmd);
   if (pos != m_command_dict.end()) {
     if (pos->second->IsRemovable()) {
@@ -1095,7 +1093,7 @@ bool CommandInterpreter::RemoveCommand(const char *cmd) {
   }
   return false;
 }
-bool CommandInterpreter::RemoveUser(const char *alias_name) {
+bool CommandInterpreter::RemoveUser(llvm::StringRef alias_name) {
   CommandObject::CommandMap::iterator pos = m_user_dict.find(alias_name);
   if (pos != m_user_dict.end()) {
     m_user_dict.erase(pos);
@@ -1313,7 +1311,7 @@ static bool ExtractCommand(std::string &command_string, std::string &command,
 }
 
 CommandObject *CommandInterpreter::BuildAliasResult(
-    const char *alias_name, std::string &raw_input_string,
+    llvm::StringRef alias_name, std::string &raw_input_string,
     std::string &alias_result, CommandReturnObject &result) {
   CommandObject *alias_cmd_obj = nullptr;
   Args cmd_args(raw_input_string);
@@ -1917,12 +1915,11 @@ bool CommandInterpreter::Confirm(const char *message, bool default_answer) {
   return confirm->GetResponse();
 }
 
-CommandAlias *CommandInterpreter::GetAlias(const char *alias_name) {
+const CommandAlias *
+CommandInterpreter::GetAlias(llvm::StringRef alias_name) const {
   OptionArgVectorSP ret_val;
 
-  std::string alias(alias_name);
-
-  auto pos = m_alias_dict.find(alias);
+  auto pos = m_alias_dict.find(alias_name);
   if (pos != m_alias_dict.end())
     return (CommandAlias *)pos->second.get();