Move more functionality from the LanguageRuntimes to the Languages.

llvm-svn: 246616
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index b44ba55..a69e3dc 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -9,8 +9,14 @@
 
 #include "CPlusPlusLanguage.h"
 
+#include <string.h>
+
+#include "llvm/ADT/StringRef.h"
+
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/UniqueCStringMap.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -62,3 +68,373 @@
         return new CPlusPlusLanguage();
     return nullptr;
 }
+
+void
+CPlusPlusLanguage::MethodName::Clear()
+{
+    m_full.Clear();
+    m_basename = llvm::StringRef();
+    m_context = llvm::StringRef();
+    m_arguments = llvm::StringRef();
+    m_qualifiers = llvm::StringRef();
+    m_type = eTypeInvalid;
+    m_parsed = false;
+    m_parse_error = false;
+}
+
+bool
+ReverseFindMatchingChars (const llvm::StringRef &s,
+                          const llvm::StringRef &left_right_chars,
+                          size_t &left_pos,
+                          size_t &right_pos,
+                          size_t pos = llvm::StringRef::npos)
+{
+    assert (left_right_chars.size() == 2);
+    left_pos = llvm::StringRef::npos;
+    const char left_char = left_right_chars[0];
+    const char right_char = left_right_chars[1];
+    pos = s.find_last_of(left_right_chars, pos);
+    if (pos == llvm::StringRef::npos || s[pos] == left_char)
+        return false;
+    right_pos = pos;
+    uint32_t depth = 1;
+    while (pos > 0 && depth > 0)
+    {
+        pos = s.find_last_of(left_right_chars, pos);
+        if (pos == llvm::StringRef::npos)
+            return false;
+        if (s[pos] == left_char)
+        {
+            if (--depth == 0)
+            {
+                left_pos = pos;
+                return left_pos < right_pos;
+            }            
+        }
+        else if (s[pos] == right_char)
+        {
+            ++depth;
+        }
+    }
+    return false;
+}
+
+
+void
+CPlusPlusLanguage::MethodName::Parse()
+{
+    if (!m_parsed && m_full)
+    {
+//        ConstString mangled;
+//        m_full.GetMangledCounterpart(mangled);
+//        printf ("\n   parsing = '%s'\n", m_full.GetCString());
+//        if (mangled)
+//            printf ("   mangled = '%s'\n", mangled.GetCString());
+        m_parse_error = false;
+        m_parsed = true;
+        llvm::StringRef full (m_full.GetCString());
+        
+        size_t arg_start, arg_end;
+        llvm::StringRef parens("()", 2);
+        if (ReverseFindMatchingChars (full, parens, arg_start, arg_end))
+        {
+            m_arguments = full.substr(arg_start, arg_end - arg_start + 1);
+            if (arg_end + 1 < full.size())
+                m_qualifiers = full.substr(arg_end + 1);
+            if (arg_start > 0)
+            {
+                size_t basename_end = arg_start;
+                size_t context_start = 0;
+                size_t context_end = llvm::StringRef::npos;
+                if (basename_end > 0 && full[basename_end-1] == '>')
+                {
+                    // TODO: handle template junk...
+                    // Templated function
+                    size_t template_start, template_end;
+                    llvm::StringRef lt_gt("<>", 2);
+                    if (ReverseFindMatchingChars (full, lt_gt, template_start, template_end, basename_end))
+                    {
+                        // Check for templated functions that include return type like: 'void foo<Int>()'
+                        context_start = full.rfind(' ', template_start);
+                        if (context_start == llvm::StringRef::npos)
+                            context_start = 0;
+
+                        context_end = full.rfind(':', template_start);
+                        if (context_end == llvm::StringRef::npos || context_end < context_start)
+                            context_end = context_start;
+                    }
+                    else
+                    {
+                        context_end = full.rfind(':', basename_end);
+                    }
+                }
+                else if (context_end == llvm::StringRef::npos)
+                {
+                    context_end = full.rfind(':', basename_end);
+                }
+
+                if (context_end == llvm::StringRef::npos)
+                    m_basename = full.substr(0, basename_end);
+                else
+                {
+                    if (context_start < context_end)
+                        m_context = full.substr(context_start, context_end - 1);
+                    const size_t basename_begin = context_end + 1;
+                    m_basename = full.substr(basename_begin, basename_end - basename_begin);
+                }
+                m_type = eTypeUnknownMethod;
+            }
+            else
+            {
+                m_parse_error = true;
+                return;
+            }
+        
+//            if (!m_context.empty())
+//                printf ("   context = '%s'\n", m_context.str().c_str());
+//            if (m_basename)
+//                printf ("  basename = '%s'\n", m_basename.GetCString());
+//            if (!m_arguments.empty())
+//                printf (" arguments = '%s'\n", m_arguments.str().c_str());
+//            if (!m_qualifiers.empty())
+//                printf ("qualifiers = '%s'\n", m_qualifiers.str().c_str());
+
+            // Make sure we have a valid C++ basename with optional template args
+            static RegularExpression g_identifier_regex("^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$");
+            std::string basename_str(m_basename.str());
+            bool basename_is_valid = g_identifier_regex.Execute (basename_str.c_str(), NULL);
+            if (!basename_is_valid)
+            {
+                // Check for C++ operators
+                if (m_basename.startswith("operator"))
+                {
+                    static RegularExpression g_operator_regex("^(operator)( ?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|\\[\\]|[\\^<>=!\\/*+-]+)(<.*>)?(\\[\\])?$");
+                    basename_is_valid = g_operator_regex.Execute(basename_str.c_str(), NULL);
+                }
+            }
+            if (!basename_is_valid)
+            {
+                // The C++ basename doesn't match our regular expressions so this can't
+                // be a valid C++ method, clear everything out and indicate an error
+                m_context = llvm::StringRef();
+                m_basename = llvm::StringRef();
+                m_arguments = llvm::StringRef();
+                m_qualifiers = llvm::StringRef();
+                m_parse_error = true;
+            }
+        }
+        else
+        {
+            m_parse_error = true;
+//            printf ("error: didn't find matching parens for arguments\n");
+        }
+    }
+}
+
+llvm::StringRef
+CPlusPlusLanguage::MethodName::GetBasename ()
+{
+    if (!m_parsed)
+        Parse();
+    return m_basename;
+}
+
+llvm::StringRef
+CPlusPlusLanguage::MethodName::GetContext ()
+{
+    if (!m_parsed)
+        Parse();
+    return m_context;
+}
+
+llvm::StringRef
+CPlusPlusLanguage::MethodName::GetArguments ()
+{
+    if (!m_parsed)
+        Parse();
+    return m_arguments;
+}
+
+llvm::StringRef
+CPlusPlusLanguage::MethodName::GetQualifiers ()
+{
+    if (!m_parsed)
+        Parse();
+    return m_qualifiers;
+}
+
+bool
+CPlusPlusLanguage::IsCPPMangledName (const char *name)
+{
+    // FIXME, we should really run through all the known C++ Language plugins and ask each one if
+    // this is a C++ mangled name, but we can put that off till there is actually more than one
+    // we care about.
+    
+    if (name && name[0] == '_' && name[1] == 'Z')
+        return true;
+    else
+        return false;
+}
+
+bool
+CPlusPlusLanguage::ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
+{
+    static RegularExpression g_basename_regex("^(([A-Za-z_][A-Za-z_0-9]*::)*)([A-Za-z_][A-Za-z_0-9]*)$");
+    RegularExpression::Match match(4);
+    if (g_basename_regex.Execute (name, &match))
+    {
+        match.GetMatchAtIndex(name, 1, context);
+        match.GetMatchAtIndex(name, 3, identifier);
+        return true;
+    }
+    return false;
+}
+
+class CPPRuntimeEquivalents
+{
+public:
+    CPPRuntimeEquivalents ()
+    {
+        
+        m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("basic_string<char>"));
+
+        // these two (with a prefixed std::) occur when c++stdlib string class occurs as a template argument in some STL container
+        m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("std::basic_string<char>"));
+        
+        m_impl.Sort();
+    }
+    
+    void
+    Add (ConstString& type_name,
+         ConstString& type_equivalent)
+    {
+        m_impl.Insert(type_name.AsCString(), type_equivalent);
+    }
+    
+    uint32_t
+    FindExactMatches (ConstString& type_name,
+                      std::vector<ConstString>& equivalents)
+    {
+        
+        uint32_t count = 0;
+
+        for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString());
+             match != NULL;
+             match = m_impl.FindNextValueForName(match))
+        {
+            equivalents.push_back(match->value);
+            count++;
+        }
+
+        return count;        
+    }
+    
+    // partial matches can occur when a name with equivalents is a template argument.
+    // e.g. we may have "class Foo" be a match for "struct Bar". if we have a typename
+    // such as "class Templatized<class Foo, Anything>" we want this to be replaced with
+    // "class Templatized<struct Bar, Anything>". Since partial matching is time consuming
+    // once we get a partial match, we add it to the exact matches list for faster retrieval
+    uint32_t
+    FindPartialMatches (ConstString& type_name,
+                        std::vector<ConstString>& equivalents)
+    {
+        
+        uint32_t count = 0;
+        
+        const char* type_name_cstr = type_name.AsCString();
+        
+        size_t items_count = m_impl.GetSize();
+        
+        for (size_t item = 0; item < items_count; item++)
+        {
+            const char* key_cstr = m_impl.GetCStringAtIndex(item);
+            if ( strstr(type_name_cstr,key_cstr) )
+            {
+                count += AppendReplacements(type_name_cstr,
+                                            key_cstr,
+                                            equivalents);
+            }
+        }
+        
+        return count;
+        
+    }
+    
+private:
+    
+    std::string& replace (std::string& target,
+                          std::string& pattern,
+                          std::string& with)
+    {
+        size_t pos;
+        size_t pattern_len = pattern.size();
+        
+        while ( (pos = target.find(pattern)) != std::string::npos )
+            target.replace(pos, pattern_len, with);
+        
+        return target;
+    }
+    
+    uint32_t
+    AppendReplacements (const char* original,
+                        const char *matching_key,
+                        std::vector<ConstString>& equivalents)
+    {
+        
+        std::string matching_key_str(matching_key);
+        ConstString original_const(original);
+        
+        uint32_t count = 0;
+        
+        for (ImplData match = m_impl.FindFirstValueForName(matching_key);
+             match != NULL;
+             match = m_impl.FindNextValueForName(match))
+        {
+            std::string target(original);
+            std::string equiv_class(match->value.AsCString());
+            
+            replace (target, matching_key_str, equiv_class);
+            
+            ConstString target_const(target.c_str());
+
+// you will most probably want to leave this off since it might make this map grow indefinitely
+#ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW
+            Add(original_const, target_const);
+#endif
+            equivalents.push_back(target_const);
+            
+            count++;
+        }
+        
+        return count;
+    }
+    
+    typedef UniqueCStringMap<ConstString> Impl;
+    typedef const Impl::Entry* ImplData;
+    Impl m_impl;
+};
+
+static CPPRuntimeEquivalents&
+GetEquivalentsMap ()
+{
+    static CPPRuntimeEquivalents g_equivalents_map;
+    return g_equivalents_map;
+}
+
+
+uint32_t
+CPlusPlusLanguage::FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents)
+{
+    uint32_t count = GetEquivalentsMap().FindExactMatches(type_name, equivalents);
+
+    bool might_have_partials= 
+        ( count == 0 )  // if we have a full name match just use it
+        && (strchr(type_name.AsCString(), '<') != NULL  // we should only have partial matches when templates are involved, check that we have
+            && strchr(type_name.AsCString(), '>') != NULL); // angle brackets in the type_name before trying to scan for partial matches
+    
+    if ( might_have_partials )
+        count = GetEquivalentsMap().FindPartialMatches(type_name, equivalents);
+    
+    return count;
+}
+
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
index 62a92a6..2ede8d8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -12,9 +12,14 @@
 
 // C Includes
 // C++ Includes
+#include <vector>
+
 // Other libraries and framework includes
+#include "llvm/ADT/StringRef.h"
+
 // Project includes
 #include "lldb/lldb-private.h"
+#include "lldb/Core/ConstString.h"
 #include "lldb/Target/Language.h"
 
 namespace lldb_private {
@@ -23,6 +28,94 @@
     public Language
 {
 public:
+    class MethodName
+    {
+    public:
+        enum Type
+        {
+            eTypeInvalid,
+            eTypeUnknownMethod,
+            eTypeClassMethod,
+            eTypeInstanceMethod
+        };
+        
+        MethodName () :
+            m_full(),
+            m_basename(),
+            m_context(),
+            m_arguments(),
+            m_qualifiers(),
+            m_type (eTypeInvalid),
+            m_parsed (false),
+            m_parse_error (false)
+        {
+        }
+
+        MethodName (const ConstString &s) :
+            m_full(s),
+            m_basename(),
+            m_context(),
+            m_arguments(),
+            m_qualifiers(),
+            m_type (eTypeInvalid),
+            m_parsed (false),
+            m_parse_error (false)
+        {
+        }
+
+        void
+        Clear();
+        
+        bool
+        IsValid ()
+        {
+            if (!m_parsed)
+                Parse();
+            if (m_parse_error)
+                return false;
+            if (m_type == eTypeInvalid)
+                return false;
+            return (bool)m_full;
+        }
+
+        Type
+        GetType () const
+        {
+            return m_type;
+        }
+        
+        const ConstString &
+        GetFullName () const
+        {
+            return m_full;
+        }
+        
+        llvm::StringRef
+        GetBasename ();
+
+        llvm::StringRef
+        GetContext ();
+        
+        llvm::StringRef
+        GetArguments ();
+        
+        llvm::StringRef
+        GetQualifiers ();
+
+    protected:
+        void
+        Parse();
+
+        ConstString     m_full;         // Full name:    "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const"
+        llvm::StringRef m_basename;     // Basename:     "GetBreakpointAtIndex"
+        llvm::StringRef m_context;      // Decl context: "lldb::SBTarget"
+        llvm::StringRef m_arguments;    // Arguments:    "(unsigned int)"
+        llvm::StringRef m_qualifiers;   // Qualifiers:   "const"
+        Type m_type;
+        bool m_parsed;
+        bool m_parse_error;
+    };
+
     virtual ~CPlusPlusLanguage() = default;
     
     CPlusPlusLanguage () = default;
@@ -47,6 +140,28 @@
     
     static lldb_private::ConstString
     GetPluginNameStatic();
+
+    static bool
+    IsCPPMangledName(const char *name);
+
+    // Extract C++ context and identifier from a string using heuristic matching (as opposed to
+    // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name with parens and arguments.
+    // If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true,
+    // and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively.
+    // If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false
+    // and identifier and context will be unchanged.
+
+    static bool
+    ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier);
+    
+    // in some cases, compilers will output different names for one same type. when that happens, it might be impossible
+    // to construct SBType objects for a valid type, because the name that is available is not the same as the name that
+    // can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names
+    // for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended
+    // to ObjC or other languages if necessary
+    static uint32_t
+    FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents);
+
     
     //------------------------------------------------------------------
     // PluginInterface protocol
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
index 8f21c46..3f37050 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -11,6 +11,7 @@
 
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/StreamString.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -66,3 +67,234 @@
             return nullptr;
     }
 }
+
+void
+ObjCLanguage::MethodName::Clear()
+{
+    m_full.Clear();
+    m_class.Clear();
+    m_category.Clear();
+    m_selector.Clear();
+    m_type = eTypeUnspecified;
+    m_category_is_valid = false;
+}
+
+bool
+ObjCLanguage::MethodName::SetName (const char *name, bool strict)
+{
+    Clear();
+    if (name && name[0])
+    {
+        // If "strict" is true. then the method must be specified with a
+        // '+' or '-' at the beginning. If "strict" is false, then the '+'
+        // or '-' can be omitted
+        bool valid_prefix = false;
+        
+        if (name[0] == '+' || name[0] == '-')
+        {
+            valid_prefix = name[1] == '[';
+            if (name[0] == '+')
+                m_type = eTypeClassMethod;
+            else
+                m_type = eTypeInstanceMethod;
+        }
+        else if (!strict)
+        {
+            // "strict" is false, the name just needs to start with '['
+            valid_prefix = name[0] == '[';
+        }
+        
+        if (valid_prefix)
+        {
+            int name_len = strlen (name);
+            // Objective C methods must have at least:
+            //      "-[" or "+[" prefix
+            //      One character for a class name
+            //      One character for the space between the class name
+            //      One character for the method name
+            //      "]" suffix
+            if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
+            {
+                m_full.SetCStringWithLength(name, name_len);
+            }
+        }
+    }
+    return IsValid(strict);
+}
+
+const ConstString &
+ObjCLanguage::MethodName::GetClassName ()
+{
+    if (!m_class)
+    {
+        if (IsValid(false))
+        {
+            const char *full = m_full.GetCString();
+            const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+            const char *paren_pos = strchr (class_start, '(');
+            if (paren_pos)
+            {
+                m_class.SetCStringWithLength (class_start, paren_pos - class_start);
+            }
+            else
+            {
+                // No '(' was found in the full name, we can definitively say
+                // that our category was valid (and empty).
+                m_category_is_valid = true;
+                const char *space_pos = strchr (full, ' ');
+                if (space_pos)
+                {
+                    m_class.SetCStringWithLength (class_start, space_pos - class_start);
+                    if (!m_class_category)
+                    {
+                        // No category in name, so we can also fill in the m_class_category
+                        m_class_category = m_class;
+                    }
+                }
+            }
+        }
+    }
+    return m_class;
+}
+
+const ConstString &
+ObjCLanguage::MethodName::GetClassNameWithCategory () 
+{
+    if (!m_class_category)
+    {
+        if (IsValid(false))
+        {
+            const char *full = m_full.GetCString();
+            const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+            const char *space_pos = strchr (full, ' ');
+            if (space_pos)
+            {
+                m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
+                // If m_class hasn't been filled in and the class with category doesn't
+                // contain a '(', then we can also fill in the m_class
+                if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
+                {
+                    m_class = m_class_category;
+                    // No '(' was found in the full name, we can definitively say
+                    // that our category was valid (and empty).
+                    m_category_is_valid = true;
+
+                }
+            }
+        }
+    }
+    return m_class_category;
+}
+
+const ConstString &
+ObjCLanguage::MethodName::GetSelector ()
+{
+    if (!m_selector)
+    {
+        if (IsValid(false))
+        {
+            const char *full = m_full.GetCString();
+            const char *space_pos = strchr (full, ' ');
+            if (space_pos)
+            {
+                ++space_pos; // skip the space
+                m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
+            }
+        }
+    }
+    return m_selector;
+}
+
+const ConstString &
+ObjCLanguage::MethodName::GetCategory ()
+{
+    if (!m_category_is_valid && !m_category)
+    {
+        if (IsValid(false))
+        {
+            m_category_is_valid = true;
+            const char *full = m_full.GetCString();
+            const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+            const char *open_paren_pos = strchr (class_start, '(');
+            if (open_paren_pos)
+            {
+                ++open_paren_pos; // Skip the open paren
+                const char *close_paren_pos = strchr (open_paren_pos, ')');
+                if (close_paren_pos)
+                    m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
+            }
+        }
+    }
+    return m_category;
+}
+
+ConstString
+ObjCLanguage::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
+{
+    if (IsValid(false))
+    {
+        if (HasCategory())
+        {
+            StreamString strm;
+            if (m_type == eTypeClassMethod)
+                strm.PutChar('+');
+            else if (m_type == eTypeInstanceMethod)
+                strm.PutChar('-');
+            strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
+            return ConstString(strm.GetString().c_str());
+        }
+        
+        if (!empty_if_no_category)
+        {
+            // Just return the full name since it doesn't have a category
+            return GetFullName();
+        }
+    }
+    return ConstString();
+}
+
+size_t
+ObjCLanguage::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
+{
+    if (!append)
+        names.clear();
+    if (IsValid(false))
+    {
+        StreamString strm;
+        const bool is_class_method = m_type == eTypeClassMethod;
+        const bool is_instance_method = m_type == eTypeInstanceMethod;
+        const ConstString &category = GetCategory();
+        if (is_class_method || is_instance_method)
+        {
+            names.push_back (m_full);
+            if (category)
+            {
+                strm.Printf("%c[%s %s]",
+                            is_class_method ? '+' : '-',
+                            GetClassName().GetCString(),
+                            GetSelector().GetCString());
+                names.push_back(ConstString(strm.GetString().c_str()));
+            }
+        }
+        else
+        {
+            const ConstString &class_name = GetClassName();
+            const ConstString &selector = GetSelector();
+            strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
+            names.push_back(ConstString(strm.GetString().c_str()));
+            strm.Clear();
+            strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
+            names.push_back(ConstString(strm.GetString().c_str()));
+            strm.Clear();
+            if (category)
+            {
+                strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
+                names.push_back(ConstString(strm.GetString().c_str()));
+                strm.Clear();
+                strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
+                names.push_back(ConstString(strm.GetString().c_str()));
+            }
+        }
+    }
+    return names.size();
+}
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
index 3a43972..70ecf90 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -12,9 +12,12 @@
 
 // C Includes
 // C++ Includes
+#include <vector>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-private.h"
+#include "lldb/Core/ConstString.h"
 #include "lldb/Target/Language.h"
 
 namespace lldb_private {
@@ -23,6 +26,110 @@
     public Language
 {
 public:
+    class MethodName
+    {
+    public:
+        enum Type
+        {
+            eTypeUnspecified,
+            eTypeClassMethod,
+            eTypeInstanceMethod
+        };
+        
+        MethodName () :
+            m_full(),
+            m_class(),
+            m_category(),
+            m_selector(),
+            m_type (eTypeUnspecified),
+            m_category_is_valid (false)
+        {
+        }
+
+        MethodName (const char *name, bool strict) :
+            m_full(),
+            m_class(),
+            m_category(),
+            m_selector(),
+            m_type (eTypeUnspecified),
+            m_category_is_valid (false)
+        {
+            SetName (name, strict);
+        }
+
+        void
+        Clear();
+
+        bool
+        IsValid (bool strict) const
+        {
+            // If "strict" is true, the name must have everything specified including
+            // the leading "+" or "-" on the method name
+            if (strict && m_type == eTypeUnspecified)
+                return false;
+            // Other than that, m_full will only be filled in if the objective C
+            // name is valid.
+            return (bool)m_full;
+        }
+        
+        bool
+        HasCategory()
+        {
+            return !GetCategory();
+        }
+
+        Type
+        GetType () const
+        {
+            return m_type;
+        }
+        
+        const ConstString &
+        GetFullName () const
+        {
+            return m_full;
+        }
+        
+        ConstString
+        GetFullNameWithoutCategory (bool empty_if_no_category);
+
+        bool
+        SetName (const char *name, bool strict);
+
+        const ConstString &
+        GetClassName ();
+
+        const ConstString &
+        GetClassNameWithCategory ();
+
+        const ConstString &
+        GetCategory ();
+        
+        const ConstString &
+        GetSelector ();
+
+        // Get all possible names for a method. Examples:
+        // If name is "+[NSString(my_additions) myStringWithCString:]"
+        //  names[0] => "+[NSString(my_additions) myStringWithCString:]"
+        //  names[1] => "+[NSString myStringWithCString:]"
+        // If name is specified without the leading '+' or '-' like "[NSString(my_additions) myStringWithCString:]"
+        //  names[0] => "+[NSString(my_additions) myStringWithCString:]"
+        //  names[1] => "-[NSString(my_additions) myStringWithCString:]"
+        //  names[2] => "+[NSString myStringWithCString:]"
+        //  names[3] => "-[NSString myStringWithCString:]"
+        size_t
+        GetFullNames (std::vector<ConstString> &names, bool append);
+    protected:
+        ConstString m_full;     // Full name:   "+[NSString(my_additions) myStringWithCString:]"
+        ConstString m_class;    // Class name:  "NSString"
+        ConstString m_class_category; // Class with category: "NSString(my_additions)"
+        ConstString m_category; // Category:    "my_additions"
+        ConstString m_selector; // Selector:    "myStringWithCString:"
+        Type m_type;
+        bool m_category_is_valid;
+
+    };
+
     virtual ~ObjCLanguage() = default;
     
     ObjCLanguage () = default;
@@ -48,6 +155,30 @@
     static lldb_private::ConstString
     GetPluginNameStatic();
     
+    static bool
+    IsPossibleObjCMethodName (const char *name)
+    {
+        if (!name)
+            return false;
+        bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
+        bool ends_right = (name[strlen(name) - 1] == ']');
+        return (starts_right && ends_right);
+    }
+    
+    static bool
+    IsPossibleObjCSelector (const char *name)
+    {
+        if (!name)
+            return false;
+            
+        if (strchr(name, ':') == NULL)
+            return true;
+        else if (name[strlen(name) - 1] == ':')
+            return true;
+        else
+            return false;
+    }
+    
     //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------