[Lldb-commits] [lldb] r283385 - Update some command aliasing functions to use StringRef.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 5 14:14:49 PDT 2016


Author: zturner
Date: Wed Oct  5 16:14:49 2016
New Revision: 283385

URL: http://llvm.org/viewvc/llvm-project?rev=283385&view=rev
Log:
Update some command aliasing functions to use StringRef.

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

Modified: lldb/trunk/include/lldb/Interpreter/CommandAlias.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandAlias.h?rev=283385&r1=283384&r2=283385&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandAlias.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandAlias.h Wed Oct  5 16:14:49 2016
@@ -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)

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=283385&r1=283384&r2=283385&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed Oct  5 16:14:49 2016
@@ -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);

Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=283385&r1=283384&r2=283385&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Wed Oct  5 16:14:49 2016
@@ -174,7 +174,7 @@ bool CommandObjectHelp::DoExecute(Args &
 
       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());
       }

Modified: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=283385&r1=283384&r2=283385&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Wed Oct  5 16:14:49 2016
@@ -143,7 +143,7 @@ bool CommandAlias::Execute(const char *a
   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());
 

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=283385&r1=283384&r2=283385&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Oct  5 16:14:49 2016
@@ -906,7 +906,7 @@ bool CommandInterpreter::AddCommand(llvm
   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(
            "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::GetCo
   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::GetAliasFullNam
   }
 }
 
-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
   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(con
   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(c
   }
   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 &
 }
 
 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 c
   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();
 




More information about the lldb-commits mailing list