<div dir="ltr">Is there going to be a test for this?</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Aug 30, 2016 at 1:48 PM Enrico Granata via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: enrico<br>
Date: Tue Aug 30 15:39:58 2016<br>
New Revision: 280151<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=280151&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=280151&view=rev</a><br>
Log:<br>
Add SBType::GetArrayType() such that - given a type - one can make an array (of a given size) of that type<br>
<br>
This is currently only implemented for the clang-based TypeSystem, but other languages are welcome to jump in!<br>
<br>
<br>
Modified:<br>
lldb/trunk/include/lldb/API/SBType.h<br>
lldb/trunk/include/lldb/Symbol/ClangASTContext.h<br>
lldb/trunk/include/lldb/Symbol/CompilerType.h<br>
lldb/trunk/include/lldb/Symbol/TypeSystem.h<br>
lldb/trunk/scripts/interface/SBType.i<br>
lldb/trunk/source/API/SBType.cpp<br>
lldb/trunk/source/Symbol/ClangASTContext.cpp<br>
lldb/trunk/source/Symbol/CompilerType.cpp<br>
lldb/trunk/source/Symbol/TypeSystem.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/API/SBType.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/API/SBType.h (original)<br>
+++ lldb/trunk/include/lldb/API/SBType.h Tue Aug 30 15:39:58 2016<br>
@@ -189,6 +189,9 @@ public:<br>
GetArrayElementType ();<br>
<br>
lldb::SBType<br>
+ GetArrayType (uint64_t size);<br>
+<br>
+ lldb::SBType<br>
GetVectorElementType ();<br>
<br>
lldb::SBType<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Aug 30 15:39:58 2016<br>
@@ -790,6 +790,9 @@ public:<br>
GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) override;<br>
<br>
CompilerType<br>
+ GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size) override;<br>
+<br>
+ CompilerType<br>
GetCanonicalType (lldb::opaque_compiler_type_t type) override;<br>
<br>
CompilerType<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/CompilerType.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/CompilerType.h?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/CompilerType.h?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/CompilerType.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/CompilerType.h Tue Aug 30 15:39:58 2016<br>
@@ -269,6 +269,9 @@ public:<br>
GetArrayElementType(uint64_t *stride = nullptr) const;<br>
<br>
CompilerType<br>
+ GetArrayType (uint64_t size) const;<br>
+<br>
+ CompilerType<br>
GetCanonicalType () const;<br>
<br>
CompilerType<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Tue Aug 30 15:39:58 2016<br>
@@ -274,6 +274,9 @@ public:<br>
GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) = 0;<br>
<br>
virtual CompilerType<br>
+ GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size);<br>
+<br>
+ virtual CompilerType<br>
GetCanonicalType (lldb::opaque_compiler_type_t type) = 0;<br>
<br>
// Returns -1 if this isn't a function of if the function doesn't have a prototype<br>
<br>
Modified: lldb/trunk/scripts/interface/SBType.i<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBType.i?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBType.i?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/scripts/interface/SBType.i (original)<br>
+++ lldb/trunk/scripts/interface/SBType.i Tue Aug 30 15:39:58 2016<br>
@@ -247,6 +247,9 @@ public:<br>
<br>
lldb::SBType<br>
GetArrayElementType ();<br>
+<br>
+ lldb::SBType<br>
+ GetArrayType (uint64_t size);<br>
<br>
lldb::SBType<br>
GetVectorElementType ();<br>
<br>
Modified: lldb/trunk/source/API/SBType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/API/SBType.cpp (original)<br>
+++ lldb/trunk/source/API/SBType.cpp Tue Aug 30 15:39:58 2016<br>
@@ -229,6 +229,14 @@ SBType::GetArrayElementType()<br>
}<br>
<br>
SBType<br>
+SBType::GetArrayType (uint64_t size)<br>
+{<br>
+ if (!IsValid())<br>
+ return SBType();<br>
+ return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size))));<br>
+}<br>
+<br>
+SBType<br>
SBType::GetVectorElementType ()<br>
{<br>
SBType type_sb;<br>
<br>
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)<br>
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Aug 30 15:39:58 2016<br>
@@ -4566,6 +4566,24 @@ ClangASTContext::GetArrayElementType (ll<br>
}<br>
<br>
CompilerType<br>
+ClangASTContext::GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size)<br>
+{<br>
+ if (type)<br>
+ {<br>
+ clang::QualType qual_type(GetCanonicalQualType(type));<br>
+ if (clang::ASTContext *ast_ctx = getASTContext())<br>
+ {<br>
+ if (size == 0)<br>
+ return CompilerType (ast_ctx, ast_ctx->getConstantArrayType(qual_type, llvm::APInt(64, size), clang::ArrayType::ArraySizeModifier::Normal, 0));<br>
+ else<br>
+ return CompilerType (ast_ctx, ast_ctx->getIncompleteArrayType(qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0));<br>
+ }<br>
+ }<br>
+<br>
+ return CompilerType();<br>
+}<br>
+<br>
+CompilerType<br>
ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type)<br>
{<br>
if (type)<br>
<br>
Modified: lldb/trunk/source/Symbol/CompilerType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompilerType.cpp?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompilerType.cpp?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/CompilerType.cpp (original)<br>
+++ lldb/trunk/source/Symbol/CompilerType.cpp Tue Aug 30 15:39:58 2016<br>
@@ -467,7 +467,16 @@ CompilerType::GetArrayElementType (uint6<br>
if (IsValid())<br>
{<br>
return m_type_system->GetArrayElementType(m_type, stride);<br>
-<br>
+ }<br>
+ return CompilerType();<br>
+}<br>
+<br>
+CompilerType<br>
+CompilerType::GetArrayType (uint64_t size) const<br>
+{<br>
+ if (IsValid())<br>
+ {<br>
+ return m_type_system->GetArrayType(m_type, size);<br>
}<br>
return CompilerType();<br>
}<br>
<br>
Modified: lldb/trunk/source/Symbol/TypeSystem.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeSystem.cpp?rev=280151&r1=280150&r2=280151&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeSystem.cpp?rev=280151&r1=280150&r2=280151&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/TypeSystem.cpp (original)<br>
+++ lldb/trunk/source/Symbol/TypeSystem.cpp Tue Aug 30 15:39:58 2016<br>
@@ -62,6 +62,12 @@ TypeSystem::IsAnonymousType (lldb::opaqu<br>
}<br>
<br>
CompilerType<br>
+TypeSystem::GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size)<br>
+{<br>
+ return CompilerType();<br>
+}<br>
+<br>
+CompilerType<br>
TypeSystem::GetLValueReferenceType (lldb::opaque_compiler_type_t type)<br>
{<br>
return CompilerType();<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>