From 639392fe76d61fcb6960f438ce0736911c964526 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Tue, 30 Aug 2016 20:39:58 +0000 Subject: [PATCH] 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 --- lldb/include/lldb/API/SBType.h | 3 +++ lldb/include/lldb/Symbol/ClangASTContext.h | 3 +++ lldb/include/lldb/Symbol/CompilerType.h | 3 +++ lldb/include/lldb/Symbol/TypeSystem.h | 3 +++ lldb/scripts/interface/SBType.i | 3 +++ lldb/source/API/SBType.cpp | 8 ++++++++ lldb/source/Symbol/ClangASTContext.cpp | 18 ++++++++++++++++++ lldb/source/Symbol/CompilerType.cpp | 11 ++++++++++- lldb/source/Symbol/TypeSystem.cpp | 6 ++++++ 9 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h index ed3c2ff..a374253 100644 --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -189,6 +189,9 @@ public: GetArrayElementType (); lldb::SBType + GetArrayType (uint64_t size); + + lldb::SBType GetVectorElementType (); lldb::SBType diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 809a12e..f383b92 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -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 diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 36f6ef3..db15a34 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -269,6 +269,9 @@ public: GetArrayElementType(uint64_t *stride = nullptr) const; CompilerType + GetArrayType (uint64_t size) const; + + CompilerType GetCanonicalType () const; CompilerType diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 220ff43..249dfba 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -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 diff --git a/lldb/scripts/interface/SBType.i b/lldb/scripts/interface/SBType.i index 76bd3f0..999941a 100644 --- a/lldb/scripts/interface/SBType.i +++ b/lldb/scripts/interface/SBType.i @@ -247,6 +247,9 @@ public: lldb::SBType GetArrayElementType (); + + lldb::SBType + GetArrayType (uint64_t size); lldb::SBType GetVectorElementType (); diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index 4922b49..a786d32 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -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; diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index f1358c0..9cc8550 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -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) diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index 2b06c93..ef788d0 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -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(); } diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp index 2cd82f2..3aadcaa 100644 --- a/lldb/source/Symbol/TypeSystem.cpp +++ b/lldb/source/Symbol/TypeSystem.cpp @@ -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(); -- 2.7.4