Added functionality to our API for SBType. This will allow users to eventually find and peruse static type information from modules.

llvm-svn: 110297
This commit is contained in:
Greg Clayton 2010-08-05 01:56:31 +00:00
parent 396cc7d477
commit ba9fbbb880
2 changed files with 298 additions and 1 deletions

View File

@ -14,14 +14,99 @@
namespace lldb {
class SBTypeMember;
class SBType
{
public:
SBType (void *ast = NULL, void *clang_type = NULL);
~SBType ();
bool
IsValid();
const char *
GetName();
uint64_t
GetByteSize();
Encoding
GetEncoding (uint32_t &count);
uint64_t
GetNumberChildren (bool omit_empty_base_classes);
bool
GetChildAtIndex (bool omit_empty_base_classes, uint32_t idx, SBTypeMember &member);
uint32_t
GetChildIndexForName (bool omit_empty_base_classes, const char *name);
bool
IsPointerType ();
SBType
GetPointeeType ();
static bool
IsPointerType (void *opaque_type);
private:
protected:
void *m_ast;
void *m_type;
};
class SBTypeMember
{
public:
SBTypeMember ();
~SBTypeMember ();
bool
IsValid ();
void
Clear();
bool
IsBitfield ();
size_t
GetBitfieldWidth ();
size_t
GetBitfieldOffset ();
size_t
GetOffset ();
const char *
GetName ();
SBType
GetType();
SBType
GetParentType();
void
SetName (const char *name);
protected:
friend class SBType;
void *m_ast;
void *m_parent_type;
void *m_member_type;
char *m_member_name;
int32_t m_offset;
uint32_t m_bit_size;
uint32_t m_bit_offset;
};

View File

@ -8,7 +8,9 @@
//===----------------------------------------------------------------------===//
#include "lldb/API/SBType.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTType.h"
using namespace lldb;
using namespace lldb_private;
@ -21,3 +23,213 @@ SBType::IsPointerType (void *opaque_type)
}
SBType::SBType (void *ast, void *clang_type) :
m_ast (ast),
m_type (clang_type)
{
}
SBType::~SBType ()
{
}
bool
SBType::IsValid ()
{
return m_ast != NULL && m_type != NULL;
}
const char *
SBType::GetName ()
{
if (IsValid ())
return ClangASTType::GetClangTypeName (m_type).AsCString(NULL);
return NULL;
}
uint64_t
SBType::GetByteSize()
{
if (IsValid ())
return ClangASTType::GetClangTypeBitWidth (static_cast<clang::ASTContext *>(m_ast), m_type);
return NULL;
}
Encoding
SBType::GetEncoding (uint32_t &count)
{
if (IsValid ())
return ClangASTType::GetEncoding (m_type, count);
count = 0;
return eEncodingInvalid;
}
uint64_t
SBType::GetNumberChildren (bool omit_empty_base_classes)
{
if (IsValid ())
return ClangASTContext::GetNumChildren(m_type, omit_empty_base_classes);
return 0;
}
bool
SBType::GetChildAtIndex (bool omit_empty_base_classes, uint32_t idx, SBTypeMember &member)
{
void *child_clang_type = NULL;
std::string child_name;
uint32_t child_byte_size = 0;
int32_t child_byte_offset = 0;
uint32_t child_bitfield_bit_size = 0;
uint32_t child_bitfield_bit_offset = 0;
if (IsValid ())
{
child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (static_cast<clang::ASTContext *>(m_ast),
NULL,
m_type,
idx,
false, // transparent pointers
omit_empty_base_classes,
child_name,
child_byte_size,
child_byte_offset,
child_bitfield_bit_size,
child_bitfield_bit_offset);
}
if (child_clang_type)
{
member.m_ast = m_ast;
member.m_parent_type = m_type;
member.m_member_type = child_clang_type,
member.SetName (child_name.c_str());
member.m_offset = child_byte_offset;
member.m_bit_size = child_bitfield_bit_size;
member.m_bit_offset = child_bitfield_bit_offset;
}
else
{
member.Clear();
}
return child_clang_type != NULL;
}
uint32_t
SBType::GetChildIndexForName (bool omit_empty_base_classes, const char *name)
{
return ClangASTContext::GetIndexOfChildWithName (static_cast<clang::ASTContext *>(m_ast),
m_type,
name,
omit_empty_base_classes);
}
bool
SBType::IsPointerType ()
{
return ClangASTContext::IsPointerType (m_type);
}
SBType
SBType::GetPointeeType ()
{
void *pointee_type = NULL;
if (IsPointerType ())
{
pointee_type = ClangASTType::GetPointeeType (m_type);
}
return SBType (pointee_type ? m_ast : NULL, pointee_type);
}
SBTypeMember::SBTypeMember () :
m_ast (NULL),
m_parent_type (NULL),
m_member_type (NULL),
m_member_name (NULL),
m_offset (0),
m_bit_size (0),
m_bit_offset (0)
{
}
SBTypeMember::~SBTypeMember ()
{
SetName (NULL);
}
void
SBTypeMember::SetName (const char *name)
{
if (m_member_name)
free (m_member_name);
if (name && name[0])
m_member_name = ::strdup (name);
else
m_member_name = NULL;
}
void
SBTypeMember::Clear()
{
m_ast = NULL;
m_parent_type = NULL;
m_member_type = NULL;
SetName (NULL);
m_offset = 0;
m_bit_size = 0;
m_bit_offset = 0;
}
bool
SBTypeMember::IsValid ()
{
return m_member_type != NULL;
}
bool
SBTypeMember::IsBitfield ()
{
return m_bit_size != 0;
}
size_t
SBTypeMember::GetBitfieldWidth ()
{
return m_bit_size;
}
size_t
SBTypeMember::GetBitfieldOffset ()
{
return m_bit_offset;
}
size_t
SBTypeMember::GetOffset ()
{
return m_offset;
}
SBType
SBTypeMember::GetType()
{
return SBType (m_ast, m_member_type);
}
SBType
SBTypeMember::GetParentType()
{
return SBType (m_ast, m_parent_type);
}
const char *
SBTypeMember::GetName ()
{
return m_member_name;
}