[Lldb-commits] [lldb] r134132 - in /lldb/trunk: include/lldb/Expression/ include/lldb/Symbol/ source/API/ source/Core/ source/Expression/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Plugins/SymbolFile/DWARF/ source/Symbol/ test/lang/c/forward/ test/lang/cpp/dynamic-value/ test/lang/objc/foundation/

Greg Clayton gclayton at apple.com
Wed Jun 29 19:28:26 PDT 2011


Author: gclayton
Date: Wed Jun 29 21:28:26 2011
New Revision: 134132

URL: http://llvm.org/viewvc/llvm-project?rev=134132&view=rev
Log:
Centralize all of the type name code so that we always strip the leading
"struct ", "class ", and "union " from the start of any type names that are
extracted from clang QualType objects. I had to fix test suite cases that
were expecting the struct/union/class prefix to be there.


Modified:
    lldb/trunk/include/lldb/Expression/ClangFunction.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/source/API/SBType.cpp
    lldb/trunk/source/Core/ValueObjectChild.cpp
    lldb/trunk/source/Core/ValueObjectConstResult.cpp
    lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
    lldb/trunk/source/Core/ValueObjectMemory.cpp
    lldb/trunk/source/Core/ValueObjectRegister.cpp
    lldb/trunk/source/Expression/ClangFunction.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/source/Symbol/ClangASTType.cpp
    lldb/trunk/source/Symbol/Type.cpp
    lldb/trunk/test/lang/c/forward/TestForwardDeclaration.py
    lldb/trunk/test/lang/cpp/dynamic-value/TestDynamicValue.py
    lldb/trunk/test/lang/objc/foundation/TestObjCMethods.py

Modified: lldb/trunk/include/lldb/Expression/ClangFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangFunction.h?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangFunction.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangFunction.h Wed Jun 29 21:28:26 2011
@@ -612,7 +612,7 @@
     
     Function                       *m_function_ptr;                 ///< The function we're going to call.  May be NULL if we don't have debug info for the function.
     Address                         m_function_addr;                ///< If we don't have the FunctionSP, we at least need the address & return type.
-    void                           *m_function_return_qual_type;    ///< The opaque clang qual type for the function return type.
+    lldb::clang_type_t              m_function_return_qual_type;    ///< The opaque clang qual type for the function return type.
     ClangASTContext                *m_clang_ast_context;            ///< This is the clang_ast_context that we're getting types from the and value, and the function return the function pointer is NULL.
 
     std::string                     m_wrapper_function_name;        ///< The name of the wrapper function.

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Wed Jun 29 21:28:26 2011
@@ -659,9 +659,6 @@
     //------------------------------------------------------------------
     // Type names
     //------------------------------------------------------------------
-    static std::string
-    GetTypeName(lldb::clang_type_t clang_type);
-    
     static bool
     IsFloatingPointType (lldb::clang_type_t clang_type, uint32_t &count, bool &is_complex);
 

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Wed Jun 29 21:28:26 2011
@@ -69,14 +69,17 @@
     }
 
     ConstString
-    GetClangTypeName ();
+    GetConstTypeName ();
 
     static ConstString
-    GetClangTypeName (lldb::clang_type_t clang_type);
-
-    static ConstString
-    GetClangTypeName (clang::QualType qual_type);
+    GetConstTypeName (lldb::clang_type_t clang_type);
     
+    static std::string
+    GetTypeNameForQualType (clang::QualType qual_type);
+
+    static std::string
+    GetTypeNameForOpaqueQualType (lldb::clang_type_t opaque_qual_type);
+
     uint32_t
     GetClangTypeBitWidth ();
 

Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Wed Jun 29 21:28:26 2011
@@ -71,7 +71,7 @@
 SBType::GetName ()
 {
     if (IsValid ())
-        return ClangASTType::GetClangTypeName (m_type).AsCString(NULL);
+        return ClangASTType::GetConstTypeName (m_type).AsCString(NULL);
     return NULL;
 }
 

Modified: lldb/trunk/source/Core/ValueObjectChild.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectChild.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectChild.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectChild.cpp Wed Jun 29 21:28:26 2011
@@ -71,7 +71,7 @@
 {
     if (m_type_name.IsEmpty())
     {
-        m_type_name = ClangASTType::GetClangTypeName (GetClangType());
+        m_type_name = ClangASTType::GetConstTypeName (GetClangType());
         if (m_type_name)
         {
             if (m_bitfield_bit_size > 0)

Modified: lldb/trunk/source/Core/ValueObjectConstResult.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResult.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResult.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectConstResult.cpp Wed Jun 29 21:28:26 2011
@@ -273,7 +273,7 @@
 ValueObjectConstResult::GetTypeName()
 {
     if (m_type_name.IsEmpty())
-        m_type_name = ClangASTType::GetClangTypeName (GetClangType());
+        m_type_name = ClangASTType::GetConstTypeName (GetClangType());
     return m_type_name;
 }
 

Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Wed Jun 29 21:28:26 2011
@@ -62,7 +62,7 @@
 {
     const bool success = UpdateValueIfNeeded();
     if (success && m_type_sp)
-        return ClangASTType::GetClangTypeName (GetClangType());
+        return ClangASTType::GetConstTypeName (GetClangType());
     else
         return m_parent->GetTypeName();
 }

Modified: lldb/trunk/source/Core/ValueObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectMemory.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectMemory.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectMemory.cpp Wed Jun 29 21:28:26 2011
@@ -140,11 +140,7 @@
 {
     if (m_type_sp)
         return m_type_sp->GetName();
-    ConstString name;
-    std::string type_name (ClangASTContext::GetTypeName (m_clang_type.GetOpaqueQualType()));
-    if (!type_name.empty())
-        name.SetCString (type_name.c_str());
-    return name;
+    return ClangASTType::GetConstTypeName (m_clang_type.GetOpaqueQualType());
 }
 
 uint32_t

Modified: lldb/trunk/source/Core/ValueObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectRegister.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectRegister.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectRegister.cpp Wed Jun 29 21:28:26 2011
@@ -322,7 +322,7 @@
 ValueObjectRegister::GetTypeName()
 {
     if (m_type_name.IsEmpty())
-        m_type_name = ClangASTType::GetClangTypeName (GetClangType());
+        m_type_name = ClangASTType::GetConstTypeName (GetClangType());
     return m_type_name;
 }
 

Modified: lldb/trunk/source/Expression/ClangFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangFunction.cpp Wed Jun 29 21:28:26 2011
@@ -118,7 +118,7 @@
     // FIXME: How does clang tell us there's no return value?  We need to handle that case.
     unsigned num_errors = 0;
     
-    std::string return_type_str = ClangASTContext::GetTypeName(m_function_return_qual_type);
+    std::string return_type_str (ClangASTType::GetTypeNameForOpaqueQualType (m_function_return_qual_type));
     
     // Cons up the function we're going to wrap our call in, then compile it...
     // We declare the function "extern "C"" because the compiler might be in C++
@@ -164,15 +164,15 @@
         if (trust_function)
         {
             lldb::clang_type_t arg_clang_type = m_function_ptr->GetArgumentTypeAtIndex(i);
-            type_name = ClangASTContext::GetTypeName(arg_clang_type);
+            type_name = ClangASTType::GetTypeNameForOpaqueQualType (arg_clang_type);
         }
         else
         {
             Value *arg_value = m_arg_values.GetValueAtIndex(i);
-            void *clang_qual_type = arg_value->GetClangType ();
+            lldb::clang_type_t clang_qual_type = arg_value->GetClangType ();
             if (clang_qual_type != NULL)
             {
-                type_name = ClangASTContext::GetTypeName(clang_qual_type);
+                type_name = ClangASTType::GetTypeNameForOpaqueQualType (clang_qual_type);
             }
             else
             {   

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Wed Jun 29 21:28:26 2011
@@ -528,7 +528,7 @@
 size_t
 AppleObjCRuntimeV2::GetByteOffsetForIvar (ClangASTType &parent_ast_type, const char *ivar_name)
 {
-    const char *class_name = parent_ast_type.GetClangTypeName().AsCString();
+    const char *class_name = parent_ast_type.GetConstTypeName().AsCString();
 
     if (!class_name || *class_name == '\0' || !ivar_name || *ivar_name == '\0')
         return LLDB_INVALID_IVAR_OFFSET;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Jun 29 21:28:26 2011
@@ -1493,7 +1493,7 @@
             
             if (class_language == eLanguageTypeObjC)
             {
-                std::string class_str (ClangASTContext::GetTypeName (clang_type));
+                std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
                 if (!class_str.empty())
                 {
                 

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Jun 29 21:28:26 2011
@@ -2571,9 +2571,8 @@
                             // Base classes should be a multiple of 8 bits in size
                             assert (bit_offset % 8 == 0);
                             child_byte_offset = bit_offset/8;
-                            std::string base_class_type_name(base_class->getType().getAsString());
-
-                            child_name.assign(base_class_type_name.c_str());
+                            
+                            child_name = ClangASTType::GetTypeNameForQualType(base_class->getType());
 
                             uint64_t clang_type_info_bit_size = ast->getTypeSize(base_class->getType());
 
@@ -3401,7 +3400,8 @@
                         if (omit_empty_base_classes && RecordHasFields(base_class_decl) == false)
                             continue;
 
-                        if (base_class->getType().getAsString().compare (name) == 0)
+                        std::string base_class_type_name (ClangASTType::GetTypeNameForQualType(base_class->getType()));
+                        if (base_class_type_name.compare (name) == 0)
                             return child_idx;
                         ++child_idx;
                     }
@@ -4660,28 +4660,6 @@
     return NULL;
 }
 
-
-std::string
-ClangASTContext::GetTypeName (clang_type_t opaque_qual_type)
-{
-    std::string return_name;
-    
-    QualType qual_type(QualType::getFromOpaquePtr(opaque_qual_type));
-
-    const TypedefType *typedef_type = qual_type->getAs<TypedefType>();
-    if (typedef_type)
-    {
-        const TypedefNameDecl *typedef_decl = typedef_type->getDecl();
-        return_name = typedef_decl->getQualifiedNameAsString();
-    }
-    else
-    {
-        return_name = qual_type.getAsString();
-    }
-
-    return return_name;
-}
-
 // Disable this for now since I can't seem to get a nicely formatted float
 // out of the APFloat class without just getting the float, double or quad
 // and then using a formatted print on it which defeats the purpose. We ideally

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Wed Jun 29 21:28:26 2011
@@ -38,57 +38,88 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
 
-
 using namespace lldb;
 using namespace lldb_private;
 
-ClangASTType::~ClangASTType()
-{
-}
 
-ConstString
-ClangASTType::GetClangTypeName ()
+ClangASTType::~ClangASTType()
 {
-    return GetClangTypeName (m_type);
 }
 
-ConstString
-ClangASTType::GetClangTypeName (clang_type_t clang_type)
+std::string
+ClangASTType::GetTypeNameForQualType (clang::QualType qual_type)
 {
-    ConstString clang_type_name;
-    if (clang_type)
+    std::string type_name;
+    
+    const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
+    if (typedef_type)
     {
-        clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));        
-        return GetClangTypeName(qual_type);
-        
+        const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
+        type_name = typedef_decl->getQualifiedNameAsString();
     }
     else
     {
-        clang_type_name.SetCString ("<invalid>");
+        type_name = qual_type.getAsString();
+    }
+    
+    // There is no call to a clang type to get the type name without the
+    // class/struct/union on the front, so lets strip it here
+    const char *type_name_cstr = type_name.c_str();
+    if (type_name_cstr[0] == 'c' &&
+        type_name_cstr[1] == 'l' &&
+        type_name_cstr[2] == 'a' &&
+        type_name_cstr[3] == 's' &&
+        type_name_cstr[4] == 's' &&
+        type_name_cstr[5] == ' ')
+    {
+        type_name.erase (0, 6);
+    }
+    else if (type_name_cstr[0] == 's' &&
+             type_name_cstr[1] == 't' &&
+             type_name_cstr[2] == 'r' &&
+             type_name_cstr[3] == 'u' &&
+             type_name_cstr[4] == 'c' &&
+             type_name_cstr[5] == 't' &&
+             type_name_cstr[6] == ' ')
+    {
+        type_name.erase (0, 7);
+    }
+    else if (type_name_cstr[0] == 'u' &&
+             type_name_cstr[1] == 'n' &&
+             type_name_cstr[2] == 'i' &&
+             type_name_cstr[3] == 'o' &&
+             type_name_cstr[4] == 'n' &&
+             type_name_cstr[5] == ' ')
+    {
+        type_name.erase (0, 6);
     }
+    return type_name;
+}
 
-    return clang_type_name;
+std::string
+ClangASTType::GetTypeNameForOpaqueQualType (clang_type_t opaque_qual_type)
+{
+    return GetTypeNameForQualType (clang::QualType::getFromOpaquePtr(opaque_qual_type));
 }
 
+
 ConstString
-ClangASTType::GetClangTypeName (clang::QualType qual_type)
+ClangASTType::GetConstTypeName ()
 {
-    ConstString clang_type_name;
-    const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
-    if (typedef_type)
-    {
-        const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
-        std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
-        if (!clang_typedef_name.empty())
-            clang_type_name.SetCString (clang_typedef_name.c_str());
-    }
+    return GetConstTypeName (m_type);
+}
+
+ConstString
+ClangASTType::GetConstTypeName (clang_type_t clang_type)
+{
+    clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
+    std::string type_name (GetTypeNameForQualType (qual_type));
+    ConstString const_type_name;
+    if (type_name.empty())
+        const_type_name.SetCString ("<invalid>");
     else
-    {
-        std::string type_name(qual_type.getAsString());
-        if (!type_name.empty())
-            clang_type_name.SetCString (type_name.c_str());
-    }
-    return clang_type_name;
+        const_type_name.SetCString(type_name.c_str());
+    return const_type_name;
 }
 
 clang_type_t

Modified: lldb/trunk/source/Symbol/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Type.cpp (original)
+++ lldb/trunk/source/Symbol/Type.cpp Wed Jun 29 21:28:26 2011
@@ -194,14 +194,10 @@
 const ConstString &
 Type::GetName()
 {
-    if (!(m_name))
+    if (!m_name)
     {
         if (ResolveClangType(eResolveStateForward))
-        {
-            std::string type_name = ClangASTContext::GetTypeName (m_clang_type);
-            if (!type_name.empty())
-                m_name.SetCString (type_name.c_str());
-        }
+            m_name = ClangASTType::GetConstTypeName (m_clang_type);
     }
     return m_name;
 }

Modified: lldb/trunk/test/lang/c/forward/TestForwardDeclaration.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/forward/TestForwardDeclaration.py?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/test/lang/c/forward/TestForwardDeclaration.py (original)
+++ lldb/trunk/test/lang/c/forward/TestForwardDeclaration.py Wed Jun 29 21:28:26 2011
@@ -47,13 +47,13 @@
         # This should display correctly.
         # Note that the member fields of a = 1 and b = 2 is by design.
         self.expect("frame variable -T *bar_ptr", VARIABLES_DISPLAYED_CORRECTLY,
-            substrs = ['(struct bar) *bar_ptr = ',
+            substrs = ['(bar) *bar_ptr = ',
                        '(int) a = 1',
                        '(int) b = 2'])
 
         # And so should this.
         self.expect("expression *bar_ptr", VARIABLES_DISPLAYED_CORRECTLY,
-            substrs = ['(struct bar)',
+            substrs = ['(bar)',
                        '(int) a = 1',
                        '(int) b = 2'])
 

Modified: lldb/trunk/test/lang/cpp/dynamic-value/TestDynamicValue.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/dynamic-value/TestDynamicValue.py?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/dynamic-value/TestDynamicValue.py (original)
+++ lldb/trunk/test/lang/cpp/dynamic-value/TestDynamicValue.py Wed Jun 29 21:28:26 2011
@@ -168,7 +168,7 @@
         # make sure that works as well:
 
         self.expect('frame var -d run-target anotherA.m_client_A._M_ptr', 'frame var finds its way into a child member',
-            patterns = ['\(.* B \*\)'])
+            patterns = ['\(B \*\)'])
 
         # Now make sure we also get it right for a reference as well:
 

Modified: lldb/trunk/test/lang/objc/foundation/TestObjCMethods.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/foundation/TestObjCMethods.py?rev=134132&r1=134131&r2=134132&view=diff
==============================================================================
--- lldb/trunk/test/lang/objc/foundation/TestObjCMethods.py (original)
+++ lldb/trunk/test/lang/objc/foundation/TestObjCMethods.py Wed Jun 29 21:28:26 2011
@@ -143,7 +143,7 @@
         self.expect("frame variable -T -s", VARIABLES_DISPLAYED_CORRECTLY,
             substrs = ["ARG: (MyString *) self"],
             patterns = ["ARG: \(.*\) _cmd",
-                        "(struct objc_selector *)|(SEL)"])
+                        "(objc_selector *)|(SEL)"])
 
         # rdar://problem/8651752
         # don't crash trying to ask clang how many children an empty record has





More information about the lldb-commits mailing list