[Lldb-commits] [lldb] r165857 - in /lldb/trunk: include/lldb/API/SBType.h include/lldb/Symbol/ClangASTContext.h include/lldb/lldb-enumerations.h scripts/Python/interface/SBType.i source/API/SBType.cpp source/Symbol/ClangASTContext.cpp

Greg Clayton gclayton at apple.com
Fri Oct 12 17:20:28 PDT 2012


Author: gclayton
Date: Fri Oct 12 19:20:27 2012
New Revision: 165857

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

>From SBType, we can now get a lldb::BasicType enumeration out of an existing type.

Modified:
    lldb/trunk/include/lldb/API/SBType.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/scripts/Python/interface/SBType.i
    lldb/trunk/source/API/SBType.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/API/SBType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBType.h (original)
+++ lldb/trunk/include/lldb/API/SBType.h Fri Oct 12 19:20:27 2012
@@ -105,6 +105,12 @@
     lldb::SBType
     GetUnqualifiedType();
 
+    // Get the "lldb::BasicType" enumeration for a type. If a type is not a basic
+    // type eBasicTypeInvalid will be returned
+    lldb::BasicType
+    GetBasicType();
+
+    // The call below confusing and should really be renamed to "CreateBasicType"
     lldb::SBType
     GetBasicType(lldb::BasicType type);
     

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Oct 12 19:20:27 2012
@@ -274,6 +274,9 @@
     lldb::clang_type_t
     GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
 
+    static lldb::BasicType
+    GetLLDBBasicTypeEnumeration (lldb::clang_type_t clang_type);
+
     //------------------------------------------------------------------
     // CVR modifiers
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Fri Oct 12 19:20:27 2012
@@ -537,7 +537,10 @@
         eBasicTypeVoid = 1,
         eBasicTypeChar,
         eBasicTypeSignedChar,
+        eBasicTypeUnsignedChar,
         eBasicTypeWChar,
+        eBasicTypeSignedWChar,
+        eBasicTypeUnsignedWChar,
         eBasicTypeChar16,
         eBasicTypeChar32,
         eBasicTypeShort,
@@ -551,6 +554,7 @@
         eBasicTypeInt128,
         eBasicTypeUnsignedInt128,
         eBasicTypeBool,
+        eBasicTypeHalf,
         eBasicTypeFloat,
         eBasicTypeDouble,
         eBasicTypeLongDouble,
@@ -559,7 +563,9 @@
         eBasicTypeLongDoubleComplex,
         eBasicTypeObjCID,
         eBasicTypeObjCClass,
-        eBasicTypeObjCSel
+        eBasicTypeObjCSel,
+        eBasicTypeNullPtr,
+        eBasicTypeOther
     } BasicType;
 
     typedef enum TypeClass

Modified: lldb/trunk/scripts/Python/interface/SBType.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBType.i (original)
+++ lldb/trunk/scripts/Python/interface/SBType.i Fri Oct 12 19:20:27 2012
@@ -177,6 +177,9 @@
     lldb::SBType
     GetUnqualifiedType();
     
+    lldb::BasicType
+    GetBasicType();
+
     lldb::SBType
     GetBasicType (lldb::BasicType type);
 

Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Fri Oct 12 19:20:27 2012
@@ -229,24 +229,51 @@
     return SBType(ClangASTType(m_opaque_sp->GetASTContext(),qt.getUnqualifiedType().getAsOpaquePtr()));
 }
 
+lldb::BasicType
+SBType::GetBasicType()
+{
+    if (IsValid())
+        return ClangASTContext::GetLLDBBasicTypeEnumeration (m_opaque_sp->GetOpaqueQualType());
+    return eBasicTypeInvalid;
+}
 
 SBType
 SBType::GetBasicType(lldb::BasicType type)
 {
-    
     if (!IsValid())
         return SBType();
     
-    clang::CanQualType base_type_qual;
+    clang::QualType base_type_qual;
     
     switch (type)
     {
+        case eBasicTypeVoid:
+            base_type_qual = m_opaque_sp->GetASTContext()->VoidTy;
+            break;
         case eBasicTypeChar:
             base_type_qual = m_opaque_sp->GetASTContext()->CharTy;
             break;
         case eBasicTypeSignedChar:
             base_type_qual = m_opaque_sp->GetASTContext()->SignedCharTy;
             break;
+        case eBasicTypeUnsignedChar:
+            base_type_qual = m_opaque_sp->GetASTContext()->UnsignedCharTy;
+            break;
+        case eBasicTypeWChar:
+            base_type_qual = m_opaque_sp->GetASTContext()->getWCharType();
+            break;
+        case eBasicTypeSignedWChar:
+            base_type_qual = m_opaque_sp->GetASTContext()->getSignedWCharType();
+            break;
+        case eBasicTypeUnsignedWChar:
+            base_type_qual = m_opaque_sp->GetASTContext()->getUnsignedWCharType();
+            break;
+        case eBasicTypeChar16:
+            base_type_qual = m_opaque_sp->GetASTContext()->Char16Ty;
+            break;
+        case eBasicTypeChar32:
+            base_type_qual = m_opaque_sp->GetASTContext()->Char32Ty;
+            break;
         case eBasicTypeShort:
             base_type_qual = m_opaque_sp->GetASTContext()->ShortTy;
             break;
@@ -265,30 +292,6 @@
         case eBasicTypeUnsignedLong:
             base_type_qual = m_opaque_sp->GetASTContext()->UnsignedLongTy;
             break;
-        case eBasicTypeBool:
-            base_type_qual = m_opaque_sp->GetASTContext()->BoolTy;
-            break;
-        case eBasicTypeFloat:
-            base_type_qual = m_opaque_sp->GetASTContext()->FloatTy;
-            break;
-        case eBasicTypeDouble:
-            base_type_qual = m_opaque_sp->GetASTContext()->DoubleTy;
-            break;
-        case eBasicTypeObjCID:
-            base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinIdTy;
-            break;
-        case eBasicTypeVoid:
-            base_type_qual = m_opaque_sp->GetASTContext()->VoidTy;
-            break;
-        case eBasicTypeWChar:
-            base_type_qual = m_opaque_sp->GetASTContext()->WCharTy;
-            break;
-        case eBasicTypeChar16:
-            base_type_qual = m_opaque_sp->GetASTContext()->Char16Ty;
-            break;
-        case eBasicTypeChar32:
-            base_type_qual = m_opaque_sp->GetASTContext()->Char32Ty;
-            break;
         case eBasicTypeLongLong:
             base_type_qual = m_opaque_sp->GetASTContext()->LongLongTy;
             break;
@@ -301,6 +304,18 @@
         case eBasicTypeUnsignedInt128:
             base_type_qual = m_opaque_sp->GetASTContext()->UnsignedInt128Ty;
             break;
+        case eBasicTypeBool:
+            base_type_qual = m_opaque_sp->GetASTContext()->BoolTy;
+            break;
+        case eBasicTypeHalf:
+            base_type_qual = m_opaque_sp->GetASTContext()->HalfTy;
+            break;
+        case eBasicTypeFloat:
+            base_type_qual = m_opaque_sp->GetASTContext()->FloatTy;
+            break;
+        case eBasicTypeDouble:
+            base_type_qual = m_opaque_sp->GetASTContext()->DoubleTy;
+            break;
         case eBasicTypeLongDouble:
             base_type_qual = m_opaque_sp->GetASTContext()->LongDoubleTy;
             break;
@@ -313,12 +328,18 @@
         case eBasicTypeLongDoubleComplex:
             base_type_qual = m_opaque_sp->GetASTContext()->LongDoubleComplexTy;
             break;
+        case eBasicTypeObjCID:
+            base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinIdTy;
+            break;
         case eBasicTypeObjCClass:
             base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinClassTy;
             break;
         case eBasicTypeObjCSel:
             base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinSelTy;
             break;
+        case eBasicTypeNullPtr:
+            base_type_qual = m_opaque_sp->GetASTContext()->NullPtrTy;
+            break;
         default:
             return SBType();
     }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=165857&r1=165856&r2=165857&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Oct 12 19:20:27 2012
@@ -3644,6 +3644,63 @@
     return NULL;
 }
 
+lldb::BasicType
+ClangASTContext::GetLLDBBasicTypeEnumeration (clang_type_t clang_type)
+{
+    if (clang_type)
+    {
+        QualType qual_type(QualType::getFromOpaquePtr(clang_type));
+        const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+        switch (type_class)
+        {
+        case clang::Type::Builtin:                  
+            switch (cast<clang::BuiltinType>(qual_type)->getKind())
+
+            case clang::BuiltinType::Void:      return eBasicTypeVoid;
+            case clang::BuiltinType::Bool:      return eBasicTypeBool;
+            case clang::BuiltinType::Char_S:    return eBasicTypeSignedChar;
+            case clang::BuiltinType::Char_U:    return eBasicTypeUnsignedChar;
+            case clang::BuiltinType::Char16:    return eBasicTypeChar16;
+            case clang::BuiltinType::Char32:    return eBasicTypeChar32;
+            case clang::BuiltinType::UChar:     return eBasicTypeUnsignedChar;
+            case clang::BuiltinType::SChar:     return eBasicTypeSignedChar;
+            case clang::BuiltinType::WChar_S:   return eBasicTypeSignedWChar;
+            case clang::BuiltinType::WChar_U:   return eBasicTypeUnsignedWChar;
+            case clang::BuiltinType::Short:     return eBasicTypeShort;
+            case clang::BuiltinType::UShort:    return eBasicTypeUnsignedShort;
+            case clang::BuiltinType::Int:       return eBasicTypeInt;
+            case clang::BuiltinType::UInt:      return eBasicTypeUnsignedInt;
+            case clang::BuiltinType::Long:      return eBasicTypeLong;
+            case clang::BuiltinType::ULong:     return eBasicTypeUnsignedLong;
+            case clang::BuiltinType::LongLong:  return eBasicTypeLongLong;
+            case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong;
+            case clang::BuiltinType::Int128:    return eBasicTypeInt128;
+            case clang::BuiltinType::UInt128:   return eBasicTypeUnsignedInt128;
+
+            case clang::BuiltinType::Half:      return eBasicTypeHalf;
+            case clang::BuiltinType::Float:     return eBasicTypeFloat;
+            case clang::BuiltinType::Double:    return eBasicTypeDouble;
+            case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble;
+
+            case clang::BuiltinType::NullPtr:   return eBasicTypeNullPtr;
+            case clang::BuiltinType::ObjCId:    return eBasicTypeObjCID;
+            case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass;
+            case clang::BuiltinType::ObjCSel:   return eBasicTypeObjCSel;
+            case clang::BuiltinType::Dependent:
+            case clang::BuiltinType::Overload:
+            case clang::BuiltinType::BoundMember:
+            case clang::BuiltinType::PseudoObject:
+            case clang::BuiltinType::UnknownAny:
+            case clang::BuiltinType::BuiltinFn:
+            case clang::BuiltinType::ARCUnbridgedCast:
+                return eBasicTypeOther;
+        }
+    }
+    
+    return eBasicTypeInvalid;
+}
+
+
 
 // If a pointer to a pointee type (the clang_type arg) says that it has no 
 // children, then we either need to trust it, or override it and return a 





More information about the lldb-commits mailing list