diff options
author | emaste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
commit | d61b076ede88b56f3372a55e7d1eac6a9d717120 (patch) | |
tree | a8f4b3abea3e6937e60728991c736e6e3d322fc1 /source/Symbol/ClangASTType.cpp | |
parent | 0c2019f4ca6b2dc6d710f6bb16a0e3ed10271531 (diff) | |
download | FreeBSD-src-d61b076ede88b56f3372a55e7d1eac6a9d717120.zip FreeBSD-src-d61b076ede88b56f3372a55e7d1eac6a9d717120.tar.gz |
Import LLDB as of upstream SVN 228549 (git 39760838)
Diffstat (limited to 'source/Symbol/ClangASTType.cpp')
-rw-r--r-- | source/Symbol/ClangASTType.cpp | 106 |
1 files changed, 84 insertions, 22 deletions
diff --git a/source/Symbol/ClangASTType.cpp b/source/Symbol/ClangASTType.cpp index 8b672fa..eaff90a 100644 --- a/source/Symbol/ClangASTType.cpp +++ b/source/Symbol/ClangASTType.cpp @@ -290,6 +290,37 @@ ClangASTType::IsArrayType (ClangASTType *element_type_ptr, } bool +ClangASTType::IsVectorType (ClangASTType *element_type, + uint64_t *size) const +{ + if (IsValid()) + { + clang::QualType qual_type (GetCanonicalQualType()); + + const clang::Type::TypeClass type_class = qual_type->getTypeClass(); + switch (type_class) + { + case clang::Type::Vector: + { + const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>(); + if (vector_type) + { + if (size) + *size = vector_type->getNumElements(); + if (element_type) + *element_type = ClangASTType(m_ast, vector_type->getElementType().getAsOpaquePtr()); + } + return true; + } + break; + default: + break; + } + } + return false; +} + +bool ClangASTType::IsRuntimeGeneratedType () const { if (!IsValid()) @@ -1663,7 +1694,7 @@ ClangASTType::GetArrayElementType (uint64_t *stride) const // TODO: the real stride will be >= this value.. find the real one! if (stride) - *stride = element_type.GetByteSize(); + *stride = element_type.GetByteSize(nullptr); return element_type; @@ -2062,28 +2093,59 @@ ClangASTType::GetBasicTypeFromAST (lldb::BasicType basic_type) const //---------------------------------------------------------------------- uint64_t -ClangASTType::GetBitSize () const +ClangASTType::GetBitSize (ExecutionContext *exe_ctx) const { if (GetCompleteType ()) { clang::QualType qual_type(GetCanonicalQualType()); - const uint32_t bit_size = m_ast->getTypeSize (qual_type); - if (bit_size == 0) + switch (qual_type->getTypeClass()) { - if (qual_type->isIncompleteArrayType()) - return m_ast->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified()); + case clang::Type::ObjCInterface: + case clang::Type::ObjCObject: + if (exe_ctx && exe_ctx->GetProcessPtr()) + { + ObjCLanguageRuntime *objc_runtime = exe_ctx->GetProcessPtr()->GetObjCLanguageRuntime(); + if (objc_runtime) + { + uint64_t bit_size = 0; + if (objc_runtime->GetTypeBitSize(*this, bit_size)) + return bit_size; + } + } + else + { + static bool g_printed = false; + if (!g_printed) + { + StreamString s; + s.Printf("warning: trying to determine the size of type "); + DumpTypeDescription(&s); + s.Printf("\n without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\nbacktrace:\n"); + Host::Backtrace(s, 10); + printf("%s\n", s.GetData()); + g_printed = true; + } + } + // fallthrough + default: + const uint32_t bit_size = m_ast->getTypeSize (qual_type); + if (bit_size == 0) + { + if (qual_type->isIncompleteArrayType()) + return m_ast->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified()); + } + if (qual_type->isObjCObjectOrInterfaceType()) + return bit_size + m_ast->getTypeSize(m_ast->ObjCBuiltinClassTy); + return bit_size; } - if (qual_type->isObjCObjectOrInterfaceType()) - return bit_size + m_ast->getTypeSize(m_ast->ObjCBuiltinClassTy); - return bit_size; } return 0; } uint64_t -ClangASTType::GetByteSize () const +ClangASTType::GetByteSize (ExecutionContext *exe_ctx) const { - return (GetBitSize () + 7) / 8; + return (GetBitSize (exe_ctx) + 7) / 8; } size_t @@ -3416,7 +3478,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, child_byte_offset = bit_offset/8; ClangASTType base_class_clang_type(m_ast, base_class->getType()); child_name = base_class_clang_type.GetTypeName().AsCString(""); - uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(); + uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(nullptr); // Base classes bit sizes should be a multiple of 8 bits in size assert (base_class_clang_type_bit_size % 8 == 0); @@ -3444,7 +3506,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, // alignment (field_type_info.second) from the AST context. ClangASTType field_clang_type (m_ast, field->getType()); assert(field_idx < record_layout.getFieldCount()); - child_byte_size = field_clang_type.GetByteSize(); + child_byte_size = field_clang_type.GetByteSize(exe_ctx); // Figure out the field offset within the current struct/union/class type bit_offset = record_layout.getFieldOffset (field_idx); @@ -3609,7 +3671,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, // We have a pointer to an simple type if (idx == 0 && pointee_clang_type.GetCompleteType()) { - child_byte_size = pointee_clang_type.GetByteSize(); + child_byte_size = pointee_clang_type.GetByteSize(exe_ctx); child_byte_offset = 0; return pointee_clang_type; } @@ -3630,7 +3692,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, char element_name[64]; ::snprintf (element_name, sizeof (element_name), "[%zu]", idx); child_name.assign(element_name); - child_byte_size = element_type.GetByteSize(); + child_byte_size = element_type.GetByteSize(exe_ctx); child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; return element_type; } @@ -3651,7 +3713,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, char element_name[64]; ::snprintf (element_name, sizeof (element_name), "[%zu]", idx); child_name.assign(element_name); - child_byte_size = element_type.GetByteSize(); + child_byte_size = element_type.GetByteSize(exe_ctx); child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; return element_type; } @@ -3701,7 +3763,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, // We have a pointer to an simple type if (idx == 0) { - child_byte_size = pointee_clang_type.GetByteSize(); + child_byte_size = pointee_clang_type.GetByteSize(exe_ctx); child_byte_offset = 0; return pointee_clang_type; } @@ -3745,7 +3807,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, // We have a pointer to an simple type if (idx == 0) { - child_byte_size = pointee_clang_type.GetByteSize(); + child_byte_size = pointee_clang_type.GetByteSize(exe_ctx); child_byte_offset = 0; return pointee_clang_type; } @@ -6643,7 +6705,7 @@ ClangASTType::GetValueAsScalar (const lldb_private::DataExtractor &data, if (encoding == lldb::eEncodingInvalid || count != 1) return false; - const uint64_t byte_size = GetByteSize(); + const uint64_t byte_size = GetByteSize(nullptr); lldb::offset_t offset = data_byte_offset; switch (encoding) { @@ -6771,7 +6833,7 @@ ClangASTType::SetValueFromScalar (const Scalar &value, Stream &strm) if (encoding == lldb::eEncodingInvalid || count != 1) return false; - const uint64_t bit_width = GetBitSize(); + const uint64_t bit_width = GetBitSize(nullptr); // This function doesn't currently handle non-byte aligned assignments if ((bit_width % 8) != 0) return false; @@ -6851,7 +6913,7 @@ ClangASTType::ReadFromMemory (lldb_private::ExecutionContext *exe_ctx, if (!GetCompleteType()) return false; - const uint64_t byte_size = GetByteSize(); + const uint64_t byte_size = GetByteSize(exe_ctx); if (data.GetByteSize() < byte_size) { lldb::DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0')); @@ -6901,7 +6963,7 @@ ClangASTType::WriteToMemory (lldb_private::ExecutionContext *exe_ctx, if (!GetCompleteType()) return false; - const uint64_t byte_size = GetByteSize(); + const uint64_t byte_size = GetByteSize(exe_ctx); if (byte_size > 0) { |