Add SBType::GetArrayType() such that - given a type - one can make an array (of a...
authorEnrico Granata <egranata@apple.com>
Tue, 30 Aug 2016 20:39:58 +0000 (20:39 +0000)
committerEnrico Granata <egranata@apple.com>
Tue, 30 Aug 2016 20:39:58 +0000 (20:39 +0000)
This is currently only implemented for the clang-based TypeSystem, but other languages are welcome to jump in!

llvm-svn: 280151

lldb/include/lldb/API/SBType.h
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/include/lldb/Symbol/CompilerType.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/scripts/interface/SBType.i
lldb/source/API/SBType.cpp
lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Symbol/CompilerType.cpp
lldb/source/Symbol/TypeSystem.cpp

index ed3c2ff..a374253 100644 (file)
@@ -189,6 +189,9 @@ public:
     GetArrayElementType ();
     
     lldb::SBType
+    GetArrayType (uint64_t size);
+    
+    lldb::SBType
     GetVectorElementType ();
 
     lldb::SBType
index 809a12e..f383b92 100644 (file)
@@ -790,6 +790,9 @@ public:
     GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) override;
     
     CompilerType
+    GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size) override;
+
+    CompilerType
     GetCanonicalType (lldb::opaque_compiler_type_t type) override;
     
     CompilerType
index 36f6ef3..db15a34 100644 (file)
@@ -269,6 +269,9 @@ public:
     GetArrayElementType(uint64_t *stride = nullptr) const;
     
     CompilerType
+    GetArrayType (uint64_t size) const;
+    
+    CompilerType
     GetCanonicalType () const;
     
     CompilerType
index 220ff43..249dfba 100644 (file)
@@ -274,6 +274,9 @@ public:
     GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) = 0;
     
     virtual CompilerType
+    GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size);
+    
+    virtual CompilerType
     GetCanonicalType (lldb::opaque_compiler_type_t type) = 0;
     
     // Returns -1 if this isn't a function of if the function doesn't have a prototype
index 76bd3f0..999941a 100644 (file)
@@ -247,6 +247,9 @@ public:
     
     lldb::SBType
     GetArrayElementType ();
+
+    lldb::SBType
+    GetArrayType (uint64_t size);
     
     lldb::SBType
     GetVectorElementType ();
index 4922b49..a786d32 100644 (file)
@@ -229,6 +229,14 @@ SBType::GetArrayElementType()
 }
 
 SBType
+SBType::GetArrayType (uint64_t size)
+{
+    if (!IsValid())
+        return SBType();
+    return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size))));
+}
+
+SBType
 SBType::GetVectorElementType ()
 {
     SBType type_sb;
index f1358c0..9cc8550 100644 (file)
@@ -4566,6 +4566,24 @@ ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_
 }
 
 CompilerType
+ClangASTContext::GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size)
+{
+    if (type)
+    {
+        clang::QualType qual_type(GetCanonicalQualType(type));
+        if (clang::ASTContext *ast_ctx = getASTContext())
+        {
+            if (size == 0)
+                return CompilerType (ast_ctx, ast_ctx->getConstantArrayType(qual_type, llvm::APInt(64, size), clang::ArrayType::ArraySizeModifier::Normal, 0));
+            else
+                return CompilerType (ast_ctx, ast_ctx->getIncompleteArrayType(qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0));
+        }
+    }
+    
+    return CompilerType();
+}
+
+CompilerType
 ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type)
 {
     if (type)
index 2b06c93..ef788d0 100644 (file)
@@ -467,7 +467,16 @@ CompilerType::GetArrayElementType (uint64_t *stride) const
     if (IsValid())
     {
         return m_type_system->GetArrayElementType(m_type, stride);
-        
+    }
+    return CompilerType();
+}
+
+CompilerType
+CompilerType::GetArrayType (uint64_t size) const
+{
+    if (IsValid())
+    {
+        return m_type_system->GetArrayType(m_type, size);
     }
     return CompilerType();
 }
index 2cd82f2..3aadcaa 100644 (file)
@@ -62,6 +62,12 @@ TypeSystem::IsAnonymousType (lldb::opaque_compiler_type_t type)
 }
 
 CompilerType
+TypeSystem::GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size)
+{
+    return CompilerType();
+}
+
+CompilerType
 TypeSystem::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
 {
     return CompilerType();