Add SBType::GetArrayType() such that - given a type - one can make an array (of a given size) of that type

This is currently only implemented for the clang-based TypeSystem, but other languages are welcome to jump in!

llvm-svn: 280151
This commit is contained in:
Enrico Granata 2016-08-30 20:39:58 +00:00
parent b7df1e2148
commit 639392fe76
9 changed files with 57 additions and 1 deletions

View File

@ -188,6 +188,9 @@ public:
lldb::SBType
GetArrayElementType ();
lldb::SBType
GetArrayType (uint64_t size);
lldb::SBType
GetVectorElementType ();

View File

@ -789,6 +789,9 @@ public:
CompilerType
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;

View File

@ -268,6 +268,9 @@ public:
CompilerType
GetArrayElementType(uint64_t *stride = nullptr) const;
CompilerType
GetArrayType (uint64_t size) const;
CompilerType
GetCanonicalType () const;

View File

@ -273,6 +273,9 @@ public:
virtual CompilerType
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;

View File

@ -247,6 +247,9 @@ public:
lldb::SBType
GetArrayElementType ();
lldb::SBType
GetArrayType (uint64_t size);
lldb::SBType
GetVectorElementType ();

View File

@ -228,6 +228,14 @@ SBType::GetArrayElementType()
return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCompilerType(true).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 ()
{

View File

@ -4565,6 +4565,24 @@ ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_
return CompilerType();
}
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)
{

View 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();
}

View File

@ -61,6 +61,12 @@ TypeSystem::IsAnonymousType (lldb::opaque_compiler_type_t type)
return false;
}
CompilerType
TypeSystem::GetArrayType (lldb::opaque_compiler_type_t type, uint64_t size)
{
return CompilerType();
}
CompilerType
TypeSystem::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
{