<rdar://problem/12749733>

Always allows getting builtin types by name even if there is no backing debug information.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@169424 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBModule.cpp b/source/API/SBModule.cpp
index 933e803..f0c916e 100644
--- a/source/API/SBModule.cpp
+++ b/source/API/SBModule.cpp
@@ -488,27 +488,29 @@
     if (name_cstr && module_sp)
     {
         SymbolContext sc;
-        TypeList type_list;
-        uint32_t num_matches = 0;
         const bool exact_match = false;
         ConstString name(name_cstr);
 
-        num_matches = module_sp->FindTypes (sc,
-                                            name,
-                                            exact_match,
-                                            1,
-                                            type_list);
+        sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match));
         
-        if (num_matches)
-            sb_type = lldb::SBType(type_list.GetTypeAtIndex(0));
+        if (!sb_type.IsValid())
+            sb_type = SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
     }
     return sb_type;
 }
 
+lldb::SBType
+SBModule::GetBasicType(lldb::BasicType type)
+{
+    ModuleSP module_sp (GetSP ());
+    if (module_sp)
+        return SBType (ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type));
+    return SBType();
+}
+
 lldb::SBTypeList
 SBModule::FindTypes (const char *type)
 {
-    
     SBTypeList retval;
     
     ModuleSP module_sp (GetSP ());
@@ -517,20 +519,27 @@
         SymbolContext sc;
         TypeList type_list;
         const bool exact_match = false;
-        uint32_t num_matches = 0;
         ConstString name(type);
+        const uint32_t num_matches = module_sp->FindTypes (sc,
+                                                           name,
+                                                           exact_match,
+                                                           UINT32_MAX,
+                                                           type_list);
         
-        num_matches = module_sp->FindTypes (sc,
-                                            name,
-                                            exact_match,
-                                            UINT32_MAX,
-                                            type_list);
-            
-        for (size_t idx = 0; idx < num_matches; idx++)
+        if (num_matches > 0)
         {
-            TypeSP type_sp (type_list.GetTypeAtIndex(idx));
-            if (type_sp)
-                retval.Append(SBType(type_sp));
+            for (size_t idx = 0; idx < num_matches; idx++)
+            {
+                TypeSP type_sp (type_list.GetTypeAtIndex(idx));
+                if (type_sp)
+                    retval.Append(SBType(type_sp));
+            }
+        }
+        else
+        {
+            SBType sb_type(ClangASTType::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name));
+            if (sb_type.IsValid())
+                retval.Append(sb_type);
         }
     }
 
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index 2020ead..0ce361c 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -2064,52 +2064,87 @@
 }
 
 lldb::SBType
-SBTarget::FindFirstType (const char* type)
+SBTarget::FindFirstType (const char* typename_cstr)
 {
     TargetSP target_sp(GetSP());
-    if (type && target_sp)
+    if (typename_cstr && typename_cstr[0] && target_sp)
     {
-        size_t count = target_sp->GetImages().GetSize();
+        ConstString const_typename(typename_cstr);
+        SymbolContext sc;
+        const bool exact_match = false;
+
+        const ModuleList &module_list = target_sp->GetImages();
+        size_t count = module_list.GetSize();
         for (size_t idx = 0; idx < count; idx++)
         {
-            SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
-            
-            if (found_at_idx.IsValid())
-                return found_at_idx;
+            ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
+            if (module_sp)
+            {
+                TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
+                if (type_sp)
+                    return SBType(type_sp);
+            }
         }
+
+        // No matches, search for basic typename matches
+        ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
+        if (clang_ast)
+            return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename));
     }
     return SBType();
 }
 
-lldb::SBTypeList
-SBTarget::FindTypes (const char* type)
+SBType
+SBTarget::GetBasicType(lldb::BasicType type)
 {
-    
-    SBTypeList retval;
-    
     TargetSP target_sp(GetSP());
-    if (type && target_sp)
+    if (target_sp)
+    {
+        ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
+        if (clang_ast)
+            return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), type));
+    }
+    return SBType();
+}
+
+
+lldb::SBTypeList
+SBTarget::FindTypes (const char* typename_cstr)
+{
+    SBTypeList sb_type_list;
+    TargetSP target_sp(GetSP());
+    if (typename_cstr && typename_cstr[0] && target_sp)
     {
         ModuleList& images = target_sp->GetImages();
-        ConstString name_const(type);
+        ConstString const_typename(typename_cstr);
         bool exact_match = false;
         SymbolContext sc;
         TypeList type_list;
         
         uint32_t num_matches = images.FindTypes (sc,
-                                                 name_const,
+                                                 const_typename,
                                                  exact_match,
                                                  UINT32_MAX,
                                                  type_list);
         
-        for (size_t idx = 0; idx < num_matches; idx++)
+        if (num_matches > 0)
         {
-            TypeSP type_sp (type_list.GetTypeAtIndex(idx));
-            if (type_sp)
-                retval.Append(SBType(type_sp));
+            for (size_t idx = 0; idx < num_matches; idx++)
+            {
+                TypeSP type_sp (type_list.GetTypeAtIndex(idx));
+                if (type_sp)
+                    sb_type_list.Append(SBType(type_sp));
+            }
+        }
+        else
+        {
+            // No matches, search for basic typename matches
+            ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
+            if (clang_ast)
+                sb_type_list.Append (SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename)));
         }
     }
-    return retval;
+    return sb_type_list;
 }
 
 SBValueList
diff --git a/source/API/SBType.cpp b/source/API/SBType.cpp
index 7387ed3..29c56a5 100644
--- a/source/API/SBType.cpp
+++ b/source/API/SBType.cpp
@@ -285,111 +285,9 @@
 SBType
 SBType::GetBasicType(lldb::BasicType type)
 {
-    if (!IsValid())
-        return SBType();
-    
-    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;
-        case eBasicTypeUnsignedShort:
-            base_type_qual = m_opaque_sp->GetASTContext()->UnsignedShortTy;
-            break;
-        case eBasicTypeInt:
-            base_type_qual = m_opaque_sp->GetASTContext()->IntTy;
-            break;
-        case eBasicTypeUnsignedInt:
-            base_type_qual = m_opaque_sp->GetASTContext()->UnsignedIntTy;
-            break;
-        case eBasicTypeLong:
-            base_type_qual = m_opaque_sp->GetASTContext()->LongTy;
-            break;
-        case eBasicTypeUnsignedLong:
-            base_type_qual = m_opaque_sp->GetASTContext()->UnsignedLongTy;
-            break;
-        case eBasicTypeLongLong:
-            base_type_qual = m_opaque_sp->GetASTContext()->LongLongTy;
-            break;
-        case eBasicTypeUnsignedLongLong:
-            base_type_qual = m_opaque_sp->GetASTContext()->UnsignedLongLongTy;
-            break;
-        case eBasicTypeInt128:
-            base_type_qual = m_opaque_sp->GetASTContext()->Int128Ty;
-            break;
-        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;
-        case eBasicTypeFloatComplex:
-            base_type_qual = m_opaque_sp->GetASTContext()->FloatComplexTy;
-            break;
-        case eBasicTypeDoubleComplex:
-            base_type_qual = m_opaque_sp->GetASTContext()->DoubleComplexTy;
-            break;
-        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();
-    }
-    
-    return SBType(ClangASTType(m_opaque_sp->GetASTContext(), base_type_qual.getAsOpaquePtr()));
+    if (IsValid())
+        return SBType (ClangASTType::GetBasicType (m_opaque_sp->GetASTContext(), type));
+    return SBType();
 }
 
 uint32_t