[Lldb-commits] [lldb] r166420 - in /lldb/trunk: include/lldb/Symbol/Type.h include/lldb/Symbol/TypeList.h source/Core/Module.cpp source/Symbol/Type.cpp source/Symbol/TypeList.cpp

Greg Clayton gclayton at apple.com
Mon Oct 22 09:19:56 PDT 2012


Author: gclayton
Date: Mon Oct 22 11:19:56 2012
New Revision: 166420

URL: http://llvm.org/viewvc/llvm-project?rev=166420&view=rev
Log:
<rdar://problem/12473003> 

Allow type searches to specify a type keyword when searching for type. Currently supported type keywords are: struct, class, union, enum, and typedef.

So now you can search for types with a string like "struct foo".


Modified:
    lldb/trunk/include/lldb/Symbol/Type.h
    lldb/trunk/include/lldb/Symbol/TypeList.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Symbol/Type.cpp
    lldb/trunk/source/Symbol/TypeList.cpp

Modified: lldb/trunk/include/lldb/Symbol/Type.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=166420&r1=166419&r2=166420&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Type.h (original)
+++ lldb/trunk/include/lldb/Symbol/Type.h Mon Oct 22 11:19:56 2012
@@ -255,9 +255,10 @@
     // From a fully qualified typename, split the type into the type basename
     // and the remaining type scope (namespaces/classes).
     static bool
-    GetTypeScopeAndBasename (const char* name_cstr,
+    GetTypeScopeAndBasename (const char* &name_cstr,
                              std::string &scope,
-                             std::string &basename);
+                             std::string &basename,
+                             lldb::TypeClass &type_class);
     void
     SetEncodingType (Type *encoding_type)
     {

Modified: lldb/trunk/include/lldb/Symbol/TypeList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeList.h?rev=166420&r1=166419&r2=166420&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeList.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeList.h Mon Oct 22 11:19:56 2012
@@ -61,7 +61,12 @@
     void
     RemoveMismatchedTypes (const std::string &type_scope,
                            const std::string &type_basename,
+                           lldb::TypeClass type_class,
                            bool exact_match);
+
+    void
+    RemoveMismatchedTypes (lldb::TypeClass type_class);
+
 private:
     typedef std::multimap<lldb::user_id_t, lldb::TypeSP> collection;
     typedef collection::iterator iterator;

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=166420&r1=166419&r2=166420&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Oct 22 11:19:56 2012
@@ -696,7 +696,8 @@
     std::string type_scope;
     std::string type_basename;
     const bool append = true;
-    if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename))
+    TypeClass type_class = eTypeClassAny;
+    if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
     {
         // Check if "name" starts with "::" which means the qualified type starts
         // from the root namespace and implies and exact match. The typenames we
@@ -711,14 +712,25 @@
         ConstString type_basename_const_str (type_basename.c_str());
         if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
         {
-            types.RemoveMismatchedTypes (type_scope, type_basename, exact_match);
+            types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
             num_matches = types.GetSize();
         }
     }
     else
     {
         // The type is not in a namespace/class scope, just search for it by basename
-        num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
+        if (type_class != eTypeClassAny)
+        {
+            // The "type_name_cstr" will have been modified if we have a valid type class
+            // prefix (like "struct", "class", "union", "typedef" etc).
+            num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
+            types.RemoveMismatchedTypes (type_class);
+            num_matches = types.GetSize();
+        }
+        else
+        {
+            num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
+        }
     }
     
     return num_matches;

Modified: lldb/trunk/source/Symbol/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=166420&r1=166419&r2=166420&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Type.cpp (original)
+++ lldb/trunk/source/Symbol/Type.cpp Mon Oct 22 11:19:56 2012
@@ -28,6 +28,8 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 
+#include "llvm/ADT/StringRef.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -728,14 +730,43 @@
 
 
 bool
-Type::GetTypeScopeAndBasename (const char* name_cstr,
+Type::GetTypeScopeAndBasename (const char* &name_cstr,
                                std::string &scope,
-                               std::string &basename)
+                               std::string &basename,
+                               TypeClass &type_class)
 {
     // Protect against null c string.
     
+    type_class = eTypeClassAny;
+
     if (name_cstr && name_cstr[0])
     {
+        llvm::StringRef name_strref(name_cstr);
+        if (name_strref.startswith("struct "))
+        {
+            name_cstr += 7;
+            type_class = eTypeClassStruct;
+        }
+        else if (name_strref.startswith("class "))
+        {
+            name_cstr += 6;
+            type_class = eTypeClassClass;
+        }
+        else if (name_strref.startswith("union "))
+        {
+            name_cstr += 6;
+            type_class = eTypeClassUnion;
+        }
+        else if (name_strref.startswith("enum "))
+        {
+            name_cstr += 5;
+            type_class = eTypeClassEnumeration;
+        }
+        else if (name_strref.startswith("typedef "))
+        {
+            name_cstr += 8;
+            type_class = eTypeClassTypedef;
+        }
         const char *basename_cstr = name_cstr;
         const char* namespace_separator = ::strstr (basename_cstr, "::");
         if (namespace_separator)

Modified: lldb/trunk/source/Symbol/TypeList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=166420&r1=166419&r2=166420&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeList.cpp (original)
+++ lldb/trunk/source/Symbol/TypeList.cpp Mon Oct 22 11:19:56 2012
@@ -207,17 +207,19 @@
 {
     std::string type_scope;
     std::string type_basename;
-    if (!Type::GetTypeScopeAndBasename (qualified_typename, type_scope, type_basename))
+    TypeClass type_class = eTypeClassAny;
+    if (!Type::GetTypeScopeAndBasename (qualified_typename, type_scope, type_basename, type_class))
     {
         type_basename = qualified_typename;
         type_scope.clear();
     }
-    return RemoveMismatchedTypes (type_scope, type_basename, exact_match);
+    return RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
 }
 
 void
 TypeList::RemoveMismatchedTypes (const std::string &type_scope,
                                  const std::string &type_basename,
+                                 TypeClass type_class,
                                  bool exact_match)
 {
     // Our "collection" type currently is a std::map which doesn't
@@ -232,6 +234,15 @@
     {
         Type* the_type = pos->second.get();
         bool keep_match = false;
+        TypeClass match_type_class = eTypeClassAny;
+
+        if (type_class != eTypeClassAny)
+        {
+            match_type_class = ClangASTType::GetTypeClass (the_type->GetClangAST(),
+                                                           the_type->GetClangForwardType());
+            if ((match_type_class & type_class) == 0)
+                continue;
+        }
 
         ConstString match_type_name_const_str (the_type->GetQualifiedName());
         if (match_type_name_const_str)
@@ -241,7 +252,8 @@
             std::string match_type_basename;
             if (Type::GetTypeScopeAndBasename (match_type_name,
                                                match_type_scope,
-                                               match_type_basename))
+                                               match_type_basename,
+                                               match_type_class))
             {
                 if (match_type_basename == type_basename)
                 {
@@ -299,6 +311,31 @@
     m_types.swap(matching_types);
 }
 
+void
+TypeList::RemoveMismatchedTypes (TypeClass type_class)
+{
+    if (type_class == eTypeClassAny)
+        return;
+
+    // Our "collection" type currently is a std::map which doesn't
+    // have any good way to iterate and remove items from the map
+    // so we currently just make a new list and add all of the matching
+    // types to it, and then swap it into m_types at the end
+    collection matching_types;
+    
+    iterator pos, end = m_types.end();
+    
+    for (pos = m_types.begin(); pos != end; ++pos)
+    {
+        Type* the_type = pos->second.get();
+        TypeClass match_type_class = ClangASTType::GetTypeClass (the_type->GetClangAST(),
+                                                                 the_type->GetClangForwardType());
+        if (match_type_class & type_class)
+            matching_types.insert (*pos);
+    }
+    m_types.swap(matching_types);
+}
+
 //void *
 //TypeList::CreateClangPointerType (Type *type)
 //{





More information about the lldb-commits mailing list