[Lldb-commits] [lldb] r262958 - Move CommandAlias to its own file; also

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 8 13:23:31 PST 2016


Author: enrico
Date: Tue Mar  8 15:23:30 2016
New Revision: 262958

URL: http://llvm.org/viewvc/llvm-project?rev=262958&view=rev
Log:
Move CommandAlias to its own file; also
Store std::unique_ptr<CommandAlias> instead of instances


Added:
    lldb/trunk/include/lldb/Interpreter/CommandAlias.h
    lldb/trunk/source/Interpreter/CommandAlias.cpp
Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Commands/CommandObjectHelp.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Added: lldb/trunk/include/lldb/Interpreter/CommandAlias.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandAlias.h?rev=262958&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandAlias.h (added)
+++ lldb/trunk/include/lldb/Interpreter/CommandAlias.h Tue Mar  8 15:23:30 2016
@@ -0,0 +1,59 @@
+//===-- CommandAlias.h -----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_CommandAlias_h_
+#define liblldb_CommandAlias_h_
+
+// C Includes
+// C++ Includes
+#include <memory>
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-forward.h"
+#include "lldb/Interpreter/Args.h"
+
+namespace lldb_private {
+class CommandAlias
+{
+public:
+    typedef std::unique_ptr<CommandAlias> UniquePointer;
+
+    static bool
+    ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
+                             const char *options_args,
+                             OptionArgVectorSP &option_arg_vector_sp);
+
+    CommandAlias (lldb::CommandObjectSP cmd_sp = nullptr,
+                  OptionArgVectorSP args_sp = nullptr);
+    
+    void
+    GetAliasHelp (StreamString &help_string);
+    
+    bool
+    IsValid ()
+    {
+        return m_underlying_command_sp && m_option_args_sp;
+    }
+    
+    explicit operator bool ()
+    {
+        return IsValid();
+    }
+    
+    lldb::CommandObjectSP GetUnderlyingCommand() { return m_underlying_command_sp; }
+    OptionArgVectorSP GetOptionArguments() { return m_option_args_sp; }
+    
+private:
+    lldb::CommandObjectSP m_underlying_command_sp;
+    OptionArgVectorSP m_option_args_sp ;
+};
+} // namespace lldb_private
+
+#endif // liblldb_CommandAlias_h_

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=262958&r1=262957&r2=262958&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Tue Mar  8 15:23:30 2016
@@ -20,6 +20,7 @@
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/IOHandler.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Interpreter/CommandAlias.h"
 #include "lldb/Interpreter/CommandHistory.h"
 #include "lldb/Interpreter/CommandObject.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
@@ -200,35 +201,7 @@ class CommandInterpreter :
     public IOHandlerDelegate
 {
 public:
-    struct CommandAlias
-    {
-        lldb::CommandObjectSP m_underlying_command_sp = nullptr;
-        OptionArgVectorSP m_option_args_sp = nullptr;
-        
-        CommandAlias (lldb::CommandObjectSP cmd_sp = nullptr,
-                      OptionArgVectorSP args_sp = nullptr);
-        
-        void
-        GetAliasHelp (StreamString &help_string);
-        
-        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<std::string, CommandAlias> CommandAliasMap;
+    typedef std::map<std::string, CommandAlias::UniquePointer> CommandAliasMap;
     
     enum
     {
@@ -329,7 +302,7 @@ public:
         m_user_dict.clear();
     }
 
-    CommandAlias
+    CommandAlias*
     GetAlias (const char *alias_name);
 
     CommandObject *

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=262958&r1=262957&r2=262958&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Tue Mar  8 15:23:30 2016
@@ -37,38 +37,23 @@ template <typename ValueType>
 int
 AddNamesMatchingPartialString (std::map<std::string,ValueType> &in_map, const char *cmd_str, StringList &matches)
 {
-    class CommandDictCommandPartialMatch
-    {
-    public:
-        CommandDictCommandPartialMatch (const char *match_str)
-        {
-            m_match_str = match_str;
-        }
-        bool operator() (const std::pair<std::string, ValueType> map_element) const
-        {
-            // A NULL or empty string matches everything.
-            if (m_match_str == nullptr || *m_match_str == '\0')
-                return true;
-            
-            return map_element.first.find (m_match_str, 0) == 0;
-        }
-        
-    private:
-        const char *m_match_str;
-    };
-
     int number_added = 0;
-    CommandDictCommandPartialMatch matcher(cmd_str);
     
-    auto matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
+    const bool add_all = ((cmd_str == nullptr) || (cmd_str[0] == 0));
     
-    while (matching_cmds != in_map.end())
+    for (auto iter = in_map.begin(), end = in_map.end();
+         iter != end;
+         iter++)
     {
-        ++number_added;
-        matches.AppendString((*matching_cmds).first.c_str());
-        matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
+        if (add_all ||
+            (iter->first.find(cmd_str,0) == 0))
+        {
+            ++number_added;
+            matches.AppendString(iter->first.c_str());
+        }
     }
-    return number_added;    
+    
+    return number_added;
 }
 
 template <typename ValueType>

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=262958&r1=262957&r2=262958&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Mar  8 15:23:30 2016
@@ -753,6 +753,7 @@
 		9428BC2C1C6E64E4002A24D7 /* LibCxxAtomic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9428BC291C6E64DC002A24D7 /* LibCxxAtomic.cpp */; };
 		94380B8219940B0A00BFE4A8 /* StringLexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */; };
 		943BDEFE1AA7B2F800789CE8 /* LLDBAssert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */; };
+		9441816E1C8F5EC900E5A8D9 /* CommandAlias.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9441816D1C8F5EC900E5A8D9 /* CommandAlias.cpp */; };
 		944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */; };
 		9443B122140C18C40013457C /* SBData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };
 		9443B123140C26AB0013457C /* SBData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9443B120140C18A90013457C /* SBData.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -2496,6 +2497,8 @@
 		943B90FC1B991586007BA499 /* VectorIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VectorIterator.h; path = include/lldb/DataFormatters/VectorIterator.h; sourceTree = "<group>"; };
 		943BDEFC1AA7B2DE00789CE8 /* LLDBAssert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = LLDBAssert.h; path = include/lldb/Utility/LLDBAssert.h; sourceTree = "<group>"; };
 		943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLDBAssert.cpp; path = source/Utility/LLDBAssert.cpp; sourceTree = "<group>"; };
+		9441816B1C8F5EB000E5A8D9 /* CommandAlias.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CommandAlias.h; path = include/lldb/Interpreter/CommandAlias.h; sourceTree = "<group>"; };
+		9441816D1C8F5EC900E5A8D9 /* CommandAlias.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandAlias.cpp; path = source/Interpreter/CommandAlias.cpp; sourceTree = "<group>"; };
 		944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterContextDummy.cpp; path = Utility/RegisterContextDummy.cpp; sourceTree = "<group>"; };
 		944372DB171F6B4300E57C32 /* RegisterContextDummy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterContextDummy.h; path = Utility/RegisterContextDummy.h; sourceTree = "<group>"; };
 		9443B120140C18A90013457C /* SBData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path = include/lldb/API/SBData.h; sourceTree = "<group>"; };
@@ -4665,6 +4668,8 @@
 				26BC7D5310F1B77400F91463 /* Args.h */,
 				26BC7E6C10F1B85900F91463 /* Args.cpp */,
 				26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */,
+				9441816B1C8F5EB000E5A8D9 /* CommandAlias.h */,
+				9441816D1C8F5EC900E5A8D9 /* CommandAlias.cpp */,
 				4C09CB73116BD98B00C7A725 /* CommandCompletions.h */,
 				4C09CB74116BD98B00C7A725 /* CommandCompletions.cpp */,
 				94BA8B71176F97D4005A91B5 /* CommandHistory.h */,
@@ -6481,6 +6486,7 @@
 				AFEC3362194A8ABA00FF05C6 /* StructuredData.cpp in Sources */,
 				6D55B2901A8A806200A70529 /* GDBRemoteCommunicationServerCommon.cpp in Sources */,
 				26474CAC18D0CB070073DEBA /* RegisterContextFreeBSD_x86_64.cpp in Sources */,
+				9441816E1C8F5EC900E5A8D9 /* CommandAlias.cpp in Sources */,
 				2689001713353DDE00698AC0 /* CommandObjectDisassemble.cpp in Sources */,
 				2689001813353DDE00698AC0 /* CommandObjectExpression.cpp in Sources */,
 				9404957B1BEC497E00926025 /* NSException.cpp in Sources */,

Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=262958&r1=262957&r2=262958&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Tue Mar  8 15:23:30 2016
@@ -189,7 +189,7 @@ CommandObjectHelp::DoExecute (Args& comm
             if (is_alias_command)
             {
                 StreamString sstr;
-                m_interpreter.GetAlias(alias_name.c_str()).GetAliasHelp(sstr);
+                m_interpreter.GetAlias(alias_name.c_str())->GetAliasHelp(sstr);
                 result.GetOutputStream().Printf ("\n'%s' is an abbreviation for %s\n", alias_name.c_str(), sstr.GetData());
             }
         }

Added: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=262958&view=auto
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (added)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Tue Mar  8 15:23:30 2016
@@ -0,0 +1,11 @@
+//===-- CommandAlias.cpp ------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Interpreter/CommandAlias.h"
+

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=262958&r1=262957&r2=262958&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Mar  8 15:23:30 2016
@@ -97,15 +97,15 @@ enum
     eSpaceReplPrompts = 3
 };
 
-CommandInterpreter::CommandAlias::CommandAlias (lldb::CommandObjectSP cmd_sp,
-                                                OptionArgVectorSP args_sp) :
+CommandAlias::CommandAlias (lldb::CommandObjectSP cmd_sp,
+                            OptionArgVectorSP args_sp) :
     m_underlying_command_sp(cmd_sp),
     m_option_args_sp(args_sp)
 {
 }
 
 void
-CommandInterpreter::CommandAlias::GetAliasHelp (StreamString &help_string)
+CommandAlias::GetAliasHelp (StreamString &help_string)
 {
     const char* command_name = m_underlying_command_sp->GetCommandName();
     help_string.Printf ("'%s", command_name);
@@ -139,9 +139,9 @@ CommandInterpreter::CommandAlias::GetAli
 }
 
 bool
-CommandInterpreter::CommandAlias::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp,
-                                                           const char *options_args,
-                                                           OptionArgVectorSP &option_arg_vector_sp)
+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();
@@ -866,7 +866,7 @@ CommandInterpreter::GetCommandSP (const
     {
         CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
         if (alias_pos != m_alias_dict.end())
-            command_sp = alias_pos->second.m_underlying_command_sp;
+            command_sp = alias_pos->second->GetUnderlyingCommand();
     }
 
     if (HasUserCommands())
@@ -917,7 +917,7 @@ CommandInterpreter::GetCommandSP (const
             cmd.assign(matches->GetStringAtIndex (num_cmd_matches));
             CommandAliasMap::iterator alias_pos = m_alias_dict.find(cmd);
             if (alias_pos != m_alias_dict.end())
-                alias_match_sp = alias_pos->second.m_underlying_command_sp;
+                alias_match_sp = alias_pos->second->GetUnderlyingCommand();
         }
 
         if (HasUserCommands())
@@ -1154,7 +1154,7 @@ CommandInterpreter::AddAlias (const char
     OptionArgVectorSP args_sp(new OptionArgVector);
     if (CommandAlias::ProcessAliasOptionsArgs(command_obj_sp, args_string, args_sp))
     {
-        m_alias_dict[alias_name] = CommandAlias(command_obj_sp,args_sp);
+        m_alias_dict[alias_name] = CommandAlias::UniquePointer(new CommandAlias(command_obj_sp,args_sp));
         return true;
     }
     return false;
@@ -1242,10 +1242,10 @@ CommandInterpreter::GetHelp (CommandRetu
             StreamString sstr;
             StreamString translation_and_help;
             std::string entry_name = alias_pos->first;
-            std::string second_entry = alias_pos->second.m_underlying_command_sp->GetCommandName();
-            alias_pos->second.GetAliasHelp(sstr);
+            std::string second_entry = alias_pos->second->GetUnderlyingCommand()->GetCommandName();
+            alias_pos->second->GetAliasHelp(sstr);
             
-            translation_and_help.Printf ("(%s)  %s", sstr.GetData(), alias_pos->second.m_underlying_command_sp->GetHelp());
+            translation_and_help.Printf ("(%s)  %s", sstr.GetData(), alias_pos->second->GetUnderlyingCommand()->GetHelp());
             OutputFormattedHelpText (result.GetOutputStream(), alias_pos->first.c_str(), "--",
                                      translation_and_help.GetData(), max_len);
         }
@@ -1455,7 +1455,7 @@ CommandInterpreter::BuildAliasResult (co
             cmd_args.Unshift (alias_name);
             
         result_str.Printf ("%s", alias_cmd_obj->GetCommandName ());
-        OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp;
+        OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name)->GetOptionArguments();
 
         if (option_arg_vector_sp.get())
         {
@@ -2082,7 +2082,7 @@ CommandInterpreter::Confirm (const char
     return confirm->GetResponse();
 }
     
-CommandInterpreter::CommandAlias
+CommandAlias*
 CommandInterpreter::GetAlias (const char *alias_name)
 {
     OptionArgVectorSP ret_val;
@@ -2091,9 +2091,9 @@ CommandInterpreter::GetAlias (const char
 
     auto pos = m_alias_dict.find(alias);
     if (pos != m_alias_dict.end())
-        return pos->second;
+        return pos->second.get();
     
-    return CommandInterpreter::CommandAlias();
+    return nullptr;
 }
 
 bool
@@ -2127,7 +2127,7 @@ CommandInterpreter::BuildAliasCommandArg
                                            std::string &raw_input_string,
                                            CommandReturnObject &result)
 {
-    OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name).m_option_args_sp;
+    OptionArgVectorSP option_arg_vector_sp = GetAlias(alias_name)->GetOptionArguments();
     
     bool wants_raw_input = alias_cmd_obj->WantsRawCommandString();
 




More information about the lldb-commits mailing list